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
32 changes: 32 additions & 0 deletions execution.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
0, 1, switch to kernel mode
1, 10, context saved
11, 1, find vector 2 in memory position 0x0004
12, 1, load address 0X0695 into the PC
13, 20, cloning the PCB
33, 0, scheduler called
33, 1, IRET
34, 10, CPU Burst
44, 1, switch to kernel mode
45, 10, context saved
55, 1, find vector 3 in memory position 0x0006
56, 1, load address 0X042B into the PC
57, 60, The program size is 10MB
117, 150, loading program into memory
267, 3, marking partition as occupied
270, 6, updating PCB
276, 0, scheduler called
276, 1, IRET
277, 50, CPU Burst
327, 1, switch to kernel mode
328, 10, context saved
338, 1, find vector 6 in memory position 0x000C
339, 1, load address 0X0639 into the PC
340, 265, SYSCALL ISR (ADD STEPS HERE)
605, 1, IRET
606, 15, CPU Burst
621, 1, switch to kernel mode
622, 10, context saved
632, 1, find vector 6 in memory position 0x000C
633, 1, load address 0X0639 into the PC
634, 265, ENDIO ISR(ADD STEPS HERE)
899, 1, IRET
88 changes: 85 additions & 3 deletions interrupts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,25 @@ std::tuple<std::string, std::string, int> simulate_trace(std::vector<std::string
///////////////////////////////////////////////////////////////////////////////////////////
//Add your FORK output here

int fork_duration = duration_intr;
execution += std::to_string(current_time) + ", " + std::to_string(fork_duration) + ", cloning the PCB\n";
current_time += fork_duration;

//PID(_pid), PPID(_ppid), program_name(_pn), size(_size), partition_number(_part_num) {}
PCB child(current.PID + 1, current.PID, current.program_name, current.size, -1);
if(!allocate_memory(&child)) {
std::cerr << "ERROR! Memory allocation failed!" << std::endl;
}

wait_queue.push_back(current); //just sending current to back of the waiting queue since child will run now "ONLY 1 CPU"
//PARENT SHOULD ALWAYS WAIT FOR CHILD PROCESS'S TO COMPLETE

system_status += "time: " + std::to_string(current_time) + "; current trace: FORK, " + std::to_string(duration_intr) + "\n";
system_status += print_PCB(child, wait_queue);

execution += std::to_string(current_time) + ", 0, scheduler called\n";
execution += std::to_string(current_time) + ", 1, IRET\n";
current_time += 1;

///////////////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -92,8 +110,27 @@ std::tuple<std::string, std::string, int> simulate_trace(std::vector<std::string
///////////////////////////////////////////////////////////////////////////////////////////
//With the child's trace, run the child (HINT: think recursion)

//auto [execution, system_status, _] = simulate_trace( trace_file,
// 0,
// vectors,
// delays,
// external_files,
// current,
// wait_queue);

//BELIEVE THIS IS THE CODE REQUIRED FOR THE RECURRSIVE-----------------------------------------------------------------------------------------------------------------
auto [child_execution, child_status, total_time] = simulate_trace(child_trace, current_time, vectors, delays, external_files, child, wait_queue);

execution += child_execution;
system_status += child_status;
current_time = total_time;

free_memory(&child);

//take the parent out of the wait queue and restore it
current = wait_queue.back();
wait_queue.pop_back();

///////////////////////////////////////////////////////////////////////////////////////////


Expand All @@ -104,6 +141,47 @@ std::tuple<std::string, std::string, int> simulate_trace(std::vector<std::string

///////////////////////////////////////////////////////////////////////////////////////////
//Add your EXEC output here
unsigned int exec_duration = duration_intr;

unsigned int new_size = get_size(program_name, external_files);
if (new_size == -1) {
std::cerr << "ERROR! Program not found!" << std::endl;
}

execution += std::to_string(current_time) + ", " + std::to_string(exec_duration) + ", The program size is " + std::to_string(new_size) + "MB \n";
current_time += exec_duration;

unsigned int load_time = new_size * 15;
execution += std::to_string(current_time) + ", " + std::to_string(load_time) + ", loading program into memory\n";
current_time += load_time;

free_memory(&current);

current.program_name = program_name;
current.size = new_size;

if (!allocate_memory(&current)) {
std::cerr << "ERROR! Memory allocation failed!" << program_name << std::endl;
exit(1);
}

//237, 3, marking partition as occupied
//240, 6, updating PCB
//246, 0, scheduler called
//246, 1, IRET

execution += std::to_string(current_time) + ", 3, marking partition as occupied\n";
current_time += 3;

execution += std::to_string(current_time) + ", 6, updating PCB\n";
current_time += 6;

system_status += "time: " + std::to_string(current_time) + "; current trace: EXEC " + program_name + ", " + std::to_string(duration_intr) + "\n";
system_status += print_PCB(current, wait_queue);

execution += std::to_string(current_time) + ", 0, scheduler called\n";
execution += std::to_string(current_time) + ", 1, IRET\n";
current_time += 1;



Expand All @@ -121,7 +199,11 @@ std::tuple<std::string, std::string, int> simulate_trace(std::vector<std::string
///////////////////////////////////////////////////////////////////////////////////////////
//With the exec's trace (i.e. trace of external program), run the exec (HINT: think recursion)


auto [exec_execution, exec_status, total_time] = simulate_trace(exec_traces, current_time, vectors, delays, external_files, current, wait_queue);

execution += exec_execution;
system_status += exec_status;
current_time = total_time;

///////////////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -156,7 +238,7 @@ int main(int argc, char** argv) {
std::vector<PCB> wait_queue;

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


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

Expand All @@ -181,4 +263,4 @@ int main(int argc, char** argv) {
write_output(system_status, "system_status.txt");

return 0;
}
}
4 changes: 4 additions & 0 deletions program1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CPU, 50
SYSCALL, 6
CPU, 15
END_IO, 6
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./bin/interrupts trace.txt vector_table.txt device_table.txt external_files.txt
13 changes: 13 additions & 0 deletions system_status.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
time: 33; current trace: FORK, 20
+------------------------------------------------------+
| PID |program name |partition number | size | state |
+------------------------------------------------------+
| 1 | init | 5 | 1 | running |
| 0 | init | 6 | 1 | waiting |
+------------------------------------------------------+
time: 276; current trace: EXEC program1, 60
+------------------------------------------------------+
| PID |program name |partition number | size | state |
+------------------------------------------------------+
| 0 | program1 | 4 | 10 | running |
+------------------------------------------------------+
6 changes: 6 additions & 0 deletions trace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FORK, 20
IF_CHILD, 0
IF_PARENT, 0
EXEC program1, 60
ENDIF, 0
CPU, 10