summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2016-04-20 18:35:37 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2016-04-20 18:48:23 +0100
commitf650aa2dd640a4a8941bae90fbd85c83da5fbb1c (patch)
treec05ea286d28ab1620afff991369b3110130a8f8a
parented6fb66a50b35efc7e879deb23742d3da31b81be (diff)
igt/gem_close_race: Batify
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--lib/igt_aux.h3
-rw-r--r--tests/gem_close_race.c102
-rw-r--r--tests/gem_shrink.c3
3 files changed, 61 insertions, 47 deletions
diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index cdaed297..f66de721 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -51,6 +51,9 @@ bool igt_sigiter_continue(struct igt_sigiter *iter, bool interrupt);
#define igt_interruptible(E) \
for (struct igt_sigiter iter__={}; igt_sigiter_continue(&iter__, (E)); )
+#define igt_timeout(T) \
+ for (struct timespec t__={}; igt_seconds_elapsed(&t__) < (T); )
+
void igt_exchange_int(void *array, unsigned i, unsigned j);
void igt_permute_array(void *array, unsigned size,
void (*exchange_func)(void *array,
diff --git a/tests/gem_close_race.c b/tests/gem_close_race.c
index 4d2b3966..158e0ae0 100644
--- a/tests/gem_close_race.c
+++ b/tests/gem_close_race.c
@@ -132,7 +132,7 @@ static uint32_t load(int fd)
return handle;
}
-static void run(int child)
+static void process(int child)
{
uint32_t handle;
int fd;
@@ -145,13 +145,12 @@ static void run(int child)
gem_read(fd, handle, 0, &handle, sizeof(handle));
}
-#define NUM_FD 768
-
struct thread {
pthread_mutex_t mutex;
int device;
- int fds[NUM_FD];
int done;
+ int nfd;
+ int fds[0];
};
static void *thread_run(void *_data)
@@ -164,7 +163,7 @@ static void *thread_run(void *_data)
while (!t->done) {
pthread_mutex_unlock(&t->mutex);
- for (int n = 0; n < NUM_FD; n++) {
+ for (int n = 0; n < t->nfd; n++) {
int fd = t->fds[n];
arg.handle = 0;
@@ -194,7 +193,7 @@ static void *thread_busy(void *_data)
pthread_mutex_lock(&t->mutex);
while (!t->done) {
struct drm_i915_gem_busy busy;
- int fd = t->fds[rand() % NUM_FD];
+ int fd = t->fds[rand() % t->nfd];
pthread_mutex_unlock(&t->mutex);
@@ -220,6 +219,47 @@ static void *thread_busy(void *_data)
return 0;
}
+static void threads(int nfd, int timeout)
+{
+ pthread_t thread[2];
+ struct thread *data = calloc(1, sizeof(struct thread));
+ int n;
+
+ data = calloc(1, sizeof(struct thread) + sizeof(int)*nfd);
+ igt_assert(data);
+
+ pthread_mutex_init(&data->mutex, NULL);
+ data->device = open(device, O_RDWR);
+ for (n = 0; n < nfd; n++)
+ data->fds[n] = open(device, O_RDWR);
+ data->nfd = nfd;
+
+ pthread_create(&thread[0], NULL, thread_run, data);
+ pthread_create(&thread[1], NULL, thread_busy, data);
+
+ igt_timeout(timeout) {
+ int i = rand() % nfd;
+ if (data->fds[i] == -1) {
+ data->fds[i] = open(device, O_RDWR);
+ } else{
+ close(data->fds[i]);
+ data->fds[i] = -1;
+ }
+ }
+
+ pthread_mutex_lock(&data->mutex);
+ data->done = 1;
+ pthread_mutex_unlock(&data->mutex);
+
+ pthread_join(thread[1], NULL);
+ pthread_join(thread[0], NULL);
+
+ for (n = 0; n < nfd; n++)
+ close(data->fds[n]);
+ close(data->device);
+ free(data);
+}
+
igt_main
{
igt_skip_on_simulation();
@@ -236,47 +276,21 @@ igt_main
close(fd);
}
- igt_subtest("process-exit") {
- igt_fork(child, NUM_FD)
- run(child);
+ igt_subtest("basic-process") {
+ igt_fork(child, 1)
+ process(child);
igt_waitchildren();
}
- igt_subtest("gem-close-race") {
- pthread_t thread[2];
- struct thread *data = calloc(1, sizeof(struct thread));
- int n;
-
- igt_assert(data);
-
- pthread_mutex_init(&data->mutex, NULL);
- data->device = open(device, O_RDWR);
- for (n = 0; n < NUM_FD; n++)
- data->fds[n] = open(device, O_RDWR);
-
- pthread_create(&thread[0], NULL, thread_run, data);
- pthread_create(&thread[1], NULL, thread_busy, data);
-
- for (n = 0; n < 1000*NUM_FD; n++) {
- int i = rand() % NUM_FD;
- if (data->fds[i] == -1) {
- data->fds[i] = open(device, O_RDWR);
- } else{
- close(data->fds[i]);
- data->fds[i] = -1;
- }
- }
-
- pthread_mutex_lock(&data->mutex);
- data->done = 1;
- pthread_mutex_unlock(&data->mutex);
+ igt_subtest("basic-threads")
+ threads(sysconf(_SC_NPROCESSORS_ONLN), 10);
- pthread_join(thread[1], NULL);
- pthread_join(thread[0], NULL);
-
- for (n = 0; n < NUM_FD; n++)
- close(data->fds[n]);
- close(data->device);
- free(data);
+ igt_subtest("process-exit") {
+ igt_fork(child, 768)
+ process(child);
+ igt_waitchildren();
}
+
+ igt_subtest("gem-close-race")
+ threads(2*sysconf(_SC_NPROCESSORS_ONLN), 120);
}
diff --git a/tests/gem_shrink.c b/tests/gem_shrink.c
index 468fcf88..eeba89ed 100644
--- a/tests/gem_shrink.c
+++ b/tests/gem_shrink.c
@@ -30,9 +30,6 @@
#include "igt.h"
#include "igt_gt.h"
-#define igt_timeout(T) \
- for (struct timespec t__={}; igt_seconds_elapsed(&t__) < (T); )
-
#ifndef MADV_FREE
#define MADV_FREE 8
#endif