Processes and operating systems - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

Processes and operating systems

Description:

Like subroutine, but caller determines the return address ... MOVS pc,r14. Preemptive multitasking. Most powerful form of multitasking: ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 37
Provided by: wayne74
Category:

less

Transcript and Presenter's Notes

Title: Processes and operating systems


1
Processes and operating systems
2
Processes and operating systems
  • Motivation for processes
  • The process abstraction
  • Context switching
  • Multitasking
  • Processes and UML

3
Why multiple processes?
  • Multiple tasks in many embedded computing
  • Processes help us manage timing complexity
  • multiple rates
  • multimedia
  • automotive
  • asynchronous input
  • user interfaces

4
Example engine control
  • Tasks
  • spark control
  • crankshaft sensing
  • fuel/air mixture
  • oxygen sensor

engine controller
5
Life without processes
  • Code turns into a mess
  • interruptions of one task for another
  • spaghetti code

A_code() B_code() if (C) C_code() A_code(
) switch (x) case C C() case D
D() ...
A
time
B
C
A
C
6
Co-routine methodology
  • Form of interleaved execution
  • Like subroutine, but caller determines the return
    address
  • Do not return, but rather resume each other
  • Local data are retained
  • Co-routines voluntarily give up control to other
    co-routines
  • Symmetric units that explicitly activate each
    other
  • Pattern of control transfers is embedded in the
    code

7
Co-routines
Co-routine 1
Co-routine 2
  • ADR r14,co2a
  • co1a
  • ADR r13,co1b
  • MOV r15,r14
  • co1b
  • ADR r13,co1c
  • MOV r15,r14
  • co1c ...
  • co2a
  • ADR r14,co2b
  • MOV r15,r13
  • co2b
  • ADR r14,co2c
  • MOV r15,r13
  • co2c

8
Processes
  • A process is a unique execution of a program
  • Several copies of a program may run
    simultaneously or at different times
  • A process has its own state
  • registers
  • memory
  • The operating system manages processes

9
Processes and CPUs
  • Activation record copy of process state
  • Context switch
  • current CPU context goes out
  • new CPU context goes in

PC
process 1
registers
process 2
CPU
...
memory
10
Terms
  • Thread lightweight process a process that
    shares memory space with other processes
  • Have their own distinct sets of values for CPU
    registers
  • Reentrancy ability of a program to be executed
    several times without reloading it from some
    pristine copy
  • Run time stack for local variables

11
Processes in POSIX
  • Create a process with fork
  • parent process keeps executing old program
  • child process executes new program

process a
process a
process b
12
fork()
  • The fork process creates child
  • childid fork()
  • if (childid 0)
  • / child operations /
  • else
  • / parent operations /

13
execv()
  • Overlays the process with the new code
  • childid fork()
  • if (childid 0)
  • execv(mychild,childargs)
  • perror(execv)
  • exit(1)

file with the new code
14
Context switching
  • Who controls when the context is switched?
  • How is the context switched?

15
Co-operative multitasking
  • Improvement on co-routines
  • hides context switching mechanism
  • still relies on processes to give up CPU
  • Each process allows a context switch at cswitch()
    call
  • Separate scheduler chooses which process runs next

16
A set of cooperatively multitasking processes
if (xgt2) sub1(y) else
sub2(y,z) cswitch() proca(a,b,c) process1
proc_data(r,s,t) cswitch() If (val 3)
abc2(y,z) process2
save_state(current) pchoose_process() load_and_
go(p) scheduler
17
Problems with co-operative multitasking
  • Programming errors can keep other processes out
  • process never gives up CPU
  • process waits too long to switch, missing input

18
Context switching
  • Must copy all registers to activation record,
    keeping proper return value for PC
  • Must copy new activation record into CPU state
  • How does the program that copies the context keep
    its own context?

19
Context switching in ARM
  • Save old process
  • STMIA r13,r0-r14
  • MRS r0,SPSR
  • STMDB r13,r0,r15
  • Start new process
  • ADR r0,NEXTPROC
  • LDR r13,r0
  • LDMDB r13,r0,r14
  • MSR SPSR,r0
  • LDMIA r13,r0-r14
  • MOVS pc,r14

20
Preemptive multitasking
  • Most powerful form of multitasking
  • OS controls when contexts switches
  • OS determines what process runs next
  • Use timer to call OS, switch contexts

interrupt
CPU
timer
21
Flow of control with preemption
interrupt
interrupt
P1
OS
P1
OS
P2
time
22
Preemptive context switching
  • Timer interrupt gives control to OS, which saves
    interrupted processs state in an activation
    record
  • OS chooses next process to run
  • OS installs desired activation record as current
    CPU state

23
Processes and operating systems
  • Operating systems

24
Operating systems
  • The operating system controls resources
  • who gets the CPU
  • when I/O takes place
  • how much memory is allocated
  • The most important resource is the CPU itself
  • CPU access controlled by the scheduler

25
Process state
  • A process can be in one of three states
  • executing on the CPU
  • ready to run
  • waiting for data

executing
gets data and CPU
gets CPU
preempted
needs data
gets data
ready
waiting
needs data
26
Operating system structure
  • OS needs to keep track of
  • process priorities
  • scheduling state
  • process activation record
  • Processes may be created
  • statically before system starts
  • dynamically during execution

27
Embedded vs. general-purpose scheduling
  • Workstations try to avoid starving processes of
    CPU access
  • Fairness access to CPU
  • Embedded systems must meet deadlines
  • Low-priority processes may not run for a long time

28
Priority-driven scheduling
  • Each process has a priority
  • CPU goes to highest-priority process that is
    ready
  • Priorities determine scheduling policy
  • fixed priority
  • time-varying priorities

29
Priority-driven scheduling example
  • Rules
  • each process has a fixed priority (1 highest)
  • highest-priority ready process gets CPU
  • process continues until done
  • Processes
  • P1 priority 1, execution time 10
  • P2 priority 2, execution time 30
  • P3 priority 3, execution time 20

30
Priority-driven scheduling example
P2
P2
P1
P3
30
60
0
10
20
40
50
time
31
The scheduling problem
  • Can we meet all deadlines?
  • Must be able to meet deadlines in all cases
  • How much CPU horsepower do we need to meet our
    deadlines?

32
Process initiation disciplines
  • Periodic process executes on (almost) every
    period
  • Aperiodic process executes on demand
  • Analyzing aperiodic process sets is harder---must
    consider worst-case combinations of process
    activations

33
Example definitions
deadline
p1
time
Initiating event
Aperiodic process
deadline
p1
time
Initiating event
period
Periodic process initiated at start of period
deadline
p1
time
Initiating event
period
Periodic process initiated by event
34
Timing requirements on processes
  • Period interval between process activations
  • Initiation interval reciprocal of period
  • Initiation time time at which process becomes
    ready
  • Deadline time at which process must finish

35
Timing violations
  • What happens if a process doesnt finish by its
    deadline?
  • Hard deadline system fails if missed
  • Soft deadline user may notice, but system
    doesnt necessarily fail

36
Example Space Shuttle software error
  • Space Shuttles first launch was delayed by a
    software timing error
  • Primary control system PASS and backup system BFS
  • BFS failed to synchronize with PASS
  • Change to one routine added delay that threw off
    start time calculation
  • 1 in 67 chance of timing problem
Write a Comment
User Comments (0)
About PowerShow.com