Message ID | 20250411112622.4075526-1-sunil.khatri@amd.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | drm: function to get process name and pid | expand |
On Fri, 11 Apr 2025, Sunil Khatri <sunil.khatri@amd.com> wrote: > 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. Where's the user for this function? BR, Jani. > > Signed-off-by: Sunil Khatri <sunil.khatri@amd.com> > --- > drivers/gpu/drm/drm_file.c | 30 ++++++++++++++++++++++++++++++ > include/drm/drm_file.h | 1 + > 2 files changed, 31 insertions(+) > > diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c > index cb5f22f5bbb6..4434258d21b5 100644 > --- a/drivers/gpu/drm/drm_file.c > +++ b/drivers/gpu/drm/drm_file.c > @@ -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) > diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h > index f0ef32e9fa5e..c01b34936968 100644 > --- a/include/drm/drm_file.h > +++ b/include/drm/drm_file.h > @@ -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);
Am 11.04.25 um 13:26 schrieb 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. Hi Sunil, you need to send this out together with the patch which makes use of the new function. Regards, Christian. > > Signed-off-by: Sunil Khatri <sunil.khatri@amd.com> > --- > drivers/gpu/drm/drm_file.c | 30 ++++++++++++++++++++++++++++++ > include/drm/drm_file.h | 1 + > 2 files changed, 31 insertions(+) > > diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c > index cb5f22f5bbb6..4434258d21b5 100644 > --- a/drivers/gpu/drm/drm_file.c > +++ b/drivers/gpu/drm/drm_file.c > @@ -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) > diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h > index f0ef32e9fa5e..c01b34936968 100644 > --- a/include/drm/drm_file.h > +++ b/include/drm/drm_file.h > @@ -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); >
[AMD Official Use Only - AMD Internal Distribution Only] Sure, I will send the patch for the user too. Regards Sunil Khatri -----Original Message----- From: Koenig, Christian <Christian.Koenig@amd.com> Sent: Friday, April 11, 2025 5:40 PM To: Khatri, Sunil <Sunil.Khatri@amd.com>; dri-devel@lists.freedesktop.org; amd-gfx@lists.freedesktop.org Cc: Deucher, Alexander <Alexander.Deucher@amd.com> Subject: Re: [PATCH] drm: function to get process name and pid Am 11.04.25 um 13:26 schrieb 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. Hi Sunil, you need to send this out together with the patch which makes use of the new function. Regards, Christian. > > Signed-off-by: Sunil Khatri <sunil.khatri@amd.com> > --- > drivers/gpu/drm/drm_file.c | 30 ++++++++++++++++++++++++++++++ > include/drm/drm_file.h | 1 + > 2 files changed, 31 insertions(+) > > diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c > index cb5f22f5bbb6..4434258d21b5 100644 > --- a/drivers/gpu/drm/drm_file.c > +++ b/drivers/gpu/drm/drm_file.c > @@ -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) diff --git > a/include/drm/drm_file.h b/include/drm/drm_file.h index > f0ef32e9fa5e..c01b34936968 100644 > --- a/include/drm/drm_file.h > +++ b/include/drm/drm_file.h > @@ -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); >
diff --git a/drivers/gpu/drm/drm_file.c b/drivers/gpu/drm/drm_file.c index cb5f22f5bbb6..4434258d21b5 100644 --- a/drivers/gpu/drm/drm_file.c +++ b/drivers/gpu/drm/drm_file.c @@ -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) diff --git a/include/drm/drm_file.h b/include/drm/drm_file.h index f0ef32e9fa5e..c01b34936968 100644 --- a/include/drm/drm_file.h +++ b/include/drm/drm_file.h @@ -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);
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. Signed-off-by: Sunil Khatri <sunil.khatri@amd.com> --- drivers/gpu/drm/drm_file.c | 30 ++++++++++++++++++++++++++++++ include/drm/drm_file.h | 1 + 2 files changed, 31 insertions(+)