All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 1/5] drm: add macro drm_file_err to print process info
@ 2025-04-17  9:13 Sunil Khatri
  2025-04-17  9:13 ` [PATCH v6 2/5] drm/amdgpu: add drm_file reference in userq_mgr Sunil Khatri
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Sunil Khatri @ 2025-04-17  9:13 UTC (permalink / raw)
  To: dri-devel, amd-gfx
  Cc: Alex Deucher, Christian König, Tvrtko Ursulin,
	Pierre-Eric Pelloux-Prayer, Jani Nikula, Sunil Khatri

Add a drm helper macro which append the process information for
the drm_file over drm_err.

v5: change to macro from function (Christian Koenig)
    add helper functions for lock/unlock (Christian Koenig)

v6: remove __maybe_unused and make function inline (Jani Nikula)
    remove drm_print.h

Signed-off-by: Sunil Khatri <sunil.khatri@amd.com>
---
 include/drm/drm_file.h | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h
index 94d365b22505..856b38e996c7 100644
--- a/include/drm/drm_file.h
+++ b/include/drm/drm_file.h
@@ -446,6 +446,43 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv)
 	return file_priv->minor->type == DRM_MINOR_ACCEL;
 }
 
+static inline struct task_struct *drm_task_lock(struct drm_file *file_priv)
+{
+	struct task_struct *task;
+	struct pid *pid;
+
+	mutex_lock(&file_priv->client_name_lock);
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+	return task;
+}
+
+static inline void drm_task_unlock(struct drm_file *file_priv)
+{
+	rcu_read_unlock();
+	mutex_unlock(&file_priv->client_name_lock);
+}
+/**
+ * drm_file_err - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @fmt: prinf() like format string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */
+#define drm_file_err(file_priv, fmt, ...)						\
+	do {										\
+		struct task_struct *task;						\
+		struct drm_device *dev = file_priv->minor->dev;				\
+											\
+		task = drm_task_lock(file_priv);					\
+		drm_err(dev, "comm: %s pid: %d client: %s " fmt,			\
+			task ? task->comm : "", task ? task->pid : 0,			\
+			file_priv->client_name ?: "Unset", ##__VA_ARGS__);		\
+		drm_task_unlock(file_priv);						\
+	} while (0)
+
 void drm_file_update_pid(struct drm_file *);
 
 struct drm_minor *drm_minor_acquire(struct xarray *minors_xa, unsigned int minor_id);
-- 
2.34.1


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

end of thread, other threads:[~2025-04-17 11:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17  9:13 [PATCH v6 1/5] drm: add macro drm_file_err to print process info Sunil Khatri
2025-04-17  9:13 ` [PATCH v6 2/5] drm/amdgpu: add drm_file reference in userq_mgr Sunil Khatri
2025-04-17  9:13 ` [PATCH v6 3/5] drm/amdgpu: use drm_file_err to add process info Sunil Khatri
2025-04-17  9:13 ` [PATCH v6 4/5] drm/amdgpu: change DRM_ERROR to drm_file_err in amdgpu_userqueue.c Sunil Khatri
2025-04-17  9:13 ` [PATCH v6 5/5] drm/amdgpu: change DRM_DBG_DRIVER to drm_dbg_driver Sunil Khatri
2025-04-17  9:35 ` [PATCH v6 1/5] drm: add macro drm_file_err to print process info Jani Nikula
2025-04-17  9:57   ` Christian König
2025-04-17 11:07     ` Jani Nikula
2025-04-17 11:18       ` Christian König
2025-04-17 11:30         ` Jani Nikula
2025-04-17 11:38           ` Khatri, Sunil

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.