Chapter 2
System Structures
Operating-System Structures
ƒ Goals: Provide a way to understand
an operating systems
ƒ Services
ƒ Interface
ƒ System Components
ƒ The type of system desired is the
basis for choices among various
algorithms and strategies!
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
Operation-System Services
ƒ Goal:
ƒ Provide an environment for the execution
of programs.
ƒ Services are provided to programs and
their users.
ƒ User Interface (UI)
ƒ Command Line Interface, Batch Interface,
Graphical User Interface (GUI), etc.
ƒ Interface between the user and the
operating system
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
Operation-System Services
ƒ Friendly UI’s
ƒ Command-line-based interfaces or
mused-based window-and-menu
interface
ƒ e.g., UNIX shell and command.com in
MS-DOS
User-friendly?
Get the next command
Execute the command
ƒ Program Execution
ƒ Loading, running, terminating, etc
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
Operation-System Services
ƒ I/O Operations
ƒ General/special operations for devices:
ƒ Efficiency & protection
ƒ File-System Manipulation
ƒ Read, write, create, delete, etc.
ƒ Files and Directories
ƒ Permission Management
ƒ Communications
ƒ Intra-processor or inter-processor
communication – shared memory or
message passing
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
Operation-System Services
ƒ Error Detection
ƒ Possible errors from CPU, memory,
devices, user programs Æ Ensure
correct & consistent computing
ƒ Resource Allocation
ƒ Utilization & efficiency
ƒ Accounting
ƒ Statistics or Accounting
ƒ Protection & Security
• user convenience or system efficiency!
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
User OS Interface –
Command Interpreter
ƒ Two approaches:
ƒ Contain codes to execute commands
ƒ Fast but the interpreter tends to be
big!
ƒ Painful in revision!
del
cd
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
User OS Interface –
Command Interpreter
ƒ
Implement commands as system
programs Æ Search exec files
which corresponds to commands
(UNIX)
ƒ Issues
a. Parameter Passing
ƒ Potential Hazard: virtual memory
b. Being Slow
c. Inconsistent Interpretation of
Parameters
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
User OS Interface – GUI
ƒ Components
ƒ Screen, Icons, Folders, Pointer, etc.
ƒ History
ƒ
ƒ
ƒ
ƒ
Xerox PARC research facility (1970’s)
Mouse – 1968
Mac OS – 1980’s
Windows 1.0 ~ XP
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
User OS Interface – GUI
ƒ Unix & Linux
ƒ Common Desktop Environment
(CDE), X-Windows, K Desktop
Environment (KDE), GNOME
ƒ Trend
ƒ Mixture of GUI and command-line
interfaces
ƒ Multimedia, Intelligence, etc.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Calls
ƒ System calls
ƒ Interface between processes & OS
ƒ How to make system calls?
ƒ Assemble-language instructions or
subroutine/functions calls in high-level
language such as C or Perl?
ƒ Generation of in-line instructions or a
call to a special run-time routine.
ƒ Example: read and copy of a file!
ƒ Library Calls vs System Calls
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Calls
ƒ Application Programming Interface
(API)
ƒ Examples: Win 32 API for Windows,
POSIX API for POSIX-based
Systems, Java API for Java virtual
machines
ƒ Benefits (API vs System Calls)
ƒ Portability
ƒ Ease of Use & Better Functionality
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Calls
ƒ How a system call
occurs?
x
register
ƒ Types and
information
x: parameters
for call
load address x
system call 13
use parameters
from table x
Code for
System
Call 13
ƒ Parameter Passing
ƒ Registers
ƒ Registers pointing to
blocks
ƒ Linux
ƒ Stacks
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Calls
ƒ
ƒ
ƒ
ƒ
ƒ
Process Control
File Management
Device Management
Information Maintenance
Communications
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Calls
ƒ Process & Job Control
ƒ End (normal exit) or abort (abnormal)
ƒ Error level or no
ƒ Interactive, batch, GUI-supported systems
ƒ Load and execute
ƒ How to return control?
ƒ e.g., shell load & execute commands
ƒ Creation and/or termination of processes
ƒ Multiprogramming?
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Calls
ƒ Process & Job Control (continued)
ƒ Process Control
ƒ Get or set attributes of processes
ƒ Wait for a specified amount of time
or an event
ƒ Signal event
ƒ Memory dumping, profiling, tracing,
memory allocation & de-allocation
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Calls
ƒ Examples: MS-DOS & UNIX
free memory
process A
process
interpreter
free memory
command
interpreter
process B
kernel
kernel
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Calls
ƒ File Management
ƒ Create and delete
ƒ Open and close
ƒ Read, write, and reposition (e.g.,
rewinding)
ƒ lseek
ƒ Get or set attributes of files
ƒ Operations for directories
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Calls
ƒ Device management
ƒ Physical or virtual devices, e.g., files.
ƒ Request or release
ƒ Open and close of special files
ƒ Files are abstract or virtual devices.
ƒ Read, write, and reposition (e.g.,
rewinding)
ƒ Get or set file attributes
ƒ Logically attach or detach devices
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Calls
ƒ Information maintenance
ƒ Get or set date or time
ƒ Get or set system data, such as the amount
of free memory
ƒ Communication
ƒ Message Passing
ƒ Open, close, accept connections
ƒ Host ID or process ID
ƒ Send and receive messages
ƒ Transfer status information
ƒ Shared Memory
ƒ Memory mapping & process synchronization
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Calls
ƒ Shared Memory
ƒ Max Speed & Comm Convenience
ƒ Message Passing
ƒ No Access Conflict & Easy Implementation
Process A M
Process A
Shared Memory
Process B M
kernel
Process B
M
kernel
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Programs
ƒ Goal:
ƒ Provide a convenient environment for
program development and execution
ƒ Types
ƒ
ƒ
ƒ
ƒ
File Management, e.g., rm.
Status information, e.g., date.
File Modifications, e.g., editors.
Program Loading and Executions, e.g.,
loader.
ƒ Programming Language Supports, e.g.,
compilers.
ƒ Communications, e.g., telnet.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Design &
Implementation
ƒ Design Goals & Specifications:
ƒ User Goals, e.g., ease of use
ƒ System Goals, e.g., reliable
ƒ Rule 1: Separation of Policy & Mechanism
ƒ Policy:What will be done?
ƒ Mechanism:How to do things?
ƒ Example: timer construct and time slice
ƒ Two extreme cases:
Microkernel-based OS
Macintosh OS
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Design &
Implementation
ƒ OS Implementation in High-Level
Languages
ƒ E.g., UNIX, OS/2, MS NT, etc.
ƒ Advantages:
ƒ Being easy to understand & debug
ƒ Being written fast, more compact,
and portable
ƒ Disadvantages:
ƒ Less efficient but more storage for
code
* Tracing for bottleneck identification, exploring of excellent algorithms, etc.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
OS Structure – MS-DOS
ƒ MS-DOS Layer Structure
Application program
Resident system program
MS-DOS device drivers
ROM BIOS device drivers
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
OS Structure – UNIX
User
interface
System call
interface
useruser user
user
user user
user
Shells, compilers, X, application programs, etc.
CPU scheduling, signal handling,
virtual memory, paging, swapping,
file system, disk drivers, caching/buffering, etc.
Kernel interface
to the hardware
terminal controller, terminals,
physical memory, device controller,
devices such as disks, memory, etc.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
UNIX
OS Structure
ƒ A Layered Approach – A Myth
Layer M
new
ops
hidden
ops
Layer M-1
existing
ops
Advantage: Modularity ~ Debugging &
Verification
Difficulty: Appropriate layer definitions, less
efficiency due to overheads!
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
OS Structure
ƒ A Layer Definition Example:
L5
L4
L3
L2
L1
L0
User programs
I/O buffering
Operator-console device driver
Memory management
CPU scheduling
Hardware
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
OS Structure – OS/2
ƒ OS/2 Layer Structure
Application
Application
Application
Application-program Interface
Subsystem
Subsystem
System kernel
Subsystem
‧memory management
‧task scheduling
‧device management
Device driver Device driver Device driver
* Some layers of NT were from user space to kernel space in NT4.0
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
OS Structure –
Microkernels
ƒ The concept of microkernels was
proposed in CMU in mid 1980s (Mach).
ƒ Moving all nonessential components
from the kernel to the user or system
programs!
ƒ No consensus on services in kernel
ƒ Mostly on process and memory
management and communication
ƒ Benefits:
ƒ Ease of OS service extensions Æ
portability, reliability, security
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
OS Structure –
Microkernels
ƒ Examples
ƒ Microkernels: True64UNIX (Mach
kernel), MacOS X (Mach kernel),
QNX (msg passing, proc scheduling,
HW interrupts, low-level networking)
ƒ Hybrid structures: Windows NT
Win32
Applications
Win32
Server
OS/2
Applications
OS/2
Server
POSIX
Applications
POSIX
Server
kernel
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
OS Structure – Modules
ƒ A Modular Kernel
ƒ A Set of Core Components
ƒ Dynamic Loadable Modules
ƒ E.g., Solaris: Scheduling Classes, File
Systems, Loadable System Calls,
Executable Formats, STREAMS
Modules, Miscellaneous, Device and
Bus Drivers
ƒ Characteristics:
ƒ Layer-Like – Modules
ƒ Microkernel-Like – the Primary Module
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
OS Structure – Modules
ƒ Example Mac OS X
App. Environ. &
Common Services
BSD
Mach
Kernel Environment
ƒ Application Environments and Common
Services
ƒ BSD: Command Line Interface, Support for
Networking and File Systems, an
Implementation of POSIX APIs.
ƒ Mach: Memory Management, Support for
Remote Procedure Calls, Interprocess
Communication Facilities
ƒ The Kernel Environment: I/O Kit for the
Development of Device Drivers and
Dynamically Loadable Modules.
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
Virtual Machine
ƒ Virtual Machines: provide an interface that is
identical to the underlying bare hardware
processes
interface
kernel
processes
processes
processes
kernel
kernel
kernel
VM1
VM2
VM3
virtual machine implementation
hardware
hardware
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
Virtual Machine
ƒ Implementation Issues:
ƒ Emulation of Physical Devices
ƒ E.g., Disk Systems
ƒ An IBM minidisk approach
ƒ User/Monitor Modes
ƒ (Physical) Monitor Mode
ƒ Virtual machine software
ƒ (Physical) User Mode
ƒ Virtual monitor mode & Virtual user
mode
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
Virtual Machine
virtual
user
mode
P1/VM1 system call
processes processes processes
virtual
monitor kernel 1 kernel 2 kernel 3
mode
monitor
mode
Finish
service
Trap
Service for the system call
Restart VM1
virtual machine software
Set program counter
& register contents,
& then restart VM1
hardware
time
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
Simulate the
effect of the I/O
instruction
Virtual Machine
ƒ Disadvantages:
ƒ Slow!
ƒ Execute most instructions directly on the
hardware
ƒ No direct sharing of resources
ƒ Physical devices and
communications
* I/O could be slow (interpreted) or fast (spooling)
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
Virtual Machine
ƒ Advantages:
ƒ Complete Protection – Complete
Isolation!
ƒ OS Research & Development
ƒ System Development Time
ƒ Extensions to Multiple Personalities, such
as Mach (software emulation)
ƒ Emulations of Machines and OS’s, e.g.,
Windows over Linux
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
Virtual Machine – VMware
ƒ VMware – The visualization layer abstracts the
physical hardware into isolated virtual
machines running as guest operating systems.
applications
applications
applications
Guest OS (Windows NT)
Virtual OS
Virtual memory
Virtual devices
Guest OS (free BSD)
Virtual OS
Virtual memory
Virtual devices
visualization layer
Linux/Windows
CPU
memory
I/O devices
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
Virtual Machine – Java
java .class files
class loader
verifier
java interpreter
ƒ Sun Microsystems in late 1995
ƒ Java Language and API Library
ƒ Java Virtual Machine (JVM)
ƒ Class loader (for
bytecode .class files)
ƒ Class verifier
ƒ Java interpreter
host system
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
ƒ An interpreter, a just-in-time (JIT)
compiler, hardware
Virtual Machine – Java
java .class files
ƒ JVM
ƒ Garbage collection
ƒ Reclaim unused objects
class loader
verifier
ƒ Implementation being specific for
different systems
ƒ Programs are architecture neutral
and portable
java interpreter
host system
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Generation
ƒ SYSGEN (System Generation)
ƒ Ask and probe for information concerning the
specific configuration of a hardware system
ƒ CPU, memory, device, OS options, etc.
No recompilation
& completely
Linking of
table-driven
modules for
selected OS
Recompilation
of a modified
source code
ƒ Issues
ƒ Size, Generality, Ease of modification
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.
System Boot
ƒ Booting
ƒ The procedure of starting a computer
by loading the kernel.
ƒ The bootstrap program or the
bootstrap loader
ƒ Firmware being ROM or EEPROM
resident
ƒ Boot/system disk with a boot block
* All rights reserved, Tei-Wei Kuo, National Taiwan University, 2005.