cheddar_3.3.0_aea10b3c/ellidiss/heuristics.ads

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- 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 CNRS 6285, Universite 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: 4589 $
--    $Date: 2023-09-29 16:02:19 +0200 (ven., 29 sept. 2023) $
--    $Author: singhoff $
------------------------------------------------------------------------------
------------------------------------------------------------------------------

with Ada.Containers.Doubly_Linked_Lists;

with task_set;              use task_set;
with scheduler;             use scheduler;
with Ada.Text_IO;           use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

---------------------------------------------------------------------
-- Package Heuristics
-- Purpose: Contains the components that allows the modelisation
-- of the heuristics used to jump in time.
---------------------------------------------------------------------
package Heuristics is
   Optimization_Mode_Activated : Boolean := False;

---------------------- HEURISTIC TYPE DEFINITION -------------------------------
   type heuristic is interface;

   -- Abstract functions and procedures:
   function Can_Run
     (This : in out heuristic;
      Si   : in     scheduling_information) return Boolean is abstract;
   function Calculate
     (This : in out heuristic;
      Si   : in     scheduling_information) return Natural is abstract;

   -- Abstract type of an Heuristic:
   type concrete_heuristics is abstract new Heuristics.heuristic with record
      Name : Unbounded_String;
      -- *
   end record;

   type heuristic_ptr is access concrete_heuristics'class;

---------------------- TYPES OF HEURISTICS -------------------------------------
   type core_no_task_info is array (0 .. 255) of Natural;
   type heuristic_1 is new concrete_heuristics with record
      CNTI                       : core_no_task_info := (others => 0);
      Number_Of_Valid_Idle_Times : Natural           := 0;
      Current_Time               : Natural           := 0;
   end record;

   type heuristic_2 is new concrete_heuristics with record
      Commit_Unit           : Natural     := 0;
      Current_Time          : Natural     := 0;
      Remaining_Task_Id     : tasks_range := 0;
      Number_Of_Tasks_Ended : Natural     := 0;
   end record;

---------------------- METHODS -------------------------------------------------
   -- Heuristics functions and procedures:
   function Can_Run
     (This : in out heuristic_1;
      Si   : in     scheduling_information) return Boolean;
   function Can_Run
     (This : in out heuristic_2;
      Si   : in     scheduling_information) return Boolean;

   function Calculate
     (This : in out heuristic_1;
      Si   : in     scheduling_information) return Natural;
   function Calculate
     (This : in out heuristic_2;
      Si   : in     scheduling_information) return Natural;

   -- Proper to Heuristic_1::Idle_Heuristic:
   procedure Update_Values
     (This    : in out heuristic_1;
      No_Task : in     Boolean;
      Core_Id : in     Natural);
   procedure Reset_Values (This : in out heuristic_1; Core_Id : in Natural);
   --
   procedure Decrease_Idle_Times
     (This    : in out heuristic_1;
      Core_Id : in     Natural);
   procedure Increase_Idle_Times
     (This    : in out heuristic_1;
      Core_Id : in     Natural);

   -- Proper to Heuristic_2::Last_Job_Remaining_Heuristic:
   function Verify_Pre_Conditions
     (This : in out heuristic_2;
      Si   : in     scheduling_information) return Boolean;
   procedure Reset_Values
     (This : in out heuristic_2;
      Si   : in     scheduling_information);
   --
   function Get_Remaining_Task
     (This         : in out heuristic_2;
      Si           : in     scheduling_information;
      Current_Time : in     Natural) return Boolean;
   function Get_Nearest_Wake_Up_Time
     (This : in out heuristic_2;
      Si   : in     scheduling_information) return Natural;

---------------------- HEURISTICS LIST -----------------------------------------
   -- Heuristic list:
   package Heuristic_Lists is new Ada.Containers.Doubly_Linked_Lists
     (heuristic_ptr);
   use Heuristic_Lists;
   Heuristic_List : list;

---------------------- INTERFACE METHODS ---------------------------------------
   -- procedure TestCalculation(Heuristic : Concrete_Heuristics'Class);

   -- Interface methods:
   function Can_Run_Heuristic
     (Heuristic : in out concrete_heuristics'class;
      Si        : in     scheduling_information) return Boolean;

   function Calculate_Heuristic
     (Heuristic : in out concrete_heuristics'class;
      Si        : in     scheduling_information) return Natural;

---------------------- HEURISTICS DECLARATIONS ---------------------------------
   -- Heuristics declarations:
   Idle_Heuristic     : heuristic_ptr := new heuristic_1;
   Last_Job_Heuristic : heuristic_ptr := new heuristic_2;
end Heuristics;