Skip to document

7. MLFQ Scheduling

An example questions on the Multilevel Feedback Queue - Preemptive -...
Course

Operating Systems Principles (CSCI 340)

16 Documents
Students shared 16 documents in this course
Academic year: 2018/2019
Uploaded by:
0followers
10Uploads
4upvotes

Comments

Please sign in or register to post comments.

Preview text

(MLFQ) Multilevel Feedback Queue ~ Preemptive ~ CPU Scheduling Algorithm

Le t

Pi be = Process i where (i = 0, 1, 2, 3, ...) AT be = Arrival Time CT be = Completion Time WT be = Waiting Time

Qn be = Queue n where (n = 1, 2, 3, ...) BT be = Burst Time TAT be = Turnaround Time RT be = Pi’s Remaining Burst Time __________________________________ Starting Time is always zero to find CT**.**

Draw Gantt Chart where Queue 1 (Q 1 ) uses RR Algorithm with q= 17 , Queue 2 (Q 2 ) uses RR Algorithm with q= 25 , Queue 3 (Q 3 ) uses FCFS Algorithm Priority from high to low : Q 1 to Q 3 Calculate CT, TAT, WT.

P AT BT CT TAT WT

P 0 0 53???

P 1 0 17???

P 2 0 68???

P 3 0 24???

Made By: asifroni673@gmail asif@qmail.cuny

Please note that this example sets all processes of arrival time t= 0**. This means the answer to this problem will be similarly set to FCFS algorithm but preemptive. Each process will all be demoted to lower queue priority. If each process was given different arrival time, resort to Step 0 as the solution will vary differently.**

Drawing Gantt Chart:

Step 0: Start with an empty Gantt Chart.

Let MLFQ Scheduler be the Data Structures of Queue with type Pi in MLFQ Algorithm defined by the following parameter :  Number of Queues (n)  Scheduling Algorithm for each Queue (Qn)  Method used to determine when : + to upgrade a process to a higher – priority queue + to demote a process to a lower – priority queue  Method used to determine which queue a process will enter when that process has remaining burst time (needs service). Let say QA be high priority of Queue and QB be low priority of Queue. When the arrival of a new process is enqueue to QA , then the process is dequeue and enqueue to QB only if  the process is dequeue from QA  the process has remaining burst time (or needs service) Otherwise the process completes its duration ( complete service time ).

MLFQ Scheduler

enqueue → ¿ Q 1 out →complete

dequeue

¿ Q 2 out →complete

dequeue

¿ Q 3 out →complete

t= 0 ⋯⋯⋯ 162 RT P 0 53

P 1 17

68

The CPU will selectively pick the process to be executed from Q 1. By dequeuing, P 0 will be the next process to be executed. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 17 ms, q= 17. Then in MLFQ algorithm, P 0 is demoted to next queue, Q 2. This process is paused and will resume to complete the remaining duration at another time. P 0 has remaining burst time of 36 ms.

MLFQ Scheduler

enqueue → P 3 P 2 P 1 P 0 →complete Q 1

←dequeue

P 0 →complete Q 2

t= 017 ⋯⋯⋯ 162 RT P 0 0 53 → 36

P 1 17

P 2 68

P 3 24

Step 3: When t= 17 , three processes (P 1 , P 2 , P 3 ) are in Q 1 selected by the CPU. Following RR algorithm : There is no new process or other available process.

MLFQ Scheduler

enqueue → P 3 P 2 P 1 P 0 →complete Q 1

The CPU will selectively pick the process to be executed from Q 1. By dequeuing, P 1 will be the next process to be executed. And because this algorithm is RR, it can run the whole duration since its’ burst time is less than or equal to 17 ms (≤ 17 ). By then, P 1 completes its service time.

MLFQ Scheduler

enqueue → P 3 P 2 P 1 P 0 →complete Q 1

←dequeue

P 0 →complete Q 2

t= 01734 ⋯ ⋯⋯ 162 RT P 0 0 36

P 1 1 17 → 0

P 2 68

P 3 24

Step 4: When t= 34 , two processes (P 2 , P 3 ) are in Q 1 selected by the CPU. Following RR algorithm : There is no new process or other available process.

MLFQ Scheduler

enqueue → P 3 P 2 P 1 P 0 →complete Q 1

dequeuing, P 3 will be the next process to be executed. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 17 ms, q= 17. Then in MLFQ algorithm, P 3 is demoted to next queue, Q 2. This process is paused and will resume to complete the remaining duration at another time. P 3 has remaining burst time of 7 ms.

MLFQ Scheduler

enqueue → P 3 P 2 P 1 P 0 →complete Q 1

←dequeue

P 3 P 2 P 0 →complete Q 2

t= 017345168 ⋯⋯ 162 RT P 0 0 36

P 1 1 0

P 2 2 51

P 3 3 24 → 7

Step 6: When t= 68 , three processes (P 0 , P 2 , P 3 ) are in Q 2 selected by the CPU.

MLFQ Scheduler

enqueue → P 3 P 2 P 1 P 0 →complete Q 1

←dequeue

P 3 P 2 P 0 →complete Q 2

←dequeue

→complete Q 3

The CPU will select the priority queue from MLFQ Scheduler.

