Introduction to Computer Science
CSCI 109
Andrew Goodney
Spring 2018
China – Tianhe-2
Introduction to Computer Science CSCI 109 China Tianhe-2 Andrew - - PowerPoint PPT Presentation
Introduction to Computer Science CSCI 109 China Tianhe-2 Andrew Goodney Spring 2018 Lecture 8: Operating Systems March 5 th , 2018 Operating Systems Working Together 1 Schedule Date
Spring 2018
China – Tianhe-2
Working Together
1
Date Topic Assigned Due Quizzes/Midterm/Final 8-Jan Introduction What is computing, how did computers come to be? HW1 15-Jan MLK Holiday 22-Jan Computer architecture How is a modern computer built? Basic architecture and assembly 29-Jan Data structures Why organize data? Basic structures for
HW1 Quiz 1 on material taught in class 1/8 and 1/22 30-Jan 5-Feb Data structures Trees, Graphs and Traversals HW2 12-Feb More Algorithms/Data Structures, Complexity and Combinatorics Recursion and run-time Quiz 2 on material taught in class 1/29, 2/5 19-Feb Presidents Day 23-Feb 26-Feb Algorithms and programming (Somewhat) More complicated algorithms and simple programming constructs, compilers HW2 Quiz 3 on material taught in class 2/12 5-Mar Operating systems What is an OS? Why do you need one? HW3 Quiz 4 on material taught in class 2/26 12-Mar Spring Break 19-Mar Midterm Midterm Midterm on all material taught so far. 26-Mar Computer networks How are networks organized? How is the Internet organized? HW3 2-Apr Artificial intelligence What is AI? Search, plannning and a quick introduction to machine learning HW4 Quiz 5 on material taught in class 3/26 6-Apr 9-Apr The limits of computation What can (and can't) be computed? Quiz 6 on material taught in class 4/2 16-Apr Robotics Robotics: background and modern systems (e.g., self-driving cars) HW4 Quiz 7 on material taught in class 4/9 23-Apr Summary, recap, review Summary, recap, review for final Quiz 8 on material taught in class 4/16 4-May Final on all material covered in the semester Final exam 11 am - 1 pm in SAL 101 Last day to drop a Monday-only class without a mark of “W” and receive a refund or change to Pass/No Pass or Audit for Session 001 Last day to drop a course without a mark of “W” on the transcript Last day to drop a class with a mark of “W” for Session 001
2
u Talk about operating systems u Review quizzes 1-3 (midterm studying) u Take quiz 4
3
uWhat is an OS? uThe kernel, processes and
uProtection/Isolation/Security uCompeting for time uCompeting for space
4
5
6
vSpace (i.e. memory) vTime (i.e. CPU compute time) vPeripherals (i.e. input and output)
u (some content from the following slides is courtesy of Mark Redekopp and CS350)
7
8
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
Kernel Mode Hardware User mode
u Microsoft Family
v MSDOS, Windows 3.1 – 98, WindowsNT -> Windows 10 v Predominately x86 (Intel) hardware, some PowerPC, some ARM v FreeDOS
u POSIX (UNIX/like)
v macOS, FreeBSD, openBSD, netBSD, Solaris, AIX, and others
u Run on most processor architectures
v iOS v Linux
u Little side project of university student u ”UNIX clone” that won the war u 20+ popular distributions u Android: heavily customized Linux and Java on phone/tablet
u Others
v PlaystationOS, VxWorks
9
10
11
u Resource
v Some part of the computer that programs use:
u Memory, CPU, Input/Output devices
u Policy
v Rules enforced by algorithms that share access to resources
u OS Developers (humans) write policies that achieve some set
12
uA bare computer is just hardware uPrograms are written to use that hardware, but
uIn simple terms, the OS:
v Enables more than one program at a time to use
v Present computer resources (CPU, disk, I/O)
v Enforce policies to manage/regulate the sharing of
13
14
– Protection against other applications – Enforce fair resource sharing
– Each program thinks it is running separately – Each program thinks it has full access to computer's resources (or unlimited resources)
– Common services (such as copy/paste) – Files can be read by any application – UI routines for look & feel – Separate applications from hardware
u Reliability (and availability) u Security & Privacy u Performance u Portability
15
u Reliable systems work properly
v Correct (or expected) outputs are generated for a set of inputs v If this is not the case, the system has failed
u Examples?
u Available systems are available to do work u Available does not imply reliable
v System can be available but not reliable (system has bugs, generates
wrong results)
v System can be reliable but not available
u Crash every 5 minutes, but saves results and restarts 5 minutes later 16
u For an OS security means the OS does not run unintended
v No virus/malware
u OS privacy means programs should not get access to data
v Password keychains, files in other users directories
u Security and Privacy require some tradeoffs with
v Some are better than others!
17
u Many machine types exist: x86, x86_64, PPC, ARM, MIPS u Many different motherboards or hardware platforms exist:
u OS with good portability abstracts these differences into a
u Also, can the OS itself be ported to new hardware easily? u Good portability leads to wide adoption
v Linux, Windows
18
u What does performance mean?
v Lots of computation? v Fluid GUI for game? v Low latency disk for database?
u OS balances these with policies
v Major axis is throughput vs. response time v Different OS’s are tuned based on use case v DB server has different policies than Windows gaming rig
19
20
21
22
Free Memory Free Memory Kernel Free Memory Executing Program Kernel Free Memory Kernel
uOne program uses the CPU at a time uOS switches CPU usage (rapidly) uCreates an illusion that all the programs are running
uChangeover from one program to another is called a
uExamples of context switching? uCan context switching be good for a program? uCan context switching be good for a CPU?
23
uResources
v Space (memory) v Time (CPU) v Peripherals (printers etc.)
uProcess: an executing
v Program counter v Contents of registers v Allocated memory &
24
uOS doesn’t worry
uInstead OS cares about
v What resources does a
v How long will it run? v How important is it?
uOther processes have to be prevented from writing to
uCrash in one program shouldn’t crash OS or other
uOS has access to all resources: privileged mode uUser programs have restricted access: user mode uWhen a user program needs access to protected
uPrinciple of least privilege (kernel has highest
25
uThink of the time the CPU spends in chunks or
uHow can blocks of time be allocated to different
uPolicy: rules to enforce process prioritization
26
uThe process queue uRound-robin uFirst-come, first-served uPriority-based
v Preset priority for each process v Shortest-remaining-time
uAll these policies keep the CPU busy uAre there other ways to judge a policy?
27
28
CPU utilization Throughput Latency Fairness Round-robin Good Variable Potentially high Yes No starvation First-come first- served Good Variable Yes Shortest remaining time Good High Potentially high No Could have starvation Fixed priority Good
29
u Utilization: how much work the CPU does u Throughput: # of processes that use the CPU in a certain time u Latency: average amount of time that processes have to wait before running u Fairness: every process gets a chance to use the CPU
uPlanes taking off: first come first served
v High efficiency for the runway v If several smaller planes in line before a large one, not
uTraffic being directed at accident: round robin
v First traffic in one direction, then another v If a police car arrives, then switch to priority-based v Unlikely to ever be shortest remaining time
30
31
32
33
34
u Unlike time, space can be
u When a process is
u When a process finishes
u Fragmentation
35
u Move memory allocation around all the time in the
u Indirection
v Physical memory ordering: memory divided into fixed size
v Logical memory ordering: in logical memory each frame
v When a process uses memory assigned to it, it uses logical
36
uUse indirection to pretend RAM is bigger than it is uDemand paging
v When a process starts, the OS doesn’t allocate it all the memory
v Instead only allocate memory needed to do immediate work v Keep rest of the requested memory in secondary storage (disk) v If a page in memory isn’t used for a while, it’s moved to disk v When a page is needed by a process, it’s copied from disk to RAM
u Other examples of virtualization: virtual environments
37
38
39
40