From 882718418309228b28146dc03d43c9253c7cfb35 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 7 Dec 2015 22:20:02 -0700 Subject: [PATCH] workqueue: add a workqueue_work type Don't pass in a struct io_u, that's specific to the use case of using this for queueing IO. Use a generic work type, so we can reuse this helper code for other purposes. Signed-off-by: Jens Axboe --- backend.c | 5 +++-- ioengine.h | 6 +++++- workqueue.c | 13 ++++++------- workqueue.h | 8 ++++++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/backend.c b/backend.c index e5ba66d6..26c1bf55 100644 --- a/backend.c +++ b/backend.c @@ -934,7 +934,7 @@ static uint64_t do_io(struct thread_data *td) if (td->error) break; - ret = workqueue_enqueue(&td->io_wq, io_u); + ret = workqueue_enqueue(&td->io_wq, &io_u->work); if (ret) ret = FIO_Q_QUEUED; else @@ -1361,8 +1361,9 @@ static uint64_t do_dry_run(struct thread_data *td) return td->bytes_done[DDIR_WRITE] + td->bytes_done[DDIR_TRIM]; } -static void io_workqueue_fn(struct thread_data *td, struct io_u *io_u) +static void io_workqueue_fn(struct thread_data *td, struct workqueue_work *work) { + struct io_u *io_u = container_of(work, struct io_u, work); const enum fio_ddir ddir = io_u->ddir; int ret; diff --git a/ioengine.h b/ioengine.h index 37f0336a..6734c7bb 100644 --- a/ioengine.h +++ b/ioengine.h @@ -7,6 +7,7 @@ #include "io_ddir.h" #include "debug.h" #include "file.h" +#include "workqueue.h" #ifdef CONFIG_LIBAIO #include @@ -89,7 +90,10 @@ struct io_u { void *engine_data; }; - struct flist_head verify_list; + union { + struct flist_head verify_list; + struct workqueue_work work; + }; /* * Callback for io completion diff --git a/workqueue.c b/workqueue.c index 82d52df8..11791209 100644 --- a/workqueue.c +++ b/workqueue.c @@ -7,7 +7,6 @@ #include #include "fio.h" -#include "ioengine.h" #include "flist.h" #include "workqueue.h" #include "lib/getrusage.h" @@ -112,14 +111,14 @@ void workqueue_flush(struct workqueue *wq) /* * Must be serialized by caller. Returns true for queued, false for busy. */ -bool workqueue_enqueue(struct workqueue *wq, struct io_u *io_u) +bool workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work) { struct submit_worker *sw; sw = get_submit_worker(wq); if (sw) { pthread_mutex_lock(&sw->lock); - flist_add_tail(&io_u->verify_list, &sw->work_list); + flist_add_tail(&work->list, &sw->work_list); sw->seq = ++wq->work_seq; sw->flags &= ~SW_F_IDLE; pthread_mutex_unlock(&sw->lock); @@ -134,12 +133,12 @@ bool workqueue_enqueue(struct workqueue *wq, struct io_u *io_u) static void handle_list(struct submit_worker *sw, struct flist_head *list) { struct workqueue *wq = sw->wq; - struct io_u *io_u; + struct workqueue_work *work; while (!flist_empty(list)) { - io_u = flist_first_entry(list, struct io_u, verify_list); - flist_del_init(&io_u->verify_list); - wq->fn(&sw->td, io_u); + work = flist_first_entry(list, struct workqueue_work, list); + flist_del_init(&work->list); + wq->fn(&sw->td, work); } } diff --git a/workqueue.h b/workqueue.h index 3a24f254..26b3aee1 100644 --- a/workqueue.h +++ b/workqueue.h @@ -3,7 +3,11 @@ #include "flist.h" -typedef void (workqueue_fn)(struct thread_data *, struct io_u *); +struct workqueue_work { + struct flist_head list; +}; + +typedef void (workqueue_fn)(struct thread_data *, struct workqueue_work *); struct workqueue { unsigned int max_workers; @@ -24,7 +28,7 @@ struct workqueue { int workqueue_init(struct thread_data *td, struct workqueue *wq, workqueue_fn *fn, unsigned int max_workers); void workqueue_exit(struct workqueue *wq); -bool workqueue_enqueue(struct workqueue *wq, struct io_u *io_u); +bool workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work); void workqueue_flush(struct workqueue *wq); #endif -- 2.25.1