with Caches; use Caches; with Caches; use Caches.Cache_Blocks_Table_Package; package body Cache_Utility is procedure swap_tasks_cache_location (a_task : in Generic_Task_Ptr; b_task : in Generic_Task_Ptr; CAPs : in Cache_Access_Profiles_Set; cache_blocks : in Cache_Blocks_Table; CS : in Integer) is a_cap : Cache_Access_Profile_Ptr; b_cap : Cache_Access_Profile_Ptr; a_start_set,a_end_set : Integer := 0; b_start_set,b_end_set : Integer := 0; a_ucb_counter : Integer := 0; b_ucb_counter : Integer := 0; a_nb_ucb : Integer := 0; b_nb_ucb : Integer := 0; a_nb_ecb : Integer := 0; b_nb_ecb : Integer := 0; begin a_cap := Search_Cache_Access_Profile(CAPs,a_task.cache_access_profile_name); b_cap := Search_Cache_Access_Profile(CAPs,b_task.cache_access_profile_name); a_start_set := b_cap.ECBs.Entries(0).cache_block_number; b_start_set := a_cap.ECBs.Entries(0).cache_block_number; a_end_set := (a_start_set + Integer(a_cap.ECBs.Nb_Entries)) mod CS; b_end_set := (b_start_set + Integer(b_cap.ECBs.Nb_Entries)) mod CS; a_nb_ucb := Integer(a_cap.UCBs.Nb_Entries); b_nb_ucb := Integer(b_cap.UCBs.Nb_Entries); a_nb_ecb := Integer(a_cap.ECBs.Nb_Entries); b_nb_ecb := Integer(b_cap.ECBs.Nb_Entries); a_ucb_counter := 0; b_ucb_counter := 0; ----------------------------------- -- Regenerate the UCBs and ECBs of task A ----------------------------------- Initialize(a_cap.UCBs); Initialize(a_cap.ECBs); if (a_start_set < a_end_set AND a_nb_ecb < CS) then for j in a_start_set..a_end_set-1 loop Add(a_cap.ECBs, cache_blocks.Entries(Cache_Blocks_Range(j))); if(a_ucb_counter <= b_nb_ucb) then Add(a_cap.UCBs, cache_blocks.Entries(Cache_Blocks_Range(j))); a_ucb_counter := a_ucb_counter + 1; end if; end loop; end if; if (a_start_set > a_end_set AND a_nb_ecb < CS) then for j in a_start_set..CS-1 loop Add(a_cap.ECBs, cache_blocks.Entries(Cache_Blocks_Range(j))); if(a_ucb_counter <= a_nb_ucb) then Add(a_cap.UCBs, cache_blocks.Entries(Cache_Blocks_Range(j))); a_ucb_counter := a_ucb_counter + 1; end if; end loop; for j in 0..a_end_set-1 loop Add(a_cap.ECBs, cache_blocks.Entries(Cache_Blocks_Range(j))); if(a_ucb_counter <= a_nb_ucb) then Add(a_cap.UCBs, cache_blocks.Entries(Cache_Blocks_Range(j))); a_ucb_counter := a_ucb_counter + 1; end if; end loop; end if; if (a_nb_ecb > CS) then for j in a_start_set..CS-1 loop Add(a_cap.ECBs, cache_blocks.Entries(Cache_Blocks_Range(j))); if(a_ucb_counter <= a_nb_ucb) then Add(a_cap.UCBs, cache_blocks.Entries(Cache_Blocks_Range(j))); a_ucb_counter := a_ucb_counter + 1; end if; end loop; for j in 0..a_start_set-1 loop Add(a_cap.ECBs, cache_blocks.Entries(Cache_Blocks_Range(j))); if(a_ucb_counter <= a_nb_ucb) then Add(a_cap.UCBs, cache_blocks.Entries(Cache_Blocks_Range(j))); a_ucb_counter := a_ucb_counter + 1; end if; end loop; end if; ----------------------------------- -- Regenerate the UCBs and ECBs of task B ----------------------------------- Initialize(b_cap.UCBs); Initialize(b_cap.ECBs); if (b_start_set < b_end_set AND b_nb_ecb < CS) then for j in b_start_set..b_end_set-1 loop Add(b_cap.ECBs, cache_blocks.Entries(Cache_Blocks_Range(j))); if(b_ucb_counter <= b_nb_ucb) then Add(b_cap.UCBs, cache_blocks.Entries(Cache_Blocks_Range(j))); b_ucb_counter := b_ucb_counter + 1; end if; end loop; end if; if (b_start_set > b_end_set AND b_nb_ecb < CS) then for j in b_start_set..CS-1 loop Add(b_cap.ECBs, cache_blocks.Entries(Cache_Blocks_Range(j))); if(b_ucb_counter <= b_nb_ucb) then Add(b_cap.UCBs, cache_blocks.Entries(Cache_Blocks_Range(j))); b_ucb_counter := b_ucb_counter + 1; end if; end loop; for j in 0..b_end_set-1 loop Add(b_cap.ECBs, cache_blocks.Entries(Cache_Blocks_Range(j))); if(b_ucb_counter <= b_nb_ucb) then Add(b_cap.UCBs, cache_blocks.Entries(Cache_Blocks_Range(j))); b_ucb_counter := b_ucb_counter + 1; end if; end loop; end if; if (b_nb_ecb > CS) then for j in b_start_set..CS-1 loop Add(b_cap.ECBs, cache_blocks.Entries(Cache_Blocks_Range(j))); if(b_ucb_counter <= b_nb_ucb) then Add(b_cap.UCBs, cache_blocks.Entries(Cache_Blocks_Range(j))); b_ucb_counter := b_ucb_counter + 1; end if; end loop; for j in 0..b_start_set-1 loop Add(b_cap.ECBs, cache_blocks.Entries(Cache_Blocks_Range(j))); if(b_ucb_counter <= b_nb_ucb) then Add(b_cap.UCBs, cache_blocks.Entries(Cache_Blocks_Range(j))); b_ucb_counter := b_ucb_counter + 1; end if; end loop; end if; end swap_tasks_cache_location; end Cache_Utility;