40
Mani Srivastava UCLA - EE Department Room: 7702-B Boelter Hall Email: [email protected] Tel: 310-267-2098 WWW: http://www.ee.ucla.edu/~mbs Copyright 2001 Mani Srivastava RTOS Scheduling – II EE202A (Fall 2001): Lecture #5

Mani Srivastava UCLA - EE Department Room: 7702-B Boelter Hall Email: [email protected] Tel: 310-267-2098 WWW: mbs Copyright 2001

  • View
    223

  • Download
    3

Embed Size (px)

Citation preview

Mani SrivastavaUCLA - EE DepartmentRoom: 7702-B Boelter HallEmail: [email protected]: 310-267-2098WWW: http://www.ee.ucla.edu/~mbs

Copyright 2001 Mani Srivastava

RTOS Scheduling – IIEE202A (Fall 2001): Lecture #5

2 Copyright 2001 Mani Srivastava

Reading List for This Lecture

Required Waldspurger, C.A.; Weihl, W.E. Lottery

scheduling: flexible proportional-share resource management. Proceedings of the First USENIX Symposium on Operating Systems Design and Implementation (OSDI), Monterey, CA, USA, 14-17 Nov. 1994. p.1-11. 280 pp.

Recommended none

Others none

3 Copyright 2001 Mani Srivastava

Deadline Driven Scheduling

Priorities are assigned to tasks according to the deadlines of their current requests

highest priority to task whose current request has the closest deadline

lowest to the one whose deadline is the furthest highest priority task with an unfulfilled request is run

Priorities of tasks change with time!

4 Copyright 2001 Mani Srivastava

Preemptive Earliest Deadline First (EDF)

Processor executes the task whose absolute deadline is the earliest

Priorities change with the closeness of a task to its absolute deadline

Example:

Task Arrival Time Execution Time

Absolute Deadline

T1 0 10 30

T2 4 3 10

T3 5 10 25

5 Copyright 2001 Mani Srivastava

EDF Schedulability

Optimal for single processor If EDF cannot schedule a task set on a single processor, then

no other scheduling algorithm can Simple schedulability test if tasks are periodic, and have

relative deadlines equal to their periods if the total utilization U of the task set is no greater than 1, the

task set can be feasibly scheduled by EDF on a single processor.

If relative deadlines are not equal to the periods, there is no simple schedulability test

one will have top develop a schedule using EDF to see whether all the deadlines are met over a given time interval

6 Copyright 2001 Mani Srivastava

EDF Schedulability for Deadline==Period Case

Theorem: Suppose we have a set of n periodic tasks (Ti, Ci, Di) , each of whose relative deadline Di equals its period Ti. The tasks can be feasibly scheduled by EDF on a single processor iff:

C1/T1 + C2/T2 + … + Cn/Tn 1

7 Copyright 2001 Mani Srivastava

EDF Schedulability for Deadline!=Period Case

Theorem: A set of n tasks (Ti, Ci, Di) is not schedulable by EDF iff

Utilization U > 1, or there exists

t < min { T + Dmax, U/(1-U) * max1 in{Ti – Di}}

such that h(t) > t, whereDmax = max1 in{Di}T = lcm(T1,…Tn)h (t) = sum of the execution times of all tasks

whose absolute deadlines are ≤ t.

With the above theorem, we only need to check for feasibility up to some finite time.

Proof see Theorem 3.1.2 + related Lemmas at

http://nesl.ee.ucla.edu/pw/ee202a/edf.pdf Note the difference in notation (T, C, D) → (P, e, d)

8 Copyright 2001 Mani Srivastava

Allowing for Precedence Constraints

So far: independent task, preemptible by others Now we relax these condition

9 Copyright 2001 Mani Srivastava

Heuristic for Uniprocessor Scheduling

10 Copyright 2001 Mani Srivastava

Heuristic for Uniprocessor Scheduling (contd.)

Schedule after step 2

Schedule after step 3

11 Copyright 2001 Mani Srivastava

Primary and Alternative Tasks So far: there must be sufficient time for the

critical tasks to execute assumed worst case execution time (WCET) quite often WCET >> mean execution time

One way: reclaim unused time for other tasks Another approach: multiple versions of tasks

Precise version Alternate version

