------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- 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 Ada.Exceptions; use Ada.Exceptions; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO; use Ada.Text_IO; with Ada.Command_Line; use Ada.Command_Line; with GNAT.Command_Line; with GNAT.OS_Lib; use GNAT.OS_Lib; with Ada.Real_Time; use Ada.Real_Time; 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 framework; use framework; with call_scheduling_framework; use call_scheduling_framework; with multiprocessor_services; use multiprocessor_services; with multiprocessor_services_interface; use multiprocessor_services_interface; use multiprocessor_services_interface.scheduling_result_per_processor_package; with Objects; use Objects; with Tasks; use Tasks; with Task_Set; use Task_Set; use task_set.generic_task_set; with Systems; use Systems; with Processors; use Processors; with Processor_Set; use Processor_Set; with Messages; use Messages; with Message_Set; use Message_Set; with Dependencies; use Dependencies; with networks; use networks; with Address_Spaces; use Address_Spaces; with Address_Space_Set; use Address_Space_Set; with Core_Units; use Core_Units; use Core_Units.Core_Units_Table_Package; with processor_set; use processor_set; use processor_set.generic_processor_set; with parameters; use parameters; with parameters.extended; use parameters.extended; use parameters.framework_parameters_table_package; with systems; use systems; with Processor_Interface; use Processor_Interface; with Scheduler_Interface; use Scheduler_Interface; with version; use version; with unbounded_strings; use unbounded_strings; use unbounded_strings.strings_table_package; use unbounded_strings.unbounded_string_list_package; with Random_Tools; use Random_Tools; with architecture_factory; use architecture_factory; with unbounded_strings; use unbounded_strings; with call_framework; use call_framework; with feasibility_test.feasibility_interval; use feasibility_test.feasibility_interval; with doubles; use doubles; with scheduling_analysis; use scheduling_analysis; with scheduling_analysis.extended; use scheduling_analysis.extended; with scheduling_analysis.extended.task_analysis; use scheduling_analysis.extended.task_analysis; use scheduling_analysis.extended.task_occurence_table_package; with time_unit_events; use time_unit_events; use time_unit_events.time_unit_lists_package; use time_unit_events.time_unit_package; with sets ; with natural_util ; use natural_util ; with discrete_util; procedure amanite is -- A set of variables required to call the framework -- response_list : framework_response_table; request_list : framework_request_table; a_request : framework_request; a_param : parameter_ptr; sys : System; project_file_dir_list : unbounded_string_list; project_file_list : unbounded_string_list; msg : Unbounded_String; Feasibility_Interval : Double; validate : Boolean; a_processor : Generic_Processor_Ptr; Output_EV_File_Name : Unbounded_String; F : File_Type; procedure compute_scheduling is begin a_processor := search_processor (sys.processors, to_unbounded_string (Argument(1))); Calculate_feasibility_interval (sys, a_processor, validate, Feasibility_Interval, msg); Put_Line ("Feasibility_Interval : " & Feasibility_Interval'Img); -- Compute the scheduling on the period given by the argument -- initialize (response_list); initialize (request_list); initialize (a_request); -- Simulation protocol selection 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 (feasibility_interval); 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 (boolean_parameter); a_param.parameter_name := To_Unbounded_String ("schedule_with_jitters"); a_param.boolean_value := False; add (a_request.param, a_param); a_param := new parameter (boolean_parameter); a_param.parameter_name := To_Unbounded_String ("minimize_preemption"); a_param.boolean_value := False; add (a_request.param, a_param); a_param := new parameter (boolean_parameter); a_param.parameter_name := To_Unbounded_String ("discard_missed_deadline"); a_param.boolean_value := False; 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); a_param := new parameter (boolean_parameter); a_param.parameter_name := To_Unbounded_String ("predictable"); a_param.boolean_value := True; add (a_request.param, a_param); add (request_list, a_request); sequential_framework_request (sys, request_list, response_list); initialize (a_request); initialize (a_request.param); initialize (response_list); initialize (request_list); 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 := True; 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 := True; add (a_request.param, a_param); a_request.target := a_processor.name; a_request.statement := scheduling_simulation_response_time; add (request_list, a_request); sequential_framework_request (sys, request_list, response_list); for j in 0 .. response_list.nb_entries - 1 loop Put_Line (To_String (response_list.entries (j).title)); Put_Line (To_String (response_list.entries (j).text)); end loop; Put_Line("Export event table"); Write_To_Xml_File (framework.Sched, Sys, Output_EV_File_Name); end compute_scheduling; my_iterator_t : tasks_iterator; my_iterator_p : processors_iterator; a_task : Generic_task_ptr; my_task : Generic_task_ptr ; --Display Task procedure display_task (a_task : in Generic_Task_Ptr) is begin reset_iterator (sys.tasks, my_iterator_t); loop current_element (sys.tasks, my_task, my_iterator_t); put_line("task name : " & to_string(my_task.name)); exit when is_last_element (sys.tasks, my_iterator_t); next_element (sys.tasks, my_iterator_t); end loop; end display_task ; time_com : Natural := 1 ; procedure compute_worst_execution_time (my_task : in Generic_Task_Ptr) is subtype task_occurence_range is task_occurence_table_package.table_range; current_date : integer; my_task_occurence_table : task_occurence_table_ptr; task_occurence_number : task_occurence_range ; worst_execution_time : Natural ; begin task_occurence_number := 0; worst_execution_time := 0 ; my_task_occurence_table := new task_occurence_table; reset_iterator (sys.tasks, my_iterator_t); loop current_element (sys.tasks, a_task, my_iterator_t); for k in 0 .. sched.nb_entries - 1 loop for j in 0 .. sched.entries(k).data.result.nb_entries - 1 loop if sched.entries (k).data.result.entries (j).data.type_of_event=task_activation then if sched.entries (k).data.result.entries (j).data.activation_task.name = a_task.name then current_date := sched.entries(k).data.result.entries(j).item; --put_line(Integer'image(current_date)); task_occurence_number := task_occurence_number + 1; --put(task_occurence_number); my_task_occurence_table.entries(task_occurence_number).arrival_time := current_date; end if; end if; if sched.entries (k).data.result.entries (j).data.type_of_event = end_of_task_capacity then if sched.entries (k).data.result.entries (j).data.end_task.name =a_task.name then current_date := sched.entries(k).data.result.entries(j).item; --put_line(Integer'image(current_date)); -- new_line; my_task_occurence_table.entries(task_occurence_number).completion_time := current_date ; my_task_occurence_table.entries(task_occurence_number).response_time := my_task_occurence_table.entries(task_occurence_number).completion_time - my_task_occurence_table.entries(task_occurence_number).arrival_time; -- put_line(Integer'image(my_task_occurence_table.entries(task_occurence_number).response_time)); if my_task_occurence_table.entries(task_occurence_number).response_time > worst_execution_time then worst_execution_time :=my_task_occurence_table.entries(task_occurence_number).response_time; end if; end if; end if; if task_occurence_number > 0 then my_task_occurence_table.entries(task_occurence_number).response_time := worst_execution_time; end if; end loop; end loop; put_line("task name : " & to_string(a_task.name)); Put_Line("worst execution time: " & Integer'Image(worst_execution_time)); exit when is_last_element (sys.tasks, my_iterator_t); next_element (sys.tasks, my_iterator_t); worst_execution_time:=0; end loop; end compute_worst_execution_time ; -- Task Set Creation procedure affiche_set (my_task : in Generic_Task_Ptr) is begin put(to_string(my_task.name)); end affiche_set; procedure liberer_set (my_task : in out Generic_Task_Ptr) is begin null; end liberer_set; function copier (my_task : in Generic_Task_Ptr) return Generic_Task_Ptr is begin null; return my_task; end copier; function xml_string (my_task : in Generic_Task_Ptr) return unbounded_string is begin null; return to_unbounded_string(""); end xml_string; function xml_ref_string (my_task : in Generic_Task_Ptr) return unbounded_string is begin null; return to_unbounded_string(""); end xml_ref_string; package my_set is new sets(100,Generic_Task_Ptr,affiche_set,liberer_set,copier,xml_string,xml_ref_string); use my_set; maximum_slot_number : constant integer := 64; my_iterator : my_set.iterator; a_set : my_set.set; type slot_id_type is new integer range 1..maximum_slot_number; type slot_type is record start_time : Natural ; duration : Natural ; Slot_id : slot_id_type ; emitters : my_set.set; end record; type tdma_frame_type is array (slot_id_type'range) of slot_type; a_slot : slot_id_type; trame : tdma_frame_type; procedure initialize_trame_tdma (t : out tdma_frame_type) is begin for i in slot_id_type'range loop t(i).start_time:=0; t(i).duration:=0; t(i).slot_id:=i; end loop; end initialize_trame_tdma; -- PPCM computation procedure ppcm_compute (PPCM : out Natural) is package natural_discrete is new discrete_util (Natural); subtype discrete_element is integer; PGCD : Natural := 0; current_period : Natural; begin reset_iterator(sys.tasks, my_iterator_t); current_element(sys.tasks, a_task, my_iterator_t); PGCD := periodic_task_ptr(a_task).period; PPCM := periodic_task_ptr(a_task).period; loop current_element(sys.tasks, a_task, my_iterator_t); current_period := periodic_task_ptr(a_task).period; -- put_line("Task name: " & to_string(a_task.name)); -- put_line("Task period: " & Natural'Image(current_period)); PGCD := natural_discrete.gcd(PGCD, current_period); PPCM := natural_discrete.lcm(PPCM, current_period); exit when is_last_element(sys.tasks, my_iterator_t); next_element(sys.tasks, my_iterator_t); end loop; put_line("PGCD of periods: " & Natural'Image(PGCD)); put_line("PPCM of periods: " & Natural'Image(PPCM)); end ppcm_compute; -- Wakeup Task computation function task_wakeup_compute (a_task : in Generic_task_Ptr) return integer is result : integer :=0; nb_wakeup : integer :=0; my_task : generic_task_ptr; PPCM : Natural :=0; begin ppcm_compute(PPCM); reset_iterator (sys.tasks, my_iterator_t); loop current_element (sys.tasks, my_task, my_iterator_t); -- put_line("task period : " & periodic_task_ptr(my_task).period'img ); nb_wakeup := PPCM / periodic_task_ptr(my_task).period ; exit when is_last_element (sys.tasks, my_iterator_t); result := result + nb_wakeup; next_element (sys.tasks, my_iterator_t); end loop; put_line ( "Number of task wakeup:" & integer'image(result)); return result; end task_wakeup_compute; function calcul_duration_slot (a_slot : in slot_id_type ) return Natural is duree : Natural :=0; result : Natural :=0; t1 : Natural :=0; begin t1 := 0 ; for t in 0 .. sched.nb_entries - 1 loop for j in 0 .. sched.entries(t).data.result.nb_entries - 1 loop if sched.entries(t).data.result.entries(j).data.type_of_event = end_of_task_capacity then t1 := sched.entries(t).data.result.entries(j).item ; duree := t1-1; result := duree ; end if ; end loop ; end loop ; return result ; end calcul_duration_slot ; procedure create_trame_tdma (t : in tdma_frame_type) is minimum_slot_number : constant integer := 32; found : boolean ; begin a_slot:=2; for t in 0 .. sched.nb_entries - 1 loop for j in 0 .. sched.entries(t).data.result.nb_entries - 1 loop if sched.entries(t).data.result.entries(j).data.type_of_event = end_of_task_capacity then if task_wakeup_compute(sched.entries(t).data.result.entries(j).data.end_task) < minimum_slot_number then trame(a_slot).Slot_id := a_slot; add(trame(a_slot).emitters, sched.entries(t).data.result.entries(j).data.end_task); trame(a_slot).duration := integer(get_number_of_elements(trame(a_slot).emitters)); trame(a_slot).start_time := sched.entries(t).data.result.entries(j).item; trame(a_slot-1).duration := sched.entries(t).data.result.entries(j).item; a_slot := a_slot + 1; trame(a_slot).duration := integer(get_number_of_elements(trame(a_slot).emitters)); trame(a_slot).start_time := sched.entries(t).data.result.entries(j).item +trame(a_slot-1).duration ; a_slot := a_slot + 1; end if ; if task_wakeup_compute(sched.entries(t).data.result.entries(j).data.end_task) > minimum_slot_number then -- Check if the task is already in the set for i in slot_id_type'range loop if not is_empty(trame(i).emitters) then reset_iterator(trame(i).emitters, my_iterator); found := false; loop current_element(trame(i).emitters, a_task, my_iterator); -- put_line("TG = " & to_string(a_task.name)); -- put_line("TD = " & to_string(sched.entries(t).data.result.entries(j).data.end_task.name)); if a_task.name = sched.entries(t).data.result.entries(j).data.end_task.name then found:=True; end if ; exit when is_last_element(trame(i).emitters, my_iterator); next_element(trame(i).emitters, my_iterator); end loop; end if ; if found = false then trame(a_slot).Slot_id := a_slot; if get_number_of_elements(trame(a_slot).emitters) < 6 then add(trame(a_slot).emitters, sched.entries(t).data.result.entries(j).data.end_task); end if; trame(a_slot).duration := integer(get_number_of_elements(trame(a_slot).emitters)); trame(a_slot).start_time := sched.entries(t).data.result.entries(j).item; trame(a_slot-1).duration := sched.entries(t).data.result.entries(j).item; a_slot := a_slot + 1; trame(a_slot).duration := 0 ; trame(a_slot).start_time := sched.entries(t).data.result.entries(j).item +trame(a_slot-1).duration ; if get_number_of_elements(trame(a_slot).emitters) = 6 then a_slot := a_slot + 1; trame(a_slot).Slot_id := a_slot; trame(a_slot).duration := 0; trame(a_slot).start_time := trame(a_slot-1).start_time + trame(a_slot-1).duration; end if; if a_slot = 64 then a_slot := 2; end if ; end if ; end loop; end if ; end if ; end loop; end loop ; end create_trame_tdma ; procedure display_tdma (t : in tdma_frame_type) is begin for i in slot_id_type'range loop put_line("Slot id/start time/duration : " & t(i).Slot_id'img & "/" & t(i).start_time'img & "/" & t(i).duration'img ); put(t(i).emitters); end loop; end display_tdma; begin -- Initialize the Cheddar framework -- call_framework.initialize (False); -- Parse command line -- if Argument_Count /= 2 then Put ("Usage: " & Command_Name & " "); Put_Line ("Processor_Name InputFilename"); GNAT.OS_Lib.OS_Exit (1); end if; Put_Line("Argument 1/Processor name : " & Argument(1)); Put_Line("Argument 2/File name : " & Argument(2)); -- Read the XML project file -- initialize (project_file_list); declare File_Name : String := Argument (2); begin Output_EV_File_Name := File_Name & to_unbounded_string(".schedule"); systems.read_from_xml_file (sys, project_file_dir_list,file_name); end; display_task(my_task); Put_Line("le temps de communication est :" & Integer'Image(time_com)); compute_scheduling; for i in 0 .. sched.nb_entries - 1 loop for j in 0 .. sched.entries (i).data.result.nb_entries - 1 loop Put (sched.entries (i).data.result.entries (j).item'img); put(" "); Put (sched.entries (i).data.result.entries (j).data.type_of_event'img); put (" "); if (sched.entries (i).data.result.entries (j).data.type_of_event=task_activation) then Put (to_string(sched.entries (i).data.result.entries (j).data.activation_task.name)); end if; if (sched.entries (i).data.result.entries (j).data.type_of_event=running_task) then Put (to_string(sched.entries (i).data.result.entries (j).data.running_task.name)); end if; new_line; end loop; end loop; compute_worst_execution_time(my_task); initialize_trame_tdma (trame); create_trame_tdma (trame); display_tdma(trame); end amanite;