Date: Wed, 15 Mar 2000 22:53:08 +0000 (GMT) From: Nick Hibma <n_hibma@calcaphon.com> To: FreeBSD Newbus Mailing List <new-bus@FreeBSD.org> Subject: Patch for review Message-ID: <Pine.BSF.4.20.0003152250090.571-200000@localhost>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] The attached patch removes the use of nextunit and replaces it with a linear search for the first element available. This avoids the unit number from ever increasing and memory being wasted if you unplug & plug two devices alternatingly. It also flags that we have called DEVICE_NOMATCH and should not call it again during a reprobe. Let me know if this is anything you would not like to see implemented. Nick -- n_hibma@webweaving.org n_hibma@freebsd.org USB project http://www.etla.net/~n_hibma/ [-- Attachment #2 --] Index: kern/subr_bus.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_bus.c,v retrieving revision 1.54 diff -u -r1.54 subr_bus.c --- kern/subr_bus.c 2000/02/29 09:36:25 1.54 +++ kern/subr_bus.c 2000/03/15 22:49:47 @@ -267,7 +267,6 @@ strcpy(dc->name, classname); dc->devices = NULL; dc->maxunit = 0; - dc->nextunit = 0; TAILQ_INIT(&dc->drivers); TAILQ_INSERT_TAIL(&devclasses, dc, link); } @@ -487,21 +486,28 @@ * device. */ if (unit != -1) { - device_t dev; - dev = devclass_get_device(dc, unit); - if (dev) { + if (unit >= 0 && unit < dc->maxunit && dc->devices[unit] != NULL) { if (bootverbose) - printf("devclass_alloc_unit: %s%d already exists, using next available unit number\n", dc->name, unit); + printf("%s-: %s%d exists, using next available unit number\n", + dc->name, dc->name, unit); unit = -1; } } + /* + * We ended up with an unwired device, so let's find the next available + * slot for it. + */ if (unit == -1) { - unit = dc->nextunit; - dc->nextunit++; - } else if (dc->nextunit <= unit) - dc->nextunit = unit + 1; + unit = 0; + while (unit < dc->maxunit && dc->devices[unit] != NULL) + unit++; + } + /* + * We've selected a unit beyond the length of the table, so let's extend + * the table to make room for all units up to and including this one. + */ if (unit >= dc->maxunit) { device_t *newlist; int newsize; @@ -571,8 +577,6 @@ dev->devclass = NULL; free(dev->nameunit, M_BUS); dev->nameunit = NULL; - while (dc->nextunit > 0 && dc->devices[dc->nextunit - 1] == NULL) - dc->nextunit--; #ifdef DEVICE_SYSCTLS device_unregister_oids(dev); @@ -1147,7 +1151,10 @@ dev->state = DS_NOTPRESENT; } } else { + if (!(dev->flags & DF_DONENOMATCH)) { BUS_PROBE_NOMATCH(bus, dev); + dev->flags |= DF_DONENOMATCH; + } } } else { if (bootverbose) { @@ -2430,8 +2437,8 @@ if ( !dc ) return; - indentprintf(("devclass %s: max units = %d, next unit = %d\n", - dc->name, dc->maxunit, dc->nextunit)); + indentprintf(("devclass %s: max units = %d\n", + dc->name, dc->maxunit)); } static void Index: sys/bus_private.h =================================================================== RCS file: /home/ncvs/src/sys/sys/bus_private.h,v retrieving revision 1.11 diff -u -r1.11 bus_private.h --- sys/bus_private.h 1999/09/07 08:42:49 1.11 +++ sys/bus_private.h 2000/02/11 13:07:41 @@ -53,7 +53,6 @@ char *name; device_t *devices; /* array of devices indexed by unit */ int maxunit; /* size of devices array */ - int nextunit; /* next unused unit number */ }; /* @@ -134,6 +133,7 @@ #define DF_WILDCARD 4 /* unit was originally wildcard */ #define DF_DESCMALLOCED 8 /* description was malloced */ #define DF_QUIET 16 /* don't print verbose attach message */ +#define DF_DONENOMATCH 32 /* don't execute DEVICE_NOMATCH again */ u_char order; /* order from device_add_child_ordered() */ u_char pad; #ifdef DEVICE_SYSCTLS
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.20.0003152250090.571-200000>
