Add support of VM PT and MQD per client-id
Subsystems (3)
v3 cover Add support of VM PT and MQD per client-id
The set of patches rearranges the debugfs related code in the drm subsystem to better manager the root node "dri". Since the dentry for the "dri" is needed in other functionality so the task is necessary.
Over the above amdgpu VM PT support along with User queues MQD dumping support is added based on per client-id as that is a unique no across devices and unlike PID it is more reliable.
Sunil Khatri (4):
drm: move debugfs functionality from drm_drv.c to drm_debugfs.c
drm: add debugfs support on per client-id basis drm/amdgpu: add debugfs support for VM pagetable per client drm/amdgpu: add support of debugfs for mqd information
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 50 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 58 +++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 +- drivers/gpu/drm/drm_debugfs.c | 59 +++++++++++++++++++++-- drivers/gpu/drm/drm_drv.c | 11 ++--- drivers/gpu/drm/drm_file.c | 10 ++++ drivers/gpu/drm/drm_internal.h | 6 +-- include/drm/drm_debugfs.h | 12 +++++ include/drm/drm_device.h | 4 ++ include/drm/drm_drv.h | 10 ++++ include/drm/drm_file.h | 7 +++ 12 files changed, 215 insertions(+), 18 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/4 drm: move debugfs functionality from drm_drv.c to drm_debugfs.c
move the functions from drm_drv.c which uses the static drm_debugfs_root as parent node in the debugfs by drm.
move this root node to the debugfs for easily handling of future requirements to add more information in the root directory and one of which is planned to have directories for each client in the root directory which is dri.
--- drivers/gpu/drm/drm_debugfs.c | 22 ++++++++++++++++++---- drivers/gpu/drm/drm_drv.c | 11 ++++------- drivers/gpu/drm/drm_internal.h | 6 ++---- include/drm/drm_drv.h | 10 ++++++++++ 4 files changed, 34 insertions(+), 15 deletions(-)
drivers/gpu/drm/drm_debugfs.c +18 -4
@@ -44,6 +44,8 @@#include "drm_crtc_internal.h" #include "drm_internal.h" +static struct dentry *drm_debugfs_root; +/*************************************************** * Initialization, etc. **************************************************/
@@ -286,6 +288,16 @@ int drm_debugfs_remove_files(const struct drm_info_list *files, int count, }EXPORT_SYMBOL (drm_debugfs_remove_files); +void drm_debugfs_create_dir (void ) +{ + drm_debugfs_root =debugfs_create_dir ("dri" ,NULL ); +} + +void drm_debugfs_remove_dir (void ) +{ +debugfs_remove (drm_debugfs_root); +} +/** * drm_debugfs_dev_init - create debugfs directory for the device * @dev: the device which we want to create the directory for
@@ -295,7 +307,10 @@ EXPORT_SYMBOL(drm_debugfs_remove_files);*/ void drm_debugfs_dev_init (struct drm_device *dev,struct dentry *root) { - dev->debugfs_root =debugfs_create_dir (dev->unique, root); +if (!root) + dev->debugfs_root =debugfs_create_dir (dev->unique, drm_debugfs_root); +else + dev->debugfs_root =debugfs_create_dir (dev->unique, root); }/**
@@ -322,14 +337,13 @@ void drm_debugfs_dev_register(struct drm_device *dev)drm_atomic_debugfs_init (dev); } -int drm_debugfs_register (struct drm_minor *minor,int minor_id, -struct dentry *root) +int drm_debugfs_register (struct drm_minor *minor,int minor_id) {struct drm_device *dev = minor->dev;char name[64 ];sprintf (name,"%d" , minor_id); - minor->debugfs_symlink =debugfs_create_symlink (name, root, + minor->debugfs_symlink =debugfs_create_symlink (name, drm_debugfs_root, dev->unique);/* TODO: Only for compatibility with drivers */
drivers/gpu/drm/drm_drv.c +4 -7
@@ -69,8 +69,6 @@ DEFINE_XARRAY_ALLOC(drm_minors_xa);*/ static bool drm_core_init_complete; -static struct dentry *drm_debugfs_root; -DEFINE_STATIC_SRCU (drm_unplug_srcu);/*
@@ -183,8 +181,7 @@ static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type)return 0 ;if (minor->type !=DRM_MINOR_ACCEL ) { - ret =drm_debugfs_register (minor, minor->index, - drm_debugfs_root); + ret =drm_debugfs_register (minor, minor->index);if (ret) {DRM_ERROR ("DRM: Failed to initialize /sys/kernel/debug/dri.\n" ); goto err_debugfs;
@@ -754,7 +751,7 @@ static int drm_dev_init(struct drm_device *dev,if (drm_core_check_feature (dev,DRIVER_COMPUTE_ACCEL ))accel_debugfs_init (dev);else -drm_debugfs_dev_init (dev, drm_debugfs_root); +drm_debugfs_dev_init (dev,NULL );return 0 ;
@@ -1168,7 +1165,7 @@ static void drm_core_exit(void)drm_panic_exit ();accel_core_exit ();unregister_chrdev (DRM_MAJOR ,"drm" ); -debugfs_remove (drm_debugfs_root); +drm_debugfs_remove_dir ();drm_sysfs_destroy ();WARN_ON (!xa_empty (&drm_minors_xa));drm_connector_ida_destroy ();
@@ -1187,7 +1184,7 @@ static int __init drm_core_init(void) goto error; } - drm_debugfs_root =debugfs_create_dir ("dri" ,NULL ); +drm_debugfs_create_dir (); ret =register_chrdev (DRM_MAJOR ,"drm" , &drm_stub_fops);if (ret <0 )
drivers/gpu/drm/drm_internal.h +2 -4
@@ -186,8 +186,7 @@ void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map);#if defined(CONFIG_DEBUG_FS )void drm_debugfs_dev_fini (struct drm_device *dev);void drm_debugfs_dev_register (struct drm_device *dev); -int drm_debugfs_register (struct drm_minor *minor,int minor_id, -struct dentry *root); +int drm_debugfs_register (struct drm_minor *minor,int minor_id);void drm_debugfs_unregister (struct drm_minor *minor);void drm_debugfs_connector_add (struct drm_connector *connector);void drm_debugfs_connector_remove (struct drm_connector *connector);
@@ -205,8 +204,7 @@ static inline void drm_debugfs_dev_register(struct drm_device *dev) { } -static inline int drm_debugfs_register (struct drm_minor *minor,int minor_id, -struct dentry *root) +static inline int drm_debugfs_register (struct drm_minor *minor,int minor_id) {return 0 ; }
include/drm/drm_drv.h +10 -0
@@ -567,10 +567,20 @@ static inline bool drm_firmware_drivers_only(void)#if defined(CONFIG_DEBUG_FS )void drm_debugfs_dev_init (struct drm_device *dev,struct dentry *root); +void drm_debugfs_create_dir (void ); +void drm_debugfs_remove_dir (void );#else static inline void drm_debugfs_dev_init (struct drm_device *dev,struct dentry *root) { } + +static inline void drm_debugfs_create_dir (void ) +{ +} + +static inline void drm_debugfs_remove_dir (void ) +{ +}#endif #endif
Signature · 1 line
2.34.1
PATCH v3 2/4 drm: add debugfs support on per client-id basis
In reply to Sunil Khatriadd support to add a directory for each client-id with root at the dri level. Since the clients are unique and not just related to one single drm device, so it makes more sense to add all the client based nodes with root as dri.
Also create a symlink back to the parent drm device from each client.
--- drivers/gpu/drm/drm_debugfs.c | 37 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_file.c | 10 ++++++++++ include/drm/drm_debugfs.h | 12 ++++++++++++ include/drm/drm_device.h | 4 ++++ include/drm/drm_file.h | 7 +++++++ 5 files changed, 70 insertions(+)
drivers/gpu/drm/drm_debugfs.c +37 -0
@@ -298,6 +298,43 @@ void drm_debugfs_remove_dir(void)debugfs_remove (drm_debugfs_root); } +int drm_debugfs_clients_add (struct drm_file *file) +{ +struct drm_device *dev; +char *dir_name, *drm_name, *symlink; + + dev = file->minor->dev; + + dir_name =kasprintf (GFP_KERNEL ,"client-%llu" , file->client_id); +if (!dir_name) +return -ENOMEM ; + +/* Create a debugfs directory for the client in root on drm debugfs */ + file->debugfs_client =debugfs_create_dir (dir_name, drm_debugfs_root); +kfree (dir_name); + + drm_name =kasprintf (GFP_KERNEL ,"%d" , file->minor->index); +if (!drm_name) +return -ENOMEM ; + + symlink =kasprintf (GFP_KERNEL ,"%s" , dev->unique); +if (!symlink) +return -ENOMEM ; + +/* Create a link from client_id to the drm device this client id belongs to */ +debugfs_create_symlink (drm_name, file->debugfs_client, symlink); +kfree (drm_name); +kfree (symlink); + +return 0 ; +} + +void drm_debugfs_clients_remove (struct drm_file *file) +{ +debugfs_remove_recursive (file->debugfs_client); + file->debugfs_client =NULL ; +} +/** * drm_debugfs_dev_init - create debugfs directory for the device * @dev: the device which we want to create the directory for
drivers/gpu/drm/drm_file.c +10 -0
@@ -39,12 +39,14 @@#include <linux/poll.h> #include <linux/slab.h> #include <linux/vga_switcheroo.h> +#include <linux/debugfs.h> #include <drm/drm_client_event.h> #include <drm/drm_drv.h> #include <drm/drm_file.h> #include <drm/drm_gem.h> #include <drm/drm_print.h> +#include <drm/drm_debugfs.h> #include "drm_crtc_internal.h" #include "drm_internal.h"
@@ -143,6 +145,13 @@ struct drm_file *drm_file_alloc(struct drm_minor *minor)rcu_assign_pointer (file->pid,get_pid (task_tgid (current))); file->minor = minor; + ret =drm_debugfs_clients_add (file); +if (ret) { +put_pid (rcu_access_pointer (file->pid)); +kfree (file); +return ERR_PTR (ret); + } +/* for compatibility root is always authenticated */ file->authenticated =capable (CAP_SYS_ADMIN );
@@ -236,6 +245,7 @@ void drm_file_free(struct drm_file *file) atomic_read(&dev->open_count));drm_events_release (file); +drm_debugfs_clients_remove (file);if (drm_core_check_feature (dev,DRIVER_MODESET )) {drm_fb_release (file);
include/drm/drm_debugfs.h +12 -0
@@ -153,6 +153,9 @@ void drm_debugfs_add_files(struct drm_device *dev,int drm_debugfs_gpuva_info (struct seq_file *m,struct drm_gpuvm *gpuvm); + +int drm_debugfs_clients_add (struct drm_file *file); +void drm_debugfs_clients_remove (struct drm_file *file);#else static inline void drm_debugfs_create_files(const struct drm_info_list *files, int count, struct dentry *root,
@@ -181,6 +184,15 @@ static inline int drm_debugfs_gpuva_info(struct seq_file *m, {return 0 ; } + +int drm_debugfs_clients_add (struct drm_file *file) +{ +return 0 ; +} + +void drm_debugfs_clients_remove (struct drm_file *file) +{ +}#endif #endif /* _DRM_DEBUGFS_H_ */
include/drm/drm_device.h +4 -0
@@ -325,6 +325,10 @@ struct drm_device {* Root directory for debugfs files. */ struct dentry *debugfs_root; +/** +* @drm_debugfs_root; +*/ + struct dentry *drm_debugfs_root; };#endif
include/drm/drm_file.h +7 -0
@@ -400,6 +400,13 @@ struct drm_file {* @client_name_lock: Protects @client_name. */ struct mutex client_name_lock; + +/** +* @debugfs_client: +* +* debugfs directory for each client under a drm node. +*/ +struct dentry *debugfs_client; };/**
Signature · 1 line
2.34.1
PATCH v3 3/4 drm/amdgpu: add debugfs support for VM pagetable per client
In reply to Sunil KhatriEach drm node is associated with a unique client-id. Create a directory for each drm-file in the dri root directory. This directory is unique to hold information related to a client id which is unique in the system irrespective of how many drm devices are on the system.
Adding root page table base address of the VM under the client-id node along with the process information in debugfs.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 58 ++++++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 +- 3 files changed, 61 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
@@ -1395,7 +1395,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)if (r) goto error_pasid; - r =amdgpu_vm_init (adev, &fpriv->vm, fpriv->xcp_id); + r =amdgpu_vm_init (adev, &fpriv->vm, fpriv->xcp_id, file_priv);if (r) goto error_pasid;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +57 -1
82 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3 -1
@@ -487,7 +487,9 @@ int amdgpu_vm_set_pasid(struct amdgpu_device *adev, struct amdgpu_vm *vm, u32 pasid);long amdgpu_vm_wait_idle (struct amdgpu_vm *vm,long timeout); -int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm,int32_t xcp_id); +int amdgpu_vm_init (struct amdgpu_device *adev,struct amdgpu_vm *vm,int32_t xcp_id, +struct drm_file *file); +int amdgpu_vm_make_compute (struct amdgpu_device *adev,struct amdgpu_vm *vm);void amdgpu_vm_fini (struct amdgpu_device *adev,struct amdgpu_vm *vm); int amdgpu_vm_lock_pd(struct amdgpu_vm *vm, struct drm_exec *exec,
Signature · 1 line
2.34.1
PATCH v3 4/4 drm/amdgpu: add support of debugfs for mqd information
In reply to Sunil Khatriadd mqd support based on queue of for each client-id so the gpu address could be used to dump the mqd.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +50 -0
@@ -343,6 +343,46 @@ static int amdgpu_userq_priority_permit(struct drm_file *filp,return -EACCES ; } +#if defined(CONFIG_DEBUG_FS ) +static int amdgpu_mqd_info_read (struct seq_file *m,void *unused) +{ +struct amdgpu_usermode_queue *queue = (struct amdgpu_usermode_queue *)m->private; +struct amdgpu_bo *bo; +int r; + +if (!queue || !queue->mqd.obj) +return -EINVAL ; + + bo =amdgpu_bo_ref (queue->mqd.obj); + r =amdgpu_bo_reserve (bo, true); +if (r) { +amdgpu_bo_unref (&bo); +return 0 ; + } + +seq_printf (m,"queue_type %d\n" , queue->queue_type); +seq_printf (m,"mqd_gpu_address: 0x%llx\n" ,amdgpu_bo_gpu_offset (queue->mqd.obj)); + +amdgpu_bo_unreserve (bo); +amdgpu_bo_unref (&bo); + +return 0 ; +} + +static int amdgpu_mqd_info_open (struct inode *inode,struct file *file) +{ +return single_open (file, amdgpu_mqd_info_read, inode->i_private); +} + +static const struct file_operations amdgpu_mqd_info_fops = { + .owner =THIS_MODULE , + .open = amdgpu_mqd_info_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +#endif +static int amdgpu_userq_create (struct drm_file *filp,union drm_amdgpu_userq *args) {
@@ -352,6 +392,8 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)const struct amdgpu_userq_funcs *uq_funcs;struct amdgpu_usermode_queue *queue;struct amdgpu_db_info db_info; +char *queue_name; +struct dentry *debugfs_queue;bool skip_map_queue;uint64_t index;int qid, r =0 ;
@@ -475,6 +517,14 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) } } + queue_name =kasprintf (GFP_KERNEL ,"queue-%d" , qid); +if (!queue_name) +return -ENOMEM ; + +/* Create a debugfs directory for the client in root on drm debugfs */ + debugfs_queue =debugfs_create_dir (queue_name, filp->debugfs_client); +debugfs_create_file ("mqd_info" ,0444 , debugfs_queue, queue, &amdgpu_mqd_info_fops); +kfree (queue_name); args->out.queue_id = qid;
Signature · 1 line
2.34.1