Skip to contentSkip to conversation

drm: function to get process name and pid

PATCH Superseded Sunil Khatri 5 participants 9 messages Apr 11, 2025 – Apr 15, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm: function to get process name and pid

Add helper function which get the process information for the drm_file and updates the user provided character buffer with the information of process name and pid as a string.

---
 drivers/gpu/drm/drm_file.c | 30 ++++++++++++++++++++++++++++++
 include/drm/drm_file.h     |  1 +
 2 files changed, 31 insertions(+)
drivers/gpu/drm/drm_file.c +30 -0
index cb5f22f5bbb6..4434258d21b5 100644
@@ -965,6 +965,36 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f)
 }
 EXPORT_SYMBOL(drm_show_fdinfo);
 
+/**
+ * drm_process_info - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @proc_info: user char ptr to write the string to
+ * @buff_size: size of the buffer passed for the string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size)
+{
+	struct task_struct *task;
+	struct pid *pid;
+	struct drm_device *dev = file_priv->minor->dev;
+
+	if (!proc_info) {
+		drm_err(dev, "Invalid user buffer\n");
+		return;
+	}
+
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+	if (task)
+		snprintf(proc_info, buff_size, "comm:%s pid:%d", task->comm, task->pid);
+
+	rcu_read_unlock();
+}
+EXPORT_SYMBOL(drm_process_info);
+
 /**
  * mock_drm_getfile - Create a new struct file for the drm device
  * @minor: drm minor to wrap (e.g. #drm_device.primary)
include/drm/drm_file.h +1 -0
index f0ef32e9fa5e..c01b34936968 100644
@@ -501,6 +501,7 @@ void drm_print_memory_stats(struct drm_printer *p,
 
 void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
 void drm_show_fdinfo(struct seq_file *m, struct file *f);
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size);
 
 struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/3 drm/amdgpu: add drm_file reference in userq_mgr

drm_file will be used in usermode queues code to enable better process information in logging and hence add drm_file part of the userq_mgr struct.

update the drm_file pointer in userq_mgr for each
amdgpu_driver_open_kms.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h | 1 +
 2 files changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -0
index 0ba3ef1e4a06..2a6ecf0d6c78 100644
@@ -1436,6 +1436,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 
 	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr, adev);
 
+	fpriv->userq_mgr.file = file_priv;
 	r = amdgpu_userq_mgr_init(&fpriv->userq_mgr, adev);
 	if (r)
 		DRM_WARN("Can't setup usermode queues, use legacy workload submission only\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +1 -0
index ec1a4ca6f632..4ddd41835be6 100644
@@ -77,6 +77,7 @@ struct amdgpu_userq_mgr {
 	struct amdgpu_device		*adev;
 	struct delayed_work		resume_work;
 	struct list_head		list;
+	struct drm_file			*file;
 };
 
 struct amdgpu_db_info {
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/3 drm/amdgpu: update the error logging for more information

In reply to Sunil Khatri

add process and pid information in the userqueue error logging to make it more useful in resolving the error by logs.

Sample log:

[   42.444297] [drm:amdgpu_userqueue_wait_for_signal [amdgpu]] *ERROR* Timed out waiting for fence f=000000001c74d978 for comm:Xwayland pid:3427
[   42.444669] [drm:amdgpu_userqueue_suspend [amdgpu]] *ERROR* Not suspending userqueue, timeout waiting for comm:Xwayland pid:3427
[   42.824729] [drm:amdgpu_userqueue_wait_for_signal [amdgpu]] *ERROR* Timed out waiting for fence f=0000000074407d3e for comm:systemd-logind pid:1058
[   42.825082] [drm:amdgpu_userqueue_suspend [amdgpu]] *ERROR* Not suspending userqueue, timeout waiting for comm:systemd-logind pid:1058
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 45 +++++++++++++++----
 1 file changed, 37 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +37 -8
index ecd49cf15b2a..5b58c41618ee 100644
@@ -62,12 +62,17 @@ amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,
 	struct amdgpu_device *adev = uq_mgr->adev;
 	const struct amdgpu_userq_funcs *uq_funcs = adev->userq_funcs[queue->queue_type];
 	struct dma_fence *f = queue->last_fence;
+	struct drm_file *file;
+	char proc_log[50];
 	int ret;
 
 	if (f && !dma_fence_is_signaled(f)) {
 		ret = dma_fence_wait_timeout(f, true, msecs_to_jiffies(100));
 		if (ret <= 0) {
-			DRM_ERROR("Timed out waiting for fence f=%p\n", f);
+			file = uq_mgr->file;
+			drm_process_info(file, proc_log, sizeof(proc_log));
+			DRM_ERROR("Timed out waiting for fence f=%p for %s\n",
+				  f, proc_log);
 			return;
 		}
 	}
@@ -427,6 +432,8 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
 	const struct amdgpu_userq_funcs *userq_funcs;
 	struct amdgpu_usermode_queue *queue;
 	int queue_id;
+	struct drm_file *file;
+	char proc_log[50];
 	int ret = 0;
 
 	/* Resume all the queues for this process */
