From: Yufei Ren Date: Sat, 20 Oct 2012 03:11:50 +0000 (-0400) Subject: thread cpu resource statistics bug fix X-Git-Tag: fio-2.0.11~50 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=f5fd0b1cd383c4a3cb8fb5078b7e93aecba8847e thread cpu resource statistics bug fix If `thread' option is enabled, resource usage should be thread based instead of process based. For the following job, fio --ioengine=cpuio --cpuload=50 --time_based --runtime=10 --name=j0 --numjobs=4 --thread before patch, each thread CPU statistics: ... cpu : usr=199.67%, sys=0.14%, ctx=1475, majf=0, minf=24 ... after patch: ... cpu : usr=49.80%, sys=0.00%, ctx=79, majf=0, minf=18446744073709538943 ... Signed-off-by: Jens Axboe --- diff --git a/os/os-linux.h b/os/os-linux.h index 9b7ff29e..2b35f346 100644 --- a/os/os-linux.h +++ b/os/os-linux.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "indirect.h" @@ -62,6 +63,10 @@ #define FIO_HAVE_FALLOC_ENG #endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) +#define FIO_HAVE_RUSAGE_THREAD +#endif + #ifdef SYNC_FILE_RANGE_WAIT_BEFORE #define FIO_HAVE_SYNC_FILE_RANGE #endif diff --git a/stat.c b/stat.c index d041ef3c..af6e1f2e 100644 --- a/stat.c +++ b/stat.c @@ -16,7 +16,11 @@ void update_rusage_stat(struct thread_data *td) { struct thread_stat *ts = &td->ts; +#ifdef FIO_HAVE_RUSAGE_THREAD + getrusage(RUSAGE_THREAD, &td->ru_end); +#else getrusage(RUSAGE_SELF, &td->ru_end); +#endif ts->usr_time += mtime_since(&td->ru_start.ru_utime, &td->ru_end.ru_utime);