xiaoxiang781216 commented on a change in pull request #1377:
URL: https://github.com/apache/incubator-nuttx/pull/1377#discussion_r490679202



##########
File path: include/nuttx/sched_note.h
##########
@@ -254,10 +266,78 @@ struct note_irqhandler_s
 };
 #endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+
+/* This is the type of the argument passed to the TRIOC_GETMODE and
+ * TRIOC_SETMODE ioctls
+ */
+
+struct note_trace_mode_s
+{
+  bool enable;                /* Trace enable */
+  unsigned int flag;          /* Trace mode flag */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+#define TRIOC_MODE_FLAG_SYSCALL      (1 << 0) /* Enable syscall trace */
+#define TRIOC_MODE_FLAG_SYSCALL_ARGS (1 << 1) /* Enable collecting syscall 
arguments */
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+#define TRIOC_MODE_FLAG_IRQ          (1 << 2) /* Enable IRQ trace */
+#endif

Review comment:
       should we move the macro defintion to the predefine section?

##########
File path: include/nuttx/sched_note.h
##########
@@ -254,10 +266,78 @@ struct note_irqhandler_s
 };
 #endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+
+/* This is the type of the argument passed to the TRIOC_GETMODE and
+ * TRIOC_SETMODE ioctls
+ */
+
+struct note_trace_mode_s

Review comment:
       should we change all note_trace_ to note_filter_?

##########
File path: include/nuttx/sched_note.h
##########
@@ -254,10 +266,78 @@ struct note_irqhandler_s
 };
 #endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+
+/* This is the type of the argument passed to the TRIOC_GETMODE and
+ * TRIOC_SETMODE ioctls
+ */
+
+struct note_trace_mode_s
+{
+  bool enable;                /* Trace enable */
+  unsigned int flag;          /* Trace mode flag */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+#define TRIOC_MODE_FLAG_SYSCALL      (1 << 0) /* Enable syscall trace */
+#define TRIOC_MODE_FLAG_SYSCALL_ARGS (1 << 1) /* Enable collecting syscall 
arguments */
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+#define TRIOC_MODE_FLAG_IRQ          (1 << 2) /* Enable IRQ trace */
+#endif
+};
+
+/* This is the type of the argument passed to the TRIOC_GETSYSCALLFILTER and
+ * TRIOC_SETSYSCALLFILTER ioctls
+ */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+struct note_trace_syscallfilter_s
+{
+  uint8_t syscall_mask[(SYS_nsyscalls + 7) / 8];
+};
+
+/* Helper macros */
+
+#define SYSCALLMASK_SET(nr, s) \

Review comment:
       SYSCALLMASK_ to NOTE_FILTER_SYSCALLMASK_ ?

##########
File path: include/nuttx/sched_note.h
##########
@@ -254,10 +266,78 @@ struct note_irqhandler_s
 };
 #endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+
+/* This is the type of the argument passed to the TRIOC_GETMODE and
+ * TRIOC_SETMODE ioctls
+ */
+
+struct note_trace_mode_s
+{
+  bool enable;                /* Trace enable */
+  unsigned int flag;          /* Trace mode flag */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+#define TRIOC_MODE_FLAG_SYSCALL      (1 << 0) /* Enable syscall trace */
+#define TRIOC_MODE_FLAG_SYSCALL_ARGS (1 << 1) /* Enable collecting syscall 
arguments */
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+#define TRIOC_MODE_FLAG_IRQ          (1 << 2) /* Enable IRQ trace */
+#endif
+};
+
+/* This is the type of the argument passed to the TRIOC_GETSYSCALLFILTER and
+ * TRIOC_SETSYSCALLFILTER ioctls
+ */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+struct note_trace_syscallfilter_s
+{
+  uint8_t syscall_mask[(SYS_nsyscalls + 7) / 8];
+};
+
+/* Helper macros */
+
+#define SYSCALLMASK_SET(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] |= (1 << ((nr) % 8)))
+#define SYSCALLMASK_CLR(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] &= ~(1 << ((nr) % 8)))
+#define SYSCALLMASK_ISSET(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] & (1 << ((nr) % 8)))
+#define SYSCALLMASK_ZERO(s) \
+  memset((s), 0, sizeof(struct note_trace_syscallfilter_s))
+#endif
+
+/* This is the type of the argument passed to the TRIOC_GETIRQFILTER and
+ * TRIOC_SETIRQFILTER ioctls
+ */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+struct note_trace_irqfilter_s
+{
+  uint8_t irq_mask[(NR_IRQS + 7) / 8];
+};
+
+/* Helper macros */
+
+#define IRQMASK_SET(nr, s) \