@@ -435,8 +442,12 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
 		ret = userq_funcs->resume(uq_mgr, queue);
 	}
 
-	if (ret)
-		DRM_ERROR("Failed to resume all the queue\n");
+	if (ret) {
+		file = uq_mgr->file;
+		drm_process_info(file, proc_log, sizeof(proc_log));
+		DRM_ERROR("Failed to resume all the queue for %s\n",
+			  proc_log);
+		}
 	return ret;
 }
 
@@ -585,6 +596,8 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
 	const struct amdgpu_userq_funcs *userq_funcs;
 	struct amdgpu_usermode_queue *queue;
 	int queue_id;
+	struct drm_file *file;
+	char proc_log[50];
 	int ret = 0;
 
 	/* Try to suspend all the queues in this process ctx */
@@ -593,8 +606,12 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
 		ret += userq_funcs->suspend(uq_mgr, queue);
 	}
 
-	if (ret)
-		DRM_ERROR("Couldn't suspend all the queues\n");
+	if (ret) {
+		file = uq_mgr->file;
+		drm_process_info(file, proc_log, sizeof(proc_log));
+		DRM_ERROR("Couldn't suspend all the queues for %s\n",
+			  proc_log);
+		}
 	return ret;
 }
 
@@ -602,6 +619,8 @@ static int
 amdgpu_userqueue_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)
 {
 	struct amdgpu_usermode_queue *queue;
+	struct drm_file *file;
+	char proc_log[50];
 	int queue_id, ret;
 
 	idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id) {
@@ -611,7 +630,10 @@ amdgpu_userqueue_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)
 			continue;
 		ret = dma_fence_wait_timeout(f, true, msecs_to_jiffies(100));
 		if (ret <= 0) {
-			DRM_ERROR("Timed out waiting for fence f=%p\n", f);
+			file = uq_mgr->file;
+			drm_process_info(file, proc_log, sizeof(proc_log));
+			DRM_ERROR("Timed out waiting for fence f=%p for %s\n",
+				  f, proc_log);
 			return -ETIMEDOUT;
 		}
 	}
@@ -624,19 +646,26 @@ amdgpu_userqueue_suspend(struct amdgpu_userq_mgr *uq_mgr,
 			 struct amdgpu_eviction_fence *ev_fence)
 {
 	int ret;
+	struct drm_file *file;
+	char proc_log[50];
 	struct amdgpu_fpriv *fpriv = uq_mgr_to_fpriv(uq_mgr);
 	struct amdgpu_eviction_fence_mgr *evf_mgr = &fpriv->evf_mgr;
 
 	/* Wait for any pending userqueue fence work to finish */
 	ret = amdgpu_userqueue_wait_for_signal(uq_mgr);
 	if (ret) {
-		DRM_ERROR("Not suspending userqueue, timeout waiting for work\n");
+		file = uq_mgr->file;
+		drm_process_info(file, proc_log, sizeof(proc_log));
+		DRM_ERROR("Not suspending userqueue, timeout waiting for %s\n",
+			  proc_log);
 		return;
 	}
 
 	ret = amdgpu_userqueue_suspend_all(uq_mgr);
 	if (ret) {
-		DRM_ERROR("Failed to evict userqueue\n");
+		file = uq_mgr->file;
+		drm_process_info(file, proc_log, sizeof(proc_log));
+		DRM_ERROR("Failed to evict userqueue for %s\n", proc_log);
 		return;
 	}
 
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH v1 3/3] drm/amdgpu: update the error logging for more information

