// Model parameters:
const bool preemptive = true; // 'true' means preemptive scheduling;
// 'false' means non-preemptive scheduling
const bool edf = true; // 'true' means dynamic priorities (edf)
// 'false' means static priorities (by task id)
const int N = // No. of tasks
17; // aviation
// 6; // ins
// 6; // flight control
// 8; // cnc
const int Deadline[N] = { // Dealines; largest value must be <= maxDL
250,250,400,500,500,590,800,800,1000,2000,2000,2000,2000,2000,2000,10000,10000
// 250,4000,62500,100000,100000,125000
// 80,125,230,350,410,525
// 2400,2400,2400,2400,4800,4800,7800,9600
};
const int maxDL = // Max deadline
10000;
// 125000;
// 5250;
// 9600;
const int Period = // Least value divisible by all deadlines
1080000;
// 500000;
// 39606000;
// 124800;
const int Comp[N] = { // Computation times
20,50,10,30,50,80,90,20,50,30,10,30,10,10,30,10,10
// 118,428,1028,2028,10028,2500
// 10,11,25,40,60,50
// 35,40,165,165,180,720,570,570
};
const int maxFreq = 100; // Max. frequency
const int Power[maxFreq+1] = { // Power consumption (function of frequency)
0,
0,0,0,0,0,0,0,3,3,4,
5,5,6,7,7,8,9,10,11,12,
13,14,15,16,17,19,20,22,23,25,
27,29,31,33,35,37,40,42,45,48,
51,54,57,60,64,68,72,76,80,85,
90,95,101,106,112,118,125,132,139,147,
155,163,172,181,191,201,212,223,235,248,
261,274,289,304,320,336,354,372,391,411,
432,454,477,501,527,553,581,610,641,673,
706,742,778,817,857,899,944,990,1038,1089
};
const int AvPower = 97; // Target average power consumption
// Model internals:
int[0,2*AvPower*Period] Cost; // Global cost
clock Time; // Global time
chan ready, run, done, stop; // Chan's between tasks and Scheduler
urgent chan set_freq; // Chan between tasks and ChooseFreq
int[0,N-1] task;
int[0,maxFreq] freq;
int[0,maxDL] elapsed;
bool error = false;
Taskconst int idclock x, t;
int target, comp;IdleReadyRunningErrorChooseFreqResetSchedulerint[0,N-1] active; // Current active task
// Remaining times till deadlines
int[0,2*maxDL] Remaining[N];
int[0,maxDL] rem(int e) {
return Remaining[e];
}
void reset_rem(int e) {
Remaining[e] += Deadline[e];
}
void update_rem() {
int i;
for (i=0; i<N; i++) {
Remaining[i] -= elapsed;
}
}
// Ready queue
int[0,N-1] list[N] = { // List of tasks ready to run
0,1,2,3,4,5,6,7
};
int[0,N] len = 0;
void add(int e){
int i=len;
len++;
while (i>0 && (edf ? rem(list[i-1])>Deadline[e] : list[i-1]>e)) {
list[i]=list[i-1];
i--;
}
list[i]=e;
}
int[0,N-1] first() {
// Precondition: queue non-empty
return list[0];
}
void remove(int e) {
// Precondition: queue contains e
int i=0;
len--;
while (list[i]!=e) {
i++;
}
for (i; i<len; i++) {
list[i]=list[i+1];
}
list[len]=0; // Not strictly necessary, but reduces state space
}
bool empty(){
return(len==0);
}
// Cost counting
void update_cost() {
Cost += Power[freq]*elapsed;
}SelectFreeOccTask0=Task(0);
Task1=Task(1);
Task2=Task(2);
Task3=Task(3);
Task4=Task(4);
Task5=Task(5);
Task6=Task(6);
Task7=Task(7);
Task8=Task(8);
Task9=Task(9);
Task10=Task(10);
Task11=Task(11);
Task12=Task(12);
Task13=Task(13);
Task14=Task(14);
Task15=Task(15);
Task16=Task(16);
system
Task0, Task1, Task2, Task3, Task4, Task5,
Task6, Task7,
Task8, Task9, Task10, Task11, Task12, Task13, Task14, Task15, Task16,
Scheduler, ChooseFreq, Reset;