Skip to content

Commit e15826b

Browse files
committed
drm/xe/guc: Refactor GuC debugfs initialization
We don't have to drmm_kmalloc() local copy of debugfs_list to write there our pointer to the struct xe_guc as we can extract pointer to the struct xe_gt from the grandparent debugfs entry, in similar way to what we did for GT debugfs files. Note that there is no change in file/directory structure, just refactored how files are created and how functions are called. Signed-off-by: Michal Wajdeczko <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 80742a1 commit e15826b

File tree

1 file changed

+67
-63
lines changed

1 file changed

+67
-63
lines changed

drivers/gpu/drm/xe/xe_guc_debugfs.c

Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -17,101 +17,105 @@
1717
#include "xe_macros.h"
1818
#include "xe_pm.h"
1919

20-
static struct xe_guc *node_to_guc(struct drm_info_node *node)
21-
{
22-
return node->info_ent->data;
23-
}
24-
25-
static int guc_info(struct seq_file *m, void *data)
20+
/*
21+
* guc_debugfs_show - A show callback for struct drm_info_list
22+
* @m: the &seq_file
23+
* @data: data used by the drm debugfs helpers
24+
*
25+
* This callback can be used in struct drm_info_list to describe debugfs
26+
* files that are &xe_guc specific in similar way how we handle &xe_gt
27+
* specific files using &xe_gt_debugfs_simple_show.
28+
*
29+
* It is assumed that those debugfs files will be created on directory entry
30+
* which grandparent struct dentry d_inode->i_private points to &xe_gt.
31+
*
32+
* /sys/kernel/debug/dri/0/
33+
* ├── gt0 # dent->d_parent->d_parent (d_inode->i_private == gt)
34+
* │   ├── uc # dent->d_parent
35+
* │   │   ├── guc_info # dent
36+
* │   │   ├── guc_...
37+
*
38+
* This function assumes that &m->private will be set to the &struct
39+
* drm_info_node corresponding to the instance of the info on a given &struct
40+
* drm_minor (see struct drm_info_list.show for details).
41+
*
42+
* This function also assumes that struct drm_info_list.data will point to the
43+
* function code that will actually print a file content::
44+
*
45+
* int (*print)(struct xe_guc *, struct drm_printer *)
46+
*
47+
* Example::
48+
*
49+
* int foo(struct xe_guc *guc, struct drm_printer *p)
50+
* {
51+
* drm_printf(p, "enabled %d\n", guc->submission_state.enabled);
52+
* return 0;
53+
* }
54+
*
55+
* static const struct drm_info_list bar[] = {
56+
* { name = "foo", .show = guc_debugfs_show, .data = foo },
57+
* };
58+
*
59+
* parent = debugfs_create_dir("uc", gtdir);
60+
* drm_debugfs_create_files(bar, ARRAY_SIZE(bar), parent, minor);
61+
*
62+
* Return: 0 on success or a negative error code on failure.
63+
*/
64+
static int guc_debugfs_show(struct seq_file *m, void *data)
2665
{
27-
struct xe_guc *guc = node_to_guc(m->private);
28-
struct xe_device *xe = guc_to_xe(guc);
2966
struct drm_printer p = drm_seq_file_printer(m);
67+
struct drm_info_node *node = m->private;
68+
struct dentry *parent = node->dent->d_parent;
69+
struct dentry *grandparent = parent->d_parent;
70+
struct xe_gt *gt = grandparent->d_inode->i_private;
71+
struct xe_device *xe = gt_to_xe(gt);
72+
int (*print)(struct xe_guc *, struct drm_printer *) = node->info_ent->data;
73+
int ret;
3074

3175
xe_pm_runtime_get(xe);
32-
xe_guc_print_info(guc, &p);
76+
ret = print(&gt->uc.guc, &p);
3377
xe_pm_runtime_put(xe);
3478

35-
return 0;
79+
return ret;
3680
}
3781

