Nachos Project Assignment 2 CPU schedualing TA HungLeng












- Slides: 12
Nachos Project Assignment 2 CPU schedualing TA: Hung-Leng Chen
Assignment 1. Implement system call “Sleep” 2. Implement Shortest-Job-First scheduling
System Call: Sleep 1. 請研究 userprog/exception. cc, userprog/syscall. h, test/start. s 這三個檔案 以了解system call是如何實作的。 2. 請實作Sleep(int x)這個system call, 把呼 叫這個system call的thread block住, 並且在 x次的timer interrupts以後才又回到READY 的狀態。
System Call: Sleep (cont. ) The user program is responsible for (defined in code/test/start. s) • Storing the system codes in Register 2 • Storing the arguments in Register 4 , 5, 6, and 7. Exception. Handler in code/userprog/exception. cc • Fetch system call number in Register 2. • Add new exception handler’s switch case in switch …case section Declare a new system call in code/userprog/syscall. h • Define a new system call ID • Declare the interface for Nachos system calls, which will be called by the user program.
System Call: Sleep (cont. ) The low level operation to support the new declared system call in code/test/start. s. . globl Print. Int. ent Print. Int: addiu $2, $0, SC_Print. Int //*put system call number in register 2 syscall //* all parameter of this system call will be stored in //* register 4, 5, 6, and 7 by MIPS machine automatically. j $31. end Print. Int
System Call: Sleep (Hint) 1. 修改exception. cc, syscall. h, start. s 2. 修改thread/alarm. cc, thread/alarm. h, 增 加Wait. Until(int x)來處理Sleep(int x)這個 system call 增加一個class來管理這些因為呼叫Sleep(x) 而處於BLOCK狀態的threads
System Call: Sleep (Hint) Alarm. cc: • 每一次的CPU timer interrupts都會呼叫Call. Back(),將目前執行的 thread yield. Your jobs: • 記錄timer interrupts次數 才知道sleep的thread是否該被叫醒 • Create a thread list 管理sleep中的thread • Wait. Until(int x) 將呼叫sleep system code的thread block, 放進 sleep thread list中 − − − 記得要產生一個interrupt 記得要記錄這個thread要sleep x timer interrupts 呼叫thread->sleep(false)讓thread sleep。(在thread/thread. cc裡) • Wake. Up 將thread叫醒 When? 每次timer interrupts時都要檢查整個sleep thread list, 看看有 誰該wake up. − 偷吃步: 可以sort這個list, 只要檢查到有thread不用wake up, 後面的 list就不用再檢查了 −
SJF Scheduling Nachos 內定的 scheduling algorithm 是 Round. Robin, 我們接下來將加入 non-preemptive SJF scheduling 用 n+1 = tn + (1 - ) n 來預估下一個CPU burst n : 第n個預估的CPU burst長度 tn : 第n個實際的CPU burst長度 : 取 0. 5, 0 = 0 (一次timer interrupt代表CPU burst加 1 公式請參考課本 156頁)
SJF Scheduling (Hint) Begin Running Per timer interrupt: 1. Record actual CPU burst 2. 叫醒應該起床的threads Invoke Sleep(x) 1. Set next predicted CPU burst 2. Insert this thread to Sleeping thread lists 3. Invoke thread->Sleep
Deadline 5/23 24: 00 am Please tar your code and e-mail to kidd@arbor. ee. ntu. edu. tw entitled as your_student_ID_p 2. tar. gz • make clean (submit source code only) • tar zcvf r 92921100_p 2. tar. gz nachos-4. 0
Grading Policy Results of your project 70% Project 2 report 30% 請自行設計一組(或多組)test case來證明你的 project是對的, 針對RR scheduling和SJF scheduling都要能work。 • 同時放到nachos下面去run的thread, 個數至少 3個。 • 請將test result output印在報告中。 • 如何compile test program請參考project 1 reference solution. 助教的test case和result放在web上供大家參考












