SystemView and RTT bindings

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
dismirlian
Posts: 65
Joined: Fri Dec 20, 2013 3:59 pm
Location: Buenos Aires, Argentina
Has thanked: 1 time
Been thanked: 16 times

Re: SystemView and RTT bindings

Postby dismirlian » Fri Oct 04, 2019 12:20 am

Thanks Giovanni.

Please let me know if you have an elegant solution for the ISR tail hook.

Diego.

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: SystemView and RTT bindings

Postby Giovanni » Tue Oct 22, 2019 7:55 am

Hi,

Update about this, in my opinion this change should not go in RT 6 because compatibility concerns, I will merge it in the RT7 branch.

Some points about my analysis:

- Hooks into ready functions is required but not sufficient, there is also the wakeup function to consider, I will look into this.
- Moving hooks inward in ISRs is OK.
- The hook for the ISR epilogue could probably go in chSchIsPreemptionRequired(), it is portable, it is the decision point and it is called when the chain is already in "tail" (note that you can hook this whole function, this could solve your problem right now).
- Probably you should not use those hooks at all, in RT there are dedicated hooks meant for the tracer, see chtrace.h, I will extend that interface:

Search for this:

Code: Select all

/*===========================================================================*/
/* Module macros.                                                            */
/*===========================================================================*/

/* When a trace feature is disabled the associated functions are replaced by
   an empty macro. Note that the macros can be externally redefined in
   order to interface 3rd parties tracing tools.*/
#if CH_DBG_TRACE_MASK == CH_DBG_TRACE_MASK_DISABLED
#if !defined(_trace_init)
#define _trace_init()
#endif
#if !defined(_trace_switch)
#define _trace_switch(ntp, otp)
#endif
#if !defined(_trace_isr_enter)
#define _trace_isr_enter(isr)
#endif
#if !defined(_trace_isr_leave)
#define _trace_isr_leave(isr)
#endif
#if !defined(_trace_halt)
#define _trace_halt(reason)
#endif
#if !defined(chDbgWriteTraceI)
#define chDbgWriteTraceI(up1, up2)
#endif
#if !defined(chDbgWriteTrace)
#define chDbgWriteTrace(up1, up2)
#endif
#endif /* CH_DBG_TRACE_MASK == CH_DBG_TRACE_MASK_DISABLED */


I will add _trace_ready(tp, msg) and _trace_preemption(flag) to the set.

Giovanni

alexblack
Posts: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

Re: SystemView and RTT bindings

Postby alexblack » Thu Oct 24, 2019 12:50 pm

Hi.
I used SystemView already 2 years and it works fine without any modifications to RT. I used it on 17.x.x and now on 19.x.x
It is my hook definitions:

Code: Select all

/*===========================================================================*/
/**
 * @name Kernel hooks
 * @{
 */
/*===========================================================================*/

/**
 * @brief   Threads descriptor structure extension.
 * @details User fields added to the end of the @p thread_t structure.
 */
#define CH_CFG_THREAD_EXTRA_FIELDS                                          \
  /* Add threads custom fields here.*/

/**
 * @brief   Threads initialization hook.
 * @details User initialization code added to the @p chThdInit() API.
 *
 * @note    It is invoked from within @p chThdInit() and implicitly from all
 *          the threads creation APIs.
 */
#if SYSVIEW_ENABLE == 1
#define CH_CFG_THREAD_INIT_HOOK(tp) {                                       \
  /* Add threads initialization code here.*/                                \
  SEGGER_SYSVIEW_OnTaskCreate((uint32_t) tp);                               \
}
#else
#define CH_CFG_THREAD_INIT_HOOK(tp) {                                       \
  /* Add threads initialization code here.*/                                \
}
#endif

/**
 * @brief   Threads finalization hook.
 * @details User finalization code added to the @p chThdExit() API.
 */
#define CH_CFG_THREAD_EXIT_HOOK(tp) {                                       \
  /* Add threads finalization code here.*/                                  \
}

/**
 * @brief   Context switch hook.
 * @details This hook is invoked just before switching between threads.
 */
