You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/10/13 06:05:57 UTC

(nuttx) 01/13: note: Move the instrument register to note_initialize

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 19851c09794bf8fa37df4cfb6cc8369b8cfec1db
Author: cuiziwei <cu...@xiaomi.com>
AuthorDate: Tue Dec 5 20:15:48 2023 +0800

    note: Move the instrument register to note_initialize
    
    avoid the instrument doesn't get registered in some case
    
    Signed-off-by: cuiziwei <cu...@xiaomi.com>
    Signed-off-by: yinshengkai <yi...@xiaomi.com>
---
 drivers/note/note_driver.c     | 40 ---------------------------------
 drivers/note/note_initialize.c | 50 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 40 deletions(-)

diff --git a/drivers/note/note_driver.c b/drivers/note/note_driver.c
index 3f6416cf2a..218e3443f3 100644
--- a/drivers/note/note_driver.c
+++ b/drivers/note/note_driver.c
@@ -41,7 +41,6 @@
 #include <nuttx/note/notestream_driver.h>
 #include <nuttx/spinlock.h>
 #include <nuttx/sched_note.h>
-#include <nuttx/instrument.h>
 
 #include "sched/sched.h"
 #include "noterpmsg.h"
@@ -157,18 +156,6 @@ struct note_taskname_s
  * Private Data
  ****************************************************************************/
 
-#ifdef CONFIG_SCHED_INSTRUMENTATION_FUNCTION
-static void note_driver_instrument_enter(FAR void *this_fn,
-            FAR void *call_site, FAR void *arg) noinstrument_function;
-static void note_driver_instrument_leave(FAR void *this_fn,
-            FAR void *call_site, FAR void *arg) noinstrument_function;
-static struct instrument_s g_note_instrument =
-{
-  .enter = note_driver_instrument_enter,
-  .leave = note_driver_instrument_leave,
-};
-#endif
-
 #ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
 static struct note_filter_s g_note_filter =
 {
@@ -1997,24 +1984,6 @@ FAR const char *note_get_taskname(pid_t pid)
 
 #endif
 
-#ifdef CONFIG_SCHED_INSTRUMENTATION_FUNCTION
-static void note_driver_instrument_enter(FAR void *this_fn,
-                                         FAR void *call_site,
-                                         FAR void *arg)
-{
-  sched_note_event_ip(NOTE_TAG_ALWAYS, (uintptr_t)this_fn,
-                      NOTE_DUMP_BEGIN, NULL, 0);
-}
-
-static void note_driver_instrument_leave(FAR void *this_fn,
-                                         FAR void *call_site,
-                                         FAR void *arg)
-{
-  sched_note_event_ip(NOTE_TAG_ALWAYS, (uintptr_t)this_fn,
-                      NOTE_DUMP_END, NULL, 0);
-}
-#endif
-
 /****************************************************************************
  * Name: note_driver_register
  ****************************************************************************/
@@ -2022,15 +1991,6 @@ static void note_driver_instrument_leave(FAR void *this_fn,
 int note_driver_register(FAR struct note_driver_s *driver)
 {
   int i;
-#ifdef CONFIG_SCHED_INSTRUMENTATION_FUNCTION
-  static bool initialized;
-
-  if (!initialized)
-    {
-      instrument_register(&g_note_instrument);
-      initialized = true;
-    }
-#endif
 
   DEBUGASSERT(driver);
   for (i = 0; i < CONFIG_DRIVERS_NOTE_MAX; i++)
diff --git a/drivers/note/note_initialize.c b/drivers/note/note_initialize.c
index 1b933e45d7..00383d2624 100644
--- a/drivers/note/note_initialize.c
+++ b/drivers/note/note_initialize.c
@@ -24,6 +24,7 @@
 
 #include <debug.h>
 
+#include <nuttx/instrument.h>
 #include <nuttx/note/note_driver.h>
 #include <nuttx/note/noteram_driver.h>
 #include <nuttx/note/notectl_driver.h>
@@ -34,6 +35,51 @@
 
 #include "noterpmsg.h"
 
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FUNCTION
+static void note_driver_instrument_enter(FAR void *this_fn,
+            FAR void *call_site, FAR void *arg) noinstrument_function;
+static void note_driver_instrument_leave(FAR void *this_fn,
+            FAR void *call_site, FAR void *arg) noinstrument_function;
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FUNCTION
+static void note_driver_instrument_enter(FAR void *this_fn,
+                                         FAR void *call_site,
+                                         FAR void *arg)
+{
+  sched_note_event_ip(NOTE_TAG_ALWAYS, (uintptr_t)this_fn,
+                      NOTE_DUMP_BEGIN, NULL, 0);
+}
+
+static void note_driver_instrument_leave(FAR void *this_fn,
+                                         FAR void *call_site,
+                                         FAR void *arg)
+{
+  sched_note_event_ip(NOTE_TAG_ALWAYS, (uintptr_t)this_fn,
+                      NOTE_DUMP_END, NULL, 0);
+}
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FUNCTION
+static struct instrument_s g_note_instrument =
+{
+  .enter = note_driver_instrument_enter,
+  .leave = note_driver_instrument_leave,
+};
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -97,6 +143,10 @@ int note_initialize(void)
 {
   int ret = 0;
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FUNCTION
+  instrument_register(&g_note_instrument);
+#endif
+
 #ifdef CONFIG_DRIVERS_NOTERAM
   ret = noteram_register();
   if (ret < 0)