Skip to content

Commit 254e8fb

Browse files
committed
printk: ringbuffer: Explain why the KUnit test ignores failed writes
The KUnit test ignores prb_reserve() failures on purpose. It tries to push the ringbuffer beyond limits. Note that it is a know problem that writes might fail in this situation. printk() tries to prevent this problem by: + allocating big enough data buffer, see log_buf_add_cpu(). + allocating enough descriptors by using small enough average record, see PRB_AVGBITS. + storing the record with disabled interrupts, see vprintk_store(). Also the amount of printk() messages is always somehow bound in practice. And they are serialized when they are printed from many CPUs on purpose, for example, when printing backtraces. Reviewed-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://patch.msgid.link/20250702095157.110916-2-pmladek@suse.com Signed-off-by: Petr Mladek <pmladek@suse.com>
1 parent 5ea2bcd commit 254e8fb

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

kernel/printk/printk_ringbuffer_kunit_test.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ static int prbtest_writer(void *data)
123123
/* specify the text sizes for reservation */
124124
prb_rec_init_wr(&r, record_size);
125125

126+
/*
127+
* Reservation can fail if:
128+
*
129+
* - No free descriptor is available.
130+
* - The buffer is full, and the oldest record is reserved
131+
* but not yet committed.
132+
*
133+
* It actually happens in this test because all CPUs are trying
134+
* to write an unbounded number of messages in a tight loop.
135+
* These failures are intentionally ignored because this test
136+
* focuses on races, ringbuffer consistency, and pushing system
137+
* usability limits.
138+
*/
126139
if (prb_reserve(&e, tr->test_data->ringbuffer, &r)) {
127140
r.info->text_len = record_size;
128141

0 commit comments

Comments
 (0)