16
Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times Programmer’s job! Every level of the system Soft versus hard real-time Streaming mp3 player versus air- traffic controller

Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Embed Size (px)

Citation preview

Page 1: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Real-time Scheduling

• Provide time guarantees

• Upper bound on response times– Programmer’s job!

– Every level of the system

• Soft versus hard real-time– Streaming mp3 player versus air-traffic controller

Page 2: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Real-time Scheduling

• Is this set of processes schedulable?– A: once every 100ms, 20ms CPU time– B: once every 200ms, 80ms CPU time– C: once every 100ms, 50ms CPU time

• If schedulable, still have to draw up a schedule for the processes

Page 3: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

CPU Scheduling: Summary

• FCFS• Shortest job first,

shortest remaining job next • Round robin – context switch overhead• Priority scheduling

– Multi-level queues – Lottery Scheduling

• Real-time schedule - schedulability

Page 4: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Deadlocks

• Can occur when multiple processes want multiple resources simultaneously

• Is this a deadlock?– Too many people, too few chairs– Two processes, A and B

• Process A in memory, blocking on a mutex• Process B not in memory, holding the mutex

• Let’s be more precise

Page 5: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Deadlock

(a) A potential deadlock. (b) an actual deadlock.What are the resources here?

Page 6: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Four Conditions for Deadlock

Mutual exclusion each resource assigned to 1 process or is available

Hold and wait process holding resources can request more

No preemption previously granted resources cannot be forcibly taken away

Circular waiting• must be a circular chain of 2 or more processes• each is waiting for resource held by next member of the chain

Page 7: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Approaches to Deadlocks

• Ignore the problem (!!)

• Detection and recovery

• Avoidance – Banker’s algorithm

• Prevention – impose an order on the resources

Page 8: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Recap for midterm

Introductory Material

• What belongs in the OS, what doesn’t?

• Basic Understanding of Hardware, Memory Hierarchy

Page 9: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Recap (2)

• What’s a process?– Unix Process Creation (fork)

– Shell Assignment (fork and exec)

• Address Space– Stack, heap, data and text regions

• What data items go where?

– What do fork() and exec() do to the address space

Page 10: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

System Calls

• How are they handled?– How are they different from regular function

calls?– Changing from user to supervisor mode and

back

• Some important system calls (including wait())

Page 11: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Multiprogramming

• What is it?

• Process Context (compare with thread context)

• Process Context Switch

• How are interrupts involved?

Page 12: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Threads

• When are they useful?

• When are they not useful?

• Difference from processes

• Basic thread operations – creation, joining, exiting, etc

• What do different threads in a process share, what don’t they share?

Page 13: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Mutual Exclusion and Synchronization

• What’s the problem with writing to shared variables simultaneously?

• Why do we need critical sections?– What is atomicity?

• Mutual Exclusion Problem – Clear definition

Page 14: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Mutex solutions

• Software Solutions– Peterson’s solution

• Hardware Support– TSL instruction

• Disabling Interrupts– Advantages and disadvantages– Doesn’t work for multiprocessors – why?

Page 15: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Beyond Mutexes

• Semaphores

• Producer and Consumer

• Readers and Writers

• Dining Philosophers – Deadlocks

Page 16: Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus

Cpr E 308 Spring 2004

Threads Implementations

• User and Kernel threads, pros and cons

• Process Scheduling – FCFS, Shortest Job First, etc.– Round robin scheduling– Priority Scheduling– Lottery Scheduling