View
216
Download
2
Tags:
Embed Size (px)
Citation preview
Operating systems
November 6, 2001
Administrivia
• Report on the midterm
• Lab 5 (or is it Lab 7?)– Need a CD and headphones
• Problem set schedule
• Duplicating homework not recommended
0
10
20
30
40
50
60
70
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
rank in c lass
sc
ore
(o
f 6
0)
Grades on Midterm
Midterm Grades
Calculated very pessimistically
Difficulties
• 1b) If your computer has 256 megabytes (MB) of RAM, how many bits are needed to be able to address all of the bytes of that memory? How does this number change if we organize bytes into words that are groups of 4 bytes (32 bits) and only need to be able to address individual words, not individual bytes?
• 2c) Give a truth table for the black box we’ve described here. You do not need to draw any logic gates. 2d) How could you use multiple copies of the black box from part c) to build a circuit that does subtraction of 4 bits numbers?
• 3a) Draw the state diagram describing this State Machine. Clearly label the arrows between states of your state machine. Don’t forget to include arrows from a state back to itself if it should stay in the same state. Make sure your diagram is complete.
Addressing Memory
Truth table
Black box
State machine
• Have to remember last input (2 bits)
• Have to create output
State machine (cont.)
Homework schedule
• Assignment 5 due next Tuesday (11/13) steganography
• Assignment 6 due 11/20 file system design
Lab schedule
• Week of 11/5 Audio
• Week of 11/12 Visual Basic 1
• Week of 11/19 No Lab
• Week of 11/26 Visual Basic 2
• Week of 12/3 Spreadsheets
• Week of 12/10 No Lab
Where we are
• Built a computer– 0’s and 1’s and representations– logic gates to compute on 0’s and 1’s– circuits of logic gates to realize truth tables– state machines (special purpose computers)– general purpose computer (programmable)
What’s next
• Figure out what it takes to use computer– Work from our experience– Work top down as well as bottom up– Identify tasks and see how they are done– Understand pieces of the operating system
• Attach computers to build network of computers– for communication (InterNet)– for computing (Seti@home, cancer cure)– for file sharing (Napster, Gnutella, Kaaza)
• Program computers– Visual basic
• Explore underpinnings– Theory– Legal– Intelligence
Lecture plan
• Week of 11/5– Operating system – Networking
• Week of 11/12– Programming
• Week of 11/19 – Distributed computing
• Week of 11/26– Algorithms– Unsolvable problems
• Week of 12/3– Encryption– Digital Rights Management
• Week of 12/10– Aritificial Intelligence– Review
Lecture plan
• Week of 11/5– Operating system (How Windows works)– Networking (How the internet works)
• Week of 11/12– Programming (Making the computer do different things)
• Week of 11/19 – Distributed computing (How Kaaza, Seti@Home work)
• Week of 11/26– Algorithms (How Google works)– Unsolvable problems
• Week of 12/3– Encryption (Why you can email your credit card #)– Digital Rights Management (Legal issues)
• Week of 12/10– Aritificial Intelligence (Replacing ourselves by machines?)– Review
User experience at the computer
• You turn it on – System boots
• First the hardware, then the Windows operating system
– Your desktop appears• First icons, then applications
– Interaction devices can be used• Machine is listening to mouse, keyboard, etc.
– Machine enters new version of the fetch/execute cycle• Machine fetches command from user
• Machine executes commands
What happens when machine boots
• Power goes on, each device is turned on• BIOS lets you talk to hardware
– Change order devices are turned on– Set system clock– Identify new interaction devices
• Then, the boot program for Windows starts.– You tell it an order to look at disks– It looks at disks in this order to find operating system
• Operating system boots– Simple program called the operating system kernel is loaded (at
location 10). This is the program that runs the computer.
Operating system kernel
• Kernel– Starts
• Device drivers– Talk to RAM, disks, CD/ROM, …
• Starts subsystems– memory management system (to organize data on RAM)– file system (to organize files on disk)
• Gets user started– Starts window manager or creates a shell– Starts fetch/execute cycle
Fetch/execute cycle
• Fetch is Event driven
• Execution is done by the operating system
Fetching
• Fetch is Event driven– The window manager listens for an event
• From keyboard– Key down/key up
• From mouse– Mouse motion, mouse button up or down
• From other device– Game controller
– Speech interface
Fetching (cont.)
• Identify where the command occurred– In which window on the screen
• Identify the action that must be taken– Examples
• Type text into Word window• Click command in window of executing program• Click on resize corner of window• Click on icon from window• Click on icon from task bar
Parsing commands
– Type text into Word window• Text is passed to Word program
– Click command in window of executing program• Command is passed to executing program
– Click on resize corner of window• Window manager
– Listens to mouse for stretching– changes the geometry of the screen
» The application might tell the window manager how
– Click on icon from window• Action to be taken is identified
– Click on icon from task bar• Sleepy program comes back to life
Parsing commands
• Possibilities– Pass information to an existing command
• Type text into Word window
• Click command in window of executing program
– Start new command• Click on icon from window
– Wake up existing command• Click on icon from task bar
– Modify the geometry of the display• Click on resize corner of window
Executing existing commands
• Type text into Word window– Text is passed to Word program
• Word program has previously been put into RAM. It is storing the text in space it has in RAM, so the new text is added to that RAM.– Von Neumann model– How is RAM managed?
• What if you need more• What if you overflow your memory?• What happens when you quit?
Starting new command
• Have to identify the command– How to start Word
• Select Word from the Start menu
• Click on icon for Word
• Click on a shortcut to the icon for Word
• Click on a file called Something.doc
• Click on an unidentified file and tell it to use word to open
• Enter from a command line
Starting new command (cont.)
• Click on a file called Something.doc• Windows registry keeps track of such things
– File associations• .doc Word• .jpg Default Image viewer• .vbs Visual Basic• .mp3 .wav etc. various music formats
– A newly installed program may change file associations
Sidebar on file associations
• AnnaKournakova.jpg.vbs– what is it?
Sidebar on file associations
• AnnaKournakova.jpg.vbs– what is it?
• It comes as an attachment– mailer opens it with Visual Basic
– It executes
Sidebar on file associations
• AnnaKournakova.jpg.vbs– what is it?
• It comes as an attachment– mailer opens it with Visual Basic
– It executes
• What it does– Open your address book
– Package itself as a message
– Sends itself to everyone you know
Starting new command (cont.)
• Once the command is found– C:\Program Files\Microsoft Office\Office\WinWord.exe
• Locate the command on the disk• Move the command to RAM• Add it to the list of commands being executed• Let it run
How do you find it on disk?How do you know where to load it in RAM?How do you keep track of all running programs?
Starting new command
• Have to identify the command– How to start Word
• Enter from a command line– Start>Run>
– C:\Program Files\Microsoft Office\Office\WinWord.exe
– Icons are just an improved User Interface• In UNIX, use keyboard to create the command line
• In Windows, use mouse to click on icons.
The Window Manager
• Maintains the geometry• Identifies events with windows
• Confusion– Windows 95, 98, NT, Me, 2000 is the operating system
– Underneath runs the window manager
• How does the window manager work?
Unresolved questions
• How is RAM managed?• How do you find it on disk?• How do you know where to load it in RAM?• How do you keep track of all running programs?• How does the window manager work?
• Answer– This is what the operating system does
Operating system
• It’s kernel is what starts at boot time• Contains memory manager for RAM• Contains file system to manage disk• Contains process manager to control running programs
• Runs the window manager• Contains the device drivers for running devices;
updates as necessary (plug and play)
The ideal operating system
• Never stops
• Uses no resources
• Is easy to modify and update
• Has no security holes and no bugs
The ideal operating system
• Never stops– If every process forgets a little data (1KB/s) machine will
crash within a few days
• Uses no resources– It shouldn’t be a drain to run it
• Is easy to modify and update– New devices come out, …
• Has no security holes and no bugs– But these are complex programs.
• IBM joke • Microsoft joke
Managing memory
• Initially– Some space reserved for the operating system– Rest of space for user programs
• When a new program starts– Gets space for execution– Gets space for data
• As a program executes– Can ask for more space– Can free up space
• When a program stops– It’s memory is released
Memory management
Op. SysInitially
Memory management
Op. SysInitially
Start Word
Op. Sys
Word.exe
Word data
Memory management
Op. SysInitially
Start Word
Word needsMore memory
Op. Sys
Word.exe
Word data
Word data2
Memory management
Op. SysInitially
Start Word
Word needsMore memory
Start IE
Op. Sys
Word.exe
Word data
Word data2
Op. Sys
Word.exe
Word data
Word data2
IE
Memory management
Op. SysInitially
Start Word
Word needsmore memory
Start IE
Word needsmore memory
Op. Sys
Word.exe
Word data
Word data2
Op. Sys
Word.exe
Word data
Word data2
IE
Word data3
Memory management
Op. SysInitially
Start Word
Word needsmore memory
Start IE
Word needsmore memory
Exit IE
Op. Sys
Word.exe
Word data
Word data2
Free Space
Word data3
Op. Sys
Word.exe
Word data
Word data2
IE
Word data3
Memory management
Op. Sys
Initially
Start Word
Word needsmore memory
Start IE
Word needsmore memory
Exit IE
Word frees space
Op. Sys
Word.exe
Free space
Word data2
Free Space
Word data3
Op. Sys
Word.exe
Word data
Word data2
Free Space
Word data3
What if you run out of memory?
• Use virtual memory– Have some memory in RAM, some in disk– Hide the details from the user– Make choices effectively
• paging
Virtual memory
• User thinks the machine has 512 MB of RAM– 256 MB are in RAM– 256 MB are on disk– Memory mapper works in units of pages
• A page may be on disk or in RAM• Common pages are on RAM• Page must be moved to RAM to be used
– Disk is just a staging area
– When request comes for information• Memory mapper finds page
– If in RAM, things proceed– If on disk, must clear space in RAM and move it there
Virtual memory (cont.)
• When request comes for information– Memory mapper finds page
• If in RAM, things proceed
• If on disk, must clear space in RAM and move it there
• What to clear?– LRU – least recently used page
Virtual MemoryOp. Sys
Word.exe
Word data
Word data2
IE
IE data
Virtual MemoryOp. Sys
Word.exe
Word data
Word data2
IE
IE data
Word wants more space
Virtual MemoryOp. Sys
Word.exe
Word data
Word data2
IE
Some IE data
Other IE data
Word data3Virtual memory on disk
Memory mapper
Requests for memorygo through the memory mapper which finds theneeded pages
Sidebar on speed
• Difference between register, RAM, disk– Registers are right there – can access right away– RAM requires
• a request onto the bus • Address decoding• Returning data on the bus
– Disk requires• Request onto the bus• Determining where data is on disk• Spinning disk platter to get there• Gathering data, putting it on the bus.
2
Storage Latency: How Far Away is the Data?
RegistersOn Chip CacheOn Board Cache
Memory
Disk
12
10
100
Tape /Optical Robot
109
10 6
Olympia
This Building
This RoomMy Head
10 min
1.5 hr
2 Years
1 min
Pluto
2,000 Years
Andromeda
Jim Gray
The File system
• How does the disk work?
• How do we organize files?– What’s in a name– Is a text file different from an executable or a
folder?
Disk
• Controller– Electronics that run the disk
– Communicate on the bus
• Disk itself is– Platters
– Arms to read off of platters
– Disk spins at 3600 or 7200 RPM• Arms read/write data at appropriate part of platter
• Might have 3 platters, 6 read/write arms
Platters
Sectors – pie shaped wedges
Tracks – concentric circles
Low-level formatting establishes the tracks and sectors on the platter. This process prepares the drive to hold blocks of bytes.
High-level formatting then writes the file-storage structures, into the sectors. This process prepares the drive to hold files.
The file system (part of the operating system) determines which file-storage sectors will hold which files.
File System
• There is a top level object called Desktop• An object can either be a file or a folder• object knows
– File or folder?– Number of blocks– Location of first block (on physical disk)– Block keeps track of next/previous block– Modification information– Sharing information– Any user supplied information
File system (cont.)
• File– First block stores data– Points to block of next data
• Folder– First block stores names of objects it holds– For each, it stores
• System given name
• Location of first block
Processes
• Any program that is executed is a process– Process state gives current status of process
• Value of program counter (as a register)
• And other registers
• And memory
– One program can lead to multiple processes
Controlling processes
• Process table– One entry for process
• Is it ready
• Is it waiting (e.g. for device)
• Dispatcher– Does process switching
• Causes an interrupt
• Process may cause it’s own interrupt
Twists and turns
• Fair scheduling– Each process gets it’s time slice if needed
– But might want to be able to assign priorities
• Deadlock prevention– Process A needs printer and CD to continue
• If gets assigned the printer
– Process B needs printer and CD to continue• It gets assigned the CD
– How do things continue?
A look at existing operating systems
• Windows *– 95, 98, NT, 2000, Me, XP
• Linux– Public domain UNIX
• MacOS– MacOS 7 was far ahead (1992) – MAC OS X trying to catch up (2001)
• Solaris– Larger server world
LinuxWHAT IS LINUX?
Linux is a Unix clone written from scratch by Linus Torvalds with assistance from a loosely-knit team of hackers across the Net.
It has all the features you would expect in a modern fully-fledged Unix, including true multitasking, virtual memory, shared libraries, demand loading, shared copy-on-write executables, proper memory management and TCP/IP networking.
It is distributed under the GNU General Public License. (open source – source code is free)
Linux -- where does the work go
ArchDriversFSlibsinitIPCKernelMM
Why is it hard to build an operating system?
• They’re big
• Parts of them are driven by need for efficiency
• Need to be backwards compatible
• Must control many devices not built here
Operating systems respond to computer systems
• Brief history– Single task– Time sharing– Multitasking– Ubiquitous computing
Computing in the 1940’s/50’s
• Single processor/Single task – Turn on the machine– Do the task– Do the next task– ….– Turn off the machine
• Tasks had time limits because computing was expensive.
Computing in 1960’s/1970’s
• Time sharing– One machine, many tasks– Each task gets 1 jiffy (= 1/60 second)– During it’s time slice
• Task (and its data) would be swapped in• Task would operate for its time• Task (and its data) would be swapped out
– Many users could be serviced at once– More efficient (why??)
Computing in the 1980’s
• Multiprocessing/multitasking– Machine can do more than one thing at a time– Like timesharing but has many users processed
at once (or such is the illusion)
Computing in the 90’s
• We compute on true multiprocessors– 1 box with multiple processors– Multiple machines connected by a network
• New challenges– Load balancing – keep each processor busy– Scaling – breaking tasks across many machines
Computing in the 00’s
• Everything is its own computer– Computers communicate and work together– Java/JINI – languages to support this
• Light weight processes
• Everything means everything– Toaster, heater, sound system, …– House of the future