Add gtod_cpu option for pinning gettimeofday() to a single CPU
[fio.git] / options.c
index b890420f4e4e06c75f0c8f0c787f9c4597fd844f..5bbeb34276e622cd9f1fc2f88d14664f619b8dcf 100644 (file)
--- a/options.c
+++ b/options.c
@@ -249,9 +249,12 @@ static int str_cpumask_cb(void *data, unsigned int *val)
 
        CPU_ZERO(&td->o.cpumask);
 
-       for (i = 0; i < sizeof(int) * 8; i++)
-               if ((1 << i) & *val)
+       for (i = 0; i < sizeof(int) * 8; i++) {
+               if ((1 << i) & *val) {
+                       dprint(FD_PARSE, "set cpu allowed %d\n", i);
                        CPU_SET(*val, &td->o.cpumask);
+               }
+       }
 
        td->o.cpumask_set = 1;
        return 0;
@@ -270,9 +273,29 @@ static int str_cpus_allowed_cb(void *data, const char *input)
        strip_blank_end(str);
 
        while ((cpu = strsep(&str, ",")) != NULL) {
+               char *str2, *cpu2;
+               int icpu, icpu2;
+
                if (!strlen(cpu))
                        break;
-               CPU_SET(atoi(cpu), &td->o.cpumask);
+
+               str2 = cpu;
+               icpu2 = -1;
+               while ((cpu2 = strsep(&str2, "-")) != NULL) {
+                       if (!strlen(cpu2))
+                               break;
+
+                       icpu2 = atoi(cpu2);
+               }
+
+               icpu = atoi(cpu);
+               if (icpu2 == -1)
+                       icpu2 = icpu;
+               while (icpu <= icpu2) {
+                       dprint(FD_PARSE, "set cpu allowed %d\n", icpu);
+                       CPU_SET(atoi(cpu), &td->o.cpumask);
+                       icpu++;
+               }
        }
 
        free(p);
@@ -474,6 +497,16 @@ static int str_gtod_reduce_cb(void *data, int *il)
        return 0;
 }
 
+static int str_gtod_cpu_cb(void *data, int *il)
+{
+       struct thread_data *td = data;
+       int val = *il;
+
+       td->o.gtod_cpu = val;
+       td->o.gtod_offload = 1;
+       return 0;
+}
+
 #define __stringify_1(x)       #x
 #define __stringify(x)         __stringify_1(x)
 
@@ -1365,6 +1398,12 @@ static struct fio_option options[] = {
                .parent = "gtod_reduce",
                .def    = "0",
        },
+       {
+               .name   = "gtod_cpu",
+               .type   = FIO_OPT_INT,
+               .cb     = str_gtod_cpu_cb,
+               .help   = "Setup dedicated gettimeofday() thread on this CPU",
+       },
        {
                .name = NULL,
        },