Q 2 is selected since Q 2 has higher priority than Q 3 (Q 2 >Q 3 ) and the size of Q 1 is empty but the size of Q 2 is not empty.

The CPU will perform Q 2 usage of Round – Robin (RR) algorithm with q= 25.

Step 7: When t= 68 , three processes (P 0 , P 2 , P 3 ) are in Q 2 selected by the CPU. Following RR algorithm : There is no new process or other available process.

MLFQ Scheduler

P 3 P 2 P 0 →complete Q 2

The CPU will selectively pick the process to be executed from Q 2. By dequeuing, P 0 will be the next process to be executed. And because this algorithm is preemptive and is RR, this process can only run partial burst time for 25 ms, q= 25. Then in MLFQ algorithm, P 0 is demoted to next queue, Q 3. This process is paused and will resume to complete the remaining duration at another time. P 0 has remaining burst time of 11 ms.

MLFQ Scheduler

P 3 P 2 P 0 →complete Q 2

P 3 P 2 P 0 →complete Q 2

←dequeue

P 2 P 0 →complete Q 3

t= 01734516893118 ⋯ 162 RT P 0 0 0 11

P 1 1 0

P 2 2 2 51 → 26

P 3 3 7

Step 9: When t= 118 , only one process (P 3 ) is in Q 2 selected by the CPU. Following RR algorithm : There is no new process or other available process.

MLFQ Scheduler

P 3 P 2 P 0 →complete Q 2

The CPU will selectively pick the process to be executed from Q 2. By dequeuing, P 3 will be the next process to be executed. And because this algorithm is RR, it can run the whole duration since its’ burst time is less than or equal to 25 ms (≤ 25 ). By then, P 3 has complete its service time.

MLFQ Scheduler

P 3 P 2 P 0 →complete Q 2

←dequeue

P 2 P 0 →complete Q 3

t= 01734516893118125 ⋯ 162 RT P 0 0 0 11

P 1 1 0

P 2 2 2 26

P 3 3 3 7 → 0

Step 10: When t= 125 , two processes (P 0 , P 2 ) are in Q 3 selected by the CPU.

MLFQ Scheduler

enqueue → P 3 P 2 P 1 P 0 →complete Q 1

←dequeue

P 3 P 2 P 0 →complete Q 2

←dequeue

P 2 P 0 →complete Q 3

P 0 0 0 0 11 → 0

P 1 1 0

P 2 2 2 26

P 3 3 3 0

Step 12: When t= 136 , only one process (P 2 ) is in Q 3 selected by the CPU. Following FCFS algorithm : There is no arrival of new process.

MLFQ Scheduler

P 2 P 0 →complete Q 3

The CPU will selectively pick the process to be executed from Q 3. By dequeuing, P 2 will be the next process to be executed.

Since this algorithm is FCFS but preemptive, this process can run but can be paused at a given time from the arrival of another process. And since there is no arrival of new process, P 2 will run the entire duration completely. By then, P 2 has complete its service time.

MLFQ Scheduler

P 2 P 0 →complete Q 3

t= 01734516893118125136162 RT

P 0 0 0 0 0

P 1 1 0

P 2 2 2 2 26 → 0

P 3 3 3 0

The Complete Gantt Chart

t= 01734516893118125136162 RT P 0 0 0 0 0

P 1 1 0

P 2 2 2 2 0

P 3 3 3 0

MLFQ Scheduler (CompleteVersion)

enqueue → P 3 P 2 P 1 P 0 →complete Q 1

←dequeue

P 3 P 2 P 0 →complete Q 2

←dequeue

P 2 P 0 →complete Q 3

P AT BT CT TAT WT

  • t= - P
    • TotalBT 17 17 17 17 25 25 7 11 26 ¿ - CT ¿ - TAT ¿ - WT ¿ - P - P - P - P
Was this document helpful?

7. MLFQ Scheduling

Course: Operating Systems Principles (CSCI 340)

16 Documents
Students shared 16 documents in this course
Was this document helpful?
asifroni673@gmail.com
(MLFQ) Multilevel Feedback Queue ~ Preemptive ~ CPU Scheduling Algorithm
Le
t
Pi
be = Process
i
where (
i
= 0, 1,
2, 3, …)
AT
be = Arrival Time
CT
be = Completion Time
WT
be = Waiting Time
Qn
be = Queue
n
where (
n
= 1,
2, 3, …)
BT
be = Burst Time
be = Turnaround Time
RT
be =
Pi
s Remaining Burst Time
__________________________________
Starting Time is always zero to find
CT
.
Draw Gantt Chart where
Queue 1 (
Q1
) uses RR Algorithm with
q=17
,
Queue 2 (
Q2
) uses RR Algorithm with
q=25
,
Queue 3 (
Q3
) uses FCFS Algorithm
Priority from high to low:
Q1
to
Q3
Calculate
CT
,
TAT
,
WT
.
P
AT
BT
CT
TAT
WT
P0
0 53 ? ? ?
P1
0 17 ? ? ?
P2
0 68 ? ? ?
P3
0 24 ? ? ?
Made By:
asifroni673@gmail.com
asif.roni18@qmail.cuny.edu
Please note that this example sets all processes of arrival time
.
This means the answer to this problem will be similarly set to FCFS
algorithm but preemptive. Each process will all be demoted to lower
queue priority. If each process was given different arrival time, resort