Computer science The Tired Librarian 80

advertisement
Computer science
A few ideas from
operating systems and
computer architecture




One of the most useful concepts in CS is “abstraction”.
To abstract: to remove the basic concept, idea or
process from a situation.
The abstraction: the removed concept, usually
expressed in another, more succinct and usually more
general form.
In CS:
 usually refers to ability to separate the high-level view of an
object from the low-level details of its implementation.
From slides by Sanjeev Arora and Hank Levy
 Enables us to understand, design and intellectually manage
large systems.
 Today: a little bit about how abstraction simplifies programming
and a little bit about what operating systems do.
The Tired Librarian
Reserves
Idea 1: Caching
(and the 80-20 rule)
50 ft



80-20 “Rule”

Pareto [1906]: 20% of the people own
80% of the wealth

Juran [1930’s]: 20% of the organization
does 80% of the work
1000 checkouts/returns per day
Distance covered = 50 x 2 x 1000 = 100,000 feet
~ 20 miles
Please help!!!
Better Arrangement
“Most popular” shelf:
20% most popular
books
Reserves
50 ft

5 ft
Distance covered per day?
1
Even better arrangement?
“Most popular” shelf:
20% most popular
books
Reserves

Is the librarian’s problem solved?
Top 4%
50 ft

5 ft
Distance covered per day?
How to predict the 20% most
popular books for next day?

In general, no easy solution

In practice, use rules of thumb
New and improved
Cache:
Very fast,
but small
memory
 Example:
“Least Recently Used”. When you
need to create space on the desk (or shelf),
move out the book that was used least
recently
Connection to Computer
Organization

Speed vs cost of various memories
Cost: $ / GB
Speed: GB/s
Hard drive
0.50
1
RAM
100
5
40000
15
On-chip memory
for CPU (L2
Cache)
© 2004 Jim Gray, Microsoft Corporation
2
Computer
Librarian arrangement
Reserves
Disk
Moral
“Most popular” shelf:
20% most popular
books Memory

Performance:
 Speed
CPU
is close to that of fastest memory
(cache)
 Overall capacity is that of largest memory
(disk)
Top 4%
Cache
Often, today’s computers have even more levels of caching
Question
Idea 2: Virtual Memory

How does the same program (.exe file) run on
different PCs with different memory
configurations?

Answer: “Virtual Memory”
Living a very useful fiction
All programs live a fiction: allowed to pretend it has
264 bytes of memory
 Illusion is preserved by hardware and operating
system -- OS maintains the illusion for each running
program that it is the only program running on the
computer.

The operating system


Software on a computer that manages the way different
programs use its hardware and acts as an intermediary
between the user and the computer.
“all the code the application programmer didn’t write” that
enables implementation of his/her program
Virtual Memory

Program’s view:
Powerpoint
Address 0

Lec15.ppt
Lec16.ppt
Memory:
Address 264 - 1
Underlying
truth:
3
Virtual Memory

Application benefits
Idea 3: Multi-tasking
Programming
simplicity

See
high-level
abstractions instead of
low-level hardware
details (ex: disk)
Portability -- can run
program in different
machine configurations

An Evening’s Tasks for a Gen-M’er
Homework
Listen to music
 Instant messaging
 Call Mom (goes to bed by 11pm)
 Answer phone
 Exercise
 Read a bit more of Joyce’s Ulysses
 Watch the Daily Show

Tasks done by my PC last night




How do you do it all?




Word processing
Play CD
Download news updates
Download email
Run clock
Hidden tasks: handle network traffic, manage
disk and RAM traffic, scheduler, etc.
Managed by Operating System
(WinXP, Linux, MacOS, etc.)
Scheduler’s objectives
Fairness
Timeliness
 Critical tasks processed promptly
 Low overhead
Aside: Multitasking versus Parallel Processing


How can one achieve these (often
conflicting) goals?
Multitasking: A single CPU handles many
tasks by switching rapidly among them.
Parallel Processing: Multiple CPUs that do the
work of a single CPU. (But, 4 CPUs do not
necessarily mean 4x speed.)
4
Idea 4: Some of the complexities of
multi-tasking
Multitasking creates
headaches…

You and your SO have a joint bank account with $100
and happen to separately go to an ATM at the same time
to withdraw $10.
Withdraw(amount, account #)
B := ReadBalance(account #);
B <-- B - amount;
WriteBalance(B, account #);
Print out slip showing client final
balance.
Code that gets executed on bank computer
Problem: arbitrary interleaving

The dining philosophers problem

You and your SO have a joint bank account with $100 and happen
to separately go to an ATM at the same time to withdraw $10.
Withdraw(amount, account #)
B := ReadBalance(account #);

B <-- B - amount;
WriteBalance(B, account #);

Various solutions: locks, complex atomic instructions,
disable interrupts…
 Deadlock
 Livelock
That’s not the only problem with multitasking or
running concurrent programs…
Meet the philosophers
(clockwise from top)
Jobs of an operating system






Plato: “Love is a serious mental disease.”
Confucious: “Choose a job you love, and
you will never have to work a day in your life.”
Socrates: “One thing only I know, and that is that I know nothing.”
and “I cannot teach anybody anything, I can only make them think.”
Voltaire: “When he who hears does not know what he who speaks
means, and when he who speaks does not know what he himself
means, that is philosophy.” and “If God did not exist, it would be
necessary to invent Him.”
Descartes: “Dubito ergo cogito; cogito ergo sum. (I doubt, therefore I
think; I think therefore I am.) and
“An optimist may see a light where there is none, but why must the
pessimist always run to blow it out?”
Each philosopher
either eats or
thinks. (don’t
speak.)
Each philosopher
needs two forks to
eat.
Potential
Problems:





Receptionist: user interface management
Dispatcher: program scheduling and activation.
Security guard: system and file access control.
Efficiency expert: efficient resource allocation
Traffic officer: deadlock and error detection.
Literally dozens of other things…
5
The Legal View….
One main
point studied by the
judge:
What is an OS?
6
Download