34
CPU Reservations and CPU Reservations and Time Constraints: Time Constraints: Implementation Implementation Experience on Experience on Windows NT Windows NT John Regehr – University of Virginia Michael B. Jones – Microsoft Research

CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Embed Size (px)

DESCRIPTION

CPU Reservations and Time Constraints: Implementation Experience on Windows NT. John Regehr – University of Virginia Michael B. Jones – Microsoft Research. Introduction Rialto Background Windows NT Implementation Performance and Traces Related Work and Conclusions. What We Did. - PowerPoint PPT Presentation

Citation preview

Page 1: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

CPU Reservations and Time CPU Reservations and Time Constraints: Implementation Constraints: Implementation Experience on Windows NTExperience on Windows NT

John Regehr – University of Virginia

Michael B. Jones – Microsoft Research

Page 2: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

IntroductionIntroduction

Rialto BackgroundRialto Background

Windows NT ImplementationWindows NT Implementation

Performance and TracesPerformance and Traces

Related Work and ConclusionsRelated Work and Conclusions

Page 3: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

What We DidWhat We Did Created Rialto/NT

Based on Windows 2000 beta 3 Added CPU Reservations & Time Constraints

Abstractions originally developed within Rialto real-time system at Microsoft Research

What’s new Coexistence with Windows NT scheduler Multiprocessor capability Periodic clock

As opposed to fine-grained individually scheduled interrupts

Page 4: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Real-TimeReal-Time

Real-time computations have deadlines Examples

Fly-by-wire aircraft: Missed deadline may endanger the aircraft

Soft modem: Missed deadline may reset the connection

Video conferencing: Missed deadline degrades audio or video

quality

Page 5: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Why not use Windows NT as is?Why not use Windows NT as is? Real-time using priorities requires global

coordination Windows is an open system

Priority inflation No path for timing information

There are scheduling algorithms that do not require global coordination CPU Reservations and Time Constraints Apps state timing requirements directly Independently developed apps can run

concurrently

Page 6: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Teaser CapabilityTeaser Capability

Apps can ask scheduler: “Can I do 5ms of work between

now+30ms and now+40ms?” Scheduler answers either:

“I guarantee it” or “You probably can’t”

Guaranteeing this 5ms work in future 10ms interval does not require reserving 50% of CPU for next 40ms

Page 7: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

How did we do it?How did we do it?

Explicitly represent future time Map app declarations of timing

needs into grants of future time

Enables: Advance guarantees to applications, or Denial of requests up front

Page 8: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

IntroductionIntroduction

Rialto BackgroundRialto Background

Windows NT ImplementationWindows NT Implementation

Performance and TracesPerformance and Traces

Related Work and ConclusionsRelated Work and Conclusions

Page 9: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Abstraction: CPU ReservationAbstraction: CPU Reservation

Guaranteed execution rate and granularity for a thread X units of time out of every Y units, e.g.

1ms every 5ms 7.5ms every 33.3ms one second every minute

Page 10: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Abstraction: Time ConstraintAbstraction: Time Constraint

Deadline-based thread execution Guarantees execution within interval, or Proactively denies constraint request

schedulable = BeginConstraint (time_interval, estimate);if (schedulable) then

Do normal work under constraintelse

Transient overload -- shed load if possibletime_taken = EndConstraint ();

Page 11: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Implementation: Implementation: Precomputed Scheduling PlanPrecomputed Scheduling Plan

Tree-based periodic map of time Supports widely varying periods

Allocation of future time intervals Ongoing for CPU Reservations One-shot for Time Constraints

Enables efficient: Scheduling decisions Feasibility analysis for constraints Guarantees for reservations, constraints

Page 12: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Scheduling Plan ExampleScheduling Plan Example

Thread A B C D E F Amount 4ms 3ms 2ms 1ms 1ms 5ms Period 20ms 10ms 40ms 20ms 10ms 40ms

3: B 1: E

4: A 2: free

1: D

3: free2: C

5: F

Page 13: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

IntroductionIntroduction

Rialto BackgroundRialto Background

Windows NT ImplementationWindows NT Implementation

Performance and TracesPerformance and Traces

Related Work and ConclusionsRelated Work and Conclusions

Page 14: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Using the Windows NT Using the Windows NT SchedulerScheduler

Rialto/NT uses existing priority scheduler to schedule its threads Rialto/NT elevates thread priorities to

cause dispatching Existing apps, abstractions work as

before Windows NT scheduler also can

schedule Rialto/NT threads

Page 15: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Multiprocessor IssuesMultiprocessor Issues

One scheduling plan per processor Tree walking happens on all plans Heuristic: add new reservation to plans in

increasing order of processor utilization Plans not pinned to particular CPUs

Allow NT scheduler to choose CPU Rely on schedule properties, affinity to

run threads mostly on same CPU Permits opportunistic scheduling on other

processors by existing scheduler