Quoted 26 lines · Sunil Khatri

add process and pid information in the userqueue error logging to make it more useful in resolving the error by logs.

Sample log:

[   42.444297] [drm:amdgpu_userqueue_wait_for_signal [amdgpu]] *ERROR* Timed out waiting for fence f=000000001c74d978 for comm:Xwayland pid:3427
[   42.444669] [drm:amdgpu_userqueue_suspend [amdgpu]] *ERROR* Not suspending userqueue, timeout waiting for comm:Xwayland pid:3427
[   42.824729] [drm:amdgpu_userqueue_wait_for_signal [amdgpu]] *ERROR* Timed out waiting for fence f=0000000074407d3e for comm:systemd-logind pid:1058
[   42.825082] [drm:amdgpu_userqueue_suspend [amdgpu]] *ERROR* Not suspending userqueue, timeout waiting for comm:systemd-logind pid:1058
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 45 +++++++++++++++----
 1 file changed, 37 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -0
index ecd49cf15b2a..5b58c41618ee 100644
@@ -62,12 +62,17 @@ amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,
        struct amdgpu_device *adev = uq_mgr->adev;
        const struct amdgpu_userq_funcs *uq_funcs = adev->userq_funcs[queue->queue_type];
        struct dma_fence *f = queue->last_fence;
+       struct drm_file *file;
+       char proc_log[50];

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr, · line 75

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +4 -1
        int ret;
 
        if (f && !dma_fence_is_signaled(f)) {
                ret = dma_fence_wait_timeout(f, true, msecs_to_jiffies(100));
                if (ret <= 0) {
-                       DRM_ERROR("Timed out waiting for fence f=%p\n", f);
+                       file = uq_mgr->file;
+                       drm_process_info(file, proc_log, sizeof(proc_log));
+                       DRM_ERROR("Timed out waiting for fence f=%p for %s\n",
+                                 f, proc_log);

user drm_err() here and below so we get proper handling of multiple devices.

Alex

Quoted 104 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +31 -8
                        return;
                }
        }
@@ -427,6 +432,8 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
        const struct amdgpu_userq_funcs *userq_funcs;
        struct amdgpu_usermode_queue *queue;
        int queue_id;
+       struct drm_file *file;
+       char proc_log[50];
        int ret = 0;
 
        /* Resume all the queues for this process */
@@ -435,8 +442,12 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
                ret = userq_funcs->resume(uq_mgr, queue);
        }
 
-       if (ret)
-               DRM_ERROR("Failed to resume all the queue\n");
+       if (ret) {
+               file = uq_mgr->file;
+               drm_process_info(file, proc_log, sizeof(proc_log));
+               DRM_ERROR("Failed to resume all the queue for %s\n",
+                         proc_log);
+               }
        return ret;
 }
 
@@ -585,6 +596,8 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
        const struct amdgpu_userq_funcs *userq_funcs;
        struct amdgpu_usermode_queue *queue;
        int queue_id;
+       struct drm_file *file;
+       char proc_log[50];
        int ret = 0;
 
        /* Try to suspend all the queues in this process ctx */
@@ -593,8 +606,12 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
                ret += userq_funcs->suspend(uq_mgr, queue);
        }
 
