drivers/note: dump the latest scheduling information when panic

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2023-02-24 11:37:35 +08:00 committed by Xiang Xiao
parent f9f0ab8dc4
commit aa6bffef83

View file

@ -26,6 +26,7 @@
#include <nuttx/note/note_driver.h>
#include <nuttx/note/notesnap_driver.h>
#include <nuttx/panic_notifier.h>
#include <nuttx/sched_note.h>
#include <sched/sched.h>
@ -51,6 +52,7 @@ struct notesnap_chunk_s
struct notesnap_s
{
struct note_driver_s driver;
struct notifier_block nb;
size_t index;
bool dumping;
struct notesnap_chunk_s buffer[CONFIG_DRIVERS_NOTESNAP_NBUFFERS];
@ -192,7 +194,10 @@ static inline void notesnap_common(FAR struct note_driver_s *drv,
FAR struct tcb_s *tcb, uint8_t type,
uintptr_t args)
{
struct notesnap_s *snap = (struct notesnap_s *)drv;
FAR struct notesnap_s *snap = (FAR struct notesnap_s *)drv;
FAR struct notesnap_chunk_s *note;
size_t index;
if (snap->dumping)
{
return;
@ -200,9 +205,8 @@ static inline void notesnap_common(FAR struct note_driver_s *drv,
/* Atomic operation, equivalent to snap.index++; */
size_t index = atomic_fetch_add(&snap->index, 1);
FAR struct notesnap_chunk_s *note =
&snap->buffer[index % CONFIG_DRIVERS_NOTESNAP_NBUFFERS];
index = atomic_fetch_add(&snap->index, 1);
note = &snap->buffer[index % CONFIG_DRIVERS_NOTESNAP_NBUFFERS];
note->type = type;
#ifdef CONFIG_SMP
@ -337,6 +341,17 @@ static void notesnap_syscall_leave(FAR struct note_driver_s *drv, int nr,
}
#endif
static int notesnap_notifier(FAR struct notifier_block *nb,
unsigned long action, FAR void *data)
{
if (action == PANIC_KERNEL)
{
notesnap_dump();
}
return 0;
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -347,6 +362,8 @@ static void notesnap_syscall_leave(FAR struct note_driver_s *drv, int nr,
int notesnap_register(void)
{
g_notesnap.nb.notifier_call = notesnap_notifier;
panic_notifier_chain_register(&g_notesnap.nb);
return note_driver_register(&g_notesnap.driver);
}