[FEATURE REQUEST] More hooks

Discussions and support about ChibiOS/RT, the free embedded RTOS.
sdalu
Posts: 35
Joined: Wed Dec 30, 2015 5:31 pm
Has thanked: 1 time
Been thanked: 2 times

[FEATURE REQUEST] More hooks

Postby sdalu » Fri Feb 05, 2016 12:00 pm

It would be nice to have a few more CH_CFG_*_HOOK

The one I found missing for my needs are:
* CH_CFG_IRQ_PROLOGUE_HOOK, CH_CFG_IRQ_EPILOGUE_HOOK
* CH_CFG_SCHED_THREAD_READY_HOOK(tp), CH_CFG_SCHED_THREAD_SLEEP_HOOK(tp, newstate)

This would allow to easily interface with SystemView from Segger
( https://www.segger.com/systemview.html )

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

Re: [FEATURE REQUEST] More hooks

Postby Giovanni » Fri Feb 05, 2016 12:03 pm

Hi,

I will try to include this in RT4 and NIL2, both are currently under development.

BTW RT4 already supports an enhanced trace buffer that keeps track of all state changes and also ISR prologue/epilogue, you can see also ISR preempting other ISRs. Would be possible to use the information stored there? it is possible that hooks are not even required.

Read this thread: viewtopic.php?f=3&t=3094#p23986

Edit: CH_CFG_CONTEXT_SWITCH_HOOK should always allow to hook transitions to ready and to sleep, just check the states of the threads being switched in/out.

Giovanni

sdalu
Posts: 35
Joined: Wed Dec 30, 2015 5:31 pm
Has thanked: 1 time
Been thanked: 2 times

Re: [FEATURE REQUEST] More hooks

Postby sdalu » Sat Feb 06, 2016 9:27 pm

Great.

I'm already using the context switch hook, but SystemView seems to also make a distinction between "ready" ("Record a Task Start Ready event.") and "start" ("The Task Start event corresponds to when a task has started to execute rather than when it is ready to execute.").* Which I interpreted as the chReady and chSysSwich.

Don't know if the trace buffer could be enough to interface with SystemView (the difficult part to use a closed source program, any alternative is welcomed), but it would surely be very nice to also have a hook in the trace buffer itself (in chDbgWriteTraceI?)

I just read the thread about the trace buffer. I'm wondering how the information is transfered from the board to the eclipse view. Is it by reading memory directly from the board using a jtag/swd?

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

Re: [FEATURE REQUEST] More hooks

Postby Giovanni » Sat Feb 06, 2016 10:11 pm

Correct, it is done using the debugger interface.

Good idea about the trace hook, I will add that tomorrow.

Note you know when the thread starts executing, it is when it goes CH_STATE_CURRENT after being created, you have both info.

Code: Select all

#define CH_STATE_READY      (tstate_t)0      /**< @brief Waiting on the
                                                  ready list.               */
#define CH_STATE_CURRENT    (tstate_t)1      /**< @brief Currently running. */
#define CH_STATE_WTSTART    (tstate_t)2      /**< @brief Just created.      */
#define CH_STATE_SUSPENDED  (tstate_t)3      /**< @brief Suspended state.   */
#define CH_STATE_QUEUED     (tstate_t)4      /**< @brief On an I/O queue.   */
#define CH_STATE_WTSEM      (tstate_t)5      /**< @brief On a semaphore.    */
#define CH_STATE_WTMTX      (tstate_t)6      /**< @brief On a mutex.        */
#define CH_STATE_WTCOND     (tstate_t)7      /**< @brief On a cond.variable.*/
#define CH_STATE_SLEEPING   (tstate_t)8      /**< @brief Sleeping.          */
#define CH_STATE_WTEXIT     (tstate_t)9      /**< @brief Waiting a thread.  */
#define CH_STATE_WTOREVT    (tstate_t)10     /**< @brief One event.         */
#define CH_STATE_WTANDEVT   (tstate_t)11     /**< @brief Several events.    */
#define CH_STATE_SNDMSGQ    (tstate_t)12     /**< @brief Sending a message,
                                                  in queue.                 */
#define CH_STATE_SNDMSG     (tstate_t)13     /**< @brief Sent a message,
                                                  waiting answer.          */
#define CH_STATE_WTMSG      (tstate_t)14     /**< @brief Waiting for a
                                                  message.                  */
#define CH_STATE_FINAL      (tstate_t)15     /**< @brief Thread terminated. */


Giovanni

fjb
Posts: 11
Joined: Tue Dec 07, 2010 9:49 pm

Re: [FEATURE REQUEST] More hooks

Postby fjb » Sun Feb 21, 2016 9:10 pm

I just found this thread because I try to add Segger SystemView support to my project which is based on ChibiOS 3.1 at the moment.

I tried to use the context switch hook but I ran into locking errors. The SystemView integration sources don't have anything like the I-class API.

Code: Select all

#define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) {                              \
   SEGGER_SYSVIEW_OnTaskStopExec();                              \
   SEGGER_SYSVIEW_OnTaskStartExec((unsigned)ntp);                     \
}

sdalu
Posts: 35
Joined: Wed Dec 30, 2015 5:31 pm
Has thanked: 1 time
Been thanked: 2 times

Re: [FEATURE REQUEST] More hooks

Postby sdalu » Sun Feb 21, 2016 9:59 pm

Locking is #define in SEGGER_RTT_Conf.h.

You can use empty definitions:
#define SEGGER_RTT_LOCK()
#define SEGGER_RTT_UNLOCK()

fjb
Posts: 11
Joined: Tue Dec 07, 2010 9:49 pm

Re: [FEATURE REQUEST] More hooks

Postby fjb » Sun Feb 21, 2016 11:55 pm

Thank you. That works. I have to do the locking outside the kernel on my own with this solution, but that should be no problem.

Now I ran in a stack overflow issue. I have the feeling that I have to make all stacks bigger or I didn't find the offending stack yet.

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

Re: [FEATURE REQUEST] More hooks

Postby Giovanni » Sun Feb 21, 2016 11:56 pm

Note that there are hooks for thread creation and exit.

In RT4 (now in trunk) there are all the required hook for that tool to work.

Giovanni

sdalu
Posts: 35
Joined: Wed Dec 30, 2015 5:31 pm
Has thanked: 1 time
Been thanked: 2 times

Re: [FEATURE REQUEST] More hooks

Postby sdalu » Mon Feb 22, 2016 12:45 am

when using Segger_RTT_printf, I use PORT_INT_REQUIRED_STACK=256

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

Re: [FEATURE REQUEST] More hooks

Postby Giovanni » Mon Feb 22, 2016 9:16 am

It takes a lot of RAM, that value is added to all threads.

Giovanni


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 3 guests