Operating Systems: Lecture On
Operating Systems: Lecture On
Operating Systems
An Introduction
Walter Kriha
2.
Modern applications no longer run as a single process. They are multiprocess engines using lots of internal threading. They use shared memory
and large scale storage areas resources they have to maintain.
3.
Non-Goals
Writing device drivers. We will look at the design patterns
behind device drivers but writing one is reserved for advanced
classes
This is not a kernel algorithm class. We will look at resource
management strategies but we dont implement kernel code
yet.
This is (no longer) a C-language class. We will focus on the
runtime system aspects only. We will use C down to the
assembly code level but becoming a guru will take more time.
At the end of this class you should know how to how to use OS tools to profile and
monitor the programs and in general be able to design an application with a
resonable guestimate on where performance problems could be and how they
could be avoided.
Schedule
Lecture:
1.
OS Introduction
2.
Linux Architecture
3.
File Management
4.
5.
6.
7.
8.
Computer Organization
9.
Virtual Machines
10. Monitoring
Exercises:
Linux Certification I, an
introduction to self-learning
System Programming
Examples
Show Cases
1.
2.
3.
4.
5.
6.
7.
8.
After this class you should be able to diagnose problems (OS, environment) by
using the proper analytical tools. You should also have a much better understanding
of how computing works.
1970s
CDC,
S/360
Accounting,
large scale apps
multics
PDP11
unix
1980s
1990s
IMS DB
vax
VMS/Ultrix
CP/M
commodore
apple
2000s
Z/OS, linux
VMs
S390 sysplex
SysV Unix,
Mach
MSDOS
windows
GUIs
CAN bus
2008
Game frame
midrange,
workstations
silicon graphics
java VM
NT/W2K/XP
linux
PDAs, mobile phones,
Symbion OS, Palm OS
mainframes
J2ME platform
Mac/OS 10
wireless
/bluetooth
PCs
wireless/bluetooth
Embedded,
UMPCs,
Playstation,xbox,wii,
Iphone/OpenMoko
Fact is that most ideas in computing are rather old. A good idea needs the right hardware
and users to blossom.
Trends (1)
1.
2.
3.
4.
5.
6.
7.
Some of those trends have started long ago and some are quite new like the Linux VMs
on mainframes. Some things dont change: users want fast and reliable programs and
services. Today mobility and interconnection is key.
Trends (2)
1.
2.
3.
4.
5.
6.
The demand for software will be very high due to ubiquitous computing the change
of our world to a completely computerized one.
Applications
Applications
An Operating System is an INTERACTIVE SYSTEM which balances events and requests
coming from different sources. It has to keep internal state of applications and of itself
consistent while at the same time making sure that users still get responses. An Operating
System GENERALIZES over many different use cases, sometimes making necessary
compromises e.g. with respect to realtime requirements. Operating Systems are unable to
make the same guarantees as reactive or transformative systems.
Other Systems
Request
Requester
OS
Input
Data
Transformer
Output
Data
Both types of systems, reactive and transformative, are much less critical with respect
to response time and reliable behavior. Unfortunately they are not fit to do an
Operating Systems job.
An OS usually provides generic functions. Functions that a lot of applications will need.
The OS does this by offering a special interface called the system call interface to
applications. An OS designer must judge whether a function is a) really a kernel function
which cannot be implemented otherwise and b) whether the function is general enough
to be useful for many applications.
File Systems
File Systems
System Services (X Server)
User Mode
Kernel
Mode
File Systems
File Systems
Resource Management
File Systems
File Systems
File Systems
Principals
Applications
Principals
OS Tools
Process management
Process management
Process management
I/O Mgmt.
I/O Mgmt.
I/O Mgmt.
Device Driver
Device Driver
Device Driver
At first glance an Operating System follows the LAYER architectural design pattern. But
there is also a lot of inter-component re-use. Please note that an Operating System has
kernel mode and user mode parts. E.g. Tools like file manager belong to the OS even
though technically they are user mode applications. Most everything within an operating
system needs to be extensible or replaceable. New devices need new device drivers, not
a new operating system releases.
events
Keyboard
Device manager
events
Hardware: ports and memory
0/1
Regular compute
operations (add, mul)
Most CPUs offer a simple protetion scheme. Dangerous operations (sensing, control) are
only allowed when the CPU has been put in kernel mode (protection bit is set).
Applications can NOT change the state of the CPU arbitrarily. They MUST use certain
controlled gates (software interrupts) to change the mode. From then on, operating
system code runs!
Application
stack used
C Language Library
System Call Library
Software Interrupt Kernel Trap
(CPU instruction)
Kernel
Mode, CPU
doing critical
things
Operating System
Kernel
stack used
Directoy Services
User Mode
Kernel
Mode
Application 1
CS
CS
Application 2
CS
CS
Kernel Functions
User services are much easier to develop, replace, monitor and debug than kernel
services. But this comes at a price: Inter-process communication means going through
the kernel which usually means context switches (CS) between processes and copying
data back and forth from application to kernel and back to the other application or
service. The good news: applications bugs usually do not crash services. And if, then
services can be restarted without rebooting the kernel. Internal kernal functions are fast
AND DANGEROUS: nothing prevents a kernel mode function from wrecking the
system. They run usually with full CPU privileges and can access everything anytime. In
times of weak hardware people put every service into the kernel. Nowadays most
services are placed in user space.
Monolithic Kernels
runtime loadable
Application 1
device
driver
firewall
module
audio
driver
User Mode
compiletime
Kernel
Mode
memory
managment
device
drivers
file
management
Kernel Functions
process
management
Monolithic kernels run all operating system functions in kernel mode. The kernel itself
either contains all necessary code already (compile time extension) or modules can be
loaded dynamically (e.g. linux). All kernel code has the same criticality: a bug and the
kernel crashes! Performance is good because internal calls are simple procedure calls and
not system calls with traps. Maintenance is bad because of millions of lines of code for
the kernel with dependencies and no protection between.
file
management
server
User Mode
Kernel
Mode
memory
managment
server
Application 1
CS
Microkernels
security
management
server
process
management
server
CS
basic
security
device
drivers
basic
memory
management
Microkernels run most of the traditional kernel functions outside in user mode services.
Only the most basic functions like device control and some security and memory
handling is performed in kernel mode. This make is easy to change e.g. to a different file
management implementation by starting a new service. The price is paid in overhead due
to increased numbers of context switches for a single function called.
Single tasking operating systems are e.g. MSDOS. This makes e.g. a modern GUI
with window technology impossible. The software structure of a single tasking
system is much simpler (and safer, thats why in some mission critical areas
asynchronous, interrupt driven multi-tasking systems where not allowed)
Real-time systems do not use timeslices like interactive systems. They assign
priorities to processes. Whenever a high-priority process becomes runnable the
scheduler will immediately preempt a low-priority process. A large amount of
simulation goes into those systems (see www.ilogics.com for simulation
software). Soft real-time systems are regular interactive systems with enough
CPU power to generally fulfill timing requirements. The design of the OS kernel
decides about whether a system qualifies for real-time requirements.
Latency
Preemption
Large blocks of code where the caller cannot be preempted make a quick reaction to external
events impossible. One solution is to create kernel threads und allow preemption on that
level. This is what the Linux RT extension does. From E.Kunst et.al, see resources)
Priority Inheritance
Now C gets temporarily a higher priority to finish processing. This will release the
mutex held by C and allow high-priority process A to continue. (Klabinus/Kunst et.al)
The Lego Mindstorms robot package is an example of a small embedded control platform. Several
operating systems exist for this device, e.g. LegOS (c++) and Lejos (Java). A small Hitachi microprocessor
and 32k of ram are available. We will use it as an example for embedded control programming (Using
cross-compilation, firmware download and subsumption architecture). See
http://www.jugs.org/protokolle/02-09-12/leJOS-v1.1.pdf
Application
backend
Application
GUI
Frontent
Application
backend
Application
GUI
Frontent
Application
backend
Operating System
The most popular systems today are the windows type desktop operating systems.
Those systems have a mostly user centric view. They provide a graphical user interface
for most tasks and make it very easy to learn the tools. New functions are usually
implemented either as extensions of existing applications or a new applications. Users
of those systems are usually relatively inexperienced computer users and the knowledge
they acquire is mostly in knowing how to use certain applications. No programming is
done by users. Software companies serving this customer and technology sector usually
depend on updates for applications which bring new features. Automation is very low,
everything has to happen manually through the GUI. Most applications get into total
feature overload because there is no functional composition used which would require
user training.
Unix systems have traditionally favored a composition pattern. Instead of creating huge
applications with hundreds of features small programs were built with very limited
capabilities. But those modules could be linked together (via pipes) to generate processing
pipelines. Or the shell language could be used to further connect those modules via scripts.
This reduced the need to always extend existing modules at the price of the user now
having to understand how this composition works a form of programming. Inexperienced
users soon found this challenging. But even worse: the business modell behind favors NOT
buying new software with a new feature. Instead, building new solutions by combining
existing modules is favored. I believe this is at the core of the decade old Unix vs.
Windows discussion. Different user groups and business models. As a side effect Unix
modules are NOT supposed to produce output for users. They need to produce output that
becomes input for other modules and must therefore be careful not to contain presentation
oriented features. Thats why Unix programs operate silently.
File management
Memory management
Process management (threads, multiprocessing)
User and Security management
GUI (window system)
Command Interpreter (shell)
Loadable Modules
Utilities
The next sessions will introduce you to all these subsystems or components.
Compatibility
Virtual
Machine
Programming
Language
OS
Computer
CPU
Operating Systems are always a hot political and economic topic resulting
from the fact that compatibility of applications is so much tied to the operating
system. The only layer that really makes a program largely independent of
platform and OS is the virtual machine.
Resources (1)
Resources (2)
Jochen Hiller, Lego Mindstorms Introduction. An excellent overview
of the lego platform and the lejos java operating system which runs on
this device. http://www.jugs.org/protokolle/02-09-12/leJOS-v1.1.pdf .
This is an ideal chance to see a java virtual machine in source code and a
small footprint.
The lejos homepage, www.lejos.org
The LegOS homepage, www.legos.org
Unix Skriptum (Deutsch) HDM
http://webcast.berkeley.edu/courses/archive.php?seriesid=1906978284
Berkley lecture "CS 162 Operating Systems and System Programming"
either as video stream or mp3 for download. (thanks to Marc Seeger for
the link)