scheduler execution

mohsen21 wrote on Friday, October 11, 2019:

Hello
as I’ve read in “using the freertos real time kernel” by Richard Barry,

“To be able to select the next task to run the scheduler itself has to execute at the end of each time
slice. A periodic interrupt called the tick interrupt is used for this purpose. The length of the time slice
is effectively set by the tick interrupt frequency” ( in page 15) ,

if my tick interrupt occurs in 1 ms, the Scheduler runs every 1 ms. now my question. if in middle of tick interrupts (for example in 500 ns after a tick interrupt), a task must unblocked (for example a semaphore release and makes a task unblocked) the given task will unblock after next interrupt (ie after scheduler runs after a tick interrupt) and will wait for running scheduler? or given task start immediately in middle of tick interrupt (ie after that 500ns scheduler runs and make that task running) ?

thank you.

rtel wrote on Friday, October 11, 2019:

If configUSE_PREEMPTION is set to 1 in FreeRTOSConfig.h, which is the
default if you leave configUSE_PREEMPTION set to 0, then the scheduler
will always run the highest priority task that is able to run even if a
task became able to run in between tick interrupts. So if a task gives
a semaphore, and giving the semaphore unblocks a higher priority task,
then the unblocked task will run immediately - it does not wait until
the next tick interrupt.

mohsen21 wrote on Friday, October 11, 2019:

thanks a lot for reply.
in sentence:
“then the unblocked task will run immediately - it does not wait until
the next tick interrupt”
can i interpret like this?
before any task runs, scheduler runs. so
“if a task gives a semaphore, and giving the semaphore unblocks a higher priority task, then first scheduler runs, and scheduler selects which task must run.”

1 Like

rtel wrote on Friday, October 11, 2019:

Yes.

mohsen21 wrote on Friday, October 11, 2019:

thank you again.
then can we say " 1- scheduler runs at the end of each time slice (tick) and 2- when a condition for unblocking task occurs". “because when a task have conditions to unblock (for example task is waiting for a semaphore or blocked with osdelay() api), an interrupt occurs and runs scheduler” ?

1 Like