CVS commit: src/sys/external/bsd/common/linux

2021-12-31 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Dec 31 14:30:20 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
drm: Convert noisy flush_workqueue message to dtrace probe.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/external/bsd/common/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/common/linux/linux_work.c
diff -u src/sys/external/bsd/common/linux/linux_work.c:1.59 src/sys/external/bsd/common/linux/linux_work.c:1.60
--- src/sys/external/bsd/common/linux/linux_work.c:1.59	Sun Dec 19 12:27:39 2021
+++ src/sys/external/bsd/common/linux/linux_work.c	Fri Dec 31 14:30:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.59 2021/12/19 12:27:39 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.60 2021/12/31 14:30:20 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.59 2021/12/19 12:27:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.60 2021/12/31 14:30:20 riastradh Exp $");
 
 #include 
 #include 
@@ -113,6 +113,8 @@ SDT_PROBE_DEFINE1(sdt, linux, work, batc
 "struct workqueue_struct *"/*wq*/);
 SDT_PROBE_DEFINE1(sdt, linux, work, batch__done,
 "struct workqueue_struct *"/*wq*/);
+SDT_PROBE_DEFINE1(sdt, linux, work, flush__self,
+"struct workqueue_struct *"/*wq*/);
 SDT_PROBE_DEFINE1(sdt, linux, work, flush__start,
 "struct workqueue_struct *"/*wq*/);
 SDT_PROBE_DEFINE1(sdt, linux, work, flush__done,
@@ -1458,8 +1460,7 @@ flush_workqueue(struct workqueue_struct 
 	struct flush_work fw;
 
 	if (lwp_getspecific(workqueue_key) == wq) {
-		aprint_debug("%s: running from workqueue %s\n", __func__,
-		wq->wq_name);
+		SDT_PROBE1(sdt, linux, work, flush__self,  wq);
 		return;
 	}
 



CVS commit: src/sys/external/bsd/common/linux

2021-12-31 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Dec 31 14:30:20 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
drm: Convert noisy flush_workqueue message to dtrace probe.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/sys/external/bsd/common/linux/linux_work.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-27 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Dec 27 14:57:30 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_tasklet.c

Log Message:
linux: Fix copypasto in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/external/bsd/common/linux/linux_tasklet.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/common/linux/linux_tasklet.c
diff -u src/sys/external/bsd/common/linux/linux_tasklet.c:1.9 src/sys/external/bsd/common/linux/linux_tasklet.c:1.10
--- src/sys/external/bsd/common/linux/linux_tasklet.c:1.9	Sun Dec 19 12:44:43 2021
+++ src/sys/external/bsd/common/linux/linux_tasklet.c	Mon Dec 27 14:57:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_tasklet.c,v 1.9 2021/12/19 12:44:43 riastradh Exp $	*/
+/*	$NetBSD: linux_tasklet.c,v 1.10 2021/12/27 14:57:30 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018, 2020, 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_tasklet.c,v 1.9 2021/12/19 12:44:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_tasklet.c,v 1.10 2021/12/27 14:57:30 riastradh Exp $");
 
 #include 
 #include 
@@ -482,7 +482,7 @@ tasklet_kill(struct tasklet_struct *task
 }
 
 /*
- * tasklet_is_scheduled(tasklet)
+ * tasklet_is_locked(tasklet)
  *
  *	True if tasklet is currently locked.  Caller must use it only
  *	for positive assertions.



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:40:11 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_rcu.c

Log Message:
linux: Fix rcu_barrier so it actually waits for everything.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/external/bsd/common/linux/linux_rcu.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/common/linux/linux_rcu.c
diff -u src/sys/external/bsd/common/linux/linux_rcu.c:1.6 src/sys/external/bsd/common/linux/linux_rcu.c:1.7
--- src/sys/external/bsd/common/linux/linux_rcu.c:1.6	Sun Dec 19 12:40:03 2021
+++ src/sys/external/bsd/common/linux/linux_rcu.c	Sun Dec 19 12:40:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_rcu.c,v 1.6 2021/12/19 12:40:03 riastradh Exp $	*/
+/*	$NetBSD: linux_rcu.c,v 1.7 2021/12/19 12:40:11 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.6 2021/12/19 12:40:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.7 2021/12/19 12:40:11 riastradh Exp $");
 
 #include 
 #include 
@@ -71,6 +71,7 @@ static struct {
 	struct rcu_head	*first_kfree;
 	struct lwp	*lwp;
 	uint64_t	gen;
+	bool		running;
 	bool		dying;
 } gc __cacheline_aligned;
 
@@ -152,13 +153,28 @@ rcu_barrier(void)
 {
 	uint64_t gen;
 
+	/*
+	 * If the GC isn't running anything yet, then all callbacks of
+	 * interest are queued, and it suffices to wait for the GC to
+	 * advance one generation number.
+	 *
+	 * If the GC is already running, however, and there are any
+	 * callbacks of interest queued but not in the GC's current
+	 * batch of work, then when the advances the generation number
+	 * it will not have completed the queued callbacks.  So we have
+	 * to wait for one more generation -- or until the GC has
+	 * stopped running because there's no work left.
+	 */
+
 	SDT_PROBE0(sdt, linux, rcu, barrier__start);
 	mutex_enter();
-	if (gc.first_callback != NULL || gc.first_kfree != NULL) {
-		gen = gc.gen;
-		do {
-			cv_wait(, );
-		} while (gc.gen == gen);
+	gen = gc.gen;
+	if (gc.running)
+		gen++;
+	while (gc.running || gc.first_callback || gc.first_kfree) {
+		cv_wait(, );
+		if (gc.gen > gen)
+			break;
 	}
 	mutex_exit();
 	SDT_PROBE0(sdt, linux, rcu, barrier__done);
@@ -238,7 +254,11 @@ gc_thread(void *cookie)
 			continue;
 		}
 
-		/* We have work to do.  Drop the lock to do it.  */
+		/*
+		 * We have work to do.  Drop the lock to do it, and
+		 * notify rcu_barrier that we're still doing it.
+		 */
+		gc.running = true;
 		mutex_exit();
 
 		/* Wait for activity on all CPUs.  */
@@ -275,6 +295,7 @@ gc_thread(void *cookie)
 
 		/* Finished a batch of work.  Notify rcu_barrier.  */
 		gc.gen++;
+		gc.running = false;
 		cv_broadcast();
 
 		/*



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:40:11 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_rcu.c

Log Message:
linux: Fix rcu_barrier so it actually waits for everything.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/external/bsd/common/linux/linux_rcu.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:40:03 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_rcu.c

Log Message:
linux: Rate-limit RCU GC thread as a cheap experiment.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/common/linux/linux_rcu.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/common/linux/linux_rcu.c
diff -u src/sys/external/bsd/common/linux/linux_rcu.c:1.5 src/sys/external/bsd/common/linux/linux_rcu.c:1.6
--- src/sys/external/bsd/common/linux/linux_rcu.c:1.5	Sun Dec 19 12:07:55 2021
+++ src/sys/external/bsd/common/linux/linux_rcu.c	Sun Dec 19 12:40:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_rcu.c,v 1.5 2021/12/19 12:07:55 riastradh Exp $	*/
+/*	$NetBSD: linux_rcu.c,v 1.6 2021/12/19 12:40:03 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.5 2021/12/19 12:07:55 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_rcu.c,v 1.6 2021/12/19 12:40:03 riastradh Exp $");
 
 #include 
 #include 
@@ -276,6 +276,15 @@ gc_thread(void *cookie)
 		/* Finished a batch of work.  Notify rcu_barrier.  */
 		gc.gen++;
 		cv_broadcast();
+
+		/*
+		 * Limit ourselves to one batch per tick, in an attempt
+		 * to make the batches larger.
+		 *
+		 * XXX We should maybe also limit the size of each
+		 * batch.
+		 */
+		(void)kpause("lxrcubat", /*intr*/false, /*timo*/1, );
 	}
 	KASSERT(gc.first_callback == NULL);
 	KASSERT(gc.first_kfree == NULL);



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:40:03 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_rcu.c

Log Message:
linux: Rate-limit RCU GC thread as a cheap experiment.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/common/linux/linux_rcu.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:27:40 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
linux: Downgrade warning about flushing from workqueue to debug.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/external/bsd/common/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/common/linux/linux_work.c
diff -u src/sys/external/bsd/common/linux/linux_work.c:1.58 src/sys/external/bsd/common/linux/linux_work.c:1.59
--- src/sys/external/bsd/common/linux/linux_work.c:1.58	Sun Dec 19 12:11:36 2021
+++ src/sys/external/bsd/common/linux/linux_work.c	Sun Dec 19 12:27:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.58 2021/12/19 12:11:36 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.59 2021/12/19 12:27:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.58 2021/12/19 12:11:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.59 2021/12/19 12:27:39 riastradh Exp $");
 
 #include 
 #include 
@@ -1458,7 +1458,7 @@ flush_workqueue(struct workqueue_struct 
 	struct flush_work fw;
 
 	if (lwp_getspecific(workqueue_key) == wq) {
-		printf("%s: running from workqueue %s\n", __func__,
+		aprint_debug("%s: running from workqueue %s\n", __func__,
 		wq->wq_name);
 		return;
 	}



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:27:40 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
linux: Downgrade warning about flushing from workqueue to debug.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/sys/external/bsd/common/linux/linux_work.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:11:36 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
linux: Make flush_workqueue a noop if run from the workqueue.

I think this matches Linux semantics but this is very much not clear
and not written down anywhere obvious and why is this such a
semantically incoherent mess.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/external/bsd/common/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/common/linux/linux_work.c
diff -u src/sys/external/bsd/common/linux/linux_work.c:1.57 src/sys/external/bsd/common/linux/linux_work.c:1.58
--- src/sys/external/bsd/common/linux/linux_work.c:1.57	Sun Dec 19 12:11:28 2021
+++ src/sys/external/bsd/common/linux/linux_work.c	Sun Dec 19 12:11:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.57 2021/12/19 12:11:28 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.58 2021/12/19 12:11:36 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.57 2021/12/19 12:11:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.58 2021/12/19 12:11:36 riastradh Exp $");
 
 #include 
 #include 
@@ -1457,6 +1457,12 @@ flush_workqueue(struct workqueue_struct 
 {
 	struct flush_work fw;
 
+	if (lwp_getspecific(workqueue_key) == wq) {
+		printf("%s: running from workqueue %s\n", __func__,
+		wq->wq_name);
+		return;
+	}
+
 	mutex_init(_lock, MUTEX_DEFAULT, IPL_VM);
 	cv_init(_cv, "lxwqflsh");
 	INIT_WORK(_work, _work_cb);



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:11:36 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
linux: Make flush_workqueue a noop if run from the workqueue.

I think this matches Linux semantics but this is very much not clear
and not written down anywhere obvious and why is this such a
semantically incoherent mess.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/external/bsd/common/linux/linux_work.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:11:28 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
linux: Fix flush_workqueue.

Simplify mechanism: we know there's only a single thread here that
processes scheduled work in FIFO order (no multi-CPU workqueues --
would have to adapt if there were), so just schedule a work item that
notifies of completion.  The previous mechanism of counting 0, 1, or
2 generation numbers was broken by an earlier change to avoid abuse
of tailqs arising from clever TAILQ_CONCAT.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/external/bsd/common/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/common/linux/linux_work.c
diff -u src/sys/external/bsd/common/linux/linux_work.c:1.56 src/sys/external/bsd/common/linux/linux_work.c:1.57
--- src/sys/external/bsd/common/linux/linux_work.c:1.56	Sun Dec 19 12:11:21 2021
+++ src/sys/external/bsd/common/linux/linux_work.c	Sun Dec 19 12:11:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.56 2021/12/19 12:11:21 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.57 2021/12/19 12:11:28 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.56 2021/12/19 12:11:21 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.57 2021/12/19 12:11:28 riastradh Exp $");
 
 #include 
 #include 
@@ -461,7 +461,7 @@ linux_workqueue_thread(void *cookie)
 			TAILQ_REMOVE(q[i], , work_entry);
 		}
 
-		/* Notify flush that we've completed a batch of work.  */
+		/* Notify cancel that we've completed a batch of work.  */
 		wq->wq_gen++;
 		cv_broadcast(>wq_cv);
 		SDT_PROBE1(sdt, linux, work, batch__done,  wq);
@@ -1428,46 +1428,22 @@ flush_scheduled_work(void)
 	flush_workqueue(system_wq);
 }
 
-/*
- * flush_workqueue_locked(wq)
- *
- *	Wait for all work queued on wq to complete.  This does not
- *	include delayed work.  True if there was work to be flushed,
- *	false it the queue was empty.
- *
- *	Caller must hold wq's lock.
- */
-static bool
-flush_workqueue_locked(struct workqueue_struct *wq)
-{
-	uint64_t gen;
-	bool work_queued = false;
-
-	KASSERT(mutex_owned(>wq_lock));
-
-	/* Get the current generation number.  */
-	gen = wq->wq_gen;
-
-	/*
-	 * If there's any work in progress -- whether currently running
-	 * or queued to run -- we must wait for the worker thread to
-	 * finish that batch.
-	 */
-	if (wq->wq_current_work != NULL ||
-	!TAILQ_EMPTY(>wq_queue) ||
-	!TAILQ_EMPTY(>wq_dqueue)) {
-		gen++;
-		work_queued = true;
-	}
+struct flush_work {
+	kmutex_t		fw_lock;
+	kcondvar_t		fw_cv;
+	struct work_struct	fw_work;
+	bool			fw_done;
+};
 
-	/* Wait until the generation number has caught up.  */
-	SDT_PROBE1(sdt, linux, work, flush__start,  wq);
-	while (wq->wq_gen < gen)
-		cv_wait(>wq_cv, >wq_lock);
-	SDT_PROBE1(sdt, linux, work, flush__done,  wq);
+static void
+flush_work_cb(struct work_struct *work)
+{
+	struct flush_work *fw = container_of(work, struct flush_work, fw_work);
 
-	/* Return whether we had to wait for anything.  */
-	return work_queued;
+	mutex_enter(>fw_lock);
+	fw->fw_done = true;
+	cv_broadcast(>fw_cv);
+	mutex_exit(>fw_lock);
 }
 
 /*
@@ -1479,10 +1455,26 @@ flush_workqueue_locked(struct workqueue_
 void
 flush_workqueue(struct workqueue_struct *wq)
 {
+	struct flush_work fw;
 
-	mutex_enter(>wq_lock);
-	(void)flush_workqueue_locked(wq);
-	mutex_exit(>wq_lock);
+	mutex_init(_lock, MUTEX_DEFAULT, IPL_VM);
+	cv_init(_cv, "lxwqflsh");
+	INIT_WORK(_work, _work_cb);
+	fw.fw_done = false;
+
+	SDT_PROBE1(sdt, linux, work, flush__start,  wq);
+	queue_work(wq, _work);
+
+	mutex_enter(_lock);
+	while (!fw.fw_done)
+		cv_wait(_cv, _lock);
+	mutex_exit(_lock);
+	SDT_PROBE1(sdt, linux, work, flush__done,  wq);
+
+	KASSERT(fw.fw_done);
+	/* no DESTROY_WORK */
+	cv_destroy(_cv);
+	mutex_destroy(_lock);
 }
 
 /*
@@ -1494,15 +1486,20 @@ void
 drain_workqueue(struct workqueue_struct *wq)
 {
 	unsigned ntries = 0;
+	bool done;
 
-	mutex_enter(>wq_lock);
-	while (flush_workqueue_locked(wq)) {
+	do {
 		if (ntries++ == 10 || (ntries % 100) == 0)
 			printf("linux workqueue %s"
 			": still clogged after %u flushes",
 			wq->wq_name, ntries);
-	}
-	mutex_exit(>wq_lock);
+		flush_workqueue(wq);
+		mutex_enter(>wq_lock);
+		done = wq->wq_current_work == NULL;
+		done &= TAILQ_EMPTY(>wq_queue);
+		done &= TAILQ_EMPTY(>wq_dqueue);
+		mutex_exit(>wq_lock);
+	} while (!done);
 }
 
 /*
@@ -1599,7 +1596,9 @@ flush_delayed_work(struct delayed_work *
 		 * Waiting for the whole queue to flush is overkill,
 		 * but doesn't hurt.
 		 */
-		(void)flush_workqueue_locked(wq);
+		mutex_exit(>wq_lock);
+		flush_workqueue(wq);
+		mutex_enter(>wq_lock);
 		waited = true;
 	}
 	mutex_exit(>wq_lock);



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:11:28 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
linux: Fix flush_workqueue.

Simplify mechanism: we know there's only a single thread here that
processes scheduled work in FIFO order (no multi-CPU workqueues --
would have to adapt if there were), so just schedule a work item that
notifies of completion.  The previous mechanism of counting 0, 1, or
2 generation numbers was broken by an earlier change to avoid abuse
of tailqs arising from clever TAILQ_CONCAT.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/external/bsd/common/linux/linux_work.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:11:21 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
linux: Update workqueue flush to reflect TAILQ_CONCAT change.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/external/bsd/common/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/common/linux/linux_work.c
diff -u src/sys/external/bsd/common/linux/linux_work.c:1.55 src/sys/external/bsd/common/linux/linux_work.c:1.56
--- src/sys/external/bsd/common/linux/linux_work.c:1.55	Sun Dec 19 11:40:14 2021
+++ src/sys/external/bsd/common/linux/linux_work.c	Sun Dec 19 12:11:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.55 2021/12/19 11:40:14 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.56 2021/12/19 12:11:21 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.55 2021/12/19 11:40:14 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.56 2021/12/19 12:11:21 riastradh Exp $");
 
 #include 
 #include 
@@ -1449,20 +1449,13 @@ flush_workqueue_locked(struct workqueue_
 	gen = wq->wq_gen;
 
 	/*
-	 * If there's a batch of work in progress, we must wait for the
-	 * worker thread to finish that batch.
+	 * If there's any work in progress -- whether currently running
+	 * or queued to run -- we must wait for the worker thread to
+	 * finish that batch.
 	 */
-	if (wq->wq_current_work != NULL) {
-		gen++;
-		work_queued = true;
-	}
-
-	/*
-	 * If there's any work yet to be claimed from the queue by the
-	 * worker thread, we must wait for it to finish one more batch
-	 * too.
-	 */
-	if (!TAILQ_EMPTY(>wq_queue) || !TAILQ_EMPTY(>wq_dqueue)) {
+	if (wq->wq_current_work != NULL ||
+	!TAILQ_EMPTY(>wq_queue) ||
+	!TAILQ_EMPTY(>wq_dqueue)) {
 		gen++;
 		work_queued = true;
 	}



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 12:11:21 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
linux: Update workqueue flush to reflect TAILQ_CONCAT change.


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/external/bsd/common/linux/linux_work.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 11:57:34 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_tasklet.c

Log Message:
linux: Use indirection for percpu simpleq.

Simpleq requires pointers into the head to work, but percpu(9) may
move objects around, so we have to allocate the simpleq head
separately with kmem(9).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/external/bsd/common/linux/linux_tasklet.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/common/linux/linux_tasklet.c
diff -u src/sys/external/bsd/common/linux/linux_tasklet.c:1.7 src/sys/external/bsd/common/linux/linux_tasklet.c:1.8
--- src/sys/external/bsd/common/linux/linux_tasklet.c:1.7	Sun Dec 19 11:49:11 2021
+++ src/sys/external/bsd/common/linux/linux_tasklet.c	Sun Dec 19 11:57:34 2021
@@ -1,7 +1,7 @@
-/*	$NetBSD: linux_tasklet.c,v 1.7 2021/12/19 11:49:11 riastradh Exp $	*/
+/*	$NetBSD: linux_tasklet.c,v 1.8 2021/12/19 11:57:34 riastradh Exp $	*/
 
 /*-
- * Copyright (c) 2018, 2020 The NetBSD Foundation, Inc.
+ * Copyright (c) 2018, 2020, 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -30,13 +30,14 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_tasklet.c,v 1.7 2021/12/19 11:49:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_tasklet.c,v 1.8 2021/12/19 11:57:34 riastradh Exp $");
 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -51,7 +52,7 @@ __KERNEL_RCSID(0, "$NetBSD: linux_taskle
 #define	TASKLET_RUNNING		((unsigned)__BIT(1))
 
 struct tasklet_queue {
-	struct percpu	*tq_percpu;	/* struct tasklet_cpu */
+	struct percpu	*tq_percpu;	/* struct tasklet_cpu * */
 	void		*tq_sih;
 };
 
@@ -114,6 +115,25 @@ linux_tasklets_fini(void)
 	tasklet_queue_fini(_queue);
 }
 
+static void
+tasklet_cpu_init(void *ptr, void *cookie, struct cpu_info *ci)
+{
+	struct tasklet_cpu **tcp = ptr, *tc;
+
+	*tcp = tc = kmem_zalloc(sizeof(*tc), KM_SLEEP);
+	SIMPLEQ_INIT(>tc_head);
+}
+
+static void
+tasklet_cpu_fini(void *ptr, void *cookie, struct cpu_info *ci)
+{
+	struct tasklet_cpu **tcp = ptr, *tc = *tcp;
+
+	KASSERT(SIMPLEQ_EMPTY(>tc_head));
+	kmem_free(tc, sizeof(*tc));
+	*tcp = NULL;		/* paranoia */
+}
+
 /*
  * tasklet_queue_init(tq, prio)
  *
@@ -126,7 +146,8 @@ tasklet_queue_init(struct tasklet_queue 
 	int error;
 
 	/* Allocate per-CPU memory.  percpu_alloc cannot fail.  */
-	tq->tq_percpu = percpu_alloc(sizeof(struct tasklet_cpu));
+	tq->tq_percpu = percpu_create(sizeof(struct tasklet_cpu),
+	tasklet_cpu_init, tasklet_cpu_fini, NULL);
 	KASSERT(tq->tq_percpu != NULL);
 
 	/* Try to establish a softint.  softint_establish may fail.  */
@@ -177,7 +198,7 @@ tasklet_softintr(void *cookie)
 {
 	struct tasklet_queue *const tq = cookie;
 	struct tasklet_head th = SIMPLEQ_HEAD_INITIALIZER(th);
-	struct tasklet_cpu *tc;
+	struct tasklet_cpu **tcp, *tc;
 	int s;
 
 	/*
@@ -186,7 +207,8 @@ tasklet_softintr(void *cookie)
 	 *
 	 * No memory barriers: CPU-local state only.
 	 */
-	tc = percpu_getref(tq->tq_percpu);
+	tcp = percpu_getref(tq->tq_percpu);
+	tc = *tcp;
 	s = splhigh();
 	SIMPLEQ_CONCAT(, >tc_head);
 	splx(s);
@@ -282,7 +304,7 @@ tasklet_queue_schedule(struct tasklet_qu
 static void
 tasklet_queue_enqueue(struct tasklet_queue *tq, struct tasklet_struct *tasklet)
 {
-	struct tasklet_cpu *tc;
+	struct tasklet_cpu **tcp, *tc;
 	int s;
 
 	KASSERT(atomic_load_relaxed(>tl_state) & TASKLET_SCHEDULED);
@@ -292,7 +314,8 @@ tasklet_queue_enqueue(struct tasklet_que
 	 * blocked, and schedule a soft interrupt to process it.  No
 	 * memory barriers: CPU-local state only.
 	 */
-	tc = percpu_getref(tq->tq_percpu);
+	tcp = percpu_getref(tq->tq_percpu);
+	tc = *tcp;
 	s = splhigh();
 	SIMPLEQ_INSERT_TAIL(>tc_head, tasklet, tl_entry);
 	splx(s);



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 11:57:34 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_tasklet.c

Log Message:
linux: Use indirection for percpu simpleq.

Simpleq requires pointers into the head to work, but percpu(9) may
move objects around, so we have to allocate the simpleq head
separately with kmem(9).


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/external/bsd/common/linux/linux_tasklet.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 11:40:05 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
linux/workqueue: Use atomic_load/store.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/external/bsd/common/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/common/linux/linux_work.c
diff -u src/sys/external/bsd/common/linux/linux_work.c:1.53 src/sys/external/bsd/common/linux/linux_work.c:1.54
--- src/sys/external/bsd/common/linux/linux_work.c:1.53	Sun Dec 19 11:38:03 2021
+++ src/sys/external/bsd/common/linux/linux_work.c	Sun Dec 19 11:40:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.53 2021/12/19 11:38:03 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.54 2021/12/19 11:40:05 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.53 2021/12/19 11:38:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.54 2021/12/19 11:40:05 riastradh Exp $");
 
 #include 
 #include 
@@ -565,7 +565,7 @@ work_claimed(struct work_struct *work, s
 	KASSERT(work_queue(work) == wq);
 	KASSERT(mutex_owned(>wq_lock));
 
-	return work->work_owner & 1;
+	return atomic_load_relaxed(>work_owner) & 1;
 }
 
 /*
@@ -578,7 +578,7 @@ bool
 work_pending(const struct work_struct *work)
 {
 
-	return work->work_owner & 1;
+	return atomic_load_relaxed(>work_owner) & 1;
 }
 
 /*
@@ -591,7 +591,8 @@ static struct workqueue_struct *
 work_queue(struct work_struct *work)
 {
 
-	return (struct workqueue_struct *)(work->work_owner & ~(uintptr_t)1);
+	return (struct workqueue_struct *)
+	(atomic_load_relaxed(>work_owner) & ~(uintptr_t)1);
 }
 
 /*
@@ -614,7 +615,7 @@ acquire_work(struct work_struct *work, s
 
 	owner = (uintptr_t)wq | 1;
 	do {
-		owner0 = work->work_owner;
+		owner0 = atomic_load_relaxed(>work_owner);
 		if (owner0 & 1) {
 			KASSERT((owner0 & ~(uintptr_t)1) == (uintptr_t)wq);
 			return false;
@@ -649,10 +650,11 @@ release_work(struct work_struct *work, s
 
 	/*
 	 * Non-interlocked r/m/w is safe here because nobody else can
-	 * write to this while the claimed bit is setand the workqueue
+	 * write to this while the claimed bit is set and the workqueue
 	 * lock is held.
 	 */
-	work->work_owner &= ~(uintptr_t)1;
+	atomic_store_relaxed(>work_owner,
+	atomic_load_relaxed(>work_owner) & ~(uintptr_t)1);
 }
 
 /*



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 11:40:05 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
linux/workqueue: Use atomic_load/store.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/external/bsd/common/linux/linux_work.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 11:20:33 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_srcu.c

Log Message:
'struct srcu' is actually called 'struct srcu_struct'

Author: Iain Hibbert 
Committer: Taylor R Campbell 


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/common/linux/linux_srcu.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/common/linux/linux_srcu.c
diff -u src/sys/external/bsd/common/linux/linux_srcu.c:1.2 src/sys/external/bsd/common/linux/linux_srcu.c:1.3
--- src/sys/external/bsd/common/linux/linux_srcu.c:1.2	Sun Dec 19 01:46:01 2021
+++ src/sys/external/bsd/common/linux/linux_srcu.c	Sun Dec 19 11:20:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_srcu.c,v 1.2 2021/12/19 01:46:01 riastradh Exp $	*/
+/*	$NetBSD: linux_srcu.c,v 1.3 2021/12/19 11:20:33 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_srcu.c,v 1.2 2021/12/19 01:46:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_srcu.c,v 1.3 2021/12/19 11:20:33 riastradh Exp $");
 
 /*
  * SRCU: Sleepable RCU
@@ -84,7 +84,7 @@ struct srcu_cpu {
  *	May sleep.
  */
 void
-srcu_init(struct srcu *srcu, const char *name)
+srcu_init(struct srcu_struct *srcu, const char *name)
 {
 
 	ASSERT_SLEEPABLE();
@@ -107,7 +107,7 @@ srcu_init(struct srcu *srcu, const char 
  *	May sleep.
  */
 void
-srcu_fini(struct srcu *srcu)
+srcu_fini(struct srcu_struct *srcu)
 {
 
 	ASSERT_SLEEPABLE();
@@ -129,7 +129,7 @@ srcu_fini(struct srcu *srcu)
  *	Never sleeps.
  */
 static void
-srcu_adjust(struct srcu *srcu, unsigned gen, int delta)
+srcu_adjust(struct srcu_struct *srcu, unsigned gen, int delta)
 {
 	struct srcu_cpu *cpu;
 	unsigned epoch = gen & 1; /* active epoch */
@@ -149,7 +149,7 @@ srcu_adjust(struct srcu *srcu, unsigned 
  *	Never sleeps.
  */
 int
-srcu_read_lock(struct srcu *srcu)
+srcu_read_lock(struct srcu_struct *srcu)
 {
 	unsigned gen;
 
@@ -181,7 +181,7 @@ srcu_read_lock(struct srcu *srcu)
  *	Never sleeps.
  */
 void
-srcu_read_unlock(struct srcu *srcu, int ticket)
+srcu_read_unlock(struct srcu_struct *srcu, int ticket)
 {
 	unsigned gen = ticket;
 
@@ -227,7 +227,7 @@ srcu_read_unlock(struct srcu *srcu, int 
 /*
  * synchronize_srcu_xc(a, b)
  *
- *	Cross-call function for synchronize_srcu: a is the struct srcu
+ *	Cross-call function for synchronize_srcu: a is the struct srcu_struct
  *	pointer; b is ignored.  Transfer the local count of srcu
  *	readers on this CPU in the inactive epoch to the global count
  *	under the srcu sync lock.
@@ -235,7 +235,7 @@ srcu_read_unlock(struct srcu *srcu, int 
 static void
 synchronize_srcu_xc(void *a, void *b)
 {
-	struct srcu *srcu = a;
+	struct srcu_struct *srcu = a;
 	struct srcu_cpu *cpu;
 	unsigned gen, epoch;
 	uint64_t local;
@@ -266,7 +266,7 @@ synchronize_srcu_xc(void *a, void *b)
  *	May sleep.  (Practically guaranteed to sleep!)
  */
 void
-synchronize_srcu(struct srcu *srcu)
+synchronize_srcu(struct srcu_struct *srcu)
 {
 
 	ASSERT_SLEEPABLE();



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 11:20:33 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_srcu.c

Log Message:
'struct srcu' is actually called 'struct srcu_struct'

Author: Iain Hibbert 
Committer: Taylor R Campbell 


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/common/linux/linux_srcu.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 11:04:58 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_tasklet.c

Log Message:
Fix membars in tasklet_disable/enable.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/common/linux/linux_tasklet.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/common/linux/linux_tasklet.c
diff -u src/sys/external/bsd/common/linux/linux_tasklet.c:1.5 src/sys/external/bsd/common/linux/linux_tasklet.c:1.6
--- src/sys/external/bsd/common/linux/linux_tasklet.c:1.5	Sun Dec 19 11:03:18 2021
+++ src/sys/external/bsd/common/linux/linux_tasklet.c	Sun Dec 19 11:04:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_tasklet.c,v 1.5 2021/12/19 11:03:18 riastradh Exp $	*/
+/*	$NetBSD: linux_tasklet.c,v 1.6 2021/12/19 11:04:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_tasklet.c,v 1.5 2021/12/19 11:03:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_tasklet.c,v 1.6 2021/12/19 11:04:58 riastradh Exp $");
 
 #include 
 #include 
@@ -373,6 +373,11 @@ tasklet_disable(struct tasklet_struct *t
 	KASSERT(disablecount < UINT_MAX);
 	KASSERT(disablecount != 0);
 
+	/* Pairs with membar_exit in __tasklet_enable.  */
+#ifndef __HAVE_ATOMIC_AS_MEMBAR
+	membar_enter();
+#endif
+
 	/* Wait for it to finish running, if it was running.  */
 	tasklet_unlock_wait(tasklet);
 }
@@ -457,13 +462,17 @@ tasklet_trylock(struct tasklet_struct *t
 	unsigned state;
 
 	do {
-		/* Pairs with membar_exit in tasklet_unlock.  */
-		state = atomic_load_acquire(>tl_state);
+		state = atomic_load_relaxed(>tl_state);
 		if (state & TASKLET_RUNNING)
 			return false;
 	} while (atomic_cas_uint(>tl_state, state,
 		state | TASKLET_RUNNING) != state);
 
+	/* Pairs with membar_exit in tasklet_unlock.  */
+#ifndef __HAVE_ATOMIC_AS_MEMBAR
+	membar_enter();
+#endif
+
 	return true;
 }
 
@@ -481,8 +490,8 @@ tasklet_unlock(struct tasklet_struct *ta
 	KASSERT(atomic_load_relaxed(>tl_state) & TASKLET_RUNNING);
 
 	/*
-	 * Pairs with atomic_load_acquire in tasklet_trylock and
-	 * tasklet_unlock.
+	 * Pairs with membar_enter in tasklet_trylock and with
+	 * atomic_load_acquire in tasklet_unlock_wait.
 	 */
 #ifndef __HAVE_ATOMIC_AS_MEMBAR
 	membar_exit();
@@ -534,6 +543,11 @@ __tasklet_disable_sync_once(struct taskl
 	KASSERT(disablecount < UINT_MAX);
 	KASSERT(disablecount != 0);
 
+	/* Pairs with membar_exit in __tasklet_enable_sync_once.  */
+#ifndef __HAVE_ATOMIC_AS_MEMBAR
+	membar_enter();
+#endif
+
 	/*
 	 * If it was zero, wait for it to finish running.  If it was
 	 * not zero, caller must not care whether it was running.
@@ -553,6 +567,11 @@ __tasklet_enable_sync_once(struct taskle
 {
 	unsigned int disablecount;
 
+	/* Pairs with membar_enter in __tasklet_disable_sync_once.  */
+#ifndef __HAVE_ATOMIC_AS_MEMBAR
+	membar_exit();
+#endif
+
 	/* Decrement the disable count.  */
 	disablecount = atomic_dec_uint_nv(>tl_disablecount);
 	KASSERT(disablecount < UINT_MAX);
@@ -615,8 +634,8 @@ __tasklet_enable(struct tasklet_struct *
 	 * before potentially allowing tasklet to run again by
 	 * decrementing the disable count.
 	 *
-	 * Pairs with atomic_load_acquire(>tl_disablecount) in
-	 * tasklet_softintr.
+	 * Pairs with atomic_load_acquire in tasklet_softintr and with
+	 * membar_enter in tasklet_disable.
 	 */
 #ifndef __HAVE_ATOMIC_AS_MEMBAR
 	membar_exit();



CVS commit: src/sys/external/bsd/common/linux

2021-12-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 11:04:58 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_tasklet.c

Log Message:
Fix membars in tasklet_disable/enable.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/common/linux/linux_tasklet.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 01:17:39 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_tasklet.c

Log Message:
Sprinkle in another assertion for good measure.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/external/bsd/common/linux/linux_tasklet.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/common/linux/linux_tasklet.c
diff -u src/sys/external/bsd/common/linux/linux_tasklet.c:1.1 src/sys/external/bsd/common/linux/linux_tasklet.c:1.2
--- src/sys/external/bsd/common/linux/linux_tasklet.c:1.1	Sun Dec 19 01:17:14 2021
+++ src/sys/external/bsd/common/linux/linux_tasklet.c	Sun Dec 19 01:17:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_tasklet.c,v 1.1 2021/12/19 01:17:14 riastradh Exp $	*/
+/*	$NetBSD: linux_tasklet.c,v 1.2 2021/12/19 01:17:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_tasklet.c,v 1.1 2021/12/19 01:17:14 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_tasklet.c,v 1.2 2021/12/19 01:17:39 riastradh Exp $");
 
 #include 
 #include 
@@ -382,6 +382,7 @@ tasklet_disable(struct tasklet_struct *t
 	/* Increment the disable count.  */
 	disablecount = atomic_inc_uint_nv(>tl_disablecount);
 	KASSERT(disablecount < UINT_MAX);
+	KASSERT(disablecount != 0);
 
 	/* Wait for it to finish running, if it was running.  */
 	while (tasklet->tl_state & TASKLET_RUNNING)



CVS commit: src/sys/external/bsd/common/linux

2021-12-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 01:17:39 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_tasklet.c

Log Message:
Sprinkle in another assertion for good measure.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/external/bsd/common/linux/linux_tasklet.c

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



CVS commit: src/sys/external/bsd/common/linux

2021-12-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 00:48:53 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
Fix copypasta in error branch.

XXX pullup to HEAD


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/external/bsd/common/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/common/linux/linux_work.c
diff -u src/sys/external/bsd/common/linux/linux_work.c:1.45 src/sys/external/bsd/common/linux/linux_work.c:1.46
--- src/sys/external/bsd/common/linux/linux_work.c:1.45	Sat Feb  1 22:38:05 2020
+++ src/sys/external/bsd/common/linux/linux_work.c	Sun Dec 19 00:48:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_work.c,v 1.45 2020/02/01 22:38:05 riastradh Exp $	*/
+/*	$NetBSD: linux_work.c,v 1.46 2021/12/19 00:48:53 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.45 2020/02/01 22:38:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.46 2021/12/19 00:48:53 riastradh Exp $");
 
 #include 
 #include 
@@ -155,7 +155,7 @@ linux_workqueue_init0(void)
 	}
 
 	system_power_efficient_wq = alloc_ordered_workqueue("lnxpwrwq", 0);
-	if (system_long_wq == NULL) {
+	if (system_power_efficient_wq == NULL) {
 		error = ENOMEM;
 		goto fail3;
 	}



CVS commit: src/sys/external/bsd/common/linux

2021-12-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Dec 19 00:48:53 UTC 2021

Modified Files:
src/sys/external/bsd/common/linux: linux_work.c

Log Message:
Fix copypasta in error branch.

XXX pullup to HEAD


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/external/bsd/common/linux/linux_work.c

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