svn commit: r292544 - in head/sys/compat/linuxkpi/common: include/linux src

Hans Petter Selasky hselasky at FreeBSD.org
Mon Dec 21 12:20:04 UTC 2015


Author: hselasky
Date: Mon Dec 21 12:20:02 2015
New Revision: 292544
URL: https://svnweb.freebsd.org/changeset/base/292544

Log:
  Implement drain_workqueue() function.
  
  MFC after:	1 week
  Sponsored by:	Mellanox Technologies

Modified:
  head/sys/compat/linuxkpi/common/include/linux/workqueue.h
  head/sys/compat/linuxkpi/common/src/linux_compat.c

Modified: head/sys/compat/linuxkpi/common/include/linux/workqueue.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/linux/workqueue.h	Mon Dec 21 12:13:03 2015	(r292543)
+++ head/sys/compat/linuxkpi/common/include/linux/workqueue.h	Mon Dec 21 12:20:02 2015	(r292544)
@@ -36,10 +36,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 {
@@ -95,6 +98,9 @@ static inline int
 queue_work(struct workqueue_struct *wq, struct work_struct *work)
 {
 	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));
 }
@@ -106,7 +112,9 @@ queue_delayed_work(struct workqueue_stru
 	int pending;
 
 	work->work.taskqueue = wq->taskqueue;
-	if (delay != 0) {
+	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 {
@@ -124,6 +132,7 @@ schedule_delayed_work(struct delayed_wor
 	struct workqueue_struct wq;
 
 	wq.taskqueue = taskqueue_thread;
+	atomic_set(&wq.draining, 0);
 	return (queue_delayed_work(&wq, dwork, delay));
 }
 
@@ -153,6 +162,14 @@ flush_taskqueue(struct taskqueue *tq)
 	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)
 {

Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_compat.c	Mon Dec 21 12:13:03 2015	(r292543)
+++ head/sys/compat/linuxkpi/common/src/linux_compat.c	Mon Dec 21 12:20:02 2015	(r292544)
@@ -945,6 +945,7 @@ linux_create_workqueue_common(const char
 	wq = kmalloc(sizeof(*wq), M_WAITOK);
 	wq->taskqueue = taskqueue_create(name, M_WAITOK,
 	    taskqueue_thread_enqueue,  &wq->taskqueue);
+	atomic_set(&wq->draining, 0);
 	taskqueue_start_threads(&wq->taskqueue, cpus, PWAIT, "%s", name);
 
 	return (wq);


More information about the svn-src-head mailing list