options: move ioprio/ioprio_class into thread_options space
authorJens Axboe <axboe@kernel.dk>
Thu, 29 Mar 2012 06:33:15 +0000 (08:33 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 29 Mar 2012 06:33:15 +0000 (08:33 +0200)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c
cconv.c
fio.h
options.c
os/os-linux.h
os/os.h
thread_options.h

index ad9231330547dc39278dd40d1ed94c37d0e2455e..968b52213d1abc1e86ddc50092dc8a47b11129f9 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -958,10 +958,12 @@ static void *thread_main(void *data)
 {
        unsigned long long elapsed;
        struct thread_data *td = data;
+       struct thread_options *o = &td->o;
        pthread_condattr_t attr;
        int clear_state;
+       int ret;
 
-       if (!td->o.use_thread) {
+       if (!o->use_thread) {
                setsid();
                td->pid = getpid();
        } else
@@ -1004,11 +1006,11 @@ static void *thread_main(void *data)
         * A new gid requires privilege, so we need to do this before setting
         * the uid.
         */
-       if (td->o.gid != -1U && setgid(td->o.gid)) {
+       if (o->gid != -1U && setgid(o->gid)) {
                td_verror(td, errno, "setgid");
                goto err;
        }
-       if (td->o.uid != -1U && setuid(td->o.uid)) {
+       if (o->uid != -1U && setuid(o->uid)) {
                td_verror(td, errno, "setuid");
                goto err;
        }
@@ -1017,16 +1019,19 @@ static void *thread_main(void *data)
         * If we have a gettimeofday() thread, make sure we exclude that
         * thread from this job
         */
-       if (td->o.gtod_cpu)
-               fio_cpu_clear(&td->o.cpumask, td->o.gtod_cpu);
+       if (o->gtod_cpu)
+               fio_cpu_clear(&o->cpumask, o->gtod_cpu);
 
        /*
         * Set affinity first, in case it has an impact on the memory
         * allocations.
         */
-       if (td->o.cpumask_set && fio_setaffinity(td->pid, td->o.cpumask) == -1) {
-               td_verror(td, errno, "cpu_set_affinity");
-               goto err;
+       if (o->cpumask_set) {
+               ret = fio_setaffinity(td->pid, o->cpumask);
+               if (ret == -1) {
+                       td_verror(td, errno, "cpu_set_affinity");
+                       goto err;
+               }
        }
 
        if (fio_pin_memory(td))
@@ -1042,29 +1047,30 @@ static void *thread_main(void *data)
        if (init_io_u(td))
                goto err;
 
-       if (td->o.verify_async && verify_async_init(td))
+       if (o->verify_async && verify_async_init(td))
                goto err;
 
-       if (td->ioprio_set) {
-               if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
+       if (o->ioprio) {
+               ret = ioprio_set(IOPRIO_WHO_PROCESS, 0, o->ioprio_class, o->ioprio);
+               if (ret == -1) {
                        td_verror(td, errno, "ioprio_set");
                        goto err;
                }
        }
 
-       if (td->o.cgroup_weight && cgroup_setup(td, cgroup_list, &cgroup_mnt))
+       if (o->cgroup_weight && cgroup_setup(td, cgroup_list, &cgroup_mnt))
                goto err;
 
        errno = 0;
-       if (nice(td->o.nice) == -1 && errno != 0) {
+       if (nice(o->nice) == -1 && errno != 0) {
                td_verror(td, errno, "nice");
                goto err;
        }
 
-       if (td->o.ioscheduler && switch_ioscheduler(td))
+       if (o->ioscheduler && switch_ioscheduler(td))
                goto err;
 
-       if (!td->o.create_serialize && setup_files(td))
+       if (!o->create_serialize && setup_files(td))
                goto err;
 
        if (td_io_init(td))
@@ -1073,12 +1079,10 @@ static void *thread_main(void *data)
        if (init_random_map(td))
                goto err;
 
-       if (td->o.exec_prerun) {
-               if (exec_string(td->o.exec_prerun))
-                       goto err;
-       }
+       if (o->exec_prerun && exec_string(o->exec_prerun))
+               goto err;
 
-       if (td->o.pre_read) {
+       if (o->pre_read) {
                if (pre_read_files(td) < 0)
                        goto err;
        }
@@ -1206,8 +1210,8 @@ err:
        cleanup_io_u(td);
        cgroup_shutdown(td, &cgroup_mnt);
 
-       if (td->o.cpumask_set) {
-               int ret = fio_cpuset_exit(&td->o.cpumask);
+       if (o->cpumask_set) {
+               int ret = fio_cpuset_exit(&o->cpumask);
 
                td_verror(td, ret, "fio_cpuset_exit");
        }
diff --git a/cconv.c b/cconv.c
index d94502b467ea1c2f60cf1f90ef1c50641ca9adf0..285db4ebb3cea26396ad1201dfd5fecb7825d7c9 100644 (file)
--- a/cconv.c
+++ b/cconv.c
@@ -153,6 +153,8 @@ void convert_thread_options_to_cpu(struct thread_options *o,
        o->iolog = le32_to_cpu(top->iolog);
        o->rwmixcycle = le32_to_cpu(top->rwmixcycle);
        o->nice = le32_to_cpu(top->nice);
+       o->ioprio = le32_to_cpu(top->ioprio);
+       o->ioprio_class = le32_to_cpu(top->ioprio_class);
        o->file_service_type = le32_to_cpu(top->file_service_type);
        o->group_reporting = le32_to_cpu(top->group_reporting);
        o->fadvise_hint = le32_to_cpu(top->fadvise_hint);
@@ -291,6 +293,8 @@ void convert_thread_options_to_net(struct thread_options_pack *top,
        top->iolog = cpu_to_le32(o->iolog);
        top->rwmixcycle = cpu_to_le32(o->rwmixcycle);
        top->nice = cpu_to_le32(o->nice);
+       top->ioprio = cpu_to_le32(o->ioprio);
+       top->ioprio_class = cpu_to_le32(o->ioprio_class);
        top->file_service_type = cpu_to_le32(o->file_service_type);
        top->group_reporting = cpu_to_le32(o->group_reporting);
        top->fadvise_hint = cpu_to_le32(o->fadvise_hint);
diff --git a/fio.h b/fio.h
index e37e5ae1e8e38e55f7508afe8ca115a49ac6a15e..9994ccd5b81da2b43212aec9abf9daabd06cd70f 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -105,8 +105,6 @@ struct thread_data {
        size_t orig_buffer_size;
        volatile int terminate;
        volatile int runstate;
-       unsigned int ioprio;
-       unsigned int ioprio_set;
        unsigned int last_was_sync;
        enum fio_ddir last_ddir;
 
index 5b668e5d1226a57878b0cfdad739be57738e6553..962ca1981f0995c0a2d7ae2f9ded72c15cbaa643 100644 (file)
--- a/options.c
+++ b/options.c
@@ -269,40 +269,6 @@ static int str_rwmix_write_cb(void *data, unsigned long long *val)
        return 0;
 }
 
-#ifdef FIO_HAVE_IOPRIO
-static int str_prioclass_cb(void *data, unsigned long long *val)
-{
-       struct thread_data *td = data;
-       unsigned short mask;
-
-       /*
-        * mask off old class bits, str_prio_cb() may have set a default class
-        */
-       mask = (1 << IOPRIO_CLASS_SHIFT) - 1;
-       td->ioprio &= mask;
-
-       td->ioprio |= *val << IOPRIO_CLASS_SHIFT;
-       td->ioprio_set = 1;
-       return 0;
-}
-
-static int str_prio_cb(void *data, unsigned long long *val)
-{
-       struct thread_data *td = data;
-
-       td->ioprio |= *val;
-
-       /*
-        * If no class is set, assume BE
-        */
-       if ((td->ioprio >> IOPRIO_CLASS_SHIFT) == 0)
-               td->ioprio |= IOPRIO_CLASS_BE << IOPRIO_CLASS_SHIFT;
-
-       td->ioprio_set = 1;
-       return 0;
-}
-#endif
-
 static int str_exitall_cb(void)
 {
        exitall_on_terminate = 1;
@@ -2176,7 +2142,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .name   = "prio",
                .lname  = "I/O nice priority",
                .type   = FIO_OPT_INT,
-               .cb     = str_prio_cb,
+               .off1   = td_var_offset(ioprio),
                .help   = "Set job IO priority value",
                .minval = 0,
                .maxval = 7,
@@ -2188,7 +2154,7 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .name   = "prioclass",
                .lname  = "I/O nice priority class",
                .type   = FIO_OPT_INT,
-               .cb     = str_prioclass_cb,
+               .off1   = td_var_offset(ioprio_class),
                .help   = "Set job IO priority class",
                .minval = 0,
                .maxval = 3,
index d5c3f76e03fb40afe8c3807f0ded8620f50b1d1e..3f5b2d8310aaa171a4ab68b47c93c884e4b9dac7 100644 (file)
@@ -111,8 +111,31 @@ static inline int fio_cpuset_exit(os_cpu_mask_t *mask)
 
 #define FIO_MAX_CPUS                   CPU_SETSIZE
 
-static inline int ioprio_set(int which, int who, int ioprio)
+enum {
+       IOPRIO_CLASS_NONE,
+       IOPRIO_CLASS_RT,
+       IOPRIO_CLASS_BE,
+       IOPRIO_CLASS_IDLE,
+};
+
+enum {
+       IOPRIO_WHO_PROCESS = 1,
+       IOPRIO_WHO_PGRP,
+       IOPRIO_WHO_USER,
+};
+
+#define IOPRIO_BITS            16
+#define IOPRIO_CLASS_SHIFT     13
+
+static inline int ioprio_set(int which, int who, int ioprio_class, int ioprio)
 {
+       /*
+        * If no class is set, assume BE
+        */
+       if (!ioprio_class)
+               ioprio_class = IOPRIO_CLASS_BE;
+
+       ioprio |= ioprio_class << IOPRIO_CLASS_SHIFT;
        return syscall(__NR_ioprio_set, which, who, ioprio);
 }
 
@@ -186,22 +209,6 @@ static inline long umem_add(unsigned long *uptr, unsigned long inc)
 }
 #endif /* FIO_HAVE_SYSLET */
 
-enum {
-       IOPRIO_CLASS_NONE,
-       IOPRIO_CLASS_RT,
-       IOPRIO_CLASS_BE,
-       IOPRIO_CLASS_IDLE,
-};
-
-enum {
-       IOPRIO_WHO_PROCESS = 1,
-       IOPRIO_WHO_PGRP,
-       IOPRIO_WHO_USER,
-};
-
-#define IOPRIO_BITS            16
-#define IOPRIO_CLASS_SHIFT     13
-
 #ifndef BLKGETSIZE64
 #define BLKGETSIZE64   _IOR(0x12,114,size_t)
 #endif
diff --git a/os/os.h b/os/os.h
index 8d2a6ae8cd0923a5b29b92bf23ba1052e7065a97..dc798c373a751b6f41f814448cfa95f2a5300439 100644 (file)
--- a/os/os.h
+++ b/os/os.h
@@ -84,7 +84,7 @@ typedef unsigned long os_cpu_mask_t;
 #endif
 
 #ifndef FIO_HAVE_IOPRIO
-#define ioprio_set(which, who, prio)   (0)
+#define ioprio_set(which, who, prioclass, prio)        (0)
 #endif
 
 #ifndef FIO_HAVE_ODIRECT
index 5a296c73d51aff00a7e3c19a27e9130b6b625a4c..4b5f9578b7dd75feea086c37ead325adccfdb479 100644 (file)
@@ -141,6 +141,8 @@ struct thread_options {
        unsigned int rwmixcycle;
        unsigned int rwmix[2];
        unsigned int nice;
+       unsigned int ioprio;
+       unsigned int ioprio_class;
        unsigned int file_service_type;
        unsigned int group_reporting;
        unsigned int fadvise_hint;
@@ -326,6 +328,8 @@ struct thread_options_pack {
        uint32_t rwmixcycle;
        uint32_t rwmix[2];
        uint32_t nice;
+       uint32_t ioprio;
+       uint32_t ioprio_class;
        uint32_t file_service_type;
        uint32_t group_reporting;
        uint32_t fadvise_hint;