with Text_IO; use Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Strings.Bounded; use Ada.Strings.Bounded; with unbounded_strings; use unbounded_strings; with Tasks; use Tasks; with Framework_Config; use Framework_Config; with Scheduling_Analysis; use Scheduling_Analysis.Task_Release_Records_Table_Package; with integer_util; use integer_util; with Priority_Assignment.Utility; use Priority_Assignment.Utility; with Priority_Assignment.Audsley_OPA; use Priority_Assignment.Audsley_OPA; with Tasks.Extended; use Tasks.Extended; with Debug; use Debug; with Integer_Arrays; use Integer_Arrays; with Cache_Set; use Cache_Set; with Priority_Assignment.Audsley_OPA_CRPD_PT; use Priority_Assignment.Audsley_OPA_CRPD_PT; with Priority_Assignment.Audsley_OPA_CRPD_Tree; use Priority_Assignment.Audsley_OPA_CRPD_Tree; with Systems; use Systems; with Caches; use Caches; with Offsets; use Offsets.Offsets_Table_Package; with Sets; with Tables; package body Priority_Assignment.Audsley_OPA_CRPD is procedure Check_Input_Data (my_tasks : in Tasks_Set; my_cache_access_profiles : in Cache_Access_Profiles_Set) is a_task : Generic_Task_Ptr; my_iterator : Tasks_Iterator; a_cap : Cache_Access_Profile_Ptr; my_iterator_cap : Cache_Access_Profiles_Iterator; begin if(Integer(get_number_of_elements(my_cache_access_profiles)) <= 0)then raise Cache_Access_Profile_Must_Be_Defined; end if; reset_iterator (my_tasks, my_iterator); loop current_element (my_tasks, a_task, my_iterator); if(a_task.task_type /= Periodic_Type)then raise Task_Must_Be_Periodic; end if; -- if(a_task.offsets.Nb_Entries <= 0) then -- raise Offset_Must_Be_Defined; -- end if; --Exception Cache_Access_Profile_Not_Found will be raised if there is a problem a_cap := Search_Cache_Access_Profile(my_cache_access_profiles, a_task.cache_access_profile_name); exit when is_last_element (my_tasks, my_iterator); next_element (my_tasks, my_iterator); end loop; end Check_Input_Data; procedure CPA (my_tasks : in out Tasks_Set; my_cache_access_profiles : in Cache_Access_Profiles_Set; complexity : in CRPD_Inteference_Computation_Complexity := PT_Simplified) is delta_set : Tasks_Set; delta_set_ecb : Tasks_Set; my_iterator : Tasks_Iterator; my_iterator_ecb : Tasks_Iterator; a_task : Generic_Task_Ptr; a_task_ecb : Generic_Task_Ptr; temp_task : Generic_Task_Ptr; n : Integer := 1; unassigned : Boolean; is_schedulable : Boolean; a_task_ucb_ecb_array_ptr : Task_UCB_ECB_Array_Ptr; a_cap : Cache_Access_Profile_Ptr; begin CAP_to_TUEA(my_tasks => my_tasks, my_cache_access_profiles => my_cache_access_profiles, a_task_ucb_ecb_array => a_task_ucb_ecb_array_ptr); duplicate(src => my_tasks, dest => delta_set); n := Integer(delta_set.get_number_of_elements); for j in 1..n loop unassigned := True; Sort(delta_set,Decreasing_Period_Deadline'Access); --The task set is sorted by period and deadline - DESC reset_iterator (delta_set, my_iterator); loop current_element (delta_set, a_task, my_iterator); --Put_Line("Assessing task: " & To_String(a_task.name) & " at priority level: " & j'Img); if(complexity = ECB_Only) then -- Duplicate(delta_set,delta_set_ecb); reset_iterator(delta_set_ecb, my_iterator_ecb); loop current_element (delta_set_ecb, a_task_ecb, my_iterator_ecb); if(a_task_ecb.name /= a_task.name) then a_cap := Search_Cache_Access_Profile(my_cache_access_profiles, a_task_ecb.cache_access_profile_name); a_task_ecb.capacity := a_task_ecb.capacity + Natural(a_cap.ECBs.Nb_Entries); -- Adding ECB to task's capacity end if; exit when is_last_element (delta_set_ecb, my_iterator_ecb); next_element (delta_set_ecb, my_iterator_ecb); end loop; OPA_Feasibility_Test(priority_level => j, i_task => a_task, my_tasks => delta_set_ecb, is_schedulable => is_schedulable); elsif (complexity = PT_Simplified) then OPA_Feasibility_Test_CRPD_Upperbound(priority_level => j, i_task => a_task, my_tasks => delta_set, is_schedulable => is_schedulable, a_task_ucb_ecb_array_ptr => a_task_ucb_ecb_array_ptr, BE_Complexity => False); elsif (complexity = PT_Binomial_Coefficient) then OPA_Feasibility_Test_CRPD_Upperbound(priority_level => j, i_task => a_task, my_tasks => delta_set, is_schedulable => is_schedulable, a_task_ucb_ecb_array_ptr => a_task_ucb_ecb_array_ptr, BE_Complexity => True); elsif (complexity = Tree) then OPA_Feasibility_Test_CRPD(priority_level => j, i_task => a_task, my_tasks => delta_set, a_tuea => a_task_ucb_ecb_array_ptr, is_schedulable => is_schedulable, number_of_task => n); end if; if(is_schedulable) then --Put_Line("Assign priority level:" & j'Img & " to task: " & To_String(a_task.name) & ASCII.LF & "---"); Delete(delta_set,a_task); temp_task := Search_Task(My_Tasks => my_tasks, Name => a_task.name); temp_task.priority := Priority_Range(j); unassigned := False; exit; end if; exit when is_last_element (delta_set, my_iterator); next_element (delta_set, my_iterator); end loop; if(unassigned) then raise NO_FEASIBLE_PRIORITY_ASSIGNMENT_EXCEPTION; end if; end loop; end CPA; procedure Set_Priority_According_To_CPA (My_Tasks : in out Tasks_Set; My_Cache_Access_Profiles : in Cache_Access_Profiles_Set; Computation_Complexity : in CRPD_Inteference_Computation_Complexity := PT_Simplified; Processor_Name : in Unbounded_String := empty_string) is Iterator1 : Tasks_Iterator; Task1 : Generic_Task_Ptr; Iterator2 : Tasks_Iterator; Task2 : Generic_Task_Ptr; Tmp : Tasks_Set; begin if Processor_Name = empty_string then duplicate (My_Tasks, Tmp); else Current_Processor_Name := Processor_Name; select_and_copy (My_Tasks, Tmp, Select_Cpu'Access); end if; Periodic_Control (Tmp, Processor_Name); Check_Input_Data (Tmp, My_Cache_Access_Profiles); -- Assign priorities -- CPA(my_tasks => Tmp, my_cache_access_profiles => My_Cache_Access_Profiles, complexity => Computation_Complexity); -- Copy resulting task objects in My_Tasks -- reset_iterator (Tmp, Iterator1); loop current_element (Tmp, Task1, Iterator1); reset_iterator (My_Tasks, Iterator2); loop current_element (My_Tasks, Task2, Iterator2); if (Task2.name = Task1.name) then Task2.priority := Task1.priority; end if; exit when Task2.name = Task1.name; exit when is_last_element (My_Tasks, Iterator2); next_element (My_Tasks, Iterator2); end loop; exit when is_last_element (Tmp, Iterator1); next_element (Tmp, Iterator1); end loop; free (Tmp); end Set_Priority_According_To_CPA; end Priority_Assignment.Audsley_OPA_CRPD;