summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-03-21 17:16:03 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2017-03-21 17:36:02 +0000
commit83884e97e18739e3588c6467a210838099d42073 (patch)
tree778bab4b309c852d3649cc901952267d0cbb5992 /lib
parent25fbae15262cf570e207e62f50e7c5233e06bc67 (diff)
Restore "lib: Open debugfs files for the given DRM device"
This reverts commit 25fbae15262cf570e207e62f50e7c5233e06bc67, restoring commit 301ad44cdf1b868b1ab89096721da91fa8541fdc Author: Tomeu Vizoso <tomeu.vizoso@collabora.com> Date: Thu Mar 2 10:37:11 2017 +0100 lib: Open debugfs files for the given DRM device with fixes. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib')
-rw-r--r--lib/drmtest.c2
-rw-r--r--lib/igt_aux.c10
-rw-r--r--lib/igt_aux.h4
-rw-r--r--lib/igt_debugfs.c315
-rw-r--r--lib/igt_debugfs.h30
-rw-r--r--lib/igt_gt.c14
-rw-r--r--lib/igt_gt.h4
-rw-r--r--lib/igt_kms.c10
-rw-r--r--lib/igt_kms.h4
-rw-r--r--lib/intel_io.h2
-rw-r--r--lib/intel_mmio.c4
-rw-r--r--lib/intel_os.c9
12 files changed, 234 insertions, 174 deletions
diff --git a/lib/drmtest.c b/lib/drmtest.c
index 065ab119..35f71c0d 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -183,7 +183,7 @@ void gem_quiescent_gpu(int fd)
gem_sync(fd, obj.handle);
gem_close(fd, obj.handle);
- igt_drop_caches_set(DROP_RETIRE | DROP_FREED);
+ igt_drop_caches_set(fd, DROP_RETIRE | DROP_FREED);
}
/**
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 7ee279a3..1222806c 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -350,10 +350,10 @@ void igt_stop_signal_helper(void)
}
static struct igt_helper_process shrink_helper;
-static void __attribute__((noreturn)) shrink_helper_process(pid_t pid)
+static void __attribute__((noreturn)) shrink_helper_process(int fd, pid_t pid)
{
while (1) {
- igt_drop_caches_set(DROP_SHRINK_ALL);
+ igt_drop_caches_set(fd, DROP_SHRINK_ALL);
usleep(1000 * 1000 / 50);
if (kill(pid, 0)) /* Parent has died, so must we. */
exit(0);
@@ -370,12 +370,12 @@ static void __attribute__((noreturn)) shrink_helper_process(pid_t pid)
*
* This should only be used from an igt_fixture.
*/
-void igt_fork_shrink_helper(void)
+void igt_fork_shrink_helper(int drm_fd)
{
assert(!igt_only_list_subtests());
- igt_require(igt_drop_caches_has(DROP_SHRINK_ALL));
+ igt_require(igt_drop_caches_has(drm_fd, DROP_SHRINK_ALL));
igt_fork_helper(&shrink_helper)
- shrink_helper_process(getppid());
+ shrink_helper_process(drm_fd, getppid());
}
/**
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 13f6f156..e62858e6 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -51,7 +51,7 @@ extern int num_trash_bos;
void igt_fork_signal_helper(void);
void igt_stop_signal_helper(void);
-void igt_fork_shrink_helper(void);
+void igt_fork_shrink_helper(int fd);
void igt_stop_shrink_helper(void);
void igt_fork_hang_detector(int fd);
@@ -198,7 +198,7 @@ void igt_debug_manual_check(const char *var, const char *expected);
/* These are separate to allow easier testing when porting, see the comment at
* the bottom of intel_os.c. */
-void intel_purge_vm_caches(void);
+void intel_purge_vm_caches(int fd);
uint64_t intel_get_avail_ram_mb(void);
uint64_t intel_get_total_ram_mb(void);
uint64_t intel_get_total_swap_mb(void);
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 527e6858..77769e0b 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -131,39 +131,62 @@ const char *igt_debugfs_mount(void)
return "/sys/kernel/debug";
}
-static bool __igt_debugfs_init(igt_debugfs_t *debugfs)
+static int __igt_debugfs_dir(int device)
{
struct stat st;
- int n;
-
- strcpy(debugfs->root, igt_debugfs_mount());
- for (n = 0; n < 16; n++) {
- int len = sprintf(debugfs->dri_path, "%s/dri/%d", debugfs->root, n);
- sprintf(debugfs->dri_path + len, "/i915_error_state");
- if (stat(debugfs->dri_path, &st) == 0) {
- debugfs->dri_path[len] = '\0';
- return true;
- }
+ const char *debugfs_root;
+ char path[200];
+ int idx;
+
+ if (fstat(device, &st)) {
+ igt_debug("Couldn't stat FD for DRM device: %s\n", strerror(errno));
+ return -1;
}
- debugfs->dri_path[0] = '\0';
- return false;
-}
+ if (!S_ISCHR(st.st_mode)) {
+ igt_debug("FD for DRM device not a char device!\n");
+ return -1;
+ }
-static igt_debugfs_t *__igt_debugfs_singleton(void)
-{
- static igt_debugfs_t singleton;
- static bool init_done = false;
+ debugfs_root = igt_debugfs_mount();
- if (init_done)
- return &singleton;
+ idx = minor(st.st_rdev);
+ snprintf(path, sizeof(path), "%s/dri/%d/name", debugfs_root, idx);
+ if (stat(path, &st))
+ return -1;
- if (__igt_debugfs_init(&singleton)) {
- init_done = true;
- return &singleton;
- } else {
- return NULL;
+ if (idx >= 64) {
+ int file, name_len, cmp_len;
+ char name[100], cmp[100];
+
+ file = open(path, O_RDONLY);
+ if (file < 0)
+ return -1;
+
+ name_len = read(file, name, sizeof(name));
+ close(file);
+
+ for (idx = 0; idx < 16; idx++) {
+ snprintf(path, sizeof(path), "%s/dri/%d/name",
+ debugfs_root, idx);
+ file = open(path, O_RDONLY);
+ if (file < 0)
+ return -1;
+
+ cmp_len = read(file, cmp, sizeof(cmp));
+ close(file);
+
+ if (cmp_len == name_len && !memcmp(cmp, name, name_len))
+ break;
+ }
+
+ if (idx == 16)
+ return -1;
}
+
+ snprintf(path, sizeof(path), "%s/dri/%d", debugfs_root, idx);
+ igt_debug("Opening debugfs directory '%s'\n", path);
+ return open(path, O_RDONLY);
}
/**
@@ -177,16 +200,15 @@ static igt_debugfs_t *__igt_debugfs_singleton(void)
* Returns:
* The Unix file descriptor for the debugfs file or -1 if that didn't work out.
*/
-int igt_debugfs_open(const char *filename, int mode)
+int igt_debugfs_open(int device, const char *filename, int mode)
{
- char buf[1024];
- igt_debugfs_t *debugfs = __igt_debugfs_singleton();
+ int dir;
- if (!debugfs)
- return -1;
+ dir = __igt_debugfs_dir(device);
+ if (dir < 0)
+ return dir;
- sprintf(buf, "%s/%s", debugfs->dri_path, filename);
- return open(buf, mode);
+ return openat(dir, filename, mode);
}
/**
@@ -200,18 +222,17 @@ int igt_debugfs_open(const char *filename, int mode)
* Returns:
* The libc FILE pointer for the debugfs file or NULL if that didn't work out.
*/
-FILE *igt_debugfs_fopen(const char *filename,
+FILE *igt_debugfs_fopen(int device,
+ const char *filename,
const char *mode)
{
- char buf[1024];
-
- igt_debugfs_t *debugfs = __igt_debugfs_singleton();
+ int fd;
- if (!debugfs)
+ fd = igt_debugfs_open(device, filename, O_RDWR);
+ if (fd < 0)
return NULL;
- sprintf(buf, "%s/%s", debugfs->dri_path, filename);
- return fopen(buf, mode);
+ return fdopen(fd, mode);
}
/**
@@ -224,21 +245,17 @@ FILE *igt_debugfs_fopen(const char *filename,
* provided buffer, then closes the file. Users should make sure that the buffer
* provided is big enough to fit the whole file, plus one byte.
*/
-void __igt_debugfs_read(const char *filename, char *buf, int buf_size)
+void __igt_debugfs_read(int fd, const char *filename, char *buf, int buf_size)
{
- FILE *file;
- size_t n_read;
-
- file = igt_debugfs_fopen(filename, "r");
- igt_assert(file);
-
- n_read = fread(buf, 1, buf_size - 1, file);
- igt_assert(n_read > 0);
- igt_assert(feof(file));
-
- buf[n_read] = '\0';
+ int dir;
+ int len;
- igt_assert(fclose(file) == 0);
+ dir = __igt_debugfs_dir(fd);
+ len = igt_sysfs_read(dir, filename, buf, buf_size - 1);
+ if (len < 0)
+ len = 0;
+ buf[len] = '\0';
+ close(dir);
}
/**
@@ -250,14 +267,14 @@ void __igt_debugfs_read(const char *filename, char *buf, int buf_size)
*
* Returns: True if the @substring is found to occur in @filename
*/
-bool igt_debugfs_search(const char *filename, const char *substring)
+bool igt_debugfs_search(int fd, const char *filename, const char *substring)
{
FILE *file;
size_t n = 0;
char *line = NULL;
bool matched = false;
- file = igt_debugfs_fopen(filename, "r");
+ file = igt_debugfs_fopen(fd, filename, "r");
igt_assert(file);
while (getline(&line, &n, file) >= 0) {
@@ -322,6 +339,7 @@ char *igt_crc_to_string(igt_crc_t *crc)
#define LEGACY_LINE_LEN (6 * 8 + 5 + 1)
struct _igt_pipe_crc {
+ int fd;
int ctl_fd;
int crc_fd;
int flags;
@@ -370,7 +388,7 @@ static bool igt_pipe_crc_do_start(igt_pipe_crc_t *pipe_crc)
sprintf(buf, "crtc-%d/crc/data", pipe_crc->pipe);
err = 0;
- pipe_crc->crc_fd = igt_debugfs_open(buf, pipe_crc->flags);
+ pipe_crc->crc_fd = igt_debugfs_open(pipe_crc->fd, buf, pipe_crc->flags);
if (pipe_crc->crc_fd < 0)
err = -errno;
@@ -392,52 +410,85 @@ static void igt_pipe_crc_pipe_off(int fd, enum pipe pipe)
igt_assert_eq(write(fd, buf, strlen(buf)), strlen(buf));
}
-static void igt_pipe_crc_reset(void)
+static void igt_pipe_crc_reset(int drm_fd)
{
- igt_debugfs_t *debugfs = __igt_debugfs_singleton();
- int fd;
struct dirent *dirent;
- char buf[128];
const char *cmd = "none";
bool done = false;
DIR *dir;
+ int fdir;
+ int fd;
- dir = opendir(debugfs->dri_path);
- if (dir) {
- while ((dirent = readdir(dir))) {
- if (strcmp(dirent->d_name, "crtc-") != 0)
- continue;
+ fdir = __igt_debugfs_dir(drm_fd);
+ if (fdir < 0)
+ return;
- sprintf(buf, "%s/%s/crc/control", debugfs->dri_path,
- dirent->d_name);
- fd = open(buf, O_WRONLY);
- if (fd == -1)
- continue;
+ dir = fdopendir(fdir);
+ if (!dir) {
+ close(fdir);
+ return;
+ }
- igt_assert_eq(write(fd, cmd, strlen(cmd)), strlen(cmd));
- done = true;
+ while ((dirent = readdir(dir))) {
+ char buf[128];
+
+ if (strcmp(dirent->d_name, "crtc-") != 0)
+ continue;
+
+ sprintf(buf, "%s/crc/control", dirent->d_name);
+ fd = openat(fdir, buf, O_WRONLY);
+ if (fd < 0)
+ continue;
+
+ igt_assert_eq(write(fd, cmd, strlen(cmd)), strlen(cmd));
+ close(fd);
+
+ done = true;
+ }
+ closedir(dir);
+
+ if (!done) {
+ fd = openat(fdir, "i915_display_crtc_ctl", O_WRONLY);
+ if (fd != -1) {
+ igt_pipe_crc_pipe_off(fd, PIPE_A);
+ igt_pipe_crc_pipe_off(fd, PIPE_B);
+ igt_pipe_crc_pipe_off(fd, PIPE_C);
close(fd);
}
- closedir(dir);
}
- if (done)
+ close(fdir);
+}
+
+static void pipe_crc_exit_handler(int sig)
+{
+ struct dirent *dirent;
+ char buf[128];
+ DIR *dir;
+ int fd;
+
+ dir = opendir("/dev/dri");
+ if (!dir)
return;
- fd = igt_debugfs_open("i915_display_crc_ctl", O_WRONLY);
- if (fd != -1) {
- igt_pipe_crc_pipe_off(fd, PIPE_A);
- igt_pipe_crc_pipe_off(fd, PIPE_B);
- igt_pipe_crc_pipe_off(fd, PIPE_C);
+ /*
+ * Try to reset CRC capture for all DRM devices, this is only needed
+ * for the legacy CRC ABI and can be completely removed once the
+ * legacy codepaths are removed.
+ */
+ while ((dirent = readdir(dir))) {
+ if (strncmp(dirent->d_name, "card", 4) != 0)
+ continue;
+
+ sprintf(buf, "/dev/dri/%s", dirent->d_name);
+ fd = open(buf, O_WRONLY);
+
+ igt_pipe_crc_reset(fd);
close(fd);
}
-}
-
-static void pipe_crc_exit_handler(int sig)
-{
- igt_pipe_crc_reset();
+ closedir(dir);
}
/**
@@ -447,25 +498,32 @@ static void pipe_crc_exit_handler(int sig)
* kernel. Uses igt_skip to automatically skip the test/subtest if this isn't
* the case.
*/
-void igt_require_pipe_crc(void)
+void igt_require_pipe_crc(int fd)
{
const char *cmd = "pipe A none";
- FILE *ctl;
- size_t written;
- int ret;
+ int ctl, written;
- ctl = igt_debugfs_fopen("crtc-0/crc/control", "r+");
- if (!ctl) {
- ctl = igt_debugfs_fopen("i915_display_crc_ctl", "r+");
+ ctl = igt_debugfs_open(fd, "crtc-0/crc/control", O_RDONLY);
+ if (ctl < 0) {
+ ctl = igt_debugfs_open(fd, "i915_display_crc_ctl", O_WRONLY);
igt_require_f(ctl,
"No display_crc_ctl found, kernel too old\n");
- written = fwrite(cmd, 1, strlen(cmd), ctl);
- ret = fflush(ctl);
- igt_require_f((written == strlen(cmd) && ret == 0) || errno != ENODEV,
+
+ written = write(ctl, cmd, strlen(cmd));
+ igt_require_f(written < 0,
"CRCs not supported on this platform\n");
}
+ close(ctl);
+}
+
+static void igt_hpd_storm_exit_handler(int sig)
+{
+ int fd = drm_open_driver_master(DRIVER_INTEL);
- fclose(ctl);
+ /* Here we assume that only one i915 device will be ever present */
+ igt_hpd_storm_reset(fd);
+
+ close(fd);
}
/**
@@ -482,9 +540,9 @@ void igt_require_pipe_crc(void)
*
* See: https://01.org/linuxgraphics/gfx-docs/drm/gpu/i915.html#hotplug
*/
-void igt_hpd_storm_set_threshold(unsigned int threshold)
+void igt_hpd_storm_set_threshold(int drm_fd, unsigned int threshold)
{
- int fd = igt_debugfs_open("i915_hpd_storm_ctl", O_WRONLY);
+ int fd = igt_debugfs_open(drm_fd, "i915_hpd_storm_ctl", O_WRONLY);
char buf[16];
if (fd < 0)
@@ -495,7 +553,7 @@ void igt_hpd_storm_set_threshold(unsigned int threshold)
igt_assert_eq(write(fd, buf, strlen(buf)), strlen(buf));
close(fd);
- igt_install_exit_handler((igt_exit_handler_t)igt_hpd_storm_reset);
+ igt_install_exit_handler(igt_hpd_storm_exit_handler);
}
/**
@@ -511,9 +569,9 @@ void igt_hpd_storm_set_threshold(unsigned int threshold)
*
* See: https://01.org/linuxgraphics/gfx-docs/drm/gpu/i915.html#hotplug
*/
-void igt_hpd_storm_reset(void)
+void igt_hpd_storm_reset(int drm_fd)
{
- int fd = igt_debugfs_open("i915_hpd_storm_ctl", O_WRONLY);
+ int fd = igt_debugfs_open(drm_fd, "i915_hpd_storm_ctl", O_WRONLY);
const char *buf = "reset";
if (fd < 0)
@@ -538,9 +596,9 @@ void igt_hpd_storm_reset(void)
*
* Returns: Whether or not an HPD storm has been detected.
*/
-bool igt_hpd_storm_detected(void)
+bool igt_hpd_storm_detected(int drm_fd)
{
- int fd = igt_debugfs_open("i915_hpd_storm_ctl", O_RDONLY);
+ int fd = igt_debugfs_open(drm_fd, "i915_hpd_storm_ctl", O_RDONLY);
char *start_loc;
char buf[32] = {0}, detected_str[4];
bool ret;
@@ -571,16 +629,16 @@ bool igt_hpd_storm_detected(void)
*
* See: https://01.org/linuxgraphics/gfx-docs/drm/gpu/i915.html#hotplug
*/
-void igt_require_hpd_storm_ctl(void)
+void igt_require_hpd_storm_ctl(int drm_fd)
{
- int fd = igt_debugfs_open("i915_hpd_storm_ctl", O_RDONLY);
+ int fd = igt_debugfs_open(drm_fd, "i915_hpd_storm_ctl", O_RDONLY);
igt_require_f(fd > 0, "No i915_hpd_storm_ctl found in debugfs\n");
close(fd);
}
static igt_pipe_crc_t *
-pipe_crc_new(enum pipe pipe, enum intel_pipe_crc_source source, int flags)
+pipe_crc_new(int fd, enum pipe pipe, enum intel_pipe_crc_source source, int flags)
{
igt_pipe_crc_t *pipe_crc;
char buf[128];
@@ -590,9 +648,9 @@ pipe_crc_new(enum pipe pipe, enum intel_pipe_crc_source source, int flags)
pipe_crc = calloc(1, sizeof(struct _igt_pipe_crc));
sprintf(buf, "crtc-%d/crc/control", pipe);
- pipe_crc->ctl_fd = igt_debugfs_open(buf, O_WRONLY);
+ pipe_crc->ctl_fd = igt_debugfs_open(fd, buf, O_WRONLY);
if (pipe_crc->ctl_fd == -1) {
- pipe_crc->ctl_fd = igt_debugfs_open("i915_display_crc_ctl",
+ pipe_crc->ctl_fd = igt_debugfs_open(fd, "i915_display_crc_ctl",
O_WRONLY);
igt_assert(pipe_crc->ctl_fd != -1);
pipe_crc->is_legacy = true;
@@ -600,7 +658,7 @@ pipe_crc_new(enum pipe pipe, enum intel_pipe_crc_source source, int flags)
if (pipe_crc->is_legacy) {
sprintf(buf, "i915_pipe_%s_crc", kmstest_pipe_name(pipe));
- pipe_crc->crc_fd = igt_debugfs_open(buf, flags);
+ pipe_crc->crc_fd = igt_debugfs_open(fd, buf, flags);
igt_assert(pipe_crc->crc_fd != -1);
igt_debug("Using legacy frame CRC ABI\n");
} else {
@@ -608,6 +666,7 @@ pipe_crc_new(enum pipe pipe, enum intel_pipe_crc_source source, int flags)
igt_debug("Using generic frame CRC ABI\n");
}
+ pipe_crc->fd = fd;
pipe_crc->pipe = pipe;
pipe_crc->source = source;
pipe_crc->flags = flags;
@@ -628,9 +687,9 @@ pipe_crc_new(enum pipe pipe, enum intel_pipe_crc_source source, int flags)
* least INTEL_PIPE_CRC_SOURCE_AUTO everywhere.
*/
igt_pipe_crc_t *
-igt_pipe_crc_new(enum pipe pipe, enum intel_pipe_crc_source source)
+igt_pipe_crc_new(int fd, enum pipe pipe, enum intel_pipe_crc_source source)
{
- return pipe_crc_new(pipe, source, O_RDONLY);
+ return pipe_crc_new(fd, pipe, source, O_RDONLY);
}
/**
@@ -646,9 +705,9 @@ igt_pipe_crc_new(enum pipe pipe, enum intel_pipe_crc_source source)
* least INTEL_PIPE_CRC_SOURCE_AUTO everywhere.
*/
igt_pipe_crc_t *
-igt_pipe_crc_new_nonblock(enum pipe pipe, enum intel_pipe_crc_source source)
+igt_pipe_crc_new_nonblock(int fd, enum pipe pipe, enum intel_pipe_crc_source source)
{
- return pipe_crc_new(pipe, source, O_RDONLY | O_NONBLOCK);
+ return pipe_crc_new(fd, pipe, source, O_RDONLY | O_NONBLOCK);
}
/**
@@ -884,17 +943,15 @@ void igt_pipe_crc_collect_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc)
* This queries the debugfs to see if it supports the full set of desired
* operations.
*/
-bool igt_drop_caches_has(uint64_t val)
+bool igt_drop_caches_has(int drm_fd, uint64_t val)
{
- FILE *file;
uint64_t mask;
+ int dir;
mask = 0;
- file = igt_debugfs_fopen("i915_gem_drop_caches", "r");
- if (file) {
- igt_ignore_warn(fscanf(file, "0x%" PRIx64, &mask));
- fclose(file);
- }
+ dir = __igt_debugfs_dir(drm_fd);
+ igt_sysfs_scanf(dir, "i915_gem_drop_caches", "0x%" PRIx64, &mask);
+ close(dir);
return (val & mask) == val;
}
@@ -906,7 +963,7 @@ bool igt_drop_caches_has(uint64_t val)
* This calls the debugfs interface the drm/i915 GEM driver exposes to drop or
* evict certain classes of gem buffer objects.
*/
-void igt_drop_caches_set(uint64_t val)
+void igt_drop_caches_set(int drm_fd, uint64_t val)
{
int fd;
char data[19];
@@ -914,7 +971,7 @@ void igt_drop_caches_set(uint64_t val)
sprintf(data, "0x%" PRIx64, val);
- fd = igt_debugfs_open("i915_gem_drop_caches", O_WRONLY);
+ fd = igt_debugfs_open(drm_fd, "i915_gem_drop_caches", O_WRONLY);
igt_assert(fd >= 0);
do {
@@ -980,17 +1037,17 @@ void igt_enable_prefault(void)
igt_prefault_control(true);
}
-static int get_object_count(void)
+static int get_object_count(int fd)
{
- FILE *file;
- int ret, scanned;
+ int dir, ret, scanned;
- igt_drop_caches_set(DROP_RETIRE | DROP_ACTIVE | DROP_FREED);
+ igt_drop_caches_set(fd, DROP_RETIRE | DROP_ACTIVE | DROP_FREED);
- file = igt_debugfs_fopen("i915_gem_objects", "r");
-
- scanned = fscanf(file, "%i objects", &ret);
+ dir = __igt_debugfs_dir(fd);
+ scanned = igt_sysfs_scanf(dir, "i915_gem_objects",
+ "%i objects", &ret);
igt_assert_eq(scanned, 1);
+ close(dir);
return ret;
}
@@ -1007,7 +1064,7 @@ int igt_get_stable_obj_count(int driver)
{
int obj_count;
gem_quiescent_gpu(driver);
- obj_count = get_object_count();
+ obj_count = get_object_count(driver);
/* The test relies on the system being in the same state before and
* after the test so any difference in the object count is a result of
* leaks during the test. gem_quiescent_gpu() mostly achieves this but
@@ -1021,7 +1078,7 @@ int igt_get_stable_obj_count(int driver)
while (loop_count < 4) {
usleep(200000);
gem_quiescent_gpu(driver);
- obj_count = get_object_count();
+ obj_count = get_object_count(driver);
if (obj_count == prev_obj_count) {
loop_count++;
} else {
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index aa59f8a8..ff396564 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -33,11 +33,11 @@ enum pipe;
const char *igt_debugfs_mount(void);
-int igt_debugfs_open(const char *filename, int mode);
-FILE *igt_debugfs_fopen(const char *filename,
+int igt_debugfs_open(int fd, const char *filename, int mode);
+FILE *igt_debugfs_fopen(int fd, const char *filename,
const char *mode);
-void __igt_debugfs_read(const char *filename, char *buf, int buf_size);
-bool igt_debugfs_search(const char *filename, const char *substring);
+void __igt_debugfs_read(int fd, const char *filename, char *buf, int buf_size);
+bool igt_debugfs_search(int fd, const char *filename, const char *substring);
/**
* igt_debugfs_read:
@@ -47,8 +47,8 @@ bool igt_debugfs_search(const char *filename, const char *substring);
* This is just a convenience wrapper for __igt_debugfs_read. See its
* documentation.
*/
-#define igt_debugfs_read(filename, buf) \
- __igt_debugfs_read((filename), (buf), sizeof(buf))
+#define igt_debugfs_read(fd, filename, buf) \
+ __igt_debugfs_read(fd, (filename), (buf), sizeof(buf))
/*
* Pipe CRC
@@ -116,11 +116,11 @@ enum intel_pipe_crc_source {
void igt_assert_crc_equal(const igt_crc_t *a, const igt_crc_t *b);
char *igt_crc_to_string(igt_crc_t *crc);
-void igt_require_pipe_crc(void);
+void igt_require_pipe_crc(int fd);
igt_pipe_crc_t *
-igt_pipe_crc_new(enum pipe pipe, enum intel_pipe_crc_source source);
+igt_pipe_crc_new(int fd, enum pipe pipe, enum intel_pipe_crc_source source);
igt_pipe_crc_t *
-igt_pipe_crc_new_nonblock(enum pipe pipe, enum intel_pipe_crc_source source);
+igt_pipe_crc_new_nonblock(int fd, enum pipe pipe, enum intel_pipe_crc_source source);
void igt_pipe_crc_free(igt_pipe_crc_t *pipe_crc);
void igt_pipe_crc_start(igt_pipe_crc_t *pipe_crc);
void igt_pipe_crc_stop(igt_pipe_crc_t *pipe_crc);
@@ -129,10 +129,10 @@ int igt_pipe_crc_get_crcs(igt_pipe_crc_t *pipe_crc, int n_crcs,
igt_crc_t **out_crcs);
void igt_pipe_crc_collect_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out_crc);
-void igt_hpd_storm_set_threshold(unsigned int threshold);
-void igt_hpd_storm_reset(void);
-bool igt_hpd_storm_detected(void);
-void igt_require_hpd_storm_ctl(void);
+void igt_hpd_storm_set_threshold(int fd, unsigned int threshold);
+void igt_hpd_storm_reset(int fd);
+bool igt_hpd_storm_detected(int fd);
+void igt_require_hpd_storm_ctl(int fd);
/*
* Drop caches
@@ -188,8 +188,8 @@ void igt_require_hpd_storm_ctl(void);
DROP_ACTIVE | \
DROP_FREED)
-bool igt_drop_caches_has(uint64_t val);
-void igt_drop_caches_set(uint64_t val);
+bool igt_drop_caches_has(int fd, uint64_t val);
+void igt_drop_caches_set(int fd, uint64_t val);
/*
* Prefault control
diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index b8e08e9a..69218681 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -360,14 +360,14 @@ void igt_post_hang_ring(int fd, igt_hang_t arg)
* stuck, either because the test manually disabled gpu resets or because the
* test hit an hangcheck bug
*/
-void igt_force_gpu_reset(void)
+void igt_force_gpu_reset(int drm_fd)
{
FILE *file;
int fd, ret, wedged;
igt_debug("Triggering GPU reset\n");
- fd = igt_debugfs_open("i915_wedged", O_RDWR);
+ fd = igt_debugfs_open(drm_fd, "i915_wedged", O_RDWR);
igt_require(fd >= 0);
ret = write(fd, "-1\n", 3);
@@ -375,7 +375,7 @@ void igt_force_gpu_reset(void)
igt_assert_eq(ret, 3);
- file = igt_debugfs_fopen("i915_wedged", "r");
+ file = igt_debugfs_fopen(drm_fd, "i915_wedged", "r");
igt_assert(file);
wedged = 1;
@@ -451,11 +451,11 @@ void igt_stop_hang_helper(void)
* Returns:
* The file descriptor of the forcewake handle or -1 if that didn't work out.
*/
-int igt_open_forcewake_handle(void)
+int igt_open_forcewake_handle(int fd)
{
if (getenv("IGT_NO_FORCEWAKE"))
return -1;
- return igt_debugfs_open("i915_forcewake_user", O_WRONLY);
+ return igt_debugfs_open(fd, "i915_forcewake_user", O_WRONLY);
}
#if defined(__x86_64__) || defined(__i386__)
@@ -543,13 +543,13 @@ unsigned intel_detect_and_clear_missed_interrupts(int fd)
gem_quiescent_gpu(fd);
- file = igt_debugfs_fopen("i915_ring_missed_irq", "r");
+ file = igt_debugfs_fopen(fd, "i915_ring_missed_irq", "r");
if (file) {
igt_assert(fscanf(file, "%x", &missed) == 1);
fclose(file);
}
if (missed) {
- file = igt_debugfs_fopen("i915_ring_missed_irq", "w");
+ file = igt_debugfs_fopen(fd, "i915_ring_missed_irq", "w");
if (file) {
fwrite("0\n", 1, 2, file);
fclose(file);
diff --git a/lib/igt_gt.h b/lib/igt_gt.h
index e44b6db1..1ed833d2 100644
--- a/lib/igt_gt.h
+++ b/lib/igt_gt.h
@@ -51,12 +51,12 @@ igt_hang_t igt_hang_ctx(int fd,
igt_hang_t igt_hang_ring(int fd, int ring);
void igt_post_hang_ring(int fd, igt_hang_t arg);
-void igt_force_gpu_reset(void);
+void igt_force_gpu_reset(int fd);
void igt_fork_hang_helper(void);
void igt_stop_hang_helper(void);
-int igt_open_forcewake_handle(void);
+int igt_open_forcewake_handle(int fd);
int igt_setup_clflush(void);
void igt_clflush_range(void *addr, int size);
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index a986145e..d9f96725 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -747,7 +747,7 @@ void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
igt_assert_neq(asprintf(&path, "%s-%d/edid_override", kmstest_connector_type_str(connector->connector_type), connector->connector_type_id),
-1);
- debugfs_fd = igt_debugfs_open(path, O_WRONLY | O_TRUNC);
+ debugfs_fd = igt_debugfs_open(drm_fd, path, O_WRONLY | O_TRUNC);
free(path);
igt_assert(debugfs_fd != -1);
@@ -1324,7 +1324,7 @@ static void parse_crtc(char *info, struct kmstest_crtc *crtc)
igt_assert_eq(ret, 2);
}
-void kmstest_get_crtc(enum pipe pipe, struct kmstest_crtc *crtc)
+void kmstest_get_crtc(int fd, enum pipe pipe, struct kmstest_crtc *crtc)
{
char tmp[256];
FILE *fid;
@@ -1333,7 +1333,7 @@ void kmstest_get_crtc(enum pipe pipe, struct kmstest_crtc *crtc)
int line;
long int n;
- fid = igt_debugfs_fopen("i915_display_info", mode);
+ fid = igt_debugfs_fopen(fd, "i915_display_info", mode);
igt_skip_on(fid == NULL);
@@ -1370,13 +1370,13 @@ void kmstest_get_crtc(enum pipe pipe, struct kmstest_crtc *crtc)
igt_skip_on(ncrtc == 0);
}
-void igt_assert_plane_visible(enum pipe pipe, bool visibility)
+void igt_assert_plane_visible(int fd, enum pipe pipe, bool visibility)
{
struct kmstest_crtc crtc;
int i;
bool visible;
- kmstest_get_crtc(pipe, &crtc);
+ kmstest_get_crtc(fd, pipe, &crtc);
visible = true;
for (i = 0; i < crtc.n_planes; i++) {
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 862525d1..595832d0 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -215,8 +215,8 @@ uint32_t kmstest_dumb_create(int fd, int width, int height, int bpp,
void *kmstest_dumb_map_buffer(int fd, uint32_t handle, uint64_t size,
unsigned prot);
unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int flags);
-void kmstest_get_crtc(enum pipe pipe, struct kmstest_crtc *crtc);
-void igt_assert_plane_visible(enum pipe pipe, bool visibility);
+void kmstest_get_crtc(int fd, enum pipe pipe, struct kmstest_crtc *crtc);
+void igt_assert_plane_visible(int fd, enum pipe pipe, bool visibility);
/*
* A small modeset API
diff --git a/lib/intel_io.h b/lib/intel_io.h
index e2d6b470..6014c485 100644
--- a/lib/intel_io.h
+++ b/lib/intel_io.h
@@ -36,7 +36,7 @@ extern void *igt_global_mmio;
void intel_mmio_use_pci_bar(struct pci_device *pci_dev);
void intel_mmio_use_dump_file(char *file);
-int intel_register_access_init(struct pci_device *pci_dev, int safe);
+int intel_register_access_init(struct pci_device *pci_dev, int safe, int fd);
void intel_register_access_fini(void);
uint32_t intel_register_read(uint32_t reg);
void intel_register_write(uint32_t reg, uint32_t val);
diff --git a/lib/intel_mmio.c b/lib/intel_mmio.c
index 4981daf9..07b9ed14 100644
--- a/lib/intel_mmio.c
+++ b/lib/intel_mmio.c
@@ -165,7 +165,7 @@ release_forcewake_lock(int fd)
* @pci_dev can be obtained from intel_get_pci_device().
*/
int
-intel_register_access_init(struct pci_device *pci_dev, int safe)
+intel_register_access_init(struct pci_device *pci_dev, int safe, int fd)
{
int ret;
@@ -187,7 +187,7 @@ intel_register_access_init(struct pci_device *pci_dev, int safe)
/* Find where the forcewake lock is. Forcewake doesn't exist
* gen < 6, but the debugfs should do the right things for us.
*/
- ret = igt_open_forcewake_handle();
+ ret = igt_open_forcewake_handle(fd);
if (ret == -1)
mmio_data.key = FAKEKEY;
else
diff --git a/lib/intel_os.c b/lib/intel_os.c
index 924ac7e7..e5dea6e5 100644
--- a/lib/intel_os.c
+++ b/lib/intel_os.c
@@ -97,8 +97,11 @@ intel_get_avail_ram_mb(void)
#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM /* Linux */
struct sysinfo sysinf;
+ int fd;
- intel_purge_vm_caches();
+ fd = drm_open_driver(DRIVER_INTEL);
+ intel_purge_vm_caches(fd);
+ close(fd);
igt_assert(sysinfo(&sysinf) == 0);
retval = sysinf.freeram;
@@ -292,11 +295,11 @@ void intel_require_memory(uint64_t count, uint64_t size, unsigned mode)
igt_skip_on_simulation();
}
-void intel_purge_vm_caches(void)
+void intel_purge_vm_caches(int drm_fd)
{
int fd;
- igt_drop_caches_set(DROP_SHRINK_ALL);
+ igt_drop_caches_set(drm_fd, DROP_SHRINK_ALL);
fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
if (fd >= 0) {