没有合适的资源?快使用搜索试试~ 我知道了~
首页Operating Systems: Three Easy Pieces 国外著名大学研究生操作系统课本(0.90版本)
Operating Systems: Three Easy Pieces 国外著名大学研究生操作系统课本(0.90版本), 我自己整理的0.90版本, 有三个pdf对应三个部分,这是第一部分:OSTP-Part I Virtualization, 二三部分可留意我之后上传的内容(本来不想要什么分,奈何最低是1分........)
资源详情
资源评论
资源推荐

1
A Dialogue on the Book
Professor: Welcome to this book! It’s called Operating Systems in Three Easy
Pieces, and I am here to teach you the things you need to know about operating
systems. I am called “Professor”; who are you?
Student: Hi Professor! I am called “Student”, as you might have guesse d. And
I am here and ready to learn!
Professor: Sounds good. Any questions?
Student: Sure! Why is it called “Three Easy Pieces”?
Professor: That’s an easy one. Well, you see, there are these great lectures on
Physics by Richard Feynman...
Student: Oh! The guy who wrote “Surely You’re Joking, Mr. Feynman”, right?
Great book! Is this going to be hilarious like that book was?
Professor: Um... well, no. That book was great, and I’m glad you’ve read it.
Hopefully this book is more like his notes on Physics. Some of the basics were
summed u p in a book called “Six Easy Pieces”. He was talking about Physics;
we’re going to do Three Easy Pieces on the fine topic of Operating Syste ms. This
is appropriate, as Operating Systems are about half as hard as Physics.
Student: Well, I liked physics, so that is probably good. What are those pieces?
Professor: They are the three key ideas we’re going to learn about: virtualiza-
tion, concurrency, and persistence. In learning about these ideas, we’ll learn
all about how an operating system works, including how it decides what program
to run next on a CPU, how it handles memory overload in a virtual memory sys-
tem, how virtual machine monitors work, how to manage information on disks,
and even a little about how to build a distributed system that works when parts
have failed. That sort of stuff.
Student: I have no idea what you’re talking about, really.
Professor: Good! That means you are in the right class.
Student: I have another question: what’s the best way to learn this stuff?
Professor: Excellent query! Well, each person needs to figure this out on their
1

2 A DIALOGUE ON THE BOOK
own, of course, but here is what I would do: go to class, to hear the professor
introduce the material. Then, at the end of every week, read these notes, to help
the ideas sink into your head a bit better. Of course, some time later (hint: before
the exam!), read the notes again to firm up your knowledge. Of course, your pro-
fessor will no doubt assign some homeworks and projects, so you should do t hose;
in particular, doing projects where you write real code to solve real problems is
the best way to put the ideas within these notes into action. As Confucius said...
Student: Oh, I know! ’I hear and I forget. I see and I remember. I do and I
understand.’ Or something like that.
Professor: (surprised) How did you know what I was going to say?!
Student: It seemed to follow. Also, I am a big fan of Confucius, and an even
bigger fan of Xunzi, who actually is a better source for this quote
1
.
Professor: (stunned) Well, I think we are going to get along just fine! Just fine
indeed.
Student: Professor – just one more question, if I may. What are these dialogues
for? I mean, isn’t this just supposed to be a book? Why not present the material
directly?
Professor: Ah, good question, good question! Well, I think it is sometimes
useful to pull yourself outside of a narrative and think a bit; these dialogues are
those times. So you and I are going to work together to make sense of all of these
pretty complex ideas. Are you up for it?
Student: So we have to think? Well, I’m up for that. I mean, what else do I have
to do anyhow? It’s not like I have much of a life outside of this book.
Professor: Me neither, sadly. So let’s get to work!
1
According to this website (http://www.barrypopik.com/index.php/new
york city/
entry/tell
me and i forget teach me and i may remember involve me and i will lear/),
Confucian philosopher Xunzi said “Not having heard something is not as good as having
heard it; having heard it is not as good as having seen it; having seen it is not as good as
knowing it; knowing it is not as good as putting it into practice.” Later on, the wisdom got
attached to Confucius for some reason. Thanks to Jiao Dong (Rutgers) for telling us!
OPERATING
SYSTEMS
[VERSION 0.90] WWW.OSTEP.ORG

