[PATCH] Add thinktime_spin parameter
authorJens Axboe <jens.axboe@oracle.com>
Sat, 17 Feb 2007 05:30:44 +0000 (06:30 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Sat, 17 Feb 2007 05:30:44 +0000 (06:30 +0100)
If you specify thinktime currently, fio will sleep for the duration.
Apps will typically do some data processing before sleeping, so add
a thinktime_spin parameter to control how much CPU to burn before
sleeping.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
HOWTO
fio.c
fio.h
init.c

diff --git a/HOWTO b/HOWTO
index f61b4c1daab6b54831d5195dc36000be502461ab..8e6e29bbc7dd98e6eb9857596c02de03ebdd0635 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -343,7 +343,14 @@ prioclass=int      Set the io priority class. See man ionice(1).
 
 thinktime=int  Stall the job x microseconds after an io has completed before
                issuing the next. May be used to simulate processing being
-               done by an application. See thinktime_blocks.
+               done by an application. See thinktime_blocks and
+               thinktime_spin.
+
+thinktime_spin=int
+               Only valid if thinktime is set - pretend to spend CPU time
+               doing something with the data received, before falling back
+               to sleeping for the rest of the period specified by
+               thinktime.
 
 thinktime_blocks
                Only valid if thinktime is set - control how many blocks
diff --git a/fio.c b/fio.c
index 78dca9a09610e3140ae5eaabc7518012bff40abe..ff169f86247947d5192635dcc6295a6c68705e76 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -466,8 +466,16 @@ requeue:
                        unsigned long long b;
 
                        b = td->io_blocks[0] + td->io_blocks[1];
-                       if (!(b % td->thinktime_blocks))
-                               usec_sleep(td, td->thinktime);
+                       if (!(b % td->thinktime_blocks)) {
+                               int left;
+
+                               if (td->thinktime_spin)
+                                       __usec_sleep(td->thinktime_spin);
+
+                               left = td->thinktime - td->thinktime_spin;
+                               if (left)
+                                       usec_sleep(td, left);
+                       }
                }
        }
 
diff --git a/fio.h b/fio.h
index 67cc06529cd8fcab52375b3969bfdc4084ed0584..934d897f7162ec880a4d8ce34ba3cb35f9272139 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -274,6 +274,7 @@ struct thread_data {
        unsigned int hugepage_size;
        unsigned int rw_min_bs;
        unsigned int thinktime;
+       unsigned int thinktime_spin;
        unsigned int thinktime_blocks;
        unsigned int fsync_blocks;
        unsigned int start_delay;
diff --git a/init.c b/init.c
index 1dec2bbd324209acf04b72e1430c4d1d5d9db2cb..9e7fb2c055e62a17ceac9dbf78757d1b83bd357c 100644 (file)
--- a/init.c
+++ b/init.c
@@ -330,6 +330,13 @@ static struct fio_option options[] = {
                .help   = "Idle time between IO buffers (usec)",
                .def    = "0",
        },
+       {
+               .name   = "thinktime_spin",
+               .type   = FIO_OPT_INT,
+               .off1   = td_var_offset(thinktime_spin),
+               .help   = "Start thinktime by spinning this amount (usec)",
+               .def    = "0",
+       },
        {
                .name   = "thinktime_blocks",
                .type   = FIO_OPT_INT,
@@ -631,6 +638,12 @@ static void fixup_options(struct thread_data *td)
         */
        if (td->filetype == FIO_TYPE_CHAR && td->odirect)
                td->odirect = 0;
+
+       /*
+        * thinktime_spin must be less than thinktime
+        */
+       if (td->thinktime_spin > td->thinktime)
+               td->thinktime_spin = td->thinktime;
 }
 
 /*