-       if (ret)
-               DRM_ERROR("Couldn't suspend all the queues\n");
+       if (ret) {
+               file = uq_mgr->file;
+               drm_process_info(file, proc_log, sizeof(proc_log));
+               DRM_ERROR("Couldn't suspend all the queues for %s\n",
+                         proc_log);
+               }
        return ret;
 }
 
@@ -602,6 +619,8 @@ static int
 amdgpu_userqueue_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)
 {
        struct amdgpu_usermode_queue *queue;
+       struct drm_file *file;
+       char proc_log[50];
        int queue_id, ret;
 
        idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id) {
@@ -611,7 +630,10 @@ amdgpu_userqueue_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)
                        continue;
                ret = dma_fence_wait_timeout(f, true, msecs_to_jiffies(100));
                if (ret <= 0) {
-                       DRM_ERROR("Timed out waiting for fence f=%p\n", f);
+                       file = uq_mgr->file;
+                       drm_process_info(file, proc_log, sizeof(proc_log));
+                       DRM_ERROR("Timed out waiting for fence f=%p for %s\n",
+                                 f, proc_log);
                        return -ETIMEDOUT;
                }
        }
@@ -624,19 +646,26 @@ amdgpu_userqueue_suspend(struct amdgpu_userq_mgr *uq_mgr,
                         struct amdgpu_eviction_fence *ev_fence)
 {
        int ret;
+       struct drm_file *file;
+       char proc_log[50];
        struct amdgpu_fpriv *fpriv = uq_mgr_to_fpriv(uq_mgr);
        struct amdgpu_eviction_fence_mgr *evf_mgr = &fpriv->evf_mgr;
 
        /* Wait for any pending userqueue fence work to finish */
        ret = amdgpu_userqueue_wait_for_signal(uq_mgr);
        if (ret) {
-               DRM_ERROR("Not suspending userqueue, timeout waiting for work\n");
+               file = uq_mgr->file;
+               drm_process_info(file, proc_log, sizeof(proc_log));
+               DRM_ERROR("Not suspending userqueue, timeout waiting for %s\n",
+                         proc_log);
                return;
        }
 
        ret = amdgpu_userqueue_suspend_all(uq_mgr);
        if (ret) {
-               DRM_ERROR("Failed to evict userqueue\n");
+               file = uq_mgr->file;
+               drm_process_info(file, proc_log, sizeof(proc_log));
+               DRM_ERROR("Failed to evict userqueue for %s\n", proc_log);
                return;
        }
 
--

2.34.1

#4 lore raw

Re: [PATCH v1 3/3] drm/amdgpu: update the error logging for more information

Quoted 38 lines · Alex Deucher
Quoted 25 lines · Sunil Khatri

add process and pid information in the userqueue error logging to make it more useful in resolving the error by logs.

Sample log:

[   42.444297] [drm:amdgpu_userqueue_wait_for_signal [amdgpu]] *ERROR* Timed out waiting for fence f=000000001c74d978 for comm:Xwayland pid:3427
[   42.444669] [drm:amdgpu_userqueue_suspend [amdgpu]] *ERROR* Not suspending userqueue, timeout waiting for comm:Xwayland pid:3427
[   42.824729] [drm:amdgpu_userqueue_wait_for_signal [amdgpu]] *ERROR* Timed out waiting for fence f=0000000074407d3e for comm:systemd-logind pid:1058
[   42.825082] [drm:amdgpu_userqueue_suspend [amdgpu]] *ERROR* Not suspending userqueue, timeout waiting for comm:systemd-logind pid:1058
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 45 +++++++++++++++----
  1 file changed, 37 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -0
index ecd49cf15b2a..5b58c41618ee 100644
@@ -62,12 +62,17 @@ amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,
         struct amdgpu_device *adev = uq_mgr->adev;
         const struct amdgpu_userq_funcs *uq_funcs = adev->userq_funcs[queue->queue_type];
         struct dma_fence *f = queue->last_fence;
+       struct drm_file *file;
+       char proc_log[50];

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr, · line 75

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +4 -1
         int ret;
 
         if (f && !dma_fence_is_signaled(f)) {
                 ret = dma_fence_wait_timeout(f, true, msecs_to_jiffies(100));
                 if (ret <= 0) {
-                       DRM_ERROR("Timed out waiting for fence f=%p\n", f);
+                       file = uq_mgr->file;
+                       drm_process_info(file, proc_log, sizeof(proc_log));
+                       DRM_ERROR("Timed out waiting for fence f=%p for %s\n",
+                                 f, proc_log);

user drm_err() here and below so we get proper handling of multiple devices.

Quoted 1 line

Alex

Sure Alex. Once i have the main drm patch reviewed would update these too. Sunil

Quoted 105 lines
Quoted 105 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +31 -8
                         return;
                 }
         }
@@ -427,6 +432,8 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
         const struct amdgpu_userq_funcs *userq_funcs;
         struct amdgpu_usermode_queue *queue;
         int queue_id;
+       struct drm_file *file;
+       char proc_log[50];
         int ret = 0;
 
         /* Resume all the queues for this process */
@@ -435,8 +442,12 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr)
                 ret = userq_funcs->resume(uq_mgr, queue);
         }
 
