Module Name: src Committed By: riastradh Date: Wed Aug 9 08:23:45 UTC 2023
Modified Files: src/sys/kern: subr_workqueue.c Log Message: workqueue(9): Avoid unnecessary mutex_exit/enter cycle each loop. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/sys/kern/subr_workqueue.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/kern/subr_workqueue.c diff -u src/sys/kern/subr_workqueue.c:1.44 src/sys/kern/subr_workqueue.c:1.45 --- src/sys/kern/subr_workqueue.c:1.44 Wed Aug 9 08:23:35 2023 +++ src/sys/kern/subr_workqueue.c Wed Aug 9 08:23:45 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_workqueue.c,v 1.44 2023/08/09 08:23:35 riastradh Exp $ */ +/* $NetBSD: subr_workqueue.c,v 1.45 2023/08/09 08:23:45 riastradh Exp $ */ /*- * Copyright (c)2002, 2005, 2006, 2007 YAMAMOTO Takashi, @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_workqueue.c,v 1.44 2023/08/09 08:23:35 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_workqueue.c,v 1.45 2023/08/09 08:23:45 riastradh Exp $"); #include <sys/param.h> #include <sys/cpu.h> @@ -162,12 +162,12 @@ workqueue_worker(void *cookie) if (wq->wq_flags & WQ_FPU) s = kthread_fpu_enter(); + mutex_enter(&q->q_mutex); for (;;) { struct workqhead tmp; SIMPLEQ_INIT(&tmp); - mutex_enter(&q->q_mutex); while (SIMPLEQ_EMPTY(&q->q_queue_pending)) cv_wait(&q->q_cv, &q->q_mutex); SIMPLEQ_CONCAT(&tmp, &q->q_queue_pending); @@ -190,8 +190,8 @@ workqueue_worker(void *cookie) KASSERTMSG(q->q_gen & 1, "q=%p gen=%"PRIu64, q, q->q_gen); q->q_gen++; cv_broadcast(&q->q_cv); - mutex_exit(&q->q_mutex); } + mutex_exit(&q->q_mutex); if (wq->wq_flags & WQ_FPU) kthread_fpu_exit(s); }