drm: introduce new method of creating debugfs files.
Subsystems (3)
cover drm: introduce new method of creating debugfs files.
Hi All,
Currently drm debugfs files are created using drm_debugfs_create_files() on request.
This series introduces new functions and infrastructure that will enable the mass creation of debugfs files during drm_dev_register(). Drivers can request for the creation of debugfs files at any time using two new
functions: drm_debugfs_add_files()/drm_debugfs_add_file(). The file requests are added to a list and tracked until drm_dev_register() when the files are created all at once.
This concept was already in use by the drm/vc4 driver and this series tries to introduce the same infrastructure in drm core. Patch 2 removes vc4's functions doing the same, and replaces it with the new drm core functions.
Patch 3 is an example of how the new functions and structs can replace the existing drm_info_list and drm_debugfs_create_files() usage.
Hoping to get some feedback or comments on the current progress of this series.
Thanks,
wambui karuga
Wambui Karuga (3):
drm/debugfs: create debugfs files during drm_dev_register(). drm/vc4: use new debugfs functions for file creation.
drm: use new debugfs functions for various files.
drivers/gpu/drm/drm_atomic.c | 11 +++--- drivers/gpu/drm/drm_client.c | 11 +++--- drivers/gpu/drm/drm_debugfs.c | 59 ++++++++++++++++++++++++++++--- drivers/gpu/drm/drm_drv.c | 2 ++ drivers/gpu/drm/drm_framebuffer.c | 11 +++--- drivers/gpu/drm/vc4/vc4_bo.c | 4 +-- drivers/gpu/drm/vc4/vc4_debugfs.c | 38 +++++--------------- drivers/gpu/drm/vc4/vc4_hdmi.c | 4 +-- drivers/gpu/drm/vc4/vc4_hvs.c | 4 +-- drivers/gpu/drm/vc4/vc4_v3d.c | 4 +-- include/drm/drm_debugfs.h | 38 ++++++++++++++++++++ include/drm/drm_device.h | 12 +++++++ 12 files changed, 138 insertions(+), 60 deletions(-)
Signature · 1 line
2.26.2
RFC PATCH 1/3 drm/debugfs: create debugfs files during drm_dev_register().
Introduce the ability to track requests for the addition of drm debugfs files at any time and have them added all at once during drm_dev_register().
Drivers can add drm debugfs file requests to a new list tied to drm_device. During drm_dev_register(), the new function drm_debugfs_create_file() will iterate over the list of added files on a given minor to create them.
Two new structs are introduced in this change: struct drm_simple_info which represents a drm debugfs file entry and struct drm_simple_info_entry which is used to track file requests and is the main parameter of choice passed by functions. Each drm_simple_info_entry is added to the new struct drm_device->debugfs_list for file requests.
--- drivers/gpu/drm/drm_debugfs.c | 59 ++++++++++++++++++++++++++++++++--- drivers/gpu/drm/drm_drv.c | 2 ++ include/drm/drm_debugfs.h | 38 ++++++++++++++++++++++ include/drm/drm_device.h | 12 +++++++ 4 files changed, 107 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_debugfs.c +55 -4
@@ -145,9 +145,10 @@ static const struct drm_info_list drm_debugfs_list[] = {static int drm_debugfs_open (struct inode *inode,struct file *file) { -struct drm_info_node *node = inode->i_private; +struct drm_simple_info_entry *entry = inode->i_private; +struct drm_simple_info *node = &entry->file; -return single_open (file, node->info_ent->show, node); +return single_open (file, node->show_fn, entry); }
@@ -159,6 +160,25 @@ static const struct file_operations drm_debugfs_fops = { .release = single_release, }; +/** +* drm_debugfs_create_file - create DRM debugfs file. +* @dev: drm_device that the file belongs to +* +* Create a DRM debugfs file from the list of files to be created +* from dev->debugfs_list. +*/ +static void drm_debugfs_create_file (struct drm_minor *minor) +{ +struct drm_device *dev = minor->dev; +struct drm_simple_info_entry *entry; + +list_for_each_entry (entry, &dev->debugfs_list, list) { +debugfs_create_file (entry->file.name, +S_IFREG |S_IRUGO , minor->debugfs_root, + entry, + &drm_debugfs_fops); + } +}/** * drm_debugfs_create_files - Initialize a given set of debugfs files for DRM
@@ -213,8 +233,7 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,sprintf (name,"%d" , minor_id); minor->debugfs_root =debugfs_create_dir (name, root); -drm_debugfs_create_files (drm_debugfs_list,DRM_DEBUGFS_ENTRIES , - minor->debugfs_root, minor); +drm_debugfs_create_file (minor);if (drm_drv_uses_atomic_modeset (dev)) {drm_atomic_debugfs_init (minor);
@@ -449,4 +468,36 @@ void drm_debugfs_crtc_remove(struct drm_crtc *crtc) crtc->debugfs_entry =NULL ; } +void drm_debugfs_add_file (struct drm_device *dev,const char *name, +drm_simple_show_t show_fn,void *data) +{ +struct drm_simple_info_entry *entry = +kzalloc (sizeof (*entry),GFP_KERNEL ); + +if (!entry) +return ; + + entry->file.name = name; + entry->file.show_fn = show_fn; + entry->file.data = data; + entry->dev = dev; + +mutex_lock (&dev->debugfs_mutex); +list_add (&entry->list, &dev->debugfs_list); +mutex_unlock (&dev->debugfs_mutex); +} +EXPORT_SYMBOL (drm_debugfs_add_file); + +void drm_debugfs_add_files (struct drm_device *dev, +const struct drm_simple_info *files,int count) +{ +int i; + +for (i =0 ; i < count; i++) { +drm_debugfs_add_file (dev, files[i].name, files[i].show_fn, + files[i].data); + } +} +EXPORT_SYMBOL (drm_debugfs_add_files); +#endif /* CONFIG_DEBUG_FS */
drivers/gpu/drm/drm_drv.c +2 -0
@@ -646,12 +646,14 @@ int drm_dev_init(struct drm_device *dev,INIT_LIST_HEAD (&dev->filelist_internal);INIT_LIST_HEAD (&dev->clientlist);INIT_LIST_HEAD (&dev->vblank_event_list); +INIT_LIST_HEAD (&dev->debugfs_list);spin_lock_init (&dev->event_lock);mutex_init (&dev->struct_mutex);mutex_init (&dev->filelist_mutex);mutex_init (&dev->clientlist_mutex);mutex_init (&dev->master_mutex); +mutex_init (&dev->debugfs_mutex); ret =drmm_add_action (dev, drm_dev_init_release,NULL );if (ret)
include/drm/drm_debugfs.h +38 -0
@@ -34,6 +34,44 @@#include <linux/types.h> #include <linux/seq_file.h> + +struct drm_device ; + +typedef int (*drm_simple_show_t )(struct seq_file *,void *); + +/** +* struct drm_simple_info - debugfs file entry +* +* This struct represents a debugfs file to be created. +*/ +struct drm_simple_info { +const char *name; +drm_simple_show_t show_fn; +u32 driver_features; +void *data; +}; + +/** +* struct drm_simple_info_entry - debugfs list entry +* +* This struct is used in tracking requests for new debugfs files +* to be created. +*/ +struct drm_simple_info_entry { +struct drm_device *dev; +struct drm_simple_info file; +struct list_head list; +}; + +void drm_debugfs_add_file (struct drm_device *dev, +const char *name, +drm_simple_show_t show_fn, +void *data); + +void drm_debugfs_add_files (struct drm_device *dev, +const struct drm_simple_info *files, +int count); +/** * struct drm_info_list - debugfs info list entry *
include/drm/drm_device.h +12 -0
@@ -326,6 +326,18 @@ struct drm_device {*/ struct drm_fb_helper *fb_helper; +/** +* @debugfs_mutex: +* Protects debugfs_list access. +*/ +struct mutex debugfs_mutex; + +/** @debugfs_list: +* List of debugfs files to add. +* Files are added during drm_dev_register(). +*/ +struct list_head debugfs_list; +/* Everything below here is for legacy driver, never use! */ /* private: */ #if IS_ENABLED (CONFIG_DRM_LEGACY )
Signature · 1 line
2.26.2
Thomas Zimmermann
maintainerRe: [RFC PATCH 1/3] drm/debugfs: create debugfs files during drm_dev_register().
Hi
Am 13.05.20 um 13:41 schrieb Wambui Karuga:
Quoted 42 lines
Introduce the ability to track requests for the addition of drm debugfs files at any time and have them added all at once during
drm_dev_register().Drivers can add drm debugfs file requests to a new list tied to
drm_device. Duringdrm_dev_register(), the new functiondrm_debugfs_create_file()will iterate over the list of added files on a given minor to create them.Two new structs are introduced in this change: struct
drm_simple_infowhich represents a drm debugfs file entry and structdrm_simple_info_entrywhich is used to track file requests and is the main parameter of choice passed by functions. Eachdrm_simple_info_entryis added to the new structdrm_device->debugfs_listfor file requests.Signed-off-by Wambui Karuga <[email protected]>--- drivers/gpu/drm/drm_debugfs.c | 59 ++++++++++++++++++++++++++++++++--- drivers/gpu/drm/drm_drv.c | 2 ++ include/drm/drm_debugfs.h | 38 ++++++++++++++++++++++ include/drm/drm_device.h | 12 +++++++ 4 files changed, 107 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_debugfs.c +3
-2@@ -145,9 +145,10 @@ static const struct drm_info_list drm_debugfs_list[] = {static int drm_debugfs_open (struct inode *inode,struct file *file) { -struct drm_info_node *node = inode->i_private; +struct drm_simple_info_entry *entry = inode->i_private; +struct drm_simple_info *node = &entry->file; -return single_open (file, node->info_ent->show, node); +return single_open (file, node->show_fn, entry); }@@ -159,6 +160,25 @@ static const struct file_operations drm_debugfs_fops = { .release = single_release,
drivers/gpu/drm/drm_debugfs.c static const struct file_operations drm_debugfs_fops = { · line 170
Quoted 10 lines
drivers/gpu/drm/drm_debugfs.c +8
-0}; +/** +* drm_debugfs_create_file - create DRM debugfs file. +* @dev: drm_device that the file belongs to +* +* Create a DRM debugfs file from the list of files to be created +* from dev->debugfs_list. +*/ +static void drm_debugfs_create_file (struct drm_minor *minor)
This function creates several files. I'd rather call it drm_debugfs_create_added_files().
drivers/gpu/drm/drm_debugfs.c static const struct file_operations drm_debugfs_fops = { · line 180
Quoted 10 lines
drivers/gpu/drm/drm_debugfs.c +10
-0+{ +struct drm_device *dev = minor->dev; +struct drm_simple_info_entry *entry; + +list_for_each_entry (entry, &dev->debugfs_list, list) { +debugfs_create_file (entry->file.name, +S_IFREG |S_IRUGO , minor->debugfs_root, + entry, + &drm_debugfs_fops); + }
I think the created items should be removed from the list. That way, drivers can call the function multiple times without recreating the same files again.
drivers/gpu/drm/drm_debugfs.c int drm_debugfs_init(struct drm_minor *minor, int minor_id, · line 217
Quoted 10 lines
drivers/gpu/drm/drm_debugfs.c +1
-2+}/** * drm_debugfs_create_files - Initialize a given set of debugfs files for DRM @@ -213,8 +233,7 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,sprintf (name,"%d" , minor_id); minor->debugfs_root =debugfs_create_dir (name, root); -drm_debugfs_create_files (drm_debugfs_list,DRM_DEBUGFS_ENTRIES , - minor->debugfs_root, minor);
By removing these two lines, aren't you losing the files listed in DRM_DEBUGFS_ENTRIES?
Quoted 69 lines
drivers/gpu/drm/drm_debugfs.c +33
-0+drm_debugfs_create_file (minor);if (drm_drv_uses_atomic_modeset (dev)) {drm_atomic_debugfs_init (minor);@@ -449,4 +468,36 @@ void drm_debugfs_crtc_remove(struct drm_crtc *crtc) crtc->debugfs_entry =NULL ; } +void drm_debugfs_add_file (struct drm_device *dev,const char *name, +drm_simple_show_t show_fn,void *data) +{ +struct drm_simple_info_entry *entry = +kzalloc (sizeof (*entry),GFP_KERNEL ); + +if (!entry) +return ; + + entry->file.name = name; + entry->file.show_fn = show_fn; + entry->file.data = data; + entry->dev = dev; + +mutex_lock (&dev->debugfs_mutex); +list_add (&entry->list, &dev->debugfs_list); +mutex_unlock (&dev->debugfs_mutex); +} +EXPORT_SYMBOL (drm_debugfs_add_file); + +void drm_debugfs_add_files (struct drm_device *dev, +const struct drm_simple_info *files,int count) +{ +int i; + +for (i =0 ; i < count; i++) { +drm_debugfs_add_file (dev, files[i].name, files[i].show_fn, + files[i].data); + } +} +EXPORT_SYMBOL (drm_debugfs_add_files); +#endif /* CONFIG_DEBUG_FS */ drivers/gpu/drm/drm_drv.c +2
-0@@ -646,12 +646,14 @@ int drm_dev_init(struct drm_device *dev,INIT_LIST_HEAD (&dev->filelist_internal);INIT_LIST_HEAD (&dev->clientlist);INIT_LIST_HEAD (&dev->vblank_event_list); +INIT_LIST_HEAD (&dev->debugfs_list);spin_lock_init (&dev->event_lock);mutex_init (&dev->struct_mutex);mutex_init (&dev->filelist_mutex);mutex_init (&dev->clientlist_mutex);mutex_init (&dev->master_mutex); +mutex_init (&dev->debugfs_mutex); ret =drmm_add_action (dev, drm_dev_init_release,NULL );if (ret)include/drm/drm_debugfs.h +1
-0@@ -34,6 +34,44 @@#include <linux/types.h> #include <linux/seq_file.h> +
include/drm/drm_debugfs.h line 47
Quoted 10 lines
include/drm/drm_debugfs.h +10
-0+struct drm_device ; + +typedef int (*drm_simple_show_t )(struct seq_file *,void *); + +/** +* struct drm_simple_info - debugfs file entry +* +* This struct represents a debugfs file to be created. +*/ +struct drm_simple_info {
drm_simple_info and drm_simple_info_entry seem to be misnomers. They should probably have some reference to debugfs in their name.
Best regards
Thomas
Quoted 54 lines
include/drm/drm_debugfs.h +27
-0+const char *name; +drm_simple_show_t show_fn; +u32 driver_features; +void *data; +}; + +/** +* struct drm_simple_info_entry - debugfs list entry +* +* This struct is used in tracking requests for new debugfs files +* to be created. +*/ +struct drm_simple_info_entry { +struct drm_device *dev; +struct drm_simple_info file; +struct list_head list; +}; + +void drm_debugfs_add_file (struct drm_device *dev, +const char *name, +drm_simple_show_t show_fn, +void *data); + +void drm_debugfs_add_files (struct drm_device *dev, +const struct drm_simple_info *files, +int count); +/** * struct drm_info_list - debugfs info list entry * include/drm/drm_device.h +12
-0@@ -326,6 +326,18 @@ struct drm_device {*/ struct drm_fb_helper *fb_helper; +/** +* @debugfs_mutex: +* Protects debugfs_list access. +*/ +struct mutex debugfs_mutex; + +/** @debugfs_list: +* List of debugfs files to add. +* Files are added during drm_dev_register(). +*/ +struct list_head debugfs_list; +/* Everything below here is for legacy driver, never use! */ /* private: */ #if IS_ENABLED (CONFIG_DRM_LEGACY )
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [RFC PATCH 1/3] drm/debugfs: create debugfs files during drm_dev_register().
Quoted 47 lines · Thomas Zimmermann
Hi
Am 13.05.20 um 13:41 schrieb Wambui Karuga:
Quoted 44 lines
Introduce the ability to track requests for the addition of drm debugfs files at any time and have them added all at once during
drm_dev_register().Drivers can add drm debugfs file requests to a new list tied to
drm_device. Duringdrm_dev_register(), the new functiondrm_debugfs_create_file()will iterate over the list of added files on a given minor to create them.Two new structs are introduced in this change: struct
drm_simple_infowhich represents a drm debugfs file entry and structdrm_simple_info_entrywhich is used to track file requests and is the main parameter of choice passed by functions. Eachdrm_simple_info_entryis added to the new structdrm_device->debugfs_listfor file requests.Signed-off-by Wambui Karuga <[email protected]>--- drivers/gpu/drm/drm_debugfs.c | 59 ++++++++++++++++++++++++++++++++--- drivers/gpu/drm/drm_drv.c | 2 ++ include/drm/drm_debugfs.h | 38 ++++++++++++++++++++++ include/drm/drm_device.h | 12 +++++++ 4 files changed, 107 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_debugfs.c +3
-2@@ -145,9 +145,10 @@ static const struct drm_info_list drm_debugfs_list[] = {static int drm_debugfs_open (struct inode *inode,struct file *file) { -struct drm_info_node *node = inode->i_private; +struct drm_simple_info_entry *entry = inode->i_private; +struct drm_simple_info *node = &entry->file; -return single_open (file, node->info_ent->show, node); +return single_open (file, node->show_fn, entry); }@@ -159,6 +160,25 @@ static const struct file_operations drm_debugfs_fops = { .release = single_release, };
Quoted 12 lines
drivers/gpu/drm/drm_debugfs.c static const struct file_operations drm_debugfs_fops = { · line 170
Quoted 8 lines
drivers/gpu/drm/drm_debugfs.c +8
-0+/** +* drm_debugfs_create_file - create DRM debugfs file. +* @dev: drm_device that the file belongs to +* +* Create a DRM debugfs file from the list of files to be created +* from dev->debugfs_list. +*/ +static void drm_debugfs_create_file (struct drm_minor *minor)This function creates several files. I'd rather call it
drm_debugfs_create_added_files().
Okay, that makes sense. I can change that.
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/drm_debugfs.c +6
-0+{ +struct drm_device *dev = minor->dev; +struct drm_simple_info_entry *entry; + +list_for_each_entry (entry, &dev->debugfs_list, list) { + debugfs_create_file(entry->file.name,
Quoted 9 lines
drivers/gpu/drm/drm_debugfs.c static const struct file_operations drm_debugfs_fops = { · line 180
Quoted 4 lines
drivers/gpu/drm/drm_debugfs.c +4
-0+S_IFREG |S_IRUGO , minor->debugfs_root, + entry, + &drm_debugfs_fops); + }I think the created items should be removed from the list. That way, drivers can call the function multiple times without recreating the same files again.
Hadn't thought of that - I can try add that.
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/drm_debugfs.c +1
-0+}/** * drm_debugfs_create_files - Initialize a given set of debugfs files for DRM @@ -213,8 +233,7 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,sprintf (name,"%d" , minor_id); minor->debugfs_root =debugfs_create_dir (name, root);
Quoted 6 lines
drivers/gpu/drm/drm_debugfs.c int drm_debugfs_init(struct drm_minor *minor, int minor_id, · line 217
Quoted 2 lines
drivers/gpu/drm/drm_debugfs.c +0
-2-drm_debugfs_create_files (drm_debugfs_list,DRM_DEBUGFS_ENTRIES , - minor->debugfs_root, minor);By removing these two lines, aren't you losing the files listed in
DRM_DEBUGFS_ENTRIES?
Yes.
When using the new functions, drm_debugfs_create_files() should not be called at this point, but for compatibility these two lines should be put back, I think.
Quoted 66 lines
Quoted 66 lines
drivers/gpu/drm/drm_debugfs.c +33
-0+drm_debugfs_create_file (minor);if (drm_drv_uses_atomic_modeset (dev)) {drm_atomic_debugfs_init (minor);@@ -449,4 +468,36 @@ void drm_debugfs_crtc_remove(struct drm_crtc *crtc) crtc->debugfs_entry =NULL ; } +void drm_debugfs_add_file (struct drm_device *dev,const char *name, +drm_simple_show_t show_fn,void *data) +{ +struct drm_simple_info_entry *entry = +kzalloc (sizeof (*entry),GFP_KERNEL ); + +if (!entry) +return ; + + entry->file.name = name; + entry->file.show_fn = show_fn; + entry->file.data = data; + entry->dev = dev; + +mutex_lock (&dev->debugfs_mutex); +list_add (&entry->list, &dev->debugfs_list); +mutex_unlock (&dev->debugfs_mutex); +} +EXPORT_SYMBOL (drm_debugfs_add_file); + +void drm_debugfs_add_files (struct drm_device *dev, +const struct drm_simple_info *files,int count) +{ +int i; + +for (i =0 ; i < count; i++) { +drm_debugfs_add_file (dev, files[i].name, files[i].show_fn, + files[i].data); + } +} +EXPORT_SYMBOL (drm_debugfs_add_files); +#endif /* CONFIG_DEBUG_FS */ drivers/gpu/drm/drm_drv.c +2
-0@@ -646,12 +646,14 @@ int drm_dev_init(struct drm_device *dev,INIT_LIST_HEAD (&dev->filelist_internal);INIT_LIST_HEAD (&dev->clientlist);INIT_LIST_HEAD (&dev->vblank_event_list); +INIT_LIST_HEAD (&dev->debugfs_list);spin_lock_init (&dev->event_lock);mutex_init (&dev->struct_mutex);mutex_init (&dev->filelist_mutex);mutex_init (&dev->clientlist_mutex);mutex_init (&dev->master_mutex); +mutex_init (&dev->debugfs_mutex); ret =drmm_add_action (dev, drm_dev_init_release,NULL );if (ret)include/drm/drm_debugfs.h +0
-0@@ -34,6 +34,44 @@
Quoted 17 lines
include/drm/drm_debugfs.h line 47
Quoted 13 lines
include/drm/drm_debugfs.h +11
-0#include <linux/types.h> #include <linux/seq_file.h> + +struct drm_device ; + +typedef int (*drm_simple_show_t )(struct seq_file *,void *); + +/** +* struct drm_simple_info - debugfs file entry +* +* This struct represents a debugfs file to be created. +*/ +struct drm_simple_info {
drm_simple_infoanddrm_simple_info_entryseem to be misnomers. They should probably have some reference to debugfs in their name.
I'll change the names.
Thanks,
wambui karuga
Quoted 68 lines
Best regards
ThomasQuoted 54 lines
include/drm/drm_debugfs.h +27
-0+const char *name; +drm_simple_show_t show_fn; +u32 driver_features; +void *data; +}; + +/** +* struct drm_simple_info_entry - debugfs list entry +* +* This struct is used in tracking requests for new debugfs files +* to be created. +*/ +struct drm_simple_info_entry { +struct drm_device *dev; +struct drm_simple_info file; +struct list_head list; +}; + +void drm_debugfs_add_file (struct drm_device *dev, +const char *name, +drm_simple_show_t show_fn, +void *data); + +void drm_debugfs_add_files (struct drm_device *dev, +const struct drm_simple_info *files, +int count); +/** * struct drm_info_list - debugfs info list entry * include/drm/drm_device.h +12
-0@@ -326,6 +326,18 @@ struct drm_device {*/ struct drm_fb_helper *fb_helper; +/** +* @debugfs_mutex: +* Protects debugfs_list access. +*/ +struct mutex debugfs_mutex; + +/** @debugfs_list: +* List of debugfs files to add. +* Files are added during drm_dev_register(). +*/ +struct list_head debugfs_list; +/* Everything below here is for legacy driver, never use! */ /* private: */ #if IS_ENABLED (CONFIG_DRM_LEGACY )Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Re: [RFC PATCH 1/3] drm/debugfs: create debugfs files during drm_dev_register().
Quoted 81 lines · Wambui Karuga
Quoted 47 lines · Thomas Zimmermann
Hi
Am 13.05.20 um 13:41 schrieb Wambui Karuga:
Quoted 44 lines
Introduce the ability to track requests for the addition of drm debugfs files at any time and have them added all at once during
drm_dev_register().Drivers can add drm debugfs file requests to a new list tied to
drm_device. Duringdrm_dev_register(), the new functiondrm_debugfs_create_file()will iterate over the list of added files on a given minor to create them.Two new structs are introduced in this change: struct
drm_simple_infowhich represents a drm debugfs file entry and structdrm_simple_info_entrywhich is used to track file requests and is the main parameter of choice passed by functions. Eachdrm_simple_info_entryis added to the new structdrm_device->debugfs_listfor file requests.Signed-off-by Wambui Karuga <[email protected]>--- drivers/gpu/drm/drm_debugfs.c | 59 ++++++++++++++++++++++++++++++++--- drivers/gpu/drm/drm_drv.c | 2 ++ include/drm/drm_debugfs.h | 38 ++++++++++++++++++++++ include/drm/drm_device.h | 12 +++++++ 4 files changed, 107 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_debugfs.c +3
-2@@ -145,9 +145,10 @@ static const struct drm_info_list drm_debugfs_list[] = {static int drm_debugfs_open (struct inode *inode,struct file *file) { -struct drm_info_node *node = inode->i_private; +struct drm_simple_info_entry *entry = inode->i_private; +struct drm_simple_info *node = &entry->file; -return single_open (file, node->info_ent->show, node); +return single_open (file, node->show_fn, entry); }@@ -159,6 +160,25 @@ static const struct file_operations drm_debugfs_fops = { .release = single_release, };Quoted 12 lines
drivers/gpu/drm/drm_debugfs.c static const struct file_operations drm_debugfs_fops = { · line 170
Quoted 8 lines
drivers/gpu/drm/drm_debugfs.c +8
-0+/** +* drm_debugfs_create_file - create DRM debugfs file. +* @dev: drm_device that the file belongs to +* +* Create a DRM debugfs file from the list of files to be created +* from dev->debugfs_list. +*/ +static void drm_debugfs_create_file (struct drm_minor *minor)This function creates several files. I'd rather call it
drm_debugfs_create_added_files().Okay, that makes sense. I can change that.
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/drm_debugfs.c +6
-0+{ +struct drm_device *dev = minor->dev; +struct drm_simple_info_entry *entry; + +list_for_each_entry (entry, &dev->debugfs_list, list) { + debugfs_create_file(entry->file.name,Quoted 9 lines
drivers/gpu/drm/drm_debugfs.c static const struct file_operations drm_debugfs_fops = { · line 180
Quoted 4 lines
drivers/gpu/drm/drm_debugfs.c +4
-0+S_IFREG |S_IRUGO , minor->debugfs_root, + entry, + &drm_debugfs_fops); + }I think the created items should be removed from the list. That way, drivers can call the function multiple times without recreating the same files again.
Quoted 1 line
Hadn't thought of that - I can try add that.
The function here is static, called once by the core. So no need for complicated logic, it's guaranteed to only be called once.
I guess what confused Thomas is the kerneldoc. We generally only do that for functions exported to drivers, that drivers should call. Not the case here. The function name itself is descriptive enough I think (with Thomas' suggestion even better). So I'd just remove the kerneldoc here.
-Daniel
Quoted 174 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/drm_debugfs.c +1
-0+}/** * drm_debugfs_create_files - Initialize a given set of debugfs files for DRM @@ -213,8 +233,7 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,sprintf (name,"%d" , minor_id); minor->debugfs_root =debugfs_create_dir (name, root);Quoted 6 lines
drivers/gpu/drm/drm_debugfs.c int drm_debugfs_init(struct drm_minor *minor, int minor_id, · line 217
Quoted 2 lines
drivers/gpu/drm/drm_debugfs.c +0
-2-drm_debugfs_create_files (drm_debugfs_list,DRM_DEBUGFS_ENTRIES , - minor->debugfs_root, minor);By removing these two lines, aren't you losing the files listed in
DRM_DEBUGFS_ENTRIES?Yes.
When using the new functions,drm_debugfs_create_files()should not be called at this point, but for compatibility these two lines should be put back, I think.Quoted 66 lines
Quoted 66 lines
drivers/gpu/drm/drm_debugfs.c +33
-0+drm_debugfs_create_file (minor);if (drm_drv_uses_atomic_modeset (dev)) {drm_atomic_debugfs_init (minor);@@ -449,4 +468,36 @@ void drm_debugfs_crtc_remove(struct drm_crtc *crtc) crtc->debugfs_entry =NULL ; } +void drm_debugfs_add_file (struct drm_device *dev,const char *name, +drm_simple_show_t show_fn,void *data) +{ +struct drm_simple_info_entry *entry = +kzalloc (sizeof (*entry),GFP_KERNEL ); + +if (!entry) +return ; + + entry->file.name = name; + entry->file.show_fn = show_fn; + entry->file.data = data; + entry->dev = dev; + +mutex_lock (&dev->debugfs_mutex); +list_add (&entry->list, &dev->debugfs_list); +mutex_unlock (&dev->debugfs_mutex); +} +EXPORT_SYMBOL (drm_debugfs_add_file); + +void drm_debugfs_add_files (struct drm_device *dev, +const struct drm_simple_info *files,int count) +{ +int i; + +for (i =0 ; i < count; i++) { +drm_debugfs_add_file (dev, files[i].name, files[i].show_fn, + files[i].data); + } +} +EXPORT_SYMBOL (drm_debugfs_add_files); +#endif /* CONFIG_DEBUG_FS */ drivers/gpu/drm/drm_drv.c +2
-0@@ -646,12 +646,14 @@ int drm_dev_init(struct drm_device *dev,INIT_LIST_HEAD (&dev->filelist_internal);INIT_LIST_HEAD (&dev->clientlist);INIT_LIST_HEAD (&dev->vblank_event_list); +INIT_LIST_HEAD (&dev->debugfs_list);spin_lock_init (&dev->event_lock);mutex_init (&dev->struct_mutex);mutex_init (&dev->filelist_mutex);mutex_init (&dev->clientlist_mutex);mutex_init (&dev->master_mutex); +mutex_init (&dev->debugfs_mutex); ret =drmm_add_action (dev, drm_dev_init_release,NULL );if (ret)include/drm/drm_debugfs.h +0
-0@@ -34,6 +34,44 @@Quoted 17 lines
include/drm/drm_debugfs.h line 47
Quoted 13 lines
include/drm/drm_debugfs.h +11
-0#include <linux/types.h> #include <linux/seq_file.h> + +struct drm_device ; + +typedef int (*drm_simple_show_t )(struct seq_file *,void *); + +/** +* struct drm_simple_info - debugfs file entry +* +* This struct represents a debugfs file to be created. +*/ +struct drm_simple_info {
drm_simple_infoanddrm_simple_info_entryseem to be misnomers. They should probably have some reference to debugfs in their name.I'll change the names.
Thanks,
wambui karugaQuoted 68 lines
Best regards
ThomasQuoted 44 lines
include/drm/drm_debugfs.h +27
-0+const char *name; +drm_simple_show_t show_fn; +u32 driver_features; +void *data; +}; + +/** +* struct drm_simple_info_entry - debugfs list entry +* +* This struct is used in tracking requests for new debugfs files +* to be created. +*/ +struct drm_simple_info_entry { +struct drm_device *dev; +struct drm_simple_info file; +struct list_head list; +}; + +void drm_debugfs_add_file (struct drm_device *dev, +const char *name, +drm_simple_show_t show_fn, +void *data); + +void drm_debugfs_add_files (struct drm_device *dev, +const struct drm_simple_info *files, +int count); +/** * struct drm_info_list - debugfs info list entry * include/drm/drm_device.h +5
-0@@ -326,6 +326,18 @@ struct drm_device {*/ struct drm_fb_helper *fb_helper; +/** +* @debugfs_mutex: +* Protects debugfs_list access. +*/ +struct mutex debugfs_mutex;include/drm/drm_device.h struct drm_device { · line 343
Quoted 10 lines
include/drm/drm_device.h +7
-0+ +/** @debugfs_list: +* List of debugfs files to add. +* Files are added during drm_dev_register(). +*/ +struct list_head debugfs_list; +/* Everything below here is for legacy driver, never use! */ /* private: */ #if IS_ENABLED (CONFIG_DRM_LEGACY )--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
RFC PATCH 2/3 drm/vc4: use new debugfs functions for file creation.
In reply to Wambui KarugaCurrently, vc4 delays adding of debugfs files until drm_dev_register() calls vc4_debugfs_init() on each registered minor.
This change removes this infrastructure and uses the new drm_debugfs_add_file() function and drm_device->debugfs_list to track debugfs files which are added at drm_dev_register() time on each minor.
--- drivers/gpu/drm/vc4/vc4_bo.c | 4 ++-- drivers/gpu/drm/vc4/vc4_debugfs.c | 38 +++++++------------------------ drivers/gpu/drm/vc4/vc4_hdmi.c | 4 ++-- drivers/gpu/drm/vc4/vc4_hvs.c | 4 ++-- drivers/gpu/drm/vc4/vc4_v3d.c | 4 ++-- 5 files changed, 16 insertions(+), 38 deletions(-)
drivers/gpu/drm/vc4/vc4_bo.c +2 -2
@@ -65,8 +65,8 @@ static void vc4_bo_stats_print(struct drm_printer *p, struct vc4_dev *vc4)static int vc4_bo_stats_debugfs (struct seq_file *m,void *unused) { -struct drm_info_node *node = (struct drm_info_node *)m->private; -struct drm_device *dev = node->minor->dev; +struct drm_simple_info_entry *entry = m->private; +struct drm_device *dev = entry->dev;struct vc4_dev *vc4 =to_vc4_dev (dev);struct drm_printer p =drm_seq_file_printer (m);
drivers/gpu/drm/vc4/vc4_debugfs.c +8 -30
@@ -11,10 +11,6 @@#include "vc4_drv.h" #include "vc4_regs.h" -struct vc4_debugfs_info_entry { -struct list_head link; -struct drm_info_list info; -};/** * Called at drm_dev_register() time on each of the minors registered
@@ -24,21 +20,15 @@ void vc4_debugfs_init(struct drm_minor *minor) {struct vc4_dev *vc4 =to_vc4_dev (minor->dev); -struct vc4_debugfs_info_entry *entry;debugfs_create_bool ("hvs_load_tracker" ,S_IRUGO |S_IWUSR , minor->debugfs_root, &vc4->load_tracker_enabled); - -list_for_each_entry (entry, &vc4->debugfs_list, link) { -drm_debugfs_create_files (&entry->info,1 , - minor->debugfs_root, minor); - } }static int vc4_debugfs_regset32 (struct seq_file *m,void *unused) { -struct drm_info_node *node = (struct drm_info_node *)m->private; -struct debugfs_regset32 *regset = node->info_ent->data; +struct drm_simple_info_entry *entry = m->private; +struct debugfs_regset32 *regset = entry->file.data;struct drm_printer p =drm_seq_file_printer (m);drm_print_regset32 (&p, regset);
@@ -49,30 +39,18 @@ static int vc4_debugfs_regset32(struct seq_file *m, void *unused)/** * Registers a debugfs file with a callback function for a vc4 component. * -* This is like drm_debugfs_create_files(), but that can only be -* called a given DRM minor, while the various VC4 components want to -* register their debugfs files during the component bind process. We -* track the request and delay it to be called on each minor during -* vc4_debugfs_init(). +* Various VC4 functions will register their debugfs files during the +* component bind process using drm_debugfs_add_file(). +* These requests are tracked and delayed until their called on each +* minor during drm_dev_register(). +* */ void vc4_debugfs_add_file (struct drm_device *dev,const char *name,int (*show)(struct seq_file *,void *),void *data) { -struct vc4_dev *vc4 =to_vc4_dev (dev); - -struct vc4_debugfs_info_entry *entry = -devm_kzalloc (dev->dev,sizeof (*entry),GFP_KERNEL ); - -if (!entry) -return ; - - entry->info.name = name; - entry->info.show = show; - entry->info.data = data; - -list_add (&entry->link, &vc4->debugfs_list); +drm_debugfs_add_file (dev, name, show, data); } void vc4_debugfs_add_regset32(struct drm_device *drm,
drivers/gpu/drm/vc4/vc4_hdmi.c +2 -2
@@ -182,8 +182,8 @@ static const struct debugfs_reg32 hd_regs[] = {static int vc4_hdmi_debugfs_regs (struct seq_file *m,void *unused) { -struct drm_info_node *node = (struct drm_info_node *)m->private; -struct drm_device *dev = node->minor->dev; +struct drm_simple_info_entry *entry = m->private; +struct drm_device *dev = entry->dev;struct vc4_dev *vc4 =to_vc4_dev (dev);struct vc4_hdmi *hdmi = vc4->hdmi;struct drm_printer p =drm_seq_file_printer (m);
drivers/gpu/drm/vc4/vc4_hvs.c +2 -2
@@ -82,8 +82,8 @@ void vc4_hvs_dump_state(struct drm_device *dev)static int vc4_hvs_debugfs_underrun (struct seq_file *m,void *data) { -struct drm_info_node *node = m->private; -struct drm_device *dev = node->minor->dev; +struct drm_simple_info_entry *entry = m->private; +struct drm_device *dev = entry->dev;struct vc4_dev *vc4 =to_vc4_dev (dev);struct drm_printer p =drm_seq_file_printer (m);
drivers/gpu/drm/vc4/vc4_v3d.c +2 -2
@@ -98,8 +98,8 @@ static const struct debugfs_reg32 v3d_regs[] = {static int vc4_v3d_debugfs_ident (struct seq_file *m,void *unused) { -struct drm_info_node *node = (struct drm_info_node *)m->private; -struct drm_device *dev = node->minor->dev; +struct drm_simple_info_entry *entry = m->private; +struct drm_device *dev = entry->dev;struct vc4_dev *vc4 =to_vc4_dev (dev);int ret =vc4_v3d_pm_get (vc4);
Signature · 1 line
2.26.2
RFC PATCH 3/3 drm: use new debugfs functions for various files.
In reply to Wambui KarugaReplace the use of drm_debugfs_create_files with the new drm_debugfs_add_files() to create various drm core debugfs files.
DRM debugfs files are also represented using the new drm_simple_info struct for use with the new functions.
--- drivers/gpu/drm/drm_atomic.c | 11 +++++------ drivers/gpu/drm/drm_client.c | 11 +++++------ drivers/gpu/drm/drm_framebuffer.c | 11 +++++------ 3 files changed, 15 insertions(+), 18 deletions(-)
drivers/gpu/drm/drm_atomic.c +5 -6
@@ -1627,8 +1627,8 @@ EXPORT_SYMBOL(drm_state_dump);#ifdef CONFIG_DEBUG_FS static int drm_state_info (struct seq_file *m,void *data) { -struct drm_info_node *node = (struct drm_info_node *) m->private; -struct drm_device *dev = node->minor->dev; +struct drm_simple_info_entry *entry = m->private; +struct drm_device *dev = entry->dev;struct drm_printer p =drm_seq_file_printer (m);__drm_state_dump (dev, &p, true);
@@ -1637,14 +1637,13 @@ static int drm_state_info(struct seq_file *m, void *data) }/* any use in debugfs files to dump individual planes/crtc/etc? */ -static const struct drm_info_list drm_atomic_debugfs_list[] = { +static const struct drm_simple_info drm_atomic_debugfs_list[] = { {"state" , drm_state_info,0 }, };void drm_atomic_debugfs_init (struct drm_minor *minor) { -drm_debugfs_create_files (drm_atomic_debugfs_list, -ARRAY_SIZE (drm_atomic_debugfs_list), - minor->debugfs_root, minor); +drm_debugfs_add_files (minor->dev, drm_atomic_debugfs_list, +ARRAY_SIZE (drm_atomic_debugfs_list)); }#endif
drivers/gpu/drm/drm_client.c +5 -6
@@ -440,8 +440,8 @@ EXPORT_SYMBOL(drm_client_framebuffer_delete);#ifdef CONFIG_DEBUG_FS static int drm_client_debugfs_internal_clients (struct seq_file *m,void *data) { -struct drm_info_node *node = m->private; -struct drm_device *dev = node->minor->dev; +struct drm_simple_info_entry *entry = m->private; +struct drm_device *dev = entry->dev;struct drm_printer p =drm_seq_file_printer (m);struct drm_client_dev *client;
@@ -453,14 +453,13 @@ static int drm_client_debugfs_internal_clients(struct seq_file *m, void *data) return 0; } -static const struct drm_info_list drm_client_debugfs_list[] = { +static const struct drm_simple_info drm_client_debugfs_list[] = { {"internal_clients" , drm_client_debugfs_internal_clients,0 }, };void drm_client_debugfs_init (struct drm_minor *minor) { -drm_debugfs_create_files (drm_client_debugfs_list, -ARRAY_SIZE (drm_client_debugfs_list), - minor->debugfs_root, minor); +drm_debugfs_add_files (minor->dev, drm_client_debugfs_list, +ARRAY_SIZE (drm_client_debugfs_list)); }#endif
drivers/gpu/drm/drm_framebuffer.c +5 -6
@@ -1188,8 +1188,8 @@ void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,#ifdef CONFIG_DEBUG_FS static int drm_framebuffer_info (struct seq_file *m,void *data) { -struct drm_info_node *node = m->private; -struct drm_device *dev = node->minor->dev; +struct drm_simple_info_entry *entry = m->private; +struct drm_device *dev = entry->dev;struct drm_printer p =drm_seq_file_printer (m);struct drm_framebuffer *fb;
@@ -1203,14 +1203,13 @@ static int drm_framebuffer_info(struct seq_file *m, void *data) return 0; } -static const struct drm_info_list drm_framebuffer_debugfs_list[] = { +static const struct drm_simple_info drm_framebuffer_debugfs_list[] = { {"framebuffer" , drm_framebuffer_info,0 }, };void drm_framebuffer_debugfs_init (struct drm_minor *minor) { -drm_debugfs_create_files (drm_framebuffer_debugfs_list, -ARRAY_SIZE (drm_framebuffer_debugfs_list), - minor->debugfs_root, minor); +drm_debugfs_add_files (minor->dev, drm_framebuffer_debugfs_list, +ARRAY_SIZE (drm_framebuffer_debugfs_list)); }#endif
Signature · 1 line
2.26.2