Skip to content

Commit 36652d0

Browse files
jognesspmladek
authored andcommitted
printk: Add this_cpu_in_panic()
There is already panic_in_progress() and other_cpu_in_panic(), but checking if the current CPU is the panic CPU must still be open coded. Add this_cpu_in_panic() to complete the set. Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Petr Mladek <[email protected]>
1 parent 0ab7cdd commit 36652d0

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

kernel/printk/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct printk_message {
130130
};
131131

132132
bool other_cpu_in_panic(void);
133+
bool this_cpu_in_panic(void);
133134
bool printk_get_next_message(struct printk_message *pmsg, u64 seq,
134135
bool is_extended, bool may_supress);
135136

kernel/printk/printk.c

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,29 @@ static bool panic_in_progress(void)
347347
return unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID);
348348
}
349349

350+
/* Return true if a panic is in progress on the current CPU. */
351+
bool this_cpu_in_panic(void)
352+
{
353+
/*
354+
* We can use raw_smp_processor_id() here because it is impossible for
355+
* the task to be migrated to the panic_cpu, or away from it. If
356+
* panic_cpu has already been set, and we're not currently executing on
357+
* that CPU, then we never will be.
358+
*/
359+
return unlikely(atomic_read(&panic_cpu) == raw_smp_processor_id());
360+
}
361+
362+
/*
363+
* Return true if a panic is in progress on a remote CPU.
364+
*
365+
* On true, the local CPU should immediately release any printing resources
366+
* that may be needed by the panic CPU.
367+
*/
368+
bool other_cpu_in_panic(void)
369+
{
370+
return (panic_in_progress() && !this_cpu_in_panic());
371+
}
372+
350373
/*
351374
* This is used for debugging the mess that is the VT code by
352375
* keeping track if we have the console semaphore held. It's
@@ -2592,26 +2615,6 @@ static int console_cpu_notify(unsigned int cpu)
25922615
return 0;
25932616
}
25942617

2595-
/*
2596-
* Return true if a panic is in progress on a remote CPU.
2597-
*
2598-
* On true, the local CPU should immediately release any printing resources
2599-
* that may be needed by the panic CPU.
2600-
*/
2601-
bool other_cpu_in_panic(void)
2602-
{
2603-
if (!panic_in_progress())
2604-
return false;
2605-
2606-
/*
2607-
* We can use raw_smp_processor_id() here because it is impossible for
2608-
* the task to be migrated to the panic_cpu, or away from it. If
2609-
* panic_cpu has already been set, and we're not currently executing on
2610-
* that CPU, then we never will be.
2611-
*/
2612-
return atomic_read(&panic_cpu) != raw_smp_processor_id();
2613-
}
2614-
26152618
/**
26162619
* console_lock - block the console subsystem from printing
26172620
*

0 commit comments

Comments
 (0)