courseware basics of real-time scheduling jan madsen informatics and mathematical modelling...

28
courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building 321 DK2800 Lyngby, Denmark [email protected]

Post on 20-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

courseware

Basics of Real-Time Scheduling

Jan Madsen

Informatics and Mathematical ModellingTechnical University of Denmark

Richard Petersens Plads, Building 321DK2800 Lyngby, Denmark

[email protected]

Page 2: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 2SoC-MOBINET courseware

WAP application

Need structure and to perform multiple processes

- send requests to server- translate data received from server

- render data on display

- operating the user’s control panel

- logically different operations

- performed at different rates

• Tasks:

• Why?

Page 3: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 3SoC-MOBINET courseware

Why use multiple processes?

Processes are a neat way to handle complex systems

• Processes introduce structure into the system design– understand each process independently– analyze communication between processes

to determine system behavior

• Timing is easier to specify• Communication between processes

provide test points• Suitable for team effort

Page 4: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 4SoC-MOBINET courseware

What is a process?

A process is a state and a procedure State:

Running Suspended Deactivated

Procedure: Sequence of separate steps

A process may interact with its surroundings

Page 5: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 5SoC-MOBINET courseware

Process execution

deadlineactivation

period

Page 6: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 6SoC-MOBINET courseware

Process execution

• Periodic

– the period is the time between successive executions

– the process rate is the inverse of its period

• Aperiodic

– non-periodic process, typical an event handler

• Sporadic

– hard real-time aperiodic process

– usually, a minimum interarrival constraint is imposed

Page 7: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 7SoC-MOBINET courseware

Example: A software processes

A process includes: code memory which belongs to the process connections to other processes

A process is a unique execution of a program In most embedded systems, processes never die!

Page 8: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 8SoC-MOBINET courseware

CPUMemory

Executing on a single CPU

P1 code & data

P2 code & data

P3 code & data

P1 state

P2 state

P3 state

PC

registers

Page 9: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 9SoC-MOBINET courseware

Execution of multiple processes

• On a single CPU

– A Pentium processor

• On a distributed homogeneous system

– A network of Pentium processors

• On a distributed heterogeneous system

– A network of differing processors (CPUs and ASICs)

Page 10: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 10SoC-MOBINET courseware

About this lecture

Huge literature on scheduling theory Aim is to give an overview of problems and

possible solutions to the multi-task scheduling problem related to RTOS

Structure of lecture: Some basic concepts and teminology Uni-processor scheduling

Rate-monotonic scheduling Earlies-deadlines-first scheduling

Multi-processor scheduling

Page 11: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 11SoC-MOBINET courseware

PART I

Scheduling Terminology and Basic Concepts

Page 12: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 12SoC-MOBINET courseware

Design flow

P1P2

P3

Partitioning/clustering

Break processes toincrease parallelism

Cluster processes toreduce communication

Allocation

PE1 PE2

MappingSchedulingCommunication

P1

P3 P2

PE1

PE2P1 P2 & P3

Page 13: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 13SoC-MOBINET courseware

Scheduling

1

34

2

a b c

1 2 os

3

4

schedulinga b c

Page 14: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 14SoC-MOBINET courseware

Terminology

Application

Architecture

constraints

Scheduler Schedule

•Architecture

•Application

•Scheduling

•Constraints

Page 15: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 15SoC-MOBINET courseware

Architecture

Components Processors

CPU, DSP, ASIC, ...

Communication Bus, network, ...

Devices sensor, actuator, display, ...

Architecture may be fixed or (re-)configurable mem device

devicea b c

os1 2

3

4

Page 16: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 16SoC-MOBINET courseware

Application

Task A module which can be envoked to perform a

particular function A schedulable entity

Characterized by its: Timing constraints Precedence contraints Exclusion constraints Resource requirements

1

34

2

Page 17: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 17SoC-MOBINET courseware

Timing constraints

r1

r1 = time at which task becomes released (or active)

e1

e1 = worst case execution time (WCET)

d1 = deadline, task should complete before this!

d1s1

s1 = time at which task starts its execution

T1

T1 = period, minimum time between task releases

1

Page 18: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 18SoC-MOBINET courseware

Task execution

Periodic the period is the time between successive executions

Aperiodic non-periodic task, typical an event handler

Sporadic hard real-time aperiodic task typical, a minimum interarrival constraint is imposed

Page 19: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 19SoC-MOBINET courseware

Precedence constraints

pi precede pj if pi must finish before pj begins

process interrelate with each other to achieve: synchronization exchange datapi

pj

pi

pj

blocked

Page 20: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 20SoC-MOBINET courseware

Exclusion constraints

pi exclude pj if no execution of pj is allowed between the time that pi starts its computation and the time that pi complete its computation

Prevent simultaneous access to shared resources data memory devices

pi

pj

pi

pj

pj blocked

Page 21: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 21SoC-MOBINET courseware

Resource constraints

R = r1, r2, …, rm

Example: R(pi) = {r1, r3} resource r1 and r3 is required by pi during

its execution

may be used to implement a critical section enforce PE assignment of processes

Page 22: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 22SoC-MOBINET courseware

Scheduling approaches

Classical scheduling theory Uniprocessor systems RMS EDF

Distributed real-time scheduling Deterministic (static) scheduling Dynamic scheduling

Page 23: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 23SoC-MOBINET courseware

Scheduling

Allocation Determine number and type of processors/resources

Assignment Binding tasks to processors

Scheduling Determine execution order

a

b

b

a

1

2 1

2

Task view

1

2

Architecture view

a

b

Page 24: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 24SoC-MOBINET courseware

Scheduling principles

Off-line A scheduler performing its job before the scheduled

system is put into operation

On-line A scheduler performing its job at run-time, when the

system is running

Typically list-based When a task is released (ready) it is placed in a list Scheduler select which task from the list to execute next Selection based on some criteria – scheduling policy

Page 25: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 25SoC-MOBINET courseware

Scheduling areas

High-level Synthesis: fine grained, operation/instruction level schedule done off-line single time constraint

Real-time operating systems (RTOS): coarse grained, programs/sub-programs scheduling done on-line multiple time constraints

Page 26: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 26SoC-MOBINET courseware

SoC scheduling

Similarity to RTOS Time constraints Context switching Task synchronization Task communication

Difference to RTOS Large design space Variable granularity Wide range of metrics

Time, power, cost, ... Flexibility, reliability, ...

High degree of optimization Dedicated hardware

Page 27: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 27SoC-MOBINET courseware

Non-preemptive scheduling

Preemptive scheduling

Preemption vs. Non-preemption

1

2

1

2

Page 28: Courseware Basics of Real-Time Scheduling Jan Madsen Informatics and Mathematical Modelling Technical University of Denmark Richard Petersens Plads, Building

Jan Madsen 28SoC-MOBINET courseware

Metrics

Minimize:

c i

w ci i

}{maxmax deL iii

lateness, tardiness

Schedule length

p1 p2 p3 p4 p5

p1p2 p3 p4 p5

d1 d2 d3 d4 d5