Source-Changes-HG archive

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

[src/trunk]: src/sys/net wg: Use RUN_ONCE to defer workqueue_create until aft...



details:   https://anonhg.NetBSD.org/src/rev/ed9b0477dc61
branches:  trunk
changeset: 976154:ed9b0477dc61
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Sep 13 17:18:13 2020 +0000

description:
wg: Use RUN_ONCE to defer workqueue_create until after configure.

Should really fix workqueue(9) so workqueue_create can be done before
CPUs have been detected in configure, but this will serve as a stop-
gap measure.

diffstat:

 sys/net/if_wg.c |  33 +++++++++++++++++++++++++++++----
 1 files changed, 29 insertions(+), 4 deletions(-)

diffs (81 lines):

diff -r 007aa7c74ef1 -r ed9b0477dc61 sys/net/if_wg.c
--- a/sys/net/if_wg.c   Sun Sep 13 17:17:31 2020 +0000
+++ b/sys/net/if_wg.c   Sun Sep 13 17:18:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wg.c,v 1.57 2020/09/13 17:17:31 riastradh Exp $     */
+/*     $NetBSD: if_wg.c,v 1.58 2020/09/13 17:18:13 riastradh Exp $     */
 
 /*
  * Copyright (C) Ryota Ozaki <ozaki.ryota%gmail.com@localhost>
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.57 2020/09/13 17:17:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.58 2020/09/13 17:18:13 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -64,6 +64,7 @@
 #include <sys/mbuf.h>
 #include <sys/module.h>
 #include <sys/mutex.h>
+#include <sys/once.h>
 #include <sys/percpu.h>
 #include <sys/pserialize.h>
 #include <sys/psref.h>
@@ -807,13 +808,25 @@
 static void
 wginit(void)
 {
-       int error __diagused;
 
        wg_psref_class = psref_class_create("wg", IPL_SOFTNET);
 
        mutex_init(&wg_softcs.lock, MUTEX_DEFAULT, IPL_NONE);
        LIST_INIT(&wg_softcs.list);
 
+       if_clone_attach(&wg_cloner);
+}
+
+/*
+ * XXX Kludge: This should just happen in wginit, but workqueue_create
+ * cannot be run until after CPUs have been detected, and wginit runs
+ * before configure.
+ */
+static int
+wginitqueues(void)
+{
+       int error __diagused;
+
        wg_pktq = pktq_create(IFQ_MAXLEN, wgintr, NULL);
        KASSERT(wg_pktq != NULL);
 
@@ -821,7 +834,17 @@
            PRI_NONE, IPL_SOFTNET, WQ_MPSAFE|WQ_PERCPU);
        KASSERT(error == 0);
 
-       if_clone_attach(&wg_cloner);
+       return 0;
+}
+
+static void
+wg_guarantee_initialized(void)
+{
+       static ONCE_DECL(init);
+       int error __diagused;
+
+       error = RUN_ONCE(&init, wginitqueues);
+       KASSERT(error == 0);
 }
 
 static int
@@ -3530,6 +3553,8 @@
        struct wg_softc *wg;
        int error;
 
+       wg_guarantee_initialized();
+
        wg = kmem_zalloc(sizeof(*wg), KM_SLEEP);
 
        if_initname(&wg->wg_if, ifc->ifc_name, unit);



Home | Main Index | Thread Index | Old Index