diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -216,6 +216,18 @@ } #endif +static int +compare_sysinit(const void *a, const void *b) +{ + const struct sysinit *s1 = *(const struct sysinit * const *)a; + const struct sysinit *s2 = *(const struct sysinit * const *)b; + /* Sort by subsystem first, then by order. */ + int cmp = (int)s1->subsystem - (int)s2->subsystem; + if (cmp == 0) + cmp = (int)s1->order - (int)s2->order; + return cmp; +} + /* * System startup; initialize the world, create process 0, mount root * filesystem, and fork to create init and pagedaemon. Most of the @@ -232,10 +244,8 @@ { struct sysinit **sipp; /* system initialization*/ - struct sysinit **xipp; /* interior loop of sort*/ - struct sysinit *save; /* bubble*/ - int last; + enum sysinit_sub_id last; #if defined(VERBOSE_SYSINIT) int verbose; #endif @@ -252,22 +262,13 @@ restart: /* - * Perform a bubble sort of the system initialization objects by - * their subsystem (primary key) and order (secondary key). + * Sort the system initialization objects by their subsystem (primary key) + * and order (secondary key). */ - TSENTER2("bubblesort"); - for (sipp = sysinit; sipp < sysinit_end; sipp++) { - for (xipp = sipp + 1; xipp < sysinit_end; xipp++) { - if ((*sipp)->subsystem < (*xipp)->subsystem || - ((*sipp)->subsystem == (*xipp)->subsystem && - (*sipp)->order <= (*xipp)->order)) - continue; /* skip*/ - save = *sipp; - *sipp = *xipp; - *xipp = save; - } - } - TSEXIT2("bubblesort"); + TSENTER2("qsort"); + qsort(sysinit, sysinit_end - sysinit, sizeof(struct sysinit *), + compare_sysinit); + TSEXIT2("qsort"); last = SI_SUB_COPYRIGHT; #if defined(VERBOSE_SYSINIT)