– shorter processing time but imprecise result– just acceptable “bare bones” result

12 Copyright 2001 Mani Srivastava

Example

Can’t schedule if only primary version available

13 Copyright 2001 Mani Srivastava

Imprecise or Approximate Computation

A time-critical task designed in such a way that an approximate result is produced when the entire precise computation cannot be completed

Motivation: tasks become easier to schedule when a tolerable amount of error can be introduced into the system

Examples: Iterative division algorithm On-line arithmetic

– Bit-serial where the output is produced MSB first

O ptiona l Task5 cycles

M andatory Task (Im precise)7 cycles

1.10111011101

Precise C om putation - 12 cycles

14 Copyright 2001 Mani Srivastava

Scheduling Model for Imprecise Computation

IRIS: Increased Reward for Increased Service Each Task, Ti, is decomposed logically into two

tasks Mi (mandatory) and Oi (optional) i = mi + oi (12 = 7 + 5)

Classical model => oi = 0

O ptiona l Task5 cycles

M andatory Task (Im precise)7 cycles

1.10111011101

Precise C om putation - 12 cycles

15 Copyright 2001 Mani Srivastava

Uniprocessor Scheduling of IRIS Tasks

Reward function

Schedule the tasks such that the reward is maximized, subject to the requirement that the mandatory portions of all the tasks are complete

16 Copyright 2001 Mani Srivastava

QoS-based Resource Allocation Model (Q-RAM)

Different total system utility by resource allocations (Rajkumar et al. 1997, 1998)

R1 5 7 4R2 5 3 6U1 5 6.5 4U2 2 2 5U 7 8.5 9

17 Copyright 2001 Mani Srivastava

RM in Distributed/Networked Embedded Systems?

Task is essentially scheduled on multiple resources in series

Need to schedule communication messages over the interconnect

propagation delay & jitter queuing delay & jitter

Divide end-to-end deadline into subsystem deadlines Need buffering to mitigate jitter problem as task may

arrive too early

18 Copyright 2001 Mani Srivastava

Assignment of Tasks to Processors

NP complete in most cases Typical heuristics:

Allocate tasks according to some simple criterion– E.g. processor utlization

Check feasibility– Communiction cost, task precedences

If not feasible, modify the allocation and retry

19 Copyright 2001 Mani Srivastava

Utilization-Balancing Algorithm

Attempts to balance processor utilization Allocate tasks one by one, and selecting the least

utilized processor Takes into account the possibility of running

multiple copies of the same task for fault tolerance

20 Copyright 2001 Mani Srivastava

Next-Fit Algorithm for RM

User defines M>3 classes as follows: Task Ti is in class j<M if In class M otherwise

Corresponding to each class is a set of processors that is only allocated tasks of that class

Tasks are allocated one by one to appropriate processor class until all the tasks have been scheduled, adding processors to classes if that is need for RM schedulability

21 Copyright 2001 Mani Srivastava

Example

Uses no more than N times the minimum # of processors

22 Copyright 2001 Mani Srivastava

Bin-packing Algorithm for EDF Periodic independent preemptible tasks assigned to

a multiprocessor with identical processors Goal EDF schedulability

assign tasks such that U no greater than 1 First-fir decreasing algorithm

23 Copyright 2001 Mani Srivastava

Example

24 Copyright 2001 Mani Srivastava

Distributed Case with Data Precedence

Implicit start and stop nodes in each task Rate constraint and deadline for each task

Period may not be constant: lower/upper bounds Execution time of processes may not be constant

Lower/upper bounds

25 Copyright 2001 Mani Srivastava

Performance Analysis

The problem of deciding whether the deadline of each task is met is NP hard

Given the schedule, allocation, and architecture Unrolling the schedule doesn’t work

Cannot easily handle non-constant period and computation times

– Can’t just use the worst case execution time!

26 Copyright 2001 Mani Srivastava

Erroneous Results in Using WCET in Unrolled Schedules

27 Copyright 2001 Mani Srivastava

Erroneous Results in Using WCET in Unrolled Schedules

28 Copyright 2001 Mani Srivastava

Lottery Scheduling: Flexible Proportional-Share Resource Management

A randomized mechanism that provides responsive control over the relative execution rates of computations

