This is an automated email from the ASF dual-hosted git repository.
ligd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new d3460aa111d note/ram: support multiple noterams to dump data when
panic occurs
d3460aa111d is described below
commit d3460aa111dabb04e593c1a59b4577cd8038f825
Author: yinshengkai <[email protected]>
AuthorDate: Mon Dec 16 17:54:01 2024 +0800
note/ram: support multiple noterams to dump data when panic occurs
When creating a noteram, you can choose whether to dump
this noteram when the system crashes.
Signed-off-by: yinshengkai <[email protected]>
---
drivers/note/noteram_driver.c | 26 ++++++++++++++++++--------
include/nuttx/note/noteram_driver.h | 3 ++-
2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/drivers/note/noteram_driver.c b/drivers/note/noteram_driver.c
index 2d49dce06b1..0cca512e41e 100644
--- a/drivers/note/noteram_driver.c
+++ b/drivers/note/noteram_driver.c
@@ -42,6 +42,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/note/note_driver.h>
#include <nuttx/note/noteram_driver.h>
+#include <nuttx/nuttx.h>
#include <nuttx/panic_notifier.h>
#include <nuttx/fs/fs.h>
#include <nuttx/streams.h>
@@ -93,6 +94,7 @@ struct noteram_driver_s
volatile unsigned int ni_read;
spinlock_t lock;
FAR struct pollfd *pfd;
+ struct notifier_block nb;
};
/* The structure to hold the context data of trace dump */
@@ -1272,19 +1274,20 @@ static void noteram_dump(FAR struct noteram_driver_s
*drv)
static int noteram_crash_dump(FAR struct notifier_block *nb,
unsigned long action, FAR void *data)
{
+ FAR struct noteram_driver_s *drv =
+ container_of(nb, struct noteram_driver_s, nb);
if (action == PANIC_KERNEL)
{
- noteram_dump(&g_noteram_driver);
+ noteram_dump(drv);
}
return 0;
}
-static void noteram_crash_dump_register(void)
+static void noteram_crash_dump_register(FAR struct noteram_driver_s *drv)
{
- static struct notifier_block nb;
- nb.notifier_call = noteram_crash_dump;
- panic_notifier_chain_register(&nb);
+ drv->nb.notifier_call = noteram_crash_dump;
+ panic_notifier_chain_register(&drv->nb);
}
#endif
@@ -1310,7 +1313,7 @@ static void noteram_crash_dump_register(void)
int noteram_register(void)
{
#ifdef CONFIG_DRIVERS_NOTERAM_CRASH_DUMP
- noteram_crash_dump_register();
+ noteram_crash_dump_register(&g_noteram_driver);
#endif
return register_driver("/dev/note/ram", &g_noteram_fops, 0666,
&g_noteram_driver);
@@ -1334,7 +1337,8 @@ int noteram_register(void)
****************************************************************************/
FAR struct note_driver_s *
-noteram_initialize(FAR const char *devpath, size_t bufsize, bool overwrite)
+noteram_initialize(FAR const char *devpath, size_t bufsize,
+ bool overwrite, bool crashdump)
{
FAR struct noteram_driver_s *drv;
#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
@@ -1349,8 +1353,8 @@ noteram_initialize(FAR const char *devpath, size_t
bufsize, bool overwrite)
{
return NULL;
}
-#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
memcpy(drv + 1, devpath, len);
drv->driver.name = (FAR const char *)(drv + 1);
drv->driver.filter.mode.flag =
@@ -1360,7 +1364,13 @@ noteram_initialize(FAR const char *devpath, size_t
bufsize, bool overwrite)
drv->driver.filter.mode.cpuset =
CONFIG_SCHED_INSTRUMENTATION_CPUSET;
# endif
+#endif
+#ifdef CONFIG_DRIVERS_NOTERAM_CRASH_DUMP
+ if (crashdump)
+ {
+ noteram_crash_dump_register(drv);
+ }
#endif
drv->driver.ops = &g_noteram_ops;
diff --git a/include/nuttx/note/noteram_driver.h
b/include/nuttx/note/noteram_driver.h
index fe85e984c8f..35c147bd1bc 100644
--- a/include/nuttx/note/noteram_driver.h
+++ b/include/nuttx/note/noteram_driver.h
@@ -112,7 +112,8 @@ extern struct noteram_driver_s g_noteram_driver;
int noteram_register(void);
FAR struct note_driver_s *
-noteram_initialize(FAR const char *devpath, size_t bufsize, bool overwrite);
+noteram_initialize(FAR const char *devpath, size_t bufsize,
+ bool overwrite, bool crashdump);
#endif
#endif /* defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT) */