Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>,
	<intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH 2/5] drm/xe: Add ref counting for xe_file
Date: Tue, 9 Jul 2024 00:28:43 +0000	[thread overview]
Message-ID: <ZoyEO5sqdnuWzKH6@DUT025-TGLU.fm.intel.com> (raw)
In-Reply-To: <Zox1iBxWvN7GtG2Z@orsosgc001>

On Mon, Jul 08, 2024 at 04:26:00PM -0700, Umesh Nerlige Ramappa wrote:
> On Mon, Jul 08, 2024 at 05:52:00PM -0500, Lucas De Marchi wrote:
> > On Mon, Jul 08, 2024 at 01:21:00PM GMT, Umesh Nerlige Ramappa wrote:
> > > Add ref counting for xe_file.
> > > 
> > > Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
> > > ---
> > > drivers/gpu/drm/xe/xe_device.c       |  7 +++++--
> > > drivers/gpu/drm/xe/xe_device.h       | 12 ++++++++++++
> > > drivers/gpu/drm/xe/xe_device_types.h |  3 +++
> > > 3 files changed, 20 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
> > > index babb697652d5..e6eacf1bcce0 100644
> > > --- a/drivers/gpu/drm/xe/xe_device.c
> > > +++ b/drivers/gpu/drm/xe/xe_device.c
> > > @@ -87,11 +87,14 @@ static int xe_file_open(struct drm_device *dev, struct drm_file *file)
> > > 	spin_unlock(&xe->clients.lock);
> > > 
> > > 	file->driver_priv = xef;
> > > +	kref_init(&xef->refcount);
> > > +
> > > 	return 0;
> > > }
> > > 
> > > -static void xe_file_destroy(struct xe_file *xef)
> > > +void xe_file_destroy(struct kref *ref)
> > 
> > why do you export this?  I don't think anybody should be calling
> > xe_file_destroy() directly and this function being executed should only
> > be the outcome of kref being 0. Also, if it's exported, it shouldn't
> > really have struct kref as argument, but rather a struct xe_file
> > 
> > 
> > > {
> > > +	struct xe_file *xef = container_of(ref, struct xe_file, refcount);
> > > 	struct xe_device *xe = xef->xe;
> > > 	struct xe_vm *vm;
> > > 	unsigned long idx;
> > > @@ -130,7 +133,7 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
> > > 		xe_exec_queue_put(q);
> > > 	}
> > > 
> > > -	xe_file_destroy(xef);
> > > +	xe_file_put(xef);
> > > }
> > > 
> > > static const struct drm_ioctl_desc xe_ioctls[] = {
> > > diff --git a/drivers/gpu/drm/xe/xe_device.h b/drivers/gpu/drm/xe/xe_device.h
> > > index bb07f5669dbb..2a8b370b1fda 100644
> > > --- a/drivers/gpu/drm/xe/xe_device.h
> > > +++ b/drivers/gpu/drm/xe/xe_device.h
> > > @@ -169,5 +169,17 @@ static inline bool xe_device_wedged(struct xe_device *xe)
> > > }
> > > 
> > > void xe_device_declare_wedged(struct xe_device *xe);
> > > +void xe_file_destroy(struct kref *ref);
> > > +
> > > +static inline struct xe_file *xe_file_get(struct xe_file *xef)
> > > +{
> > > +	kref_get(&xef->refcount);
> > > +	return xef;
> > > +}
> > > +
> > > +static inline void xe_file_put(struct xe_file *xef)
> > 
> > I think if you just make this non-inline, passing file_destroy and
> > leave it in the same place, it should work.
> 
> the put is called from xe_exec_queue.c and xe_vm.c also, so passing the
> destroy may not work.
> 
> Based on the patterns below, xe_file_put/xe_file_get will need to be moved
> to xe_device.c and then exported. It looks cleaner, hoping that'w what you
> mean.
> 
> In xe_device.h:
> 
> void xe_file_put(struct xe_file *xef);
> struct xe_file *xe_file_get(struct xe_file *xef);
> 

My opinion is the way you have it is correct.

Most of Xe is coded this way...

