Scheduling and Synchronous messages

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

Scheduling and Synchronous messages

Postby bb00 » 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.

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

Re: Scheduling and Synchronous messages

Postby Giovanni » Tue Oct 22, 2024 3:10 pm

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: 2
Joined: Tue Oct 22, 2024 2:33 pm

Re: Scheduling and Synchronous messages

Postby bb00 » Tue Oct 22, 2024 4:12 pm

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: 14565
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1112 times
Been thanked: 937 times
Contact:

Re: Scheduling and Synchronous messages

Postby Giovanni » Tue Oct 22, 2024 5:18 pm

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

Giovanni


Return to “ChibiOS/RT”

Who is online

Users browsing this forum: No registered users and 11 guests