00001 /** @file System.h 00002 * @author Gabor Madl 00003 * @date Created 05/2005 00004 * @brief Distributed Real-time Embedded system model of computation. 00005 * 00006 * 00007 * ================================================================= 00008 * DREAM License v2.0 00009 * 00010 * DREAM - Distributed Real-time Embedded Analysis Method 00011 * http://dre.sourceforge.net. 00012 * Copyright (c) 2005-2007 Gabor Madl, All Rights Reserved. 00013 * 00014 * This file is part of DREAM. 00015 * 00016 * DREAM is free software; you can redistribute it and/or modify it 00017 * under the terms of the GNU General Public License version 2 as 00018 * published by the Free Software Foundation. No future versions of 00019 * the GPL license may be automatically applied to DREAM. It is in 00020 * the sole discretion of the copyright holder to determine whether 00021 * DREAM may be released under a different license or terms. There 00022 * are no restrictions on the use of DREAM for any purpose. 00023 * 00024 * DREAM is distributed in the hope that it will be useful, 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00027 * GNU General Public License for more details. 00028 * 00029 * You should have received a copy of the GNU General Public License 00030 * along with this program; if not, write to the Free Software 00031 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00032 * MA 02110-1301, USA. 00033 * 00034 * By submitting comments, suggestions, code, code snippets, 00035 * techniques (including that of usage), and algorithms, submitters 00036 * acknowledge that they have the right to do so, that any such 00037 * submissions are given freely and unreservedly, and that they 00038 * waive any claims to copyright or ownership. In addition, 00039 * submitters acknowledge that any such submission might become 00040 * part of the copyright maintained on the overall body of code, 00041 * which comprises DREAM. By making a submission, submitter agrees 00042 * to these terms. Furthermore, submitters acknowledge that the 00043 * incorporation or modification of such submissions is entirely 00044 * at the discretion of the moderators of the DREAM project. 00045 * 00046 * DREAM links to the Libxml2 third party library. Please see 00047 * COPYING-libxml for the copyright information of Libxml2. 00048 * ================================================================= 00049 */ 00050 00051 #ifndef DREAM_SYSTEM 00052 #define DREAM_SYSTEM 00053 00054 #include "Scheduler.h" 00055 00056 namespace DREAM 00057 { 00058 00059 class PriorityInversionList; 00060 00061 /** Distributed Real-time Embedded system model. 00062 * This class implements the DRE model of computation for analyzing the distributed real-time scheduling of 00063 * embedded systems. 00064 */ 00065 class System 00066 { 00067 public: 00068 /** Constructor. */ 00069 System (); 00070 00071 /** Destructor. */ 00072 virtual ~System (); 00073 00074 /** Adds a Scheduler into the overall model of computation. 00075 * @param scheduler_ptr specifies the Scheduler to be added. 00076 */ 00077 void add_scheduler (DREAM::Scheduler* scheduler_ptr); 00078 00079 #ifdef DREAM_RACE_CONDITION 00080 /** Clears the priority list and frees up memory. */ 00081 void destroy_priority_list (); 00082 #endif 00083 00084 /** Returns the number of CPUs in the system. */ 00085 uint CPUs () const; 00086 00087 #ifdef DREAM_RACE_CONDITION 00088 /** This function returns which Task to execute given the parameter AVL tree. */ 00089 DREAM::Task* find_current (const DREAM::TASK_AVLTREE* task_avltree_ptr, DREAM::Task* task_ptr) const 00090 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING 00091 throw (DREAM::Exception) 00092 #endif 00093 ; 00094 00095 /** This function introduces a single priority inversion in the priority_list_ptr_. 00096 * The function returns false if all permutations of priority inversions have been checked. 00097 */ 00098 virtual bool inversion (); 00099 #endif 00100 00101 /** Returns the time of the next event. */ 00102 virtual double next_event (bool deterministic) const 00103 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING 00104 throw (DREAM::Exception) 00105 #endif 00106 ; 00107 00108 /** Resets Schedulers (when restarting the simulation). */ 00109 virtual void reset (); 00110 00111 /** Returns relevant_event_. */ 00112 virtual bool relevant_event () const; 00113 00114 /** Tasks call this function when publishing to signal that their event has to be considered for model checking. */ 00115 virtual void relevant_event (bool value); 00116 00117 /** Returns the Scheduler map. 00118 * Used in output generation. 00119 * @return a pointer to the scheduler_map_. 00120 */ 00121 virtual const DREAM::SCHEDULER_MAP* scheduler_map () 00122 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING 00123 throw (DREAM::Exception) 00124 #endif 00125 ; 00126 00127 /** Starts deterministic simulation. 00128 * This simulation will simulate a deterministic trace of the system. 00129 * @param verbose specifies whether messages will be generated. 00130 * @param deterministic specifies whether deterministic schedule is assumed. 00131 * @param endtoend updates the pointer's target with the end-to-end execution time of the model (unless the pointer is NULL). 00132 */ 00133 virtual void simulate (bool verbose, bool deterministic, double* endtoend = NULL); 00134 00135 /** This function builds the error list. 00136 * The function is used by genetic algorithms. 00137 * @param task_avltree stores the list of Tasks from the Scheduler error list. 00138 */ 00139 virtual void visitor_error_avltree (DREAM::TASK_AVLTREE* task_avltree) 00140 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING 00141 throw (DREAM::Exception) 00142 #endif 00143 ; 00144 00145 /** This function is part of the IF system description generator. 00146 * @param task_map stores the Task pointers. 00147 * @param channel_map stores the Channel pointers. 00148 * @param timer_map stores the Timer pointers. 00149 * @param f_stream is the output stream to be written to. 00150 */ 00151 virtual void visitor_if (DREAM::NODE_MAP* task_map, DREAM::NODE_MAP* channel_map, DREAM::NODE_MAP* timer_map, std::ofstream& f_stream) 00152 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING 00153 throw (DREAM::Exception) 00154 #endif 00155 ; 00156 00157 /** This function fills the IDs (names) of tasks, channels and timers to the parameter lists. 00158 * The function is used to generate output for model checkers. 00159 * @param task_map stores the Task pointers. 00160 * @param channel_map stores the Channel pointers. 00161 * @param timer_map stores the Timer pointers. 00162 */ 00163 virtual void visitor_map (DREAM::NODE_MAP* task_map, DREAM::NODE_MAP* channel_map, DREAM::NODE_MAP* timer_map) 00164 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING 00165 throw (DREAM::Exception) 00166 #endif 00167 ; 00168 00169 /** This function builds the task list for manipulation. 00170 * The function is used by genetic algorithms. 00171 * @param task_avltree stores the Task pointers. 00172 */ 00173 virtual void visitor_task_avltree (DREAM::TASK_AVLTREE* task_avltree) 00174 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING 00175 throw (DREAM::Exception) 00176 #endif 00177 ; 00178 00179 /** This function updates task values in the system. 00180 * The function is used by genetic algorithms. 00181 * @param task_avltree stores the Task pointers. 00182 */ 00183 virtual void visitor_update_task_avltree (DREAM::TASK_AVLTREE* task_avltree) 00184 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING 00185 throw (DREAM::Exception) 00186 #endif 00187 ; 00188 00189 /** This function is part of the Uppaal system description generator. 00190 * @param task_map stores the Task pointers. 00191 * @param channel_map stores the Channel pointers. 00192 * @param timer_map stores the Timer pointers. 00193 * @param f_stream is the output stream to be written to. 00194 */ 00195 virtual void visitor_uppaal (DREAM::NODE_MAP* task_map, DREAM::NODE_MAP* channel_map, DREAM::NODE_MAP* timer_map, std::ofstream& f_stream) 00196 #ifdef DREAM_ENHANCED_EXCEPTION_CHECKING 00197 throw (DREAM::Exception) 00198 #endif 00199 ; 00200 00201 private: 00202 00203 /** Flag to signal end of event loop. */ 00204 bool active_; 00205 00206 /** List of all the Schedulers in the model of computation. */ 00207 DREAM::SCHEDULER_MAP scheduler_map_; 00208 00209 /** Clock for the System. */ 00210 double time_; 00211 00212 #ifdef DREAM_RACE_CONDITION 00213 /** Queue that stores tasks that need to be checked for race conditions. 00214 * The model checker implements the checks by introducing artificial priority inversions at simulation time. 00215 */ 00216 DREAM::PriorityInversionList* priority_list_ptr_; 00217 #endif 00218 00219 /** This variable is set to true if branching points have to be considered for the actual event. */ 00220 bool relevant_event_; 00221 }; 00222 00223 } 00224 00225 #endif