Page 1 of 1
chSysGetIdleThreadX erratum + Segger SystemView contribution
Posted: Fri Apr 13, 2018 3:52 am
by lungj
does not work as described when called during the context switch hook. My quick skimming of the calling code leads me to believe this is due to the fact that the idle thread is no longer in its usual place as the lowest priority thread on the ready list because it about to become the active thread. I don't think this is a software bug as much as something that would be useful to document in the accompanying comments (just so that someone doesn't spend time trying to figure out why their context switch hook code doesn't work).
The reason I looking for a pointer to the idle thread in the hook is because I need to do something different in the case of switching to/from the idle thread. Specifically, I was writing a hook for Segger's SystemView. I used a workaround where I looked at the incoming and outgoing threads' priority levels. The hack requires that the only thread to have idle priority is the idle thread. And here is the code for anyone who's interested:
Code: Select all
/**
* @brief Context switch hook.
* @details This hook is invoked just before switching between threads.
*/
#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) \
{ \
/* Context switch code here.*/ \
if (otp->prio != IDLEPRIO) { \
SEGGER_SYSVIEW_OnTaskStopReady(otp, otp->state); \
} \
if (ntp->prio == IDLEPRIO) { \
SEGGER_SYSVIEW_OnIdle(); \
} else { \
SEGGER_SYSVIEW_OnTaskStartExec((unsigned)ntp); \
} \
\
}
Re: chSysGetIdleThreadX erratum + Segger SystemView contribution
Posted: Fri Apr 13, 2018 7:51 am
by Giovanni
Hi,
Moving in bug reports, I am not sure if just document the behavior or slightly change the order of operations yet.
Question, are the hooks sufficient for a full integration?
Giovanni
Re: chSysGetIdleThreadX erratum + Segger SystemView contribution
Posted: Fri Apr 13, 2018 9:16 am
by Giovanni
Hi,
Have you considered using the following hooks for idle enter/leave?
CH_CFG_IDLE_ENTER_HOOK()
CH_CFG_IDLE_LEAVE_HOOK()
Giovanni
Re: chSysGetIdleThreadX erratum + Segger SystemView contribution
Posted: Sat Apr 14, 2018 1:05 am
by lungj
Hi Giovanni,
By placing the hooks in the context switch hook, SystemView will show you the active thread and the reason for context switch (well, a numeric code anyway). Modifying only the idle hooks produces events in the wrong event sequence for SystemView (at least the only ways I could think of).
I think the hooks, as shown, are sufficient for showing all the times the microprocessor is idle and which thread it is executing. I haven't tested the code fully, yet. If someone cares about interrupts that are occurring and want to see those on the SystemView timeline, this code does not support that. If someone has such code, I hope they'll share since I haven't gotten around to it, yet
