Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4901077imu; Wed, 19 Dec 2018 02:11:11 -0800 (PST) X-Google-Smtp-Source: AFSGD/Uf0onn45F9cHZHTKZRJ0oTXkAviYwOwvoJHuh1cB0XDcJrnnNzuE7EF3e/DzQqmqzBx6eL X-Received: by 2002:a65:47ca:: with SMTP id f10mr19330436pgs.166.1545214271610; Wed, 19 Dec 2018 02:11:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545214271; cv=none; d=google.com; s=arc-20160816; b=PjtaZ6q0agNOveLWtL3Av/BffcB1AAoTpTRkPxQfVndNbIfVoCDBLFzyuXe4UjGIE8 oS0rQuSemnm0u37WEwAh5fqgrsYGiIx5YW7Qt/hFZ32jsCwHJaZ203Fs2plSFQ5LKNg/ K5Q0T3MvIZPLnPQNzs0kdZKJcz3bZbrhWcbOlGErvjtrImoW0RcBaYfNqi3yBWZxdYyj xa86e0yd0aBGe/Ur0vvqv2VsVxHb8JZfcRuW0+mhQNnvgM+/irAdCBQQeUH3lR52J3ZV VHt7P0uAkQbuZh0m3sATTVed2CQb60d21hN1WpWgwuPBFIFWnhMM7Kun7GJXhZ9hu0Is n2Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5/K3ksz2cOuGH+8ZePuFENnYOvHlfiSjHSQXc/PYJ2c=; b=MZHLXsqp1OfMgapM9e6OH8GSxeTKX70j/yR+esZ9m95o1GGac7HQvxzMDjUBE5sL2p 0rYRkVr5lEMt9OGgCDELVeZ5CJ9oH2JFgWG3Dd+dMCs/aV5a6zR42M+w1UYs2gc01NCf X+5UmIaLrC3l0NUgOZIMWXawfKnPtt1NN+merAwPUX2ceXIrwhli+/H23D0XCDjPGNbZ PKuDC4niDUn1w/GyL4tzmK8LhKJGw47HiqvQUX5pr+aRb0NTDISrtdtliNBzP7xl7xgK uwB1YfFE9ZcqcutHSQBch62ZgX1oD7CYvHfL88s1MMnyTSieAFnsvnWN669dKzOzaBzW KEDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RQ3h4xZ8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a24si15618712pgd.248.2018.12.19.02.10.55; Wed, 19 Dec 2018 02:11:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RQ3h4xZ8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728897AbeLSKKF (ORCPT + 99 others); Wed, 19 Dec 2018 05:10:05 -0500 Received: from mail-vs1-f65.google.com ([209.85.217.65]:39168 "EHLO mail-vs1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728708AbeLSKKF (ORCPT ); Wed, 19 Dec 2018 05:10:05 -0500 Received: by mail-vs1-f65.google.com with SMTP id h78so11892890vsi.6 for ; Wed, 19 Dec 2018 02:10:04 -0800 (PST) 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=5/K3ksz2cOuGH+8ZePuFENnYOvHlfiSjHSQXc/PYJ2c=; b=RQ3h4xZ8xf011F6uO04XuKcLaR0eSLQf56kPf2PwCFf8encr5t4yZcsP2//ZUyeqZb 0XXXQmjZFkshO8WK7FK5I42B2gPtvDAJeSIXTVi/NmmtJ6ZrNE1Z7zS/bkzbmnlLRXbj HWW1rGq17p4uQiOt++oJtRbnnmPV1J0IvFiv4= 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=5/K3ksz2cOuGH+8ZePuFENnYOvHlfiSjHSQXc/PYJ2c=; b=ZgN7GonQpvhqgqXVrqIUNfLuMJl6fC/+hNcaaGUx241rnYATkel6Cstm/Iaj9+oLnY lcf/csThXwDhSMRlIM/CNOmD8oCI2Y2FNHaPF1CoNlpPwzoUPwdvpZeAxnMMruB2DmL5 70aUdhM31QRiNHCa7gO1GDxLvhFUeZf9Cfg3Cd0pTVOpEXtUp6bTpmeNTn6Zkik1DH/M hwGDIHTwaUNyexBDPGsez/rhYpEF6d9WFMQt5Tqa0SUpVllHUNHlt7B+XY0PiI1ma3ve hRlwh0WjHQP7aZI88JGT8op5VLVmD06Y8VnX1+3gyptIN6IryE55iCaoey+7iFQalNBb yW3w== X-Gm-Message-State: AA+aEWZeA3HLCdDmGliUTtroXB3fqMNM+gGYpVEqI4+Q6z9nXW8BP9oE diiPky1Eb/0pRo8RN+K4hYIoTpVINvwPNbtGquV9Og== X-Received: by 2002:a67:e002:: with SMTP id c2mr10059987vsl.34.1545214203976; Wed, 19 Dec 2018 02:10:03 -0800 (PST) MIME-Version: 1.0 References: <20181129174700.16585-1-ulf.hansson@linaro.org> <20181129174700.16585-5-ulf.hansson@linaro.org> <5529fc0a-af96-b10a-ca4a-f1417598f4ee@linaro.org> In-Reply-To: <5529fc0a-af96-b10a-ca4a-f1417598f4ee@linaro.org> From: Ulf Hansson Date: Wed, 19 Dec 2018 11:09:28 +0100 Message-ID: Subject: Re: [PATCH v10 04/27] PM / Domains: Add genpd governor for CPUs To: Daniel Lezcano Cc: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Linux PM , "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 , Thomas Gleixner , Frederic Weisbecker , Ingo Molnar Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 19 Dec 2018 at 10:54, Daniel Lezcano wrote: > > On 29/11/2018 18:46, Ulf Hansson wrote: > > As it's now perfectly possible that a PM domain managed by genpd contains > > devices belonging to CPUs, we should start to take into account the > > residency values for the idle states during the state selection process. > > The residency value specifies the minimum duration of time, the CPU or a > > group of CPUs, needs to spend in an idle state to not waste energy entering > > it. > > > > To deal with this, let's add a new genpd governor, pm_domain_cpu_gov, that > > may be used for a PM domain that have CPU devices attached or if the CPUs > > are attached through subdomains. > > > > The new governor computes the minimum expected idle duration time for the > > online CPUs being attached to the PM domain and its subdomains. Then in the > > state selection process, trying the deepest state first, it verifies that > > the idle duration time satisfies the state's residency value. > > > > It should be noted that, when computing the minimum expected idle duration > > time, we use the information from tick_nohz_get_next_wakeup(), to find the > > next wakeup for the related CPUs. Future wise, this may deserve to be > > improved, as there are more reasons to why a CPU may be woken up from idle. > > > > Cc: Thomas Gleixner > > Cc: Daniel Lezcano > > Cc: Lina Iyer > > Cc: Frederic Weisbecker > > Cc: Ingo Molnar > > Co-developed-by: Lina Iyer > > Signed-off-by: Ulf Hansson > > --- > > > > Changes in v10: > > - Fold in patch that extended the new genpd CPU governor to cope with > > QoS constraints, as to avoid confusion. > > - Simplified the code according to suggestions from Rafael. > > > > --- > > drivers/base/power/domain_governor.c | 61 +++++++++++++++++++++++++++- > > include/linux/pm_domain.h | 3 ++ > > 2 files changed, 63 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/base/power/domain_governor.c b/drivers/base/power/domain_governor.c > > index 99896fbf18e4..61a7c3c03c98 100644 > > --- a/drivers/base/power/domain_governor.c > > +++ b/drivers/base/power/domain_governor.c > > @@ -10,6 +10,9 @@ > > #include > > #include > > #include > > +#include > > +#include > > +#include > > > > static int dev_update_qos_constraint(struct device *dev, void *data) > > { > > @@ -211,8 +214,10 @@ static bool default_power_down_ok(struct dev_pm_domain *pd) > > struct generic_pm_domain *genpd = pd_to_genpd(pd); > > struct gpd_link *link; > > > > - if (!genpd->max_off_time_changed) > > + if (!genpd->max_off_time_changed) { > > + genpd->state_idx = genpd->cached_power_down_state_idx; > > return genpd->cached_power_down_ok; > > + } > > > > /* > > * We have to invalidate the cached results for the masters, so > > @@ -237,6 +242,7 @@ static bool default_power_down_ok(struct dev_pm_domain *pd) > > genpd->state_idx--; > > } > > > > + genpd->cached_power_down_state_idx = genpd->state_idx; > > return genpd->cached_power_down_ok; > > } > > > > @@ -245,6 +251,54 @@ static bool always_on_power_down_ok(struct dev_pm_domain *domain) > > return false; > > } > > > > +static bool cpu_power_down_ok(struct dev_pm_domain *pd) > > +{ > > + struct generic_pm_domain *genpd = pd_to_genpd(pd); > > + ktime_t domain_wakeup, cpu_wakeup; > > + s64 idle_duration_ns; > > + int cpu, i; > > + > > + /* Validate dev PM QoS constraints. */ > > + if (!default_power_down_ok(pd)) > > + return false; > > + > > + if (!(genpd->flags & GENPD_FLAG_CPU_DOMAIN)) > > + return true; > > Is it possible to have this function called without the > GENPD_FLAG_CPU_DOMAIN flag set in the genpd? Theoretically yes, however in practice, probably not. Do note, if the GENPD_FLAG_CPU_DOMAIN isn't set, then we haven't allocated the cpumask for the genpd, so then we shouldn't use it. > > > + /* > > + * Find the next wakeup for any of the online CPUs within the PM domain > > + * and its subdomains. Note, we only need the genpd->cpus, as it already > > + * contains a mask of all CPUs from subdomains. > > + */ > > + domain_wakeup = ktime_set(KTIME_SEC_MAX, 0); > > + for_each_cpu_and(cpu, genpd->cpus, cpu_online_mask) { > > + cpu_wakeup = tick_nohz_get_next_wakeup(cpu); > > + if (ktime_before(cpu_wakeup, domain_wakeup)) > > + domain_wakeup = cpu_wakeup; > > + } > > + [...] Kind regards Uffe