You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/01/28 14:09:39 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a change in pull request #5327: note/sysview: add Segger System View support

pkarashchenko commented on a change in pull request #5327:
URL: https://github.com/apache/incubator-nuttx/pull/5327#discussion_r794530586



##########
File path: drivers/segger/note_sysview.c
##########
@@ -0,0 +1,553 @@
+/****************************************************************************
+ * drivers/segger/note_sysview.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <syslog.h>
+#include <syscall.h>
+
+#include <nuttx/clock.h>
+#include <nuttx/sched.h>
+#include <nuttx/sched_note.h>
+
+#include <SEGGER_RTT.h>
+#include <SEGGER_SYSVIEW.h>
+
+#include "sched/sched.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_SMP_NCPUS
+#define CONFIG_SMP_NCPUS 1
+#endif

Review comment:
       ```suggestion
   ```
   Already available from `sys/types.h`

##########
File path: drivers/segger/note_sysview.c
##########
@@ -0,0 +1,553 @@
+/****************************************************************************
+ * drivers/segger/note_sysview.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <syslog.h>
+#include <syscall.h>
+
+#include <nuttx/clock.h>
+#include <nuttx/sched.h>
+#include <nuttx/sched_note.h>
+
+#include <SEGGER_RTT.h>
+#include <SEGGER_SYSVIEW.h>
+
+#include "sched/sched.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_SMP_NCPUS
+#define CONFIG_SMP_NCPUS 1
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct sysview_cpu_s
+{
+  FAR struct tcb_s *tcb;
+  unsigned int      irq;
+  bool              in_isrcb;
+};
+
+struct sysview_s
+{
+  struct sysview_cpu_s      scpu[CONFIG_SMP_NCPUS];
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  struct note_filter_mode_s mode;
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+  struct note_filter_irq_s  irq_mask;
+#endif
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct sysview_s g_sysview =
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  .mode =
+    {
+      .flag = CONFIG_SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE,
+#ifdef CONFIG_SMP
+      .cpuset = CONFIG_SCHED_INSTRUMENTATION_CPUSET,
+#endif
+    }
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sysview_send_taskinfo
+ ****************************************************************************/
+
+static void sysview_send_taskinfo(FAR struct tcb_s *tcb)
+{
+  SEGGER_SYSVIEW_TASKINFO info;
+
+  info.TaskID     = tcb->pid;
+  info.sName      = tcb->name;
+  info.Prio       = tcb->sched_priority;
+  info.StackBase  = (uintptr_t)tcb->stack_base_ptr;
+  info.StackSize  = tcb->adj_stack_size;
+
+  SEGGER_SYSVIEW_SendTaskInfo(&info);
+}
+
+/****************************************************************************
+ * Name: sysview_get_time
+ ****************************************************************************/
+
+static uint64_t sysview_get_time(void)
+{
+  return TICK2MSEC(clock_systime_ticks());
+}
+
+/****************************************************************************
+ * Name: sysview_send_tasklist
+ ****************************************************************************/
+
+static void sysview_send_tasklist(void)
+{
+  int i;
+
+  for (i = 0; i < g_npidhash; i++)
+    {
+      if (g_pidhash[i] != NULL)
+        {
+          sysview_send_taskinfo(g_pidhash[i]);
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: sysview_send_description
+ ****************************************************************************/
+
+static void sysview_send_description(void)
+{
+  SEGGER_SYSVIEW_SendSysDesc("N="SEGGER_SYSVIEW_APP_NAME"");

Review comment:
       ```suggestion
     SEGGER_SYSVIEW_SendSysDesc("N="SEGGER_SYSVIEW_APP_NAME);
   ```
   ??  Not sure why `""` is needed

##########
File path: drivers/segger/config/SEGGER_SYSVIEW_Conf.h
##########
@@ -0,0 +1,63 @@
+/****************************************************************************
+ * drivers/segger/config/SEGGER_SYSVIEW_Conf.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 __DRIVERS_SEGGER_CONFIG_SEGGER_SYSVIEW_CONF_H
+#define __DRIVERS_SEGGER_CONFIG_SEGGER_SYSVIEW_CONF_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+extern unsigned int sysview_get_interrupt_id(void);
+extern unsigned int sysview_get_cycle_counter(void);
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Function macro to retrieve the Id of the currently active interrupt.
+ * Call user-supplied function SEGGER_SYSVIEW_X_GetInterruptId().
+ */
+
+#define SEGGER_SYSVIEW_GET_INTERRUPT_ID    sysview_get_interrupt_id
+
+/* Function macro to retrieve a system timestamp for SYSVIEW events.
+ * Call user-supplied function SEGGER_SYSVIEW_X_GetTimestamp().
+ */
+
+#define SEGGER_SYSVIEW_GET_TIMESTAMP       sysview_get_cycle_counter
+
+/* Number of bytes that SystemView uses for the RTT buffer. */
+
+#define SEGGER_SYSVIEW_RTT_BUFFER_SIZE     CONFIG_SEGGER_SYSVIEW_RTT_BUFFER_SIZE
+
+/* Largest cache line size (in bytes) in the target system. */
+
+#define SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE CONFIG_SEGGER_RTT_CPU_CACHE_LINE_SIZE
+
+/* Enable calling SEGGER_SYSVIEW_Start() after initialization. */
+
+#ifdef CONFIG_SEGGER_SYSVIEW_START_ON_INIT
+  #define SEGGER_SYSVIEW_START_ON_INIT     1

Review comment:
       ```suggestion
   #  define SEGGER_SYSVIEW_START_ON_INIT     1
   ```

##########
File path: drivers/segger/note_sysview.c
##########
@@ -0,0 +1,553 @@
+/****************************************************************************
+ * drivers/segger/note_sysview.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <syslog.h>
+#include <syscall.h>
+
+#include <nuttx/clock.h>
+#include <nuttx/sched.h>
+#include <nuttx/sched_note.h>
+
+#include <SEGGER_RTT.h>
+#include <SEGGER_SYSVIEW.h>
+
+#include "sched/sched.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_SMP_NCPUS
+#define CONFIG_SMP_NCPUS 1
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct sysview_cpu_s
+{
+  FAR struct tcb_s *tcb;
+  unsigned int      irq;
+  bool              in_isrcb;
+};
+
+struct sysview_s
+{
+  struct sysview_cpu_s      scpu[CONFIG_SMP_NCPUS];
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  struct note_filter_mode_s mode;
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+  struct note_filter_irq_s  irq_mask;
+#endif
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct sysview_s g_sysview =
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  .mode =
+    {
+      .flag = CONFIG_SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE,
+#ifdef CONFIG_SMP
+      .cpuset = CONFIG_SCHED_INSTRUMENTATION_CPUSET,
+#endif
+    }
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sysview_send_taskinfo
+ ****************************************************************************/
+
+static void sysview_send_taskinfo(FAR struct tcb_s *tcb)
+{
+  SEGGER_SYSVIEW_TASKINFO info;
+
+  info.TaskID     = tcb->pid;
+  info.sName      = tcb->name;
+  info.Prio       = tcb->sched_priority;
+  info.StackBase  = (uintptr_t)tcb->stack_base_ptr;
+  info.StackSize  = tcb->adj_stack_size;
+
+  SEGGER_SYSVIEW_SendTaskInfo(&info);
+}
+
+/****************************************************************************
+ * Name: sysview_get_time
+ ****************************************************************************/
+
+static uint64_t sysview_get_time(void)
+{
+  return TICK2MSEC(clock_systime_ticks());
+}
+
+/****************************************************************************
+ * Name: sysview_send_tasklist
+ ****************************************************************************/
+
+static void sysview_send_tasklist(void)
+{
+  int i;
+
+  for (i = 0; i < g_npidhash; i++)
+    {
+      if (g_pidhash[i] != NULL)
+        {
+          sysview_send_taskinfo(g_pidhash[i]);
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: sysview_send_description
+ ****************************************************************************/
+
+static void sysview_send_description(void)
+{
+  SEGGER_SYSVIEW_SendSysDesc("N="SEGGER_SYSVIEW_APP_NAME"");
+  SEGGER_SYSVIEW_SendSysDesc("D="CONFIG_LIBC_HOSTNAME"");
+  SEGGER_SYSVIEW_SendSysDesc("O=NuttX");
+}
+
+/****************************************************************************
+ * Name: sysview_isenabled
+ *
+ * Description:
+ *   Check whether the instrumentation is enabled.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   True is returned if the instrumentation is enabled.
+ *
+ ****************************************************************************/
+
+static bool sysview_isenabled(void)
+{
+  bool enable;
+
+  enable = SEGGER_SYSVIEW_IsStarted();
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (enable)
+    {
+      if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE) == 0)
+        {
+          g_sysview.mode.flag |= NOTE_FILTER_MODE_FLAG_ENABLE;
+        }
+    }
+  else
+    {
+      if (g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE)
+        {
+          g_sysview.mode.flag &= ~NOTE_FILTER_MODE_FLAG_ENABLE;
+        }
+    }
+
+  if (enable)
+    {
+#  ifdef CONFIG_SMP
+      /* Ignore notes that are not in the set of monitored CPUs */
+
+      if ((g_sysview.mode.cpuset & (1 << this_cpu())) == 0)
+        {
+          /* Not in the set of monitored CPUs.  Do not log the note. */
+
+          return false;
+        }
+#  endif
+    }
+
+#endif
+
+  return enable;
+}
+
+/****************************************************************************
+ * Name: sysview_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 sysview_isenabled_irq(int irq, bool enter)
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (!sysview_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_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_IRQ) ||
+      NOTE_FILTER_IRQMASK_ISSET(irq, &g_sysview.irq_mask))
+    {
+      return false;
+    }
+#endif
+
+  return true;
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_note_start, sched_note_stop, sched_note_switch,
+ *       sched_note_premption
+ *
+ * Description:
+ *   Hooks to scheduler monitor
+ *
+ * Input Parameters:
+ *   Varies
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void sched_note_start(FAR struct tcb_s *tcb)
+{
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  SEGGER_SYSVIEW_OnTaskCreate(tcb->pid);
+  sysview_send_taskinfo(tcb);
+}
+
+void sched_note_stop(FAR struct tcb_s *tcb)
+{
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  SEGGER_SYSVIEW_OnTaskTerminate(tcb->pid);
+}
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
+void sched_note_suspend(FAR struct tcb_s *tcb)
+{
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  if (g_sysview.scpu[up_cpu_index()].in_isrcb == false)
+    {
+      SEGGER_SYSVIEW_OnTaskStopExec();
+    }
+}
+
+void sched_note_resume(FAR struct tcb_s *tcb)
+{
+  struct sysview_cpu_s *scpu;
+
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  scpu = &g_sysview.scpu[up_cpu_index()];
+
+  if (scpu->in_isrcb == false)
+    {
+#if CONFIG_SMP_NCPUS == 1
+      if (tcb->flink == NULL)
+        {
+          SEGGER_SYSVIEW_OnIdle();
+        }
+      else
+#endif
+        {
+          SEGGER_SYSVIEW_OnTaskStartExec(tcb->pid);
+        }
+    }
+  else
+    {
+      scpu->tcb = tcb;
+    }
+}
+#endif
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+void sched_note_irqhandler(int irq, FAR void *handler, bool enter)
+{
+  struct sysview_cpu_s *scpu;
+
+  if (!sysview_isenabled_irq(irq, enter))
+    {
+      return;
+    }
+
+  scpu = &g_sysview.scpu[up_cpu_index()];
+
+  if (enter)
+    {
+      if (g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE)
+        {
+          scpu->in_isrcb = true;
+          SEGGER_SYSVIEW_OnTaskStopExec();
+        }
+
+      scpu->irq = irq;
+      SEGGER_SYSVIEW_RecordEnterISR();
+    }
+  else
+    {
+      SEGGER_SYSVIEW_RecordExitISR();
+
+      if (scpu->in_isrcb)
+        {
+#if CONFIG_SMP_NCPUS == 1
+          if (scpu->tcb && scpu->tcb->flink != NULL)
+            {
+              SEGGER_SYSVIEW_OnTaskStartExec(scpu->tcb->pid);
+            }
+          else
+            {
+              SEGGER_SYSVIEW_OnIdle();
+            }
+#else
+          if (scpu->tcb)
+            {
+              SEGGER_SYSVIEW_OnTaskStartExec(scpu->tcb->pid);
+            }
+          else
+            {
+              SEGGER_SYSVIEW_OnTaskStartExec(up_cpu_index());
+            }
+#endif
+
+          scpu->tcb = NULL;
+          scpu->in_isrcb = false;
+        }
+
+      scpu->irq = 0;
+    }
+}
+#endif
+
+/****************************************************************************
+ * Name: sysview_get_interrupt_id
+ *
+ * Description:
+ *   Retrieve the Id of the currently active interrupt.
+ *
+ ****************************************************************************/
+
+unsigned int sysview_get_interrupt_id(void)
+{
+  return g_sysview.scpu[up_cpu_index()].irq;
+}
+
+/****************************************************************************
+ * Name: sysview_get_cycle_counter
+ *
+ * Description:
+ *   Retrieve a system timestamp for SYSVIEW events.
+ *
+ ****************************************************************************/
+
+unsigned int sysview_get_cycle_counter(void)
+{
+  return up_perf_gettime();
+}
+
+/****************************************************************************
+ * Name: sysview_initialize
+ *
+ * Description:
+ *   Initializes the SYSVIEW module.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   Zero on succress. A negated errno value is returned on a failure.
+ *
+ ****************************************************************************/
+
+int sysview_initialize(void)
+{
+  uint32_t freq = up_perf_getfreq();
+
+  static const SEGGER_SYSVIEW_OS_API g_sysview_trace_api =
+    {
+      sysview_get_time,
+      sysview_send_tasklist,
+    };
+
+  SEGGER_SYSVIEW_Init(freq, freq, &g_sysview_trace_api,
+                      sysview_send_description);
+
+#if CONFIG_SEGGER_SYSVIEW_RAM_BASE != 0
+  SEGGER_SYSVIEW_SetRAMBase(CONFIG_SEGGER_SYSVIEW_RAM_BASE);
+#endif
+
+#ifdef CONFIG_SEGGER_SYSVIEW_START_ON_INIT
+  if (g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE)

Review comment:
       ```suggestion
     if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE) != 0)
   ```

##########
File path: drivers/segger/note_sysview.c
##########
@@ -0,0 +1,553 @@
+/****************************************************************************
+ * drivers/segger/note_sysview.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <syslog.h>
+#include <syscall.h>
+
+#include <nuttx/clock.h>
+#include <nuttx/sched.h>
+#include <nuttx/sched_note.h>
+
+#include <SEGGER_RTT.h>
+#include <SEGGER_SYSVIEW.h>
+
+#include "sched/sched.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_SMP_NCPUS
+#define CONFIG_SMP_NCPUS 1
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct sysview_cpu_s
+{
+  FAR struct tcb_s *tcb;
+  unsigned int      irq;
+  bool              in_isrcb;
+};
+
+struct sysview_s
+{
+  struct sysview_cpu_s      scpu[CONFIG_SMP_NCPUS];
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  struct note_filter_mode_s mode;
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+  struct note_filter_irq_s  irq_mask;
+#endif
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct sysview_s g_sysview =
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  .mode =
+    {
+      .flag = CONFIG_SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE,
+#ifdef CONFIG_SMP
+      .cpuset = CONFIG_SCHED_INSTRUMENTATION_CPUSET,
+#endif
+    }
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sysview_send_taskinfo
+ ****************************************************************************/
+
+static void sysview_send_taskinfo(FAR struct tcb_s *tcb)
+{
+  SEGGER_SYSVIEW_TASKINFO info;
+
+  info.TaskID     = tcb->pid;
+  info.sName      = tcb->name;
+  info.Prio       = tcb->sched_priority;
+  info.StackBase  = (uintptr_t)tcb->stack_base_ptr;
+  info.StackSize  = tcb->adj_stack_size;
+
+  SEGGER_SYSVIEW_SendTaskInfo(&info);
+}
+
+/****************************************************************************
+ * Name: sysview_get_time
+ ****************************************************************************/
+
+static uint64_t sysview_get_time(void)
+{
+  return TICK2MSEC(clock_systime_ticks());
+}
+
+/****************************************************************************
+ * Name: sysview_send_tasklist
+ ****************************************************************************/
+
+static void sysview_send_tasklist(void)
+{
+  int i;
+
+  for (i = 0; i < g_npidhash; i++)
+    {
+      if (g_pidhash[i] != NULL)
+        {
+          sysview_send_taskinfo(g_pidhash[i]);
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: sysview_send_description
+ ****************************************************************************/
+
+static void sysview_send_description(void)
+{
+  SEGGER_SYSVIEW_SendSysDesc("N="SEGGER_SYSVIEW_APP_NAME"");
+  SEGGER_SYSVIEW_SendSysDesc("D="CONFIG_LIBC_HOSTNAME"");
+  SEGGER_SYSVIEW_SendSysDesc("O=NuttX");
+}
+
+/****************************************************************************
+ * Name: sysview_isenabled
+ *
+ * Description:
+ *   Check whether the instrumentation is enabled.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   True is returned if the instrumentation is enabled.
+ *
+ ****************************************************************************/
+
+static bool sysview_isenabled(void)
+{
+  bool enable;
+
+  enable = SEGGER_SYSVIEW_IsStarted();
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (enable)
+    {
+      if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE) == 0)
+        {
+          g_sysview.mode.flag |= NOTE_FILTER_MODE_FLAG_ENABLE;
+        }
+    }
+  else
+    {
+      if (g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE)
+        {
+          g_sysview.mode.flag &= ~NOTE_FILTER_MODE_FLAG_ENABLE;
+        }
+    }
+
+  if (enable)
+    {
+#  ifdef CONFIG_SMP
+      /* Ignore notes that are not in the set of monitored CPUs */
+
+      if ((g_sysview.mode.cpuset & (1 << this_cpu())) == 0)
+        {
+          /* Not in the set of monitored CPUs.  Do not log the note. */
+
+          return false;
+        }
+#  endif
+    }
+
+#endif
+
+  return enable;
+}
+
+/****************************************************************************
+ * Name: sysview_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 sysview_isenabled_irq(int irq, bool enter)
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (!sysview_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_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_IRQ) ||

Review comment:
       ```suggestion
     if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_IRQ) == 0 ||
   ```

##########
File path: drivers/segger/note_sysview.c
##########
@@ -0,0 +1,553 @@
+/****************************************************************************
+ * drivers/segger/note_sysview.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <syslog.h>
+#include <syscall.h>
+
+#include <nuttx/clock.h>
+#include <nuttx/sched.h>
+#include <nuttx/sched_note.h>
+
+#include <SEGGER_RTT.h>
+#include <SEGGER_SYSVIEW.h>
+
+#include "sched/sched.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_SMP_NCPUS
+#define CONFIG_SMP_NCPUS 1
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct sysview_cpu_s
+{
+  FAR struct tcb_s *tcb;
+  unsigned int      irq;
+  bool              in_isrcb;
+};
+
+struct sysview_s
+{
+  struct sysview_cpu_s      scpu[CONFIG_SMP_NCPUS];
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  struct note_filter_mode_s mode;
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+  struct note_filter_irq_s  irq_mask;
+#endif
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct sysview_s g_sysview =
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  .mode =
+    {
+      .flag = CONFIG_SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE,
+#ifdef CONFIG_SMP
+      .cpuset = CONFIG_SCHED_INSTRUMENTATION_CPUSET,
+#endif
+    }
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sysview_send_taskinfo
+ ****************************************************************************/
+
+static void sysview_send_taskinfo(FAR struct tcb_s *tcb)
+{
+  SEGGER_SYSVIEW_TASKINFO info;
+
+  info.TaskID     = tcb->pid;
+  info.sName      = tcb->name;
+  info.Prio       = tcb->sched_priority;
+  info.StackBase  = (uintptr_t)tcb->stack_base_ptr;
+  info.StackSize  = tcb->adj_stack_size;
+
+  SEGGER_SYSVIEW_SendTaskInfo(&info);
+}
+
+/****************************************************************************
+ * Name: sysview_get_time
+ ****************************************************************************/
+
+static uint64_t sysview_get_time(void)
+{
+  return TICK2MSEC(clock_systime_ticks());
+}
+
+/****************************************************************************
+ * Name: sysview_send_tasklist
+ ****************************************************************************/
+
+static void sysview_send_tasklist(void)
+{
+  int i;
+
+  for (i = 0; i < g_npidhash; i++)
+    {
+      if (g_pidhash[i] != NULL)
+        {
+          sysview_send_taskinfo(g_pidhash[i]);
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: sysview_send_description
+ ****************************************************************************/
+
+static void sysview_send_description(void)
+{
+  SEGGER_SYSVIEW_SendSysDesc("N="SEGGER_SYSVIEW_APP_NAME"");
+  SEGGER_SYSVIEW_SendSysDesc("D="CONFIG_LIBC_HOSTNAME"");
+  SEGGER_SYSVIEW_SendSysDesc("O=NuttX");
+}
+
+/****************************************************************************
+ * Name: sysview_isenabled
+ *
+ * Description:
+ *   Check whether the instrumentation is enabled.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   True is returned if the instrumentation is enabled.
+ *
+ ****************************************************************************/
+
+static bool sysview_isenabled(void)
+{
+  bool enable;
+
+  enable = SEGGER_SYSVIEW_IsStarted();
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (enable)
+    {
+      if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE) == 0)
+        {
+          g_sysview.mode.flag |= NOTE_FILTER_MODE_FLAG_ENABLE;
+        }
+    }
+  else
+    {
+      if (g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE)
+        {
+          g_sysview.mode.flag &= ~NOTE_FILTER_MODE_FLAG_ENABLE;
+        }
+    }
+
+  if (enable)
+    {
+#  ifdef CONFIG_SMP
+      /* Ignore notes that are not in the set of monitored CPUs */
+
+      if ((g_sysview.mode.cpuset & (1 << this_cpu())) == 0)
+        {
+          /* Not in the set of monitored CPUs.  Do not log the note. */
+
+          return false;
+        }
+#  endif
+    }
+
+#endif
+
+  return enable;
+}
+
+/****************************************************************************
+ * Name: sysview_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 sysview_isenabled_irq(int irq, bool enter)
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (!sysview_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_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_IRQ) ||
+      NOTE_FILTER_IRQMASK_ISSET(irq, &g_sysview.irq_mask))
+    {
+      return false;
+    }
+#endif
+
+  return true;
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_note_start, sched_note_stop, sched_note_switch,
+ *       sched_note_premption
+ *
+ * Description:
+ *   Hooks to scheduler monitor
+ *
+ * Input Parameters:
+ *   Varies
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void sched_note_start(FAR struct tcb_s *tcb)
+{
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  SEGGER_SYSVIEW_OnTaskCreate(tcb->pid);
+  sysview_send_taskinfo(tcb);
+}
+
+void sched_note_stop(FAR struct tcb_s *tcb)
+{
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  SEGGER_SYSVIEW_OnTaskTerminate(tcb->pid);
+}
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
+void sched_note_suspend(FAR struct tcb_s *tcb)
+{
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  if (g_sysview.scpu[up_cpu_index()].in_isrcb == false)
+    {
+      SEGGER_SYSVIEW_OnTaskStopExec();
+    }
+}
+
+void sched_note_resume(FAR struct tcb_s *tcb)
+{
+  struct sysview_cpu_s *scpu;
+
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  scpu = &g_sysview.scpu[up_cpu_index()];
+
+  if (scpu->in_isrcb == false)

Review comment:
       ```suggestion
     if (!scpu->in_isrcb)
   ```

##########
File path: drivers/segger/config/SEGGER_SYSVIEW_Conf.h
##########
@@ -0,0 +1,63 @@
+/****************************************************************************
+ * drivers/segger/config/SEGGER_SYSVIEW_Conf.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 __DRIVERS_SEGGER_CONFIG_SEGGER_SYSVIEW_CONF_H
+#define __DRIVERS_SEGGER_CONFIG_SEGGER_SYSVIEW_CONF_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+extern unsigned int sysview_get_interrupt_id(void);
+extern unsigned int sysview_get_cycle_counter(void);

Review comment:
       Maybe should be moved to a separate section?

##########
File path: drivers/segger/note_sysview.c
##########
@@ -0,0 +1,553 @@
+/****************************************************************************
+ * drivers/segger/note_sysview.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <syslog.h>
+#include <syscall.h>
+
+#include <nuttx/clock.h>
+#include <nuttx/sched.h>
+#include <nuttx/sched_note.h>
+
+#include <SEGGER_RTT.h>
+#include <SEGGER_SYSVIEW.h>
+
+#include "sched/sched.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_SMP_NCPUS
+#define CONFIG_SMP_NCPUS 1
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct sysview_cpu_s
+{
+  FAR struct tcb_s *tcb;
+  unsigned int      irq;
+  bool              in_isrcb;
+};
+
+struct sysview_s
+{
+  struct sysview_cpu_s      scpu[CONFIG_SMP_NCPUS];
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  struct note_filter_mode_s mode;
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+  struct note_filter_irq_s  irq_mask;
+#endif
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct sysview_s g_sysview =
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  .mode =
+    {
+      .flag = CONFIG_SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE,
+#ifdef CONFIG_SMP
+      .cpuset = CONFIG_SCHED_INSTRUMENTATION_CPUSET,
+#endif
+    }
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sysview_send_taskinfo
+ ****************************************************************************/
+
+static void sysview_send_taskinfo(FAR struct tcb_s *tcb)
+{
+  SEGGER_SYSVIEW_TASKINFO info;
+
+  info.TaskID     = tcb->pid;
+  info.sName      = tcb->name;
+  info.Prio       = tcb->sched_priority;
+  info.StackBase  = (uintptr_t)tcb->stack_base_ptr;
+  info.StackSize  = tcb->adj_stack_size;
+
+  SEGGER_SYSVIEW_SendTaskInfo(&info);
+}
+
+/****************************************************************************
+ * Name: sysview_get_time
+ ****************************************************************************/
+
+static uint64_t sysview_get_time(void)
+{
+  return TICK2MSEC(clock_systime_ticks());
+}
+
+/****************************************************************************
+ * Name: sysview_send_tasklist
+ ****************************************************************************/
+
+static void sysview_send_tasklist(void)
+{
+  int i;
+
+  for (i = 0; i < g_npidhash; i++)
+    {
+      if (g_pidhash[i] != NULL)
+        {
+          sysview_send_taskinfo(g_pidhash[i]);
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: sysview_send_description
+ ****************************************************************************/
+
+static void sysview_send_description(void)
+{
+  SEGGER_SYSVIEW_SendSysDesc("N="SEGGER_SYSVIEW_APP_NAME"");
+  SEGGER_SYSVIEW_SendSysDesc("D="CONFIG_LIBC_HOSTNAME"");

Review comment:
       ```suggestion
     SEGGER_SYSVIEW_SendSysDesc("D="CONFIG_LIBC_HOSTNAME);
   ```
   ??  Not sure why `""` is needed

##########
File path: drivers/segger/note_sysview.c
##########
@@ -0,0 +1,553 @@
+/****************************************************************************
+ * drivers/segger/note_sysview.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <syslog.h>
+#include <syscall.h>
+
+#include <nuttx/clock.h>
+#include <nuttx/sched.h>
+#include <nuttx/sched_note.h>
+
+#include <SEGGER_RTT.h>
+#include <SEGGER_SYSVIEW.h>
+
+#include "sched/sched.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_SMP_NCPUS
+#define CONFIG_SMP_NCPUS 1
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct sysview_cpu_s
+{
+  FAR struct tcb_s *tcb;
+  unsigned int      irq;
+  bool              in_isrcb;
+};
+
+struct sysview_s
+{
+  struct sysview_cpu_s      scpu[CONFIG_SMP_NCPUS];
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  struct note_filter_mode_s mode;
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+  struct note_filter_irq_s  irq_mask;
+#endif
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct sysview_s g_sysview =
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  .mode =
+    {
+      .flag = CONFIG_SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE,
+#ifdef CONFIG_SMP
+      .cpuset = CONFIG_SCHED_INSTRUMENTATION_CPUSET,
+#endif
+    }
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sysview_send_taskinfo
+ ****************************************************************************/
+
+static void sysview_send_taskinfo(FAR struct tcb_s *tcb)
+{
+  SEGGER_SYSVIEW_TASKINFO info;
+
+  info.TaskID     = tcb->pid;
+  info.sName      = tcb->name;
+  info.Prio       = tcb->sched_priority;
+  info.StackBase  = (uintptr_t)tcb->stack_base_ptr;
+  info.StackSize  = tcb->adj_stack_size;
+
+  SEGGER_SYSVIEW_SendTaskInfo(&info);
+}
+
+/****************************************************************************
+ * Name: sysview_get_time
+ ****************************************************************************/
+
+static uint64_t sysview_get_time(void)
+{
+  return TICK2MSEC(clock_systime_ticks());
+}
+
+/****************************************************************************
+ * Name: sysview_send_tasklist
+ ****************************************************************************/
+
+static void sysview_send_tasklist(void)
+{
+  int i;
+
+  for (i = 0; i < g_npidhash; i++)
+    {
+      if (g_pidhash[i] != NULL)
+        {
+          sysview_send_taskinfo(g_pidhash[i]);
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: sysview_send_description
+ ****************************************************************************/
+
+static void sysview_send_description(void)
+{
+  SEGGER_SYSVIEW_SendSysDesc("N="SEGGER_SYSVIEW_APP_NAME"");
+  SEGGER_SYSVIEW_SendSysDesc("D="CONFIG_LIBC_HOSTNAME"");
+  SEGGER_SYSVIEW_SendSysDesc("O=NuttX");
+}
+
+/****************************************************************************
+ * Name: sysview_isenabled
+ *
+ * Description:
+ *   Check whether the instrumentation is enabled.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   True is returned if the instrumentation is enabled.
+ *
+ ****************************************************************************/
+
+static bool sysview_isenabled(void)
+{
+  bool enable;
+
+  enable = SEGGER_SYSVIEW_IsStarted();
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (enable)
+    {
+      if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE) == 0)
+        {
+          g_sysview.mode.flag |= NOTE_FILTER_MODE_FLAG_ENABLE;
+        }
+    }
+  else
+    {
+      if (g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE)

Review comment:
       ```suggestion
         if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE) != 0)
   ```

##########
File path: drivers/segger/note_sysview.c
##########
@@ -0,0 +1,553 @@
+/****************************************************************************
+ * drivers/segger/note_sysview.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <syslog.h>
+#include <syscall.h>
+
+#include <nuttx/clock.h>
+#include <nuttx/sched.h>
+#include <nuttx/sched_note.h>
+
+#include <SEGGER_RTT.h>
+#include <SEGGER_SYSVIEW.h>
+
+#include "sched/sched.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_SMP_NCPUS
+#define CONFIG_SMP_NCPUS 1
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct sysview_cpu_s
+{
+  FAR struct tcb_s *tcb;
+  unsigned int      irq;
+  bool              in_isrcb;
+};
+
+struct sysview_s
+{
+  struct sysview_cpu_s      scpu[CONFIG_SMP_NCPUS];
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  struct note_filter_mode_s mode;
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+  struct note_filter_irq_s  irq_mask;
+#endif
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct sysview_s g_sysview =
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  .mode =
+    {
+      .flag = CONFIG_SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE,
+#ifdef CONFIG_SMP
+      .cpuset = CONFIG_SCHED_INSTRUMENTATION_CPUSET,
+#endif
+    }
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sysview_send_taskinfo
+ ****************************************************************************/
+
+static void sysview_send_taskinfo(FAR struct tcb_s *tcb)
+{
+  SEGGER_SYSVIEW_TASKINFO info;
+
+  info.TaskID     = tcb->pid;
+  info.sName      = tcb->name;
+  info.Prio       = tcb->sched_priority;
+  info.StackBase  = (uintptr_t)tcb->stack_base_ptr;
+  info.StackSize  = tcb->adj_stack_size;
+
+  SEGGER_SYSVIEW_SendTaskInfo(&info);
+}
+
+/****************************************************************************
+ * Name: sysview_get_time
+ ****************************************************************************/
+
+static uint64_t sysview_get_time(void)
+{
+  return TICK2MSEC(clock_systime_ticks());
+}
+
+/****************************************************************************
+ * Name: sysview_send_tasklist
+ ****************************************************************************/
+
+static void sysview_send_tasklist(void)
+{
+  int i;
+
+  for (i = 0; i < g_npidhash; i++)
+    {
+      if (g_pidhash[i] != NULL)
+        {
+          sysview_send_taskinfo(g_pidhash[i]);
+        }
+    }
+}
+
+/****************************************************************************
+ * Name: sysview_send_description
+ ****************************************************************************/
+
+static void sysview_send_description(void)
+{
+  SEGGER_SYSVIEW_SendSysDesc("N="SEGGER_SYSVIEW_APP_NAME"");
+  SEGGER_SYSVIEW_SendSysDesc("D="CONFIG_LIBC_HOSTNAME"");
+  SEGGER_SYSVIEW_SendSysDesc("O=NuttX");
+}
+
+/****************************************************************************
+ * Name: sysview_isenabled
+ *
+ * Description:
+ *   Check whether the instrumentation is enabled.
+ *
+ * Input Parameters:
+ *   None
+ *
+ * Returned Value:
+ *   True is returned if the instrumentation is enabled.
+ *
+ ****************************************************************************/
+
+static bool sysview_isenabled(void)
+{
+  bool enable;
+
+  enable = SEGGER_SYSVIEW_IsStarted();
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (enable)
+    {
+      if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE) == 0)
+        {
+          g_sysview.mode.flag |= NOTE_FILTER_MODE_FLAG_ENABLE;
+        }
+    }
+  else
+    {
+      if (g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE)
+        {
+          g_sysview.mode.flag &= ~NOTE_FILTER_MODE_FLAG_ENABLE;
+        }
+    }
+
+  if (enable)
+    {
+#  ifdef CONFIG_SMP
+      /* Ignore notes that are not in the set of monitored CPUs */
+
+      if ((g_sysview.mode.cpuset & (1 << this_cpu())) == 0)
+        {
+          /* Not in the set of monitored CPUs.  Do not log the note. */
+
+          return false;
+        }
+#  endif
+    }
+
+#endif
+
+  return enable;
+}
+
+/****************************************************************************
+ * Name: sysview_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 sysview_isenabled_irq(int irq, bool enter)
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+  if (!sysview_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_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_IRQ) ||
+      NOTE_FILTER_IRQMASK_ISSET(irq, &g_sysview.irq_mask))
+    {
+      return false;
+    }
+#endif
+
+  return true;
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_note_start, sched_note_stop, sched_note_switch,
+ *       sched_note_premption
+ *
+ * Description:
+ *   Hooks to scheduler monitor
+ *
+ * Input Parameters:
+ *   Varies
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void sched_note_start(FAR struct tcb_s *tcb)
+{
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  SEGGER_SYSVIEW_OnTaskCreate(tcb->pid);
+  sysview_send_taskinfo(tcb);
+}
+
+void sched_note_stop(FAR struct tcb_s *tcb)
+{
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  SEGGER_SYSVIEW_OnTaskTerminate(tcb->pid);
+}
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
+void sched_note_suspend(FAR struct tcb_s *tcb)
+{
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  if (g_sysview.scpu[up_cpu_index()].in_isrcb == false)
+    {
+      SEGGER_SYSVIEW_OnTaskStopExec();
+    }
+}
+
+void sched_note_resume(FAR struct tcb_s *tcb)
+{
+  struct sysview_cpu_s *scpu;
+
+  if (!sysview_isenabled())
+    {
+      return;
+    }
+
+  scpu = &g_sysview.scpu[up_cpu_index()];
+
+  if (scpu->in_isrcb == false)
+    {
+#if CONFIG_SMP_NCPUS == 1
+      if (tcb->flink == NULL)
+        {
+          SEGGER_SYSVIEW_OnIdle();
+        }
+      else
+#endif
+        {
+          SEGGER_SYSVIEW_OnTaskStartExec(tcb->pid);
+        }
+    }
+  else
+    {
+      scpu->tcb = tcb;
+    }
+}
+#endif
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+void sched_note_irqhandler(int irq, FAR void *handler, bool enter)
+{
+  struct sysview_cpu_s *scpu;
+
+  if (!sysview_isenabled_irq(irq, enter))
+    {
+      return;
+    }
+
+  scpu = &g_sysview.scpu[up_cpu_index()];
+
+  if (enter)
+    {
+      if (g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE)

Review comment:
       ```suggestion
         if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE) != 0)
   ```




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

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org