Question

Vous désirez savoir comment le planificateur est appelé pour qu'il puisse passer des tâches. Comme dans même si son préemptif ou la planification de tournoi à la ronde - le planificateur doit venir à l'image pour faire toute sorte de changement de tâche. En supposant une faible tâche prioritaire a une boucle infinie - quand est le planificateur d'intervenir et passer à une tâche de priorité plus élevée

La requête est: 1. Qui appelle le planificateur? [En VxWorks] 2. Si elle est appelée à intervalles réguliers - comment ce mécanisme mis en œuvre

Merci à l'avance.

- Ashwin

Était-ce utile?

La solution

The simple answer is that vxWorks takes control through a hardware interrupt from the system timer that occurs continually at fixed intervals while the system is running.

Here's more detail:

When vxWorks starts, it configures your hardware to generate a timer interrupt every n milliseconds, where n is often 10 but completely depends on your hardware. The timer interval is generally set up by vxWorks in your Board Support Package (BSP) when it starts.

Every time the timer fires an interrupt, the system starts executing the timer interrupt handler. The timer interrupt handler is part of vxWorks, so now vxWorks has control. The first thing it does is save the CPU state (such as registers) into the Task Control Block (TCB) of the currently running task.

Then eventually vxWorks runs the scheduler to determine who runs next. To run a task, vxWorks copies the state of the task from its TCB into the machine registers, and after it does that the task has control of the CPU.

Bonus info:

vxWorks provides hooks into the task switching logic so you can have a function get called whenever your task gets preempted.

Autres conseils

indiv provides a very good answer, but it is only partially accurate.
The actual working of the system is slightly more complex.

The scheduler can be executed as a result of either synchronous or asynchronous operations.

Synchronous refers to operations that are caused as a result of the code in the currently executing task. A prime example of this would be to take a semaphore (semTake).
If the semaphore is not available, the currently executing task will pend and no longer be available to execute. At this point, the scheduler will be invoked and determine the next task that should execute and will perform a context switch.

Asynchronous operations essentially refer to interrupts. Timer interrupts were very well described by indiv. However, a number of different elements could cause an interrupt to execute: network traffic, sensor, serial data, etc...

It is also good to remember that the timer interrupt does not necessarily cause a context switch! Yes, the interrupt will occur, and delayed task and the time slice counters will be decremented. However, if the time slice is not expired, or no higher priority task transitions from the pended to the ready state, then the scheduler will not actually be invoked, and you will return back to the original task, at the exact point where execution was interrupted.

Note that the scheduler does not have its own context; it is not a task. It is simply code that executes in whatever context it is invoked from. Either from the interrupt context (asynchronous) or from the invoking task context (synchronous).

Unless you have a majorily-customized target build, the scheduler is invoked by the Timer interrupt. Details are platform-specific, though.

The scheduler also gets invoked if current task gets completed or blocks.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top