Review comment:
       IRQMASK_ to NOTE_FILTER_IRQMASK_?

##########
File path: sched/sched/sched_note.c
##########
@@ -587,13 +652,25 @@ void sched_note_irqhandler(int irq, FAR void *handler, 
bool enter)
   struct note_irqhandler_s note;
   FAR struct tcb_s *tcb = this_task();
 
-#ifdef CONFIG_SMP
-  /* Ignore notes that are not in the set of monitored CPUs */
-
-  if ((CONFIG_SCHED_INSTRUMENTATION_CPUSET & (1 << this_cpu())) == 0)
+  if (!note_isenabled())
     {
-      /* Not in the set of monitored CPUs.  Do not log the note. */
+      return;
+    }
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  /* If the IRQ trace is disabled or the IRQ number is masked,
+   * do nothing.
+   */
+
+  if (g_note_filter.mode.flag & TRIOC_MODE_FLAG_IRQ)

Review comment:
       should we add a new function note_isenabled_irq which call 
note_isenabled and check IRQMASK_ISSET?

##########
File path: drivers/note/noteram_driver.c
##########
@@ -57,28 +58,33 @@ struct noteram_info_s
 {
   volatile unsigned int ni_head;
   volatile unsigned int ni_tail;
+  volatile unsigned int ni_read;

Review comment:
       why we need ni_tail and ni_read two location?

##########
File path: include/nuttx/sched_note.h
##########
@@ -254,10 +266,78 @@ struct note_irqhandler_s
 };
 #endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+
+/* This is the type of the argument passed to the TRIOC_GETMODE and
+ * TRIOC_SETMODE ioctls
+ */
+
+struct note_trace_mode_s
+{
+  bool enable;                /* Trace enable */
+  unsigned int flag;          /* Trace mode flag */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+#define TRIOC_MODE_FLAG_SYSCALL      (1 << 0) /* Enable syscall trace */

Review comment:
       TRIOC_ to NOTE_FILTER_?

##########
File path: include/nuttx/sched_note.h
##########
@@ -254,10 +266,78 @@ struct note_irqhandler_s
 };
 #endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+
+/* This is the type of the argument passed to the TRIOC_GETMODE and
+ * TRIOC_SETMODE ioctls
+ */
+
+struct note_trace_mode_s
+{
+  bool enable;                /* Trace enable */
+  unsigned int flag;          /* Trace mode flag */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+#define TRIOC_MODE_FLAG_SYSCALL      (1 << 0) /* Enable syscall trace */
+#define TRIOC_MODE_FLAG_SYSCALL_ARGS (1 << 1) /* Enable collecting syscall 
arguments */
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+#define TRIOC_MODE_FLAG_IRQ          (1 << 2) /* Enable IRQ trace */
+#endif
+};
+
+/* This is the type of the argument passed to the TRIOC_GETSYSCALLFILTER and
+ * TRIOC_SETSYSCALLFILTER ioctls
+ */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+struct note_trace_syscallfilter_s

Review comment:
       note_filter_syscall_s?

##########
File path: include/nuttx/sched_note.h
##########
@@ -254,10 +266,78 @@ struct note_irqhandler_s
 };
 #endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+
+/* This is the type of the argument passed to the TRIOC_GETMODE and
+ * TRIOC_SETMODE ioctls
+ */
+
+struct note_trace_mode_s
+{
+  bool enable;                /* Trace enable */
+  unsigned int flag;          /* Trace mode flag */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+#define TRIOC_MODE_FLAG_SYSCALL      (1 << 0) /* Enable syscall trace */
+#define TRIOC_MODE_FLAG_SYSCALL_ARGS (1 << 1) /* Enable collecting syscall 
arguments */
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+#define TRIOC_MODE_FLAG_IRQ          (1 << 2) /* Enable IRQ trace */
+#endif
+};
+
+/* This is the type of the argument passed to the TRIOC_GETSYSCALLFILTER and
+ * TRIOC_SETSYSCALLFILTER ioctls
+ */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+struct note_trace_syscallfilter_s
+{
+  uint8_t syscall_mask[(SYS_nsyscalls + 7) / 8];
+};
+
+/* Helper macros */
+
+#define SYSCALLMASK_SET(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] |= (1 << ((nr) % 8)))
+#define SYSCALLMASK_CLR(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] &= ~(1 << ((nr) % 8)))
+#define SYSCALLMASK_ISSET(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] & (1 << ((nr) % 8)))
+#define SYSCALLMASK_ZERO(s) \
+  memset((s), 0, sizeof(struct note_trace_syscallfilter_s))
+#endif

