igt-dev.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>
Cc: igt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t] lib: Stop caching __drm_device_id
Date: Fri, 31 Aug 2018 07:20:13 -0700	[thread overview]
Message-ID: <20180831142013.GG2219@intel.com> (raw)
In-Reply-To: <20180831121853.18786-1-chris@chris-wilson.co.uk>

On Fri, Aug 31, 2018 at 01:18:53PM +0100, Chris Wilson wrote:
> In a multi-device system there is no guarantee that the fd being probed
> in intel_get_drm_devid() is the same as was opened earlier. Any cache
> may outlive the fd, so is frought with lifetime issues. The primary
> reason for caching the devid was to avoid extra ioctls in the
> dmesg/strace, but hopefully all users now grab the id in their fixture
> and not inside every function.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Katarzyna Dec <katarzyna.dec@intel.com>

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

> ---
>  lib/drmtest.c       |  3 ---
>  lib/intel_chipset.c | 14 +++++++++-----
>  2 files changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/drmtest.c b/lib/drmtest.c
> index fae6f86f2..ecb535f5d 100644
> --- a/lib/drmtest.c
> +++ b/lib/drmtest.c
> @@ -75,8 +75,6 @@
>   * and [batchbuffer](igt-gpu-tools-intel-batchbuffer.html) libraries as dependencies.
>   */
>  
> -uint16_t __drm_device_id;
> -
>  static int __get_drm_device_name(int fd, char *name)
>  {
>  	drm_version_t version;
> @@ -142,7 +140,6 @@ static bool has_known_intel_chipset(int fd)
>  	if (!intel_gen(devid))
>  		return false;
>  
> -	__drm_device_id = devid;
>  	return true;
>  }
>  
> diff --git a/lib/intel_chipset.c b/lib/intel_chipset.c
> index ab35fa70c..4748a3fb8 100644
> --- a/lib/intel_chipset.c
> +++ b/lib/intel_chipset.c
> @@ -112,8 +112,6 @@ intel_get_pci_device(void)
>  	return pci_dev;
>  }
>  
> -extern uint16_t __drm_device_id;
> -
>  /**
>   * intel_get_drm_devid:
>   * @fd: open i915 drm file descriptor
> @@ -127,16 +125,22 @@ extern uint16_t __drm_device_id;
>  uint32_t
>  intel_get_drm_devid(int fd)
>  {
> +	struct drm_i915_getparam gp;
>  	const char *override;
> +	int devid = 0;
>  
>  	igt_assert(is_i915_device(fd));
> -	igt_assert(__drm_device_id);
>  
>  	override = getenv("INTEL_DEVID_OVERRIDE");
>  	if (override)
>  		return strtol(override, NULL, 0);
> -	else
> -		return __drm_device_id;
> +
> +	memset(&gp, 0, sizeof(gp));
> +	gp.param = I915_PARAM_CHIPSET_ID;
> +	gp.value = &devid;
> +	ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
> +
> +	return devid;
>  }
>  
>  /**
> -- 
> 2.19.0.rc1
> 
> _______________________________________________
> igt-dev mailing list
> igt-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/igt-dev
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2018-08-31 14:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-31 12:18 [igt-dev] [PATCH i-g-t] lib: Stop caching __drm_device_id Chris Wilson
2018-08-31 12:42 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2018-08-31 13:10 ` [igt-dev] [PATCH i-g-t] " Katarzyna Dec
2018-08-31 13:25   ` Chris Wilson
2018-08-31 14:20 ` Rodrigo Vivi [this message]
2018-08-31 16:58 ` [igt-dev] ✗ Fi.CI.IGT: 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=20180831142013.GG2219@intel.com \
    --to=rodrigo.vivi@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;
as well as URLs for NNTP newsgroup(s).