All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/amdgpu: add ptl_format module parameter
@ 2026-11-23  7:22 Perry Yuan
  2026-11-23  7:22 ` [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock Perry Yuan
  2026-11-24  2:59 ` [PATCH 1/2] drm/amdgpu: add ptl_format module parameter Zhang, Yifan
  0 siblings, 2 replies; 5+ messages in thread
From: Perry Yuan @ 2026-11-23  7:22 UTC (permalink / raw)
  To: amd-gfx; +Cc: Alexander.Deucher, Christian.Koenig, Yifan1.Zhang, perry.yuan

PTL always starts with VECTOR,F8 at driver load. Users who need other
formats have to rewrite the ptl_format sysfs file after every boot,
and that file only accepts writes once PTL is enabled.

Add an amdgpu.ptl_format module parameter that takes "FMT1,FMT2", for
example ptl_format=F8,BF16. The formats are applied on the first PTL
initialization; resume and reset keep using the cached formats as
before. An invalid value is reported and the VECTOR,F8 defaults are
kept.

Move the format parsing out of ptl_format_store() into
amdgpu_ptl_parse_formats() so the sysfs file and the module parameter
share the same validation.

Signed-off-by: Perry Yuan <perry.yuan@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h      |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c  | 10 +++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c  | 34 +++++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c  | 14 +++++++++-
 drivers/gpu/drm/amd/include/amdgpu_ptl.h |  3 +++
 5 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index a7a2b6b5a497..53eb4824f922 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -270,6 +270,7 @@ extern int amdgpu_rebar;
 extern int amdgpu_wbrf;
 extern int amdgpu_user_queue;
 extern int amdgpu_ptl;
+extern char *amdgpu_ptl_format;
 
 extern uint amdgpu_hdmi_hpd_debounce_delay_ms;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 6478506d8089..5b366fc910ae 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -254,6 +254,7 @@ int amdgpu_rebar = -1; /* auto */
 int amdgpu_user_queue = -1;
 uint amdgpu_hdmi_hpd_debounce_delay_ms;
 int amdgpu_ptl = -1; /* auto */
+char *amdgpu_ptl_format;
 
 DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
 			"DRM_UT_CORE",
@@ -1183,6 +1184,15 @@ module_param_named(hdmi_hpd_debounce_delay_ms, amdgpu_hdmi_hpd_debounce_delay_ms
 MODULE_PARM_DESC(ptl, "Enable PTL (-1 = auto, 0 = disable (default), 1 = enable, 2 = permanently disable)");
 module_param_named(ptl, amdgpu_ptl, int, 0444);
 
+/**
+ * DOC: ptl_format (charp)
+ * PTL preferred formats applied at driver load, as "FMT1,FMT2"
+ * (e.g. "F8,BF16"). Supported formats: I8, F16, BF16, F32, F64, F8,
+ * VECTOR. The two formats must differ. Default is VECTOR,F8.
+ */
+MODULE_PARM_DESC(ptl_format, "PTL formats at load, \"FMT1,FMT2\" (default VECTOR,F8)");
+module_param_named(ptl_format, amdgpu_ptl_format, charp, 0444);
+
 /* These devices are not supported by amdgpu.
  * They are supported by the mach64, r128, radeon drivers
  */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index c19600f8b7f8..09648b68d066 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -1880,6 +1880,26 @@ static enum amdgpu_ptl_fmt str_to_ptl_fmt(const char *str)
 	return AMDGPU_PTL_FMT_INVALID;
 }
 
