From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CFDCC33CB3 for ; Tue, 14 Jan 2020 18:51:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6C9524670 for ; Tue, 14 Jan 2020 18:51:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Ow6Bjq+P" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728769AbgANSvG (ORCPT ); Tue, 14 Jan 2020 13:51:06 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:36415 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726450AbgANSvF (ORCPT ); Tue, 14 Jan 2020 13:51:05 -0500 Received: by mail-pj1-f68.google.com with SMTP id n59so6288731pjb.1 for ; Tue, 14 Jan 2020 10:51:05 -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=8RHb25MFJpPZhJdjI8xQKql5/uxFuwEOzuS1j12SrJk=; b=Ow6Bjq+PMUgyYD4Z7oS58hmebH/2FCuoQLR5BmldOvhqhhrktMYHsU7MqISY/Qc4mR ksHt82V82HrQHDybguDhh42mdUaf5i9sfnxS+IGXGYaPLFU4CxrQ68v65EapYscHtN2L T4xvsI4/pL2FSbDcYfrS9dURi2fnRLTNNwjbk= 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=8RHb25MFJpPZhJdjI8xQKql5/uxFuwEOzuS1j12SrJk=; b=s/Cf7RXUbRHzB6TZW0LcjgnJmB0cs3VSt5dgTi4F6TDnUFnwJ0uZEknXDqN2/gYP/I MtgseKeq7LtD28g5gNIAX7tWk7YSgQKdBr76Pw653Hc46HV6jfrCWoDA0gQ7eJeSn2Mj JyMEnnwUZz+utmCEL/Qtz0s+/wTCxR+i3ENroQuzqWo8wZ+5EsnCg8+Fu2vOUOKECceP MRPCvyv97WIqEad/WD2Asop3F/jFYG9ghnvUczf+fvXgdDPQYt3lWdCzcUQD3i5T7PyU 1N+Xd8XwC4zJwb1ceCQa8658fGgtXZ0cjmUpYs2zBQ44CotEZLl7SsQU63XSOjL2Kgt8 lChg== X-Gm-Message-State: APjAAAUDRSzKXGOTgdecbhCmThLLrExQAgcwZXQ7or32buAcsApr+1RM s3Jd6y5LceEBxBomV+6uYbu/vK7h4J0= X-Google-Smtp-Source: APXvYqwyGpqR1K6wjcjKgJO0oKzp9z8mLoiE+SZlVD3ctdnXJ8HANMRK5I9mc5T6ayqXehxYp1DYKw== X-Received: by 2002:a17:90a:7781:: with SMTP id v1mr15038696pjk.108.1579027864707; Tue, 14 Jan 2020 10:51:04 -0800 (PST) Received: from localhost ([2620:15c:202:1:4fff:7a6b:a335:8fde]) by smtp.gmail.com with ESMTPSA id b185sm19678208pfa.102.2020.01.14.10.51.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jan 2020 10:51:04 -0800 (PST) Date: Tue, 14 Jan 2020 10:51:02 -0800 From: Matthias Kaehlcke To: Chanwoo Choi Cc: MyungJoo Ham , Kyungmin Park , Zhang Rui , Daniel Lezcano , Amit Kucheria , Leonard Crestez , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: Re: [PATCH 1/2] thermal: devfreq_cooling: Use PM QoS to set frequency limits Message-ID: <20200114185102.GJ89495@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 Mon, Jan 13, 2020 at 04:25:17PM +0900, Chanwoo Choi wrote: > Hi, > > On 1/11/20 2:49 AM, 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 > > --- > > > > 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; > > Need to add the description of 'req_max_freq'. will add the description > > }; > > > > -/** > > - * 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; > > Jump 'free_table' instead of 'remove_qos_req'. ack > > + > > err = ida_simple_get(&devfreq_ida, 0, 0, GFP_KERNEL); > > if (err < 0) > > goto free_tables; > > Jump remove_qos_req. ack > > @@ -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); > > + > > 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);