From: Jens Axboe Date: Tue, 12 Jul 2011 19:17:49 +0000 (+0200) Subject: Add gettid() for proper thread affinity on Linux X-Git-Tag: fio-1.56~3 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=47f767c113be7448eb8aa9d4a9f9aa8f760ef642;hp=804bb9a18bb747c8c7c481c9d8dca86a29837ecd Add gettid() for proper thread affinity on Linux Signed-off-by: Jens Axboe --- diff --git a/fio.c b/fio.c index a8608f49..2855ddf2 100644 --- a/fio.c +++ b/fio.c @@ -1045,10 +1045,11 @@ static void *thread_main(void *data) 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 34a7cc53..a36552ba 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 @@ static inline int ioprio_set(int which, int who, int 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. diff --git a/os/os.h b/os/os.h index 3df7b41b..cd2bb523 100644 --- a/os/os.h +++ b/os/os.h @@ -187,4 +187,11 @@ static inline unsigned int cpus_online(void) } #endif +#ifndef FIO_HAVE_GETTID +static inline int gettid(void) +{ + return getpid(); +} +#endif + #endif