Real-time Limited Preemptive Scheduling
Full text
FACULDADE DE ENGENHARIA DA UNIVERSIDADE DO PORTO Real-time Limited Preemptive Scheduling José Manuel Silva dos Santos Marinho Doutoramento em Engenharia Electrotécnica e de Computadores Orientador: Stefan Markus Ernst Petters (Dr.) 2015
c José Manuel Silva dos Santos Marinho, 2015
Real-time Limited Preemptive Scheduling José Manuel Silva dos Santos Marinho Doutoramento em Engenharia Electrotécnica e de Computadores 2015
This thesis was partially suported by FCT (Portuguese Foundation for Science and Technology) under PhD grant SFRH/BD/81085/2011 UNIÃO EUROPEIA Fundo Social Europeu
O desenho de sistemas reativos de alto desempenho depende do controlo preciso de variáveis impactantes no comportamento do sistema. As entidades responsáveis por este controlo tomam, comummente, corpo num dispositivo computacional digital. As propriedades dinâmicas dos fenómenos sob controlo, em conjunto com os requisitos de comportamento pretendido pelo projetista, impõem restrições ao máximo espaçamento temporal entre a observação de um evento e a correspondente atuação. A área de sistemas de tempo-real providencia uma base teórica sobre a qual propriedades temporais do sistema são estudadas, possibilitando a derivação de garantias mínimas de desempenho. As análises providenciadas são por definição seguras, i.e. , qualquer garantia dada sobre a obtenção das metas temporais será verificada, sob qualquer pretexto concebível, durante a utilização do sistema. Uma análise segura tem geralmente associada a si um nível de pessimismo. Pessimismo, em termos gerais, é uma medida da dificuldade de caracterização do pior caso possível verificável durante a utilização do sistema, por mais improvável que seja a ocorrência desse pior caso. É somente possível reduzir o pessimismo das análises através do uso de estratégias de escalonamento que se caracterizem por uma maior e melhor especificação das circunstâncias observadas durante a utilização do sistema. Estas políticas de escalonamento deverão obter um desempenho melhor ou semelhante àquelas em que existe menor informação sobre os possíveis cenários. As características temporais do sistema são largamente afetadas pelo fenómeno da preempção. Uma preempção define-se pela interrupção de uma dada tarefa, por outra de maior prioridade, durante um intervalo de tempo. A tarefa que interrompe acede a recursos partilhados alterando o seu estado. Quando a tarefa inicial tornar a executar, irá sofrer uma interferência temporal adicional devido à alteração de estado dos recursos partilhados. A natureza deste tipo de interferência é bastante complexa. Inerentemente, a caracterização do pior cenário possível esta dotada de um pessimismo acentuado. Nesta tese o comportamento das preempções e as suas consequências, no pior caso, são estudadas num enquadramento de prioridades limitadas, o que permite a redução considerável do pessimismo das análises temporais em comparação com os métodos existentes na literatura. Os algoritmos de escalonamento providenciados oferecem melhores garantias de desempenho na fase de conceção, bem como melhor comportamento em média durante a execução do sistema. i
ii
Abstract Physical phenomenons, regardless of its degree of human intervention, from the more pristine to the more vain facets of some human made appliance, require controlling strategies to achieve an intended set of properties or some performance level. The controllers’ implementation may range from the simpler mechanical or analog circuitry but more commonly are embodied as a recurrent set of commands on some computational boolean logic device. The dynamic properties of such physical phenomenons, paired with the designer intended behaviour, impose restrictions on the maximum delay between an event and the desired actuation. Real-time systems strive to provide a framework where the considerations about the overall system’s temporal feasibility are drawn. In a nutshell, real-time systems enable guarantees on the temporal properties of the computational apparatus which are used in such control loops. Any analysis used in the hard real-time framework should be proven safe. This generally means that the outcome of any analysis states whether all the temporal properties can be guaranteed or that some cannot be trusted upon. The quantity of pessimism involved in the analysis – which leads to an abundance of false negatives or to an over-provisioning of resources – should be reduced as much as possible. Analysis’ pessimism can be thought of, in broad terms, as an artefact of the lack of information necessary to accurately characterize the worst-case temporal behaviour of each application. The pessimism can only be mitigated by employing mechanisms where more abundant information about the worst-case run-time behaviour is available. These mechanism should nevertheless have a better or comparable performance to the ones with reduced certainties. In this thesis both scheduling algorithms and accompanying analysis tools are provided which, by enhancing the available information about what might happen at run-time, allow for a reduction on the level of pessimism associated with the analysis outcomes and bring a better performance in the average case situation. An interesting aspect pertaining to realtime systems is the nature and implications associated with pre-emption. A pre-emption occurs when an application is swapped for another in the execution platform to which it eventually returns. Besides from the time the pre-empting application prevents the preempted one from executing, some shared resources are accessed by the former which will potentially interfere with the remaining execution of the latter. The nature of the interference occurring at such resources as the caches or dynamic branch predictors just to name a few is highly complex to analyse and generally a single and oftenly quite isolated worst-case quantity is assumed in the state-of-the-art real-time analysis. The quantification of the worst-case penalty associated to pre-emptions and the bounding their frequency of occurrence constitutes the bulk of this thesis’ contribution. Both scheduling algorithms as well as analysis are provided that both decrease the worst-case number of pre-emptions and also diminish the penalty considered per instance of this event. iii
iv
Acknowledgements I feel fortunate for having had the opportunity to conduct research in such a supportive Laboratory where much of the strain of being a PhD student is waned. I am grateful to Eduardo Tovar for having built such a sustainable research environment where any reasonable material request is hardly ever denied. CISTER’s team – non-static in time – was always extremely capable. I wish to acknowledge all of the people whose time frame in this team overlaps with mine (even if partially) and to thank all of whom positively contributed to my experience here, whether with fruitful discussions or by easing much of the every-day bureaucracy as Sandra Almeida, Inês Almeida and lately Cristiana have so efficiently done. A note of appreciation is due to Dr. Vincent Nélis for his contribution to this work and for his habit of finding holes in other people’s work, which I find most amusing and ever since tried to mimic. I am invaluably grateful to Dr. Stefan Petters for enduring me throughout these years. In many accounts he has been a thoughtful and kind supervisor. I wish to thank him especially for his patience with my deambulations, my random neglect for bibtex entries and for always making the effort to motivate me. His expertise on the pre-emption delay, WCET computation, systems architecture (processor and O.S.) and on general real-time scheduling subjects were fundamental for the development of many aspects of my work. More recently, his commitment to reviewing this document was truly remarkable. Research duties aside, I will always remember the time when we (along with Filipe Pacheco and Björn Andersson) did a 2 day road-trip across Europe (from the approximate N.E. extreme to the S.W. corner – all thanks to Eyjafjallajökull, RTAS 2010 and CISTER money), this one is truly memorable for me, despite it being strenuous at the time. Several contributions in this thesis resulted from collaborations with researchers external to CISTER, namely Dr. Isabelle Puaut, Dr. Robert I. Davis and Dr. Marko Bertogna. I am deeply thankful to all the co-authors for the time they put on the discussions we had and solutions collaboratively derived. I wish to thank Dr. Michael Paulitsch for having hosted me at Airbus Group Innovations and for giving me a task to perform which was as much to my liking as it was challenging. Several people exerted a positive influence on me through the years, out of that set I find it only fair to mention Professor Gabriel Falcão in this context. As my MSc. thesis co-advisor he was largely responsible for getting me interested by academic research. Finally, I would like to thank my Mother for nurturing my curiosity from early age. I am mostly grateful to my family for their encouragement and for accepting the choice of delaying my entry into adulthood, and to Sara for having shared all this time with me, keeping me focused whenever I went astray, for being my partner in the full sense of the word. v
CONTENTS xii
List of Figures 1.1 Flight Level Closed Loop Controller Diagram . . . . . . . . . . . . . . . . 2 1.2 Correct controller behaviour versus incorrect behaviour . . . . . . . . . . . 3 1.3 Conceptual Real-time System . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.4 CacheRepresentation............................. 9 2.1 ExampleCFG................................. 17 2.2 Limited Pre-emptive Schedule vs Fully Pre-emptive Schedule (task-set in Table 2.1) ................................... 29 2.3 Floating Non-pre-emptive Region Scheduling Example . . . . . . . . . . . 30 3.3 Scenario Motivated by Theorem 2 . . . . . . . . . . . . . . . . . . . . . . 46 3.4 Outline of the Devised Approximations for Equation 3.3 .......... 46 3.8 Ready-Q Locking Example. . . . . . . . . . . . . . . . . . . . . . . . . . 56 3.9 rlist List Evolution over Time . . . . . . . . . . . . . . . . . . . . . . . . . 57 3.10 Schedulability Condition . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 3.11 Set of Relevant Offsets for Frame q..................... 63 4.1 Example of CFG for loop-free code. . . . . . . . . . . . . . . . . . . . . . 75 4.2 Comparison between Function fiand the Run-time Pre-emption Delay . . . 77 4.3 Algorithm iteration sketch . . . . . . . . . . . . . . . . . . . . . . . . . . 78 4.4 Example glocal bFunction Where BBbExecution May Generate at Most 10 ExtrinsicCacheMisses............................ 82 4.5 gout bComputation for BBb........................... 83 4.6 Algorithm Iteration Sketch . . . . . . . . . . . . . . . . . . . . . . . . . . 85 4.7 flocal b(t)GraphicalExample ......................... 91 4.8 Task Wide fi(t)Obtention .......................... 91 5.1 Sporadic Server Budget Replenishment . . . . . . . . . . . . . . . . . . . 99 5.2 Budget Augmentation Example . . . . . . . . . . . . . . . . . . . . . . . . 104 5.3 Excessive Pre-emption Delay Due to Minimum Interarrival Time Violation 107 5.4 Budget Augmentation Example . . . . . . . . . . . . . . . . . . . . . . . . 111 5.5 Pre-emption Delay Compensation Array . . . . . . . . . . . . . . . . . . . 112 5.6 Bit Field Snapshots of Relevance . . . . . . . . . . . . . . . . . . . . . . . 113 6.1 Functions WNC(τj,t)and WCI(τj,t)depiction for a given task τj......120 6.2 Functions Wdiff(τj,t)depiction for two distinct relations between Cjand Rj123 xiii
LIST OF FIGURES 6.3 Intersection Points Between the Wdiff(τj,t)Functions of Distinct Higher PriorityTasks.................................124 6.4 Possible Priority Inversion After a Job From τiCommences Execution in RDS127 6.5 Maximum Interference Function Due to mNon-pre-emptive Regions of Lower or Equal Priority Tasks . . . . . . . . . . . . . . . . . . . . . . . . 131 6.6 Depiction of the solution provided for Problem 1 . . . . . . . . . . . . . . 134 6.7 Blocking Estimations (k=8,n=88). . . . . . . . . . . . . . . . . . . . . . . 139 6.8 Observed Pre-emptions in Simulated Schedules, m=2,n=20 . . . . . . . . . 140 6.9 Observed Pre-emptions in Simulated Schedules, m=2,n=32 . . . . . . . . . 141 6.10 Observed Pre-emptions in Simulated Schedules, m=4,n=32 . . . . . . . . . 141 6.11 Observed Pre-emptions in Simulated Schedules, m=4,n=64 . . . . . . . . . 142 6.12 Results for m=2 and n=10 with Ti∈[400,40000]..............143 6.13 Results for m=2 and n=20 with Ti∈[400,40000]..............144 6.14 Results for m=4 and n=20 with Ti∈[400,40000]..............144 6.15 Results for m=4 and n=40 with Ti∈[400,40000]..............145 6.16Executionmodel ...............................147 6.17 depiction of a mpre-emption chain triggered by a single job release . . . . 148 6.18 Results for m=2 and n=10 with Ti∈[400,40000]and CPMD value per Preemption as a random variable in the interval [0,40].............150 6.19 Results for m=2 and n=20 with Ti∈[400,40000]and CPMD value per Preemption as a random variable in the interval [0,40].............151 6.20 Results for m=3 and n=15 with Ti∈[400,40000]and CPMD value per Preemption as a random variable in the interval [0,40].............152 6.21 GEDF Example Schedules. . . . . . . . . . . . . . . . . . . . . . . . . . . 155 xiv
List of Tables 2.1 Limited Pre-emptive Motivating Task-set . . . . . . . . . . . . . . . . . . 29 3.1 Example Task-set Denoting a Pre-emption Corner-case . . . . . . . . . . . 48 3.2 Floating Non-Pre-emptive Increased Schedulability Task-set . . . . . . . . 53 3.3 Floating Non-Pre-emptive Unschedulable Task-set . . . . . . . . . . . . . 54 6.1 GEDFexampletask-set............................154 xv
LIST OF TABLES xvi
Acronyms and Abbreviations ACS Abstract Cache States BB Basic Block BRT Block Reload Time CFG Control Flow Graph CPMD Cache Related Preemption and Migration Delay CRPD Cache Related Preemption Delay CUV Cache Utility Vector DJP Dynamic Job Priority ECB Evicting Cache Blocks ECS Evicting Cache Set EDF Earliest Deadline First FJP Fixed Job Priority FTP Fixed Task Priority GFTP Global Fixed Task Priority LCS Live Cache State LMB Leaving Memory Blocks RCS Reaching Cache State RMB Reaching Memory Blocks RQL Ready Queue Locking RTA Response Time Analysis SIL Safety Integrity Level UCB Usefull Cache Blocks WCET Worst-case Execution Time WCRT Worst-case Response Time xvii
ACRONYMS AND ABBREVIATIONS xviii
Chapter 1 Introduction The vast majority of the digital computing devices are embedded into larger systems, where the functionality is greater than the one provided by the computing apparatus. Some of these embedded devices, due to the constraints of the systems in which they are embedded, need to meet temporal requirements. The term real-time is sometimes miss-understood. Real-time systems as a subject does not necessarily deal with high performance devices where the focus is on the presentation of the results to the user such that the illusion of latency absence would be produced. Straightforwardly, real-time system design focuses on obtaining upper-bounds on the completion time of a given workload on a given hardware platform. In order to derive such upper-bounds the specifics of the workload and of the execution platform need to be studied. Generally a model of the workload is created and the assessment of the schedulability is done considering its characteristics. Any considered system is assumed to be deterministic. This means that if the initial state is fully characterized and the model is sufficiently detailed then a perfect description of future states is obtained. Both the attainment of the full initial state description and the model might be prohibitively expensive in time and complexity terms. Hence generally over-approximations of both are considered in the analysis. The level of detail contained in the workload and the hardware platform models influences the pessimism involved in the analysis and the time consumed to perform it. It is common that increasing the detail level of the model leads to lengthy and more complex analysis processes. Rather than dealing with average-case situations, the analysis in real-time systems is concerned with the worst-case scenario. For this scenario, which has to be specified on the framework provided by the concrete model adopted, each task in the system is certified to finish the entire work issued by it before a pre-specified time instant. This time instant is commonly referred to as the deadline. If the worst-case workload completion time is smaller than the workload deadline than the workload is termed schedulable on that platform. 1
1.1. REAL-WORLD TIMING REQUIREMENTS 1.1 Real-world Timing Requirements Any outcome emerging from the processing carried out from a digital computer loses interest as time passes. The sole purpose of computers is to process and transmit signals to a given entity which at times takes decisions and acts based on the provided output. An entity may entrust a computer with the task of answering a given question, say, the “Ultimate Question of Life, the Universe, and Everything” 1. If the answer is presented 7.5 million years later, so long that the entity forgot what the question was, little usage exists for the glorious outcome of 42. Whether 42 is a correct outcome or not is not of importance in real-time systems research but rather the focus of the areas of dependability and reliability. Real-time systems research focuses only on the timing aspects of the solution generation. In the most evident scenarios a timing drift of the output generation instant from the actual useful output generation time interval brings no consequence other than lack of system responsiveness and frustration for the eventual operator. There are cases though, where the failure to generate the computation output on time has substantially more severe consequences. Let us observe the requirements of a given system responsible for adjusting and maintaining a plane cruising altitude. This system, given an altitude set-point, will be responsible for actuating on the airplane control surfaces and engines such that the set-point is reached while meeting certain performance requirements. altitude set point Ki Kdd dt Rdt Kp Figure 1.1: Flight Level Closed Loop Controller Diagram In this example the altitude controller is implemented with a classic Proportional Integral and Derivative (PID) controller (Figure 1.1). After the controller parameters are tuned in continuous time so as to achieve the intended closed loop system behaviour, the controller 1illustrative example extracted from the book “The hitchhiker’s guide to the galaxy” , ISBN:0517542099 9780517542095 2
1.1. REAL-WORLD TIMING REQUIREMENTS is mapped into an equivalent discrete time controller. The discrete time version of the controller is implemented in software and run in the execution platform. The specificities of the controller parameter tuning and mapping process from continuous time to discrete are not fundamental for the understanding of the issues up for discussion. The single fact that the reader must acknowledge is that during the mapping procedure one sampling period is chosen (Ts). This sampling period is at the heart of the controller description and behaviour. In order for the closed loop transfer function to be in accordance with the one derived, this sampling rate must be stringently met. This means that at every Tstime units the set-point has to be evaluated as well as the current airplane altitude. Having the two input variables the control signal is computed. This computation has to be completed before the next control period. The consequences of not meeting the strict timing requirements of this controller may be mild, in the sense that the system may take longer than intended to match the actual altitude to the set-point. In a worst case the controller may become unstable, leading to violent altitude oscillations from the plane as depicted in Figure 1.2. If the system does not behave according to the specification, given some circumstances, it may lead to life threatening situations or significant financial losses. It is fundamental to ensure that such situation can never happen irrespective of the circumstances 2. time Altitude time Altitude Set point Set point Figure 1.2: Correct controller behaviour versus incorrect behaviour In order to prove the correct temporal behaviour of the system a framework where such proofs can be derived is required. In this framework the interaction between different softwares and the executing platform is modelled. Let us describe a possible system abstraction where the correct temporal behaviour of the system can be proven. 2The presented PID example constitutes an oversimplification of a flight controller implemented in a digital apparatus, its intention is solely to illustrate the origin of the temporal constraints in hard real-time systems 3
1.4. BACKGROUND ON CACHES cache-set-map is defined as follows: cache-set-map(address,line-size,#cache-sets)def =address line-sizemod #cache-sets.(1.2) This means that whenever a memory location is referenced, when the corresponding memory line is fetched it will be mapped to the cache-set-map(address,line-size,#cache-sets) cache set and stored in some cache lines belonging to that set. When a memory address is referenced two situations may arise: •address is in cache in which case a cache hit is said to occur •address is not in cache at this time a cache miss occurs, and the line where the referenced memory address sits is loaded into the cache. A memory reference is generally between one to 64 bits in length and the address points to the first byte. When a memory is referenced the entire line where the memory is resides is brought to the cache. This means that when a given address is referenced then the line-size bytes in the set {address mod #associativity,··· ,(address mod #associativity)+line-size} are loaded into the cache. If the destination set is filled with valid memory lines but does not contain the referenced memory block, one of the lines present in the set has to be evicted in order to make space for the current line reference. There exist several cache replacement policies that mediate the line eviction on the cache sets. The most commonly considered in worst-case execution time assessment are Least Recently Used (LRU), First In First Out (FIFO), Pseudo Least Recently Used (PLRU). •LRU: From all the memory blocks in a given set, the one which was referenced the furthest in the past is the one evicted at the time of a new memory block insertion into the cache set. Since this replacement policy relies on dlog2(#associativity!)e additional bits per cache-set so as to preserve a full track of the entries age it is uncommon for LRU to be employed for #associativity >4; •FIFO: if a given memory block is not in the cache set then it is inserted into the cache head and evicts the last element in the queue. A memory reference to a given line in the set does not alter the set ordering. Hence, a cache line can only survive in a set for I−1 new element insertions •PLRU: There exist several possibilities of implementing this type of cache replacement protocol. Overall, it tries to approximate the behaviour of LRU without incurring on the resource usage and greater latencies involved with actual LRU implementation. In the tree based implementation, the log2(#associativity) + 1 most recently 10
1.4. BACKGROUND ON CACHES used cache lines are safe from eviction [RGBW07], whereas an eviction victim is chosen dependent on the state of the tree from the #associativity−log2(#associativity)− 1 remaining cache lines. This implies that PLRU caches may be approximated to an equivalent LRU cache with #associativity0=log2(#associativity) + 1 and size cache-size0=#associativity0×line-size×#cache-sets. By far the most employed in modern processors, when #associativity >2 is PLRU, for #associativity =2 then LRU is commonly used. Once the cache set and the cache line where the referenced memory line is going to be placed, the evicted cache line may or may not be written to the lower memory level. This will largely depend on the write policy of the cache. The two most common are: •write-through: all memory block modifications are added to the cache and in parallel written to lower memory levels; •write-back: changed memory blocks in the cache are only written to lower memorylevels once an eviction occurs. The write-through will have as a consequence that every memory store induces a change on main memory following said reference. This may greatly increase the traffic observed in the communication bus. On the other hand the write-back policy has the unfortunate consequence that when a write occurs which yields a cache miss then it can only be completed once the evicted cache is written onto lower levels. This situation only occurs in data caches, since generally instructions change (self-modifying code) is not perceived as an architectural use-case. In the architectural model employed in this work we use two values to model the behaviour of cache hits and misses. A cache hit has a latency of THIT time units. In regular processors THIT is a constant value of between one or few processor clock cycles. The systems considered are composed of a single cache level, hence a cache miss occurrence triggers a memory fetch from main memory to the cache. A cache miss is assumed to have a latency TMISS. Even though a cache miss will have a variable latency, TMISS is conservatively assumed to be a constant, upper-bounding the maximum amount of time that a memory block takes to be transfered from main memory to the cache, which is one memory operation for write-through and two memory accesses for the write-back policy (in case the evicted line had been modified – dirty bit set). This previously holds true for data caches, whereas the TMISS for instruction caches is set to one memory access time irrespective of the write policy. Furthermore we will restrict our model to systems for which #associativity =1 since it allows for easier explanation of the concepts and extensions to #associativity >1 for well behaved replacement policies as LRU are trivial to obtain. If a task has several memory blocks in cache which may reuse in the future and its execution is interrupted by another task, some of these blocks may get evicted. When the 11
1.5. THESIS ORGANIZATION task resumes execution the state of the cache will be distinct in relation to the point when it was pre-empted. Eventually the task as it executes requires the state of the cache to be reestablished. The reconstruction procedure is subject to time penalties. In real-time systems, where timeliness is an essential property of the system, these penalties need to be carefully evaluated to ensure that all deadlines are met. Generally, since the WCET is computed for each task in isolation, all the overheads attached to the scheduler pre-emptive behaviour are not present in the WCET value. The consequences of pre-emptive behaviour then has to be accounted for at later stages of the schedulability analysis. In order to avoid double accounting of overheads, it is important to have in mind the assumptions and procedures used in the WCET computation. For instance the cache misses considered in WCET should not be again considered as an effect of the pre-emptive behaviour. Once an upper-bound of the overheads has been computed an integration into the schedulability tests is performed for the current workload such that the schedulability is guaranteed in any possible scenario. More on the subject of WCET computation, pre-emption delay assessment and schedulability conditions taking both parameters into account are described in Chapter 2. 1.5 Thesis Organization The thesis put forward on this work grounded both on several state-of-the-art works and novel contributions presented in this document is clearly posed in the following wording: Thesis– Limited pre-emptive schedulers allow for significantly reducing pessimism in the pre-emption delay accounting in single-core and for enhanced schedulability when employing global fixed task priority schedulers. In this thesis the theory of limited pre-emptive scheduling is addressed and extended. Following this preliminary chapter(1), where the work is put into context and a broad depiction of the real-time area is provided, the related work is described (Chapter 2). The related work chapter covers the aspects of the worst-case execution time computation strategies. The assumptions taken during these steps greatly influence the considerations taken during the pre-emption delay assessment. An overview of the literature pre-emption delay assessment strategies for regular fully-pre-emptive scheduling is provided. Finally some further information is provided on the matters of limited pre-emptive theory in single-core and related to the temporal-isolation aspects. The bulk content of the thesis is provided in the chapters succeeding the state-of-the-art. The thesis can be broadly organized in in four main areas content-wise: •Single Processor Limited Pre-emptive Theory Extension (Chapter 3): 12
1.5. THESIS ORGANIZATION The single-core limited pre-emptive theory for fixed task-priority scheduler is revisited. An series of methodologies are provided which, by resorting to information available at run-time, allow for extensions to the non-pre-emptive region length to be obtained. The properties of the algorithms with respect to pre-emptions is studied and upper-bounds on the number of pre-emptions are derived. Experimental results are presented showing that the proposed solution reduces the observed number of pre-emptions when compared to the state-of-the-art limited pre-emptive method. A method to increase the schedulability in a similar way to the one achieved with fixed non-pre-emptive regions is also presented in this chapter. Unlike the more static limited pre-emptive schedulers (fixed non-pre-emptive) the more dynamic (floating non-pre-emptive) does not easily allow for schedulability increases. The presented ready queue locking mechanism prevents higher priority releases that occur after a prespecified time instant to interfere with lower priority pending work. An integration of this methodology with the well known pre-emption threshold is described as well. The derivation of the schedulability conditions is presented. •Pre-emption Delay estimation for the Floating Non Pre-emptive Region Model (Chapter 4): The usage of the floating non-pre-emptive region model in the state of the art works so far only allowed for a reduction on the number of pre-emptions quantified at design time. In this section the scheduling information is exploited in the analysis along with a further description of the workload to be executed and the evolution of the pre-emption delay cost as the execution progresses. A method which considers a function of the pre-emption delay per progress unit is described which yields an upper-bound on the pre-emption delay a task is subject to in the floating non-pre-emptive region model. Further extensions to this model are provided that take into account an additional function and reduce the pessimism taking into account assumptions from the WCET analysis phase. •Ensuring Temporal-isolation in Platforms with Non-negligible Pre-emption Overheads (Chapter 5): More often than not, temporal-isolation is overlooked in the realtime theory. The same cannot be said in industry where strong independence must be proven between separate workload modules in order for systems to be certified. This Chapter proves that the state-of-the-art temporal-isolation solutions are wasteful of resources and that in more complex models fail to provide the temporal-isolation property at all. An alternative method to encompass the temporal-isolation problematic in systems with non-negligible pre-emption delays is described. This method is presented for single-core scheduling but can be adapted to multi-core scheduling as well. 13
1.5. THESIS ORGANIZATION •Derivation of the Limited Pre-emptive Theory for Global Multiprocessor Scheduling (Chapter 6): This Chapter delves on the multi-processor limited pre-emptive theory. The derivation of some models for limited pre-emptive scheduling (fixed non-pre-emptive) is described for global fixed task priority. The floating non-pre-emptive region model theory is further addressed as well. Even though most of the work was carried out assuming fixed global task priority schedulers it is shown that the limited pre-emptive scheduling mechanism allows for a schedulability increase in the GEDF case. Experimental results were obtained in order to assess whether the same patterns observed for single core would translate into global scheduling with respect to schedulability and overall estimation of pre-emptions. The thesis is finalized by Chapter 7where a summary of the thesis is provided and the a list of possible future directions is debated. 14
Chapter 2 Related Work 2.1 WCET Upper-bound Computation Execution time bounds for task operation are an ubiquitous input in real-time systems theory. The value is computed in isolation or with the inherent assumption of non-pre-emptive execution. The computation of these upper-bounds may be divided into two distinct categories. 1. Measurement Based 2. Static Analysis 3. Hybrid 2.1.1 Measurement Based Measurement based WCET estimation procedures rely on the end-to-end or partial execution of the task in order to extract an estimate of the upper-bound. A set of relevant input vectors is decided a-priori by the system designer. The main drawback of this approach is that it is often impossible to know a-priori which input vector will lead to the worst-case execution time. As a result the largest execution time observed can not be trusted as a safe upper-bound, and thus can not really be employed as an input for schedulability assessment in hard real-time systems. An additional concern is that measurement based WCET estimation does not easily allow for the quantification of the pre-emption delay associated to each task. 2.1.2 Static Analysis A different approach for the execution time estimation is the static analysis of the task. This methodology relies on four specific steps: 15
2.1. WCET UPPER-BOUND COMPUTATION •Control Flow Graph (CFG) extraction; •Micro-architectural modeling; •Value analysis; –Path analysis; –Constraint analysis; •Value computation In the first step the program is parsed at source or machine language level in order to extract valuable information for subsequent analysis steps. Using abstract interpretation a structural representation of the program is achieved [CC77]. This abstract representation is a directed graph denominated control flow graph (CFG) [CP01]. The set of nodes composing a CFG are of different types: •Entry: has no predecessors and a single successor; •Assignment: has exactly one predecessor and one successor. The functional parts of the code (i.e. the actual instructions) are associated to this node; •Test: has a predecessor and two successors. The jump instructions are associated with such nodes; •Junction: has more than one predecessor and a single successor. Every execution path joining will occur in this node type; •Exit: has one predecessor and no successors. A CFG is then a directed graph where nodes are termed basic blocks. An example is provided in Figure 2.1. At this point the CFG is again parsed, at the value analysis step, in order to remove infeasible paths, and extraction of loop bounds. This is done either by knowing the set of possible inputs or by analyzing the semantics of the program. The information present in the CFG may be exploited by several techniques to compute the WCET. As next step, the Micro-architectural modeling procedure is performed. This is constituted by analyzing each instruction in the assignment Basic Block (BB) of the CFG with respect to its latency. Another important aspect of this stage of WCET computation lies on the classification of the memory references with respect to both instruction and data caches. In order to classify each memory instruction the CFG is parsed by two fixed point algorithms, the must and may analysis, with the knowledge of the cache, line size and associativity level. The must analysis computes, for each program point the set of memory lines 16
2.1. WCET UPPER-BOUND COMPUTATION which must be in the cache at each program point. The may analysis, in contrary, computes the set of memory lines which may be in the cache for every program point. Both must and may analysis sets are Abstract Cache Set (ACS) since they are the product of an analysis which does not consider a specific program path. This in turn yields the following memory reference classification: •always-hit (AH): at the given program point the memory address referenced by the instruction is present in the ACSmust; •always-miss (AM): at the given program point the memory address referenced by the instruction is not present in the ACSmust nor in the ACSmay; •not-classified (NC): the memory line referenced in the current instruction is not in the ACSmust but is part of the ACSmay. For a system with a single cache level the memory references classified as AH will be treated as a cache hit, whereas the ones classified as AM and NC are treated as cache misses. 1 3 4 5 2 0 6 Figure 2.1: Example CFG With the memory classifications available, the cost of executing each basic block is extracted. As a last step the value computation is performed. Having the cost of each basic block execution and the set of feasible paths in the CFG, a technique called Implicit Path Enumeration is used. In this framework all possible paths from the CFG are encoded in a linear equation which is then maximized. The outcome of the maximization is the WCET for the given task. A simpler mechanism may be used in the value computation stage. This method termed tree based analysis relies on the information provided by a syntax tree rather than a CFG. Though the procedure may be explained from a CFG perspective. Basic blocks belonging to the same path segment have their execution cost summed in order to create a fictitious node with the computed execution cost. In the case of a conditional path in the CFG the 17
2.2. PRE-EMPTION DELAY ESTIMATION maximum between the two possible fictitious nodes is taken and another fictitious node is created to represent this conditional part of the program. Overall the main drawback of static WCET computation is that it relies on an accurate model of the target platform. This, in order not to be optimistic, will have to rely on pessimistic values for the parameters used to model the behaviour of the execution platform. On the other hand measurement based mechanisms can never be guaranteed to be safe and since no cache analysis is performed will always lack information to compute an upper-bound on the CRPD. 2.1.2.1 Hybrid Approach It is possible to create tools which consist not only of static analysis but also perform measurements on the program or segments of it on the target platform. These methods embody a category denominated as hybrid approach [Bet10]. The CFG information is extracted from the source or object code. Having the program logical structure available one can run the code segments in order to obtain execution upper bounds for each segment in the real platform. Before each segment is run a worst-case scenario can be constructed depending on architectural considerations. This can be for instance the flushing of all caches or running a specific piece of code which polutes the cache forcing subsequent writes to memory for every cache miss observed during the segment run. The segment execution times are then merged in order to obtain a safe upper-bound on the worst case execution time of the task. This tries to overcome the limitations from the previous approaches by joining the best of both worlds. Since static analysis is employed upper-bound on the pre-emption delay penalties can be extracted from the formal analysis of the object code. 2.2 Pre-emption Delay Estimation As mentioned before, the WCET analysis inherently considers each task in isolation similar to what occurs in non-pre-emptive scheduling. As it turns out generally the system has a pre-emptive scheduler which in turn requires the effect of pre-emptions to be incorporated into the execution time of the tasks. The pre-emption delay is present whenever some subsystem used in the task execution exhibits some inherent state. A set of states are assumed in the WCET computation. Whenever a pre-emption occurs, the pre-empting task may alter the state of several of the subsystems present in the execution environment. Whenever the pre-empted task resumes execution, if the subsystems it is using are in a different state in comparison to the time instant at which it was pre-empted, it will eventually suffer from pre-emption delay in future execution points. It is inherently assumed that the state changes for these subsystems have a non-negligible time penalty. 18
2.2. PRE-EMPTION DELAY ESTIMATION The subsystem considered most often in literature is the cache. This is due to the large size of these apparatus and the time penalty for a cache miss which is around two orders of magnitude greater than the latency of a cache hit in modern architectures [McK04,EEKS06, BDM09,RGBW07]. Cache Related Pre-emption Delay (CRPD) estimation has been a subject of wide study. Several methods have been proposed that provide an off-line estimation based on static analysis, for this inter-task interference value. Lee et al. presented one of the earliest works on CRPD estimation for the instruction caches [LHS+98] where the notion of the set of memory blocks that might have been used in the past and may be used in the future, termed Useful Cache Blocks (UCB), was first introduced. A UCB, for a given program point, is one which might have been used in any program path leading to this program point, which was not evicted, and that might be used in any future program point accessible from the current location. The computation of UCB sets is carried out in an abstract interpretation framework. Lee et al. defines genbto be the set of memory accesses operated at basic block bmapped into their corresponding cache line [LHS+98]. For example consider a cache with X=4 cache sets, if in BBbmemory addresses m1,m2and m4, which map to cache set 1,2 and 4, are referenced then genb={m1,m2,⊥,m4}. Where ⊥signifies that there are no memory references in BBbmapping to cache block 3. The following operator will aid us on the algorithm explanation task: xydef = y[i],if y[i]6=⊥ x[i],if y[i] =⊥ (2.1) Both xand yare an ACS. An ACS is a representation of all the memory blocks which may be in each cache set at a given time. In definition of the operator 2.1, the values x[i] and y[i]represents the contents of the ith cache set in ACS xand yrespectively. There are two ACS computed per basic block, both obtained by a fixed point algorithm. The first, Reaching Memory Blocks (RMB), is computed by an algorithm starting from the first node of the CFG [LHS+98]. The RMB set computed in Algorithm 1, for each BBb presents the information of all the memory blocks which might have been loaded into the cache on any CFG path leading to BBbwhich have not been evicted since. 19
2.3. PRE-EMPTION DELAY INTEGRATION WITH SCHEDULABILITY ASSESSMENT Where the ∆sta i,j(t)parameter denotes the pre-emption delay caused by jobs from task τjin a given time window of length tdefined as: ∆sta i,j(t)def =TMISS × n ∑ l=1 (t) l max(M) .(2.18) The function maxh() returns the hth biggest value in the set. The function n(t)states the maximum number of jobs from tasks in the set {j,··· ,i−1} which can be released in an interval of length t, i.e.: n(t)def = i−1 ∑ l=jt Tl.(2.19) The variable M is defined as: Mdef =]i k=j+1]lt Tkm m=1ˆ δj,k(2.20) Where ˆ δj,kis a set containing exactly lRk Tlmelements which are the highest CRPD values associated to consecutive pre-emptions by jobs from τjon a single τkjob. Hence ˆ δj,kis defined by Staschulat as: ˆ δj,k def =(δ1 j,k,··· ,δlRk Tlm j,k)(2.21) where δ1 j,k=max1 p∈CFG{UCBp k∩ECBj},δ2 j,k=max2 p∈CFG{UCBp k∩ECBj}and generically δh j,k=maxh p∈CFG{UCBp k∩ECBj}. The complex formulation presented by Stachulat enables the consideration of variable pre-emption costs through the execution of each job, though no ordering of occurrences is considered. All of the CRPD aware schedulability tests presented thus far are for the fixed task priority scheduling policy. Another work exists integrating CRPD into the schedulability analysis of EDF. This consist of demand-bound function based procedure proposed by Ju et al. [JCR07]. Ju, as Mitra did, considers the pairwise pre-emption delay CRPDj,iwhich encodes the maximum CRPD penalty a job from task τjmay induce in a job from τi. Let us define the demand bound function of a given task (dbf) [Bar05]: db f (τi,t)def =t−Di Ti×Ci(2.22) 26
2.4. LIMITED PRE-EMPTIVE SCHEDULING Ju extends this definition by considering the Ciof the task and the maximum preemption delay it is subject to as an upper-bound for its workload, which yields: db f Ju(τi,t)def =t−Di Ti×(Ci+∑ j∈Hi ni,jCRPDj,i).(2.23) In Ju’s formulation His the set of tasks of smaller relative deadline than τi, which are the only tasks which can in fact pre-empt jobs from τiand ni,j=lDi−Dj Tjmupper-bounds the maximum number of times jobs from τjmay pre-empt a single job from τi. EDF successfully schedules the task-set if the following condition is verified: ∀t∈L,∑ τi∈T db f Ju(τi,t)⩽t(2.24) Note that this schedulability test is sufficient but no longer necessary when CRPD is considered in the task-system due to the overestimation involved in the pre-emption delay estimation. 2.4 Limited Pre-emptive Scheduling Non-pre-emptive scheduling has its benefits. Besides completely removing the problem of pre-emption delay, it schedules some task-sets that would not otherwise be schedulable under fully pre-emptive fixed priority (FP) [WS99] and enables considerable memory savings by allowing for the existence of a single stack of size equal to the maximum stack requirement by any task that compose the task-set. Nevertheless non-pre-emptive scheduling is not always a feasible solution to resort to. Fully pre-emptive scheduling has its own drawbacks since there exists an inherent difficulty in assessing the worst-case number of pre-emptions in these policies. This may lead to overly pessimistic analysis. A different type of scheduler which does not lie in either extremes (fully pre-emptive or non-pre-emptive) allows for the encompassing of the benefits observed in both extremes. This can be achieved by thoughtfully restricting the pre-emptions, either by scheduler aid or by using specific pre-emption points in the code. The framework offers a viable ground over which to address the problem of pre-emption delay estimation. Scheduling the workload with such sort of policies enables more information to be present at the design time with respect to where the pre-emptions will occur in a given system execution. The sole purpose of a scheduling algorithm is to determine which tasks execute on the target processor at each point in time. A scheduling algorithm can be, non-ambiguously, described through a function A.Atakes as an input the set of active tasks and knowledge 27
2.4. LIMITED PRE-EMPTIVE SCHEDULING of future task releases when available. The output of Ais a partially ordered set of tasks. The mhighest priority tasks are then executed upon the available processors. The scheduling algorithms are generally classified according to the Abehaviour with respect to the priority ordering. 1. fixed task priority each job is assigned the same fixed priority 2. fixed job priority each job is assigned a fixed priority which is not necessarily the same as previously or subsequently released jobs (from the same task) 3. dynamic job priority the priority of the job varies during its frame (between its absolute release time and absolute deadline) It is easy to observe that algorithms of type 1are a subset of type 2which in turn are a subset of type 3. The algorithms of the subsets are associated to lower run-time complexity when compared to the ones on the complement set which yields the super-set. Generally these algorithms tend to dispatch onto the execution platform the highest priority workload which is available to be executed at any instant in time. Any scheduler for which a task pre-empts another running in the system immediately before a given time instant twhen the pre-empting task had a priority increase that surpasses the pre-empted task can be termed as a fully pre-emptive scheduler. In informal terms, limited pre-emptive schedulers can be seen as the product of slight modifications to the so called fully pre-emptive schedulers such that the pre-emptions do not generally occur synchronously with the release or increase in the priority level of some workload but in a more controlled manner after, for instance, a known time interval elapses. At run-time some pre-emptions which would generally occur in the fully pre-emptive schedule are now said to be deferred in the limited pre-emptive model. The more common limited pre-emptive scheduling algorithms existing in literature, although being generally referred to as extensions to type 1and 2schedulers, can in fact be considered to be type 3algorithms. The pre-emption deferral can in fact be seen as a temporary priority increase from the part of the executing task. Another analogy, which is more commonly referred to is that whenever a pre-emption is being deferred, the task which remains executing is in fact executing – for a limited time interval – in a non-pre-emptive manner. The mechanism of pre-emption deferral has a number of advantages as has been pointed out in several works [YBB10,YBB09,BBM+10]. These scheduling policies present a trade-off between the extremes of fixed priority non-pre-emptive and fully pre-emptive scheduling. Gang Yao et al. provide a comparison of all the available methods described so far in literature [YBB10]. Aside for enabling heightened sense of where pre-emptions occur, the limited preemptive model also allows for schedulability increases. An example is provided in task-set 28
2.4. LIMITED PRE-EMPTIVE SCHEDULING C T τ12 10 τ29 12 Table 2.1: Limited Pre-emptive Motivating Task-set shown in table 2.1 where the task fails to be schedulable under fully pre-emptive fixed task priority but it is in fact schedulable by non-pre-emptive scheduling. For this task-set, the fully pre-emptive schedule is displayed in Figure 2.2 to the right. One possible limited preemptive schedule which ensures schedulability of the task-set is displayed in the same figure to the left. It is apparent that task τ2misses a deadline at t=12 since it still has one unit of pending workload at this deadline. In the exemplified limited pre-emptive schedule all tasks meet their deadlines until t=24 and hence it is concluded that the task-set is schedulable with this policy since at exactly t=24 there is virtually no pending workload left to process in the system. τ1 τ2 τ1 τ2 0 2 20 t0 2 10 12 t1210 24 Figure 2.2: Limited Pre-emptive Schedule vs Fully Pre-emptive Schedule (task-set in Table 2.1) The limited pre-emptive scheduling algorithms can be categorized into two broad groups depending on the nature and properties of the non-pre-emptive regions. This two groups are denominated as: •Fixed non-pre-emptive; •Floating non-pre-emptive. 2.4.1 Floating Non-pre-emptive Regions In the regular floating non-pre-emptive region scheduling, each task τihas a maximum deferral time defined which will be denoted by the parameter Qi. When a task τiis executing and τiis not the highest priority task in the ready queue, then it is said that a pre-emption deferral chain is occurring. A pre-emption deferral chain, as is shown in Figure 2.3 starts with a higher priority release, and lasts at most Qitime units. At the end of a pre-emption deferral chain a pre-emption invariably happens. In Figure 2.3 task τiis executing when 29
2.4. LIMITED PRE-EMPTIVE SCHEDULING a job from τjis released, at some time in between a job from τkis released. The deferral chain ends exactly Qitime units after the first higher priority release. τk τi τj Qi t Figure 2.3: Floating Non-pre-emptive Region Scheduling Example All the scheduling policies presented so far were created with the intention of enabling the floating non-pre-emptive regions usage. Effectively by extending the schedulability of fixed task priority the overall admissible blocking tolerance of higher priority tasks will increase in accordance. A practical consequence is that the allowed non-pre-emptive regions will increase in size in comparison to the limits considered by the schedulability test which does not contemplate the schedulability increase (i.e. the fully pre-emptive condition). Having bigger values for the non-pre-emptive regions is obviously advisable since this will inevitably allow for a reduction on the number of pre-emptions, and will enable less pessimism in the pre-emption delay computation [MNPP12a]. In the simple ready queue locking, and in the ready queue locking with pre-emption threshold maximum blocking times admissible for all the tasks are computed. This information alone enables the usage of the floating non-pre-emptive regions scheduling. 2.4.2 Fixed Non-pre-emptive Regions The mechanism of restricting pre-emptions was first proposed by Burns et al. [Bur95] where only fixed non-pre-emptive regions are considered (fixed pre-emption points). The fixed non-pre-emptive region model differs from the previously mention (floating) in that the pre-emption points are restricted to occurring at very well defined points in the task code. In this work it is referred that dividing the tasks into a set of consecutive non-pre- emptive jobs would be a interesting way of increasing the schedulability of the task-sets. This initial work suffered from the shortcoming of only considering the first frame of a task in a synchronous release situation to account for the critical situation. Keskin et al. discuss the theory of fixed non-pre-emptive region schedulability [KBL10]. The author deemed the available test [Bur95] optimistic, arguing that under no assumptions 30
2.4. LIMITED PRE-EMPTIVE SCHEDULING the worst-case response time for a job of task τimay no longer arise in the first critical region in a synchronous release situation but that it may show up in a job kof task τiin the level-iactive period generated at a synchronous release situation. Until this point, the answer to what the maximum length of the non-pre-emptive regions would be had not been found yet. A basic ingredient for this is identifying the amount of slack in the higher priority schedule. Slack computation was the subject of some attention in the past [DTB93,LRT92]. These works mainly deal with the detection of slack in the schedule that enables the execution of aperiodic tasks with low priorities to execute uninterrupted. This benefits the latency of those applications considerably. The drawback of these methods is that they either rely on off-line analysis and the periodic behaviour of hard deadline tasks [LRT92] or on the on-line computation of the slack using methods with variable execution (recursive method) time and high complexity [DTB93]. The previously mentioned works do not address the issue of pre-emption reduction nor consider slack stealing on a purely hard real-time system. A similar point of view is proposed by Dobrin et al. [DFP01]. In this work an off-line analysis parses the schedule identifying pre-emptions. It then tries to remove these by changing tasks priorities and the offsets without jeopardizing the schedulability. This method is solely applicable to periodic task-sets though. Slack computation in a schedule is the base theory for computing the maximum allowed blocking times for a given set of tasks. The maximum admissible blocking time depends on the task-set and the priority relation between the tasks and the scheduling policy. The first maximum admissible blocking time computations were proposed by Baruah [Bar05] for EDF scheduling policy, and later by Yao et al. [YBB09] for fixed task priority scheduling mechanism. In the initial work Baruah defined a maximum length for the non-pre-emptive chunks of each task. At the deadline of the first job of each task τj, in a synchronous release with all other higher priority tasks, the slack (βj) is computed: βj def =Dj−∑ h∈{1,···,j−1} db f (Dj,τ,h).(2.25) The value βjdenotes the maximum amount of blocking time the task would endure without missing a deadline. The maximum length of the non-pre-emptive regions of each task τiis referred to as Qiwhich is defined as: Qi def =min j∈{1,···,i−1}βj(2.26) This ensures that task τinever induces a bigger blocking time to higher priority jobs from task τjwhere j∈ {1,··· ,i−1}such that they would miss a deadline. Note that in this situation tasks are ordered by increasing relative deadlines ∀i∈ {1,···n−1}Di⩽Di+1. The priority of the workload is a function of each jobs absolute deadline (EDF [LL73]). 31
2.4. LIMITED PRE-EMPTIVE SCHEDULING This result was then further extended by Baruah and Bertogna in order to consider a variable length for the non-pre-emptive regions of each task [BB10]. In this work a monotonically decreasing function is considered Q(t). Q(t)def =min t0∈[0,t]t0−∑ i∈{1,···,n} db f (t0,τi)(2.27) Assume that at time t2, a job from task τiwhich was released at time t1<t2, is executing on the processor. Further assume that at time t2−εthe job from τiis the highest priority active job in the system and that at time instant t2task τjreleases a job. At this event the job from task τiwill start executing non-pre-emptively for Q(t1+Di−t2). It is easily shown that Qi⩽Q(t1+Di−t2), hence this extension enables bigger non-pre-emptive regions for each task at the cost of added run-time overhead. The authors propose the usage of a table to implement this mechanism and observe that the number of table elements is generally quite small. A fixed priority scheduling method has been devised by Yao et al. [YBB09]. Yao defines an upper bound on the maximum admissible blocking time each task may suffer as: βi def =max t∈[0,Di]t−∑ j∈{1,···,i} rb f (t,τj),(2.28) Where rb f (t,τi)def =t Tj×Cj.(2.29) The maximum length of the non-pre-emptive regions is then defined as: Qi def =min j∈{1,···,i−1}βj(2.30) The computed value is the maximum allowed for systems scheduled with floating nonpre-emptive regions but it is not optimal when fixed non-pre-emptive regions are considered. Still this only allows the scheduling of tasks that were schedulable under the fully preemptive model. The author proves that if the task-set is schedulable under fully pre-emptive fixed priority, the job of task τiwith worst-case response time will still be the first job in the synchronous release situation. Later the work was extended with fixed non-pre-emptive regions in mind [YBB11a]. Since the last part of τiexecutes non-pre-emptively for a maximum duration of Qitime units. The maximum admissible blocking time per task is then rewritten as: βi def =min k∈{0,···,K}(max t∈[k×Ti,k×Ti+Di−Qi](t−∑ j∈{1,···,i−} rb f (t,τj)+Ci−Qi)),(2.31) 32
2.4. LIMITED PRE-EMPTIVE SCHEDULING where kupper-bounds the maximum number of jobs τihas in a level-i busy period blocked by the maximum admissible time. Let us assume Li(B)to be the maximum length of the level-i busy period blocked for B time units, Li(B)def =min{t|t−(B+rbf(Γi,t)) = 0}.(2.32) Then Kmay be written as: Kdef =Li(Qi) Ti,(2.33) since the level −ibusy period can never be blocked by more than Qitime units. In the initial work [YBB09] the regular fully pre-emptive schedulability test was employed. In this case the synchronous release of all higher priority tasks constitutes the worst possible case from the point of view of higher priority workload interference. As the work was extended to take into advantage the schedulability gains possible with the fixed nonpre-emptive region model, a new schedulability test was devised [YBB11a]. In this new test not only the first frame of each task in a synchronous release situation had to be checked for deadline misses. Instead all the frames in the busy period commencing with a synchronous release need to be checked to ensure all deadlines are met. This is tied to the fact that, with this analysis, task-sets which were not schedulable under fully pre-emptive fixed task priority might be so. Hence, due to the larger non-pre-emptive regions, some workload might be postponed to execute in a future time interval when compared to the interval observed with fully pre-emptive fixed task priority scheduling. The pre-emption delay estimation problem using fixed non-pre-emptive region scheduling was presented by Bertogna et al. [BBM+10]. In order to reduce CRPD, the usage of fixed non-pre-emptive areas of code is proposed. There exists an extensive set of possible pre-emption points. For each pair of points a pre-emption delay value is defined. Bertogna et al. propose in their model a mechanism to choose a set of points as actual pre-emption points such that, the worst case execution time distance between each chosen pair of points, considering pre-emption delay is never greater than Qitime units, otherwise higher priority task’s temporal requirements might not be met. This work may be used both with fixed task priority as well as with EDF, the Qiparameter considered for each scheduling policy is the one defined in [YBB11a] and [Bar05] respectively. An extension of this work was presented by Bertogna et al. in [BXM+11], where the optimal set points is selected with the aim of minimizing the pre-emption delay the task may suffer overall. This has the limitation of requiring manipulation of the code of tasks and thus is not very amenable to system developers. Also, it is not straightforward to take into account tasks with complex control-flow graphs [BXM+11]. Additionally it can not be easily applied in situations where the task-sets are subject to run-time changes, as the maximum distance between pre-emption points is defined by the higher priority workload. 33
2.5. TEMPORAL ISOLATION ENFORCEMENT A different mechanism to reduce pre-emptions was proposed by Express Logic [Lam] termed pre-emption threshold. In this work a task may only pre-empt another if its priority is bigger than that task’s pre-emption threshold. Wang and Saksena provided an optimal priority assignment for pre-emption-threshold scheduling policy [WS99]. The pre-emption thresholds are computed by aid of a search algorithm that will test several possibilities until it either reaches a solution that ensures schedulability for the given task-set or fails. The pre-emption-threshold values are the sufficient for ensuring schedulability. Later the work was extended [SW00] by the same authors to assign the pre-emption threshold to the highest possible priority value which maintains schedulability. 2.5 Temporal Isolation Enforcement Before a safety-critical system can be deployed and marketed, a certification authority must validate that all the safety-related norms are met. All the components comprising that system (the software, the hardware, and the interfaces) are scrutinized to ensure conformance to safety standards. Timing guarantees must be derived at design time and consequently enforced during run-time for the system to be certified. These timing guarantees are obtained through timing and schedulability analysis techniques, which are typically more accurate and simpler when spatial and temporal isolation between tasks is provided. This is because timing analysis techniques must thoroughly examine every shared resource and identify a worst-case interference scenario in which the analysed task incurs the maximum delay before accessing the shared resource[s]. Without a proper isolation between the tasks: First, the number of interference scenarios to be explored may be out of proportion, hence compelling the analysis techniques to introduce an undesired pessimism into the computation by over-approximating these scenarios. Secondly, having a high number of possible interference scenarios naturally increases the probability of encountering a “pathological” case, where the delay incurred by the analysed task in that particular scenario is far higher than in the average case. Since the analysis tools must capture the worst-case scenario, this pathological case will be retained and used in higher-level analyses (like schedulability analyses) which are built upon the results of timing analyses (thus propagating the pessimism all the way up to system-level analyses). A first step in the certification process is to categorize each component (software and hardware) by its level of criticality and assign a unitary safety integrity level1(SIL) to all components. When integrated in the same platform the components of different SILs share low-level hardware resources such as cores, cache subsystems, communication buses, main 1A Safety Integrity Level (SIL) is defined as a relative level of risk-reduction provided by a safety function, or to specify a target level of risk reduction. In simple terms, a SIL is a measurement of performance required for a safety instrumented function. 34
2.5. TEMPORAL ISOLATION ENFORCEMENT memory, etc. To provide the required degree of “sufficient independence” between components of different SILs, Industry and Academy have been seeking solutions for many years to (1) render the components of a specific SIL as independent and isolated as possible from the components with different SILs and (2) upper-bound the residual impact that components of different SILs may have on each other after the segregation step, with the primary objective of certifying each subset of components at its own SIL. Generally the sufficient separation is achieved in regular system model by resorting to specific reserves which strictly dictate the rate of access to a given platform by the workload. Reservation-based systems are quite a mature topic in real-time literature. Sporadic servers [AB04,SSL89] are proposed in real-time literature to ensure temporal isolation in fixed task priority systems. Each server reserves a budget for the task execution. A task can only execute if the server budget is not depleted. This ensures that the interference generated by a task in the schedule cannot exceed what is dictated by its server parameters and servers are the scheduled entities. Solutions for temporal isolation in Earliest Deadline First (EDF) also exist employing the sporadic server concept, namely constant bandwidth server (CBS) [AB04] and Rate Based Earliest Deadline First (RBED) [LKPB06]. Each server has an absolute deadline associated to it which acts as the server priority. On top of the temporal isolation properties these frameworks also employ budget passing mechanisms which enhance the average-case response time of tasks in the system without jeopardizing the temporal guarantees [NP08, LB05]. The previously employed execution models assume that the interference between workload occurs solely on the CPU. As it turns out, if other architectural subsystems are shared in the execution platform which present some state with non-negligible state transition times (e.g. caches), interference between task will be created (commonly referred to as pre-emption delay). The maximum pre-emption delay any task may endure may still be integrated into the task’s budget2, this solution is shown in this thesis to be subject to heavy pessimism.When minimum inter-arrival times of tasks cannot be relied upon (i.e. tasks release jobs at a faster rate than computed at design time), the previously mentioned frameworks fail to ensure temporal isolation between concurrent tasks in the system. In order to ensure temporal isolation cache partitioning may be employed [BCSM08]. This technique has the disadvantage of decreasing the usable cache area available to each task, and as a consequence impacting its performance. Other architectural subsystems exist (e.g. TLB, dynamic branch predictors, etc.) which cannot be partitioned in order to remove the interference source between tasks. Recently an approach has been proposed where, when a task starts to execute it stores onto the main memory all the contents of the 2we assign one server per task, the task and server term is used interchangeably in this document 35
3.1. ON-LINE FTP FLOATING NON-PRE-EMPTIVE REGION EXTENSION synchronous arrival of higher priority workload situation. Note that Theorem 1 only refers to the amount of time a job of task τimay be deferred so that it does not miss its deadline. The same reasoning has to be applied to all jobs currently deferring the pre-emption so that no deadline is missed in the system. At every instant in time, while there are jobs deferring their pre-emptions βi(δi(t),ϕ ϕ ϕi(t)),∀i∈Sis computed, where S=lep(j)∩hp(p) In this case τjdenotes the highest priority task blocked at time t,τpthe task currently running and lep(j)is the set of task of lower or equal priority in relation to task τj. At the time instant when there exists an isuch that βi(δi(t),ϕ ϕ ϕi(t)) = 0, a pre-emption occurs and all previously deferring jobs cease to defer, at which point the blocked job with highest priority is scheduled to execute. Normal fixed priority scheduling is carried out until there is a release of a task of higher priority than the currently running task. Implementing a scheduling policy following this exact methodology is clearly unrealistic since it implies a high complexity algorithm to operate at every instant in time. Some approximations may be used though. The simplifications rely on the observations described in the following text. 3.1.2 Practical Usage of Equation (3.3) A straightforward way to exploit the knowledge provided by Equation (3.3), is to trigger a non-pre-emptive execution region for the job of task τlcurrently running, whenever a release from a higher priority job occurs. In the next step the situations where no higher priority job releases are present in the system is considered, so all the elements in vector ϕi ϕi ϕi(t)will be equal to the amount of time elapsed since rl i(t). Equation (3.3) may then be rewritten as, βi(δi(t),ϕ ϕ ϕi(t)) = βi(δi(t)),(3.4) since ∀j∈hp(i),ϕi j(t) = δi(t). The non-pre-emptive region should have a duration equal to mini∈hp(l)(βi(0)). This approach is the one presented by Yao et al. [YBB09]. A simple low complexity build up on the previous approach would be to still consider βi(0)as the time a job from task τimay defer its pre-emption, and create a set of rules that enable the scheduler to perform better or equally well whenever the schedule is not in the worst-case scenario (synchronous release of higher priority tasks). Property 1. Whenever a job of task τiis released, if it has higher priority than the running task and no other job is already deferring its pre-emption, the scheduler may safely delay its pre-emption by βi(0)). The Property is a direct consequence of the definition of the βi(δi(t)) function (Equation (3.4)). By definition if at δi(t) = 0 there exists no pending higher priority workload, then the level-ischedule can be blocked for βi(0)time units. So task τ3may be safely delayed for that amount and always complete before the deadline as stated in Theorem 1. 42
3.1. ON-LINE FTP FLOATING NON-PRE-EMPTIVE REGION EXTENSION Property 2. If one or more tasks are already deferring their pre-emption and no job has higher priority than the job from τi, the timer is set to timer =min(timer,βi(0)). The variable “timer” denotes time instant (t’) when the highest priority blocked task is poised to pre-empt the currently running task. This variable can be defined for every time instant tas timer =t0−t. Henceforth the term “timer” is used to denote both this quantity as well as the architectural device responsible for automatically updating it at the rate of time progression. The previously deferring jobs (if any exist) already set the timer in order not to miss a deadline. In case the highest priority task at time tis executing upon the platform then timer =∞. If the lower priority tasks are to complete execution before deadline the minimum amount of time that all jobs may be deferred for has to be taken into consideration in this situation. Property 3. If in the previous situation there is at least one higher priority job already deferring its pre-emption, the timer is set to min(timer,max(βi(0)−(rl i(t)−t0),0), where t0 is the instant in time when the first job, from the set of jobs currently blocked, was released. This is due to the fact that βi(0)represents the amount of time a job may be deferred if no other higher priority job is deferring at that instant in time. If at time rl i(t)there is higher priority workload deferring pre-emption it was released mandatorily after t0(i. e. t0<rl i(t)). This implies that at time instant t0no job with higher priority than the current job of task τiwas deferring its pre-emption. If the current job of task τihad been released at time t0it could defer its pre-emption until t0+βi(0)without missing its deadline, as a consequence if the job arrives at a time instant after t0it can still defer its pre-emption until the same point in time (t0+βi(0)). 3.1.3 Sufficient Schedulability Condition for Proposed Framework The presented framework (properties 1to 3) cannot schedule all task-sets which would be schedulable with the fully pre-emptive or regular limited pre-emptive schedulers. When trying to leverage these three properties caution must be exercised in order to make sure that the following overload situation does not occur. For some task-sets, some arrival patterns may lead to a task being released in a situation where the admissible pre-emption deferral would in fact be negative. In this situation a deadline may be missed. During the schedulability test a synchronous release situation is considered. This was proven to be the situation leading to the worst-case response time of a task in fixed priority scheduling [BLV07a]. In restricted pre-emption fixed priority scheduling policy the synchronous release of higher priority tasks situation may not lead to the largest response time of a task [BLV07a]. 43
3.1. ON-LINE FTP FLOATING NON-PRE-EMPTIVE REGION EXTENSION Lemma 1. Not more than one additional job from every higher priority task may appear (in comparison to the synchronous release case) in the time interval bounded by a release and a deadline of a task. Proof. In the synchronous release situation jDi Tjk+1×Cjunits of higher priority workload per higher priority task may be considered. If some lower priority task defers the start of execution of a higher priority task then no more than lTi+Di Tjm×Cjunits of workload need to be considered. If a middle priority task τihad a release more than Tjtime units after the release of a job from task τjthen, considering the constrained deadline task model, the workload of task τjwould have been concluded at the time of release of task τi, hence not interfering in its response time. As a consequence of Lemma 1a sufficient schedulability test ensuring that no such situations can occur is presented in Equation (3.5). Theorem 2. A task-set is schedulable when using the presented framework (properties 1to 3) if, for all tasks, the following inequality is respected: Di⩾Ci+∑ j∈hp(i)Di Tj×Cj+∑ j∈hp(i)min(Cj,Di−Di Tj×Tj(3.5) Proof. From Lemma 1a bound on the maximum number of jobs a higher priority task can release in a given time window is provided. By summing over all higher priority tasks considering the over-provisioning stated in Lemma 1an upper-bound on the interference any task τisuffers in the interval [0,Di]is obtained. Note that the lower priority blocking is inherently considered by the Lemma 1since the additional higher priority job considered in the [0,Di]is a direct consequence of the blocking. Hence the sufficient schedulability test is proven safe. The condition stated in inequality (3.5) reflects the fact that at most one additional job of every higher priority task may be present in the time interval bounded by a release and deadline of a middle priority job. Equation (3.5) takes into account the workload of every higher priority task that executes entirely until completion in a time interval of length Diand then sums two additional workloads or the length of the interval Di−jDi Tjk×Tj, whichever is smaller, as additional higher priority workload. For task-sets that miss the sufficient schedulability test a safety mechanism needs to be added to the protocol, which prevents deadlines from being missed. At run-time the sum of the worst-case execution times of all tasks with higher priority than the running task is computed. If at a release this value becomes greater than minj∈hp(i)(βj)then the timer is set to t−t0+minj∈hp(i)(βj). The previously described set of rules takes into account the existence of job release phasing in relation to the worst-case (synchronous release of higher priority) during the normal run 44
3.1. ON-LINE FTP FLOATING NON-PRE-EMPTIVE REGION EXTENSION of the schedule and enables better decisions when sporadic behaviour is present (commonly denominated as minimum inter-arrival time). The set of rules may be enhanced by considering that if no higher priority workload is available then the job may be even further delayed. This fact motivates the following theorem. Theorem 3. A job of task τimay defer its pre-emption for Di−WCRTitime units while no job with priority higher than τiis released in the time interval [rl i(t),rl i(t) +∆i]. Proof. The amount of pre-emption deferral time is referred to by ∆idefined as ∆i def =Di− WCRTi. The quantity WCRTiis defined in the usual way, WCRTi=Rk, where kis the smallest value that satisfies Rk=Rk−1. The Rkvalue is iteratively computed by the following equation [Bur95], Rk=Ci+∑ j∈hp(i)Rk−1 Tj×Cj(3.6) and choosing R0=Ci+∑j∈hp(i)Cjas the initial value in the iteration for R. If no higher priority job is released in the interval [rl i(t),rl i(t)+∆i], the job from task τimeets its deadline if it pre-empts at t=rl i(t) + ∆iirrespective of the pre-emption deferral admissible for all the higher priority workload that may be released after or at instant rl i(t) + ∆i, due to the definition of WCRTi. Using the previous theorem in the protocol generates a situation requiring special consideration: Assume one task is deferring, having set the timer on arrival to its corresponding ∆according to the previous theorem. A higher priority task arriving may not use the past value in the timer, but needs now to take into account the B(0)of the highest priority job already deferring. An example of a problematic situation is displayed in Figure 3.3. If some middle priority job of task τiis released at time rl i(t) = 0, followed by a release of a lower priority job from task τl,ϕi l(rl l(t)) time units after, the situation depicted in Figure 3.3 may arise. The hollow arrows in the picture represent timer values that tasks contended with in the timer setting procedure and set the timer (i.e. were the minimum value at the contending time). According to previous rules the job from task τlsets the timer since its admissible preemption deferral is smaller than the value τiloaded into the timer, max(Bl(0)−rl l(t)),0)< ∆i−rl l(t). At time instant rl j(t), when a job from task τjwas released (where jis of higher priority than i)τihas again to check if its admissible deferral time is the minimum among all deferring jobs. When it was released it tried to set the timer until ∆i, since higher priority workload is available and no knowledge about Equation (3.3) exists at this stage apart from βi(0), the scheduler has to check if this would yield the minimum value for the timer if it was used at time rl i(t). When this scenario occurs the following relation is true max(Bl(0)−rl j(t),0)>max(βi(0)−rl j(t),0). The timer has to be loaded at this time with 45
3.1. ON-LINE FTP FLOATING NON-PRE-EMPTIVE REGION EXTENSION τi τl τj τr rl i(t)rl l(t)rl j(t)tBi(0) ∆i Bl(0) −ϕi l(t) Figure 3.3: Scenario Motivated by Theorem 2 max(min(Bl(0)−ϕi j,βi(0)−ϕi j,∆j),0). The information on the highest priority job deferring its pre-emption has to be stored then, along with the time instant of its release in order for the mechanism to work, since when some other higher priority workload is released its admissible deferral has to mandatorily be re-evaluated. 3.1.4 Admissible Deferral Approximation It is clear that a trade-off between memory usage and efficiency may be exploited in order to better use the knowledge presented by Equation (3.3). Using only its initial point is too restrictive. Two efficient approaches for having a lower bound on βi(a)(Equation (3.4)) are presented, which may be used at run-time to achieve longer pre-emption deferrals. The following two strategies are employed at the time instant tif task τiwas the highest priority task blocked at time t−εand at this time instant (t) an even higher priority task is released. Bi(δt i) 0Di in A 1 A 1 A 2 t Threshold Maximizing the Area Points Maximizing Area for A 2 Figure 3.4: Outline of the Devised Approximations for Equation 3.3 46
3.1. ON-LINE FTP FLOATING NON-PRE-EMPTIVE REGION EXTENSION A 1 One may consider the usage of another point of βi(a)function to improve deferral decisions. Based on the notion that βi(a)is monotonically decreasing, and that dβi(a) dt = 0 or dβi(a) dt =−1 the following method may be devised. The value set on the timer is βi(threshold), i.e. any job of task τimay have its pre-emption deferred for βi(threshold)if no threshold time units have elapsed since its release when a higher priority release occurs. After threshold time units have elapsed since the release, the value is set to the timer is βi(threshold)−(threshold −timer). This approximation is made possible by the specificities of Equation (3.3) previously referred. A 2 a linear equation which is a lower bound of βi(a)in the interval [0,∆i]may be created. This linear function is always smaller or equal to βi(a)and tangent to the convex hull defined by βi(a). At the time of release of a higher priority task relative to the previously highest deferring task the deferral is computed by y2−y1 x2−x1×a+ (y1−y2−y1 x2−x1×x1). Both quantities y2−y1 x2−x1and y1−y2−y1 x2−x1×x1are computed off-line. Both methods define a lower bound on βi(a)function which takes up little memory space and may be exploited quite efficiently. Without any prior knowledge on the arrival pattern of higher priority workload and possible phasings a rule of thumb stating that both areas should be maximized to achieve better performance. For the first approach (A 1), the point that maximizes area =a×βi(a) + a2 2is the one chosen. The second one (A 2) chooses the two adjacent points defined by (x1,y1)and (x2,y2)of the convex hull defined by function βi(a)that maximize area =y2 1 m+2×y1×x1−m×x2 1, where m=y2−y1 x2−x1. Both approximation are used in a scenario where the previous highest priority job deferring its pre-emption faces a release from a higher priority job. 3.1.5 Implementation Overhead All of the methods presented so far have small time complexity, having at most three comparisons when setting the timer. At every release a maximum of four values have to be compared in order to chose the minimum. The last approximations rely on a limited number of computations, as was shown in A 1 and A 2 description. These computations are cheap in comparison to the overall savings that they provide. 3.1.6 Tighter Bound on the Number of Pre-emptions The maximum number of pre-emptions per task may be upper bounded both in the state of the art [YBB09] as well as in our methods by jCi Qik, where Qi=minj∈hp(i)(βj(0)). This bound is implicitly stated in the work of Yao et al. [YBB09]. For our method it suffices to state that whenever a job from task τiexecutes on the processor it will do so for at least Qitime units uninterrupted by a higher priority workload. Observe that in all the presented 47
3.1. ON-LINE FTP FLOATING NON-PRE-EMPTIVE REGION EXTENSION protocols, whenever a single higher priority task τjrelease occurs, the lower priority task τiwill execute non-pre-emptively for at least βj(0). If subsequent higher priority releases occur, for which the corresponding tasks have smaller Bk(0)(i.e Bk(0)<βj(0)) in the worst case scenario then Bk(0)time units would be counted sincet0(the start of the deferral chain). If Bk(0) = minj∈hp(i)(βj(0)) , then Qi=Bk(0). Hence the same bound applies. Suppose the following taskset presented in table 3.1 CiDiTiQi τ12 2 5 ∞ τ23-ε15 7 3 τ32 15 15 ε Table 3.1: Example Task-set Denoting a Pre-emption Corner-case The value denoted by εis an arbitrarily small value. This yields the following relation, lim ε→0Ci ε=∞.(3.7) The bound provided, considering the previous bound for jobs of task τ3would be overly pessimistic in cases where Qiis small. Bear in mind that this is an extreme case to motivate the fact that, in specific situations, the number of higher priority releases in a given interval is itself a tighter bound on the number of pre-emptions for a given task. All the higher priority jobs that arrive WCRTi−Qitime units after the job of τistarted first to execute are guaranteed not to pre-empt and hence may be disregarded in the maximum number of pre-emption computation. This indicates that a suitable bound should then be min Ci Qi,max ∑ j∈hp(i)WCRTi−Qi Tj,0!!.(3.8) A less pessimistic pre-emption quantification may be obtained by posing the following trivial optimisation problem, which exploits the notion that some higher priority releases will lead to extended non-pre-emptive regions. The intent is to maximize the number of pre-emption taking as constraints: 1) the maximum number of job releases that each task τjproduces in a interval of length Di; 2) the summation of the non-pre-emptive regions considered cannot be greater than Ci, since in the worst-case after each execution resume from τia higher priority release occurs, triggering a subsequent non-pre-emptive region. 48
3.2. EVALUATION maximize i−1 ∑ j=1 aj subject to : aj⩽Di Tj,j∈ {1,··· ,i−1} i−1 ∑ j=1 aj×min k∈{1,···,j−1}{βk}⩽Ci A solution to this problem is easily derived by noting that mink∈{1,···,j−1}{βk}increases monotonically as the values of jdecrease. This motivates Algorithm 3which computes an upper-bound on the number of pre-emptions a task τiis subject to. Algorithm 3: Pre-emption Upper-bound preempt ←0 exec ←0 j←i−1 while exec ⩽Ci&j⩾1do preempt ←preempt+minjDi Tjk,Ci−exec mink∈{1,···,j−1}{βk} exec ←exec+jDi Tjk×mink∈{1,···,j−1}{βk} j←j−1 The upper-bound on the number of pre-emptions is contained on the variable pre-empt. The algorithm considers the ajcoefficients to take the greatest possible value allowed by its constraint (the maximum number of job releases by τjin an interval of length Di) in a decreasing priority order. This maximizes the objective function since the quantity mink∈{1,···,j−1}{βk}decreases monotonically as the priority decreases. 3.2 Evaluation In this section comparative results on all previously mentioned approaches are demonstrated. The approaches are denominated from first to fourth with the following meaning: •first approach – implements Properties 1 to 3 ; •second approach – implements the method described by the Theorem 3 on top of the first approach; •third approach – implement the approximation A1 of Equation (3.3) on top of the second approach; 49
3.2. EVALUATION •fourth approach – implement the approximation A2 of Equation (3.3) on top of the second approach. 3.2.1 Discussion With greater non-pre-emptive execution length, the likelihood of several higher priority jobs becoming blocked increases. These situations are actually benign and intended, since these will reduce the amount of pre-emptions generally. Take for instance an illustrative scenario where task τiis executing and a release from τjoccurs at time instant tfollowed by a release of τhat t+δand i>j>h. In this case at time tτjbecomes blocked. If τjpre-empted τi before t+δthen τjmight be pre-empted in the future by the job released by τhat t+δ. If the non-pre-emptive region of τiis in this case larger than δthen τhwill pre-empt only τi and never the job from τj. In broad terms one can state that larger non-pre-emptive region length promote priority ordered schedules from dispatch and hence reduce the number of required pre-emptions. Parallel to that mechanism, delaying further also enables higher priority workload to wait for a lower priority job to finish its execution, hence reducing the number of pre-emptions as well. Both these facts contend with a contrary effect. By further delaying some middle priority jobs, situations where hypothetical higher priority jobs arrive and cannot be deferred for the same amount of time will generate pre-emptions where none should have existed if all jobs were deferred for the same amount of time as a function of the priority of the running task (Yao et al. approach [YBB09]). Our claim is that the first two effects generally dominate over the third one. This is supported by the experimental data presented in the following subsection. The possibilities of increasing the number of pre-emptions in relation to Yao et al. only stems from the fact that higher priority workload is being moved in the schedule, which does not change any of the off-line guarantees in terms of pre-emptions for each task. 3.2.2 Simulations The three system models were evaluated using simulations. In each model all tasks are generated using the unbiased task-set generator method presented by Bini and Buttazzo (UU- niFast) [BB04a]. Tasks are randomly generated for every utilization step, their maximum execution requirements (Ci) were uniformly distributed in the interval [50,500]. In the first situation the task-set behaves in a fully periodic manner with implicit deadlines (Di=Ti). In the second situation constrained deadlines are investigated. The constrained deadline model was implemented by randomizing the period of the tasks in relation to their deadlines. For this data run the periods are constructed in the following manner Di=Ti−S, where Sis a random variable with uniform distribution in the interval [0,0.2×Ti]. In the sporadic model the consecutive release of a task is Ti+Aunits separated 50
3.2. EVALUATION from the last release of the same task. Ais taken from a uniform distribution in the interval [0,0.5×Ti]. For every utilization step, the schedule is simulated for 10000 task-sets which respect the sufficient schedulability test from Theorem 2. The observed pre-emptions are quantified and its average across all runs is computed. Utilization steps are non-uniformly distributed and the points are given by the function step(k) = 1.1−1−k·4 k·4where k∈[0,16]. This enables us to get a better concentrations of data at higher utilisations. 3.2.2.1 Implicit Deadlines Periodic Model 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 1 2 3 4 5 6 7x 104 utilisation number of preemptions fourth approach Yao et al. (a) Gains on Implicit Deadline Model - 16 tasks 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 10 12 14 16 18 20 22 utilisation percentage of preemptions saved over Yao et al. first approach second approach third approach fourth approach (b) Implicit Deadline Model - 16 tasks 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 2 3 4 5 6 7 8 utilisation percentage of preemptions saved over Yao et al. first approach second approach third approach fourth approach (c) Implicit Deadline Model - 4 tasks 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 6 7 8 9 10 11 12 13 14 15 16 utilisation percentage of preemptions saved over Yao et al. first approach second approach third approach fourth approach (d) Implicit Deadline Model - 8 tasks Figure 3.5: Implicit Deadline Task Model Experimental Results In Figure 3.5a the results in number of average pre-emptions for task-sets with 16 tasks are presented showing the state of the art algorithm and our fourth approach. Both lines display an exponential behaviour, the fourth approach has a brief offset, which implies greater pre-emption savings as is shown in the following plots. It is generally observable 51
3.4. READY-Q LOCKING CONCEPT Algorithm 4: Ready Queue Locking Management on event: release job from task τi: rqli←release+RQLi if QueueIsLocked then τl←GetTaskLockingReadyQ() append job from τito τllist of blocked tasks on event: first dispatch of job from task τi: if rqli<rlist[0]then rlist.push(rqli) on event: t == rlist[0]: assign the lock of the ready queue to the task which set rlist[0] rlist.pop() on event: terminate execution of τijob: insert all tasks blocked by τiinto the ready queue The job from τiwill then proceed to complete its workload without requiring to lock the ready queue since a lower priority task conducted that procedure on its behalf. The ready queue remains locked until the job from τlfinishes its execution. At any time instant t, if rlist is not empty, there exists a timer which will fire at time t0=rlist(0), the time instant at the top of rlist. When the timer fires, all the higher priority releases that occur after t0and before rlist(1)(if such value exists) are inserted into the ready queue once the job from the task that sets rlist(0)finishes its workload. In the timer event handler the head of rlist is popped. A task locks the ready queue between the time instant t0 (at which a timer set by it fires) and a time instant t00 when either it completes execution or the timer set by some other task fires. Any job released in the interval [t0,t00]is inserted into a separate buffer which stores a pointer to all the tasks which are currently blocked. Once task τifinishes its workload the scheduler will check whether there were tasks blocked by task τi, in case there were, these are then moved from the separate queue into the ready queue with their correct priority. In an extreme case RQLicould be set to 0. This would constitute effectively non-pre- emptive scheduling, where once jobs from τistart to execute they would not suffer any further interference. Which could jeopardize the timing properties of tasks with priority greater than τi. The value of RQLihas then to be decided upon considering the higher priority workload timing guarantees; i.e. no higher priority task can miss a deadline due to a lower priority one. These considerations are developed in the following sections. When the ready queue is locked, the tasks released in the meantime are inserted into a separate circular buffer. The task τithat currently holds the ready queue lock has a pointer for the first task to be released while it held the lock, and another pointer to the last task to 58
3.4. READY-Q LOCKING CONCEPT be released while it held the lock. Once task τiterminates the tasks in the circular buffer between the start and the end pointer are inserted into the ready queue. Notice that the complexity of operating this mechanism is reduced in comparison to EDF. It is important to stress that all operations on the rlist have O(1)complexity. A readyqueue lock is only enforced at the release of some higher priority task, and a new element can only be added to the rlist at the time of the first dispatch of a job. In the same manner an element in rlist is only removed when the job responsible for its insertion terminates. 3.4.2 Maximum Interference Computation The computation of the maximum interference a job might suffer in a ready queue locking framework is presented in this subsection. This computation is carried out on the maximum busy period of the level-i priority for task τi. The worst-case level-i busy period value represents the biggest amount of workload from tasks with priority bigger or equal than imay execute continuously assuming that all the level-i priority tasks are blocked by the maximum allowed time (B). Let us define Γias the set of tasks with priority greater or equal to i. The largest of the level-i busy period occurs when all tasks in Γiare release synchronously and are blocked by the longest time possible(B) [KBL10]. The worst-case level-h busy period is defined as: Li(B)def =min{t|t−(B+rbf(Γi,t)) = 0}(3.9) Let us assume that each task locks the ready queue at time RQLi. A bound on the higher priority interference is required. This bound consists on all the higher priority releases, prior to the release of a job from task τi, which have not yet completed at the release time instant and all of the higher priority releases that occur since the release of τiand RQLi. Theorem 4. The maximum interference any job from task τiis subject to is generated in the level-i busy period where the first job of task τiin the busy period is released φtime units after a synchronous release of all higher priority tasks, where 0⩽φ⩽Li−1(Qi). Proof. Assume that a synchronous release of all higher priority tasks occurs at time t=0 and that a release from τioccurs at t=0 as well. In this scenario the interference the current job from task τican suffer is I0. Let us assume now that φ6=0. For this case the interference the job from task τiis I0−φ, provided that the number of higher priority releases in the interval [0,RQLi]is the same as for the interval [0,RQLi+φ]. In a situation where the number of higher priority releases in the interval [0,RQLi+φ]is greater than the count from [0,RQLi], then the interference suffered by the job of task τiis I0−φ+W, where Wis the additional workload released in the interval [RQLi,RQLi+φ]which will interfere with τiuntil Di. The φfor which the interference is greater constitutes the worst-case scenario for a job from task τi. 59
3.4. READY-Q LOCKING CONCEPT After Li−1(Qi)time units have elapsed since the previous synchronous release of all higher priority tasks has elapsed, mandatorily an idle time has occurred in the processor. If for some φ>Li−1a situation of bigger amount of higher priority workload is generated then the critical scenario would not start with a synchronous release of all higher priority workload, which would contradict the first part of the proof. Since higher priority tasks cannot endure a larger blocking time than Qithen the same value is at most the maximum admissible blocking time for tasks of priority higher or equal to i. Hence the Theorem is proven. In order to find the maximum amount of interference one has then to find the correct higher priority synchronous release offset φ. The value φis extracted by looking at the frame considering all the possible φvalues in the interval [0,Li−1(Qi)] Each frame of the task τi, in the busy period which starts with a synchronous release of the tasks in the level i−1 priority level, has to be checked for its temporal behaviour. The deadline is met in qth frame if the slack in the frame is greater or equal to 0. Let us assume Γito be the subset of tasks with higher priority that task τi. Let us define the following variable in order to ease the discussion: rq i(φ) = (q−1)×Ti+φ(3.10) The variable rq i(φ)encodes the value of the release of the qth job from task τirelative to an absolute time instant, with a given φoffset. Definition 6 [job frame]: The time interval between a job release and its deadline is termed job frame. All jobs in the level-i busy period have to be checked for deadline violations. In order to compute the number of jobs in the busy period, a maximum possible blocking for the level-i has to be considered. The level-i schedule can never be blocked by more than Qi time units, since the tasks of priority greater than τicould otherwise suffer deadline misses. On the other hand τican never be blocked by more than Di−Ci, hence an upper bound on the number of jobs from τiin the busy period can be obtained considering min(Qi,Di−Ci) as the workload initially blocking the level-i schedule. K=Li(min(Qi,Di−Ci)) Ti(3.11) The slack in each frame qmay be expressed by: 60
3.4. READY-Q LOCKING CONCEPT βq i=min φ{max(max t∈[rq−1 i(φ),rq−1 i(φ)+RQLi]{t−(rbf(Γi,t)+q×Ci)}, (rq−1 i(φ)+Di)−(rbf*(Γi,rq−1 i(φ)+RQLi)+q×Ci))}(3.12) Where rbf(Γi,t)def =∑ j∈Γit Tj×Cj(3.13) and rbf*(Γi,t)def =∑ j∈Γit Tj+1×Cj.(3.14) Notice that equations 3.13 and 3.14 only differ in value in multiples of Tj. The usage of both request bound function forms is tied to reducing equation display complexity. The Equation (3.12) is composed by two terms. In the first one the maximum idle time in the schedule is searched for in the interval between the release of a job from task τiand the ready queue locking time instant of the said job. In the second term the maximum idle time for the given frame is searched in the interval between the ready queue locking time instant of the job and its deadline, but since higher priority jobs released in this interval do not interfere with task τiit suffices to compute the idle time at the deadline of the job. For a given φthe maximum idle time is then the maximum value given by the two mentioned terms. Then for all the possible φthe minimum of the idle times is stored in βq i. Considering all the frames the maximum amount of blocking that a job from task τican endure is then defined as: βi=min q{βq i}(3.15) A simple depiction of the schedulability condition is provided in Figure 3.10. In this example the taskset is composed of three tasks. All tasks are implicit deadline tasks with parameters (Ti,Ci). Task τ1has (5,1), and τ2,τ3have (7,2)and (16,4)respectively. It is implicitly assumed that RQLi=Dito simplify the visualization. The subject of schedulability analysis is in this case τ3. Two frames from τ3are present in the figure. One can observe that β1 3=4 and β2 3=8. Since both frames present a non-negative slack value, then the τ3is deemed schedulable. Note that the maximum blocking time admissible for τ3is then 4 time units. This then implies that the level-3 busy period terminates at time instant 24, hence no more frames from task τ3require to be checked. The maximum admissible blocking time for task τiis denoted by βi. The task τiis schedulable if βi>0, when task τiis the task with lowest priority in the system. In order 61
3.4. READY-Q LOCKING CONCEPT t 6 0 4 1st frame 2nd frame 8 5 7 10 14 15 20 21 25 28 30 32 τ1−3τ1τ2τ1τ2τ1τ3τ3 τ1τ2τ1τ2τ1 Figure 3.10: Schedulability Condition for the task-set to be schedulable the RQLivalues for all the tasks have to be set so that the higher priority tasks temporal guarantees are still met. For every qth frame only a subset of the φ∈[0,Li−1(Qi)] needs to be checked. The higher priority workload increment for each frame occurs only at the boundary of the minimum inter arrival time of each higher priority task. Since only offsets up to the maximum busy-level period of the i−1 priority level needs to be checked as has been shown in Theorem 4, only the set of possible higher priority releases in the interval [0,Li−1(Qi)] need to be checked. The discrete set of offsets considered are the ones smaller than Li−1(Qi)(as per Theorem 4) and such that the ready-queue locking rime instant coincides with the arrival of a new higher priority job. This set is defined as: Φq i def ={0}∪ [ j∈hp(i) (&rq−1 i(0)+RQLi Tj',··· ,$Li−1(βi) +rq−1 i(0)+RQLi Tj%)× Tj−(rq−1 i(0)+RQLi)!(3.16) 62
3.4. READY-Q LOCKING CONCEPT t Li−1(βi) + rq−1 i(0) + RQLi rq−1 i(0) + RQLi Figure 3.11: Set of Relevant Offsets for Frame q In Figure 3.11 the set of relevant offsets for the given frame is graphically represents. The offsets are intuitively shown as the distance between the higher priority releases in the hrq−1 i(0)+RQLi,Li−1(βi)+rq−1 i(0)+RQLiiinterval. Of course φ=0 still has to be tested since the sysnchronous release of all the tasks in the level −ipriority band might still generate the critical interference scenario for task τi. 3.4.3 Ready-queue Locking Time Instant The RQLivalue has to be such that τihas enough time to carry out its workload and the higher priority task are not blocked by more time than it is admissible. Each task in the system may endure a maximum blocking time without endangering its timing guarantees [YBB11a]; i.e. all tasks may be blocked by a lower priority task up to a certain limit without missing any deadline. The task with highest priority in the system can always sustain a maximum blocking time of β1=D1−C1. Let us assume that RQL2=D2−Q2. A hypothetical release from task τ1arriving at time instant RQL2would see its ready queue insertion delayed by task τ2by at most Q2 time units. Since, by definition, Q2⩽β1this job from task τ1would still meet the deadline. The concept may be generalized to ntasks by using the following relations: Qi def = 0,if i=1 minj∈hp(i)(βj),if 1 <i⩽n (3.17) Equation (3.17) defines the maximum blocking time (Qi) that all task of higher priority than imay endure without missing a deadline. Assuming RQLi=Di−Qiensures then that, after locking the ready queue a job from task τican only maintain it blocked by at most Qitime units, hence not jeopardising higher priority task’s temporal behaviour. Even if a synchronous release of all tasks in the i−1 63
3.4. READY-Q LOCKING CONCEPT priority level occurs after a ready-queue lock, at time instant rqlithen the queue will not be locked by more than Qi. In a scenario where Ci<Qithen RQLi=Di−Ci. Since values are only inserted into the rlist at time of the first dispatch of a job, it might be the case that the first dispatch of the job occurs after rqli, and hence the job might suffer more interference than it is admissible. By setting RQLi=Di−Ciit is ensured that the first dispatch of the job will always occur before rqli. For each task in the system the RQLiis then set in the following manner: RQLi=Di−min(Qi,Ci)(3.18) Theorem 5. The ready-queue locking scheduling policy dominates over fully pre-emptive fixed task priority. Proof. The maximum interference (UIi) a task τiis subject to is smaller or equal to the interference the same task may endure without the ready-queue locking mechanism. This fact is trivially proved by noting that for the same arrival pattern a job can be interfered by jobs released in a smaller time interval. Hence all the task-sets scheduled by fully preemptive fixed priority are schedulable with ready-queue locking. Since the UIimay at times be smaller than the maximum interference, in fully pre-emptive scheduling, there exist task-sets schedulable by ready-queue locking which fail to be in fully pre-emptive scheduling. It is worth noting that setting RQLi=Di−min(Qi,Ci)is not necessarily the optimal RQLitime instant assignment. This is driven by the fact that an earlier locking will be possible in many situations, caused by a worst-case response time of a task which is shorter than RQLi. Even more, the higher priority task τjwhich limits Qi, may have a worst-case phasing such that an earlier RQLiwill not lead to a reduction of direct interference and thus have no negative effect on the higher priority task and a later than worst-case release would mean more progress for the locking task. However, deriving the optimal RQLiis non-trivial and beyond the scope of this work. 3.4.4 Ready-q Locking with Pre-emption Threshold Another adaptation of FTP targeted at reducing the number of pre-emptions is termed preemption threshold. In this framework tasks are characterized by a base priority and a preemption threshold. When tasks are in the ready queue and not executing they conserve their base priority. When a task commences execution on the processor its priority is increased to its pre-emption threshold value. Effectively, this task can only be pre-empted by tasks with base priority exceeding its pre-emption threshold value. The initial pre-emption- threshold assignment algorithm has been presented in [WS99]. The main drawback of the 64
3.4. READY-Q LOCKING CONCEPT pre-emption-threshold assignment method is that it does not easily allow for a maximum blocking time per task computation. With this in mind the algorithm is rethought. As opposed to the solution proposed in [WS99] the taskset is parsed from the highest priority task to the lowest priority one. Let us assume that the pre-emption threshold (πi) of a task τiis: πi=min(j|Ci⩽min k∈{ j,···,i−1}βk). Upon release a job from task τiis inserted into the ready queue (in case the ready queue is not locked) with priority i. At the time of its first dispatch onto the processor its priority is elevated to πi. The set Γh idenotes the set of tasks of higher priority than πi, whereas the set Γl idenotes the set of tasks with priority higher than ibut lower than or equal to πi. In order to ensure schedulability of the system, for each task, an initial upper-bound on the maximum blocking tolerance is provided. Initially βi=min(Di−Ci,Qi), which is the maximum value that the blocking time could potentially take. The level −ibusy period is then parsed and checked for deadline misses. Let us first define tq sas the worst-case time instant for the first dispatch of the qth job from task τi. This time would be similar to computing the length of the level −ibusy period without considering the qth job from task τi. Where tq sis the worst-case instant in time when the qth job of task τistarts to execute considering a blocking of βitime units in the beginning of the busy period. tq s=min{t|t−(βi+rb f (Γi,t)+(q−1)×Ci)⩾0}(3.19) Notice that if tq s>rq i(0) + RQLithen the qth job from task τiwould miss a deadline since Di−RQLi⩽Ci. A deadline is missed in the qth frame when there does not exist any idle time instant for the level −ibusy period in the interval [tq s,rq i(φ) + Di]. This condition may be written in the following form: @t∈[tq s,rq i(φ)+RQLi]|t−(βi+rb f (Γh i,tq s)+rb f (Γl i,t)+q×Ci)⩾0 (3.20) ∧ Di−(βi+rbf*(Γh i,tq s)+rbf*(Γl i,rq i(φ)+RQLi)+q×Ci)⩽0 (3.21) 65
3.4. READY-Q LOCKING CONCEPT The condition expressed in Equation (3.20) relates to the idle time occurrence in the interval between the release time of the qth job of task τiand the instant in time at which it locks the ready queue. The second condition in Equation (3.21) relates to the search of idle time after the ready-queue is locked by task τi, in an interval where higher priority workload with higher priority than τi’s pre-emption threshold do not interfere with the execution of τi. If both conditions are met simultaneously, then for the given βia deadline may be missed in the qth frame of task τiIn this case, the βiparameter has to be decreased. β− i def =minmin t∈A{t−(βi+rb f (Γi,t)+(q−1)×Ci)}, min t∈[tq s,rq i(φ)+RQLi]{t−(βi+rb f (Γh i,tq s)+rb f (Γl i,t)+q×Ci)}, Di−(βi+rbf*(Γh i,tq s)+rbf*(Γl i,rq i(φ)+RQLi)+q×Ci)(3.22) where Ais the set of time instants when higher priority releases occur in the time interval [rq i(φ),tq s]: Adef ={0}∪ [ j∈hp(i) (&rq−1 i(φ) Tj',··· ,tq s Tj)×Tj!(3.23) In Equation (3.22) there are three terms present. The first one relates to the tq svalue, and both the second and the third relate to the idle time available in the qth frame of task τifor the given φparameter. In the second and third terms the minimum amount of βireduction required to compute all the workload in the frame is computed. In the first parameter the minimum βidecrease which ensures that the tq stime instant occurs before one higher priority job is computed. The βdecreased computed in the first term aims at decreasing the tq ssuch that the qth job from τistarts earlier potentially suffering smaller interference from tasks of higher priority which is still lower than the τipre-emption threshold. The minimum value between the three parameters is then chosen to be the value of β− ifor the current algorithm iteration. Finally the current maximum blocking time allowed by task τiis obtained by : βk i=βk−1 i−β−(k−1) i(3.24) The iterative nature of the procedure described in Equation (3.24) is patent on the super scripts usage. These are omitted from the remainder discussion so as to not overload notations unnecessarily. 66
3.4. READY-Q LOCKING CONCEPT If the deadline is met for the qth frame with φ=0, using ready-q locking still requires all the possible offsets to be tested. As is the case for the ready-q locking mechanism only a subset of all possible φvalues has to be tested, this subset Φq iis defined in Equations 3.23. When the following condition is met ∀q∈ {0,··· ,K},∀φ∈[0,Li−1(β)],∃t∈[rq i(0),rq i(0)+Di]: t−βi+rb f (Γh i,tq s)+rb f (Γl i,t)+q×Ci⩾0 (3.25) then no deadlines are missed for task τi. Ensuring that the condition is met for all the tasks in the taskset will ensure the schedulability of the taskset. Algorithm 5: Pre-emption Threshold Assignment with Ready-q Locking Input :T β1=D1−C1 π1=1 for i={2,··· ,n}do πi=min(j|Ci⩽mink∈{ j,···,i−1}βk) Qi=minj∈hp(i){βj} RQLi=Di−min(Qi,Ci) βi=min(Di−Ci,Qi) K=lLi(βi) Tjm for q∈ {1,··· ,K}do for φ∈Φq ido tq s=min{t|t−(βi+rb f (Γh i,t)+rb f (Γl i,t)+(q−1)×Ci)⩾0} while @t∈[tq s,rq i(φ)+RQLi]|t−(βi+rb f (Γh i,tq s)+rb f (Γl i,t)+q×Ci)⩾ 0∧Di−(βi+rbf*(Γh i,tq s)+rbf*(Γl i,rq i(φ)+RQLi)+q×Ci)⩽0do β− i=min(mint∈A{t−(βi+rb f (Γi,t)+(q−1)× Ci)},mint∈[tq s,rq i(φ)+RQLi]{t−(βi+rb f (Γh i,tq s)+rb f (Γl i,t)+q× Ci)},Di−(βi+rbf*(Γh i,tq s)+rbf*(Γl i,rq i(φ)+RQLi)+q×Ci)) βi=βi−β− i if βi<0then return UNSCHED tq s=min{t|t−(βi+rb f (Γh i,t)+rb f (Γl i,t)+(q−1)×Ci)⩾0} return SCHED 67
4.1. CRPD ESTIMATION 4.1 CRPD Estimation The CRPD when pre-empting a task at a given basic block is estimated using the method proposed by Negi et al in [NMR03]. The method relies on the fixed-point computation, for every basic block of: •Reaching Cache States (RCS). The Reaching Cache States at a basic block BBbof a program, denoted as RCSb, is the set of possible cache states when BBbis reached via any incoming program path. This notion captures the possible cache content when the task is pre-empted at BBb. •Live Cache State (LCS). The LCS at BBb, denoted as LCSb, is the set of memory blocks that may be referenced in the future in any outgoing program path from BBb. This notion captures the potential reuse of memory blocks after a pre-emption point occurring at BBb. Cache Utility Vectors (CUV) as defined in [NMR03] are then computed, and correspond to the cache blocks that may be in the cache (in RCS) and may be reused (in LCS). By definition, the pre-emption delay upper-bound function fi(t)holds the worst-case pre-emption penalty associated to each progress point t. This penalty value is a function of the CUV at that particular point and the cache sets used by the pre-empting tasks. In order not to consider multiple fi(t)functions (distinct functions per higher priority task), just a single ECS could be assumed for all higher priority tasks. This ECS would be computed through the union of the ECS sets of all tasks with priority greater than the considered task. In order not to overload notation, and without loss of generality, the CRPD at BBbis then simply the delay to reload all the cache blocks in CUVb, without considering cache usage in the pre-empting task(s) as done by Negi et al. [NMR03] and Altmeyer et al. [AB11]. 4.2 Computing Execution Intervals Computing fi(t)for every task τi, represented by its control-flow graph (see left part of Figure 4.1), requires the identification of the corresponding time interval during which every basic block bof τimight execute. The minimum and maximum execution time of every basic block b, noted respectively emin band emax bhave to be known. The cache analysis method used to classify every memory access uses the following categories: •AH (Always Hit) when the access will always result in a hit •AM (Always Miss) when the access will always result in a miss 74
4.2. COMPUTING EXECUTION INTERVALS 1 3 4 5 2 0 6 1 3 4 5 2 0 6 [15,25] [20,40] [10,20] [20,30] [0,0] [15,25] [35,65] [30,85] [0,0] [0,0] [50,115] [0,0] [15,35] [15,25] (a). CFG with Execution Time Intervals per BB Latest Start Offsets per BB (b). CFG with Computed Earliest and Figure 4.1: Example of CFG for loop-free code. •FM (First Miss) the access could neither be classified as hit nor miss the first time it occurs but will result in cache hits afterwards (this category is used for code inside loops) •NC (Not Classified) when no precise categorization can be achieved Given the classification of every reference, respective values of emin band emax bare easily generated by considering the lower and higher delays allowed by the category (e.g. hit delay and miss delay for the category NC). The first iteration of every loop is virtually unrolled before applying the analysis in order to ease the analysis and still allow for the limitation of the number of references classified FM and NC. Then, computing execution intervals on loop-free code requires to know for every basic block bits earliest and latest start offsets smin band smax b. This can be done by a breadth-first traversal of the CFG, applying to every traversed basic block bthe following formulas: smin 0=smax 0=0 (4.1) smin b=min x∈pred(b)(smin x+emin x)(4.2) smax b=max x∈pred(b)(smax x+emax x)(4.3) 75
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS with pred(b) the direct predecessor(s) of a basic block bin the CFG, and the task entry basic block (BB0). In the formulas, emin x(resp. emax x) represent the minimum (resp. maximum) execution time of basic block b; such values can be produced by standard WCET estimation tools (variations between emin xand emax xcome for example from memory references that cannot be determined statically as hitting or missing the cache). The right part of Figure 4.1 shows for every basic block its earliest and latest start offset after applying the above formulas. Then, the time interval within which every basic block b may execute is [smin b,smax b+emax b]. The method was generalized to code with natural loops and function calls as follows. A fundamental assumption in the WCET analysis is that there exist definite bounds to the number of iterations of each loop. Every loop can then be unrolled (i.e. an equivalent CFG can be derived which does not contain any loop). The computation of execution time intervals is done on every loop starting from the innermost one, and then considering every loop as a single node with known earliest and latest start offsets. Similarly, in case of function calls, each function is analysed for every call context, starting from the leaves in the acyclic call graph. 4.2.1 Computation of fi(t) Knowing the possible execution interval [smin b,smax b+emax b]of every basic block b, the set of basic blocks that may execute at a time instant t, noted BB(t) = n∪{b|smin b⩽t⩽smax b+emax b}BBbo is known. For each basic block bin this set, fi(t)can then be computed as follows, with CRPDbthe CRPD paid when pre-empting the task at basic block BBb: fi(t) = max ∀b∈BB(t) {CRPDb}(4.4) 4.3 Determination of Pre-emption Delay Upper-bounds As stated previously, when floating non-pre-emptive region scheduling is employed, a task will always execute non-pre-emptively for at least Qitime units before a pre-emption occurs, unless it completes before the end of the non-pre-emptive region. In the present discussion, the term “progression point“ is employed referring to a specific instruction in the tasks’ code. Program points are loosely associated to a time value in the task execution time frame. This means that a program point can have a minimum access time and a maximum access time but the instant at which it is reached may vary between jobs. In this framework if pk<pathen the program point pkprecedes pa. For clarity purposes a precedence relation is assumed between any pair of program points. A naïve thought to upper-bound the cumulative pre-emption delay over a task’s execution (say τi) might be to select from fithe maximum number of progression points pk(each 76
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS p1 f(t) PD Hypothetical Run p1 p2 p2 p3 Q2Q3Q4Q Figure 4.2: Comparison between Function fiand the Run-time Pre-emption Delay distanced from every other by at least Qitime units) such that the sum ∑∀pkfi(pk)is maximized. However, the simple example depicted in Figure 4.2 shows that this solution is not correct. As one can see, on the top plot where fiis depicted, there are at most two points that may be selected (since no three points could be distanced by at least Qitime units in time). The bottom plot presents a hypothetical run of task τi, where the run-time pre-emption delay cost is presented. At run-time, since time is spent paying pre-emption delay after each pre-emption, more points can be selected (see the bottom plot), hence providing a higher cumulative pre-emption delay. A pessimistic, but correct, solution to upper-bound the execution time C0 iof a task τi while taking into account all the possible pre-emption delays that τimight suffer during its execution, is simply to multiply the maximum number of pre-emptions that can occur during τi’s execution (i.e., jCi Qik, this is discussed in more detail in the previous section) by the maximum delay of one pre-emption (i.e., maxt∈[0,Ci]fi(t)). Given the increase in the WCET due to this cumulative overhead, the maximum number of pre-emptions that can occur eventually increases as well. Therefore, this computation has to be performed iteratively, in the style of the well-know task response-time computation, i.e., C0(0) i=Ciand C0(k) i=Ci+$C0(k−1) i Qi%×max t∈[0,Ci]fi(t)(4.5) The pessimism of this computation comes directly from the fact that it considers a constant cost for every possible pre-emption, and this constant cost is assumed to be the maximum possible cost. That is, this approach is not sensitive to the pre-emption cost pattern of the task. As it was claimed in the abstract, using this additional information (the tasks 77
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS Algorithm 6: Upper-Bound the Pre-emption Delay Input :fi(): pre-emption delay function of task τi Qi: length of the non-pre-emptive region Output: total_delay: cumulative pre-emption delay suffered by τi 1prog ←0 ; 2total_delay ←0; 3delaymax ←0 ; 4pnext ←Qi; /*While the next progression is not beyond Ci*/ 5while pnext <Cido /*Update time, progression and delay */ 6prog ←pnext ; /*Compute the next progression step and the next delay to account for */ 7p∩←min{px}such that 8px∈[prog(k),prog(k)+Qi] 9and fi(px) = −px+prog(k)+Qi}; 10 if p∩=null then p∩←prog+Qi; 11 pmax ←argmaxpx∈[prog,p∩]{fi(px)}; 12 delaymax ←fi(pmax); 13 pnext ←prog+Qi−delaymax; 14 total_delay ←total_delay+delaymax ; 15 return total_delay ; pre-emption cost pattern) enables us to derive a more accurate upper-bound. This second technique is described in Algorithm 6, and a detailed explanation is provided below. Qi prog +Qi pmax prog D(x, t) p∩ pnext delaymax Qi−delaymax delaymax Figure 4.3: Algorithm iteration sketch 78
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS Description of Algorithm 6.Initially an explanation of the intuition behind the approach is provided on Figure 4.3 before presenting the actual algorithm. In Figure 4.3 the grey curve is the fifunction. Suppose that prog is the current progression in the task execution. Considering the next pre-emption point, the approach is looking for the lower bound on the progression which will be achieved within the next Qitime units in any pre-emption scenario. For this, function fiis investigated from the current prog to prog+Qi. On the ordinate also at length Qia line D(x,t)is drawn to prog+Qi. The point p∩where ffirst crosses D(x,t)limits the range of values which need to be considered. A pre-emption past this value would lead to a situation where this point would again be considered in a subsequent iteration, since then prog would not pass this point in the current iteration. Within the interval, delaymax is determined. That means in an interval Qiunder any preemption scenario at least Qi−delaymax progress in program execution will be achieved. It is a conservative bound as a later pre-emption means that also the non pre-emptible region will only start then. This point prog+Qi−delaymax will serve as new starting point. Returning to the Algorithm 6: Lines 1–4 initialise the variables. The variable prog records the current progression in the task’s operations while total_delay records the cumulative pre-emption delay accounted for up to the current progression point. As the task τi executes, it accounts for progressing in its execution (and the variable prog is increased) and for the pre-emption delay (which updates the variable total_delay). The algorithm is iterative, and at each iteration the variables delaymax and pnext (lines 3 and 4) are the preemption delay taking place only in the current iteration and the next progression point in τi’s execution at which the next iteration will start, respectively. Lines 1–4 can be seen as the first iteration of the algorithm. delaymax is set to 0 and pnext to Qi, because no pre-emption can occur during the first Qitime units of τi’s execution. The algorithm starts iterating at line 5, and it iterates as long as the next computed progression point pnext does not fall beyond τi’s execution boundary. Line 6 shifts the current progression point of τito the computed value pnext. Then, lines 12 and 13 compute the next progression point pnext and the maximum delay that τicould suffer while progressing in its operations from its current progression point to pnext. Finally, line 14 adds this maximum delay to the current cumulative delay accounted so far. In the following Theorem 6, it is proven that the value returned by Algorithm 6is an upper-bound on the cumulative pre-emption delay that the given task τimight suffer during its execution. This implies that the WCET of τi(while taking into account all the possible pre-emption delays that τimight suffer during its execution) is given by C0 i def =Ci+total_delay (4.6) where total_delay is the value returned by Algorithm 6. 79
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS Theorem 6. Algorithm 6returns an upper-bound on the pre-emption delay that a given task τican suffer during the execution of any of its jobs. Proof. Algorithm 6computes the maximum cumulative pre-emption delay iteratively, by progressing step by step through the execution of the task τi. Hereafter, the notation prog(k) is employed to denote the progression through τi’s execution at the beginning of the kth iteration of the algorithm. Similarly, total_delay(k)will be used to denote the cumulative pre-emption delay that τihas suffered until it reached a progression of prog(k). In this proof, it is shown that at each iteration k>0, total_delay(k)provides an upper-bound on the cumulative pre-emption delay that τimight suffer before reaching a progression of prog(k) in its execution. The proof is made by induction. Basic step. Algorithm 6first considers that τiprogresses by Qitime units in its execution without suffering any pre-emption delay (since it cannot get pre-empted during these first Qitime units). This first step is devised as the first iteration of the algorithm. That is, straightforwardly, total_delay(1)=0 is an upper (and even exact) bound on the cumulative pre-emption delay that τimay suffer before reaching a progression of Qitime units in its execution. Induction step. It is assumed (by induction) that total_delay(k),k>1, is an upper-bound on the cumulative pre-emption delay that τimight suffer before reaching a progression of prog(k)time units in its execution. During the kth iteration, Algorithm 6computes prog(k+1)and total_delay(k+1)as follows: prog(k+1)=prog(k)+Qi−delaymax (4.7) total_delay(k+1)=total_delay(k)+delaymax (4.8) where delaymax =fi(pmax)(4.9) pmax =argmax px∈[prog(k),p∩] {fi(px)}(4.10) p∩=min{px}such that (4.11) px∈[prog(k),prog(k)+Qi] and fi(px) = −px+prog(k)+Qi Equations 4.7 and 4.8 can be interpreted as follows. During the kth iteration, Algorithm 6 assumes that τiexecutes for Qitime units during which τiprogresses by Qi−delaymax units of time in its execution and suffers from a delay of delaymax; The algorithm assumes that τigets pre-empted when its progression reaches pmax given by Equation (4.10). Below 80
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS we show that choosing any other pre-emption point pother 6=pmax would ultimately, when τi’s execution will be completed, result in a cumulative pre-emption delay lower than the one returned by Algorithm 6, thus showing that the value returned by Algorithm 6is an upper-bound. Only two cases are possible: pother >pnext or pother ⩽pnext. Case 1:pother >pnext. This means that τiprogresses in its execution until it reaches pnext without being pre-empted, i.e., from a progression of prog(k),τireaches a progression of pnext by being executed only for (pnext −prog(k))time units, and with an unchanged cumulative pre-emption delay of total_delay(k). On the other hand, in the execution scenario built by Algorithm 6,τi’s execution reaches a progression of prog(k+1)=pnext by being executed for Qitime units, and with a cumulative pre-emption delay of total_delay(k+1)= total_delay(k)+delaymax ≥total_delay(k). In other words, Algorithm 6manages to progress slower in τi’s execution while suffering from a greater pre-emption delay. Furthermore, pother is still a candidate pre-emption point for a further iteration of Algorithm 6. Case 2.pother ⩽pnext.After executing τifor Qitime units, the following facts hold 1. the delay of the pre-emption that occurs when τi’s progression reaches pother has been totally accounted for (since pother <pnext ⩽p∩). 2. the progression of τiin this scenario becomes progother =prog(k)+Qi−fi(pother) ⩾prog(k)+Qi−fi(pmax) ⩾prog(k+1)(4.12) 3. the cumulative pre-emption delay becomes total_delayother =total_delay(k)+fi(pother) ⩽total_delay(k)+fi(pmax) ⩽total_delay(k+1)(4.13) Thus, after executing τifor Qitime units Algorithm 6progressed less in the execution of τi(Inequality 4.12) while suffering from a higher pre-emption delay (Inequality 4.13). As a consequence of Cases 1 and 2, it holds at each iteration of Algorithm 6that choosing to pre-empt the task when it reaches a progression of pmax ultimately leads to an upper-bound on its cumulative pre-emption delay. 4.3.1 Extrinsic Cache Miss Function Until now the pre-emption delay is assumed to be paid immediately following a pre-emption. By analysing the task code it is possible to extract information on when the pre-emption de- 81
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS lay may be paid. This is captured through the concept of the Extrinsic Cache Misses or “Miss Function”. Definition 3 [Extrinsic Cache Miss]: A memory access resulting in a cache miss due to the prior eviction of the requested cache line by code not belonging to the current task is termed extrinsic cache miss. The extrinsic cache miss function Gi(t)is an upper bound on the number of extrinsic cache misses a task might suffer, multiplied by the maximum time penalty to service a cache miss, in the interval [0,t].Gi(t)is then an upper-bound on the pre-emption delay that might have been paid in the same interval. Using the Gi(t)information it is possible to provide pre-emption delay estimations in the presented framework for situations where Qi⩽ maxt(fi(t)), whereas in the methodology provided in Algorithm 6this is not possible. This subsection is devoted to the explanation of the procedure to compute this Gi(t)function. 0t emax b 10 10 ×BRT glocal i Figure 4.4: Example glocal bFunction Where BBbExecution May Generate at Most 10 Extrinsic Cache Misses Each basic block has a fixed number of memory requests which may lead to extrinsic cache miss during its execution. For each BBithis number is given by extrinsic-missb=|RCSb∩genb|(4.14) Recall that genbis defined as the set of memory blocks accessed during the execution of BBband RCSbis the set of memory blocks that may be in the cache while BBbis being executed. The intersection of both sets at each BBbeffectively yields the upper bound on the number of extrinsic cache misses that may occur while BBbis executed after a pre-emption. For each BBba function can then be constructed. This function glocal b, has the memory requests that may lead to an extrinsic cache miss in BBb. These requests are assumed to occur as early as possible and at the maximum rate at which they can occur, as is displayed in Figure 4.4. This function is defined in the interval [0,emax b], which is the maximum length execution time interval for BBb. Let us define the following constant BRR modeling the block reload rate: 82
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS BRR def =THIT +TMISS THIT where THIT is the time to serve a cache hit, and TMISS is the time to serve a cache miss. The constant BRR imposes a restriction on the maximum rate in comparison to progression that pre-emption delay may be paid. Assuming BRR 6=∞ensures that while paying pre-emption delay progression is still occurring, albeit at a slower pace. Intuitively BRR is an upper bound on the maximum rate at which cache miss penalties may be generated while executing the program. Formally the glocal bfunction is defined per basic block as: glocal b def = BRR×t,if0 ⩽t⩽extrisic-missb BRR extrisic-missb,ifextrisic-missb BRR <t⩽emax b (4.15) A task-wide glocal function is constructed starting from the first BB1of the CFG. An initial function gin 1is fed into the CFG. Where gin 1(t) = 0,∀t. The input functions for each BBbare then merged together with glocal bas is shown in Figure 4.5 gout jgout k jk bgin bglocal b gout b gin b Figure 4.5: gout bComputation for BBb The two merge operations used to conduct the computation of the task-wide extrinsic cache misses function are defined next. Each block outputs a function gout b. Accordingly each basic block has one input function gin b. This input function is a product of the merging of all the output functions of the BBbparent nodes. The input merging operation is defined by: gout j⊕gout k def =max t∈[0,Ci](gout j(t),gout k(t)) (4.16) The input function is then merged with the corresponding node-specific glocal bfunction using the merge-at-node operation defined in the following way: 83
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS pre-empt the task when it reaches a progression of pmax ultimately leads to an upper-bound on its cumulative pre-emption delay. 4.3.3 Reducing the pessimism of fi(t) For computation of the pre-emption delay estimation the obtained fi(t)function is pessimistic. The main source of pessimism is the fact that the earliest possible entry time for each basic block is considered in the function computation. Even though the fi(t)function is an upper bound on the pre-emption delay that might be paid at any progression point tin the task a less pessimistic function may be extracted. In fact if a basic block is accessed earlier than its worst case access time then the execution is in a situation which will never lead to the WCET. If the task is pre-empted in this basic block at an earlier time than the worst case access time, the pre-emption delay that has to be paid is already doubly accounted on the WCET computation. To exemplify this intuition consider the example provided in Figure 4.1 (page 75). For the case of BB4,smin 4=35, smax 4=65 and emax 4=20. Lets arbitrate CRPD4=5. If this BB4is accessed at t=40, and a pre-emption occurs at t0=45, when the task resumes its execution at most 7 units of time will be spent regaining cache state. The BB4exit time would be t00 =65 whereas the worst case exit time computed statically is smax 4+emax 4=85. One can then observe that t00 <smax 4+emax 4. The conclusion follows that: pre-emptions occurring in BB4at an earlier time in comparison to the worst-case execution time behaviour do not necessitate to consider the full worst-case pre-emption delay penalty. Clearly t00 is smaller than the statically computed worst-case exit time and hence it does not make sense to consider a pre-emption delay of 5 units when the basic block is accessed at time t=40. A more thorough definition and explanation of the concept follows. The optimised fi(t)function is then defined as: fi(t) = max b{flocal b(t)}(4.27) The function flocal b(t)is defined for each BBb. It represents the pre-emption delay value the tasks is subject to when pre-empted in each basic block but refrains from considering the full pre-emption delay cost when the basic block is accessed earlier than in the worst-case time access profile. The function flocal b(t)is formally defined in the following manner: 90
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS flocal b(t)def = 0,0⩽t<max(smax b−CRPDb,smin b) CRPDb×(t−smax b−CRPDb),max(smax b−CRPDb,smin b)⩽t⩽smax b CRPDb,smax b<t⩽emax b 0,t>emax b (4.28) smin b CRPDb smax b−crpdbtsmax b Figure 4.7: flocal b(t)Graphical Example Figure 4.7 presents a graphical representation of the flocal b(t)function. From smin bto smax b−CRPDbthe value of the function flocal b(t)is zero. In the interval smax b−CRPDbto smax bthe function flocal b(t)has a first derivative of one. Lastly, from smax bto smax b+emax bthe function is constant at the CRPDbvalue. 0 10 20 30 40 50 60 70 80 90 100 110 120 t fi(t) Figure 4.8: Task Wide fi(t)Obtention In Figure 4.8 the procedure to compute the task-wide fi(t)function is graphically portrayed. Several flocal b(t)function are displayed with dashed lines. For all the instants in 91
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS time, the maximum value of all the local flocal b(t)is taken as the value of fi(t). Lemma 2. Assuming an entry time t1such that smax b−CRPDb⩽t1<smax band a pre-emption occurring at t1, the progression point achieved in a Qilength time window assuming a preemption delay payment of f local b(t1)is equal to the progression point assuming an entry time t2=smax b. Proof. f local b(t1) = t1−(smax b−CRPDb) prog1=Qi−t1+(smax b−CRPDb)+t1 prog2=Qi−CRPDb+t2 prog1=prog2⇔Qi−(t1−(smax b−CRPDb)) +t1=Qi−CRPDb+t2⇔Qi+smax b= Qi+t2. Since t2=smax bthe Lemma is proven There exits a set of possible paths from BB1to BBbsuch that for all these possible program paths BBbwill be accessed at a time instant p0in the program where p0∈[smin b,smax b]. For all possible paths where the entry time of BBbfor which p0<smax bthen the execution is earlier in relation to the worst-case execution time by smax b−p0time units. When computing the fi(t)function for each progression point considered the point with the maximum pre-emption delay is chosen. It is the case that for the paths which diverge from the worst-case execution time behaviour then paying pre-emption delay in this paths would just bring them closer to the worst case execution time behaviour. As long as the progression is sufficiently distanced from the worst-case pattern for BBb execution then no pre-emption delay has to be considered, since this would lead to a double accounting of the pre-emption delay. Consider a situation where smax b−p0>CRPDb, if the task would be executing in BBb, by paying the pre-emption delay of CRPDbwould not bring this execution to the worst-case execution time scenario. In the same way if 0 <smax b−p0<CRPDbthen paying a portion of the pre-emption delay payment given by smax b−p0would bring the execution exactly into the worst case scenario. From this point onwards the maximum pre-emption delay for the basic block should be paid since the progression on BBbis already in a worst-case scenario. Lemma 3. For all the BBbthat a given progression point p might belong to, the pre-emption delay payment is given maxbmax(min(CRPDb−(smax b−p),CRPDb),0). Proof. For a given BBb, and a current actual progression point p, if CRPDb−(smax b−p)<0 then for BBbis smax b−ptime units earlier in relation to the worst-case entry time behaviour for the given block. Paying CRPDbin this instance is not putting it in a worse situation than the worst-case entry smax b−pand hence is not leading a optimistic analysis result. 92
4.3. DETERMINATION OF PRE-EMPTION DELAY UPPER-BOUNDS Theorem 9. The Function fi(t), considering f local b, provides a safe upper bound on the pre-emption delay paid during a pre-emption of BBbin a WCET context. Proof. In Lemma 2it is shown that any scenario where a basic block is considered to be accessed between smax b−CRPDband smax bwill be treated such that is equivalent of accessing BBbat time smax b. Additionally, in Lemma 3it is proven that BBbarriving before smax b− CRPDbthe actual progression in the real execution is at least as good as arriving at smax b. Hence, using fi(t)provides a safe upper bound for the pre-emption delay to be taken into account during analysis. 4.3.4 Reducing the pessimism of Gi(t) Following the same reasoning as in section 4.3.3, the Gi(t)function holds pessimism for the pre-emption delay computation in a WCET analysis context. The merge at node operation is then defined as: glocal b⊗gin b def = gin b(t),if t⩽max(smax b−glocal i(emax b),smin b) max(gin b(t) +glocal b(t−max(smax b−glocal i(emax b),smin b))) ,if max(smax b−glocal b(emax b),smin b)<t<Ci (4.29) In this way the pre-emption delay is only accounted for when the task execution is in a path that would lead into the WCET. Theorem 10. The Function Gi(t)is an upper-bound on the extrinsic cache misses occurring during the execution of task τifor any time t in a WCET context. Proof. The redefinition of the merge-at-node operation integrates the glocal bfunction only at the time instant t=max(smax b−glocal b(emax b),smin b). For all the time instants t0<tif the BBb is executing and generates an extrinsic cache miss then this value was already accounted for in the WCET analysis since: t0+glocal b(emax b)+emax b<smax b+emax b⇔t0+glocal b(emax b<smax b⇔t0<smax b−glocal b(emax b) The only change to the computation procedure of Gi(t)lies on the merge-at-node operation. Hence proving the correctness of the merge-at-node operation redefinition along with Theorem 7proves the present theorem. 93
4.4. EXPERIMENTAL EVALUATION 4.4 Experimental Evaluation In order to experimentally validate both the new pre-emption delay estimation algorithm 7 the fi(t)and glocal(t)function extraction procedures were implemented in Heptane. Results are also provided for the previous function fi(t)(Algorithm 6). The framework is trialled on a set of benchmarks available online [NCS+06]. Not all the benchmark results are presented. From the set of benchmark programs the results for acquisition task, autopilot task 6, autopilot task 9 and interrupt handler routine are shown. All the results are given for a direct-mapped instruction cache of 4KB, with a line size of 32 bytes (8 instructions). The data cache is perfect (i.e. data cache misses are assumed never to occur). Only results regarding instruction caches are presented at this time since data caches were not yet addressed theoretically. The analysed code is MIPS code (fixedsize 4B instructions). The code also works with set-associative caches. There is only one level of cache, with 1 cycle when the fetched instruction hits the cache, 10 cycles in case of a miss. 4.4.1 fi(t)functions A comparative evaluation between the prior fi(t)function extraction procedure and the more recent one is presented. As is apparent in all the benchmarks the current method enables a considerable increase in the amount of information present in the new fi(t)functions. The regular fi(t)(Equation (4.4)) is always greater than the optimized version (Equation (4.27)). With this new concepts it is then possible to decrease the level of pessimism present in the analysis of the pre-emption delay. The major differences are present in the results shown in Figures 4.9b, 4.9c and 4.9d. For these benchmarks, the results of the optimized fi(t)function are lesser pessimistic than the prior method presented initially in section 4.3. 4.4.2 Pre-emption Delay Estimations The pre-emption delay estimations are presented in this subsection. Only the improved version of the fi(t)is used, since it is obvious that the results could never be worse than using the old version of the function. In all the results present in Figures 4.10a to 4.10d it is apparent that the results are less pessimistic both for the previous method (which only uses fi(t)information) and for the new method with the Giknowledge in comparison to the naïve state of the art method (Equation (4.5)). The naive state of the art method in Equation 4.5 is an intuitive upper-bound on the pre-emption delay for the floating non-pre-emptive regions scheduling. Its results are the curves labeled as “SOTA” in figures 4.10a to 4.10d. The method using the Gifunction information is never worse than the one which relies purely 94
4.4. EXPERIMENTAL EVALUATION 0 100 200 300 400 500 600 0 20000 40000 60000 80000 100000 120000 140000 160000 Preemption Delay Non-preemptive Region Length (Q) Regular f(t) Optimized f(t) (a) Regular fi(t)and Optimized fi(t)Function for Acquisition Task 0 10 20 30 40 50 60 0 1000 2000 3000 4000 5000 6000 Preemption Delay Non-preemptive Region Length (Q) Regular f(t) Optimized f(t) (b) Regular fi(t)and Optimized fi(t)Function for Autopilot.t6 0 10 20 30 40 50 60 70 80 0 1000 2000 3000 4000 5000 6000 7000 8000 Preemption Delay Non-preemptive Region Length (Q) Regular f(t) Optimized f(t) (c) Regular fi(t)and Optimized fi(t)Function for Autopilot.t9 0 20 40 60 80 100 120 0 200 400 600 800 1000 1200 1400 Preemption Delay Non-preemptive Region Length (Q) Regular f(t) Optimized f(t) (d) Regular fi(t)and Optimized fi(t)Function for Interrupt Handler Figure 4.9: fi(t)Experimental Results on the fi(t)function, and enables solutions to be obtained for situations where Qiis lower than some value of fi(t)as is shown in figures 4.10a to 4.10d. 95
4.4. EXPERIMENTAL EVALUATION 10 100 1000 10000 100000 1e+06 0 20000 40000 60000 80000 100000 120000 140000 160000 Total Preemption Delay Non-preemptive Region Length (Q) Algorithm 3 Algorithm 4 SOTA (a) Pre-emption Delay Estimations Function for Acquisition Task 10 100 1000 10000 100000 0 1000 2000 3000 4000 5000 6000 Total Preemption Delay Non-preemptive Region Length (Q) Algorithm 7 Algorithm 8 SOTA (b) Pre-emption Delay Estimations Function for Autopilot.t6 10 100 1000 10000 100000 1e+06 0 1000 2000 3000 4000 5000 6000 7000 8000 Total Preemption Delay Non-preemptive Region Length (Q) Algorithm 7 Algorithm 8 SOTA (c) Pre-emption Delay Estimations Function for Autopilot.t9 10 100 1000 10000 100000 1e+06 0 200 400 600 800 1000 1200 Total Preemption Delay Non-preemptive Region Length (Q) Algorithm 7 Algorithm 8 SOTA (d) Pre-emption Delay Estimations Function for Interrupt Handler Figure 4.10: glocaltExperimental Results 96
Chapter 5 Temporal-isolation Enforcement Before a safety-critical system can be deployed and marketed, a certification authority must validate that all the safety-related norms are met. All the components comprising that system (the software, the hardware, and the interfaces) are scrutinized to ensure conformance to safety standards. To provide the required degree of “sufficient independence” between components of different SILs, Industry and Academy have always been working in close collaboration, seeking solutions to (1) render the components of a same SIL as independent and isolated as possible from the components with different SILs and (2) upper-bound the residual impact that components of different SILs may have on each other after the segregation step, with the primary objective of certifying each subset of components at its own SIL. This chapter presents a novel solution for ensuring the temporal-isolation property in systems where pre-emptions are subject to non-negligible overheads. In this case a symmetric isolation is enforced, i.e. where tasks do not impact each other irrespective of their individual SIL. A prior version of this framework has been presented in a previous work [MNP14]. A standard implementation of the symmetric temporal-isolation is by the usage of servers [AB04], [LKPB06]. These servers provide a certain share of the processing resource called budget, which is supplied to a task in a recurrent fashion. While the general concepts of servers have been well explored, the use of implicitly shared resources, like caches is still an open issue for server-based systems. When a task executing in a server is pre-empted by a higher priority task, it loses at least partially its set of useful memory blocks in the caches (working set) and other shared resources. This loss of working set leads to an additional execution time requirement on resumption of execution, which either needs to be accounted for in the sizing of the budgets of individual tasks, or treated through online mechanisms. Besides easing timing analyses, schedulability analyses, and the certification process, the main objective of temporal-isolation via servers is also to isolate applications from other 97
5.1. CHAPTER-WISE UPDATE ON SYSTEM MODEL temporally misbehaving applications and their corresponding effects. This misbehaviour can come in two distinct flavours. Firstly, in terms of a violation of the WCET assumptions, secondly in the minimum inter-arrival time assumption made in the analysis step. While the former has been treated to reasonable extent [LKPB06], the latter is of equal importance. In this chapter a mechanism which enforces temporal isolation is presented. The devised solution is able to accommodate both forms of misbehaviour. At the end of the chapter an experimental evaluation attestss to the efficiency and benefit extracted from the usage of said mechanism. 5.1 Chapter-wise Update on System Model When tackling a given problem the simplest possible system model which allows for an adequate property manipulations is employed. Generally a system model as presented in section 1.2 offers a robust footing on which to develop and prove theories for real-time systems. Unfortunately the model presented in section 1.2 relies on a fundamental assumption which is generally not present in the real world. That of which the task’s assumed properties at design time are stringently met at runtime. Tasks are written according to a specification. It is the job of the developer entity to ensure that in fact the WCET is met in the given platform, that the minimum inter-arrival time is in fact observed (i.e. that under any circumstance will a given task request to execute at a greater frequency than anticipated). As in section 1.2, the workload is modelled by a task-set T={τ1,...,τn}composed of ntasks. Each task τiis characterized by the three-tuple hCi,Di,Tiiwith the following interpretation: τigenerates a potentially infinite sequence of jobs, with the first job released at any time during the system execution and subsequent jobs released at least Titime units apart. Each job released by τimust execute for at most Citime units within Ditime units from its release. Hence, the parameter Ciis referred to as the “worst-case execution time”, Diis the relative deadline of the task and Tiis its minimum inter-release time (often called, its period). Contrary to the bulk of this document where the three parameters Ci,Diand Tiare assumed to fully characterize and describe the tasks and its interaction with the system (at least the interactions which are of interest to this work – duration of resource usage), in this chapter these parameters solely represent the terms of an agreement between the task and the system. This concept reflects an inherent distrust from the system point of view towards the implementation that embodies each task and the nature of the events that might trigger its execution – which may in turn be external to the embedded system itself. In order for each task’s behaviour not to suffer from external misbehaviour the system has to ensure that each party respects its contract. 98
5.1. CHAPTER-WISE UPDATE ON SYSTEM MODEL A task τiis said to “behave” if it does not require more system resources than by its contracted parameters. Otherwise, if any job of τicomes to request more than Citime units to complete, or if τireleases two consecutive jobs in a time interval <Titime units, then τi is said to be “misbehaving”. The other party – the system – is assumed to never violate its contracts with any task. The system associates to each task τiasporadic server Sidefined by the two-tuple hBi,Ts ii. The parameter Biencodes the execution budget that Siprovides to τiin any time window of length Ts i. This budget is consumed as task τiexecutes and a task can only execute if its budget is not depleted. The function Bi(t)denotes the remaining budget in the server Siat every time instant t. t Bi t τi 0Ti Ti Figure 5.1: Sporadic Server Budget Replenishment A sporadic server is, at any time instant, in either one of the two following states: active when there is pending workload from task τiand Bi(t)>0; idle when there is no pending workload from task τior Bi(t) = 0. The sporadic server budget replenishment mechanics can be described succinctly by the protocol formulated with the two following rules: •When the server transits to the Active state at a time t1, a recharging event is set to occur at time instant t1+Ts i; •when Sitransits to the idle state at a time t2, the replenishment amount corresponding to the last recharging time is set to the amount of capacity consumed by Siin the interval [t1,t2). 99
5.4. PROPOSED BUDGET DONATION FRAMEWORK As introduced earlier, if every task τiaugments its budget for δj,itime units after being pre-empted by a task τj, then an upper bound on the total budget augmentation in any time window of length tis given by ∑i−1 j=1∆j,i(t). It can be shown that in any given time window of length t, an upper-bound on the number of execution resumptions in a schedule is given by q1,i(t)since according to its definition the maximum possible number of job releases of tasks with priority greater than i, in an interval [0,t], is accounted for. Therefore, assuming that performing each execution of the budget augmentation consumes Fcost units of time, the time-penalty attached to the implementation of the proposed framework has an upper bound of delay(t) = q1,i(t)×Fcost (5.16) Integrating these quantities into Schedulability Test 1yields the following test: Schedulability Test 2. A task set Tis schedulable if, ∀τi∈T,∃t∈(0,Di]such that Ci+delay(t) + i−1 ∑ j=1 [rbf(Sj,t)+∆j,i(t)] ⩽t(5.17) Correctness of Schedulability Test 2.Function (5.6) upper-bounds the number of times that jobs from task τjmay pre-empt jobs of priority lower than τjand higher or equal than τi in a window of length t. Function (5.5) (∆j,i(t)) is the summation over the qj,i(t)largest values in the multi-set Mj,i(t). The function ∆j,i(t)is then an upper-bound on the amount of pre-emption delay compensation that can be extracted from task τjfrom any task of priority lower than τjand higher or equal than τiin a window of length t. Thus ∑i−1 j=1∆j,i(t)is an upper-bound on the pre-emption delay compensation budget used by tasks of priority higher or equal than τifor any time t. As a consequence and by the correctness of schedulability test 1, the correctness of this schedulability test is proven. According to Schedulability Test 2and as a consequence of Theorem 11, assuming delay(t) = 0 then the proposed framework enables a higher schedulability than considering the budget Biof each server Sito be equal to Ciplus the maximum pre-emption delay that any job of τimay be potentially subject to (see Equation (5.2)). However, in a scenario where delay(t)is non-negligible the dominance relation does no longer hold. 5.4 Proposed Budget Donation Framework The framework presented above is a combination of a reservation-based mechanism (budget initially assigned to each task) and a budget augmentation policy (budget inflated at return from pre-emption). This combination ensures that the temporal-isolation property is always 106
5.4. PROPOSED BUDGET DONATION FRAMEWORK 00 00 00 11 11 11 00 00 00 11 11 11 0 0 0 1 1 1 τ1 τ2 t τ1 τ2 t T1T1 Figure 5.3: Excessive Pre-emption Delay Due to Minimum Interarrival Time Violation met as long as none of the tasks violates its minimum inter-arrival constraint, i.e., as long as none of them release two consecutive jobs in a time interval shorter than its pre-defined period Ti. This condition of not violating the minimum inter-arrival constraint is implicitly assumed by Equations (5.5) and (5.6), in which the upper-bound on the pre-emption delay interference inherently relies on the number of jobs released by every task in a given time window. If any task violates its minimum inter-arrival time constraint, the temporal-isolation property no longer holds. An example of this is depicted in Figure 5.3. On the left-hand side of the picture, task τ1releases a single job in a time interval of length T1. This job executes for C1time units and task τ2suffers only from one pre-emption, leading to an increase of δ1,2on its execution requirement. In the right-hand side of the picture, τ1releases more than one job in the same time interval of length T1and τ2now suffers from 2 pre-emptions, leading to an increase of 2×δ1,2on its execution requirement. In the latter scenario, task τ2augments its budget accordingly but may face a deadline miss, or a lower priority tasks may be subject to more interference than what was accounted for in the schedulability test. In order to avoid this issue, a second server Yiis associated to each task τi. This server Yihas parameters hZi,TY ii–Ziis the budget and TY iis the replenishment period. Unlike the server Si, the budget Ziis not consumed while τiis running. The purpose of this second server Yiis to “pay” for the damage caused by τiin the system when τipre-empts another task. That is, each task τj, when it is pre-empted by τi, obtains a budget donations by transferring some execution budget from the server Yito its execution budget Bj. These budgets Yiimpose a new condition to their associated task τiin order to accommodate for the minimum inter-arrival misbehaviour: task τiis allowed to pre-empt only if there is sufficient budget in Yi. In this way the pre-emption delay that τimay cause in the schedule is tightly monitored. The replenishment condition for server Yiis defined as follows: Server Yireplenishment rule: At a time instant t0, when task τipre-empts some lower 107
5.4. PROPOSED BUDGET DONATION FRAMEWORK priority workload, a replenishment event is set for Yito occur at time instant t0+TY i. The amount of budget replenished to serverYiat the t0+TY ievent is equal to the quantity reserved to pay the maximum pre-emption delay penalty associated to a single pre-emption. This replenishment mechanism is in accordance with the sporadic server replenishment rules [SSL89] and hence the server Yiis a sporadic server. These two parameters Ziand TY iare set by the system designer and the question of how to define them will be discussed later. For now, bear in mind that these two parameters are given for each task τi∈T. The purpose of each server Yiis to ensure that new jobs of a task τican only be released as long as the maximum pre-emption delay that τican induce in the schedule (according to the schedulability test) is available in Yi. To effectively implement this solution, the budget augmentation mechanism presented in the previous section is reformulated as a budget transfer mechanism. The main concept remains simple: 1. To release a new job (say at time t), a task τjis required to have at least Pmax jtime units in its budget Zj(t). This quantity Pmax jis the maximum delay that τjcan cause on the lower priority tasks by pre-empting them. It is straightforwardly defined as Pmax j def = n ∑ k=j+1 δj,k(5.18) If Zi(t)<Pmax jthen τjis not authorized to release a new job at time tand must wait until the earliest time instant t0>twhen Zj(t0)⩾Pmax j. 2. Unlike the budget augmentation protocol proposed in the previous section, each time a task τiresumes its execution (say at time t) after being pre-empted (let H(i)denote the set of tasks that pre-empted τi), τidoes not experience its execution budget Bi(t) being simply augmented by ∑τj∈H(i)δj,itime units, with ∑τj∈H(i)δj,icoming from thin air. Instead, δj,i(t)time units are transferred from the budget Zj(t)of each task τj∈H(i)to its execution budget Bi(t). It is important to stress that this framework is explained by considering two distinct servers to ease explanation and to allow for more flexibility in order to have different replenishment periods for the execution and pre-emption delay donation server. Nevertheless, if there is not sufficient budget in the pre-emption compensation server and there is sufficient budget on the execution server then the required budget on the execution server has to be transferred to the pre-emption delay server. This prevents the generation of unwanted blocking scenarios. Informally speaking, the underlying concept behind this budget transfer protocol can be summarized as follows: “a task τiis allowed to pre-empt only if it can pay for the maximum 108
5.4. PROPOSED BUDGET DONATION FRAMEWORK damage that it may cause to all the tasks that it may pre-empt”. If the task τican pay the required amount of time units, i.e., τihas a provably sufficient amount of time units saved in its budget Zi(t), then it can release its new job and the pre-empted tasks will claim their due pre-emption delay compensation when they will eventually resume their execution. This simple concept makes the framework safe. Rather than a formal proof, a set of arguments to substantiate the claim is provided. Suppose that a task τistarts misbehaving by frenetically releasing jobs that execute for an arbitrarily short time; hence clearly violating its minimum inter-arrival constraint. 1. From the point of view of a higher priority task (say, τj): each job of τjcan pre-empt at most one job from τiand before releasing each of its jobs, τjmakes sure that there is enough provision in its budget Yjto compensate for the damage caused to the lower priority tasks, including τi. 2. From the point of view of the misbehaving task τi: this task will keep on generating jobs until its budget Zi(t)is depleted. For each job released, the framework ensures that the job can actually pay for the damage caused to the lower priority tasks. Regarding the higher priority tasks, each job of τimay be pre-empted and request some extra time units upon resumption of its execution. However, this extra budget requested has been accounted for when the higher priority jobs were allowed to be released – as mentioned in 1). 3. From the point of view of a lower priority task (say, τk): each job of τkmay be preempted multiple times by the abnormal job release pattern of τi. However, upon each resumption of execution, τkwill be compensated for the delay incurred by receiving some extra time units from the budget Zi(t)of the misbehaving task – as guaranteed in 2). As seen, the sole purpose of each serverYi,∀i∈[1,n]is to control the pre-emption delay that the task τiinduces on the schedule. Since the upper-bound on the pre-emption delay related interference is now dictated by these servers, Schedulability Test 2presented in the previous section can be rewritten as: Schedulability Test 3. A task set Tis schedulable if, ∀τi∈T,∃t∈(0,Di]such that Ci+delay(t) + i−1 ∑ j=1 [rbf(Sj,t)+rbf(Yj,t)] ⩽t(5.19) Correctness of Schedulability Test 3.The replenishment mechanism of server Yiis in accordance with the sporadic server replenishment rules. As a consequence of this fact and according to the Theorem 12 the maximum amount of budget consumed in any interval of 109
5.5. LIMITING THE PRE-EMPTION INDUCED BUDGET AUGMENTATION FOR MISBEHAVING TASKS length TY iis Zi. This means that rbf(Yj,t)is an upper-bound on the budget used for execution by any task that was pre-empted by task τjand got the due compensation in any interval of length t. By this reasoning and the correctness of schedulability tests 1and 2the correctness of this schedulability test is thus proven. The choice of the parameters of each Yjserver is left at the criteria of the system designer. However, in a given period Tiany task τiwill require at least the execution of one job. As a consequence the budget Ziof Yimust necessarily be greater than or equal to Pmax i. The simpler approach would be to define each server Yias hZi=Pmax i,TY i=Tiias Yiwould have enough budget to compensate for all the interference that τimay cause in the schedule, assuming that the minimum inter-arrival constraint is not violated. However, the system designer may prefer TY i>TS ito provide more flexibility in case the task τiis expected to violate its minimum inter-arrival constraint, or even to accommodate intended bursty arrival of requests. As a last note it is important to state the advantage of this framework with respect to a simple mechanism imposing a limitation on the number of jobs a task may release in a given time window. With this framework the number of jobs that a task may release without breaking the temporal-isolation guarantees is variable (and always greater than the worstcase that had to be considered if a static number of jobs had to be enforced) since this depends on the number of lower priority jobs that it has actually pre-empted so far. This allows for a more dynamic system with overall better responsiveness. 5.5 Limiting the Pre-emption Induced Budget Augmentation for Misbehaving Tasks Suppose that a task τimisbehaves by violating its minimum inter-arrival constraint, i.e., it releases more than one job in a time interval <Ti, and one of its jobs gets pre-empted by a higher priority task, it is meaningful to consider whether task τishould get a preemption delay compensation when it will eventually resume its execution. In fact, it might be preferable not to transfer extra time units to its budget Biuntil it returns to a state where it is respecting its contract parameters. For this choice of design, Schedulability Test 3becomes: Schedulability Test 4. A task set Tis schedulable if, ∀τi∈T,∃t∈[0,Di]such that Ci+delay(t) + i−1 ∑ j=1 rbf(Sj,t)+ i−1 ∑ j=1 min rbf(Yj,t), q0j,i(t) ∑ `=1 ` max(Mj,i(t)) ⩽t 110
5.6. IMPLEMENTATION ISSUES 00 00 00 11 11 11 0 0 1 1 00 00 11 11 t τ4 τ3 τ2 τ1 t Z1 H1 δ2,4 t δ1,4+δ3,4 B4 Pmax 1=P4 k=2 δ1,k δ1,3 δ1,4 Figure 5.4: Budget Augmentation Example where q0j,i(t)def = i−1 ∑ k=j nk(t) since the tasks are not eligible for pre-emption delay compensation when they don not meet the minimum interarrival requirements, the maximum pre-emption delay related interference in the schedule is still upper-bounded by the analysis presented in Equation (5.5). 5.6 Implementation Issues An efficient implementation is key for a useful approach to server-based scheduling. The general principle pursued is that the pre-emption delay repayment budget is only granted when an actual pre-emption occurs and is only transferred on resumption of execution. 111
5.6. IMPLEMENTATION ISSUES δ1,2δ1,3δ1,n δ2,3δn−1,n Figure 5.5: Pre-emption Delay Compensation Array As a first step the pre-emption delay repayment budget values δi,jare arranged in a linear pre-emption delay array (Figure 5.5). A second data structure employed to assist on the management of the temporal isolation framework is termed the pre-emption queue. This queue trivially maintains a depiction of the pre-emption order. When a task is first dispatched to execute upon the processor and hence pre-empts a previously running task then this task is inserted into the pre-emption queue. When a task terminates its execution it is removed from the queue. As a third element, each task τi’s control block has two bitfields (outb f (τi)and inb f (τi)) of length n. The “in” bitfield contains the information about which tasks have to compensate τiand the “out” bitfield conserve the information about the tasks which have to compensate tasks which were pre-empted by τi. The mechanism utilizing this information is described in Algorithm 8. At the moment of job release from τi, the “out” bitfield is initialized with only the bit relative to τiset (i.e. outb f (τi) = 0x1<< (i−1)). When a job τjterminates its execution at time t, it holds true that τjis the head of the preemption queue. At this time instant the task immediately preceding τjin the pre-emption queue (τi) has its “in” bitfield assigned in the following way: inb f (τi) = inb f (τi)∨outb f (τj). Scheduling decisions are only taken after this procedure terminates. After this operation it is not necessarily true that τiwill become the head of the pre-emption queue and execute on the processor. When a job from τiresumes execution, after a pre-emption, the scheduler examines the “in” bitfield inb f (τi). The “in” bitfield holds the information on which tasks have preempted τisince the last time instant at which it was executing. The budget from server Si is then accordingly augmented. If the considered framework is the one ensuring temporalisolation with respect to minimum inter-arrival time misbehaving the corresponding preemption delay donations are deduced from the pre-emption delay donation servers of the tasks which have pre-empted τi. After the budget of the task is duly augmented, the “out” bitfield is logically ORed with the “in” bitfield (i.e. outb f (τi) = inb f (τi)∨outb f (τj). Immediately after this step the “in” bitfield is reset (inb f (τi) =0x0). These three procedures need to be carried out atomically. Let us use a different schedule example to better visualize the bitfield related operations. In Figure 5.6 an example of the bit-field evolution as a response to a given set of events is presented. There are 9 events present. When a task has no active job in the system its bit 112
5.7. EXAMPLE OF FRAMEWORK USAGE WITH CRPD 0001 0010 0100 1000 0000 0010 0100 1000 0000 0000 0100 1000 0000 0000 0110 1000 0001 0000 0110 1000 0000 0010 0111 1000 0000 0000 0111 1000 0000 0000 0000 1111 0000 0000 0000 1000 outbf (τ1) outbf (τ2) outbf (τ3) outbf (τ4) τ4 τ3 τ2 τ1 t t2t3t4t5t6t7t8t9 t1 inbf (τ3) = 0001 inbf (τ2) = 0000 Figure 5.6: Bit Field Snapshots of Relevance field is by default 0. At events 1–3, tasks τ1to τ3release jobs, consequently their bit fields are set to their respective index. At time t4, the first job of task τ2finishes its execution. At this time instant, and since τ2is the prior pre-emption queue head and τ3is the task after the queue head, the bit field from task the inb f (τ3) = inb f (τ3)∨outb f (τ2). After this operation is performed inb f (τ2) = 0. At t5and t6jobs from τ1and τ2are released correspondingly. At each event the corresponding bitfield is set accordingly. The job from task τ1terminates at t7. At this time instant, the “out” bitfield of task τ1is passed onto the subsequent task in the pre-emption queue (τ3). Hence inb f (τ3) = inb f (τ3)∨outb f (τ1)Since τ2was not in the ready queue the “out” bitfield from τ1does not get passed to its “in” bitfield. The algorithm describing the bitfield inspection and budget augmentation is presented in Algorithm 8. Notice that in the scenario where minimum inter-arrival times cannot be relied upon, after the budget is augmented (line 6), the same value has to be decreased from the Yindex server of the pre-empting task. In the same framework it is then necessary to set up a replenishment event for server Yindex,Tindex units after the execution resumption (line 7). At this replenishment event Zindex is set to be replenished by δ[array_index]units. The variable offsetiis an offset with respect to the base of the δarray, where the first element pre-emption delay compensation value (δ1,i) from task τiis stored (Figure 5.5). 5.7 Example of Framework Usage with CRPD The previously described theory may be exploited in order to ensure temporal-isolation with respect to any subsystem holding state concurrently accessed by tasks in the system. In this 113
5.7. EXAMPLE OF FRAMEWORK USAGE WITH CRPD Algorithm 8: Pre-emption Delay Augmentation Algorithm τiexecution resumption after pre-emption: index =0; while index <ido if inb f (τi)&0x1 then array_index =offseti+index; Bi+ = δ[array_index]; Yindex−=δ[array_index]; Set_replenishment_event(τindex,δ[array_index]) inb f (τi) = inb f (τi)>> 1; index ++; inb f (τi) = 0x0 section a description on how temporal-isolation is ensured, when caches are present in the execution platform by usage of the presented framework, is provided. At each program point a task has a set of useful memory blocks (UCB) in cache. These memory blocks were loaded into the cache at some prior program point and will be reused in the future. Each program point pof task τkhas an associated UCB set denoted as UCBp k[AB09]. Additionally, the set of cache lines accessed during the execution of task τj (ECBj) [AB09] may be constructed. The maximum CRPD which a pre-emption by task τjmay induce in task τkis then defined as [AB09]: δj,k def =BRT ×max pnUCBp k\ECBjo(5.20) BRT is a constant, denoting the worst case latency for a cache miss to be served. 5.7.1 Temporal-isolation Assumptions In order to ensure full temporal-isolation with the used pre-emption delay estimation mechanisms, when using information from the pre-empting tasks to compute the δj,i, it is mandatory to ensure that the ECB sets of each pre-empting task are met at run-time, as it is assumed that a task can execute for longer than expected, which implies that it might in turn also use a larger cache footprint. Both instruction and data cache footprints have to be relied upon. In order to ensure the worst-case cache footprint, it suffices to ensure that each task only accesses the basic blocks assumed in the static analysis. This can be easily achieved with the work by Martín Abadi et al. [ABEL09], where each jump instruction is guarded against jumps into illegal memory locations. Since at run-time, all the possible basic blocks accessed are the exact same as the ones assumed in the static analysis the instruction cache ECB set is never violated. When 114
5.7. EXAMPLE OF FRAMEWORK USAGE WITH CRPD using [ABEL09], all the jump targets in the code are statically defined, i.e. jump to function pointers in the code are not allowed. In the case of data caches, since the basic blocks accessed at run-time are enforced, it is sufficient to ensure that no dynamic memory is used, which is generally the case in real-time workload. Another assumption is that any access to an array is guarded against accesses outside of the array bounds. As a last assumption, recursive calls are forbidden in order to ensure that the stack footprint is known offline. If the ECB set of any task cannot be relied upon, it is always safe to consider that the maximum pre-emption delay induced in task τkwhen pre-empted by any task τjis the time to reload the entire UCBkset: ∀j:δj,k=BRT ×|UCBk|.(5.21) 5.7.2 Experimental Results In order to assess the validity of the contribution a set of experiments was conducted. The schedulability guarantees from the proposed framework is trialled against the scenario where the maximum pre-emption delay is integrated into the budget of the execution server. Results for the same task sets are also displayed for a schedulability test oblivious of preemption delay. As in previous chapters, all tasks are generated using the unbiased task set generator method presented by Bini (UUniFast) [BB04a]. Task systems are generated for every utilization step in the set {0.75,0.8,0.85,0.9,0.95} in a random fashion, their maximum execution requirements (Ci) were uniformly distributed in the interval [20,400]. Knowing Ciand the task utilization Ui,Tiis obtained. At each utilization step 1000 task sets are trialled and checked whether the respective algorithm considers it schedulable. Task set sizes of 4, 8, and 16 tasks have been explored. The relative deadline of tasks is equal to the minimum inter-arrival time (Di=Ti). When each task is randomly generated pre-emption delay cost is obtained for each task pair in the task-set. The cache considered is composed of 10 cache lines. For each task a set of useful cache lines is computed, the usage of each cache line follows a uniform distribution. Similarly for each task a set of cache lines which are accessed during its execution is computed. The cardinality of interception of the useful set of τiwith the accessed set of τjupper-bounds the maximum number of cache lines that τihas to re-fetch has a result of a pre-emption by τj. The servers Sihave been attributed parameters Bi=Ciand TS i=Ti. For the situation where the pre-emption delay server Yjis put to use, its parameters are Zj=∑j<kδj,kand TY j=Tj. The results are depicted in Figures 5.7a to 5.7c. In the plots the scenario where the pre-emption delay is incorporated into the task execution budget is displayed is presented 115
6.1. GLOBAL FIXED TASK PRIORITY RESPONSE TIME ANALYSIS higher priority than τiwould yield an upper-bound on the higher priority workload that would execute in the time interval of length t. Since it is known that in the worst-case some m−1 tasks present carry-in workload at the beginning of the interval, then this additional workload will never exceed the difference between the maximum workload in a no carry-in situation and the carry-in situation. By choosing the m−1 higher priority tasks which for a given interval length display the biggest difference between the no carry-in and carryin situation and by summing these differences over all functions of no carry-in an upperbound on the workload which higher priority tasks may execute in the interval of length tis obtained. In [Bak03] Baker showed that in a multi-core platform composed of midentical cores, a unit of higher priority workload can interfere with the execution of task τiby at most 1 mtime units. Consider that some task τjis executing on one processor during one time unit. By executing on this processor it will not prevent τifrom getting hold of some other processing entity as there exist m−1 others in the platform. In order for τito be prevented from executing, the mprocessors need to be busy. In order for mcores to be busy for one time unit then mtime units of higher priority workload need to execute on the overall platform. Combining (6.4) and this fact enables the statement of the upper-bound on the overall interference a task τiis subject to in a time interval of length t. This is written as: Ii(t) = Ωi(t) m(6.5) When considering the fully pre-emptive global fixed task priority scheduling policy, by exploiting the upper-bound on the interference by higher priority workload, the following sufficient schedulability test is devised: ∀τi∈T,∃t∈[0,Di]:Ii(t)+Ci⩽t(6.6) A task-set is said to be schedulable if for all task τi∈Tthe condition in (6.6) holds. The schedulability test presented in (6.6) is a sufficient test. This means that some task-sets may indeed manage to meet all the deadlines even if for some tasks the condition in (6.6) is not met. Nevertheless if the condition is met for all the tasks in the taskset then the timing requirements of all the tasks are guaranteed to be met at run-time. Similarly to the single processor case this condition need not be tested for all of the values in the continuous interval [0,Di]but rather for a finite number of time instants. Both functions WNC j(t)and WCI j(t)are piecewise linear functions, i.e. they may be defined as a set of linear functions in distinct time intervals. As a consequence of this, the Ωi(t)function itself may be defined as a set of linear functions in distinct time intervals as well. Hence the relation t−Ii(t)is maximized in the [0,Di]interval for some value t∈Γi. The set Γi encloses the Γ0 iset of points where the first derivative of the function Ωi(t)changes in value 122
6.1. GLOBAL FIXED TASK PRIORITY RESPONSE TIME ANALYSIS and the time instant of the deadline Diof τi. The Γ0 i∪{Di}set of points contains the points of interest when trying to maximize the value of t−Ii(t). Let us now focus on the derivation of the set Γicontaining the points where the condition has to be tested. Tj+ 2Cj−Rj Tj Tj+Cj−Rj Tj+Cj 0 0 Tj+Cj−Rj TjTj+Cj Cj 0 Cj 2Cj 0 2Cj Cj Cj WNC(τj, t) WCI(τj, t) Tj+ 2Cj−Rj Wdiff(τj, t)Wdiff(τj, t) Figure 6.2: Functions Wdiff(τj,t)depiction for two distinct relations between Cjand Rj The difference between Ωi(t)and the supply line is maximized at some points where the Ωi(t)first derivative changes value. The Ωi(t)function has increases in its first derivative at specific points which are related to scenarios here described. Since the Ωi(t)function is a sum of two functions for each higher priority task, the changes in the Ωi(t)function first derivative can only occur at any twhere either the first derivative of Wdiff(τh,t)or WNC(τh,t)changes or if both change. 1. first derivative increase of WNC(τj,t): occurs at every k×Tj(this can be observed in Figure 6.1) Γ1 i def =[ j∈{1,···,i−1}k×Tj|k∈N,0⩽k⩽t Tj 2. first derivative increase of Wdiff(τj,t): occurs at every k×Tj+Cj−Rj(this can be observed in figures 6.1 and 6.2) 123
6.1. GLOBAL FIXED TASK PRIORITY RESPONSE TIME ANALYSIS 3c 0 Cj Wdiff (τj, t) MDlMDk 3a 3b Figure 6.3: Intersection Points Between theWdiff(τj,t)Functions of Distinct Higher Priority Tasks Γ2 i def =[ j∈{1,···,i−1}k×Tj+Cj−Rj|k∈N,0⩽k⩽t+Rj−Cj Tj(6.7) 3. When there is a change in the set of m−1Wdiff(τj,t)functions with greatest value. Three distinct situations have to be considered. These distinct typology of occurrences can be observed in Figure 6.3 where the three situations are marked accordingly: (a) When “upward segment” of one Wdiff(τj,t)“intersects a plateau” of another Wdiff(τk,t)function (b) When “downward segment” of one Wdiff(τj,t)“intersects a plateau” of another Wdiff(τk,t)function (c) When “upward segment” of one Wdiff(τj,t)“intersects” with a “downward segment” of another Wdiff(τk,t)function Let us define the following variable MDj=min{Cj,Rj−Cj}which represents the maximum value of the function Wdiff(τj,t)for any time instant t. The upward segments of Wdiff(τj,t)start at every k×Tj+Cj−Rjand terminate at k×Tj+Cj−Rj+MDj. Whereas a downward segment starts at every k×Tj+Cj−MDjand terminate at k×Tj+Cj. In a time window of length t, a task τjhas at most Kj=jt+Rj−Cj Tjkupward segments of function Wdiff(τj,t)since for each k⩽t−Cj+Rj Tjone upward segment starts inside the time interval of length t. For the case 3a it suffices to check for each k⩽Kj,k×Tj+Cj−Rj+ max(MDh,MDj)and for each remainder higher priority task τh. Only MDhunits after its beginning can an upward segment of task τjintersect a plateau of another task τh. In case the maximum value of Wdiff(τh,t)is greater than the maximum value of Wdiff(τj,t)then an 124
6.1. GLOBAL FIXED TASK PRIORITY RESPONSE TIME ANALYSIS upward segment from τkwill never intersect the plateau of τh. Γ3a i def =[ j∈{1,···,i−1}[ h∈{1,···,i−1}\ jk×Tj+Cj−Rj+max(MDh,MDj)|k∈N,0⩽k⩽Kj (6.8) In a time window of length t, a task τjhas at most Lj=jt−Cj+MDj Tjkdownward segments of function Wdiff(τl,t)since for any l⩽t−Cj+MDj Tja downward segment of τjstarts in a time interval of length t. For the case 3b it is enough to check the condition for all l⩽Lj, l×Tj−Cj−max(MDh,MDj)and for each remainder higher priority task τh. If a downward segment from task τjintersects a plateau from task τhthen the intersection occurs at l×Tj+ Cj−MDh, i.e. MDhtime units before the downward segment from τjends. If the plateau of τhis greater than the plateau from τjthis intersection never occurs. Γ3b i def =[ j∈{1,···,i−1}[ h∈{1,···,i−1}\ jl×Tj+Cj−max(MDh,MDj)|l∈N,0⩽l⩽Lj(6.9) The third case 3c proves slightly more complex. For each of the Kjdownward segments from τj, the possible upward segments of task τhwith which it intersects need to be found. An intersection between an upward segment from τhand a downward segment from τj occurs at midpoint between the start of the upward segment and the end of the downward segment. Again, a downward segment from τjterminates at k×Tj+Cj. This downward segment can only intersect with the upward segment from τhwhich started before time instant k×Tj+Cj. The later upward segment from τhthen starts at time instant k×Tj+Cj−Ch+Rh Th×Th+Ch−Rh(6.10) The set Γ3c iis then defined as: Γ3c i def =[ j∈{1,···,i−1}[ j∈{1,···,i−1}\ j jk×Tj+Cj−Ch+Rh Thk×Th+Ch−Rh+k×Tj+Cj 2|k∈N,0⩽k⩽Kj (6.11) The set Γiis finally constructed by applying the union set operation over all the previously described sets: Γi def =Γ1 i∪Γ2 i∪Γ3a i∪Γ3b i∪Γ3c i∪{Di}(6.12) 125
6.2. GFTP LIMITED PRE-EMPTIVE SCHEDULING POLICIES When the schedulability condition is tested over a discrete set of points the response time computation can still be efficiently carried out: t1=min{t∈Γi|Ii(t)+Ci⩽t}(6.13) t2=max{t∈Γi|t<t1}(6.14) RUB i=t1+Ii(t1) +Ci−t1 1−Ii(t2)−Ii(t1) t2−t1 (6.15) The quantity RUB i∈(t2,t1]is the intersection between the line segment I(t) = I(t1)−I(t2) t1−t2×t+I(t1)−I(t1)−I(t2) t1−t2×t1(6.16) defined ∀t∈(t2,t1]and the supply line f(t) = t. The formulation of the sufficient schedulability condition presented in this work is equivalent to the one in [GSYY09]. 6.2 GFTP Limited Pre-emptive Scheduling Policies In a multi-core platform global fixed task priority fully pre-emptive scheduling discipline may be informally described as a policy where at any time tthe mhighest priority tasks with available workload execute on the mprocessors comprising the platform. When tasks are composed of both pre-emptible and non-pre-emptible workload then more complex protocols may be devised reflecting the more complex nature of the workload. In this work two scheduling policies are considered: 1. Regular Deferred Scheduling (RDS): At any point in time, the pre-emptible jobs executing on any processor are eligible for being pre-empted by a higher priority job; 2. Adapted Deferred Scheduling (ADS): At any point in time a pre-emption can only occur if the lowest priority running job is pre-emptible, in which case the lowest priority running job is pre-empted from the processor on which it runs and the highest priority waiting job is dispatched onto the same processor. Bear in mind that these are only two generalisations of the regular fully pre-emptive scheduling discipline. The RDS policy is the straightforward derivation of the fully preemptive scheduler whereas the ADS is an adaptation which enables some interesting properties with respect to lower priority interference to be achieved. In the RDS policy, a higher priority job from τimight suffer interference from lower priority non-pre-emptive regions more than once after τihas commenced execution. A situation where said priority inversion occurs after the start of τiexecution may be observed 126
6.2. GFTP LIMITED PRE-EMPTIVE SCHEDULING POLICIES t π2 π1 π2 π1 τi RDS Schedule τi HP release ADS Schedule HP release HP LP HPLP t Figure 6.4: Possible Priority Inversion After a Job From τiCommences Execution in RDS in the top schedule displayed in Figure 6.4. In Figure 6.4 the crosses represent fixed preemption points. The bottom schedule in the same picture displays the ADS schedule for the specific workload pattern. In this case, before τiis pre-empted, all other lower priority workload has to be pre-empted first from the platform. A task can only be pre-empted if it is the task currently running upon some processor such that it has the lowest priority among all tasks currently executing in the system. Once a task starts to execute its last non-pre-emptive region it ceases to suffer interference, as a consequence it is only subject to interference during the execution of the first Ci−Qiunits of workload. The schedulability test then becomes: ∃t∈[0,Di−Qi]:t−1 m× WAdi f f i(t) + ∑ τj∈hp(i) WNC j(t) +ANC i(t)!−(Ci−Qi)>0 (6.17) The corresponding upper-bound on the response time of a given task τican thus be computed as: RUB i=min(t|t−1 m× WAdi f f i(t) + ∑ τj∈hp(i) WNC j(t) +ANC i(t)!−(Ci−Qi)>0)+Qi (6.18) 127
6.3. RDS LOWER PRIORITY INTERFERENCE Similarly to the fully pre-emptive scenario, the term ∑τj∈hp(i)WNC j(t)upper-bounds the maximum interference that higher priority workload may induce on τiwhen no higher priority carry-in exists. The ANC i(t)function characterizes the maximum amount of interference due to lower priority workload released inside the interval of interest, which may exhibit non-pre-emptive regions and hence prevent higher priority workload from executing on the processors. The function WAdi f f i(t)encapsulates the maximum interference contribution from carry-in workload. This is workload which was released before or immediately before the beginning of the interval of interest and which will be executed inside the interval of interest. Similarly to the fully pre-emptive GFTP sufficient test [GSYY09], where only m−1 higher priority tasks with carry-in workload are considered, in the limited pre-emptive scheduling policies at most m−1 higher priority tasks are considered to have carry-in (although the worst-case response time of higher priority tasks may be higher in the limited pre-emptive scenario ). In the case of non-pre-emptive regions there might exist at most mlower priority tasks which were executing immediately before the start of the interval of interest. If some core is executing lower priority workload then this implies that this core cannot be executing higher priority carry-in in the beginning of the interval of interest. As a consequence then, if there are klower priority tasks executing non-pre-emptively in the beginning of the interval of interest, then there can be at most m−khigher priority tasks with carry-in. The maximum additional workload due to the klower or equal priority tasks executing in the beginning of the interval of interest is denoted by Ak i. The computation of an upper-bound of Ak igiven a set of lower or equal priority non-pre-emptive regions is the subject of the subsequent sections. The WAdi f f i(t)function is defined as follows: WAdi f f i(t)def =max k∈{1,···,m}(Ak i+ m−k ∑ l=1 ` max τh∈τ1,···,τi−1 Wdiff(τh,t))(6.19) 6.3 RDS Lower Priority Interference The RDS policy’s sufficient schedulability test was previously published in [DBM+13]. In the RDS policy the function ANC i(t)can be constructed by considering that each non-pre- emptive region of any task with priority lower than τimay indeed interfere with τiexecution. A lower priority non-pre-emptive region, from task τ`, may commence immediately before the release of a higher priority task τj. If task τihappens to be executing pre-emptively or if it happens that the release of τjcoincides with a pre-emption point, τiis pre-empted by τj. In this case τiis indeed being interfered by τ`which is of lower priority. This situation can occur for any non-pre-emptive region of a lower priority task. Hence an upper-bound on the 128
6.4. ADS LOWER PRIORITY INTERFERENCE interference by lower priority workload can be written by resorting to Equation (6.20) and Equation (6.21). ANC i(t) = n ∑ j=i+1max(t−Cj,0) Tj×Cvj+min[[t−Cvj]0mod Tj−(Tj−Rj)]0,Cvj(6.20) Ak i(t) = n ∑ j=i Cvj(6.21) In equations (6.20) and (6.21) the the quantity Cvjis equal to the maximum amount of time that jobs from task τjexecute non-pre-emptively. Equation (6.21) models the non-pre-emptive workload that might be released prior to the interval of interest and execute inside it. In turn the Equation (6.20) models the non-pre- emptive lower priority workload which can be released inside the interval of interest and execute inside the same interval. In order to evaluate the schedulability increase obtained with RDS only a single last non-pre-emptive region is considered per task. Considering multiple last non-pre-emptive regions would virtually not aid on increasing the schedulability since only the last region manages to postpone effectively interfering workload and having more than one non-pre- emptive region would lead to a heavier share of lower priority workload being considered as interfering with the higher priority tasks. 6.4 ADS Lower Priority Interference In the ADS policy ANC i(t) = 0. Lower priority tasks may execute on other processors while τiis executing, but higher priority workload will only be able to pre-empt τiwhen τiis the lowest priority task executing on any processor. As a consequence of this, lower priority workload can only interfere with τiexecution if they are currently executing once τiis released. This is the key difference between ADS and regular fixed priority scheduling with deferred pre-emption (RDS). Contrary to the single processor limited pre-emptive theory, where multiple jobs from τiin a level −ibusy period need to be checked for the temporal correctness, this is not the case in the presented schedulability condition ((6.17)). As a consequence, when m=1 the analysis provided is still safe albeit pessimistic as the provided test is sufficient but not necessary, whereas the test available in the literature for single processor is both necessary and sufficient [BLV07b,BLV09]. 129
6.5. FIXED TASK PRIORITY LIMITED PRE-EMPTIVE SCHEDULABILITY TEST Theorem 13 (Correctness of the Schedulability Condition (6.17)).Let us assume that the term Ak i(t), in (6.19), gives an upper-bound on the workload generated by all the jobs from tasks with priority lower than or equal to i, released before time t and executed nonpre-emptively on k processors (the upper-bound computation is the subject of later sect). If (6.17)is satisfied for all task τithen the task-set is schedulable. Proof. For a given k∈[1,m], the equation in the brackets of (6.19) gives an upper-bound on the carry-in workload at time t, where (i) k processors execute non-pre-emptive workload coming from k lower or equal priority jobs released before time t, and (ii) m−kprocessors execute pre-emptive workload coming from m−khigher priority jobs released before time t. Therefore, WAdi f f i(t)as defined in Equation (6.19), which takes the max for all k, is an upper-bound on the carry-in workload at time t. From the definitions of WNC j(t)and since ANC i(t) = 0, it holds for a given time-instant tthat the sum WADIFF i(t) + ∑τj∈hp(i)WNC j(t) gives an upper-bound on the total workload at time t(including both carry-in and non carryin workload from lower- and higher-priority tasks). The correctness of the condition given by Inequality (6.17) immediately follows from the meaning of this sum, i.e., if the condition is satisfied for a given t, then it means that any job from task τiwill always be able to execute for at least Ci−Qi+εtime units within Di−Qitime units from its release. Given that every job of τiwill get the highest priority after executing for Ci−Qi+εtime units, it implies that all jobs of τiwill have to execute its (at most) Qiremaining time units within the last Qitime units to their respective deadline, which they will always do. In order to assess the schedulability of τiit is important to quantify Ak iwhere k∈ {1,··· ,m}. The derivation of upper-bounds for Ak iis the subject of the subsequent section. 6.5 Fixed Task Priority Limited Pre-emptive Schedulability Test Having a characterization of the lower priority interference that each higher priority task is subject to, enables the derivation of a sufficient schedulability condition. The task-set is deemed schedulable for a given set of last non-pre-emptive region for all the task τi∈Tif: ∀τi∈T,∀k∈ {1,··· ,m},βk i(Qi)⩾Ak i(6.22) where βk i(Qi)def =max t∈[0,Di−Qi]m×t−∑ τj∈hp(i) WNC j(t)−m×(Ci−Qi)− m−k ∑ l=1 ` max τh∈τ1,···,τi−1 Wdiff(τh,t) (6.23) 130
6.6. MAXIMUM INTERFERENCE FROM LOWER OR EQUAL PRIORITY NON-PRE-EMPTIVE REGIONS IN ADS The computation of the Function (6.23) can be performed by analyzing the limited set of time instants Γidescribed previously. Fk i(t) = max {t0∈Γi∪{t}|t0⩽t}m×t0−∑ τj∈hp(i) WNC j(t0)−m×Ci− m−k ∑ l=1 ` max τh∈τ1,···,τi−1 Wdiff(τh,t0) (6.24) Equation (6.23) may then be rewritten as: βk i(Qi) = Fk i(Di−Qi)+Qi×m(6.25) 6.6 Maximum Interference from Lower or Equal Priority Non- Pre-emptive Regions in ADS τl τa τd τs ⩽Ca ⩽Cs ⩽Cd m cores Figure 6.5: Maximum Interference Function Due to mNon-pre-emptive Regions of Lower or Equal Priority Tasks The ADS scheduling policy considered in this section dictates that a task can only be dispatched to run on one of the mcores, at a time instant t, when either a core is idle or a pre-emption point of the lowest priority task running on any mprocessors has been reached. The task which is pre-empted is then the lowest priority task running on any of the cores at time t. The worst-case interference pattern generated by the lower or equal priority non-pre- emptive region execution is represented in Figure 6.5 for a platform where m=4. In Figure 6.5 the crosses represent fixed pre-emption points. In a scenario where mprocessors are executing lower or equal priority workload and several higher priority releases 131