Module Name: src Committed By: riastradh Date: Sat Oct 3 22:32:50 UTC 2020
Modified Files: src/sys/dev/ata: ata.c src/sys/kern: subr_autoconf.c src/sys/sys: device.h Log Message: autoconf: Blame devices holding up boot with config_pending. Blame message requires `boot -x' (AB_DEBUG). Fix ata so it doesn't mismatch config_pending_incr/decr devices. To generate a diff of this commit: cvs rdiff -u -r1.159 -r1.160 src/sys/dev/ata/ata.c cvs rdiff -u -r1.273 -r1.274 src/sys/kern/subr_autoconf.c cvs rdiff -u -r1.157 -r1.158 src/sys/sys/device.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/ata/ata.c diff -u src/sys/dev/ata/ata.c:1.159 src/sys/dev/ata/ata.c:1.160 --- src/sys/dev/ata/ata.c:1.159 Mon May 25 19:05:30 2020 +++ src/sys/dev/ata/ata.c Sat Oct 3 22:32:50 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ata.c,v 1.159 2020/05/25 19:05:30 jdolecek Exp $ */ +/* $NetBSD: ata.c,v 1.160 2020/10/03 22:32:50 riastradh Exp $ */ /* * Copyright (c) 1998, 2001 Manuel Bouyer. All rights reserved. @@ -25,7 +25,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.159 2020/05/25 19:05:30 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ata.c,v 1.160 2020/10/03 22:32:50 riastradh Exp $"); #include "opt_ata.h" @@ -298,7 +298,7 @@ atabusconfig(struct atabus_softc *atabus ata_delref(chp); - config_pending_decr(atac->atac_dev); + config_pending_decr(atabus_sc->sc_dev); } /* @@ -424,7 +424,7 @@ atabusconfig_thread(void *arg) ata_delref(chp); - config_pending_decr(atac->atac_dev); + config_pending_decr(atabus_sc->sc_dev); kthread_exit(0); } Index: src/sys/kern/subr_autoconf.c diff -u src/sys/kern/subr_autoconf.c:1.273 src/sys/kern/subr_autoconf.c:1.274 --- src/sys/kern/subr_autoconf.c:1.273 Sat Aug 1 11:18:26 2020 +++ src/sys/kern/subr_autoconf.c Sat Oct 3 22:32:50 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_autoconf.c,v 1.273 2020/08/01 11:18:26 jdolecek Exp $ */ +/* $NetBSD: subr_autoconf.c,v 1.274 2020/10/03 22:32:50 riastradh Exp $ */ /* * Copyright (c) 1996, 2000 Christopher G. Demetriou @@ -77,7 +77,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.273 2020/08/01 11:18:26 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.274 2020/10/03 22:32:50 riastradh Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -224,7 +224,8 @@ static int alldevs_nread = 0; static int alldevs_nwrite = 0; static bool alldevs_garbage = false; -static int config_pending; /* semaphore for mountroot */ +static struct devicelist config_pending = + TAILQ_HEAD_INITIALIZER(config_pending); static kmutex_t config_misc_lock; static kcondvar_t config_misc_cv; @@ -2095,9 +2096,12 @@ config_pending_incr(device_t dev) { mutex_enter(&config_misc_lock); - config_pending++; + KASSERTMSG(dev->dv_pending < INT_MAX, + "%s: excess config_pending_incr", device_xname(dev)); + if (dev->dv_pending++ == 0) + TAILQ_INSERT_TAIL(&config_pending, dev, dv_pending_list); #ifdef DEBUG_AUTOCONF - printf("%s: %s %d\n", __func__, device_xname(dev), config_pending); + printf("%s: %s %d\n", __func__, device_xname(dev), dev->dv_pending); #endif mutex_exit(&config_misc_lock); } @@ -2106,13 +2110,15 @@ void config_pending_decr(device_t dev) { - KASSERT(0 < config_pending); mutex_enter(&config_misc_lock); - config_pending--; + KASSERTMSG(dev->dv_pending > 0, + "%s: excess config_pending_decr", device_xname(dev)); + if (--dev->dv_pending == 0) + TAILQ_REMOVE(&config_pending, dev, dv_pending_list); #ifdef DEBUG_AUTOCONF - printf("%s: %s %d\n", __func__, device_xname(dev), config_pending); + printf("%s: %s %d\n", __func__, device_xname(dev), dev->dv_pending); #endif - if (config_pending == 0) + if (TAILQ_EMPTY(&config_pending)) cv_broadcast(&config_misc_cv); mutex_exit(&config_misc_lock); } @@ -2165,8 +2171,12 @@ config_finalize(void) * them to finish any deferred autoconfiguration. */ mutex_enter(&config_misc_lock); - while (config_pending != 0) + while (!TAILQ_EMPTY(&config_pending)) { + device_t dev; + TAILQ_FOREACH(dev, &config_pending, dv_pending_list) + aprint_debug_dev(dev, "holding up boot\n"); cv_wait(&config_misc_cv, &config_misc_lock); + } mutex_exit(&config_misc_lock); KERNEL_LOCK(1, NULL); Index: src/sys/sys/device.h diff -u src/sys/sys/device.h:1.157 src/sys/sys/device.h:1.158 --- src/sys/sys/device.h:1.157 Sat Dec 1 01:51:38 2018 +++ src/sys/sys/device.h Sat Oct 3 22:32:50 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: device.h,v 1.157 2018/12/01 01:51:38 msaitoh Exp $ */ +/* $NetBSD: device.h,v 1.158 2020/10/03 22:32:50 riastradh Exp $ */ /* * Copyright (c) 1996, 2000 Christopher G. Demetriou @@ -165,6 +165,9 @@ struct device { int *dv_locators; /* our actual locators (optional) */ prop_dictionary_t dv_properties;/* properties dictionary */ + int dv_pending; /* config_pending count */ + TAILQ_ENTRY(device) dv_pending_list; + size_t dv_activity_count; void (**dv_activity_handlers)(device_t, devactive_t);