drm: add macro drm_file_err to print process info
Subsystems (3)
PATCH v6 1/5 drm: add macro drm_file_err to print process info
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
--- include/drm/drm_file.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
include/drm/drm_file.h +37 -0
@@ -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);
Signature · 1 line
2.34.1
PATCH v6 2/5 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 eachamdgpu_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
@@ -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
@@ -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
PATCH v6 3/5 drm/amdgpu: use drm_file_err to add process info
In reply to Sunil Khatriadd process and pid information in the userqueue error logging to make it more useful in resolving the error by logs. drm_file_err logs pid and process name by default.
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 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +8 -6
@@ -43,7 +43,7 @@ amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,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); +drm_file_err (uq_mgr->file,"Timed out waiting for fence f=%p\n" , f);return ; } }
@@ -440,7 +440,8 @@ amdgpu_userqueue_resume_all(struct amdgpu_userq_mgr *uq_mgr) }if (ret) -DRM_ERROR ("Failed to map all the queues\n" ); +drm_file_err (uq_mgr->file,"Failed to map all the queues\n" ); +return ret; }
@@ -598,7 +599,8 @@ amdgpu_userqueue_suspend_all(struct amdgpu_userq_mgr *uq_mgr) }if (ret) -DRM_ERROR ("Couldn't unmap all the queues\n" ); +drm_file_err (uq_mgr->file,"Couldn't unmap all the queues\n" ); +return ret; }
@@ -615,7 +617,7 @@ 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); +drm_file_err (uq_mgr->file,"Timed out waiting for fence f=%p\n" , f);return -ETIMEDOUT ; } }
@@ -634,13 +636,13 @@ amdgpu_userqueue_suspend(struct amdgpu_userq_mgr *uq_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" ); +drm_file_err (uq_mgr->file,"Not suspending userqueue, timeout waiting\n" );return ; } ret =amdgpu_userqueue_suspend_all (uq_mgr);if (ret) { -DRM_ERROR ("Failed to evict userqueue\n" ); +drm_file_err (uq_mgr->file,"Failed to evict userqueue\n" );return ; }
Signature · 1 line
2.34.1
PATCH v6 4/5 drm/amdgpu: change DRM_ERROR to drm_file_err in amdgpu_userqueue.c
In reply to Sunil Khatrichange the DRM_ERROR to drm_file_err to ad process name and pid to the logging.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +29 -23
@@ -123,25 +123,25 @@ int amdgpu_userqueue_create_object(struct amdgpu_userq_mgr *uq_mgr, r =amdgpu_bo_create (adev, &bp, &userq_obj->obj);if (r) { -DRM_ERROR ("Failed to allocate BO for userqueue (%d)" , r); +drm_file_err (uq_mgr->file,"Failed to allocate BO for userqueue (%d)" , r);return r; } r =amdgpu_bo_reserve (userq_obj->obj, true);if (r) { -DRM_ERROR ("Failed to reserve BO to map (%d)" , r); +drm_file_err (uq_mgr->file,"Failed to reserve BO to map (%d)" , r); goto free_obj; } r =amdgpu_ttm_alloc_gart (&(userq_obj->obj)->tbo);if (r) { -DRM_ERROR ("Failed to alloc GART for userqueue object (%d)" , r); +drm_file_err (uq_mgr->file,"Failed to alloc GART for userqueue object (%d)" , r); goto unresv; } r =amdgpu_bo_kmap (userq_obj->obj, &userq_obj->cpu_ptr);if (r) { -DRM_ERROR ("Failed to map BO for userqueue (%d)" , r); +drm_file_err (uq_mgr->file,"Failed to map BO for userqueue (%d)" , r); goto unresv; }
@@ -177,7 +177,7 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, gobj =drm_gem_object_lookup (filp, db_info->doorbell_handle);if (gobj ==NULL ) { -DRM_ERROR ("Can't find GEM object for doorbell\n" ); +drm_file_err (uq_mgr->file,"Can't find GEM object for doorbell\n" );return -EINVAL ; }
@@ -187,13 +187,15 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,/* Pin the BO before generating the index, unpin in queue destroy */ r =amdgpu_bo_pin (db_obj->obj,AMDGPU_GEM_DOMAIN_DOORBELL );if (r) { -DRM_ERROR ("[Usermode queues] Failed to pin doorbell object\n" ); +drm_file_err (uq_mgr->file, +"[Usermode queues] Failed to pin doorbell object\n" ); goto unref_bo; } r =amdgpu_bo_reserve (db_obj->obj, true);if (r) { -DRM_ERROR ("[Usermode queues] Failed to pin doorbell object\n" ); +drm_file_err (uq_mgr->file, +"[Usermode queues] Failed to pin doorbell object\n" ); goto unpin_bo; }
@@ -215,7 +217,8 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,break ;default : -DRM_ERROR ("[Usermode queues] IP %d not support\n" , db_info->queue_type); +drm_file_err (uq_mgr->file, +"[Usermode queues] IP %d not support\n" , db_info->queue_type); r = -EINVAL ; goto unpin_bo; }
@@ -282,7 +285,8 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)if (args->in.ip_type !=AMDGPU_HW_IP_GFX && args->in.ip_type !=AMDGPU_HW_IP_DMA && args->in.ip_type !=AMDGPU_HW_IP_COMPUTE ) { -DRM_ERROR ("Usermode queue doesn't support IP type %u\n" , args->in.ip_type); +drm_file_err (uq_mgr->file, +"Usermode queue doesn't support IP type %u\n" , args->in.ip_type);return -EINVAL ; }
@@ -304,14 +308,16 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) uq_funcs = adev->userq_funcs[args->in.ip_type];if (!uq_funcs) { -DRM_ERROR ("Usermode queue is not supported for this IP (%u)\n" , args->in.ip_type); +drm_file_err (uq_mgr->file, +"Usermode queue is not supported for this IP (%u)\n" , + args->in.ip_type); r = -EINVAL ; goto unlock; } queue =kzalloc (sizeof (struct amdgpu_usermode_queue ),GFP_KERNEL );if (!queue) { -DRM_ERROR ("Failed to allocate memory for queue\n" ); +drm_file_err (uq_mgr->file,"Failed to allocate memory for queue\n" ); r = -ENOMEM ; goto unlock; }
@@ -327,7 +333,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)/* Convert relative doorbell offset into absolute doorbell index */ index =amdgpu_userqueue_get_doorbell_index (uq_mgr, &db_info, filp);if (index == (uint64_t )-EINVAL ) { -DRM_ERROR ("Failed to get doorbell for queue\n" ); +drm_file_err (uq_mgr->file,"Failed to get doorbell for queue\n" );kfree (queue); goto unlock; }
@@ -336,13 +342,13 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)xa_init_flags (&queue->fence_drv_xa,XA_FLAGS_ALLOC ); r =amdgpu_userq_fence_driver_alloc (adev, queue);if (r) { -DRM_ERROR ("Failed to alloc fence driver\n" ); +drm_file_err (uq_mgr->file,"Failed to alloc fence driver\n" ); goto unlock; } r = uq_funcs->mqd_create (uq_mgr, &args->in, queue);if (r) { -DRM_ERROR ("Failed to create Queue\n" ); +drm_file_err (uq_mgr->file,"Failed to create Queue\n" );amdgpu_userq_fence_driver_free (queue);kfree (queue); goto unlock;
@@ -350,7 +356,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) qid =idr_alloc (&uq_mgr->userq_idr, queue,1 ,AMDGPU_MAX_USERQ_COUNT ,GFP_KERNEL );if (qid <0 ) { -DRM_ERROR ("Failed to allocate a queue id\n" ); +drm_file_err (uq_mgr->file,"Failed to allocate a queue id\n" );amdgpu_userq_fence_driver_free (queue); uq_funcs->mqd_destroy (uq_mgr, queue);kfree (queue);
@@ -360,7 +366,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args) r = uq_funcs->map (uq_mgr, queue);if (r) { -DRM_ERROR ("Failed to map Queue\n" ); +drm_file_err (uq_mgr->file,"Failed to map Queue\n" );idr_remove (&uq_mgr->userq_idr, qid);amdgpu_userq_fence_driver_free (queue); uq_funcs->mqd_destroy (uq_mgr, queue);
@@ -388,7 +394,7 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,return -EINVAL ; r =amdgpu_userqueue_create (filp, args);if (r) -DRM_ERROR ("Failed to create usermode queue\n" ); +drm_file_err (filp,"Failed to create usermode queue\n" );break ;case AMDGPU_USERQ_OP_FREE :
@@ -406,7 +412,7 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,return -EINVAL ; r =amdgpu_userqueue_destroy (filp, args->in.queue_id);if (r) -DRM_ERROR ("Failed to destroy usermode queue\n" ); +drm_file_err (filp,"Failed to destroy usermode queue\n" );break ;default :
@@ -479,7 +485,7 @@ amdgpu_userqueue_validate_bos(struct amdgpu_userq_mgr *uq_mgr) ret =amdgpu_vm_lock_pd (vm, &exec,2 );drm_exec_retry_on_contention (&exec);if (unlikely (ret)) { -DRM_ERROR ("Failed to lock PD\n" ); +drm_file_err (uq_mgr->file,"Failed to lock PD\n" ); goto unlock_all; }
@@ -519,7 +525,7 @@ amdgpu_userqueue_validate_bos(struct amdgpu_userq_mgr *uq_mgr) bo = bo_va->base.bo; ret =amdgpu_userqueue_validate_vm_bo (NULL , bo);if (ret) { -DRM_ERROR ("Failed to validate BO\n" ); +drm_file_err (uq_mgr->file,"Failed to validate BO\n" ); goto unlock_all; }
@@ -550,7 +556,7 @@ amdgpu_userqueue_validate_bos(struct amdgpu_userq_mgr *uq_mgr) ret =amdgpu_eviction_fence_replace_fence (&fpriv->evf_mgr, &exec);if (ret) -DRM_ERROR ("Failed to replace eviction fence\n" ); +drm_file_err (uq_mgr->file,"Failed to replace eviction fence\n" ); unlock_all:drm_exec_fini (&exec);
@@ -569,13 +575,13 @@ static void amdgpu_userqueue_resume_worker(struct work_struct *work) ret =amdgpu_userqueue_validate_bos (uq_mgr);if (ret) { -DRM_ERROR ("Failed to validate BOs to restore\n" ); +drm_file_err (uq_mgr->file,"Failed to validate BOs to restore\n" ); goto unlock; } ret =amdgpu_userqueue_resume_all (uq_mgr);if (ret) { -DRM_ERROR ("Failed to resume all queues\n" ); +drm_file_err (uq_mgr->file,"Failed to resume all queues\n" ); goto unlock; }
Signature · 1 line
2.34.1
PATCH v6 5/5 drm/amdgpu: change DRM_DBG_DRIVER to drm_dbg_driver
In reply to Sunil Khatriupdate the functions in amdgpu_userqueues.c from DRM_DBG_DRIVER to drm_dbg_driver so multi gpu instance can be logged in.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +5 -3
@@ -225,7 +225,8 @@ amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr, index =amdgpu_doorbell_index_on_bar (uq_mgr->adev, db_obj->obj, db_info->doorbell_offset, db_size); -DRM_DEBUG_DRIVER ("[Usermode queues] doorbell index=%lld\n" , index); +drm_dbg_driver (adev_to_drm (uq_mgr->adev), +"[Usermode queues] doorbell index=%lld\n" , index);amdgpu_bo_unreserve (db_obj->obj);return index;
@@ -252,7 +253,7 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id) queue =amdgpu_userqueue_find (uq_mgr, queue_id);if (!queue) { -DRM_DEBUG_DRIVER ("Invalid queue id to destroy\n" ); +drm_dbg_driver (adev_to_drm (adev),"Invalid queue id to destroy\n" );mutex_unlock (&uq_mgr->userq_mutex);return -EINVAL ; }
@@ -416,7 +417,8 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,break ;default : -DRM_DEBUG_DRIVER ("Invalid user queue op specified: %d\n" , args->in.op); +drm_dbg_driver (dev,"Invalid user queue op specified: %d\n" , + args->in.op);return -EINVAL ; }
Signature · 1 line
2.34.1
Quoted 8 lines · Sunil Khatri
Add a drm helper macro which append the process information for the
drm_fileoverdrm_err.v5: change to macro from function (Christian Koenig)
add helper functions for lock/unlock (Christian Koenig)v6: remove
__maybe_unusedand make function inline (Jani Nikula)
removedrm_print.h
I guess I gave all kinds of comments, but in the end my conclusion was:
why does *any* of this have to be static inline or macros? Make drm_file_err() a regular function and hide the implementation inside drm_file.c. That's the cleanest approach IMO.
BR,
Jani.
Quoted 54 lines
Signed-off-by Sunil Khatri <[email protected]>--- include/drm/drm_file.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)include/drm/drm_file.h +37
-0@@ -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);
Signature · 1 line
Jani Nikula, Intel
Christian König
maintainerAm 17.04.25 um 11:35 schrieb Jani Nikula:
Quoted 7 lines · Sunil Khatri
Quoted 6 lines
Add a drm helper macro which append the process information for the
drm_fileoverdrm_err.v5: change to macro from function (Christian Koenig)
add helper functions for lock/unlock (Christian Koenig)
Quoted 6 lines
Quoted 2 lines
v6: remove
__maybe_unusedand make function inline (Jani Nikula)
removedrm_print.hI guess I gave all kinds of comments, but in the end my conclusion was:
why does *any* of this have to be static inline or macros? Makedrm_file_err()a regular function and hide the implementation insidedrm_file.c. That's the cleanest approach IMO.
That won't work. The macro is necessary to concatenate the format strings.
But the drm_task_lock() and drm_task_unlock() functions shouldn't be in the header. Those can be perfectly in drm_file.c or drm_print.c
And we should put drm_file_err into drm_print.h instead of drm_file.h as far as I can see.
Regards,
Christian.
Quoted 57 lines
BR,
Jani.Quoted 53 lines
Signed-off-by Sunil Khatri <[email protected]>--- include/drm/drm_file.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)include/drm/drm_file.h +37
-0@@ -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);
Quoted 8 lines · Christian König
Am 17.04.25 um 11:35 schrieb Jani Nikula:
Quoted 7 lines · Sunil Khatri
Quoted 6 lines
Add a drm helper macro which append the process information for the
drm_fileoverdrm_err.v5: change to macro from function (Christian Koenig)
add helper functions for lock/unlock (Christian Koenig)
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
v6: remove
__maybe_unusedand make function inline (Jani Nikula)
removedrm_print.hI guess I gave all kinds of comments, but in the end my conclusion was:
why does *any* of this have to be static inline or macros? Makedrm_file_err()a regular function and hide the implementation insidedrm_file.c. That's the cleanest approach IMO.That won't work. The macro is necessary to concatenate the format strings.
I think you can handle them using struct va_format and %pV.
BR,
Jani.
Quoted 66 lines
But the
drm_task_lock()anddrm_task_unlock()functions shouldn't be in the header. Those can be perfectly indrm_file.cordrm_print.cAnd we should put
drm_file_errintodrm_print.hinstead ofdrm_file.has far as I can see.Regards,
Christian.Quoted 57 lines
BR,
Jani.Quoted 53 lines
Signed-off-by Sunil Khatri <[email protected]>--- include/drm/drm_file.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)include/drm/drm_file.h +37
-0@@ -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);
Signature · 1 line
Jani Nikula, Intel
Christian König
maintainerAm 17.04.25 um 13:07 schrieb Jani Nikula:
Quoted 9 lines · Christian König
Quoted 8 lines
Am 17.04.25 um 11:35 schrieb Jani Nikula:
Quoted 7 lines · Sunil Khatri
Quoted 6 lines
Add a drm helper macro which append the process information for the
drm_fileoverdrm_err.v5: change to macro from function (Christian Koenig)
add helper functions for lock/unlock (Christian Koenig)
Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
v6: remove
__maybe_unusedand make function inline (Jani Nikula)
removedrm_print.hI guess I gave all kinds of comments, but in the end my conclusion was:
why does *any* of this have to be static inline or macros? Makedrm_file_err()a regular function and hide the implementation insidedrm_file.c. That's the cleanest approach IMO.That won't work. The macro is necessary to concatenate the format strings.
I think you can handle them using struct
va_formatand %pV.
Oh, really good point! I wasn't aware that this functionality exists.
Going to discuss that with Sunil internally.
Thanks,
Christian.
Quoted 68 lines
BR,
Jani.Quoted 63 lines
But the
drm_task_lock()anddrm_task_unlock()functions shouldn't be in the header. Those can be perfectly indrm_file.cordrm_print.cAnd we should put
drm_file_errintodrm_print.hinstead ofdrm_file.has far as I can see.Regards,
Christian.Quoted 56 lines
BR,
Jani.Quoted 53 lines
Signed-off-by Sunil Khatri <[email protected]>--- include/drm/drm_file.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)include/drm/drm_file.h +37
-0@@ -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);
Quoted 16 lines · Christian König
Am 17.04.25 um 13:07 schrieb Jani Nikula:
Quoted 15 lines · Christian König
Quoted 14 lines
Am 17.04.25 um 11:35 schrieb Jani Nikula:
Quoted 13 lines · Sunil Khatri
Quoted 8 lines
Add a drm helper macro which append the process information for the
drm_fileoverdrm_err.v5: change to macro from function (Christian Koenig)
add helper functions for lock/unlock (Christian Koenig)v6: remove
__maybe_unusedand make function inline (Jani Nikula)
removedrm_print.hI guess I gave all kinds of comments, but in the end my conclusion was:
why does *any* of this have to be static inline or macros? Makedrm_file_err()a regular function and hide the implementation insidedrm_file.c. That's the cleanest approach IMO.
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
That won't work. The macro is necessary to concatenate the format strings.
I think you can handle them using struct
va_formatand %pV.Oh, really good point! I wasn't aware that this functionality exists.
Going to discuss that with Sunil internally.
Please see the completely untested patch below for a starting point.
BR,
Jani.
From 55968ab339467c5b6e12ceb157ecbaf62eaa6082 Mon Sep 17 00:00:00 2001
From: Sunil Khatri <[email protected]>
Date: Thu, 17 Apr 2025 14:43:51 +0530
Subject: [PATCH] drm: add macro drm_file_err to print process info
Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
Cc: Jani Nikula <[email protected]>
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
--- drivers/gpu/drm/drm_file.c | 45 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_file.h | 3 +++ 2 files changed, 48 insertions(+)
drivers/gpu/drm/drm_file.c +45 -0
@@ -1025,3 +1025,48 @@ struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags)return file; }EXPORT_SYMBOL_FOR_TESTS_ONLY (mock_drm_getfile); + +static 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 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 +* @format: printf() like format string +* +* This update the user provided buffer with process +* name and pid information for @file_priv +*/ +void drm_file_err (struct drm_file *file_priv,const char *format, ...) +{ +struct drm_device *dev = file_priv->minor->dev; +struct task_struct *task; +struct va_format vaf; +va_list args; + +va_start (args, format); + vaf.fmt = format; + vaf.va = &args; + + task =drm_task_lock (file_priv); +drm_err (dev,"comm: %s pid: %d client: %s %pV" , + task ? task->comm :"" , task ? task->pid :0 , + file_priv->client_name ?:"Unset" , &vaf); +drm_task_unlock (file_priv); +} +EXPORT_SYMBOL (drm_file_err);
include/drm/drm_file.h +3 -0
@@ -446,6 +446,9 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv)return file_priv->minor->type ==DRM_MINOR_ACCEL ; } +__printf(2, 3) +void drm_file_err (struct drm_file *file_priv,const char *format, ...); +void drm_file_update_pid (struct drm_file *);struct drm_minor *drm_minor_acquire (struct xarray *minors_xa,unsigned int minor_id);
Signature · 7 lines
2.39.5 -- Jani Nikula, Intel
[AMD Official Use Only - AMD Internal Distribution Only]
-----Original Message-----
From: Jani Nikula <[email protected]>
Sent: Thursday, April 17, 2025 5:00 PM
To: Koenig, Christian <[email protected]>; Khatri, Sunil <[email protected]>; [email protected]; [email protected]
Cc: Deucher, Alexander <[email protected]>; Tvrtko Ursulin <[email protected]>; Pelloux-Prayer, Pierre-Eric <[email protected]>
Subject: Re: [PATCH v6 1/5] drm: add macro drm_file_err to print process info
Quoted 16 lines · Christian König
Am 17.04.25 um 13:07 schrieb Jani Nikula:
Quoted 15 lines · Christian König
Quoted 14 lines
Am 17.04.25 um 11:35 schrieb Jani Nikula:
Quoted 13 lines · Sunil Khatri
Quoted 8 lines
Add a drm helper macro which append the process information for the
drm_fileoverdrm_err.v5: change to macro from function (Christian Koenig)
add helper functions for lock/unlock (Christian Koenig)v6: remove
__maybe_unusedand make function inline (Jani Nikula)
removedrm_print.hI guess I gave all kinds of comments, but in the end my conclusion was:
why does *any* of this have to be static inline or macros? Makedrm_file_err()a regular function and hide the implementation insidedrm_file.c. That's the cleanest approach IMO.
Quoted 6 lines
Quoted 2 lines
Quoted 1 line
That won't work. The macro is necessary to concatenate the format strings.
I think you can handle them using struct
va_formatand %pV.Oh, really good point! I wasn't aware that this functionality exists.
Going to discuss that with Sunil internally.
Please see the completely untested patch below for a starting point.
BR,
Jani.
From 55968ab339467c5b6e12ceb157ecbaf62eaa6082 Mon Sep 17 00:00:00 2001
From: Sunil Khatri <[email protected]>
Date: Thu, 17 Apr 2025 14:43:51 +0530
Subject: [PATCH] drm: add macro drm_file_err to print process info
Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
Cc: Jani Nikula <[email protected]>
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
--- drivers/gpu/drm/drm_file.c | 45 ++++++++++++++++++++++++++++++++++++++ include/drm/drm_file.h | 3 +++ 2 files changed, 48 insertions(+)
drivers/gpu/drm/drm_file.c +41 -0
@@ -1025,3 +1025,48 @@ struct file *mock_drm_getfile(struct drm_minor *minor, unsigned int flags)return file; }EXPORT_SYMBOL_FOR_TESTS_ONLY (mock_drm_getfile); + +static 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 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 +* @format: printf() like format string +* +* This update the user provided buffer with process +* name and pid information for @file_priv */ void drm_file_err (struct +drm_file *file_priv,const char *format, ...) { +struct drm_device *dev = file_priv->minor->dev; +struct task_struct *task; +struct va_format vaf; +va_list args; + +va_start (args, format); + vaf.fmt = format; + vaf.va = &args; + + task =drm_task_lock (file_priv); +drm_err (dev,"comm: %s pid: %d client: %s %pV" , + task ? task->comm :"" , task ? task->pid :0 , + file_priv->client_name ?:"Unset" , &vaf); +drm_task_unlock (file_priv); +} +EXPORT_SYMBOL (drm_file_err);
I made this change only and validating it. Thanks a lot for suggesting it. Would be great if it works as intended and as we need it.
Regards
Sunil Khatri
include/drm/drm_file.h +3 -1
@@ -446,6 +446,9 @@ static inline bool drm_is_accel_client(const struct drm_file *file_priv)return file_priv->minor->type ==DRM_MINOR_ACCEL ; } +__printf(2, 3) +void drm_file_err (struct drm_file *file_priv,const char *format, ...); +void drm_file_update_pid (struct drm_file *);struct drm_minor *drm_minor_acquire (struct xarray *minors_xa,unsigned int minor_id); --
2.39.5
--
Jani Nikula, Intel