From 6437872c1d665c2605f54e8ff040b0ba41edad07 Mon Sep 17 00:00:00 2001 From: Isaac Cilia Attard Date: Mon, 29 Apr 2024 22:44:27 +0200 Subject: New sysctl to disable NOMATCH until devmatch runs Introduce hw.bus.devctl_nomatch_enabled and use it to suppress NOMATCH until devmatch runs There's a lot of NOMATCH events generated at boot. We also run devmatch once during early boot to load unmatched devices. To avoid redundant work, don't start generating NOMATCH events until after devmatch runs. Set hw.bus.devctl_nomatch_enabled=1 just before we run devmatch. The kernel will suppress NOMATCH events until this is set to true. This saves about 170ms from the boot on aarch64 running atop Apple M-series processors and the VMWare Fusion hypervisor. Reviewed by: imp, cperciva MFC after: 3 days Sponsored by: Google Summer of Code Pull Request: https://github.com/freebsd/freebsd-src/pull/1213 --- libexec/rc/rc.d/devmatch | 1 + sys/kern/kern_devctl.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libexec/rc/rc.d/devmatch b/libexec/rc/rc.d/devmatch index 78050cfa4541..67bb14761614 100755 --- a/libexec/rc/rc.d/devmatch +++ b/libexec/rc/rc.d/devmatch @@ -46,6 +46,7 @@ devmatch_start() if [ -n "$one_nomatch" ]; then list=$(devmatch -p "${one_nomatch}" | sort -u) else + sysctl hw.bus.devctl_nomatch_enabled=1 list=$(devmatch | sort -u) fi diff --git a/sys/kern/kern_devctl.c b/sys/kern/kern_devctl.c index 12d4f9ebfc4d..0dd05a49c9ad 100644 --- a/sys/kern/kern_devctl.c +++ b/sys/kern/kern_devctl.c @@ -89,6 +89,9 @@ static int sysctl_devctl_queue(SYSCTL_HANDLER_ARGS); static int devctl_queue_length = DEVCTL_DEFAULT_QUEUE_LEN; SYSCTL_PROC(_hw_bus, OID_AUTO, devctl_queue, CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, NULL, 0, sysctl_devctl_queue, "I", "devctl queue length"); +static bool nomatch_enabled = false; +SYSCTL_BOOL(_hw_bus, OID_AUTO, devctl_nomatch_enabled, CTLFLAG_RWTUN, + &nomatch_enabled, 0, "enable nomatch events"); static void devctl_attach_handler(void *arg __unused, device_t dev); static void devctl_detach_handler(void *arg __unused, device_t dev, @@ -208,7 +211,8 @@ devctl_detach_handler(void *arg __unused, device_t dev, enum evhdev_detach state static void devctl_nomatch_handler(void *arg __unused, device_t dev) { - devaddq("?", "", dev); + if (nomatch_enabled) + devaddq("?", "", dev); } static int -- cgit v1.2.3