introduction to computer science...examples of operating systems u microsoft family v msdos, windows...
TRANSCRIPT
Introduction to Computer ScienceCSCI109
AndrewGoodneySpring2018
China– Tianhe-2
Lecture8:OperatingSystemsMarch5th, 2018
ìOperating SystemsWorkingTogether
1
ScheduleDate Topic Assigned Due Quizzes/Midterm/Final
8-Jan IntroductionWhatiscomputing,howdidcomputerscometobe?
HW1
15-Jan MLKHoliday
22-Jan ComputerarchitectureHowisamoderncomputerbuilt?Basicarchitectureandassembly
29-Jan DatastructuresWhyorganizedata?Basicstructuresfororganizingdata
HW1Quiz1onmaterialtaughtinclass1/8and1/22
30-Jan
5-Feb DatastructuresTrees,GraphsandTraversals
HW2
12-FebMoreAlgorithms/DataStructures,ComplexityandCombinatorics Recursionandrun-time
Quiz2onmaterialtaughtinclass1/29,2/5
19-Feb PresidentsDay
23-Feb
26-Feb Algorithmsandprogramming(Somewhat)Morecomplicatedalgorithmsandsimpleprogrammingconstructs,compilers
HW2Quiz3onmaterialtaughtinclass2/12
5-Mar Operatingsystems WhatisanOS?Whydoyouneedone? HW3Quiz4onmaterialtaughtinclass2/26
12-Mar SpringBreak
19-Mar Midterm MidtermMidtermonallmaterialtaughtsofar.
26-Mar ComputernetworksHowarenetworksorganized?HowistheInternetorganized?
HW3
2-Apr ArtificialintelligenceWhatisAI?Search,plannningandaquickintroductiontomachinelearning
HW4Quiz5onmaterialtaughtinclass3/26
6-Apr
9-Apr Thelimitsofcomputation Whatcan(andcan't)becomputed?Quiz6onmaterialtaughtinclass4/2
16-Apr RoboticsRobotics:backgroundandmodernsystems(e.g.,self-drivingcars)
HW4Quiz7onmaterialtaughtinclass4/9
23-Apr Summary,recap,review Summary,recap,reviewforfinalQuiz8onmaterialtaughtinclass4/16
4-MayFinalonallmaterialcoveredinthesemester
Finalexam11am-1pminSAL101
LastdaytodropaMonday-onlyclasswithoutamarkof“W”andreceivearefundorchangetoPass/NoPassorAuditforSession001
Lastdaytodropacoursewithoutamarkof“W”onthetranscript
Lastdaytodropaclasswithamarkof“W”forSession001
2
Agenda
u Talkaboutoperatingsystemsu Reviewquizzes1-3(midtermstudying)
u Takequiz4
3
Operating Systems
uWhatisanOS?uThekernel,processesandresources
uProtection/Isolation/SecurityuCompetingfortimeuCompetingforspace
4
Reading:St.Amant Ch.6
The need for an OS
5
CPU,Memory,Disk,I/OProgram
Problem
Solution:Algorithm+DataStructures
Pseudocode
Low-levelinstructions
Executeson
Compilesto
The OS as a executive manager
6
CPU,Memory,Disk,I/OProgram
Problems
Solution:Algorithms +DataStructures
Pseudocode
Low-levelinstructions
Executionsmanagedby
Compileto
Low-levelinstructionsLow-levelinstructions
ProgramProgramProgram
OperatingSystem
What is an Operating System?
uAnexecutivemanagerforthecomputeruManagesresources
v Space(i.e.memory)vTime(i.e.CPUcomputetime)vPeripherals(i.e.inputandoutput)
uOSisaprogramthatstarts,runs,pauses,restarts,andendsotherprograms
u (somecontentfromthefollowingslidesiscourtesyofMarkRedekopp andCS350)7
8
4
Definition
• A piece of software that manages a computer’s resources
• What resources need managing?– CPU (threads and processes)– Memory (Virtual memory,
protection)– I/O (Abstraction, interrupts,
protection)DISK
Processor
Mem. Management Unit
Network
Graphics
I/O Drivers & Protocols
File Systems
Memory Translation
Processes & Scheduling
System Library
System Library
User App User App
Ker
nel
Mod
eH
ardw
are
Use
r m
ode
Examples of Operating Systems
u MicrosoftFamilyv MSDOS,Windows3.1– 98,WindowsNT ->Windows10v Predominatelyx86(Intel)hardware,somePowerPC,someARMv FreeDOS
u POSIX(UNIX/like)v macOS,FreeBSD,openBSD,netBSD,Solaris,AIX,andothers
u Runonmostprocessorarchitecturesv iOSv Linux
u Littlesideprojectofuniversitystudentu ”UNIXclone”thatwonthewaru 20+populardistributionsu Android:heavilycustomizedLinuxandJavaonphone/tablet
u Othersv PlaystationOS,VxWorks
9
10
11
8
Genealogy of Operating Systems
Figure 1.9,OS:PP 2nd Ed.
Important Vocabulary
u Resourcev Somepartofthecomputerthatprogramsuse:
u Memory,CPU,Input/Output devices
u Policyv Rulesenforcedbyalgorithmsthatshareaccesstoresources
u OSDevelopers(humans)writepoliciesthatachievesomesetofgoalsfortheoperatingsystems
12
What does an Operating System do?
uAbarecomputerisjusthardwareuProgramsarewrittentousethathardware,butexclusiveuseisinefficient
uInsimpleterms,theOS:v Enablesmorethanoneprogramatatimetousethecomputerhardware
v Presentcomputerresources(CPU,disk,I/O)throughabstractinterfacestoallowsharing
v Enforcepoliciestomanage/regulatethesharingofresources
13
Roles
14
9
Roles
• Textbook regularly revisits 3 roles an OS plays:
• Referee
– Protection against other applications
– Enforce fair resource sharing
• Why doesn't an infinite loop require a reboot?
• Illusionist (Virtualization)
– Each program thinks it is running separately
– Each program thinks it has full access to computer's resources (or unlimited
resources)
• Glue
– Common services (such as copy/paste)
– Files can be read by any application
– UI routines for look & feel
– Separate applications from hardware
• so you don’t need to know which keyboard, disk drive, etc
OS Design Criteria
u Reliability(andavailability)u Security&Privacy
u Performanceu Portability
15
Reliability and Availably
u Reliablesystemsworkproperlyv Correct(orexpected)outputsaregeneratedforasetofinputsv Ifthisisnotthecase,thesystemhasfailed
u Examples?
u Availablesystemsareavailabletodoworku Availabledoesnotimplyreliable
v Systemcanbeavailablebutnotreliable(systemhasbugs,generateswrongresults)
v Systemcanbereliablebutnotavailableu Crashevery5minutes,butsavesresultsandrestarts5minuteslater
16
Privacy, Security, Isolation
u ForanOSsecuritymeanstheOSdoesnotrununintendedcodeorgetintoacompromisedstatev Novirus/malware
u OSprivacymeansprogramsshouldnotgetaccesstodatatheyshouldnothavev Passwordkeychains,filesinotherusersdirectories
u SecurityandPrivacyrequiresometradeoffswithperformance,whichiswhyOS’sarenot100%securev Somearebetterthanothers!
17
Portability
u Manymachinetypesexist:x86,x86_64,PPC,ARM,MIPSu Manydifferentmotherboardsorhardwareplatformsexist:serverwith8CPUs12PCIe slotstoRaspberryPi,toAppleTV,etc.
u OSwithgoodportabilityabstractsthesedifferencesintoastableAPIsoprogrammersdon’tnotice
u Also,cantheOSitselfbeportedtonewhardwareeasily?
u Goodportabilityleadstowideadoptionv Linux,Windows
18
Performance
u Whatdoesperformancemean?v Lotsofcomputation?v FluidGUIforgame?v Lowlatencydiskfordatabase?
u OSbalancesthesewithpoliciesv Majoraxisisthroughputvs.responsetimev DifferentOS’saretunedbasedonusecasev DBserverhasdifferentpoliciesthanWindowsgamingrig
19
Examples of Policies
uTasksaregivenpriorities;higherprioritytasksarehandledfirst
uSomekindoftasksareneverinterrupteduAlltasksareequalpriority;round-robinuSometaskscanonlyusepartofadiskuSometaskscanusenetwork
20
The kernel
uThekernelisthecoreofanOSuKernelcoordinatesotherprogramsuWhenthecomputerstartsupthekerneliscopiedfromthedisktothememory
uKernelrunsuntilsomeotherprogramneedstousetheCPU
uKernelpausesitselftorunotherprogram21
How memory is used
22
FreeMemory
FreeMemory
Kernel
FreeMemory
ExecutingProgram
Kernel
FreeMemory
Kernel
Start Kernelloaded
Userprogramruns
Userprogramdone
Multitasking
uOneprogramusestheCPUatatimeuOSswitchesCPUusage(rapidly)uCreatesanillusionthatalltheprogramsarerunningatthesametime
uChangeoverfromoneprogramtoanotheriscalledacontextswitch
uExamplesofcontextswitching?uCancontextswitchingbegoodforaprogram?uCancontextswitchingbegoodforaCPU?
23
Abstractions: Processes and Resources
uResourcesv Space(memory)v Time(CPU)v Peripherals(printersetc.)
uProcess:anexecutingprogramv Programcounterv Contentsofregistersv Allocatedmemory&contents
24
uOSdoesn’tworryaboutwhateachprogramdoes
u InsteadOScaresaboutv Whatresourcesdoesaprocessneed?
v Howlongwillitrun?v Howimportantisit?
Protection/Isolation
uOtherprocesseshavetobepreventedfromwritingtothememoryusedbythekernel
uCrashinoneprogramshouldn’tcrashOSorotherprograms
uOShasaccesstoallresources:privilegedmodeuUserprogramshaverestrictedaccess:usermodeuWhenauserprogramneedsaccesstoprotectedresourcesitmakesasystemcall(e.g.,managingfiles,accessingaprinter)
uPrincipleofleastprivilege (kernelhashighestprivilege)
25
Competing for time
uThinkofthetimetheCPUspendsinchunksorblocks
uHowcanblocksoftimebeallocatedtodifferentprocessessothatworkcanbedoneefficiently?
uPolicy:rulestoenforceprocessprioritization
26
Process Scheduling Policies
uTheprocessqueueuRound-robinuFirst-come,first-serveduPriority-based
v Presetpriorityforeachprocessv Shortest-remaining-time
uAllthesepolicieskeeptheCPUbusyuArethereotherwaystojudgeapolicy?
27
Keeping CPU busy
28
How to evaluate a policy?
CPUutilization Throughput Latency Fairness
Round-robin Good Variable Potentiallyhigh
YesNostarvation
First-comefirst-served
Good Variable Yes
Shortestremainingtime
Good High Potentiallyhigh
NoCouldhavestarvation
Fixedpriority Good
29
u Utilization:howmuchworktheCPUdoes
u Throughput:#ofprocessesthatusetheCPUinacertaintime
u Latency:averageamountoftimethatprocesseshavetowaitbeforerunning
u Fairness:everyprocessgetsachancetousetheCPU
Everyday policies
uPlanestakingoff:firstcomefirstservedv Highefficiencyfortherunwayv Ifseveralsmallerplanesinlinebeforealargeone,notefficientfortheaveragepassenger
uTrafficbeingdirectedataccident:roundrobinv Firsttrafficinonedirection,thenanotherv Ifapolicecararrives,thenswitchtopriority-basedv Unlikelytoeverbeshortestremainingtime
30
First-come, first serve (non-pre-emptive)
31
Round Robin (pre-emptive)
32
Weighted Round Robin
33
Shortest-time Remaining
34
Competing for space
uUnliketime,spacecanbereused
uWhenaprocessisrunning,itisallocatedasingleregionofmemory
uWhenaprocessfinishesrunning,thememoryallocatedtoitisgivenbacktotheOS
u Fragmentation35
Kernel
A
B
CD
E
Kernel
A
D
Dealing with fragmentation
uMovememoryallocationaroundallthetimeinthebackgroundsowhenanewprocessneedsmemory,thereisalargeenoughcontiguousblocktoallocate
u Indirectionv Physicalmemoryordering:memorydividedintofixedsizeblockscalledframes
v Logicalmemoryordering:inlogicalmemoryeachframecorrespondstoapage(arenumberedframe)
v Whenaprocessusesmemoryassignedtoit,ituseslogicaladdresses;theOStranslateslogicalmemorylocationstophysicalmemorylocations
36
Virtual memory
uUseindirectiontopretendRAMisbiggerthanitisuDemandpaging
v Whenaprocessstarts,theOSdoesn’tallocateitallthememoryitneeds
v Insteadonlyallocatememoryneededtodoimmediateworkv Keeprestoftherequestedmemoryinsecondarystorage(disk)v Ifapageinmemoryisn’tusedforawhile,it’smovedtodiskv Whenapageisneededbyaprocess,it’scopiedfromdisktoRAM
uOtherexamplesofvirtualization:virtualenvironments(renderondemand),half-courtbasketball,etc.
37
The need for an OS
38
CPU,Memory,Disk,I/OProgram
Problem
Solution:Algorithm+DataStructures
Pseudocode
Low-levelinstructions
Executeson
Compilesto
The OS as a executive manager
39
CPU,Memory,Disk,I/OProgram
Problems
Solution:Algorithms +DataStructures
Pseudocode
Low-levelinstructions
Executionsmanagedby
Compileto
Low-levelinstructionsLow-levelinstructions
ProgramProgramProgram
OperatingSystem
Quiz #4
40
http://bit.ly/2FdlyCD