aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ogness <john.ogness@linutronix.de>2020-11-30 01:42:05 +0106
committerSebastian Andrzej Siewior <bigeasy@linutronix.de>2021-03-19 22:00:01 +0100
commitbc04b285e73c1a64fd5d9723af20a21ce0feb628 (patch)
tree3f5517287bfffb0d199f3fa542c07297107e35fb
parent7ce1e5e65cac099b0540124e2d58622f5cfbeb43 (diff)
downloadlinux-rt-devel-bc04b285e73c1a64fd5d9723af20a21ce0feb628.tar.gz
printk: use seqcount_latch for console_seq
In preparation for atomic printing, change @console_seq to use seqcount_latch so that it can be read without requiring @console_sem. Signed-off-by: John Ogness <john.ogness@linutronix.de> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
-rw-r--r--kernel/printk/printk.c68
1 files changed, 41 insertions, 27 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 4dabdf116ed3e..818120aa79367 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -367,9 +367,7 @@ static u64 syslog_seq;
static size_t syslog_partial;
static bool syslog_time;
-/* All 3 protected by @console_sem. */
-/* the next printk record to write to the console */
-static u64 console_seq;
+/* Both protected by @console_sem. */
static u64 exclusive_console_stop_seq;
static unsigned long console_dropped;
@@ -379,6 +377,17 @@ struct latched_seq {
};
/*
+ * The next printk record to write to the console. There are two
+ * copies (updated with seqcount_latch) so that reads can locklessly
+ * access a valid value. Writers are synchronized by @console_sem.
+ */
+static struct latched_seq console_seq = {
+ .latch = SEQCNT_LATCH_ZERO(console_seq.latch),
+ .val[0] = 0,
+ .val[1] = 0,
+};
+
+/*
* The next printk record to read after the last 'clear' command. There are
* two copies (updated with seqcount_latch) so that reads can locklessly
* access a valid value. Writers are synchronized by @syslog_lock.
@@ -441,7 +450,7 @@ bool printk_percpu_data_ready(void)
return __printk_percpu_data_ready;
}
-/* Must be called under syslog_lock. */
+/* Must be called under associated write-protection lock. */
static void latched_seq_write(struct latched_seq *ls, u64 val)
{
raw_write_seqcount_latch(&ls->latch);
@@ -2276,7 +2285,8 @@ EXPORT_SYMBOL(printk);
#define prb_first_valid_seq(rb) 0
static u64 syslog_seq;
-static u64 console_seq;
+#error FIXME
+static atomic64_t console_seq = ATOMIC64_INIT(0);
static u64 exclusive_console_stop_seq;
static unsigned long console_dropped;
@@ -2592,6 +2602,7 @@ void console_unlock(void)
bool do_cond_resched, retry;
struct printk_info info;
struct printk_record r;
+ u64 seq;
if (console_suspended) {
up_console_sem();
@@ -2634,12 +2645,14 @@ again:
size_t len;
skip:
- if (!prb_read_valid(prb, console_seq, &r))
+ seq = latched_seq_read_nolock(&console_seq);
+ if (!prb_read_valid(prb, seq, &r))
break;
- if (console_seq != r.info->seq) {
- console_dropped += r.info->seq - console_seq;
- console_seq = r.info->seq;
+ if (seq != r.info->seq) {
+ console_dropped += r.info->seq - seq;
+ latched_seq_write(&console_seq, r.info->seq);
+ seq = r.info->seq;
}
if (suppress_message_printing(r.info->level)) {
@@ -2648,13 +2661,13 @@ skip:
* directly to the console when we received it, and
* record that has level above the console loglevel.
*/
- console_seq++;
+ latched_seq_write(&console_seq, seq + 1);
goto skip;
}
/* Output to all consoles once old messages replayed. */
if (unlikely(exclusive_console &&
- console_seq >= exclusive_console_stop_seq)) {
+ seq >= exclusive_console_stop_seq)) {
exclusive_console = NULL;
}
@@ -2675,7 +2688,7 @@ skip:
len = record_print_text(&r,
console_msg_format & MSG_FORMAT_SYSLOG,
printk_time);
- console_seq++;
+ latched_seq_write(&console_seq, seq + 1);
printk_safe_enter_irqsave(flags);
@@ -2712,7 +2725,7 @@ skip:
* there's a new owner and the console_unlock() from them will do the
* flush, no worries.
*/
- retry = prb_read_valid(prb, console_seq, NULL);
+ retry = prb_read_valid(prb, latched_seq_read_nolock(&console_seq), NULL);
if (retry && console_trylock())
goto again;
}
@@ -2764,18 +2777,19 @@ void console_unblank(void)
*/
void console_flush_on_panic(enum con_flush_mode mode)
{
- /*
- * If someone else is holding the console lock, trylock will fail
- * and may_schedule may be set. Ignore and proceed to unlock so
- * that messages are flushed out. As this can be called from any
- * context and we don't want to get preempted while flushing,
- * ensure may_schedule is cleared.
- */
- console_trylock();
- console_may_schedule = 0;
-
- if (mode == CONSOLE_REPLAY_ALL)
- console_seq = prb_first_valid_seq(prb);
+ if (console_trylock()) {
+ if (mode == CONSOLE_REPLAY_ALL)
+ latched_seq_write(&console_seq, prb_first_valid_seq(prb));
+ } else {
+ /*
+ * Another context is holding the console lock and
+ * @console_may_schedule may be set. Ignore and proceed to
+ * unlock so that messages are flushed out. As this can be
+ * called from any context and we don't want to get preempted
+ * while flushing, ensure @console_may_schedule is cleared.
+ */
+ console_may_schedule = 0;
+ }
console_unlock();
}
@@ -3012,11 +3026,11 @@ void register_console(struct console *newcon)
* ignores console_lock.
*/
exclusive_console = newcon;
- exclusive_console_stop_seq = console_seq;
+ exclusive_console_stop_seq = latched_seq_read_nolock(&console_seq);
/* Get a consistent copy of @syslog_seq. */
spin_lock_irqsave(&syslog_lock, flags);
- console_seq = syslog_seq;
+ latched_seq_write(&console_seq, syslog_seq);
spin_unlock_irqrestore(&syslog_lock, flags);
}
console_unlock();