Skip to content

Commit fb0713b

Browse files
committed
Added Makefile and made it more modularised
1 parent fb2e6a7 commit fb0713b

File tree

7 files changed

+194
-150
lines changed

7 files changed

+194
-150
lines changed

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CC=gcc
2+
3+
flags=-c -Wall
4+
5+
executableName=test
6+
7+
driver=test
8+
9+
all: Main
10+
11+
Main: $(driver).o printInfo.o frameConditions.o createTaskInstances.o calculateSchedule.o
12+
$(CC) $(driver).o printInfo.o frameConditions.o createTaskInstances.o calculateSchedule.o -o $(executableName)
13+
14+
$(driver).o: $(driver).c
15+
$(CC) $(flags) $(driver).c
16+
17+
printInfo.o: printInfo.c
18+
$(CC) $(flags) printInfo.c
19+
20+
frameConditions.o: frameConditions.c
21+
$(CC) $(flags) frameConditions.c
22+
23+
createTaskInstances.o: createTaskInstances.c
24+
$(CC) $(flags) createTaskInstances.c
25+
26+
calculateSchedule.o: calculateSchedule.c
27+
$(CC) $(flags) calculateSchedule.c
28+
29+
clean:
30+
rm -f *.o $(executableName)

README.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
# RTS-Assignment-2
22
Given a set of periodic, aperiodic and sporadic jobs in an RTS, finding a feasible schedule for the task set with valid frame sizes
3+
4+
5+
# Tasks to be done
6+
- [X] Find CPU utilisation and hyperperiod.
7+
- [X] Create a Makefile.
8+
- [ ] Pointer to pointers for every frame to point to its set of jobs.
9+
- [ ] Algorithm of selecting the jobs in a frame.
10+
- [ ] While selecting a job that has been split, making sure that the there is an order that is followed.
11+
- [ ] Find a way to slice multiple jobs more efficiently.
12+
- [ ] Convert all data types into float.
13+
- [ ] Adding the aperiodic and sporadic jobs part.
14+
- [ ] Making the actual execution time as 20%-100% of wcet using pseudo random numbers.
15+
16+
# Known bugs
17+
- [ ] Malloc and realloc throw errors in calculateSchedule.c

calculateSchedule.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#include <stdio.h>
2+
#include <stdbool.h>
3+
#include <stdlib.h>
4+
#include "struct.h"
5+
6+
/*
7+
* Attempts to create a schedule using EDF algorithm.
8+
*
9+
*/
10+
void
11+
calculateSchedule(TaskInstance *jobs, int numJobs, int frameSize, int hyperperiod, Frame *frames)
12+
{
13+
int numOfFrames = hyperperiod / frameSize;
14+
15+
int aliveCount = numJobs;
16+
printf("initial aliveCount=%d\n", aliveCount);
17+
printf("hyperperiod=%d, frameSize=%d, numOfFrames=%d\n", hyperperiod, frameSize, numOfFrames);
18+
for (int f = 0; f < numOfFrames; ++f)
19+
{
20+
printf("Frame No=%d\nJobs=", f);
21+
frames[f].numFrame = f;
22+
frames[f].numJobs = 0;
23+
// frames[f].jobs = (TaskInstance **) malloc(sizeof(TaskInstance *) * aliveCount);
24+
25+
bool flag = true;
26+
int minIndex;
27+
int timeLeft = frameSize;
28+
while(flag)
29+
{
30+
flag = false;
31+
minIndex = 0;
32+
33+
for (int i = 0; i < numJobs; ++i) // For finding the first valid entry in the array.
34+
{
35+
if (!(jobs[i].alive && jobs[i].maxFrame > f && jobs[i].startFrame <= f && jobs[i].wcet <= timeLeft))
36+
minIndex++;
37+
else
38+
{
39+
flag = true;
40+
break;
41+
}
42+
}
43+
44+
// printf("minIndex=%d\n", minIndex);
45+
for (int i = minIndex+1; i < numJobs; ++i)
46+
{
47+
if (jobs[i].alive && jobs[i].startFrame <= f && jobs[i].maxFrame > f && jobs[i].maxFrame < jobs[minIndex].maxFrame && jobs[i].wcet <= timeLeft)
48+
{
49+
minIndex = i;
50+
}
51+
// else if(jobs[i].alive && jobs[i].startFrame <= f && jobs[i].maxFrame == jobs[minIndex].maxFrame && jobs[i].wcet <= timeLeft)
52+
// if (jobs[i].wcet > jobs[minIndex].wcet)
53+
// {
54+
// minIndex = i;
55+
// flag = true;
56+
// }
57+
}
58+
59+
if (!flag)
60+
break;
61+
// printf("minIndex=%d\n", minIndex);
62+
printf("J%d,%d; ", jobs[minIndex].taskNum, jobs[minIndex].instanceNum);
63+
// frames[f].jobs[numJobs] = &jobs[minIndex];
64+
frames[f].numJobs++;
65+
jobs[minIndex].alive = false;
66+
aliveCount--;
67+
timeLeft -= jobs[minIndex].wcet;
68+
}
69+
70+
printf("frames[f].numJobs=%d\n", frames[f].numJobs);
71+
fflush(stdout);
72+
// frames[f].jobs = (TaskInstance **) realloc(frames[f].jobs, sizeof(TaskInstance *) * frames[f].numJobs);
73+
// printf("numJobs in Frame-%d is: %d", f, frames[f].numJobs);
74+
printf("\n");
75+
}
76+
77+
printf("final aliveCount=%d\n", aliveCount);
78+
if (aliveCount > 0)
79+
{
80+
printf("Could not schedule this set.\n");
81+
}
82+
else
83+
{
84+
printf("Schedule has been made!!\n");
85+
}
86+
87+
// Resetting the jobs so that they can be scheduled again.
88+
for (int i = 0; i < numJobs; i++)
89+
jobs[i].alive = true;
90+
91+
return;
92+
}

