Upload
alden-benison
View
223
Download
2
Embed Size (px)
Citation preview
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Book Reminder…
• Required reading…• “Computer Science: A Modern Introduction (2nd
Edition)” Les Goldschlager and Andrew Lister, £22.95• “Fundamentals of Operating Systems”,
A. M. Lister and R. D. Eager, Fifth Edition, Macmillan Computer Science Series, ISBN. 0-333-59848-2, £13.99.
• “Operating Systems Design and Implementation”, A. S. Tanenbaum, Prentice-Hall International, ISBN. 0-13-630195-9, about £29.99.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Obtaining Slides….
• Intranet• http://info.comp.lancs.ac.uk/
• From my homepage…• www.comp.lancs.ac.uk/computing/staff/kc/
keiths_teaching.html• From library short loan…
• CD-ROM• Queries
• E-mail: [email protected]• Office: C36
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Course Structure
• Topic 1 : Introduction - 1 lecture• Topic 2 : Building a computer - 2 lectures• Topic 3 : Controlling the computer - 3 lectures• Topic 4 : I/O Devices & Networks - 3 lectures• Topic 5 : Performance - 1 lecture
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Course Structure
• Topic 6 : Introduction to OS - 2 lectures• Topic 7 : Concurrency control - 2 lectures• Topic 8 : Memory management - 1 lecture• Topic 9 : File Systems - 1 lecture• Topic 10 : Systems Software - 1 lecture• Topic 11 : Java Support - 1 lecture• Topic 12 : System security - 1 lecture
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
2: The Fundamentals
• Storage and manipulation of information within a computer:• binary, octal and hex number systems.• representing negative numbers in binary.• logic gates: AND, OR and NOT.• using logic gates to manipulate binary numbers.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
3: The Programmable Computer
• How a computer can be constructed from logic gate based components:• memory.• buses.• clocks.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
3: Microcode
• Understanding of how a computer may be controlled:• microcode.• a microcode interpreter: the fetch/execute cycle.• relationship between microcode and higher
level languages.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
3: Machine Languages and Assembly Languages
• Understanding of how a computer may be controlled (contd):• rational behind machine and assembly languages.• typical format of instructions in machine code and
assembly language.• addressing modes.• simple machine language programs.• relationship between machine code and other
languages.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
3: Languages in a Computer System
machine codemicroprogrammed interpreter
hardware
General Purpose
Systems
Assembly
translators translatorstranslators
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
4: Storage Devices and Techniques
• Knowledge of how a computer can interact with the outside world:• examples of input/output devices.
• operation of a magnetic disk, CD-ROM, mice and printers.
• techniques for dealing with the processor/device performance mismatch.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
4 : Networking
• Support for computer networks.• Parallel and serial transmission.• Issues for networking at each of seven
levels.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
5 : Processors and Processor Developments• Performance
• Many factors affect the overall performance of a computer:
• the processor clock speed.• the capacity and speed of the memory.• the number of bits in each stored word.• the features provided by the instruction set.
• Performance is typically measured in either MIPS or MFLOPS but these are not very useful.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
5 : Processors and Processor Developments
• The Role of The Clock• The clock period is particularly important in
determining the performance of a computer.• Clock period = time allocated for each basic internal
operation to the processor.• E.g. clock frequency of 1 GHz = period of 1 ns. If one
instruction per cycle then speed = 1000 MIPS.• Speeding up the clock speeds up the
processor.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
5 : Pipelined Systems
• Pipelining is a method which can be used to increase the speed of operation of the processor.
• The basic task is divided into a number of subtasks.
• Each task can be performed by a separate unit.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
5 : Pipelined Systems ... contd.
• Analogous to conveyor-belts in a factory.
IN
OUT
Stage 1 Stage 2 Stage 3
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
5 : Problems With Pipelines
• Pipelines assume:-• instructions are executed in sequence.• no interaction between tasks.
• Problems caused by:-• branch instructions.• data dependencies.• conflicts for hardware resources.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
5 : Processor Design: RISC and CISC• The design of a computer’s instruction set can
have a significant impact on its performance.• Key question is how sophisticated to make the
instruction set.• Traditional approach is to provide complex
instruction sets:• replace sequences of primitive operations.• many addressing modes.• support for procedure calls and parameter passing.• support for operating system functions.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
5 : Multiprocessor Systems
• Another approach to improving performance is to introduce more processors.
• Each processor works on some part of the overall task in parallel.
• Problems:• dividing the task into parallel units with the fewest
possible dependencies.• minimising the communication overheads between the
processors.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
6: Operating SystemsProvide a Virtual Machine
Hardware
Operating System Specific Interface
O/S
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
6: Operating Systems Also Manage Resources
• Share resources between multiple programs and multiple users.
• Ensure use of resources is optimised.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
6: Operating Systems in Context
Applications Software (e.g. packages)
System Software (e.g. operating systems)
Computer Hardware (e.g. CPU, memory, I/O devices)
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
6: Loading Programs: a Basic OS Task• Sit in a loop waiting for a program to be
ready to run.• Load the specified program from disk into
memory.• Use base and limit registers to make sure
program addresses work.• When the program has finished go back to
the loop and wait for another to be ready.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Why Multiple Programs?
• Support multiple tasks by users.
• Allow tasks to proceed in background.
• Allow programs to be structured as
independent tasks.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Some Simple Definitions
• Sequential = doing things one at a time.
• Concurrent = doing things (apparently) at the same time.
• Parallel = doing things at the same time.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Summary of Execution Patterns
Sequential
Concurrent
Parallel
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Extending Our Dispatcher to Deal With Concurrency• Load programs into different parts of
memory.• Make each program save its data and where
it is when it wants to temporarily stop running (c.f. interrupts).
• Modify the dispatcher so it can jump to these saved points.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: The Process State Model …
Ready
Running
Process is selected to run
BlockedProcess blocks (e.g. I/O)
Blocking operation finishes (e.g. I/O)
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Round Robin Scheduling
12
3
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Process Interaction
• Processes running on the same machine inevitably effect each other.
• This may be negative:-• longer execution times• competition for resources• modification of shared data
• Or positive:-• delegation of jobs• modification of shared data
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Concurrency Control
• In order to ensure safe execution of concurrent processes concurrency control is required.
• In many cases, concurrency control is required to implement mutual exclusion.
• Mutual exclusion ensures only one process has access to a given resource at a time.
• Implies only one process has access to critical sections of code.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Semaphores
• Semaphores are non negative integers which (apart from their initialisation) can only be operated on by the operations wait and signal.
• Signal adds one to the value of a semaphore.• Wait subtracts one from the value of the
semaphore unless the semaphore is zero in which case the process is blocked until the subtraction can be done without making the semaphore negative.
• Semaphores are implemented as queues.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: The Cashpoint Program using Semaphores
Beginwait (mutex);read A;read B;A := A + 50;B := B - 50;write A;write B;signal (mutex);
End.
Beginwait (mutex);read B;B : = B + 100;write B;signal (mutex);
End.
Semaphore : mutex := 1;
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Semaphores and Resource Allocation
Begin
prepare data;
wait (disk);
wait (printer);
print (data);
signal (printer);
signal (disk);
End.
Begin
prepare data;
wait (printer);
wait (disk);
print (data);
signal (disk);
signal (printer);
End.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Deadlock !Got Disk,Waiting on Printer
Got Printer,Waiting on Disk
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Conditions for Deadlock
• The resources involved are unsharable.• Processes hold the resources they have been
allocated while waiting for new ones.• Resources cannot be pre-emptied.• A circular chain of processes exists.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
7: Solutions to Deadlock Problem
• Prevent deadlock.• Detect deadlock and try to recover.• Avoid deadlock by anticipating events.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
8: Processes and Memory
• If you have only one program and it is smaller than memory then there are no problems - use static addressing.
• But .. • If we want multiple programs need to be able to
relocate programs and their data - this is tricky.• The dispatcher we built in lecture 2 used base and
limit registers to enable code to be re-located.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
8: Memory management
• If we try and run multiple processes in memory then as they start and finish so the memory becomes fragmented.
• The solution is to compact the processes currently running.
• But ... compaction is very slow (lots of copy instructions).
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
8: Reducing the Impact of Fragmentation
• Selecting the optimum place in memory to start a process can help reduce the effect of fragmentation.
• Four common solutions:-• Best Fit• Worst Fit• First Fit• Buddy
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
8: Swapping
• Suppose a program hasn’t finished - just been blocked.
• We can still run other processes if we can shift the original process out of memory while it is blocked.
• Best (only) place to put it is on disk - this is called swapping.
• But still limited to the size of main memory.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
8: Paging - A Real Important Concept• The basic idea - divide all memory up into
page frames.• Divide processes up into pages.• Maintain a table which allows you to map
addresses to the appropriate page/page frame.
• Very widely used - 486 processors have paging support built in.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
1 2 3
8: Paging .. How It WorksProcess A
Mem
ory
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
8: Placement and Replacement Policies• Placement doesn’t matter because you can’t
subdivide pages.• Replacement is critical because you want to avoid
swapping out pages which will be accessed again soon.
• Three common strategies:-• Least Recently Used (LRU).• Least Frequently Used (LFU).• First In First Our (FIFO).
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
8: ThrashingP
roce
ssor
Uti
lisa
tion
No. of Processes
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
9 : File System Objectives
• Provide persistent storage for programs and data files.• creation and deletion of files• reading and writing of files• allow reference to files by symbolic name• manage space available on secondary storage• protect files from unauthorised access and
system failure• allow sharing of files
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
9 : Basic Operations
• fd = open (filename, mode)• fd = a file descriptor• mode = read or write
• Read (fd, buffer)• Write (fd, buffer)• Seek (fd, position)• Close (fd)
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
9 : Storing Files on Disk
• The next issue to address is how to store files on the disk.
• Remember disks are block oriented devices,• Therefore files must be stored as a series of
blocks.• Of course the question is how big to make
the blocks ?
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
9 : Block Size and File System Performance• The average UNIX file is 1K.• If blocks are made large then small files are
very wasteful of disk space.• For example, if we make the block size
equal to one cylinder (32K) then 97% of the disk space is wasted.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
9: The Trade Off
128 256 512 1K 2K 4K 8K
100
150
50
0
Kby
tes/
Sec
0
25
50
75
100200
Data Rate
Disk space utilisation
Block Size
Assuming file size of 1K
Dis
k sp
ace
util
isat
ion
(%)
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
9 : Sharing and Security
• This is only an issue in multi-user operating systems or those which support remote access to files.
• The owners of files must be able to specify the access rights for files.
• Two main approaches are to use either a protection mask or access control lists.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
10: Interfacing to the O/S
• To many people the interface to the o/s is via, e.g. windows, icons, menus and pointers.
• Examples of operating systems with WIMP interfaces are MacOS and Windows95.
• The windowing system doesn’t have to be bundled with the operating system:• X Windows.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
10 : Interfacing to the O/S ...
• Many O/Ss still have textual command interfaces.• All O/Ss have a ‘function call’ based interface:
• gettimeofday ().• open (), close ().
• The function calls to the O/S are called system calls.
• Complex O/Ss such as UNIX have hundreds of system calls.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
10 : Protection
• System calls require access to the underlying operating system data structures which is not normally allowed.
• Hence, system calls typically run as operating system processes not user processes (different permissions for, e.g. files).
• As a result, there is a context switch each time a system call takes place.
• Context switches are expensive and hence minimising system calls is important.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
10: Other Systems Software
• Operating systems.• Editors:
• emacs.• vi.
• Assemblers.• Compilers and Interpreters.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
10: Approaches to Language Translation
machine codemicroprogrammed interpreter
hardware
General Purpose
Systems
Assembly
translators translatorstranslators
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
10: Approaches to Language Translation• There are two basic approaches to language
translation:• interpretation.• compilation.
• Each approach has its own advantages and disadvantages.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
11: Java on a Host OS
Host Operating System
Java Run-Time
libawt libnet
Foundation Classes
AWT Classes
NetClasses
Java API
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
11: JavaOS
Java Virtual Machine
Foundation Classes AWT Classes Net & I/O Classes
JavaOS Windows
JavaOS Graphics
TCP NFS
UDP
IP Device Drivers
Java API
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
11: Analysis of JavaOS
• JavaOS differs from a conventional system in several ways:• no file system• no virtual memory• no separate address space• support for only one program language• no o/s specific system calls
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
11: Analysis of JavaOS
• JavaOs is like a conventional system:• it is bootable• it supports user authentication• it supports protection between applets• it has device drivers• it communicates using IP etc.• it has its own windowing system• it has its own API• used to run applications
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
11: Analysis of JavaOS
• Performance• Depends in part on whether Java code is JIT
compiled or interpreted• Prototypes appear to achieve good performance
because of the lack of layers• Space
• Fits easily into 4 MB ROM and 4MB RAM• Minimal kernel will run in 512K ROM, 128K
RAM
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
12: Security
• If our OS is capable of process scheduling then we can have concurrent processing.
• These processes need not be owned by the same user.• Users have an identity on the system with an
associated user identifier• Users login (i.e. are admitted to the system)• Each process they run is attributed to their
identity
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
12: Let’s stop bad users getting in• Need to assert that user is who they claim to
be.• Identity cards• Physical characteristics, e.g. fingerprints, finger
length analysis, retina scans!• Signature analysis
• Has to be acceptable.• e.g. Urine analysis!
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
12: Passwords
• Login program prompts the user for their login name and password.
• The password is encrypted immediately.• The encrypted password is checked against
a stored form.• If it matches they get in!
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
12: How secure are they?
• In ‘79, Morris and Thompson compiled a list of words.• names, cities, a moderate dictionary, backward
words, short strings of random characters, etc.
• The words were encrypted using a public algorithm (UNIX scheme).
• They broke 86% of their system’s passwords!
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
12: Questions and answers
• User supplies a long list of Q&As on joining.
• Login process consists of questioning the user.
• Must be simple enough not to require writing down.• e.g. What is the name of your pet ?
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
12: Challenge-response
• User chooses an algorithm on joining,e.g. simple polynomial x2.
• On logging in the user is asked to respond to an appropriate challenge, e.g. 8
• And must respond with the correct answer, i.e. 64.
• Variety can be introduced depending on terminal, time etc.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
12: Can increase security by...
• Restricting points of access• e.g. UNIX superuser can only log in from the console
(notionally!)
• Dialup lines can use a callback system.• The user dials up and logs in• The system immediately breaks the connection and
calls the user on a prearranged number
• Record logins and present information to users allowing detection of security breeches.
C.Sc. 110: Computer SystemsC.Sc. 110: Computer Systems
Obtaining Slides….
• Intranet• http://info.comp.lancs.ac.uk/
• From my homepage…• www.comp.lancs.ac.uk/computing/staff/kc/
keiths_teaching.html• From library short loan…
• CD-ROM• Queries
• E-mail: [email protected]• Office: C36