Execution Time Monitoring in Linux∗
Total Page:16
File Type:pdf, Size:1020Kb
Execution Time Monitoring in Linux∗ Mikael Asberg,˚ Thomas Nolte Clara M. Otero Perez´ Shinpei Kato MRTC/Malardalen¨ University NXP Semiconductors/Research The University of Tokyo P.O. Box 883, SE-721 23, High Tech Campus 32 (102) 7-3-1 Hongo, Bunkyo-ku, Vaster¨ as,˚ Sweden 5656 AE Eindhoven, Holland Tokyo 113-8656, Japan [email protected] [email protected] [email protected] Abstract estimate and the current system state. For example, if only one component is active, then it can run at the maximum This paper presents an implementation of an Execution QoS using 75% of a given resource. However, if a sec- Time Monitor (ETM) which can be applied in a resource ond identical component is started, then both components management framework, such as the one proposed in the will have to adapt to a lower QoS where each of them uses Open Media Platform (OMP) [4]. OMP is a European 50% of the same resource. project which aims at creating an open, flexible and re- In media processing systems, the load is very dynamic source efficient software architecture for mobile devices and the worst case is often unknown (unpredictable) or too such as cell phones and handsets. One of its goals is to high to do worst case resource allocation (since it will im- open up the possibility for software portability and fast ply wasting resources). The initial resource estimate pro- integration of applications, in order to decrease develop- vided by the component is used to create the initial allo- ment costs. The task of the ETM is to measure task exe- cation of resources. However, this initial allocation has to cution time and provide this information to the scheduler be monitored, at run time, to make sure that the allocation which then can schedule tasks in a more efficient and dy- matches the actual resource utilization. For example, the namic way. This implementation is our first step towards estimated processor cycles of decoding one frame of an a full resource management framework that later will in- H264 stream, measured in a given platform, can vary more clude a hierarchical scheduler, for soft real-time systems. than 5 times depending on the video content (and type of frame, number of reference frames .etc). The RMF keeps track of the actual usage (with the use of an ETM) and 1 Introduction signals an alarm when a component consistently under or over utilizes its initial allocation. This alarm mechanism Our previous work includes, among others, a synchro- enables the upper software layers to learn and adapt the nization protocol for hierarchical scheduling [9] and the resource allocation to the real need. The aim of the ETM implementation of a two-level Hierarchical Scheduling is to measure CPU resource utilization and give this in- Framework (HSF) in VxWorks [8]. This paper presents a formation to the RMF, in order for it to conduct resource continuation of our research and aims towards HSF in soft allocation adjustments during runtime. The implementa- real-time scheduling, such as media applications. HSF tion of the ETM is done in Linux because it has a high provides temporal isolation among concurrent executing degree of functionality (an abundance of libraries and de- applications. This isolation enables guaranteed resource vice drivers) in embedded systems and mobile phones [2]. availability for multiple media applications in the context of open platforms, such as the one targeted by the Open Resource management The Resource manager (Fig- Media Platform (OMP) [4]. In this project, media com- ure 1) is in charge of allocating/deallocating resources to ponents encapsulating functionality (such as video/audio application components. It also provides admission con- decoders) have the capability to trade Quality Of Service trol (checking feasibility before allocating requested re- (QoS) for resource usage, e.g., memory or CPU resources. sources) and enforcement to ensure that the allocated re- The aim of the OMP project is to standardize the inter- sources are also guaranteed. The resource manager has faces, used to adapt QoS, to achieve portability, reusability an overview of the system resources, whereas for ev- and easy integration. In particular, to trade resources, the ery shared resource, the corresponding Resource con- Resource Management Framework (RMF) offers an in- troller implements the resource allocation and monitoring terface to allocate a guaranteed amount of resource (e.g., mechanisms for that resource. For each resource, the re- CPU) to components, based on the component resource source controller keeps track of the allocation of resources ∗The work in this paper is supported by the Swedish Foundation for (Resource budget), its users (Resource users which is Strategic Research (SSF), via the research programme PROGRESS. basically components) and the runtime usage (Resource usage) of a given resource user on a given resource bud- then iterates trough a chain of scheduling classes (Fig- get. ure 3), where each of these classes tries to fetch the next running task. Eventually, idle class will pick a next task to Resource manager run if no higher class has succeeded with this. All schedul- ing classes share the same interface (set of functions), this Resource controller Resource controller Resource usage 35% Resource budget 16% makes it is easy to add new scheduling classes without changing the core scheduler. Resource user Resource usage 39% Resource (memory) Resource (CPU) class = sched class highest /* The latter is a global kernel variable, 1st: real-time scheduling class. */ Figure 1. Resource management WHILE (TRUE) p = class.pick next task(run queue) IF(p) CPU resource allocation The CPU resource controller RETURN p is realized with a HSF, illustrated in Figure 2. Our next ENDIF step is to implement this scheduler with minimum mod- class = class.next /* 2nd: fair scheduling class. */ ification on the operating system, similar to the imple- ENDWHILE mentation in [8]. The Global scheduler will schedule the Budgets according to their allocation (T ime interface) Figure 3. Sample pseudo-code of function pick next task, and an arbitrary scheduling scheme. T asks are scheduled which is part of the Linux scheduler (sched.c) within the budget according to the scheduling strategy of the Local scheduler. The global scheduler schedules the The outline of the paper is as follows: Section 2 budgets periodically, the budget runs according to a pre- presents related work. In Section 3 we present the im- defined amount of time and the order of execution of the plementation of our ETM in Linux and discuss how it can budgets are decided by the budget priorities. The admis- be applied. Finally, Section 4 concludes. sion control checks whether the current configuration of budgets are schedulable. This check is done if new bud- 2 Related work gets are activated or if running budgets need to change pa- rameters in their time interface. Tasks within a budget are The AQuoSA framework [11] is a RMF based on CBS assumed to be schedulable, with respect to the budget time scheduling with advanced adaptive resource reservation. interface. Parameters in the budget time interface such as The framework is built on a patch which exports appro- period, execution time and priority may be dynamic, e.g., priate scheduling hooks. they may change during runtime. Unused budget may be In [12], the authors present a RMF consisting of server allocated to tasks belonging to other budgets (weak en- based scheduling of tasks and a predictable disk schedul- forcement). ing mechanism. CPU usage monitoring is used within the framework to calibrate application resource usage. Global scheduler RTAI [7] is a collection of loadable modules that pro- vides a rich real-time Application Programming Interface Time interface Time interface Time interface (API) to the user, trough the usage of a hardware abstrac- Budget Budget Budget tion layer named ADEOS [1]. The RTAI API includes Local Local Local Scheduler Scheduler Scheduler add/delete hooks for every task start, switch and delete. RT-Linux [5] is a patch to the Linux kernel and intro- Task ... Task ... Task ... Task ... Task ... Task duces a layer between the OS and the hardware. Linux is scheduled as low priority task while real-time tasks have Figure 2. Hierarchical scheduling framework higher priority (similar to [7]). Scheduling classes in Linux Starting from Linux ker- Related to CPU allocation, cgroups [3] is a Linux nel version 2.6.23 (released in October of 2007) [6], patch which partitions processes into groups and give there is a distinction between real − time and regular them a specified share of the processor. Each partition is tasks. This is done by the introduction of two schedul- scheduled according to its period and will run a predefined ing classes: real-time and fair scheduling (sched rt.c amount of time. All groups must have the same period. and sched fair.c). Basically, a Linux process is either regular or real − time depending on which scheduling 3 Execution time monitoring policy that it is configured with. The processes which are real−time have higher priority (0-99 where 0 is the high- The ETM provides the resource manager with infor- est) than regular processes. Whenever there is a schedul- mation, in order for it to analyze the suitability and to ing event (time-slice expiration, task suspend/sleep, etc.), fit a resource budget for a given resource user(s). Most the CPU (for which the scheduling event belongs to) run- monitors are time-stamp based with a coarse time-base, queue (ready-queue) is fetched. The Linux core scheduler e.g., time consumed by a task during the past 5 seconds. In this case we get an average value, without knowledge hook fair.