Thread freezes in Ready state

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
alexblack
Posts: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

Thread freezes in Ready state

Postby alexblack » Mon May 28, 2018 3:35 pm

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?

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

Re: Thread freezes in Ready state

Postby Giovanni » Mon May 28, 2018 3:53 pm

10kHz is not too much, all demos use those settings.

Are debug options enabled in chconf.h?

Giovanni

alexblack
Posts: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

Re: Thread freezes in Ready state

Postby alexblack » Mon May 28, 2018 4:10 pm

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.

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

Re: Thread freezes in Ready state

Postby Giovanni » Mon May 28, 2018 4:28 pm

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

alexblack
Posts: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

Re: Thread freezes in Ready state

Postby alexblack » Mon May 28, 2018 4:59 pm

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.

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

Re: Thread freezes in Ready state

Postby Giovanni » Mon May 28, 2018 9:11 pm

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

alexblack
Posts: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

Re: Thread freezes in Ready state

Postby alexblack » Tue May 29, 2018 6:39 am

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.

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

Re: Thread freezes in Ready state

Postby Giovanni » Tue May 29, 2018 7:23 am

If a ready thread is never executed probably it is because there is an higher priority thread that does not release the CPU.

Giovanni

alexblack
Posts: 276
Joined: Mon Sep 24, 2012 3:52 pm
Location: Donetsk
Been thanked: 32 times
Contact:

Re: Thread freezes in Ready state

Postby alexblack » Tue May 29, 2018 8:44 am

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

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

Re: Thread freezes in Ready state

Postby Giovanni » Tue May 29, 2018 8:53 am

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


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 75 guests