Skip to content

HurSungYun/OperatingSystem_scheduler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

project 3: Weighted Round-Robin scheduler for linux kernel

High-level design and Implementation

Data Structures and Functions used in sched_class

  • Two data structures are newly defined to support the newly defined policy in the kernel: wrr_rq and sched_wrr_entity.

  • wrr_rq is defined in kernel/sched/sched.h and consists of a run queue of sched_wrr_entity, a cursor to point to the current head of the circular list, and the sum of weight of the entities in the run queue. wrr_rq structure is included in the existing struct rq to support wrr policy.

  • sched_wrr_entity is defined in include/linux/sched.h and consists of its weight, time slice, and a list head to be included in wrr_rq. sched_wrr_entity structure is included in the existing struct task_struct to support the policy.

  • Among the various methods defined sched_class, our wrr_sched_class uses the following: select_task_rq; enqueue_task; dequeue_task; pick_next_task; task_tick; task_fork; switched_to; get_rr_interval

  • enqueue_task, dequeue_task, pick_next_task are all implemented according to the policy of weighted round-robin.

  • In enqueue_task, if no task is currently in the run queue, add the task to the run queue and point the cursor to the task. Else, add the task right before the cursor.

  • In dequeue_task, if the task that needs to be deleted is pointed by the cursor, update the cursor to the task right next to the current cursor. Else, simply delete the task.

  • In pick_next_task, simply return the task current cursor is pointing to.

  • In task_tick, the time slice of the currently running task is decreased every time. If the time slice is zero, move the cursor to the next task and reschedule.

  • task_fork resets the timeslice of the forked task. switched_to sets weight and timeslice to default value, and get_rr_interval returns the weight of the task multiplied by WRR_TIMESLICE.

Load balancing algorithm

  • Load balancing between rqs are done in scheduler_tick in core.c.

  • First, there exists a global variable to store the last balancing time. At each tick, cpus try to get the balance_lock and check if it is time for load balancing. If it is, the cpu that checked the timestamp updates the timestamp, releases the balance_lock and starts load balancing.

  • Load balancing starts with finding the MAX and MIN RQ. Afterwards, the locks for the two runqueues are acquired, and the function tries to find a migratable task with maximum weight.

  • If there exists a migratable task, the function migrates the task to MIN RQ and unlocks those two locks.

Investigation

We did the investigation with two test programs. One, test.c forks itself into 16 tasks and loops infinitely. The other one, trial.c does the trial division for 1874919423 which can be divided into 3, 13 and 48074857. The last number 4804867 makes the program run for a long time. By this test, we found several relations between program weight and execution time.

  • The execution time decreases when program weight increase. In our result, the relation between weight and execution time was t = 194393*x^(-0.923) with r^2 value 0.982.

  • We inferred the reason of the result. When the weight increases, the time slice for the process increases and the cpu runs our code for a longer time before it switches to other tasks. So the number of interrupts during the process is smaller and the waiting time is shorter.

  • With the result, we can see that our scheduler works well.

Lessons learned.

  • SUNG-YUN HUR: It is really difficult to add new scheduler without guidance. Also, I realized I still have a lot of things to learn.
  • EUN-HYANG KIM: Learned the structure of scheduler.
  • YEON-WOO KIM: Fixing the kernel code is difficult and often dangerous; Always look and look again for possible bugs before testing.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published