Skip to contentSkip to conversation

initcall dependency solution.

PATCH In review Rusty Russell 2 participants 3 messages Jun 7, 2002

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 initcall dependency solution.

This patch allows you to name initcall dependencies and subsystems. It is backward compatible with the current initcall levels, but doesn't respect link order: a couple of changes to make it boot, but more will be needed I expect.

Example usages:

	/* Simple initcall, don't care when we run. */
	initcall(myinitfn, foodriver);

	/* Initcall which must run after it */
	initcall(myinitfn, bardriver, init_after(foodriver));

	/* Initcalls which are part of a subsystem */
	initcall(myinitfn, bazdriver_a, init_as_part_of(bazdriver_init));
	initcall(myinitfn, bazdriver_b,
		 init_as_part_of(bazdriver_init),
		 init_after(bazdriver_a));

	/* Initcall which requires a subsystem */
	initcall(myinitfn, wuzdriver, init_after(bazdriver_init));

I think we should keep core_init (for mm), and probably let the others evolve as required. We can move much more to initfuncs now, too.

Questions & feedback welcome...
Rusty.
PS. Yes, it slows down kernel build. But sh is portable and easy.

include/linux/init.h +57 -28
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.20/include/linux/init.h working-2.5.20-initorder/include/linux/init.h
@@ -1,7 +1,12 @@
 #ifndef _LINUX_INIT_H
 #define _LINUX_INIT_H
+/* Hacked on by just about everyone.  Explicit ordering work by:
+ * Rusty Russell (C) 2002 IBM Corporation */
+
+/* Change this file, make sure you don't break scripts/build-initcalls */
 
 #include <linux/config.h>
+#include <linux/stringify.h>
 
 /* These macros are used to mark some functions or 
  * initialized data (doesn't apply to uninitialized data)
@@ -48,29 +53,46 @@
 typedef int (*initcall_t)(void);
 typedef void (*exitcall_t)(void);
 
-extern initcall_t __initcall_start, __initcall_end;
+#define INITCALL_MAX_NAMELEN 32
+#define INITCALL_MAX_DEPS 3
 
-/* initcalls are now grouped by functionality into separate 
- * subsections. Ordering inside the subsections is determined
- * by link order. 
- * For backwards compatability, initcall() puts the call in 
- * the device init subsection.
- */
+/* Ensure it's initialized after x */
+#define init_after(x) { .follows = __stringify(x) "-end" }
 
-#define __define_initcall(level,fn) \
-	static initcall_t __initcall_##fn __attribute__ ((unused,__section__ (".initcall" level ".init"))) = fn
+/* Ensure it's initialized before x */
+#define init_before(x) { .preceeds = __stringify(x) "-start" }
 
-#define core_initcall(fn)		__define_initcall("1",fn)
-#define unused_initcall(fn)		__define_initcall("2",fn)
-#define arch_initcall(fn)		__define_initcall("3",fn)
-#define subsys_initcall(fn)		__define_initcall("4",fn)
-#define fs_initcall(fn)			__define_initcall("5",fn)
-#define device_initcall(fn)		__define_initcall("6",fn)
-#define late_initcall(fn)		__define_initcall("7",fn)
+/* This is part of the x subsystem initialization */
+#define init_as_part_of(x)						\
+  { .follows = __stringify(x) "-start",  .preceeds = __stringify(x) "-end" }
 
-#define __initcall(fn) device_initcall(fn)
+/* Example usage:
+	initcall(myinit, ppc_extras,
+		 init_after(ppc_core),
+		 init_as_part_of(arch_init));
+   Do not use a "_init" name except for subsystems (ie. init_as_part_of()).
+*/
+#define initcall(initfn,initname,...)					\
+	static inline initcall_t __init_##initname##_test(void)		\
+	{ return initfn; }						\
+	int __init_##initname(void) __attribute__((alias(#initfn)));	\
+	static const struct initcall_info initfn##_initcall_info	\
+	__attribute__ ((__section__ (".initcalls"))) =			\
+	{ .name = __stringify(initname), { __VA_ARGS__ } };
 
