diff mbox series

[v4] drm/i915/gt: allow setting generic data pointer

Message ID 20200306230344.53559-1-andi@etezian.org (mailing list archive)
State New, archived
Headers show
Series [v4] drm/i915/gt: allow setting generic data pointer | expand

Commit Message

Andi Shyti March 6, 2020, 11:03 p.m. UTC
From: Andi Shyti <andi.shyti@intel.com>

When registering debugfs files the intel gt debugfs library
forces a 'struct *gt' private data on the caller.

To be open to different usages make the new
"intel_gt_debugfs_register_files()"[*] function more generic by
converting the 'struct *gt' pointer to a 'void *' type.

I take the chance to rename the functions by using "intel_gt_" as
prefix instead of "debugfs_", so that "debugfs_gt_register_files()"
becomes "intel_gt_debugfs_register_files()".

Signed-off-by: Andi Shyti <andi.shyti@intel.com>
Reviewed-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
---
Hi,

Thanks Daniele for the review.

Andi

Changelog:
v4:
 - removed the wrapper which turns out it's not needed anymore.
v3:
 - removed unused gt parameter from the
   __intel_gt_debugfs_register_files()
v2:
 - the eval function is made generic as suggested by Daniele.

 drivers/gpu/drm/i915/gt/debugfs_engines.c |  2 +-
 drivers/gpu/drm/i915/gt/debugfs_gt.c      | 11 +++++------
 drivers/gpu/drm/i915/gt/debugfs_gt.h      |  9 ++++-----
 drivers/gpu/drm/i915/gt/debugfs_gt_pm.c   | 14 +++++++++-----
 4 files changed, 19 insertions(+), 17 deletions(-)

Comments

