summaryrefslogtreecommitdiffstats
path: root/sys/net/netisr.c
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2004-08-28 15:11:13 +0000
committerrwatson <rwatson@FreeBSD.org>2004-08-28 15:11:13 +0000
commit69e658ec5ae80337e0ce0fd7124b7a4344161a9c (patch)
tree6ad9ef1cb5054a0cc25ff444831031fb77cb783f /sys/net/netisr.c
parentbb60ef092768837ab9067cd484bec4f3c179c5a5 (diff)
downloadFreeBSD-src-69e658ec5ae80337e0ce0fd7124b7a4344161a9c.zip
FreeBSD-src-69e658ec5ae80337e0ce0fd7124b7a4344161a9c.tar.gz
Change the default disposition of debug.mpsafenet from 0 to 1, which
will cause the network stack to operate without the Giant lock by default. This change has the potential to improve performance by increasing parallelism and decreasing latency in network processing. Due to the potential exposure of existing or new bugs, the following compatibility functionality is maintained: - It is still possible to disable Giant-free operation by setting debug.mpsafenet to 0 in loader.conf. - Add "options NET_WITH_GIANT", which will restore the default value of debug.mpsafenet to 0, and is intended for use on systems compiled with known unsafe components, or where a more conservative configuration is desired. - Add a new declaration, NET_NEEDS_GIANT("componentname"), which permits kernel components to declare dependence on Giant over the network stack. If the declaration is made by a preloaded module or a compiled in component, the disposition of debug.mpsafenet will be set to 0 and a warning concerning performance degraded operation printed to the console. If it is declared by a loadable kernel module after boot, a warning is displayed but the disposition cannot be changed. This is implemented by defining a new SYSINIT() value, SI_SUB_SETTINGS, which is intended for the processing of configuration choices after tunables are read in and the console is available to generate errors, but before much else gets going. This compatibility behavior will go away when we've finished the last of the locking work and are confident that operation is correct.
Diffstat (limited to 'sys/net/netisr.c')
-rw-r--r--sys/net/netisr.c87
1 files changed, 84 insertions, 3 deletions
diff --git a/sys/net/netisr.c b/sys/net/netisr.c
index 8f573d9..ec7b7ad 100644
--- a/sys/net/netisr.c
+++ b/sys/net/netisr.c
@@ -27,6 +27,8 @@
* $FreeBSD$
*/
+#include "opt_net.h"
+
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/rtprio.h>
@@ -55,11 +57,18 @@
/*
* debug_mpsafenet controls network subsystem-wide use of the Giant lock,
- * from system calls down to interrupt handlers. It can be changed only
- * via a tunable at boot, not at run-time, due to the complexity of
- * unwinding.
+ * from system calls down to interrupt handlers. It can be changed only via
+ * a tunable at boot, not at run-time, due to the complexity of unwinding.
+ * The compiled default is set via a kernel option; right now, the default
+ * unless otherwise specified is to run the network stack without Giant.
*/
+#ifdef NET_WITH_GIANT
int debug_mpsafenet = 0;
+#else
+int debug_mpsafenet = 1;
+#endif
+int debug_mpsafenet_toolatetotwiddle = 0;
+
TUNABLE_INT("debug.mpsafenet", &debug_mpsafenet);
SYSCTL_INT(_debug, OID_AUTO, mpsafenet, CTLFLAG_RD, &debug_mpsafenet, 0,
"Enable/disable MPSAFE network support");
@@ -74,6 +83,78 @@ struct netisr {
static void *net_ih;
+/*
+ * Note all network code is currently capable of running MPSAFE; however,
+ * most of it is. Since those sections that are not are generally optional
+ * components not shipped with default kernels, we provide a basic way to
+ * determine whether MPSAFE operation is permitted: based on a default of
+ * yes, we permit non-MPSAFE components to use a registration call to
+ * identify that they require Giant. If the system is early in the boot
+ * process still, then we change the debug_mpsafenet setting to choose a
+ * non-MPSAFE execution mode (degraded). If it's too late for that (since
+ * the setting cannot be changed at run time), we generate a console warning
+ * that the configuration may be unsafe.
+ */
+static int mpsafe_warn_count;
+
+/*
+ * Function call implementing registration of a non-MPSAFE network component.
+ */
+void
+net_warn_not_mpsafe(const char *component)
+{
+
+ /*
+ * If we're running with Giant over the network stack, there is no
+ * problem.
+ */
+ if (!debug_mpsafenet)
+ return;
+
+ /*
+ * If it's not too late to change the MPSAFE setting for the network
+ * stack, do so now. This effectively suppresses warnings by
+ * components registering later.
+ */
+ if (!debug_mpsafenet_toolatetotwiddle) {
+ debug_mpsafenet = 0;
+ printf("WARNING: debug.mpsafenet forced to = as %s requires "
+ "Giant\n", component);
+ return;
+ }
+
+ /*
+ * We must run without Giant, so generate a console warning with some
+ * information with what to do about it. The system may be operating
+ * unsafely, however.
+ */
+ printf("WARNING: Network stack Giant-free, but %s requires Giant.\n",
+ component);
+ if (mpsafe_warn_count == 0)
+ printf(" Consider adding 'options NET_WITH_GIANT' or "
+ "setting debug.mpsafenet=0\n");
+ mpsafe_warn_count++;
+}
+
+/*
+ * This sysinit is run after any pre-loaded or compiled-in components have
+ * announced that they require Giant, but before any modules loaded at
+ * run-time.
+ */
+static void
+net_mpsafe_toolate(void *arg)
+{
+
+ debug_mpsafenet_toolatetotwiddle = 1;
+
+ if (!debug_mpsafenet)
+ printf("WARNING: MPSAFE network stack disabled, expect "
+ "reduced performance.\n");
+}
+
+SYSINIT(net_mpsafe_toolate, SI_SUB_SETTINGS, SI_ORDER_ANY, net_mpsafe_toolate,
+ NULL);
+
void
legacy_setsoftnet(void)
{
OpenPOWER on IntegriCloud