1. Homepage
  2. Programming
  3. CSI3101 Operating Systems - Project 2: CPU Scheduling

CSI3101 Operating Systems - Project 2: CPU Scheduling

Engage in a Conversation
YonseiCSI3101Operating SystemsCPU SchedulingC

Project 2: CPU Scheduling CourseNana.COM

CourseNana.COM

Project plan CourseNana.COM

Total 6 projects CourseNana.COM

  1. Booting xv6 CourseNana.COM

  2. System call CourseNana.COM

  3. CPU scheduling (this project) CourseNana.COM

  4. Virtual memory CourseNana.COM

  5. Page replacement CourseNana.COM

  6. File systems CourseNana.COM

CourseNana.COM

Background: xv6 Process State CourseNana.COM

CourseNana.COM

Background: xv6 CPU Scheduler CourseNana.COM

CourseNana.COM

Background: xv6 Scheduling Points CourseNana.COM

This command will list up codes that invokes sched() CourseNana.COM

CourseNana.COM

Background: xv6 Scheduling Examples CourseNana.COM

  • Every timer IRQ enforces an yield of a CPU CourseNana.COM

  • Process to be scheduled to RUNNING will be chosen in round-robin manner CourseNana.COM

tick tick tick tick CourseNana.COM

P1 P2 P3 CourseNana.COM

RUNNABLE CourseNana.COM

This slide is about the master branch (Project 0), NOT project1 branch CourseNana.COM

CourseNana.COM

Objective 1: Priority Scheduler CourseNana.COM

Implement a priority scheduler in xv6 Requirements CourseNana.COM

Schedule a process with the highest priority to run
nice value: -5 (highest priority) to 4 (lowest priority)
For processes with the same priority, a process with the lowest PID is scheduled CourseNana.COM

Scheduling points CourseNana.COM

  • When a process exits (exit()) CourseNana.COM

  • When a process is blocked (sleep(), read(), etc.) CourseNana.COM

  • Whenaprocesscallstheyield()syscall CourseNana.COM

  • When a process changes its priority (nice()) CourseNana.COM

  • When a process is woken up (wakeup()) CourseNana.COM

  • All outcomes of the CPU scheduling must comply with the priority scheduling policy, hence scheduling a process with the highest priority CourseNana.COM

CourseNana.COM

Objective 1: Priority Scheduler CourseNana.COM

Hints CourseNana.COM

Timer tick is left to occur but should not incur CPU scheduling CourseNana.COM

When you call sched(), you need to refer to the comments of the sched() function CourseNana.COM

When there is no runnable process, the scheduler context is running In this case, invoking sched() may lead to unexpected behavior CourseNana.COM

CourseNana.COM

Objective 2: MLFQ Scheduler CourseNana.COM

Implement a MLFQ scheduler in xv6 Requirements CourseNana.COM

3 priority classes (high, medium, low)
Rule 1: If Priority(A) > Priority(B), A runs (B doesn’t).
Rule 2: If Priority(A) = Priority(B), A & B run in RR.
Rule 3: When a job enters the system, it is placed at the highest priority. CourseNana.COM

Rule 4: If a job uses up an entire time slice while running, its priority is reduced (i.e. moves down one queue). If a job gives up the CPU before the time slice is up, it stays at the same priority level. CourseNana.COM

RR time slice is 4 ticks CourseNana.COM

A process’s time slice is reduced every time a timer tick happens, even if the process has not fully utilized the time provided by that timer tick. CourseNana.COM

CourseNana.COM

Objective 2: MLFQ Scheduler CourseNana.COM

Requirements (cont’d) CourseNana.COM

Scheduling points
When a new process is created (fork())
When a process exits (exit())
When a process is blocked (sleep(), read(), etc.) Whenaprocesscallstheyield()syscall
When a process is woken up (wakeup())
When a time slice is expired CourseNana.COM

Hints
A timer tick can cause a CPU scheduling. This policy is different from priority CourseNana.COM

scheduling
nice() has no effect under MLFQ CourseNana.COM

CourseNana.COM

