Skip to contentSkip to conversation

Better interface for hooking early initcalls.

PATCH In review Eduard - Gabriel Munteanu 3 participants 7 messages Jun 21, 2008 – Jun 22, 2008 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 Better interface for hooking early initcalls.

Added early initcall (pre-SMP) support, using an identical interface to that of regular initcalls. Functions called from do_pre_smp_initcalls() could be converted to use this cleaner interface.

This is required by CPU hotplug, because early users have to register notifiers before going SMP. One such CPU hotplug user is the relay interface with buffer-only channels, which needs to register such a notifier, to be usable in early code. This in turn is used by kmemtrace.

---
 include/asm-generic/vmlinux.lds.h |    2 ++
 include/linux/init.h              |    7 +++++++
 init/main.c                       |   13 +++++++++++--
 3 files changed, 20 insertions(+), 2 deletions(-)
include/asm-generic/vmlinux.lds.h +2 -0
index f054778..4a318e5 100644
@@ -326,6 +326,8 @@
 	}
 
 #define INITCALLS							\
+	*(.initcallearly.init)						\
+	__early_initcall_end = .;					\
   	*(.initcall0.init)						\
   	*(.initcall0s.init)						\
   	*(.initcall1.init)						\
include/linux/init.h +7 -0
index 21d658c..bd12a4c 100644
@@ -170,6 +170,13 @@ extern void (*late_time_init)(void);
 	__attribute__((__section__(".initcall" level ".init"))) = fn
 
 /*
+ * Early initcalls run before initializing SMP.
+ *
+ * Only for built-in code, not modules.
+ */
+#define early_initcall(fn)		__define_initcall("early",fn,early)
+
+/*
  * A "pure" initcall has no dependencies on anything else, and purely
  * initializes variables that couldn't be statically initialized.
  *
init/main.c +11 -2
index f7fb200..bd5df3e 100644
@@ -736,13 +736,13 @@ static void __init do_one_initcall(initcall_t fn)
 }
 
 
-extern initcall_t __initcall_start[], __initcall_end[];
+extern initcall_t __initcall_start[], __initcall_end[], __early_initcall_end[];
 
 static void __init do_initcalls(void)
 {
 	initcall_t *call;
 
-	for (call = __initcall_start; call < __initcall_end; call++)
+	for (call = __early_initcall_end; call < __initcall_end; call++)
 		do_one_initcall(*call);
 
 	/* Make sure there is no pending stuff from the initcall sequence */
@@ -775,6 +775,14 @@ static int __init nosoftlockup_setup(char *str)
 }
 __setup("nosoftlockup", nosoftlockup_setup);
 
+static void __init __do_pre_smp_initcalls(void)
+{
+	initcall_t *call;
+
+	for (call = __initcall_start; call < __early_initcall_end; call++)
+		(*call)();
+}
+
 static void __init do_pre_smp_initcalls(void)
 {
 	extern int spawn_ksoftirqd(void);
@@ -856,6 +864,7 @@ static int __init kernel_init(void * unused)
 
 	smp_prepare_cpus(setup_max_cpus);
 
+	__do_pre_smp_initcalls();
 	do_pre_smp_initcalls();
 
 	smp_init();
Signature · 1 line
1.5.5.4
#1 lore raw

Hi Eduard,

Quoted 3 lines · Eduard - Gabriel Munteanu

Added early initcall (pre-SMP) support, using an identical interface to that of regular initcalls. Functions called from do_pre_smp_initcalls() could be converted to use this cleaner interface.

As there aren't that many functions called from do_pre_smp_initcalls() , I'd suggest you just go ahead and convert them to get this patch merged to mainline.

#2 lore raw
Quoted 1 line · On Sun, 22 Jun 2008 22:22:00 +0300 "Pekka Enberg" <[email protected]>…

Hi Eduard,

Hi,

Quoted 3 lines

As there aren't that many functions called from do_pre_smp_initcalls() , I'd suggest you just go ahead and convert them to get this patch merged to mainline.

Will do, good idea. However, I feel like these should be two different patches. The first adds the new interface, the second converts existing users to the new interface. Will resubmit the patch series soon, along with the conversion patch.

Eduard

#3 lore raw
Quoted 4 lines · Eduard - Gabriel Munteanu

Will do, good idea. However, I feel like these should be two different patches. The first adds the new interface, the second converts existing users to the new interface. Will resubmit the patch series soon, along with the conversion patch.

By the way -- may I ask why it is called early_initcall() and not pre_smp_initcall()? I think it makes sense to encode the exact purpose of the initcall into the name. "early" is not very explicit. This is just my opinion :-) Thanks.

Vegard

Signature · 4 lines
"The animistic metaphor of the bug that maliciously sneaked in while
the programmer was not looking is intellectually dishonest as it
disguises that the error is the programmer's own creation."
	-- E. W. Dijkstra, EWD1036
#4 lore raw
Quoted 4 lines · Vegard Nossum

By the way -- may I ask why it is called early_initcall() and not pre_smp_initcall()? I think it makes sense to encode the exact purpose of the initcall into the name. "early" is not very explicit. This is just my opinion :-) Thanks.

Sounds good to me.

#5 lore raw
Quoted 8 lines · On Sun, 22 Jun 2008 23:45:57 +0300 "Pekka Enberg" <[email protected]>…
Quoted 4 lines · Vegard Nossum

By the way -- may I ask why it is called early_initcall() and not pre_smp_initcall()? I think it makes sense to encode the exact purpose of the initcall into the name. "early" is not very explicit. This is just my opinion :-) Thanks.

Sounds good to me.

Which one? :-)

I mean I could change the name, just let me know which one is better. One encodes the purpose, while the other is consistent with CPU hotplug stuff. Not that we couldn't change CPU hotplug docs to mention this, this is an idea too.

#6 lore raw
In reply to Vegard Nossum
Quoted 4 lines · On Sun, 22 Jun 2008 22:43:55 +0200 "Vegard Nossum" <[email protected]>…

By the way -- may I ask why it is called early_initcall() and not pre_smp_initcall()? I think it makes sense to encode the exact purpose of the initcall into the name. "early" is not very explicit. This is just my opinion :-) Thanks.

CPU hotplug docs name these (inexisting at that time) initcalls 'early', so I went on implementing 'early initcalls'. However, I don't have strong feelings for either of these two names, so this could change.

Quoted 2 lines

Vegard