Introduction
:
bool
Scheduler::ShouldISwitch ( Thread oldThread, Thread newThread )
{
bool doSwitch;
switch(policy)
{
case SCHED_FCFS:
{
doSwitch = false;
break;
}
case SCHED_SJF:
{
//YOUR PROJECT2 CODE HERE
doSwitch = false;
break;
}
case SCHED_PRIO_NP:
{
//YOUR PROJECT2 CODE HERE
doSwitch = false;
break;
}
default:
doSwitch = false;
break;
}
return doSwitch;
}
Requirement
COMP 3511
Operating Systems
Project #2
Objectives and Tasks
n Run Nachos with Pre-implemented Scheduling
System Skeleton
n Implement SJF and Non-preemptive Priority
Scheduling Algorithms
n Explain the Results
You are strongly recommended to use the servers in
this lab for this project.
ssh username@csl2wk01(~csl2wk40).cse.ust.hk
Task 1
n Task 1: Run Nachos with Pre-implemented
Scheduling System Skeleton
n Step 1: Download Nachos source code of this project
n Step 2: Extract the source code
n Step 3: Compile the code
n Step 4: Run nachos
n Step 5: Read the code
Task 1
n Three scheduling algorithms
n First Come First Serve (FCFS)
n Shortest Job First (SJF)
n Non-Preemptive Priority (NP_Priority)
Executable File Source File
Corresponding
Algorithm
Already
Implemented?
test0 test.0.cc FCFS Yes
test1 test.1.cc SJF No
test2 test.2.cc NP_Priority No
Task 1
n Read the codes (threads/scheduler.cc)
n ReadyToRun()
n placing a thread into ready queue
n FindNextToRun()
n decides the policy of picking one thread to run from the
ready queue
n ShouldISwitch()
n whether the running thread should preemptively give up
to a newly forked thread
Task 2
n Implement SJF and NP_Priority
n Only modify scheduler.cc
n Scheduler::ReadyToRun
n Scheduler::FindNextToRun
n Scheduler::ShouldISwitch
Task 2
n Shortest Job First
n the thread with the shortest burst time in the ReadyList
should be scheduled for running after the current
thread is done with burst.
n Return first thread when scheduler needs to pick one
thread to run
n Hint: insert the thread to ReadyList according to its
burst time when a thread gets ready.
n Make use of the function SortedInsert() in List.cc
n Example:
list->SortedInsert(thread,thread->getBurstTime());
this line of code insert the thread into the list based
on its burst time.
Task 2
n Non-Preemptive Priority Scheduling
n the thread with the highest priority in the ReadyList
should be scheduled for running after the current
thread is done with burst.
n Return first thread when scheduler needs to pick one
thread to run
n Hint: insert the thread to ReadyList according to its
priority when a thread gets ready.
n Make use of the function SortedInsert() in List.cc
n Take care of the order!
Task 2
n Compile and Run
n Save your outputs to project2_test1.txt and
project2_test2.txt, respectively,
n Keep your source code scheduler.cc
Task 3
n Explain the Results
1. Understand the output of test0 (FCFS scheduling) , test1 (SJF
scheduling) and test2 (NPPriority). Then calculate the following
performance metrics of each scheduling algorithms:
a) Average waiting time;
b) Average response time;
c) Average turn-around time.
2. Compare the performance among the first two scheduling algorithms
(FCFS and SJF) in the aspects mentioned in question 1, then discuss
the pros and cons of each scheduling algorithms. (Note: you are
strongly encouraged to change the input threads in test.0.cc and
test.1.cc in order to make your discussion more convincing. However,
when submitting the outputs of test1, please do submit the outputs with
the original input threads.)
Outputs
n Please generate a single file using ZIP and submit it through
CASS
n Name of the ZIP: “proj2**.zip” (* as student ID)
n Inside the ZIP file:
File Name Description
scheduler.cc
Source code you have accomplished by
the end of Task2
project2_test1.txt Output of test1
project2_test2.txt Output of test2
project2_report.txt The answer to the questions in Task 3