add a scheduling module
TRANSCRIPT
Add a Scheduling Module
Lab Objectives:
Practice with Linux scheduler implementation Understand Linux 2.6.24 kernel code Learn Earliest Deadline First Algorithm
Earliest Deadline First Algorithm
A dynamic scheduling algorithm that assigns the highest priority to the job with the earliest deadline.
Essential Parameters: Start time at Si Worst case execution time for Ci Deadline at Di In this lab, we will implement the EDF real-time algorithm in
Linux kernel, which we call the CASIO scheduling class. Reference: http://en.wikipedia.org/wiki/Earliest_deadline_first_scheduling
EDF Scheduling Example
VM setup
• Download the image using – wget http://cslabs.clarkson.edu/oslab/sched_lab.vdi • Applications -> Accessories-> VirtualBox • In Virtual box window click New • Name: Sched_username • Type: Linux • Version: Debian(64 bit) click next
VM setup
• Memory size – increase to 2048MB click next!!• Hard Drive – Select Use an existing virtual
hard drive!!• Browse to find the file syscall_lab.vdi that you
downloaded from cslabs website and then click open!
• Click Create!
VM setup
• Click start!
• UserName: csguest!
• Password: cspassword!
• Become a root user sudo -i!
Lab: Complete the Scheduling Module
Current status: The VM is running in Linux i686 2.6.17.13 A modified kernel is at /usr/src/linux-stable Assume the default working directory is /usr/src/linux-stable Lab plan: Running the VM in Linux i686 2.8.24-casio Run the scheduler simulation and collect test data (upload to polaris) Answer the questions about the linux code and turn in a hardcopy.
Source Code Modification
• Be cautious when modifying the kernel file • Be aware of your typos
• It is good to look for the C preprocessor condition
"CONFIG_SCHED_CASIO_POLICY" In this lab
o You are intensively modifying the kernel
o Your kernel may go into "kernel panic"(=segment fault)
Complete the CASIO Scheduling Module
Define a New Scheduling Class-CASIO
Edit include/linux/sched.h at line 41 and add a new scheduling class shown below right after #define SCHED_IDLE 5 (look for TODO comment)
#ifdef CONFIG_SCHED_CASIO_POLICY #define SCHED_CASIO 6 #endif Question 1: What scheduling classes does Linux kernel 2.6.24 have?
Add Real Time Parameters in PCB
Still in sched.h Fill in the code between #ifdef CONFIG_SCHED_CASIO_POLICY and #endif At around Line 51 add two fields in struct sched_param unsigned int casio_id; unsigned long long deadline; At around line 926-1191 add the same two fields above in
struct task_struct Question 2: Browsing the task_struct structure, list 10 variables and explain
what values they are holding for a process.
Enforce CASIO Class as a RT Policy
Go to kernel/sched.c In function int rt_policy(int policy) around line 140, add the
SCHED_CASIO justification || unlikely(policy == SCHED_CASIO) Question 3: What other real time algorithms does Linux Kernel 2.6.24
support?
Add a RT Queue in Each CPU's RQ Naming Convention: rq represents a running queue kernel/sched.c rb represents red-black tree include/linux/rbtree.h list-head represents header of a double linked list include/linux/list.h Still in kerne/sched.c Inside struct rq at around line 295-324, add the casio real-
time running queue struct casio_rq casio_rq; Question 4: Look for the definition of struct casio_rq and struct casio_task, explain
the data structure of casio_rq and casio_task. (casio_task represents the entity of a casio real-time process)
Set a CASIO RT Process Still in sched.c Inside the function int sched_setscheduler at line 4375, set the
process's scheduling class if(policy ==SCHED_CASIO){ p->deadline=param->deadline; p->casio_id=param->casio_id; } And at line 4402, add the process into casio runqueue if(policy==SCHED_CASIO) { add_casio_task_2_list(&rq->casio_rq, p); }
Set a CASIO RT Process (Con't) Still in sched.c Inside the function __setscheduler at line 4290, set the
process's scheduling operation case SCHED_CASIO: p->sched_class = &casio_sched_class; break; Question 5: Looking at kernel/sched_casio.c, what operations does CASIO
RT scheduling class have?
Decide Which Process to Run NO CODING NEEDED!
Look at kernel/sched.c Question 6: In general, which function decides who is the next process to
run? Question 7: Which function does the job of switching the processes on and
off the CPU? Look at kernel/sched_rt.c Question 8: Which function decides who is the next CASIO process to run?
Configure and Compile Linux Kernel
Configure the Linux kernel
Edit arch/x86/Kconfig and add a new menu entry on line 1605 menu "New RT scheduler" config SCHED_CASIO_POLICY bool "New RT CASIO scheduling policy" default y endmenu right before source "net/Kconfig" Go back to the working directory /usr/src/linux-stable Type the command: make menuconfig Browse the Linux kernel configuration, and make sure "New RT
Scheduler" option is selected.
Compile the kernel
In the working directory /usr/src/linux-stable Compile the kernel Type the command: make Type the command: make modules_install Type the command: make install Type the command: update-grub Type the command: reboot Select CASIO recovery Type root password : stallman
Test the CASIO RT Scheduler
In home directory /root/tasks, there is a user program for CASIO real-time simulation.
Modify the task configuration file system 50 duration 1 5 5 16 16 16 0 0 2 4 4 15 15 15 1 1 3 3 3 14 14 14 2 2 4 2 2 10 10 10 3 3 ---------------------------------------------------------------------------------- Run the simulator Type the comand: ./casio_system system
Collect the Simulation Data
Dump the simulation data to a file: Type the comand: cat /proc/casio_event >
username.dump Type dhclient eth0 (sometimes it can be eth1) Upload that simulation file to the directory: scp username.dump [email protected]:/afs/cu/class/cs444/sp16/
username/sched
References
Adopted from Implementing a new real-time scheduling policy for Linux http://www.eetimes.com/design/embedded/4204929/Real-
Time-Linux-Scheduling-Part-1 Earliest Deadline First Algorithm http://en.wikipedia.org/wiki/Earliest_deadline_first_scheduling Linux 2.6.24 Complete Fair Share Scheduler http://www.ibm.com/developerworks/linux/library/l-completely-
fair-scheduler/ Linux 2.6.24 Source Code Browser http://lxr.linux.no/linux+v2.6.24/include/linux/sched.h