From patchwork Wed Nov 13 09:13:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Konieczny X-Patchwork-Id: 11241425 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 57EBF15AB for ; Wed, 13 Nov 2019 09:13:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 04BCD2245C for ; Wed, 13 Nov 2019 09:13:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="s8lVm24k" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727133AbfKMJNx (ORCPT ); Wed, 13 Nov 2019 04:13:53 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:34895 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726165AbfKMJNx (ORCPT ); Wed, 13 Nov 2019 04:13:53 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20191113091352euoutp0165fe7a33e2296be657659647fe69be4c~Wrf9Z225x1861418614euoutp01h for ; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20191113091352euoutp0165fe7a33e2296be657659647fe69be4c~Wrf9Z225x1861418614euoutp01h DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1573636432; bh=psmbkYgjxBJEqnX794aWZ+U0IHZUM+JDqPP7km6ZABk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s8lVm24kE5ETmMHYf3NtCQcgrNJstmgmLLytg09CrMfTyfQDkUh7uSxZta03LDESJ vPD88peo+XU3UvSO6ZtXujcmElDVsxZOnlKDPXGl4Ps1E5o1Zhy3frthXw8SX/aT5I kKpzJpUV/IbXAaXBq3q6JbQeBEGqHYcBcvDd8zmo= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20191113091351eucas1p2d7af01ab946580e5f8000d6757e82833~Wrf9HXl8V1779617796eucas1p2s; Wed, 13 Nov 2019 09:13:51 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 7D.24.04309.F49CBCD5; Wed, 13 Nov 2019 09:13:51 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20191113091351eucas1p24afdb94f868b6a7a52b43e81462bb674~Wrf81ft_p2899928999eucas1p2G; Wed, 13 Nov 2019 09:13:51 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20191113091351eusmtrp1021c6dcdbffd05353b2adb24f08b9622~Wrf807xvn0965609656eusmtrp1j; Wed, 13 Nov 2019 09:13:51 +0000 (GMT) X-AuditID: cbfec7f4-afbff700000010d5-03-5dcbc94f530c Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id E7.DA.04117.F49CBCD5; Wed, 13 Nov 2019 09:13:51 +0000 (GMT) Received: from AMDC3218.digital.local (unknown [106.120.51.18]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20191113091350eusmtip1b579afc177f22b4f615f4525f15851b9~Wrf8Wo5P30379503795eusmtip1P; Wed, 13 Nov 2019 09:13:50 +0000 (GMT) From: Kamil Konieczny To: k.konieczny@samsung.com Cc: Bartlomiej Zolnierkiewicz , Chanwoo Choi , Kamil Konieczny , Krzysztof Kozlowski , Kyungmin Park , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Marek Szyprowski , MyungJoo Ham Subject: [PATCH 1/7] devfreq: change time stats to 64-bit Date: Wed, 13 Nov 2019 10:13:30 +0100 Message-Id: <20191113091336.5218-2-k.konieczny@samsung.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191113091336.5218-1-k.konieczny@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBKsWRmVeSWpSXmKPExsWy7djPc7r+J0/HGhxeoG2xccZ6VovrX56z WvTt+89oseDTDFaL8+c3sFucbXrDbnF51xw2i8+9Rxgt1h65y25xu3EFmwOXx6ZVnWweB9/t YfLo27KK0ePzJrkAligum5TUnMyy1CJ9uwSujGtnT7MVnBSr+HqnlbmB8blQFyMnh4SAicSX 9RvZuxi5OIQEVjBK3Pz2iBHC+cIoMf37YxYI5zOjxO8lnYwwLcsXdDOB2EICyxklnpwqgOt4 svE9G0iCTUBf4uDZkywgtoiAtETnoolMIEXMAr+ZJLb+2Qs2SVjAUuLZ/ndgk1gEVCWW/ZnA DmLzClhLLJ53jLmLkQNom7zEnLcaIGFOARuJpT/XQJUISpyc+QRsPjNQSfPW2cwg8yUEFrFL 7F10hBniUheJ+2/72SFsYYlXx7dA2TISpyf3sEDY5RJPF/axQzS3MEo8aP8IlbCWOHz8IivI EcwCmhLrd+lDhB0lvnStY4O4jU/ixltBiBv4JCZtmw51Mq9ERxs0eFUlnp/qYYKwpSW6/q9j hbA9JDp2fWSbwKg4C8k3s5B8Mwth7wJG5lWM4qmlxbnpqcVGeanlesWJucWleel6yfm5mxiB 6ef0v+NfdjDu+pN0iFGAg1GJh/fAvFOxQqyJZcWVuYcYJTiYlUR4d1SciBXiTUmsrEotyo8v Ks1JLT7EKM3BoiTOW83wIFpIID2xJDU7NbUgtQgmy8TBKdXA6Cx9yrJY/uHGF0rlz6emH/78 wCbjR5fDTL+uz9w3eE4o8XQa2+2dHz5F2PKV70JfjqBk1/u+M+5NDnk2hUX+d+1to9CTKw/M /nvyZYmG61lW9sLs42fiuoVevxfv+Oz7U3ndCQNzh4L9DwrDN51/u7296SXTFc89t9d8CSz6 dpXlVSrXDOVH95VYijMSDbWYi4oTAfLKs6U7AwAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOIsWRmVeSWpSXmKPExsVy+t/xu7r+J0/HGvz9K26xccZ6VovrX56z WvTt+89oseDTDFaL8+c3sFucbXrDbnF51xw2i8+9Rxgt1h65y25xu3EFmwOXx6ZVnWweB9/t YfLo27KK0ePzJrkAlig9m6L80pJUhYz84hJbpWhDCyM9Q0sLPSMTSz1DY/NYKyNTJX07m5TU nMyy1CJ9uwS9jGtnT7MVnBSr+HqnlbmB8blQFyMnh4SAicTyBd1MXYxcHEICSxklVj5+zwaR kJZoPL2aCcIWlvhzrYsNougTo8T2zp3sIAk2AX2Jg2dPsoDYIkANnYsmgk1iFmhklrh4oAms W1jAUuLZ/ndgNouAqsSyPxPAmnkFrCUWzzvG3MXIAbRBXmLOWw2QMKeAjcTSn2vASoSASp5s eMsGUS4ocXLmE7BdzEDlzVtnM09gFJiFJDULSWoBI9MqRpHU0uLc9NxiI73ixNzi0rx0veT8 3E2MwEjZduznlh2MXe+CDzEKcDAq8fAemHcqVog1say4MvcQowQHs5II746KE7FCvCmJlVWp RfnxRaU5qcWHGE2BfpjILCWanA+M4rySeENTQ3MLS0NzY3NjMwslcd4OgYMxQgLpiSWp2amp BalFMH1MHJxSDYz2zwPWH50n9a1s3UGezdn5v/WOqO/NqPwfY7Mi3Y6n+QF//ILYd+sDf9Wb uKX/1Q2Kkq+V5NE+09jwSVHI5Kiufeb6WXn/eWe5XTpSf69U37Wu/8euxSmX8jJ6Pj02e3/S 6lKzdRJvqOvF84WGL/ZaPHGVXbgstjYmZG3R1r5Xt5w7XO7lNSuxFGckGmoxFxUnAgAg3k/s qgIAAA== X-CMS-MailID: 20191113091351eucas1p24afdb94f868b6a7a52b43e81462bb674 X-Msg-Generator: CA X-RootMTR: 20191113091351eucas1p24afdb94f868b6a7a52b43e81462bb674 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20191113091351eucas1p24afdb94f868b6a7a52b43e81462bb674 References: <20191113091336.5218-1-k.konieczny@samsung.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Change time stats counting to bigger type by using 64-bit jiffies. This will make devfreq stats code look similar to cpufreq stats and prevents overflow (for HZ = 1000 after 49.7 days). Signed-off-by: Kamil Konieczny Acked-by: Chanwoo Choi --- drivers/devfreq/devfreq.c | 14 +++++++------- include/linux/devfreq.h | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index ab22bf8a12d6..1602cca20fc4 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -158,9 +158,9 @@ static int set_freq_table(struct devfreq *devfreq) int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) { int lev, prev_lev, ret = 0; - unsigned long cur_time; + unsigned long long cur_time; - cur_time = jiffies; + cur_time = get_jiffies_64(); /* Immediately exit if previous_freq is not initialized yet. */ if (!devfreq->previous_freq) @@ -478,7 +478,7 @@ void devfreq_monitor_resume(struct devfreq *devfreq) queue_delayed_work(devfreq_wq, &devfreq->work, msecs_to_jiffies(devfreq->profile->polling_ms)); - devfreq->last_stat_updated = jiffies; + devfreq->last_stat_updated = get_jiffies_64(); devfreq->stop_polling = false; if (devfreq->profile->get_cur_freq && @@ -698,7 +698,7 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->time_in_state = devm_kcalloc(&devfreq->dev, devfreq->profile->max_state, - sizeof(unsigned long), + sizeof(*devfreq->time_in_state), GFP_KERNEL); if (!devfreq->time_in_state) { mutex_unlock(&devfreq->lock); @@ -706,7 +706,7 @@ struct devfreq *devfreq_add_device(struct device *dev, goto err_devfreq; } - devfreq->last_stat_updated = jiffies; + devfreq->last_stat_updated = get_jiffies_64(); srcu_init_notifier_head(&devfreq->transition_notifier_list); @@ -1423,8 +1423,8 @@ static ssize_t trans_stat_show(struct device *dev, for (j = 0; j < max_state; j++) len += sprintf(buf + len, "%10u", devfreq->trans_table[(i * max_state) + j]); - len += sprintf(buf + len, "%10u\n", - jiffies_to_msecs(devfreq->time_in_state[i])); + len += sprintf(buf + len, "%10llu\n", (u64) + jiffies64_to_msecs(devfreq->time_in_state[i])); } len += sprintf(buf + len, "Total transition : %u\n", diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index 2bae9ed3c783..b81a86e47fb9 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -174,8 +174,8 @@ struct devfreq { /* information for device frequency transition */ unsigned int total_trans; unsigned int *trans_table; - unsigned long *time_in_state; - unsigned long last_stat_updated; + u64 *time_in_state; + unsigned long long last_stat_updated; struct srcu_notifier_head transition_notifier_list; }; From patchwork Wed Nov 13 09:13:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Konieczny X-Patchwork-Id: 11241437 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66B3C15AB for ; Wed, 13 Nov 2019 09:14:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F2A322459 for ; Wed, 13 Nov 2019 09:14:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="lXCcNpQF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727343AbfKMJN5 (ORCPT ); Wed, 13 Nov 2019 04:13:57 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:34899 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727122AbfKMJNy (ORCPT ); Wed, 13 Nov 2019 04:13:54 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20191113091352euoutp01f7b0180f155efc8b4a3398fa2fadb43e~Wrf91Xxwl1861518615euoutp01e for ; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20191113091352euoutp01f7b0180f155efc8b4a3398fa2fadb43e~Wrf91Xxwl1861518615euoutp01e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1573636432; bh=2hSYwsWRrAXuVQQ2q56rq82t4/LIFohQQV4E4ogL2q8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lXCcNpQFMRH/Se9QyO+8MbT+tDgPgNiDkjHAhUSudDlbcRAxhft+K0wrb0p8lCA9c yx47DfHLJJxmrJXZ0Ocqc5e/gcUuTWDJERvWxhq1IufZqPbwKxCmxlJX3uOXOb5zcC XHj9h09YVEcGZRRBpou69i4EKqtFLL80t395qiM0= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20191113091352eucas1p1a9bcbb3837a23f4d7707f726deb061cd~Wrf9lPHVq1266712667eucas1p1r; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 9E.24.04309.059CBCD5; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20191113091351eucas1p2f83c221ce94fdea695775e00d5215458~Wrf9UUWKf2780427804eucas1p2M; Wed, 13 Nov 2019 09:13:51 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20191113091351eusmtrp28ed5dcd8cf12aecc5e302a572297fa4c~Wrf9TnkE91340513405eusmtrp2T; Wed, 13 Nov 2019 09:13:51 +0000 (GMT) X-AuditID: cbfec7f4-ae1ff700000010d5-06-5dcbc9502f36 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 1C.1A.04166.F49CBCD5; Wed, 13 Nov 2019 09:13:51 +0000 (GMT) Received: from AMDC3218.digital.local (unknown [106.120.51.18]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20191113091351eusmtip19eb2d99482a66f74433152085f7cadc6~Wrf80lxbK0379503795eusmtip1Q; Wed, 13 Nov 2019 09:13:51 +0000 (GMT) From: Kamil Konieczny To: k.konieczny@samsung.com Cc: Bartlomiej Zolnierkiewicz , Chanwoo Choi , Kamil Konieczny , Krzysztof Kozlowski , Kyungmin Park , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Marek Szyprowski , MyungJoo Ham Subject: [PATCH 2/7] devfreq: protect devfreq stats data with spinlock Date: Wed, 13 Nov 2019 10:13:31 +0100 Message-Id: <20191113091336.5218-3-k.konieczny@samsung.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191113091336.5218-1-k.konieczny@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOKsWRmVeSWpSXmKPExsWy7djP87oBJ0/HGiy5w2OxccZ6VovrX56z WvTt+89oseDTDFaL8+c3sFucbXrDbnF51xw2i8+9Rxgt1h65y25xu3EFmwOXx6ZVnWweB9/t YfLo27KK0ePzJrkAligum5TUnMyy1CJ9uwSujOMvzrMXLJGpWPduInsD4zbxLkZODgkBE4mG C23MXYxcHEICKxgl3l+fyAThfGGUWHj2KZTzmVFi1cnr7DAtv1/sZwOxhQSWM0qsvM0G13H9 4VuwIjYBfYmDZ0+ygNgiAtISnYsgxjIL/GaS2PpnLyNIQljATeLM2Q3MIDaLgKpER9NasDiv gLXEhq79QIM4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i3PTc4sN9YoTc4tL89L1kvNz NzECI2XbsZ+bdzBe2hh8iFGAg1GJh/fAvFOxQqyJZcWVuYcYJTiYlUR4d1SciBXiTUmsrEot yo8vKs1JLT7EaAr0w0RmKdHkfGAU55XEG5oamltYGpobmxubWSiJ83YIHIwREkhPLEnNTk0t SC2C6WPi4JRqYPQ3CU7vkaz9LN+uolwdlqsSd8LRPC9T48eigkk1e0S/popvFk56LZkkW7qZ ff4EJ96p7/jyNeO2BqtMFonx44+JSOV4Wv9v+6QHWb89fB5d1l75apnN3rvHs4Q02rgPdV+5 UPrn0FPB7s5/4cqS8iv/Znxk6vuVe+3e2Z02Dhezai8GdJy0VWIpzkg01GIuKk4EAG64pseq AgAA X-CMS-MailID: 20191113091351eucas1p2f83c221ce94fdea695775e00d5215458 X-Msg-Generator: CA X-RootMTR: 20191113091351eucas1p2f83c221ce94fdea695775e00d5215458 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20191113091351eucas1p2f83c221ce94fdea695775e00d5215458 References: <20191113091336.5218-1-k.konieczny@samsung.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Protect access to devfreq transitions stats with spinlock. Signed-off-by: Kamil Konieczny --- drivers/devfreq/devfreq.c | 18 +++++++++++++++--- include/linux/devfreq.h | 3 +++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 1602cca20fc4..ac04b5baef70 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -163,10 +163,16 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) cur_time = get_jiffies_64(); /* Immediately exit if previous_freq is not initialized yet. */ - if (!devfreq->previous_freq) - goto out; + if (!devfreq->previous_freq) { + spin_lock(&devfreq->stats_lock); + devfreq->last_stat_updated = cur_time; + spin_unlock(&devfreq->stats_lock); + return 0; + } prev_lev = devfreq_get_freq_level(devfreq, devfreq->previous_freq); + + spin_lock(&devfreq->stats_lock); if (prev_lev < 0) { ret = prev_lev; goto out; @@ -174,7 +180,6 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) devfreq->time_in_state[prev_lev] += cur_time - devfreq->last_stat_updated; - lev = devfreq_get_freq_level(devfreq, freq); if (lev < 0) { ret = lev; @@ -189,6 +194,7 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) out: devfreq->last_stat_updated = cur_time; + spin_unlock(&devfreq->stats_lock); return ret; } EXPORT_SYMBOL(devfreq_update_status); @@ -478,7 +484,9 @@ void devfreq_monitor_resume(struct devfreq *devfreq) queue_delayed_work(devfreq_wq, &devfreq->work, msecs_to_jiffies(devfreq->profile->polling_ms)); + spin_lock(&devfreq->stats_lock); devfreq->last_stat_updated = get_jiffies_64(); + spin_unlock(&devfreq->stats_lock); devfreq->stop_polling = false; if (devfreq->profile->get_cur_freq && @@ -707,6 +715,7 @@ struct devfreq *devfreq_add_device(struct device *dev, } devfreq->last_stat_updated = get_jiffies_64(); + spin_lock_init(&devfreq->stats_lock); srcu_init_notifier_head(&devfreq->transition_notifier_list); @@ -1405,6 +1414,8 @@ static ssize_t trans_stat_show(struct device *dev, len = sprintf(buf, " From : To\n"); len += sprintf(buf + len, " :"); + + spin_lock(&devfreq->stats_lock); for (i = 0; i < max_state; i++) len += sprintf(buf + len, "%10lu", devfreq->profile->freq_table[i]); @@ -1429,6 +1440,7 @@ static ssize_t trans_stat_show(struct device *dev, len += sprintf(buf + len, "Total transition : %u\n", devfreq->total_trans); + spin_unlock(&devfreq->stats_lock); return len; } static DEVICE_ATTR_RO(trans_stat); diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index b81a86e47fb9..a344e0be99f3 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -135,6 +135,8 @@ struct devfreq_dev_profile { * @trans_table: Statistics of devfreq transitions * @time_in_state: Statistics of devfreq states * @last_stat_updated: The last time stat updated + * @stats_lock: Lock protecting trans_table, time_in_state, last_time + * and total_trans used for statistics * @transition_notifier_list: list head of DEVFREQ_TRANSITION_NOTIFIER notifier * * This structure stores the devfreq information for a give device. @@ -176,6 +178,7 @@ struct devfreq { unsigned int *trans_table; u64 *time_in_state; unsigned long long last_stat_updated; + spinlock_t stats_lock; struct srcu_notifier_head transition_notifier_list; }; From patchwork Wed Nov 13 09:13:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Konieczny X-Patchwork-Id: 11241443 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F34F15AB for ; Wed, 13 Nov 2019 09:14:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 371972245A for ; Wed, 13 Nov 2019 09:14:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="GCTgbkJt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727321AbfKMJN4 (ORCPT ); Wed, 13 Nov 2019 04:13:56 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:32954 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727205AbfKMJNz (ORCPT ); Wed, 13 Nov 2019 04:13:55 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20191113091353euoutp02dfd4dcaa0102286dff535a8a259dda0d~Wrf_pCvNP2236522365euoutp02c for ; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20191113091353euoutp02dfd4dcaa0102286dff535a8a259dda0d~Wrf_pCvNP2236522365euoutp02c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1573636433; bh=fefHGcRJB0KQtAWan8ZucPbHfX9vKVV2/4VW/b5EgdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GCTgbkJt5q2bR+vQV364IYwficXX9J8hzYbfy0zOs8pxTF4FCp3HxUWcH4rU1fGj9 2G6i+Ofz26+2WsLp4LeDtLpv1tTePueFoyhxFadaJbEJw6VlcPS08vFw30rJ9k13ej A54B7cm7enYGEYIMknT4qoQfQmXPysZPfGa0Taj0= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20191113091353eucas1p13fd91e9cb9bc336500ea3de2c9e902f4~Wrf_UOtav1712317123eucas1p1K; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id DF.94.04374.059CBCD5; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20191113091352eucas1p2c30c8a73a8362aff872e3cd9312eb24b~Wrf9xIPCq2485524855eucas1p2M; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20191113091352eusmtrp1e8e7326047355e67920c10610e8019e6~Wrf9wm46t1033410334eusmtrp1D; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) X-AuditID: cbfec7f5-4f7ff70000001116-92-5dcbc9508192 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id A9.DA.04117.059CBCD5; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) Received: from AMDC3218.digital.local (unknown [106.120.51.18]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20191113091351eusmtip1d248033f0d70c89c053cfce6364032ef~Wrf9RRtLb0136201362eusmtip1X; Wed, 13 Nov 2019 09:13:51 +0000 (GMT) From: Kamil Konieczny To: k.konieczny@samsung.com Cc: Bartlomiej Zolnierkiewicz , Chanwoo Choi , Kamil Konieczny , Krzysztof Kozlowski , Kyungmin Park , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Marek Szyprowski , MyungJoo Ham Subject: [PATCH 3/7] devfreq: add clearing transitions stats in sysfs Date: Wed, 13 Nov 2019 10:13:32 +0100 Message-Id: <20191113091336.5218-4-k.konieczny@samsung.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191113091336.5218-1-k.konieczny@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOKsWRmVeSWpSXmKPExsWy7djP87oBJ0/HGky5aWGxccZ6VovrX56z WvTt+89oseDTDFaL8+c3sFucbXrDbnF51xw2i8+9Rxgt1h65y25xu3EFmwOXx6ZVnWweB9/t YfLo27KK0ePzJrkAligum5TUnMyy1CJ9uwSujBsrtApu8VQ0rv/J1MD4iKuLkZNDQsBEYt/F aYxdjFwcQgIrGCUanr6Ecr4wSnx7OYcVwvnMKPH1zz42mJYnc16xQySWM0qcW/yXHaGlpRms ik1AX+Lg2ZMsILaIgLRE56KJTCBFzAK/mSS2/tnLCJIQFnCVuP2uixXEZhFQlXj49ANYnFfA WuL9uYdAzRxA6+Ql5rzVAAlzCthILP25hh2iRFDi5MwnYPOZgUqat85mBpkvIbCIXWLblqvs EKe6SHy/sogZwhaWeHV8C1RcRuL05B4WCLtc4unCPnaI5hZGiQftH6ES1hKHj19kBTmCWUBT Yv0ufYiwo8SVD9NZIW7jk7jxVhDiBj6JSdumM0OEeSU62oQgqlUlnp/qYYKwpSW6/q+D6vSQ OPA6bAKj4iwkz8xC8swshLULGJlXMYqnlhbnpqcWG+ellusVJ+YWl+al6yXn525iBCaf0/+O f93BuO9P0iFGAQ5GJR5eiYWnY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PMs9DtvxuvsNTO9ufL8x6/ree60mJue +PPA39L9Y3Ck+MoWsaQLYkInAxZarek9rHJ3b6DU2aXKB6fP27JMiaU4I9FQi7moOBEAVkvO w6gCAAA= X-CMS-MailID: 20191113091352eucas1p2c30c8a73a8362aff872e3cd9312eb24b X-Msg-Generator: CA X-RootMTR: 20191113091352eucas1p2c30c8a73a8362aff872e3cd9312eb24b X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20191113091352eucas1p2c30c8a73a8362aff872e3cd9312eb24b References: <20191113091336.5218-1-k.konieczny@samsung.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add new function trans_reset in sysfs for clearing transition table and time in states devfreq statistics. Signed-off-by: Kamil Konieczny --- drivers/devfreq/devfreq.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index ac04b5baef70..0a88055d1362 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -1445,6 +1445,31 @@ static ssize_t trans_stat_show(struct device *dev, } static DEVICE_ATTR_RO(trans_stat); +static void defvreq_stats_clear_table(struct devfreq *devfreq) +{ + unsigned int count = devfreq->profile->max_state; + + spin_lock(&devfreq->stats_lock); + memset(devfreq->time_in_state, 0, count * sizeof(u64)); + memset(devfreq->trans_table, 0, count * count * sizeof(int)); + devfreq->last_stat_updated = get_jiffies_64(); + devfreq->total_trans = 0; + spin_unlock(&devfreq->stats_lock); +} + +static ssize_t trans_reset_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t count) +{ + struct devfreq *devfreq = to_devfreq(dev); + + defvreq_stats_clear_table(devfreq); + + return count; +} +static DEVICE_ATTR_WO(trans_reset); + static struct attribute *devfreq_attrs[] = { &dev_attr_governor.attr, &dev_attr_available_governors.attr, @@ -1455,6 +1480,7 @@ static struct attribute *devfreq_attrs[] = { &dev_attr_min_freq.attr, &dev_attr_max_freq.attr, &dev_attr_trans_stat.attr, + &dev_attr_trans_reset.attr, NULL, }; ATTRIBUTE_GROUPS(devfreq); From patchwork Wed Nov 13 09:13:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Konieczny X-Patchwork-Id: 11241427 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9C86D17E6 for ; Wed, 13 Nov 2019 09:13:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 754F0222D0 for ; Wed, 13 Nov 2019 09:13:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="plouXazu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727262AbfKMJNz (ORCPT ); Wed, 13 Nov 2019 04:13:55 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:34910 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726422AbfKMJNz (ORCPT ); Wed, 13 Nov 2019 04:13:55 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20191113091353euoutp0188a83b5ab6b28d9429312397a972cf3d~Wrf-DJv7g1914219142euoutp01G for ; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20191113091353euoutp0188a83b5ab6b28d9429312397a972cf3d~Wrf-DJv7g1914219142euoutp01G DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1573636433; bh=yzWOzEn9xl+o0h/YwB50Z5PsuJeNLsiTaz8iIyEE6Rg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=plouXazuKAN1Q2rMtGAffaS/b6n4AlyOAJZOg6+3ukzRCtkUWu2FdcrAPP41i76+N xhzOdqvk3RvJfDwfOBkX7GE0uBcGEEiXB6POfSQI4j87jloj2e+6kwfFduCl4WibQV 3himnHzO3Hga4wnvNUAJWCQDaONNszpAWywMIL6U= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20191113091353eucas1p1a6b890ef91a9265a8b60d18f0670e20d~Wrf_yvvlt0367003670eucas1p1F; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 6F.24.04309.159CBCD5; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20191113091352eucas1p1825d815661c1a8377449f511c65ea230~Wrf_P0Wsf0367003670eucas1p1E; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20191113091352eusmtrp2dac0dd15584ca1abc852136932a9b07d~Wrf_PP9_w1340513405eusmtrp2V; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) X-AuditID: cbfec7f4-ae1ff700000010d5-08-5dcbc9516243 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id EC.1A.04166.059CBCD5; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) Received: from AMDC3218.digital.local (unknown [106.120.51.18]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20191113091352eusmtip10d9792413003df2016df248371553a1a~Wrf9ucwub0379503795eusmtip1R; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) From: Kamil Konieczny To: k.konieczny@samsung.com Cc: Bartlomiej Zolnierkiewicz , Chanwoo Choi , Kamil Konieczny , Krzysztof Kozlowski , Kyungmin Park , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Marek Szyprowski , MyungJoo Ham Subject: [PATCH 4/7] devfreq: change var name used in time statistics Date: Wed, 13 Nov 2019 10:13:33 +0100 Message-Id: <20191113091336.5218-5-k.konieczny@samsung.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191113091336.5218-1-k.konieczny@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGKsWRmVeSWpSXmKPExsWy7djP87qBJ0/HGrzYLmmxccZ6VovrX56z WvTt+89oseDTDFaL8+c3sFucbXrDbnF51xw2i8+9Rxgt1h65y25xu3EFmwOXx6ZVnWweB9/t YfLo27KK0ePzJrkAligum5TUnMyy1CJ9uwSujBO9NQUvpCq2/z3N1sB4XKyLkZNDQsBE4tLa y0xdjFwcQgIrGCX2rV3KCJIQEvjCKLF2czBE4jOjxOT709hhOnZv2soKkVjOKNFxqw/KAeo4 fG4eWBWbgL7EwbMnWUBsEQFpic5FE8F2MAv8ZpLY+mcv2A5hAVeJtpPbwWwWAVWJKQfbwJp5 Bawl5nxtZOti5ABaJy8x560GSJhTwEZi6c81UCWCEidnPgGbzwxU0rx1NjPEdYvYJc72hUDY LhJXV7xmhbCFJV4d3wL1gYzE/53zmSDscomnC/vYQW6TEGhhlHjQ/pEFImEtcfj4RVaQG5gF NCXW79KHCDtKdHw6yApxGp/EjbeCECfwSUzaNp0ZIswr0dEmBFGtKvH8VA/UJmmJrv/roK7x kPh9Yi7zBEbFWUiemYXkmVkIexcwMq9iFE8tLc5NTy02ykst1ytOzC0uzUvXS87P3cQITD2n /x3/soNx15+kQ4wCHIxKPLwH5p2KFWJNLCuuzD3EKMHBrCTCu6PiRKwQb0piZVVqUX58UWlO avEhRmkOFiVx3mqGB9FCAumJJanZqakFqUUwWSYOTqkGxhk7Gnt0NnxfMXvvZAP9tRUc4ku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ucas1p1825d815661c1a8377449f511c65ea230 X-Msg-Generator: CA X-RootMTR: 20191113091352eucas1p1825d815661c1a8377449f511c65ea230 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20191113091352eucas1p1825d815661c1a8377449f511c65ea230 References: <20191113091336.5218-1-k.konieczny@samsung.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Change var name used in time statistics from last_stat_updated to last_time. This will make it shorter and similar to cpufreq_stats. Signed-off-by: Kamil Konieczny --- drivers/devfreq/devfreq.c | 12 ++++++------ include/linux/devfreq.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 0a88055d1362..6e5a17f4c92c 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -165,7 +165,7 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) /* Immediately exit if previous_freq is not initialized yet. */ if (!devfreq->previous_freq) { spin_lock(&devfreq->stats_lock); - devfreq->last_stat_updated = cur_time; + devfreq->last_time = cur_time; spin_unlock(&devfreq->stats_lock); return 0; } @@ -179,7 +179,7 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) } devfreq->time_in_state[prev_lev] += - cur_time - devfreq->last_stat_updated; + cur_time - devfreq->last_time; lev = devfreq_get_freq_level(devfreq, freq); if (lev < 0) { ret = lev; @@ -193,7 +193,7 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) } out: - devfreq->last_stat_updated = cur_time; + devfreq->last_time = cur_time; spin_unlock(&devfreq->stats_lock); return ret; } @@ -485,7 +485,7 @@ void devfreq_monitor_resume(struct devfreq *devfreq) msecs_to_jiffies(devfreq->profile->polling_ms)); spin_lock(&devfreq->stats_lock); - devfreq->last_stat_updated = get_jiffies_64(); + devfreq->last_time = get_jiffies_64(); spin_unlock(&devfreq->stats_lock); devfreq->stop_polling = false; @@ -714,7 +714,7 @@ struct devfreq *devfreq_add_device(struct device *dev, goto err_devfreq; } - devfreq->last_stat_updated = get_jiffies_64(); + devfreq->last_time = get_jiffies_64(); spin_lock_init(&devfreq->stats_lock); srcu_init_notifier_head(&devfreq->transition_notifier_list); @@ -1452,7 +1452,7 @@ static void defvreq_stats_clear_table(struct devfreq *devfreq) spin_lock(&devfreq->stats_lock); memset(devfreq->time_in_state, 0, count * sizeof(u64)); memset(devfreq->trans_table, 0, count * count * sizeof(int)); - devfreq->last_stat_updated = get_jiffies_64(); + devfreq->last_time = get_jiffies_64(); devfreq->total_trans = 0; spin_unlock(&devfreq->stats_lock); } diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index a344e0be99f3..2ddf25993f7d 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -134,7 +134,7 @@ struct devfreq_dev_profile { * @total_trans: Number of devfreq transitions * @trans_table: Statistics of devfreq transitions * @time_in_state: Statistics of devfreq states - * @last_stat_updated: The last time stat updated + * @last_time: The last time stats were updated * @stats_lock: Lock protecting trans_table, time_in_state, last_time * and total_trans used for statistics * @transition_notifier_list: list head of DEVFREQ_TRANSITION_NOTIFIER notifier @@ -177,7 +177,7 @@ struct devfreq { unsigned int total_trans; unsigned int *trans_table; u64 *time_in_state; - unsigned long long last_stat_updated; + unsigned long long last_time; spinlock_t stats_lock; struct srcu_notifier_head transition_notifier_list; From patchwork Wed Nov 13 09:13:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Konieczny X-Patchwork-Id: 11241445 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2B4BF1390 for ; Wed, 13 Nov 2019 09:14:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EDDBB22459 for ; Wed, 13 Nov 2019 09:14:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="pLT7ngax" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727291AbfKMJN4 (ORCPT ); Wed, 13 Nov 2019 04:13:56 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:32961 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727221AbfKMJNz (ORCPT ); Wed, 13 Nov 2019 04:13:55 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20191113091353euoutp02ed582669be7682fc13414865bd93f600~Wrf-KA7Bs2229622296euoutp02k for ; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20191113091353euoutp02ed582669be7682fc13414865bd93f600~Wrf-KA7Bs2229622296euoutp02k DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1573636433; bh=RN3M6NGDwfSrIDMXV1ECarDkUOgoQmAqCZDQaPlLzGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pLT7ngax6MOzLJ/J+HBUNYGLCexTEHJEHMTWePru0hJWvv6pggwieeLg0Qxnqa4R7 pcP1OVrQ0LBz7jNZoAHUdvqqULaZrICH+VXSPOREm3wwLjnllBgPbUHzdypfPiDdiz IGLaR+GFoT+TuaKdU2MujQgCJDPpHQCKJxnoTAos= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20191113091353eucas1p1663dcbc0990a252b7c38a95b40e756d8~Wrf_7OX2R1712317123eucas1p1M; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id A7.82.04469.159CBCD5; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20191113091353eucas1p283be3173c7a9ea726b4767f9cb113f0f~Wrf_psG_H2485524855eucas1p2N; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20191113091353eusmtrp1ec110aef3d0a253e26b7ab2bd467f195~Wrf_pDb5_1033410334eusmtrp1F; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) X-AuditID: cbfec7f2-569ff70000001175-b0-5dcbc9514cec Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 9A.DA.04117.159CBCD5; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) Received: from AMDC3218.digital.local (unknown [106.120.51.18]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20191113091352eusmtip17b7ddd21cc8578c4caa048af473b8941~Wrf_LtsQj2887828878eusmtip16; Wed, 13 Nov 2019 09:13:52 +0000 (GMT) From: Kamil Konieczny To: k.konieczny@samsung.com Cc: Bartlomiej Zolnierkiewicz , Chanwoo Choi , Kamil Konieczny , Krzysztof Kozlowski , Kyungmin Park , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Marek Szyprowski , MyungJoo Ham Subject: [PATCH 5/7] devfreq: move transition statistics to devfreq profile structure Date: Wed, 13 Nov 2019 10:13:34 +0100 Message-Id: <20191113091336.5218-6-k.konieczny@samsung.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191113091336.5218-1-k.konieczny@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBKsWRmVeSWpSXmKPExsWy7djP87qBJ0/HGqy9q2axccZ6VovrX56z WvTt+89oseDTDFaL8+c3sFucbXrDbnF51xw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y1CJ9uwS9jB2vrzEWTAupWHlvOmsDY4drFyMnh4SAiUTz+Z9MXYxcHEICSxklmv5OYIdI SEs0nl7NBGELS/y51sUGUfSJUWLbp/tgCTYBfYmDZ0+ygNgiQA2diyaCTWIWaGSWuHigCaxI WCBU4vfh6WBFLAKqEt1n+8DivALWEg/+/AGyOYA2yEvMeasBEuYUsJFY+nMN2BFCQCVPNrxl gygXlDg58wnYGGag8uats5knMArMQpKahSS1gJFpFaNIamlxbnpusZFecWJucWleul5yfu4m RmCkbDv2c8sOxq53wYcYBTgYlXh4D8w7FSvEmlhWXJl7iFGCg1lJhHdHxYlYId6UxMqq1KL8 +KLSnNTiQ4ymQD9MZJYSTc4HRnFeSbyhqaG5haWhubG5sZmFkjhvh8DBGCGB9MSS1OzU1ILU Ipg+Jg5OqQbGMrO/X0tMtGzijD3FF7tpe8y9rGpbqCzheOuQkdWv3xcPp0Q8l2aWUHt55Fzs Jb1rWeZMecXn7Gor/t/iNX+U9tcwbN0XRy/FvcvDb/ocV5SpDrbnXN2YddDIa/7Xg1Ocgjbs eFuarCCu2TVx3bb5//ze7p+9enNadrvm1J7VV00TjH4sqF+sxFKckWioxVxUnAgA/e8pKqoC AAA= X-CMS-MailID: 20191113091353eucas1p283be3173c7a9ea726b4767f9cb113f0f X-Msg-Generator: CA X-RootMTR: 20191113091353eucas1p283be3173c7a9ea726b4767f9cb113f0f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20191113091353eucas1p283be3173c7a9ea726b4767f9cb113f0f References: <20191113091336.5218-1-k.konieczny@samsung.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Move transition statistics to devfreq profile structure. This is for preparation for moving transition statistics into separate struct. It is safe to do as frequency table and maximum state information are already present in devfreq profile structure and there are no devfreq drivers using more than one instance of devfreq structure per devfreq profile one. It also makes devfreq code more similar to cpufreq one. Signed-off-by: Kamil Konieczny --- drivers/devfreq/devfreq.c | 115 +++++++++++++++++++------------------- include/linux/devfreq.h | 25 ++++----- 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 6e5a17f4c92c..70533b787744 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -128,7 +128,7 @@ static int set_freq_table(struct devfreq *devfreq) profile->max_state = count; profile->freq_table = devm_kcalloc(devfreq->dev.parent, - profile->max_state, + count, sizeof(*profile->freq_table), GFP_KERNEL); if (!profile->freq_table) { @@ -157,29 +157,30 @@ static int set_freq_table(struct devfreq *devfreq) */ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) { - int lev, prev_lev, ret = 0; + struct devfreq_dev_profile *profile = devfreq->profile; unsigned long long cur_time; + int lev, prev_lev, ret = 0; cur_time = get_jiffies_64(); /* Immediately exit if previous_freq is not initialized yet. */ if (!devfreq->previous_freq) { - spin_lock(&devfreq->stats_lock); - devfreq->last_time = cur_time; - spin_unlock(&devfreq->stats_lock); + spin_lock(&profile->stats_lock); + profile->last_time = cur_time; + spin_unlock(&profile->stats_lock); return 0; } prev_lev = devfreq_get_freq_level(devfreq, devfreq->previous_freq); - spin_lock(&devfreq->stats_lock); + spin_lock(&profile->stats_lock); if (prev_lev < 0) { ret = prev_lev; goto out; } - devfreq->time_in_state[prev_lev] += - cur_time - devfreq->last_time; + profile->time_in_state[prev_lev] += + cur_time - profile->last_time; lev = devfreq_get_freq_level(devfreq, freq); if (lev < 0) { ret = lev; @@ -187,14 +188,14 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) } if (lev != prev_lev) { - devfreq->trans_table[(prev_lev * - devfreq->profile->max_state) + lev]++; - devfreq->total_trans++; + profile->trans_table[(prev_lev * + profile->max_state) + lev]++; + profile->total_trans++; } out: - devfreq->last_time = cur_time; - spin_unlock(&devfreq->stats_lock); + profile->last_time = cur_time; + spin_unlock(&profile->stats_lock); return ret; } EXPORT_SYMBOL(devfreq_update_status); @@ -474,23 +475,23 @@ EXPORT_SYMBOL(devfreq_monitor_suspend); void devfreq_monitor_resume(struct devfreq *devfreq) { unsigned long freq; + struct devfreq_dev_profile *profile = devfreq->profile; mutex_lock(&devfreq->lock); if (!devfreq->stop_polling) goto out; - if (!delayed_work_pending(&devfreq->work) && - devfreq->profile->polling_ms) + if (!delayed_work_pending(&devfreq->work) && profile->polling_ms) queue_delayed_work(devfreq_wq, &devfreq->work, - msecs_to_jiffies(devfreq->profile->polling_ms)); + msecs_to_jiffies(profile->polling_ms)); - spin_lock(&devfreq->stats_lock); - devfreq->last_time = get_jiffies_64(); - spin_unlock(&devfreq->stats_lock); + spin_lock(&profile->stats_lock); + profile->last_time = get_jiffies_64(); + spin_unlock(&profile->stats_lock); devfreq->stop_polling = false; - if (devfreq->profile->get_cur_freq && - !devfreq->profile->get_cur_freq(devfreq->dev.parent, &freq)) + if (profile->get_cur_freq && + !profile->get_cur_freq(devfreq->dev.parent, &freq)) devfreq->previous_freq = freq; out: @@ -657,7 +658,7 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->data = data; devfreq->nb.notifier_call = devfreq_notifier_call; - if (!devfreq->profile->max_state && !devfreq->profile->freq_table) { + if (!profile->max_state && !profile->freq_table) { mutex_unlock(&devfreq->lock); err = set_freq_table(devfreq); if (err < 0) @@ -693,29 +694,29 @@ struct devfreq *devfreq_add_device(struct device *dev, goto err_out; } - devfreq->trans_table = devm_kzalloc(&devfreq->dev, - array3_size(sizeof(unsigned int), - devfreq->profile->max_state, - devfreq->profile->max_state), - GFP_KERNEL); - if (!devfreq->trans_table) { + profile->trans_table = devm_kzalloc(&devfreq->dev, + array3_size(sizeof(unsigned int), + profile->max_state, + profile->max_state), + GFP_KERNEL); + if (!profile->trans_table) { mutex_unlock(&devfreq->lock); err = -ENOMEM; goto err_devfreq; } - devfreq->time_in_state = devm_kcalloc(&devfreq->dev, - devfreq->profile->max_state, - sizeof(*devfreq->time_in_state), - GFP_KERNEL); - if (!devfreq->time_in_state) { + profile->time_in_state = devm_kcalloc(&devfreq->dev, + profile->max_state, + sizeof(*profile->time_in_state), + GFP_KERNEL); + if (!profile->time_in_state) { mutex_unlock(&devfreq->lock); err = -ENOMEM; goto err_devfreq; } - devfreq->last_time = get_jiffies_64(); - spin_lock_init(&devfreq->stats_lock); + profile->last_time = get_jiffies_64(); + spin_lock_init(&profile->stats_lock); srcu_init_notifier_head(&devfreq->transition_notifier_list); @@ -1402,9 +1403,10 @@ static ssize_t trans_stat_show(struct device *dev, struct device_attribute *attr, char *buf) { struct devfreq *devfreq = to_devfreq(dev); + struct devfreq_dev_profile *profile = devfreq->profile; ssize_t len; int i, j; - unsigned int max_state = devfreq->profile->max_state; + unsigned int max_state = profile->max_state; if (!devfreq->stop_polling && devfreq_update_status(devfreq, devfreq->previous_freq)) @@ -1415,46 +1417,45 @@ static ssize_t trans_stat_show(struct device *dev, len = sprintf(buf, " From : To\n"); len += sprintf(buf + len, " :"); - spin_lock(&devfreq->stats_lock); + spin_lock(&profile->stats_lock); for (i = 0; i < max_state; i++) len += sprintf(buf + len, "%10lu", - devfreq->profile->freq_table[i]); + profile->freq_table[i]); len += sprintf(buf + len, " time(ms)\n"); for (i = 0; i < max_state; i++) { - if (devfreq->profile->freq_table[i] - == devfreq->previous_freq) { + if (profile->freq_table[i] == devfreq->previous_freq) len += sprintf(buf + len, "*"); - } else { + else len += sprintf(buf + len, " "); - } + len += sprintf(buf + len, "%10lu:", - devfreq->profile->freq_table[i]); + profile->freq_table[i]); for (j = 0; j < max_state; j++) len += sprintf(buf + len, "%10u", - devfreq->trans_table[(i * max_state) + j]); + profile->trans_table[(i * max_state) + j]); len += sprintf(buf + len, "%10llu\n", (u64) - jiffies64_to_msecs(devfreq->time_in_state[i])); + jiffies64_to_msecs(profile->time_in_state[i])); } len += sprintf(buf + len, "Total transition : %u\n", - devfreq->total_trans); - spin_unlock(&devfreq->stats_lock); + profile->total_trans); + spin_unlock(&profile->stats_lock); return len; } static DEVICE_ATTR_RO(trans_stat); -static void defvreq_stats_clear_table(struct devfreq *devfreq) +static void defvreq_stats_clear_table(struct devfreq_dev_profile *profile) { - unsigned int count = devfreq->profile->max_state; - - spin_lock(&devfreq->stats_lock); - memset(devfreq->time_in_state, 0, count * sizeof(u64)); - memset(devfreq->trans_table, 0, count * count * sizeof(int)); - devfreq->last_time = get_jiffies_64(); - devfreq->total_trans = 0; - spin_unlock(&devfreq->stats_lock); + unsigned int count = profile->max_state; + + spin_lock(&profile->stats_lock); + memset(profile->time_in_state, 0, count * sizeof(u64)); + memset(profile->trans_table, 0, count * count * sizeof(int)); + profile->last_time = get_jiffies_64(); + profile->total_trans = 0; + spin_unlock(&profile->stats_lock); } static ssize_t trans_reset_store(struct device *dev, @@ -1464,7 +1465,7 @@ static ssize_t trans_reset_store(struct device *dev, { struct devfreq *devfreq = to_devfreq(dev); - defvreq_stats_clear_table(devfreq); + defvreq_stats_clear_table(devfreq->profile); return count; } diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index 2ddf25993f7d..4ceb2a517a9c 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -91,6 +91,12 @@ struct devfreq_dev_status { * @freq_table: Optional list of frequencies to support statistics * and freq_table must be generated in ascending order. * @max_state: The size of freq_table. + * @total_trans: Number of devfreq transitions + * @trans_table: Statistics of devfreq transitions + * @time_in_state: Statistics of devfreq states + * @last_time: The last time stats were updated + * @stats_lock: Lock protecting trans_table, time_in_state, + * last_time and total_trans used for statistics */ struct devfreq_dev_profile { unsigned long initial_freq; @@ -104,6 +110,12 @@ struct devfreq_dev_profile { unsigned long *freq_table; unsigned int max_state; + /* information for device frequency transition */ + unsigned int total_trans; + unsigned int *trans_table; + u64 *time_in_state; + unsigned long long last_time; + spinlock_t stats_lock; }; /** @@ -131,12 +143,6 @@ struct devfreq_dev_profile { * @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 - * @last_time: The last time stats were updated - * @stats_lock: Lock protecting trans_table, time_in_state, last_time - * and total_trans used for statistics * @transition_notifier_list: list head of DEVFREQ_TRANSITION_NOTIFIER notifier * * This structure stores the devfreq information for a give device. @@ -173,13 +179,6 @@ struct devfreq { unsigned long resume_freq; atomic_t suspend_count; - /* information for device frequency transition */ - unsigned int total_trans; - unsigned int *trans_table; - u64 *time_in_state; - unsigned long long last_time; - spinlock_t stats_lock; - struct srcu_notifier_head transition_notifier_list; }; From patchwork Wed Nov 13 09:13:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Konieczny X-Patchwork-Id: 11241429 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0B89316B1 for ; Wed, 13 Nov 2019 09:13:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8CA722470 for ; Wed, 13 Nov 2019 09:13:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="FU88YKzs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727316AbfKMJN4 (ORCPT ); Wed, 13 Nov 2019 04:13:56 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:34910 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727238AbfKMJNz (ORCPT ); Wed, 13 Nov 2019 04:13:55 -0500 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20191113091355euoutp01b5123259eb7b63a09e78cc606f2e6a2a~WrgATfG1g1907619076euoutp01K for ; Wed, 13 Nov 2019 09:13:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20191113091355euoutp01b5123259eb7b63a09e78cc606f2e6a2a~WrgATfG1g1907619076euoutp01K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1573636435; bh=wPJLPIsHPtd18ziWhoH1wLWeb4q37D6cAXWrtAjIfCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FU88YKzsFUJsb004xDNiMrlnOVgNUcTiS6pjohpHdlYLjznjOg7s3PtmB16fu2Z6d BFxmC/+sAhliwQkUXazBiLt9YJMvYKqMcwZqA9QspFJOfLFqhtJdBNm8y38bLQGSMq bLd20bweejvTkqPveZ/tWMGavoGYYWg4x3/je1mY= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20191113091354eucas1p2ad1b28ccb6a72356006ababe017063d4~Wrf-k_upb0764807648eucas1p2l; Wed, 13 Nov 2019 09:13:54 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 58.82.04469.259CBCD5; Wed, 13 Nov 2019 09:13:54 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20191113091353eucas1p2d9f82697e6ec44c0e38225988227c73c~Wrf-Fn6EJ2485524855eucas1p2O; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20191113091353eusmtrp28034d2cb04b30372ec8194b4870e6a65~Wrf-E_i1c1340513405eusmtrp2X; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) X-AuditID: cbfec7f2-54fff70000001175-b3-5dcbc952ed22 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id DD.1A.04166.159CBCD5; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) Received: from AMDC3218.digital.local (unknown [106.120.51.18]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20191113091353eusmtip1f821ee2964d300f19482fb418683e635~Wrf_oTuqG0379503795eusmtip1S; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) From: Kamil Konieczny To: k.konieczny@samsung.com Cc: Bartlomiej Zolnierkiewicz , Chanwoo Choi , Kamil Konieczny , Krzysztof Kozlowski , Kyungmin Park , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Marek Szyprowski , MyungJoo Ham Subject: [PATCH 6/7] devfreq: move transition statistics allocations to set_freq_stats() Date: Wed, 13 Nov 2019 10:13:35 +0100 Message-Id: <20191113091336.5218-7-k.konieczny@samsung.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191113091336.5218-1-k.konieczny@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOKsWRmVeSWpSXmKPExsWy7djP87pBJ0/HGkzawW+xccZ6VovrX56z WvTt+89oseDTDFaL8+c3sFucbXrDbnF51xw2i8+9Rxgt1h65y25xu3EFmwOXx6ZVnWweB9/t YfLo27KK0ePzJrkAligum5TUnMyy1CJ9uwSujHVvjrAUvBeq2LfmJlMD43L+LkZODgkBE4nt px8xdzFycQgJrGCUOPn/ABuE84VRYue6XewQzmdGiW2Tf7PCtJy494UNxBYSWM4o0fElB67j w+cpTCAJNgF9iYNnT7KA2CIC0hKdiyYygRQxC/xmktj6Zy8jSEJYIErid8tNsAYWAVWJv88/ g03lFbCWuNp8C2gbB9A2eYk5bzVAwpwCNhJLf65hhygRlDg58wnYfGagkuats8F+kBBYxC7x Zf4mqF4XiZYplRBHC0u8Or6FHcKWkfi/cz4ThF0u8XRhHztEbwujxIP2jywQCWuJw8cvgs1h FtCUWL9LHyLsKPFk9VtmiPF8EjfeCkKcwCcxadt0qDCvREebEES1qsTzUz1Qm6Qluv6v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+TGH7KiYGuMrvf8UXz2fwv1Y6MSHgo/vSypfrNhTqzv1s9DD CT6X1U9MFfqQ9DeTeZr2zon5PPP+nOx+rfs460LugTD5/qUdPOZC/Gu5lk559aRqdWfI5ndL EzWen2X54mY2ce2kqr9tse4PWH8+8E5lCf4k+bA1rv215nPzz/WvlFiKMxINtZiLihMB8HcD QqkCAAA= X-CMS-MailID: 20191113091353eucas1p2d9f82697e6ec44c0e38225988227c73c X-Msg-Generator: CA X-RootMTR: 20191113091353eucas1p2d9f82697e6ec44c0e38225988227c73c X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20191113091353eucas1p2d9f82697e6ec44c0e38225988227c73c References: <20191113091336.5218-1-k.konieczny@samsung.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org All users of [devm_]devfreq_add_device() don't set freq_table nor max_state, and there is only one "struct devfreq_profile" per every "struct devfreq", so move transition memory allocations to function set_freq_stats() and initialize there other statistics fields. Signed-off-by: Kamil Konieczny --- drivers/devfreq/devfreq.c | 44 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index 70533b787744..d79412b0de59 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -147,7 +147,26 @@ static int set_freq_table(struct devfreq *devfreq) profile->freq_table[i] = freq; } + profile->trans_table = devm_kzalloc(devfreq->dev.parent, + array3_size(sizeof(unsigned int), + count, count), + GFP_KERNEL); + if (!profile->trans_table) + goto err_no_mem; + + profile->time_in_state = devm_kcalloc(devfreq->dev.parent, count, + sizeof(*profile->time_in_state), + GFP_KERNEL); + if (!profile->time_in_state) + goto err_no_mem; + + profile->last_time = get_jiffies_64(); + spin_lock_init(&profile->stats_lock); + return 0; +err_no_mem: + profile->max_state = 0; + return -ENOMEM; } /** @@ -694,30 +713,6 @@ struct devfreq *devfreq_add_device(struct device *dev, goto err_out; } - profile->trans_table = devm_kzalloc(&devfreq->dev, - array3_size(sizeof(unsigned int), - profile->max_state, - profile->max_state), - GFP_KERNEL); - if (!profile->trans_table) { - mutex_unlock(&devfreq->lock); - err = -ENOMEM; - goto err_devfreq; - } - - profile->time_in_state = devm_kcalloc(&devfreq->dev, - profile->max_state, - sizeof(*profile->time_in_state), - GFP_KERNEL); - if (!profile->time_in_state) { - mutex_unlock(&devfreq->lock); - err = -ENOMEM; - goto err_devfreq; - } - - profile->last_time = get_jiffies_64(); - spin_lock_init(&profile->stats_lock); - srcu_init_notifier_head(&devfreq->transition_notifier_list); mutex_unlock(&devfreq->lock); @@ -749,7 +744,6 @@ struct devfreq *devfreq_add_device(struct device *dev, err_init: mutex_unlock(&devfreq_list_lock); -err_devfreq: devfreq_remove_device(devfreq); devfreq = NULL; err_dev: From patchwork Wed Nov 13 09:13:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamil Konieczny X-Patchwork-Id: 11241431 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CBD517E6 for ; Wed, 13 Nov 2019 09:14:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 23869222D0 for ; Wed, 13 Nov 2019 09:14:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="NBLpNodz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727202AbfKMJN5 (ORCPT ); Wed, 13 Nov 2019 04:13:57 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:34927 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727283AbfKMJN5 (ORCPT ); Wed, 13 Nov 2019 04:13:57 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20191113091355euoutp01ad2643435aa9fa0438242a5dd3af696a~WrgAhoVSF1861518615euoutp01g for ; Wed, 13 Nov 2019 09:13:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20191113091355euoutp01ad2643435aa9fa0438242a5dd3af696a~WrgAhoVSF1861518615euoutp01g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1573636435; bh=N49/a4oWp3P4D7BBjUxpg5NsZssRUbfxVnbYKU9Xn/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NBLpNodzdUZIV1fmcub5ssUkGDK8Jv/uBSoAhbuCw4R7jGb80T25648gRPCD8yeCB 6ib3pEQ0gWZ7CWptSlvXCbaz9Jzkc0Sg1JiXaEee1aKoprww7Ivf+GpqZSW8mvX69Z LbXUpYATDoyZNM1lowVGqGWEwjeF4QTElHLZaUZk= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20191113091354eucas1p1119ec71a7c14d025558ea3eb5d60a956~WrgAI1hgR0377603776eucas1p1z; Wed, 13 Nov 2019 09:13:54 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 49.82.04469.259CBCD5; Wed, 13 Nov 2019 09:13:54 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20191113091354eucas1p265de4985d167814f5080fbdf21b75a0a~Wrf-viiw51333913339eucas1p22; Wed, 13 Nov 2019 09:13:54 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20191113091354eusmtrp2612372748ac1f755a2964f056937dcc4~Wrf-u0Izx1340513405eusmtrp2a; Wed, 13 Nov 2019 09:13:54 +0000 (GMT) X-AuditID: cbfec7f2-569ff70000001175-b6-5dcbc95236a3 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 1F.1A.04166.259CBCD5; Wed, 13 Nov 2019 09:13:54 +0000 (GMT) Received: from AMDC3218.digital.local (unknown [106.120.51.18]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20191113091353eusmtip13fd034159458230afac32a5df05d39c3~Wrf-FFRzN0136201362eusmtip1a; Wed, 13 Nov 2019 09:13:53 +0000 (GMT) From: Kamil Konieczny To: k.konieczny@samsung.com Cc: Bartlomiej Zolnierkiewicz , Chanwoo Choi , Kamil Konieczny , Krzysztof Kozlowski , Kukjin Kim , Kyungmin Park , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Marek Szyprowski , MyungJoo Ham Subject: [PATCH 7/7] devfreq: move statistics to separate struct Date: Wed, 13 Nov 2019 10:13:36 +0100 Message-Id: <20191113091336.5218-8-k.konieczny@samsung.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191113091336.5218-1-k.konieczny@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNKsWRmVeSWpSXmKPExsWy7djPc7pBJ0/HGmy/bGGxccZ6VovrX56z WvTt+89oseDTDFaL/sevmS3On9/AbnG26Q27xabH11gtLu+aw2bxufcIo8WM8/uYLNYeuctu cbtxBZsDr8emVZ1sHpuX1HscfLeHyaNvyypGj8+b5AJYo7hsUlJzMstSi/TtErgyPv9rYCn4 1cVY8W71CtYGxqmFXYycHBICJhI/7t9i7GLk4hASWMEoMXXJfSjnC6PEjCct7CBVQgKfGSW+ tWjCdNxs6maCKFoOFH94lQWuo/PjTRaQKjYBfYmDZ0+C2SIC0hKdiyaCdTALPGeWuDz/PzNI QljAQWL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mJOW81QMKcAjYSS3+uASsRAip5suEtG0S5oMTJmU/AdjEDlTdvnc08gVFgFpLULCSpBYxM qxhFUkuLc9Nziw31ihNzi0vz0vWS83M3MQIjatuxn5t3MF7aGHyIUYCDUYmH98C8U7FCrIll xZW5hxglOJiVRHh3VJyIFeJNSaysSi3Kjy8qzUktPsRoCvTDRGYp0eR8YLTnlcQbmhqaW1ga mhubG5tZKInzdggcjBESSE8sSc1OTS1ILYLpY+LglGpgNFNweiSwQM7sMd8EkWVN+R4Z33zf ndPqPxU/Rdli052TKjtyrnxZwBrzlOv1ngMsej6KdyNlQrTnyEWUzaxOOCg2Z0PwT071BUdy yuY/lfJpdJrWKsR5xfB7uemHi0lLJPZIfzilFTDj6a/6piXN8+52aa2ySt/64FrLQ/Vn9heX yq/J9Z98TomlOCPRUIu5qDgRAIrne8q+AgAA X-CMS-MailID: 20191113091354eucas1p265de4985d167814f5080fbdf21b75a0a X-Msg-Generator: CA X-RootMTR: 20191113091354eucas1p265de4985d167814f5080fbdf21b75a0a X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20191113091354eucas1p265de4985d167814f5080fbdf21b75a0a References: <20191113091336.5218-1-k.konieczny@samsung.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Count time and transitions between devfreq frequencies in separate struct for improved code readability and maintenance. Signed-off-by: Kamil Konieczny --- drivers/devfreq/devfreq.c | 156 ++++++++++++++++------------- drivers/devfreq/exynos-bus.c | 6 +- drivers/devfreq/governor_passive.c | 26 +++-- include/linux/devfreq.h | 43 ++++---- 4 files changed, 129 insertions(+), 102 deletions(-) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index d79412b0de59..d85867a91230 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -105,10 +105,11 @@ static unsigned long find_available_max_freq(struct devfreq *devfreq) */ static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq) { + struct devfreq_stats *stats = devfreq->profile->stats; int lev; - for (lev = 0; lev < devfreq->profile->max_state; lev++) - if (freq == devfreq->profile->freq_table[lev]) + for (lev = 0; lev < stats->max_state; lev++) + if (freq == stats->freq_table[lev]) return lev; return -EINVAL; @@ -117,56 +118,64 @@ static int devfreq_get_freq_level(struct devfreq *devfreq, unsigned long freq) static int set_freq_table(struct devfreq *devfreq) { struct devfreq_dev_profile *profile = devfreq->profile; + struct devfreq_stats *stats; struct dev_pm_opp *opp; unsigned long freq; - int i, count; + int i, count, err = -ENOMEM; /* Initialize the freq_table from OPP table */ count = dev_pm_opp_get_opp_count(devfreq->dev.parent); if (count <= 0) return -EINVAL; - profile->max_state = count; - profile->freq_table = devm_kcalloc(devfreq->dev.parent, - count, - sizeof(*profile->freq_table), - GFP_KERNEL); - if (!profile->freq_table) { - profile->max_state = 0; + stats = devm_kzalloc(devfreq->dev.parent, + sizeof(struct devfreq_stats), GFP_KERNEL); + if (!stats) return -ENOMEM; - } - for (i = 0, freq = 0; i < profile->max_state; i++, freq++) { + profile->stats = stats; + stats->max_state = count; + stats->freq_table = devm_kcalloc(devfreq->dev.parent, + count, + sizeof(*stats->freq_table), + GFP_KERNEL); + if (!stats->freq_table) + goto err_no_mem; + + for (i = 0, freq = 0; i < count; i++, freq++) { opp = dev_pm_opp_find_freq_ceil(devfreq->dev.parent, &freq); if (IS_ERR(opp)) { - devm_kfree(devfreq->dev.parent, profile->freq_table); - profile->max_state = 0; - return PTR_ERR(opp); + devm_kfree(devfreq->dev.parent, stats->freq_table); + stats->max_state = 0; + err = PTR_ERR(opp); + goto err_no_mem; } dev_pm_opp_put(opp); - profile->freq_table[i] = freq; + stats->freq_table[i] = freq; } - profile->trans_table = devm_kzalloc(devfreq->dev.parent, - array3_size(sizeof(unsigned int), - count, count), - GFP_KERNEL); - if (!profile->trans_table) + stats->trans_table = devm_kzalloc(devfreq->dev.parent, + array3_size(sizeof(unsigned int), + count, count), + GFP_KERNEL); + if (!stats->trans_table) goto err_no_mem; - profile->time_in_state = devm_kcalloc(devfreq->dev.parent, count, - sizeof(*profile->time_in_state), - GFP_KERNEL); - if (!profile->time_in_state) + stats->time_in_state = devm_kcalloc(devfreq->dev.parent, count, + sizeof(*stats->time_in_state), + GFP_KERNEL); + if (!stats->time_in_state) goto err_no_mem; - profile->last_time = get_jiffies_64(); - spin_lock_init(&profile->stats_lock); + stats->last_time = get_jiffies_64(); + spin_lock_init(&stats->stats_lock); return 0; err_no_mem: - profile->max_state = 0; - return -ENOMEM; + stats->max_state = 0; + devm_kfree(devfreq->dev.parent, profile->stats); + profile->stats = NULL; + return err; } /** @@ -176,7 +185,7 @@ static int set_freq_table(struct devfreq *devfreq) */ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) { - struct devfreq_dev_profile *profile = devfreq->profile; + struct devfreq_stats *stats = devfreq->profile->stats; unsigned long long cur_time; int lev, prev_lev, ret = 0; @@ -184,22 +193,21 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) /* Immediately exit if previous_freq is not initialized yet. */ if (!devfreq->previous_freq) { - spin_lock(&profile->stats_lock); - profile->last_time = cur_time; - spin_unlock(&profile->stats_lock); + spin_lock(&stats->stats_lock); + stats->last_time = cur_time; + spin_unlock(&stats->stats_lock); return 0; } prev_lev = devfreq_get_freq_level(devfreq, devfreq->previous_freq); - spin_lock(&profile->stats_lock); + spin_lock(&stats->stats_lock); if (prev_lev < 0) { ret = prev_lev; goto out; } - profile->time_in_state[prev_lev] += - cur_time - profile->last_time; + stats->time_in_state[prev_lev] += cur_time - stats->last_time; lev = devfreq_get_freq_level(devfreq, freq); if (lev < 0) { ret = lev; @@ -207,14 +215,14 @@ int devfreq_update_status(struct devfreq *devfreq, unsigned long freq) } if (lev != prev_lev) { - profile->trans_table[(prev_lev * - profile->max_state) + lev]++; - profile->total_trans++; + stats->trans_table[(prev_lev * + stats->max_state) + lev]++; + stats->total_trans++; } out: - profile->last_time = cur_time; - spin_unlock(&profile->stats_lock); + stats->last_time = cur_time; + spin_unlock(&stats->stats_lock); return ret; } EXPORT_SYMBOL(devfreq_update_status); @@ -504,9 +512,9 @@ void devfreq_monitor_resume(struct devfreq *devfreq) queue_delayed_work(devfreq_wq, &devfreq->work, msecs_to_jiffies(profile->polling_ms)); - spin_lock(&profile->stats_lock); - profile->last_time = get_jiffies_64(); - spin_unlock(&profile->stats_lock); + spin_lock(&profile->stats->stats_lock); + profile->stats->last_time = get_jiffies_64(); + spin_unlock(&profile->stats->stats_lock); devfreq->stop_polling = false; if (profile->get_cur_freq && @@ -677,7 +685,7 @@ struct devfreq *devfreq_add_device(struct device *dev, devfreq->data = data; devfreq->nb.notifier_call = devfreq_notifier_call; - if (!profile->max_state && !profile->freq_table) { + if (!profile->stats) { mutex_unlock(&devfreq->lock); err = set_freq_table(devfreq); if (err < 0) @@ -1282,6 +1290,7 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct devfreq *df = to_devfreq(dev); + struct devfreq_stats *stats = df->profile->stats; unsigned long value; int ret; @@ -1297,13 +1306,13 @@ static ssize_t min_freq_store(struct device *dev, struct device_attribute *attr, goto unlock; } } else { - unsigned long *freq_table = df->profile->freq_table; + unsigned long *freq_table = stats->freq_table; /* Get minimum frequency according to sorting order */ - if (freq_table[0] < freq_table[df->profile->max_state - 1]) + if (freq_table[0] < freq_table[stats->max_state - 1]) value = freq_table[0]; else - value = freq_table[df->profile->max_state - 1]; + value = freq_table[stats->max_state - 1]; } df->min_freq = value; @@ -1326,6 +1335,7 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct devfreq *df = to_devfreq(dev); + struct devfreq_stats *stats = df->profile->stats; unsigned long value; int ret; @@ -1341,11 +1351,11 @@ static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr, goto unlock; } } else { - unsigned long *freq_table = df->profile->freq_table; + unsigned long *freq_table = stats->freq_table; /* Get maximum frequency according to sorting order */ - if (freq_table[0] < freq_table[df->profile->max_state - 1]) - value = freq_table[df->profile->max_state - 1]; + if (freq_table[0] < freq_table[stats->max_state - 1]) + value = freq_table[stats->max_state - 1]; else value = freq_table[0]; } @@ -1373,14 +1383,15 @@ static ssize_t available_frequencies_show(struct device *d, char *buf) { struct devfreq *df = to_devfreq(d); + struct devfreq_stats *stats = df->profile->stats; ssize_t count = 0; int i; mutex_lock(&df->lock); - for (i = 0; i < df->profile->max_state; i++) + for (i = 0; i < stats->max_state; i++) count += scnprintf(&buf[count], (PAGE_SIZE - count - 2), - "%lu ", df->profile->freq_table[i]); + "%lu ", stats->freq_table[i]); mutex_unlock(&df->lock); /* Truncate the trailing space */ @@ -1398,9 +1409,10 @@ static ssize_t trans_stat_show(struct device *dev, { struct devfreq *devfreq = to_devfreq(dev); struct devfreq_dev_profile *profile = devfreq->profile; + struct devfreq_stats *stats = profile->stats; + unsigned int max_state = stats->max_state; ssize_t len; int i, j; - unsigned int max_state = profile->max_state; if (!devfreq->stop_polling && devfreq_update_status(devfreq, devfreq->previous_freq)) @@ -1411,45 +1423,45 @@ static ssize_t trans_stat_show(struct device *dev, len = sprintf(buf, " From : To\n"); len += sprintf(buf + len, " :"); - spin_lock(&profile->stats_lock); + spin_lock(&stats->stats_lock); for (i = 0; i < max_state; i++) len += sprintf(buf + len, "%10lu", - profile->freq_table[i]); + stats->freq_table[i]); len += sprintf(buf + len, " time(ms)\n"); for (i = 0; i < max_state; i++) { - if (profile->freq_table[i] == devfreq->previous_freq) + if (stats->freq_table[i] == devfreq->previous_freq) len += sprintf(buf + len, "*"); else len += sprintf(buf + len, " "); len += sprintf(buf + len, "%10lu:", - profile->freq_table[i]); + stats->freq_table[i]); for (j = 0; j < max_state; j++) len += sprintf(buf + len, "%10u", - profile->trans_table[(i * max_state) + j]); + stats->trans_table[(i * max_state) + j]); len += sprintf(buf + len, "%10llu\n", (u64) - jiffies64_to_msecs(profile->time_in_state[i])); + jiffies64_to_msecs(stats->time_in_state[i])); } len += sprintf(buf + len, "Total transition : %u\n", - profile->total_trans); - spin_unlock(&profile->stats_lock); + stats->total_trans); + spin_unlock(&stats->stats_lock); return len; } static DEVICE_ATTR_RO(trans_stat); -static void defvreq_stats_clear_table(struct devfreq_dev_profile *profile) +static void defvreq_stats_clear_table(struct devfreq_stats *stats) { - unsigned int count = profile->max_state; - - spin_lock(&profile->stats_lock); - memset(profile->time_in_state, 0, count * sizeof(u64)); - memset(profile->trans_table, 0, count * count * sizeof(int)); - profile->last_time = get_jiffies_64(); - profile->total_trans = 0; - spin_unlock(&profile->stats_lock); + unsigned int count = stats->max_state; + + spin_lock(&stats->stats_lock); + memset(stats->time_in_state, 0, count * sizeof(u64)); + memset(stats->trans_table, 0, count * count * sizeof(int)); + stats->last_time = get_jiffies_64(); + stats->total_trans = 0; + spin_unlock(&stats->stats_lock); } static ssize_t trans_reset_store(struct device *dev, @@ -1459,7 +1471,7 @@ static ssize_t trans_reset_store(struct device *dev, { struct devfreq *devfreq = to_devfreq(dev); - defvreq_stats_clear_table(devfreq->profile); + defvreq_stats_clear_table(devfreq->profile->stats); return count; } diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c index d9f377912c10..b212aae2bb3e 100644 --- a/drivers/devfreq/exynos-bus.c +++ b/drivers/devfreq/exynos-bus.c @@ -496,9 +496,9 @@ static int exynos_bus_probe(struct platform_device *pdev) } out: - max_state = bus->devfreq->profile->max_state; - min_freq = (bus->devfreq->profile->freq_table[0] / 1000); - max_freq = (bus->devfreq->profile->freq_table[max_state - 1] / 1000); + max_state = profile->stats->max_state; + min_freq = (profile->stats->freq_table[0] / 1000); + max_freq = (profile->stats->freq_table[max_state - 1] / 1000); pr_info("exynos-bus: new bus device registered: %s (%6ld KHz ~ %6ld KHz)\n", dev_name(dev), min_freq, max_freq); diff --git a/drivers/devfreq/governor_passive.c b/drivers/devfreq/governor_passive.c index 58308948b863..b2d87a88335c 100644 --- a/drivers/devfreq/governor_passive.c +++ b/drivers/devfreq/governor_passive.c @@ -18,6 +18,8 @@ static int devfreq_passive_get_target_freq(struct devfreq *devfreq, struct devfreq_passive_data *p_data = (struct devfreq_passive_data *)devfreq->data; struct devfreq *parent_devfreq = (struct devfreq *)p_data->parent; + struct devfreq_stats *parent_stats = parent_devfreq->profile->stats; + struct devfreq_stats *stats; unsigned long child_freq = ULONG_MAX; struct dev_pm_opp *opp; int i, count, ret = 0; @@ -47,10 +49,14 @@ static int devfreq_passive_get_target_freq(struct devfreq *devfreq, * device. And then the index is used for getting the suitable * new frequency for passive devfreq device. */ - if (!devfreq->profile || !devfreq->profile->freq_table - || devfreq->profile->max_state <= 0) + if (!devfreq->profile || !devfreq->profile->stats || + devfreq->profile->stats->max_state <= 0 || + !parent_devfreq->profile || !parent_devfreq->profile->stats || + parent_devfreq->profile->stats->max_state <= 0) return -EINVAL; + stats = devfreq->profile->stats; + parent_stats = parent_devfreq->profile->stats; /* * The passive governor have to get the correct frequency from OPP * list of parent device. Because in this case, *freq is temporary @@ -68,21 +74,21 @@ static int devfreq_passive_get_target_freq(struct devfreq *devfreq, * Get the OPP table's index of decided freqeuncy by governor * of parent device. */ - for (i = 0; i < parent_devfreq->profile->max_state; i++) - if (parent_devfreq->profile->freq_table[i] == *freq) + for (i = 0; i < parent_stats->max_state; i++) + if (parent_stats->freq_table[i] == *freq) break; - if (i == parent_devfreq->profile->max_state) { + if (i == parent_stats->max_state) { ret = -EINVAL; goto out; } /* Get the suitable frequency by using index of parent device. */ - if (i < devfreq->profile->max_state) { - child_freq = devfreq->profile->freq_table[i]; + if (i < stats->max_state) { + child_freq = stats->freq_table[i]; } else { - count = devfreq->profile->max_state; - child_freq = devfreq->profile->freq_table[count - 1]; + count = stats->max_state; + child_freq = stats->freq_table[count - 1]; } /* Return the suitable frequency for passive device. */ @@ -109,7 +115,7 @@ static int update_devfreq_passive(struct devfreq *devfreq, unsigned long freq) if (ret < 0) goto out; - if (devfreq->profile->freq_table + if (devfreq->profile->stats && (devfreq_update_status(devfreq, freq))) dev_err(&devfreq->dev, "Couldn't update frequency transition information.\n"); diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index 4ceb2a517a9c..8459af1a1583 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -64,6 +64,30 @@ struct devfreq_dev_status { */ #define DEVFREQ_FLAG_LEAST_UPPER_BOUND 0x1 +/** + * struct devfreq_stats - Devfreq's transitions stats counters + * @freq_table: Optional list of frequencies to support statistics + * and freq_table must be generated in ascending order. + * @max_state: The size of freq_table. + * @total_trans: Number of devfreq transitions + * @trans_table: Statistics of devfreq transitions + * @time_in_state: Statistics of devfreq states + * @last_time: The last time stats were updated + * @stats_lock: Lock protecting trans_table, time_in_state, + * last_time and total_trans used for statistics + */ +struct devfreq_stats { + unsigned long *freq_table; + unsigned int max_state; + + /* information for device frequency transition */ + unsigned int total_trans; + unsigned int *trans_table; + u64 *time_in_state; + unsigned long long last_time; + spinlock_t stats_lock; +}; + /** * struct devfreq_dev_profile - Devfreq's user device profile * @initial_freq: The operating frequency when devfreq_add_device() is @@ -88,15 +112,7 @@ struct devfreq_dev_status { * from devfreq_remove_device() call. If the user * has registered devfreq->nb at a notifier-head, * this is the time to unregister it. - * @freq_table: Optional list of frequencies to support statistics - * and freq_table must be generated in ascending order. - * @max_state: The size of freq_table. - * @total_trans: Number of devfreq transitions - * @trans_table: Statistics of devfreq transitions - * @time_in_state: Statistics of devfreq states - * @last_time: The last time stats were updated - * @stats_lock: Lock protecting trans_table, time_in_state, - * last_time and total_trans used for statistics + * @stats: Statistics of devfreq states and state transitions */ struct devfreq_dev_profile { unsigned long initial_freq; @@ -108,14 +124,7 @@ struct devfreq_dev_profile { int (*get_cur_freq)(struct device *dev, unsigned long *freq); void (*exit)(struct device *dev); - unsigned long *freq_table; - unsigned int max_state; - /* information for device frequency transition */ - unsigned int total_trans; - unsigned int *trans_table; - u64 *time_in_state; - unsigned long long last_time; - spinlock_t stats_lock; + struct devfreq_stats *stats; }; /**