Review comment:
       move to predefined section?

##########
File path: include/nuttx/sched_note.h
##########
@@ -254,10 +266,78 @@ struct note_irqhandler_s
 };
 #endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+
+/* This is the type of the argument passed to the TRIOC_GETMODE and
+ * TRIOC_SETMODE ioctls
+ */
+
+struct note_trace_mode_s
+{
+  bool enable;                /* Trace enable */
+  unsigned int flag;          /* Trace mode flag */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+#define TRIOC_MODE_FLAG_SYSCALL      (1 << 0) /* Enable syscall trace */
+#define TRIOC_MODE_FLAG_SYSCALL_ARGS (1 << 1) /* Enable collecting syscall 
arguments */
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+#define TRIOC_MODE_FLAG_IRQ          (1 << 2) /* Enable IRQ trace */
+#endif
+};
+
+/* This is the type of the argument passed to the TRIOC_GETSYSCALLFILTER and
+ * TRIOC_SETSYSCALLFILTER ioctls
+ */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+struct note_trace_syscallfilter_s
+{
+  uint8_t syscall_mask[(SYS_nsyscalls + 7) / 8];
+};
+
+/* Helper macros */
+
+#define SYSCALLMASK_SET(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] |= (1 << ((nr) % 8)))
+#define SYSCALLMASK_CLR(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] &= ~(1 << ((nr) % 8)))
+#define SYSCALLMASK_ISSET(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] & (1 << ((nr) % 8)))
+#define SYSCALLMASK_ZERO(s) \
+  memset((s), 0, sizeof(struct note_trace_syscallfilter_s))
+#endif
+
+/* This is the type of the argument passed to the TRIOC_GETIRQFILTER and
+ * TRIOC_SETIRQFILTER ioctls
+ */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+struct note_trace_irqfilter_s

Review comment:
       note_filter_irq_s?

##########
File path: include/nuttx/sched_note.h
##########
@@ -357,6 +437,125 @@ void sched_note_irqhandler(int irq, FAR void *handler, 
bool enter);
 
 void sched_note_add(FAR const void *note, size_t notelen);
 
