Add gettid() for proper thread affinity on Linux
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
diff --git a/fio.c b/fio.c
index a8608f4..2855ddf 100644
--- a/fio.c
+++ b/fio.c
@@ -1045,10 +1045,11 @@
pthread_condattr_t attr;
int clear_state;
- if (!td->o.use_thread)
+ if (!td->o.use_thread) {
setsid();
-
- td->pid = getpid();
+ td->pid = getpid();
+ } else
+ td->pid = gettid();
dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
diff --git a/os/os-linux.h b/os/os-linux.h
index 34a7cc5..a36552b 100644
--- a/os/os-linux.h
+++ b/os/os-linux.h
@@ -41,6 +41,7 @@
#define FIO_HAVE_TRIM
#define FIO_HAVE_BINJECT
#define FIO_HAVE_CLOCK_MONOTONIC
+#define FIO_HAVE_GETTID
/*
* Can only enable this for newer glibcs, or the header and defines are
@@ -109,6 +110,11 @@
return syscall(__NR_ioprio_set, which, who, ioprio);
}
+static inline int gettid(void)
+{
+ return syscall(__NR_gettid);
+}
+
/*
* Just check for SPLICE_F_MOVE, if that isn't there, assume the others
* aren't either.
diff --git a/os/os.h b/os/os.h
index 3df7b41..cd2bb52 100644
--- a/os/os.h
+++ b/os/os.h
@@ -187,4 +187,11 @@
}
#endif
+#ifndef FIO_HAVE_GETTID
+static inline int gettid(void)
+{
+ return getpid();
+}
+#endif
+
#endif