Module Name:    src
Committed By:   riastradh
Date:           Wed Jan 22 14:58:20 UTC 2014

Modified Files:
        src/sys/external/bsd/drm2/linux [riastradh-drm2]: linux_work.c

Log Message:
Fix queue_delayed_work edge cases.

- Copy the relevant part of queue_work in-line for ticks == 0, since
  queue_work itself will choke on a delayed work.

- Don't reschedule the callout if it is already scheduled -- let it
  fire when it was already scheduled to fire.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.8 -r1.1.2.9 src/sys/external/bsd/drm2/linux/linux_work.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/linux/linux_work.c
diff -u src/sys/external/bsd/drm2/linux/linux_work.c:1.1.2.8 src/sys/external/bsd/drm2/linux/linux_work.c:1.1.2.9
--- src/sys/external/bsd/drm2/linux/linux_work.c:1.1.2.8	Mon Dec 30 04:52:21 2013
+++ src/sys/external/bsd/drm2/linux/linux_work.c	Wed Jan 22 14:58:20 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.1.2.8 2013/12/30 04:52:21 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.1.2.9 2014/01/22 14:58:20 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.1.2.8 2013/12/30 04:52:21 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.1.2.9 2014/01/22 14:58:20 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -512,25 +512,32 @@ queue_delayed_work(struct workqueue_stru
 
 	KASSERT(wq != NULL);
 
-	/* If we're not actually delaying, queue the work now.  */
-	if (ticks == 0) {
-		queue_work(wq, &dw->work);
-		return;
-	}
-
 	linux_work_lock(&dw->work);
 	switch (dw->work.w_state) {
 	case WORK_IDLE:
 	case WORK_INVOKED:
-		callout_init(&dw->dw_callout, CALLOUT_MPSAFE);
-		callout_reset(&dw->dw_callout, ticks, &linux_worker_intr, dw);
-		dw->work.w_state = WORK_DELAYED;
-		dw->work.w_wq = wq;
-		TAILQ_INSERT_HEAD(&wq->wq_delayed, dw, dw_entry);
+		if (ticks == 0) {
+			/* Skip the delay and queue it now.  */
+			dw->work.w_state = WORK_PENDING;
+			dw->work.w_wq = wq;
+			workqueue_enqueue(wq->wq_workqueue, &dw->work.w_wk,
+			    NULL);
+		} else {
+			callout_init(&dw->dw_callout, CALLOUT_MPSAFE);
+			callout_reset(&dw->dw_callout, ticks,
+			    &linux_worker_intr, dw);
+			dw->work.w_state = WORK_DELAYED;
+			dw->work.w_wq = wq;
+			TAILQ_INSERT_HEAD(&wq->wq_delayed, dw, dw_entry);
+		}
 		break;
 
 	case WORK_DELAYED:
-		callout_schedule(&dw->dw_callout, ticks);
+		/*
+		 * Timer is already ticking.  Leave it to time out
+		 * whenever it was going to time out, as Linux does --
+		 * neither speed it up nor postpone it.
+		 */
 		break;
 
 	case WORK_PENDING:

Reply via email to