workqueue: move init worker private code to the caller
authorJens Axboe <axboe@fb.com>
Tue, 8 Dec 2015 15:28:53 +0000 (08:28 -0700)
committerJens Axboe <axboe@fb.com>
Tue, 8 Dec 2015 15:28:53 +0000 (08:28 -0700)
Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c
workqueue.c
workqueue.h

index 0842370..b40a3ce 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1444,12 +1444,61 @@ static void io_workqueue_free_fn(struct submit_worker *sw)
        sw->private = NULL;
 }
 
+static int io_workqueue_init_worker_fn(struct submit_worker *sw)
+{
+       struct thread_data *parent = sw->wq->td;
+       struct thread_data *td = sw->private;
+       int fio_unused ret;
+
+       memcpy(&td->o, &parent->o, sizeof(td->o));
+       memcpy(&td->ts, &parent->ts, sizeof(td->ts));
+       td->o.uid = td->o.gid = -1U;
+       dup_files(td, parent);
+       td->eo = parent->eo;
+       fio_options_mem_dupe(td);
+
+       if (ioengine_load(td))
+               goto err;
+
+       if (td->o.odirect)
+               td->io_ops->flags |= FIO_RAWIO;
+
+       td->pid = gettid();
+
+       INIT_FLIST_HEAD(&td->io_log_list);
+       INIT_FLIST_HEAD(&td->io_hist_list);
+       INIT_FLIST_HEAD(&td->verify_list);
+       INIT_FLIST_HEAD(&td->trim_list);
+       INIT_FLIST_HEAD(&td->next_rand_list);
+       td->io_hist_tree = RB_ROOT;
+
+       td->o.iodepth = 1;
+       if (td_io_init(td))
+               goto err_io_init;
+
+       fio_gettime(&td->epoch, NULL);
+       fio_getrusage(&td->ru_start);
+       clear_io_state(td, 1);
+
+       td_set_runstate(td, TD_RUNNING);
+       td->flags |= TD_F_CHILD;
+       td->parent = parent;
+       return 0;
+
+err_io_init:
+       close_ioengine(td);
+err:
+       return 1;
+
+}
+
 struct workqueue_ops rated_wq_ops = {
        .fn                     = io_workqueue_fn,
        .pre_sleep_flush_fn     = io_workqueue_pre_sleep_flush_fn,
        .pre_sleep_fn           = io_workqueue_pre_sleep_fn,
        .alloc_worker_fn        = io_workqueue_alloc_fn,
        .free_worker_fn         = io_workqueue_free_fn,
+       .init_worker_fn         = io_workqueue_init_worker_fn,
 };
 
 /*
index f0ebd8a..818baf8 100644 (file)
@@ -130,53 +130,6 @@ static void handle_list(struct submit_worker *sw, struct flist_head *list)
        }
 }
 
-static int init_submit_worker(struct submit_worker *sw)
-{
-       struct thread_data *parent = sw->wq->td;
-       struct thread_data *td = sw->private;
-       int fio_unused ret;
-
-       memcpy(&td->o, &parent->o, sizeof(td->o));
-       memcpy(&td->ts, &parent->ts, sizeof(td->ts));
-       td->o.uid = td->o.gid = -1U;
-       dup_files(td, parent);
-       td->eo = parent->eo;
-       fio_options_mem_dupe(td);
-
-       if (ioengine_load(td))
-               goto err;
-
-       if (td->o.odirect)
-               td->io_ops->flags |= FIO_RAWIO;
-
-       td->pid = gettid();
-
-       INIT_FLIST_HEAD(&td->io_log_list);
-       INIT_FLIST_HEAD(&td->io_hist_list);
-       INIT_FLIST_HEAD(&td->verify_list);
-       INIT_FLIST_HEAD(&td->trim_list);
-       INIT_FLIST_HEAD(&td->next_rand_list);
-       td->io_hist_tree = RB_ROOT;
-
-       td->o.iodepth = 1;
-       if (td_io_init(td))
-               goto err_io_init;
-
-       fio_gettime(&td->epoch, NULL);
-       fio_getrusage(&td->ru_start);
-       clear_io_state(td, 1);
-
-       td_set_runstate(td, TD_RUNNING);
-       td->flags |= TD_F_CHILD;
-       td->parent = parent;
-       return 0;
-
-err_io_init:
-       close_ioengine(td);
-err:
-       return 1;
-}
-
 #ifdef CONFIG_SFAA
 static void sum_val(uint64_t *dst, uint64_t *src)
 {
@@ -251,7 +204,7 @@ static void *worker_thread(void *data)
        unsigned int eflags = 0, ret;
        FLIST_HEAD(local_list);
 
-       ret = init_submit_worker(sw);
+       ret = workqueue_init_worker(sw);
        pthread_mutex_lock(&sw->lock);
        sw->flags |= SW_F_RUNNING;
        if (ret)
index b48f9db..f724f90 100644 (file)
@@ -24,6 +24,7 @@ typedef bool (workqueue_pre_sleep_flush_fn)(struct submit_worker *);
 typedef void (workqueue_pre_sleep_fn)(struct submit_worker *);
 typedef int (workqueue_alloc_worker_fn)(struct submit_worker *);
 typedef void (workqueue_free_worker_fn)(struct submit_worker *);
+typedef int (workqueue_init_worker_fn)(struct submit_worker *);
 
 struct workqueue_ops {
        workqueue_work_fn *fn;
@@ -31,6 +32,7 @@ struct workqueue_ops {
        workqueue_pre_sleep_fn *pre_sleep_fn;
        workqueue_alloc_worker_fn *alloc_worker_fn;
        workqueue_free_worker_fn *free_worker_fn;
+       workqueue_init_worker_fn *init_worker_fn;
 };
 
 struct workqueue {
@@ -73,4 +75,14 @@ static inline void workqueue_pre_sleep(struct submit_worker *sw)
                wq->ops.pre_sleep_fn(sw);
 }
 
+static inline int workqueue_init_worker(struct submit_worker *sw)
+{
+       struct workqueue *wq = sw->wq;
+
+       if (!wq->ops.init_worker_fn)
+               return 0;
+
+       return wq->ops.init_worker_fn(sw);
+}
+
 #endif