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.Os_Lib; with Objects; use Objects; with Memories; use Memories; use Memories.Memories_Table_Package; with Memory_set; use Memory_set; with Tasks; use Tasks; with Task_Set; use Task_Set; with Systems; use Systems; with Processors; use Processors; with Processor_Set; use Processor_Set; 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 batteries; use batteries; with battery_set; use battery_set; with Processor_Interface; use Processor_Interface; with Scheduler_Interface; use Scheduler_Interface; 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 priority_assignment.rm; use priority_assignment.rm; with Ada.Numerics; with Ada.Numerics.Float_Random; procedure Generate_amc_multicore is sys : System; a_core : Core_Unit_Ptr; a_processor : Generic_Processor_Ptr; a_core_unit_table : Core_Units_Table; msg : Unbounded_String; Feasibility_Interval : Double; validate : Boolean; Actual_CPU_Usage : Float :=0.0; N_Tasks : Integer := 8; N_Different_Periods : Integer :=0; Threshold_Quality : Natural :=0; N_High_Tasks : Natural := 0; N_Medium_Tasks : Natural := 0; Multicore_Parameter : Unbounded_string; first_time : Boolean := True; u_values : random_tools.float_array (0 .. 7); tab_criticality : integer_array (1 .. 8) := (2,2,2,2,0,0,0,0); cpu_utilization_values : float_array(1 .. 8):= (20.0,30.0,40.0,50.0,60.0,70.0,80.0,90.0); Target_Cpu_Usage : float := 50.0; coefficients : array (1 .. 3) of coefficient := (20,50,80); coef : coefficient := 50; file1 : Unbounded_string; file2 : Unbounded_string; file3 : Unbounded_string; file4 : Unbounded_string; seed : Natural := 0; cpu_used_factor : Float := 1.0; core_name : Unbounded_string; 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; function compute_criticality(NT: integer) return integer_array is tab_criticality : integer_array (1 .. NT); begin for i in 1 .. NT loop if (i mod 2) = 0 then tab_criticality(i) := 2; else tab_criticality(i) := 0; end if; end loop; shuffle_an_array(tab_criticality); return tab_criticality; end compute_criticality; function compute_period(NT : integer) return integer_array is tab_period : integer_array (1 .. NT); var : Natural := 1; counter : Natural := NT; t_values : random_tools.integer_array (1 .. 8) := (2000,2500,1500,3000,3750,5000,10000,6000); begin while counter /= 0 loop if (var mod 9) = 0 then var := 1; end if; tab_period(counter) := t_values(var); counter := counter - 1; var := var + 1; end loop; -- shuffle period array shuffle_an_array(tab_period); return tab_period; end compute_period; begin declare tab_criticality : integer_array (1 .. N_Tasks); tab_period : integer_array (1 .. N_Tasks); u_values : random_tools.float_array (0 .. N_Tasks-1); begin -- fill criticality tab tab_criticality := compute_criticality(N_Tasks); -- fill period tab tab_period := compute_period(N_Tasks); u_values := gen_uunifast_with_limited_utilization(N_Tasks, cpu_utilization_values(1)/100.0); -- Parse command line if Argument_Count /= 7 then Put ("Usage: " & Command_Name & " "); Put_Line ("N_Tasks N_Different_Periods threshold N_High_Tasks N_Medium_Tasks Filename MulticoreParameter"); GNAT.OS_Lib.OS_Exit (1); else N_Tasks := Natural'Value(Argument(1)); N_Different_Periods := Natural'Value(Argument(2)); Threshold_Quality := Natural'Value(Argument(3)); N_High_Tasks := Natural'Value(Argument(4)); N_Medium_Tasks := Natural'Value(Argument(5)); Multicore_Parameter := To_Unbounded_String(Argument(7)); end if; -- iterate on coefficient --for coef of coefficients loop cpu_used_factor := 1.0; -- Remove the space in front of the number of coefficient file1 := To_Unbounded_String(integer(coef)'img); Delete(file1,1,1); -- Initialize the System and the Cheddar framework -- Call_Framework.initialize (False); Initialize (sys); Add_core_unit (sys.Core_units, a_core, to_unbounded_string("c1"), preemptive, 0, 1, 0, 0, 0, To_Unbounded_String (""), To_Unbounded_String (""), MIXED_CRITICALITY_AMC_PROTOCOL, no_memories, empty_string, empty_string, 0, Threshold_Quality); Add (a_core_unit_table, a_core); Add_core_unit (sys.Core_units, a_core, to_unbounded_string("c2"), preemptive, 0, 1, 0, 0, 0, To_Unbounded_String (""), To_Unbounded_String (""), MIXED_CRITICALITY_AMC_PROTOCOL, no_memories, empty_string, empty_string, 0, Threshold_Quality); Add (a_core_unit_table, a_core); if Multicore_Parameter = "no" then Add_Processor (sys.Processors, To_Unbounded_String ("processor1"), A_Core_Unit_Table, No_Migration_Type); elsif Multicore_Parameter = "job" then Add_Processor (sys.Processors, To_Unbounded_String ("processor1"), A_Core_Unit_Table, Job_Level_Migration_Type); elsif Multicore_Parameter = "task" then Add_Processor (sys.Processors, To_Unbounded_String ("processor1"), A_Core_Unit_Table, Time_Unit_Migration_Type); end if; Add_Address_Space (sys.Address_Spaces, To_Unbounded_String ("addr1"), To_Unbounded_String ("processor1"), 0, 0, 0, 0); -- Remove the space in front of the number of CPU utilization file2 := To_Unbounded_String(integer(Target_Cpu_Usage)'img); Delete(file2,1,1); -- initialize the seed value seed := 0; --for coefficient in coefficients loop for iter in 1 .. 1000 loop Actual_CPU_Usage := 0.0; -- Adding Cores, Processor and address_space -- -- Adding Cores, Processor and address_space -- Create_Mixedcriticality_Independant_Periodic_Taskset_System (Sys, Actual_CPU_Usage, N_Tasks, Target_Cpu_Usage, 1.0,1.0, true, N_Different_Periods, N_High_Tasks, N_Medium_Tasks, coef, Sched_Fifo, first_time, u_values, tab_criticality, tab_period, cpu_used_factor, True, seed); first_time := false; set_priority_mixedcriticality_rm(sys.tasks, to_unbounded_string("processor1")); --Calculate_feasibility_interval --(sys, --a_processor, --validate, --Feasibility_Interval, -- msg); Feasibility_Interval := 30000.0; -- Remove the space in front of the number of iteration file3 := To_Unbounded_String(integer(iter)'img); file4 := To_Unbounded_String(integer(Threshold_Quality)'img); Delete(file4,1,1); if iter < 10 then Replace_Element(file3,1,'0'); else Delete(file3,1,1); end if; -- declare File_Name : String := Argument(6) & "_coef_" & To_String(file1) & "_threshold_"& to_String(file4) & "_iter" & To_String(file3) & ".xmlv3"; begin write_to_xml_file (sys, File_Name); end; seed := seed + 1; end loop; cpu_used_factor := cpu_used_factor + 0.5; --end loop; end; end Generate_amc_multicore;