Add gettid() for proper thread affinity on Linux
authorJens Axboe <jaxboe@fusionio.com>
Tue, 12 Jul 2011 19:17:49 +0000 (21:17 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Tue, 12 Jul 2011 19:17:49 +0000 (21:17 +0200)
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
fio.c
os/os-linux.h
os/os.h

diff --git a/fio.c b/fio.c
index a8608f49fdd4023c6e54d4e3cf38ec14234498f5..2855ddf289748cf93e506aa7950aa82c2ac43e11 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -1045,10 +1045,11 @@ static void *thread_main(void *data)
        pthread_condattr_t attr;
        int clear_state;
 
        pthread_condattr_t attr;
        int clear_state;
 
-       if (!td->o.use_thread)
+       if (!td->o.use_thread) {
                setsid();
                setsid();
-
-       td->pid = getpid();
+               td->pid = getpid();
+       } else
+               td->pid = gettid();
 
        dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
 
 
        dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
 
index 34a7cc53fb33d680e6750bd16c20e127ed51df89..a36552ba68ba93caf6ca58e5fc9761fc53c0b88d 100644 (file)
@@ -41,6 +41,7 @@
 #define FIO_HAVE_TRIM
 #define FIO_HAVE_BINJECT
 #define FIO_HAVE_CLOCK_MONOTONIC
 #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
 
 /*
  * Can only enable this for newer glibcs, or the header and defines are
@@ -109,6 +110,11 @@ static inline int ioprio_set(int which, int who, int ioprio)
        return syscall(__NR_ioprio_set, which, who, ioprio);
 }
 
        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.
 /*
  * 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 3df7b41be4b6447c73783abf03808b38ca2ee586..cd2bb523bb9ef931f27ea123c3e239bcdc035518 100644 (file)
--- a/os/os.h
+++ b/os/os.h
@@ -187,4 +187,11 @@ static inline unsigned int cpus_online(void)
 }
 #endif
 
 }
 #endif
 
+#ifndef FIO_HAVE_GETTID
+static inline int gettid(void)
+{
+       return getpid();
+}
+#endif
+
 #endif
 #endif