-       if (ret)
-               DRM_ERROR("Failed to resume all the queue\n");
+       if (ret) {
+               file = uq_mgr->file;
+               drm_process_info(file, proc_log, sizeof(proc_log));
+               DRM_ERROR("Failed to resume all the queue for %s\n",
+                         proc_log);
+               }
         return ret;
  }
 
@@ -585,6 +596,8 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
         const struct amdgpu_userq_funcs *userq_funcs;
         struct amdgpu_usermode_queue *queue;
         int queue_id;
+       struct drm_file *file;
+       char proc_log[50];
         int ret = 0;
 
         /* Try to suspend all the queues in this process ctx */
@@ -593,8 +606,12 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr)
                 ret += userq_funcs->suspend(uq_mgr, queue);
         }
 
-       if (ret)
-               DRM_ERROR("Couldn't suspend all the queues\n");
+       if (ret) {
+               file = uq_mgr->file;
+               drm_process_info(file, proc_log, sizeof(proc_log));
+               DRM_ERROR("Couldn't suspend all the queues for %s\n",
+                         proc_log);
+               }
         return ret;
  }
 
@@ -602,6 +619,8 @@ static int
  amdgpu_userqueue_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)
  {
         struct amdgpu_usermode_queue *queue;
+       struct drm_file *file;
+       char proc_log[50];
         int queue_id, ret;
 
         idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id) {
@@ -611,7 +630,10 @@ amdgpu_userqueue_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr)
                         continue;
                 ret = dma_fence_wait_timeout(f, true, msecs_to_jiffies(100));
                 if (ret <= 0) {
-                       DRM_ERROR("Timed out waiting for fence f=%p\n", f);
+                       file = uq_mgr->file;
+                       drm_process_info(file, proc_log, sizeof(proc_log));
+                       DRM_ERROR("Timed out waiting for fence f=%p for %s\n",
+                                 f, proc_log);
                         return -ETIMEDOUT;
                 }
         }
