Vous êtes sur la page 1sur 31

Chapter 2: Operating-System Structures

Operating system design Interface provided to users & programmers


System calls (programmer access) User level access to system

Services

System Structure
Layered approach
Operating system divided into layers Higher levels use only services of lower levels Basic principle of abstract data types (classes)

Figure 2.14

Mechanism vs. Policy


Mechanisms determine how to do something
Provided by the operating system E.g., ability to set the priority of a user process

Policies determine what will be done


E.g., determining which processes get highest priority

Separation gives flexibility Solaris example p. 67


CPU scheduling controlled by loadable tables These tables provide a general purpose mechanism for scheduling The policy is determined by the specific table loaded E.g., different tables can provide time-sharing, batch processing or real-time scheduling

Example

Directory BlockGroup BlockLinkedList FreeList

Original Unix O/S: Kernel Approach

Figure 2.13, p. 69

monolithic structure

Monolithic Structure
an enormous amount of functionality combined into one level [of abstraction in software] (p. 69, Our text-- Silberschatz et al.) this approach might well be subtitled The Big Mess. The structure is that there is no structure. The operating system is written as a collection of procedures, each of which can call any of the other ones whenever it wants to. (p. 56, Tanenbaum, 2001, Modern Operating Systems, 2nd Ed).
6

Microkernel Approach
More like a client-server system Kernel supports efficient message passing
Plus some other low-level services such as interrupt handling, loading device drivers

Much of former kernel runs in user mode (not kernel mode)


E.g., file system (server) may run in user mode

Mach (some versions), and QNX (http://www.qnx.com/) operating systems organized this way QNX is real-time; small (micro) kernel can be advantageous to real-time systems
7

http://en.wikipedia.org/wiki/Microkernel

Alternate View of Microkernel

device driver

Mac OS X: Microkernel Approach (not fully)

Emphasis: Mach and BSD Unix both run in kernel mode

Figure 2.16

10

Solaris: Modular approach

Fig 2.15

Perhaps the best current methodology for operating-system design involves using objectoriented programming techniques to create a modular kernel (p. 72) modules are typically dynamically loadable (e.g., Solaris, Linux, Mac OS X)

11

Machine Code of a Typical Process Running on an Operating System


top of process in RAM (low numbered addresses)

Machine instructions executed in user mode


System call

bottom of process in RAM (low numbered addresses) etc.


12

Process Interfaces to the System


In what weve been talking about so far, a process can either execute machine language code or it can make system calls What other kinds of process interfaces are possible? API or library interfaces; e.g., POSIX Virtual machine interface
13

Virtual Machines
Processes provided with an interface virtually identical to the bare hardware Each process is provided with a (virtual) copy of the underlying computer E.g., IBM VM mainframe operating system Devices are an issue
e.g., Disks must be partitioned

Each user runs an operating system on their own virtual machine


Some instructions run directly on hardware Some instructions (e.g., I/O) are interpreted
14

Figure 2.17: Virtual & Non-Virtual Machines

Non-virtual Machine

Virtual Machine
15

Hosted Virtual Machine

16

Java Virtual Machine (JVM)


Specification for an abstract computer
http://java.sun.com/docs/books/jvms/
http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html

Instructions specified as bytecodes Architecture neutral Java program code is compiled (javac) into files containing bytecode JVM includes
Class loader Bytecode verifier Bytecode interpreter
18

Services
User interface Program execution: Processes Resource allocation I/O operations File-system manipulation Communications Protection & security Error detection Figure 2.1, p. 48 of text Accounting
19

Services - 1
User Interface
GUI and command line are the most common for general purpose operating systems

Program execution
System must be able to load a machine language program into RAM memory and run that program

Resource allocation
Multiple processes or users: Need to share, allocate, and manage resources Examples of types of resources: CPU cycles (time), main memory, disk files, I/O devices (printers, USB flash drives etc).
20

Services - 2
I/O operations
All I/O that a program does is typically carried out by the O/S This is for efficiency and protection

File-system manipulation
creating, reading, writing files & directories

Communications
Between processes on the same computer and between processes across different computers e.g., Shared memory & message passing
21

Services - 3
Protection & security
In multiuser systems, some people want to control access to their information Generally, when several separate processes execute concurrently, it should not be possible for one process to interfere with others or with the operating system itself (p. 49)

Error detection
OS needs be constantly aware of possible errors (p. 49) Hardware errors include: power, memory, device errors Software errors include: divide by 0, access of an illegal memory location

Accounting
Which processes/users use which resources and for how long? For statistics or for billing, and possibly for imposing resource limits 22

What is a system call?


A means for application programs to access operating system kernel functionality Types of calls
Process control: E.g., create, load, execute File operations: E.g., create, open, read, write Device manipulation: E.g., request, read, write Information: E.g., get or set process attributes Communications: E.g., create connection, send or receive message
23

Figure 1.10: Transition from User to Kernel Mode


24

System Call Implementation


For example? E.g., file open, close, read or write Software interrupt CPU instruction is executed e.g., Intel x86 and MIPS: syscall instruction (others on Intel: sysenter, int 0x80) Execution control passes to an interrupt service routine in O/S; context switch is required CPU mode bit is set to monitor (kernel) mode Parameters
Software interrupt parameters may give type of system call (e.g., read or write), or may be given as as system call parameters Parameters to system call passed in registers, in a block of data, or user stack E.g., kernel code runs Process is executing kernel code for duration of system call
25

System call is executed


Process is resumed (return from interrupt), back in user mode; context switch is required

Procedure Calls vs. System Calls


Libraries

Libraries

User process

User process

System call Return value(s) Procedure call is within the user process address space Operating system
26

Making a System Call in Linux


http://www.ibm.com/developerworks/linux/li brary/l-system-calls/ http://www.linuxjournal.com/article/4048?pa ge=0,1 http://www.win.tue.nl/~aeb/linux/lk/lk-3.html
http://stackoverflow.com/questions/344829/what-iskernel-vsyscall http://stackoverflow.com/questions/9977968/addinga-new-system-call-in-linux-kernel-3-3
29

System calls have numbers

30

A system call from C


#include <stdlib.h> int main() {
exit(42);

31

Making a system call from assembly language

See also http://www.win.tue.nl/~aeb/linux/lk/lk-3.html

32

System Programs
How does a system program differ from a system call? System program: Application programs that provide system related services
Use operating system calls to provide operating system related functionality Run in user mode (not kernel mode)

Examples of system programs


Network communications such as http servers (e.g., apache) Compilers (e.g., g++) File management: directory listing (ls on Unix), copying files (cp on Unix) 33 User interface (X11, Gnome)

End!

34

Vous aimerez peut-être aussi