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



##########
File path: sched/sched/sched_note.c
##########
@@ -100,6 +127,175 @@ 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;
+    }
+
+#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
+ *   tcb   - The TCB of the thread
+ *   enter - syscall enter/leave flag
+ *
+ * Returned Value:
+ *   True is returned if the instrumentation is enabled.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
+static inline int note_isenabled_syscall(int nr,
+                                         FAR struct tcb_s *tcb, bool enter)
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  irqstate_t irq_mask;
+#endif
+
+  if (!note_isenabled())
+    {
+      return false;
+    }
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  /* sched_note_syscall_enter() and sched_note_syscall_leave() will be
+   * called from not only applications, but interrupt handlers and many
+   * kernel APIs. Exclude such situations.
+   */
+
+  if (up_interrupt_context())

Review comment:
       > The same reason to 
https://github.com/apache/incubator-nuttx/pull/1377/files#r498625054
   > tracecompass cannot handle the syscall in interrupt handler correctly.
   > 
   > So I'll take the similar solution to nested syscalls. Remove the syscall 
inside the interrupt handler by app code.
   > 
   > But I'll not record the syscall when:
   > 
   > * The syscall is issued in the interrupt handler
   > * But the handling IRQ is not traced
   > 
   > Because in such case we cannot distinguish whether the syscall is called 
in the app code or interrupt handler.
   
   But if we turn off IRQ trace in the first place, how tracecompass detect 
whether syscall happen inside irq context or not?
   
   > > * But the handling IRQ is not traced
   > 
   > @xiaoxiang781216 It seems that there are no way to get the IRQ number 
currently executing inside the interrupt handler.
   > sched_note_syscall_enter/leave() cannot decide whether the syscall should 
be recorded or not in the interrupt handler.
   > So we have to leave this as it is.
   
   The post process tool could maintain a count which:
   1. Increase the count in the record of sched_note_irq_enter
   2. Decrease the count in the reord of sched_note_irq_leave
   3. Filter out the syscall if the count isn't equal to zero
   
   Yes, the user can disable all or partial irq trace, but tracecompass should 
handle the syscall record correctly if there isn't irq related record between 
them, regardless wether it's due to either no irq happen at all or irq is 
filtered by user.




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