programmer interface (API) replaces the embedded system. CPU model thus allowing for a higher-level of abstraction for design, simulation, and co-verification.
An Integrated SystemC Framework for Real-Time Scheduling Assessments on System Level Prih Hastono, Stephan Klaus and Sorin A. Huss Integrated Circuits and Systems Laboratory Department of Computer Science - Technische Universität Darmstadt Hochschulstr. 10, 64289 Darmstadt Germany
{hastono|klaus|huss}@iss.tu-darmstadt.de
Abstract The rate and reactivity figures of embedded systems are distinctly influenced by the chosen scheduling policy since embedded software processes more and more dominate the functionality of embedded systems. Seeking a suitable schedule policy typically requires some heuristics in conjunction with analytic approaches. A stand-alone scheduling simulator can considerably help reducing these efforts. However, a tedious integration work will be required in order to jointly validate both behavioural and architectural design decisions. Therefore, we present an open framework for real-time scheduling simulation by exploiting the SystemC modeling style. Especially the real-time software modeling capabilities of SystemC are enhanced to a large extent by this work, which allows an integration of software tasks scheduling simulation into existing approaches of modeling using SystemC. Thus, design alternatives, scheduling decisions, and associated real-time performance can be explored in early design phases.
1. Introduction One important issue of a successful design methodology for complex real-time embedded systems is a realistic, reliable, and fast system-level simulation support. Design and implementation alternatives should be validated as early as possible in the design flow in order to allow for a comprehensive design space exploration. Especially software execution properties must be timely taken into account, since software modules more and more dominate the functionality of embedded systems. The execution of software in such real-time systems is in general controlled by a real-time operating system (RTOS). In order to achieve real-time performance, the system behavior predictability is of paramount concern. Central to the method of achieving this predictability is the scheduling algorithm that decides which activity is allowed to execute at some instant of time, so that a maximum amount of tasks meet their deadlines reliably. An optimal schedule may be found analytically during schedulability analysis. However, it is often desirable to verify its results or to open the possibility to find new approaches empirically during scheduling exploration. Thus, the need of a flexible customizable scheduling simulator is advocated for assessing the behavior of a certain scheduling approach expressed as an algorithm under simulated conditions. Such a scheduling simulator must provide enough services to let the real-time researcher stay focused on the details of the scheduling algorithm and yet must be open and flexible enough to support new solution strategies. In this paper we take into consideration that the system is being modeled in SystemC [2] thus providing a simulation model of the system under development in the framework which is based on SystemC, too. The choice for working with a system level design language is important for ensuring model portability. We select SystemC because it emerges as the industrial standard for both transaction-level modeling and system-level design language for co-simulation of mixed HW/SW systems. In the framework scheduling simulation has to be done in the same environment of both for the functional system-level validation and the design
space exploration. Such a framework for scheduling simulation is illustrated in Figure 1. Based on analysis and selection operations during simulation a scheduling decision can be taken. The scenario of interfacing both the system and scheduling simulation is illustrated in Figure 2. It presents a typical viewpoint for the interface for real-time scheduling simulation, which may easily be modified for real-time scheduling assessment. In this scenario, the system status updates the initial conditions when a decision is needed - either based on an exception or continuously. If alternatives exist, then each of them would be simulated and the best may then be selected. Thus, the proposed framework is a novel solution to the problem of integrating both system model and scheduling simulation. A SystemC model that represents real-time systems composed from hardware-software and their interactions thus can be evaluated under various scheduling policies.
2. Related Work Scheduling for embedded systems performance estimation and synthesis has been intensively studied in the last years [4]. Different approaches for scheduling simulation of real-time systems focused on a particular scheduling problems can be found, such as in PERTS [5] and STRESS [6]. A review of recent developments using simulation as a tool in real-time scheduling can be found in [1]. SystemC, the increasingly used C++ based modeling language for system level design, is intensively exercised by its community. As modeling and simulation language, it requires extension to cope with software modeling features including a capability to model real-time software. However, in the current version of SystemC (2.0), this feature is still missing [3]. Therefore, we propose in this paper the scheduling simulation capability extension to work on SystemC models aiming to extend of its usage for real-time scheduling assessment. The basic approach of [7] is mapped to SystemC by extending the scope considerably to allow for a complete integration of HW/SW scheduling simulation into the embedded system co-design flow.
3. Simulation Framework Overview sy s t e m lev e l S y st e m C m odel
HW Mode l
e v e nts a n d d a t a re ce pt io n lo g g in g a n d p re s e n t a t io n
u s e r s che d ule a s A dd -In s t a t ic a lg o rit h m d y n a m ic a lg o rit h m
s che du ling s im u lat ion e ng ine
lo g f ile s
o ff-lin e s e ctio n
GUI
o n -lin e se ctio n
c o m u la t if s t o ra g e
e rro r in je c t io n a lg o rit h m f o r e rro r in je c t io n
r es ult an alys is
Figure 1. Proposed Simulation Framework The proposed simulation framework integrates functional validation with architectural and scheduling exploration on system level. The simulation engine along with software code
written for a specific real-time operating system application programmer interface (API) replaces the embedded system CPU model thus allowing for a higher-level of abstraction for design, simulation, and co-verification. This goes well beyond the standard approach of CPU instruction set emulation. This is accomplished by introducing a model of the resources of the RTOS itself and thus allowing in a straight forward way for task-level operation debugging.
S c h e d u le r e n g in e m a in fu n c tio n
P a rt o f c o d e th a t im p le m e n ts s c h e d u le r e n g in e fu n c tio n a litie s a n d its in te rn a l d a ta in itia lis a tio n .
U s e r a d d e d s ta tic s c h e d u liln g a lg o r ith m s U s efu l fu n c tio n to o v e rrid e : on_static_schedule
S c h e d u lin g s im u la tio n lo o p
U s e fu l e v e n t h a n d le rs to o v errid e : - on_ready - on_finished - on_preempted - on_scheduled - on_postponing - on_postponed - on_resuming - on_resumed - on_killing - on_killed - on_start_sleep - on_wokeup - on_awaking - on_miss_absolut_deadline - on_miss_relatif_deadline - on_miss_period_deadline - e tc .
S yste m S tatu s
Y es
S p ecify S ch e d ulin g O p tion s o ption 1
No U pd ate S imula tio n w / C u rren t S yste m S ta tu s
o ptio n 2
… o p tio n N
U s e r a d d e d o n -lin e s c h e d u liln g a lg o r ith m s
S che du lin g O ptio n S imu lation o ption 1
o ptio n 2
U s e fu l fu n c tio n to o v e rrid e : on line schedule
… o p tio n N
An aly ze & S e lect S ch ed u ling O ption
S im u la tio n tim e in c r e m e n t
S e lected S ch ed ulin g O p tio n
Figure 2. Scheduling and System Simulation The advocated solution for providing the scheduling simulation framework is achieved by the following strategies: 1. Modeling a set of generic-services on top of SystemC to provide real-time software modeling capability. 2. Modeling the SystemC module in which a scheduling algorithm can be simulated. 3. The solutions must provide the ways to specify the scheduling algorithm on that module and to track the states of both tasks and scheduler in timely manner. The proposed scheduling simulator implements the scheduler in which a scheduling algorithm can be simulated such that its status and all managed tasks states are tractable. In this model the scheduler is implemented as an internal thread that executes the functionality embodied in its main function as outlined in Figure 3. The engine provides the basic infrastructure to build a real-time scheduling simulator suited for particular needs along with a support of a number of scheduling decisions right out of the engine. Consequently, in order to add a new scheduler or task model, in most cases the real-time designer can refine or add only a few specific classes or callback functions rather than to redo everything from scratch during scheduling simulation and analysis. The simulation engine replaces the embedded system CPU and/or the real-time operating system thus simulating the behavior of the entire embedded system under development. Consequently, the simulation engine must provide the way to specify and to execute simulated the scheduling algorithm such that both tasks and scheduler states can be tracked in a timely manner.
4. Extensions to SystemC As mentioned before, in order to realize the environment for scheduling simulation, we provide a set of generic-services on top of SystemC. This approach requires a considerable extension of SystemC modeling features due to the lack of its software modeling capabilities as addressed in [3] which are mainly dynamic process creation, process control (suspend, resume, kill, etc.), scheduler modeling, and task preemption. The extension provides reasonable improvement of its capability to cope with software modeling along with a multi-tasking environment for concurrent and real-time programming. We model and construct the scheduling simulation engine as a complete SystemC module in which a scheduling policy expressed as an algorithm can be executed and then assessed by means of simulation results.
{
O n -lin e s c h e d u le r ta s k s e v a lu a to r
S ystem U nd er D e ve lop me nt S imu la tion
D ecision N ee de d ?
{
Im p le m e n ta tio n s p e c ific c o d e
}
}
B a s ed o n u s e r s p e c ifie d S y s te m C s im u la tio n tim e g ra n u la rity
Figure 3. Body of the Simulator G e n e ric S e rv ic e s A bstract fo r S W ta s k in g R aTnO d S S c h e d u lin g M odel S im u la tio n
M eth o d o lo g y S p ec ific C h a n n e ls
S tan d a rd C h a n n els fo r V ario u s M O C ’s K a h n P ro ce ss N e tw o rk s
M a s te r / S la ve
S ta tic D a ta fllo w , e tc .
L ib ra ry , e tc.
E le m en tary C h a n n els S ig n a l, T im e r, M u te x, S e m a p h o re , F ifo , e tc
C o re L a n g u ag e
D a ta T yp e s
M o d u le s
L o g ic T y p e (0 1 X Z )
P o rts P ro ce s se s In te rfa ce s C h a n n e ls E v e n ts
L o g ic V e cto rs B its a n d B it V e cto rs A rb itra ry P re c isio n In te g e rs F ixe d P o in t In te g e rs
C + + L a n g u a g e S tan d a rd
Figure 4. Enhancements to SystemC
4.1 Generic Services In order to extend SystemC capability with the features for real-time application modeling and scheduling assessment we provide a set of generic services built on top layer based on constructs available in the current version (SystemC 2.0) as architecturally illustrated in Figure 4. Figure 5 presents the basic interface highlighting the proposed generic services as extensions to SystemC. This solution thus provides an environment for embedded system designers to construct their real-time system model using SystemC model since the typical real-time programming techniques and modeling are now enabled. Among those are static or dynamic task creation, modeling task preemption, simulating task execution time, specifying task priority, task periodicity, and task ready time. The enable led capabilities for scheduling simulation and assessment cover both static (event-driven, time-triggered, etc.) and dynamic scheduling (earliest deadline first, least laxity first, etc.).
4.2 SystemC Class Based Implementation The building block of the simulation framework is based on SystemC and C++ classes as illustrated in Figure 6. We classify the classes into three layers. The top level addresses SystemC classes from which the framework’s classes are derived. In the second layer, class sim_task implements the task model. It defines task states along with its internal information (priority, ready time, task identity, period, …). The task methods are defined in the sim_task_interface class, whereas sim_basic_interface defines the basic interface provided
by the simulator engine. The interface deploys the services commonly available in modern RTOS. The class services are realized in the simulation engine class sim_engine, where a simulation engine object can be instantiated directly. The class maintains a task typed vector variable to handle the ready tasks in the queue. The third layer is intended to address user-defined classes. For example, when a user wants to refine the simulation engine class by additional services or by a user defined schedule, he/she can perform it simply by interface definition and class inheritance. First, an interface class (e.g. user_defined_ interface) in which the additional services are specified must be inherited (from sc_interface class). Then, a user customized class (e.g. user_customized_engine) is inherited from both user_defined_interface and sim_ engine classes as shown in Figure 6. Then the bodies of userdefined services are realized in the user_customized_ engine class. Thus, a user can implements the scheduling policy as an algorithm “inserted” into simulator object i.e. the instance of user_customized_engine class. class sim_basic_interface: virtual public sc_interface {
SystemC classes
4.4 Scheduling Policy Definition We propose two distinct approaches to specify scheduling policy by the scheduling. The first approach is based on the callback implementation approach. We refer to this approach as scheduler refinement since the default schedule object internally defined in the simulation engine is still used, but its algorithm is refined based on the user definition. The second approach is based on the port-channel binding concept, where a user specifies the scheduling algorithm by implementation of a schedule object and then links it to the simulation engine schedule port. We refer to this approach as schedule binding.
4.4.1 Scheduler Refinement The implementation of a scheduler algorithm for simulation purposes is done by refining the default scheduler of the simulation engine. In order to support scheduling policy implementations the simulation engine provides two callback function variables, i.e., on_static_schedule and on_line_schedule. The callbacks are prepared to be overrided later by a user-defined function implementing a static
sc_module
sc_event
sc_interface
/* RTOS model & scheduling simulation services*/ virtual void ini()= 0; virtual void start(rt_scheduling sch)=0; /* Task creation & termination services */ virtual rt_task* create_task ( sc_module_name name, void (__closure *mainfunc)(), rt_priority priority, rt_time first_ready_time, rt_periodicity periodicity, rt_time period, sc_time_unit time_unit )= 0; virtual void kill(rt_task *t)= 0; virtual void abort(rt_task *t)= 0; /* Task syncronization services*/ virtual void resume(rt_task *t)= 0; virtual void postpone(rt_task *t)= 0; virtual void sleep(double v, sc_time_unit tu)= 0; virtual void wakeup(rt_task *t)= 0;
*
Framework classes
sim_task_interface
sim_basic_interface
task_methods(…)
sim_basic_services(…)
sim_task - task_atributes + task_methods(…)
*
+ tasks
vector
- runnable_tasks
sim_basic_engine + on_static_schedule + on_line_schedule + event callbacks variables
+ schedule_port
sim_schedule
- events triggering event callbacks
sim_main_function()
offline_policy(…) online_policy(…)
User implementation classes
user_customized_schedule offline_policy(…) online_policy(…)
/* Atominc function execution time modeling*/ virtual void await(rt_time v,sc_time_unit tu)= 0; };
Figure 5. Basic Interface Implementing the Generic Services 4.3 Task Implementation Model The task model is implemented by means of the
sc_thread macro in SystemC as active entity inside the sim_task instance. In order to characterize the task instance, a number of parameters, such as task priority, ready time, arrival periodicity status, arrival period, and simulation time unit, are passed when it is instantiated. In case of preemptable tasks models the task preemption model is constructed in conjunction with the timing model, i.e., by exploiting mainly the await() service provided by the simulator class (see Figure 5). We assume that it is possible to model atomic actions such that any functionality of a task can be built from these actions whereas their executions are atomic in the sense of ‘run–to– completion’. Each atomic action code is assumed to have a fixed current execution time defined by time value passing as a parameter when calling the await() method. As a consequence of this conceptional model, preemption can only happen at the end of the await() statement, which is denoted as the preemption point which, in turn, determines the granularity of a preemption algorithms implementation.
implementation approach I
user_customized_engine user_defined_services(…) offline_policy() online_policy()
user_defined_interface user_defined_services(…)
implementation approach II
.
Figure 6. UML Diagram of Class Layers or dynamic scheduling algorithm. In case of static scheduling, as can be seen in Figure 3, the function will be executed before simulation time. In case of dynamic scheduling, the function is called every time step according to the simulation granularity. To allow the users implementing their own scheduling algorithms, an access mechanism to the list of executable processes present in the simulation engine must be provided. This can be done by passing the access through the parameter list of the overriding function as shown in Figure 7 and Figure 8 that illustrate how a user scheduling policy is implemented by overriding the default algorithm of the simulator.
4.4.2 Schedule Binding The port/interface binding technique is inherently established in the SystemC language. The technique can also be used as a way of implementing the user defined schedule policy into the proposed simulation engine. A port named schedule_port is therefore defined internally and bound to an internal scheduler object as the default component. Later, a user can rebound the port to an externally user-defined scheduler to implement his/her schedule into the simulation engine thus gaining considerable flexibility. Then, the engine will select the latest bounded scheduler to invoke its internal
processes. In this technique, the definition of the new schedule object is done by class derivation form the sim_schedule class provided by the framework. The scheduling algorithm is implemented by overloading the predefined methods. Because the scheduling policy can be either static or dynamic, the class provides two methods to override, i.e., offline_policy()and online_policy(). The methods overriding is illustrated in Figure 8. class user_sim_engine : public sim_engine { public: user_sim_engine_os(sc_module_name name) : sim_engine (name) { on_static_schedule = rma_schedule; on_line_schedule = rma_schedule; } void rma_schedule (vector &tasks) { /* The definition of function “RMA_schedule” is here.*/ } void rma_schedule (vector &tasks, sc_time &t) { /* The definition of function “EDF_schedule” is here*/ } };
Figure 7. Re-scheduling by Callback Overriding class user_schedule : public sim_schedule { public: user_schedule(sc_module_name aname) : sim_schedule(aname){} void offline_policy(vector &tasks) { /* Algorithm of user static scheduling policy is defined here. E.g. RMA */ } void online_policy(vector &tasks,sc_time %t) { /* Algorithm of user online scheduling policy is defined here. E.g. EDF */ } };
Figure 8. Re-scheduling by Port Binding
5. Design Flow to Experiment Results This section demonstrates the feasibility of the proposed methods for embedded systems design by means of an application example. As an example we exploit an autonomous robot equipped with ultrasound distance sensors, a camera, and a wireless data link subsystem, where its entire specification consisting of 17 tasks is captured os a task graph along with their timings properties (estimated max-min execution times). The design flow starts with the allocated specification model. During system design, the functional specification is then partitioned onto multiple processing elements (PEs). In this example, the envisaged generic hardware architecture for the information processing of this robot is a multi-processor system composed from a set of Pes, i.e., a co-processor on a PCI FPGA board, a PC, and a microcontroller attached to the mobile robot. The PEs communicate through a PCI bus (between PC and FPGA) and via a set of wireless RS232 modems (between µC on mobile robot and PC). Due to the inherently sequential nature of one PE, tasks mapped to the same PE need to be serialized and then scheduled statically or dynamically. In case of a dynamic scheduling implementation, a scheduler is required, where in the proposed framework is a customizable component of scheduling simulator module. Next, the process of generating SystemC models of the distributed information processing of the robot is based on the partitioned model of the specification. This generated model forms the basis for the evaluation of the system-level design decisions exploiting the proposed simulation environment. The PEs are modeled by SystemC models that communicate to each other by means of SystemC channels. In order to allow for scheduling with the proposed simulator, the tasks running on each PE are converted into simulator-based tasks created by instantiation from the sim_task class (See Figure 6). By invoking the simulator service for task execution timing (wait()method), the tasks execution times are modeled statistically based on the Gumbel distribution [8]. The resulting model is a SystemC model consisting from multiple PEs modules (PC, µC, FPGA), which communicate via a set of SystemC channels (RS232, PCI Bus). A PE in which more than
one tasks are executed schedules the tasks based on scheduling algorithm implemented on the simulator object instantiated internally in the PE modules (from sim_basic_engine class). In this case the simulator object acts like an RTOS. A scheduling algorithm is implemented on a simulator object by creating the instances from user_custimized_schedule class and overloading its predefined methods provided for scheduling algorithm insertion. Finally, the SystemC simulation is running and relevant simulation data is recorded. Due to the stochastic execution times one hundred different runs were executed and evaluated. The evaluation results regarding task execution times for different scheduling policies are presented in Table 1. In our case, we get a deviation value of about 3% of system ACET on simulation with 10% task ACET deviation selected for each individual task used to generate task execution time. Based on this result a suited scheduling strategy can be chosen. The different scheduling policies are to the simulator by linked callback mechanism, which takes a few seconds and a recompilation. The scheduling co-simulation within the proposed framework takes only 5 seconds for this example on an AMD Athlon™ 1600 processor. Due to the structure of the problem, dynamic or preemptive scheduling does not lead to better results. So, since this robot is not a highly safe-critical application, event driven scheduling is considered as the most feasible strategy in this case. One comes up to this result from high-level analysis of this embedded information system. Table 1. Simulation Performance Results Time triggered Event Driven Priority-based Ordering Preemptive Scheduling
BCET 540 ms 331 ms 335 ms 335 ms
ACET 540 ms 357 ms 361 ms 361 ms
WCET 540 ms 431 ms 435 ms 435 ms
6. Conclusions and Future Work In this paper, a SystemC based scheduling simulator along with its integrated environment is presented. It provides a framework for assessing scheduling algorithms options, while the bulk of the design is modeled in SystemC at a high abstraction level. It is thus possible to exercise both hardware and real-time software modules of system-level allowing early system performance assessment as well as verification and validation of different implementation alternatives and scheduling strategies. Application scenarios for modeling distributed system is a challenging subject for future work in order to extend the simulation methodology for global scheduling analysis.
7. References [1] C. M. Harmonosky, Simulation-Based Real-Time Scheduling: [2] [3] [4] [5] [6] [7] [8]
Review of Recent Developments, In Proc. of the 1995 Winter Simulation Conference, December 1995. SystemC, http://www.systemc.org. T. Grötker, Modeling Software with SystemC 3.0, Synopsys Inc, 6th European SystemC Users Group Presentations, 2002. F. Balarin, et. al., Scheduling for Embedded Real-Time Systems. IEEE Design & Test of Computers, January 1998. J. W. S. Liu, et. al., PERTS: A prototyping environment for realtime systems, In: Proc. of 14th Real-Time Systems Symposium, IEEE, December 1993. N.C. Audsley, et. al., STRESS: A simulator for hard real-time systems. Software Practice and Experience, July 1994. T. Kramp, M. Adrian, R. Koster, An open Framework for Realtime Scheduling Simulation, IPDPS Workshops, 2000. S. M. Petters, How much Worst Case is Needed in WCET Estimation?, In 2nd International Workshop on Worst Case Execution Time Analysis, Vienna, Austria, June 2002.