2
Introduction to Operating Systems
If you are taking an undergraduate operating systems course, you should
already have some idea of what a computer program does when it runs.
If not, this book (and the corresponding cour se) is going to be difficult
— so you should probably stop reading this book, or run to the nearest
bookstore and quickly consume the necessary background material be-
fore continuing (both Patt/Patel [PP03] and particularly Bryant/O’Hallaron
[BOH10] are pretty great books).
So what happens when a program runs?
Well, a running program does one very simple thing: it executes in-
structions. Many milli ons (and these days, even billions) of times ev-
ery second, the processor fetches an instruction from memory, decodes
it (i.e., figures out which instruction this is), and executes it (i.e., it does
the thing that it is supposed to do, like add two numbers together, access
memory, check a condition, jump to a function, and so forth). After it is
done with this instruction, the processor moves on to the next instruction,
and so on, and so on, until the program finally completes
1
.
Thus, we have just described the basics of the Von Neumann model of
computing
2
. Sounds simple, right? But in this class, we will be learning
that while a program runs, a lot of other wild things are going on with
the primary goal of making the system easy to use.
There is a body of software, in fact, that is responsible for making it
easy to run programs (even allowing you to seemingly run many at the
same time), allowing programs t o share memory, enabling programs to
interact with devices, and other fun stuff like that. That body of software
1
Of course, modern processors do many bizarre and frightening things underneath the
hood to make programs run faster, e.g., executing multiple instructions at once, and even issu-
ing and completing them out of order! But that is not our concern here; we are just concerned
with the simple model most programs assume: that instructions seemingly execute one at a
time, in an orderly and sequential fashion.
2
Von Neumann was one of the early pioneers of computing systems. He also did pioneer-
ing work on game theory and atomic bombs, and played in the NBA for six years. OK, one of
those things isn’t true.
1

2 INTRODUCTION TO OPERATING SYSTEMS
THE CRUX OF THE PROBLEM:
HOW TO VIRTUALIZE RESOURCES
One central question we will answer in this book is q uite simple: how
does the operating system virtualize resources? This is the crux of our
problem. Why the OS does this is not the main question, as the answer
should be obvious: it makes the system easier to use. Thus, we focus on
the how: what mechanisms and policies are implemented by the OS to
attain virtualization? How does the OS do so efficiently? What hardware
support is needed?
We will use the “crux of the problem”, in shaded boxes such as this one,
as a way to call out specific problems we are trying to solve in building
an operating system. Thus, within a note on a particular topic, you may
find one or more cruces (yes, this is the proper plural) which highlight the
problem. The details within the chapter, of course, present the solution,
or at least the basic parameters of a solution.
is called the operating system (OS)
3
, as it is in charge of making sure the
system operates correctly and efficiently in an easy-to-use m anner.
The primary way the OS does this is through a general technique that
we call virtualization. That is, the OS takes a physical resource (such as
the processor, or memory, or a disk) and transforms it into a more gen-
eral, powerful, and easy-to-use virtual form of itself. Thus, we sometimes
refer to the operating system as a virtual machine.
Of course, in order to allow users to tell the OS what to do and thus
make use of t he features of the virtual machine (such as running a pro-
gram, or allocating memory, or accessing a file), the OS also provides
some interfaces (APIs) that you can call. A typical OS, in fact, exports
a few hundred system calls that are available to applications. Because
the OS provides these calls to run programs, access memory and devices,
and other related actions, we also sometimes say that the OS provides a
standard library to applications.
Finally, because virtualization allows many programs to run (thus shar-
ing the CPU), and many programs to concurrently access their own in-
structions and data (thus sharing memory), and many programs t o access
devices (thus sharing disks and so forth), the OS is sometimes known as
a resource manager. Each of the CPU, memory, and disk is a resource
of the system; it is thus the operating system’s role to manage those re-
sources, doing so efficiently or fairly or indeed with many other possible
goals in mind. To understand the role of the OS a little bit better, let’s take
a look at some examples.
3
Another early name for the OS was the supervisor or even the master control program.
Apparently, the latter sounded a little overzealous (see the movie Tron for details) and thus,
thankfully, “operating system” caught on instead.
OPERATING
SYSTEMS
[VERSION 0.92] WWW.OSTEP.ORG

INTRODUCTION TO OPERATING SYSTEMS 3
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/time.h>
4 #include <assert.h>
5 #include "common.h"
6
7 int
8 main(int argc, char
*
argv[])
9 {
10 if (argc != 2) {
11 fprintf(stderr, "usage: cpu <string>\n");
12 exit(1);
13 }
14 char
*
str = argv[1];
15 while (1) {
16 Spin(1);
17 printf("%s\n", str);
18 }
19 return 0;
20 }
Figure 2.1: Simple Example: Code T hat Loops and Prints (cpu.c)
2.1 Virtualizing the CPU
Figure 2.1 depicts our first program. I t doesn’t do much. In fact, all
it does is call Spin(), a function that repeatedly checks the time and
returns once it has run for a second. Then, it prints out the string that the
user passed in on the command line, and repeats, forever.
Let’s say we save this file as cpu.c and decide to compile and run it
on a system with a single processor (or CPU as we will sometimes call it).
Here is what we will see:
prompt> gcc -o cpu cpu.c -Wall
prompt> ./cpu "A"
A
A
A
A
ˆC
prompt>
Not too interesting of a run — the system begins running the program,
which repeatedly checks the time until a second has elapsed. Once a sec-
ond has passed, the code prints the input string passed in by the user
(in this example, the letter “A”), and continues. Note the program will
run forever; only by pressing “Control-c” (which on UNIX-based systems
will terminate the program running in the foreground) can we halt the
program.
Now, let’s do the same thing, but this time, let’s run many different in-
stances of this same program. Figure 2.2 shows the results of this slightly
more complicated example.
c
2014, ARPACI-DUSSEAU
THREE
EASY
PIECES
剩余261页未读,继续阅读














安全验证
文档复制为VIP权益,开通VIP直接复制

评论0