From nobody Wed Oct 1 23:35:08 2025 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E26C626560D; Mon, 29 Sep 2025 07:48:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759132084; cv=pass; b=opg2b5joI9y3UjlsZkmlNMFGJyilRc9zhoy4Pno1L7FjLrCKTDoLMi5xjU49zgmYXAtPv/gyGHjbb8+iSPVAEkn55B81UvEXT7qrINNPb1KYBbVCFLeJi0fxFQUMQPtGxmfwItCjGjhonE0G9s0tIfYr370mJ27q6rD0GhD8nWk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759132084; c=relaxed/simple; bh=J+S5dkYsvaXSvVoWJtH+qdatS47qSJPWCgwwNDAH91E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uMdVfM116RKBh41ba8KSE6QwR32EZDN2HtGP2snVJxKxy8us1YJ+thAtNPfrK6fe63420hchUF+5S4QXGEP83gT9oSdozcxFAVZkaxwyAiaxyQbM8dKDiAcgJjcFNVKIs3vRpgJrjf4+fFNWTwxqi+sKra/6GGRnMa7Ohb9QGAc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b=AIwG7z87; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=collabora.com header.i=nicolas.frattaroli@collabora.com header.b="AIwG7z87" ARC-Seal: i=1; a=rsa-sha256; t=1759132063; cv=none; d=zohomail.com; s=zohoarc; b=FUz8zp72Tt7pw5iAyypUQjqVT7b99p+SZ0yoghJ1sXdtytkowKAQY+eDRB+unU/+vr9L8/tNDhHm8QLLTGpjI9GqU+Jz6DlmsuHAhN9RYc+ojqeKpYzehT4FEZqMl8xqo/JPfacpd+XNcgwmPpal+YVCg2zMx4u0o06LR3Vf1Qg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759132063; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=UxZvjhEJCAiuvf/8CnR5ujZ+N4d9oN5GgfPWk3NAFVg=; b=YNGlsFp9yR5OIyDyGrngsXOMW2Jn4777VRiQza+D632jT1mUe9HGHjL5N/QuiRQGIKVxq97UwT8y3MLuw73fmZpRF0PwSKxUUnsPoCkkc/Dz7Yzgd/m0eNrXN7/OashHtM2z0+0reTklgS1P2iEEiQzA8VhR1MA9pLb10VLgAcs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1759132063; s=zohomail; d=collabora.com; i=nicolas.frattaroli@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=UxZvjhEJCAiuvf/8CnR5ujZ+N4d9oN5GgfPWk3NAFVg=; b=AIwG7z87z64hZCBzwbH+Scv7mkuLgo1PBvodZhjEKzi2DjJfAK/4xY86c7zsFc9+ ye+oJvZlJpMIe0CPcxh3Kqpa1ktuaFd+h2ppBjax4tI32f4XPOVAcSWHl95IkSGyCsT A6sE3SgfD/DNcapFVr9Hdwq3LnTF8uE1jWFHrJvM= Received: by mx.zohomail.com with SMTPS id 1759132061411582.1664225473443; Mon, 29 Sep 2025 00:47:41 -0700 (PDT) From: Nicolas Frattaroli Date: Mon, 29 Sep 2025 09:46:48 +0200 Subject: [PATCH v5 5/7] drm/panthor: call into devfreq for current frequency Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250929-mt8196-gpufreq-v5-5-3056e5ecf765@collabora.com> References: <20250929-mt8196-gpufreq-v5-0-3056e5ecf765@collabora.com> In-Reply-To: <20250929-mt8196-gpufreq-v5-0-3056e5ecf765@collabora.com> To: AngeloGioacchino Del Regno , Boris Brezillon , Jassi Brar , Chia-I Wu , Chen-Yu Tsai , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Brugger , Kees Cook , "Gustavo A. R. Silva" , Ulf Hansson Cc: kernel@collabora.com, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-hardening@vger.kernel.org, linux-pm@vger.kernel.org, Nicolas Frattaroli X-Mailer: b4 0.14.2 As it stands, panthor keeps a cached current frequency value for when it wants to retrieve it. This doesn't work well for when things might switch frequency without panthor's knowledge. Instead, implement the get_cur_freq operation, and expose it through a helper function to the rest of panthor. Reviewed-by: Steven Price Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Nicolas Frattaroli --- drivers/gpu/drm/panthor/panthor_devfreq.c | 33 +++++++++++++++++++++++++++= ---- drivers/gpu/drm/panthor/panthor_devfreq.h | 2 ++ drivers/gpu/drm/panthor/panthor_device.h | 3 --- drivers/gpu/drm/panthor/panthor_drv.c | 4 +++- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_devfreq.c b/drivers/gpu/drm/pa= nthor/panthor_devfreq.c index 3686515d368db5bb329f4858d4a7247a4957cc24..8903f60c0a3f06313ac2008791c= 210ff32b6bd52 100644 --- a/drivers/gpu/drm/panthor/panthor_devfreq.c +++ b/drivers/gpu/drm/panthor/panthor_devfreq.c @@ -62,7 +62,6 @@ static void panthor_devfreq_update_utilization(struct pan= thor_devfreq *pdevfreq) static int panthor_devfreq_target(struct device *dev, unsigned long *freq, u32 flags) { - struct panthor_device *ptdev =3D dev_get_drvdata(dev); struct dev_pm_opp *opp; int err; =20 @@ -72,8 +71,6 @@ static int panthor_devfreq_target(struct device *dev, uns= igned long *freq, dev_pm_opp_put(opp); =20 err =3D dev_pm_opp_set_rate(dev, *freq); - if (!err) - ptdev->current_frequency =3D *freq; =20 return err; } @@ -115,11 +112,21 @@ static int panthor_devfreq_get_dev_status(struct devi= ce *dev, return 0; } =20 +static int panthor_devfreq_get_cur_freq(struct device *dev, unsigned long = *freq) +{ + struct panthor_device *ptdev =3D dev_get_drvdata(dev); + + *freq =3D clk_get_rate(ptdev->clks.core); + + return 0; +} + static struct devfreq_dev_profile panthor_devfreq_profile =3D { .timer =3D DEVFREQ_TIMER_DELAYED, .polling_ms =3D 50, /* ~3 frames */ .target =3D panthor_devfreq_target, .get_dev_status =3D panthor_devfreq_get_dev_status, + .get_cur_freq =3D panthor_devfreq_get_cur_freq, }; =20 int panthor_devfreq_init(struct panthor_device *ptdev) @@ -198,7 +205,6 @@ int panthor_devfreq_init(struct panthor_device *ptdev) return PTR_ERR(opp); =20 panthor_devfreq_profile.initial_freq =3D cur_freq; - ptdev->current_frequency =3D cur_freq; =20 /* * Set the recommend OPP this will enable and configure the regulator @@ -296,3 +302,22 @@ void panthor_devfreq_record_idle(struct panthor_device= *ptdev) =20 spin_unlock_irqrestore(&pdevfreq->lock, irqflags); } + +unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev) +{ + struct panthor_devfreq *pdevfreq =3D ptdev->devfreq; + unsigned long freq =3D 0; + int ret; + + if (!pdevfreq || !pdevfreq->devfreq) + return 0; + + if (pdevfreq->devfreq->profile->get_cur_freq) { + ret =3D pdevfreq->devfreq->profile->get_cur_freq(ptdev->base.dev, + &freq); + if (ret) + return 0; + } + + return freq; +} diff --git a/drivers/gpu/drm/panthor/panthor_devfreq.h b/drivers/gpu/drm/pa= nthor/panthor_devfreq.h index b7631de695f7d79456478c87e8af5dc47673cd1d..f8e29e02f66cb3281ed4bb4c75c= da9bd4df82b92 100644 --- a/drivers/gpu/drm/panthor/panthor_devfreq.h +++ b/drivers/gpu/drm/panthor/panthor_devfreq.h @@ -18,4 +18,6 @@ void panthor_devfreq_suspend(struct panthor_device *ptdev= ); void panthor_devfreq_record_busy(struct panthor_device *ptdev); void panthor_devfreq_record_idle(struct panthor_device *ptdev); =20 +unsigned long panthor_devfreq_get_freq(struct panthor_device *ptdev); + #endif /* __PANTHOR_DEVFREQ_H__ */ diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/pan= thor/panthor_device.h index 9f0649ecfc4fc697a21a8b2fc4dd89c8ecf298df..f32c1868bf6d782d99df9dbd0ba= bcea049c917e0 100644 --- a/drivers/gpu/drm/panthor/panthor_device.h +++ b/drivers/gpu/drm/panthor/panthor_device.h @@ -214,9 +214,6 @@ struct panthor_device { /** @profile_mask: User-set profiling flags for job accounting. */ u32 profile_mask; =20 - /** @current_frequency: Device clock frequency at present. Set by DVFS*/ - unsigned long current_frequency; - /** @fast_rate: Maximum device clock frequency. Set by DVFS */ unsigned long fast_rate; =20 diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/pantho= r/panthor_drv.c index ea4a37b566a8b215f2b7a09c333a696f1dcdb58f..4d59d94c353c3ca76f4b98a411c= 8f8284efafd08 100644 --- a/drivers/gpu/drm/panthor/panthor_drv.c +++ b/drivers/gpu/drm/panthor/panthor_drv.c @@ -25,6 +25,7 @@ #include #include =20 +#include "panthor_devfreq.h" #include "panthor_device.h" #include "panthor_fw.h" #include "panthor_gem.h" @@ -1519,7 +1520,8 @@ static void panthor_gpu_show_fdinfo(struct panthor_de= vice *ptdev, drm_printf(p, "drm-cycles-panthor:\t%llu\n", pfile->stats.cycles); =20 drm_printf(p, "drm-maxfreq-panthor:\t%lu Hz\n", ptdev->fast_rate); - drm_printf(p, "drm-curfreq-panthor:\t%lu Hz\n", ptdev->current_frequency); + drm_printf(p, "drm-curfreq-panthor:\t%lu Hz\n", + panthor_devfreq_get_freq(ptdev)); } =20 static void panthor_show_internal_memory_stats(struct drm_printer *p, stru= ct drm_file *file) --=20 2.51.0