38-
static int guc_log(struct seq_file *m, void *data)
82+
static int guc_log(struct xe_guc *guc, struct drm_printer *p)
3983
{
40-
struct xe_guc *guc = node_to_guc(m->private);
41-
struct xe_device *xe = guc_to_xe(guc);
42-
struct drm_printer p = drm_seq_file_printer(m);
43-
44-
xe_pm_runtime_get(xe);
45-
xe_guc_log_print(&guc->log, &p);
46-
xe_pm_runtime_put(xe);
47-
84+
xe_guc_log_print(&guc->log, p);
4885
return 0;
4986
}
5087

51-
static int guc_log_dmesg(struct seq_file *m, void *data)
88+
static int guc_log_dmesg(struct xe_guc *guc, struct drm_printer *p)
5289
{
53-
struct xe_guc *guc = node_to_guc(m->private);
54-
struct xe_device *xe = guc_to_xe(guc);
55-
56-
xe_pm_runtime_get(xe);
5790
xe_guc_log_print_dmesg(&guc->log);
58-
xe_pm_runtime_put(xe);
59-
6091
return 0;
6192
}
6293

63-
static int guc_ctb(struct seq_file *m, void *data)
94+
static int guc_ctb(struct xe_guc *guc, struct drm_printer *p)
6495
{
65-
struct xe_guc *guc = node_to_guc(m->private);
66-
struct xe_device *xe = guc_to_xe(guc);
67-
struct drm_printer p = drm_seq_file_printer(m);
68-
69-
xe_pm_runtime_get(xe);
70-
xe_guc_ct_print(&guc->ct, &p, true);
71-
xe_pm_runtime_put(xe);
72-
96+
xe_guc_ct_print(&guc->ct, p, true);
7397
return 0;
7498
}
7599

76-
static int guc_pc(struct seq_file *m, void *data)
100+
static int guc_pc(struct xe_guc *guc, struct drm_printer *p)
77101
{
78-
struct xe_guc *guc = node_to_guc(m->private);
79-
struct xe_device *xe = guc_to_xe(guc);
80-
struct drm_printer p = drm_seq_file_printer(m);
81-
82-
xe_pm_runtime_get(xe);
83-
xe_guc_pc_print(&guc->pc, &p);
84-
xe_pm_runtime_put(xe);
85-
102+
xe_guc_pc_print(&guc->pc, p);
86103
return 0;
87104
}
88105

89106
static const struct drm_info_list debugfs_list[] = {
90-
{"guc_info", guc_info, 0},
91-
{"guc_log", guc_log, 0},
92-
{"guc_log_dmesg", guc_log_dmesg, 0},
93-
{"guc_ctb", guc_ctb, 0},
94-
{"guc_pc", guc_pc, 0},
107+
{ "guc_info", .show = guc_debugfs_show, .data = xe_guc_print_info },
108+
{ "guc_log", .show = guc_debugfs_show, .data = guc_log },
109+
{ "guc_log_dmesg", .show = guc_debugfs_show, .data = guc_log_dmesg },
110+
{ "guc_ctb", .show = guc_debugfs_show, .data = guc_ctb },
111+
{ "guc_pc", .show = guc_debugfs_show, .data = guc_pc },
95112
};
96113

97114
void xe_guc_debugfs_register(struct xe_guc *guc, struct dentry *parent)
98115
{
99116
struct drm_minor *minor = guc_to_xe(guc)->drm.primary;
100-
struct drm_info_list *local;
101-
int i;
102-
103-
#define DEBUGFS_SIZE (ARRAY_SIZE(debugfs_list) * sizeof(struct drm_info_list))
104-
local = drmm_kmalloc(&guc_to_xe(guc)->drm, DEBUGFS_SIZE, GFP_KERNEL);
105-
if (!local)
106-
return;
107-
108-
memcpy(local, debugfs_list, DEBUGFS_SIZE);
109-
#undef DEBUGFS_SIZE
110-
111-
for (i = 0; i < ARRAY_SIZE(debugfs_list); ++i)
112-
local[i].data = guc;
113117

114-
drm_debugfs_create_files(local,
118+
drm_debugfs_create_files(debugfs_list,
115119
ARRAY_SIZE(debugfs_list),
116120
parent, minor);
117121
}

0 commit comments

Comments
 (0)