Chris Wilson March 7, 2020, 12:07 p.m. UTC | #1
Quoting Andi Shyti (2020-03-06 23:03:44)
> -void debugfs_gt_register_files(struct intel_gt *gt,
> -                              struct dentry *root,
> -                              const struct debugfs_gt_file *files,
> -                              unsigned long count)
> +void intel_gt_debugfs_register_files(struct dentry *root,
> +                                    const struct debugfs_gt_file *files,
> +                                    unsigned long count, void *data)
>  {
>         while (count--) {
> -               if (!files->eval || files->eval(gt))
> +               if (!files->eval || files->eval(data))
>                         debugfs_create_file(files->name,
> -                                           0444, root, gt,
> +                                           0444, root, data,
>                                             files->fops);
>  

And now we are not a intel_gt routine, you'll want to move again :)
i915_debugfs_utils.c ? :)
-Chris
Andi Shyti March 7, 2020, 12:55 p.m. UTC | #2
Hi Chris,

On Sat, Mar 07, 2020 at 12:07:22PM +0000, Chris Wilson wrote:
> Quoting Andi Shyti (2020-03-06 23:03:44)
> > -void debugfs_gt_register_files(struct intel_gt *gt,
> > -                              struct dentry *root,
> > -                              const struct debugfs_gt_file *files,
> > -                              unsigned long count)
> > +void intel_gt_debugfs_register_files(struct dentry *root,
> > +                                    const struct debugfs_gt_file *files,
> > +                                    unsigned long count, void *data)
> >  {
> >         while (count--) {
> > -               if (!files->eval || files->eval(gt))
> > +               if (!files->eval || files->eval(data))
> >                         debugfs_create_file(files->name,
> > -                                           0444, root, gt,
> > +                                           0444, root, data,
> >                                             files->fops);
> >  
> 
> And now we are not a intel_gt routine, you'll want to move again :)
> i915_debugfs_utils.c ? :)

Actually, this is what it came to and this was the first
discussion I had with Daniele and that's also why I was loyal to
th "_gt_" wrappers until the end. But I had to agree that this
was becoming more a limitation.

The biggest difference left, which by the way is the real
distinguishing factor other than the *gt pointer, is that we
create files under gt directory, instead of having the root
imposed by the drm (even though the caller can eventually choose
different roots).

We could perhaps store the root pointer in the intel_gt
structure so that this function stays de facto an intel_gt
routine and the caller doesn't need to care where the files will
be generated. This is what we planned to do with sysfs as well.

What do you think?

Andi
Chris Wilson March 7, 2020, 5:35 p.m. UTC | #3
Quoting Andi Shyti (2020-03-07 12:55:31)
> Hi Chris,
> 
> On Sat, Mar 07, 2020 at 12:07:22PM +0000, Chris Wilson wrote:
> > Quoting Andi Shyti (2020-03-06 23:03:44)
> > > -void debugfs_gt_register_files(struct intel_gt *gt,
> > > -                              struct dentry *root,
> > > -                              const struct debugfs_gt_file *files,
> > > -                              unsigned long count)
> > > +void intel_gt_debugfs_register_files(struct dentry *root,
> > > +                                    const struct debugfs_gt_file *files,
> > > +                                    unsigned long count, void *data)
> > >  {
> > >         while (count--) {
> > > -               if (!files->eval || files->eval(gt))
> > > +               if (!files->eval || files->eval(data))
> > >                         debugfs_create_file(files->name,
> > > -                                           0444, root, gt,
> > > +                                           0444, root, data,
> > >                                             files->fops);
> > >  
> > 
> > And now we are not a intel_gt routine, you'll want to move again :)
> > i915_debugfs_utils.c ? :)
> 
> Actually, this is what it came to and this was the first
> discussion I had with Daniele and that's also why I was loyal to
> th "_gt_" wrappers until the end. But I had to agree that this
> was becoming more a limitation.
> 
> The biggest difference left, which by the way is the real
> distinguishing factor other than the *gt pointer, is that we
> create files under gt directory, instead of having the root
> imposed by the drm (even though the caller can eventually choose
> different roots).
> 
> We could perhaps store the root pointer in the intel_gt
> structure so that this function stays de facto an intel_gt
> routine and the caller doesn't need to care where the files will
> be generated. This is what we planned to do with sysfs as well.
> 
> What do you think?

I thought we were passing along the root. If not I think we should, more
of a debugfs constructor context?

The main thing of course is not to overengineer and do the minimal
necessary for the immediate users we have. We can always extend and
refactor for a third user, etc, etc.

So if this works for gt + children, go for it and worry about tomorrow,
tomorrow. Trusting our good practice for "a stitch in time saves nine".
-Chris
Andi Shyti March 7, 2020, 10:19 p.m. UTC | #4
Hi Chris,

> > > Quoting Andi Shyti (2020-03-06 23:03:44)
> > > > -void debugfs_gt_register_files(struct intel_gt *gt,
> > > > -                              struct dentry *root,
> > > > -                              const struct debugfs_gt_file *files,
> > > > -                              unsigned long count)
> > > > +void intel_gt_debugfs_register_files(struct dentry *root,
> > > > +                                    const struct debugfs_gt_file *files,
> > > > +                                    unsigned long count, void *data)
> > > >  {
> > > >         while (count--) {
> > > > -               if (!files->eval || files->eval(gt))
> > > > +               if (!files->eval || files->eval(data))
> > > >                         debugfs_create_file(files->name,
> > > > -                                           0444, root, gt,
> > > > +                                           0444, root, data,
> > > >                                             files->fops);
> > > >  
> > > 
> > > And now we are not a intel_gt routine, you'll want to move again :)
> > > i915_debugfs_utils.c ? :)
> > 
> > Actually, this is what it came to and this was the first
> > discussion I had with Daniele and that's also why I was loyal to
> > th "_gt_" wrappers until the end. But I had to agree that this
> > was becoming more a limitation.
> > 
> > The biggest difference left, which by the way is the real
> > distinguishing factor other than the *gt pointer, is that we
> > create files under gt directory, instead of having the root
> > imposed by the drm (even though the caller can eventually choose
> > different roots).
> > 
> > We could perhaps store the root pointer in the intel_gt
> > structure so that this function stays de facto an intel_gt
> > routine and the caller doesn't need to care where the files will
> > be generated. This is what we planned to do with sysfs as well.
> > 
> > What do you think?
> 
> I thought we were passing along the root. If not I think we should, more
> of a debugfs constructor context?

What do you mean with debugfs constructor context? Is it a
gt->debugfs_root pointer like the gt->sysfs_root?

> The main thing of course is not to overengineer and do the minimal
> necessary for the immediate users we have. We can always extend and
> refactor for a third user, etc, etc.
> 
> So if this works for gt + children, go for it and worry about tomorrow,
> tomorrow. Trusting our good practice for "a stitch in time saves nine".

this came after Daniele's guc patches where he preferred to
define his own functions instead of using this one that is meant
to be used in that situation.

Andi
Daniele Ceraolo Spurio March 9, 2020, 10:05 p.m. UTC | #5
On 3/7/20 2:19 PM, Andi Shyti wrote:
> Hi Chris,
> 
>>>> Quoting Andi Shyti (2020-03-06 23:03:44)
>>>>> -void debugfs_gt_register_files(struct intel_gt *gt,
>>>>> -                              struct dentry *root,
>>>>> -                              const struct debugfs_gt_file *files,
>>>>> -                              unsigned long count)
>>>>> +void intel_gt_debugfs_register_files(struct dentry *root,
>>>>> +                                    const struct debugfs_gt_file *files,
>>>>> +                                    unsigned long count, void *data)
>>>>>   {
>>>>>          while (count--) {
>>>>> -               if (!files->eval || files->eval(gt))
>>>>> +               if (!files->eval || files->eval(data))
>>>>>                          debugfs_create_file(files->name,
>>>>> -                                           0444, root, gt,
>>>>> +                                           0444, root, data,
>>>>>                                              files->fops);
>>>>>   
>>>>
>>>> And now we are not a intel_gt routine, you'll want to move again :)
>>>> i915_debugfs_utils.c ? :)
>>>
>>> Actually, this is what it came to and this was the first
>>> discussion I had with Daniele and that's also why I was loyal to
>>> th "_gt_" wrappers until the end. But I had to agree that this
>>> was becoming more a limitation.
>>>
>>> The biggest difference left, which by the way is the real
>>> distinguishing factor other than the *gt pointer, is that we
>>> create files under gt directory, instead of having the root
>>> imposed by the drm (even though the caller can eventually choose
>>> different roots).
>>>
>>> We could perhaps store the root pointer in the intel_gt
>>> structure so that this function stays de facto an intel_gt
>>> routine and the caller doesn't need to care where the files will
>>> be generated. This is what we planned to do with sysfs as well.
>>>
>>> What do you think?
>>
>> I thought we were passing along the root. If not I think we should, more
>> of a debugfs constructor context?
> 
> What do you mean with debugfs constructor context? Is it a
> gt->debugfs_root pointer like the gt->sysfs_root?
> 

Getting the root pointer internally from gt wouldn't work well for 
subfolders, like the gt/uc/ folder I want to add for GuC/HuC files. I 
think extracting this generic helper to a common file, possibly as a 
follow-up step, isn't a bad idea, also considering that there is at 
least 1 more use-case in i915_debugfs_register(). Maybe we can 
generalize as something like:

struct i915_debugfs_files {
	const char *name;
	const struct file_operations *fops;
	bool (*eval)(void *data);
}

void i915_debugfs_register_files(struct dentry *root,
				 const struct i915_debugfs_files *files,
				 unsigned long count, void *data)
{
  	while (count--) {
		umode_t mode = files->fops->write ? 0644 : 0444;
		if (!files->eval || files->eval(data))
  			debugfs_create_file(files->name,
					    mode, root, data,
  					    files->fops);
	}
}

Daniele

>> The main thing of course is not to overengineer and do the minimal
>> necessary for the immediate users we have. We can always extend and
>> refactor for a third user, etc, etc.
>>
>> So if this works for gt + children, go for it and worry about tomorrow,
>> tomorrow. Trusting our good practice for "a stitch in time saves nine".
> 
> this came after Daniele's guc patches where he preferred to
> define his own functions instead of using this one that is meant
> to be used in that situation.
> 
> Andi
>
Andi Shyti March 9, 2020, 10:38 p.m. UTC | #6
Hi Daniele,

> > > > > Quoting Andi Shyti (2020-03-06 23:03:44)
> > > > > > -void debugfs_gt_register_files(struct intel_gt *gt,
> > > > > > -                              struct dentry *root,
> > > > > > -                              const struct debugfs_gt_file *files,
> > > > > > -                              unsigned long count)
> > > > > > +void intel_gt_debugfs_register_files(struct dentry *root,
> > > > > > +                                    const struct debugfs_gt_file *files,
> > > > > > +                                    unsigned long count, void *data)
> > > > > >   {
> > > > > >          while (count--) {
> > > > > > -               if (!files->eval || files->eval(gt))
> > > > > > +               if (!files->eval || files->eval(data))
> > > > > >                          debugfs_create_file(files->name,
> > > > > > -                                           0444, root, gt,
> > > > > > +                                           0444, root, data,
> > > > > >                                              files->fops);
> > > > > 
> > > > > And now we are not a intel_gt routine, you'll want to move again :)
> > > > > i915_debugfs_utils.c ? :)
> > > > 
> > > > Actually, this is what it came to and this was the first
> > > > discussion I had with Daniele and that's also why I was loyal to
> > > > th "_gt_" wrappers until the end. But I had to agree that this
> > > > was becoming more a limitation.
> > > > 
> > > > The biggest difference left, which by the way is the real
> > > > distinguishing factor other than the *gt pointer, is that we
> > > > create files under gt directory, instead of having the root
> > > > imposed by the drm (even though the caller can eventually choose
> > > > different roots).
> > > > 
> > > > We could perhaps store the root pointer in the intel_gt
> > > > structure so that this function stays de facto an intel_gt
> > > > routine and the caller doesn't need to care where the files will
> > > > be generated. This is what we planned to do with sysfs as well.
> > > > 
> > > > What do you think?
> > > 
> > > I thought we were passing along the root. If not I think we should, more
> > > of a debugfs constructor context?
> > 
> > What do you mean with debugfs constructor context? Is it a
> > gt->debugfs_root pointer like the gt->sysfs_root?
> > 

> Getting the root pointer internally from gt wouldn't work well for
> subfolders, like the gt/uc/ folder I want to add for GuC/HuC files.

this was not my idea, actually I was thinking the opposite.

When in this case you call "intel_gt_debugfs_register_files", you
would provide "gt" pointer where the funcion extracts and handles
by its own the debugfs_root. The caller doesn't need to care
about it.

Another idea could be to use contexts, e.g. guc or pm or whatever
comes to mind, and the intel_gt_debugfs handles everything
including subdirectories.

> I think extracting this generic helper to a common file, possibly as a follow-up
> step, isn't a bad idea, also considering that there is at least 1 more
> use-case in i915_debugfs_register(). Maybe we can generalize as something
> like:
> 
> struct i915_debugfs_files {
> 	const char *name;
> 	const struct file_operations *fops;
> 	bool (*eval)(void *data);
> }
> 
> void i915_debugfs_register_files(struct dentry *root,
> 				 const struct i915_debugfs_files *files,
> 				 unsigned long count, void *data)
> {
>  	while (count--) {
> 		umode_t mode = files->fops->write ? 0644 : 0444;
> 		if (!files->eval || files->eval(data))
>  			debugfs_create_file(files->name,
> 					    mode, root, data,
>  					    files->fops);
> 	}
> }

apart from the mode, isn't this the same as the latest patch you
actually reviewed?

> void i915_debugfs_register_files(struct dentry *root,

based on my proposal, root would point, in your case, to the
"guc/" directory that will be created under the "gt/". NULL if
you want the file to be created in the main "gt/" directory.

While if we want to go by context, we could do something like:

struct i915_debugfs_files {                                    
      const char *name;                                        
      const struct file_operations *fops;                      
      bool (*eval)(void *data);                                
      enum intel_gt_context context;
}

and the gt handles everything.

Andi
Daniele Ceraolo Spurio March 9, 2020, 11:11 p.m. UTC | #7
On 3/9/20 3:38 PM, Andi Shyti wrote:
> Hi Daniele,
> 
>>>>>> Quoting Andi Shyti (2020-03-06 23:03:44)
>>>>>>> -void debugfs_gt_register_files(struct intel_gt *gt,
>>>>>>> -                              struct dentry *root,
>>>>>>> -                              const struct debugfs_gt_file *files,
>>>>>>> -                              unsigned long count)
>>>>>>> +void intel_gt_debugfs_register_files(struct dentry *root,
>>>>>>> +                                    const struct debugfs_gt_file *files,
>>>>>>> +                                    unsigned long count, void *data)
>>>>>>>    {
>>>>>>>           while (count--) {
>>>>>>> -               if (!files->eval || files->eval(gt))
>>>>>>> +               if (!files->eval || files->eval(data))
>>>>>>>                           debugfs_create_file(files->name,
>>>>>>> -                                           0444, root, gt,
>>>>>>> +                                           0444, root, data,
>>>>>>>                                               files->fops);
>>>>>>
>>>>>> And now we are not a intel_gt routine, you'll want to move again :)
>>>>>> i915_debugfs_utils.c ? :)
>>>>>
>>>>> Actually, this is what it came to and this was the first
>>>>> discussion I had with Daniele and that's also why I was loyal to
>>>>> th "_gt_" wrappers until the end. But I had to agree that this
>>>>> was becoming more a limitation.
>>>>>
>>>>> The biggest difference left, which by the way is the real
>>>>> distinguishing factor other than the *gt pointer, is that we
>>>>> create files under gt directory, instead of having the root
>>>>> imposed by the drm (even though the caller can eventually choose
>>>>> different roots).
>>>>>
>>>>> We could perhaps store the root pointer in the intel_gt
>>>>> structure so that this function stays de facto an intel_gt
>>>>> routine and the caller doesn't need to care where the files will
>>>>> be generated. This is what we planned to do with sysfs as well.
>>>>>
>>>>> What do you think?
>>>>
>>>> I thought we were passing along the root. If not I think we should, more
>>>> of a debugfs constructor context?
>>>
>>> What do you mean with debugfs constructor context? Is it a
>>> gt->debugfs_root pointer like the gt->sysfs_root?
>>>
> 
>> Getting the root pointer internally from gt wouldn't work well for
>> subfolders, like the gt/uc/ folder I want to add for GuC/HuC files.
> 
> this was not my idea, actually I was thinking the opposite.
> 
> When in this case you call "intel_gt_debugfs_register_files", you
> would provide "gt" pointer where the funcion extracts and handles
> by its own the debugfs_root. The caller doesn't need to care
> about it.
> 
> Another idea could be to use contexts, e.g. guc or pm or whatever
> comes to mind, and the intel_gt_debugfs handles everything
> including subdirectories.
> 
>> I think extracting this generic helper to a common file, possibly as a follow-up
>> step, isn't a bad idea, also considering that there is at least 1 more
>> use-case in i915_debugfs_register(). Maybe we can generalize as something
>> like:
>>
>> struct i915_debugfs_files {
>> 	const char *name;
>> 	const struct file_operations *fops;
>> 	bool (*eval)(void *data);
>> }
>>
>> void i915_debugfs_register_files(struct dentry *root,
>> 				 const struct i915_debugfs_files *files,
>> 				 unsigned long count, void *data)
>> {
>>   	while (count--) {
>> 		umode_t mode = files->fops->write ? 0644 : 0444;
>> 		if (!files->eval || files->eval(data))
>>   			debugfs_create_file(files->name,
>> 					    mode, root, data,
>>   					    files->fops);
>> 	}
>> }
> 
> apart from the mode, isn't this the same as the latest patch you
> actually reviewed?
> 

Yes, but by adding the mode and making the naming generic we can re-use 
it outside the GT code, e.g. in i915_debugfs_connector_add() and to 
replace the loop in i915_debugfs_register(). I was reconnecting to 
Chris' proposal of having a common function in i915_debugfs_utils.c (or 
even just in i915_debugfs.c ?).

>> void i915_debugfs_register_files(struct dentry *root,
> 
> based on my proposal, root would point, in your case, to the
> "guc/" directory that will be created under the "gt/". NULL if
> you want the file to be created in the main "gt/" directory.
> 

If I'm understanding correctly, you're proposing to pass both struct 
intel_gt *gt and struct dentry *root, with the latter being set only if 
we want a folder different that gt/ ? What would that gain us compared 
to just passing the desired root every time like we currently do?

> While if we want to go by context, we could do something like:
> 
> struct i915_debugfs_files {
>        const char *name;
>        const struct file_operations *fops;
>        bool (*eval)(void *data);
>        enum intel_gt_context context;

This seems overkill, also because you'd have to save all the roots 
inside of the gt struct to allow accessing them from within the 
register_files function.

> }
> 
> and the gt handles everything.

Maybe I'm misunderstanding your proposal, but it feels like you're 
trying to find a use for a gt variable we don't really need just to keep 
this as a gt routine.

Daniele

> 
> Andi
>
Andi Shyti March 11, 2020, 8:24 a.m. UTC | #8
Hi Daniele,

> > > > > > > Quoting Andi Shyti (2020-03-06 23:03:44)
> > > > > > > > -void debugfs_gt_register_files(struct intel_gt *gt,
> > > > > > > > -                              struct dentry *root,
> > > > > > > > -                              const struct debugfs_gt_file *files,
> > > > > > > > -                              unsigned long count)
> > > > > > > > +void intel_gt_debugfs_register_files(struct dentry *root,
> > > > > > > > +                                    const struct debugfs_gt_file *files,
> > > > > > > > +                                    unsigned long count, void *data)
> > > > > > > >    {
> > > > > > > >           while (count--) {
> > > > > > > > -               if (!files->eval || files->eval(gt))
> > > > > > > > +               if (!files->eval || files->eval(data))
> > > > > > > >                           debugfs_create_file(files->name,
> > > > > > > > -                                           0444, root, gt,
> > > > > > > > +                                           0444, root, data,
> > > > > > > >                                               files->fops);
> > > > > > > 
> > > > > > > And now we are not a intel_gt routine, you'll want to move again :)
> > > > > > > i915_debugfs_utils.c ? :)
> > > > > > 
> > > > > > Actually, this is what it came to and this was the first
> > > > > > discussion I had with Daniele and that's also why I was loyal to
> > > > > > th "_gt_" wrappers until the end. But I had to agree that this
> > > > > > was becoming more a limitation.
> > > > > > 
> > > > > > The biggest difference left, which by the way is the real
> > > > > > distinguishing factor other than the *gt pointer, is that we
> > > > > > create files under gt directory, instead of having the root
> > > > > > imposed by the drm (even though the caller can eventually choose
> > > > > > different roots).
> > > > > > 
> > > > > > We could perhaps store the root pointer in the intel_gt
> > > > > > structure so that this function stays de facto an intel_gt
> > > > > > routine and the caller doesn't need to care where the files will
> > > > > > be generated. This is what we planned to do with sysfs as well.
> > > > > > 
> > > > > > What do you think?
> > > > > 
> > > > > I thought we were passing along the root. If not I think we should, more
> > > > > of a debugfs constructor context?
> > > > 
> > > > What do you mean with debugfs constructor context? Is it a
> > > > gt->debugfs_root pointer like the gt->sysfs_root?
> > > > 
> > 
> > > Getting the root pointer internally from gt wouldn't work well for
> > > subfolders, like the gt/uc/ folder I want to add for GuC/HuC files.
> > 
> > this was not my idea, actually I was thinking the opposite.
> > 
> > When in this case you call "intel_gt_debugfs_register_files", you
> > would provide "gt" pointer where the funcion extracts and handles
> > by its own the debugfs_root. The caller doesn't need to care
> > about it.
> > 
> > Another idea could be to use contexts, e.g. guc or pm or whatever
> > comes to mind, and the intel_gt_debugfs handles everything
> > including subdirectories.
> > 
> > > I think extracting this generic helper to a common file, possibly as a follow-up
> > > step, isn't a bad idea, also considering that there is at least 1 more
> > > use-case in i915_debugfs_register(). Maybe we can generalize as something
> > > like:
> > > 
> > > struct i915_debugfs_files {
> > > 	const char *name;
> > > 	const struct file_operations *fops;
> > > 	bool (*eval)(void *data);
> > > }
> > > 
> > > void i915_debugfs_register_files(struct dentry *root,
> > > 				 const struct i915_debugfs_files *files,
> > > 				 unsigned long count, void *data)
> > > {
> > >   	while (count--) {
> > > 		umode_t mode = files->fops->write ? 0644 : 0444;
> > > 		if (!files->eval || files->eval(data))
> > >   			debugfs_create_file(files->name,
> > > 					    mode, root, data,
> > >   					    files->fops);
> > > 	}
> > > }
> > 
> > apart from the mode, isn't this the same as the latest patch you
> > actually reviewed?
> > 
> 
> Yes, but by adding the mode and making the naming generic we can re-use it
> outside the GT code, e.g. in i915_debugfs_connector_add() and to replace the
> loop in i915_debugfs_register(). I was reconnecting to Chris' proposal of
> having a common function in i915_debugfs_utils.c (or even just in
> i915_debugfs.c ?).

that's where we are coming from, we just moved this in :)

> > > void i915_debugfs_register_files(struct dentry *root,
> > 
> > based on my proposal, root would point, in your case, to the
> > "guc/" directory that will be created under the "gt/". NULL if
> > you want the file to be created in the main "gt/" directory.
> > 
> 
> If I'm understanding correctly, you're proposing to pass both struct
> intel_gt *gt and struct dentry *root, with the latter being set only if we
> want a folder different that gt/ ? What would that gain us compared to just
> passing the desired root every time like we currently do?
> 
> > While if we want to go by context, we could do something like:
> > 
> > struct i915_debugfs_files {
> >        const char *name;
> >        const struct file_operations *fops;
> >        bool (*eval)(void *data);
> >        enum intel_gt_context context;
> 
> This seems overkill, also because you'd have to save all the roots inside of
> the gt struct to allow accessing them from within the register_files
> function.
> 
> > }
> > 
> > and the gt handles everything.
> 
> Maybe I'm misunderstanding your proposal, but it feels like you're trying to
> find a use for a gt variable we don't really need just to keep this as a gt
> routine.

I'm just thinking aloud here also to avoid moving things back and
forth so easily.

I don't want to overdo things, but the way I see it, and the way
it was thought originally, is to have a hierarchical organization
of the debugfs, so taht "uc" and other gt systems cannot create
files above gt.

This patch is not just becoming gt independent, but it's i915
independent and, at this point, we can send it directly under
inode.c.

Andi
Daniele Ceraolo Spurio March 12, 2020, 12:37 a.m. UTC | #9
On 3/11/20 1:24 AM, Andi Shyti wrote:
> Hi Daniele,
> 
>>>>>>>> Quoting Andi Shyti (2020-03-06 23:03:44)
>>>>>>>>> -void debugfs_gt_register_files(struct intel_gt *gt,
>>>>>>>>> -                              struct dentry *root,
>>>>>>>>> -                              const struct debugfs_gt_file *files,
>>>>>>>>> -                              unsigned long count)
>>>>>>>>> +void intel_gt_debugfs_register_files(struct dentry *root,
>>>>>>>>> +                                    const struct debugfs_gt_file *files,
>>>>>>>>> +                                    unsigned long count, void *data)
>>>>>>>>>     {
>>>>>>>>>            while (count--) {
>>>>>>>>> -               if (!files->eval || files->eval(gt))
>>>>>>>>> +               if (!files->eval || files->eval(data))
>>>>>>>>>                            debugfs_create_file(files->name,
>>>>>>>>> -                                           0444, root, gt,
>>>>>>>>> +                                           0444, root, data,
>>>>>>>>>                                                files->fops);
>>>>>>>>
>>>>>>>> And now we are not a intel_gt routine, you'll want to move again :)
>>>>>>>> i915_debugfs_utils.c ? :)
>>>>>>>
>>>>>>> Actually, this is what it came to and this was the first
>>>>>>> discussion I had with Daniele and that's also why I was loyal to
>>>>>>> th "_gt_" wrappers until the end. But I had to agree that this
>>>>>>> was becoming more a limitation.
>>>>>>>
>>>>>>> The biggest difference left, which by the way is the real
>>>>>>> distinguishing factor other than the *gt pointer, is that we
>>>>>>> create files under gt directory, instead of having the root
>>>>>>> imposed by the drm (even though the caller can eventually choose
>>>>>>> different roots).
>>>>>>>
>>>>>>> We could perhaps store the root pointer in the intel_gt
>>>>>>> structure so that this function stays de facto an intel_gt
>>>>>>> routine and the caller doesn't need to care where the files will
>>>>>>> be generated. This is what we planned to do with sysfs as well.
>>>>>>>
>>>>>>> What do you think?
>>>>>>
>>>>>> I thought we were passing along the root. If not I think we should, more
>>>>>> of a debugfs constructor context?
>>>>>
>>>>> What do you mean with debugfs constructor context? Is it a
>>>>> gt->debugfs_root pointer like the gt->sysfs_root?
>>>>>
>>>
>>>> Getting the root pointer internally from gt wouldn't work well for
>>>> subfolders, like the gt/uc/ folder I want to add for GuC/HuC files.
>>>
>>> this was not my idea, actually I was thinking the opposite.
>>>
>>> When in this case you call "intel_gt_debugfs_register_files", you
>>> would provide "gt" pointer where the funcion extracts and handles
>>> by its own the debugfs_root. The caller doesn't need to care
>>> about it.
>>>
>>> Another idea could be to use contexts, e.g. guc or pm or whatever
>>> comes to mind, and the intel_gt_debugfs handles everything
>>> including subdirectories.
>>>
>>>> I think extracting this generic helper to a common file, possibly as a follow-up
>>>> step, isn't a bad idea, also considering that there is at least 1 more
>>>> use-case in i915_debugfs_register(). Maybe we can generalize as something
>>>> like:
>>>>
>>>> struct i915_debugfs_files {
>>>> 	const char *name;
>>>> 	const struct file_operations *fops;
>>>> 	bool (*eval)(void *data);
>>>> }
>>>>
>>>> void i915_debugfs_register_files(struct dentry *root,
>>>> 				 const struct i915_debugfs_files *files,
>>>> 				 unsigned long count, void *data)
>>>> {
>>>>    	while (count--) {
>>>> 		umode_t mode = files->fops->write ? 0644 : 0444;
>>>> 		if (!files->eval || files->eval(data))
>>>>    			debugfs_create_file(files->name,
>>>> 					    mode, root, data,
>>>>    					    files->fops);
>>>> 	}
>>>> }
>>>
>>> apart from the mode, isn't this the same as the latest patch you
>>> actually reviewed?
>>>
>>
>> Yes, but by adding the mode and making the naming generic we can re-use it
>> outside the GT code, e.g. in i915_debugfs_connector_add() and to replace the
>> loop in i915_debugfs_register(). I was reconnecting to Chris' proposal of
>> having a common function in i915_debugfs_utils.c (or even just in
>> i915_debugfs.c ?).
> 
> that's where we are coming from, we just moved this in :)
> 
>>>> void i915_debugfs_register_files(struct dentry *root,
>>>
>>> based on my proposal, root would point, in your case, to the
>>> "guc/" directory that will be created under the "gt/". NULL if
>>> you want the file to be created in the main "gt/" directory.
>>>
>>
>> If I'm understanding correctly, you're proposing to pass both struct
>> intel_gt *gt and struct dentry *root, with the latter being set only if we
>> want a folder different that gt/ ? What would that gain us compared to just
>> passing the desired root every time like we currently do?
>>
>>> While if we want to go by context, we could do something like:
>>>
>>> struct i915_debugfs_files {
>>>         const char *name;
>>>         const struct file_operations *fops;
>>>         bool (*eval)(void *data);
>>>         enum intel_gt_context context;
>>
>> This seems overkill, also because you'd have to save all the roots inside of
>> the gt struct to allow accessing them from within the register_files
>> function.
>>
>>> }
>>>
>>> and the gt handles everything.
>>
>> Maybe I'm misunderstanding your proposal, but it feels like you're trying to
>> find a use for a gt variable we don't really need just to keep this as a gt
>> routine.
> 
> I'm just thinking aloud here also to avoid moving things back and
> forth so easily.
> 

As I've mentioned above I wasn't suggesting moving this around now, just 
pointing out that there are other parts of the driver that open-code 
what we do in the gt and therefore there is space for code re-use in the 
future. I'm ok with merging this as-is in the meantime.

> I don't want to overdo things, but the way I see it, and the way
> it was thought originally, is to have a hierarchical organization
> of the debugfs, so taht "uc" and other gt systems cannot create
> files above gt.

But this hierarchy is currently implemented by passing the correct root 
pointer in and not via the gt pointer, so from the function POV you 
nothing stops you from passing in a root above gt/. The only thing the 
gt pointer is used for are data and eval().

> 
> This patch is not just becoming gt independent, but it's i915
> independent and, at this point, we can send it directly under
> inode.c.
> 

Fair point :)
I'm going to send my patches rebased on top of this one to better show 
what I mean when I say I don't use the gt variable locally at all. If we 
decide we still want it I'll throw in a guc/huc_to_gt to take it out.

Daniele

> Andi
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gt/debugfs_engines.c b/drivers/gpu/drm/i915/gt/debugfs_engines.c
index 6a5e9ab20b94..5e3725e62241 100644
--- a/drivers/gpu/drm/i915/gt/debugfs_engines.c
+++ b/drivers/gpu/drm/i915/gt/debugfs_engines.c
@@ -32,5 +32,5 @@  void debugfs_engines_register(struct intel_gt *gt, struct dentry *root)
 		{ "engines", &engines_fops },
 	};
 
-	debugfs_gt_register_files(gt, root, files, ARRAY_SIZE(files));
+	intel_gt_debugfs_register_files(root, files, ARRAY_SIZE(files), gt);
 }
diff --git a/drivers/gpu/drm/i915/gt/debugfs_gt.c b/drivers/gpu/drm/i915/gt/debugfs_gt.c
index 75255aaacaed..de73b63d6ba7 100644
--- a/drivers/gpu/drm/i915/gt/debugfs_gt.c
+++ b/drivers/gpu/drm/i915/gt/debugfs_gt.c
@@ -26,15 +26,14 @@  void debugfs_gt_register(struct intel_gt *gt)
 	debugfs_gt_pm_register(gt, root);
 }
 
-void debugfs_gt_register_files(struct intel_gt *gt,
-			       struct dentry *root,
-			       const struct debugfs_gt_file *files,
-			       unsigned long count)
+void intel_gt_debugfs_register_files(struct dentry *root,
+				     const struct debugfs_gt_file *files,
+				     unsigned long count, void *data)
 {
 	while (count--) {
-		if (!files->eval || files->eval(gt))
+		if (!files->eval || files->eval(data))
 			debugfs_create_file(files->name,
-					    0444, root, gt,
+					    0444, root, data,
 					    files->fops);
 
 		files++;
diff --git a/drivers/gpu/drm/i915/gt/debugfs_gt.h b/drivers/gpu/drm/i915/gt/debugfs_gt.h
index 4ea0f06cda8f..f77540f727e9 100644
--- a/drivers/gpu/drm/i915/gt/debugfs_gt.h
+++ b/drivers/gpu/drm/i915/gt/debugfs_gt.h
@@ -28,12 +28,11 @@  void debugfs_gt_register(struct intel_gt *gt);
 struct debugfs_gt_file {
 	const char *name;
 	const struct file_operations *fops;
-	bool (*eval)(const struct intel_gt *gt);
+	bool (*eval)(void *data);
 };
 
-void debugfs_gt_register_files(struct intel_gt *gt,
-			       struct dentry *root,
-			       const struct debugfs_gt_file *files,
-			       unsigned long count);
+void intel_gt_debugfs_register_files(struct dentry *root,
+				     const struct debugfs_gt_file *files,
+				     unsigned long count, void *data);
 
 #endif /* DEBUGFS_GT_H */
diff --git a/drivers/gpu/drm/i915/gt/debugfs_gt_pm.c b/drivers/gpu/drm/i915/gt/debugfs_gt_pm.c
index 059c9e5c002e..dc024944873a 100644
--- a/drivers/gpu/drm/i915/gt/debugfs_gt_pm.c
+++ b/drivers/gpu/drm/i915/gt/debugfs_gt_pm.c
@@ -506,9 +506,11 @@  static int llc_show(struct seq_file *m, void *data)
 	return 0;
 }
 
-static bool llc_eval(const struct intel_gt *gt)
+static bool llc_eval(void *data)
 {
-	return HAS_LLC(gt->i915);
+	struct intel_gt *gt = data;
+
+	return gt && HAS_LLC(gt->i915);
 }
 
 DEFINE_GT_DEBUGFS_ATTRIBUTE(llc);
@@ -580,9 +582,11 @@  static int rps_boost_show(struct seq_file *m, void *data)
 	return 0;
 }
 
-static bool rps_eval(const struct intel_gt *gt)
+static bool rps_eval(void *data)
 {
-	return HAS_RPS(gt->i915);
+	struct intel_gt *gt = data;
+
+	return gt && HAS_RPS(gt->i915);
 }
 
 DEFINE_GT_DEBUGFS_ATTRIBUTE(rps_boost);
@@ -597,5 +601,5 @@  void debugfs_gt_pm_register(struct intel_gt *gt, struct dentry *root)
 		{ "rps_boost", &rps_boost_fops, rps_eval },
 	};
 
-	debugfs_gt_register_files(gt, root, files, ARRAY_SIZE(files));
+	intel_gt_debugfs_register_files(root, files, ARRAY_SIZE(files), gt);
 }