drm/amdgpu: use ARRAY_SIZE() to add amdgpu debugfs files
Subsystems (2)
PATCH 1/1 drm/amdgpu: use ARRAY_SIZE() to add amdgpu debugfs files
to easily add new debugfs file w/o changing the hardcoded list count.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4 -2
@@ -781,8 +781,10 @@ int amdgpu_debugfs_fence_init(struct amdgpu_device *adev) {#if defined(CONFIG_DEBUG_FS )if (amdgpu_sriov_vf (adev)) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list_sriov,1 ); -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list,2 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list_sriov, +ARRAY_SIZE (amdgpu_debugfs_fence_list_sriov)); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list, +ARRAY_SIZE (amdgpu_debugfs_fence_list));#else return 0 ;#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
@@ -928,7 +928,8 @@ static const struct drm_info_list amdgpu_debugfs_gem_list[] = {int amdgpu_debugfs_gem_init (struct amdgpu_device *adev) {#if defined(CONFIG_DEBUG_FS ) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_gem_list,1 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_gem_list, +ARRAY_SIZE (amdgpu_debugfs_gem_list));#endif return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2 -1
@@ -468,7 +468,8 @@ static const struct drm_info_list amdgpu_debugfs_sa_list[] = {int amdgpu_debugfs_sa_init (struct amdgpu_device *adev) {#if defined(CONFIG_DEBUG_FS ) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_sa_list,1 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_sa_list, +ARRAY_SIZE (amdgpu_debugfs_sa_list));#else return 0 ;#endif
Signature · 6 lines
2.20.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Public Use]
Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Xiaojie Yuan
Sent: Monday, July 13, 2020 14:00
To: [email protected]
Cc: Yuan, Xiaojie <[email protected]>
Subject: [PATCH] drm/amdgpu: use ARRAY_SIZE() to add amdgpu debugfs files
to easily add new debugfs file w/o changing the hardcoded list count.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4 -2
@@ -781,8 +781,10 @@ int amdgpu_debugfs_fence_init(struct amdgpu_device *adev) { #if defined(CONFIG_DEBUG_FS)if (amdgpu_sriov_vf (adev)) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list_sriov,1 ); -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list,2 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list_sriov, +ARRAY_SIZE (amdgpu_debugfs_fence_list_sriov)); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list, +ARRAY_SIZE (amdgpu_debugfs_fence_list));#else return 0 ;#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -1
@@ -928,7 +928,8 @@ static const struct drm_info_list amdgpu_debugfs_gem_list[] = { int amdgpu_debugfs_gem_init(struct amdgpu_device *adev) { #if defined(CONFIG_DEBUG_FS) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_gem_list,1 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_gem_list, +ARRAY_SIZE (amdgpu_debugfs_gem_list));#endif return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2 -2
@@ -468,7 +468,8 @@ static const struct drm_info_list amdgpu_debugfs_sa_list[] = { int amdgpu_debugfs_sa_init(struct amdgpu_device *adev) { #if defined(CONFIG_DEBUG_FS) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_sa_list,1 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_sa_list, +ARRAY_SIZE (amdgpu_debugfs_sa_list));#else return 0 ;#endif --
2.20.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Chawking.zhang%40amd.com%7C22bf311806fe4925f70c08d826f206b6%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637302168223168477&sdata=4U%2BsydWtuJp3XUmMmB9H8ApnBORKYF9eL5yRBjQgYa4%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 13.07.20 um 07:59 schrieb Xiaojie Yuan:
Quoted 1 line
to easily add new debugfs file w/o changing the hardcoded list count.
In general a good idea, but I would rather like to see amdgpu_debugfs_add_files() completely removed and debugfs_create_file() used directly instead.
Christian.
Quoted 44 lines
Signed-off-by Xiaojie Yuan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4
-2@@ -781,8 +781,10 @@ int amdgpu_debugfs_fence_init(struct amdgpu_device *adev) {#if defined(CONFIG_DEBUG_FS )if (amdgpu_sriov_vf (adev)) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list_sriov,1 ); -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list,2 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list_sriov, +ARRAY_SIZE (amdgpu_debugfs_fence_list_sriov)); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list, +ARRAY_SIZE (amdgpu_debugfs_fence_list));#else return 0 ;#endif drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-1@@ -928,7 +928,8 @@ static const struct drm_info_list amdgpu_debugfs_gem_list[] = {int amdgpu_debugfs_gem_init (struct amdgpu_device *adev) {#if defined(CONFIG_DEBUG_FS ) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_gem_list,1 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_gem_list, +ARRAY_SIZE (amdgpu_debugfs_gem_list));#endif return 0 ; }drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c static const struct drm_info_list amdgpu_debugfs_sa_list[] = { · line 475
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-1@@ -468,7 +468,8 @@ static const struct drm_info_list amdgpu_debugfs_sa_list[] = {int amdgpu_debugfs_sa_init (struct amdgpu_device *adev) {#if defined(CONFIG_DEBUG_FS ) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_sa_list,1 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_sa_list, +ARRAY_SIZE (amdgpu_debugfs_sa_list));#else return 0 ;#endif
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Hi Chris,
This was observed when I was trying to add a new debugfs file. Some similar occurrences using ARRAY_SIZE() are:
- amdgpu_kms.c :: amdgpu_firmware_info_list
- amdgpu_pm.c :: amdgpu_debugfs_pm_info
- amdgpu_ttm.c :: amdgpu_ttm_debugfs_list
- amdgpu_dm_debugfs.c :: amdgpu_dm_debugfs_list
This patch simply unified the usage of amdgpu_debugfs_add_files().
BTW, do you intended to use:debugfs_create_file() - need to call debugfs_remove() explicitly or the drm helperdrm_debugfs_create_files() - debugfs files will be removed automatically
If so, we need a separate patch to cleanup them in a batch.
BR,
Xiaojie
________________________________________
From: Christian König <[email protected]>
Sent: Monday, July 13, 2020 4:38 PM
To: Yuan, Xiaojie; [email protected]
Subject: Re: [PATCH] drm/amdgpu: use ARRAY_SIZE() to add amdgpu debugfs files
Am 13.07.20 um 07:59 schrieb Xiaojie Yuan:
Quoted 1 line
to easily add new debugfs file w/o changing the hardcoded list count.
In general a good idea, but I would rather like to see amdgpu_debugfs_add_files() completely removed and debugfs_create_file() used directly instead.
Christian.
Quoted 44 lines
Signed-off-by Xiaojie Yuan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4
-2@@ -781,8 +781,10 @@ int amdgpu_debugfs_fence_init(struct amdgpu_device *adev) {#if defined(CONFIG_DEBUG_FS )if (amdgpu_sriov_vf (adev)) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list_sriov,1 ); -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list,2 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list_sriov, +ARRAY_SIZE (amdgpu_debugfs_fence_list_sriov)); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list, +ARRAY_SIZE (amdgpu_debugfs_fence_list));#else return 0 ;#endif drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-1@@ -928,7 +928,8 @@ static const struct drm_info_list amdgpu_debugfs_gem_list[] = {int amdgpu_debugfs_gem_init (struct amdgpu_device *adev) {#if defined(CONFIG_DEBUG_FS ) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_gem_list,1 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_gem_list, +ARRAY_SIZE (amdgpu_debugfs_gem_list));#endif return 0 ; }drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c static const struct drm_info_list amdgpu_debugfs_sa_list[] = { · line 475
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-1@@ -468,7 +468,8 @@ static const struct drm_info_list amdgpu_debugfs_sa_list[] = {int amdgpu_debugfs_sa_init (struct amdgpu_device *adev) {#if defined(CONFIG_DEBUG_FS ) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_sa_list,1 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_sa_list, +ARRAY_SIZE (amdgpu_debugfs_sa_list));#else return 0 ;#endif
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAm 13.07.20 um 15:34 schrieb Yuan, Xiaojie:
Quoted 5 lines
[AMD Official Use Only - Internal Distribution Only]
Hi Chris,
This was observed when I was trying to add a new debugfs file.
In this case please add the new file using debugfs_create_file() directly and don't touch this old code.
Quoted 8 lines
Some similar
occurrences usingARRAY_SIZE()are:-
amdgpu_kms.c::amdgpu_firmware_info_list
-amdgpu_pm.c::amdgpu_debugfs_pm_info
-amdgpu_ttm.c::amdgpu_ttm_debugfs_list
-amdgpu_dm_debugfs.c::amdgpu_dm_debugfs_list
Quoted 6 lines
This patch simply unified the usage of
amdgpu_debugfs_add_files().BTW, do you intended to use:
debugfs_create_file()- need to calldebugfs_remove()explicitly or the drm helperdrm_debugfs_create_files()- debugfs files will be removed automatically
No, exactly that's the point. All debugfs files are automatically removed when the driver unloads because the parent directory is removed.
See the debugfs.h file in the Linux source code:
Quoted 2 lines
void
debugfs_remove<https://elixir.bootlin.com/linux/latest/C/ident/debugfs_remove>(struct dentry <https://elixir.bootlin.com/linux/latest/C/ident/dentry> *dentry <https://elixir.bootlin.com/linux/latest/C/ident/dentry>);
#definedebugfs_remove_recursive<https://elixir.bootlin.com/linux/latest/C/ident/debugfs_remove_recursive>debugfs_remove<https://elixir.bootlin.com/linux/latest/C/ident/debugfs_remove>
The whole tracking amdgpu_debugfs_add_files() and the underlying DRM function do are completely nonsense and was only added because somebody didn't knew that this stuff is automatically removed.
The only functionality amdgpu_debugfs_add_files() still provides is protecting to not try to add files twice. And that in turn is a coding bug we should probably fix :)
Regards,
Christian.
Quoted 64 lines
If so, we need a separate patch to cleanup them in a batch.
BR,
Xiaojie________________________________________
From: Christian König <[email protected]>
Sent: Monday, July 13, 2020 4:38 PM
To: Yuan, Xiaojie; [email protected]
Subject: Re: [PATCH] drm/amdgpu: useARRAY_SIZE()to add amdgpu debugfs filesAm 13.07.20 um 07:59 schrieb Xiaojie Yuan:
Quoted 1 line
to easily add new debugfs file w/o changing the hardcoded list count.
In general a good idea, but I would rather like to see
amdgpu_debugfs_add_files()completely removed anddebugfs_create_file()used directly instead.Christian.
Quoted 44 lines
Signed-off-by Xiaojie Yuan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +4
-2@@ -781,8 +781,10 @@ int amdgpu_debugfs_fence_init(struct amdgpu_device *adev) {#if defined(CONFIG_DEBUG_FS )if (amdgpu_sriov_vf (adev)) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list_sriov,1 ); -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list,2 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list_sriov, +ARRAY_SIZE (amdgpu_debugfs_fence_list_sriov)); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_fence_list, +ARRAY_SIZE (amdgpu_debugfs_fence_list));#else return 0 ;#endif drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2
-1@@ -928,7 +928,8 @@ static const struct drm_info_list amdgpu_debugfs_gem_list[] = {int amdgpu_debugfs_gem_init (struct amdgpu_device *adev) {#if defined(CONFIG_DEBUG_FS ) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_gem_list,1 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_gem_list, +ARRAY_SIZE (amdgpu_debugfs_gem_list));#endif return 0 ; }drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +0
-0@@ -468,7 +468,8 @@ static const struct drm_info_list amdgpu_debugfs_sa_list[] = {int amdgpu_debugfs_sa_init (struct amdgpu_device *adev)
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c static const struct drm_info_list amdgpu_debugfs_sa_list[] = { · line 475
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +2
-1{#if defined(CONFIG_DEBUG_FS ) -return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_sa_list,1 ); +return amdgpu_debugfs_add_files (adev, amdgpu_debugfs_sa_list, +ARRAY_SIZE (amdgpu_debugfs_sa_list));#else return 0 ;#endif
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx