Page 1 of 2

Thread freezes in Ready state

Posted: Mon May 28, 2018 3:35 pm
by alexblack
Hi.
I have project on STM32F303 mcu with ChibiOS 17.6.5.
It has 5 threads. At some moment one thread is stopping. The DEBUG shows that his state is CH_STATE_READY.
This happens very rarely. Maybe once an hour or maybe less. This began to happen after certain changes in the program:
One of then is that I switched to tickless mode with CH_CFG_ST_FREQUENCY = 10000 and CH_CFG_ST_TIMEDELTA = 2.
If I changed compiller options then the problem dissapears. What is the reason that the thread is in Ready state all time and do not switch to Run state at all. May be this is effect of corruption of system variables by other error or may be 10kHz is too fast for 72MHz MCU or what it can be?

Re: Thread freezes in Ready state

Posted: Mon May 28, 2018 3:53 pm
by Giovanni
10kHz is not too much, all demos use those settings.

Are debug options enabled in chconf.h?

Giovanni

Re: Thread freezes in Ready state

Posted: Mon May 28, 2018 4:10 pm
by alexblack
I was developed the project long time with all debug options on and have no problems. When I released the final project with all debug options off then I have troubles.

Re: Thread freezes in Ready state

Posted: Mon May 28, 2018 4:28 pm
by Giovanni
Which option triggers the trouble? any of them? all of them? a specific one?

Probably it is a race condition triggered when the code becomes "faster".

Giovanni

Re: Thread freezes in Ready state

Posted: Mon May 28, 2018 4:59 pm
by alexblack
This is difficult to understand because I need hours to try one variant. I have 2 global options: DEBUG (all debug options and assertions is ON and compiller optimization is OFF) and RELESE (all debug options are OFF and compiller optimization is MAX).
Strange thing that I added some new functionaliity that does not interact with this thread, but if I switch option to OFF of the new functionality in runtime then I have no trouble with that thread. When the thread is freezes the new functionality stay working and other functionality working too.
Clip2net_180528185344.jpg

Now I have working project with frozen thread. I can show You some variables if it will help.
I tried to debug the stack of the thread to find the point of the trouble but can't find it exact. Plus compiler optimizations change the code.

Re: Thread freezes in Ready state

Posted: Mon May 28, 2018 9:11 pm
by Giovanni
I am not sure to understand what do you mean by "stopping" in ready state. Is it never executed again while other threads are still running?

Look at the state of all other threads and to the trace buffer, you can use the ChibiOS debug plugin for this.

You may also use chSysIntegrityCheckI() in some thread in order to check system integrity.

Giovanni

Re: Thread freezes in Ready state

Posted: Tue May 29, 2018 6:39 am
by alexblack
Hello.
I am using KEIL, debug plugin not possible.
I am not sure to understand what do you mean by "stopping" in ready state. Is it never executed again while other threads are still running?

Yes, the thread never running while other threads still running. The variable state of this thread is zero = CH_STATE_READY and never changed.
I was found that this happened after executing the code

Code: Select all

chThdSleepMicroseconds(500);

About chSysIntegrityCheckI() it is interesting, I will try it.

Re: Thread freezes in Ready state

Posted: Tue May 29, 2018 7:23 am
by Giovanni
If a ready thread is never executed probably it is because there is an higher priority thread that does not release the CPU.

Giovanni

Re: Thread freezes in Ready state

Posted: Tue May 29, 2018 8:44 am
by alexblack
There are no threads that load the CPU for 100% and this thread has maximum priority. When I pause the execution of the program it is often is in IDLE loop.
Clip2net_180529104204.jpg

Re: Thread freezes in Ready state

Posted: Tue May 29, 2018 8:53 am
by Giovanni
alexblack wrote:There are no threads that load the CPU for 100% and this thread has maximum priority. When I pause the execution of the program it is often is in IDLE loop.
Clip2net_180529104204.jpg


Then it is possible that the thread is not in the ready list even if it is ready, do that integrity check. you may also inspect the ready list using the debugger and see if it is as expected.

Giovanni