History

printk: remove console flushing special cases for partial buffered lines

It actively hurts proper merging, and makes for a lot of special cases. There was a good(ish) reason for doing it originally, but it's getting too painful to maintain. And most of the original reasons for it are long gone. So instead of having special code to flush partial lines to the console (as opposed to the record buffers), do _all_ the console writing from the record buffer, and be done with it. If an oops happens (or some other synchronous event), we will flush the partial lines due to the oops printing activity, so this does not affect that. It does mean that if you have a completely hung machine, a partial preceding line may not have been printed out. That was some of the original reason for this complexity, in fact, back when we used to test for the historical i386 "halt" instruction problem by doing pr_info("Checking 'hlt' instruction... "); if (!boot_cpu_data.hlt_works_ok) { pr_cont("disabled\n"); return; } halt(); halt(); halt(); halt(); pr_cont("OK\n"); and that model no longer works (it the 'hlt' instruction kills the machine, the partial line won't have been flushed, so you won't even see it). Of course, that was also back in the days when people actually had textual console output rather than a graphical splash-screen at bootup. How times change..

Linus Torvalds committed 10 years ago

Commit 5c2992e1 parent 5aa068e1 file · +5 −103Browse files

Unified · Split

kernel/printk/printk.c+5−103
@@ -1583,46 +1583,25 @@ static inline void printk_delay(void) · 1582 unmodified lines
15831583 static struct cont {
15841584 char buf[LOG_LINE_MAX];
15851585 size_t len; /* length == 0 means unused buffer */
1586− size_t cons; /* bytes written to console */
15871586 struct task_struct *owner; /* task of first print*/
15881587 u64 ts_nsec; /* time of first print */
15891588 u8 level; /* log level of first message */
15901589 u8 facility; /* log facility of first message */
15911590 enum log_flags flags; /* prefix, newline flags */
1592− bool flushed:1; /* buffer sealed and committed */
15931591 } cont;
15941592
15951593 static void cont_flush(void)
15961594 {
1597− if (cont.flushed)
1598− return;
15991595 if (cont.len == 0)
16001596 return;
1601− if (cont.cons) {
1602− /*
1603− * If a fragment of this line was directly flushed to the
1604− * console; wait for the console to pick up the rest of the
1605− * line. LOG_NOCONS suppresses a duplicated output.
1606− */
1607− log_store(cont.facility, cont.level, cont.flags | LOG_NOCONS,
1608− cont.ts_nsec, NULL, 0, cont.buf, cont.len);
1609− cont.flushed = true;
1610− } else {
1611− /*
1612− * If no fragment of this line ever reached the console,
1613− * just submit it to the store and free the buffer.
1614− */
1615− log_store(cont.facility, cont.level, cont.flags, 0,
1616− NULL, 0, cont.buf, cont.len);
1617− cont.len = 0;
1618− }
1597+
1598+ log_store(cont.facility, cont.level, cont.flags, cont.ts_nsec,
1599+ NULL, 0, cont.buf, cont.len);
1600+ cont.len = 0;
16191601 }
16201602
16211603 static bool cont_add(int facility, int level, enum log_flags flags, const char *text, size_t len)
16221604 {
1623− if (cont.len && cont.flushed)
1624− return false;
1625−
16261605 /*
16271606 * If ext consoles are present, flush and skip in-kernel
16281607 * continuation. See nr_ext_console_drivers definition. Also, if
@@ -1639,8 +1618,6 @@ static bool cont_add(int facility, int level, enum log_flags flags, const char * · 10 unmodified lines
16391618 cont.owner = current;
16401619 cont.ts_nsec = local_clock();
16411620 cont.flags = flags;
1642− cont.cons = 0;
1643− cont.flushed = false;
16441621 }
16451622
16461623 memcpy(cont.buf + cont.len, text, len);
@@ -1659,34 +1636,6 @@ static bool cont_add(int facility, int level, enum log_flags flags, const char * · 12 unmodified lines
16591636 return true;
16601637 }
16611638
1662−static size_t cont_print_text(char *text, size_t size)
1663−{
1664− size_t textlen = 0;
1665− size_t len;
1666−
1667− if (cont.cons == 0) {
1668− textlen += print_time(cont.ts_nsec, text);
1669− size -= textlen;
1670− }
1671−
1672− len = cont.len - cont.cons;
1673− if (len > 0) {
1674− if (len+1 > size)
1675− len = size-1;
1676− memcpy(text + textlen, cont.buf + cont.cons, len);
1677− textlen += len;
1678− cont.cons = cont.len;
1679− }
1680−
1681− if (cont.flushed) {
1682− if (cont.flags & LOG_NEWLINE)
1683− text[textlen++] = '\n';
1684− /* got everything, release buffer */
1685− cont.len = 0;
1686− }
1687− return textlen;
1688−}
1689−
16901639 static size_t log_output(int facility, int level, enum log_flags lflags, const char *dict, size_t dictlen, char *text, size_t text_len)
16911640 {
16921641 /*
@@ -1957,7 +1906,6 @@ static void call_console_drivers(int level, · 264 unmodified lines
19571906 const char *text, size_t len) {}
19581907 static size_t msg_print_text(const struct printk_log *msg,
19591908 bool syslog, char *buf, size_t size) { return 0; }
1960−static size_t cont_print_text(char *text, size_t size) { return 0; }
19611909 static bool suppress_message_printing(int level) { return false; }
19621910
19631911 /* Still needs to be defined for users */
@@ -2221,42 +2169,6 @@ static inline int can_use_console(void) · 257 unmodified lines
22212169 return cpu_online(raw_smp_processor_id()) || have_callable_console();
22222170 }
22232171
2224−static void console_cont_flush(char *text, size_t size)
2225−{
2226− unsigned long flags;
2227− size_t len;
2228−
2229− raw_spin_lock_irqsave(&logbuf_lock, flags);
2230−
2231− if (!cont.len)
2232− goto out;
2233−
2234− if (suppress_message_printing(cont.level)) {
2235− cont.cons = cont.len;
2236− if (cont.flushed)
2237− cont.len = 0;
2238− goto out;
2239− }
2240−
2241− /*
2242− * We still queue earlier records, likely because the console was
2243− * busy. The earlier ones need to be printed before this one, we
2244− * did not flush any fragment so far, so just let it queue up.
2245− */
2246− if (console_seq < log_next_seq && !cont.cons)
2247− goto out;
2248−
2249− len = cont_print_text(text, size);
2250− raw_spin_unlock(&logbuf_lock);
2251− stop_critical_timings();
2252− call_console_drivers(cont.level, NULL, 0, text, len);
2253− start_critical_timings();
2254− local_irq_restore(flags);
2255− return;
2256−out:
2257− raw_spin_unlock_irqrestore(&logbuf_lock, flags);
2258−}
2259−
22602172 /**
22612173 * console_unlock - unlock the console system
22622174 *
@@ -2310,9 +2222,6 @@ again: · 47 unmodified lines
23102222 return;
23112223 }
23122224
2313− /* flush buffered message fragment immediately to console */
2314− console_cont_flush(text, sizeof(text));
2315−
23162225 for (;;) {
23172226 struct printk_log *msg;
23182227 size_t ext_len = 0;
@@ -2341,8 +2250,7 @@ skip: · 22 unmodified lines
23412250
23422251 msg = log_from_idx(console_idx);
23432252 level = msg->level;
2344− if ((msg->flags & LOG_NOCONS) ||
2345− suppress_message_printing(level)) {
2253+ if (suppress_message_printing(level)) {
23462254 /*
23472255 * Skip record we have buffered and already printed
23482256 * directly to the console when we received it, and
@@ -2350,12 +2258,6 @@ skip: · 1 unmodified line
23502258 */
23512259 console_idx = log_next(console_idx);
23522260 console_seq++;
2353− /*
2354− * We will get here again when we register a new
2355− * CON_PRINTBUFFER console. Clear the flag so we
2356− * will properly dump everything later.
2357− */
2358− msg->flags &= ~LOG_NOCONS;
23592261 goto skip;
23602262 }
23612263

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t