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
2 changes: 1 addition & 1 deletion Exercises/Response-Time Analysis/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"preLaunchTask": "build"
}
]
}
}
Binary file not shown.
88 changes: 88 additions & 0 deletions Exercises/Response-Time Analysis/src/real_time_analysis copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import pandas as pd
import math


def read_csv(file):
"""
Read tasks from a CSV file and convert to a list of task dictionaries.
"""
df = pd.read_csv(file)
req_columns = ['Task', 'BCET', 'WCET', 'Period', 'Deadline', 'Priority']

if not all(col in df.columns for col in req_columns):
raise ValueError(f"Missing required column(s): {req_columns}")

tasks = []
for _, row in df.iterrows():
task = {
"name": row['Task'],
"bcet": row['BCET'],
"wcet": row['WCET'],
"period": row['Period'],
"deadline": row['Deadline'],
"priority": row['Priority']
}
tasks.append(task)

return tasks


def response_time_analysis(tasks):
"""
Perform Response-Time Analysis.
"""
# Sort tasks by priority (lower number means higher priority)
sorted_tasks = sorted(tasks, key=lambda x: x['priority'])

results = []

for i, task in enumerate(sorted_tasks):
R = task['wcet'] # Initial response time
last_R = -1
schedulable = True

while R != last_R:
last_R = R
interference = 0

# Calculate interference from higher-priority tasks
for j in range(i):
higher_task = sorted_tasks[j]
interference += math.ceil(R / higher_task['period']) * higher_task['wcet']

R = task['wcet'] + interference

# Check if the task is schedulable
if R > task['deadline']:
schedulable = False
break

# Store results
result = {
'Task': task['name'],
'WCRT': R,
'Deadline': task['deadline'],
'Status': 'Schedulable' if schedulable else 'Not Schedulable'
}
results.append(result)

return results


def run_rta(path_file):
"""
Main function to read tasks and perform response time analysis.
"""
# Read tasks from CSV
tasks = read_csv(path_file)

# Perform response time analysis
analysis_results = response_time_analysis(tasks)

# Print results
for result in analysis_results:
if result['Status'] == 'Schedulable':
print(f"Task {result['Task']} is schedulable with WCRT = {result['WCRT']:.1f}")
else:
print(f"Task {result['Task']} is not schedulable with WCRT.")
return analysis_results
110 changes: 110 additions & 0 deletions Exercises/Response-Time Analysis/src/real_time_analysis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <cmath>

using namespace std;

struct Task {
string id;
int BCET;
int WCET;
int period;
int deadline;
int priority; // Lower number => higher priority for RMS, if you wish
};


void readTasksCSV(const string& filename, vector<Task>& tasks)
{
ifstream file(filename);
if (!file.is_open()) {
cerr << "Error: Could not open file " << filename << endl;
return;
}

string line;
getline(file, line); // Skip header

while (getline(file, line))
{
stringstream ss(line);
Task task;
string token;

getline(ss, token, ','); // Task ID
task.id = token;
getline(ss, token, ','); // WCET
task.WCET = stoi(token);
getline(ss, token, ','); // BCET
task.BCET = stoi(token);
getline(ss, token, ','); // Period
task.period = stoi(token);
getline(ss, token, ','); // Deadline
task.deadline = stoi(token);
getline(ss, token, ','); // Priority
task.priority = stoi(token);

tasks.push_back(task);
}
file.close();
}

void RTA_test(vector<Task>& tasks)
{
// Sort tasks by priority (lower number means higher priority)
sort(tasks.begin(), tasks.end(), [](const Task& a, const Task& b) {
return a.priority < b.priority; // Ensure lower priority number = higher priority
});

for (size_t task = 0; task < tasks.size(); task++)
{
int R = tasks[task].WCET;
int last_R = -1;
bool schedulable = true;
int I = 0; // Reset interference for each iteration

while (R != last_R)
{
last_R = R;

// Compute interference from higher-priority tasks
for (size_t j = 0; j < task; j++)
{
I += ceil((double)R / tasks[j].period) * tasks[j].WCET;
}

R = I + tasks[task].WCET;

if (R > tasks[task].deadline)
{
cout << "Task " << tasks[task].id << " is not schedulable." << endl;
schedulable = false;
break;
}
}

if (schedulable)
{
cout << "Task " << tasks[task].id << " is schedulable with WCRT = " << R << endl;
}
}
}

int main(int argc, char* argv[])
{
if (argc != 2) {
cerr << "Usage: " << argv[0] << " <tasks.csv>" << endl;
return 1;
}

string filename = argv[1];
vector<Task> tasks;
readTasksCSV(filename, tasks);

RTA_test(tasks);

return 0;
}
16 changes: 16 additions & 0 deletions Exercises/Very Simple Simulator/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
25 changes: 25 additions & 0 deletions Exercises/Very Simple Simulator/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug C++",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/very_simple_simulator",
"args": ["${workspaceFolder}/exercise-TC2.csv"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build"
}
]
}
5 changes: 5 additions & 0 deletions Exercises/Very Simple Simulator/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"iostream": "cpp"
}
}
43 changes: 43 additions & 0 deletions Exercises/Very Simple Simulator/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${workspaceFolder}/src/very_simple_simulator.cpp",
"-o",
"${workspaceFolder}/build/very_simple_simulator"
],
"group": "build",
"problemMatcher": [
"$gcc"
]
},
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
Binary file not shown.
14 changes: 14 additions & 0 deletions Exercises/Very Simple Simulator/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
- Period: Task period
- Deadline: Task deadline (equal to the period)
- Priority: Task priority (assigned by Rate Monotonic scheduling, with lower period yielding higher priority)

These examples illustrate one possible format. Students may use a different format and create additional test cases.
Binary file not shown.
8 changes: 8 additions & 0 deletions Exercises/Very Simple Simulator/exercise-TC1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Task,BCET,WCET,Period,Deadline,Priority
T1,0,1,6,6,1
T2,3,4,60,60,7
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
12 changes: 12 additions & 0 deletions Exercises/Very Simple Simulator/exercise-TC2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Task,BCET,WCET,Period,Deadline,Priority
T1,0,1,15,15,1
T2,1,2,20,20,2
T3,2,3,25,25,3
T4,2,4,30,30,4
T5,3,5,50,50,5
T6,3,5,60,60,6
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
10 changes: 10 additions & 0 deletions Exercises/Very Simple Simulator/exercise-TC3.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Task,BCET,WCET,Period,Deadline,Priority
T1,1,3,40,40,1
T2,2,7,80,80,2
T3,1,13,100,100,3
T4,3,18,160,160,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
Loading
Loading