Scheduling and Synchronous messages
Posted: Tue Oct 22, 2024 2:35 pm
Hello,
I am currently using ChibiOS/RT for a small project.
I am trying to build a service based architecture, where I have multiple different "service" threads for different hardware and software parts (like Display, HID, Log, etc.)
For communication I use chMsgSend and chMsgRelease, so synchronous messages.
I have a main application running with the highest priority and the service threads all running in the same priority with round-robin scheduling enabled.
The problem is: When I send a message with chMsgSend and return with chMsgRelease, the service thread still uses up its while timeslot (about 10ms or more) before it switches to the higher priority main application thread again. chMsgRelease returns immediately but also does not switch threads to the higher priority thread.
Question: Why is this happening? From reading the code, the RTOS should sleep the current thread and immediately switch to the receiver thread when chMsgSend is called, and immediately return from the service thread and switch to the highest priority thread (my main application thread) when chMsgRelease is called.
I uploaded a https://gist.github.com/birdboat00/e9af ... 0430ad1b85 "pseudo-code" example on Gist.
Thank you all a lot!
Maybe I am just misunderstanding how RTOSes schedule and i may need another scheduling algorithm.
But I would be really grateful if you could atleast give me a bit of a direction of what I may be understanding or doing wrong.
I am currently using ChibiOS/RT for a small project.
I am trying to build a service based architecture, where I have multiple different "service" threads for different hardware and software parts (like Display, HID, Log, etc.)
For communication I use chMsgSend and chMsgRelease, so synchronous messages.
I have a main application running with the highest priority and the service threads all running in the same priority with round-robin scheduling enabled.
The problem is: When I send a message with chMsgSend and return with chMsgRelease, the service thread still uses up its while timeslot (about 10ms or more) before it switches to the higher priority main application thread again. chMsgRelease returns immediately but also does not switch threads to the higher priority thread.
Question: Why is this happening? From reading the code, the RTOS should sleep the current thread and immediately switch to the receiver thread when chMsgSend is called, and immediately return from the service thread and switch to the highest priority thread (my main application thread) when chMsgRelease is called.
I uploaded a https://gist.github.com/birdboat00/e9af ... 0430ad1b85 "pseudo-code" example on Gist.
Thank you all a lot!
Maybe I am just misunderstanding how RTOSes schedule and i may need another scheduling algorithm.
But I would be really grateful if you could atleast give me a bit of a direction of what I may be understanding or doing wrong.