+/****************************************************************************
+ * Name: sched_note_trace_start
+ *
+ * Description:
+ *   Start task tracing
+ *   (Same as TRIOC_START ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_start(void);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_stop
+ *
+ * Description:
+ *   Stop task tracing
+ *   (Same as TRIOC_STOP ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_stop(void);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_mode
+ *
+ * Description:
+ *   Set and get task trace mode.
+ *   (Same as TRIOC_GETMODE / TRIOC_SETMODE ioctls)
+ *
+ * Input Parameters:
+ *   oldm - A writable pointer to struct note_trace_mode_s to get current
+ *          trace mode
+ *          If 0, no data is written.
+ *   newm - A read-only pointer to struct note_trace_mode_s which holds the
+ *          new trace mode
+ *          If 0, the trace mode is not updated.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_mode(struct note_trace_mode_s *oldm,
+                           struct note_trace_mode_s *newm);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_syscallfilter
+ *
+ * Description:
+ *   Set and get syscall trace filter setting
+ *   (Same as TRIOC_GETSYSCALLFILTER / TRIOC_SETSYSCALLFILTER ioctls)
+ *
+ * Input Parameters:
+ *   oldf - A writable pointer to struct note_trace_syscallfilter_s to get
+ *          current syscall trace filter setting
+ *          If 0, no data is written.
+ *   newf - A read-only pointer to struct note_trace_syscallfilter_s of the
+ *          new syscall trace filter setting
+ *          If 0, the setting is not updated.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL

Review comment:
       change to?
   ```
   #if defined(CONFIG_SCHED_INSTRUMENTATION_FILTER) && 
defined(CONFIG_SCHED_INSTRUMENTATION_SYSCALL)
   ```

##########
File path: sched/Kconfig
##########
@@ -990,6 +990,14 @@ config SCHED_INSTRUMENTATION_IRQHANDLER
 
                        void sched_note_irqhandler(int irq, FAR void *handler, 
bool enter);
 
+config SCHED_INSTRUMENTATION_FILTER
+       bool "Instrumenation filter"
+       default n
+       ---help---
+               Enables the filter logic of the instrumentation data.  If this 
option
+               is enabled, the instrumentation is disabled by default and must 
be
+               enabled explicitly by filter APIs.

Review comment:
       should we reword the comment?

##########
File path: sched/sched/sched_note.c
##########
@@ -100,6 +123,43 @@ static void note_common(FAR struct tcb_s *tcb,
   note->nc_systime[3] = (uint8_t)((systime >> 24) & 0xff);
 }
 
+/****************************************************************************
+ * Name: note_isenabled
+ *
+ * Description:
+ *   Check whether the instrumentation is enabled.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   True is returned if the instrumentation is enabled.
+ *
+ ****************************************************************************/
+
+static inline int note_isenabled(void)
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (!g_note_filter.mode.enable)
+    {
+      return false;
+    }
+#endif
+
+#ifdef CONFIG_SMP
+  /* Ignore notes that are not in the set of monitored CPUs */
+
+  if ((CONFIG_SCHED_INSTRUMENTATION_CPUSET & (1 << this_cpu())) == 0)

Review comment:
       should we add cpuset to note_trace_mode_s like other filter?

##########
File path: include/nuttx/sched_note.h
##########
@@ -357,6 +437,125 @@ void sched_note_irqhandler(int irq, FAR void *handler, 
bool enter);
 
 void sched_note_add(FAR const void *note, size_t notelen);
 
+/****************************************************************************
+ * Name: sched_note_trace_start
+ *
+ * Description:
+ *   Start task tracing
+ *   (Same as TRIOC_START ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_start(void);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_stop
+ *
+ * Description:
+ *   Stop task tracing
+ *   (Same as TRIOC_STOP ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_stop(void);

Review comment:
       why not reuse sched_note_trace_mode to save two api?

##########
File path: include/nuttx/sched_note.h
##########
@@ -357,6 +437,125 @@ void sched_note_irqhandler(int irq, FAR void *handler, 
bool enter);
 
 void sched_note_add(FAR const void *note, size_t notelen);
 
+/****************************************************************************
+ * Name: sched_note_trace_start
+ *
+ * Description:
+ *   Start task tracing
+ *   (Same as TRIOC_START ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_start(void);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_stop
+ *
+ * Description:
+ *   Stop task tracing
+ *   (Same as TRIOC_STOP ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_stop(void);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_mode
+ *
+ * Description:
+ *   Set and get task trace mode.
+ *   (Same as TRIOC_GETMODE / TRIOC_SETMODE ioctls)
+ *
+ * Input Parameters:
+ *   oldm - A writable pointer to struct note_trace_mode_s to get current
+ *          trace mode
+ *          If 0, no data is written.
+ *   newm - A read-only pointer to struct note_trace_mode_s which holds the
+ *          new trace mode
+ *          If 0, the trace mode is not updated.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_mode(struct note_trace_mode_s *oldm,
+                           struct note_trace_mode_s *newm);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_syscallfilter
+ *
+ * Description:
+ *   Set and get syscall trace filter setting
+ *   (Same as TRIOC_GETSYSCALLFILTER / TRIOC_SETSYSCALLFILTER ioctls)
+ *
+ * Input Parameters:
+ *   oldf - A writable pointer to struct note_trace_syscallfilter_s to get
+ *          current syscall trace filter setting
+ *          If 0, no data is written.
+ *   newf - A read-only pointer to struct note_trace_syscallfilter_s of the
+ *          new syscall trace filter setting
+ *          If 0, the setting is not updated.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+void sched_note_trace_syscallfilter(struct note_trace_syscallfilter_s *oldf,

Review comment:
       sched_note_filter_syscall?

##########
File path: sched/sched/sched_note.c
##########
@@ -25,10 +25,12 @@
 #include <nuttx/config.h>
 
 #include <stdint.h>
+#include <stdbool.h>

Review comment:
       don't need

##########
File path: include/nuttx/sched.h
##########
@@ -748,6 +748,10 @@ struct tcb_s
 #if CONFIG_TASK_NAME_SIZE > 0
   char name[CONFIG_TASK_NAME_SIZE + 1];  /* Task name (with NUL terminator)    
 */
 #endif
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+  int syscall_nest;                      /* Syscall nest level */

