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
11 changes: 11 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/SYSC4001_A1.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

248 changes: 248 additions & 0 deletions .idea/editor.xml

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 103 additions & 2 deletions interrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
*
* @file interrupts.cpp
* @author Sasisekhar Govind
* @author Fareen. Lavji
* @author Dearell Tobenna Ezeoke
* @version October 05, 2025
*
* Assignment assumptions:
* --> ISR of both END/IO and SYSCALL for the same device takes the same amount of time
* --> I/O devices are always available, i.e., no delay on I/O request, immediate start
*/

#include<interrupts.hpp>
Expand All @@ -20,7 +26,25 @@ int main(int argc, char** argv) {

/******************ADD YOUR VARIABLES HERE*************************/


std::string activity;
int eventDuration = 0;
int deviceNumber = 0;
int taskEstimate = 0;
std::string isrAddress;
int modeBit = 0;
std::string deviceName;

// Fixed constants (all measured in ms)
const int switchModeDuration = 1;
const int saveContextDuration = 10;
const int isrAddressSearchDuration = 1;
const int isrAddressExtractDuration = 1;
const int iretExecuteDuration = 1;

// Simulation clocking and events
long long timeOfEvent = 0;
std::string eventType;
int traceFileLineNumber = 0;

/******************************************************************/

Expand All @@ -30,7 +54,84 @@ int main(int argc, char** argv) {

/******************ADD YOUR SIMULATION CODE HERE*************************/


++traceFileLineNumber;

// Keep the parsed label as our event type for logging
eventType = activity;

if (activity == "CPU") {
eventDuration = duration_intr;

execution += std::to_string(timeOfEvent) + ", "
+ std::to_string(eventDuration) + ", CPU burst\n";

timeOfEvent += eventDuration;
modeBit = 0;
continue;
}

// For interrupts: SYSCALL or END_IO
if (activity == "SYSCALL" || activity == "END_IO") {
deviceNumber = duration_intr;

isrAddress = vectors.at(deviceNumber);
int totalISRTime = delays.at(deviceNumber);

int overheadBefore =
switchModeDuration + saveContextDuration
+ isrAddressSearchDuration + isrAddressExtractDuration;

int overheadAfter = iretExecuteDuration;

// Compute remaining ISR
taskEstimate = totalISRTime - (overheadBefore + overheadAfter);
if (taskEstimate < 0) taskEstimate = 0;

// This will switch to kernel mode
modeBit = 1;
eventDuration = switchModeDuration;
execution += std::to_string(timeOfEvent) + ", "
+ std::to_string(eventDuration) + ", switch to kernel mode\n";
timeOfEvent += eventDuration;

// save context
eventDuration = saveContextDuration;
execution += std::to_string(timeOfEvent) + ", "
+ std::to_string(eventDuration) + ", context saved\n";
timeOfEvent += eventDuration;

// This part searches the vector table entry
eventDuration = isrAddressSearchDuration;
execution += std::to_string(timeOfEvent) + ", "
+ std::to_string(eventDuration) + ", find vector for device "
+ std::to_string(deviceNumber) + "\n";
timeOfEvent += eventDuration;

// This will extract ISR address
eventDuration = isrAddressExtractDuration;
execution += std::to_string(timeOfEvent) + ", "
+ std::to_string(eventDuration) + ", obtain ISR address "
+ isrAddress + "\n";
timeOfEvent += eventDuration;

if (taskEstimate > 0) {
eventDuration = taskEstimate;
execution += std::to_string(timeOfEvent) + ", "
+ std::to_string(eventDuration) + ", execute ISR activity (device "
+ std::to_string(deviceNumber) + ")\n";
timeOfEvent += eventDuration;
}

// IRET
eventDuration = iretExecuteDuration;
execution += std::to_string(timeOfEvent) + ", "
+ std::to_string(eventDuration) + ", IRET\n";
timeOfEvent += eventDuration;

// Sets it back to user mode
modeBit = 0;
continue;
}

/************************************************************************/

Expand Down
23 changes: 23 additions & 0 deletions interrupts.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
#ifndef INTERRUPTS_HPP_
#define INTERRUPTS_HPP_

/**
*
* @file interrupts.hpp
* @author Sasisekhar Govind
* @author Fareen. Lavji
* @author Dearell Tobenna Ezeoke
* @version October 05, 2025
*
* Assignment assumptions:
* --> ISR of both END/IO and SYSCALL for the same device takes the same amount of time
* --> I/O devices are always available, i.e., no delay on I/O request, immediate start
*/
#include<iostream>
#include<fstream>
#include<string>
Expand Down Expand Up @@ -139,4 +151,15 @@ void write_output(std::string execution) {

std::cout << "Output generated in execution.txt" << std::endl;
}

// Function to iterate through the table line by line
void iterateByLine() const {
for (const auto& row : table_) {
if (row.size() == 2) { // Ensure the row has exactly 2 columns
std::cout << "Column 1: " << row[0] << ", Column 2: " << row[1] << std::endl;
} else {
std::cerr << "Invalid row size. Skipping..." << std::endl;
}
}
}
#endif