How to get pointer to IDLE thread?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

How to get pointer to IDLE thread?

Post by barthess »

Hi Giovanni,
In my project I need to roughly estimate "CPU usage". It can be calculated from Idle ticks and whole system ticks. For this purpose I need to get pointer to Idle thread. Is there elegant way to get Idle thread pointer? I have found 2:
1) Iterate through thread registry and search name "idle". Ugly.
2) Modify chSysInit() function to return idle thread pointer.

Also, I can realize second way and commit to trunk if it acceptable.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: How to get pointer to IDLE thread?

Post by Giovanni »

Hi,

There is already a macro chSysGetIdleThread() but it only works when the idle thread is the one internally defined.

Probably it would be better to change it to use "rlist.r_queue.r_prev", it always point to the idle thread because it is at the lowest priority and always ready.

Giovanni
Post Reply