mbrost@lstrano-desk:xe$ grep _get\( *.h | grep inline
xe_bo.h:static inline struct xe_bo *xe_bo_get(struct xe_bo *bo)
xe_device.h:static inline struct xe_file *xe_file_get(struct xe_file *xef)
xe_exec_queue.h:static inline struct xe_exec_queue *xe_exec_queue_get(struct xe_exec_queue *q)
xe_lrc.h:static inline struct xe_lrc *xe_lrc_get(struct xe_lrc *lrc)
xe_sched_job.h:static inline struct xe_sched_job *xe_sched_job_get(struct xe_sched_job *job)
xe_vm.h:static inline struct xe_vm *xe_vm_get(struct xe_vm *vm)

I'm kinda confused by what Lucas is suggesting.

Matt

> Thanks,
> Umesh
> 
> > 
> > Looking for patterns in the kernel for example, see pinctrl_get(),
> > pinctrl_put() and pinctrl_release().... or clk_get(), clk_put(),
> > __clk_release()
> > 
> > Lucas De Marchi
> > 
> > > +{
> > > +	kref_put(&xef->refcount, xe_file_destroy);
> > > +}
> > > 
> > > #endif
> > > diff --git a/drivers/gpu/drm/xe/xe_device_types.h b/drivers/gpu/drm/xe/xe_device_types.h
> > > index c37be471d11c..ec2b0fb6afe1 100644
> > > --- a/drivers/gpu/drm/xe/xe_device_types.h
> > > +++ b/drivers/gpu/drm/xe/xe_device_types.h
> > > @@ -566,6 +566,9 @@ struct xe_file {
> > > 
> > > 	/** @client: drm client */
> > > 	struct xe_drm_client *client;
> > > +
> > > +	/** @refcount: ref count of this xe file */
> > > +	struct kref refcount;
> > > };
> > > 
> > > #endif
> > > -- 
> > > 2.38.1
> > > 

  reply	other threads:[~2024-07-09  0:29 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-08 20:20 [PATCH 0/5] Have xe_vm and xe_exec_queue take references to xef Umesh Nerlige Ramappa
2024-07-08 20:20 ` [PATCH 1/5] drm/xe: Move part of xe_file cleanup to a helper Umesh Nerlige Ramappa
2024-07-08 21:21   ` Matthew Brost
2024-07-08 22:12     ` Umesh Nerlige Ramappa
2024-07-08 22:18       ` Matthew Brost
2024-07-08 20:21 ` [PATCH 2/5] drm/xe: Add ref counting for xe_file Umesh Nerlige Ramappa
2024-07-08 21:23   ` Matthew Brost
2024-07-08 22:15     ` Umesh Nerlige Ramappa
2024-07-08 22:19       ` Matthew Brost
2024-07-08 23:00     ` Umesh Nerlige Ramappa
2024-07-08 22:52   ` Lucas De Marchi
2024-07-08 23:26     ` Umesh Nerlige Ramappa
2024-07-09  0:28       ` Matthew Brost [this message]
2024-07-09 15:11         ` Lucas De Marchi
2024-07-09 16:37           ` Umesh Nerlige Ramappa
2024-07-09 20:37             ` Matthew Brost
2024-07-11 13:46               ` Lucas De Marchi
2024-07-08 20:21 ` [PATCH 3/5] drm/xe: Take a reference to xe file when user creates exec_queue Umesh Nerlige Ramappa
2024-07-08 21:25   ` Matthew Brost
2024-07-08 20:21 ` [PATCH 4/5] drm/xe: Take a ref to xe file when user creates a VM Umesh Nerlige Ramappa
2024-07-08 21:32   ` Matthew Brost
2024-07-08 20:21 ` [PATCH 5/5] Revert "drm/xe: Do not access xe file when updating exec queue run_ticks" Umesh Nerlige Ramappa
2024-07-08 21:33   ` Matthew Brost
2024-07-08 20:26 ` ✓ CI.Patch_applied: success for Have xe_vm and xe_exec_queue take references to xef Patchwork
2024-07-08 20:27 ` ✓ CI.checkpatch: " Patchwork
2024-07-08 20:28 ` ✓ CI.KUnit: " Patchwork
2024-07-08 20:40 ` ✓ CI.Build: " Patchwork
2024-07-08 20:42 ` ✓ CI.Hooks: " Patchwork
2024-07-08 20:43 ` ✓ CI.checksparse: " Patchwork
2024-07-08 21:16 ` ✗ CI.BAT: failure " Patchwork
2024-07-08 21:37 ` [PATCH 0/5] " Lucas De Marchi
2024-07-09  1:07 ` ✗ CI.FULL: failure for " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZoyEO5sqdnuWzKH6@DUT025-TGLU.fm.intel.com \
    --to=matthew.brost@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@intel.com \
    --cc=umesh.nerlige.ramappa@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox