All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Mikko Perttunen
	<mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
	thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
Cc: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 06/10] drm/tegra: Deliver job completion callback to client
Date: Thu, 16 Nov 2017 19:33:39 +0300	[thread overview]
Message-ID: <a5b3d90e-6cc9-8c1a-5141-d5cb8548add9@gmail.com> (raw)
In-Reply-To: <20171105110118.15142-7-mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

On 05.11.2017 14:01, Mikko Perttunen wrote:
> To allow client drivers to free resources when jobs have completed,
> deliver job completion callbacks to them. This requires adding
> reference counting to context objects, as job completion can happen
> after the userspace application has closed the context. As such,
> also add kref-based refcounting for contexts.
> 

It's very likely that we will need contexts kref'ing for other things as well,
would be nice if you could factor out kref addition into a standalone patch.

> Signed-off-by: Mikko Perttunen <mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> ---
>  drivers/gpu/drm/tegra/drm.c | 27 ++++++++++++++++++++++++---
>  drivers/gpu/drm/tegra/drm.h |  4 ++++
>  2 files changed, 28 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
> index 2cdd054520bf..3e2a4a19412e 100644
> --- a/drivers/gpu/drm/tegra/drm.c
> +++ b/drivers/gpu/drm/tegra/drm.c
> @@ -281,8 +281,11 @@ static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp)
>  	return 0;
>  }
>  
> -static void tegra_drm_context_free(struct tegra_drm_context *context)
> +static void tegra_drm_context_free(struct kref *ref)
>  {
> +	struct tegra_drm_context *context =
> +		container_of(ref, struct tegra_drm_context, ref);
> +
>  	context->client->ops->close_channel(context);
>  	kfree(context);
>  }
> @@ -379,6 +382,16 @@ static int host1x_waitchk_copy_from_user(struct host1x_waitchk *dest,
>  	return 0;
>  }
>  
> +static void tegra_drm_job_done(struct host1x_job *job)
> +{
> +	struct tegra_drm_context *context = job->callback_data;
> +
> +	if (context->client->ops->submit_done)
> +		context->client->ops->submit_done(context);
> +
> +	kref_put(&context->ref, tegra_drm_context_free);
> +}
> +
>  int tegra_drm_submit(struct tegra_drm_context *context,
>  		     struct drm_tegra_submit *args, struct drm_device *drm,
>  		     struct drm_file *file)
> @@ -560,6 +573,9 @@ int tegra_drm_submit(struct tegra_drm_context *context,
>  	job->syncpt_id = syncpt.id;
>  	job->timeout = 10000;
>  
> +	job->done = tegra_drm_job_done;
> +	job->callback_data = context;
> +
>  	if (args->timeout && args->timeout < 10000)
>  		job->timeout = args->timeout;
>  
> @@ -567,8 +583,11 @@ int tegra_drm_submit(struct tegra_drm_context *context,
>  	if (err)
>  		goto fail;
>  
> +	kref_get(&context->ref);
> +
>  	err = host1x_job_submit(job);
>  	if (err) {
> +		kref_put(&context->ref, tegra_drm_context_free);
>  		host1x_job_unpin(job);
>  		goto fail;
>  	}
> @@ -717,6 +736,8 @@ static int tegra_open_channel(struct drm_device *drm, void *data,
>  	if (err < 0)
>  		kfree(context);
>  
> +	kref_init(&context->ref);
> +

Would be a bit cleaner to move kref_init into tegra_client_open() where the rest
of context variables getting initialized.

>  	mutex_unlock(&fpriv->lock);
>  	return err;
>  }
> @@ -738,7 +759,7 @@ static int tegra_close_channel(struct drm_device *drm, void *data,
>  	}
>  
>  	idr_remove(&fpriv->contexts, context->id);
> -	tegra_drm_context_free(context);
> +	kref_put(&context->ref, tegra_drm_context_free);
>  
>  unlock:
>  	mutex_unlock(&fpriv->lock);
> @@ -1026,7 +1047,7 @@ static int tegra_drm_context_cleanup(int id, void *p, void *data)
>  {
>  	struct tegra_drm_context *context = p;
>  
> -	tegra_drm_context_free(context);
> +	kref_put(&context->ref, tegra_drm_context_free);
>  
>  	return 0;
>  }
> diff --git a/drivers/gpu/drm/tegra/drm.h b/drivers/gpu/drm/tegra/drm.h
> index 063f5d397526..079aebb3fb38 100644
> --- a/drivers/gpu/drm/tegra/drm.h
> +++ b/drivers/gpu/drm/tegra/drm.h
> @@ -13,6 +13,7 @@
>  #include <uapi/drm/tegra_drm.h>
>  #include <linux/host1x.h>
>  #include <linux/iova.h>
> +#include <linux/kref.h>
>  #include <linux/of_gpio.h>
>  
>  #include <drm/drmP.h>
> @@ -74,6 +75,8 @@ struct tegra_drm {
>  struct tegra_drm_client;
>  
>  struct tegra_drm_context {
> +	struct kref ref;
> +
>  	struct tegra_drm_client *client;
>  	struct host1x_channel *channel;
>  	unsigned int id;
> @@ -88,6 +91,7 @@ struct tegra_drm_client_ops {
>  	int (*submit)(struct tegra_drm_context *context,
>  		      struct drm_tegra_submit *args, struct drm_device *drm,
>  		      struct drm_file *file);
> +	void (*submit_done)(struct tegra_drm_context *context);
>  };
>  
>  int tegra_drm_submit(struct tegra_drm_context *context,
> 

WARNING: multiple messages have this Message-ID (diff)
From: Dmitry Osipenko <digetx@gmail.com>
To: Mikko Perttunen <mperttunen@nvidia.com>,
	thierry.reding@gmail.com, jonathanh@nvidia.com
Cc: dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 06/10] drm/tegra: Deliver job completion callback to client
Date: Thu, 16 Nov 2017 19:33:39 +0300	[thread overview]
Message-ID: <a5b3d90e-6cc9-8c1a-5141-d5cb8548add9@gmail.com> (raw)
In-Reply-To: <20171105110118.15142-7-mperttunen@nvidia.com>

On 05.11.2017 14:01, Mikko Perttunen wrote:
> To allow client drivers to free resources when jobs have completed,
> deliver job completion callbacks to them. This requires adding
> reference counting to context objects, as job completion can happen
> after the userspace application has closed the context. As such,
> also add kref-based refcounting for contexts.
> 

It's very likely that we will need contexts kref'ing for other things as well,
would be nice if you could factor out kref addition into a standalone patch.

> Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
> ---
>  drivers/gpu/drm/tegra/drm.c | 27 ++++++++++++++++++++++++---
>  drivers/gpu/drm/tegra/drm.h |  4 ++++
>  2 files changed, 28 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
> index 2cdd054520bf..3e2a4a19412e 100644
> --- a/drivers/gpu/drm/tegra/drm.c
> +++ b/drivers/gpu/drm/tegra/drm.c
> @@ -281,8 +281,11 @@ static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp)
>  	return 0;
>  }
>  
> -static void tegra_drm_context_free(struct tegra_drm_context *context)
> +static void tegra_drm_context_free(struct kref *ref)
>  {
> +	struct tegra_drm_context *context =
> +		container_of(ref, struct tegra_drm_context, ref);
> +
>  	context->client->ops->close_channel(context);
>  	kfree(context);
>  }
> @@ -379,6 +382,16 @@ static int host1x_waitchk_copy_from_user(struct host1x_waitchk *dest,
>  	return 0;
>  }
>  
> +static void tegra_drm_job_done(struct host1x_job *job)
> +{
> +	struct tegra_drm_context *context = job->callback_data;
> +
> +	if (context->client->ops->submit_done)
> +		context->client->ops->submit_done(context);
> +
> +	kref_put(&context->ref, tegra_drm_context_free);
> +}
> +
>  int tegra_drm_submit(struct tegra_drm_context *context,
>  		     struct drm_tegra_submit *args, struct drm_device *drm,
>  		     struct drm_file *file)
> @@ -560,6 +573,9 @@ int tegra_drm_submit(struct tegra_drm_context *context,
>  	job->syncpt_id = syncpt.id;
>  	job->timeout = 10000;
>  
> +	job->done = tegra_drm_job_done;
> +	job->callback_data = context;
> +
>  	if (args->timeout && args->timeout < 10000)
>  		job->timeout = args->timeout;
>  
> @@ -567,8 +583,11 @@ int tegra_drm_submit(struct tegra_drm_context *context,
>  	if (err)
>  		goto fail;
>  
> +	kref_get(&context->ref);
> +
>  	err = host1x_job_submit(job);
>  	if (err) {
> +		kref_put(&context->ref, tegra_drm_context_free);
>  		host1x_job_unpin(job);
>  		goto fail;
>  	}
> @@ -717,6 +736,8 @@ static int tegra_open_channel(struct drm_device *drm, void *data,
>  	if (err < 0)
>  		kfree(context);
>  
> +	kref_init(&context->ref);
> +

Would be a bit cleaner to move kref_init into tegra_client_open() where the rest
of context variables getting initialized.

>  	mutex_unlock(&fpriv->lock);
>  	return err;
>  }
> @@ -738,7 +759,7 @@ static int tegra_close_channel(struct drm_device *drm, void *data,
>  	}
>  
>  	idr_remove(&fpriv->contexts, context->id);
> -	tegra_drm_context_free(context);
> +	kref_put(&context->ref, tegra_drm_context_free);
>  
>  unlock:
>  	mutex_unlock(&fpriv->lock);
> @@ -1026,7 +1047,7 @@ static int tegra_drm_context_cleanup(int id, void *p, void *data)
>  {
>  	struct tegra_drm_context *context = p;
>  
> -	tegra_drm_context_free(context);
> +	kref_put(&context->ref, tegra_drm_context_free);
>  
>  	return 0;
>  }
> diff --git a/drivers/gpu/drm/tegra/drm.h b/drivers/gpu/drm/tegra/drm.h
> index 063f5d397526..079aebb3fb38 100644
> --- a/drivers/gpu/drm/tegra/drm.h
> +++ b/drivers/gpu/drm/tegra/drm.h
> @@ -13,6 +13,7 @@
>  #include <uapi/drm/tegra_drm.h>
>  #include <linux/host1x.h>
>  #include <linux/iova.h>
> +#include <linux/kref.h>
>  #include <linux/of_gpio.h>
>  
>  #include <drm/drmP.h>
> @@ -74,6 +75,8 @@ struct tegra_drm {
>  struct tegra_drm_client;
>  
>  struct tegra_drm_context {
> +	struct kref ref;
> +
>  	struct tegra_drm_client *client;
>  	struct host1x_channel *channel;
>  	unsigned int id;
> @@ -88,6 +91,7 @@ struct tegra_drm_client_ops {
>  	int (*submit)(struct tegra_drm_context *context,
>  		      struct drm_tegra_submit *args, struct drm_device *drm,
>  		      struct drm_file *file);
> +	void (*submit_done)(struct tegra_drm_context *context);
>  };
>  
>  int tegra_drm_submit(struct tegra_drm_context *context,
> 

  parent reply	other threads:[~2017-11-16 16:33 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-05 11:01 [PATCH 00/10] Dynamic Host1x channel allocation Mikko Perttunen
2017-11-05 11:01 ` [PATCH 02/10] gpu: host1x: Print MLOCK state in debug dumps on T186 Mikko Perttunen
2017-11-05 11:01 ` [PATCH 03/10] gpu: host1x: Add lock around channel allocation Mikko Perttunen
2017-11-05 11:01 ` [PATCH 04/10] gpu: host1x: Lock classes during job submission Mikko Perttunen
2017-11-05 11:01   ` Mikko Perttunen
     [not found]   ` <20171105110118.15142-5-mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2017-11-05 16:46     ` Dmitry Osipenko
2017-11-05 16:46       ` Dmitry Osipenko
2017-11-07 12:28       ` Mikko Perttunen
     [not found]         ` <ef08d3d8-94a7-8804-c339-5310719333f3-/1wQRMveznE@public.gmane.org>
2017-11-07 21:23           ` Dmitry Osipenko
2017-11-07 21:23             ` Dmitry Osipenko
     [not found]             ` <dc39398b-ea49-6e97-28ba-652f8b49db44-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-12-05 13:21               ` Mikko Perttunen
2017-12-05 13:21                 ` Mikko Perttunen
     [not found]                 ` <2b4d9283-dabe-9e1f-f8cb-6ddbc16e3f0f-/1wQRMveznE@public.gmane.org>
2017-12-05 13:43                   ` Dmitry Osipenko
2017-12-05 13:43                     ` Dmitry Osipenko
2017-11-05 11:01 ` [PATCH 05/10] gpu: host1x: Add job done callback Mikko Perttunen
     [not found] ` <20171105110118.15142-1-mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2017-11-05 11:01   ` [PATCH 01/10] gpu: host1x: Parameterize channel aperture size Mikko Perttunen
2017-11-05 11:01     ` Mikko Perttunen
2017-11-05 11:01   ` [PATCH 06/10] drm/tegra: Deliver job completion callback to client Mikko Perttunen
2017-11-05 11:01     ` Mikko Perttunen
     [not found]     ` <20171105110118.15142-7-mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2017-11-16 16:33       ` Dmitry Osipenko [this message]
2017-11-16 16:33         ` Dmitry Osipenko
2017-11-16 16:40     ` Dmitry Osipenko
     [not found]       ` <1afa1ba9-3103-3672-2e15-fb8c7de2520b-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-11-29  9:09         ` Mikko Perttunen
2017-11-29  9:09           ` Mikko Perttunen
2017-11-05 11:01   ` [PATCH 07/10] drm/tegra: Make syncpoints be per-context Mikko Perttunen
2017-11-05 11:01     ` Mikko Perttunen
2017-11-07 15:34   ` [PATCH 00/10] Dynamic Host1x channel allocation Dmitry Osipenko
2017-11-07 15:34     ` Dmitry Osipenko
2017-11-05 11:01 ` [PATCH 08/10] drm/tegra: Implement dynamic channel allocation model Mikko Perttunen
     [not found]   ` <20171105110118.15142-9-mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2017-11-05 17:43     ` Dmitry Osipenko
2017-11-05 17:43       ` Dmitry Osipenko
2017-11-07 12:29       ` Mikko Perttunen
     [not found]         ` <38fcf947-0d5d-e2c7-f49f-9efce5eeb1a3-/1wQRMveznE@public.gmane.org>
2017-11-13 11:49           ` Dmitry Osipenko
2017-11-13 11:49             ` Dmitry Osipenko
2017-11-05 11:01 ` [PATCH 09/10] drm/tegra: Boot VIC in runtime resume Mikko Perttunen
2017-11-05 11:01 ` [PATCH 10/10] gpu: host1x: Optionally block when acquiring channel Mikko Perttunen
2017-11-05 11:01   ` Mikko Perttunen
     [not found]   ` <20171105110118.15142-11-mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2017-11-05 17:14     ` Dmitry Osipenko
2017-11-05 17:14       ` Dmitry Osipenko
     [not found]       ` <9c5676eb-ba6f-c187-29e4-7b331bd3962f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-11-07 13:11         ` Mikko Perttunen
2017-11-07 13:11           ` Mikko Perttunen
2017-11-07 15:29           ` Dmitry Osipenko
     [not found]             ` <1b35ec93-167b-3436-0ff2-5e2e0886aea7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-11-10 21:15               ` Dmitry Osipenko
2017-11-10 21:15                 ` Dmitry Osipenko
     [not found]                 ` <dcb8c4ef-9eb9-556f-cc96-651a50636afa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-11-12 11:23                   ` Dmitry Osipenko
2017-11-12 11:23                     ` Dmitry Osipenko
2017-11-29  9:10                     ` Mikko Perttunen
2017-11-29 12:18                       ` Dmitry Osipenko
     [not found]                         ` <07e28b40-dd2b-774f-2d07-3b5d6cf08c46-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-11-29 12:25                           ` Mikko Perttunen
2017-11-29 12:25                             ` Mikko Perttunen
     [not found]                             ` <a4adb6ac-b72e-3f9b-fc6c-2a56bc6537ce-/1wQRMveznE@public.gmane.org>
2017-11-29 12:37                               ` Dmitry Osipenko
2017-11-29 12:37                                 ` Dmitry Osipenko

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=a5b3d90e-6cc9-8c1a-5141-d5cb8548add9@gmail.com \
    --to=digetx-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mperttunen-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.