Lines Matching +full:per +full:- +full:cpu

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * printk_safe.c - Safe printk for printk-deadlock-prone contexts
21 * the strings into a per-CPU buffer. The content of the buffer
26 * per-CPU variable.
28 * The implementation allows to flush the strings also from another CPU.
33 #define SAFE_LOG_BUF_LEN ((1 << CONFIG_PRINTK_SAFE_LOG_BUF_SHIFT) - \
34 sizeof(atomic_t) - \
35 sizeof(atomic_t) - \
56 irq_work_queue(&s->work); in queue_flush_work()
60 * Add a message to per-CPU context-dependent buffer. NMI and printk-safe
61 * have dedicated buffers, because otherwise printk-safe preempted by
62 * NMI-printk would have overwritten the NMI messages.
65 * from other CPU, concurrently with printk_safe_log_store(). Should this
66 * happen, printk_safe_log_store() will notice the buffer->len mismatch
77 len = atomic_read(&s->len); in printk_safe_log_store()
80 if (len >= sizeof(s->buffer) - 1) { in printk_safe_log_store()
81 atomic_inc(&s->message_lost); in printk_safe_log_store()
94 add = vscnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, ap); in printk_safe_log_store()
102 * makes sure that the data were written before updating s->len. in printk_safe_log_store()
104 if (atomic_cmpxchg(&s->len, len, len + add) != len) in printk_safe_log_store()
135 printk_safe_flush_line(start, c - start + 1); in printk_safe_flush_buffer()
148 printk_safe_flush_line(start, c - start); in printk_safe_flush_buffer()
162 printk_safe_flush_line(start, end - start); in printk_safe_flush_buffer()
171 int lost = atomic_xchg(&s->message_lost, 0); in report_message_lost()
178 * Flush data from the associated per-CPU buffer. The function
202 len = atomic_read(&s->len); in __printk_safe_flush()
210 if ((i && i >= len) || len > sizeof(s->buffer)) { in __printk_safe_flush()
222 i += printk_safe_flush_buffer(s->buffer + i, len - i); in __printk_safe_flush()
228 * updating s->len. in __printk_safe_flush()
230 if (atomic_cmpxchg(&s->len, len, 0) != len) in __printk_safe_flush()
239 * printk_safe_flush - flush all per-cpu nmi buffers.
247 int cpu; in printk_safe_flush() local
249 for_each_possible_cpu(cpu) { in printk_safe_flush()
251 __printk_safe_flush(&per_cpu(nmi_print_seq, cpu).work); in printk_safe_flush()
253 __printk_safe_flush(&per_cpu(safe_print_seq, cpu).work); in printk_safe_flush()
258 * printk_safe_flush_on_panic - flush all per-cpu nmi buffers when the system
265 * Note that it could try harder when there is only one CPU online.
286 * Safe printk() for NMI context. It uses a per-CPU buffer to
289 * CPU, so we need to be careful.
315 * and use the per-CPU buffers only as a fallback when the lock
339 * Lock-less printk(), to avoid deadlocks should the printk() recurse
340 * into itself. It uses a per-CPU buffer to store the message, just like
398 int cpu; in printk_safe_init() local
400 for_each_possible_cpu(cpu) { in printk_safe_init()
403 s = &per_cpu(safe_print_seq, cpu); in printk_safe_init()
404 init_irq_work(&s->work, __printk_safe_flush); in printk_safe_init()
407 s = &per_cpu(nmi_print_seq, cpu); in printk_safe_init()
408 init_irq_work(&s->work, __printk_safe_flush); in printk_safe_init()