Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5570214ybl; Tue, 14 Jan 2020 11:08:55 -0800 (PST) X-Google-Smtp-Source: APXvYqw3ZG4tBdlaFUyBVguUkYB98q6ct0nGIUEZCHtu8nP+G45VcJYun8HWa1yNgY+ov4C2ot/I X-Received: by 2002:aca:ab0e:: with SMTP id u14mr18550975oie.1.1579028935622; Tue, 14 Jan 2020 11:08:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579028935; cv=none; d=google.com; s=arc-20160816; b=WzY3mc7bJALEW1ahtaoMD/1NBso5A6X5jum4JmYZJ3vPq75l58cj0EBykgW00pmyNh nXv1G8iTIHolea/6Lq/TT9LnqQlVK3xtVNb2ANZ577UdpVjCkMyP2Ith8RJc+r955kqD Z6KonBpTeMo9VqXbiPzPz8Rw1/0Gt8uU1MgoJzRidsqGKi0+3TxB5cmeM2qIYtxfzPIT MPqRRcOEKAQZLwsxYROHpcHVv10pqdaBn6a2+QBWfR+SsEXXVMUdAv4OJ7yxMc6S9Pch tl5oqaWRkEYq/wrCNJSIfNe3kRJ3zEXTG/xuU1Ps2FpAaep9AikfK6XdSEFr9B3CR/CQ rzxg== 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=aLELjPYcaLo58QAAHC+0RioxZHEHGruSV5XSCPDClP4=; b=ldWizOhlFpMitu8lZ2xXklsE34iw6TQCcaS9k/6Ks/d8VdUWA8CsYPxq4nwpVhtjiy ZDOQI4KsLhhSCmxTVZHUC/NxpMP+GVJxntmyBB+2EK2poWJNjEAJhDXW+Ry3PNQU5xdj adgFsaGhLVvwDgkek8wi/GstE5BCRp8XG81ntnKjVfzBXPOpicjeZ9/zZlT9FzffZs5o LKuOXyx+5z5al4AGRT/pS8Jen8ThYIABzwJD5raSzjRUZ/QiaNvCre+7VcXGuZgCO/Pz 0SCyfHKb9R6+GbSwVw8YAAjllnjp053EOJi4yeDMUeD0F9tYd8rYZ/CKmsaZFetfSouv sxFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DOjVACsA; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m24si8746090otn.67.2020.01.14.11.08.43; Tue, 14 Jan 2020 11:08:55 -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=@chromium.org header.s=google header.b=DOjVACsA; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728810AbgANTHq (ORCPT + 99 others); Tue, 14 Jan 2020 14:07:46 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:33384 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727092AbgANTHp (ORCPT ); Tue, 14 Jan 2020 14:07:45 -0500 Received: by mail-pg1-f193.google.com with SMTP id 6so6839455pgk.0 for ; Tue, 14 Jan 2020 11:07:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=aLELjPYcaLo58QAAHC+0RioxZHEHGruSV5XSCPDClP4=; b=DOjVACsA2rRiS1aDwEMcceeN2dNSvb9rjohA9MxOUbTcAVYrKBgIYw+en0ypMeJgnT CBeuzWi6XwUAA8SCJ0srksS+ZIfko3Cg4FD3RAyIta3Ei/gX3GbOiHX89gtoRLGTsh75 SQdMdYm2M09apsaZDDNHhsq4sRgp4Y61i9rIE= 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=aLELjPYcaLo58QAAHC+0RioxZHEHGruSV5XSCPDClP4=; b=MeGvbt8KNhMvpJpbGlRotAVK3ZNZAQBYwjXwQHEPsVMKYDII2SBvoX1XYjpgMVaSPl lkEY+Sn/2rTMsxSMacgCrliFXGVZ4gk899x9eB7hBrpubu/2JKllmJC8L5qzWUzyZBlE hy/YDpfn2TYdtm3ZmfVOJ9D4rQJDsYHFE5KaAKKFz7AX/gC8thINXt7Vs0GXUpb+E7M0 MG0TZDBOzYWlIKAWXDHy0gpLXNR5RS1yq38keLGn9c/icrhN6wywxCrgEqqsq6hiJwAy g6E/tW6ii1aPiGnqKPa0ZnFA08RqPAkme2gLBVMFHNav+NRp+dnfqOFjtmU3RNc+t/2L ceuw== X-Gm-Message-State: APjAAAVBHBiZKYg87qZ2lBQ8O8THcgsj/ftC3ne+OhofD5/Kj70DKGOj M2nT1YNQtXawpbarv0UilYxjFQ== X-Received: by 2002:a63:dc41:: with SMTP id f1mr29452244pgj.119.1579028864875; Tue, 14 Jan 2020 11:07:44 -0800 (PST) Received: from localhost ([2620:15c:202:1:4fff:7a6b:a335:8fde]) by smtp.gmail.com with ESMTPSA id s21sm18963322pfe.20.2020.01.14.11.07.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jan 2020 11:07:44 -0800 (PST) Date: Tue, 14 Jan 2020 11:07:43 -0800 From: Matthias Kaehlcke To: Leonard Crestez Cc: Chanwoo Choi , MyungJoo Ham , Kyungmin Park , Zhang Rui , Daniel Lezcano , Amit Kucheria , "linux-kernel@vger.kernel.org" , "linux-pm@vger.kernel.org" , Viresh Kumar , "Rafael J. Wysocki" Subject: Re: [PATCH 1/2] thermal: devfreq_cooling: Use PM QoS to set frequency limits Message-ID: <20200114190743.GK89495@google.com> References: <20200110094913.1.I146403d05b9ec82f48b807efd416a57f545b447a@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: 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 On Tue, Jan 14, 2020 at 04:08:38PM +0000, Leonard Crestez wrote: > On 10.01.2020 19:49, Matthias Kaehlcke wrote: > > Now that devfreq supports limiting the frequency range of a device > > through PM QoS make use of it instead of disabling OPPs that should > > not be used. > > > > Signed-off-by: Matthias Kaehlcke > > --- > > It is not obvious but this changes behavior when min max requests > conflict (min > max): with PM QoS a MIN_FREQUENCY request takes > precedence but if higher OPPs are disabled then this will override > MIN_FREQUENCY. Thanks for pointing this out. > There are very few users of this functionality so I don't think there > are any systems that depend on this behaving one way or the other but > perhaps it should be mentioned in commit message? Sounds good, I'll add a note. > As far as I can tell the only user of devfreq_cooling in upstream is > drivers/gpu/drm/panfrost? Indeed, apparently GPUs are the primary devfreq device used for cooling, and unfortunately most GPU drivers are not in upstream. > > drivers/thermal/devfreq_cooling.c | 66 ++++++++++--------------------- > > 1 file changed, 20 insertions(+), 46 deletions(-) > > > > diff --git a/drivers/thermal/devfreq_cooling.c b/drivers/thermal/devfreq_cooling.c > > index ef59256887ff..3a63603afcf2 100644 > > --- a/drivers/thermal/devfreq_cooling.c > > +++ b/drivers/thermal/devfreq_cooling.c > > @@ -24,11 +24,13 @@ > > #include > > #include > > #include > > +#include > > #include > > > > #include > > > > -#define SCALE_ERROR_MITIGATION 100 > > +#define HZ_PER_KHZ 1000 > > +#define SCALE_ERROR_MITIGATION 100 > > > > static DEFINE_IDA(devfreq_ida); > > > > @@ -65,49 +67,9 @@ struct devfreq_cooling_device { > > struct devfreq_cooling_power *power_ops; > > u32 res_util; > > int capped_state; > > + struct dev_pm_qos_request req_max_freq; > > }; > > > > -/** > > - * partition_enable_opps() - disable all opps above a given state > > - * @dfc: Pointer to devfreq we are operating on > > - * @cdev_state: cooling device state we're setting > > - * > > - * Go through the OPPs of the device, enabling all OPPs until > > - * @cdev_state and disabling those frequencies above it. > > - */ > > -static int partition_enable_opps(struct devfreq_cooling_device *dfc, > > - unsigned long cdev_state) > > -{ > > - int i; > > - struct device *dev = dfc->devfreq->dev.parent; > > - > > - for (i = 0; i < dfc->freq_table_size; i++) { > > - struct dev_pm_opp *opp; > > - int ret = 0; > > - unsigned int freq = dfc->freq_table[i]; > > - bool want_enable = i >= cdev_state ? true : false; > > - > > - opp = dev_pm_opp_find_freq_exact(dev, freq, !want_enable); > > - > > - if (PTR_ERR(opp) == -ERANGE) > > - continue; > > - else if (IS_ERR(opp)) > > - return PTR_ERR(opp); > > - > > - dev_pm_opp_put(opp); > > - > > - if (want_enable) > > - ret = dev_pm_opp_enable(dev, freq); > > - else > > - ret = dev_pm_opp_disable(dev, freq); > > - > > - if (ret) > > - return ret; > > - } > > - > > - return 0; > > -} > > - > > static int devfreq_cooling_get_max_state(struct thermal_cooling_device *cdev, > > unsigned long *state) > > { > > @@ -134,7 +96,7 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev, > > struct devfreq_cooling_device *dfc = cdev->devdata; > > struct devfreq *df = dfc->devfreq; > > struct device *dev = df->dev.parent; > > - int ret; > > + unsigned long freq; > > > > if (state == dfc->cooling_state) > > return 0; > > @@ -144,9 +106,10 @@ static int devfreq_cooling_set_cur_state(struct thermal_cooling_device *cdev, > > if (state >= dfc->freq_table_size) > > return -EINVAL; > > > > - ret = partition_enable_opps(dfc, state); > > - if (ret) > > - return ret; > > + freq = dfc->freq_table[state]; > > + > > + dev_pm_qos_update_request(&dfc->req_max_freq, > > + DIV_ROUND_UP(freq, HZ_PER_KHZ)); > > > > dfc->cooling_state = state; > > > > @@ -529,6 +492,12 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, > > if (err) > > goto free_dfc; > > > > + err = dev_pm_qos_add_request(df->dev.parent, &dfc->req_max_freq, > > + DEV_PM_QOS_MAX_FREQUENCY, > > + PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE); > > + if (err < 0) > > + goto remove_qos_req; > > + > > err = ida_simple_get(&devfreq_ida, 0, 0, GFP_KERNEL); > > if (err < 0) > > goto free_tables; > > @@ -552,6 +521,10 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df, > > > > release_ida: > > ida_simple_remove(&devfreq_ida, dfc->id); > > + > > +remove_qos_req: > > + dev_pm_qos_remove_request(&dfc->req_max_freq); > + > > A quirk of the dev_pm_qos API is that dev_pm_qos_remove_request prints a > WARN splat if !dev_pm_qos_request_active and this can true on > dev_pm_qos_add_request error. > > I dealt with this by checking dev_pm_qos_request_active explicitly but > perhaps dev_pm_qos API could be changed? In general "free/release" > functions shouldn't complain if there's nothing to do. I think we should be good here if we jump to 'free_tables' if _add_request() fails, as requested by Chanwoo. Then _remove_request() is only called when _add_request() was successful. > > free_tables: > > kfree(dfc->power_table); > > kfree(dfc->freq_table); > > @@ -600,6 +573,7 @@ void devfreq_cooling_unregister(struct thermal_cooling_device *cdev) > > > > thermal_cooling_device_unregister(dfc->cdev); > > ida_simple_remove(&devfreq_ida, dfc->id); > > + dev_pm_qos_remove_request(&dfc->req_max_freq); > > kfree(dfc->power_table); > > kfree(dfc->freq_table);