#include <linux/smp_lock.h>
#include <linux/console.h>
#include <linux/init.h>
-#include <linux/jiffies.h>
-#include <linux/nmi.h>
#include <linux/module.h>
-#include <linux/moduleparam.h>
#include <linux/interrupt.h> /* For in_interrupt() */
+#include <linux/config.h>
#include <linux/delay.h>
#include <linux/smp.h>
#include <linux/security.h>
DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */
};
-EXPORT_UNUSED_SYMBOL(console_printk); /* June 2006 */
+EXPORT_SYMBOL(console_printk);
/*
* Low lever drivers may need that to know if they can schedule in
* driver system.
*/
static DECLARE_MUTEX(console_sem);
-static DECLARE_MUTEX(secondary_console_sem);
struct console *console_drivers;
/*
* This is used for debugging the mess that is the VT code by
* path in the console code where we end up in places I want
* locked without the console sempahore held
*/
-static int console_locked, console_suspended;
+static int console_locked;
/*
* logbuf_lock protects log_buf, log_start, log_end, con_start and logged_chars
static int log_buf_len = __LOG_BUF_LEN;
static unsigned long logged_chars; /* Number of chars produced since last read+clear operation */
+/*
+ * Setup a list of consoles. Called from init/main.c
+ */
+static int __init console_setup(char *str)
+{
+ char name[sizeof(console_cmdline[0].name)];
+ char *s, *options;
+ int idx;
+
+ /*
+ * Decode str into name, index, options.
+ */
+ if (str[0] >= '0' && str[0] <= '9') {
+ strcpy(name, "ttyS");
+ strncpy(name + 4, str, sizeof(name) - 5);
+ } else
+ strncpy(name, str, sizeof(name) - 1);
+ name[sizeof(name) - 1] = 0;
+ if ((options = strchr(str, ',')) != NULL)
+ *(options++) = 0;
+#ifdef __sparc__
+ if (!strcmp(str, "ttya"))
+ strcpy(name, "ttyS0");
+ if (!strcmp(str, "ttyb"))
+ strcpy(name, "ttyS1");
+#endif
+ for (s = name; *s; s++)
+ if ((*s >= '0' && *s <= '9') || *s == ',')
+ break;
+ idx = simple_strtoul(s, NULL, 10);
+ *s = 0;
+
+ add_preferred_console(name, idx, options);
+ return 1;
+}
+
+__setup("console=", console_setup);
+
static int __init log_buf_len_setup(char *str)
{
unsigned long size = memparse(str, &str);
__setup("log_buf_len=", log_buf_len_setup);
-#ifdef CONFIG_BOOT_DELAY
-
-extern unsigned int boot_delay; /* msecs to delay after each printk during bootup */
-extern long preset_lpj;
-extern unsigned long long printk_delay_msec;
-
-static void boot_delay_msec(int millisecs)
-{
- unsigned long long k = printk_delay_msec * millisecs;
- unsigned long timeout;
-
- timeout = jiffies + msecs_to_jiffies(millisecs);
- while (k) {
- k--;
- cpu_relax();
- /*
- * use (volatile) jiffies to prevent
- * compiler reduction; loop termination via jiffies
- * is secondary and may or may not happen.
- */
- if (time_after(jiffies, timeout))
- break;
- touch_nmi_watchdog();
- }
-}
-
-#endif
-
/*
* Commands to do_syslog:
*
struct console *con;
for (con = console_drivers; con; con = con->next) {
- if ((con->flags & CON_ENABLED) && con->write &&
- (cpu_online(smp_processor_id()) ||
- (con->flags & CON_ANYTIME)))
+ if ((con->flags & CON_ENABLED) && con->write)
con->write(con, &LOG_BUF(start), end - start);
}
}
unsigned long cur_index, start_print;
static int msg_level = -1;
- BUG_ON(((long)(start - end)) > 0);
+ if (((long)(start - end)) > 0)
+ BUG();
cur_index = start;
start_print = start;
#else
static int printk_time = 0;
#endif
-module_param(printk_time, int, S_IRUGO | S_IWUSR);
static int __init printk_time_setup(char *str)
{
return sched_clock();
}
-/* Check if we have any console registered that can be called early in boot. */
-static int have_callable_console(void)
-{
- struct console *con;
-
- for (con = console_drivers; con; con = con->next)
- if (con->flags & CON_ANYTIME)
- return 1;
-
- return 0;
-}
-
/**
* printk - print a kernel message
* @fmt: format string
r = vprintk(fmt, args);
va_end(args);
-#ifdef CONFIG_BOOT_DELAY
- if (boot_delay && system_state == SYSTEM_BOOTING)
- boot_delay_msec(boot_delay);
-#endif
-
return r;
}
zap_locks();
/* This stops the holder of console_sem just where we want him */
- local_irq_save(flags);
- lockdep_off();
- spin_lock(&logbuf_lock);
+ spin_lock_irqsave(&logbuf_lock, flags);
printk_cpu = smp_processor_id();
/* Emit the output into the temporary buffer */
log_level_unknown = 1;
}
- if (!down_trylock(&console_sem)) {
+ if (!cpu_online(smp_processor_id())) {
/*
- * We own the drivers. We can drop the spinlock and
- * let release_console_sem() print the text, maybe ...
+ * Some console drivers may assume that per-cpu resources have
+ * been allocated. So don't allow them to be called by this
+ * CPU until it is officially up. We shouldn't be calling into
+ * random console drivers on a CPU which doesn't exist yet..
*/
- console_locked = 1;
printk_cpu = UINT_MAX;
- spin_unlock(&logbuf_lock);
-
+ spin_unlock_irqrestore(&logbuf_lock, flags);
+ goto out;
+ }
+ if (!down_trylock(&console_sem)) {
+ console_locked = 1;
/*
- * Console drivers may assume that per-cpu resources have
- * been allocated. So unless they're explicitly marked as
- * being able to cope (CON_ANYTIME) don't call them until
- * this CPU is officially up.
+ * We own the drivers. We can drop the spinlock and let
+ * release_console_sem() print the text
*/
- if (cpu_online(smp_processor_id()) || have_callable_console()) {
- console_may_schedule = 0;
- release_console_sem();
- } else {
- /* Release by hand to avoid flushing the buffer. */
- console_locked = 0;
- up(&console_sem);
- }
- lockdep_on();
- local_irq_restore(flags);
+ printk_cpu = UINT_MAX;
+ spin_unlock_irqrestore(&logbuf_lock, flags);
+ console_may_schedule = 0;
+ release_console_sem();
} else {
/*
* Someone else owns the drivers. We drop the spinlock, which
* console drivers with the output which we just produced.
*/
printk_cpu = UINT_MAX;
- spin_unlock(&logbuf_lock);
- lockdep_on();
- local_irq_restore(flags);
+ spin_unlock_irqrestore(&logbuf_lock, flags);
}
-
+out:
preempt_enable();
return printed_len;
}
#endif
-/*
- * Set up a list of consoles. Called from init/main.c
- */
-static int __init console_setup(char *str)
-{
- char name[sizeof(console_cmdline[0].name)];
- char *s, *options;
- int idx;
-
- /*
- * Decode str into name, index, options.
- */
- if (str[0] >= '0' && str[0] <= '9') {
- strcpy(name, "ttyS");
- strncpy(name + 4, str, sizeof(name) - 5);
- } else {
- strncpy(name, str, sizeof(name) - 1);
- }
- name[sizeof(name) - 1] = 0;
- if ((options = strchr(str, ',')) != NULL)
- *(options++) = 0;
-#ifdef __sparc__
- if (!strcmp(str, "ttya"))
- strcpy(name, "ttyS0");
- if (!strcmp(str, "ttyb"))
- strcpy(name, "ttyS1");
-#endif
- for (s = name; *s; s++)
- if ((*s >= '0' && *s <= '9') || *s == ',')
- break;
- idx = simple_strtoul(s, NULL, 10);
- *s = 0;
-
- add_preferred_console(name, idx, options);
- return 1;
-}
-__setup("console=", console_setup);
-
/**
* add_preferred_console - add a device to the list of preferred consoles.
* @name: device name
return 0;
}
-/**
- * suspend_console - suspend the console subsystem
- *
- * This disables printk() while we go into suspend states
- */
-void suspend_console(void)
-{
- acquire_console_sem();
- console_suspended = 1;
-}
-
-void resume_console(void)
-{
- console_suspended = 0;
- release_console_sem();
-}
-
/**
* acquire_console_sem - lock the console system for exclusive use.
*
*/
void acquire_console_sem(void)
{
- BUG_ON(in_interrupt());
- if (console_suspended) {
- down(&secondary_console_sem);
- return;
- }
+ if (in_interrupt())
+ BUG();
down(&console_sem);
console_locked = 1;
console_may_schedule = 1;
{
return console_locked;
}
-EXPORT_UNUSED_SYMBOL(is_console_locked); /* June 2006 */
+EXPORT_SYMBOL(is_console_locked);
/**
* release_console_sem - unlock the console system
unsigned long _con_start, _log_end;
unsigned long wake_klogd = 0;
- if (console_suspended) {
- up(&secondary_console_sem);
- return;
- }
-
- console_may_schedule = 0;
-
for ( ; ; ) {
spin_lock_irqsave(&logbuf_lock, flags);
wake_klogd |= log_start - log_end;
local_irq_restore(flags);
}
console_locked = 0;
+ console_may_schedule = 0;
up(&console_sem);
spin_unlock_irqrestore(&logbuf_lock, flags);
- if (wake_klogd && !oops_in_progress && waitqueue_active(&log_wait)) {
- /*
- * If we printk from within the lock dependency code,
- * from within the scheduler code, then do not lock
- * up due to self-recursion:
- */
- if (!lockdep_internal())
- wake_up_interruptible(&log_wait);
- }
+ if (wake_klogd && !oops_in_progress && waitqueue_active(&log_wait))
+ wake_up_interruptible(&log_wait);
}
EXPORT_SYMBOL(release_console_sem);