diff options
-rw-r--r-- | lib/igt_sysfs.c | 20 | ||||
-rw-r--r-- | lib/igt_sysfs.h | 2 | ||||
-rw-r--r-- | tests/gem_ctx_thrash.c | 20 | ||||
-rw-r--r-- | tests/gem_exec_nop.c | 16 | ||||
-rw-r--r-- | tests/gem_exec_whisper.c | 16 | ||||
-rw-r--r-- | tests/gem_read_read_speed.c | 39 | ||||
-rw-r--r-- | tests/gem_sync.c | 16 |
7 files changed, 51 insertions, 78 deletions
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c index 1cf7f710..633aeab0 100644 --- a/lib/igt_sysfs.c +++ b/lib/igt_sysfs.c @@ -218,3 +218,23 @@ out: close(fd); return buf; } + +bool igt_sysfs_get_boolean(int dir, const char *attr) +{ + char *str; + bool result; + + str = igt_sysfs_get(dir, attr); + result = str && atoi(str) > 0; + free(str); + + return result; +} + +bool igt_sysfs_set_boolean(int dir, const char *attr, bool value) +{ + char buf[8]; + + sprintf(buf, "%d", value); + return igt_sysfs_set(dir, attr, buf); +} diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h index 51c7910d..ce0501f1 100644 --- a/lib/igt_sysfs.h +++ b/lib/igt_sysfs.h @@ -31,5 +31,7 @@ int igt_sysfs_open(int device, int *idx); int igt_sysfs_open_parameters(int fd); bool igt_sysfs_set(int dir, const char *attr, const char *value); char *igt_sysfs_get(int dir, const char *attr); +bool igt_sysfs_get_boolean(int dir, const char *attr); +bool igt_sysfs_set_boolean(int dir, const char *attr, bool value); #endif /* __IGT_SYSFS_H__ */ diff --git a/tests/gem_ctx_thrash.c b/tests/gem_ctx_thrash.c index 9f20b694..8990312c 100644 --- a/tests/gem_ctx_thrash.c +++ b/tests/gem_ctx_thrash.c @@ -23,6 +23,7 @@ */ #include "igt.h" +#include "igt_sysfs.h" #include <stdio.h> #include <string.h> #include <errno.h> @@ -41,18 +42,17 @@ static void xchg_int(void *array, unsigned i, unsigned j) igt_swap(A[i], A[j]); } -static bool has_execlists(void) +static bool has_execlists(int fd) { - FILE *file; bool enabled = false; + int dir; - file = fopen("/sys/module/i915/parameters/enable_execlists", "r"); - if (file) { - int value; - if (fscanf(file, "%d", &value) == 1) - enabled = value != 0; - fclose(file); - } + dir = igt_sysfs_open_parameters(fd); + if (dir < 0) + return false; + + enabled = igt_sysfs_get_boolean(dir, "enable_execlists"); + close(dir); return enabled; } @@ -67,7 +67,7 @@ static unsigned get_num_contexts(int fd, int num_engines) ggtt_size = gem_global_aperture_size(fd); size = 64 << 10; /* Most gen require at least 64k for ctx */ - if (has_execlists()) { + if (has_execlists(fd)) { size *= 2; /* ringbuffer as well */ if (num_engines) /* one per engine with execlists */ size *= num_engines; diff --git a/tests/gem_exec_nop.c b/tests/gem_exec_nop.c index dc7f5143..9b892607 100644 --- a/tests/gem_exec_nop.c +++ b/tests/gem_exec_nop.c @@ -200,35 +200,25 @@ static void all(int fd, uint32_t handle, int timeout) static void print_welcome(int fd) { bool active; - char *str; int dir; dir = igt_sysfs_open_parameters(fd); if (dir < 0) return; - str = igt_sysfs_get(dir, "enable_guc_submission"); - active = str && atoi(str) > 0; - free(str); - + active = igt_sysfs_get_boolean(dir, "enable_guc_submission"); if (active) { igt_info("Using GuC submission\n"); goto out; } - str = igt_sysfs_get(dir, "enable_execlists"); - active = str && atoi(str) > 0; - free(str); - + active = igt_sysfs_get_boolean(dir, "enable_execlists"); if (active) { igt_info("Using Execlists submission\n"); goto out; } - str = igt_sysfs_get(dir, "semaphores"); - active = str && atoi(str) > 0; - free(str); - + active = igt_sysfs_get_boolean(dir, "semaphores"); igt_info("Using Legacy submission %s\n", active ? ", with semaphores" : ""); diff --git a/tests/gem_exec_whisper.c b/tests/gem_exec_whisper.c index eeaa21f1..cd7fd6bb 100644 --- a/tests/gem_exec_whisper.c +++ b/tests/gem_exec_whisper.c @@ -395,35 +395,25 @@ static void whisper(int fd, unsigned engine, unsigned flags) static void print_welcome(int fd) { bool active; - char *str; int dir; dir = igt_sysfs_open_parameters(fd); if (dir < 0) return; - str = igt_sysfs_get(dir, "enable_guc_submission"); - active = str && atoi(str) > 0; - free(str); - + active = igt_sysfs_get_boolean(dir, "enable_guc_submission"); if (active) { igt_info("Using GuC submission\n"); goto out; } - str = igt_sysfs_get(dir, "enable_execlists"); - active = str && atoi(str) > 0; - free(str); - + active = igt_sysfs_get_boolean(dir, "enable_execlists"); if (active) { igt_info("Using Execlists submission\n"); goto out; } - str = igt_sysfs_get(dir, "semaphores"); - active = str && atoi(str) > 0; - free(str); - + active = igt_sysfs_get_boolean(dir, "semaphores"); igt_info("Using Legacy submission %s\n", active ? ", with semaphores" : ""); diff --git a/tests/gem_read_read_speed.c b/tests/gem_read_read_speed.c index c01e4c25..0ac6f830 100644 --- a/tests/gem_read_read_speed.c +++ b/tests/gem_read_read_speed.c @@ -27,6 +27,7 @@ */ #include "igt.h" +#include "igt_sysfs.h" #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -48,39 +49,19 @@ igt_render_copyfunc_t rendercopy; struct intel_batchbuffer *batch; int width, height; -static int gem_param(int fd, int name) +static int semaphores_enabled(int fd) { - drm_i915_getparam_t gp; - int v = -1; /* No param uses the sign bit, reserve it for errors */ - - memset(&gp, 0, sizeof(gp)); - gp.param = name; - gp.value = &v; - if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp)) - return -1; + bool enabled = false; + int dir; - return v; -} + dir = igt_sysfs_open_parameters(fd); + if (dir < 0) + return false; -static int semaphores_enabled(int fd) -{ - FILE *file; - int detected = -1; - int ret; - - ret = gem_param(fd, 20); - if (ret != -1) - return ret > 0; - - file = fopen("/sys/module/i915/parameters/semaphores", "r"); - if (file) { - int value; - if (fscanf(file, "%d", &value) == 1) - detected = value; - fclose(file); - } + enabled = igt_sysfs_get_boolean(dir, "semaphores"); + close(dir); - return detected; + return enabled; } static drm_intel_bo *rcs_copy_bo(drm_intel_bo *dst, drm_intel_bo *src) diff --git a/tests/gem_sync.c b/tests/gem_sync.c index 44b2378c..2a80efc4 100644 --- a/tests/gem_sync.c +++ b/tests/gem_sync.c @@ -693,35 +693,25 @@ store_all(int fd, int num_children) static void print_welcome(int fd) { bool active; - char *str; int dir; dir = igt_sysfs_open_parameters(fd); if (dir < 0) return; - str = igt_sysfs_get(dir, "enable_guc_submission"); - active = str && atoi(str) > 0; - free(str); - + active = igt_sysfs_get_boolean(dir, "enable_guc_submission"); if (active) { igt_info("Using GuC submission\n"); goto out; } - str = igt_sysfs_get(dir, "enable_execlists"); - active = str && atoi(str) > 0; - free(str); - + active = igt_sysfs_get_boolean(dir, "enable_execlists"); if (active) { igt_info("Using Execlists submission\n"); goto out; } - str = igt_sysfs_get(dir, "semaphores"); - active = str && atoi(str) > 0; - free(str); - + active = igt_sysfs_get_boolean(dir, "semaphores"); igt_info("Using Legacy submission %s\n", active ? ", with semaphores" : ""); |