#if SYSVIEW_ENABLE == 1
#if SYSVIEW_CFG_HIDE_IDLE == TRUE
#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) {                              \
  /* Context switch code here.*/                                            \
  if (otp->prio != IDLEPRIO)                                                \
  {                                                                         \
    SEGGER_SYSVIEW_OnTaskStopExec();                                        \
  }                                                                         \
  if (ntp->prio == IDLEPRIO)                                                \
  {                                                                         \
    SEGGER_SYSVIEW_OnIdle();                                                \
  } else                                                                    \
  {                                                                         \
    SEGGER_SYSVIEW_OnTaskStartExec((unsigned)ntp);                          \
  }                                                                         \
}
#else
#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) {                              \
  /* Context switch code here.*/                                            \
  SEGGER_SYSVIEW_OnTaskStopExec();                                          \
  SEGGER_SYSVIEW_OnTaskStartExec((unsigned)ntp);                            \
}
#endif
#else
#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) {                              \
  /* Context switch code here.*/                                            \
}
#endif

/**
 * @brief   ISR enter hook.
 */
#if SYSVIEW_ENABLE == 1
#define CH_CFG_IRQ_PROLOGUE_HOOK() {                                        \
  /* IRQ prologue code here.*/                                              \
  SEGGER_SYSVIEW_RecordEnterISR();                                          \
}
#else
#define CH_CFG_IRQ_PROLOGUE_HOOK() {                                        \
  /* IRQ prologue code here.*/                                              \
}
#endif

/**
 * @brief   ISR exit hook.
 */
#if SYSVIEW_ENABLE == 1
#define CH_CFG_IRQ_EPILOGUE_HOOK() {                                        \
  /* IRQ epilogue code here.*/                                              \
  if (chSchIsPreemptionRequired())                                          \
    SEGGER_SYSVIEW_RecordExitISRToScheduler();                              \
  else                                                                      \
    SEGGER_SYSVIEW_RecordExitISR();                                         \
}
#else
#define CH_CFG_IRQ_EPILOGUE_HOOK() {                                        \
  /* IRQ epilogue code here.*/                                              \
}
#endif

/**
 * @brief   Idle thread enter hook.
 * @note    This hook is invoked within a critical zone, no OS functions
 *          should be invoked from here.
 * @note    This macro can be used to activate a power saving mode.
 */
#define CH_CFG_IDLE_ENTER_HOOK() {                                          \
  /* Idle-enter code here.*/                                                \
}

/**
 * @brief   Idle thread leave hook.
 * @note    This hook is invoked within a critical zone, no OS functions
 *          should be invoked from here.
 * @note    This macro can be used to deactivate a power saving mode.
 */
#define CH_CFG_IDLE_LEAVE_HOOK() {                                          \
  /* Idle-leave code here.*/                                                \
}

/**
 * @brief   Idle Loop hook.
 * @details This hook is continuously invoked by the idle thread loop.
 */
#if !defined(_FROM_ASM_)
#ifdef __cplusplus
extern "C" {
#endif
void mcu_sleep(void);
#ifdef __cplusplus
}
#endif
#endif /**< _FROM_ASM_ */
#define CH_CFG_IDLE_LOOP_HOOK() {                                           \
  /* Idle loop code here.*/                                                 \
  mcu_sleep();                                                              \
}

/**
 * @brief   System tick event hook.
 * @details This hook is invoked in the system tick handler immediately
 *          after processing the virtual timers queue.
 */
#define CH_CFG_SYSTEM_TICK_HOOK() {                                         \
  /* System tick event code here.*/                                         \
}

/**
 * @brief   System halt hook.
 * @details This hook is invoked in case to a system halting error before
 *          the system is halted.
 */
#define CH_CFG_SYSTEM_HALT_HOOK(reason) {                                   \
  /* System halt code here.*/                                               \
}

/**
 * @brief   Trace hook.
 * @details This hook is invoked each time a new record is written in the
 *          trace buffer.
 */
#define CH_CFG_TRACE_HOOK(tep) {                                            \
  /* Trace code here.*/                                                     \
}

/** @} */

Attachments
SystemView.jpg

meatball
Posts: 32
Joined: Thu May 19, 2016 4:39 pm
Has thanked: 9 times
Been thanked: 2 times

Re: SystemView and RTT bindings

Postby meatball » Thu May 07, 2020 2:06 am

Hi,

Is the _trace_ready(tp, msg) and _trace_preemption(flag) API still planned as the final integration step for this feature?

I don't see them yet on the master branch.


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 16 guests