thread cpu resource statistics bug fix
authorYufei Ren <renyufei83@gmail.com>
Sat, 20 Oct 2012 03:11:50 +0000 (23:11 -0400)
committerJens Axboe <axboe@kernel.dk>
Mon, 22 Oct 2012 08:02:34 +0000 (10:02 +0200)
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 <axboe@kernel.dk>
os/os-linux.h
stat.c

index 9b7ff29e50af7f07d656cf3e763e7fafe409a669..2b35f346217e88205c6022d87390ac577cb54602 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/unistd.h>
 #include <linux/raw.h>
 #include <linux/major.h>
 #include <linux/unistd.h>
 #include <linux/raw.h>
 #include <linux/major.h>
+#include <linux/version.h>
 #include <endian.h>
 
 #include "indirect.h"
 #include <endian.h>
 
 #include "indirect.h"
 #define FIO_HAVE_FALLOC_ENG
 #endif
 
 #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
 #ifdef SYNC_FILE_RANGE_WAIT_BEFORE
 #define FIO_HAVE_SYNC_FILE_RANGE
 #endif
diff --git a/stat.c b/stat.c
index d041ef3c0bb56c770334d551061824113c8b5b2d..af6e1f2efe9a6864137e5600d2520f754863ae70 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -16,7 +16,11 @@ void update_rusage_stat(struct thread_data *td)
 {
        struct thread_stat *ts = &td->ts;
 
 {
        struct thread_stat *ts = &td->ts;
 
+#ifdef FIO_HAVE_RUSAGE_THREAD
+       getrusage(RUSAGE_THREAD, &td->ru_end);
+#else
        getrusage(RUSAGE_SELF, &td->ru_end);
        getrusage(RUSAGE_SELF, &td->ru_end);
+#endif
 
        ts->usr_time += mtime_since(&td->ru_start.ru_utime,
                                        &td->ru_end.ru_utime);
 
        ts->usr_time += mtime_since(&td->ru_start.ru_utime,
                                        &td->ru_end.ru_utime);