------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- 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: 4716 $ -- $Date: 2023-12-18 11:19:31 +0100 (lun. 18 déc. 2023) $ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Text_IO; use Text_IO; with processor_set; use processor_set; 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 tasks; use tasks; with task_set; use task_set; use task_set.generic_task_set; with systems; use systems; 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 GNAT.Command_Line; with GNAT.OS_Lib; use GNAT.OS_Lib; with version; use version; with Ada.Exceptions; use Ada.Exceptions; 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; procedure preemption_delay 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_list : unbounded_string_list; project_file_dir_list : unbounded_string_list; -- Is the command should run in verbose mode ? -- verbose : Boolean := False; -- Do we export results in a CSV format ? csv : Boolean := False; -- The XML file to read (architecture model to analyze) -- input_file : Boolean := False; input_file_name : Unbounded_String; -- The XML file to write scheduling table computed by Cheddar -- scheduling_output_file : Boolean := False; scheduling_output_file_name : Unbounded_String; -- The XML file to write preemption delays computed by the program -- preemption_delay_output_file : Boolean := False; preemption_delay_output_file_name : Unbounded_String; a_file : File_Type; -- The duration on which we must compute the scheduling -- feasibility_interval_string : Unbounded_String; feasibility_interval : Natural := 0; ok : Boolean := False; -- Iterator to analyse all tasks of the model -- preemption_delay : integer; a_task : Generic_task_ptr; my_iterator_t : tasks_iterator; state : boolean; procedure usage is begin Put_Line ("preemption_delay is a program which computes preemption delays of a task set from a scheduling. The analysis is run from an XML Cheddar project file and results are saved into a second XML file and display on the screen."); New_Line; Put_Line ("Check Cheddar home page for details : http://beru.univ-brest.fr/cheddar "); New_Line; New_Line; Put_Line ("Usage : preemption_delay [switch] [scheduling-feasibility-interval]"); Put_Line (" switch can be :"); Put_Line (" -u get this help"); Put_Line (" -v verbose mode "); Put_Line (" -x export results in CSV format "); Put_Line (" -o file-name, write the scheduling into the XML file file-name "); Put_Line (" if no -o argument is given, then the scheduling is not displayed/saved "); Put_Line (" -i file-name, read the system to analyze from the XML file file-name "); Put_Line (" -r file-name, write preemption delay results computed from the scheduling in the file file-name "); New_Line; end usage; -- Compute preemption delay from scheduling simulation -- procedure compute_from_simulation is begin 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 := 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 (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); -- Export Event table into the event_table.xml file -- if (scheduling_output_file) then write_to_xml_file (framework.sched, sys, scheduling_output_file_name); end if; -- Now compute preemption delays and display result on the standard output -- Text file for the analysis results -- if (preemption_delay_output_file) then Create (a_file, Mode => Out_File, Name => To_String (preemption_delay_output_file_name)); end if; -- Compute preemption delays -- reset_iterator (sys.tasks, my_iterator_t); loop current_element (sys.tasks, a_task, my_iterator_t); if csv then if (preemption_delay_output_file) then Put (a_file, to_string(a_task.name) & " "); else Put (to_string(a_task.name) & " "); end if; else if (preemption_delay_output_file) then Put (a_file, to_string(a_task.name) & " =>"); else Put (to_string(a_task.name) & " =>"); end if; end if; state:=false; 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=running_task) and (state=false) then if (sched.entries (k).data.result.entries (j).data.running_task.name = a_task.name) then preemption_delay := 0; state:=true; end if; else if (sched.entries (k).data.result.entries (j).data.type_of_event=running_task) and (state=true) then if (sched.entries (k).data.result.entries (j).data.running_task.name /= a_task.name) then preemption_delay:=preemption_delay+1; end if; else if (sched.entries (k).data.result.entries (j).data.type_of_event=end_of_task_capacity) and (state=true) then if (sched.entries (k).data.result.entries (j).data.end_task.name = a_task.name) then state:=false; if csv then if (preemption_delay_output_file) then Put (a_file, " ," & preemption_delay'img & " "); else Put (" ," & preemption_delay'img & " "); end if; else if (preemption_delay_output_file) then Put (a_file, " " & preemption_delay'img & " "); else Put (" " & preemption_delay'img & " "); end if; end if; end if; end if; end if; end if; end loop; end loop; if (preemption_delay_output_file) then Put_line (a_file, ""); else Put_line (""); end if; exit when is_last_element (sys.tasks, my_iterator_t); next_element (sys.tasks, my_iterator_t); end loop; -- Text file for the analysis results -- if (preemption_delay_output_file) then Close (a_file); end if; end compute_from_simulation; begin copyright ("preemption_delay"); -- Get arguments -- loop case GNAT.Command_Line.Getopt ("u x v i: o: r:") is when ASCII.NUL => exit; when 'i' => input_file := True; input_file_name := To_Unbounded_String (GNAT.Command_Line.Parameter); when 'o' => scheduling_output_file := True; scheduling_output_file_name := To_Unbounded_String (GNAT.Command_Line.Parameter); when 'r' => preemption_delay_output_file := True; preemption_delay_output_file_name := To_Unbounded_String (GNAT.Command_Line.Parameter); when 'v' => verbose := True; when 'x' => csv := True; when 'u' => usage; OS_Exit (0); when others => usage; OS_Exit (0); end case; end loop; loop declare s : constant String := GNAT.Command_Line.Get_Argument (Do_Expansion => True); begin exit when s'length = 0; feasibility_interval_string := feasibility_interval_string & s; end; end loop; -- Check the feasibility interval on which we will compute the scheduling -- if (feasibility_interval_string /= empty_string) then to_natural (feasibility_interval_string, feasibility_interval, ok); if not ok then usage; Raise_Exception (Constraint_Error'identity, "The Feasibility Interval to compute the scheduling must be a numeric value"); end if; end if; -- Is an input file and an output file given ??? -- if (not input_file) then usage; OS_Exit (0); end if; -- Initialize the Cheddar framework -- call_framework.initialize (False); -- Read the XML project file -- initialize (project_file_list); systems.read_from_xml_file (sys, project_file_dir_list, input_file_name); if (feasibility_interval = 0) then usage; Raise_Exception (Constraint_Error'identity, "Requires a value for the feasibility interval"); end if; compute_from_simulation; end preemption_delay;