chSysGetIdleThreadX erratum + Segger SystemView contribution Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
lungj
Posts: 8
Joined: Wed Feb 03, 2016 7:57 am
Been thanked: 1 time

chSysGetIdleThreadX erratum + Segger SystemView contribution  Topic is solved

Postby lungj » Fri Apr 13, 2018 3:52 am

Code: Select all

chSysGetIdleThreadX()
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);   \
    }                                                  \
  \
}

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

Re: chSysGetIdleThreadX erratum + Segger SystemView contribution

Postby Giovanni » Fri Apr 13, 2018 7:51 am

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

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

Re: chSysGetIdleThreadX erratum + Segger SystemView contribution

Postby Giovanni » Fri Apr 13, 2018 9:16 am

Hi,

Have you considered using the following hooks for idle enter/leave?

CH_CFG_IDLE_ENTER_HOOK()
CH_CFG_IDLE_LEAVE_HOOK()

Giovanni

lungj
Posts: 8
Joined: Wed Feb 03, 2016 7:57 am
Been thanked: 1 time

Re: chSysGetIdleThreadX erratum + Segger SystemView contribution

Postby lungj » Sat Apr 14, 2018 1:05 am

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


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 5 guests