From patchwork Thu Sep 28 10:15:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9975713 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 444C7603F2 for ; Thu, 28 Sep 2017 10:18:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33A922954D for ; Thu, 28 Sep 2017 10:18:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 286D02954E; Thu, 28 Sep 2017 10:18:43 +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 2023429549 for ; Thu, 28 Sep 2017 10:18:41 +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 1dxVrV-000882-6Q; Thu, 28 Sep 2017 10:16:09 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dxVrU-00087q-4v for xen-devel@lists.xenproject.org; Thu, 28 Sep 2017 10:16:08 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id 89/30-02226-7EBCCC95; Thu, 28 Sep 2017 10:16:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrHIsWRWlGSWpSXmKPExsXiVRvkrPvw9Jl Ig0OHzSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oz1LR+ZC/5KV5xv7GNuYPwi1sXIxSEkMINR Yv79ZWwgDovAGlaJTTffsnQxcnJICFxilXjarwxhp0ks33SfEcZe+vU/K4RdLnFv5naweiEBF Ymb21cxQUz9ySix9PsusISwgJ7EkaM/2CFsF4kTz98yg9hsAgYSb3bsBRskIqAkcW/VZLBmZo FXjBKnT+0D28YioCqxekELmM0r4C3R+fcGG4jNCWSvm/IBaAEH0DYvidapYSBhUQE5iZWXW1g hygUlTs58AlbCLKApsX6XPkiYWUBeYvvbOcwTGEVnIamahVA1C0nVAkbmVYwaxalFZalFuoaW eklFmekZJbmJmTm6hgbGermpxcWJ6ak5iUnFesn5uZsYgXFRz8DAuIPx93G/Q4ySHExKorw6J 85ECvEl5adUZiQWZ8QXleakFh9ilOHgUJLgZQPGmZBgUWp6akVaZg4wQmHSEhw8SiK8TCBp3u KCxNzizHSI1ClGXY59e279YRJiycvPS5US5113CqhIAKQoozQPbgQsWVxilJUS5mVkYGAQ4il ILcrNLEGVf8UozsGoJMwrBbKKJzOvBG4TMBqA7hfhnTwR7IiSRISUVAOjwvI5XKd/a4jobc4o eSymKf7o44u4c/e+3vSOLPVi36d5aob1tX7eWYnNltLCmffrTim1dc11i5beIXJLcfGTn/PZD uZyfNvVeFS/KVVWx0gysOxK8q2P8x9lLfh9uelpcvWGrE1fX1qZLpG2bZjX5+Idl8naxuShX1 nXIM7T/tFt99xrYsVKLMUZiYZazEXFiQB5H+CfEQMAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-2.tower-31.messagelabs.com!1506593761!105246149!1 X-Originating-IP: [74.125.82.67] 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 1474 invoked from network); 28 Sep 2017 10:16:01 -0000 Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by server-2.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 28 Sep 2017 10:16:01 -0000 Received: by mail-wm0-f67.google.com with SMTP id u138so1195903wmu.5 for ; Thu, 28 Sep 2017 03:16:01 -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=EJmA2H4D5yVDWwS1P5WD7w+E2ANAOwvYRVQp+6cHHNM=; b=BaPParXCJOed8Quk291g54MAZz49kUOD9MSaXrL5LqusXaWEdXNLc+Kj2PJrXE3BAY NchGWW/Z8nb2anA34/s2SKz01zbSwc1mEP1vR8wLahDDVz3DhkZM3xrlU3uaHo5ove2A UXWrvKpuA+KdAgZcWuOIJx/TNEtplD+mFvAkU2pJboUCbUaqX4bqzIhdlzPelLEn4jDN epCO92gL0wAS9sqMAXHUjiuKC36m4p2e5FrFOGIhktndxdVxxLuIh7JJ8vtEc3A4Mm+R 0VaclM4MjOQsyGq/P0xsw6oIMk60RVctxCwRzs6/qEyPe1C+VnK+VAxNvp5R5BC0/yHM /43w== 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=EJmA2H4D5yVDWwS1P5WD7w+E2ANAOwvYRVQp+6cHHNM=; b=KN2da9ws++Gxdlkpx1rm/u2cAYqRcKFtUHH4wxNg63P1EfM05tE/bCymN4iaFA488U nTVDfc6Gr8yqxO+mf8dhoh7LnW5OqxOkEThHWkIRiFAVKrL+dDgLI8kyeNoGWtKGXnvy 25fN3gruk9QwABX6NqExY1ZF/MWoytGYmXCIJ8a3rDpfNoP5M2FL8jvbL7sgYlZ6+kp2 Llz/3Nba8z8LOnPpTYtBX3lSde+Q4mQA0OZwgVzXFb8YBYgb5UjSPcfLqcUvbAHMwtv3 4QPqe2lC4JcuoZi4XxsrcCAMG97jyJiMOxt3JGnw8gUgC+7wsbXdyVygbpLAPkvd5XnH T5zw== X-Gm-Message-State: AHPjjUj2IOu0CIqzfUM0R7FIDJLTqEJtQxAwVCsrBFMpkuaTZhQz3kgU B3fy5JYX5r7sjtW5Frb0oCc= X-Google-Smtp-Source: AOwi7QBUMX7KbYzMjDhEt3wR87chdvdH1McnO9cZwAL3LHe1wzXM7aClc9dQY4oja3fXbZB/Vn6+IQ== X-Received: by 10.28.6.149 with SMTP id 143mr615564wmg.114.1506593761417; Thu, 28 Sep 2017 03:16:01 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.52]) by smtp.gmail.com with ESMTPSA id l11sm1336331wre.53.2017.09.28.03.16.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Sep 2017 03:16:00 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Thu, 28 Sep 2017 12:15:59 +0200 Message-ID: <150659375919.4057.11728919580033384187.stgit@Solace.fritz.box> In-Reply-To: <150659250903.4057.6425247157210641083.stgit@Solace.fritz.box> References: <150659250903.4057.6425247157210641083.stgit@Solace.fritz.box> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Cc: Stefano Stabellini , George Dunlap , Andrew Cooper , Tim Deegan , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH v2 1/3] xen: RCU: let the RCU idle timer handler run 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 stop_timer() is called between when the RCU idle timer's interrupt arrives (and TIMER_SOFTIRQ is raised) and when softirqs are checked and handled, the timer is deactivated, and the handler never runs. This happens to the RCU idle timer because stop_timer() is called on it during the wakeup from idle (e.g., C-states, on x86) path. To fix that, we avoid calling stop_timer(), in case we see that the timer itself is: - still active, - expired (i.e., it's expiry time is in the past). In fact, that indicates (for this particular timer) that it has fired, and we are just about to handle the TIMER_SOFTIRQ (which will perform the timer deactivation and run its handler). Signed-off-by: Dario Faggioli --- Cc: Andrew Cooper Cc: George Dunlap Cc: Jan Beulich Cc: Stefano Stabellini Cc: Julien Grall Cc: Tim Deegan --- Changes from v1: - logic changed completely: instead of avoiding deactivate_timer() in stop_timer(), we avoid stop_timer() in rcu_idle_timer_stop() (if appropriate, of course). --- xen/common/rcupdate.c | 16 +++++++++++++++- xen/common/timer.c | 17 +++++++++++++++++ xen/include/xen/timer.h | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/xen/common/rcupdate.c b/xen/common/rcupdate.c index 871936f..4a02cdd 100644 --- a/xen/common/rcupdate.c +++ b/xen/common/rcupdate.c @@ -465,7 +465,21 @@ void rcu_idle_timer_stop() return; rdp->idle_timer_active = false; - stop_timer(&rdp->idle_timer); + + /* + * In general, as the CPU is becoming active again, we don't need the + * idle timer, and so we want to stop it. + * + * However, in case we are here because idle_timer has (just) fired and + * has woken up the CPU, we skip stop_timer() now. In fact, if we stop + * it, then the TIMER_SOFTIRQ handler wouldn't find idle_timer among the + * active timers any longer, and hence won't call rcu_idle_timer_handler(). + * + * Therefore, if we see that the timer is expired already, leave it alone. + * It will be finally deactiveted by the TIMER_SOFTIRQ handler. + */ + if ( !timer_is_expired(&rdp->idle_timer, NOW()) ) + stop_timer(&rdp->idle_timer); } static void rcu_idle_timer_handler(void* data) diff --git a/xen/common/timer.c b/xen/common/timer.c index d9ff669..a768aa3 100644 --- a/xen/common/timer.c +++ b/xen/common/timer.c @@ -332,6 +332,23 @@ void stop_timer(struct timer *timer) } +bool timer_is_expired(struct timer *timer, s_time_t now) +{ + unsigned long flags; + bool ret = false; + + if ( !timer_lock_irqsave(timer, flags) ) + return ret; + + if ( active_timer(timer) && timer->expires <= now ) + ret = true; + + timer_unlock_irqrestore(timer, flags); + + return ret; +} + + void migrate_timer(struct timer *timer, unsigned int new_cpu) { unsigned int old_cpu; diff --git a/xen/include/xen/timer.h b/xen/include/xen/timer.h index 9531800..a095007 100644 --- a/xen/include/xen/timer.h +++ b/xen/include/xen/timer.h @@ -70,6 +70,9 @@ void set_timer(struct timer *timer, s_time_t expires); */ void stop_timer(struct timer *timer); +/* True if a timer is active, but with its expiry time before now. */ +bool timer_is_expired(struct timer *timer, s_time_t now); + /* Migrate a timer to a different CPU. The timer may be currently active. */ void migrate_timer(struct timer *timer, unsigned int new_cpu);