From patchwork Wed Aug 16 16:45:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9904153 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 2DB0C600CA for ; Wed, 16 Aug 2017 16:48:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F1FF28A1B for ; Wed, 16 Aug 2017 16:48:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13C8828A4C; Wed, 16 Aug 2017 16:48:18 +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 9A4ED28A1B for ; Wed, 16 Aug 2017 16:48:17 +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 1di1SE-00025n-7z; Wed, 16 Aug 2017 16:46:02 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1di1SC-00025M-Ta for xen-devel@lists.xenproject.org; Wed, 16 Aug 2017 16:46:01 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 1F/D5-03044-8C674995; Wed, 16 Aug 2017 16:46:00 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBIsWRWlGSWpSXmKPExsVyMbThiO7xsim RBkv/aVh83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBmfp+9lLTgsWvHwew9LA+NEwS5GLg4hgRmM EpNOXWAGcVgE1rBK3F/1iRXEkRC4BOSs2MPWxcgJ5MRJXPzexQxhV0ncProKLC4koCJxc/sqJ ohR3xgl7lyFSAgL6EkcOfqDvYuRA8j2kljaaw4SZhMwkHizYy8riC0ioCRxb9VkJhCbWeAJk8 TKp4wgNouAqsT3NW1gcV4Bb4mr5/+A7eUU8JVY+OAyC8ReH4mDPXvB6kUF5CRWXm5hhagXlDg 58wkLyFpmAU2J9bv0IcbLS2x/O4d5AqPILCRVsxCqZiGpWsDIvIpRozi1qCy1SNfQUC+pKDM9 oyQ3MTNH19DATC83tbg4MT01JzGpWC85P3cTIzD8GYBgB+OnZQGHGCU5mJREeb3yp0QK8SXlp 1RmJBZnxBeV5qQWH2KU4eBQkuDdUAqUEyxKTU+tSMvMAUYiTFqCg0dJhPcsSJq3uCAxtzgzHS J1itGY48qVdV+YOKYc2P6FSYglLz8vVUqcdxFIqQBIaUZpHtwgWIK4xCgrJczLCHSaEE9BalF uZgmq/CtGcQ5GJWHeSyBTeDLzSuD2vQI6hQnolCvtk0BOKUlESEk1MDq2pc+feMHelU94Ul3V vuWfA+7tdf55L3hyYLZ5+ILfHBa7QtO3Ta06kHvoFNOX8vfs+hbx2WxXNgRNeyjmw1offcxkH reeVQ7HdPuFYQve8b4PYdj1U7nfpV2K0eKgiN/eA5xf3llc65kfcMp6Qf7ui/6dryxftAVYyD yVWLi17972BZ8YI5VYijMSDbWYi4oTAd7vn68LAwAA X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-2.tower-21.messagelabs.com!1502901959!64287730!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 15173 invoked from network); 16 Aug 2017 16:45:59 -0000 Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by server-2.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 16 Aug 2017 16:45:59 -0000 Received: by mail-wr0-f196.google.com with SMTP id x43so4012005wrb.1 for ; Wed, 16 Aug 2017 09:45:59 -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=dMFNwzZXZdoneucayKvFdHg7c4IzOgqEUUjzFsDY/xGH03BPlkVWn4BzAYs2GhafZg S/pynLxz1/4hzQQ65Zc7m8DJ5Ke4ycGKDv1VpBbirgCrOV7qRslJhbd4X7eHDevzPe8M WD29QaVnln263JxGXgiqUsKgdTzvNRxC4KTay/x7WLJopiUfhabeLtLIKPNuVUyqvSQP SnTSx1A4QqQSEFrdE7zei/8fHaPxfGFv7fC3pcCYUkA9WadiZDqR/Cflwh8cbPs7lCdF g7cUQCeBApAcOomP22idV1kdLW2LjnnXuugJQ1yUi5nWUeYugmSYD0oIaJTFwfb+aTPZ xC4A== 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=fxyiSKcRcYWyT6mrYET4xQvSZIYYZPBba9mD7JRHRpu9ED/+GaJMIaZq7emHxwL97i 8XXSoZ2YpS4kZpAQiuHlCb1MdvCtg2MO2urTFtbxV8OMu8C2kUDbbktV1aJcn++a7vcV +4O54bvJIkrwPgiTHS1PtIuCOkvvMw+Eh2nzHdrHjuVWMy27CKcJFWavkZXGD1PI1YQ5 dCZHj8wyh/06MV4dnfL3DxamIAaI4i7r08SR0Y29oB76FQ3qDVFgdZqZhfhVGHW3zuxo wmFW2PAoXu43LZYVL9zM0TRuFarGxFEukcCbtl4pANPcyQpP7VScTK86WObi2vJ+cLp+ rvaQ== X-Gm-Message-State: AHYfb5hne96roDLROwuqCNn6LMZbVNTA8R/rlXT5vrx2PRGXgSYkOaXW oxiB/u9y+8A8XQ== X-Received: by 10.28.150.142 with SMTP id y136mr1526069wmd.51.1502901959317; Wed, 16 Aug 2017 09:45:59 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.3]) by smtp.gmail.com with ESMTPSA id 91sm1088716wri.7.2017.08.16.09.45.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Aug 2017 09:45:58 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Wed, 16 Aug 2017 18:45:57 +0200 Message-ID: <150290195713.24854.3267681243338344295.stgit@Solace.fritz.box> In-Reply-To: <150290125292.24854.17418548557562763544.stgit@Solace.fritz.box> References: <150290125292.24854.17418548557562763544.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 v2 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 --- 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))