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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425 | ------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Cheddar is a GNU GPL real-time scheduling analysis tool.
-- This program provides services to automatically check schedulability and
-- other performance criteria of real-time architecture models.
--
-- Copyright (C) 2002-2023, Frank Singhoff, Alain Plantec, Jerome Legrand,
-- Hai Nam Tran, Stephane Rubini
--
-- The Cheddar project was started in 2002 by
-- Frank Singhoff, Lab-STICC UMR 6285, Université de Bretagne Occidentale
--
-- Cheddar has been published in the "Agence de Protection des Programmes/France" in 2008.
-- Since 2008, Ellidiss technologies also contributes to the development of
-- Cheddar and provides industrial support.
--
-- The full list of contributors and sponsors can be found in README.md
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--
--
-- Contact : cheddar@listes.univ-brest.fr
--
------------------------------------------------------------------------------
-- Last update :
-- $Rev: 4589 $
-- $Date: 2023-09-29 16:02:19 +0200 (ven., 29 sept. 2023) $
-- $Author: singhoff $
------------------------------------------------------------------------------
------------------------------------------------------------------------------
with xml_tag; use xml_tag;
with Parameters; use Parameters;
with Parameters.extended;
use Parameters.Framework_Parameters_Table_Package;
with Tasks; use Tasks;
with task_set; use task_set;
with Offsets; use Offsets;
with Offsets; use Offsets.Offsets_Table_Package;
with Offsets.extended; use Offsets.extended;
with tables;
with sets;
with Framework_Config; use Framework_Config;
with Ada.IO_Exceptions; use Ada.IO_Exceptions;
with GNAT.Current_Exception; use GNAT.Current_Exception;
with Text_IO; use Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with unbounded_strings; use unbounded_strings;
use unbounded_strings.strings_table_package;
use unbounded_strings.unbounded_string_list_package;
with Parameters; use Parameters;
with Parameters.extended; use Parameters.extended;
use Parameters.Framework_Parameters_Table_Package;
with systems; use systems;
with framework; use framework;
with call_framework; use call_framework;
with Call_Framework_Interface; use Call_Framework_Interface;
use Call_Framework_Interface.Framework_Response_Package;
use Call_Framework_Interface.Framework_Request_Package;
with call_scheduling_framework; use call_scheduling_framework;
with multiprocessor_services; use multiprocessor_services;
with Multiprocessor_Services_Interface; use Multiprocessor_Services_Interface;
with Multiprocessor_Services_Interface;
use Multiprocessor_Services_Interface.Scheduling_Result_Per_Processor_Package;
with GNAT.Command_Line;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with version; use version;
with Ada.Exceptions; use Ada.Exceptions;
with time_unit_events; use time_unit_events;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with Ada.Directories; use Ada.Directories;
with scheduler; use scheduler;
with Ada.Directories; use Ada.Directories;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Command_Line; use Ada.Command_Line;
with Ada.Strings; use Ada.Strings;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with feasibility_test.feasibility_interval;
use feasibility_test.feasibility_interval;
with resource_set; use resource_set;
procedure Call_Cheddar is
task_exist : Integer;
start, finish : Integer;
sub_str : Unbounded_String;
command : Unbounded_String;
-- A set of variables required to call the framework
--
Response_List : framework_response_table;
Request_List : framework_request_table;
A_Param : parameter_ptr;
A_Request : framework_request;
dir : unbounded_string_list;
str1, str2 : Unbounded_String;
Simulation_basics_text : Unbounded_String;
Simulation_blocking_time_text : Unbounded_String;
Nb_tasks : Integer;
Sum_Laxities : Integer;
Sum_blocking : Integer;
Nb_preemptions : Integer;
Nb_context_switches : Integer;
response_time : Integer;
blocking_time : Integer;
Deadline_i : Integer;
task_set_file_name : Unbounded_String;
Data, line, sched_period : Unbounded_String;
dir1 : unbounded_string_list;
Sys : system;
F, F2 : Ada.Text_IO.File_Type;
Min_lax : Integer;
Max_blocking : Integer;
laxity_i : Integer;
Data2 : Unbounded_String;
Fitness_5 : Float;
sum_response_time : Integer;
max_response_time : Integer;
begin
call_framework.initialize (False);
sched_period := To_Unbounded_String (Argument (1));
task_set_file_name := To_Unbounded_String (Argument (2));
initialize (Sys);
read_from_xml_file (Sys, dir1, task_set_file_name);
initialize (Response_List);
initialize (Request_List);
Initialize (A_Request);
A_Request.statement := scheduling_simulation_time_line;
A_Param := new parameter (integer_parameter);
A_Param.parameter_name := To_Unbounded_String ("period");
A_Param.integer_value := Integer'value (To_String (sched_period));
add (A_Request.param, A_Param);
A_Param := new parameter (boolean_parameter);
A_Param.parameter_name := To_Unbounded_String ("schedule_with_offsets");
A_Param.boolean_value := True;
add (A_Request.param, A_Param);
A_Param := new parameter (boolean_parameter);
A_Param.parameter_name :=
To_Unbounded_String ("schedule_with_precedencies");
A_Param.boolean_value := True;
add (A_Request.param, A_Param);
A_Param := new parameter (boolean_parameter);
A_Param.parameter_name := To_Unbounded_String ("schedule_with_resources");
A_Param.boolean_value := True;
add (A_Request.param, A_Param);
A_Param := new parameter (integer_parameter);
A_Param.parameter_name := To_Unbounded_String ("seed_value");
A_Param.integer_value := 0;
add (A_Request.param, A_Param);
add (Request_List, A_Request);
sequential_framework_request (Sys, Request_List, Response_List);
initialize (Request_List);
initialize (Response_List);
Initialize (A_Request);
A_Request.statement := scheduling_simulation_basics;
add (Request_List, A_Request);
sequential_framework_request (Sys, Request_List, Response_List);
sequential_framework_request (Sys, Request_List, Response_List);
-- Compute the blocking-time of tasks
-- from simulation
initialize (Request_List);
initialize (A_Request.param);
initialize (Response_List);
Initialize (A_Request);
A_Param := new parameter (boolean_parameter);
A_Param.parameter_name := To_Unbounded_String ("worst_case");
A_Param.boolean_value := True;
add (A_Request.param, A_Param);
A_Param := new parameter (boolean_parameter);
A_Param.parameter_name := To_Unbounded_String ("best_case");
A_Param.boolean_value := False;
add (A_Request.param, A_Param);
A_Param := new parameter (boolean_parameter);
A_Param.parameter_name := To_Unbounded_String ("average_case");
A_Param.boolean_value := False;
add (A_Request.param, A_Param);
A_Request.statement := scheduling_simulation_blocking_time;
add (Request_List, A_Request);
sequential_framework_request (Sys, Request_List, Response_List);
Simulation_basics_text := Response_List.entries (1).text;
Simulation_blocking_time_text := Response_List.entries (0).text;
-- Extracting the decision about the schedulability
-- From the simulation
str1 := Simulation_basics_text;
Put_Line
("=================SCHEDULING SIMULATION TEXT========================");
Put (str1);
Put_Line ("=============================================");
Append (Data2, To_String (Simulation_basics_text));
task_exist := Index (str1, "/worst");
while task_exist /= 0 loop
Put_Line ("task_exist" & task_exist'img);
str1 :=
Unbounded_Slice
(str1,
Index (str1, "/worst") + Length (To_Unbounded_String ("/worst")),
Length (str1));
task_exist := Index (str1, "/worst");
end loop;
sub_str := Unbounded_Slice (str1, Index (str1, "-"), 8);
Append (Data2, To_String (sub_str) & ASCII.LF);
if sub_str = To_Unbounded_String ("- No d") then
-- In this case, the task set is schedulable
-- Then we exctract from the results of the simulation,
-- values of fitness functions of the candidate solution
-- i.e : context switches, number of preemptions, laxity of tasks
-- and blocking-time of tasks
start :=
Index (Simulation_basics_text, "- Number of context switches : ") +
Length (To_Unbounded_String ("- Number of context switches : "));
finish :=
start +
Index
(Unbounded_Slice
(Simulation_basics_text,
start,
Length (Simulation_basics_text)),
ASCII.LF & "") -
2;
Nb_context_switches :=
Integer'value
(To_String
(Unbounded_Slice (Simulation_basics_text, start, finish)));
start :=
Index (Simulation_basics_text, "- Number of preemptions : ") +
Length (To_Unbounded_String ("- Number of preemptions : "));
finish :=
start +
Index
(Unbounded_Slice
(Simulation_basics_text,
start,
Length (Simulation_basics_text)),
ASCII.LF & "") -
2;
Nb_preemptions :=
Integer'value
(To_String
(Unbounded_Slice (Simulation_basics_text, start, finish)));
Nb_tasks :=
Integer
(get_number_of_task_from_processor
(Sys.tasks,
To_Unbounded_String ("processor1")));
Sum_Laxities := 0;
Sum_blocking := 0;
Fitness_5 := 0.0;
sum_response_time := 0;
str1 := Simulation_basics_text;
str2 := Simulation_blocking_time_text;
for i in 1 .. Nb_tasks loop
start := Index (str1, "=> ") + Length (To_Unbounded_String ("=> "));
finish := Index (str1, "/worst") - 1;
response_time :=
Integer'value (To_String (Unbounded_Slice (str1, start, finish)));
start := Index (str2, "=> ") + Length (To_Unbounded_String ("=> "));
finish := Index (str2, "/worst") - 1;
blocking_time :=
Integer'value (To_String (Unbounded_Slice (str2, start, finish)));
Deadline_i :=
get
(my_tasks => Sys.tasks,
task_name =>
suppress_space (To_Unbounded_String ("Task" & i'img)),
param_name => deadline);
laxity_i := Deadline_i - response_time;
if i = 1 then
Min_lax := laxity_i;
Max_blocking := blocking_time;
max_response_time := response_time;
else
if laxity_i < Min_lax then
Min_lax := laxity_i;
end if;
if blocking_time > Max_blocking then
Max_blocking := blocking_time;
end if;
if response_time > max_response_time then
max_response_time := response_time;
end if;
end if;
Sum_Laxities := Sum_Laxities + (Deadline_i - response_time);
Sum_blocking := Sum_blocking + blocking_time;
Fitness_5 := Fitness_5 + Float (response_time) / Float (Deadline_i);
sum_response_time := sum_response_time + response_time;
str1 :=
Unbounded_Slice
(str1,
Index (str1, "/worst") + Length (To_Unbounded_String ("/worst")),
Length (str1));
str2 :=
Unbounded_Slice
(str2,
Index (str2, "/worst") + Length (To_Unbounded_String ("/worst")),
Length (str2));
end loop;
Append (Data, "schedulability : true" & ASCII.LF);
Append (Data, "f1 = preemptions = " & Nb_preemptions'img & ASCII.LF);
Append
(Data,
"f2 = contextSwitches = " & Nb_context_switches'img & ASCII.LF);
Append (Data, "f3 = tasks = " & Nb_tasks'img & ASCII.LF);
Append
(Data,
"f4 = sum(Li) = sum(Di-Ri) = " & Sum_Laxities'img & ASCII.LF);
Append (Data, "f5 = sum(Ri/Di) = " & Fitness_5'img & ASCII.LF);
Append (Data, "f6 = min(Li) = " & Min_lax'img & ASCII.LF);
Append (Data, "f7 = sum(Ri) = " & sum_response_time'img & ASCII.LF);
Append (Data, "f8 = max(Ri) = " & max_response_time'img & ASCII.LF);
Append (Data, "f9 = sum(Bi) = " & Sum_blocking'img & ASCII.LF);
Append (Data, "f10 = max(Bi) = " & Max_blocking'img & ASCII.LF);
Append
(Data,
"f11 = sharedResources = " &
get_number_of_resource_from_processor
(Sys.resources,
To_Unbounded_String ("processor1"))'
img &
ASCII.LF);
else
Append (Data, "schedulability : false" & ASCII.LF);
end if;
-- Laurent //
start :=
Index (task_set_file_name, "candidate_solution") +
Length (To_Unbounded_String ("candidate_solution"));
finish := Index (task_set_file_name, ".xmlv3") - 1;
sub_str :=
Unbounded_Slice (task_set_file_name, start, finish); -- the eidx string
-- This file contains, the result of the schedulability
-- of the candidate solution as well as values of
-- potential fitness functions
command := "Output" & sub_str & ".txt";
Create (F, Ada.Text_IO.Out_File, To_String (command));
Unbounded_IO.Put_Line (F, Data);
Close (F);
---- This file contains the result of scheduling
---- simulation of the candidate solution
--command := To_Unbounded_String("Output2" & To_String(sub_str) & ".txt");
--Create(F2,Ada.Text_IO.Out_File,To_String(command));
--Unbounded_IO.Put_Line(F2, Data2);
--Close(F2);
-- Deleting the file "candidate_solution eidx.xmlv3"
--
Open
(File => F2,
Mode => Ada.Text_IO.In_File,
Name => To_String (task_set_file_name));
Ada.Text_IO.Delete (File => F2);
end Call_Cheddar;
|