[Intel-xe] [PATCH 3/4] drm/xe/pm: Add vram_d3cold_threshold Sysfs

Anshuman Gupta anshuman.gupta at intel.com
Fri May 19 16:25:54 UTC 2023


Add per pci device vram_d3cold_threshold Sysfs to
control the d3cold_allowed knob.

Cc: Rodrigo Vivi <rodrigo.vivi at intel.com>
Signed-off-by: Anshuman Gupta <anshuman.gupta at intel.com>
---
 drivers/gpu/drm/xe/xe_device_types.h |  8 ++++
 drivers/gpu/drm/xe/xe_pm.c           | 65 ++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
index 8fd3acf60719..68222a3447cf 100644
--- a/drivers/gpu/drm/xe/xe_device_types.h
+++ b/drivers/gpu/drm/xe/xe_device_types.h
@@ -272,6 +272,14 @@ struct xe_device {
 	/** @d3cold_allowed: Indicates if d3cold is a valid device state */
 	bool d3cold_allowed;
 
+	/**
+	 * @vram_d3cold_threshold is the permissible threshold(in megabytes)
+	 * for vram save/restore. d3cold will be disallowed, when vram_usages is
+	 * above threshold value to avoid the vram save/restore latency.
+	 * Default threshold value is 300mb.
+	 */
+	u32 vram_d3cold_threshold;
+
 	/* private: */
 
 #if IS_ENABLED(CONFIG_DRM_XE_DISPLAY)
diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
index c250a36b99ad..ebdbdf2e0898 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -7,6 +7,7 @@
 
 #include <linux/pm_runtime.h>
 
+#include <drm/drm_managed.h>
 #include <drm/ttm/ttm_placement.h>
 
 #include "xe_bo.h"
@@ -132,6 +133,68 @@ static bool xe_pm_pci_d3cold_capable(struct pci_dev *pdev)
 	return true;
 }
 
+static ssize_t
+vram_d3cold_threshold_show(struct device *dev,
+			   struct device_attribute *attr, char *buf)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct xe_device *xe = pdev_to_xe_device(pdev);
+	int ret;
+
+	if (!xe)
+		return -EINVAL;
+
+	ret = sysfs_emit(buf, "%d\n", xe->vram_d3cold_threshold);
+
+	return ret;
+}
+
+static ssize_t
+vram_d3cold_threshold_store(struct device *dev, struct device_attribute *attr,
+			    const char *buff, size_t count)
+{
+	struct pci_dev *pdev = to_pci_dev(dev);
+	struct xe_device *xe = pdev_to_xe_device(pdev);
+	u32 vram_d3cold_threshold;
+	int ret;
+
+	if (!xe)
+		return -EINVAL;
+
+	ret = kstrtou32(buff, 0, &vram_d3cold_threshold);
+	if (ret)
+		return ret;
+
+	dev_dbg(dev, "vram_d3cold_threshold: %d\n", vram_d3cold_threshold);
+
+	xe->vram_d3cold_threshold = vram_d3cold_threshold;
+
+	return ret ?: count;
+}
+
+DEVICE_ATTR_RW(vram_d3cold_threshold);
+
+void xe_pm_sysfs_fini(struct drm_device *drm, void *arg)
+{
+	struct xe_device *xe = arg;
+
+	sysfs_remove_file(&xe->drm.dev->kobj, &dev_attr_vram_d3cold_threshold.attr);
+}
+
+int xe_pm_sysfs_init(struct xe_device *xe)
+{
+	struct device *dev = xe->drm.dev;
+	int ret;
+
+	ret = sysfs_create_file(&dev->kobj, &dev_attr_vram_d3cold_threshold.attr);
+	if (ret)
+		return ret;
+
+	ret = drmm_add_action_or_reset(&xe->drm, xe_pm_sysfs_fini, xe);
+
+	return ret;
+}
+
 static void xe_pm_runtime_init(struct xe_device *xe)
 {
 	struct device *dev = xe->drm.dev;
@@ -150,6 +213,8 @@ void xe_pm_init(struct xe_device *xe)
 
 	xe_pm_runtime_init(xe);
 	xe->d3cold_capable = xe_pm_pci_d3cold_capable(pdev);
+	xe->vram_d3cold_threshold = 300;
+	xe_pm_sysfs_init(xe);
 }
 
 void xe_pm_runtime_fini(struct xe_device *xe)
-- 
2.38.0



More information about the Intel-xe mailing list