-
Notifications
You must be signed in to change notification settings - Fork 0
Scheduling implementation
Victor Correal Ramos edited this page May 2, 2020
·
3 revisions
The first step is define a task, that contains the following fields:
typedef struct task{
struct cpu_context myContext; //Context
tid tid; //Task IDentifier
task_info myInfo; //Some statics
int quantumLeft; //Quantum left
bool preemption_enable; //True for avoid context switch
enum state state; //Actual state of the task (RUN, READY, BLOCKED)
}task;Once a task is created, we need to create the task. A task is defined by the code/instructions and the arguments/parameters, so the interface:
sys_response init_task(void * fn, void * data);In addition the task managment, we need some structures and policy for the scheduling process:
- ready Queue : Here the task wait in order to a quantum of CPU.
- next task policy : In this case, the next in the ready queue. The
sched_next_rr()search in this queue for the next task to be executed. - nTask : A counter for design a unique TID to all the new tasks.
- quantumLeft : Remaining quantum for a context switch. In every timer tick, this variable is decremented.
- need replacement : Condition for search the next task. In this case, is the quantum is 0 and the preemption is enabled. The
needs_sched_rr()implements this feature. - idle task: This task is the one if we need a replacement and the ready queue is empty.
The init_schedulign() method initialize all the necessary structures.
For perform a context switch, I use the assembler entry cpu_switch_to(prev, next), this assembler instructions restore all the registers saved before.
In order to maintain the structures updated, the task switch manages the states and the ready queue
All the schedule logic is inside taskscheduling.c and taskscheduling.h files.
Powered by GreenTreeData