------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- 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-2016, Frank Singhoff, Alain Plantec, Jerome Legrand -- -- The Cheddar project was started in 2002 by -- Frank Singhoff, Lab-STICC UMR 6285 laboratory, 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 AUTHORS.txt and SPONSORS.txt -- -- 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: 3561 $ -- $Date: 2020-11-02 08:25:02 +0100 (Mon, 02 Nov 2020) $ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions; with Ada.Strings; use Ada.Strings; with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random ; with unbounded_strings; use unbounded_strings; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with unbounded_strings; use unbounded_strings; with Ada.Strings; use Ada.Strings; with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO; with Ada.Directories; use Ada.Directories; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Unbounded_Strings; use Unbounded_Strings; with convert_unbounded_strings; use unbounded_strings.unbounded_string_list_package; use unbounded_strings.strings_table_package; with Ada.Strings; use Ada.Strings; with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO; with Ada.text_IO; use Ada.text_IO; with Ada.Integer_text_IO; use Ada.Integer_text_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; with Dependencies; use Dependencies; with Task_Dependencies; use Task_Dependencies; with Task_Dependencies; use Task_Dependencies.Half_Dep_Set; with Message_Set ; use Message_Set; with Messages; use Messages; with Tasks; use Tasks; with Task_Set; use Task_Set; with Resources; use Resources; with Resource_Set; use Resource_Set; with Objects; use Objects; with convert_unbounded_strings; use unbounded_strings.unbounded_string_list_package; with Scheduler_Interface; use Scheduler_Interface; with Address_Spaces; use Address_Spaces; with Address_Space_Set; use Address_Space_Set; 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 Pipe_Commands; use Pipe_Commands; with Ada.Text_IO; use Ada.Text_IO; with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO; with Ada.Directories; use Ada.Directories; with GNAT.OS_Lib; use GNAT.OS_Lib; with Debug; use Debug; with Random_Tools; use Random_Tools; use unbounded_strings.strings_table_package; with architecture_factory; use architecture_factory; with Ada.Integer_text_IO; use Ada.Integer_text_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; with Systems; use Systems; with Processors; use Processors; with Processor_Set; use Processor_Set; with processor_interface; use processor_interface; use Processor_Set.Generic_Processor_Set; with Core_Units; use Core_Units; use Core_Units.Core_Units_Table_Package; with natural_util; use natural_util; with feasibility_test.feasibility_interval; use feasibility_test.feasibility_interval; with integer_util; use integer_util; use Resources.Resource_Accesses; with float_util; use float_util; with Ada.Characters.Latin_1; use Ada.Characters; with Ada.Text_IO; use Ada.Text_IO; with GNAT.String_Split; use GNAT; with MILS_Security; use MILS_Security; with Random_Tools; use Random_Tools; with Memories; use Memories; with Objective_Functions_and_Feasibility_Checks_mils; use Objective_Functions_and_Feasibility_Checks_mils; with security_implementation; use security_implementation; with Chromosome_Data_Manipulation_mils; use Chromosome_Data_Manipulation_mils; package body model_generator is procedure generator_model_Uunifast( a_solution : in solution; nb_partitions: in Integer;N_diff_periods : in Integer; Total_cpu_utilization: in Float) is --------------------------------------------- a_system : System; -- nb_partitions : constant integer := 2 ; actual_cpu_utilization : float := 0.00; Hyperperiod_of_Initial_Taskset : Integer := 4250; T_values : Integer_Array (1 .. genes); -- Priority_values : Integer_Array (1 .. genes):=(5,4,3,2,1,5,4,3,2,1,5,4,3,2,1); Priority_values : Integer_Array (1 .. genes):=(5,4,3,2,1,5,4,3,2,1,5,4,3,2,1); --------------------------------------------- Period12000_values :Integer_Array (1 .. 13):=(500,600,750,800,1000,1200,1500,2000,2400,3000,4000,6000,12000); Period_N_diff_periods:Integer_Array (1 .. 3):=(0,0,0); --to 3 different periods shoose randomly in Period12000_values G : Ada.Numerics.Float_Random.Generator; j: Integer; A_task_source : Generic_Task_Ptr; A_task_sink : Generic_Task_Ptr; found: Boolean; Project_File_Dir_List : unbounded_string_list; function found_element_in_array (x: integer ; Seq : Integer_Array; N_diff_periods:Integer) return boolean is b : boolean := false; i : integer := 1; begin for j in 1..N_diff_periods loop if (seq(i)=x) then b := true; end if; end loop; return b; end found_element_in_array; procedure Shuffle_An_Array (To_Shuffle : in out Integer_Array) is use Ada.Numerics.Float_Random ; N : integer; G : Ada.Numerics.Float_Random.Generator; A_random_position : integer := 0; A_value : integer; begin N := To_Shuffle'Length; reset (G); while N > 1 loop A_random_position := 0; while (A_random_position < 1) or (A_random_position > N) loop A_random_position := Integer (Random(G) * Float(N)); end loop; N := N - 1; A_value := To_Shuffle (A_random_position); To_Shuffle (A_random_position) := To_Shuffle (N); To_Shuffle (N) := A_value; end loop; end Shuffle_An_Array; begin reset(G); -- Initialise the float generator if (N_diff_periods=0) then --cas1 -- T_values:=(500,1000,1000,500,1000,500,1000,1000,500,1000,500,1000,1000,500,1000); T_values:=(500,1000,1000,500,1000,500,1000,1000,500,1000,500,1000,1000,500,1000); -- T_values:=(500,1000,1000,2000,2000,500,1000,1000,2000,2000,500,1000,1000,2000,2000); -- T_values:=(500,1000,1000,2000,2000,500,1000,1000,2000,2000,500,1000,1000,2000,2000,1000,1000,1000,1000,1000,1000,1000); -- cas2_set1 -- T_values:=(800,4000,4000,600,600,800,4000,4000,600,600,800,4000,4000,600,600); -- cas2_set2 -- T_values:=(1200,750,750,4000,4000,1200,750,750,4000,4000,1200,750,750,4000,4000); -- cas2_set3 -- T_values:=(800,1000,1000,6000,6000,800,1000,1000,6000,6000,800,1000,1000,6000,6000); else j := 0; -- choose randomly N_diff_periods periods in Period12000_values for i in 1..N_diff_periods loop loop while (j > 13) or (j < 1) loop j := integer (float(13) * random(G)); end loop; found:=found_element_in_array (Period12000_values(j),Period_N_diff_periods,N_diff_periods); exit when not found; end loop; Period_N_diff_periods(i):= Period12000_values(j); Shuffle_An_Array (Period12000_values); end loop; for i in 1..genes loop if (i=1) OR (i=6) OR (i=11) then T_values(i):= Period_N_diff_periods(1); elsif (i=2) OR (i=7) OR (i=12) then T_values(i):= Period_N_diff_periods(2); elsif (i=3) OR (i=8) OR (i=13) then T_values(i):= Period_N_diff_periods(2); elsif (i=4) OR (i=9) OR (i=14) then T_values(i):= Period_N_diff_periods(3); elsif (i=5) OR (i=10) OR (i=15) then T_values(i):= Period_N_diff_periods(3); end if; end loop; end if; -------------------------------------------------------- ------ generate core, processor, address_space ------ -------------------------------------------------------- Create_system(a_system, A_solution); ------------------------- --generate task set ----- ------------------------- Create_Independant_Periodic_TaskSet_System (S => a_system, Current_cpu_utilization => actual_cpu_utilization, N_Tasks => genes, Target_cpu_utilization => Total_cpu_utilization, T_values => T_values, Priority_values => Priority_values); Initial_System:= a_system; ------------------------------ --- Assigne the security levels of tasks and produce dependency --- ------------------------------ for i in 1..genes loop A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("Task"& i'Img))) ; A_task_source.name := Suppress_Space(To_Unbounded_String(""& i'Img)); end loop; A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("1"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("2"))); A_task_source.mils_confidentiality_level:= Top_Secret; A_task_source.mils_integrity_level:= Medium; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("2"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("3"))); A_task_source.mils_confidentiality_level:= Secret; A_task_source.mils_integrity_level:= High; -- A_task_source.criticality:=3; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("3"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("4"))); A_task_source.mils_confidentiality_level:= Top_Secret; A_task_source.mils_integrity_level:= High; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("4"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("5"))); A_task_source.mils_confidentiality_level:= Secret; A_task_source.mils_integrity_level:= Medium; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); ----------------------------------1\C8RE DUPLICATION----------------------------------------- A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("6"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("7"))); -- A_task_source.mils_confidentiality_level:= Top_Secret; -- A_task_source.mils_integrity_level:= Medium; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("7"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("8"))); -- A_task_source.mils_confidentiality_level:= Secret; -- A_task_source.mils_integrity_level:= High; -- A_task_source.criticality:=3; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("8"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("9"))); -- A_task_source.mils_confidentiality_level:= Top_Secret; -- A_task_source.mils_integrity_level:= High; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("9"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("10"))); -- A_task_source.mils_confidentiality_level:= Secret; -- A_task_source.mils_integrity_level:= Medium; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); ------------------------------2\C8ME DUPLICATION----------------------------------------- A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("11"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("12"))); A_task_source.mils_confidentiality_level:= Top_Secret; A_task_source.mils_integrity_level:= Medium; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("12"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("13"))); A_task_source.mils_confidentiality_level:= Secret; A_task_source.mils_integrity_level:= High; -- A_task_source.criticality:=3; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("13"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("14"))); A_task_source.mils_confidentiality_level:= Top_Secret; A_task_source.mils_integrity_level:= High; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("14"))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String ("15"))); A_task_source.mils_confidentiality_level:= Secret; A_task_source.mils_integrity_level:= Medium; Add_One_Task_Dependency_precedence (My_Dependencies => Initial_System.dependencies, Source => A_task_source, Sink => A_task_sink); ------------------------------------------------------------------------------------------- Put_Debug ("Writing test_Unifast.xmlv3"); Write_To_Xml_File (A_System => Initial_System, File_Name => Suppress_Space (To_Unbounded_String ( "test_Unifast.xmlv3"))); Put_Debug ("Finish write test_Unifast.xmlv3"); end generator_model_Uunifast; ------------------ -- duplication -- ------------------ procedure Task_duplicate is Sys: System; My_iterator: Tasks_Dependencies_Iterator; Dep_Ptr: Dependency_Ptr; My_dependencies: Tasks_Dependencies_Ptr; y: Natural:=genes+1; A_task_source : Generic_Task_Ptr; A_task_sink : Generic_Task_Ptr; addr: Unbounded_String; begin Sys := Initial_System; My_dependencies := Sys.Dependencies; reset_iterator(My_dependencies.Depends, My_iterator); loop current_element(My_dependencies.Depends, Dep_Ptr, My_iterator); if (Dep_Ptr.precedence_source.address_space_name=To_Unbounded_String("addr1")) then addr:=To_Unbounded_String("addr2"); else addr:=To_Unbounded_String("addr1"); end if; Add_Task(My_Tasks => Sys.Tasks, Name => Suppress_Space (To_Unbounded_String (""&y'img)), Cpu_Name => Suppress_Space ((To_Unbounded_string("processor1"))) , Address_Space_Name => Suppress_Space (addr), core_name => To_unbounded_string(""), Task_Type => Periodic_Type, Start_Time => 0 , Capacity => Dep_Ptr.precedence_source.capacity, Period => Dep_Ptr.precedence_source.deadline, Deadline => Dep_Ptr.precedence_source.deadline, Jitter => 0, Blocking_Time => 0, Priority => Integer'Value( Dep_Ptr.precedence_source.priority'Img), Criticality => 0, Policy => Sched_Fifo, mils_task => Dep_Ptr.precedence_source.mils_task ); A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String (Integer'Image(y)))) ; y:=y+1; if (Dep_Ptr.precedence_sink.address_space_name=To_Unbounded_String("addr1")) then addr:=To_Unbounded_String("addr2"); else addr:=To_Unbounded_String("addr1"); end if; Add_Task(My_Tasks => Sys.Tasks, Name => Suppress_Space (To_Unbounded_String (""&y'img)), Cpu_Name => Suppress_Space ((To_Unbounded_string("processor1"))) , Address_Space_Name => Suppress_Space (addr), core_name => To_unbounded_string(""), Task_Type => Periodic_Type, Start_Time => 0 , Capacity => Dep_Ptr.precedence_sink.capacity, Period => Dep_Ptr.precedence_sink.deadline, Deadline => Dep_Ptr.precedence_sink.deadline, Jitter => 0, Blocking_Time => 0, Priority => Integer'Value( Dep_Ptr.precedence_sink.priority'Img), Criticality => 0, Policy => Sched_Fifo, mils_task => Dep_Ptr.precedence_sink.mils_task ); A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (To_Unbounded_String (Integer'Image(y)))) ; Add_One_Task_Dependency_precedence (My_Dependencies => Sys.dependencies, Source => A_task_source, Sink => A_task_sink); end loop; end Task_duplicate; end model_generator;