Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8889261ybl; Fri, 17 Jan 2020 02:56:05 -0800 (PST) X-Google-Smtp-Source: APXvYqx7p8nZ8m8eNV4Mf3RIOCKKq3Syfb1k2CLxOHwnJOU4Ioq2GrdvzRe5fMSV50DDphCAGrro X-Received: by 2002:a05:6830:214d:: with SMTP id r13mr5618335otd.225.1579258565499; Fri, 17 Jan 2020 02:56:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579258565; cv=none; d=google.com; s=arc-20160816; b=1CREgHpq/ftyG1xfdO8MnoVVjgYK4rV11zAVBLf6TULkvWRNu+V9It9qZGNoe88T6s ZG2X0XziET/uRDYISCREdTMqTd4R9QdSWmK8SSWKTa8385+seZGr2AcYewqyeZT95Ef4 Es/srlMHSjO2VTtG/HaVThKqnR18X4F3J3FuMdvC4WHB7n7Z2xygsgQlswE8awUvsIS3 qwx1PRNwA3SQELJ+43KOAO3ZuFlW8TxDPTxOZYjWD9WbFWMeGoHicSNHPZanHMkFHiUf 5IX/uhvfXtC/XeaiMgUGhuEBkNEbF65e/oSWnOjXC9LZUtkb79q6bQY2Q3xWQj1vHUFA ZtNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ZIor9gKMoZIiatH4TckXR6kw5rMM1XpWfkSuSCSgKXE=; b=sABMSkPwJxtS6IHzdcNGwZ7B7npfCCwyF6uqotdKYd/J3ASO0ThY2X1EfNANdn7zAI xbtNNcE5F09bfl+0gHvcWqdjs/YXSlyjjoakjwAYUkZSyMWhH8wOGijmbIbi3e8y50VI 4rWdoy/Ycs9I69QYO6gdaN8z80V/d+SpeDh/8UBGYWF6VcSofvKBVct1NThd10lBfCkM QnjpHvqt7mczltGSWgTDg2/j8Qzgb9JEdGPmayKYzJ2QS4MQrP+yT1YcRkNZs2J3WJlr gKNDgebTutm3yPACrNPybeuIUarCO7UY65Hd23l83k6Z/upu/DA85GeSbHvXOBGAkPnz gENQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OWTd1xPA; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j24si16253995otk.76.2020.01.17.02.55.52; Fri, 17 Jan 2020 02:56:05 -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=@google.com header.s=20161025 header.b=OWTd1xPA; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726915AbgAQKyq (ORCPT + 99 others); Fri, 17 Jan 2020 05:54:46 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38161 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726861AbgAQKyp (ORCPT ); Fri, 17 Jan 2020 05:54:45 -0500 Received: by mail-wr1-f65.google.com with SMTP id y17so22256202wrh.5 for ; Fri, 17 Jan 2020 02:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ZIor9gKMoZIiatH4TckXR6kw5rMM1XpWfkSuSCSgKXE=; b=OWTd1xPAQY9tXJXOZoWIjFDzF/j5k4C12aIyvlJSkkdhXlVbD45jelTm6GVI3uVYL7 n9xkBrIBsIRyofHDfGxI/l2E5DARRbN+kNYjfXDlt0D2NMz3tS9otMH27qG8unAMXkVK vbv+o0soDwEv+wngnnE6P2hSuYjaWEszgXFVB2E8sY/8BNNmwio0HXgTBeM5ojO90Xqz eXsC84eVsPLNozUlGBGgx1RDyImJeajA48zW6/mFqj9bm+S8xvtQCF24bQIklM7kmSQd UX9n+G82Jt0cw5vAEM+XOAz116BMbTc1FuSDri3NMDqzY9VqQE8QDk2hGTzsWxJxyW1O /sRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ZIor9gKMoZIiatH4TckXR6kw5rMM1XpWfkSuSCSgKXE=; b=W+72mWU3NKpSTMeQ0OjL05fGw2w3MVbnkHPCrvo2IDucQ8i4orSm8qh5NWOmJXAW4R votdbYb/eoJN4dQVn/5yrzJR3jwN4wy04TXy7UP7x2OVjrOfFmT9pim3a+BXG81bnRV+ prrQkTNXUiEReAgiX9PsAmT1oFipRNjpDXPTUnGuXkRYs5OUOMkoD8v4WDrRuNEPQS3N URg3HErx2blYJwV3/Fm/HNPn9VL5av/XnJ26uRH5gwXAV5C3qjtIT67sdNVTzJBnupAU sb8dYBjd2L6ESBA2bwPAkYIt+lPIiNVR24CWdYz91Td4EH3TFcACRy1xgU3ffNY+ThnL YIkw== X-Gm-Message-State: APjAAAUOYMiMoIOs2oyB9PJ1C0R5pIva/monJH7lNohIs1jxAURQuh3o Th1Qd2IZcC9pujyi9Tg5tvzoZg== X-Received: by 2002:a05:6000:1288:: with SMTP id f8mr2534273wrx.66.1579258481679; Fri, 17 Jan 2020 02:54:41 -0800 (PST) Received: from google.com ([2a00:79e0:d:110:d6cc:2030:37c1:9964]) by smtp.gmail.com with ESMTPSA id b17sm33252857wrp.49.2020.01.17.02.54.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2020 02:54:40 -0800 (PST) Date: Fri, 17 Jan 2020 10:54:37 +0000 From: Quentin Perret To: lukasz.luba@arm.com Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-omap@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-imx@nxp.com, Morten.Rasmussen@arm.com, Dietmar.Eggemann@arm.com, Chris.Redpath@arm.com, ionela.voinescu@arm.com, javi.merino@arm.com, cw00.choi@samsung.com, b.zolnierkie@samsung.com, rjw@rjwysocki.net, sudeep.holla@arm.com, viresh.kumar@linaro.org, nm@ti.com, sboyd@kernel.org, rui.zhang@intel.com, amit.kucheria@verdurent.com, daniel.lezcano@linaro.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, kernel@pengutronix.de, khilman@kernel.org, agross@kernel.org, bjorn.andersson@linaro.org, robh@kernel.org, matthias.bgg@gmail.com, steven.price@arm.com, tomeu.vizoso@collabora.com, alyssa.rosenzweig@collabora.com, airlied@linux.ie, daniel@ffwll.ch, kernel-team@android.com Subject: Re: [PATCH 1/4] PM / EM: and devices to Energy Model Message-ID: <20200117105437.GA211774@google.com> References: <20200116152032.11301-1-lukasz.luba@arm.com> <20200116152032.11301-2-lukasz.luba@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200116152032.11301-2-lukasz.luba@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hey Lukasz, Still reading through this, but with small changes, this looks pretty good to me. On Thursday 16 Jan 2020 at 15:20:29 (+0000), lukasz.luba@arm.com wrote: > +int em_register_perf_domain(struct device *dev, unsigned int nr_states, > + struct em_data_callback *cb) > { > unsigned long cap, prev_cap = 0; > struct em_perf_domain *pd; > - int cpu, ret = 0; > + struct em_device *em_dev; > + cpumask_t *span = NULL; > + int cpu, ret; > > - if (!span || !nr_states || !cb) > + if (!dev || !nr_states || !cb || !cb->active_power) Nit: you check !cb->active_power in em_create_pd() too I think, so only one of the two is needed. > return -EINVAL; > > - /* > - * Use a mutex to serialize the registration of performance domains and > - * let the driver-defined callback functions sleep. > - */ > mutex_lock(&em_pd_mutex); > > - for_each_cpu(cpu, span) { > - /* Make sure we don't register again an existing domain. */ > - if (READ_ONCE(per_cpu(em_data, cpu))) { > + if (_is_cpu_device(dev)) { > + span = kzalloc(cpumask_size(), GFP_KERNEL); > + if (!span) { > + mutex_unlock(&em_pd_mutex); > + return -ENOMEM; > + } > + > + ret = dev_pm_opp_get_sharing_cpus(dev, span); > + if (ret) > + goto free_cpumask; That I think should be changed. This creates some dependency on PM_OPP for the EM framework. And in fact, the reason we came up with PM_EM was precisely to not depend on PM_OPP which was deemed too Arm-specific. Suggested alternative: have two registration functions like so: int em_register_dev_pd(struct device *dev, unsigned int nr_states, struct em_data_callback *cb); int em_register_cpu_pd(cpumask_t *span, unsigned int nr_states, struct em_data_callback *cb); where em_register_cpu_pd() does the CPU-specific work and then calls em_register_dev_pd() (instead of having that big if (_is_cpu_device(dev)) as you currently have). Would that work ? Another possibility would be to query CPUFreq instead of PM_OPP to get the mask, but I'd need to look again at the driver registration path in CPUFreq to see if the policy masks have been populated when we enter PM_EM ... I am not sure if this is the case, but it's worth having a look too. Thanks, Quentin