Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/sys New workqueue flag WQ_FPU.



details:   https://anonhg.NetBSD.org/src/rev/403d8d7f2107
branches:  trunk
changeset: 936629:403d8d7f2107
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Aug 01 02:14:43 2020 +0000

description:
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

diffstat:

 share/man/man9/workqueue.9 |  7 ++++++-
 sys/kern/subr_workqueue.c  |  9 +++++++--
 sys/sys/workqueue.h        |  3 ++-
 3 files changed, 15 insertions(+), 4 deletions(-)

diffs (79 lines):

diff -r 2411aef29e75 -r 403d8d7f2107 share/man/man9/workqueue.9
--- a/share/man/man9/workqueue.9        Sat Aug 01 02:13:34 2020 +0000
+++ b/share/man/man9/workqueue.9        Sat Aug 01 02:14:43 2020 +0000
@@ -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 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.
diff -r 2411aef29e75 -r 403d8d7f2107 sys/kern/subr_workqueue.c
--- a/sys/kern/subr_workqueue.c Sat Aug 01 02:13:34 2020 +0000
+++ b/sys/kern/subr_workqueue.c Sat Aug 01 02:14:43 2020 +0000
@@ -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 @@
 {
        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 @@
                }
                mutex_exit(&q->q_mutex);
        }
+       if (wq->wq_flags & WQ_FPU)
+               kthread_fpu_exit(s);
 }
 
 static void
diff -r 2411aef29e75 -r 403d8d7f2107 sys/sys/workqueue.h
--- a/sys/sys/workqueue.h       Sat Aug 01 02:13:34 2020 +0000
+++ b/sys/sys/workqueue.h       Sat Aug 01 02:14:43 2020 +0000
@@ -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 @@
 
 #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);



Home | Main Index | Thread Index | Old Index