Concurrency, Processes, and System calls Benefits and issues of concurrency

advertisement
Concurrency, Processes, and
System calls
Benefits and issues of concurrency
 The basic concept of process
 System calls

Concurrency

Allows multiple applications to run at
the same time

Analogy: juggling
Benefits of Concurrency

What are the limitations without
concurrency?



Better resource utilization


Long response time
Resources under utilized
Resources unused by one application can be
used by the others
Better average response time

No need to wait for other applications to
complete
Benefits of Concurrency
Keyboard
CPU
Disk
Time
Finishing time
Keyboard
CPU
Disk
Issues related to concurrency


It is easier to do one thing at a time.
Problems with doing multiple things:



Applications need to be protected from
one another
Additional coordination mechanisms
among applications
Overhead to switch among applications

Potential performance degradation when
running too many applications
Process




A process is a program in execution.
A process is a basic scheduling unit in an OS:
during the execution, each process has a virtual
machine.
 The execution of processes does not
interference with one another.
In a computer system, concurrency is realized by
allowing multiple processes to co-exist at the same
time.
Most programs are single process programs and
the OS hides the details about creation and
termination of processes.
Process .vs. Program


Program: a collection of instructions
Process: a running instance of the
program, with additional states and
system resources


Example of additional states: process
state (running, waiting, ready, etc)
Example of system resources: memory.
Process != Program

Two processes can run the same
program


The code segment of two processes are
the same program
These two processes are totally
independent of one another.
Program != Process

A program can create multiple
processes

Example: Internet Explorer
Process context


It takes more than the “executable” to
run a program.
Process context, sometimes also
called process image, includes
everything needed for the OS to run
the program correctly.


Program counter
Stack pointer, etc
System calls


System calls are functions (enhanced instructions)
implemented in OS that can be used by user
processes.
Handling system calls is like handling interrupts
(sometimes call software interrupts).


Instead of a hardware event, the program issues an
“interrupt” instruction.
All processors support such an instruction. The semantics
of such instructions on different processors are similar (but
have some slight differences).



On x86, the instruction is int/iret.
On MIPS, the instruction is syscall.
On some other older machines, the instruction is called trap.

Void open (char *file_name) {
asm {
load OpenSystemCallNum, r8
move filename, r9
syscall
}
}
Interrupt vector
0x0
0x1
.
.
OpenSystemCallNum

The semantic of the syscall
instruction is similar to a
routine call instruction.
The difference is that (1)
the syscall handler address
is obtained from the system
call/interrupt vector (table)
maintained by the OS; and
(2) the mode is changed to
the system mode.
“Open” handler

Question: The purpose of a system call is to
invoke the system call handler routine. Why
use the system call, instead of the simple
routine call?

A system call changes the execution mode into
system mode.


Some instruction can only be executed under the
system mode.
Some services can only be provided correctly by the
operating system due to the concurrency.


Question: Is syscall a system mode
instruction or a user mode instruction?
How about iret in x86?

Typical sequence of events when running
the syscall instruction:






Current program counter (PC) and program
status word (PSW) are saved.
The program mode is changed to the system
mode.
Hardware load PC from the system call interrupt
vector location
Execute the system call interrupt handler
Change mode back to user mode
Restore PC and PSW and continue user
program.

System call interface



The system call interface is the description of
the set of system calls supported by the OS.
The OS interface is pretty much defined by the
system call interface.
Typical types of system calls





Process control
File management
Device management
Information management
Communication management

Assuming that a system call and a
routine performs the same task, which
one will have better performance?

Homework!!
Download