From c348829d0518a55a5a4da0fb7967be70cc6e42fb Mon Sep 17 00:00:00 2001 From: Brandon Hopper Date: Wed, 15 Aug 2018 16:12:13 -0400 Subject: [PATCH 1/4] initial commit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0660c39..6d1f32e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Multi-Level Feedback Queue +# Multi-Level Feedback Queue ### Motivation After talking about one of the most popular scheduling algorithms used by operating systems to schedule processes, From 9f962b23e9fe66500bfa128001a180174f5dd8cb Mon Sep 17 00:00:00 2001 From: Brandon Hopper Date: Wed, 15 Aug 2018 16:53:44 -0400 Subject: [PATCH 2/4] -ran npm install and completed Process.js --- src/Process.js | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Process.js b/src/Process.js index 159a307..38aedfb 100644 --- a/src/Process.js +++ b/src/Process.js @@ -16,11 +16,16 @@ class Process { } setParentQueue(queue) { - + this.queue = queue; } isFinished() { - + if (this.blockingTimeNeeded) { + return false; + } + else { + return this.cpuTimeNeeded <= 0; + } } // If no blocking time is needed by this process, decrement the amount of @@ -29,7 +34,18 @@ class Process { // by emitting the appropriate interrupt // Make sure the `stateChanged` flag is toggled appropriately executeProcess(time) { - + const { PROCESS_BLOCKED } = SchedulerInterrupt; + if (this.blockingTimeNeeded > 0) { + this.stateChanged = !this.stateChanged; + this.queue.emitInterrupt(this, PROCESS_BLOCKED); + } + else { + for (let i = time; i > 0; i--) { + if (--this.cpuTimeNeeded == 0) { + break; + } + } + } } // If this process requires blocking time, decrement the amount of blocking @@ -38,16 +54,27 @@ class Process { // top running queue by emitting the appropriate interrupt // Make sure the `stateChanged` flag is toggled appropriately executeBlockingProcess(time) { + for (let i = time; i > 0; i--) { + if (--this.blockingTimeNeeded == 0) { + break; + } + } + + const { PROCESS_READY } = SchedulerInterrupt; + if (this.blockingTimeNeeded <= 0) { + this.stateChanged = !this.stateChanged; + this.queue.emitInterrupt(this, PROCESS_READY); + } } // Returns this process's stateChanged property isStateChanged() { - + return this.stateChanged; } get pid() { - + return this._pid; } // Private function used for testing; DO NOT MODIFY From 47584c933a794f8087309208bafeb32fa7e21631 Mon Sep 17 00:00:00 2001 From: Brandon Hopper Date: Wed, 15 Aug 2018 18:28:13 -0400 Subject: [PATCH 3/4] -Queue stack started still in red --- src/Queue.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Queue.js b/src/Queue.js index 7b45fdf..7d8832c 100644 --- a/src/Queue.js +++ b/src/Queue.js @@ -18,30 +18,31 @@ class Queue { } // Enqueues the given process. Return the enqueue'd process - enqueue(process) { - - } + enqueue(process) { + process.setParentQueue(this); + return this.processes.push(process); +; } // Dequeues the next process in the queue. Return the dequeue'd process dequeue() { - + return this.processes.shift(); } // Return the least-recently added process without removing it from the list of processes peek() { - + return this.processes[0]; } isEmpty() { - + return this.processes == 0; } getPriorityLevel() { - + return this.priorityLevel; } getQueueType() { - + return this.queueType; } // Manages a process's execution for the given amount of time @@ -49,26 +50,26 @@ class Queue { // Once a process has received the alloted time, it needs to be dequeue'd and // then handled accordingly, depending on whether it has finished executing or not manageTimeSlice(currentProcess, time) { - + } // Execute the next non-blocking process (assuming this is a CPU queue) // This method should call `manageTimeSlice` as well as execute the next running process doCPUWork(time) { - + } // Execute the next blocking process (assuming this is the blocking queue) // This method should call `manageTimeSlice` as well as execute the next blocking process doBlockingWork(time) { - + } // The queue's interrupt handler for notifying when a process needs to be moved to a different queue // Should handle PROCESS_BLOCKED and PROCESS_READY interrupts // The process also needs to be removed from the queue emitInterrupt(source, interrupt) { - + } } From d2787007e112ba9af501b670e5b6dfa57e245bdc Mon Sep 17 00:00:00 2001 From: Brandon Hopper Date: Thu, 16 Aug 2018 10:45:28 -0400 Subject: [PATCH 4/4] -remaining Quese class test completed all in green --- src/Queue.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Queue.js b/src/Queue.js index 7d8832c..ba486f0 100644 --- a/src/Queue.js +++ b/src/Queue.js @@ -20,7 +20,8 @@ class Queue { // Enqueues the given process. Return the enqueue'd process enqueue(process) { process.setParentQueue(this); - return this.processes.push(process); + this.processes.push(process); + return process; ; } // Dequeues the next process in the queue. Return the dequeue'd process @@ -50,26 +51,47 @@ class Queue { // Once a process has received the alloted time, it needs to be dequeue'd and // then handled accordingly, depending on whether it has finished executing or not manageTimeSlice(currentProcess, time) { - + if (currentProcess.stateChanged) { + this.quantumClock = 0; + this.scheduler.handleInterrupt(this, currentProcess, SchedulerInterrupt.PROCESS_BLOCKED); + } + else if (time < this.quantum) { + this.quantumClock += time; + } + if (time > this.quantum) { + if (currentProcess.cpuTimeNeeded != 0 && currentProcess.blockingTimeNeeded === 0) { + this.scheduler.handleInterrupt(this, currentProcess, SchedulerInterrupt.LOWER_PRIORITY); + this.quantumClock = 0; + } + this.dequeue(); + } + return currentProcess; } // Execute the next non-blocking process (assuming this is a CPU queue) // This method should call `manageTimeSlice` as well as execute the next running process doCPUWork(time) { + const proc = this.peek(); + proc.executeProcess(time); + this.manageTimeSlice(proc, time); } // Execute the next blocking process (assuming this is the blocking queue) // This method should call `manageTimeSlice` as well as execute the next blocking process doBlockingWork(time) { - + const proc = this.peek(); + proc.executeBlockingProcess(time); + this.manageTimeSlice(proc, time); } // The queue's interrupt handler for notifying when a process needs to be moved to a different queue // Should handle PROCESS_BLOCKED and PROCESS_READY interrupts // The process also needs to be removed from the queue emitInterrupt(source, interrupt) { - + const sourceIndex = this.processes.indexOf(source); + this.processes.splice(sourceIndex, 1); + this.scheduler.handleInterrupt(this, source, interrupt); } }