Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8046722imu; Tue, 4 Dec 2018 01:54:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/VGds4ZTJ0J8bzTL7tX6HweAYd4Ht8amOo9rVovQrv483DlymxOE75Sh1Bj5Ype8dgNpY7x X-Received: by 2002:a63:4b25:: with SMTP id y37mr16744854pga.181.1543917279353; Tue, 04 Dec 2018 01:54:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543917279; cv=none; d=google.com; s=arc-20160816; b=f7qbzP03G1qKbbnfv6ydJ90r2mjcH4p8wUWKRRzrzH+9vvEW8N6NB8S4dHjps1qOQo RUULT0wJVuU19GVwAH62v1Bq8Z1jwCWtNJf/SWCY/Gd4wVRqLNRfsW9YGzfNb0pP67Jb 0e0iusibcu4WPTS0lgK8M8nHd73Z2IG4GaBc0sOdju1HM4d/5GKPRgyogZhhdWJBZNP9 pkQGxUJIkMnKm0R6TDQEKgbAoqorAMqkWXUsEvYCT/XM7c9GT8L9CfEddv1B47qQDer9 tpZeTmwmrPsGO6FpAuUZXNhe9DWy+RfeJZHCN71lK08L43H3NfsWl48aWEDx0OJy5j0v J5GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type :content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:cc:to:subject:dkim-signature :dkim-filter; bh=X11KD8/OnWuY3VZejmzvr+fMzr/vWkgerT/hAHvNABw=; b=GX2oaTk/jpGXHb7RLpVuqm63bwRqBxBVv9/2BwLzIsjsgt7n5o9BHBEHBDll5PjCWH EY3MwKNQmM61S4bNxHJh8WpvIAPS5bINN3oQDB8K97fao4nMeGEVOsQpto7eXJFeL1Ls icITWzav7kmtQFXyHEmUUbb0cl5ekM/fNaLzO/lEZGGCHBQQHY506Lk1xFUI5XdS9PNx n/TN89oajk2qipCTxXYC1vPhqdCyzOIbzo9Is87o80oR2jmT+WpEFCd/CA/BwyxpQFJc gN4e4iRYUKOyOt+B75qIbkBWeXqm9iqclkkvAd7LlPiDyiem6dzqNc4kQRO2XpVklagr 1OWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=F2aR87bY; 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 bf4si15880761plb.163.2018.12.04.01.54.24; Tue, 04 Dec 2018 01:54:39 -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=@samsung.com header.s=mail20170921 header.b=F2aR87bY; 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 S1726142AbeLDJxc (ORCPT + 99 others); Tue, 4 Dec 2018 04:53:32 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:39906 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725767AbeLDJxb (ORCPT ); Tue, 4 Dec 2018 04:53:31 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20181204095329euoutp01abe2a665752bc129bc0c86e6eb86f7df~tGIWenLhd2886828868euoutp01d for ; Tue, 4 Dec 2018 09:53:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20181204095329euoutp01abe2a665752bc129bc0c86e6eb86f7df~tGIWenLhd2886828868euoutp01d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1543917209; bh=X11KD8/OnWuY3VZejmzvr+fMzr/vWkgerT/hAHvNABw=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=F2aR87bYpgIqDcs5+cDUiMHybE987tRyM6wbNh6nHnIw/WoSzJwttr0wQzaoj3CIR j7+O/MSa8LzfomFyVigI5rlrdB5CqXcsnfsYhTTFhvNI1M4YRCYTzuiVb7KB+UVv0F 11neoeepScZ3rnznYp0xtotnB11T/knm0hbS3mls= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20181204095328eucas1p151fbacdbf340b22cb385b040b95167e4~tGIVgARhs0348503485eucas1p1a; Tue, 4 Dec 2018 09:53:28 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 97.32.04294.89E460C5; Tue, 4 Dec 2018 09:53:28 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20181204095327eucas1p2d50b5ff6000b959fbd6929ed26369292~tGIUxV0E92231822318eucas1p2F; Tue, 4 Dec 2018 09:53:27 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20181204095327eusmtrp1ea6b7ce8ef01de4e8eeecd1bc6ada374~tGIUhpg5f1349913499eusmtrp1g; Tue, 4 Dec 2018 09:53:27 +0000 (GMT) X-AuditID: cbfec7f4-84fff700000010c6-d6-5c064e98d9c7 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 2B.53.04128.79E460C5; Tue, 4 Dec 2018 09:53:27 +0000 (GMT) Received: from [106.120.51.20] (unknown [106.120.51.20]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20181204095326eusmtip239a607085920ad679072e052515b4644~tGITn1MwD2938229382eusmtip2a; Tue, 4 Dec 2018 09:53:26 +0000 (GMT) Subject: Re: [PATCH v2 2/5] devfreq: add support for suspend/resume of a devfreq device To: Chanwoo Choi , linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org Cc: tjakobi@math.uni-bielefeld.de, myungjoo.ham@samsung.com, kyungmin.park@samsung.com, rjw@rjwysocki.net, len.brown@intel.com, pavel@ucw.cz, gregkh@linuxfoundation.org, keescook@chromium.org, anton@enomsg.org, ccross@android.com, tony.luck@intel.com, robh+dt@kernel.org, mark.rutland@arm.com, kgene@kernel.org, krzk@kernel.org, m.szyprowski@samsung.com, b.zolnierkie@samsung.com From: Lukasz Luba Message-ID: <7662d626-5c3e-aec5-05e4-c6cd2e56ef49@partner.samsung.com> Date: Tue, 4 Dec 2018 10:53:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <5C061A57.7040002@samsung.com> Content-Language: en-US Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA01Sa2yLYRj1fveN8iqzJ+aS1AjDXCNvQsRE5IuE+GcYU/YZsXb02zAkakZr bBMTqi4bI53uUpuulrLNahSd3dwvYzOXMENscYss1n4T+3fO85zznvMkr0Crz3DDhY36JMmg 1yZouGDGdetX3WTLEi5mamUmR6rLJpASi4MlV0q+s+Rx13uW5NTUsWRvnoMjtQd1JKutnSb1 9Zd4ci/1E0+sRysoUtr2iCX33ac40plRg4ilvpIiRTXNPLnwuJEiz/fkc6T57s0ev6+JJfsq aniyv+ArSz41vGTmhYquqy5WLDxTiMSTxkZGPJz1DYl51z5QYqn9ACdWnS7kxcvnd4vdt3jR +dDEiJlOOxLzC37wYmfp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tDDSM7S00DMysdQzNDaPtTIyVdK3 s0lJzcksSy3St0vQy7jXsYCp4LZJRfda6QbGA1pdjJwcEgImEq+/3GDuYuTiEBJYyijRN38e C0RCTGLSvu3sELawxJ9rXWwQRa8ZJbrnzmcESQgLREqcWvwUrFtE4DSjxJTzp5hAHGaBVmaJ l28XMUK07GOSuLLyMVCGg4NNQE9ix6pCkG5eATeJc71vwSaxCKhInOh9zApiiwpESJx9uY4R okZQ4uTMJ2AncQpoS1xecIsJxGYWMJOYt/khM4QtLnHryXyouLxE89bZzBMYhWYhaZ+FpGUW kpZZSFoWMLKsYhRJLS3OTc8tNtIrTswtLs1L10vOz93ECEwv24793LKDsetd8CFGAQ5GJR7e GU6sMUKsiWXFlbmHGCU4mJVEeO+oscUI8aYkVlalFuXHF5XmpBYfYjQFem4is5Rocj4w9eWV xBuaGppbWBqaG5sbm1koifOeN6iMEhJITyxJzU5NLUgtgulj4uCUamDs3stlJXP4z/nL3yt3 zov9fX+/Y0Tdlgj9SB/lh1sNZ3s+mJZzRO2R2OFZ01bdEr2UmXvvoRrHo15btYApqnFBpRrX ZtaXpUkanYzUVFnKt1z3t0yi8+s/6xx60pyqCjVeLClxWaG5KsbhscBiDuNgH8/Q1t3qv0oi m0uUmf/PaMpLfXmmL1eJpTgj0VCLuag4EQAnXwwhRQMAAA== X-CMS-MailID: 20181204095327eucas1p2d50b5ff6000b959fbd6929ed26369292 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20181203143131eucas1p217f22ac6d19682a54a57658a06980914 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20181203143131eucas1p217f22ac6d19682a54a57658a06980914 References: <1543847475-7600-1-git-send-email-l.luba@partner.samsung.com> <1543847475-7600-3-git-send-email-l.luba@partner.samsung.com> <5C06124B.5030409@samsung.com> <5C06140E.7010603@samsung.com> <5C061A57.7040002@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Chanwoo, On 12/4/18 7:10 AM, Chanwoo Choi wrote: > Hi Lukasz, > > I add the comment about 'suspend_count'. > > On 2018년 12월 04일 14:43, Chanwoo Choi wrote: >> Hi, >> >> On 2018년 12월 04일 14:36, Chanwoo Choi wrote: >>> Hi Lukasz, >>> >>> Looks good to me. But, I add the some comments. >>> If you will fix it, feel free to add my tag: >>> Reviewed-by: Chanwoo choi >> >> Sorry. Fix typo 'choi' to 'Choi' as following. >> Reviewed-by: Chanwoo Choi >> >>> >>> On 2018년 12월 03일 23:31, Lukasz Luba wrote: >>>> The patch prepares devfreq device for handling suspend/resume >>>> functionality. The new fields will store needed information during this >>> >>> nitpick. Remove unneeded space. There are two spaces between '.' and 'The new'. >>> >>>> process. Devfreq framework handles opp-suspend DT entry and there is no >>> >>> ditto. >>> >>>> need of modyfications in the drivers code. It uses atomic variables to >>> >>> ditto. >>> >>>> make sure no race condition affects the process. >>>> >>>> The patch is based on earlier work by Tobias Jakobi. >>> >>> Please remove it from each patch description. >>> >>>> >>>> Suggested-by: Tobias Jakobi >>>> Suggested-by: Chanwoo Choi >>>> Signed-off-by: Lukasz Luba >>>> --- >>>> drivers/devfreq/devfreq.c | 51 +++++++++++++++++++++++++++++++++++++++-------- >>>> include/linux/devfreq.h | 7 +++++++ >>>> 2 files changed, 50 insertions(+), 8 deletions(-) >>>> >>>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c >>>> index a9fd61b..36bed24 100644 >>>> --- a/drivers/devfreq/devfreq.c >>>> +++ b/drivers/devfreq/devfreq.c >>>> @@ -316,6 +316,10 @@ static int devfreq_set_target(struct devfreq *devfreq, unsigned long new_freq, >>>> "Couldn't update frequency transition information.\n"); >>>> >>>> devfreq->previous_freq = new_freq; >>>> + >>>> + if (devfreq->suspend_freq) >>>> + devfreq->resume_freq = cur_freq; >>>> + >>>> return err; >>>> } >>>> >>>> @@ -667,6 +671,9 @@ struct devfreq *devfreq_add_device(struct device *dev, >>>> } >>>> devfreq->max_freq = devfreq->scaling_max_freq; >>>> >>>> + devfreq->suspend_freq = dev_pm_opp_get_suspend_opp_freq(dev); >>>> + atomic_set(&devfreq->suspend_count, 0); >>>> + >>>> dev_set_name(&devfreq->dev, "devfreq%d", >>>> atomic_inc_return(&devfreq_no)); >>>> err = device_register(&devfreq->dev); >>>> @@ -867,14 +874,28 @@ EXPORT_SYMBOL(devm_devfreq_remove_device); >>>> */ >>>> int devfreq_suspend_device(struct devfreq *devfreq) >>>> { >>>> + int ret; >>>> + >>>> if (!devfreq) >>>> return -EINVAL; >>>> >>>> - if (!devfreq->governor) >>>> - return 0; >>>> + if (devfreq->governor) { >>>> + ret = devfreq->governor->event_handler(devfreq, >>>> + DEVFREQ_GOV_SUSPEND, NULL); >>>> + if (ret) >>>> + return ret; >>>> + } >>>> + >>>> + if (devfreq->suspend_freq) { >>>> + if (atomic_inc_return(&devfreq->suspend_count) > 1) >>>> + return 0; >>>> + >>>> + ret = devfreq_set_target(devfreq, devfreq->suspend_freq, 0); >>>> + if (ret) >>>> + return ret; >>>> + } > > In this patch, if some users call 'devfreq_suspend_device' twice, > 'devfreq->governor->event_handler(devfreq, DEVFREQ_GOV_SUSPEND, NULL)' > is called twice but devfreq_set_target() is called only one. > I knew that it is no problem for operation. > > But, > I think that you better to use 'suspend_count' as the reference count > of devfreq_suspend/resume_device(). But, if you use 'suspend_count' > in order to check whether this devfreq is suspended or not, > we can reduce the unneeded redundant call when calling it twice. > > clock and regulator used the 'reference count' method in order to > remove the redundant call. I think I've got the point. I will move the atomic check just after the !devfreq check. Something like the code bellow is what you would like to see? ---8<----- if (!devfreq) return -EINVAL; if (atomic_inc_return(&devfreq->suspend_count) > 1) return0; ---->8------- > > >>>> >>>> - return devfreq->governor->event_handler(devfreq, >>>> - DEVFREQ_GOV_SUSPEND, NULL); >>>> + return 0; >>>> } >>>> EXPORT_SYMBOL(devfreq_suspend_device); >>>> >>>> @@ -888,14 +909,28 @@ EXPORT_SYMBOL(devfreq_suspend_device); >>>> */ >>>> int devfreq_resume_device(struct devfreq *devfreq) >>>> { >>>> + int ret; >>>> + >>>> if (!devfreq) >>>> return -EINVAL; >>>> >>>> - if (!devfreq->governor) >>>> - return 0; >>>> + if (devfreq->resume_freq) { >>>> + if (atomic_dec_return(&devfreq->suspend_count) >= 1) >>>> + return 0; > > ditto. Same approach here: ---8<----- if (!devfreq) return -EINVAL; if (atomic_dec_return(&devfreq->suspend_count) >= 1) return 0; ---->8------- Regards, Lukasz > >>>> >>>> - return devfreq->governor->event_handler(devfreq, >>>> - DEVFREQ_GOV_RESUME, NULL); >>>> + ret = devfreq_set_target(devfreq, devfreq->resume_freq, 0); >>>> + if (ret) >>>> + return ret; >>>> + } >>>> + >>>> + if (devfreq->governor) { >>>> + ret = devfreq->governor->event_handler(devfreq, >>>> + DEVFREQ_GOV_RESUME, NULL); >>>> + if (ret) >>>> + return ret; >>>> + } >>>> + >>>> + return 0; >>>> } >>>> EXPORT_SYMBOL(devfreq_resume_device); >>>> >>>> diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h >>>> index e4963b0..d985199 100644 >>>> --- a/include/linux/devfreq.h >>>> +++ b/include/linux/devfreq.h >>>> @@ -131,6 +131,9 @@ struct devfreq_dev_profile { >>>> * @scaling_min_freq: Limit minimum frequency requested by OPP interface >>>> * @scaling_max_freq: Limit maximum frequency requested by OPP interface >>>> * @stop_polling: devfreq polling status of a device. >>>> + * @suspend_freq: frequency of a device set during suspend phase. >>>> + * @resume_freq: frequency of a device set in resume phase. >>>> + * @suspend_count: suspend requests counter for a device. >>>> * @total_trans: Number of devfreq transitions >>>> * @trans_table: Statistics of devfreq transitions >>>> * @time_in_state: Statistics of devfreq states >>>> @@ -167,6 +170,10 @@ struct devfreq { >>>> unsigned long scaling_max_freq; >>>> bool stop_polling; >>>> >>>> + unsigned long suspend_freq; >>>> + unsigned long resume_freq; >>>> + atomic_t suspend_count; >>>> + >>>> /* information for device frequency transition */ >>>> unsigned int total_trans; >>>> unsigned int *trans_table; >>>> >>> >>> >> >> > >