Review comment:
       The same info expose inside arch's xcptcontext:
   ```
   #ifdef CONFIG_LIB_SYSCALL
     /* The following array holds the return address and the exc_return value
      * needed to return from each nested system call.
      */
   
     uint8_t nsyscalls;
     struct xcpt_syscall_s syscall[CONFIG_SYS_NNEST];
   
   #endif
   ```
   But I don't have a good idea how to reuse this info.

##########
File path: include/nuttx/sched_note.h
##########
@@ -357,6 +437,125 @@ void sched_note_irqhandler(int irq, FAR void *handler, 
bool enter);
 
 void sched_note_add(FAR const void *note, size_t notelen);
 
+/****************************************************************************
+ * Name: sched_note_trace_start
+ *
+ * Description:
+ *   Start task tracing
+ *   (Same as TRIOC_START ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_start(void);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_stop
+ *
+ * Description:
+ *   Stop task tracing
+ *   (Same as TRIOC_STOP ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_stop(void);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_mode
+ *
+ * Description:
+ *   Set and get task trace mode.
+ *   (Same as TRIOC_GETMODE / TRIOC_SETMODE ioctls)
+ *
+ * Input Parameters:
+ *   oldm - A writable pointer to struct note_trace_mode_s to get current
+ *          trace mode
+ *          If 0, no data is written.
+ *   newm - A read-only pointer to struct note_trace_mode_s which holds the
+ *          new trace mode
+ *          If 0, the trace mode is not updated.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_mode(struct note_trace_mode_s *oldm,
+                           struct note_trace_mode_s *newm);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_syscallfilter
+ *
+ * Description:
+ *   Set and get syscall trace filter setting
+ *   (Same as TRIOC_GETSYSCALLFILTER / TRIOC_SETSYSCALLFILTER ioctls)
+ *
+ * Input Parameters:
+ *   oldf - A writable pointer to struct note_trace_syscallfilter_s to get
+ *          current syscall trace filter setting
+ *          If 0, no data is written.
+ *   newf - A read-only pointer to struct note_trace_syscallfilter_s of the
+ *          new syscall trace filter setting
+ *          If 0, the setting is not updated.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+void sched_note_trace_syscallfilter(struct note_trace_syscallfilter_s *oldf,
+                                    struct note_trace_syscallfilter_s *newf);
+#endif
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_irqfilter
+ *
+ * Description:
+ *   Set and get IRQ trace filter setting
+ *   (Same as TRIOC_GETIRQFILTER / TRIOC_SETIRQFILTER ioctls)
+ *
+ * Input Parameters:
+ *   oldf - A writable pointer to struct note_trace_irqfilter_s to get
+ *          current IRQ trace filter setting
+ *          If 0, no data is written.
+ *   newf - A read-only pointer to struct note_trace_irqfilter_s of the new
+ *          IRQ trace filter setting
+ *          If 0, the setting is not updated.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+void sched_note_trace_irqfilter(struct note_trace_irqfilter_s *oldf,

Review comment:
       sched_note_filter_irq?

##########
File path: sched/sched/sched_note.c
##########
@@ -556,15 +578,58 @@ void sched_note_syscall_leave(int nr, uintptr_t result)
   struct note_syscall_leave_s note;
   FAR struct tcb_s *tcb = this_task();
 
-#ifdef CONFIG_SMP
-  /* Ignore notes that are not in the set of monitored CPUs */
+  if (!note_isenabled())
+    {
+      return;
+    }
 
-  if ((CONFIG_SCHED_INSTRUMENTATION_CPUSET & (1 << this_cpu())) == 0)
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  irqstate_t irq_mask;
+
+  irq_mask = enter_critical_section();

Review comment:
       should we add a new function note_isenabled_syscall which call 
note_isenabled and check SYSCALLMASK_ISSET?

##########
File path: include/nuttx/sched_note.h
##########
@@ -357,6 +437,125 @@ void sched_note_irqhandler(int irq, FAR void *handler, 
bool enter);
 
 void sched_note_add(FAR const void *note, size_t notelen);
 
+/****************************************************************************
+ * Name: sched_note_trace_start
+ *
+ * Description:
+ *   Start task tracing
+ *   (Same as TRIOC_START ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_start(void);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_stop
+ *
+ * Description:
+ *   Stop task tracing
+ *   (Same as TRIOC_STOP ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_stop(void);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_mode
+ *
+ * Description:
+ *   Set and get task trace mode.
+ *   (Same as TRIOC_GETMODE / TRIOC_SETMODE ioctls)
+ *
+ * Input Parameters:
+ *   oldm - A writable pointer to struct note_trace_mode_s to get current
+ *          trace mode
+ *          If 0, no data is written.
+ *   newm - A read-only pointer to struct note_trace_mode_s which holds the
+ *          new trace mode
+ *          If 0, the trace mode is not updated.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_mode(struct note_trace_mode_s *oldm,
+                           struct note_trace_mode_s *newm);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_syscallfilter
+ *
+ * Description:
+ *   Set and get syscall trace filter setting
+ *   (Same as TRIOC_GETSYSCALLFILTER / TRIOC_SETSYSCALLFILTER ioctls)
+ *
+ * Input Parameters:
+ *   oldf - A writable pointer to struct note_trace_syscallfilter_s to get
+ *          current syscall trace filter setting
+ *          If 0, no data is written.
+ *   newf - A read-only pointer to struct note_trace_syscallfilter_s of the
+ *          new syscall trace filter setting
+ *          If 0, the setting is not updated.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+void sched_note_trace_syscallfilter(struct note_trace_syscallfilter_s *oldf,
+                                    struct note_trace_syscallfilter_s *newf);
+#endif
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_irqfilter
+ *
+ * Description:
+ *   Set and get IRQ trace filter setting
+ *   (Same as TRIOC_GETIRQFILTER / TRIOC_SETIRQFILTER ioctls)
+ *
+ * Input Parameters:
+ *   oldf - A writable pointer to struct note_trace_irqfilter_s to get
+ *          current IRQ trace filter setting
+ *          If 0, no data is written.
+ *   newf - A read-only pointer to struct note_trace_irqfilter_s of the new
+ *          IRQ trace filter setting
+ *          If 0, the setting is not updated.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER

Review comment:
       change to?
   ```
   #if defined(CONFIG_SCHED_INSTRUMENTATION_FILTER) && 
defined(CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER)
   ```

##########
File path: include/nuttx/note/notectl_driver.h
##########
@@ -0,0 +1,128 @@
+/****************************************************************************
+ * include/nuttx/note/notectl_driver.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTE_NOTECTL_DRIVER_H
+#define __INCLUDE_NUTTX_NOTE_NOTECTL_DRIVER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+
+#include <nuttx/sched_note.h>
+#include <nuttx/fs/ioctl.h>
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* IOCTL Commands ***********************************************************/
+
+/* TRIOC_START
+ *              - Start task tracing
+ *                Argument: Ignored
+ * TRIOC_STOP
+ *              - Stop task tracing
+ *                Argument: Ignored
+ * TRIOC_GETMODE
+ *              - Get task trace mode
+ *                Argument: A writable pointer to struct note_trace_mode_s
+ * TRIOC_SETMODE
+ *              - Set task trace mode
+ *                Argument: A read-only pointer to struct note_trace_mode_s
+ * TRIOC_GETSYSCALLFILTER
+ *              - Get syscall trace filter setting
+ *                Argument: A writable pointer to struct
+ *                          note_trace_syscallfilter_s
+ * TRIOC_SETSYSCALLFILTER
+ *              - Set syscall trace filter setting
+ *                Argument: A read-only pointer to struct
+ *                          note_trace_syscallfilter_s
+ * TRIOC_GETIRQFILTER
+ *              - Get IRQ trace filter setting
+ *                Argument: A writable pointer to struct
+ *                          note_trace_irqfilter_s
+ * TRIOC_SETIRQFILTER
+ *              - Set IRQ trace filter setting
+ *                Argument: A read-only pointer to struct
+ *                          note_trace_irqfilter_s
+ */
+
+#ifdef CONFIG_DRIVER_NOTECTL
+
+#define _NOTECTLBASE        (0xfe00)
+#define _NOTECTLIOCVALID(c) (_IOC_TYPE(c) == _NOTECTLBASE)
+#define _NOTECTLIOC(nr)     _IOC(_NOTECTLBASE, nr)

Review comment:
       should we move to nuttx/fs/ioctl.h like other driver?

##########
File path: drivers/note/noteram_driver.c
##########
@@ -473,5 +644,7 @@ void sched_note_add(FAR const void *note, size_t notelen)
 
 int noteram_register(void)
 {
+  noteram_buffer_clear();

Review comment:
       let's keep the trace already save.

##########
File path: include/nuttx/sched_note.h
##########
@@ -254,10 +266,78 @@ struct note_irqhandler_s
 };
 #endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */
 
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+
+/* This is the type of the argument passed to the TRIOC_GETMODE and
+ * TRIOC_SETMODE ioctls
+ */
+
+struct note_trace_mode_s
+{
+  bool enable;                /* Trace enable */
+  unsigned int flag;          /* Trace mode flag */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+#define TRIOC_MODE_FLAG_SYSCALL      (1 << 0) /* Enable syscall trace */
+#define TRIOC_MODE_FLAG_SYSCALL_ARGS (1 << 1) /* Enable collecting syscall 
arguments */
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+#define TRIOC_MODE_FLAG_IRQ          (1 << 2) /* Enable IRQ trace */
+#endif
+};
+
+/* This is the type of the argument passed to the TRIOC_GETSYSCALLFILTER and
+ * TRIOC_SETSYSCALLFILTER ioctls
+ */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+struct note_trace_syscallfilter_s
+{
+  uint8_t syscall_mask[(SYS_nsyscalls + 7) / 8];
+};
+
+/* Helper macros */
+
+#define SYSCALLMASK_SET(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] |= (1 << ((nr) % 8)))
+#define SYSCALLMASK_CLR(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] &= ~(1 << ((nr) % 8)))
+#define SYSCALLMASK_ISSET(nr, s) \
+  ((s)->syscall_mask[(nr) / 8] & (1 << ((nr) % 8)))
+#define SYSCALLMASK_ZERO(s) \
+  memset((s), 0, sizeof(struct note_trace_syscallfilter_s))
+#endif
+
+/* This is the type of the argument passed to the TRIOC_GETIRQFILTER and
+ * TRIOC_SETIRQFILTER ioctls
+ */
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+struct note_trace_irqfilter_s
+{
+  uint8_t irq_mask[(NR_IRQS + 7) / 8];
+};
+
+/* Helper macros */
+
+#define IRQMASK_SET(nr, s) \
+  ((s)->irq_mask[(nr) / 8] |= (1 << ((nr) % 8)))
+#define IRQMASK_CLR(nr, s) \
+  ((s)->irq_mask[(nr) / 8] &= ~(1 << ((nr) % 8)))
+#define IRQMASK_ISSET(nr, s) \
+  ((s)->irq_mask[(nr) / 8] & (1 << ((nr) % 8)))
+#define IRQMASK_ZERO(s) \
+  memset((s), 0, sizeof(struct note_trace_irqfilter_s))
+#endif
+
+#endif /* CONFIG_SCHED_INSTRUMENTATION_FILTER */
+
 /****************************************************************************
  * Public Function Prototypes
  ****************************************************************************/
 
+#if defined(__KERNEL__) || defined(CONFIG_BUILD_FLAT)

Review comment:
       don't need?

