mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-09 00:46:17 +00:00
igt/gem_close_race: Batify
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
parent
ed6fb66a50
commit
f650aa2dd6
@ -51,6 +51,9 @@ bool igt_sigiter_continue(struct igt_sigiter *iter, bool interrupt);
|
|||||||
#define igt_interruptible(E) \
|
#define igt_interruptible(E) \
|
||||||
for (struct igt_sigiter iter__={}; igt_sigiter_continue(&iter__, (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_exchange_int(void *array, unsigned i, unsigned j);
|
||||||
void igt_permute_array(void *array, unsigned size,
|
void igt_permute_array(void *array, unsigned size,
|
||||||
void (*exchange_func)(void *array,
|
void (*exchange_func)(void *array,
|
||||||
|
@ -132,7 +132,7 @@ static uint32_t load(int fd)
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void run(int child)
|
static void process(int child)
|
||||||
{
|
{
|
||||||
uint32_t handle;
|
uint32_t handle;
|
||||||
int fd;
|
int fd;
|
||||||
@ -145,13 +145,12 @@ static void run(int child)
|
|||||||
gem_read(fd, handle, 0, &handle, sizeof(handle));
|
gem_read(fd, handle, 0, &handle, sizeof(handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NUM_FD 768
|
|
||||||
|
|
||||||
struct thread {
|
struct thread {
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
int device;
|
int device;
|
||||||
int fds[NUM_FD];
|
|
||||||
int done;
|
int done;
|
||||||
|
int nfd;
|
||||||
|
int fds[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
static void *thread_run(void *_data)
|
static void *thread_run(void *_data)
|
||||||
@ -164,7 +163,7 @@ static void *thread_run(void *_data)
|
|||||||
while (!t->done) {
|
while (!t->done) {
|
||||||
pthread_mutex_unlock(&t->mutex);
|
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];
|
int fd = t->fds[n];
|
||||||
|
|
||||||
arg.handle = 0;
|
arg.handle = 0;
|
||||||
@ -194,7 +193,7 @@ static void *thread_busy(void *_data)
|
|||||||
pthread_mutex_lock(&t->mutex);
|
pthread_mutex_lock(&t->mutex);
|
||||||
while (!t->done) {
|
while (!t->done) {
|
||||||
struct drm_i915_gem_busy busy;
|
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);
|
pthread_mutex_unlock(&t->mutex);
|
||||||
|
|
||||||
@ -220,6 +219,47 @@ static void *thread_busy(void *_data)
|
|||||||
return 0;
|
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_main
|
||||||
{
|
{
|
||||||
igt_skip_on_simulation();
|
igt_skip_on_simulation();
|
||||||
@ -236,47 +276,21 @@ igt_main
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
igt_subtest("process-exit") {
|
igt_subtest("basic-process") {
|
||||||
igt_fork(child, NUM_FD)
|
igt_fork(child, 1)
|
||||||
run(child);
|
process(child);
|
||||||
igt_waitchildren();
|
igt_waitchildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
igt_subtest("gem-close-race") {
|
igt_subtest("basic-threads")
|
||||||
pthread_t thread[2];
|
threads(sysconf(_SC_NPROCESSORS_ONLN), 10);
|
||||||
struct thread *data = calloc(1, sizeof(struct thread));
|
|
||||||
int n;
|
|
||||||
|
|
||||||
igt_assert(data);
|
igt_subtest("process-exit") {
|
||||||
|
igt_fork(child, 768)
|
||||||
pthread_mutex_init(&data->mutex, NULL);
|
process(child);
|
||||||
data->device = open(device, O_RDWR);
|
igt_waitchildren();
|
||||||
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);
|
igt_subtest("gem-close-race")
|
||||||
data->done = 1;
|
threads(2*sysconf(_SC_NPROCESSORS_ONLN), 120);
|
||||||
pthread_mutex_unlock(&data->mutex);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,6 @@
|
|||||||
#include "igt.h"
|
#include "igt.h"
|
||||||
#include "igt_gt.h"
|
#include "igt_gt.h"
|
||||||
|
|
||||||
#define igt_timeout(T) \
|
|
||||||
for (struct timespec t__={}; igt_seconds_elapsed(&t__) < (T); )
|
|
||||||
|
|
||||||
#ifndef MADV_FREE
|
#ifndef MADV_FREE
|
||||||
#define MADV_FREE 8
|
#define MADV_FREE 8
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user