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
1583static struct cont {1583static struct cont {
1584 char buf[LOG_LINE_MAX];1584 char buf[LOG_LINE_MAX];
1585 size_t len; /* length == 0 means unused buffer */1585 size_t len; /* length == 0 means unused buffer */
1586 size_t cons; /* bytes written to console */
1587 struct task_struct *owner; /* task of first print*/1586 struct task_struct *owner; /* task of first print*/
1588 u64 ts_nsec; /* time of first print */1587 u64 ts_nsec; /* time of first print */
1589 u8 level; /* log level of first message */1588 u8 level; /* log level of first message */
1590 u8 facility; /* log facility of first message */1589 u8 facility; /* log facility of first message */
1591 enum log_flags flags; /* prefix, newline flags */1590 enum log_flags flags; /* prefix, newline flags */
1592 bool flushed:1; /* buffer sealed and committed */
1593} cont;1591} cont;
1594 1592
1595static void cont_flush(void)1593static void cont_flush(void)
1596{1594{
1597 if (cont.flushed)
1598 return;
1599 if (cont.len == 0)1595 if (cont.len == 0)
1600 return;1596 return;
1601 if (cont.cons) {1597
1602 /*1598 log_store(cont.facility, cont.level, cont.flags, cont.ts_nsec,
1603 * If a fragment of this line was directly flushed to the1599 NULL, 0, cont.buf, cont.len);
1604 * console; wait for the console to pick up the rest of the1600 cont.len = 0;
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 }
1619}1601}
1620 1602
1621static bool cont_add(int facility, int level, enum log_flags flags, const char *text, size_t len)1603static bool cont_add(int facility, int level, enum log_flags flags, const char *text, size_t len)
1622{1604{
1623 if (cont.len && cont.flushed)
1624 return false;
1625
1626 /*1605 /*
1627 * If ext consoles are present, flush and skip in-kernel1606 * If ext consoles are present, flush and skip in-kernel
1628 * continuation. See nr_ext_console_drivers definition. Also, if1607 * 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
1639 cont.owner = current;1618 cont.owner = current;
1640 cont.ts_nsec = local_clock();1619 cont.ts_nsec = local_clock();
1641 cont.flags = flags;1620 cont.flags = flags;
1642 cont.cons = 0;
1643 cont.flushed = false;
1644 }1621 }
1645 1622
1646 memcpy(cont.buf + cont.len, text, len);1623 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
1659 return true;1636 return true;
1660}1637}
1661 1638
1662static 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
1690static size_t log_output(int facility, int level, enum log_flags lflags, const char *dict, size_t dictlen, char *text, size_t text_len)1639static size_t log_output(int facility, int level, enum log_flags lflags, const char *dict, size_t dictlen, char *text, size_t text_len)
1691{1640{
1692 /*1641 /*
@@ -1957,7 +1906,6 @@ static void call_console_drivers(int level, · 264 unmodified lines
1957 const char *text, size_t len) {}1906 const char *text, size_t len) {}
1958static size_t msg_print_text(const struct printk_log *msg,1907static size_t msg_print_text(const struct printk_log *msg,
1959 bool syslog, char *buf, size_t size) { return 0; }1908 bool syslog, char *buf, size_t size) { return 0; }
1960static size_t cont_print_text(char *text, size_t size) { return 0; }
1961static bool suppress_message_printing(int level) { return false; }1909static bool suppress_message_printing(int level) { return false; }
1962 1910
1963/* Still needs to be defined for users */1911/* Still needs to be defined for users */
@@ -2221,42 +2169,6 @@ static inline int can_use_console(void) · 257 unmodified lines
2221 return cpu_online(raw_smp_processor_id()) || have_callable_console();2169 return cpu_online(raw_smp_processor_id()) || have_callable_console();
2222}2170}
2223 2171
2224static 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;
2256out:
2257 raw_spin_unlock_irqrestore(&logbuf_lock, flags);
2258}
2259
2260/**2172/**
2261 * console_unlock - unlock the console system2173 * console_unlock - unlock the console system
2262 *2174 *
@@ -2310,9 +2222,6 @@ again: · 47 unmodified lines
2310 return;2222 return;
2311 }2223 }
2312 2224
2313 /* flush buffered message fragment immediately to console */
2314 console_cont_flush(text, sizeof(text));
2315
2316 for (;;) {2225 for (;;) {
2317 struct printk_log *msg;2226 struct printk_log *msg;
2318 size_t ext_len = 0;2227 size_t ext_len = 0;
@@ -2341,8 +2250,7 @@ skip: · 22 unmodified lines
2341 2250
2342 msg = log_from_idx(console_idx);2251 msg = log_from_idx(console_idx);
2343 level = msg->level;2252 level = msg->level;
2344 if ((msg->flags & LOG_NOCONS) ||2253 if (suppress_message_printing(level)) {
2345 suppress_message_printing(level)) {
2346 /*2254 /*
2347 * Skip record we have buffered and already printed2255 * Skip record we have buffered and already printed
2348 * directly to the console when we received it, and2256 * directly to the console when we received it, and
@@ -2350,12 +2258,6 @@ skip: · 1 unmodified line
2350 */2258 */
2351 console_idx = log_next(console_idx);2259 console_idx = log_next(console_idx);
2352 console_seq++;2260 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;
2359 goto skip;2261 goto skip;
2360 }2262 }
2361 2263

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