Does away with “primitive” priority based schemes Implements proportional-share resource management

whereby the resource consumption rates are proportional to the relative shares that they are allocated

“Found to provide efficient, flexible control over relative execution rates”

29 Copyright 2001 Mani Srivastava

Allocation of Resource Rights

Resource allocation determined by holding a lottery

This effectively allocates resources to competing clients in proportion to the number of tickets that they hold

30 Copyright 2001 Mani Srivastava

Lottery

Scheduling by lottery is probabilistically fair Number of lotteries won by a client has a binomial

distribution P = t/T E[w] = np

= np(1-p)

Number of lotteries required for a client’s first win has a geometric distribution E[n] = 1/p

= (1-p)/p2

Typical scheduling quantum is 10 ms (100 lotteries per second)

31 Copyright 2001 Mani Srivastava

Lottery Tickets

Properties Abstract Relative Uniform

Analogous to that of money in computational economics Abstractly encapsulate resource rights Allow for modular resource management

32 Copyright 2001 Mani Srivastava

Modular Resource Management

Ticket transfers Explicit transfers of tickets from one client to another Can be used in any situation where a client blocks due to some

dependency Solves conventional priority inversion problem in a manner similar

to priority inheritance

Ticket inflation Alternative to explicit ticket transfers Escalate resource rights by creating more lottery tickets Need for mutual trust among clients Inflation and deflation can be used to adjust resource allocations

w/o explicit communication

33 Copyright 2001 Mani Srivastava

Modular Resource Management (cont’d)

Ticket currencies Resources rights could be expressed in “local” units, with

granularity tuned for that particular resource Each currency is backed, or funded, by tickets that are

denominated in more primitive currencies Exchange rates could be established between local currency and

base currency Compensation Tickets

Compensation ticket granted for client only consuming only a fraction f of its allocated resource quantum, inflate its value by 1/f

Ex: Threads A and B each hold tickets valued at 400 base units (1:1 ratio)

Thread A always consumes its entire 100 ms of quantum Thread B uses only 20 ms => f = 1/5

34 Copyright 2001 Mani Srivastava

Implementation Modified Mach 3.0 microkernel running on a 25MHz MIPS-

based DECStation 5000/125 Kernel representation of tickets and currencies

1000Base

amountcurrency

alice300

Ticket

List of backing tickets

List of issued tickets

Unique name

Active amount

Currency

35 Copyright 2001 Mani Srivastava

System Overhead

Core lottery scheduling mechanism Ex: tree-based lottery need only generate a random

number and perform log n additions and comparisons to select winner among n clients

Comparing unoptimized kernel to unmodified Mach kernel, it was found that application executed 1.7% faster

36 Copyright 2001 Mani Srivastava

Experimental Results

Multimedia Applications 3 MPEG viewers, 3:2:1 allocation ratio Actual ratio, 1.92:1.50:1 No need for cooperation between media-based

applications, nor feedback to adjust frame rates Load Insulation

Two tasks A and B w/ equal funding Subtasks A1 and A2 have allocations of 100 and 200,

respectively Subtasks B1 and B2 have identical allocations

Currency has an abstract barrier that locally contains intra-currency fluctuations

System was found to be fair, flexible, and robust

37 Copyright 2001 Mani Srivastava

Inverse Lotteries

Basic idea: a “loser” is chosen to relinquish a unit of a resource that it holds

Instead of obtaining a resource, client tries to prevent having its resource allocation revoked

P = 1/(n-1)*(1-t/T)

38 Copyright 2001 Mani Srivastava

Multiple Resources

Clients can make quantitative comparisons to make decisions involving tradeoffs between different resources

Questions Funding policies? Frequency of fund allocation evaluation?

39 Copyright 2001 Mani Srivastava

“Financial Advisor”

Abstract the evaluation of resource management options

Financial manager would be allocated a fixed small percentage (e.g. 1%) of application’s overall funding (or computation time)

Default simple managers for most applications, complex management strategies for sophisticated applications

40 Copyright 2001 Mani Srivastava

Lottery Scheduling Summary

Lottery scheduling is conceptually very simple and easily implemented

Used to manage any resource where management is necessary to resolve multiple requests

Current ongoing work involves exploring various applications of lottery scheduling in interactive systems, including GUI element