------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- 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.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; a_tcb.current_capacities.entries(0).values_eu := a_tcb.tsk.capacities.entries(0).values_eu; 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; a_tcb.current_I_LO_value := a_tcb.tsk.capacities.entries(0).values_eu - a_tcb.current_dc_value; a_tcb.current_I_HI_value := a_tcb.current_capacities.entries(2).values_eu - a_tcb.current_dc_value; -- Compute DC / E value temp_capacity := Box_Muller_Normal2(a_tcb.tsk.capacity,a_tcb.tsk.capacities.entries(2).values_eu,seed); a_tcb.rest_of_capacity := Natural'Max(1,temp_capacity); -- Didactic example -- --if a_tcb.tsk.priority = 1 then -- temp_capacity := 9; --elsif a_tcb.tsk.priority = 2 then -- temp_capacity := 5; --elsif a_tcb.tsk.priority = 3 then -- temp_capacity := 4; --end if; --put_line("Release"&a_tcb.activation'img&" Valeur simulĂ©e entre "&a_tcb.current_dc_value'img&" et "&a_tcb.current_capacities.entries(2).values_eu'img&" = "&temp_capacity'img); 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 compute_quality (elected_task : in mixed_criticality_tcb_ptr; my_scheduler : in out mixed_criticality_scheduler) is begin -- Check if they rest 1 of capacity for the elected task if elected_task.rest_of_capacity = 1 and not elected_task.suspended then -- We'll only take LO tasks into account. if elected_task.tsk.criticality = 0 then my_scheduler.quality_system := my_scheduler.quality_system + elected_task.current_quality_exit; end if; end if; end compute_quality; procedure compute_score (my_scheduler : in mixed_criticality_scheduler) is begin null; end compute_score; procedure compute_missed_deadline (elected_task : in mixed_criticality_tcb_ptr; my_scheduler : in out mixed_criticality_scheduler; current_time : in Natural) is begin if elected_task.rest_of_capacity = 0 and current_time /= elected_task.tsk.deadline and not elected_task.suspended then my_scheduler.number_of_missed_deadline := my_scheduler.number_of_missed_deadline + 1; end if; end compute_missed_deadline; 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); if (elected_task.completion_time + 1 > elected_task.current_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); my_scheduler.nb_adaptation := my_scheduler.nb_adaptation + 1; -- 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 -- compute clo from the new E and coefficient -- old version --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); -- new version elected_task.current_capacities.entries(0).values_eu := elected_task.current_dc_value + elected_task.current_I_LO_value; elected_task.current_capacities.entries(2).values_eu := elected_task.current_dc_value + elected_task.current_I_HI_value; -- 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, 2); if get_name(my_scheduler) /= mixed_criticality_smc_protocol then -- stop tasks stop_tasks(current_mode,si,my_scheduler); 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 -- response time value a_item : time_unit_event_ptr; begin -- count the number of change mode -- remove this for the quality --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; my_scheduler : in out mixed_criticality_scheduler) 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; my_scheduler.nb_stops_tasks := my_scheduler.nb_stops_tasks + 1; end if; i := i + 1; exit when si.tcbs (i) = null; end loop; end stop_tasks; procedure do_quality_result (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); --put_line("quality :"¤t_time'img); end do_quality_result; 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 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; end scheduler.mixed_criticality;