Source-Changes-HG archive

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

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



details:   https://anonhg.NetBSD.org/src-all/rev/eb50202b0d36
branches:  trunk
changeset: 936596:eb50202b0d36
user:      Taylor R Campbell <riastradh%NetBSD.org@localhost>
date:      Fri Jul 31 18:18:17 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.

diffstat:

 share/man/man9/workqueue.9 |  5 +++++
 sys/kern/subr_workqueue.c  |  5 +++++
 sys/sys/workqueue.h        |  1 +
 3 files changed, 11 insertions(+), 0 deletions(-)

diffs (52 lines):

diff -r ea7314ad86ed -r eb50202b0d36 share/man/man9/workqueue.9
--- a/share/man/man9/workqueue.9        Fri Jul 31 03:14:59 2020 +0000
+++ b/share/man/man9/workqueue.9        Fri Jul 31 18:18:17 2020 +0000
@@ -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 ea7314ad86ed -r eb50202b0d36 sys/kern/subr_workqueue.c
--- a/sys/kern/subr_workqueue.c Fri Jul 31 03:14:59 2020 +0000
+++ b/sys/kern/subr_workqueue.c Fri Jul 31 18:18:17 2020 +0000
@@ -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 ea7314ad86ed -r eb50202b0d36 sys/sys/workqueue.h
--- a/sys/sys/workqueue.h       Fri Jul 31 03:14:59 2020 +0000
+++ b/sys/sys/workqueue.h       Fri Jul 31 18:18:17 2020 +0000
@@ -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