CS代写 COVID-19

Design philosophy of operating systems (II)

Recap: How applications can use privileged operations?
Implemented in “trap” instructions

Copyright By PowCoder代写 加微信 powcoder

• Raiseanexceptionintheprocessor
• TheprocessorsavestheexceptionPCandjumps to the corresponding exception handler in the OS kernel
The OS kernel only get involved when necessary • System calls
user program
sbb %ecx,0x13(%rcx)
and %cl,(%rbx)
xor $0x19,%al
add %edx,(%rbx)
add %al,(%rax)
add %al,(%rbx)
add 0x1bad(%eax),%dh
add %al,(%eax)
decb 0x52(%edi)
in $0x8d,%al
mov %eax,0x101c
lea -0x2bb84(%ebx),%eax
mov %eax,-0x2bb8a(%ebx)
lgdtl -0x2bb8c(%ebx)
lea -0x2bf3d(%ebx),%eax
push $0x10
• Hardware interrupts • Exceptions
return-from-trap
The OS kernel works on behave of the
requesting process — not a process
Somehow like a function call to a dynamic linking library
variables for kernel code and etc…
As a result — overhead of copying registers, allocating local 2
kernel/privileged mode

Why should people care about this paper in 1968?
• Turn-aroundtimeofshortprogramsProcessAbstraction • • • Economicuseofthemachine
Recap: THE
Designing a system is difficult in 1968
• Difficult to verify soundness
• Difficult to prove correctness
• Difficult to deal with the complexities
Layered Design

Recap: THE
layer 3: I/O & peripherals buffering
layer 2: message interpreter
layer 1: memory (segment/page) management
privilege boundary
privilege boundary
privilege boundary
privilege boundary
layer 0: processor allocation & scheduling

The overhead of kernel switches/system calls
On a 3.7GHz intel Core i5-9600K Processor, please make a guess of the overhead of switching from user-mode to kernel mode.
A. asingledigitofnanoseconds B. tensofnanoseconds
D. asingledigitofmicroseconds E. tensofmicroseconds
C. hundreds of nanoseconds
Operations
Main memory reference
Read 1 MB sequentially from memory
Compress 1K bytes with Zippy
Latency (ns)
L1 cache reference
Branch mispredict
L2 cache reference
Mutex lock/unlock
Send 2K bytes over network
Read 4K randomly from SSD*
Read 1 MB sequentially from SSD*
Round trip within same datacenter
Read 1 MB sequentially from disk
500,000 ns
825,000 ns
Send packet CA-Netherlands-CA
2,000,000 ns
150,000,000 ns

Recap: Why layered/hierarchical design?
How many the following is/are true regarding the proposed
hierarchical design
! Thehierarchicaldesignfacilitatesdebugging
” Thehierarchicaldesignmakesverificationofsystemcomponentseasier
# Thehierarchicaldesignreducestheoverheadofrunningasingleprocess
$ Thehierarchicaldesignallowsflexibleresourceallocation
— what a potential problem is this?
— function calls/syscalls, memory copying, and etc…

C. Freedom
Recap: Why “Nucleus”
Which of the following words best described the why of “The
Nucleus of a Multiprogramming System”
A. Feasibility
B. Performance
D. Hierarchy E. Robustness
avoid this kind of pronoun

Nucleus (cont.) Outline
The UNIX time-sharing operating system
Mach: A New Kernel Foundation For UNIX Development

Poll close in
What is “system nucleus”
Regarding “system nucleus”, how many of the following statements are
! Thesystemnucleusisaprocess
” Thesystemnucleusallowsmultipleoperatingsystemstoexecuteconcurrently # Thesystemnucleusprovidesprimitivestoloadandswapprograms
$ Operatingsystemsareuser-levelprocessesinthesystemnucleusarchitecture A. 0

System Nucleus
System Nucleus …

What is “system nucleus”
Regarding “system nucleus”, how many of the following statements are
! Thesystemnucleusisaprocess
” Thesystemnucleusallowsmultipleoperatingsystemstoexecuteconcurrently # Thesystemnucleusprovidesprimitivestoloadandswapprograms
$ Operatingsystemsareuser-levelprocessesinthesystemnucleusarchitecture A. 0

Can multiple OSs running concurrently?
S—The primitive OS
System Nucleus

