Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp356030imm; Fri, 3 Aug 2018 04:45:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdSIoRZOZNWvOHMIWU4J/1anLOfY5jG9ibR3vfdOCngka95rk2o4fBoXhIAR85InmwAHC4h X-Received: by 2002:a17:902:a24:: with SMTP id 33-v6mr3258358plo.88.1533296701062; Fri, 03 Aug 2018 04:45:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533296701; cv=none; d=google.com; s=arc-20160816; b=Ztfzn44+FzPNFNm4X60KTgwXp/edY2u0ekh1v4pr87ntZtyxyQGfOVjqLkNJg+iS2v kI/1EwjL0AcrTtXNJUJKnWr3Slqdc3pptC5OelO8kX2s6v1Y6vkDsBMMp4FAcDfpfPJr qpQtWM6EJmuy5xORV0EtzzMJJVq2wDVWZ/94lwjUzRvuPzniVLYMFLmvYvl0E3xwYDMq HIx/jtweQeJv2hyHS5jzHrNQZXd682xdg7BCCHa2tAvdHAU8UMCtiKBeq3sAndBn6G4B 9YCoGijTUEqDH+GgHdXPtHJhFHQJ13SKBYBGSalnwnb4q8ztJ5i18p/DY2nWtc1ImG6G X/GA== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=oXuR2hcc/+Fmwt8ZzggVTWaIgwkPtS17lwQkmL2iLr0=; b=HcAtldhgcD5xVpUsG8W1Y+/+942wFTxAiPBv1rbO4tOQXQhqeiJ43gXiu77ZUFfUDM TBNz5gcdtg6yyP9FBOVcXr5PGFAgAhD/6rU0bh5Ficw4uWz0ZsxK8eG5FLI5xIbB3cQg ih71w3a9i/i/KXYlgx3KawrmYdWs4mv6lTHXEM3AZPs5p28zIhhYIocmsujokoQuH7C3 EqjNYXdEXaNYyjRaLtB7V7q6sDa0QsF6frJqmkKyFSX7bAs2tlLW+GQBNIU/X+v5Lene kwmDhBmHxBfGYytUCVDAgCEVgUGHgYeMegw+cA3+QrlrdaUZi1twuC+seKrDNWa4E6EX 3z+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cXMFTiB4; 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 f9-v6si3398170plo.206.2018.08.03.04.44.45; Fri, 03 Aug 2018 04:45:01 -0700 (PDT) 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=cXMFTiB4; 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 S1728752AbeHCNjQ (ORCPT + 99 others); Fri, 3 Aug 2018 09:39:16 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:38792 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727464AbeHCNjQ (ORCPT ); Fri, 3 Aug 2018 09:39:16 -0400 Received: by mail-it0-f65.google.com with SMTP id v71-v6so7937166itb.3 for ; Fri, 03 Aug 2018 04:43:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=oXuR2hcc/+Fmwt8ZzggVTWaIgwkPtS17lwQkmL2iLr0=; b=cXMFTiB4CW0kv8u1Hm54AlScQ/eGXxGgHlIrE+vRpnm6IuoEp8xkRjVXiOuNfT/CsH gfyEOEefLd4z3QaFo6TdoETEBAHvPjMPMpWyEVJ4s1T0d1QbyrfuUq3JHmehIAEesfG1 HBJr/h5ESZeIeX0XCEoy1d9st9jBglGSLmYQs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=oXuR2hcc/+Fmwt8ZzggVTWaIgwkPtS17lwQkmL2iLr0=; b=gw83loH4WK9JLXEvDpghesQZ7ZgQCb/N0R2rJZQSvVWCdR5RSDX3R+p0aQMl+4/rog 5LMPsvdJggxo1cWy/zULxnCif4Kxk+r0pd+ekknDpgeqZTg2sUa29GPr/AYALzcg/DmU dUWuAwtV81W9xFHO0k+rLzSAtZYIJiFQMlDtBGg0g7Lm21SmA3ew5RPTknPWQFY6LHWq Bk0mnePl9lkKrRDuq2Vpc0VpUsZlAEpAC+lYa+lywNVN7S/U++fmQmBMs9U5j/tRwyGO G+eqfWyVTTisuyIb6mfCrN20P9Bg8h23meyUfgw8qOWt4iDeUEWr75lIFH0Qx7c0BUEu QTeQ== X-Gm-Message-State: AOUpUlFJAEA/Px0cbAmb0Bh+RZKBlxw7u7cY7XfoF56C9CYvgMC7oRdC FQeZEV83trp1W5zL1FjeJuYNXIQBKqhu291bcqXC2A== X-Received: by 2002:a02:570c:: with SMTP id u12-v6mr3034946jaa.142.1533296598836; Fri, 03 Aug 2018 04:43:18 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:2b03:0:0:0:0:0 with HTTP; Fri, 3 Aug 2018 04:43:18 -0700 (PDT) In-Reply-To: <1678369.6pMUSOvdlV@aspire.rjw.lan> References: <20180620172226.15012-1-ulf.hansson@linaro.org> <20180620172226.15012-5-ulf.hansson@linaro.org> <1678369.6pMUSOvdlV@aspire.rjw.lan> From: Ulf Hansson Date: Fri, 3 Aug 2018 13:43:18 +0200 Message-ID: Subject: Re: [PATCH v8 04/26] PM / Domains: Add support for CPU devices to genpd To: "Rafael J. Wysocki" Cc: Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Linux PM , Kevin Hilman , Lina Iyer , Lina Iyer , Rob Herring , Daniel Lezcano , Thomas Gleixner , Vincent Guittot , Stephen Boyd , Juri Lelli , Geert Uytterhoeven , Linux ARM , linux-arm-msm , Linux Kernel Mailing List 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 19 July 2018 at 12:25, Rafael J. Wysocki wrote: > On Wednesday, June 20, 2018 7:22:04 PM CEST Ulf Hansson wrote: >> To enable a device belonging to a CPU to be attached to a PM domain managed >> by genpd, let's do a few changes to genpd as to make it convenient to >> manage the specifics around CPUs. >> >> First, as to be able to quickly find out what CPUs that are attached to a >> genpd, which typically becomes useful from a genpd governor as following >> changes is about to show, let's add a cpumask 'cpus' to the struct >> generic_pm_domain. >> >> At the point when a device that belongs to a CPU, is attached/detached to >> its corresponding PM domain via genpd_add_device(), let's update the >> cpumask in genpd->cpus. Moreover, propagate the update of the cpumask to >> the master domains, which makes the genpd->cpus to contain a cpumask that >> hierarchically reflect all CPUs for a genpd, including CPUs attached to >> subdomains. >> >> Second, to unconditionally manage CPUs and the cpumask in genpd->cpus, is >> unnecessary for cases when only non-CPU devices are parts of a genpd. >> Let's avoid this by adding a new configuration bit, GENPD_FLAG_CPU_DOMAIN. >> Clients must set the bit before they call pm_genpd_init(), as to instruct >> genpd that it shall deal with CPUs and thus manage the cpumask in >> genpd->cpus. >> >> Cc: Lina Iyer >> Co-developed-by: Lina Iyer >> Signed-off-by: Ulf Hansson >> --- >> drivers/base/power/domain.c | 69 ++++++++++++++++++++++++++++++++++++- >> include/linux/pm_domain.h | 3 ++ >> 2 files changed, 71 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c >> index 21d298e1820b..6149ce0bfa7b 100644 >> --- a/drivers/base/power/domain.c >> +++ b/drivers/base/power/domain.c >> @@ -20,6 +20,7 @@ >> #include >> #include >> #include >> +#include >> >> #include "power.h" >> >> @@ -126,6 +127,7 @@ static const struct genpd_lock_ops genpd_spin_ops = { >> #define genpd_is_irq_safe(genpd) (genpd->flags & GENPD_FLAG_IRQ_SAFE) >> #define genpd_is_always_on(genpd) (genpd->flags & GENPD_FLAG_ALWAYS_ON) >> #define genpd_is_active_wakeup(genpd) (genpd->flags & GENPD_FLAG_ACTIVE_WAKEUP) >> +#define genpd_is_cpu_domain(genpd) (genpd->flags & GENPD_FLAG_CPU_DOMAIN) >> >> static inline bool irq_safe_dev_in_no_sleep_domain(struct device *dev, >> const struct generic_pm_domain *genpd) >> @@ -1377,6 +1379,62 @@ static void genpd_free_dev_data(struct device *dev, >> dev_pm_put_subsys_data(dev); >> } >> >> +static void __genpd_update_cpumask(struct generic_pm_domain *genpd, >> + int cpu, bool set, unsigned int depth) >> +{ >> + struct gpd_link *link; >> + >> + if (!genpd_is_cpu_domain(genpd)) >> + return; >> + >> + list_for_each_entry(link, &genpd->slave_links, slave_node) { >> + struct generic_pm_domain *master = link->master; >> + >> + genpd_lock_nested(master, depth + 1); >> + __genpd_update_cpumask(master, cpu, set, depth + 1); >> + genpd_unlock(master); >> + } >> + >> + if (set) >> + cpumask_set_cpu(cpu, genpd->cpus); >> + else >> + cpumask_clear_cpu(cpu, genpd->cpus); >> +} > > As noted elsewhere, there is a concern about the possible weight of this > cpumask and I think that it would be good to explicitly put a limit on it. I have been digesting your comments on the series, but wonder if this is still a relevant concern? Updating the mask is only done when the cpu is attached to its PM domain. However, of course, I should not allocate the cpumask in pm_genpd_init() unless the GENPD_FLAG_CPU_DOMAIN is set, as that is just a waste. > >> + >> +static void genpd_update_cpumask(struct generic_pm_domain *genpd, >> + struct device *dev, bool set) >> +{ >> + bool is_cpu = false; >> + int cpu; >> + >> + if (!genpd_is_cpu_domain(genpd)) >> + return; >> + >> + for_each_possible_cpu(cpu) { >> + if (get_cpu_device(cpu) == dev) { >> + is_cpu = true; > > You may call __genpd_update_cpumask() right here and then you won't > need the extra is_cpu variable. Yes, indeed this looks weird, thanks for spotting it! Ah, now I recall, the idea was to store an is_cpu variable per device, to avoid looking up the cpu device at detach, but this is just unnecessary. :-) [...] Thanks for reviewing! Kind regards Uffe