Skip to content
Merged
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
tests/.tmp
.pytest_cache
.vscode
__pycache__
__pycache__
.vscode
.ruff_cache
4 changes: 2 additions & 2 deletions Exercises/Response-Time Analysis/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Debug C++",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/response_time_analysis",
"program": "${workspaceFolder}/build/response_time_analysis",
"args": ["${workspaceFolder}/exercise-TC2.csv"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
Expand All @@ -22,4 +22,4 @@
"preLaunchTask": "build"
}
]
}
}
2 changes: 1 addition & 1 deletion Exercises/Response-Time Analysis/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
"problemMatcher": ["$gcc"]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ struct Task {
string id;
int BCET;
int WCET;
int period;
int deadline;
int period;
int deadline;
int priority; // Lower number => higher priority for RMS, if you wish
};

Expand Down Expand Up @@ -68,7 +68,7 @@ void RTA_test(vector<Task>& tasks)
while (R != last_R)
{
last_R = R;
int I = 0;
int I = 0;
for (size_t j = 0; j < i; j++)
{
I += ceil((double)R / tasks[j].period) * tasks[j].WCET;
Expand Down
16 changes: 0 additions & 16 deletions Exercises/Very Simple Simulator/.vscode/c_cpp_properties.json

This file was deleted.

25 changes: 0 additions & 25 deletions Exercises/Very Simple Simulator/.vscode/launch.json

This file was deleted.

5 changes: 0 additions & 5 deletions Exercises/Very Simple Simulator/.vscode/settings.json

This file was deleted.

43 changes: 0 additions & 43 deletions Exercises/Very Simple Simulator/.vscode/tasks.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ README.txt
The files in the Exerercise/Content tab are test cases are provided as a starting point for the 02225 DRTS exercise.

They are in CSV (Comma-Separated Values) format and contain the model parameters for periodic tasks:

- Task: Task name
- BCET: Best-case execution time
- WCET: Worst-case execution time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ T3,1,1,10,10,2
T4,1,2,12,12,3
T5,1,2,15,15,4
T6,1,3,20,20,5
T7,1,4,30,30,6
T7,1,4,30,30,6
8 changes: 8 additions & 0 deletions Exercises/VerySimpleSimulator/exercise-TC1_s.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Task,WCRT,Deadline,Status
T1,1,6,true
T2,54,60,true
T3,2,10,true
T4,4,12,true
T5,6,15,true
T6,10,20,true
T7,28,30,true
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ T7,4,6,75,75,7
T8,5,9,100,100,8
T9,3,12,120,120,9
T10,5,11,150,150,10
T11,6,15,300,300,11
T11,6,15,300,300,11
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ T5,1,22,200,200,5
T6,5,27,300,300,6
T7,8,29,320,320,7
T8,10,34,400,400,8
T9,22,35,480,480,9
T9,22,35,480,480,9
43 changes: 43 additions & 0 deletions Exercises/VerySimpleSimulator/src/jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from dataclasses import dataclass
import numpy as np


# struct to keep track of the jobs
@dataclass
class Jobs:
task: np.array
release_time: int
remaining_time: int
response_time: int


# function to check if every job is done
def check_remaining_jobs(jobs: np.array) -> bool:
"""
Checks if there are any jobs remaining to be executed.
Parameters:
jobs (np.array): The list of jobs to check.
Returns:
bool: True if there are jobs remaining, False otherwise.
"""
for job in jobs:
if job.remaining_time > 0:
return True
return False


# function to check if the job is ready to be executed
def get_ready_list(jobs: np.array, current_time: int) -> np.array:
"""
Get the list of jobs that are ready to be executed.
Args:
jobs (np.array): An array of job objects. Each job object is expected to have 'release_time' and 'remaining_time' attributes.
current_time (int): The current time against which the jobs' readiness is evaluated.
Returns:
np.array: An array of job objects that are ready to be executed. A job is considered ready if its release_time is less than or equal to the current_time and its remaining_time is greater than 0.
"""
ready_job: np.array = []
for job in jobs:
if job.release_time <= current_time and job.remaining_time > 0:
ready_job.append(job)
return ready_job
26 changes: 26 additions & 0 deletions Exercises/VerySimpleSimulator/src/task_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pandas as pd
import numpy as np


def output_result_csv(ouput_path: str, wcrt_dict: dict, tasks: np.array) -> None:
"""
Writes the worst-case response time dictionary to a CSV file.
Parameters:
output_path (str): The file path to write the CSV file to.
wcrt_dict (dict): The dictionary containing the worst-case response times for each task.
"""
# Create a list to store the results
results = []

for job in tasks:
task = job["Task"]
wcrt = wcrt_dict[task]
deadline = job["Deadline"]
status = "true" if wcrt <= deadline else "false"
results.append([task, wcrt, deadline, status])

# Create a DataFrame from the results
results_df = pd.DataFrame(results, columns=["Task", "WCRT", "Deadline", "Status"])

# Save the DataFrame to a CSV file
results_df.to_csv(ouput_path.removesuffix(".csv") + "_s.csv", index=False)
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ struct Task {
string id;
int BCET;
int WCET;
int period;
int deadline;
int period;
int deadline;
int priority; // Lower number => higher priority for RMS
};

Expand All @@ -28,7 +28,7 @@ struct Job {
void readTasksCSV(const string& filename, vector<Task>& tasks)
{
ifstream file(filename);
if (!file.is_open())
if (!file.is_open())
{
cerr << "Error: Could not open file " << filename << endl;
return;
Expand Down Expand Up @@ -68,7 +68,7 @@ void readTasksCSV(const string& filename, vector<Task>& tasks)
// Function to find the job with the highest priority
Job *highest_priority(vector<Job *>& readyList)
{
if (readyList.empty())
if (readyList.empty())
{
return nullptr;
}
Expand All @@ -77,7 +77,7 @@ Job *highest_priority(vector<Job *>& readyList)
readyList.begin(),
readyList.end(),
[](Job* a, Job* b) {
return a->task.priority < b->task.priority;
return a->task.priority < b->task.priority;
}
);
}
Expand All @@ -101,7 +101,7 @@ int advanceTime()

int main(int argc, char* argv[])
{
if (argc != 2)
if (argc != 2)
{
cerr << "Usage: " << argv[0] << " <tasks.csv>" << endl;
return 1;
Expand All @@ -112,7 +112,7 @@ int main(int argc, char* argv[])
readTasksCSV(filename, tasks);

// Simulation time (n cycles)
int n = 1000;
int n = 1000;
int currentTime = 0;

// List of all jobs that are in the system
Expand All @@ -128,16 +128,16 @@ int main(int argc, char* argv[])
while (currentTime <= n)
{
// For each task, if it is time to release a new job, create it.
for (size_t i = 0; i < tasks.size(); ++i)
for (size_t i = 0; i < tasks.size(); ++i)
{
if (currentTime >= nextReleaseTimes[i])
if (currentTime >= nextReleaseTimes[i])
{
Job newJob { tasks[i], currentTime, tasks[i].WCET, 0 };
jobs.push_back(newJob);
nextReleaseTimes[i] += tasks[i].period;
}
}

vector<Job*> readyList = get_ready(jobs, currentTime);
Job* currentJob = highest_priority(readyList);

Expand All @@ -148,16 +148,16 @@ int main(int argc, char* argv[])
currentJob->remainingTime -= delta;

// If the job has completed execution, calculate its response time and update WCRT
if (currentJob->remainingTime <= 0)
if (currentJob->remainingTime <= 0)
{
currentJob->responseTime = currentTime - currentJob->releaseTime;

// Find the corresponding task index
auto it = find_if(tasks.begin(), tasks.end(), [&](const Task& t) {
return t.id == currentJob->task.id;
});

if (it != tasks.end())
if (it != tasks.end())
{
size_t taskIndex = distance(tasks.begin(), it);
worstCaseResponseTimes[taskIndex] = max(
Expand All @@ -178,12 +178,12 @@ int main(int argc, char* argv[])
// Output the worst-case response times for each task
cout << "Task\tWCRT\tDeadline\tStatus" << endl;
cout << "---------------------------------" << endl;
for (size_t i = 0; i < tasks.size(); ++i)
for (size_t i = 0; i < tasks.size(); ++i)
{
string status = (worstCaseResponseTimes[i] <= tasks[i].deadline) ? "✓" : "✗";
cout << " " << tasks[i].id << "\t"
<< worstCaseResponseTimes[i] << "\t"
<< tasks[i].deadline << "\t\t"
cout << " " << tasks[i].id << "\t"
<< worstCaseResponseTimes[i] << "\t"
<< tasks[i].deadline << "\t\t"
<< status << endl;
}

Expand Down
Loading
Loading