Page 16: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Affinity vs. PriorityAffinity vs. Priority

Rialto/NT counts on priority elevation to cause thread dispatching No contention because at most one

elevated (Rialto/NT) thread per CPU On MP highest priority threads not

always scheduled Heuristics sometimes elevate thread

affinity over thread priority Changed scheduler to immediately

dispatch Rialto/NT elevated-priority threads when ready

Page 17: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Discrete TimeDiscrete Time

Windows NT clock interrupts on periodic basis Typically 10-15ms, HAL-dependent Can usually be set to 1ms period

Discrete interrupts limit enforceable scheduling granularity

So, Rialto/NT: Initializes interrupt period to 1ms Aligns rescheduling with clock interrupts

Page 18: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Implementation DetailsImplementation Details

Reschedule runs in DPC context Use NT kernel timers to schedule DPCs

Rialto/NT threads run at priority 30 Second highest Windows NT priority Other values could be chosen

New plans for reservations computed in requesting thread context Optimistic concurrency control to avoid

perturbing existing schedule

Page 19: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Non-invasive ImplementationNon-invasive Implementation

Easier to argue correctness Modified only two kernel routines

Changed behavior of one Added to the kernel:

6000 lines of C 4 system calls

Page 20: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Complication: Unpredictable Complication: Unpredictable Dispatch LatencyDispatch Latency

When latency occurs we: Penalize the running thread Keep the schedule on time

Causes of scheduling latency: Interrupt handlers Kernel code running at high IRQL Long DPCs

Latencies controllable through concerted latency testing discipline

Page 21: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Better Living Through Better Living Through SimulationSimulation

Rialto/NT runs in simulator in addition to kernel Exactly the same sources

Makes some debugging much easier Reproducible runs Better tools No race conditions Reboot time not in critical path

Page 22: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

IntroductionIntroduction

Rialto BackgroundRialto Background

Windows NT ImplementationWindows NT Implementation

Performance and TracesPerformance and Traces

Related Work and ConclusionsRelated Work and Conclusions

Page 23: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Test PlatformTest Platform

333 MHz Pentium II PCs 128MB RAM Intel EtherExpress Pro Adaptec SCSI

Single- and dual-processor

Page 24: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Context Switch TimeContext Switch Time

Tested: 10 threads on released Windows 2000 beta 3 10 Rialto/NT threads with CPU Reservations

Rialto/NT adds 8µs to median context switch time 0.8% overhead at 1ms scheduling

granularity

Page 25: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Time to Acquire ReservationsTime to Acquire ReservationsReasonable even in pathological cases

Times to begin simultaneous reservations

0

1

2

3

4

5

0 10 20 30 40 50 60

Reservation Number

Tim

e t

o M

ak

e R

es

erv

ati

on

(m

s)

Uniprocessor Dual-processor

Page 26: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Time to Acquire ConstraintsTime to Acquire ConstraintsReasonable even in pathological cases

Times to begin simultaneous constraints

0

10

20

30

40

0 10 20 30 40 50 60Time Constraint Number

Co

nst

rain

t A

cqu

ire

Tim

e (µ

s)

W ithout Reservations With Reservations

Page 27: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Reservations with a Reservations with a Background ThreadBackground Thread

Threads run only during time assigned to their reservations

1 processor, 3 threads with reservations, 1 high-priority competitor thread

Page 28: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Reservations and ConstraintsReservations and Constraints

Thread 3 gains additional time with constraints

1 processor, 3 threads with reservations (one also using constraints), 1 high-priority competitor thread

Page 29: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Dual Processor TracesDual Processor TracesWithout affinity change: thread 3 not always scheduled

With affinity change: all threads properly scheduled

Page 30: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

IntroductionIntroduction

Rialto BackgroundRialto Background

Windows NT ImplementationWindows NT Implementation

Performance and TracesPerformance and Traces

Related Work and ConclusionsRelated Work and Conclusions

Page 31: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Related WorkRelated Work

Real-time add-ins for Windows NT RTX from VenturCom, INtime from RadiSys,

Hyperkernel from Imagination Systems Lin et. al ’98

Windows NT soft real-time scheduling server Candea & Jones ’98

Vassal loadable scheduler framework Lots of reservation- and deadline-based

scheduling work

Page 32: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

Further ResearchFurther Research

Evaluate when applied to real apps Add activity abstraction

Reservation shared among threads Gang scheduling

Lots of policy issues Resource management Placement of reservations among CPUs

Page 33: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

ConclusionsConclusions

Scheduling plan effective on MPs Plan adapted to use periodic clock New scheduler cooperatively coexists

with, uses Windows NT scheduler Rialto/NT brings CPU Reservations

and Time Constraints to Windows NT

Page 34: CPU Reservations and Time Constraints: Implementation Experience on Windows NT

For more information…For more information…

http://www.cs.virginia.edu/~jdr8d/research/ http://research.microsoft.com/~mbj/