@@ -624,19 +646,26 @@ amdgpu_userqueue_suspend(struct amdgpu_userq_mgr *uq_mgr,
                          struct amdgpu_eviction_fence *ev_fence)
  {
         int ret;
+       struct drm_file *file;
+       char proc_log[50];
         struct amdgpu_fpriv *fpriv = uq_mgr_to_fpriv(uq_mgr);
         struct amdgpu_eviction_fence_mgr *evf_mgr = &fpriv->evf_mgr;
 
         /* Wait for any pending userqueue fence work to finish */
         ret = amdgpu_userqueue_wait_for_signal(uq_mgr);
         if (ret) {
-               DRM_ERROR("Not suspending userqueue, timeout waiting for work\n");
+               file = uq_mgr->file;
+               drm_process_info(file, proc_log, sizeof(proc_log));
+               DRM_ERROR("Not suspending userqueue, timeout waiting for %s\n",
+                         proc_log);
                 return;
         }
 
         ret = amdgpu_userqueue_suspend_all(uq_mgr);
         if (ret) {
-               DRM_ERROR("Failed to evict userqueue\n");
+               file = uq_mgr->file;
+               drm_process_info(file, proc_log, sizeof(proc_log));
+               DRM_ERROR("Failed to evict userqueue for %s\n", proc_log);
                 return;
         }
 
--

2.34.1

#5 lore raw
In reply to Sunil Khatri

Ping?

Quoted 63 lines · Sunil Khatri

Add helper function which get the process information for the drm_file and updates the user provided character buffer with the information of process name and pid as a string.

---
  drivers/gpu/drm/drm_file.c | 30 ++++++++++++++++++++++++++++++
  include/drm/drm_file.h     |  1 +
  2 files changed, 31 insertions(+)
drivers/gpu/drm/drm_file.c +30 -0
index cb5f22f5bbb6..4434258d21b5 100644
@@ -965,6 +965,36 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f)
  }
  EXPORT_SYMBOL(drm_show_fdinfo);
 
+/**
+ * drm_process_info - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @proc_info: user char ptr to write the string to
+ * @buff_size: size of the buffer passed for the string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size)
+{
+	struct task_struct *task;
+	struct pid *pid;
+	struct drm_device *dev = file_priv->minor->dev;
+
+	if (!proc_info) {
+		drm_err(dev, "Invalid user buffer\n");
+		return;
+	}
+
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+	if (task)
+		snprintf(proc_info, buff_size, "comm:%s pid:%d", task->comm, task->pid);
+
+	rcu_read_unlock();
+}
+EXPORT_SYMBOL(drm_process_info);
+
  /**
   * mock_drm_getfile - Create a new struct file for the drm device
   * @minor: drm minor to wrap (e.g. #drm_device.primary)
include/drm/drm_file.h +1 -0
index f0ef32e9fa5e..c01b34936968 100644
@@ -501,6 +501,7 @@ void drm_print_memory_stats(struct drm_printer *p,
 
  void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
  void drm_show_fdinfo(struct seq_file *m, struct file *f);
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size);
 
  struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);
 
#6 lore raw
In reply to Sunil Khatri

Adding Pierre-eric and Tvrtko as well.

Am 11.04.25 um 15:04 schrieb Sunil Khatri:

Quoted 33 lines

Add helper function which get the process information for the drm_file and updates the user provided character buffer with the information of process name and pid as a string.

---
 drivers/gpu/drm/drm_file.c | 30 ++++++++++++++++++++++++++++++
 include/drm/drm_file.h     |  1 +
 2 files changed, 31 insertions(+)
drivers/gpu/drm/drm_file.c +15 -0
index cb5f22f5bbb6..4434258d21b5 100644
@@ -965,6 +965,36 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f)
 }
 EXPORT_SYMBOL(drm_show_fdinfo);
 
+/**
+ * drm_process_info - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @proc_info: user char ptr to write the string to
+ * @buff_size: size of the buffer passed for the string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size)
+{
+	struct task_struct *task;
+	struct pid *pid;
+	struct drm_device *dev = file_priv->minor->dev;
+

drivers/gpu/drm/drm_file.c void drm_show_fdinfo(struct seq_file *m, struct file *f) · line 992

Quoted 10 lines
drivers/gpu/drm/drm_file.c +10 -0
+	if (!proc_info) {
+		drm_err(dev, "Invalid user buffer\n");
+		return;
+	}
+
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+	if (task)
+		snprintf(proc_info, buff_size, "comm:%s pid:%d", task->comm, task->pid);

Looks good in general, but I think people would like to see the optional client name here as well.

It's rather useful to have for native context.

Regards,
Christian.

Quoted 20 lines
drivers/gpu/drm/drm_file.c +5 -0
+
+	rcu_read_unlock();
+}
+EXPORT_SYMBOL(drm_process_info);
+
 /**
  * mock_drm_getfile - Create a new struct file for the drm device
  * @minor: drm minor to wrap (e.g. #drm_device.primary)
include/drm/drm_file.h +1 -0
index f0ef32e9fa5e..c01b34936968 100644
@@ -501,6 +501,7 @@ void drm_print_memory_stats(struct drm_printer *p,
 
 void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
 void drm_show_fdinfo(struct seq_file *m, struct file *f);
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size);
 
 struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);
 
#7 lore raw
Quoted 1 line · Christian König

Adding Pierre-eric and Tvrtko as well.

Thanks!

Quoted 28 lines

Am 11.04.25 um 15:04 schrieb Sunil Khatri:

Quoted 27 lines

Add helper function which get the process information for the drm_file and updates the user provided character buffer with the information of process name and pid as a string.

---
  drivers/gpu/drm/drm_file.c | 30 ++++++++++++++++++++++++++++++
  include/drm/drm_file.h     |  1 +
  2 files changed, 31 insertions(+)
drivers/gpu/drm/drm_file.c +9 -0
index cb5f22f5bbb6..4434258d21b5 100644
@@ -965,6 +965,36 @@ void drm_show_fdinfo(struct seq_file *m, struct file *f)
  }
  EXPORT_SYMBOL(drm_show_fdinfo);
 
+/**
+ * drm_process_info - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @proc_info: user char ptr to write the string to
+ * @buff_size: size of the buffer passed for the string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */
Quoted 8 lines

