parallel booting init in C - even larger speedup
Petter Reinholdtsen
pere at hungry.com
Mon Nov 14 00:03:55 UTC 2005
[Olivier Sessink]
> I saw the posting from Petter Reinholdtsen, and some years ago I wrote a
> similar program in C: it runs all init scripts with the same sequence
> number in parallel.
Thank you. I finally found time to look at it. I managed to get it
running, but had to patch it slightly to get it working and avoid a
few compile warnings.
What is the license of this source? GPL would be nice.
I did not measure the boot speed, so I do not know if this speeded up
the boot or not. I hope to get to that soonish.
Here is the patch.
- add clean target to makefile, and a few more warning flags.
- convert to unsigned to signed int before comparing it to signed int.
- enable some debug output, to figure out what is going on.
- allow short circuiting the start scripts when moving from runlevel
S too.
- handle non-existing previous runlevel a bit better.
diff -urw parallel_init/Makefile parallel_init-pere/Makefile
--- parallel_init/Makefile 2004-05-20 23:36:33.000000000 +0200
+++ parallel_init-pere/Makefile 2005-11-14 00:48:12.197827916 +0100
@@ -1,9 +1,8 @@
-
-rc: rc.c
- gcc -g -Wall -O2 rc.c -o rc
-
-
all: rc
+rc: rc.c
+ gcc -g -Wall -W -pedantic -O2 rc.c -o rc
+clean:
+ $(RM) rc *~
--- parallel_init/rc.c 2004-05-23 23:52:47.000000000 +0200
+++ parallel_init-pere/rc.c 2005-11-14 00:49:05.891599618 +0100
@@ -75,12 +79,12 @@
unsigned int count;
count = count_strarr(arr);
- if (max > 0 && max < count) {
+ if (max > 0 && max < (int)count) {
count = max;
}
newarr = tmp2 = malloc((count+1)*sizeof(char *));
- while (tmp1 - arr < count) {
-/* printf("duplicated %s\n",*tmp1);*/
+ while (tmp1 - arr < (int)count) {
+ printf("duplicated %s\n",*tmp1);
*tmp2 = strdup(*tmp1);
tmp2++;
tmp1++;
@@ -97,7 +101,7 @@
pattern = strncat(pattern, runleveldir,14);
pattern = strncat(pattern, startchar, 14);
pattern = strncat(pattern, "*", 14);
-/* printf("searching for %s\n", pattern);*/
+ printf("searching for %s\n", pattern);
ret = glob(pattern, 0, NULL, &globbuf);
free(pattern);
if (0 == ret) {
@@ -218,31 +222,34 @@
}
Sscripts = return_scripts_sorted(runleveldir, "S");
- if (prev_runlevel && strcmp(prev_runlevel,"S")!=0) {
+ if (prev_runlevel) {
/* if this suffix is already started in the previous runlevel, and not
stopped in this runlevel, we don't need to start it anymore */
char **tmp;
char *prevrunleveldir = build_runleveldir(prev_runlevel);
prevSscripts = return_scripts_sorted(prevrunleveldir, "S");
+ if (prevSscripts) {
tmp = prevSscripts;
while (*tmp) {
char *suffix = get_suffix(*tmp);
- if (strarr_has_suffix(Sscripts, suffix) && !strarr_has_suffix(Kscripts, suffix)) {
+ if (strarr_has_suffix(Sscripts, suffix) &&
+ !strarr_has_suffix(Kscripts, suffix)) {
Sscripts = remove_suffix_from_strarr(Sscripts, suffix);
}
tmp++;
}
}
+ }
/* run batches of scripts with the same sequence number parallel */
if (Sscripts) {
unsigned short int start=0,len=1,i;
char **batch;
for (i=1;Sscripts[i]!=NULL;i++) {
-/* printf("comparing %s and %s\n",scripts[start], scripts[i]);*/
+ printf("comparing %s and %s\n",Sscripts[start], Sscripts[i]);
if (strncmp(Sscripts[start], Sscripts[i], 14)==0) {
len++;
-/* printf("the same! len=%d\n",len);*/
+ printf("the same! len=%d\n",len);
} else {
batch = duplicate_strarr(&Sscripts[start], len);
run_batch(batch, "start");
More information about the initscripts-ng-devel
mailing list