Module Name: src Committed By: riastradh Date: Sat Aug 1 02:14:43 UTC 2020
Modified Files: src/share/man/man9: workqueue.9 src/sys/kern: subr_workqueue.c src/sys/sys: workqueue.h Log Message: New workqueue flag WQ_FPU. Arranges kthread_fpu_enter/exit around calls to the worker. Saves cost over explicit calls to kthread_fpu_enter/exit in the worker by only doing it once, since there's often a high cost to flushing the icache and zeroing the fpu registers. As proposed on tech-kern: https://mail-index.netbsd.org/tech-kern/2020/06/20/msg026524.html To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/share/man/man9/workqueue.9 cvs rdiff -u -r1.37 -r1.38 src/sys/kern/subr_workqueue.c cvs rdiff -u -r1.10 -r1.11 src/sys/sys/workqueue.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/man/man9/workqueue.9 diff -u src/share/man/man9/workqueue.9:1.12 src/share/man/man9/workqueue.9:1.13 --- src/share/man/man9/workqueue.9:1.12 Thu Dec 28 07:00:52 2017 +++ src/share/man/man9/workqueue.9 Sat Aug 1 02:14:43 2020 @@ -1,4 +1,4 @@ -.\" $NetBSD: workqueue.9,v 1.12 2017/12/28 07:00:52 ozaki-r Exp $ +.\" $NetBSD: workqueue.9,v 1.13 2020/08/01 02:14:43 riastradh Exp $ .\" .\" Copyright (c)2005 YAMAMOTO Takashi, .\" All rights reserved. @@ -83,6 +83,11 @@ The highest IPL at which this workqueue The value of 0 indicates a standard create operation, however the following flags may be bitwise ORed together: .Bl -tag -width WQ_MPSAFE +.It Dv WQ_FPU +Specifies that the kthread must be allowed to use any machine-dependent +per-CPU floating-point units or SIMD vector units, as in +.Xr kthread_fpu_enter 9 / Xr kthread_fpu_exit 9 , +when it executes the worker function.u .It Dv WQ_MPSAFE Specifies that the workqueue is multiprocessor safe and does its own locking; otherwise the kernel lock will be held while processing work. Index: src/sys/kern/subr_workqueue.c diff -u src/sys/kern/subr_workqueue.c:1.37 src/sys/kern/subr_workqueue.c:1.38 --- src/sys/kern/subr_workqueue.c:1.37 Wed Jun 13 05:26:12 2018 +++ src/sys/kern/subr_workqueue.c Sat Aug 1 02:14:43 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_workqueue.c,v 1.37 2018/06/13 05:26:12 ozaki-r Exp $ */ +/* $NetBSD: subr_workqueue.c,v 1.38 2020/08/01 02:14:43 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.37 2018/06/13 05:26:12 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_workqueue.c,v 1.38 2020/08/01 02:14:43 riastradh Exp $"); #include <sys/param.h> #include <sys/cpu.h> @@ -112,10 +112,13 @@ workqueue_worker(void *cookie) { struct workqueue *wq = cookie; struct workqueue_queue *q; + int s; /* find the workqueue of this kthread */ q = workqueue_queue_lookup(wq, curlwp->l_cpu); + if (wq->wq_flags & WQ_FPU) + s = kthread_fpu_enter(); for (;;) { /* * we violate abstraction of SIMPLEQ. @@ -141,6 +144,8 @@ workqueue_worker(void *cookie) } mutex_exit(&q->q_mutex); } + if (wq->wq_flags & WQ_FPU) + kthread_fpu_exit(s); } static void Index: src/sys/sys/workqueue.h diff -u src/sys/sys/workqueue.h:1.10 src/sys/sys/workqueue.h:1.11 --- src/sys/sys/workqueue.h:1.10 Thu Dec 28 07:00:52 2017 +++ src/sys/sys/workqueue.h Sat Aug 1 02:14:43 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: workqueue.h,v 1.10 2017/12/28 07:00:52 ozaki-r Exp $ */ +/* $NetBSD: workqueue.h,v 1.11 2020/08/01 02:14:43 riastradh Exp $ */ /*- * Copyright (c)2002, 2005 YAMAMOTO Takashi, @@ -47,6 +47,7 @@ struct workqueue; #define WQ_MPSAFE 0x01 #define WQ_PERCPU 0x02 +#define WQ_FPU 0x04 int workqueue_create(struct workqueue **, const char *, void (*)(struct work *, void *), void *, pri_t, int, int);