+int amdgpu_ptl_parse_formats(const char *buf, enum amdgpu_ptl_fmt *fmt1,
+		enum amdgpu_ptl_fmt *fmt2)
+{
+	char fmt1_str[8], fmt2_str[8];
+	enum amdgpu_ptl_fmt f1, f2;
+
+	if (sscanf(buf, "%7[^,],%7s", fmt1_str, fmt2_str) != 2)
+		return -EINVAL;
+
+	f1 = str_to_ptl_fmt(fmt1_str);
+	f2 = str_to_ptl_fmt(fmt2_str);
+	if (f1 >= AMDGPU_PTL_FMT_INVALID || f2 >= AMDGPU_PTL_FMT_INVALID ||
+	    f1 == f2)
+		return -EINVAL;
+
+	*fmt1 = f1;
+	*fmt2 = f2;
+	return 0;
+}
+
 static ssize_t ptl_supported_formats_show(struct device *dev,
 		struct device_attribute *attr, char *buf)
 {
@@ -1979,7 +1999,6 @@ static ssize_t ptl_format_store(struct device *dev,
 {
 	struct drm_device *ddev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = drm_to_adev(ddev);
-	char fmt1_str[8], fmt2_str[8];
 	enum amdgpu_ptl_fmt fmt1_enum, fmt2_enum;
 	struct amdgpu_ptl *ptl = &adev->psp.ptl;
 	uint32_t ptl_state, fmt1, fmt2;
@@ -1990,18 +2009,7 @@ static ssize_t ptl_format_store(struct device *dev,
 		return -EPERM;
 
 	mutex_lock(&ptl->mutex);
-	/* Parse input, expecting "FMT1,FMT2" */
-	if (sscanf(buf, "%7[^,],%7s", fmt1_str, fmt2_str) != 2) {
-		mutex_unlock(&ptl->mutex);
-		return -EINVAL;
-	}
-
-	fmt1_enum = str_to_ptl_fmt(fmt1_str);
-	fmt2_enum = str_to_ptl_fmt(fmt2_str);
-
-	if (fmt1_enum >= AMDGPU_PTL_FMT_INVALID ||
-			fmt2_enum >= AMDGPU_PTL_FMT_INVALID ||
-			fmt1_enum == fmt2_enum) {
+	if (amdgpu_ptl_parse_formats(buf, &fmt1_enum, &fmt2_enum)) {
 		mutex_unlock(&ptl->mutex);
 		return -EINVAL;
 	}
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
index b789f528f3b0..0cf13e78b821 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
@@ -2454,14 +2454,26 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool ena
 		return -EOPNOTSUPP;
 
 	if (ptl->hw_supported_state == AMDGPU_PTL_HW_UNINIT) {
+		enum amdgpu_ptl_fmt f1, f2;
+
 		fmt1 = GFX_FTYPE_VECTOR;
 		fmt2 = GFX_FTYPE_F8;
+		if (amdgpu_ptl_format) {
+			if (!amdgpu_ptl_parse_formats(amdgpu_ptl_format, &f1, &f2)) {
+				fmt1 = f1;
+				fmt2 = f2;
+			} else {
+				dev_warn(adev->dev,
+					 "Invalid amdgpu.ptl_format=%s, using VECTOR,F8\n",
+					 amdgpu_ptl_format);
+			}
+		}
 	} else {
 		fmt1 = ptl->fmt1;
 		fmt2 = ptl->fmt2;
 	}
 
-	/* initialize PTL with default formats: GFX_FTYPE_VECTOR & GFX_FTYPE_F8 */
+	/* Defaults or amdgpu.ptl_format on first init, cached formats after */
 	r = amdgpu_ptl_perf_monitor_ctrl(adev, PSP_PTL_PERF_MON_SET, &ptl_state,
 							&fmt1, &fmt2);
 	if (r) {
diff --git a/drivers/gpu/drm/amd/include/amdgpu_ptl.h b/drivers/gpu/drm/amd/include/amdgpu_ptl.h
index eead62b4b327..c445525833a2 100644
--- a/drivers/gpu/drm/amd/include/amdgpu_ptl.h
+++ b/drivers/gpu/drm/amd/include/amdgpu_ptl.h
@@ -64,6 +64,9 @@ int amdgpu_ptl_perf_monitor_ctrl(struct amdgpu_device *adev, u32 req_code,
 		enum amdgpu_ptl_fmt *fmt1,
 		enum amdgpu_ptl_fmt *fmt2);
 
+int amdgpu_ptl_parse_formats(const char *buf, enum amdgpu_ptl_fmt *fmt1,
+		enum amdgpu_ptl_fmt *fmt2);
+
 int amdgpu_ptl_sysfs_init(struct amdgpu_device *adev);
 void amdgpu_ptl_sysfs_fini(struct amdgpu_device *adev);
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-24  2:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  7:22 [PATCH 1/2] drm/amdgpu: add ptl_format module parameter Perry Yuan
2026-11-23  7:22 ` [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock Perry Yuan
2026-11-23  7:38   ` sashiko-bot
2026-11-24  2:58   ` Zhang, Yifan
2026-11-24  2:59 ` [PATCH 1/2] drm/amdgpu: add ptl_format module parameter Zhang, Yifan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.