Hand-out Instruction CourseNana.COM

  • This assignment is based on project 1
    nice() and yield() system calls are necessary CourseNana.COM

    Do this assignment upon your project 1 source code CourseNana.COM

  • For those who don’t have a proper implementation of the two syscalls, You can download project 2 branch after April 8th
    $ cd csi3101-xv6/
    $ git fetch origin CourseNana.COM

    $ git checkout -b project2 remotes/origin/project2 CourseNana.COM

CourseNana.COM

Hand-in Instruction CourseNana.COM

  • You need to submit three files to LearnUs CourseNana.COM

    • –  A source code containing a priority scheduler CourseNana.COM

    • –  A source code containing a MLFQ scheduler CourseNana.COM

    • –  A PDF report with a short description of what you’ve done with your project and a screenshot of your project result CourseNana.COM

  • An instruction to generate the source code to submit Use the command “make submission” CourseNana.COM

    $ make submission CourseNana.COM

    This will generate a tarball file “xv6_submission.tar CourseNana.COM

    Make two different tarball files and submit each to LearnUs using different names xv6_submission_prio.tar,xv6_submission_mlfq.tar CourseNana.COM

  • Due date: 5/3 (Friday), 23:59:59 PM
    -20% penalty per day for delayed submission CourseNana.COM

CourseNana.COM

Hints (1/5) CourseNana.COM

Use gdb to debug your xv6 CourseNana.COM

You need to create a gdbinit file CourseNana.COM

$ mkdir -p ~/.config/gdb CourseNana.COM

$ echo “add-auto-load-safe-path /path/to/xv6/” > ~/.config/gdb/gdbinit CourseNana.COM

Then, run “make qemu-nox-gdbOpen another terminal and run “gdb CourseNana.COM

CourseNana.COM

Hints (2/5) CourseNana.COM

Identifying callsites addr2line CourseNana.COM

Convert addresses into file names and line numbers CourseNana.COM

Example: $ addr2line -e kernel 80103eb1 8010427b 80105ded 80105afc 8010313f 8010328c CourseNana.COM

CourseNana.COM

Hints (3/5) CourseNana.COM

  • The xv6 kernel programming interface is different from the userspace API cprintf() is for the kernel but printf() is for userspace CourseNana.COM

    Please refer to other kernel source codes to identify what APIs you can use defs.h contains functions available in the xv6 kernel CourseNana.COM

  • User space APIs is available in user.h fork(),wait(),sleep(),uptime(),open(),read(), ... CourseNana.COM

  • Build your own test program to test CPU schedulers CourseNana.COM

    Use fork() to spawn multiple processes CourseNana.COM

    Use sleep() to make a process interactive
    int sleep(int ticks) /* sleeps for a specified number of ticks */ CourseNana.COM

CourseNana.COM

Hints (4/5) CourseNana.COM

xv6 has no dynamic memory allocator like malloc() in C
If you need dynamic memory allocation, use kalloc() which returns 4KB CourseNana.COM

memory CourseNana.COM

Before using kalloc(), please consider whether your required memory can be allocated statically CourseNana.COM

Memory leak should NOT occur. Hence, you need to free memory whenever the memory is no longer necessary CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
Yonsei代写,CSI3101代写,Operating Systems代写,CPU Scheduling代写,C代写,Yonsei代编,CSI3101代编,Operating Systems代编,CPU Scheduling代编,C代编,Yonsei代考,CSI3101代考,Operating Systems代考,CPU Scheduling代考,C代考,Yonseihelp,CSI3101help,Operating Systemshelp,CPU Schedulinghelp,Chelp,Yonsei作业代写,CSI3101作业代写,Operating Systems作业代写,CPU Scheduling作业代写,C作业代写,Yonsei编程代写,CSI3101编程代写,Operating Systems编程代写,CPU Scheduling编程代写,C编程代写,Yonseiprogramming help,CSI3101programming help,Operating Systemsprogramming help,CPU Schedulingprogramming help,Cprogramming help,Yonseiassignment help,CSI3101assignment help,Operating Systemsassignment help,CPU Schedulingassignment help,Cassignment help,Yonseisolution,CSI3101solution,Operating Systemssolution,CPU Schedulingsolution,Csolution,