-#define __exitcall(fn)								\
+struct initcall_order
+{
+	char preceeds[INITCALL_MAX_NAMELEN];
+	char follows[INITCALL_MAX_NAMELEN];
+};
+
+struct initcall_info
+{
+	char name[INITCALL_MAX_NAMELEN];
+	struct initcall_order order[INITCALL_MAX_DEPS];
+};
+
+#define __exitcall(fn)	\
 	static exitcall_t __exitcall_##fn __exit_call = fn
 
 /*
@@ -86,7 +108,6 @@
 #define __setup(str, fn)								\
 	static char __setup_str_##fn[] __initdata = str;				\
 	static struct kernel_param __setup_##fn __attribute__((unused)) __initsetup = { __setup_str_##fn, fn }
-
 #endif /* __ASSEMBLY__ */
 
 /*
@@ -135,7 +156,6 @@
 #define __exit
 #define __initdata
 #define __exitdata
-#define __initcall(fn)
 /* For assembly routines */
 #define __INIT
 #define __FINIT
@@ -159,14 +179,7 @@
 
 #define __setup(str,func) /* nothing */
 
-#define core_initcall(fn)		module_init(fn)
-#define unused_initcall(fn)		module_init(fn)
-#define arch_initcall(fn)		module_init(fn)
-#define subsys_initcall(fn)		module_init(fn)
-#define fs_initcall(fn)			module_init(fn)
-#define device_initcall(fn)		module_init(fn)
-#define late_initcall(fn)		module_init(fn)
-
+#define initcall(initfn,initname,...) module_init(initfn)
 #endif
 
 /* Data marked not to be saved by software_suspend() */
@@ -185,5 +198,21 @@
 #define __devexitdata __exitdata
 #define __devexit_p(x)  0
 #endif
+
+/* This many levels of indirection really required */
+#define ___CAT2(a,b) a##b
+#define __CAT2(a,b) ___CAT2(a,b)
+#define __FAKENAME __CAT2(KBUILD_BASENAME,__LINE__)
+#define __obs_initcall(fn,name,subsys) \
+	initcall(fn,name,init_as_part_of(subsys))
+
+/* Backwards compat macros: deprecated */
+#define core_initcall(fn) __obs_initcall(fn,__FAKENAME,core_init)
+#define arch_initcall(fn) __obs_initcall(fn,__FAKENAME,arch_init)
+#define subsys_initcall(fn) __obs_initcall(fn,__FAKENAME,subsys_init)
+#define fs_initcall(fn) __obs_initcall(fn,__FAKENAME,fs_init)
+#define device_initcall(fn) __obs_initcall(fn,__FAKENAME,device_init)
+#define late_initcall(fn) __obs_initcall(fn,__FAKENAME,late_init)
+#define __initcall(fn) device_initcall(fn)
 
 #endif /* _LINUX_INIT_H */
Makefile +6 -2
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.20/Makefile working-2.5.20-initorder/Makefile
@@ -156,6 +156,7 @@
 		$(DRIVERS) \
 		$(NETWORKS) \
 		--end-group \
+		init/generated-initcalls.o \
 		-o vmlinux
 
 #	set -e makes the rule exit immediately on error
@@ -172,7 +173,10 @@
 	$(NM) vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
 endef
 
-vmlinux: $(CONFIGURATION) $(vmlinux-objs) FORCE
+init/generated-initcalls.c: $(vmlinux-objs) scripts/build-initcalls
+	scripts/build-initcalls $(OBJDUMP) $(vmlinux-objs) >$@
+
+vmlinux: $(CONFIGURATION) $(vmlinux-objs) init/generated-initcalls.o FORCE
 	$(call if_changed_rule,link_vmlinux)
 
 #	The actual objects are generated when descending, 
