From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D9D4C47DB3 for ; Wed, 31 Jan 2024 14:29:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tJEwY5+K9gfqYYPXw8OLORQyFhebBiDBLTnGKZtZBoU=; b=C/yEEZ77cZEBg9 Jdhj3GUhlLy+ygTfzveov+6IA+CEvqng9tVbGLeqam4C3h1C22RIr2bAfu8DpXpG6/CmEFM5NWxYk okaDV0X3QycyI2eQ6n72FGl+aFBylX1L69NmDEVePd12sf+l1IqD6BKR6bFC6T+qyHrSPuJQPemDR vERj3BDStClDSV3kr3VUcFEPX5g6XAIJSJVavAfw/K8EyC4j9FbP2OP2T0X7jpnEuSwqehYowEVVm 2oOpT3QupjlYobECzLE9+kDWhHpdFl/G2xSvtLtkGAiBhIqwF26U3y5O5pv8smZvEqyKFDoAy7Q4w Sn5w/su0L5ZyfEFYYhTw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVBax-00000003thY-0dmD; Wed, 31 Jan 2024 14:29:43 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVBao-00000003teE-3YwW for linux-arm-kernel@lists.infradead.org; Wed, 31 Jan 2024 14:29:36 +0000 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 6F6E5DA7; Wed, 31 Jan 2024 06:30:13 -0800 (PST) Received: from [10.34.100.129] (e126645.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6948D3F738; Wed, 31 Jan 2024 06:29:28 -0800 (PST) Message-ID: <512d7296-2706-4779-b475-fbf2d208e282@arm.com> Date: Wed, 31 Jan 2024 15:29:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH V2 4/4] cpufreq: scmi: Register for limit change notifications Content-Language: en-US To: Sibi Sankar Cc: linux-arm-kernel@lists.infradead.org, sudeep.holla@arm.com, linux-pm@vger.kernel.org, cristian.marussi@arm.com, linux-kernel@vger.kernel.org, rafael@kernel.org, viresh.kumar@linaro.org, quic_mdtipton@quicinc.com, lukasz.luba@arm.com, linux-arm-msm@vger.kernel.org, dietmar.eggemann@arm.com, morten.rasmussen@arm.com References: <20240117104116.2055349-1-quic_sibis@quicinc.com> <20240117104116.2055349-5-quic_sibis@quicinc.com> From: Pierre Gondois In-Reply-To: <20240117104116.2055349-5-quic_sibis@quicinc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_062935_031409_0BDF2774 X-CRM114-Status: GOOD ( 21.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hello Sibi, On 1/17/24 11:41, Sibi Sankar wrote: > Register for limit change notifications if supported with the help of > perf_notify_support interface and determine the throttled frequency > using the perf_freq_xlate to apply HW pressure. > > Signed-off-by: Sibi Sankar > --- > > v2: > * Export cpufreq_update_pressure and use it directly [Lukasz] > > drivers/cpufreq/scmi-cpufreq.c | 42 +++++++++++++++++++++++++++++++++- > 1 file changed, 41 insertions(+), 1 deletion(-) > > diff --git a/drivers/cpufreq/scmi-cpufreq.c b/drivers/cpufreq/scmi-cpufreq.c > index 4ee23f4ebf4a..e0aa85764451 100644 > --- a/drivers/cpufreq/scmi-cpufreq.c > +++ b/drivers/cpufreq/scmi-cpufreq.c > @@ -25,9 +25,13 @@ struct scmi_data { > int domain_id; > int nr_opp; > struct device *cpu_dev; > + struct cpufreq_policy *policy; > cpumask_var_t opp_shared_cpus; > + struct notifier_block limit_notify_nb; > }; > > +const struct scmi_handle *handle; > +static struct scmi_device *scmi_dev; > static struct scmi_protocol_handle *ph; > static const struct scmi_perf_proto_ops *perf_ops; > > @@ -144,6 +148,22 @@ scmi_get_cpu_power(struct device *cpu_dev, unsigned long *power, > return 0; > } > > +static int scmi_limit_notify_cb(struct notifier_block *nb, unsigned long event, void *data) > +{ > + unsigned long freq_hz; > + struct scmi_perf_limits_report *limit_notify = data; > + struct scmi_data *priv = container_of(nb, struct scmi_data, limit_notify_nb); > + struct cpufreq_policy *policy = priv->policy; > + > + if (perf_ops->perf_freq_xlate(ph, priv->domain_id, limit_notify->range_max, &freq_hz)) > + return NOTIFY_OK; > + > + policy->max = freq_hz / HZ_PER_KHZ; Maybe 'policy->max' should be checked. The limits received by SCMI is blindly trusted. This might be ok, but could also lead to some inconsistency. The scmi_cpufreq_driver's verify() callback could be used. --- I think there might also be corner cases where the SCP might advertise the maximum boosted frequency as the max limit, but boosting might not be enabled on the kernel side. So I think this should be checked when setting 'policy->max', Regards, Pierre > + cpufreq_update_pressure(policy); > + > + return NOTIFY_OK; > +} > + > static int scmi_cpufreq_init(struct cpufreq_policy *policy) > { > int ret, nr_opp, domain; > @@ -151,6 +171,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy) > struct device *cpu_dev; > struct scmi_data *priv; > struct cpufreq_frequency_table *freq_table; > + struct scmi_perf_notify_info info = {}; > > cpu_dev = get_cpu_device(policy->cpu); > if (!cpu_dev) { > @@ -250,6 +271,25 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy) > policy->fast_switch_possible = > perf_ops->fast_switch_possible(ph, domain); > > + ret = perf_ops->perf_notify_support(ph, domain, &info); > + if (ret) > + dev_warn(cpu_dev, "failed to get supported notifications: %d\n", ret); > + > + if (info.perf_limit_notify) { > + priv->limit_notify_nb.notifier_call = scmi_limit_notify_cb; > + ret = handle->notify_ops->devm_event_notifier_register(scmi_dev, SCMI_PROTOCOL_PERF, > + SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED, > + &domain, > + &priv->limit_notify_nb); > + if (ret) { > + dev_err(cpu_dev, "Error in registering limit change notifier for domain %d\n", > + domain); > + return ret; > + } > + } > + > + priv->policy = policy; > + > return 0; > > out_free_opp: > @@ -321,8 +361,8 @@ static int scmi_cpufreq_probe(struct scmi_device *sdev) > { > int ret; > struct device *dev = &sdev->dev; > - const struct scmi_handle *handle; > > + scmi_dev = sdev; > handle = sdev->handle; > > if (!handle) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel