CS代考 CS162 Operating Systems and Systems Programming

CS162 Operating Systems and Systems Programming
June 21, 2022 Rahul & Edward cs162.org

Introduction

Copyright By PowCoder代写 加微信 powcoder

A Simple Computer
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.3

• This system is not easy to use! • Why?
– Not set up to run multiple programs at the same time
– What if you run a program with an infinite loop
– Programs have to know how to talk to all kinds of hardware
06/21/2022
Rahul & S162 © UCB Summer 2022

Task Manager
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.5

Introduction
There is a body of software that is responsible for making it easy to run programs
This body of software is the Operating System.
06/21/2022
Rahul & S162 © UCB Summer 2022 Lec 1.6

What does an Operating System do?
• Share CPU across multiple running programs
• Isolate different running programs
• Create the notion of files and directories
• Provide special services to running programs
• Abstract hardware details away from running programs
06/21/2022
Rahul & S162 © UCB Summer 2022

06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.8

Lines of Code
Millions of Lines of Code
(source https://informationisbeautiful.net/visualizations/million-lines-of-code/)
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.9

Course Info & Logistics

Why take CS162?
• Some of you will actually design and build operating systems.
• Many of you will create systems that utilize the core concepts in operating systems.
– The concepts and design patterns appear at many levels
• All of you will build applications that utilize operating systems.
– The better you understand their design and implementation, the better use you’ll make of them.
06/21/2022
Rahul & S162 © UCB Summer 2022

Who am I? Edward
• Graduating senior
• CS & Math
• 6th time on CS162 staff
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.12

Who am I? Rahul
• Graduating senior
• 2nd time on CS162 staff
• Previously:EE105,EE140,CS189
06/21/2022
Rahul & S162 © UCB Summer 2022

CS162 TAs and Readers
06/21/2022
Rahul & S162 © UCB Summer 2022 Lec 1.14

Course Format
Discussion
In-person, with recorded walkthroughs, 2 sections a week
Office Hours
Project Party
Operating Systems: Principles and Practice (2nd Edition) by Anderson and
cs162.org, all course info can be found here. Piazza for questions.
• 6 homework assignments (HW0, PROJ0, HW1, HW2, HW3, HW4)
• 3 group projects (PROJ1, PROJ2, PROJ3)
• 1 midterm exam
• 1 final exam
06/21/2022
Rahul & S162 © UCB Summer 2022

Getting started
• Everyone
– Start homework 0 right away
• Attend any section you want
• Find group members if you haven’t already
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.16

Assignments
• Individual Homeworks
– HW0.Tools & Environment,Autograding, recall C, executable – PROJ0. Getting Started with PintOS
– HW1. Lists in C
– HW2. BYOS – build your own shell
– HW3. Sockets & Threads in HTTP server
– HW4. Memory management and MALLOC
• Three Group Projects
– PROJ1. User-programs (exec & syscall)
– PROJ2.Threads & Scheduling (no user multi-threading) – PROJ3. File Systems
• Extensions policy and form on course website
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.17

Group Projects
• Project teams have 4 members!
– Each project team will be assigned a TA.
• Communication and cooperation will be essential
– Joint work on Design Documents
– Slack/Messenger/whatever doesn’t replace face-to-face!
• Everyone should do work and have clear responsibilities
– You will evaluate your teammates at the end of each project – Not all tasks are equal.Work as a team.
• Communicate with your TA
– What is the team’s plan?
– What is each member’s responsibility?
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.18

PreparingYourself for this Class
• The projects will require you to be very comfortable with programming and debugging C
– Pointers (including function pointers, void*)
– Memory Management (malloc, free, stack vs heap) – Debugging with GDB
• You will be working on a larger, more sophisticated code base than anything you’ve likely seen in 61C!
• Review Session on C on 6/24
• Resources page on website – Ebooks on git and C
• C programming reference (still in beta): – https://cs162.eecs.berkeley.edu/ladder/
• First section is dedicated to programming and debugging review
06/21/2022
Rahul & S162 © UCB Summer 2022

• 40% exams
• 40% projects
• 20% homework
• Projects
– Initial design document, design review, code, final report
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.20

CS 162 Collaboration Policy
Explaining a concept to someone in another group Discussing algorithms/testing strategies with other groups Discussing debugging approaches with other groups Searching online for generic algorithms (e.g. hash table)
Sharing code or test cases with another group
Copying OR reading another group’s code or test cases Copying OR reading online code or test cases from prior years Helping someone in another group to debug their code
• We have tools to detect academic misconduct and will take actions against offenders.
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.21

Basic OS Concepts
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.22

Basic OS Concepts
• Operating systems abstract away the underlying hardware
• They provide an easier-to-use interface for user programs
• We’ll see several examples in the next few slides
• This is just an overview; we’ll go into much more detail later on
06/21/2022
Rahul & S162 © UCB Summer 2022

Processes and Threads
Hardware: CPU
OS abstraction: processes and threads
What’s in a process?
• Address Space
• One or more threads of control executing in that address space
• Additional system state associated with it – Open files
– Open sockets (network connections) –…
Application
Operating System
Abstract Machine Interface Physical Machine Interface
06/21/2022
Rahul & S162 © UCB Summer 2022

Hardware Multiplexing
What if you want to run 2 processes on 1 single-core CPU?
• Give the illusion that both are running simultaneously
• Applications can’t be trusted to voluntarily give up the CPU
• OS needs a mechanism to retake control of the CPU
• Typically: a hardware timer interrupts the CPU, giving control to the OS • The OS can then pick another thread/process to run
06/21/2022
Rahul & S162 © UCB Summer 2022

Filesystems
Hardware: Disk
OS abstraction: files/directories
How does the OS provide a filesystem?
• Disk is essentially just a collection of bytes, organized into chunks called sectors
• Ask disk to load i’th sector; get back a chunk of (say) 4096 bytes
• When you access the file /a/b/c/foo.txt, OS translates the file path into a set of sectors that store the contents of foo.txt
• Applications don’t worry about how exactly the disk works; they can think solely in terms of files and directories
06/21/2022
Rahul & S162 © UCB Summer 2022

Hardware: Physical memory (usually SRAM/DRAM) OS abstraction:Virtual memory
• Like disk, physical memory is just a collection of chunks of bits
• OS performs address translation: converting virtual addresses into physical addresses to send to the memory controller
• Applications can act as if they have their entire address space to themselves
• Address translation often accelerated by hardware
06/21/2022
Rahul & S162 © UCB Summer 2022

Isolation/Security
Isolation is a very important job of the operating system!
• Processes should not be able to access memory belonging to another process
• Bugs in one application should not crash the entire system
• Applications must not be able to read or modify operating system data
Other security features the OS helps enforce:
• Filesystem permissions (read/write/execute, access control lists)
• Firmware verification / secure boot
• Firewalls / network access control
06/21/2022
Rahul & S162 © UCB Summer 2022

Only one way for applications to use OS services: syscalls.
• Syscalls are the interface between user programs and the OS kernel
• The “narrow waist” between user programs and the kernel
• Use syscalls to:
– open/read/write files
– create processes
– access the network
– get the system time
– communicate with other processes –…
06/21/2022
Rahul & S162 © UCB Summer 2022

Example: Shell
Before modern user interfaces, the shell was the only way to interact with a computer.
Nowadays, shells are wrapped in their own graphical user interface. Many flavors:sh,bash,fish,zsh,csh
06/21/2022
Rahul & S162 © UCB Summer 2022

What happens when you run ls? 1. Shell reads the command, and parses arguments.
Command:“ls /”
Two arguments:“ls”, “/”
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.31

What happens when you run ls? 2. Shell searches for an executable file called “ls”.
Where does it search? The directories listed in PATH. How can you tell which file it found? Run “which ls”.
On my system:“/bin/ls”.
06/21/2022
Rahul & S162 © UCB Summer 2022

What happens when you run ls?
3. Shell spawns a new process running the executable /bin/ls.
Syscalls:fork, exec.
Shell passes the arguments [“ls”, “/”] to this process.
Fork returns a PID (process ID) – we’ll use this later!
06/21/2022
Rahul & S162 © UCB Summer 2022

What happens when you run ls? 4.The process running ls reads the current working directory.
Syscalls:opendir, readdir, …
How does it know which directory to read? The current working directory is inherited by the child process.
06/21/2022
Rahul & S162 © UCB Summer 2022

What happens when you run ls? 5. ls writes the directory entries to its standard output.
Syscalls: write.
06/21/2022
Rahul & S162 © UCB Summer 2022 Lec 1.35

What happens when you run ls? 6.The shell displays the standard output.
Child processes inherit standard output.
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.36

What happens when you run ls?
7.The shell waits for ls to finish before prompting you for another command.
Syscalls:wait, waitpid.
Repeat the same process for other commands! A bit more complicated: shells
support redirection, pipes, aliases, etc.
06/21/2022
Rahul & S162 © UCB Summer 2022 Lec 1.37

06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.38

PintOS is the educational operating system we use in all projects.
You’ll add several basic features:
• Project 1: User program support – Argument passing
– Syscalls
• Project 2: Scheduling
– Scheduling
– Timer interrupts
– Thread synchronization
• Project 3: Filesystems – Files
– Directories – Cache
06/21/2022
Rahul & S162 © UCB Summer 2022

“In conclusion…Operating Systems:”
• Provide convenient abstractions to handle diverse hardware
– Convenience, protection, reliability obtained in creating the illusion
• Coordinate resources and protect users from each other – Using a few critical hardware mechanisms
• Simplify application development by providing standard services • Provide fault containment, fault tolerance, and fault recovery
• CS162 combines things from many other areas of computer science: – Languages, data structures, hardware, and algorithms
06/21/2022
Rahul & S162 © UCB Summer 2022

Acknowledgements
Slides courtesy of , . Joseph, ,AJ Shankar, ,AlexAiken, , ,Ion Stoica,DougTygar, , ,
06/21/2022 Rahul & S162 © UCB Summer 2022 Lec 1.41

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com