09/04/2018 What is a model? A model is a representation of something. It captures not all attributes of the represented thing, but rather only those that are relevant for a specific purpose. “ Confusing a model with reality would be like going to a restaurant and eat the menu ” like going to a restaurant and eat the menu Golomb’s Law on mathematical models 2 What is a good model? Important aspects It should be expressive (an accurate representation of reality) Building a model implies: It should be tractable (provide results in a bounded time) simplifying reality (but not too much), capturing the features of interest; Unfortunately, expressiveness and tractability do not get along very well defining the variables that characterize the model. Untractability (complexity) Untractability (complexity) defining the system interface (variables exposed to the user); Useless models (too complex to clearly identifying the assumptions (affecting values); GOOD be analyzed) Useless models MODEL defining the metrics for evaluating the outputs of your (too far from reality) system and its performance. expressiveness 3 4 Types of variables Example Parameters (variables you don’t want to change); Input variables (commands given by the user/controller) Design variables (variables you want to identify to apply your control actions); your control actions); Parameters: Parameters: Pole length/mass, cart mass P l l th/ t State variables (variables describing the system state Input variables: Force applied to the cart and behavior); Design variables: Control parameters (K P , K I , K D ) Output variables (variables you want to measure to State variables: evaluate the performance of your method). Position/speed of the cart and pole Output variables: Pole angle 5 1
09/04/2018 Elements of computation Elements of computation Instruction : Function : a It is the elementary entity of a programming language. It is a container for a set of instructions. y It may take multiple input arguments b and produces a single output. Examples in ASM X86: MOV AX, 5; MOV BX MOV BX, 7; 7; ADD AX, BX; A function can call other functions: Examples in C: int x; x = a + b; if (x > threshold) y = 1; else y = 0; 7 8 Elements of computation Elements of computation Task : Application : It is a function performing a given computational activity in a It consists of a set of tasks interacting through a set of system (e.g., sensory processing, motor control, filtering). shared resources: It is the elementary entity managed by an operating system. R1 R1 It may have specific constraints (e g It may have specific constraints (e.g., activation time, activation time R2 R2 R3 period, deadline, precedence relations with other tasks). 1 2 It can communicate with other tasks by shared resources. Resource : It is a set of variables that can be used by tasks to store data or temporary results: 9 10 Task execution Task important variables The execution of a task on a processor is C i represented by a bar on a timeline. t a i s i f i Activation Task i Task i C i time (a i ) R i computation time computation time Start time (s i ) The interval f i a i t is referred to as the task response time R i Computation time (C i ) here the processor is idle Finishing time (f i ) 2
09/04/2018 RTOS responsibilities Ready queue A real-time operating system is responsible for: In a concurrent system, more tasks can be simultaneously active, but only one can be in execution (running). Managing concurrency; An active task that is not in execution is said to be ready. Activating periodic tasks at the beginning of each Ready tasks are kept in a ready queue, managed by a p period (time management); ( g ) scheduling policy. h d l l Deciding the execution order of tasks (scheduling); The processor is assigned to the first task in the queue through a dispatching operation. Solving possible timing conflicts during the access of shared resources (mutual exclusion); Ready queue activation dispatching termination Manage the timely execution of asynchronous 3 2 1 CPU events (interrupt handling). Preemption Schedule It is a kernel mechanism that allows to suspend the Is a particular assignement of tasks to the processor that execution of the running task in favor of a more important determines the task execution sequence: task. The suspended task goes back in the ready queue. Formally, given a task set = { 1 , ..., n }, a schedule is a function : R + N that associates an integer k to each Ready queue activation dispatching termination 3 2 1 interval of time [t, t+1) with the following meaning: i l f i [ 1) i h h f ll i i CPU preemption k = 0 in [t, t+1) the processor is IDLE Preemption enhances concurrency and allows reducing the response times of high priority tasks. in [t, t+1) the processor executes k k > 0 It can be disabled (completely or temporarily) to ensure the consistency of certain critical operations. Schedule Preemptive schedule priority 1 2 3 1 idle idle (t) 2 3 3 2 3 1 0 2 4 6 8 10 12 14 16 18 20 0 t 1 t 2 t 3 t 4 t (t) Each interval [t i , t i+1 ) is called a time slice . 3 2 In time instants t 1 , t 2 , t 3 , t 4 the processor is said to 1 0 perform a context switch . 0 2 4 6 8 10 12 14 16 18 20 3
09/04/2018 Task states Task states priority running 1 BLOCKED signal wait running running 2 ready running running 3 ready dispatching p g 3 0 2 4 6 8 10 12 14 16 18 20 activation termination READY RUNNING (t) preemption 3 2 1 ACTIVE 0 0 2 4 6 8 10 12 14 16 18 20 Real-Time Task Slack and Lateness It is a task characterized by a timing constraint on its D i response time, called deadline: i relative deadline D i t a i s i f i d i i R i R slack = d slack i = d i - f i f t a i s i f i d i D i lateness L i = f i - d i absolute deadline response time R i ( d i = a i + D i ) i t A real ‐ time task i is said to be feasible if it guaranteed to a i s i d i f i complete within its deadline, that is, if f i d i , o R i equivalently, if R i D i Performance Metrics Tasks and jobs How do we evaluate the performance of a scheduler? A task running several times on different input data generates a sequence of instances (or jobs): For non real-time task sets: Average response time: R avg = 1/n SUM R i Total finishing time: Job 1 Job k Job k+1 F tot = max(f i ) – min(r i ) i,1 i,k i,k+1 For real-time task sets: C i Maximum lateness: i L max = max(f i – d i ) t a i,1 a i,k a i,k+1 No. of deadline misses: N miss = SUM i H(f i – d i ) Feasibility: F = H(N miss ) 4
09/04/2018 Periodic task Activation mode • Time driven : ( periodic tasks) input C i U i = A task is automatically activated by the T i C i computation time operating system at predefined time instants. output utilization factor sync timer (period T i ) • Event driven : ( aperiodic tasks) A task is activated at the arrival of an event (by A periodic task i generates an infinite sequence of interrupt or by another task through an explicit jobs: i1 , i2 , …, ik (same code on different data): system call). T i C i i Periodic task Aperiodic task i (C i , T i , D i ) Aperiodic: job ik a i,k+1 > a i,k minimum T i interarrival time C i Sporadic: a i,k+1 a i,k + T i a i,1 = i a i,k a i,k+1 t job ik task phase C i C i C i i … a i,k = i + (k 1) T i often t a i,1 a i,k a i,k+1 D i = T i d i,k = a i,k + D i Using models Estimating C i is not easy Each job operates on different data and Application model Timing solution can take different paths. Analysis Task model Assumptions ? Even for the same data, computation time Evaluation metrics depends on the processor state (cache, Definition of task/app NO feasible? prefetch queue, number of preemptions). parameters loop YES ? ? # occurrencies Sys. Req. implementation ? System model RTOS model Platform model execution System to be controlled time I/O RTOS timer min max devices C i C i 29 5
Recommend
More recommend