public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Andi Shyti <andi.shyti@intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH i-g-t] lib: Fix intel_get_current_physical_engine() iterator
Date: Wed, 29 May 2019 17:33:28 +0300	[thread overview]
Message-ID: <20190529143328.GD3552@intel.intel> (raw)
In-Reply-To: <20190529132421.27905-1-chris@chris-wilson.co.uk>

Hi Chris,

On Wed, May 29, 2019 at 02:24:21PM +0100, Chris Wilson wrote:
> If we run out of engines, intel_get_current_physical_engine() degrades
> into an infinite loop as although it advanced the iterator, it did not
> update its local engine pointer.

The patch looks like it does everything "but" what you say in the
commit log :)

> 
> Reported-by: Petri Latvala <petri.latvala@intel.com>
> Fixes: 17c77e7b0c3c ("lib/i915: add gem_engine_topology library and for_each loop definition")
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Andi Shyti <andi.shyti@intel.com>
> Cc: Petri Latvala <petri.latvala@intel.com>
> ---
>  lib/i915/gem_engine_topology.c | 49 +++++-----------------------------
>  lib/i915/gem_engine_topology.h | 36 ++++++++++++++++---------
>  2 files changed, 29 insertions(+), 56 deletions(-)
> 
> diff --git a/lib/i915/gem_engine_topology.c b/lib/i915/gem_engine_topology.c
> index fdd1b9516..17f67786f 100644
> --- a/lib/i915/gem_engine_topology.c
> +++ b/lib/i915/gem_engine_topology.c
> @@ -81,11 +81,10 @@ static void ctx_map_engines(int fd, struct intel_engine_data *ed,
>  			    struct drm_i915_gem_context_param *param)
>  {
>  	struct i915_context_param_engines *engines =
> -			from_user_pointer(param->value);
> +		from_user_pointer(param->value);
>  	int i = 0;
>  
> -	for (typeof(engines->engines[0]) *p =
> -	     &engines->engines[0];
> +	for (struct i915_engine_class_instance *p = &engines->engines[0];
>  	     i < ed->nengines; i++, p++) {
>  		p->engine_class = ed->engines[i].class;
>  		p->engine_instance = ed->engines[i].instance;
> @@ -136,7 +135,7 @@ static void query_engine_list(int fd, struct intel_engine_data *ed)
>  {
>  	uint8_t buff[SIZEOF_QUERY] = { };
>  	struct drm_i915_query_engine_info *query_engine =
> -			(struct drm_i915_query_engine_info *) buff;
> +		(struct drm_i915_query_engine_info *)buff;

Until here, nothing is related to the description in the commit
log. Can we put the above in a different patch?

> -struct intel_execution_engine2 *
> -intel_get_current_engine(struct intel_engine_data *ed)
> -{
> -	if (!ed->n)
> -		ed->current_engine = &ed->engines[0];
> -	else if (ed->n >= ed->nengines)
> -		ed->current_engine = NULL;
> -
> -	return ed->current_engine;
> -}
> -
> -void intel_next_engine(struct intel_engine_data *ed)
> -{
> -	if (ed->n + 1 < ed->nengines) {
> -		ed->n++;
> -		ed->current_engine = &ed->engines[ed->n];
> -	} else {
> -		ed->n = ed->nengines;
> -		ed->current_engine = NULL;
> -	}
> -}
> -
> -struct intel_execution_engine2 *
> -intel_get_current_physical_engine(struct intel_engine_data *ed)
> -{
> -	struct intel_execution_engine2 *e;
> -
> -	for (e = intel_get_current_engine(ed);
> -	     e && e->is_virtual;
> -	     intel_next_engine(ed))
> -		;
> -
> -	return e;
> -}
> -

Moving these functions to inline in the header file is unrelated
to the patch topic, right?

>  static int gem_topology_get_param(int fd,
>  				  struct drm_i915_gem_context_param *p)
>  {
> @@ -197,10 +161,9 @@ static int gem_topology_get_param(int fd,
>  		return 0;
>  
>  	/* size will store the engine count */
> -	p->size = (p->size - sizeof(struct i915_context_param_engines)) /
> -		  (offsetof(struct i915_context_param_engines,
> -			    engines[1]) -
> -		  sizeof(struct i915_context_param_engines));
> +	igt_assert(p->size >= sizeof(struct i915_context_param_engines));
> +	p->size -= sizeof(struct i915_context_param_engines);
> +	p->size /= sizeof(struct i915_engine_class_instance);

This is also unrelated.

>  struct intel_engine_data {
> -	uint32_t nengines;
> -	uint32_t n;
> -	struct intel_execution_engine2 *current_engine;

so we don't have anymore current_engine... I had the feeling the
Tvrtko really wanted it :)

> +	uint32_t nengines, cur;

[ some copy paste ]

> -	uint32_t nengines;
> -	uint32_t n;
> +	uint32_t nengines, cur;

mmhhh... why?

> +static inline struct intel_execution_engine2 *
> +intel_get_current_engine(struct intel_engine_data *ed)
> +{
> +	if (ed->cur >= ed->nengines)
> +		return NULL;
> +
> +	return &ed->engines[ed->cur];
> +}
> +
> +static inline struct intel_execution_engine2 *
> +intel_get_current_physical_engine(struct intel_engine_data *ed)
> +{
> +	struct intel_execution_engine2 *e;
> +
> +	for (; (e = intel_get_current_engine(ed)) && e->is_virtual; ed->cur++)
> +		;

The above two lines are the only ones related to the commit
message.  Can we keep this patch smaller? and put cosmetics in a
different patchset?

Thanks,
Andi
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2019-05-29 14:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29 13:24 [PATCH i-g-t] lib: Fix intel_get_current_physical_engine() iterator Chris Wilson
2019-05-29 14:33 ` Andi Shyti [this message]
2019-06-03 10:19 ` [igt-dev] " Tvrtko Ursulin
2019-06-03 10:32   ` Petri Latvala
2019-06-03 10:39     ` Tvrtko Ursulin
2019-06-03 11:19       ` Petri Latvala
2019-06-03 12:47         ` Tvrtko Ursulin

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=20190529143328.GD3552@intel.intel \
    --to=andi.shyti@intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox