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



##########
File path: sched/sched/sched_note.c
##########
@@ -100,6 +137,162 @@ 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.flag & NOTE_FILTER_MODE_FLAG_ENABLE))
+    {
+      return false;
+    }
+
+#ifdef CONFIG_SMP
+  /* Ignore notes that are not in the set of monitored CPUs */
+
+  if ((g_note_filter.mode.cpuset & (1 << this_cpu())) == 0)
+    {
+      /* Not in the set of monitored CPUs.  Do not log the note. */
+
+      return false;
+    }
+#endif
+#endif
+
+  return true;
+}
+
+/****************************************************************************
+ * Name: note_isenabled_syscall
+ *
+ * Description:
+ *   Check whether the syscall instrumentation is enabled.
+ *
+ * Input Parameters:
+ *   nr - syscall number
+ *
+ * Returned Value:
+ *   True is returned if the instrumentation is enabled.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+static inline int note_isenabled_syscall(int nr)
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (!note_isenabled())
+    {
+      return false;
+    }
+
+  /* Exclude the case of syscall called by the interrupt handler which is
+   * not traced.
+   */
+
+  if (up_interrupt_context())
+    {
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+#ifdef CONFIG_SMP
+      int cpu = this_cpu();
+#else
+      int cpu = 0;
+#endif
+
+      if (g_note_disabled_irq_nest[cpu] > 0)
+        {
+          return false;
+        }
+#else
+      return false;
+#endif
+    }
+
+  /* If the syscall trace is disabled or the syscall number is masked,
+   * do nothing.
+   */
+
+  if (!(g_note_filter.mode.flag & NOTE_FILTER_MODE_FLAG_SYSCALL) ||
+      NOTE_FILTER_SYSCALLMASK_ISSET(nr - CONFIG_SYS_RESERVED,
+                                    &g_note_filter.syscall_mask))
+    {
+      return false;
+    }
+#endif
+
+  return true;
+}
+#endif
+
+/****************************************************************************
+ * Name: note_isenabled_irqhandler
+ *
+ * Description:
+ *   Check whether the interrupt handler instrumentation is enabled.
+ *
+ * Input Parameters:
+ *   irq   - IRQ number
+ *   enter - interrupt enter/leave flag
+ *
+ * Returned Value:
+ *   True is returned if the instrumentation is enabled.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+static inline int note_isenabled_irq(int irq, bool enter)
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (!note_isenabled())
+    {
+      return false;
+    }
+
+  /* If the IRQ trace is disabled or the IRQ number is masked, disable
+   * subsequent syscall traces until leaving the interrupt handler
+   */
+
+  if (!(g_note_filter.mode.flag & NOTE_FILTER_MODE_FLAG_IRQ) ||
+      NOTE_FILTER_IRQMASK_ISSET(irq, &g_note_filter.irq_mask))
+    {
+      irqstate_t irq_mask;
+#ifdef CONFIG_SMP
+      int cpu = this_cpu();
+#else
+      int cpu = 0;
+#endif
+
+      irq_mask = enter_critical_section();

Review comment:
       don't need? the interrupt should already disable in the current state.

##########
File path: sched/Kconfig
##########
@@ -990,6 +990,25 @@ 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 for the instrumentation. If this option
+               is enabled, the instrumentation data passed to sched_note_add()
+               can be filtered by syscall and IRQ number.
+               The filter logic can be configured by sched_note_filter APIs 
defined in
+               include/nuttx/sched_note.h.
+
+config SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE
+       hex "Default instrumentation filter mode"
+       default 0x7

Review comment:
       add depend on SCHED_INSTRUMENTATION_FILTER




----------------------------------------------------------------
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