Source-Changes-HG archive

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

[src/trunk]: src/sys/kern avoid 'marching unit numbers' for cloning devices. ...



details:   https://anonhg.NetBSD.org/src/rev/3a0180e5a09b
branches:  trunk
changeset: 479999:3a0180e5a09b
user:      cgd <cgd%NetBSD.org@localhost>
date:      Thu Dec 30 01:03:43 1999 +0000

description:
avoid 'marching unit numbers' for cloning devices.  (e.g., previously,
if you com* at pcmcia?, and com3 and com4 as pcmcia cards, and removed
and reinserted the card that was com3, it would become com5.  if you then
removed and reinserted com4, it would become com6.  etc.)  Now, instead
of incrementing FSTATE_STAR configuration entries for a driver when
a cloning instance is attached, leave it alone, and scan the device softc
array (starting at the first cloning unit number) for units which are
available for use.  This wastes a tiny bit of time (can require a linear
scan of the softc table for the device), but device attachment should be
relatively infrequent and the number of units of each type of device
is never particularly large anyway.

diffstat:

 sys/kern/subr_autoconf.c |  26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)

diffs (65 lines):

diff -r 5fb5caf9a95a -r 3a0180e5a09b sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Thu Dec 30 01:01:48 1999 +0000
+++ b/sys/kern/subr_autoconf.c  Thu Dec 30 01:03:43 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_autoconf.c,v 1.44 1999/09/23 15:14:57 minoura Exp $       */
+/*     $NetBSD: subr_autoconf.c,v 1.45 1999/12/30 01:03:43 cgd Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -308,10 +308,16 @@
        ca = cf->cf_attach;
        if (ca->ca_devsize < sizeof(struct device))
                panic("config_attach");
-       myunit = cf->cf_unit;
-       if (cf->cf_fstate == FSTATE_STAR)
-               cf->cf_unit++;
-       else {
+       if (cf->cf_fstate == FSTATE_STAR) {
+               for (myunit = cf->cf_unit; myunit < cd->cd_ndevs; myunit++)
+                       if (cd->cd_devs[myunit] == NULL)
+                               break;
+               /*
+                * myunit is now the unit of the first NULL device pointer,
+                * or max(cd->cd_ndevs,cf->cf_unit).
+                */
+       } else {
+               myunit = cf->cf_unit;
                KASSERT(cf->cf_fstate == FSTATE_NOTFOUND);
                cf->cf_fstate = FSTATE_FOUND;
        }
@@ -379,15 +385,12 @@
 
        /*
         * Before attaching, clobber any unfound devices that are
-        * otherwise identical, or bump the unit number on all starred
-        * cfdata for this device.
+        * otherwise identical.
         */
        for (cf = cfdata; cf->cf_driver; cf++)
                if (cf->cf_driver == cd && cf->cf_unit == dev->dv_unit) {
                        if (cf->cf_fstate == FSTATE_NOTFOUND)
                                cf->cf_fstate = FSTATE_FOUND;
-                       if (cf->cf_fstate == FSTATE_STAR)
-                               cf->cf_unit++;
                }
 #if defined(__alpha__) || defined(hp300) || defined(__i386__) || \
        defined(__sparc__) || defined(__vax__) || defined(x68k)
@@ -476,17 +479,12 @@
 
        /*
         * Mark cfdata to show that the unit can be reused, if possible.
-        * Note that we can only re-use a starred unit number if the unit
-        * being detached had the last assigned unit number.
         */
        for (cf = cfdata; cf->cf_driver; cf++) {
                if (cf->cf_driver == cd) {
                        if (cf->cf_fstate == FSTATE_FOUND &&
                            cf->cf_unit == dev->dv_unit)
                                cf->cf_fstate = FSTATE_NOTFOUND;
-                       if (cf->cf_fstate == FSTATE_STAR &&
-                           cf->cf_unit == dev->dv_unit + 1)
-                               cf->cf_unit--;
                }
        }
 



Home | Main Index | Thread Index | Old Index