@@ -440,7 +444,7 @@
 
 #	files removed with 'make clean'
 CLEAN_FILES += \
-	kernel/ksyms.lst include/linux/compile.h \
+	init/generated-initcalls.c kernel/ksyms.lst include/linux/compile.h \
 	vmlinux System.map \
 	.tmp* \
 	drivers/char/consolemap_deftbl.c drivers/video/promcon_tbl.c \
init/main.c +3 -13
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.20/init/main.c working-2.5.20-initorder/init/main.c
@@ -421,19 +421,7 @@
 
 struct task_struct *child_reaper = &init_task;
 
-static void __init do_initcalls(void)
-{
-	initcall_t *call;
-
-	call = &__initcall_start;
-	do {
-		(*call)();
-		call++;
-	} while (call < &__initcall_end);
-
-	/* Make sure there is no pending stuff from the initcall sequence */
-	flush_scheduled_tasks();
-}
+extern void do_initcalls(void);
 
 /*
  * Ok, the machine is now initialized. None of the devices
@@ -485,6 +473,8 @@
 
 	start_context_thread();
 	do_initcalls();
+	/* Make sure there is no pending stuff from the initcall sequence */
+	flush_scheduled_tasks();
 }
 
 extern void prepare_namespace(void);
kernel/exec_domain.c +1 -1
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.20/kernel/exec_domain.c working-2.5.20-initorder/kernel/exec_domain.c
@@ -281,7 +281,7 @@
 	return 0;
 }
 
-__initcall(abi_register_sysctl);
+initcall(abi_register_sysctl, exec_domain, init_as_part_of(core_init));
 
 
 EXPORT_SYMBOL(abi_defhandler_coff);
kernel/softirq.c +1 -1
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.20/kernel/softirq.c working-2.5.20-initorder/kernel/softirq.c
@@ -412,4 +412,4 @@
 	return 0;
 }
 
-__initcall(spawn_ksoftirqd);
+initcall(spawn_ksoftirqd, ksoftirqd, init_as_part_of(core_init));
mm/highmem.c +1 -1
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.20/mm/highmem.c working-2.5.20-initorder/mm/highmem.c
@@ -220,7 +220,7 @@
 	return 0;
 }
 
-__initcall(init_emergency_pool);
+initcall(init_emergency_pool, "highmem", init_as_part_of(core_init));
 
 /*
  * highmem version, map in to vec
mm/slab.c +1 -1
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.20/mm/slab.c working-2.5.20-initorder/mm/slab.c
@@ -508,7 +508,7 @@
 	return 0;
 }
 
-__initcall(kmem_cpucache_init);
+initcall(kmem_cpucache_init, slab, init_as_part_of(core_init));
 
 /* Interface to system's page allocator. No need to hold the cache-lock.
  */
scripts/build-initcalls +104 -0

104 lines not on this page · raw message

--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#1 lore raw
Quoted 4 lines · Rusty Russell

This patch allows you to name initcall dependencies and subsystems. It is backward compatible with the current initcall levels, but doesn't respect link order: a couple of changes to make it boot, but more will be needed I expect.

Interesting. So in theory this mechanism could also be used to speed booting by parallelizing execution of each independent initcall dependancy tree...

-Erik

--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--

#2 lore raw

In message <[email protected]> you write:

Quoted 9 lines · Rusty Russell
Quoted 4 lines

This patch allows you to name initcall dependencies and subsystems. It is backward compatible with the current initcall levels, but doesn't respect link order: a couple of changes to make it boot, but more will be needed I expect.

Interesting. So in theory this mechanism could also be used to speed booting by parallelizing execution of each independent initcall dependancy tree...

In theory. But the right solution is to move userspace as soon as possible, for spinning up non-root disks, etc.

More importantly we can use the same mechanism to say "do this after all cpus are up" or "do this once we have a userspace" etc, and move more things to initcalls (ie. neaten the boot code).

Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.