How many layers?
S—The primitive OS
System Nucleus
privileged mode

What is “system nucleus”
Regarding “system nucleus”, how many of the following statements are
! Thesystemnucleusisaprocess
” Thesystemnucleusallowsmultipleoperatingsystemstoexecuteconcurrently # Thesystemnucleusprovidesprimitivestoloadandswapprograms
$ Operatingsystemsareuser-levelprocessesinthesystemnucleusarchitecture A. 0

Hierarchical design v.s. flat structure
Hierarchical
• Easeofdebugging/verification/testing
• Lackofflexibility—youcanonlyinteractwithneighborlayers • Overheadineachlayer—notsogreatforperformance
• Flexibility/Freedom

What the OS kernel should do?

The UNIX Time-Sharing System
. Ritchie and Bell Laboratories

Poll close in
Why they built “UNIX”
How many of following statements is/are the motivations of building
! ReducingthecostofbuildingmachineswithpowerfulOSes ” ReducingtheburdenofmaintainingtheOScode
# ReducingthesizeoftheOScode
$ Supportingnetworksandmultiprocessors
A. 0 B. 1 C. 2 D. 3 E. 4

Why they built “UNIX”
How many of following statements is/are the motivations of building
! ReducingthecostofbuildingmachineswithpowerfulOSes ” ReducingtheburdenofmaintainingtheOScode
# ReducingthesizeoftheOScode
$ Supportingnetworksandmultiprocessors

Why should we care about “UNIX”
An operating system promotes simplicity, elegance, and ease They made it
A powerful operating system on “inexpensive” hardware (still
costs USD $40,000)

Providing a file system
File as the unifying abstraction in UNIX Remind what we mentioned before
What UNIX proposed

Poll close in
How many of the following statements about UNIX is/are correct?
! Thesemanticsofaccessingadeviceandaccessingatextfileisthesame
” Forthefilename/alpha/beta/gamma,alpha,beta,gammaareallfiles.
# Alteringthecontentofdirectoryrequiresprivilegedoperations
$ Theprogrammerneedstotreatrandomandsequentialfileaccesses differently
A. 0 B. 1 C. 2 D. 3 E. 4
The file abstraction

How many of the following statements about UNIX is/are correct?
! Thesemanticsofaccessingadeviceandaccessingatextfileisthesame
” Forthefilename/alpha/beta/gamma,alpha,beta,gammaareallfiles.
# Alteringthecontentofdirectoryrequiresprivilegedoperations
differently A. 0
The file abstraction
$ Theprogrammerneedstotreatrandomandsequentialfileaccesses

Poll close in
Protection
Regarding the protection in the assigned UNIX paper, how many of the
followings is/are correct?
! Thesamefilemayhavedifferentpermissionsfordifferentuser-id
” Theownerofthefilemaynothavethepermissionofwritingafile
# Iftheuserdoesnothaveapermissiontoaccessadevice,set-user-idwill guarantee that the user will not be able to access that device
$ IntheUNIXsystemdescribedinthispaper,ifthefileowneris“foo”,thentheuser “bar” will have the same permission as another user (e.g. “xyz”).
A. 0 B. 1 C. 2 D. 3 E. 4

followings is/are correct?
Protection
Regarding the protection in the assigned UNIX paper, how many of the
! Thesamefilemayhavedifferentpermissionsfordifferentuser-id
” Theownerofthefilemaynothavethepermissionofwritingafile
# Iftheuserdoesnothaveapermissiontoaccessadevice,set-user-idwill guarantee that the user will not be able to access that device
A. 0 B. 1 C. 2 D. 3 E. 4
The UNIX system at that time doesn’t have “group” — everyone other than the owner is “others”
allow the user to have the same permission as the creator of the
$ IntheUNIXsystemdescribedinthispaper,ifthefileowneris“foo”,thentheuser “bar” will have the same permission as another user (e.g. “xyz”).

Right amplification

Demo: setuid
chmod u+s allows “others” to execute the program as the
There exists a file “others” cannot read
Another program can dump the content
Without setuid, others still cannot read the content With setuid, others can read that!

UNIX’s interface of managing processes

The basic process API of UNIX

