lib: Cache static queries

We frequently check for device capabilities, for which we can safely
assume that there is but one on a system and so cache the first query
value and return it for all future queries. The benefit is to reduce
dmesg debug spam which helps when either bringing up a test or trying to
track down why a test fails.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2015-04-13 19:04:13 +01:00
parent 10f903aa23
commit fb950bc17f
3 changed files with 89 additions and 44 deletions

View File

@ -59,7 +59,7 @@
*/ */
void igt_require_hang_ring(int fd, int ring) void igt_require_hang_ring(int fd, int ring)
{ {
gem_context_require_param(fd, LOCAL_CONTEXT_PARAM_BAN_PERIOD); gem_context_require_ban_period(fd);
igt_require(intel_gen(intel_get_drm_devid(fd)) >= 5); igt_require(intel_gen(intel_get_drm_devid(fd)) >= 5);
} }

View File

@ -724,6 +724,24 @@ void gem_context_require_param(int fd, uint64_t param)
igt_require(drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0); igt_require(drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0);
} }
void gem_context_require_ban_period(int fd)
{
static int has_ban_period = -1;
if (has_ban_period < 0) {
struct local_i915_gem_context_param p;
p.context = 0;
p.param = LOCAL_CONTEXT_PARAM_BAN_PERIOD;
p.value = 0;
p.size = 0;
has_ban_period = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0;
}
igt_require(has_ban_period);
}
/** /**
* gem_sw_finish: * gem_sw_finish:
* @fd: open i915 drm file descriptor * @fd: open i915 drm file descriptor
@ -807,34 +825,40 @@ bool gem_uses_aliasing_ppgtt(int fd)
*/ */
int gem_available_fences(int fd) int gem_available_fences(int fd)
{ {
struct drm_i915_getparam gp; static int num_fences = -1;
int val = 0;
memset(&gp, 0, sizeof(gp)); if (num_fences < 0) {
gp.param = I915_PARAM_NUM_FENCES_AVAIL; struct drm_i915_getparam gp;
gp.value = &val;
if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp))) memset(&gp, 0, sizeof(gp));
return 0; gp.param = I915_PARAM_NUM_FENCES_AVAIL;
gp.value = &num_fences;
errno = 0; num_fences = 0;
return val; ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
errno = 0;
}
return num_fences;
} }
bool gem_has_llc(int fd) bool gem_has_llc(int fd)
{ {
struct drm_i915_getparam gp; static int has_llc = -1;
int val = 0;
memset(&gp, 0, sizeof(gp)); if (has_llc < 0) {
gp.param = I915_PARAM_HAS_LLC; struct drm_i915_getparam gp;
gp.value = &val;
if (ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp))) memset(&gp, 0, sizeof(gp));
return 0; gp.param = I915_PARAM_HAS_LLC;
gp.value = &has_llc;
errno = 0; has_llc = 0;
return val; ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
errno = 0;
}
return has_llc;
} }
/** /**
@ -851,24 +875,26 @@ bool gem_has_llc(int fd)
*/ */
int gem_get_num_rings(int fd) int gem_get_num_rings(int fd)
{ {
int num_rings = 1; /* render ring is always available */ static int num_rings = -1;
if (gem_has_bsd(fd)) if (num_rings < 0) {
num_rings++; num_rings = 1; /* render ring is always available */
else
goto skip;
if (gem_has_blt(fd)) if (gem_has_bsd(fd))
num_rings++; num_rings++;
else else
goto skip; goto skip;
if (gem_has_vebox(fd))
num_rings++;
else
goto skip;
if (gem_has_blt(fd))
num_rings++;
else
goto skip;
if (gem_has_vebox(fd))
num_rings++;
else
goto skip;
}
skip: skip:
return num_rings; return num_rings;
} }
@ -911,7 +937,10 @@ bool gem_has_enable_ring(int fd,int param)
*/ */
bool gem_has_bsd(int fd) bool gem_has_bsd(int fd)
{ {
return gem_has_enable_ring(fd,I915_PARAM_HAS_BSD); static int has_bsd = -1;
if (has_bsd < 0)
has_bsd = gem_has_enable_ring(fd,I915_PARAM_HAS_BSD);
return has_bsd;
} }
/** /**
@ -927,7 +956,10 @@ bool gem_has_bsd(int fd)
*/ */
bool gem_has_blt(int fd) bool gem_has_blt(int fd)
{ {
return gem_has_enable_ring(fd,I915_PARAM_HAS_BLT); static int has_blt = -1;
if (has_blt < 0)
has_blt = gem_has_enable_ring(fd,I915_PARAM_HAS_BLT);
return has_blt;
} }
#define LOCAL_I915_PARAM_HAS_VEBOX 22 #define LOCAL_I915_PARAM_HAS_VEBOX 22
@ -945,7 +977,10 @@ bool gem_has_blt(int fd)
*/ */
bool gem_has_vebox(int fd) bool gem_has_vebox(int fd)
{ {
return gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_VEBOX); static int has_vebox = -1;
if (has_vebox < 0)
has_vebox = gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_VEBOX);
return has_vebox;
} }
#define LOCAL_I915_PARAM_HAS_BSD2 31 #define LOCAL_I915_PARAM_HAS_BSD2 31
@ -962,7 +997,10 @@ bool gem_has_vebox(int fd)
*/ */
bool gem_has_bsd2(int fd) bool gem_has_bsd2(int fd)
{ {
return gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_BSD2); static int has_bsd2 = -1;
if (has_bsd2 < 0)
has_bsd2 = gem_has_enable_ring(fd,LOCAL_I915_PARAM_HAS_BSD2);
return has_bsd2;
} }
/** /**
* gem_available_aperture_size: * gem_available_aperture_size:
@ -994,13 +1032,19 @@ uint64_t gem_available_aperture_size(int fd)
*/ */
uint64_t gem_aperture_size(int fd) uint64_t gem_aperture_size(int fd)
{ {
struct drm_i915_gem_get_aperture aperture; static uint64_t aperture_size = 0;
memset(&aperture, 0, sizeof(aperture)); if (aperture_size == 0) {
aperture.aper_size = 256*1024*1024; struct drm_i915_gem_get_aperture aperture;
do_ioctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture);
return aperture.aper_size; memset(&aperture, 0, sizeof(aperture));
aperture.aper_size = 256*1024*1024;
do_ioctl(fd, DRM_IOCTL_I915_GEM_GET_APERTURE, &aperture);
aperture_size = aperture.aper_size;
}
return aperture_size;
} }
/** /**
@ -1063,10 +1107,10 @@ void gem_require_ring(int fd, int ring_id)
case I915_EXEC_RENDER: case I915_EXEC_RENDER:
return; return;
case I915_EXEC_BLT: case I915_EXEC_BLT:
igt_require(HAS_BLT_RING(intel_get_drm_devid(fd))); igt_require(gem_has_blt(fd));
return; return;
case I915_EXEC_BSD: case I915_EXEC_BSD:
igt_require(HAS_BSD_RING(intel_get_drm_devid(fd))); igt_require(gem_has_bsd(fd));
return; return;
#ifdef I915_EXEC_VEBOX #ifdef I915_EXEC_VEBOX
case I915_EXEC_VEBOX: case I915_EXEC_VEBOX:

View File

@ -104,6 +104,7 @@ struct local_i915_gem_context_param {
#define LOCAL_CONTEXT_PARAM_BAN_PERIOD 0x1 #define LOCAL_CONTEXT_PARAM_BAN_PERIOD 0x1
uint64_t value; uint64_t value;
}; };
void gem_context_require_ban_period(int fd);
void gem_context_require_param(int fd, uint64_t param); void gem_context_require_param(int fd, uint64_t param);
void gem_context_get_param(int fd, struct local_i915_gem_context_param *p); void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
void gem_context_set_param(int fd, struct local_i915_gem_context_param *p); void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);