How Free RTOS scheduler decide Tasks Time

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have spend hard time to understand how free rtos scheduler decide task's time. I have looked through freertos website but I don't have any idea 

 

let's say I want to run task's something like this 

 

T1 runs once for 8ms in every 40ms with Priority 2
T2 runs twice for 5ms in every 40ms with Priority1
T3 runs three times for 10ms in every 40ms with Priority3

 

Task's execution 

TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT.
22222111111113333333222223333333333333

 

I use xTaskCreate  function to create Task's and vTaskStartScheduler();  to start scheduler.

 

I don't have any idea which API function need to perform task as shown in my example 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think that's how it works; you don't get to specify time allocated to a task in the scheduler, you get to specify the time-slice for pre-emption.

A task will run either until it does something that blocks, or until the time-slice expires.

For your example, you could set the slice to 10ms, and T1 and T2 can voluntarily suspend after 8ms and 5ms.

 

(This is a generalization of preemptive OSes in general; I'm not sure of the specifics of FreeRTOS.)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

T1 runs once for 8ms in every 40ms with Priority 2
T2 runs twice for 5ms in every 40ms with Priority1
T3 runs three times for 10ms in every 40ms with Priority3

 

Well, at least get the ball rolling without describing things ambiguously

T3 runs three times for 10ms in every 40ms

    So, is it using up 30ms every 40ms?    Since the grand total would be more than 40ms in every 40ms, like squeezing 48 ms in a 40 ms suitcase, something has to give--but you don't  say what.

    Or are you desiring 10ms total?  Don't leave it vague.

    What do you really want to say?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Mon. Sep 13, 2021 - 03:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Isn't it explained on the FreeRTOS site?...

 

https://www.freertos.org/impleme...

https://www.freertos.org/impleme...

Last Edited: Mon. Sep 13, 2021 - 09:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:
What do you really want to say?

Ok my mistake here is correct example 

 

T1 runs once for 8ms in every 38ms with Priority 2
T2 runs twice for 5ms in every 38ms with Priority1
T3 runs twice times for 10ms in every 38ms with Priority3

 

clawson wrote:

Isn't it explained on the FreeRTOS site?...

 

https://www.freertos.org/impleme...

https://www.freertos.org/impleme...

 

Actually I already went on this page but I don't understand how to implement in code. Which API need to call  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

rahulk7 wrote:
T1 runs once for 8ms in every 40ms with Priority 2
T2 runs twice for 5ms in every 40ms with Priority1
T3 runs three times for 10ms in every 40ms with Priority3

 

So I've not used FreeRTOS, is priority 1 highest priority or is it lowest priority, I have worked on different systems where it has been one way or the other,

I would think you will find more expertise here on FreeRTOS: https://forums.freertos.org/

 

Jim

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

rahulk7 wrote:
Actually I already went on this page but I don't understand how to implement in code. Which API need to call  
What it is saying is that FreeRTOS will just run your tasks according to (a) their priority and (b) whether they are blocking on the wait for a resource.

 

I think (though I haven't examined it in depth) that FreeRTOS will also have the concept of timers so you can ask for a task (or perhaps a callback) to happen at exact times but usually you don't try to micro-manage an RTOS to give an explicit time when things run - it just runs thing as and when it can according to CPU time available, priority and whether some tasks have made a deliberate yield for some reason (often during the attempt to acquire a sem4 or mutex).

 

Sounds like you may want to explore these pages too - in that one of the tasks is waiting on a timer: 

 

https://www.freertos.org/impleme...

https://www.freertos.org/impleme...

 

EDIT: this support thread looks useful:

 

https://freertos.org/FreeRTOS_Su...

 

But looking through the API maybe you just need something like 

 

https://www.freertos.org/a00127....

or perhaps

https://www.freertos.org/vtaskde...

 

 

Last Edited: Mon. Sep 13, 2021 - 01:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

with Priority1

 BTW, I wouldn't normally assign a different priority to each task, especially for time-limited functions.

That could cause the scheduler to make inappropriate decisions (ie T2 runs for 5ms and voluntarily suspends.  But it's still the highest priority task, so ... it runs again.)

 

I have previously implemented (for a proprietary OS) a "friendly_suspend" function (for a proprietary OS) to ensure that a compute-bound process would not use up more than a "fair share" of a cpu, essentially:

 

if (current_runtime() > FRIENDLY_QUANTUM) {
    ms_sleep(FRIENDLY_QUANTUM * 100/FRIENDLY_PERCENTAGE);
}

(so if the Quantum is 10ms, and the desired percentage was 20%, the process would run for 10ms and then sleep for 50ms.  Or something like that.)