------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- 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-2023, 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 README.md -- -- 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: 3520 $ -- $Date: 2020-07-23 12:44:45 +0200 (Thu, 23 Jul 2020) $ -- $Author: singhoff $ ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with translate; use translate; with unbounded_strings; use unbounded_strings; with Scheduling_Analysis; use Scheduling_Analysis; use Scheduling_Analysis.Double_Tasks_Parameters_Package; with qs_tools; use qs_tools; with Text_IO; use Text_IO; with systems; use systems; package body scheduler.mixed_criticality is function build_tcb (my_scheduler : in mixed_criticality_scheduler; a_task : generic_task_ptr) return tcb_ptr is a_tcb : mixed_criticality_tcb_ptr; begin a_tcb := new mixed_criticality_tcb; initialize (tcb (a_tcb.all), a_task); initialize (a_tcb.all); return tcb_ptr (a_tcb); end build_tcb; procedure initialize (a_tcb : in out mixed_criticality_tcb) is temp_capacity : Natural; seed : Generator; begin reset (seed,a_tcb.tsk.seed); a_tcb.is_execution_continue := False; a_tcb.current_quality_exit := a_tcb.tsk.qualities.entries(0).values_eu; a_tcb.tsk.qualities.entries(0).values_eu := a_tcb.tsk.qualities.entries(1).values_eu; a_tcb.current_capacities.nb_entries := 3; a_tcb.current_capacities.entries(0) := new execution_unit; a_tcb.current_capacities.entries(1) := new execution_unit; a_tcb.current_capacities.entries(2) := new execution_unit; -- Compute DC value a_tcb.tsk.capacity := Natural((a_tcb.tsk.capacities.entries(0).values_eu * a_tcb.tsk.qualities.entries(2).values_eu)/100); if a_tcb.tsk.capacity = 0 then a_tcb.tsk.capacity := 1; end if; temp_capacity := Box_Muller_Normal2(a_tcb.tsk.capacity,a_tcb.tsk.capacities.entries(2).values_eu,seed); put_line("Release"&a_tcb.activation'img&" Valeur simulée entre "&a_tcb.tsk.capacity'img&" et "&a_tcb.tsk.capacities.entries(2).values_eu'img&" = "&temp_capacity'img); a_tcb.rest_of_capacity := Natural'Max(1,temp_capacity); a_tcb.current_capacities.entries(0).values_eu := a_tcb.rest_of_capacity; a_tcb.current_capacities.entries(1).values_eu := a_tcb.tsk.capacities.entries(1).values_eu; a_tcb.current_capacities.entries(2).values_eu := a_tcb.tsk.capacities.entries(2).values_eu; a_tcb.current_dc_value := a_tcb.tsk.capacity; Save(seed,a_tcb.task_seed); end initialize; procedure check_before_scheduling (my_scheduler : in mixed_criticality_scheduler; my_tasks : in tasks_set; processor_name : in Unbounded_String) is begin null; end check_before_scheduling; procedure specific_scheduler_initialization (my_scheduler : in out mixed_criticality_scheduler; si : in out scheduling_information; processor_name : in Unbounded_String; address_space_name : in Unbounded_String; my_tasks : in out tasks_set; my_schedulers : in scheduler_table; my_resources : in out resources_set; my_buffers : in out buffers_set; my_messages : in messages_set; msg : in out Unbounded_String) is begin null; end specific_scheduler_initialization; procedure do_election (my_scheduler : in out mixed_criticality_scheduler; si : in out scheduling_information; result : in out scheduling_sequence_ptr; msg : in out Unbounded_String; current_time : in Natural; processor_name : in Unbounded_String; address_space_name : in Unbounded_String; core_name : in Unbounded_String; options : in scheduling_option; event_to_generate : in time_unit_event_type_boolean_table; elected : in out tasks_range; no_task : in out Boolean) is begin null; end do_election; procedure find_elected_task (si : in scheduling_information; my_scheduler : in mixed_criticality_scheduler; core_name : in Unbounded_String; address_space_name : in Unbounded_String; processor_name : in Unbounded_String; current_time : in Natural; options : in scheduling_option; highiest_priority : in out Natural; elected : in out tasks_range) is i : tasks_range := 0; begin loop if not si.tcbs (i).already_run_at_current_time and not si.tcbs(i).suspended then if (si.tcbs (i).tsk.cpu_name = processor_name) and ((address_space_name = To_Unbounded_String ("")) or (address_space_name = si.tcbs (i).tsk.address_space_name)) then if ((si.tcbs (i).tsk.core_name = To_Unbounded_String ("")) or (si.tcbs (i).tsk.core_name = core_name)) then if check_core_assignment (my_scheduler, si.tcbs (i)) then if (si.tcbs (i).wake_up_time <= current_time) and (Natural(mixed_criticality_tcb_ptr (si.tcbs (i)).tsk.priority) > highiest_priority) and (si.tcbs (i).rest_of_capacity /= 0) then if (options.with_jitters = False) or (si.tcbs (i).is_jitter_ready) then if (options.with_offsets = False) or check_offset (si.tcbs (i), current_time) then if (options.with_precedencies = False) or check_precedencies(si,current_time,si.tcbs (i)) then highiest_priority := Natural(mixed_criticality_tcb_ptr (si.tcbs (i)).tsk.priority); elected := i; end if; end if; end if; end if; end if; end if; end if; end if; i := i + 1; exit when si.tcbs (i) = null; end loop; end find_elected_task; procedure verification_of_budget_overruns (elected_task : in out mixed_criticality_tcb_ptr; my_scheduler : in out mixed_criticality_scheduler; result : in out scheduling_sequence_ptr; find : in out Boolean; highiest_priority : in out Natural; si : in out scheduling_information; options : in scheduling_option; elected : in tasks_range; current_time : in Natural; current_mode : in mode_range) is threshold_quality : Integer := my_scheduler.parameters.threshold; current_I : Natural := 0; current_c_lo : Natural := 0; cnt : Natural:= 0; i :tasks_range := 0; begin --put_line("time : "¤t_time'img); -- combien de tâche il reste if (elected_task.completion_time + 1 > elected_task.tsk.capacities.entries(Execution_Units_Table_Package.table_range(current_mode)).values_eu) and elected_task.rest_of_capacity /= 0 and not elected_task.suspended and not elected_task.is_execution_continue then -- AMC-Anytime part -- -- Adaptating if elected_task.current_quality_exit - 1 >= threshold_quality and get_name(my_scheduler) = mixed_criticality_anytime_amc_protocol and elected_task.tsk.criticality /= 2 then --put_line("time : "¤t_time'img); --put_line("===> Adaptation T"&Natural(elected+1)'img); -- Reduce the capacity by the quality profile if elected_task.current_quality_exit = 2 then elected_task.current_dc_value := mixed_criticality_tcb_ptr (si.tcbs (elected)).tsk.capacity * 30/100; elsif elected_task.current_quality_exit = 3 then elected_task.current_dc_value := mixed_criticality_tcb_ptr (si.tcbs (elected)).tsk.capacity * 50/100; elsif elected_task.current_quality_exit = 4 then elected_task.current_dc_value := mixed_criticality_tcb_ptr (si.tcbs (elected)).tsk.capacity * 70/100; end if; -- Reduce quality : Q(i) := Q(i-1) elected_task.current_quality_exit := elected_task.current_quality_exit - 1; -- Change C(HI) values current_c_lo := (elected_task.current_dc_value * 100)/ elected_task.tsk.qualities.entries(2).values_eu; current_I := current_c_lo - elected_task.current_dc_value; elected_task.current_capacities.entries(2).values_eu := 2 * (elected_task.current_dc_value + current_I); -- stop the LO job and continue the others if elected_task.tsk.criticality /= 0 then elected_task.is_execution_continue := True; else compute_next_task_activation(my_scheduler,si.tcbs (elected),si,options,elected); highiest_priority := Natural'first; end if; else -- mode change --put_line("time : "¤t_time'img); --put_line("Mode change ! "); if elected_task.tsk.criticality = Natural(current_mode) then elected_task.suspended := True; highiest_priority := Natural'first; else elected_task.is_execution_continue := True; end if; do_mode_change(my_scheduler, options, si, result, current_time, current_mode, current_mode+1); if get_name(my_scheduler) /= mixed_criticality_smc_protocol then -- stop tasks stop_tasks(current_mode,si); end if; end if; else find := true; end if; end verification_of_budget_overruns; procedure do_mode_change (my_scheduler : in out mixed_criticality_scheduler; options : in scheduling_option; si : in scheduling_information; result : in out scheduling_sequence_ptr; current_time : in Natural; from_mode : in mode_range; to_mode : in mode_range ) is a_item : time_unit_event_ptr; begin -- count the number of change mode produce_mode_change(my_scheduler, options, si, a_item, from_mode, to_mode); add (result.all, current_time, a_item); -- change variable values my_scheduler.state := to_mode; my_scheduler.is_change_mode := True; end do_mode_change; procedure produce_mode_change (my_scheduler : in mixed_criticality_scheduler; options : in scheduling_option; si : in scheduling_information; an_event : out time_unit_event_ptr; from_mode : in mode_range; to_mode : in mode_range) is begin an_event := new time_unit_event (mode_change); an_event.from_mode := from_mode; an_event.to_mode := to_mode; end produce_mode_change; procedure stop_tasks ( from_mode : in mode_range; si : in out scheduling_information) is i : tasks_range := 0; begin -- suspend tasks loop if si.tcbs(i).tsk.criticality = Natural(from_mode) and si.tcbs(i).tsk.criticality /= 2 then si.tcbs(i).suspended := True; end if; i := i + 1; exit when si.tcbs (i) = null; end loop; end stop_tasks; procedure update_simulation_data_on_mode_change (my_scheduler : in out mixed_criticality_scheduler; si : in out scheduling_information; elected : in tasks_range; no_task : in Boolean) is j : tasks_range; current_state : Natural; current_task : mixed_criticality_tcb_ptr; begin current_state := Natural(my_scheduler.state); if (my_scheduler.is_change_mode) then j := 0; loop current_task := mixed_criticality_tcb_ptr(si.tcbs(j)); -- Used the next criticality capacities if j /= elected then -- Check tasks not yet activated if current_task.current_capacities.entries(1).values_eu = current_task.rest_of_capacity and not current_task.suspended then current_task.rest_of_capacity := current_task.current_capacities.entries(1).values_eu; elsif current_task.current_capacities.entries(2).values_eu = current_task.rest_of_capacity and not current_task.suspended then current_task.rest_of_capacity := current_task.current_capacities.entries(2).values_eu; end if; if get_name(my_scheduler) = mixed_criticality_anytime_amc_protocol then -- Recover the original quality exit and DC value current_task.current_quality_exit := current_task.tsk.qualities.entries(0).values_eu; current_task.current_dc_value := current_task.tsk.capacity; end if; end if; si.tcbs(j) := tcb_ptr(current_task); j := j + 1; exit when si.tcbs (j) = null; end loop; my_scheduler.is_change_mode := False; end if; end update_simulation_data_on_mode_change; procedure compute_score (my_scheduler : in mixed_criticality_scheduler) is begin null; -- Compute score -- with factor for each criticality tasks -- --factors(1):= 1; --factors(2):= 2; --factors(3):= 4; -- if mixed_criticality_tcb_ptr( si.tcbs (elected)).rest_of_capacity = 1 -- then -- if my_scheduler.state = Low_criticality -- then -- if mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.criticality = 0 -- then -- mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(1,1) := mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(1,1) + mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.qualities.entries(0).values_eu * factors(1); -- elsif mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.criticality = 1 -- then -- mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(1,2) := mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(1,2) + mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.qualities.entries(0).values_eu * factors(2); -- else -- mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(1,3) := mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(1,3) + mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.qualities.entries(0).values_eu * factors(3); -- end if; -- elsif my_scheduler.state = Medium_criticality -- then -- if mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.criticality = 0 -- then -- mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(2,1) := mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(2,1) + mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.qualities.entries(0).values_eu * factors(1); -- elsif mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.criticality = 1 -- then -- mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(2,2) := mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(2,2) + mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.qualities.entries(0).values_eu * factors(2); -- else -- mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(2,3) := mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(2,3) + mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.qualities.entries(0).values_eu * factors(3); -- end if; -- else -- if mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.criticality = 0 -- then -- mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(3,1) := mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(3,1) + mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.qualities.entries(0).values_eu * factors(1); -- elsif mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.criticality = 1 -- then -- mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(3,2) := mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(3,2) + mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.qualities.entries(0).values_eu * factors(2); -- else -- mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(3,3) := mixed_criticality_tcb_ptr(si.tcbs(elected)).tsk.scores(3,3) + mixed_criticality_tcb_ptr( si.tcbs (elected)).tsk.qualities.entries(0).values_eu * factors(3); -- end if; -- end if; -- end if; -- end compute_score; end scheduler.mixed_criticality;