From 2a888f938e5f02e6579c0a12283121a626a90fe1 Mon Sep 17 00:00:00 2001 From: "Kenneth D. Merry" Date: Wed, 10 Feb 1999 00:04:13 +0000 Subject: Add a prioritization field to the devstat_add_entry() call so that peripheral drivers can determine where in the devstat(9) list they are inserted. This requires recompilation of libdevstat, systat, vmstat, rpc.rstatd, and any ports that depend on the devstat code, since the size of the devstat structure has changed. The devstat version number has been incremented as well to reflect the change. This sorts devices in the devstat list in "more interesting" to "less interesting" order. So, for instance, da devices are now more important than floppy drives, and so will appear before floppy drives in the default output from systat, iostat, vmstat, etc. The order of devices is, for now, kept in a central table in devicestat.h. If individual drivers were able to make a meaningful decision on what priority they should be at attach time, we could consider splitting the priority information out into the various drivers. For now, though, they have no way of knowing that, so it's easier to put them in an easy to find table. Also, move the checkversion() call in vmstat(8) to a more logical place. Thanks to Bruce and David O'Brien for suggestions, for reviewing this, and for putting up with the long time it has taken me to commit it. Bruce did object somewhat to the central priority table (he would rather the priorities be distributed in each driver), so his objection is duly noted here. Reviewed by: bde, obrien --- sys/kern/subr_devstat.c | 64 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 5 deletions(-) (limited to 'sys/kern/subr_devstat.c') diff --git a/sys/kern/subr_devstat.c b/sys/kern/subr_devstat.c index 5fcf88efdca7..d08c0c9d5aea 100644 --- a/sys/kern/subr_devstat.c +++ b/sys/kern/subr_devstat.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 1998 Kenneth D. Merry. + * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: subr_devstat.c,v 1.7 1998/12/04 22:54:51 archie Exp $ + * $Id: subr_devstat.c,v 1.8 1998/12/27 18:03:29 dfr Exp $ */ #include @@ -52,10 +52,12 @@ void devstat_add_entry(struct devstat *ds, const char *dev_name, int unit_number, u_int32_t block_size, devstat_support_flags flags, - devstat_type_flags device_type) + devstat_type_flags device_type, + devstat_priority priority) { int s; struct devstatlist *devstat_head; + struct devstat *ds_tmp; if (ds == NULL) return; @@ -68,15 +70,67 @@ devstat_add_entry(struct devstat *ds, const char *dev_name, devstat_head = &device_statq; - STAILQ_INSERT_TAIL(devstat_head, ds, dev_links); + /* + * Priority sort. Each driver passes in its priority when it adds + * its devstat entry. Drivers are sorted first by priority, and + * then by probe order. + * + * For the first device, we just insert it, since the priority + * doesn't really matter yet. Subsequent devices are inserted into + * the list using the order outlined above. + */ + if (devstat_num_devs == 1) + STAILQ_INSERT_TAIL(devstat_head, ds, dev_links); + else { + for (ds_tmp = STAILQ_FIRST(devstat_head); ds_tmp != NULL; + ds_tmp = STAILQ_NEXT(ds_tmp, dev_links)) { + struct devstat *ds_next; + + ds_next = STAILQ_NEXT(ds_tmp, dev_links); + + /* + * If we find a break between higher and lower + * priority items, and if this item fits in the + * break, insert it. This also applies if the + * "lower priority item" is the end of the list. + */ + if ((priority <= ds_tmp->priority) + && ((ds_next == NULL) + || (priority > ds_next->priority))) { + STAILQ_INSERT_AFTER(devstat_head, ds_tmp, ds, + dev_links); + break; + } else if (priority > ds_tmp->priority) { + /* + * If this is the case, we should be able + * to insert ourselves at the head of the + * list. If we can't, something is wrong. + */ + if (ds_tmp == STAILQ_FIRST(devstat_head)) { + STAILQ_INSERT_HEAD(devstat_head, + ds, dev_links); + break; + } else { + STAILQ_INSERT_TAIL(devstat_head, + ds, dev_links); + printf("devstat_add_entry: HELP! " + "sorting problem detected " + "for %s%d\n", dev_name, + unit_number); + break; + } + } + } + } ds->device_number = devstat_current_devnumber++; ds->unit_number = unit_number; strncpy(ds->device_name, dev_name, DEVSTAT_NAME_LEN); - ds->device_name[DEVSTAT_NAME_LEN - 1] = 0; + ds->device_name[DEVSTAT_NAME_LEN - 1] = '\0'; ds->block_size = block_size; ds->flags = flags; ds->device_type = device_type; + ds->priority = priority; s = splclock(); getmicrotime(&ds->dev_creation_time); -- cgit v1.3