concurrency, processes, and system calls benefits and issues of concurrency the basic concept of...

17
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

Upload: lizbeth-davidson

Post on 18-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

Concurrency, Processes, and System calls

Benefits and issues of concurrency The basic concept of process System calls

Page 2: 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

Page 3: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

Benefits of Concurrency

What are the limitations without concurrency? Long response time Resources under utilized

Better resource utilization Resources unused by one application can be

used by the others Better average response time

No need to wait for other applications to complete

Page 4: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

Benefits of Concurrency

Keyboard

CPU

Disk

Time

Finishing time

Keyboard

CPU

Disk

Page 5: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

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

Page 6: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

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.

Page 7: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

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.

Page 8: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

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.

Page 9: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

Program != Process

A program can create multiple processes Example: Internet Explorer

Page 10: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

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

Page 11: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

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.

Page 12: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

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.

Void open (char *file_name) { asm { load OpenSystemCallNum, r8 move filename, r9 syscall }}

Interrupt vector

0x00x1..

OpenSystemCallNum “Open” handler

Page 13: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

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.

Page 14: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

Question: Is syscall a system mode instruction or a user mode instruction?

How about iret in x86?

Page 15: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

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.

Page 16: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

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

Page 17: Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls

Assuming that a system call and a routine performs the same task, which one will have better performance? Homework!!