createTaskInstances.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <stdbool.h>
2+
#include "struct.h"
3+
4+
/*
5+
* Fills in the details of the array of various instances of the tasks based on the task details.
6+
* Also, takes care of the tasks that have been split.
7+
*/
8+
void
9+
createTaskInstances(Task *tasks, TaskInstance *jobs, int frameSize, int hyperperiod, int numTasks, int numJobs)
10+
{
11+
int jobIndex = 0;
12+
for (int i = 0; i < numTasks; ++i) // Iterates of tasks
13+
{
14+
for (int j = 0; j < hyperperiod; j += tasks[i].period) // Iterattes over the period of a task.
15+
{
16+
int startFrame = j / frameSize;
17+
int maxFrame = (j + tasks[i].deadline) / frameSize;
18+
if (j % frameSize != 0)
19+
startFrame++;
20+
21+
if (tasks[i].numOfSplits != 0) // If the task has been split.
22+
{
23+
for (int k = 0; k < tasks[i].numOfSplits + 1; k++) // Iterates over the various splits of a task.
24+
{
25+
jobs[jobIndex].startFrame = startFrame;
26+
jobs[jobIndex].maxFrame = maxFrame;
27+
jobs[jobIndex].wcet = tasks[i].splits[k];
28+
jobs[jobIndex].splitNum = k;
29+
jobs[jobIndex].taskNum = i;
30+
jobs[jobIndex].instanceNum = j / tasks[i].period;
31+
jobs[jobIndex].alive = true;
32+
33+
jobIndex++;
34+
}
35+
}
36+
else // If the task has not been split.
37+
{
38+
jobs[jobIndex].startFrame = startFrame;
39+
jobs[jobIndex].maxFrame = maxFrame;
40+
jobs[jobIndex].taskNum = i;
41+
jobs[jobIndex].splitNum = -1;
42+
jobs[jobIndex].wcet = tasks[i].wcet;
43+
jobs[jobIndex].instanceNum = j / tasks[i].period;
44+
jobs[jobIndex].alive = true;
45+
jobIndex++;
46+
}
47+
}
48+
}
49+
50+
return;
51+
}

firstCheck.c

Whitespace-only changes.

periodicJobs.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
4
2-
4 1 4
3-
5 1 5
4-
10 1 10
5-
20 3 20
1+
3
2+
15 1 15
3+
22 3 44
4+
20 2 20

test.c

Lines changed: 2 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ main(int argc, char const *argv[])
4242
int numLines;
4343
fscanf(periodicJobFile, " %d", &numLines);
4444
printf("No. of lines = %d.\n", numLines);
45-
int *periods, *deadlines, *wcet;
4645

4746
Task *tasks = (Task *) malloc(sizeof(Task) * numLines);
4847
int i;
@@ -54,9 +53,11 @@ main(int argc, char const *argv[])
5453
if (tasks[i].wcet > tasks[i].deadline)
5554
{
5655
fprintf(stderr, "WCET is greater than deadline. Please input valid data.\n" );
56+
fclose(periodicJobFile);
5757
goto free;
5858
}
5959
}
60+
fclose(periodicJobFile);
6061

6162
float cpuUtilisation = calculateCpuUtilisation(tasks, numLines);
6263
if (cpuUtilisation < 1.0f)
@@ -197,8 +198,6 @@ main(int argc, char const *argv[])
197198
// printFrameInfo(frames, hyperperiod / frameSize);
198199

199200

200-
201-
202201
free(condition2Sizes);
203202
free(condition3Sizes);
204203
free:
@@ -208,149 +207,7 @@ main(int argc, char const *argv[])
208207
free(tasks[i].splits);
209208
}
210209
free(tasks);
211-
fclose(periodicJobFile);
212210