drivers/gpu/drm/drm_file.c void drm_show_fdinfo(struct seq_file *m, struct file *f) · line 984

Quoted 8 lines
drivers/gpu/drm/drm_file.c +8 -0
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size)
+{
+	struct task_struct *task;
+	struct pid *pid;
+	struct drm_device *dev = file_priv->minor->dev;
+
+	if (!proc_info) {
+		drm_err(dev, "Invalid user buffer\n");

I'd replace this with drm_WARN_ON_ONCE.

Another thing I would consider is avoiding the need for stack space by exporting a logging helper instead. Something like (from patch 3/3):

drm_file_err(uq_mgr->file, "Timed out waiting for fence %p\n", f);

Which would output the client name info as a prefix or something.

Especially attractive if you add client name.

Also while here, is %p for the fence is useful? FWIW in the tracing series we are going for %llu:%llu (context:seqno).

Regards,

Tvrtko

Quoted 37 lines

drivers/gpu/drm/drm_file.c void drm_show_fdinfo(struct seq_file *m, struct file *f) · line 992

Quoted 8 lines
drivers/gpu/drm/drm_file.c +8 -0
+		return;
+	}
+
+	rcu_read_lock();
+	pid = rcu_dereference(file_priv->pid);
+	task = pid_task(pid, PIDTYPE_TGID);
+	if (task)
+		snprintf(proc_info, buff_size, "comm:%s pid:%d", task->comm, task->pid);

Looks good in general, but I think people would like to see the optional client name here as well.

It's rather useful to have for native context.

Regards,
Christian.

Quoted 20 lines
drivers/gpu/drm/drm_file.c +5 -0
+
+	rcu_read_unlock();
+}
+EXPORT_SYMBOL(drm_process_info);
+
  /**
   * mock_drm_getfile - Create a new struct file for the drm device
   * @minor: drm minor to wrap (e.g. #drm_device.primary)
include/drm/drm_file.h +1 -0
index f0ef32e9fa5e..c01b34936968 100644
@@ -501,6 +501,7 @@ void drm_print_memory_stats(struct drm_printer *p,
 
  void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
  void drm_show_fdinfo(struct seq_file *m, struct file *f);
+void drm_process_info(struct drm_file *file_priv, char *proc_info, size_t buff_size);
 
  struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);
 
#8 lore raw
Quoted 47 lines · Tvrtko Ursulin
Quoted 1 line · Christian König

Adding Pierre-eric and Tvrtko as well.

Thanks!

Quoted 29 lines

Am 11.04.25 um 15:04 schrieb Sunil Khatri:

Quoted 28 lines

Add helper function which get the process information for the drm_file and updates the user provided character buffer with the information of process name and pid as a string.

---
  drivers/gpu/drm/drm_file.c | 30 ++++++++++++++++++++++++++++++ include/drm/drm_file.h     |  1 +

  2 files changed, 31 insertions(+)
drivers/gpu/drm/drm_file.c +0 -0
index cb5f22f5bbb6..4434258d21b5 100644
@@ -965,6 +965,36 @@ void drm_show_fdinfo(struct seq_file *m, struct 
 file *f)
   }
   EXPORT_SYMBOL(drm_show_fdinfo);

  +/**
+ * drm_process_info - Fill info string with process name and pid
+ * @file_priv: context of interest for process name and pid
+ * @proc_info: user char ptr to write the string to
+ * @buff_size: size of the buffer passed for the string
+ *
+ * This update the user provided buffer with process
+ * name and pid information for @file_priv
+ */
+void drm_process_info(struct drm_file *file_priv, char *proc_info,

Quoted 8 lines

drivers/gpu/drm/drm_file.c void drm_show_fdinfo(struct seq_file *m, struct file *f) · line 984

Quoted 8 lines

size_t buff_size)

