early console registration
PATCH 1/1 early console registration
Here's another patch that just sets the bit corresponding to the boot CPU in the cpu_online_map if we successfully register an early console. The early_console_setup routine is simple, and I'd expect additions of the form:
...
#ifdef CONFIG_SGI_L1_SERIAL_CONSOLE
{
extern int sn_serial_console_early_setup(void);
if (!sn_serial_console_early_setup())
return 0;
}
#endif
...
#ifdef CONFIG_FOO_CONSOLE
{
extern int foo_early_setup(void);
if (!foo_early_setup())
return 0;
}#endif
...
etc.
Is this reasonable? I've tested it on a couple of machines here and it works well. It's really useful for debugging setup_arch problems.
Thanks,
Jesse
===== arch/ia64/kernel/setup.c 1.70 vs edited =====
arch/ia64/kernel/setup.c +26 -0
@@ -280,6 +280,28 @@ }#endif +/** +* early_console_setup - setup debugging console +* +* Consoles started here require little enough setup that we can start using +* them very early in the boot process, either right after the machine +* vector initialization, or even before if the drivers can detect their hw. +* +* Returns non-zero if a console couldn't be setup. +*/ +static int __init early_console_setup (void ) +{ +#ifdef CONFIG_SGI_L1_SERIAL_CONSOLE + { +extern int sn_serial_console_early_setup (void ); +if (!sn_serial_console_early_setup ()) +return 0 ; + } +#endif + +return -1 ; +} +void __init setup_arch (char **cmdline_p) {
@@ -296,6 +318,10 @@#ifdef CONFIG_IA64_GENERIC machvec_init (acpi_get_sysname ());#endif + +/* If we register an early console, allow CPU 0 to printk */ +if (!early_console_setup ()) +cpu_set (smp_processor_id (), cpu_online_map);#ifdef CONFIG_ACPI_BOOT /* Initialize the ACPI boot-time table parser */
===== drivers/char/sn_serial.c 1.11 vs edited =====
drivers/char/sn_serial.c +49 -27
110 lines not on this page · raw message
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jesse Barnes
Jesse> Is this reasonable? I've tested it on a couple of machines Jesse> here and it works well. It's really useful for debugging Jesse> setup_arch problems.
I don't like the #ifdef's very much, but I suppose I can live with them in this case. IIRC, Bjorn also has been working on some early-printk changes so I'd be interested in his opinion.
--david
Quoted 10 lines · David Mosberger
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On Fri, 14 May 2004 14:25:59 -0700, Jesse Barnes
<[email protected]> said:Jesse> Is this reasonable? I've tested it on a couple of machines Jesse> here and it works well. It's really useful for debugging Jesse>
setup_archproblems.I don't like the #ifdef's very much, but I suppose I can live with them in this case. IIRC, Bjorn also has been working on some early-printk changes so I'd be interested in his opinion.
Yeah, me neither, but I like the alternative even less--ia64_platform_is and .weak symbols or something. I *think* this approach will work for Bjorn too (and any other driver that's ok with being called early), but it would be nice to hear it. :)
Thanks,
Jesse
Quoted 8 lines · Jesse Barnes
Quoted 7 lines · David Mosberger
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On Fri, 14 May 2004 14:25:59 -0700, Jesse Barnes
<[email protected]> said:Jesse> Is this reasonable? I've tested it on a couple of machines Jesse> here and it works well. It's really useful for debugging Jesse>
setup_archproblems.
Quoted 8 lines
Quoted 3 lines
I don't like the #ifdef's very much, but I suppose I can live with them in this case. IIRC, Bjorn also has been working on some early-printk changes so I'd be interested in his opinion.
Yeah, me neither, but I like the alternative even less--ia64_platform_is and .weak symbols or something. I *think* this approach will work for Bjorn too (and any other driver that's ok with being called early), but it would be nice to hear it. :)
Well, you could always implement a PCDP (primary console & debug port device table -- an extension of HCDP). That would remove the need for the ia64_platform_is() in your driver and move the #ifdefs into the pcdp setup routine. That wouldn't solve the problem for legacy firmware, though, so what you've got is probably the best we can do for now.
The interesting bit to me is setting CPU 0 online early. We've already set up I/O port space and the machine vector, so that should be OK. We haven't done cpu_init() yet, so the per-CPU data mapping isn't set up yet. I guess it's probably reasonable to prohibit early console drivers from using per-CPU data.
Bjorn
Quoted 5 lines · Bjorn Helgaas
The interesting bit to me is setting CPU 0 online early. We've already set up I/O port space and the machine vector, so that should be OK. We haven't done
cpu_init()yet, so the per-CPU data mapping isn't set up yet. I guess it's probably reasonable to prohibit early console drivers from using per-CPU data.
Yeah, that's a good point. In the comments above the early console setup function we should outline the requirements and restrictions for a console registered there. So far we've got:
o cannot allocate memory
o cannot use per-cpu data
o cannot use interrupts
What else?
Jesse
PATCH 1/1 early console registration
In reply to Jesse BarnesHere's an updated early console registration patch, how does it look? There's another piece to update the sn2 console driver with support for it, but I can send that straight to Andrew. I think Bjorn has a similar patch for the zx1 console.
Allow consoles to be registered early if they support doing output very early in the boot process. Consoles that allow this are subject to the limitations outlined in the comments for the early_console_setup routine.
Thanks,
Jesse
===== arch/ia64/kernel/setup.c 1.71 vs edited =====
arch/ia64/kernel/setup.c +34 -0
@@ -280,6 +280,36 @@ }#endif +/** +* early_console_setup - setup debugging console +* +* Consoles started here require little enough setup that we can start using +* them very early in the boot process, either right after the machine +* vector initialization, or even before if the drivers can detect their hw. +* +* Since these drivers are initialized and called very early on in the boot +* process, some services are unavailable until the system is up: +* o memory allocation +* o per-cpu data +* o interrupts +* The driver is free to have an initcall that switches the console ops +* though, as is done in the sn2 console driver. +* +* Returns non-zero if a console couldn't be setup. +*/ +static int __init early_console_setup (void ) +{ +#ifdef CONFIG_SGI_L1_SERIAL_CONSOLE + { +extern int sn_serial_console_early_setup (void ); +if (!sn_serial_console_early_setup ()) +return 0 ; + } +#endif + +return -1 ; +} +void __init setup_arch (char **cmdline_p) {
@@ -296,6 +326,10 @@#ifdef CONFIG_IA64_GENERIC machvec_init (acpi_get_sysname ());#endif + +/* If we register an early console, allow CPU 0 to printk */ +if (!early_console_setup ()) +cpu_set (smp_processor_id (), cpu_online_map);#ifdef CONFIG_ACPI_BOOT /* Initialize the ACPI boot-time table parser */
Quoted 3 lines · Jesse Barnes
Allow consoles to be registered early if they support doing output very early in the boot process. Consoles that allow this are subject to the limitations outlined in the comments for the
early_console_setuproutine.
(See original mail with patch here:
http://www.gelato.unsw.edu.au/linux-ia64/0406/9894.html)
I'm still a little uneasy about setting cpu_online for CPU 0 so early. What if somebody comes along in the future and assumes the original semantics for cpu_online(0)?
As another possibility, the following is a little more intrusive to printk.c, but also a little more explicit about what we're doing (untested).
=== drivers/char/sn_serial.c 1.14 vs edited ==--- 1.14/drivers/char/sn_serial.c 2004-05-11 09:25:13 -06:00
+++ edited/drivers/char/sn_serial.c 2004-06-14 16:24:05 -06:00
@@ -1007,6 +1007,7 @@
static struct console sal_console = {
.name = "ttyS",
+ .flags = CON_EARLY,
.write = sn_sal_console_write,
.device = sn_sal_console_device,
.setup = sn_sal_console_setup,
=== include/linux/console.h 1.13 vs edited ==--- 1.13/include/linux/console.h 2004-05-14 20:00:12 -06:00
+++ edited/include/linux/console.h 2004-06-14 12:42:16 -06:00
@@ -80,6 +80,7 @@
#define CON_PRINTBUFFER (1)
#define CON_CONSDEV (2) /* Last on the command line */
#define CON_ENABLED (4)
+#define CON_EARLY (8) /* Works before CPU is online */
struct console
{
=== kernel/printk.c 1.38 vs edited ==--- 1.38/kernel/printk.c 2004-05-25 03:53:03 -06:00
+++ edited/kernel/printk.c 2004-06-14 16:12:17 -06:00
@@ -113,6 +113,9 @@
/* Flag: console code may call schedule() */
static int console_may_schedule;
+/* Early consoles work before CPU is online */
+static int early_console_registered;
+
/*
* Setup a list of consoles. Called from init/main.c
*/
@@ -384,7 +387,8 @@
struct console *con;
for (con = console_drivers; con; con = con->next) {
- if ((con->flags & CON_ENABLED) && con->write)
+ if ((con->flags & CON_ENABLED) && con->write &&
+ (cpu_online(smp_processor_id()) || con->flags & CON_EARLY))
con->write(con, &LOG_BUF(start), end - start);
}
}
@@ -544,7 +548,8 @@
}
if (!cpu_online(smp_processor_id()) &&
- system_state != SYSTEM_RUNNING) {
+ system_state != SYSTEM_RUNNING &&
+ !early_console_registered) { /*
* Some console drivers may assume that per-cpu resources have
* been allocated. So don't allow them to be called by this
@@ -733,6 +738,8 @@
if (!(console->flags & CON_ENABLED))
return;
+
+ early_console_registered |= console->flags & CON_EARLY;
/*
* Put this console in the list - keep the
Quoted 8 lines · Bjorn Helgaas
Quoted 3 lines · Jesse Barnes
Allow consoles to be registered early if they support doing output very early in the boot process. Consoles that allow this are subject to the limitations outlined in the comments for the
early_console_setuproutine.(See original mail with patch here:
http://www.gelato.unsw.edu.au/linux-ia64/0406/9894.html)
Quoted 7 lines
I'm still a little uneasy about setting
cpu_onlinefor CPU 0 so early. What if somebody comes along in the future and assumes the original semantics forcpu_online(0)?As another possibility, the following is a little more intrusive to
printk.c, but also a little more explicit about what we're doing (untested).
Yeah, that's fine. In fact, I've tested something similar and sent it to Andrew, but he came back and asked why not just set CPU 0 online early? And given that CPU 0 is 'online' as soon as the kernel starts executing head.S, it seems like it *should* keep working, and we should probably keep it that way.
But either way is fine with me, so long as it gets upstream somehow.
Jesse
Quoted 5 lines · Jesse Barnes
Yeah, that's fine. In fact, I've tested something similar and sent it to Andrew, but he came back and asked why not just set CPU 0 online early? And given that CPU 0 is 'online' as soon as the kernel starts executing
head.S, it seems like it *should* keep working, and we should probably keep it that way.
It's *not* online as soon as it starts head.S, though -- that's what I meant about preserving the original cpu_online semantics. It currently means that at least cpu_init() has been called, so memory allocation, per-cpu data, and interrupts should work.
If we mark CPU 0 as 'online' earlier, some hypothetical new code could test cpu_online(0) and incorrectly assume per-cpu data works.
But AFAIK, there is no such code now, and I don't have any better ideas, so maybe we should just go with your ia64-specific patch for now.
Quoted 11 lines · Bjorn Helgaas
Quoted 5 lines · Jesse Barnes
Yeah, that's fine. In fact, I've tested something similar and sent it to Andrew, but he came back and asked why not just set CPU 0 online early? And given that CPU 0 is 'online' as soon as the kernel starts executing
head.S, it seems like it *should* keep working, and we should probably keep it that way.It's *not* online as soon as it starts
head.S, though -- that's what I meant about preserving the originalcpu_onlinesemantics. It currently means that at leastcpu_init()has been called, so memory allocation, per-cpu data, and interrupts should work.
Well, online in the sense that it can execute instructions, but yes, other limitations apply, I tried to spell them out in the comments for the function.
Quoted 2 lines
If we mark CPU 0 as 'online' earlier, some hypothetical new code could test
cpu_online(0)and incorrectly assume per-cpu data works.
Yeah, that's possible, but the window is pretty small.
Quoted 2 lines
But AFAIK, there is no such code now, and I don't have any better ideas, so maybe we should just go with your ia64-specific patch for now.
Sounds good to me.
Jesse
PATCH 1/1 early console registration
In reply to Jesse BarnesQuoted 4 lines
Quoted 2 lines
But AFAIK, there is no such code now, and I don't have any better ideas, so maybe we should just go with your ia64-specific patch for now.
Sounds good to me.
Bjorn is ok with it, so here it is again. Pat, can you fix up the #ifdef check for your new driver when it gets in? You should be able to reuse the function name...
Allow consoles to register early if they're capable of early output. If one of them registers successfully, set CPU 0 online so that printk() will actually call the console drivers.
Drivers that are capable of early output can add themselves to the early_console_setup routine in the following form:
...
#ifdef CONFIG_SGI_L1_SERIAL_CONSOLE
{
extern int sn_serial_console_early_setup(void);
if (!sn_serial_console_early_setup())
return 0;
}
#endif
...
#ifdef CONFIG_FOO_CONSOLE
{
extern int foo_early_setup(void);
if (!foo_early_setup())
return 0;
}#endif
...
Thanks,
Jesse
===== arch/ia64/kernel/setup.c 1.74 vs edited =====
arch/ia64/kernel/setup.c +26 -0
@@ -280,6 +280,28 @@ }#endif +/** +* early_console_setup - setup debugging console +* +* Consoles started here require little enough setup that we can start using +* them very early in the boot process, either right after the machine +* vector initialization, or even before if the drivers can detect their hw. +* +* Returns non-zero if a console couldn't be setup. +*/ +static int __init early_console_setup (void ) +{ +#ifdef CONFIG_SGI_L1_SERIAL_CONSOLE + { +extern int sn_serial_console_early_setup (void ); +if (!sn_serial_console_early_setup ()) +return 0 ; + } +#endif + +return -1 ; +} +void __init setup_arch (char **cmdline_p) {
@@ -296,6 +318,10 @@#ifdef CONFIG_IA64_GENERIC machvec_init (acpi_get_sysname ());#endif + +/* If we register an early console, allow CPU 0 to printk */ +if (!early_console_setup ()) +cpu_set (smp_processor_id (), cpu_online_map);#ifdef CONFIG_ACPI_BOOT /* Initialize the ACPI boot-time table parser */