Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2648094ybl; Mon, 20 Jan 2020 06:53:27 -0800 (PST) X-Google-Smtp-Source: APXvYqytAoJqpDRpHaHdMHzjriDv2OT2kKZd4BeIxWF0huNJTH36zxn8ALEjDCIphTIvaqZjsoY/ X-Received: by 2002:a05:6830:1d7b:: with SMTP id l27mr15317475oti.251.1579532007779; Mon, 20 Jan 2020 06:53:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579532007; cv=none; d=google.com; s=arc-20160816; b=YMS57eXCt5EQfTbRJGfhun75D3K19A5WLBRTO4pcZibQTDTcqh3Z4KPYSb/0iySfvs W7PV6PdoY1o/7+vt5jhHcaBNcb/PLUs0SwbxONTQh3LEi5+dNL+IwgV/BoPKgfu3dRZY nA5zwSNUHc/hnvJQvgnhC8GYazYaA3ZUfvQgSA0xfc2qm4K/WRed7+rpcKHZ1mcSMVVD 4ltumoEmBkcsbR+ZUjEfpg3kwP9mQePtIjPMXWv3JSZgJfWVBkFTH/6rQNCkm8du0vvU 6nqHa3IZWe4xwXv8YmXFehppXTIvdlkpLJBtNar+5Ux/fvb1ZwMFVwIgN8Vfy57RmZKq SpXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=pPtBlvM65qHlcy4e3OzZwTrjeFPyo3wwFSC9oCHyKtU=; b=Vbgp32ITDEKzhHy88NcvMr36NMqhup5apPkT8LBPEvvzIhLt2l8Ishe8eWqQrNKIQW I4Ew2gBKqWneafTmH7wlOjBcZnMwL+LWYlQIQ7asUsCmqez1AElWaqaCOHoLF5pwTqto SB71c1qCjHgGR8hsS5MU4BdMWYimoiEDsVP6G5JRMtzh4YRl7+2APd4dyZkyChUYvgTq z6jkxXqfR3dVa7z51MioeXMw9AOxdmkb0IQ6oj4Oc8KkQTKA30Hl6+iTjOesjiQMKKtA GQfQfzHFkddfsoR5tOfbAT5zLCaTGJnV/8gBdH2Bxduoyk5pRS+3acZuedJFf/CWCKyu FAMQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t74si17435019oih.155.2020.01.20.06.53.15; Mon, 20 Jan 2020 06:53:27 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728928AbgATOwV (ORCPT + 99 others); Mon, 20 Jan 2020 09:52:21 -0500 Received: from foss.arm.com ([217.140.110.172]:33072 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726819AbgATOwV (ORCPT ); Mon, 20 Jan 2020 09:52:21 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2545930E; Mon, 20 Jan 2020 06:52:20 -0800 (PST) Received: from [10.37.12.169] (unknown [10.37.12.169]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D71C33F52E; Mon, 20 Jan 2020 06:52:09 -0800 (PST) Subject: Re: [PATCH 1/4] PM / EM: and devices to Energy Model To: Quentin Perret 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 References: <20200116152032.11301-1-lukasz.luba@arm.com> <20200116152032.11301-2-lukasz.luba@arm.com> <20200117105437.GA211774@google.com> From: Lukasz Luba Message-ID: <40587d98-0e8d-cbac-dbf5-d26501d47a8c@arm.com> Date: Mon, 20 Jan 2020 14:52:07 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200117105437.GA211774@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Quentin, On 1/17/20 10:54 AM, Quentin Perret wrote: > 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. good point, thanks > >> 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); Interesting, in the internal review Dietmar asked me to remove these two functions. I had the same idea, which would simplify a bit the registration and it does not need to check the dev->bus if it is CPU. Unfortunately, we would need also two function in drivers/opp/of.c: dev_pm_opp_of_register_cpu_em(policy->cpus); and dev_pm_opp_of_register_dev_em(dev); Thus, I have created only one registration function, which you can see in this patch set. What do you think Dietmar? > > 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 ? Yes, I think you made a good point with this OPP dependency, which we could avoid when we implement these two registration functions. > > 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. The policy mask is populated, our registration function is called at the end of the init code of CPUfreq drivers. I will check this option. > > Thanks, > Quentin > Thank you for your comments. Regards, Lukasz