`
`A Design-Oriented Approach
`
`Charles Crowley
`University ofNew Mexico
`
`J, ROBERT VAN PELT LIBRARY
`MICHIGAN TECHNOLOGICAL UNIVERSITY
`HOUGHTON, MICHIGAN
`
`IRWIN
`e Caracas
`Chicago « Bogota e Boston e Buenos Aires
`London « Madrid e Mexico City @ Sydney e Toronto
`
`Google Exhibit 1121
`Google v. VirtaMove
`
`Google Exhibit 1121
`Google v. VirtaMove
`
`
`
`raplenisnable resources. we at IRWIN can assure you thal every effcr is made fo
`meel or exceed Environmental Protection Agency (EPA) recommendations and require-
`ments fora “greener workplace
`
`
`
`
`
`@@ IRWIN Concerned about Our Environment
`&oe in recognition of the fact that our company is a large end-user of fragile yet
`
`
` To preserve these natural assets, a number of environmental policies, both companywide
`
`| mentally unsafe productswithsafer alternatives
`
`and department-specilic, have been implemented. Fromthe use of 50% recycled paper in
`| our textbooks to the printing of promotional matenals with recycled slock and soy inks to our
`office paper recycling program, we are committed to reducing waste and replacing anviron-
`
`© Richord D.
`
`fewin, a Times Mirror Higher Education Group. Inc., company, 1997
`
`All rrelity reserved, No partof this publication may be
`reproduced, stored in a retrieval system, or transmuted,
`invany form or by any means, electronic, mechanical,
`photocopying, recording, or otherwise, without the prior
`whiten permission of the publisher.
`
`Irwin Book Team
`
`Publisher: Torn Casson
`Senior sponsoring editor: Elizabeth A, Janes
`Senior developmental editor: Kelley Butcher
`Project supervisor: Lynne Basler
`Semor Production supervisor: Lawrie Sander
`Director. Prepress Purchasing: Kimberly Meriwether David
`Compositor: [nferaciive Composition Corporation
`Typeface: /0//2 Times Roman
`Printer: Times Mirror Higher Education Group, Ine, Print Group
`
`FS Times Mirror
`é Higher Education Group
`
`Library of Congress Cataloging-in-Publication Data
`acti
`Crowley. Charles (Charles Patrick’
`Operating systems : a design-oriented approach / Charles Crowley.
`p. em
`Includes bibliographical references and index,
`ISBN 0-256-15151-2
`1, Operating systems (Computers)
`QA76,76.063C77
`1997
`005.4°3—de20
`
`[ Title.
`
`Printed inthe United States of America
`1234567890 WCB32109876
`
`Yb 4708
`
`
`
`To Mom, Pat, Cathy, Ella, and Kendra
`
`APR 18 2002
`
`
`
`PREFACE
`
`In this book [ have tried to approachthe traditional, junior or senior level operating systems
`course ina new way. There are several areas where I have done things differently:
`
`*
`
`*
`
`*
`
`*
`
`Describe the external operating system interface: | start with a description of the sys-
`temcall interface to an operating system.
`Use of code: [have tried to steer a middle course between a concepts approach anda
`case study approach.
`Development of concepts: Lhave tried to show howthe operating system concepts de-
`veloped into their present form,
`Design orientation,
`U have tned to show howideas fromthe design of operating sys-
`tems relate to the design of other types of programs.
`
`EXTERNAL OPERATING SYSTEM INTERFACE
`
`Manystudents come to an operating system class without a clear understanding of what an
`operating systemreally does. These students should understand howoperating systemser-
`vices are used before learning howthese services are implemented. To deal with this, the
`book begins with a simplified, UNIX-like set of system calls. The book includes a discus-
`sion of these calls, example programs using these calls, and a simple shell program tointe-
`grate the examples.
`
`CONCEPTS OR Case STUDIES
`
`There have always been two approaches to the operating systems class. The first approach
`is the concept or theory approach which concentrates on the basic conceptual issues in the
`design of operating systems. These courses discuss each ofthe basic problems in operating
`systems design and the range of common solutions to those problems. The books are
`mostly text and diagrams with very litte code. The second approach ts the case stidy
`method which concentrates on an example operating system that is simple but complete.
`The books contain a lot of code and spend alot of pages explaining the code in detail.
`the
`There are advantages and disadvantages to both approaches, Some people feel
`ideal situation is to take both classes but this is rarely possiblein an already crowded com-
`puter science curriculum so one is required to make a choice.
`
`USE OF CODE
`
`| have tried to find a middle course between the two approaches. This book is basically a
`concepts oriented book with more code than is usual. | have found that seeing actual code
`allows the students to understand the concepts more deeply, feel more comfortable about
`
`ee
`vil
`
`
`
`PRERFAC'E
`
`the material, and ask questions they wouldn't have thought to ask in @ purely con-
`cepts onented course. The code does not comprise a complete operating system how-
`ever and it as simple as possible in order to reduce the amount of pages devoted to
`explaming it.
`
`DEVELOPMENT OF CONCEPTS
`
`| have tried to show howthese ideas developed. Many of the concepts in operating
`systems have developed over many years and the current solutions were developed
`slowly, in several stuges. Each newsolution had a problem that the next solution tried
`to fix.
`| think it helps the student to understand this development and see that these
`ideas were not brilliant flashes of insight that came out of nowhere but ideas that
`were improved by many people over many years. The development was a series of
`good ideas where each tmprovement made sense in the context in which it was de-
`veloped. Seeing this development helps to understand why the solutions have their
`present form. In addition, it ts useful to know the design constraints that caused so-
`lutions to develop into their present form because technological advances often
`change these constraints and old solutions that used to be interior suddenly become
`practical again. Finally these developments give students examples of the design
`process through a series of potential but flawed solutions to a problemto a tinal so-
`lution that is acceptable.
`
`DESIGN ORIENTATION
`
`Finally there 1s a concentration on design. In some ways designing an operating sys-
`tem is a pretty specialized activity having to do mainly with resource management.
`But manybasic design ideas run through all designs and they show up in operating
`systems as much as anywhere else, Throughout the book I note places where we are
`presented with typical design problems.
`| abstract the operating systems related
`problems and solutions from the book into the general design problems and solutions
`and present them in a waythat they can be applied to design problemsin other areas
`of computer science.
`Clearly it is not possible to cover all design topics and issues. | am striving for
`two things. First, | want to give the student an awareness of design issues, where they
`come up. which techniques to apply, how they can be generalized, etc.
`| do not pre-
`sent an organized survey of design techniques but a series of useful ones that come
`up in the context of operating systems. | hope to make the student aware of design
`and to enable the student to start doing their own generalizing about design. Second,
`| present a collection of useful design techniques that the students can use in their de-
`sign toolkit.
`Very few computer professionals wall participate in the design of an operating
`system during the course of their careers. While it is important that students of
`computer science have a good foundation in the basic concepts in specialized areas
`such as operating systems, iL is not necessary that every computer science student
`
`
`
`Pretace
`
`understandall the details, However, there is.a thread running through all areas of
`software engineering: the concept of design. There are manyissued whichare tack-
`led during the design of an operating system which can be generalized and applied
`to other areas of computer science. In this book, | attempt to focus on these design
`issues and their implications for other areas.
`I have oriented this book to provide a solid preparation for the larger design
`projects the student will encounter in later software engineering courses and as
`preparation for their career as a software professional designing, implementing
`and maintaining a wide variety ot systems. This orientation also enables the oper-
`uling systems course follows modern developments in the field of computer sel-
`ence. The interrelations between the separate areas of computer science are
`becoming more important, For example,
`in the area of high speed parallel ma-
`chines. it is clear that
`it is necessary to think of the hardware, the operating sys-
`tem, and the programming language as a single system to get maximum
`performance. Optimization in any part of the system will have consequences for
`the other parts of the system.
`The design techniques are noted in side bars as they come up and longer expla-
`nations of each design topic are placed in separate chapters from the operating svs-
`tem material, The instructor can structure a course with varying degrees of
`concentration on design aspects. The goal is that the design sections are independent
`of the main flow of the text and independent from-each other. This will allow the in-
`structor to pick and choose those design sections he or she finds to be useful.
`
`USING THIS BOOK IN A COURSE
`
`There 1s more material in this book than can be comfortably covered in a One-semester
`course. A numberof the sections of the book have been marked with an asterisk. This
`indicates that they can be skipped with no loss of continuity in the presentation. In ad-
`dition, all of the design chapters and design sidebars can be skipped with no loss of
`continuity. If you skip all the design chapters you can probably just cover the book ina
`semester. | expect that most instructors will choose to skip some ofthe design sections
`und some of the optional sections and teach a course that 1s about 90 percent operating
`systems and 10 percent design issues. Alternatively, the design issues could be covered
`Ina separate one-unit course, strictly on design, that is taken along with the operating
`systems COUrse,
`
`ACKNOWLEDGMENTS
`
`| want to thank my colleague Barney Maccabe whostarted out as my co-author on
`the book but had too many other commitments to work on the book. Our discussions
`lead to the conception of the book and the design orentation. | have talked with Bar-
`ney on many aspects of operating systems and computer science and those discus-
`sions shaped many of my ideas.
`
`
`
`PREFACE
`
`| also want to thank John Brayer whoused drafts of the book in several of his op-
`erating systems courses and put up with many typos, badly written sections, and un-
`finished sections. His comments helped in the development ofthe book.
`| also want to thank my other colleagues in the Computer Science Department al
`the University of New Mexico. Continuing “in-the-hall” discussions with them have
`helped me formulate and improve my ideas.
`Manystudents in CS 48] have used drafts of the books and have provided man
`useful comments and suggestions. I want to particularly thank Dave Rosenbaum who
`provided extensive comments on the entire draft, found numerous errors and typos
`and taught me somethings about wnting good English as well.
`My treatment of the design chapters was greatly influenced by the design pat-
`terns developments in recent years and particularly the fine book by Gammaet el.
`(1995). Lused their presentation format in the design chapters.
`| want to thank all the people whoreviewed this book while it was being devel-
`oped,
`| corrected many problems and got many ideas for the presentation fromtheir
`careful reviews and comments. The design chapters especially profited from their
`comments.
`
`* Mustaque Ahamad, Georgia Institute of Technology
`*
`Jim Alves-Foss, University of Idaho
`*
`Anish Arora, The Ohio State University
`*
`Brent Auernheimer, California State University - Fresno
`*
`Anthony Q, Baxter, University of Kentucky
`* Mahesh Dodani, University of lowa
`*
`—H. George Friedman, Jr., University of Hlinots - Urbana
`*
`Tim Gottleber
`
`Stephen J. Hartley, Drexel University
`*
`Giorgio P. Ingargiola, Temple University
`*
`StephenJ. Krebsbach, South Dakota State University
`*
`Donald S. Miller, Arizona State University
`*
`* Matt W. Mutka, Michigan State University
`*
`Richard Newman-Wolfe, University of Florida
`*
`Steve Reichenbach, University of Nebraska - Lincoln
`*
`Bernhard Weinberg, Michigan State University
`Finally my wife, Ella Sitkin, put up with many bad moods and excusesthat | was
`“too busy” during the years this book was developed. As if that wasn't enough, she
`also edited several chapters.
`:
`
`
`
`This material may be protected by Copyright law (Title 17 U.S. Code)
`
`
`
`Cu ALP TER 34
`
`
`
`1.1 WHERE DOES AN OPERATINGSYSTEM FITIN?
`
`OPE iatingy sysiem
`
`An operating system1s the layer of a computer system between the hardware andthe
`user programs (user software). (See Figure |.1.) An operating system does what all
`sottware does: it implements some desired functionality by building on the function-
`ality available imlower levels. Software transforms one interface into another inter-
`face. For example, a BASIC mterpreter transforms a computer into a BASIC
`machine. 4 statistical package transforms a computer into a statistics machine, a
`computer game program transforms a computer into a game machine, ete.
`An operating systemis built directly on the hardware interface and provides an
`interface between the hardware andthe user programs. The first thing we will do in
`this book ts look at exactly what kind ofinterface the operating system implements.
`Then. in the rest of the book, we will look at how the operating systems interface 1s
`implemented,
`A computer system, as it comes “out of the box,” is not easy to use—it requires
`un operating system and application software to run on it, An application software
`package. as it comes “out of the box” (or “out of the shrinkwrap”™), will not run di-
`rectly on the computer hardware—it requires an operating system to run it.) An op-
`erating system is the layer of software that nearly every application software
`package expects to be present. The operating system ts the first program run on a
`computer when the computer boots up. There can be only one operating systemrun-
`ning on a computer.”
`
`The operating systemis thelayer between the hardware and the software
`
`1.1.1
`
`Sysrem LeEveLs
`
`hardware interface
`
`operating system interface
`
`Figure 1.1 illustrates the layered structure of the hardware. the software, and the
`operating system, The hardware interfuce consists ofthings like program counter,
`registers,
`interrupts, disks,
`terminals, etc. The hardware interface consists of
`everything you need to know about the hardware in order to write programs that
`will execute on the hardware. In Chapter 2. we describe the hardware interface for
`the example hardware used in this book. The operating system interface is de-
`scribed in Chapter 3.
`
`‘This is nol true in all cases. There are some special programs that are intended to be run onthe bare hard-
`wore One example would be a program that fixes disk problems. These are special cases, however. and
`are not'common
`"Technically this is not.olways true since if js possible to have o “virtual” operating system that runs other op-
`erating systems. The correct statement is thal only one operating system is in direct central of the hardware
`at any one time
`
`
`
`Introduction
`
`3
`
`User programs
`
`Operating system intertace
`
`
`
`|
`
`Operating system
`
`Hardware interface
`
`
`
`Hardware
`
`Figure 1.1
`
`Levels in.a computer system
`
`An operating system shares characteristics with both hardware and software. An
`operating system 1s software, that 1s, it is a program that is compiled, linked, and run
`on a computer. However, it is like hardware in that only one copyof the operating
`systemruns ona computer and it extends the capabilities of the hardware. The ser-
`vices of the operating system are invoked with a special “trap” or “system call” in-
`struction that is used just like any other hardware instruction.
`
`the upper
`
` DESIGN TECHNIQUE: TWO-LEVEL IMPLEMENTATION
`
`An operating system is a lower level of software that
`to implement 4 language that
`lower level
`user programs run on. Together they form a two-level
`level is written in.
`Two-level implementations are especially usetul when
`structure where the operating system implements
`the lower level can be reused by more thun one upper
`funchionality used by the user program. This idea is
`level. This ts the case with an operating system and most
`called a pwe-level
`imiplemenration and i is seen in
`languages, A good lowerlevel can be reused manytimes.
`many places in computer science. We wall see several
`Two-level
`implementations are used in operating
`more examples later in the book.
`A programming language is another example. It is
`systems lo separate mechanism from poliey. A mecha-
`nism is a set of basic facilities that can be used in muny
`the lower level used to implement programs, Special-
`purpose languages are an even better example. The
`ditferent ways. For example, a programming language 1s
`a mechanism for writing programs. A policyis the use of
`special-purpose language provides low-level primi-
`a mechanism for a particular purpose—tfor example, a
`tives tor solving certain kinds of problems, and the user
`writes programs in that language. Some examples are
`programto solve a specific equation. An example from
`the 4GL languages for producing reports from database
`operating systems is the protection of tiles. UNIX pro-
`information, and spreadsheet macro languages.
`vides a protection mechanism that determines whether
`other people can read, write. or execute yourfiles. You
`Ina two-level implementation, you use the “divide
`decide on the policy, that is, which files are readable,
`und conguer” strategy by dividing the problem inte
`two parts and solving each part separately, A two-level
`writable, or executable. The distinction between mecha-
`nism and policy ts a basic concept in operating systems
`Implementation ts a special case of a modular imple-
`and will reappear in manyplaces in this book.
`mentation, but the two-level case occurs se often that it
`is useful to discuss it as a separate design technique
`You can learn more about two-level implementa-
`trom modular implementation.
`It
`is common for the
`tions in Section 4.4.
`
`
`
`
`EASES ESR
`
`al
`
`
`1.2.) WHAT DOES AN OPERATING SYSTEM DO?
`
`The functions of an operating system can be viewedin two ways:
`
`+
`*
`
`Asa resource manager.
`Asan implementor of virtual computers.
`
`By virtual computer we mean an implementation of the functionality of a computer
`in software. In this section we will introduce both viewpoints.
`
`An operating sysiem is a resource manager and a virtual computer manager.
`
`1.2.1.
`
`HarpWARE RESOURCES
`
`hardware resource
`
`The operating system manages the hardware resources of the computer system. The
`main hardware resources in a compuler systemare:
`
`«
`
` Processor—the processoris the part of the computer system capable of execut-
`ing instructions.
`* Memory—the memorycontains all instructions and data used by a processor.
`Input/output (1 O) controllers—processors that know howtotransfer data be-
`tween memory and devices.
`Disk devices—disks provide long-term storage for data.
`Other devices—hardware components that accept data from or generate datafor
`[/O controllers. Examples are terminals, networks, tape drives, ete.
`
`«
`
`Figure |.2 showsthe resources in a computer system.
`
`Controller
`
` Ane
`
`Primary resources
`(Computing)
`
`Figure 1.2
`
`The hardware resources in a computer system
`
`Secondary resources
`(Interfaces and long-term Storage)
`
`
` 10
`
`Memory
`Processor
`
`
`
`eee
`
`2
`
`
`
`1.2.2
`
`ResouRCE MANAGEMENT
`
`Resource MANAZEMENT Is:
`
`Introduction
`
`faqource mohpagemen!
`
`«
`
`Transforming—crealing a new resource from an existing resource. The created
`resource will act as a substitute for the existing resource but will be easier to use
`© Multiplexinge—creating the illusion of several resources from one resource.
`=
`Scheduling—deciding which programs should get each resource and when thes
`should get iL.
`
`To give a more concrete meaning for transformation and multiplexing, we con-
`sider the construction of muluple virtual printers— onefor each virtual computer
`
`Transformation Hardware resources have moderately complex interfaces. The hard-
`ware interface to a printer might Consist of a data register, a control register. and a status
`register. To send a character to the printer, you need to poll (repeatedly read) the status
`register until it indicates that the printer 1s ready to accept the next character. Once the
`printer is ready, the data value needs to be written to the data register and a “send”
`command written to the control register. None ofthis is particularly difficult, but it
`ts
`tedious and error prone: you need to knowthe addresses of the data, control. andstatus
`registers and you needto Knowthe structure ofthe bits in the control and status registers
`Operating systems transform physical resources into virtual resources to avoid
`the difficulties associated with using hardware resources. A virtual resource provides
`the essential functionality of the hardware resource, but is easier to use because the de-
`tails of the hardware interface are hidden. For example. an operating system might
`provide a virtual printer that is capable ofprinting a character. To use this virtual re-
`source, an application only needs to specify the character to be printed, The virtual
`printer provides the essential functionality ofthe hardware printer, while the operating
`system handles the details that make the hardware interface difficult to use (register
`addresses, register formats, and wait-until the printer is ready for each character)
`
`Operating systems transform physical resources into virtual resources that provide functionality which
`is similar to the physical resources, but have a simplerinterface.
`
`fraonstormoliay
`
`Wittig) (source
`
`Multiplexing When there are more virtual computers than physical resources, the
`operating system needs to make sure that the virtual computers can share the physical
`resources. The sharing of physical resources 1s called mud/tiplexing. Continuing with
`our printer example, suppose your system only has one printer. [f you run two or
`more applications. the operating system needs to make tt appear as if each virtual
`computer has its own printer. That is, the operating system needs to makesure that
`the characters printed by one virtual Computer are not mixed with the characters
`printed by another virtual computer.
`
`multiplexing
`
`
`
`smOoinGFs
`
`Hmescivision PU ee try
`
`time-sharing
`
`spacedivision multiplexing
`
`spocesharing
`
`EH APTER 1
`
`‘To create the illusion of multiple printers, the operating system can implement a
`virtual printer using a disk file. In this solution, each virtual computer has its own
`“printerfile.” Every time the application prints a character, the operating system sim-
`ply appends the character to the end of the printer file which belongs to the virtual
`computer being used for that application. When the application finishes, the operat-
`ing system queues the application’s printer file. The software that drives the physical
`printer only prints files.
`Historically this solution was called spooling. and the application's “printer file”
`Is Called a spool file.SPOOL1s an acronym for Simultaneous Peripheral Operations
`On Line, Simultaneous refers to the fact that two or more virtual Computers can issue
`printer operations at the same time. Online refers to the fact that the hardware printer
`is connected to the same computer as the virtual printers are running on. Thealterna-
`live to on-line printing ts to write the print file to a tape andprint the tape on a differ-
`ent computer. See Section 5.16.1 for a more detailed explanation ofoff-line printing.
`Our printer example illustrates a simple form of fime-division multiplexing. In
`time-division muluiplexing, the resource 1s usedfor different virtual computers at dit-
`ferent mes. In manycontexts, ime-division multiplexing ts called tume-s/ariig.
`This form of ume-division multiplexing 1s relatively simple because the printer
`does not begin printing the output for a virtual computer until the application 1s fin-
`ished. Moreover,the printer finishes printingall of the output for one virtual computer
`before it starts to print the output for another virtual computer. Other instances of
`time-division multiplexing may involve switching between virtual resources while
`they are still being used by applications. Time-division multiplexing is appropriate
`when the resource cannot be divided into smaller versions ofitself,
`In space-diviston multiplexing, a resource 1s divided into smaller versions of 1t-
`self and each virtual computer is given a part of the resource. Space-division multi-
`plexing 1s used in muluplexing primary and secondary storage (memory anddisks).
`Although not commonly used.
`the term space-sharing is a synonym for space-
`division multiplexing,
`
`Multiplexing (sharing) of a single physical resource involvesdividing the resource based on time or
`space.
`
`An operating systemmultiplexes, transforms, andallocates hardware resources.
`
`1.2.3) Virruat COMPUTERS
`
`AN operating system creates software copies of the processor (the capability to
`execute instructions) and the memory(the capability to store information).
`It also
`
`
`
`Introduction
`
`transforms the disk devices into a file systemandthe other input-output devices into
`more abstract (less detailed) and easily used devices. Thus an operating system:
`
`«
`
`*
`
`*
`
`Creates multiple procesyes (simulated processors) out of the single processor
`and allocates them to programs.
`It accomplishes this by time-multiplexing the
`processor.
`Creates muluple address spaces (memory fora process to run in) out of the mem-
`ory and allocates them to processes. It accomplishes this by space-multiplexing
`the processor,’
`Implements a fi/e system and input/output (1/O) system so that processes can
`easily use and share the disks. It accomplishes this by space-multiplexing the
`disks and time-multiplexing the | O channels.
`
`The operating system creates what we will call virtual computers from the phys-
`ical computer. The first thing we need to look at is how a virtual computer differs
`from the physical computer.
`The most significant difference is that there are many virtual computers while
`there 1s only one physical computer. The operating system creates the illusion of
`many virtual computers by transforming the single, physical computer. Figure 1.3
`shows the structure.
`Each virtual computer ts similar to the physical computer in many ways but it is
`easier to use than the physical computer.
`| O, and sec-
`A computer has four basic parts: processor, primary memory,
`ondary memory, Let us look at each of these in turn and see howour virtual computer
`differs from the physical computer.
`
`PIGtess
`
`address spoce
`
`file system
`
`virtual compuier
`
`User
`Process
`
`Liser
`Provess
`
`Physical Computer
`
`Figure 1.3
`
`Multiple virtual computers in an operating system
`
`|
`
`"Virtual memory systems time-multiples memory
`
`
`
`CHAPTER 1
`
`Computing requires @ processor and some memory.
`
`SSeeSeeee
`1.30
`A VIRTUAL COMPUTER
`
`A virtual computeris a Computer implementedin software using the hardware resources
`of the physical computer, It has the same four basic components (processor, memory,
`[ O, anddisk) as the physical computer. Each virtual resource will be a transformedand
`multiplexed version of the physical resource. Figures 1.4, 1.5, 1.6, and 1.7 show the
`multiplexing of the four virtualized resources. Note that all of the multiplexing 1s done
`in the same way: the physical resource 1s broken up into discrete pieces andthese pieces
`are put together to create the virtual resources.
`In some cases the pieces are spatial
`(space-multiplexing) and in some cases they are pieces of time (time-multiplexing).
`In the next few sections we will describe the ways in whichthese resources ure
`transformed into virtual resources.
`
`Operating systems create virtualcomputers that can solve the sameproblems as a real computer, but
`that areeasier to use.
`
`1.3.1
`
` Virtruat PROCESSOR
`
`The virtual processor has nearly the same interface to the user as the physical proces-
`sor, that is, it has nearly the same set of instructions, One reason for this ts that it 1s
`implemented by using the physical processor directly. The operating system will
`rapidly switch the services of the physical processor between the virtual computers
`to implementthe virtual processors.
`The operating system removes some of the physical processor instructions and
`adds some other operations. The instructions it removes are the ones that control the
`physical resources of the computer (processor, memory, | O). Theseare the instruc-
`tions that affect access to memory, provide direct access to the devices, and change
`the protection state of the processor. In return for the instructions, the operating sys-
`tem adds instructions that allowthe virtual processor to request virtual resources
`from the operating system. These instructions are called system calls. System calls
`allow a programmer to:
`
`-
`*
`*
`*
`
`*
`
`Create new virtual computers:
`Communicate with other virtual computers:
`Allocate memory as needed:
`DoTI/O; and
`
`Access a sophisticated file system.
`
`system. call
`
`
`
`Virtual Process (VP; |
`
`Virtual Process (WP)
`
`Time
`Slices
`
`Interface
`
`Virtual
`Interface
`
`Physical
`
`VP,
`
`VP,
`
`VP,
`
`VP,
`
`VP,
`
`VP.
`
`Figure 1.4
`
`Multiplexing the processor by time-slicing
`
`Virtual Memory (VM, |
`
`Virtual Memory (VM)
`
`*
`
`;
`
`'
`
`'
`
`,
`
`y
`
`si
`
`:
`
`Physical
`Memory
`
`¥
`
`;
`
`"
`
`;
`
`,
`
`é
`
`i
`
`f
`
`7
`
`i
`
`4
`
`4
`
`;
`
`é
`
`i
`
`i
`
`“lt
`
`y|
`
`}
`
`i
`
`f
`
`é
`
`.
`
`i
`
`i
`
`j
`
`u
`
`#
`
`Virtual
`Interface
`
`Physical
`Interface
`
`VM,
`
`VM;
`
`Figure 1.5
`
`Multiplexing the physical memory by dividing it into pieces
`
`1/0), for P
`
`1/0, for P;
`
`Virtual
`
`i /|Interface‘ i
`os
`‘
`/
`i
`a
`M4
`r
`
`
`
`
`
`,
`
`4
`
`ry
`
`‘.
`
`'
`
`.
`Tine
`a ——e
`Slices
`
`‘
`
`oh
`
`‘
`
`x
`
`i
`
`\:
`
`i
`
`if
`
`/
`
`/
`
`f
`
`L
`
`/
`
`i
`
`ay
`Nie
`
`Py
`
`P,
`
`;
`
`of
`
`i
`
`i
`
`'
`
`it
`
`é
`
`Physical
`,
`Interface
`
`Figure 1.6
`
`Multiplexing the |/© processor by sequential use
`
`File]
`
`!
`
`Te
`
`Fite 2
`
`
`Bi
`
`a
`
`: Virtual
`
`Interface
`
`Interface
`
`Figure 1.7
`
`Multiplexing the disk by dividing it into pieces
`
`Physical
`
`
`
`CHARTER 7
`
`Modern processors provide systemcall instructions precisely because operating sys-
`tems need them to provide users with safe access to operating system services.
`We can summarize the relationship in the equation (where P is a processor):
`
`Pvouat = Popywcat ~ (Dangerous instructions} + {Useful replacements |
`
`The virtual processor does not change the instruction set of the physical processor
`very much since the main goal ofthe operating system 1s to create virtual copies of
`the processor. Creating an improved virtual instruction set is a complex job and1s
`done by compilers and interpreters.
`Modern processors make removing the resource control instructions easy by provid-
`ing two processor modes: system anduser. In user mode. the instructions that control the
`physical resources of the computer are not allowed. Processors have processor modes pre-
`cisely because operating systems need themto provide a safe virtual processor. The oper-
`ating systemis managing the hardware resources of the computer and it must keep control
`of them. Itallows the virtual computer to use these resources but not to control them.
`
`1.3.2 VirruAL PRIMARY MEMORY
`
`The memoryofthe virtual computer is very similar to the hardware memory,that is. it
`is a long sequence ofcells with sequential, numerical names. The operating system will
`divide up the physical memoryinto parts and give a part to each virtual computer. The
`operating system usually creates. with help from the hardware, the illusion that
`the
`memoryseen by each virtual computer ts named with numerical namesstarting at 0. The
`operating system mayalso create the illusion that the virtual computer has more mem-
`ory than the physical computer has physical memory. This is called virtual memory.
`The programming language concept of an array 1s taken directly fromthis model
`of memory, so you are already familiar with the software emulation of physical
`memory, although you may not have realized it.
`
`1.3.3 VirTuar SECONDARY MEMORY
`
`Secondary storage provides long-term storage for data, This is done physically on
`disk blocks and virtually in disk files. The virtual computersees a file system con-
`sisting of hierarchically namedfiles that can be of any size and can be read and writ-
`ten in any size units. A considerable amount of operating system codeis required to
`create this illusion.
`
`1.3.4 VirruaLl O
`
`The I O operations ofthe virtual computer are completely different than t