drivers/gpu/drm/drm_file.c +7 -0
+{
+    struct task_struct *task;
+    struct pid *pid;
+    struct drm_device *dev = file_priv->minor->dev;
+
+    if (!proc_info) {
+        drm_err(dev, "Invalid user buffer\n");

I'd replace this with drm_WARN_ON_ONCE.
This sounds fine, will update with warn once in next version.

Quoted 5 lines

Another thing I would consider is avoiding the need for stack space by exporting a logging helper instead. Something like (from patch 3/3):

drm_file_err(uq_mgr->file, "Timed out waiting for fence %p\n", f);

Which would output the client name info as a prefix or something.

I guess here we are making a generic function and nothing specific to the driver or a feature like uq_manager. this is supposed to be a common helper function for all drm clients and based on drm_file. With respect to the user i guess the driver/feature specific information can we placed in the caller itself and thats upto the user.

Quoted 5 lines

Especially attractive if you add client name.

Also while here, is %p for the fence is useful? FWIW in the tracing series we are going for %llu:%llu (context:seqno).
To be frank i dont see the fence ptr to be very useful as they are being reused too and we do see same fence ptr again too. but this we could improve later. I will push a new patch series for this with the comments taken into.

Regards
Sunil Khatri

Quoted 42 lines

Regards,

Tvrtko

Quoted 36 lines
Quoted 9 lines

+        return;
+    }
+
+    rcu_read_lock();
+    pid = rcu_dereference(file_priv->pid);
+    task = pid_task(pid, PIDTYPE_TGID);
+    if (task)
+        snprintf(proc_info, buff_size, "comm:%s pid:%d", task->comm, task->pid);

Looks good in general, but I think people would like to see the optional client name here as well.

It's rather useful to have for native context.

Regards,
Christian.

Quoted 18 lines
drivers/gpu/drm/drm_file.c +5 -0
+
+    rcu_read_unlock();
+}
+EXPORT_SYMBOL(drm_process_info);
+

  /**
   * mock_drm_getfile - Create a new struct file for the drm device
   * @minor: drm minor to wrap (e.g. #drm_device.primary)

include/drm/drm_file.h +1 -0
index f0ef32e9fa5e..c01b34936968 100644
@@ -501,6 +501,7 @@ void drm_print_memory_stats(struct drm_printer *p,
     void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file);
   void drm_show_fdinfo(struct seq_file *m, struct file *f);
+void drm_process_info(struct drm_file *file_priv, char *proc_info, 
 size_t buff_size);
     struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags);