lib: Cache DRM device id to reduce number of ioctls

The DRM device id for the igfx is fixed, since there can only be one in
the system. So once we query it for the first time we can safely report
that value on every subsequent request, cutting out a lot of noisy
ioctls from inside tests.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2015-02-18 15:58:06 +00:00
parent a22548fec0
commit eaa7e6183c
2 changed files with 15 additions and 18 deletions

View File

@ -73,6 +73,8 @@
* and [batchbuffer](intel-gpu-tools-intel-batchbuffer.html) libraries as dependencies. * and [batchbuffer](intel-gpu-tools-intel-batchbuffer.html) libraries as dependencies.
*/ */
uint16_t __drm_device_id;
static int is_i915_device(int fd) static int is_i915_device(int fd)
{ {
drm_version_t version; drm_version_t version;
@ -101,7 +103,11 @@ is_intel(int fd)
if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp))) if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp)))
return 0; return 0;
return IS_INTEL(devid); if (!IS_INTEL(devid))
return 0;
__drm_device_id = devid;
return 1;
} }
static void check_stop_rings(void) static void check_stop_rings(void)

View File

@ -112,6 +112,8 @@ intel_get_pci_device(void)
return pci_dev; return pci_dev;
} }
extern uint16_t __drm_device_id;
/** /**
* intel_get_drm_devid: * intel_get_drm_devid:
* @fd: open i915 drm file descriptor * @fd: open i915 drm file descriptor
@ -125,26 +127,15 @@ intel_get_pci_device(void)
uint32_t uint32_t
intel_get_drm_devid(int fd) intel_get_drm_devid(int fd)
{ {
uint32_t devid = 0;
const char *override; const char *override;
igt_assert(__drm_device_id);
override = getenv("INTEL_DEVID_OVERRIDE"); override = getenv("INTEL_DEVID_OVERRIDE");
if (override) { if (override)
devid = strtod(override, NULL); return strtod(override, NULL);
} else { else
struct drm_i915_getparam gp; return __drm_device_id;
int ret;
memset(&gp, 0, sizeof(gp));
gp.param = I915_PARAM_CHIPSET_ID;
gp.value = (int *)&devid;
ret = ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
igt_assert(ret == 0);
errno = 0;
}
return devid;
} }
/** /**