From 47f767c113be7448eb8aa9d4a9f9aa8f760ef642 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 12 Jul 2011 21:17:49 +0200 Subject: [PATCH] Add gettid() for proper thread affinity on Linux Signed-off-by: Jens Axboe --- fio.c | 7 ++++--- os/os-linux.h | 6 ++++++ os/os.h | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) 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 -- 2.25.1