##########
File path: drivers/note/notectl_driver.c
##########
@@ -263,5 +263,13 @@ static int notectl_ioctl(struct file *filep, int cmd, 
unsigned long arg)
 
 int notectl_register(void)
 {
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER_ENABLE_ONBOOT
+  struct note_trace_mode_s mode = {
+    true, CONFIG_SCHED_INSTRUMENTATION_FILTER_ENABLE_ONBOOT_MODE

Review comment:
       still too later, need to initialize g_note_filter directly.

##########
File path: drivers/note/noteram_driver.c
##########
@@ -419,6 +569,15 @@ void sched_note_add(FAR const void *note, size_t notelen)
   spin_lock_wo_note(&g_noteram_lock);
 #endif
 
+  if (!g_noteram_info.ni_enable)

Review comment:
       can we change to no overwrite semantics instead of oneshot? so we need 
have enable/disable status.

##########
File path: include/nuttx/sched_note.h
##########
@@ -357,6 +437,125 @@ void sched_note_irqhandler(int irq, FAR void *handler, 
bool enter);
 
 void sched_note_add(FAR const void *note, size_t notelen);
 
+/****************************************************************************
+ * Name: sched_note_trace_start
+ *
+ * Description:
+ *   Start task tracing
+ *   (Same as TRIOC_START ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_start(void);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_stop
+ *
+ * Description:
+ *   Stop task tracing
+ *   (Same as TRIOC_STOP ioctl)
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_stop(void);
+#endif
+
+/****************************************************************************
+ * Name: sched_note_trace_mode
+ *
+ * Description:
+ *   Set and get task trace mode.
+ *   (Same as TRIOC_GETMODE / TRIOC_SETMODE ioctls)
+ *
+ * Input Parameters:
+ *   oldm - A writable pointer to struct note_trace_mode_s to get current
+ *          trace mode
+ *          If 0, no data is written.
+ *   newm - A read-only pointer to struct note_trace_mode_s which holds the
+ *          new trace mode
+ *          If 0, the trace mode is not updated.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+void sched_note_trace_mode(struct note_trace_mode_s *oldm,

Review comment:
       sched_note_filter_mode?

##########
File path: drivers/note/noteram_driver.c
##########
@@ -326,6 +395,24 @@ static ssize_t noteram_size(void)
   return notelen;
 }
 
+/****************************************************************************
+ * Name: noteram_open
+ ****************************************************************************/
+
+static int noteram_open(FAR struct file *filep)
+{
+  irqstate_t flags;
+
+  flags = enter_critical_section();
+
+  /* Reset the read index of the circular buffer */
+
+  g_noteram_info.ni_read = g_noteram_info.ni_tail;

Review comment:
       why do this? we lose the initial trace info which is critical to 
debuging the boot issue.

##########
File path: include/nuttx/note/notectl_driver.h
##########
@@ -0,0 +1,128 @@
+/****************************************************************************
+ * include/nuttx/note/notectl_driver.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_NOTE_NOTECTL_DRIVER_H
+#define __INCLUDE_NUTTX_NOTE_NOTECTL_DRIVER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdint.h>
+
+#include <nuttx/sched_note.h>
+#include <nuttx/fs/ioctl.h>
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* IOCTL Commands ***********************************************************/
+
+/* TRIOC_START
+ *              - Start task tracing
+ *                Argument: Ignored
+ * TRIOC_STOP
+ *              - Stop task tracing
+ *                Argument: Ignored
+ * TRIOC_GETMODE
+ *              - Get task trace mode
+ *                Argument: A writable pointer to struct note_trace_mode_s
+ * TRIOC_SETMODE
+ *              - Set task trace mode
+ *                Argument: A read-only pointer to struct note_trace_mode_s
+ * TRIOC_GETSYSCALLFILTER
+ *              - Get syscall trace filter setting
+ *                Argument: A writable pointer to struct
+ *                          note_trace_syscallfilter_s
+ * TRIOC_SETSYSCALLFILTER
+ *              - Set syscall trace filter setting
+ *                Argument: A read-only pointer to struct
+ *                          note_trace_syscallfilter_s
+ * TRIOC_GETIRQFILTER
+ *              - Get IRQ trace filter setting
+ *                Argument: A writable pointer to struct
+ *                          note_trace_irqfilter_s
+ * TRIOC_SETIRQFILTER
+ *              - Set IRQ trace filter setting
+ *                Argument: A read-only pointer to struct
+ *                          note_trace_irqfilter_s
+ */
+
+#ifdef CONFIG_DRIVER_NOTECTL
+
+#define _NOTECTLBASE        (0xfe00)
+#define _NOTECTLIOCVALID(c) (_IOC_TYPE(c) == _NOTECTLBASE)
+#define _NOTECTLIOC(nr)     _IOC(_NOTECTLBASE, nr)
+
+#define TRIOC_START             _NOTECTLIOC(0x01)

Review comment:
       change to TRIOC_ to NOTECTL_?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to