------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- 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-2020, 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 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: 3477 $ -- $Date: 2020-07-13 11:43:48 +0200 (Mon, 13 Jul 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 Tasks; use Tasks; with Task_Set; use Task_Set; with Resources; use Resources; with Resource_Set; use Resource_Set; 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 Objective_Functions_and_Feasibility_Checks; use Objective_Functions_and_Feasibility_Checks; 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 Memories; use Memories; with Dependencies; use Dependencies; with Task_Dependencies; use Task_Dependencies; with Task_Dependencies; use Task_Dependencies.Half_Dep_Set; with MILS_Security; use MILS_Security; with result_parser; use result_parser; with mils_analysis; use mils_analysis; with security_implementation; use security_implementation; package body Chromosome_Data_Manipulation is -------------- -- init_F2T -- -------------- procedure init_F2T is F : Ada.Text_IO.File_Type; gene_i : unbounded_String; chrom_str : unbounded_String; -- Subs is populated by the actual substrings. Subs : String_Split.Slice_Set; -- just an arbitrary simple set of whitespace. Seps : constant String := " " & Latin_1.HT; begin if Using_preprocessed_initial_sol then -- Initialize the current solution c with the preprocessed -- initial solution -- 1/ get the chromosome of the preprocessed initial solution -- from the file chrom_preprocessed_initial_solution.txt Open (File => F, Mode => Ada.Text_IO.In_File, Name => "chrom_preprocessed_initial_solution.txt"); loop exit when Ada.Text_IO.End_Of_File (F); Ada.Strings.Unbounded.Append (chrom_str, To_Unbounded_String(Get_Line (File => F))); end loop; close (F); Put_Line ("chrom_str: " & To_string (chrom_str)); -- 2/ extract gene values from chrom_str to initialize the -- initial current solution -- The following code is inspired from: -- http://wiki.ada-dk.org/gnat.string_split_basic_usage_example String_Split.Create (S => Subs, From => To_String(chrom_str), Separators => Seps, Mode => String_Split.Multiple); for i in 1 .. genes loop c.chrom_task (i) := Integer'Value(String_Split.Slice (Subs, String_Split.Slice_Number(i+1))); end loop; Put ("The initial preprocessed solution: "); print_genome(c); else -- initialize the current solution c with 1-1 fctsTotasks mapping -- solution -- for i in 1 .. genes loop c.chrom_task(i) := i; end loop; end if; If Check_Feasibility_of_A_Solution (One_to_one_mapping_solution, 0) then evaluate_F2T (c, 0); end if; end init_F2T; -------------- -- init_T2P -- -------------- procedure init_T2P is F : Ada.Text_IO.File_Type; gene_i : unbounded_String; gene_task_i : unbounded_String; gene_com_i : unbounded_String; chrom_str : unbounded_String; -- Subs is populated by the actual substrings. Subs : String_Split.Slice_Set; -- just an arbitrary simple set of whitespace. Seps : constant String := " " & Latin_1.HT; j, k : Integer; My_iterator: Tasks_Dependencies_Iterator; Dep_Ptr: Dependency_Ptr; My_dependencies: Tasks_Dependencies_Ptr; A_task_i : Generic_Task_Ptr; Sys1,Sys2, Sys3, Sys4, Sys5, Sys6, Sys7 : System; app_limit,num_app: Integer; begin if Using_preprocessed_initial_sol then -- Initialize the current solution c with the preprocessed -- initial solution -- 1/ get the chromosome of the preprocessed initial solution -- from the file chrom_preprocessed_initial_solution.txt Open (File => F, Mode => Ada.Text_IO.In_File, Name => "chrom_preprocessed_initial_solution.txt"); loop exit when Ada.Text_IO.End_Of_File (F); Ada.Strings.Unbounded.Append (chrom_str, To_Unbounded_String(Get_Line (File => F))); end loop; close (F); Put_Debug ("chrom_str: " & To_string (chrom_str)); -- 2/ extract gene values from chrom_str to initialize the -- initial current solution -- The following code is inspired from: -- http://wiki.ada-dk.org/gnat.string_split_basic_usage_example String_Split.Create (S => Subs, From => To_String(chrom_str), Separators => Seps, Mode => String_Split.Multiple); for i in 1 .. genes loop c.chrom_task (i) := Integer'Value(String_Split.Slice (Subs, String_Split.Slice_Number(i+1))); end loop; Put ("The initial preprocessed solution: "); print_genome(c); else for n in 1..15 loop nb_secu_conf_choice(n):=0; end loop; --initialize the number of tasks per application --Experiments6: 2 autopilot nb_task_per_app(1):=5; --Autopilot1 nb_task_per_app(2):=5; --Autopilot2 --Experiments1: 2 app -- nb_task_per_app(1):=15; --Rosace -- nb_task_per_app(2):=7; --JPEG --Experiments2: 6 app -- nb_task_per_app(1):=15; --Rosace -- nb_task_per_app(2):=4; --CFAR -- nb_task_per_app(3):=7; --JPEG -- nb_task_per_app(4):=5; --Autopilot1 -- nb_task_per_app(5):=5; --Autopilot2 -- nb_task_per_app(6):=5; --Autopilot3 -- --Experiments4: 5 app -- nb_task_per_app(1):=15; --Rosace -- nb_task_per_app(2):=4; --CFAR -- nb_task_per_app(3):=5; --Autopilot1 -- nb_task_per_app(4):=5; --Autopilot2 -- nb_task_per_app(5):=5; --Autopilot3 -- -- initialize the current solution c by puting all the tasks in the same partition -- solution -- nb_InitSol:=0; nb_NoFeasible_Sol := 0; num_app:=1; app_limit:=nb_task_per_app(1); for i in 1 .. genes loop if (num_app<=nb_app) then task_to_app(i):=num_app; if (i>=app_limit) then num_app:=num_app+1; app_limit:=app_limit+nb_task_per_app(num_app); end if; end if; c.chrom_task(i) := 1; sol_init1.chrom_task(i) := 1; if i <= genes/2 then sol_init2.chrom_task(i) := 1; else sol_init2.chrom_task(i) := 2; end if; -- if i <= genes/4 then -- sol_init2.chrom_task(i) := 1; -- elsif (i > genes/4) AND (i <= genes/2) then -- sol_init2.chrom_task(i) := 2; -- elsif (i > genes/2) AND (i <= 3*genes/4) then -- sol_init2.chrom_task(i) := 3; -- else -- sol_init2.chrom_task(i) := 4; -- end if; A_task_i := Search_Task (Initial_System.Tasks, Suppress_Space (i'Img)) ; -- all tasks with the same confidentiality level should be put in the same partition if(A_task_i.mils_confidentiality_level= Top_Secret) then sol_init3.chrom_task(i):= 1; sol_init4.chrom_task(i):= 1; elsif (A_task_i.mils_confidentiality_level= Secret) then sol_init3.chrom_task(i):= 2; sol_init4.chrom_task(i):= 2; elsif (A_task_i.mils_confidentiality_level= Classified)then sol_init3.chrom_task(i):= 3; sol_init4.chrom_task(i):= 3; else sol_init3.chrom_task(i):= 4; sol_init4.chrom_task(i):= 4; end if; -- all tasks with the same integrity level should be put in the same partition if(A_task_i.mils_integrity_level= High) then sol_init5.chrom_task(i):= 1; sol_init6.chrom_task(i):= 1; elsif (A_task_i.mils_integrity_level= Medium) then sol_init5.chrom_task(i):= 2; sol_init6.chrom_task(i):= 2; else sol_init5.chrom_task(i):= 3; sol_init6.chrom_task(i):= 3; end if; end loop; -- Put_Line("task_to_appppppppppppppppppppp"); for n in 1..genes loop Put (task_to_app(n)'Img & " "); end loop; New_Line; -- -- for i in 1..nb_partitions+1 loop -- c.chrom_partition_PU(i) := 1; -- sol_init1.chrom_partition_PU(i) := 1; -- sol_init2.chrom_partition_PU(i):=1; -- sol_init3.chrom_partition_PU(i):=1; -- sol_init4.chrom_partition_PU(i):=1; -- sol_init5.chrom_partition_PU(i):=1; -- sol_init6.chrom_partition_PU(i):=1; -- end loop; My_dependencies:= Initial_System.Dependencies; if is_empty( My_dependencies.Depends) then Put_Debug("No dependencies"); else j:= 1; k:= 1; reset_iterator(My_dependencies.Depends, My_iterator); loop current_element(My_dependencies.Depends, Dep_Ptr, My_iterator); if(Dep_Ptr.type_of_dependency=precedence_dependency)then if ( (Dep_Ptr.precedence_sink.mils_confidentiality_level=UnClassified)AND ((Dep_Ptr.precedence_source.mils_confidentiality_level= Secret)OR (Dep_Ptr.precedence_source.mils_confidentiality_level= Top_Secret)) ) OR ( (Dep_Ptr.precedence_source.mils_integrity_level= Low ) AND (( Dep_Ptr.precedence_sink.mils_integrity_level=Medium) OR ( Dep_Ptr.precedence_sink.mils_integrity_level=High)) )then -- Resolve confidentiality and integrity constraints problem c.chrom_com(j).mode := emission; c.chrom_com(j).link := communication; c.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init1.chrom_com(j).mode := emission; sol_init1.chrom_com(j).link := communication; sol_init1.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init2.chrom_com(j).mode := emission; sol_init2.chrom_com(j).link := communication; sol_init2.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init3.chrom_com(j).mode := emission; sol_init3.chrom_com(j).link := communication; sol_init3.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init4.chrom_com(j).mode := emission; sol_init4.chrom_com(j).link := communication; sol_init4.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init5.chrom_com(j).mode := emission; sol_init5.chrom_com(j).link := communication; sol_init5.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init6.chrom_com(j).mode := emission; sol_init6.chrom_com(j).link := communication; sol_init6.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); else if(Dep_Ptr.precedence_sink.mils_confidentiality_level< Dep_Ptr.precedence_source.mils_confidentiality_level) OR (Dep_Ptr.precedence_source.mils_integrity_level< Dep_Ptr.precedence_sink.mils_integrity_level)then -- resolve all security problems k := k+1; c.chrom_com(j).mode := emission; c.chrom_com(j).link := communication; c.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init4.chrom_com(j).mode := emission; sol_init4.chrom_com(j).link := communication; sol_init4.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init6.chrom_com(j).mode := emission; sol_init6.chrom_com(j).link := communication; sol_init6.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); else c.chrom_com(j).mode := noDW; c.chrom_com(j).link := noDW; c.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init4.chrom_com(j).mode := noDW; sol_init4.chrom_com(j).link := noDW; sol_init4.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init6.chrom_com(j).mode := noDW; sol_init6.chrom_com(j).link := noDW; sol_init6.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); end if; sol_init1.chrom_com(j).mode := noDW; sol_init1.chrom_com(j).link := noDW; sol_init1.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init2.chrom_com(j).mode := noDW; sol_init2.chrom_com(j).link := noDW; sol_init2.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init3.chrom_com(j).mode := noDW; sol_init3.chrom_com(j).link := noDW; sol_init3.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); sol_init5.chrom_com(j).mode := noDW; sol_init5.chrom_com(j).link := noDW; sol_init5.chrom_com(j).source_sink := suppress_space(To_String(Dep_Ptr.precedence_source.name) & "_" & To_String(Dep_Ptr.precedence_sink.name)); end if; j := j+1; end if; exit when is_last_element (My_Dependencies.Depends, My_Iterator); next_element (My_Dependencies.Depends, My_Iterator); end loop; end if; end if; normalize(sol_init3); normalize(sol_init4); normalize(sol_init5); normalize(sol_init6); Put_Debug("===============c================"); print_genome(c); Put_Debug("===============sol_init1================"); print_genome(sol_init1); Put_Debug("===============sol_init2================"); print_genome(sol_init2); Put_Debug("===============sol_init3================"); print_genome(sol_init3); Put_Debug("===============sol_init4================"); print_genome(sol_init4); Put_Debug("===============sol_init5================"); print_genome(sol_init5); Put_Debug("===============sol_init6================"); print_genome(sol_init6); If Check_Feasibility_of_A_Solution (sol_init1, 0) then Put_Line("===============sol_init1 evaluation ================"); evaluate_T2P (sol_init1, 0); archive_soln(sol_init1); update_grid(sol_init1); Append (Data3, " 0" & " " & sol_init1.obj(1)'img &" " &sol_init1.obj(2)'img &" " & sol_init1.obj(3)'img &" " & sol_init1.security_config'img &" "& ASCII.LF); Put_Debug ("sol1" & " " & sol_init1.obj(1)'img &" " &sol_init1.obj(2)'img &" " & sol_init1.obj(3)'img &" "& ASCII.LF); Put_Line ("sol1" & " " & sol_init1.obj(1)'img &" " &sol_init1.obj(2)'img &" " & sol_init1.obj(3)'img &" "& ASCII.LF); nb_InitSol:=nb_InitSol+1; Create_system_T2P (Sys1, sol_init1); Transform_Chromosome_To_CheddarADL_Model(Sys1 ,sol_init1); Write_To_Xml_File (A_System => Sys1, File_Name => To_string (Suppress_Space (To_Unbounded_String ("sol_init1" & ".xmlv3")))); Put_Debug("=============== end sol_init1 evaluation ================"); end if; --Just for version 3------- -- If Check_Feasibility_of_A_Solution (sol_init2, 0) then -- Put_Line("===============sol_init2 evaluation ================"); -- Put_Debug("===============sol_init2 evaluation ================"); -- evaluate_T2P (sol_init2, 0); -- archive_soln(sol_init2); -- update_grid(sol_init2); -- Append (Data3, " 0" & " " & sol_init2.obj(1)'img &" " &sol_init2.obj(2)'img &" " & sol_init2.obj(3)'img &" "& sol_init2.security_config'img &" "&ASCII.LF); -- Put_Debug ("sol2" & " " & sol_init2.obj(1)'img &" " &sol_init2.obj(2)'img &" " & sol_init2.obj(3)'img &" "& ASCII.LF); -- -- nb_InitSol:=nb_InitSol+1; -- -- Create_system (Sys2, sol_init2); -- Transform_Chromosome_To_CheddarADL_Model(Sys2 ,sol_init2); -- Write_To_Xml_File (A_System => Sys2, -- File_Name => To_string (Suppress_Space (To_Unbounded_String ("sol_init2" & ".xmlv3")))); -- -- end if; -- -- If Check_Feasibility_of_A_Solution (sol_init3, 0) then -- Put_Debug("===============sol_init3 evaluation ================"); -- evaluate_T2P (sol_init3, 0); -- archive_soln(sol_init3); -- update_grid(sol_init3); -- Append (Data3, " 0" & " " & sol_init3.obj(1)'img &" " &sol_init3.obj(2)'img &" " & sol_init3.obj(3)'img &" "&sol_init3.security_config'img &" "& ASCII.LF); -- Put_Debug ("sol3" & " " & sol_init3.obj(1)'img &" " &sol_init3.obj(2)'img &" " & sol_init3.obj(3)'img &" "& ASCII.LF); -- nb_InitSol:=nb_InitSol+1; -- -- Create_system (Sys3, sol_init3); -- Transform_Chromosome_To_CheddarADL_Model(Sys3 ,sol_init3); -- Write_To_Xml_File (A_System => Sys3, -- File_Name => To_string (Suppress_Space (To_Unbounded_String ("sol_init3" & ".xmlv3")))); -- -- -- end if; -- -- If Check_Feasibility_of_A_Solution (sol_init4, 0) then -- Put_Debug("===============sol_init4 evaluation ================"); -- evaluate_T2P (sol_init4, 0); -- archive_soln(sol_init4); -- update_grid(sol_init4); -- Append (Data3, " 0" & " " & sol_init4.obj(1)'img &" " &sol_init4.obj(2)'img &" " & sol_init4.obj(3)'img &" "& sol_init4.security_config'img &" "& ASCII.LF); -- Put_Debug ("sol4" & " " & sol_init4.obj(1)'img &" " &sol_init4.obj(2)'img &" " & sol_init4.obj(3)'img &" "& ASCII.LF); -- -- nb_InitSol:=nb_InitSol+1; -- -- Create_system (Sys4, sol_init4); -- Transform_Chromosome_To_CheddarADL_Model(Sys4 ,sol_init4); -- Write_To_Xml_File (A_System => Sys4, -- File_Name => To_string (Suppress_Space (To_Unbounded_String ("sol_init4" & ".xmlv3")))); -- -- -- end if; -- -- If Check_Feasibility_of_A_Solution (sol_init5, 0) then -- Put_Debug("===============sol_init5 evaluation ================"); -- evaluate_T2P (sol_init5, 0); -- archive_soln(sol_init5); -- update_grid(sol_init5); -- Append (Data3, " 0" & " " & sol_init5.obj(1)'img &" " &sol_init5.obj(2)'img &" " & sol_init5.obj(3)'img &" "& sol_init5.security_config'img &" "&ASCII.LF); -- Put_Debug ("sol5" & " " & sol_init5.obj(1)'img &" " &sol_init5.obj(2)'img &" " & sol_init5.obj(3)'img &" "& ASCII.LF); -- -- nb_InitSol:=nb_InitSol+1; -- -- Create_system (Sys5, sol_init5); -- Transform_Chromosome_To_CheddarADL_Model(Sys5 ,sol_init5); -- Write_To_Xml_File (A_System => Sys5, -- File_Name => To_string (Suppress_Space (To_Unbounded_String ("sol_init5" & ".xmlv3")))); -- -- -- -- end if; -- If Check_Feasibility_of_A_Solution (sol_init6, 0) then -- Put_Debug("===============sol_init6 evaluation ================"); -- evaluate_T2P (sol_init6, 0); -- archive_soln(sol_init6); -- update_grid(sol_init6); -- Append (Data3, " 0" & " " & sol_init6.obj(1)'img &" " &sol_init6.obj(2)'img &" " & sol_init6.obj(3)'img &" "& sol_init6.security_config'img &" "& ASCII.LF); -- Put_Debug ("sol6" & " " & sol_init6.obj(1)'img &" " &sol_init6.obj(2)'img &" " & sol_init6.obj(3)'img &" "& ASCII.LF); -- -- nb_InitSol:=nb_InitSol+1; -- -- Create_system (Sys6, sol_init6); -- Transform_Chromosome_To_CheddarADL_Model(Sys6 ,sol_init6); -- Write_To_Xml_File (A_System => Sys6, -- File_Name => To_string (Suppress_Space (To_Unbounded_String ("sol_init6" & ".xmlv3")))); -- -- end if; -- -- If Check_Feasibility_of_A_Solution (One_to_one_mapping_solution, 0) then If Check_Feasibility_of_A_Solution (c, 0) then evaluate_T2P (c, 0); Put_Debug("===============c evaluation finish================"); if (Float'Value(c.obj(1)'img)=0.0) and (Float'Value(c.obj(2)'img)=0.0) and (Float'Value(c.obj(3)'img)=0.0) then Put_debug("MissedDeadlines" & c.obj(1)'img &" Bell " & c.obj(2)'img &" Biba " & c.obj(2)'img ); Put_Debug("Simple design: no need for optimization"); archive_soln(c); Create_system_T2P (Sys7, c); Transform_Chromosome_To_CheddarADL_Model(Sys7 ,c); Write_To_Xml_File (A_System => Sys7, File_Name => To_string (Suppress_Space (To_Unbounded_String ("c" & ".xmlv3")))); OS_Exit(0); else archive_soln(c); update_grid(c); Append (Data3, " 0" & " " & c.obj(1)'img &" " &c.obj(2)'img &" " & c.obj(3)'img &" "& c.security_config'img &" "& ASCII.LF); nb_InitSol:=nb_InitSol+1; Create_system_T2P (Sys7, c); Transform_Chromosome_To_CheddarADL_Model(Sys7 ,c); Write_To_Xml_File (A_System => Sys7, File_Name => To_string (Suppress_Space (To_Unbounded_String ("c" & ".xmlv3")))); end if; else -- if c (that is supposed to be the first current solution) is non feasible if arclength>0 then -- if the archive is not empty c:=arc(1); --the first element of the archive becomes the first current solution else Put_Debug("All the initial solutions are non feasible"); return; end if; end if; end init_T2P; ---------------- -- mutate_F2T -- ---------------- procedure mutate_F2T (s : in out solution; eidx : in Natural) is random_task, fn : integer; A_system : System; A_Task_set, New_Task_set : Tasks_Set; Nb_tasks, New_nb_tasks : integer; period_fn, period_j : natural; harmonic_tasks : chrom_type; tmp_mod, k, j, counter : integer; is_harmonic, exist : boolean; Sol_is_mutated : boolean; A_sol : solution; Nb_harmonic_tasks : integer; G : Ada.Numerics.Float_Random.Generator; New_resource_set : Resources_Set; begin Create_system (A_system); sol_is_mutated := false; reset(G); -- Initialise the float generator -- I think, we should add a counter, if this counter reach a threashold -- and it failed to generate a mutated solution then we stop counter := 1; while (not sol_is_mutated) and (counter <= 100000) loop Put_Debug ("................................................................"); Put_Debug ("The " & counter'img & " attempt of the mutation procedure "); Put_Debug ("................................................................"); A_sol := s; Transform_Chromosome_To_CheddarADL_Model (A_system, A_sol); Nb_tasks := Number_of_tasks (A_sol); fn := 0; -- choose randomly an index of a function between 1 and genes while (fn > genes) or (fn < 1) loop fn := integer (float(genes) * random(G)); end loop; Put_Debug ("The randomly chosen function is : " & fn'img); -- determine the set of harmonic tasks with the choosen function fn K := 0; period_fn := Get (My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & fn'Img)), Param_Name => Period); for j in 1 .. Nb_tasks loop period_j := Get (My_Tasks => A_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & j'Img)), Param_Name => Period); if period_fn > period_j then tmp_mod := period_fn mod period_j; else tmp_mod := period_j mod period_fn; end if; if tmp_mod = 0 then Put_Debug ("period_fn = " & period_fn'Img & " period_j = " & period_j'Img); k := k + 1; harmonic_tasks (k) := j; Put_Debug ("harmonic_tasks (" & k'Img & ") = " & j'Img); end if; end loop; nb_harmonic_tasks := k; -- if the set of tasks which are harmonic with "fn" is not empty -- else i.e the function fn is not harmonic with any task, only its own task -- then we repeat the procedure with another function chosen randomly if nb_harmonic_tasks /= 0 then -- choose randomly a task random_task over tasks in the set harmonic_tasks -- (including tau_j = chrom[fn]); is_harmonic := false; while (not is_harmonic) loop random_task := 0; -- generate a random number of task comprised between 1 and nb_tasks while (random_task > nb_tasks) or (random_task < 1) loop random_task := integer (float(nb_tasks) * random(G)); end loop; Put_Debug ("nb_tasks =" & nb_tasks'img & " and The task chosen randomly is :" & random_task'img); Put_Debug ("The harmonic tasks with " & fn'Img & " are: "); for j in 1 .. nb_harmonic_tasks loop Put_Debug (" " & harmonic_tasks (j)'Img); end loop; Put_Debug(" ");--New_Line; -- verify if random_task is among the set of harmonic tasks j := 1; exist := false; while (not exist) and (j <= nb_harmonic_tasks) loop if random_task = harmonic_tasks (j) then exist := true; end if; j := j + 1; end loop; if exist then is_harmonic := true; end if; end loop; if (random_task /= A_sol.chrom_task(fn)) then -- if the function "fn" is not intially in -- the task "random_task" the "fn" is moved -- to the task "random_task" A_sol.chrom_task(fn) := random_task; sol_is_mutated := true; elsif (not is_isolated (fn, A_sol)) then -- if coincidentally the function "fn" is intially in the task "random_task" -- then if the function "fn" is not initially isolated, we create a new task -- in which we isolate it -- else i.e the function "fn" is alone then we repeat the procedure with another function -- chosen randomly A_sol.chrom_task(fn) := nb_tasks + 1; sol_is_mutated := true; end if; end if; if sol_is_mutated then Put_Debug(" "); Put_Debug ("The mutated solution is : "); print_debug_genome(A_sol); Put_Debug(" "); -- normalize the mutate solution normalize(A_sol); Put_Debug(" "); Put_Debug ("After normalization the candidate solution is : "); print_debug_genome(A_sol); Put_Debug(" "); -- After generating a mutate solution, we shoud verify -- if it is feasible else we must regenerate a new candidate solution: -- If Check_Feasibility_of_A_Solution (A_sol,eidx) then Put_Debug (" The candidate solution is feasible"); New_nb_tasks := Number_of_tasks (A_sol); sol_is_mutated := true; s := A_sol; else Put_Debug (" The candidate solution is NOt Feasible " & " we should regenerate another candidate solution"); sol_is_mutated := false; counter := counter + 1; end if; end if; end loop; if counter > 100000 then Put_Debug(" ");--New_Line; Put_Debug(" ");--New_Line; Put_Debug("Exit the program, there is no schedulable candidate solution !"); Put_Debug(" ");--New_Line; Put_Debug(" ");--New_Line; OS_Exit (0); end if; end mutate_F2T; -------mutate_T2P----------- ---------------------------- ---------------------------- procedure mutate_T2P (s : in out solution; eidx : in Natural) is random_partition, random_app, tn, x, half_iter, cn, finish,sol_config : integer; -- random_proc: integer; -- DW_link: integer; l:integer:=0; A_system : System; A_Task_set, New_Task_set : Tasks_Set; -- Nb_partitions : integer; -- period_fn, period_j : natural; -- harmonic_tasks : chrom_type; counter : integer; -- is_harmonic, exist : boolean; Sol_is_mutated : boolean; A_sol : solution; -- Nb_harmonic_tasks : integer; G : Ada.Numerics.Float_Random.Generator; New_resource_set : Resources_Set; A_task_source : Generic_Task_Ptr; A_task_sink : Generic_Task_Ptr; begin Create_system_T2P (A_system, s); sol_is_mutated := false; reset(G); -- Initialise the float generator half_iter:=iterations/2; -- half_iter:=3*iterations/4; Put_Line("half_iter: " & half_iter'Img); -- genes_init := genes; -- I think, we should add a counter, if this counter reach a threashold -- and it failed to generate a mutated solution then we stop counter := 1; -- Put_Line("task to app"); -- New_Line; -- for i in 1..genes loop -- Put (task_to_app(i)'Img & " "); -- end loop; -- New_Line; while (not sol_is_mutated) and (counter <= 100000) loop Put_Debug ("................................................................"); Put_Debug ("The " & counter'img & " attempt of the mutation procedure "); Put_Debug ("................................................................"); Put_Debug ("................................................................"); Put_Debug ("The " & counter'img & " attempt of the mutation procedure "); Put_Debug ("................................................................"); A_sol := s; Put_Debug ("The randomly chosen version is : " & A_sol.exploration_version'img); Put_Line ("The randomly chosen version is : " & A_sol.exploration_version'img); random_partition := 0; -- generate a random number of partition comprised between 1 and nb_partitions -- reset(G); -- Initialise the float generator while (random_partition > nb_partitions) OR (random_partition < 1) loop random_partition := integer (float(nb_partitions) * random(G)); end loop; Put_Debug ("The randomly chosen partition is : " & random_partition'img); Put_Line ("The randomly chosen partition is : " & random_partition'img); Put_Line("iterrrrrrrrrrr :" & iter'Img); If ( A_sol.exploration_version=1) OR (( A_sol.exploration_version=2) AND (iter nb_app) OR (random_app < 1) loop random_app := integer (float(nb_app) * random(G)); end loop; Put_Debug ("The randomly chosen application is : " & random_app'img); Put_Line ("The randomly chosen application is : " & random_app'img); for l in 1..genes loop -- if (task_to_app(l)=random_app) and (A_sol.chrom_task(l)/=random_partition) then if (task_to_app(l)=random_app) then A_sol.chrom_task(l):=random_partition; end if; sol_is_mutated := true; end loop; elsif (A_sol.exploration_version=3) OR ((A_sol.exploration_version=2) AND (iter>=half_iter)) then -- exploration_version=1: Tasks of an application can be on different partitions (tasks mutation) -- choose randomly an index of a task between 1 and genes tn := 0; while (tn > genes) or (tn < 1) loop tn := integer (float(genes) * random(G)); end loop; Put_Debug ("The randomly chosen task is : " & tn'img); -- Put_Line ("The randomly chosen task is : " & tn'img); -- the task "tn" is not intially in the partition "random_partition" then "tn" is moved -- to the partition "random_partition" if (random_partition /= A_sol.chrom_task(tn)) then A_sol.chrom_task(tn) := random_partition; sol_is_mutated := true; -- elsif not (is_isolated (tn, A_sol)) then -- -- if coincidentally the task "tn" is initially in the task "random_partition" -- -- then if the task "tn" is not initially isolated, we create a new partition -- -- in which we isolate it -- A_sol.chrom_task(tn) := Nb_partitions + 1; -- sol_is_mutated := true; end if; end if; --- We are using one processor unit -- then we assigned all the partitions to that single processor unit -- for i in 1..nb_partitions loop -- for i in 1..Number_of_partitions(A_sol) loop -- Assign all the tasks to the same core -- for i in 1..genes loop -- A_sol.chrom_task_core(i):=1; -- end loop; -- --Assign all the partitions to the same core -- for i in 1..nb_partitions+1 loop -- A_solution.chrom_partition_PU(i) := 1; -- end loop; -- -- choose randomly the configuration to secure communications sol_config:=0; reset(G); -- Initialise the float generator while (sol_config > 15) or (sol_config < 1) loop sol_config := integer (15.0 * random(G)); end loop; A_sol.security_config:=sol_config; Put_Debug ("The chosen configuration is : " & sol_config'img); Put ("The chosen configuration is : " & sol_config'img); -- communication mutation -- choose randomly an index of a task between 1 and genes_com between risky communications x:=0; while (x > Nb_NonSecure_low) or (x < 1) loop x := Integer(float(Nb_NonSecure_low) * random(G)); end loop; cn := NonSecure_list(x); Put_Debug ("The randomly chosen communication is : " & cn'img); -- Put_Line ("The randomly chosen communication is : " & cn'img); Put_Debug ("This chosen communication is : " & To_String(s.chrom_com(cn).source_sink)); -- Put_Line ("This chosen communication is : " & To_String(s.chrom_com(cn).source_sink)); finish := index(A_sol.chrom_com(cn).source_sink,"_"); A_task_source := Search_Task (Initial_System.Tasks, Suppress_Space (Unbounded_Slice(s.chrom_com(cn).source_sink,1,finish-1))) ; A_task_sink := Search_Task (Initial_System.Tasks, Suppress_Space (Unbounded_Slice(s.chrom_com(cn).source_sink,finish+1,Length(s.chrom_com(cn).source_sink)))); if (A_task_sink.mils_confidentiality_level< A_task_source.mils_confidentiality_level) OR (A_task_source.mils_integrity_level< A_task_sink.mils_integrity_level)then if ((A_task_sink.mils_task/=Downgrader) AND (A_task_sink.mils_task/=Upgrader)AND (A_task_source.mils_task/=Downgrader)AND (A_task_source.mils_task/=Upgrader)) then if (A_sol.chrom_com(cn).mode = noDW) then A_sol.chrom_com(cn).mode := emission; -- DW at emission (we suppose that a DW should always be at the emission) -- DW linked to the communication A_sol.chrom_com(cn).link := communication; -- Choose randomly if the added Downgrader should be linked to -- task (DW_link = 1) -- or communication (DW_link = 2) -- or partition (DW_link = 3) -- DW_link := 0; -- -- while (DW_link > 3) or (DW_link < 1) loop -- DW_link := integer (float(3) * random(G)); -- end loop; -- -- if (DW_link = 1) then -- A_sol.chrom_com(cn).link := tsk; -- DW linked to the task -- elsif (DW_link = 2) then -- DW linked to the communication -- A_sol.chrom_com(cn).link := communication; -- elsif (DW_link = 3) then -- DW linked to the partition -- A_sol.chrom_com(cn).link := partition; -- end if; sol_is_mutated := true; -- elsif (A_sol.chrom_com(cn).mode = emission) or (A_sol.chrom_com(cn).mode = reception) then elsif ( A_sol.chrom_com(cn).link = communication) then A_sol.chrom_com(cn).mode := noDW; A_sol.chrom_com(cn).link := noDW; sol_is_mutated := true; end if; end if; end if; -- -- elsif (not is_isolated (tn, A_sol)) then -- -- if coincidentally the task "tn" is intially in the task "random_task" -- -- then if the task "tn" is not initially isolated, we create a new task -- -- in which we isolate it -- -- else i.e the function "fn" is alone then we repeat the procedure with another function -- -- chosen randomly -- A_sol.chrom(fn) := nb_tasks + 1; -- sol_is_mutated := true; -- end if; -- -- end if; if sol_is_mutated then Put_Debug(" "); Put_Debug ("The mutated solution is : "); print_debug_genome(A_sol); Put_Debug(" "); -- normalize the mutate solution normalize(A_sol); Put_Debug(" "); Put_Debug ("After normalization the candidate solution is : "); Put_Line("After normalization the candidate solution is : "); print_debug_genome(A_sol); Put_Debug(" "); -- After generating a mutate solution, we shoud verify -- if it is feasible else we must regenerate a new candidate solution: -- If Check_Feasibility_of_A_Solution (A_sol,eidx) then Put_Debug (" The candidate solution is feasible"); -- New_nb_tasks := Number_of_tasks (A_sol); sol_is_mutated := true; s := A_sol; nb_secu_conf_choice(sol_config):=nb_secu_conf_choice(sol_config)+1; else Put_Debug (" The candidate solution is NOt Feasible " & " we should regenerate another candidate solution"); sol_is_mutated := false; counter := counter + 1; nb_NoFeasible_Sol := nb_NoFeasible_Sol+1; -- genes := genes_init; end if; end if; end loop; if counter > 100000 then Put_Debug(" ");--New_Line; Put_Debug(" ");--New_Line; Put_Debug("Exit the program, there is no schedulable candidate solution !"); Put_Debug(" ");--New_Line; Put_Debug(" ");--New_Line; OS_Exit (0); end if; end mutate_T2P; -------------------------------- -- generate_next_solution_F2T -- -------------------------------- procedure generate_next_solution_F2T (s : in out solution; m : in out chrom_Type; space_search_is_exhausted : out boolean) is i,max : integer; begin -- Update s: 1 1 1 1 -> 2 1 1 1 -> 1 2 1 1 -> 2 2 1 1 -> 3 2 1 1 -> 1 1 2 1 ... i := 1; s.chrom_task(i) := s.chrom_task(i) + 1; while ((i < genes) and (s.chrom_task(i) > m(i) + 1)) loop s.chrom_task(i) := 1; i := i + 1; s.chrom_task(i) := s.chrom_task(i) + 1; end loop; -- If i is has reached n-1 th element, then the last unique partitiong -- has been found -- if (i = genes) then space_search_is_exhausted := true; else -- Because all the first i elements are now 1, s[i] (i + 1 th element) -- is the largest. So we update max by copying it to all the first i -- positions in m. max := s.chrom_task(i); if (m(i) > max) then max := m(i); end if; for j in 1 .. i-1 loop m(j) := max; end loop; space_search_is_exhausted := false; end if; end generate_next_solution_F2T; ----------------- -- is_isolated -- ----------------- function is_isolated(function_index : integer; s : solution) return boolean is result : boolean := true; i : integer := 1; begin while (result and i <= genes) loop if (s.chrom_task(i) = s.chrom_task(function_index)) and then (function_index /= i) then result := false; end if; i := i + 1; end loop; return result; end is_isolated; --------------- -- Normalize -- --------------- procedure normalize(s : in out solution) is nb_tasks : integer := 1; -- the vector var is used to know if a gene is normalized or not yet var : chrom_Type; begin -- initialization of the vector var. for i in 1..genes loop var(i) := 0; end loop; ------------------------------------------------------------ -- if var(i) = 0 ==> s.chrom(i) is not yet normalized -- if var(i) = 1 ==> s.chrom(i) is normalized ------------------------------------------------------------ for i in 1..genes loop if (var(i) = 0) then for j in i+1..genes loop if (s.chrom_task(j) = s.chrom_task(i)) and then (var(j) = 0) then var(j) := 1; -- if s.chrom(i) is not normalized then all s.chrom(j) (which egal s.all.chrom(i)) -- are not normalized if (s.chrom_task(i) /= nb_tasks) then s.chrom_task(j) := nb_tasks; end if; end if; end loop; -- we normalize s.chrom(i) if (s.chrom_task(i) /= nb_tasks) then s.chrom_task(i) := nb_tasks; end if; var(i) := 1; nb_tasks := nb_tasks + 1; end if; end loop; end normalize; -------------normalize_T2P---------------- ------------------------------------------ ------------------------------------------ procedure normalize_T2P(s : in out solution) is nb_partitions : integer := 1; -- nb_proc: Integer:=1; -- the vector var is used to know if a gene is normalized or not yet var : chrom_Type; begin -- initialization of the vector var. for i in 1..genes loop var(i) := 0; -- var2(i) :=0; end loop; ------------------------------------------------------------ -- if var(i) = 0 ==> s.chrom(i) is not yet normalized -- if var(i) = 1 ==> s.chrom(i) is normalized ------------------------------------------------------------ for i in 1..genes loop if (var(i) = 0) then for j in i+1..genes loop if (s.chrom_task(j) = s.chrom_task(i)) and then (var(j) = 0) then var(j) := 1; -- if s.chrom(i) is not normalized then all s.chrom(j) (which egal s.all.chrom(i)) -- are not normalized if (s.chrom_task(i) /= nb_partitions) then s.chrom_task(j) := nb_partitions; end if; end if; end loop; -- we normalize s.chrom(i) if (s.chrom_task(i) /= nb_partitions) then s.chrom_task(i) := nb_partitions; end if; var(i) := 1; nb_partitions := nb_partitions + 1; end if; end loop; end normalize_T2P; --------------------- -- number_of_tasks -- --------------------- function Number_of_tasks (s : in solution) return integer is permutation : integer := 1; var : chrom_type; nb_tasks, tmp : integer; begin -- assignment of the table var with elements of s.chrom for i in 1..genes loop var(i) := s.chrom_task(i); end loop; -- sorting elements of var in the increasing order while permutation = 1 loop permutation := 0; for i in 1..genes-1 loop if (var(i) > var(i+1)) then tmp := var(i); var(i) := var(i+1); var(i+1) := tmp; permutation := 1; end if; end loop; end loop; nb_tasks := genes; for i in 1..genes-1 loop if (var(i) = var(i+1)) then nb_tasks := nb_tasks - 1; end if; end loop; return nb_tasks; end Number_of_tasks; --------Number_of_partitions--------- ------------------------------------- ------------------------------------- function Number_of_partitions (s : in solution) return integer is permutation : integer := 1; var : chrom_type; nb_partitions, tmp : integer; begin -- assignment of the table var with elements of s.chrom for i in 1..genes loop var(i) := s.chrom_task(i); end loop; -- sorting elements of var in the increasing order while permutation = 1 loop permutation := 0; for i in 1..genes-1 loop if (var(i) > var(i+1)) then tmp := var(i); var(i) := var(i+1); var(i+1) := tmp; permutation := 1; end if; end loop; end loop; nb_partitions := genes; for i in 1..genes-1 loop if (var(i) = var(i+1)) then nb_partitions := nb_partitions - 1; end if; end loop; return nb_partitions; end Number_of_partitions; ---------------------------------------------- -- Transform_Chromosome_To_CheddarADL_Model -- ---------------------------------------------- procedure Transform_Chromosome_To_CheddarADL_Model (A_sys : in out System; s : in solution) is A_Tasks_set : Tasks_Set; A_Task : Periodic_Task; nb_tasks,k,A_function_index : integer; period_i, period_j : natural; capacity_i, capacity_j : natural; deadline_i, deadline_j : natural; var : chrom_type; A_task_name : Unbounded_String; Initial_number_of_resources : Resources_Range; Nb_critical_sections_of_Resource_i : Resource_Accesses_Range; A_Resources_set : Resources_Set; A_resource : Generic_Resource_Ptr; r : critical_section; rt, rt2 : Resource_Accesses_Table; Is_shared : boolean; tab : array (Resource_Accesses_Range) of integer; begin -- 1) Generate the tasks set from the solution s -- nb_tasks := number_of_tasks(s); Initialize (A_Task); for i in 1..genes loop var(i) := 0; end loop; k := 1; for i in 1..genes loop Put_Debug ("i = " & i'img); Initialize (A_Task); if var(i) = 0 then var (i) := 1; period_i := Get (My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & i'Img)), Param_Name => Period); Put_Debug ("period_i = " & period_i'img); capacity_i := Get (My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & i'Img)), Param_Name => Capacity); Put_Debug ("capacity_i = " & capacity_i'img); deadline_i := Get (My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & i'Img)), Param_Name => Deadline); Put_Debug ("deadline_i = " & deadline_i'img); for j in i+1 .. genes loop if (s.chrom_task(i) = s.chrom_task(j)) then var (j) := 1; period_j := Get(My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & j'Img)), Param_Name => Period); capacity_j := Get(My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & j'Img)), Param_Name => Capacity); deadline_j := Get(My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & j'Img)), Param_Name => Deadline); if (A_Task.period = 0) then A_Task.capacity := capacity_i + capacity_j; if period_i > period_j then A_Task.period := period_j; else A_Task.period := period_i; end if; if deadline_i > deadline_j then A_Task.deadline := deadline_j; else A_Task.deadline := deadline_i; end if; else A_Task.capacity := A_Task.capacity + capacity_j; if A_Task.period > period_j then A_Task.period := period_j; end if; if A_Task.deadline > deadline_j then A_Task.deadline := deadline_j; end if; end if; end if; end loop; if (A_Task.period = 0) then A_Task.period := period_i; A_Task.capacity := capacity_i; A_Task.deadline := deadline_i; end if; Add_Task(My_Tasks => A_Tasks_set, Name => Suppress_Space (To_Unbounded_String ("Task" & k'Img)), Cpu_Name => To_Unbounded_String("processor1"), Address_Space_Name => To_Unbounded_String("addr1"), core_name => Suppress_Space (To_Unbounded_String("")), Task_Type => Periodic_Type, Start_Time => 0, Capacity => A_Task.capacity, Period => A_Task.period, Deadline => A_Task.deadline, Jitter => 0, Blocking_Time => 0, Priority => Task_priority, Criticality => 0, Policy => Sched_policy); k := k + 1; end if; end loop; A_sys.Tasks := A_Tasks_set; -- 2) Deduce the resources set from the solution s Initial_number_of_resources := Get_Number_Of_Resource_From_Processor (Initial_system.Resources, To_Unbounded_String("processor1")); Put_debug ("Initial_number_of_resources = " & Initial_number_of_resources'img); for i in 1 .. Initial_number_of_resources loop Initialize(rt); -- Extracting all resources of the initial system model -- in which each function is assigned to a task -- So, in the initial system model there is no difference -- between a task or a function (Function1 == Task1) A_resource := search_Resource (Initial_System.Resources, suppress_space (To_Unbounded_String ("R" & i'Img))); Nb_critical_sections_of_Resource_i := A_resource.critical_sections.nb_entries; for j in 0 .. Nb_critical_sections_of_Resource_i - 1 loop -- A task name is in the form "Taskxxx" -- where xxx is the index of the task (i.e the function) -- Here, we trait resources of the initial model -- were each Task represent a function i.e. Task1 => Function1 -- Task2 => Function2 ... A_task_name := A_resource.Critical_sections.entries(j).item; A_function_index := Integer'Value (to_string (Unbounded_Slice (A_task_name,length(To_Unbounded_String("Task"))+1,length(A_task_name)))); -- Compute new critical_section_j of the Resource_i k := 1; r.task_begin := A_resource.Critical_sections.entries(j).data.task_begin; r.task_end := A_resource.Critical_sections.entries(j).data.task_end; While (k < A_function_index) loop if s.chrom_task(k) = s.chrom_task(A_function_index) then r.task_begin := r.task_begin + Get (My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & k'Img)), Param_Name => Capacity); r.task_end := r.task_end + Get (My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("Task" & k'Img)), Param_Name => Capacity); end if; k := k + 1; end loop; -- Add the computed critical_section_j to the table of -- critical sections of the Resource_i add (rt, Suppress_Space (To_Unbounded_String ("Task" & Integer'Image(s.chrom_task(A_function_index)))), r); end loop; -- There is two cases that we have to deal with : -- --1) Case_1 : Check if there are consecutive critical sections for the same task -- For example, the computation of new critical-sections (CSs) according to the solution s, -- gives the following CSs: -- Task1 task_begin=2 task_end=3 (**) -- the function accessing the CS is assigned to Task1 -- Task2 task_begin=1 task_end=1 -- the function accessing the CS is assigned to Task2 -- Task1 task_begin=4 task_end=4 (**) -- the function accessing the CS is assigned to Task1 -- -- => The two critical-sections marked (**) are consecutive, so It's better -- to merge them in the same CS, the resulting CSs are : -- Task1 task_begin=2 task_end=4 -- Task2 task_begin=1 task_end=1 -- -- 2) Case_2 : Check if the resource_i is accessed by a single task i.e all -- critical sections of the resource_i corresponds to the same task, -- in other words, all functions that access the resource_i are assigned -- to the same task. -- For example, the computation of new critical-sections (CSs) according to the solution s, -- gives the following CSs: -- Task1 task_begin=2 task_end=3 -- Task1 task_begin=1 task_end=1 -- Task1 task_begin=5 task_end=6 -- -- => In this case, the resource_i is used only by the Task1, so It is no longer shared -- between tasks, for that, we no longer need to consider it in the conccurency model -- (i.e the analysis model) -- -- Is_shared := false; for j in 0 .. rt.nb_entries - 1 loop tab(j) := 0; end loop; for j in 0 .. rt.nb_entries - 1 loop if tab(j) = 0 then tab(j) := 1; for l in j+1 .. rt.nb_entries - 1 loop if tab(l) = 0 then if (rt.entries(j).item = rt.entries(l).item) then tab(l) := 1; -- check if critical sections of rt.entries(l) and rt.entries(j) are consecutive if (rt.entries(l).data.task_begin = (rt.entries(j).data.task_end + 1)) then rt.entries(j).data.task_end := rt.entries(l).data.task_end; tab(l) := 2; -- rt.entries(l) sould be deleted after because, -- its critical section is concatenated in the -- critical section of rt.entries(j) elsif (rt.entries(j).data.task_begin = (rt.entries(l).data.task_end + 1)) then rt.entries(j).data.task_begin := rt.entries(l).data.task_begin; tab(l) := 2; -- rt.entries(l) sould be deleted after because -- its critical section is concatenated in the -- critical section of rt.entries(j) end if; else -- The resource_i is shared by at least 2 tasks Is_shared := true; end if; end if; end loop; end if; end loop; -- delete rt.entries(l) whose critical sections are merged in other critical sections Initialize (rt2); for j in 0 .. rt.nb_entries - 1 loop if tab(j) /= 2 then rt2.entries(rt2.nb_entries) := rt.entries(j); rt2.nb_entries := rt2.nb_entries + 1; end if; end loop; -- Add the resource to the system "A_sys" only if -- it is shared by at least 2 tasks if Is_shared then Add_Resource (A_Resources_set, suppress_space (To_Unbounded_String ("R" & i'Img)), 1, 0, 0, To_Unbounded_String ("processor1"), To_Unbounded_String ("addr1"), Priority_Ceiling_Protocol, rt2, 0, Automatic_Assignment); end if; end loop; A_sys.Resources := A_Resources_set; end Transform_Chromosome_To_CheddarADL_Model; ------------------Transform_Chromosome_To_CheddarADL_Model_T2P------------- --------------------------------------------------------------------------- procedure Transform_Chromosome_To_CheddarADL_Model_T2P (A_sys : in out System; s : in solution) is A_Tasks_set : Tasks_Set; A_Task : Periodic_Task; k : integer; -- A_function_index : integer; period_i : natural; capacity_i : natural; deadline_i : natural; priority_i : natural; criticality_i : natural; confidentiality_i, integrity_i : Unbounded_String; begin -- 1) Generate the tasks set from the solution s -- -- nb_tasks := number_of_tasks(s); Initialize (A_sys.Tasks); Initialize(A_sys.Dependencies.Depends); for i in 1..genes loop k := s.chrom_task(i); -- l:= s.chrom_partition_PU(k); period_i := Get(My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("" & i'Img)), Param_Name => Period); capacity_i := Get(My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("" & i'Img)), Param_Name => Capacity); deadline_i := Get(My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("" & i'Img)), Param_Name => Deadline); priority_i:= Get(My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("" & i'Img)), Param_Name => Priority); criticality_i:= Get(My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("" & i'Img)), Param_Name => Criticality); confidentiality_i := Get(My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("" & i'Img)), Param_Name => mils_confidentiality_level); integrity_i := Get(My_Tasks => Initial_system.Tasks, Task_Name => Suppress_Space (To_Unbounded_String ("" & i'Img)), Param_Name => mils_integrity_level); Add_Task(My_Tasks => A_sys.Tasks, Name => Suppress_Space (To_Unbounded_String ("" & i'Img)), Cpu_Name => Suppress_Space (To_Unbounded_String("processor1")), Address_Space_Name => Suppress_Space (To_Unbounded_String ("addr" & k'Img)), core_name => Suppress_Space (To_Unbounded_String("")), Task_Type => Periodic_Type, Start_Time => 0, Capacity => capacity_i, Period => period_i, Deadline => deadline_i, Jitter => 0, Blocking_Time => 0, Priority => priority_i, Criticality => criticality_i, Policy => Sched_policy, mils_confidentiality_level => MILS_Confidentiality_Level_Type'value( To_String(confidentiality_i)), mils_integrity_level => MILS_Integrity_Level_Type'value( To_String(integrity_i)) ); New_Line; end loop; -- 2) Generate the dependencies and secure the system depending on the choosen security configuration -- nb_bell_resolved:=0; nb_biba_resolved:=0; if (s.security_config = 1)then security_configuration1(A_sys, s); elsif (s.security_config = 2)then security_configuration2(A_sys, s); elsif (s.security_config = 3)then security_configuration3(A_sys, s); elsif (s.security_config = 4)then security_configuration4(A_sys, s); elsif (s.security_config =5)then security_configuration5(A_sys, s); elsif (s.security_config = 6)then security_configuration6(A_sys, s); elsif (s.security_config = 7)then security_configuration7(A_sys, s); elsif (s.security_config = 8)then security_configuration8(A_sys, s); elsif (s.security_config =9)then security_configuration9(A_sys, s); elsif (s.security_config = 10)then security_configuration10(A_sys, s); elsif (s.security_config =11)then security_configuration11(A_sys, s); elsif (s.security_config = 12)then security_configuration12(A_sys, s); elsif (s.security_config = 13)then security_configuration13(A_sys, s); elsif (s.security_config = 14)then security_configuration14(A_sys, s); elsif (s.security_config =15)then security_configuration15(A_sys, s); end if; -- consider inter and intra communications overheads com_overhead(A_sys); Put_Debug("end_transform"); end Transform_Chromosome_To_CheddarADL_Model_T2P; ------------------------------------------- -- consider inter and intra partition -- ------------------------------------------- Procedure com_overhead(A_sys : in out System) is My_iterator: Tasks_Dependencies_Iterator; Dep_Ptr: Dependency_Ptr; My_dependencies: Tasks_Dependencies_Ptr; begin My_dependencies:=A_sys.Dependencies; if is_empty( My_dependencies.Depends) then Put_Line("NO dependencies"); else 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=Dep_Ptr.precedence_sink.address_space_name)then -- if (Integer'Value (To_String (Suppress_Space (Dep_Ptr.precedence_source.name))) <= 19) then -- display_blackboard_time:=1; -- read_blackboard_time:=1; -- elsif (Integer'Value (To_String (Suppress_Space (Dep_Ptr.precedence_source.name))) > 19) -- AND (Integer'Value (To_String (Suppress_Space (Dep_Ptr.precedence_source.name))) <= 26) then -- display_blackboard_time:=7714; -- read_blackboard_time:=9947; -- else -- display_blackboard_time:=157; -- read_blackboard_time:=201; -- end if; Dep_Ptr.precedence_source.capacity:= Dep_Ptr.precedence_source.capacity+display_blackboard_time; Dep_Ptr.precedence_sink.capacity:= Dep_Ptr.precedence_sink.capacity+read_blackboard_time; else -- if (Integer'Value (To_String (Suppress_Space (Dep_Ptr.precedence_source.name))) <= 19) then -- read_sampling_port_time:=1; -- write_sampling_port_time:=1; -- elsif (Integer'Value (To_String (Suppress_Space (Dep_Ptr.precedence_source.name))) > 19) -- AND (Integer'Value (To_String (Suppress_Space (Dep_Ptr.precedence_source.name))) <= 26) then -- read_sampling_port_time:=43037; -- write_sampling_port_time:=51208; -- else -- read_sampling_port_time:=868; -- write_sampling_port_time:=1033; -- -- end if; Dep_Ptr.precedence_source.capacity:= Dep_Ptr.precedence_source.capacity+write_sampling_port_time; Dep_Ptr.precedence_sink.capacity:= Dep_Ptr.precedence_sink.capacity+read_sampling_port_time; end if; exit when is_last_element (My_Dependencies.Depends, My_Iterator); next_element (My_Dependencies.Depends, My_Iterator); end loop; end if; end com_overhead; -- communication_cost -- ------------------- Procedure communication_cost(sys: in system; com_cost: out com_cost_type)is My_iterator: Tasks_Dependencies_Iterator; Dep_Ptr: Dependency_Ptr; My_dependencies: Tasks_Dependencies_Ptr; begin My_dependencies:=sys.Dependencies; if is_empty( My_dependencies.Depends) then Put_Line("NO dependencies"); else for i in 1..5 loop com_cost(i):=0.0; end loop; 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=Dep_Ptr.precedence_sink.address_space_name)then com_cost(1):=com_cost(1)+1.0; com_cost(2):=com_cost(2)+1.0; com_cost(5):=com_cost(5)+Float (display_blackboard_time*(Hyperperiod_of_Initial_Taskset/Dep_Ptr.precedence_source.deadline)+read_blackboard_time*(Hyperperiod_of_Initial_Taskset/Dep_Ptr.precedence_sink.deadline)); else com_cost(3):=com_cost(3)+1.0; com_cost(4):=com_cost(4)+1.0; com_cost(5):=com_cost(5)+Float (write_sampling_port_time*(Hyperperiod_of_Initial_Taskset/Dep_Ptr.precedence_source.deadline)+read_sampling_port_time*(Hyperperiod_of_Initial_Taskset/Dep_Ptr.precedence_sink.deadline)); end if; exit when is_last_element (My_Dependencies.Depends, My_Iterator); next_element (My_Dependencies.Depends, My_Iterator); end loop; end if; end communication_cost; ------------------- -- Create_system -- ------------------- Procedure Create_system (A_system : in out System) is a_core : core_unit_ptr; a_core_unit_table : Core_Units_Table; mem : Memories_Table; begin Initialize(A_System); Add_Address_Space (A_System.address_spaces, To_unbounded_string("addr1"), To_unbounded_string("processor1"), 0, 0, 0, 0); Add_core_unit(My_core_units => A_System.core_units, A_core_unit => a_core, Name => to_unbounded_string("core1"), Is_Preemptive => preemptive, Quantum => 0, speed => 1, capacity => 0, period => 0, Priority => 0, File_Name => to_unbounded_string(""), A_Scheduler => The_scheduler, mem => mem); Add (a_core_unit_table, a_core); Add_Processor(My_Processors => A_System.processors, Name => to_unbounded_string("processor1"), a_Core => a_core); end Create_system; -- Create_system_T2P -- ------------------- Procedure Create_system_T2P (A_system : in out System; s : in solution) is a_core : core_unit_ptr; a_core_unit_table : Core_Units_Table; mem : Memories_Table; partition_sched_file_name: Unbounded_String; nb_part: integer; begin Initialize(A_System); -- Put_Line("nb_proc : " & nb_proc'Img); -- Put_Line("nb_partitions : " & nb_partitions'Img); -- for j in 1..nb_proc loop -- Generate partitions for i in 1..Number_of_partitions(s) loop -- for i in 1.. nb_partitions loop -- if (s.chrom_partition_PU(i)=j) then Add_Address_Space (My_Address_Spaces => A_system.address_spaces, Name => Suppress_Space (To_Unbounded_String ("addr" & i'Img)), Cpu_Name => Suppress_Space(To_unbounded_string("processor1")), Text_Memory_Size => 0, Stack_Memory_Size => 0, Data_Memory_Size => 0, Heap_Memory_Size => 0, A_Scheduler => POSIX_1003_HIGHEST_PRIORITY_FIRST_PROTOCOL); -- end if; end loop; if (s.exploration_version<10) then nb_part:=Number_of_partitions(s); else nb_part:=Number_of_partitions(s)+1; end if; partition_sched_file_name:=Suppress_Space(to_unbounded_string("partition_scheduling_paes"& nb_part'Img &".xml")); Add_core_unit(My_core_units => A_System.core_units, A_core_unit => a_core, Name => Suppress_Space(to_unbounded_string("core1")), Is_Preemptive => preemptive, Quantum => 0, speed => 1, capacity => 0, period => 0, Priority => 0, File_Name => partition_sched_file_name, A_Scheduler => The_scheduler, mem => mem); Add (a_core_unit_table, a_core); Add_Processor(My_Processors => A_System.processors, Name => Suppress_Space(to_unbounded_string("processor1")), a_Core => a_core); -- initialize(A_Table => a_core_unit_table); -- initialize(mem); -- initialize(a_core); -- end loop; end Create_system_T2P; end Chromosome_Data_Manipulation;