From patchwork Fri Aug 18 18:04:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9909699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F55B60385 for ; Fri, 18 Aug 2017 18:06:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 587F428D18 for ; Fri, 18 Aug 2017 18:06:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D6DC28D2B; Fri, 18 Aug 2017 18:06:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DEB2028D18 for ; Fri, 18 Aug 2017 18:06:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dildN-0002Iv-OL; Fri, 18 Aug 2017 18:04:37 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dildM-0002IR-Qa for xen-devel@lists.xenproject.org; Fri, 18 Aug 2017 18:04:36 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id 85/7C-01731-43C27995; Fri, 18 Aug 2017 18:04:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOIsWRWlGSWpSXmKPExsVyMbThiK6BzvR Ig/MfrS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozP0/eyFhwWrXj4vYelgXGiYBcjF4eQwHRG ifczethAHBaBNawSPRPbmEEcCYFLrBJPW98BZTiBnDiJ59tbmSHsaolDfz6C2UICKhI3t69ig hj1k1HibFMHI0hCWEBP4sjRH+wQtpfE9nnHwGw2AQOJNzv2soLYIgJKEvdWTWYCsZkFnjBJrH wK1MsBdIaqRP+JSpAwr4CPxJfvjWDlnED2i4snWCH2eku8+72CBcQWFZCTWHm5hRWiXlDi5Mw nLCBjmAU0Jdbv0oeYLi+x/e0c5gmMIrOQVM1CqJqFpGoBI/MqRvXi1KKy1CJdI72kosz0jJLc xMwcXUMDU73c1OLixPTUnMSkYr3k/NxNjMDgZwCCHYzf/zgdYpTkYFIS5f09a0qkEF9SfkplR mJxRnxRaU5q8SFGGQ4OJQleLu3pkUKCRanpqRVpmTnAOIRJS3DwKInwPtICSvMWFyTmFmemQ6 ROMRpzXLmy7gsTx5QD278wCbHk5eelSonzsoNMEgApzSjNgxsESw+XGGWlhHkZgU4T4ilILcr NLEGVf8UozsGoJMzrDrKQJzOvBG7fK6BTmIBOMWydBnJKSSJCSqqBMdWE5fSqih8BZ7giN/xO Nzm8uUxo1f6kG8eesU2uMJKePSnlXs+RzU86Zn8ur966Z+lxw/NPBFZcLr6WGe3RuD/GgvMNe wNLpsRR2y13OS8u+rXDf9Wxa+3F4T6Fn+JUdjY8kTmlq32saVqP2IHpWXfY5Q8G8y09XsMsUX Wo9bfbIasPcw9LpimxFGckGmoxFxUnAgBJoR53CgMAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1503079472!105059677!1 X-Originating-IP: [209.85.128.196] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34720 invoked from network); 18 Aug 2017 18:04:32 -0000 Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by server-6.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 18 Aug 2017 18:04:32 -0000 Received: by mail-wr0-f196.google.com with SMTP id 49so7924395wrw.5 for ; Fri, 18 Aug 2017 11:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=kqorUZTiSnS1+/m1t4Kb42OBDVxq+XpUy8C0BXFbhvg=; b=U6G8dL+Vu/N9jZSW5nYQDF3FVO53bKdLY7APB3vBgaAou7leJwGCAfyi07/4o137Za dHLXjMNhb7bz4fRAgqcuhW2Ti+L0Cakmg2zLiXgWnL4J46YckXsPV3SxMIOhtUWgV/hm wP/R8KyhUPUrJCIFK0bjt+1d65AsrjTF+U0fSTS1Wf1mYAGy6SECEyU3dfW9RPDMMS4n CQ1/idkVKc7UqFOnsPe9HWX4x9GtgQ5qCk62OKvrfiEh0aGk9mUR5o8z66zyIPJstCAl Iu7zwrVcWTOsdenw4U29mJKVRYt+pNLa9g4qLuY1yQB95/9Dgofq80H6TU6gchLtXWPv HSXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:from:to:cc:date:message-id :in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=kqorUZTiSnS1+/m1t4Kb42OBDVxq+XpUy8C0BXFbhvg=; b=RC0QvDe7HzW7qcmAEcuxB2XeQWGxE7W+fz1OPEYwzAVV8grEU7Wv5YJfNYMMxLq7Ta X3zckqn5TfTXaxJEWQwEimPdaPbNTHiwjn8YOOd6fBVa40TAF5x/RBvpvuDqmYym+yH3 bzjIdWHNB6tBeRn7qyMVxsR6ziWa8V05Y0hdY8HTcB80vgRY04fVFxaXRK13TXwb7T/+ K1eiPq/fnEpBfdQ13xemOz1UUVy8JfgBUmpM24QS/NBdH0ON5RVi+uTfTq8N6NJTKcFt ecm+8utZ2nX53wL+7sloZX0a9ll0o/V1TUzLrOkrBYglpvT6NHu0pbHfZTa2HrIVXTIo WCNg== X-Gm-Message-State: AHYfb5ggIM/izkdt27O0aGr5ON5knwGAYXQ62quZAKoV+8dLpF0o/clJ UyCehz1Fb6n/7Q== X-Received: by 10.223.158.205 with SMTP id b13mr5582467wrf.131.1503079472576; Fri, 18 Aug 2017 11:04:32 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.3]) by smtp.gmail.com with ESMTPSA id u46sm12422833wrf.15.2017.08.18.11.04.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Aug 2017 11:04:31 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Fri, 18 Aug 2017 20:04:30 +0200 Message-ID: <150307947033.29525.16503215464785953885.stgit@Solace.fritz.box> In-Reply-To: <150307710991.29525.3681195976643263117.stgit@Solace.fritz.box> References: <150307710991.29525.3681195976643263117.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH v3 4/6] xen: RCU: don't let a CPU with a callback go idle. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP If a CPU has a callback queued, it must be ready to invoke it, as soon as all the other CPUs involved in the grace period has gone through a quiescent state. But if we let such CPU go idle, we can't really tell when (if!) it will realize that it is actually time to invoke the callback. To solve this problem, a CPU that has a callback queued (and has already gone through a quiescent state itself) will stay online, until the grace period ends, and the callback can be invoked. This is similar to what Linux does, and is the second and last step for fixing the overly long (or infinite!) grace periods. The problem, though, is that, within Linux, we have the tick, so, all that is necessary is to not stop the tick for the CPU (even if it has gone idle). In Xen, there's no tick, so we must avoid for the CPU to go idle entirely, and let it spin on rcu_pending(), consuming power and causing overhead. In this commit, we implement the above, using rcu_needs_cpu(), in a way similar to how it is used in Linux. This it correct, useful and not wasteful for CPUs that participate in grace period, but have not a callback queued. For the ones that has callbacks, an optimization that avoids having to spin is introduced in a subsequent change. Signed-off-by: Dario Faggioli Reviewed-by: Jan Beulich Acked-by: George Dunlap --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Julien Grall Cc: Tim Deegan Cc: Wei Liu --- xen/include/xen/sched.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 5828a01..c116604 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -847,7 +847,8 @@ uint64_t get_cpu_idle_time(unsigned int cpu); /* * Used by idle loop to decide whether there is work to do: - * (1) Run softirqs; or (2) Play dead; or (3) Run tasklets. + * (1) Deal with RCU; (2) or run softirqs; or (3) Play dead; + * or (4) Run tasklets. * * About (3), if a tasklet is enqueued, it will be scheduled * really really soon, and hence it's pointless to try to @@ -855,7 +856,8 @@ uint64_t get_cpu_idle_time(unsigned int cpu); * the tasklet_work_to_do() helper). */ #define cpu_is_haltable(cpu) \ - (!softirq_pending(cpu) && \ + (!rcu_needs_cpu(cpu) && \ + !softirq_pending(cpu) && \ cpu_online(cpu) && \ !per_cpu(tasklet_work_to_do, cpu))