Finding slack of tasks for LST scheduling in Posix-GCC

I am very new to freertos and was trying to modify the demo program for Posix-GCC on
linux.

How can we set the deadline for tasks? And how can we find the actual execution time?

I was trying to implement a simple LST (Least Slack Time first) scheduling algorithm
(just to get a hang of it not going to apply it yet) as part of an RTS course.

Needed deadline and execution time to calculate slack.

I tried looking at this post:
https://forums.freertos.org/t/setting-deadline-for-tasks/3318
which advised to check out the Check functions in the demo but I couldn’t find a way.

Can you help me figure this out?

You can use something like run-time stats to see the percentage of CPU time allocated to each task. The scheduling algorithm is fixed though - other than options to turn preemption and time slicing on or off.

The scheduling algorithm is fixed meaning we cannot even simulate (don’t know if that’s the term) scheduling algorithsm like Earliest deadline first, Least slack time first, Rate monotonic, Deadline monotonic and all (just throwing terms I had heard here)?

Which scheduling algorithm does FreeRTOS use? Any idea?

The scheduling of FreeRTOS is highest priority scheduling with round robin in a priority.

Some other methods like rate monotonic, which are static priority systems, can just be mapped to FreeRTOS priorities.

Systems with dynamic priorities would need you to add some special ‘scheduler’ to the system that adjusted the FreeRTOS task priorities to map them to make them ordered by that scheduling rule. This likely needs this scheduler to keep some extra information about the tasks that FreeRTOS doesn’t keep now.

The code is all there in tasks.c. You can analyze it to find that out yourself or change it to your heart’s desire.

1 Like

The code is all there in tasks.c. You can analyze it

If we were to change the scheduling algorithm by editing tasks.c, is it vTaskStartScheduler() that we should focus on?

Excuse the question, but do you know how to read C code? FreeRTOS is really well written. Everything related to tasks and task scheduling is encapuslated in (appropriately named) tasks.c, so understanding the scheduling control flow once you know where to look isn’t too hard and also seems like the prerequirement to manipulating it.

The short answer, though, is: Look at taskSELECT_HIGHEST_PRIORITY_TASK(). Already the name should give away what it does and how it fits into the picture. Likewise vTaskStartScheduler() which does nothing but kick start the OS by assigning the CPU to the first ready task. The scheduler takes over every time a task loses the CPU afterwards (or some event enforces a task switch). Function and macro names aren’t arbitrary.

Apologies if this remark should sound rude, but in “my days,” the name of a source file to open used to be all it took to do the rest oneself.

1 Like

Sorry, I don’t have a lot of experience working with code (especially C code) and am only getting used to it. :grimacing:

Now that I got a better let me see what I can cook up (hopefully without wrecking it :sweat_smile:).

Thanks for the guidance, everyone :slight_smile:

One of the good things about software is that you can’t wreck it like one can wreck a car. If worst comes to worst, it crashes on your target (leaving no physical harm to anything or anybody involved), then you simply try something else until you get it to work.

Sorry for having been rudish earlier on. If you aren’t familar with coding at all yet, scheduling algorithms are indeed a fairly tall order to digest code wise.