Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions bin/interrupts_EP.dSYM/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.interrupts_EP</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
triple: 'x86_64-apple-darwin'
binary-path: 'bin/interrupts_EP'
relocations: []
...
Binary file added bin/interrupts_EP_RR
Binary file not shown.
20 changes: 20 additions & 0 deletions bin/interrupts_EP_RR.dSYM/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.interrupts_EP_RR</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
triple: 'x86_64-apple-darwin'
binary-path: 'bin/interrupts_EP_RR'
relocations: []
...
20 changes: 20 additions & 0 deletions bin/interrupts_RR.dSYM/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.interrupts_RR</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
triple: 'x86_64-apple-darwin'
binary-path: 'bin/interrupts_RR'
relocations: []
...
9 changes: 6 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ else
rm bin/*
fi

g++ -g -O0 -I . -o bin/interrupts_EP interrupts_student1_student2_EP.cpp
g++ -g -O0 -I . -o bin/interrupts_RR interrupts_student1_student2_RR.cpp
g++ -g -O0 -I . -o bin/interrupts_EP_RR interrupts_student1_student2_EP_RR.cpp
#g++ -g -O0 -I . -o bin/interrupts_EP interrupts_student1_student2_EP.cpp
#g++ -g -O0 -I . -o bin/interrupts_RR interrupts_student1_student2_RR.cpp
g++ -g -O0 -I . -o bin/interrupts_EP_RR interrupts_student1_student2_EP_RR.cpp
#./bin/interrupts_EP ./test1.txt
#./bin/interrupts_RR ./test1.txt
./bin/interrupts_EP_RR ./test1.txt
38 changes: 38 additions & 0 deletions execution.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
+------------------------------------------------+
|Time of Transition |PID | Old State | New State |
+------------------------------------------------+
| 0 |100 | NEW | READY |
| 0 |100 | READY | RUNNING |
| 50 | 10 | NEW | READY |
| 50 |100 | RUNNING | READY |
| 50 | 10 | READY | RUNNING |
| 70 | 10 | RUNNING | WAITING |
| 70 |100 | READY | RUNNING |
| 120 | 10 | WAITING | READY |
| 119 |100 | RUNNING | READY |
| 119 | 10 | READY | RUNNING |
| 139 | 10 | RUNNING | WAITING |
| 139 |100 | READY | RUNNING |
| 189 | 10 | WAITING | READY |
| 188 |100 | RUNNING | READY |
| 188 | 10 | READY | RUNNING |
| 208 | 10 | RUNNING |TERMINATED |
| 208 |100 | READY | RUNNING |
| 308 |100 | RUNNING | READY |
| 308 |100 | READY | RUNNING |
| 408 |100 | RUNNING | READY |
| 408 |100 | READY | RUNNING |
| 508 |100 | RUNNING | READY |
| 508 |100 | READY | RUNNING |
| 608 |100 | RUNNING | READY |
| 608 |100 | READY | RUNNING |
| 708 |100 | RUNNING | READY |
| 708 |100 | READY | RUNNING |
| 808 |100 | RUNNING | READY |
| 808 |100 | READY | RUNNING |
| 908 |100 | RUNNING | READY |
| 908 |100 | READY | RUNNING |
| 1008 |100 | RUNNING | READY |
| 1008 |100 | READY | RUNNING |
| 1060 |100 | RUNNING |TERMINATED |
+------------------------------------------------+
Binary file added interrupts_student1_student2
Binary file not shown.
13 changes: 10 additions & 3 deletions interrupts_student1_student2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ struct PCB{
int PID;
unsigned int size;
unsigned int arrival_time;
int start_time;
int start_time; // time when process starts execution
unsigned int processing_time;
unsigned int remaining_time;
unsigned int remaining_time; // cpu burst time, dont mix with remaining io time
int partition_number;
enum states state;
unsigned int io_freq;
unsigned int io_freq; // frquenxy of io interrupts
unsigned int io_duration;

int remaining_io_time; // added for tracking remaining io time, wait time
int time_until_next_io; // added for tracking time until next io interrupt

};

//------------------------------------HELPER FUNCTIONS FOR THE SIMULATOR------------------------------
Expand Down Expand Up @@ -270,6 +274,9 @@ PCB add_process(std::vector<std::string> tokens) {
process.partition_number = -1;
process.state = NOT_ASSIGNED;

process.remaining_io_time = 0; // initialize wait timer to 0
process.time_until_next_io = process.io_freq; // initialize burst timer to frequency

return process;
}

Expand Down
54 changes: 52 additions & 2 deletions interrupts_student1_student2_EP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,61 @@ std::tuple<std::string /* add std::string for bonus mark */ > run_simulation(std

///////////////////////MANAGE WAIT QUEUE/////////////////////////
//This mainly involves keeping track of how long a process must remain in the ready queue

for (auto itr = wait_queue.begin(); itr != wait_queue.end();){
itr->remaining_io_time--; // decrement IO remaining time
if (itr->remaining_io_time == 0){
PCB process = *itr; // process for the completed IO

process.state = READY;
ready_queue.push_back(process); // add process to the ready queue

sync_queue(job_list, process); // syncing copy of the process state to the real process state
execution_status += print_exec_status(current_time, process.PID, WAITING, READY); // process went from waiting to ready
itr = wait_queue.erase(itr); // remove from wait queue
}
else{
++itr;
}
}
/////////////////////////////////////////////////////////////////

//////////////////////////SCHEDULER//////////////////////////////
FCFS(ready_queue); //example of FCFS is shown here
//FCFS(ready_queue); //example of FCFS is shown here
// asumption: lower pid = higher priority
if(running.PID == -1 && !ready_queue.empty()) { // handling empty CPU
run_process(running, job_list, ready_queue, current_time); // set new running process
execution_status += print_exec_status(current_time, running.PID, READY, RUNNING);
}

if (running.PID != -1){ // handling if there is a running process NO PREEMPTION

if(running.remaining_time == 0){ // handling when the process is finished
execution_status += print_exec_status(current_time, running.PID, RUNNING, TERMINATED);
terminate_process(running, job_list);
idle_CPU(running); // set CPU to idle

if(!ready_queue.empty()) { // checking if there is a ready process that can run
run_process(running, job_list, ready_queue, current_time);
execution_status += print_exec_status(current_time, running.PID, READY, RUNNING);
}
}

else if (running.io_freq > 0 && running.time_until_next_io == 0){ // handling IO interrupt
running.state = WAITING;
running.remaining_io_time = running.io_duration; // set remaining IO time for waiting
running.time_until_next_io = running.io_freq; // reset time until next IO interrupt

wait_queue.push_back(running); // add running process to wait queue
execution_status += print_exec_status(current_time, running.PID, RUNNING, WAITING);

idle_CPU(running);
}
running.remaining_time--; // decrement remaining time of running process
running.time_until_next_io--; // decrement time until next IO interrupt
sync_queue(job_list, running);
}

current_time++;
/////////////////////////////////////////////////////////////////

}
Expand Down
122 changes: 120 additions & 2 deletions interrupts_student1_student2_EP_RR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ std::tuple<std::string /* add std::string for bonus mark */ > run_simulation(std
//to make the code easier :).

unsigned int current_time = 0;
int quantum_counter = 0;
const int TIME_QUANTUM = 100;

PCB running;

//Initialize an empty running process
Expand Down Expand Up @@ -63,11 +66,126 @@ std::tuple<std::string /* add std::string for bonus mark */ > run_simulation(std

///////////////////////MANAGE WAIT QUEUE/////////////////////////
//This mainly involves keeping track of how long a process must remain in the ready queue

for (auto itr = wait_queue.begin(); itr != wait_queue.end();){ // same method approach as in EP and RR
itr->remaining_io_time--;

if (itr->remaining_io_time <= 0){
PCB process = *itr; // process for the completed IO

process.state = READY;
ready_queue.push_back(process); // add process to the ready queue

sync_queue(job_list, process); // syncing copy of the process state to the real process state
execution_status += print_exec_status(current_time + 1, process.PID, WAITING, READY); // process went from waiting to ready
itr = wait_queue.erase(itr); // remove from wait queue
}
else{
++itr;
}
}
/////////////////////////////////////////////////////////////////

//////////////////////////SCHEDULER//////////////////////////////
FCFS(ready_queue); //example of FCFS is shown here
//assumption: picking the next process with the lowest PID from the ready queue

if(ready_queue.size() > 1){ // using bubble sort!! to sort the lowest to highest PID (might be inefficient tho)
for(int i = 0; i < ready_queue.size() - 1; i++){
for(int j = 0; j < ready_queue.size() - i - 1; j++){
// Swap if Left is Smaller than Right (pushes Smallest to the Right/Back)
bool swap = false;
if (ready_queue[j].PID < ready_queue[j+1].PID) {
swap = true;
} else if (ready_queue[j].PID == ready_queue[j+1].PID) {
if (ready_queue[j].arrival_time < ready_queue[j+1].arrival_time) {
swap = true;
}
}
if (swap) {
PCB temp = ready_queue[j];
ready_queue[j] = ready_queue[j+1];
ready_queue[j+1] = temp;
}
}
}
}

if (running.PID != -1 && !ready_queue.empty()) { // handling busy CPU but other opocesses
PCB lower_PID = ready_queue.back(); // Now valid because we sorted above
if (lower_PID.PID < running.PID){ // preempt running process

running.state = READY;
ready_queue.push_back(running); // add running process to ready queue

sync_queue(job_list, running);
execution_status += print_exec_status(current_time, running.PID, RUNNING, READY);
idle_CPU(running);
quantum_counter = 0;
}
}

if (running.PID == -1 && !ready_queue.empty()) {
if(ready_queue.size() > 1){ // nunnle sprt again just in case some processes were added back to ready queue
for(int i = 0; i < ready_queue.size() - 1; i++){
for(int j = 0; j < ready_queue.size() - i - 1; j++){
bool swap = false;
if (ready_queue[j].PID < ready_queue[j+1].PID) {
swap = true;
} else if (ready_queue[j].PID == ready_queue[j+1].PID) {
if (ready_queue[j].arrival_time < ready_queue[j+1].arrival_time) {
swap = true;
}
}
if (swap) {
PCB temp = ready_queue[j];
ready_queue[j] = ready_queue[j+1];
ready_queue[j+1] = temp;
}
}
}
}

run_process(running, job_list, ready_queue, current_time);
quantum_counter = 0;
execution_status += print_exec_status(current_time, running.PID, READY, RUNNING);
}

if (running.PID != -1){ // taken from RR, handling if there is a running process
running.remaining_time--;
if(running.io_freq > 0) {
running.time_until_next_io--;
}
quantum_counter++;
sync_queue(job_list, running);

if(running.remaining_time <= 0){ // handling when the process is finished, taken from RR
execution_status += print_exec_status(current_time + 1, running.PID, RUNNING, TERMINATED);
terminate_process(running, job_list);
idle_CPU(running);
quantum_counter = 0; // reset quantum count
}

else if (running.io_freq > 0 && running.time_until_next_io <= 0){ // taken from EP, handling IO interrupt
running.state = WAITING;
running.remaining_io_time = running.io_duration;
running.time_until_next_io = running.io_freq;

wait_queue.push_back(running);
execution_status += print_exec_status(current_time + 1, running.PID, RUNNING, WAITING);

idle_CPU(running);
quantum_counter = 0;
}

else if (quantum_counter >= TIME_QUANTUM){ // handling if quantum time is over
running.state = READY;
ready_queue.push_back(running); // add running process to back of ready queue
execution_status += print_exec_status(current_time + 1, running.PID, RUNNING, READY);

idle_CPU(running);
quantum_counter = 0;
}
}
current_time++;
/////////////////////////////////////////////////////////////////

}
Expand Down
Loading