From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ulf Hansson Subject: Re: [PATCH v12 3/4] cpuidle: Export the next timer/tick expiration for a CPU Date: Mon, 25 Mar 2019 15:23:27 +0100 Message-ID: References: <20190227195836.24739-1-ulf.hansson@linaro.org> <20190227195836.24739-4-ulf.hansson@linaro.org> <2942111.nn8VVVUCAL@aspire.rjw.lan> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: In-Reply-To: <2942111.nn8VVVUCAL@aspire.rjw.lan> Sender: linux-kernel-owner@vger.kernel.org To: "Rafael J. Wysocki" Cc: Linux PM , Frederic Weisbecker , Thomas Gleixner , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , Linux ARM , linux-arm-msm , Linux Kernel Mailing List List-Id: linux-arm-msm@vger.kernel.org On Mon, 25 Mar 2019 at 13:21, Rafael J. Wysocki wrote: > > On Wednesday, February 27, 2019 8:58:35 PM CET Ulf Hansson wrote: > > To be able to predict the sleep duration for a CPU that is entering idle, > > knowing when the next timer/tick is going to expire, is extremely useful. > > Both the teo and the menu cpuidle governors already makes use of this > > information, while selecting an idle state. > > > > Moving forward, the similar prediction needs to be done, but for a group of > > idle CPUs rather than for a single idle CPU. Following changes implements a > > new genpd governor, which needs this. > > > > Support this, by sharing a new function called > > tick_nohz_get_next_hrtimer(), which returns the next hrtimer or the next > > tick, whatever that expires first. > > > > Additionally, when cpuidle is about to invoke the ->enter() callback, then > > call tick_nohz_get_next_hrtimer() and store its return value in the per CPU > > struct cpuidle_device, as to make it available outside cpuidle. > > > > Do note, at the point when cpuidle calls tick_nohz_get_next_hrtimer(), the > > governor's ->select() callback has already made a decision whether to stop > > the tick or not. In this way, tick_nohz_get_next_hrtimer() actually returns > > the next timer expiration, whatever origin. > > > > Cc: Lina Iyer > > Co-developed-by: Lina Iyer > > Co-developed-by: Daniel Lezcano > > Signed-off-by: Ulf Hansson > > --- > > > > Changes in v12: > > - New patch. > > > > --- > > drivers/cpuidle/cpuidle.c | 8 ++++++++ > > include/linux/cpuidle.h | 1 + > > include/linux/tick.h | 7 ++++++- > > kernel/time/tick-sched.c | 12 ++++++++++++ > > 4 files changed, 27 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c > > index 7f108309e871..255365b1a6ab 100644 > > --- a/drivers/cpuidle/cpuidle.c > > +++ b/drivers/cpuidle/cpuidle.c > > @@ -328,6 +328,14 @@ int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, > > int cpuidle_enter(struct cpuidle_driver *drv, struct cpuidle_device *dev, > > int index) > > { > > + /* > > + * Store the next hrtimer, which becomes either next tick or the next > > + * timer event, whatever expires first. Additionally, to make this data > > + * useful for consumers outside cpuidle, we rely on that the governor's > > + * ->select() callback have decided, whether to stop the tick or not. > > + */ > > + dev->next_hrtimer = tick_nohz_get_next_hrtimer(); > > I would use WRITE_ONCE() to set next_hrtimer here and READ_ONCE() for > reading that value in the next patch, as a matter of annotation if > nothing else. Okay! > > > + > > if (cpuidle_state_is_coupled(drv, index)) > > return cpuidle_enter_state_coupled(dev, drv, index); > > return cpuidle_enter_state(dev, drv, index); > > Also I would clear next_hrtimer here to avoid dragging stale values > around. Right, I can do that. However, at least in my case it would be an unnecessary update of the variable, as I am never in a path where the value can be "stale". Even if one theoretically could use a stale value, it's seems likely to not be an issue, don't you think? Anyway, if I don't hear from you, I do the change as you suggested. > > Apart from this the series LGTM. Great, thanks. I re-spin a new version. Kind regards Uffe From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46830C43381 for ; Mon, 25 Mar 2019 14:24:22 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1637C2084D for ; Mon, 25 Mar 2019 14:24:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="j5CNRgnl"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="NPybfnOj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1637C2084D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oVWzPxZnNx+yDCtA0CPAHPU/pEsWOpwCF0D2AcHlp68=; b=j5CNRgnlvYHl7n E5YK/AjhHe7m4OxXYY6ZBFznwDDgesLAhi1QXxyZ2HGGAeUSoa/kIkoqd33cQBWsH8sKy7CY51xmk p4u4VsU7mK9RKB26hrNZB/hza73oN3Up5kjdJ4I9yB0yjlaT3TUS192Fz0UWC5O/EBocp7fOYH51P PBKHUbFYaFYmI7Y1gxGU/0YCVIGm1XkvNMwiCMX4k3raDZBmot9LQHhoBgF1hq0VMVw8PFCgkN4xj v+p0ZcZyQAneJg863jkXBfohOvl27PJ4HQvHBz+Nh8//0HVySUJZYDmmOFB7uNTyYhM8s9zktrjZB cLBYIBdYpNftQDZf92TA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8QWH-0001Qk-FA; Mon, 25 Mar 2019 14:24:09 +0000 Received: from mail-vk1-xa43.google.com ([2607:f8b0:4864:20::a43]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8QWD-0001Q9-5Z for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 14:24:07 +0000 Received: by mail-vk1-xa43.google.com with SMTP id j195so1978269vkj.9 for ; Mon, 25 Mar 2019 07:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=18Uy2+5EeK7lK1NTsT1PhmlbcUQuf+mmQID+bLSg5mI=; b=NPybfnOjuYYvfG5P4rUPY46w6oJ+pu+1nvaFz3rSOexY5JI6jJwcZSiKwzUzZrsRsY mDrICkRcbzGwX0ct8NIYXBV7T+Bo79nVVBxs9FqkNnFVQpw5Cyuba/vuSA7L7nDuZbX+ Kc+cdGd8TZqVGpdAKVd5sXnWLHZQKoXU6WlR5ZCOM1zLrhaiqCpWq8FZxW1QfNqBZqGg gKpSVQqB31F/6nMY3yE8PpU2hRpDQcyYHYrX3CRasyrWnQjVNGseKCG17YqaZ762RKSt 44HsJWWbUK4Nxkhxo1NeDjSWziS5Mk7W6RV+zcH2PiYbhuGQGy130/18ZvicwrSkLWgj oPzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=18Uy2+5EeK7lK1NTsT1PhmlbcUQuf+mmQID+bLSg5mI=; b=fzlNRcu4e4r2AQCCUlt7osJ4Irv63TlNC3Imi8iMft2DMQwNN+umcuyhmuRj3v218A YpXcCtvdOIBUlNiTSsMWzHcivQx310OVs9MCTk9Qt1u+M3LsGu/jRZehcLOSOduVovfC bNM4LdjLe9vtUSPOVXqEVC2KaEMcC3bDB0ESxaBRl4OTCVlyFhJd18zqdn7slXs1ucbS x4D7qvlLjetLWisfauidYLGY9n1GuMDNc+FCPf0yDtZJYRZ85IJ6n56O2x6Mgvx6kHk9 hFP0oNFsxdOg/ljLMV5pVBBPYIt2JcHcYxeFrYbYXaayMhqiaSBGKfp1PFullp1SQGIM mOsg== X-Gm-Message-State: APjAAAXfefimisEC3C9CtUuZasg0SYJZEsvQ47ANLCjP+ANMylLZZ7wM AqrsW6mVT4pB1z8y52LTPb54pjISeMEFVG66kdHosg== X-Google-Smtp-Source: APXvYqyK5Sj8t0/bmtqkpbdMu8pleiBUSOsqzKm1/sXL0Xmus+qPMB2fDPyYUiHVAUaC20uNARhr/OqBhC599wkycao= X-Received: by 2002:a1f:3458:: with SMTP id b85mr3910490vka.4.1553523843044; Mon, 25 Mar 2019 07:24:03 -0700 (PDT) MIME-Version: 1.0 References: <20190227195836.24739-1-ulf.hansson@linaro.org> <20190227195836.24739-4-ulf.hansson@linaro.org> <2942111.nn8VVVUCAL@aspire.rjw.lan> In-Reply-To: <2942111.nn8VVVUCAL@aspire.rjw.lan> From: Ulf Hansson Date: Mon, 25 Mar 2019 15:23:27 +0100 Message-ID: Subject: Re: [PATCH v12 3/4] cpuidle: Export the next timer/tick expiration for a CPU To: "Rafael J. Wysocki" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_072405_221005_FEC307EC X-CRM114-Status: GOOD ( 27.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Lorenzo Pieralisi , Vincent Guittot , Geert Uytterhoeven , Linux PM , Stephen Boyd , Frederic Weisbecker , linux-arm-msm , Daniel Lezcano , Kevin Hilman , Lina Iyer , Linux Kernel Mailing List , Tony Lindgren , Viresh Kumar , Sudeep Holla , Thomas Gleixner , "Raju P . L . S . S . S . N" , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 25 Mar 2019 at 13:21, Rafael J. Wysocki wrote: > > On Wednesday, February 27, 2019 8:58:35 PM CET Ulf Hansson wrote: > > To be able to predict the sleep duration for a CPU that is entering idle, > > knowing when the next timer/tick is going to expire, is extremely useful. > > Both the teo and the menu cpuidle governors already makes use of this > > information, while selecting an idle state. > > > > Moving forward, the similar prediction needs to be done, but for a group of > > idle CPUs rather than for a single idle CPU. Following changes implements a > > new genpd governor, which needs this. > > > > Support this, by sharing a new function called > > tick_nohz_get_next_hrtimer(), which returns the next hrtimer or the next > > tick, whatever that expires first. > > > > Additionally, when cpuidle is about to invoke the ->enter() callback, then > > call tick_nohz_get_next_hrtimer() and store its return value in the per CPU > > struct cpuidle_device, as to make it available outside cpuidle. > > > > Do note, at the point when cpuidle calls tick_nohz_get_next_hrtimer(), the > > governor's ->select() callback has already made a decision whether to stop > > the tick or not. In this way, tick_nohz_get_next_hrtimer() actually returns > > the next timer expiration, whatever origin. > > > > Cc: Lina Iyer > > Co-developed-by: Lina Iyer > > Co-developed-by: Daniel Lezcano > > Signed-off-by: Ulf Hansson > > --- > > > > Changes in v12: > > - New patch. > > > > --- > > drivers/cpuidle/cpuidle.c | 8 ++++++++ > > include/linux/cpuidle.h | 1 + > > include/linux/tick.h | 7 ++++++- > > kernel/time/tick-sched.c | 12 ++++++++++++ > > 4 files changed, 27 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c > > index 7f108309e871..255365b1a6ab 100644 > > --- a/drivers/cpuidle/cpuidle.c > > +++ b/drivers/cpuidle/cpuidle.c > > @@ -328,6 +328,14 @@ int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, > > int cpuidle_enter(struct cpuidle_driver *drv, struct cpuidle_device *dev, > > int index) > > { > > + /* > > + * Store the next hrtimer, which becomes either next tick or the next > > + * timer event, whatever expires first. Additionally, to make this data > > + * useful for consumers outside cpuidle, we rely on that the governor's > > + * ->select() callback have decided, whether to stop the tick or not. > > + */ > > + dev->next_hrtimer = tick_nohz_get_next_hrtimer(); > > I would use WRITE_ONCE() to set next_hrtimer here and READ_ONCE() for > reading that value in the next patch, as a matter of annotation if > nothing else. Okay! > > > + > > if (cpuidle_state_is_coupled(drv, index)) > > return cpuidle_enter_state_coupled(dev, drv, index); > > return cpuidle_enter_state(dev, drv, index); > > Also I would clear next_hrtimer here to avoid dragging stale values > around. Right, I can do that. However, at least in my case it would be an unnecessary update of the variable, as I am never in a path where the value can be "stale". Even if one theoretically could use a stale value, it's seems likely to not be an issue, don't you think? Anyway, if I don't hear from you, I do the change as you suggested. > > Apart from this the series LGTM. Great, thanks. I re-spin a new version. Kind regards Uffe _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel