CSCE 311 Fall 2008: Thread Scheduling with Multi-level Queue on OSP2 Simulator - Prof. J. , Study Guides, Projects, Research of Operating Systems

The instructions for project #3 in csce 311 fall 2008 course. Students are required to implement a multi-level queue with round-robin scheduling algorithm for threadcb.java in osp2 simulator. Details on creating two separate queues, estimating cpu burst time using exponential averaging, and inserting threads into the appropriate queue based on the estimated burst time.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 09/02/2009

koofers-user-ezw
koofers-user-ezw 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCE 311
Fall 2008
Project # 3
Assigned: Sept. 23, 2008
Due: Oct. 2th, 2008 (timestamp must be earlier than lecture time)
Objective: To implement Thread scheduling on the OSP2 simulator. You will implement
the module ThreadCB.java to further your understanding of CPU scheduling. You
are required to implement a multi-level queue that uses the round-robin scheduling
algorithm.
Required to turn in: Follow all directions regarding hand-in procedures. Points will be
deducted if you do not follow directions precisely. You must turn in a hard copy of the
ThreadCB.java code you implemented. You must also provide a hard copy of one
run (i.e. osp.log) using the multi-level queue scheduling algorithm described
in this document. You must also submit an electronic copy of your multi-level
queue solution (or your best try) via dropbox. Late assignments will not be accepted.
You must document your code and provide a one-page explanation of how you
accomplished the assignment (or what you have currently and why you could not
complete). You should describe your use, creation, and manipulation of data structures to
accomplish the assignment.
Building and executing the simulation
I suggest that you create a new directory and copy your files from the first part of the cpu
scheduling project and starting with that version of ThreadCB.java modify it to
create the multi-level queue solution. The only file you should have to modify is
ThreadCB.java. Modifying the other files will probably "break" OSP2.
The only changes you need to make to your code from the previous project are:
1) Create a multi-level queue that consists of two separate queues; a high priority
queue and a lower priority queue. (You will need two separate queues.) The high
priority queue will use round-robin scheduling with a quantum value of 20.
The lower priority queue will use round-robin scheduling with a quantum
value of 150.
2) Each time you insert a thread into the multi-level ready queue, you will estimate
the cpu burst time using exponential averaging (τn = αtn-1 + (1-α)τn-1). Use an
alpha value of 0.9, i.e., τn=0.9tn-1+0.1τn-1 . To make this work you will need to
keep track of the last cpu burst for the thread. You will also need to keep track of
the last estimate of the burst time. Do this by adding two additional variables to
the ThreadCB class:
a. int lastCpuBurst (this is tn-1 in the equation)
b. int estimatedBurstTime (this is τ in the equation)
c. long lastDispatch (you need this to compute lastCpuBurst)
When you first create a thread you should initialize these variables to -1. When
you estimate the cpu burst for a new process, there are no previous values of tn-1
and τn-1 that you can use. Instead simply set τn = 20 the quantum for the high
pf2

Partial preview of the text

Download CSCE 311 Fall 2008: Thread Scheduling with Multi-level Queue on OSP2 Simulator - Prof. J. and more Study Guides, Projects, Research Operating Systems in PDF only on Docsity!

CSCE 311

Fall 2008

Project # 3

Assigned: Sept. 23, 2008

Due: Oct. 2th, 2008 (timestamp must be earlier than lecture time)

Objective: To implement Thread scheduling on the OSP2 simulator. You will implement the module ThreadCB.java to further your understanding of CPU scheduling. You are required to implement a multi-level queue that uses the round-robin scheduling algorithm.

Required to turn in: Follow all directions regarding hand-in procedures. Points will be deducted if you do not follow directions precisely. You must turn in a hard copy of the ThreadCB.java code you implemented. You must also provide a hard copy of one run (i.e. osp.log) using the multi-level queue scheduling algorithm described in this document. You must also submit an electronic copy of your multi-level queue solution (or your best try) via dropbox. Late assignments will not be accepted. You must document your code and provide a one-page explanation of how you accomplished the assignment (or what you have currently and why you could not complete). You should describe your use, creation, and manipulation of data structures to accomplish the assignment.

Building and executing the simulation I suggest that you create a new directory and copy your files from the first part of the cpu scheduling project and starting with that version of ThreadCB.java modify it to create the multi-level queue solution. The only file you should have to modify is ThreadCB.java. Modifying the other files will probably "break" OSP2. The only changes you need to make to your code from the previous project are:

  1. Create a multi-level queue that consists of two separate queues; a high priority queue and a lower priority queue. (You will need two separate queues.) The high priority queue will use round-robin scheduling with a quantum value of 20. The lower priority queue will use round-robin scheduling with a quantum value of 150.
  2. Each time you insert a thread into the multi-level ready queue, you will estimate the cpu burst time using exponential averaging (τn = αt (^) n-1 + (1-α)τn-1). Use an alpha value of 0.9 , i.e., τ n = 0.9 t (^) n-1 +0.1 τ n-1. To make this work you will need to keep track of the last cpu burst for the thread. You will also need to keep track of the last estimate of the burst time. Do this by adding two additional variables to the ThreadCB class: a. int lastCpuBurst (this is tn-1 in the equation) b. int estimatedBurstTime (this is τ in the equation) c. long lastDispatch (you need this to compute lastCpuBurst) When you first create a thread you should initialize these variables to -1. When you estimate the cpu burst for a new process, there are no previous values of t (^) n- and τn-1 that you can use. Instead simply set τn = 20 the quantum for the high

priority queue. You can recognize that a process is new because the value of lastCpuBurst is -1.

  1. In order to estimate the burst time, you need the value of lastCpuBurst. Each time you insert a thread into the multi-level queue you should calculate the value of lastCpuBurst and save it in this variable. You calculate the value using the following equation: thread.lastCpuBurst = HClock.get() – thread.lastDispatch; As you can see, you will need the value of lastDispatch in order to do this. Be sure to set this variable each time you dispatch a thread, i.e., thread.lastDispatch = HClock.get() just before returning from do_dispatch.
  2. If the estimated burst time is less than the quantum, you will insert the process into the higher priority round-robin queue. Otherwise you will insert the process into the lower priority round-robin queue. Be sure to save the estimated burst time into the class variable estimatedBurstTime.
  3. When your do_dispatch()is invoked, after checking whether there was a process running (and preempting it and inserting it into the multi-level queue if there was), you will first check the higher priority round-robin queue. If it is not empty then dispatch a process from that queue. (In this case SET THE TIMER USING THE QUANTUM VALUE OF 20). Otherwise check the lower priority round-robin queue. If it is not empty then dispatch a process from that queue, BEING CAREFUL TO SET THE TIMER WITH THE QUANTUM VALUE OF 150 so that you have round-robin instead of FCFS scheduling. If both queues are empty then set PTBR=NULL and return.

Some more hints:

  • The outlined algorithm for the solution to CPU scheduling is derived from a discussion in your OSP2 book regarding the thread scheduling module ThreadCB. Your OSP2 book (and the Silberschatz book) are your best references for conceptual questions on implementation of ThreadCB.java.
  • Be very careful that you do not leave a thread in the ready queue when it is dispatched. If you do, and then re-insert it after a timer-runout or block, the queue may become disconnected, making some ready threads inaccessible. These stranded threads can never be re-scheduled, so threads may starve in the ready queue.

Turning in Your Assignment via dropbox When you are satisfied that your CPU scheduling algorithm in ThreadCB works, use dropbox to submit your project. Use dropbox to submit the following files to Project 3. Do not submit to Project 2, that will overwrite your FCFS solution from the week before :

  1. ThreadCB.java (the multi-level queue version that you have implemented)
  2. osp.log (the output generated from your project)

Remember to turn your assignment in on time. I don't accept late submissions, but I will give partial credit if the assignment actually runs and is on time.