213211
end:
214212
return 0;
215-
}
216-
217-
218-
219-
220-
/*
221-
* Fills in the details of the array of various instances of the tasks based on the task details.
222-
* Also, takes care of the tasks that have been split.
223-
*/
224-
void
225-
createTaskInstances(Task *tasks, TaskInstance *jobs, int frameSize, int hyperperiod, int numTasks, int numJobs)
226-
{
227-
int jobIndex = 0;
228-
for (int i = 0; i < numTasks; ++i) // Iterates of tasks
229-
{
230-
for (int j = 0; j < hyperperiod; j += tasks[i].period) // Iterattes over the period of a task.
231-
{
232-
int startFrame = j / frameSize;
233-
int maxFrame = (j + tasks[i].deadline) / frameSize;
234-
if (j % frameSize != 0)
235-
startFrame++;
236-
237-
if (tasks[i].numOfSplits != 0) // If the task has been split.
238-
{
239-
for (int k = 0; k < tasks[i].numOfSplits + 1; k++) // Iterates over the various splits of a task.
240-
{
241-
jobs[jobIndex].startFrame = startFrame;
242-
jobs[jobIndex].maxFrame = maxFrame;
243-
jobs[jobIndex].wcet = tasks[i].splits[k];
244-
jobs[jobIndex].splitNum = k;
245-
jobs[jobIndex].taskNum = i;
246-
jobs[jobIndex].instanceNum = j / tasks[i].period;
247-
jobs[jobIndex].alive = true;
248-
249-
jobIndex++;
250-
}
251-
}
252-
else // If the task has not been split.
253-
{
254-
jobs[jobIndex].startFrame = startFrame;
255-
jobs[jobIndex].maxFrame = maxFrame;
256-
jobs[jobIndex].taskNum = i;
257-
jobs[jobIndex].splitNum = -1;
258-
jobs[jobIndex].wcet = tasks[i].wcet;
259-
jobs[jobIndex].instanceNum = j / tasks[i].period;
260-
jobs[jobIndex].alive = true;
261-
jobIndex++;
262-
}
263-
}
264-
}
265-
266-
return;
267-
}
268-
269-
270-
271-
/*
272-
* Attempts to create a schedule using EDF algorithm.
273-
*
274-
*/
275-
void
276-
calculateSchedule(TaskInstance *jobs, int numJobs, int frameSize, int hyperperiod, Frame *frames)
277-
{
278-
int numOfFrames = hyperperiod / frameSize;
279-
280-
int aliveCount = numJobs;
281-
printf("initial aliveCount=%d\n", aliveCount);
282-
printf("hyperperiod=%d, frameSize=%d, numOfFrames=%d\n", hyperperiod, frameSize, numOfFrames);
283-
for (int f = 0; f < numOfFrames; ++f)
284-
{
285-
printf("Frame No=%d\nJobs=", f);
286-
frames[f].numFrame = f;
287-
frames[f].numJobs = 0;
288-
frames[f].jobs = (TaskInstance **) malloc(sizeof(TaskInstance *) * aliveCount);
289-
290-
bool flag = true;
291-
int minIndex;
292-
int timeLeft = frameSize;
293-
while(flag)
294-
{
295-
flag = false;
296-
minIndex = 0;
297-
298-
for (int i = 0; i < numJobs; ++i) // For finding the first valid entry in the array.
299-
{
300-
if (!(jobs[i].alive && jobs[i].maxFrame > f && jobs[i].startFrame <= f && jobs[i].wcet <= timeLeft))
301-
minIndex++;
302-
else
303-
{
304-
flag = true;
305-
break;
306-
}
307-
}
308-
// printf("minIndex=%d\n", minIndex);
309-
for (int i = minIndex+1; i < numJobs; ++i)
310-
{
311-
if (jobs[i].alive && jobs[i].startFrame <= f && jobs[i].maxFrame > f && jobs[i].maxFrame < jobs[minIndex].maxFrame && jobs[i].wcet <= timeLeft)
312-
{
313-
minIndex = i;
314-
}
315-
// else if(jobs[i].alive && jobs[i].startFrame <= f && jobs[i].maxFrame == jobs[minIndex].maxFrame && jobs[i].wcet <= timeLeft)
316-
// if (jobs[i].wcet > jobs[minIndex].wcet)
317-
// {
318-
// minIndex = i;
319-
// flag = true;
320-
// }
321-
}
322-
323-
if (!flag)
324-
break;
325-
// printf("minIndex=%d\n", minIndex);
326-
printf("J%d,%d; ", jobs[minIndex].taskNum, jobs[minIndex].instanceNum);
327-
frames[f].jobs[numJobs] = &jobs[minIndex];
328-
frames[f].numJobs++;
329-
jobs[minIndex].alive = false;
330-
aliveCount--;
331-
timeLeft -= jobs[minIndex].wcet;
332-
}
333-
334-
printf("frames[f].numJobs=%d\n", frames[f].numJobs);
335-
fflush(stdout);
336-
frames[f].jobs = (TaskInstance **) realloc(frames[f].jobs, sizeof(TaskInstance *) * frames[f].numJobs);
337-
// printf("numJobs in Frame-%d is: %d", f, frames[f].numJobs);
338-
printf("\n\n");
339-
}
340-
341-
printf("final aliveCount=%d\n", aliveCount);
342-
if (aliveCount > 0)
343-
{
344-
printf("Could not schedule this set.\n");
345-
}
346-
else
347-
{
348-
printf("Schedule has been made!!\n");
349-
}
350-
351-
// Resetting the jobs so that they can be scheduled again.
352-
for (int i = 0; i < numJobs; i++)
353-
jobs[i].alive = true;
354-
355-
return;
356213
}

0 commit comments

Comments
 (0)