Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp682614imm; Tue, 5 Jun 2018 02:42:26 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL5ijo4acMFsH5pbS2qfT9Qy3JOj2AgVuND32uYvK1xRLB32ZhZu/nBTgyw42ls4N954N8K X-Received: by 2002:a62:ecdb:: with SMTP id e88-v6mr25203374pfm.16.1528191746804; Tue, 05 Jun 2018 02:42:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528191746; cv=none; d=google.com; s=arc-20160816; b=W4rkPyYiN8lrMFqKG7aQpavgYNp5pGH+5TfDKhuJThjFWajJgVnMMhZ35j9ytl75Yy xMOnZhpq71Z+7+VTY4DnTlpxP//4wXlqvWn3Vo7yowHBZeudXdCl1zxyH6EFh3ATY/Ae YEhBxoPvRzBkK2RTdSDW0I7OUP5JJglxu22kWmYycst70/w4Rro8oys3FEz10fkNJ1gi 1drIMgukmOwFjWn4zF0/5d3AEA/VfzbwkdhZN37eILgmI6HmzToYnqXlhdP2/mg+O/lE BsP2UgUqQ9O3wNOqQRdzxGqZ0maNk0QFzv6oyZ1D1JCbOYisjNzGkjWIlnIbPu8SQPF3 LOdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type :in-reply-to:subject:cc:to:user-agent:organization:from:date :message-id:content-transfer-encoding:mime-version:dkim-signature :dkim-filter:arc-authentication-results; bh=kDDNInpDFJs0UjLC5Dm6TcukCDLZZfmaUiLHOTQqsrg=; b=bhaIzGJ+wmc8Fck+Cki04AXWRx26of5EBTzl0okBe46uPw0XkY6QLneUuA6Ka+IaZD Kx/NIOosXd+I7VCIgn6/sXcIH2bIlGEyatNVhHrRW62eZjYr4ZphMbIQjiYdc3iNuqyS 8gFMkwCRlBa3KCpr2A2z7EGdypZRh2GoakzYOFbYBjQaQjBxVukGwzlvbUauvZdrNvXF iirWAPB+pXZDS1ffLC1ctfJilpszwEqPuZ5mwTSeBmSzyp8Fk6MuZ8BvSr7rs0OK6Aoy SRBI5nylerLUpztNwxpp2/pNJ8lOZoAN8C9VZAEdRCrG/AraJ5xlQlQWhE2Y2jPYWaZl 3IpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=XaKNm7Vp; 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=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 32-v6si25162982ple.447.2018.06.05.02.42.12; Tue, 05 Jun 2018 02:42:26 -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=@samsung.com header.s=mail20170921 header.b=XaKNm7Vp; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751833AbeFEJkp (ORCPT + 99 others); Tue, 5 Jun 2018 05:40:45 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:21920 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751575AbeFEJkS (ORCPT ); Tue, 5 Jun 2018 05:40:18 -0400 Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20180605094016epoutp020f313ded3b1086ef1baf3413bd899b49~1Oi2zawkX2220422204epoutp020; Tue, 5 Jun 2018 09:40:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20180605094016epoutp020f313ded3b1086ef1baf3413bd899b49~1Oi2zawkX2220422204epoutp020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1528191616; bh=kDDNInpDFJs0UjLC5Dm6TcukCDLZZfmaUiLHOTQqsrg=; h=Date:From:To:Cc:Subject:In-reply-to:References:From; b=XaKNm7VpbMxzzyBp2+uvdo+yNWTYKLTUcJfTa8Xn1T/QcLLCmcMKCKviI2V1iNMvv RwHAz491H3Xt+dcz5Xsf5Bcqg6PIhfN86gzpFNUNfs59fxVM0iIHQ/7Eiov2HXGcgv SrG0Jhvvp7T4qy4GAccM7PW50UEByLT7f/Nr1KzE= Received: from epsmges1p2.samsung.com (unknown [182.195.40.157]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20180605094014epcas1p21db53432437ec83de5056f29b3643bb6~1Oi0s3Ks90670306703epcas1p2F; Tue, 5 Jun 2018 09:40:14 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 22.55.04068.E7A561B5; Tue, 5 Jun 2018 18:40:14 +0900 (KST) Received: from epsmgms2p1new.samsung.com (unknown [182.195.42.142]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20180605094013epcas1p16262c28c94da0db1cf8a2b452064198c~1Oi0U-Zol2944429444epcas1p1K; Tue, 5 Jun 2018 09:40:13 +0000 (GMT) X-AuditID: b6c32a36-bd1ff70000000fe4-65-5b165a7eb3d6 Received: from epmmp2 ( [203.254.227.17]) by epsmgms2p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 6F.F2.03915.D7A561B5; Tue, 5 Jun 2018 18:40:13 +0900 (KST) MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset="utf-8" Received: from [10.113.63.77] by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P9U00HY5G71Y400@mmp2.samsung.com>; Tue, 05 Jun 2018 18:40:13 +0900 (KST) Message-id: <5B165A7D.90004@samsung.com> Date: Tue, 05 Jun 2018 18:40:13 +0900 From: Chanwoo Choi Organization: Samsung Electronics User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 To: Matthias Kaehlcke Cc: MyungJoo Ham , Kyungmin Park , Arnd Bergmann , Greg Kroah-Hartman , Rob Herring , Mark Rutland , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Brian Norris , Douglas Anderson , =?UTF-8?B?w5hyamFuIEVpZGU=?= , John Einar Reitan Subject: Re: [PATCH 02/11] PM / devfreq: Fix handling of min/max_freq == 0 In-reply-to: <20180530211301.GA194977@google.com> X-Brightmail-Tracker: H4sIAAAAAAAAA01Sa0hTYRjm2zk7m+Xqa6Z+GNo6XUjD5dncOkWLoLB1AyEKc8Q66dcmujPZ mZVRYVdtbZV2oVZmVwkTk2lm0c1LGUaaRtk9wijpaiyzsqRtx6hf3/s97/O8vM/DKyeUXipG nsU7sYPncmhqGFnXFJ+UuCk9ypT040A4+7vkloz1ffksZcua26Ts3fIGit166jzF9lcEv1s+ yNj7l49SrN/TDNgzXR0S1l/dDdinm89S7LWaJpLdfrVZNnuEsfJYJTAO/CwBxiMFHaTRV7GT Ml4vrZQZd9dWAKPfF5cqS8czrZjLxA4V5jPsmVm8xUAvXGKeY9bpk5hEZjo7jVbxnA0b6LmL UhNTsnICO9OqNVxOXgBK5QSBnjprpsOe58Qqq11wGmgTw2jUTNI0tUYTeLUrZmh0AcpKbL39 is+9OGVd+aUboADUjXcBuRzBZNTaYnWBYXIlrAdoW1+DVPz0A9TlriJdICxE2t3dDsRGNUAP jnVRwYYCjkLf970gg5MIOBY1d2YHYQLGo56vJaTIfw7QwwtthMifjO48KZUE+SSciJ55I4Iw BRPQ9Z5HoZEj4Tj04Hs3CNaRMA1dKvsmC9ajA9LXA+IOBBw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l7iFGCQ5mJRFe HnexaCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8t/OORQoJpCeWpGanphakFsFkmTg4pRoYRexM lH29FSIrbcy1w6SPLCliWfU4XFqKp6/8xvL4JPd381mT3gYrf/Q34r7lzSRgorXT969g39Og xSf231NfVv5Xpe8G39PctY5p05wvLvZ9bKhy4IhmhI2PdZrZ7pK+0Cv7X666cnGDY2GdxoRi oSVP1X99qxW1vSPR6B66zvboywlujw4psRRnJBpqMRcVJwIADzs57ZoCAAA= X-CMS-MailID: 20180605094013epcas1p16262c28c94da0db1cf8a2b452064198c X-Msg-Generator: CA CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20180525203323epcas4p45ba35c38413e227f76f68fe331011b19 References: <20180525203043.249193-1-mka@chromium.org> <20180525203043.249193-3-mka@chromium.org> <5B0BA3BB.8060505@samsung.com> <20180529185758.GG168650@google.com> <5B0E5AFE.8090703@samsung.com> <20180530211301.GA194977@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2018년 05월 31일 06:13, Matthias Kaehlcke wrote: > On Wed, May 30, 2018 at 05:04:14PM +0900, Chanwoo Choi wrote: >> Hi, >> >> On 2018년 05월 30일 03:57, Matthias Kaehlcke wrote: >>> On Mon, May 28, 2018 at 03:37:47PM +0900, Chanwoo Choi wrote: >>>> Hi, >>>> >>>> On 2018년 05월 26일 05:30, Matthias Kaehlcke wrote: >>>>> Commit ab8f58ad72c4 ("PM / devfreq: Set min/max_freq when adding the >>>>> devfreq device") initializes df->min/max_freq with the min/max OPP when >>>>> the device is added. Later commit f1d981eaecf8 ("PM / devfreq: Use the >>>>> available min/max frequency") adds df->scaling_min/max_freq and the >>>>> following to the frequency adjustment code: >>>>> >>>>> max_freq = MIN(devfreq->scaling_max_freq, devfreq->max_freq); >>>>> >>>>> With the current handling of min/max_freq this is incorrect: >>>>> >>>>> Even though df->max_freq is now initialized to a value != 0 user space >>>>> can still set it to 0, in this case max_freq would be 0 instead of >>>>> df->scaling_max_freq as intended. In consequence the frequency adjustment >>>>> is not performed: >>>>> >>>>> if (max_freq && freq > max_freq) { >>>>> freq = max_freq; >>>>> >>>>> To fix this set df->min/max freq to the min/max OPP in max/max_freq_store, >>>>> when the user passes a value of 0. This also prevents df->max_freq from >>>>> being set below the min OPP when df->min_freq is 0, and similar for >>>>> min_freq. Since it is now guaranteed that df->min/max_freq can't be 0 the >>>>> checks for this case can be removed. >>>>> >>>>> Fixes: f1d981eaecf8 ("PM / devfreq: Use the available min/max frequency") >>>>> Signed-off-by: Matthias Kaehlcke >>>>> --- >>>>> drivers/devfreq/devfreq.c | 30 ++++++++++++++++++------------ >>>>> 1 file changed, 18 insertions(+), 12 deletions(-) >>>>> >>>>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c >>>>> index 0057ef5b0a98..67da4e7b486b 100644 >>>>> --- a/drivers/devfreq/devfreq.c >>>>> +++ b/drivers/devfreq/devfreq.c >>>>> @@ -283,11 +283,11 @@ int update_devfreq(struct devfreq *devfreq) >>>>> max_freq = MIN(devfreq->scaling_max_freq, devfreq->max_freq); >>>>> min_freq = MAX(devfreq->scaling_min_freq, devfreq->min_freq); >>>>> >>>>> - if (min_freq && freq < min_freq) { >>>>> + if (freq < min_freq) { >>>>> freq = min_freq; >>>>> flags &= ~DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use GLB */ >>>>> } >>>>> - if (max_freq && freq > max_freq) { >>>>> + if (freq > max_freq) { >>>>> freq = max_freq; >>>>> flags |= DEVFREQ_FLAG_LEAST_UPPER_BOUND; /* Use LUB */ >>>>> } >>>>> @@ -1123,17 +1123,20 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr, >>>>> struct devfreq *df = to_devfreq(dev); >>>>> unsigned long value; >>>>> int ret; >>>>> - unsigned long max; >>>>> >>>>> ret = sscanf(buf, "%lu", &value); >>>>> if (ret != 1) >>>>> return -EINVAL; >>>>> >>>>> mutex_lock(&df->lock); >>>>> - max = df->max_freq; >>>>> - if (value && max && value > max) { >>>>> - ret = -EINVAL; >>>>> - goto unlock; >>>>> + >>>>> + if (value) { >>>>> + if (value > df->max_freq) { >>>>> + ret = -EINVAL; >>>>> + goto unlock; >>>>> + } >>>>> + } else { >>>>> + value = df->profile->freq_table[df->profile->max_state - 1]; >>>>> } >>>> >>>> If you want to prevent that df->min_freq is zero, >>>> you should reinitialize 'value' as following. >>>> Because freq_table must be in ascending order. >>>> value = df->profile->freq_table[0]; >>> >>> Thanks for pointing this out! >>> >>> The devfreq device I tested with (a Mali GPU) uses descending order >>> for some reason, and I assumed that's the usual order. >>> >>> https://chromium.googlesource.com/chromiumos/third_party/kernel/+/chromeos-4.4/drivers/gpu/arm/midgard/backend/gpu/mali_kbase_devfreq.c#208 >>> >>> It seems the ordering doesn't have any impact beyond this patch. If >>> the order isn't mandatory for drivers that set up their own freq_table >>> we should probably support both cases to be safe. >> >> Prior to that 'freq_table' is optional. So, patch[1] initialize the 'freq_table' >> by using OPP interface if 'freq_table' is NULL. >> [1] commit 0ec09ac2cebe ("PM / devfreq: Set the freq_table of devfreq device") >> >> Current devfreq recommend the ascending order for 'freq_table'. >> But, as you know, it might be not enough to support them. >> >> I agree that we should support the both cases (ascending or descending order). >> >> Maybe, it might be not proper to access the freq_table[] directly >> because we don't know the ordering style of 'freq_table' >> if 'freq_table' is made by devfreq user instead of devfreq core. > > If we can assume that it is either ascending or descending, but not > random order than a simple check if freq_table[0] < > freq_table[max_state - 1] would be sufficient. Also, we should consider the order way of freq_table on available_frequency because available_frequency have to show the frequency as the ascending order even if freq_table uses the descending order. > > Otherwise we could also determine the min/max after initialization and > save the result, though that would leave us with yet another frequency > pair, which might be confusing, especially if we don't come up with > good names to distinguish between them. IMO, it might make the confusion if devfreq device has the two frequency table. -- Best Regards, Chanwoo Choi Samsung Electronics