scheduling.multi_level_feedback_queue¶
Attributes¶
Classes¶
MLFQ(Multi Level Feedback Queue) |
|
Module Contents¶
- class scheduling.multi_level_feedback_queue.MLFQ(number_of_queues: int, time_slices: list[int], queue: collections.deque[Process], current_time: int)¶
MLFQ(Multi Level Feedback Queue) https://en.wikipedia.org/wiki/Multilevel_feedback_queue MLFQ has a lot of queues that have different priority In this MLFQ, The first Queue(0) to last second Queue(N-2) of MLFQ have Round Robin Algorithm The last Queue(N-1) has First Come, First Served Algorithm
- calculate_completion_time(queue: list[Process]) list[int] ¶
This method calculates completion time of processes >>> P1 = Process(“P1”, 0, 53) >>> P2 = Process(“P2”, 0, 17) >>> P3 = Process(“P3”, 0, 68) >>> P4 = Process(“P4”, 0, 24) >>> mlfq = MLFQ(3, [17, 25], deque([P1, P2, P3, P4]), 0) >>> _ = mlfq.multi_level_feedback_queue() >>> mlfq.calculate_turnaround_time([P1, P2, P3, P4]) [136, 34, 162, 125]
- calculate_remaining_burst_time_of_processes(queue: collections.deque[Process]) list[int] ¶
This method calculate remaining burst time of processes >>> P1 = Process(“P1”, 0, 53) >>> P2 = Process(“P2”, 0, 17) >>> P3 = Process(“P3”, 0, 68) >>> P4 = Process(“P4”, 0, 24) >>> mlfq = MLFQ(3, [17, 25], deque([P1, P2, P3, P4]), 0) >>> finish_queue, ready_queue = mlfq.round_robin(deque([P1, P2, P3, P4]), 17) >>> mlfq.calculate_remaining_burst_time_of_processes(mlfq.finish_queue) [0] >>> mlfq.calculate_remaining_burst_time_of_processes(ready_queue) [36, 51, 7] >>> finish_queue, ready_queue = mlfq.round_robin(ready_queue, 25) >>> mlfq.calculate_remaining_burst_time_of_processes(mlfq.finish_queue) [0, 0] >>> mlfq.calculate_remaining_burst_time_of_processes(ready_queue) [11, 26]
- calculate_sequence_of_finish_queue() list[str] ¶
This method returns the sequence of finished processes >>> P1 = Process(“P1”, 0, 53) >>> P2 = Process(“P2”, 0, 17) >>> P3 = Process(“P3”, 0, 68) >>> P4 = Process(“P4”, 0, 24) >>> mlfq = MLFQ(3, [17, 25], deque([P1, P2, P3, P4]), 0) >>> _ = mlfq.multi_level_feedback_queue() >>> mlfq.calculate_sequence_of_finish_queue() [‘P2’, ‘P4’, ‘P1’, ‘P3’]
- calculate_turnaround_time(queue: list[Process]) list[int] ¶
This method calculates turnaround time of processes >>> P1 = Process(“P1”, 0, 53) >>> P2 = Process(“P2”, 0, 17) >>> P3 = Process(“P3”, 0, 68) >>> P4 = Process(“P4”, 0, 24) >>> mlfq = MLFQ(3, [17, 25], deque([P1, P2, P3, P4]), 0) >>> _ = mlfq.multi_level_feedback_queue() >>> mlfq.calculate_turnaround_time([P1, P2, P3, P4]) [136, 34, 162, 125]
- calculate_waiting_time(queue: list[Process]) list[int] ¶
This method calculates waiting time of processes >>> P1 = Process(“P1”, 0, 53) >>> P2 = Process(“P2”, 0, 17) >>> P3 = Process(“P3”, 0, 68) >>> P4 = Process(“P4”, 0, 24) >>> mlfq = MLFQ(3, [17, 25], deque([P1, P2, P3, P4]), 0) >>> _ = mlfq.multi_level_feedback_queue() >>> mlfq.calculate_waiting_time([P1, P2, P3, P4]) [83, 17, 94, 101]
- first_come_first_served(ready_queue: collections.deque[Process]) collections.deque[Process] ¶
FCFS(First Come, First Served) FCFS will be applied to MLFQ’s last queue A first came process will be finished at first >>> P1 = Process(“P1”, 0, 53) >>> P2 = Process(“P2”, 0, 17) >>> P3 = Process(“P3”, 0, 68) >>> P4 = Process(“P4”, 0, 24) >>> mlfq = MLFQ(3, [17, 25], deque([P1, P2, P3, P4]), 0) >>> _ = mlfq.first_come_first_served(mlfq.ready_queue) >>> mlfq.calculate_sequence_of_finish_queue() [‘P1’, ‘P2’, ‘P3’, ‘P4’]
- multi_level_feedback_queue() collections.deque[Process] ¶
MLFQ(Multi Level Feedback Queue) >>> P1 = Process(“P1”, 0, 53) >>> P2 = Process(“P2”, 0, 17) >>> P3 = Process(“P3”, 0, 68) >>> P4 = Process(“P4”, 0, 24) >>> mlfq = MLFQ(3, [17, 25], deque([P1, P2, P3, P4]), 0) >>> finish_queue = mlfq.multi_level_feedback_queue() >>> mlfq.calculate_sequence_of_finish_queue() [‘P2’, ‘P4’, ‘P1’, ‘P3’]
- round_robin(ready_queue: collections.deque[Process], time_slice: int) tuple[collections.deque[Process], collections.deque[Process]] ¶
RR(Round Robin) RR will be applied to MLFQ’s all queues except last queue All processes can’t use CPU for time more than time_slice If the process consume CPU up to time_slice, it will go back to ready queue >>> P1 = Process(“P1”, 0, 53) >>> P2 = Process(“P2”, 0, 17) >>> P3 = Process(“P3”, 0, 68) >>> P4 = Process(“P4”, 0, 24) >>> mlfq = MLFQ(3, [17, 25], deque([P1, P2, P3, P4]), 0) >>> finish_queue, ready_queue = mlfq.round_robin(mlfq.ready_queue, 17) >>> mlfq.calculate_sequence_of_finish_queue() [‘P2’]
- update_waiting_time(process: Process) int ¶
This method updates waiting times of unfinished processes >>> P1 = Process(“P1”, 0, 53) >>> P2 = Process(“P2”, 0, 17) >>> P3 = Process(“P3”, 0, 68) >>> P4 = Process(“P4”, 0, 24) >>> mlfq = MLFQ(3, [17, 25], deque([P1, P2, P3, P4]), 0) >>> mlfq.current_time = 10 >>> P1.stop_time = 5 >>> mlfq.update_waiting_time(P1) 5
- current_time¶
- number_of_queues¶
- ready_queue¶
- time_slices¶
- class scheduling.multi_level_feedback_queue.Process(process_name: str, arrival_time: int, burst_time: int)¶
- arrival_time¶
- burst_time¶
- process_name¶
- stop_time¶
- turnaround_time = 0¶
- waiting_time = 0¶
- scheduling.multi_level_feedback_queue.P1¶