2022-01-21 13:00:26 +01:00
|
|
|
/****************************************************************************
|
2023-01-02 12:56:19 +01:00
|
|
|
* drivers/segger/note_sysview.c
|
2022-01-21 13:00:26 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
#include <stddef.h>
|
2022-01-21 13:00:26 +01:00
|
|
|
#include <syslog.h>
|
|
|
|
|
|
|
|
#include <nuttx/clock.h>
|
|
|
|
#include <nuttx/sched.h>
|
|
|
|
#include <nuttx/sched_note.h>
|
2023-01-05 11:15:06 +01:00
|
|
|
#include <nuttx/note/note_driver.h>
|
2022-12-11 14:14:34 +01:00
|
|
|
#include <nuttx/segger/sysview.h>
|
2022-01-21 13:00:26 +01:00
|
|
|
|
|
|
|
#include <SEGGER_RTT.h>
|
|
|
|
#include <SEGGER_SYSVIEW.h>
|
|
|
|
|
|
|
|
#include "sched/sched.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
struct note_sysview_driver_s
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
2023-01-05 11:15:06 +01:00
|
|
|
struct note_driver_s driver;
|
|
|
|
unsigned int irq[CONFIG_SMP_NCPUS];
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
|
|
|
|
struct note_filter_syscall_s syscall_marker;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void note_sysview_start(FAR struct note_driver_s *drv,
|
|
|
|
FAR struct tcb_s *tcb);
|
|
|
|
static void note_sysview_stop(FAR struct note_driver_s *drv,
|
|
|
|
FAR struct tcb_s *tcb);
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
|
|
|
|
static void note_sysview_suspend(FAR struct note_driver_s *drv,
|
|
|
|
FAR struct tcb_s *tcb);
|
|
|
|
static void note_sysview_resume(FAR struct note_driver_s *drv,
|
|
|
|
FAR struct tcb_s *tcb);
|
2022-01-21 13:00:26 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_irqhandler(FAR struct note_driver_s *drv, int irq,
|
|
|
|
FAR void *handler, bool enter);
|
2022-03-08 03:58:44 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_syscall_enter(FAR struct note_driver_s *drv,
|
|
|
|
int nr, int argc, va_list *ap);
|
|
|
|
static void note_sysview_syscall_leave(FAR struct note_driver_s *drv,
|
|
|
|
int nr, uintptr_t result);
|
2022-01-21 13:00:26 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
static const struct note_driver_ops_s g_note_sysview_ops =
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
2023-01-05 11:15:06 +01:00
|
|
|
NULL, /* add */
|
|
|
|
note_sysview_start, /* start */
|
|
|
|
note_sysview_stop, /* stop */
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
|
|
|
|
note_sysview_suspend, /* suspend */
|
|
|
|
note_sysview_resume, /* resume */
|
2023-03-15 05:03:23 +01:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SMP
|
2023-01-05 11:15:06 +01:00
|
|
|
NULL, /* cpu_start */
|
|
|
|
NULL, /* cpu_started */
|
2023-03-15 05:03:23 +01:00
|
|
|
# ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
|
2023-01-05 11:15:06 +01:00
|
|
|
NULL, /* cpu_pause */
|
|
|
|
NULL, /* cpu_paused */
|
|
|
|
NULL, /* cpu_resume */
|
|
|
|
NULL, /* cpu_resumed */
|
|
|
|
# endif
|
2022-01-21 13:00:26 +01:00
|
|
|
#endif
|
2023-01-05 11:15:06 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION
|
|
|
|
NULL, /* premption */
|
2022-01-21 13:00:26 +01:00
|
|
|
#endif
|
2023-01-05 11:15:06 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
|
|
|
|
NULL, /* csection */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
|
|
|
|
NULL, /* spinlock */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
|
|
|
|
note_sysview_syscall_enter, /* syscall_enter */
|
|
|
|
note_sysview_syscall_leave, /* syscall_leave */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
|
|
|
note_sysview_irqhandler, /* irqhandler */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct note_sysview_driver_s g_note_sysview_driver =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
&g_note_sysview_ops
|
|
|
|
}
|
2022-01-21 13:00:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-01-05 11:15:06 +01:00
|
|
|
* Name: note_sysview_send_taskinfo
|
2022-01-21 13:00:26 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_send_taskinfo(FAR struct tcb_s *tcb)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_TASKINFO info;
|
|
|
|
|
|
|
|
info.TaskID = tcb->pid;
|
2022-04-02 13:38:49 +02:00
|
|
|
#if CONFIG_TASK_NAME_SIZE > 0
|
2022-01-21 13:00:26 +01:00
|
|
|
info.sName = tcb->name;
|
2022-04-02 13:38:49 +02:00
|
|
|
#else
|
|
|
|
info.sName = "<noname>";
|
|
|
|
#endif
|
2022-01-21 13:00:26 +01:00
|
|
|
info.Prio = tcb->sched_priority;
|
|
|
|
info.StackBase = (uintptr_t)tcb->stack_base_ptr;
|
|
|
|
info.StackSize = tcb->adj_stack_size;
|
|
|
|
|
|
|
|
SEGGER_SYSVIEW_SendTaskInfo(&info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-01-05 11:15:06 +01:00
|
|
|
* Name: note_sysview_get_time
|
2022-01-21 13:00:26 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
static uint64_t note_sysview_get_time(void)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
return TICK2USEC(clock_systime_ticks());
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-01-05 11:15:06 +01:00
|
|
|
* Name: note_sysview_send_tasklist
|
2022-01-21 13:00:26 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_send_tasklist(void)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < g_npidhash; i++)
|
|
|
|
{
|
|
|
|
if (g_pidhash[i] != NULL)
|
|
|
|
{
|
2023-01-05 11:15:06 +01:00
|
|
|
note_sysview_send_taskinfo(g_pidhash[i]);
|
2022-01-21 13:00:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-01-05 11:15:06 +01:00
|
|
|
* Name: note_sysview_send_description
|
2022-01-21 13:00:26 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_send_description(void)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_SendSysDesc("N="SEGGER_SYSVIEW_APP_NAME);
|
|
|
|
SEGGER_SYSVIEW_SendSysDesc("D="CONFIG_LIBC_HOSTNAME);
|
|
|
|
SEGGER_SYSVIEW_SendSysDesc("O=NuttX");
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-01-05 11:15:06 +01:00
|
|
|
* Name: note_sysview_*
|
2022-01-21 13:00:26 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Hooks to scheduler monitor
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* Varies
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_start(FAR struct note_driver_s *drv,
|
|
|
|
FAR struct tcb_s *tcb)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_OnTaskCreate(tcb->pid);
|
2023-01-05 11:15:06 +01:00
|
|
|
note_sysview_send_taskinfo(tcb);
|
2022-01-21 13:00:26 +01:00
|
|
|
}
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_stop(FAR struct note_driver_s *drv,
|
|
|
|
FAR struct tcb_s *tcb)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_OnTaskTerminate(tcb->pid);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_suspend(FAR struct note_driver_s *drv,
|
|
|
|
FAR struct tcb_s *tcb)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
if (!up_interrupt_context())
|
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_OnTaskStopExec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_resume(FAR struct note_driver_s *drv,
|
|
|
|
FAR struct tcb_s *tcb)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
if (!up_interrupt_context())
|
|
|
|
{
|
2022-10-28 08:22:17 +02:00
|
|
|
if (is_idle_task(tcb))
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_OnIdle();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_OnTaskStartExec(tcb->pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_irqhandler(FAR struct note_driver_s *drv, int irq,
|
|
|
|
FAR void *handler, bool enter)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
2023-01-05 11:15:06 +01:00
|
|
|
FAR struct note_sysview_driver_s *driver =
|
|
|
|
(FAR struct note_sysview_driver_s *)drv;
|
2022-01-21 13:00:26 +01:00
|
|
|
|
|
|
|
if (enter)
|
|
|
|
{
|
2023-01-05 11:15:06 +01:00
|
|
|
driver->irq[up_cpu_index()] = irq;
|
2022-01-21 13:00:26 +01:00
|
|
|
|
|
|
|
SEGGER_SYSVIEW_OnTaskStopExec();
|
|
|
|
SEGGER_SYSVIEW_RecordEnterISR();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_RecordExitISR();
|
|
|
|
|
|
|
|
if (up_interrupt_context())
|
|
|
|
{
|
|
|
|
FAR struct tcb_s *tcb = this_task();
|
|
|
|
|
2022-10-28 08:22:17 +02:00
|
|
|
if (tcb && !is_idle_task(tcb))
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_OnTaskStartExec(tcb->pid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_OnIdle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
driver->irq[up_cpu_index()] = 0;
|
2022-01-21 13:00:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-03-08 03:58:44 +01:00
|
|
|
#ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_syscall_enter(FAR struct note_driver_s *drv, int nr,
|
|
|
|
int argc, va_list *ap)
|
2022-03-08 03:58:44 +01:00
|
|
|
{
|
2023-01-05 11:15:06 +01:00
|
|
|
FAR struct note_sysview_driver_s *driver =
|
|
|
|
(FAR struct note_sysview_driver_s *)drv;
|
2022-03-08 03:58:44 +01:00
|
|
|
nr -= CONFIG_SYS_RESERVED;
|
|
|
|
|
|
|
|
/* Set the name marker if the current syscall nr is not active */
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
if (NOTE_FILTER_SYSCALLMASK_ISSET(nr, &driver->syscall_marker) == 0)
|
2022-03-08 03:58:44 +01:00
|
|
|
{
|
|
|
|
/* Set the name marker */
|
|
|
|
|
|
|
|
SEGGER_SYSVIEW_NameMarker(nr, g_funcnames[nr]);
|
|
|
|
|
|
|
|
/* Mark the syscall active */
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
NOTE_FILTER_SYSCALLMASK_SET(nr, &driver->syscall_marker);
|
2022-03-08 03:58:44 +01:00
|
|
|
|
|
|
|
/* Use the Syscall "0" to identify whether the syscall is enabled,
|
|
|
|
* if the host tool is closed abnormally, use this bit to clear
|
|
|
|
* the active set.
|
|
|
|
*/
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
if (NOTE_FILTER_SYSCALLMASK_ISSET(0, &driver->syscall_marker) == 0)
|
2022-03-08 03:58:44 +01:00
|
|
|
{
|
2023-01-05 11:15:06 +01:00
|
|
|
NOTE_FILTER_SYSCALLMASK_SET(0, &driver->syscall_marker);
|
2022-03-08 03:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SEGGER_SYSVIEW_MarkStart(nr);
|
|
|
|
}
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
static void note_sysview_syscall_leave(FAR struct note_driver_s *drv,
|
|
|
|
int nr, uintptr_t result)
|
2022-03-08 03:58:44 +01:00
|
|
|
{
|
2023-01-05 11:15:06 +01:00
|
|
|
FAR struct note_sysview_driver_s *driver =
|
|
|
|
(FAR struct note_sysview_driver_s *)drv;
|
2022-03-08 03:58:44 +01:00
|
|
|
nr -= CONFIG_SYS_RESERVED;
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
if (NOTE_FILTER_SYSCALLMASK_ISSET(nr, &driver->syscall_marker) != 0)
|
2022-03-08 03:58:44 +01:00
|
|
|
{
|
|
|
|
SEGGER_SYSVIEW_MarkStop(nr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-01-21 13:00:26 +01:00
|
|
|
/****************************************************************************
|
2023-01-02 12:56:19 +01:00
|
|
|
* Name: note_sysview_get_interrupt_id
|
2022-01-21 13:00:26 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Retrieve the Id of the currently active interrupt.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-01-02 12:56:19 +01:00
|
|
|
unsigned int note_sysview_get_interrupt_id(void)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
2023-01-05 11:15:06 +01:00
|
|
|
return g_note_sysview_driver.irq[up_cpu_index()];
|
2022-01-21 13:00:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-01-02 12:56:19 +01:00
|
|
|
* Name: note_sysview_get_timestamp
|
2022-01-21 13:00:26 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Retrieve a system timestamp for SYSVIEW events.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-01-02 12:56:19 +01:00
|
|
|
unsigned int note_sysview_get_timestamp(void)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
return up_perf_gettime();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-01-02 12:56:19 +01:00
|
|
|
* Name: note_sysview_initialize
|
2022-01-21 13:00:26 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Initializes the SYSVIEW module.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero on succress. A negated errno value is returned on a failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-01-02 12:56:19 +01:00
|
|
|
int note_sysview_initialize(void)
|
2022-01-21 13:00:26 +01:00
|
|
|
{
|
|
|
|
uint32_t freq = up_perf_getfreq();
|
|
|
|
|
|
|
|
static const SEGGER_SYSVIEW_OS_API g_sysview_trace_api =
|
|
|
|
{
|
2023-01-05 11:15:06 +01:00
|
|
|
note_sysview_get_time,
|
|
|
|
note_sysview_send_tasklist,
|
2022-01-21 13:00:26 +01:00
|
|
|
};
|
|
|
|
|
2023-01-06 04:04:08 +01:00
|
|
|
if (freq == 0)
|
|
|
|
{
|
|
|
|
syslog(LOG_ERR, "up_perf isn't initialized, sysview isn't available");
|
|
|
|
PANIC();
|
|
|
|
}
|
|
|
|
|
2022-01-21 13:00:26 +01:00
|
|
|
SEGGER_SYSVIEW_Init(freq, freq, &g_sysview_trace_api,
|
2023-01-05 11:15:06 +01:00
|
|
|
note_sysview_send_description);
|
2022-01-21 13:00:26 +01:00
|
|
|
|
|
|
|
#if CONFIG_SEGGER_SYSVIEW_RAM_BASE != 0
|
|
|
|
SEGGER_SYSVIEW_SetRAMBase(CONFIG_SEGGER_SYSVIEW_RAM_BASE);
|
|
|
|
#endif
|
|
|
|
|
2023-01-05 11:15:06 +01:00
|
|
|
SEGGER_SYSVIEW_Start();
|
|
|
|
note_driver_register(&g_note_sysview_driver.driver);
|
2022-01-21 13:00:26 +01:00
|
|
|
syslog(LOG_NOTICE, "SEGGER RTT Control Block Address: %#" PRIxPTR "\n",
|
|
|
|
(uintptr_t)&_SEGGER_RTT +
|
|
|
|
CONFIG_SEGGER_RTT_UNCACHED_OFF);
|
|
|
|
return 0;
|
|
|
|
}
|