summaryrefslogtreecommitdiff
path: root/benchmarks/gem_exec_tracer.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-03-28 15:11:26 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2017-03-28 15:13:11 +0100
commitf6256cd5f04b8e30233a4601d40c20de5e0db75f (patch)
tree4a07138c9796f18d9c812bc5641e9a0112b012ed /benchmarks/gem_exec_tracer.c
parent4bf3ca8422e2153b208b0cba791b8a45c64ac9d9 (diff)
benchmarks/gem_exec_trace: Make the tracer threadsafe
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'benchmarks/gem_exec_tracer.c')
-rw-r--r--benchmarks/gem_exec_tracer.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/benchmarks/gem_exec_tracer.c b/benchmarks/gem_exec_tracer.c
index 4316e218..d9589853 100644
--- a/benchmarks/gem_exec_tracer.c
+++ b/benchmarks/gem_exec_tracer.c
@@ -38,6 +38,7 @@
#include <sys/mman.h>
#include <dlfcn.h>
#include <i915_drm.h>
+#include <pthread.h>
#include "intel_aub.h"
#include "intel_chipset.h"
@@ -45,6 +46,8 @@
static int (*libc_close)(int fd);
static int (*libc_ioctl)(int fd, unsigned long request, void *argp);
+static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+
struct trace {
int fd;
FILE *file;
@@ -146,6 +149,7 @@ trace_exec(struct trace *trace,
fail_if(execbuffer2->flags & (I915_EXEC_FENCE_IN | I915_EXEC_FENCE_OUT),
"fences not supported yet\n");
+ flockfile(trace->file);
{
struct trace_exec t = {
EXEC,
@@ -177,6 +181,7 @@ trace_exec(struct trace *trace,
}
fflush(trace->file);
+ funlockfile(trace->file);
#undef to_ptr
}
@@ -220,6 +225,7 @@ close(int fd)
{
struct trace *t, **p;
+ pthread_mutex_lock(&mutex);
for (p = &traces; (t = *p); p = &t->next) {
if (t->fd == fd) {
*p = t->next;
@@ -228,6 +234,7 @@ close(int fd)
break;
}
}
+ pthread_mutex_unlock(&mutex);
return libc_close(fd);
}
@@ -276,6 +283,7 @@ ioctl(int fd, unsigned long request, ...)
if (_IOC_TYPE(request) != DRM_IOCTL_BASE)
goto untraced;
+ pthread_mutex_lock(&mutex);
for (p = &traces; (t = *p); p = &t->next) {
if (fd == t->fd) {
if (traces != t) {
@@ -289,18 +297,23 @@ ioctl(int fd, unsigned long request, ...)
if (!t) {
char filename[80];
- if (!is_i915(fd))
+ if (!is_i915(fd)) {
+ pthread_mutex_unlock(&mutex);
goto untraced;
+ }
t = malloc(sizeof(*t));
- if (!t)
+ if (!t) {
+ pthread_mutex_unlock(&mutex);
return -ENOMEM;
+ }
sprintf(filename, "/tmp/trace-%d.%d", getpid(), fd);
t->file = fopen(filename, "w+");
t->fd = fd;
if (!fwrite(&version, sizeof(version), 1, t->file)) {
+ pthread_mutex_unlock(&mutex);
fclose(t->file);
free(t);
return -ENOMEM;
@@ -309,6 +322,7 @@ ioctl(int fd, unsigned long request, ...)
t->next = traces;
traces = t;
}
+ pthread_mutex_unlock(&mutex);
switch (request) {
case DRM_IOCTL_I915_GEM_EXECBUFFER2: