From patchwork Thu Sep 28 17:06:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Faggioli X-Patchwork-Id: 9976417 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 6472760365 for ; Thu, 28 Sep 2017 17:09:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F31F2965C for ; Thu, 28 Sep 2017 17:09:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4422A29688; Thu, 28 Sep 2017 17:09:20 +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 CC31E296BA for ; Thu, 28 Sep 2017 17:09:19 +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 1dxcGb-0002vx-BD; Thu, 28 Sep 2017 17:06:29 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dxcGZ-0002vr-Nd for xen-devel@lists.xenproject.org; Thu, 28 Sep 2017 17:06:27 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 3A/BF-03454-31C2DC95; Thu, 28 Sep 2017 17:06:27 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmleJIrShJLcpLzFFi42K5GNpwRFdI52y kwc11whbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8b3ZU0sBVPkK/Y2PGduYNwn2cXIySEkMIVR 4uOigC5GLg4WgTWsEn9a2hlBHAmBS6wSrc0PmUGqJATSJHZdeckGYy+e+hgozgFkV0l03OODG KQicXP7KiaQXiGB74wSj49eZwRJCAvoSRw5+oMdwnaRmLxgNZjNJmAg8WbHXlYQW0RASeLeqs lgzcwCrxglTp/aB9bMIqAq0fp0J1gRr4C3xO2HP8HinED2oTPz2SE2e0mserMaLC4qICex8nI LVL2gxMmZT1hADmUW0JRYv0sfJMwsIC+x/e0c5gmMorOQVM1CqJqFpGoBI/MqRvXi1KKy1CJd Y72kosz0jJLcxMwcXUMDM73c1OLixPTUnMSkYr3k/NxNjMCoYACCHYwd/5wOMUpyMCmJ8uprn 40U4kvKT6nMSCzOiC8qzUktPsQow8GhJMF7SAsoJ1iUmp5akZaZA4xPmLQEB4+SCO86kDRvcU FibnFmOkTqFKMxx4U7l/4wcRzYc+sPkxBLXn5eqpQ472eQUgGQ0ozSPLhBsLRxiVFWSpiXEeg 0IZ6C1KLczBJU+VeM4hyMSsK8DCC38mTmlcDtA0YG0BcivJMnngE5pSQRISXVwBgm5TX/tTfP pwvWs9i7D1kemS+g1q/VLMx9wP3Bs53r+l7bXZyZKNJ9fQJz9C5Ln51Vl9+ufacmvPIFO8etC qNcA1PJ5CbLBTJaTGVt80+ez7s54dsBwU9MhRvKTrM/P/VyQr1CzjStOTdmt7Przn++LXtThf Kkc6KdC6ezLi0V/rLkg1MRQ44SS3FGoqEWc1FxIgBPG58aFgMAAA== X-Env-Sender: raistlin.df@gmail.com X-Msg-Ref: server-10.tower-27.messagelabs.com!1506618386!95839613!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 40348 invoked from network); 28 Sep 2017 17:06:26 -0000 Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by server-10.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 28 Sep 2017 17:06:26 -0000 Received: by mail-wr0-f196.google.com with SMTP id 45so2431wry.5 for ; Thu, 28 Sep 2017 10:06:26 -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=GnEBhTnC3rBT4p4qD4ps4cWKaXZLUzENeic6MwKWZgY=; b=SQLBgmSebiKrUAZFo8teCWDeMbE87ZlBx4YYDoy53KqbnyYqN7nu9EuMSJz7inZuog eVAp4N35ZZ/q7297ABTh+cumtCmGXbbYqreIM7tK10FbE38R8cpng7MnRqO0m1tYu9s8 u6by3ns7AgyJKeLBSIQrTm1zRZypey/o+kX7/UToxVZkRk6u1Drfssr3MPNtcq2rkRIw HpYbQpvX1Y9hQ4IZN7IAszJKZJ7a8mDslRoxgbm7BtfdwMne5GRWwR6CMKrGokUJf7D3 5DOsAcMiNKkXc2bQratuWZQjNfOhl7kKJ7QUDVf2Py1IOtZA7WB3B/fWkBWBeqfFb3FG r1ow== 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=GnEBhTnC3rBT4p4qD4ps4cWKaXZLUzENeic6MwKWZgY=; b=ihUtz5yFNhgT123LXwVK1ipn0CZ8rjjXKKY86D80ZhGRf1MPVDwdoHUtiUg8RpWN3E waxtZ3AXQ4nBi31k02DPBIHSrUIuhXSMwqAyso89jFiGx4TZfkNJddG2L5UszpHiv1xI EJyPb48kXpSO+YLYqwtmSwMASbWzKoG7qpKobrSweCRuL7iAerDOagjZ7BstTc7f+7pR TMohWrtczbUMyCx35hGRIVd0ajw1El+R1W9w+J0CqodIEM/fQHputRUYZOAynmQvGHat 3FIPmdCdcx7xx4hV8V96ilUT69EDOfRxl42+HOMRI2R5wuJE8JVyDGJSzAPh+NRuYhCR XR8g== X-Gm-Message-State: AHPjjUjnbTt/Ggj7f6m9ietVViB88D07ACC11XqJzPm6qr+ySI6dNw1W KsFeAkzCAAOLNaH39VO8V5w= X-Google-Smtp-Source: AOwi7QBCOrTmfUguh9n56776KMOIU5pvJOFkkVAJ1ATAA3vunRjFcU5eWJ+8FbTRR8Eb2wL45xnTTw== X-Received: by 10.223.153.149 with SMTP id y21mr5564037wrb.46.1506618381049; Thu, 28 Sep 2017 10:06:21 -0700 (PDT) Received: from Solace.fritz.box ([80.66.223.52]) by smtp.gmail.com with ESMTPSA id o3sm1169104wmg.3.2017.09.28.10.06.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Sep 2017 10:06:20 -0700 (PDT) From: Dario Faggioli To: xen-devel@lists.xenproject.org Date: Thu, 28 Sep 2017 19:06:19 +0200 Message-ID: <150661837885.4976.14015806170584961193.stgit@Solace.fritz.box> In-Reply-To: <150661816186.4976.5537636029076214002.stgit@Solace.fritz.box> References: <150661816186.4976.5537636029076214002.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 v3 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 Reviewed-by: Jan Beulich --- Cc: Andrew Cooper Cc: George Dunlap Cc: Jan Beulich Cc: Stefano Stabellini Cc: Julien Grall Cc: Tim Deegan --- Changes from v2: - improved comment in rcu_idle_timer_stop(); - introduce a more generic timer_expires_before() function, and make timer_is_expired() a macro which does not take any time parameter. 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 | 19 ++++++++++++++++++- xen/common/timer.c | 17 +++++++++++++++++ xen/include/xen/timer.h | 5 +++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/xen/common/rcupdate.c b/xen/common/rcupdate.c index 871936f..252e01b 100644 --- a/xen/common/rcupdate.c +++ b/xen/common/rcupdate.c @@ -465,7 +465,24 @@ 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, when a CPU + * wakes up from idle, this code always runs before do_softirq() has the + * chance to check and deal with TIMER_SOFTIRQ. And if we stop the timer + * now, the TIMER_SOFTIRQ handler will see it as inactive, and will not + * call rcu_idle_timer_handler(). + * + * Therefore, if we see that the timer is expired already, we leave it + * alone. The TIMER_SOFTIRQ handler will then run the timer routine, and + * deactivate it. + */ + if ( !timer_is_expired(&rdp->idle_timer) ) + 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..fa45db2 100644 --- a/xen/common/timer.c +++ b/xen/common/timer.c @@ -332,6 +332,23 @@ void stop_timer(struct timer *timer) } +bool timer_expires_before(struct timer *timer, s_time_t t) +{ + unsigned long flags; + bool ret = false; + + if ( !timer_lock_irqsave(timer, flags) ) + return ret; + + if ( active_timer(timer) && timer->expires <= t ) + 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..4513260 100644 --- a/xen/include/xen/timer.h +++ b/xen/include/xen/timer.h @@ -70,6 +70,11 @@ void set_timer(struct timer *timer, s_time_t expires); */ void stop_timer(struct timer *timer); +/* True if a timer is active, and its expiry time is earlier than t. */ +bool timer_expires_before(struct timer *timer, s_time_t t); + +#define timer_is_expired(t) timer_expires_before(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);