summaryrefslogtreecommitdiffstats
path: root/sys/ofed/include/linux/workqueue.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/ofed/include/linux/workqueue.h')
-rw-r--r--sys/ofed/include/linux/workqueue.h121
1 files changed, 56 insertions, 65 deletions
diff --git a/sys/ofed/include/linux/workqueue.h b/sys/ofed/include/linux/workqueue.h
index 38cd2fe..41ca80f 100644
--- a/sys/ofed/include/linux/workqueue.h
+++ b/sys/ofed/include/linux/workqueue.h
@@ -2,7 +2,7 @@
* Copyright (c) 2010 Isilon Systems, Inc.
* Copyright (c) 2010 iX Systems, Inc.
* Copyright (c) 2010 Panasas, Inc.
- * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
+ * Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,10 +34,13 @@
#include <linux/timer.h>
#include <linux/slab.h>
+#include <asm/atomic.h>
+
#include <sys/taskqueue.h>
struct workqueue_struct {
struct taskqueue *taskqueue;
+ atomic_t draining;
};
struct work_struct {
@@ -46,11 +49,19 @@ struct work_struct {
void (*fn)(struct work_struct *);
};
+typedef __typeof(((struct work_struct *)0)->fn) work_func_t;
+
struct delayed_work {
struct work_struct work;
struct callout timer;
};
+extern void linux_work_fn(void *, int);
+extern void linux_flush_fn(void *, int);
+extern void linux_delayed_work_fn(void *);
+extern struct workqueue_struct *linux_create_workqueue_common(const char *, int);
+extern void destroy_workqueue(struct workqueue_struct *);
+
static inline struct delayed_work *
to_delayed_work(struct work_struct *work)
{
@@ -58,21 +69,11 @@ to_delayed_work(struct work_struct *work)
return container_of(work, struct delayed_work, work);
}
-
-static inline void
-_work_fn(void *context, int pending)
-{
- struct work_struct *work;
-
- work = context;
- work->fn(work);
-}
-
#define INIT_WORK(work, func) \
do { \
(work)->fn = (func); \
(work)->taskqueue = NULL; \
- TASK_INIT(&(work)->work_task, 0, _work_fn, (work)); \
+ TASK_INIT(&(work)->work_task, 0, linux_work_fn, (work)); \
} while (0)
#define INIT_DELAYED_WORK(_work, func) \
@@ -81,7 +82,7 @@ do { \
callout_init(&(_work)->timer, CALLOUT_MPSAFE); \
} while (0)
-#define INIT_DEFERRABLE_WORK INIT_DELAYED_WORK
+#define INIT_DEFERRABLE_WORK(...) INIT_DELAYED_WORK(__VA_ARGS__)
#define schedule_work(work) \
do { \
@@ -91,20 +92,15 @@ do { \
#define flush_scheduled_work() flush_taskqueue(taskqueue_thread)
-static inline int queue_work (struct workqueue_struct *q, struct work_struct *work)
+static inline int
+queue_work(struct workqueue_struct *wq, struct work_struct *work)
{
- (work)->taskqueue = (q)->taskqueue;
- /* Return opposite val to align with Linux logic */
- return !taskqueue_enqueue((q)->taskqueue, &(work)->work_task);
-}
-
-static inline void
-_delayed_work_fn(void *arg)
-{
- struct delayed_work *work;
-
- work = arg;
- taskqueue_enqueue(work->work.taskqueue, &work->work.work_task);
+ work->taskqueue = wq->taskqueue;
+ /* Check for draining */
+ if (atomic_read(&wq->draining) != 0)
+ return (!work->work_task.ta_pending);
+ /* Return opposite value to align with Linux logic */
+ return (!taskqueue_enqueue(wq->taskqueue, &work->work_task));
}
static inline int
@@ -113,57 +109,44 @@ queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work,
{
int pending;
- pending = work->work.work_task.ta_pending;
work->work.taskqueue = wq->taskqueue;
- if (delay != 0)
- callout_reset(&work->timer, delay, _delayed_work_fn, work);
- else
- _delayed_work_fn((void *)work);
-
+ if (atomic_read(&wq->draining) != 0) {
+ pending = work->work.work_task.ta_pending;
+ } else if (delay != 0) {
+ pending = work->work.work_task.ta_pending;
+ callout_reset(&work->timer, delay, linux_delayed_work_fn, work);
+ } else {
+ callout_stop(&work->timer);
+ pending = taskqueue_enqueue(work->work.taskqueue,
+ &work->work.work_task);
+ }
return (!pending);
}
-static inline bool schedule_delayed_work(struct delayed_work *dwork,
- unsigned long delay)
-{
- struct workqueue_struct wq;
- wq.taskqueue = taskqueue_thread;
- return queue_delayed_work(&wq, dwork, delay);
-}
-
-static inline struct workqueue_struct *
-_create_workqueue_common(char *name, int cpus)
+static inline bool
+schedule_delayed_work(struct delayed_work *dwork,
+ unsigned long delay)
{
- struct workqueue_struct *wq;
+ struct workqueue_struct wq;
- wq = kmalloc(sizeof(*wq), M_WAITOK);
- wq->taskqueue = taskqueue_create((name), M_WAITOK,
- taskqueue_thread_enqueue, &wq->taskqueue);
- taskqueue_start_threads(&wq->taskqueue, cpus, PWAIT, "%s", name);
-
- return (wq);
+ wq.taskqueue = taskqueue_thread;
+ atomic_set(&wq.draining, 0);
+ return (queue_delayed_work(&wq, dwork, delay));
}
-
#define create_singlethread_workqueue(name) \
- _create_workqueue_common(name, 1)
+ linux_create_workqueue_common(name, 1)
#define create_workqueue(name) \
- _create_workqueue_common(name, MAXCPU)
+ linux_create_workqueue_common(name, MAXCPU)
-static inline void
-destroy_workqueue(struct workqueue_struct *wq)
-{
- taskqueue_free(wq->taskqueue);
- kfree(wq);
-}
+#define alloc_ordered_workqueue(name, flags) \
+ linux_create_workqueue_common(name, 1)
-#define flush_workqueue(wq) flush_taskqueue((wq)->taskqueue)
+#define alloc_workqueue(name, flags, max_active) \
+ linux_create_workqueue_common(name, max_active)
-static inline void
-_flush_fn(void *context, int pending)
-{
-}
+#define flush_workqueue(wq) flush_taskqueue((wq)->taskqueue)
static inline void
flush_taskqueue(struct taskqueue *tq)
@@ -171,12 +154,20 @@ flush_taskqueue(struct taskqueue *tq)
struct task flushtask;
PHOLD(curproc);
- TASK_INIT(&flushtask, 0, _flush_fn, NULL);
+ TASK_INIT(&flushtask, 0, linux_flush_fn, NULL);
taskqueue_enqueue(tq, &flushtask);
taskqueue_drain(tq, &flushtask);
PRELE(curproc);
}
+static inline void
+drain_workqueue(struct workqueue_struct *wq)
+{
+ atomic_inc(&wq->draining);
+ flush_taskqueue(wq->taskqueue);
+ atomic_dec(&wq->draining);
+}
+
static inline int
cancel_work_sync(struct work_struct *work)
{
@@ -213,7 +204,7 @@ cancel_delayed_work_sync(struct delayed_work *work)
static inline bool
mod_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork,
- unsigned long delay)
+ unsigned long delay)
{
cancel_delayed_work(dwork);
queue_delayed_work(wq, dwork, delay);
OpenPOWER on IntegriCloud