-
Notifications
You must be signed in to change notification settings - Fork 0
/
SchedulingAlgorithms.cc
executable file
·97 lines (81 loc) · 2.21 KB
/
SchedulingAlgorithms.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* SchedulingAlgorithms.cc
*
* Driver for the scheduling algorithms test fixture project.
*
* This driver expects two command line arguments:
* 1. A test file containing the set of tasks on each line
* formatted as:
* <task name> <compute time> <period> <deadline>
* e.g. T2 3 5 5
* 2. The scheduling algorithm ID as a number:
* Rate-Monotonic: 1
* Shortest Completion Time: 2
* Earliest Deadline First: 3
*
* Usage:
* ./SchedulingAlgorithms <path/to/test/file> <algorithm ID>
*
* Created on: Mar 13, 2013
* Author: dam7633
*/
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <unistd.h>
using namespace std;
#include "SchedulingAlgorithms.h"
#include "RMAScheduler.h"
#include "EDFScheduler.h"
#include "SCTScheduler.h"
int main(int argc, char *argv[]) {
//for the scheduler
Scheduler* sc;
int choice = -1;
// Storage for parsing the task set file.
string name;
int computeTime, deadline, period;
if (argc == 3) {
std::ifstream file;
file.open(argv[1], ios::in);
//select the scheduling algorithm...
choice = atoi(argv[2]);
switch (choice) {
case 3:
cout << "EDF Scheduler." << endl;
sc = new EDFScheduler();
break;
case 2:
cout << "SCT Scheduler." << endl;
sc = new SCTScheduler();
break;
case 1:
default:
cout << "RMA Scheduler." << endl;
sc = new RMAScheduler();
break;
}
// Create tasks from the file until it it has been fully read.
while (!(file.eof() || file.fail())) {
// Grab the task as a string in the following order
file >> name >> computeTime >> deadline >> period;
if (!(file.eof() || file.fail())) {
cout << "Making task: " << name << " " << computeTime << " "
<< period << " " << deadline << endl;
sc->createTask(name, computeTime, period, deadline);
}
}
cout << "Starting..." << endl;
// Start the simulation
sc->start();
// This will stick because the thread never gets stop()'d
sc->join();
// Cleanup
delete sc;
cout << "Exiting..." << endl;
} else {
cerr << "Usage: " << argv[0] << " Filename SchedulerInt" << endl;
}
return EXIT_SUCCESS;
}