Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp815241lqj; Mon, 3 Jun 2024 01:14:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWNbLkyE++ciHUgqKBuJK4sSn3dIojHrAMBzCXnbr9j3rmrCj46SC8HZ3QSOTnGuQ2Nk2RFMlsTyetY8sFN99BFNB4V7FrdbsexknJZZA== X-Google-Smtp-Source: AGHT+IH4BTxfkoWvs5oJ3RYmhSm9t+V1Po9IF4gv+rgfhhWRwGFHJokm0VWjJ3EPrMn+jXv7QPOv X-Received: by 2002:a05:6a00:3908:b0:702:4077:97f4 with SMTP id d2e1a72fcca58-702478c8226mr10060478b3a.30.1717402498887; Mon, 03 Jun 2024 01:14:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717402498; cv=pass; d=google.com; s=arc-20160816; b=0jZQMgwlGLMa39q8/NVFguV4OTEEASJLtUVA4Nn3bECefK74tgzkgzzZGuIlVGnetF 5T7XPsYgZTfuCeNDjNrifB1BnL+IBLcCbL8o8hd5SNDxXYTClqkwGpkFLbMCeKAw7hKr N3aKdQHpDWbvVdwP2MZLLOHRbJFphD1vyC+aLkRb9VOuv0It8bIUtxEcCDtUaONBWLXa y2HGDNFncqjSYIYWnA3XIdixtW26Z3yKv1GIB8vI1RnZQoLzOIm8ZOg7jDtKLsDUukK9 I1MqLuhLtXXS8siYeS29hfN7mTzlahm3hpttSR2iv76m1jRr518xmzzBmV/BVFGpOAdB +8hg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=4/46y5p8VlsP4/VvYwSgcz6uXuh0tlOn0EcrIjW9cGs=; fh=AyitRlTZz0zWOkaDgeQ/rtFeXpBx8yIFdX4+bmn696s=; b=uwweomG/P7ec004uzYdgQ2nAtAEzjPF5A8OaFTrPKru8ygeBADv+rj5EZS8QFYIKj1 FcMhqt5N+0RuUo+Ho5igQIL2Xb/lgUCBHc2+ytnzk24E9Ojp19GasEReCkrktl6UKD5g AstUjYt3qkI9ei0ymIWcBiEIutuwN7Ev8Koe0GHtLQOtA7HqymNZ+X4HazXD+N7EOiUx ZHR9hBGuz3HL44sdo/+5F0wVSNAGfjTWH8YpSOBSsiUvywUasRAAyBMjPvhObRg0qpUZ I0yPjyD4Lt+BZl/ZuNaMDNe2gVxCLFuE4To/P1vvswCvYgz5yV1Xt7rYQz0O+RhfogRJ dMhA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-198761-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198761-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-7025b9b462dsi3433433b3a.208.2024.06.03.01.14.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 01:14:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198761-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-198761-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198761-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9318CB22248 for ; Mon, 3 Jun 2024 08:14:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 72B566F073; Mon, 3 Jun 2024 08:13:56 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2C8D59B4A; Mon, 3 Jun 2024 08:13:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717402436; cv=none; b=td64iQUSC3WsLSyD1+I0+qw8TIzOXpre68BEnsGvDXc7vGFTzym4EavgTi6mivsHDs6QSCuizdY7AfJQ+Dw2Mkh1Bnt4Gl6/+9oWkx0N3HQN7JSBEDRfLbQ4EjfoZ/ILjwh2nVsa1pCftiD1308APHmmw+62RR7Z4hBEdxZZ2eE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717402436; c=relaxed/simple; bh=yhcFTKDrrJswRkQGSVNrK7EEevy1VSzs20U97xZ+xfQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l/XsAiyBiLS7QwBNM8f7Hkapk9wkHk7tpnfqKWEb1jxO3+m/PXEfbUkKUA4A0lrqLiPX72zbwpb2PdxGV8ABD2V+PFevAdYuYbBqv5axLYO9gj2ssTDVCtItgrNqgacI5ztmTvDGpx0Bpx3FZ8DhglwO2IYKRoKdJbsioMfbMVE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7EE381063; Mon, 3 Jun 2024 01:14:17 -0700 (PDT) Received: from e125905.cambridge.arm.com (e125905.cambridge.arm.com [10.1.194.73]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 150D33F792; Mon, 3 Jun 2024 01:13:51 -0700 (PDT) From: Beata Michalska To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rafael@kernel.org, viresh.kumar@linaro.org, len.brown@intel.com Cc: ionela.voinescu@arm.com, vanshikonda@os.amperecomputing.com, sumitg@nvidia.com Subject: [PATCH 1/1] cpufreq: Rewire arch specific feedback for cpuinfo/scaling_cur_freq Date: Mon, 3 Jun 2024 09:13:31 +0100 Message-Id: <20240603081331.3829278-2-beata.michalska@arm.com> In-Reply-To: <20240603081331.3829278-1-beata.michalska@arm.com> References: <20240603081331.3829278-1-beata.michalska@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Some architectures provide a way to determine an average frequency over a certain period of time, based on available performance monitors (AMU on ARM or APERF/MPERf on x86). With those at hand, enroll arch_freq_get_on_cpu into cpuinfo_cur_freq policy sysfs attribute handler, which is expected to represent the current frequency of a given CPU,as obtained by the hardware. This is the type of feedback that counters do provide. At the same time, keep the scaling_cur_freq attribute align with the docs and make it provide most recently requested frequency, still allowing to fallback to using arch_freq_get_on_cpu for cases when cpuinfo_cur_freq is not available. Signed-off-by: Beata Michalska --- drivers/cpufreq/cpufreq.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index a45aac17c20f..3b0eabe4a983 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -758,7 +758,8 @@ static ssize_t show_scaling_cur_freq(struct cpufreq_policy *policy, char *buf) ssize_t ret; unsigned int freq; - freq = arch_freq_get_on_cpu(policy->cpu); + freq = !cpufreq_driver->get ? arch_freq_get_on_cpu(policy->cpu) + : 0; if (freq) ret = sprintf(buf, "%u\n", freq); else if (cpufreq_driver->setpolicy && cpufreq_driver->get) @@ -795,7 +796,10 @@ store_one(scaling_max_freq, max); static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy, char *buf) { - unsigned int cur_freq = __cpufreq_get(policy); + unsigned int cur_freq = arch_freq_get_on_cpu(policy->cpu); + + if (!cur_freq) + cur_freq = __cpufreq_get(policy); if (cur_freq) return sprintf(buf, "%u\n", cur_freq); -- 2.25.1