@@ -42,7 +42,6 @@ main(int argc, char const *argv[])
4242int numLines ;
4343fscanf (periodicJobFile , " %d" , & numLines );
4444printf ("No. of lines = %d.\n" , numLines );
45- int * periods , * deadlines , * wcet ;
4645
4746Task * tasks = (Task * ) malloc (sizeof (Task ) * numLines );
4847int i ;
@@ -54,9 +53,11 @@ main(int argc, char const *argv[])
5453if (tasks [i ].wcet > tasks [i ].deadline )
5554{
5655fprintf (stderr , "WCET is greater than deadline. Please input valid data.\n" );
56+ fclose (periodicJobFile );
5757goto free ;
5858}
5959}
60+ fclose (periodicJobFile );
6061
6162float cpuUtilisation = calculateCpuUtilisation (tasks , numLines );
6263if (cpuUtilisation < 1.0f )
@@ -197,8 +198,6 @@ main(int argc, char const *argv[])
197198// printFrameInfo(frames, hyperperiod / frameSize);
198199
199200
200-
201-
202201free (condition2Sizes );
203202free (condition3Sizes );
204203free :
@@ -208,149 +207,7 @@ main(int argc, char const *argv[])
208207free (tasks [i ].splits );
209208}
210209free (tasks );
211- fclose (periodicJobFile );
212210
213211end :
214212return 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