pid_t fork();
fork used to create processes (UNIX)
What does fork() do?
• Createsanewaddressspace(forchild)
• Copiesparent’saddressspacetochild’s
• Pointskernelresourcestotheparent’sresources(e.g.openfiles) • Insertschildprocessintoreadyqueue
fork() returns twice
• Returnsthechild’sPIDtotheparent • Returns“0”tothechild

Poll close in
What happens if we execute the following code?
int main() {
the parent’s PID is 2; child’s PID is 7.
if ((pid = fork()) == 0) {
} printf (”My pid is %d\n”, getpid());
printf (”Child pid is %d\n”, pid);
What will happen?
# of times “my pid” is printed
my pid values printed
# of times “child pid” is printed
child pid values printed

Poll close in
What happens if we execute the following code?
int main() {
the parent’s PID is 2; child’s PID is 7.
if ((pid = fork()) == 0) {
} printf (”My pid is %d\n”, getpid());
printf (”Child pid is %d\n”, pid);
What will happen?
# of times “my pid” is printed
my pid values printed
# of times “child pid” is printed
child pid values printed

What happens if we execute the following code?
int main() {
the parent’s PID is 2; child’s PID is 7.
if ((pid = fork()) == 0) {
} printf (”My pid is %d\n”, getpid());
printf (”Child pid is %d\n”, pid);
What will happen?
# of times “my pid” is printed
my pid values printed
# of times “child pid” is printed
child pid values printed

the parent’s PID is 2; child’s PID is 7.
if ((pid = fork()) == 0) {
printf(“My pid is %d\n”, getpid());
printf(“Child pid is %d\n”, pid);
static data
heap stack
Virtual memory

the parent’s PID is 2; child’s PID is 7.
if ((pid = fork()) == 0) {
printf(“My pid is %d\n”, getpid());
printf(“Child pid is %d\n”, pid);
static data
heap stack
Virtual memory
if ((pid = fork()) == 0) {
printf(“My pid is %d\n”, getpid());
printf(“Child pid is %d\n”, pid);
static data
heap stack
Virtual memory

the parent’s PID is 2; child’s PID is 7.
Output: Mypidis7
if ((pid = fork()) == 0) {
printf(“My pid is %d\n”, getpid());
printf(“Child pid is %d\n”, pid);
static data
heap stack
Virtual memory
if ((pid = fork()) == 0) {
printf(“My pid is %d\n”, getpid());
printf(“Child pid is %d\n”, pid);
static data
heap stack
Virtual memory

the parent’s PID is 2; child’s PID is 7.
Output: Mypidis7 Child pid is 0
if ((pid = fork()) == 0) {
printf(“My pid is %d\n”, getpid());
printf(“Child pid is %d\n”, pid);
static data
heap stack
Virtual memory
if ((pid = fork()) == 0) {
printf(“My pid is %d\n”, getpid());
printf(“Child pid is %d\n”, pid);
static data
heap stack
Virtual memory

the parent’s PID is 2; child’s PID is 7.
Output: Mypidis7 Child pid is 0
Child pid is 7
if ((pid = fork()) == 0) {
printf(“My pid is %d\n”, getpid());
printf(“Child pid is %d\n”, pid);
static data
heap stack
Virtual memory
if ((pid = fork()) == 0) {
printf(“My pid is %d\n”, getpid());
printf(“Child pid is %d\n”, pid);
static data
heap stack
Virtual memory

What happens if we execute the following code?
int main() {
the parent’s PID is 2; child’s PID is 7.
if ((pid = fork()) == 0) {
} printf (”My pid is %d\n”, getpid());
printf (”Child pid is %d\n”, pid);
What will happen?
# of times “my pid” is printed
my pid values printed
# of times “child pid” is printed
child pid values printed

Reading quizzes due next Tuesday
• Welcomenewfriends!—willdropatotalof6readingquizzesforthequarter • Attendancecountas4readingquizzes
• Weplantohaveatotalof11readingquizzes
Announcement
Office Hour links are inside Google Calendar events
• https://calendar.google.com/calendar/u/0/r?
We will make both midterm and final exams online this quarter
• AvoidtheuncertaintyofCOVID-19
• Avoidhigh-densityintheclassroom(onlysits60andwehave59fornow)during examines

Different links from lecture ones
We cannot share through any public channels so that we can better avoid Zoom bombing

Engineering

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