Scheduling and Synchronous messages

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
bb00
Posts: 3
Joined: Tue Oct 22, 2024 2:33 pm

Scheduling and Synchronous messages

Post by bb00 »

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.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Scheduling and Synchronous messages

Post by Giovanni »

Hi,

The quantum should not be relevant, the 10mS should be the message processing time by the threads.

Try measuring around the "processing", chMsgSend() waits for the whole time spent between chMsgWait() and chMsgRelease().

Scheduling is done by priority, at equal priority round robin occurs, it could be a good idea for determinism to give to the "server" threads +1 and +2 priorities.

Giovanni
bb00
Posts: 3
Joined: Tue Oct 22, 2024 2:33 pm

Re: Scheduling and Synchronous messages

Post by bb00 »

Hi Giovanni,

the processing part, so between chMsgWait and chMsgRelease takes about 1-2 milliseconds or even less.

Best Regards
Sebastian
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Scheduling and Synchronous messages

Post by Giovanni »

It could be the 2 processing parts combined, for sure it does not spend time by itself.

Giovanni
Post Reply