Midterm Review Questions Flashcards

1
Q

What are 3 key roles of an operating system?

A
  1. hide hardware complexity
  2. manage underlying hardware resources
  3. provide isolation and protection
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give an example of how an OS hides hardware complexity

For example, the operating system provides __________________ as a representation of ______________________

A

For example, the operating system provides the file abstraction as a representation of logical components of information stored on disk.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give3 examples of how the OS manages or arbitrates underlying hardware resources

A
  • allocates memory
  • schedules application to run on CPU
  • controls access to I/O
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Give an example of how the OS provides isolation and protection.

A

With multiple applications running concurrently, the operating system must make sure that no one application interferes with the execution of another application.

For example, the operating system ensures that memory allocated to one application is neither read from nor written to by another application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Apart from simplicity, another benefit of abstractions is ________

Operating systems are free to _____ out their ___________ to suit different hardware resources, and as long as their API remains ______, programs will still run.

A

Apart from simplicity, another benefit of abstractions is their portability.

Operating systems are free to swap out their implementations to suit different hardware resources, and as long as their API remains constant, programs will still run.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe each of the following in one sentence:

  • OS abstractions,
  • OS mechanisms
  • OS policies
A
  • Abstractions are entities that represent other entities (e.g. file)
  • Mechanisms are the tools by which policies are implemented.
  • Policies are the rules around how a system is maintained and resources are utilized.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A file is an example of …

A

an OS abstraction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

processes and threads are examples of …

file, socket, memory page are examples of …

A

software abstractions

hardware abstractions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

As an example of a policy a common technique for swapping memory to disk is ________________

Explain this policy: _______________________

______________________________________

A

LRU (least recently used)

This policy states that the memory that was least recently accessed will be swapped to disk.

Policies help dictate the rules a system follows to manage and maintain a workable state. Note that policies can be different in different contexts or a different times in a system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the mechanism for implementing LRU?

A

Mechanisms are the tools by which policies are implemented. For example, in order to enforce the LRU policy of memory management above, memory addresses/blocks may be moved to the front of a queue every time they are accessed.

When it comes time to swap memory to disk, the memory at the back of the queue can be swapped. In this example, the queue is the mechanism by which the LRU policy is implemented.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the principle of separation of mechanism and policy mean?

A

how you enforce a policy shouldn’t be coupled to the policy itself.

That being said, certain policies may occur more frequently than others, so it may make sense to optimize our mechanisms a little bit in one direction or anything while still maintaining their flexibility.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the principle optimize for the common case mean?

A

ensuring that the most frequent path of execution operates as performantly as possible.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Optimize for the common case -cite an example of this is as discussed in the SunOS paper.

A

A great example of this is discussed in the SunOS paper, when talking about using threads for signal handling instead of changing masks before entering/after exiting a mutex:

The additional overhead in taking an interrupt
is about 40 SPARC instructions. The savings in the mutex enter/exit path is about 12 instructions. However, mutex operations are much more frequent than interrupts, so there is a net gain in time cost, as long as interrupts don’t block too frequently. The work to convert an interrupt into a “real” thread is performed only when there is lock contention.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Give two reasons why context switch from user to kernel mode is slow?

  1. _____________________________________________
  2. _____________________________________________
A

This context switch takes CPU cycles to perform which is real overhead on the system.

In addition, context switching will most likely invalidate the hardware cache (hot -> cold), meaning that memory accesses for the kernel context will initially come from main memory and not from cache, which is slow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What happens during a user-kernel mode crossing?

A

Distinguishing between user and kernel mode is supported directly in the hardware. For instance, when operating in kernel mode, a special bit is set on the CPU, and if that bit is set, any instruction that directly manipulates the hardware is allowed. When in user mode, the bit will not be set, and any attempt to perform such privileged operations will be forbidden.

Such forbidden attempts will actually cause a trap. The executing application will be interrupted, and the hardware will switch control back to the operating system a specific location - the trap handler. At this point, the operating system will have a chance to determine what caused the trap and then decide if it should grant access or perhaps terminate the transgressive process.

This context switch takes CPU cycles to perform which is real overhead on the system. In addition, context switching will most likely invalidate the hardware cache (hot -> cold), meaning that memory accesses for the kernel context will initially come from main memory and not from cache, which is slow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Distinguishing between _____ and _______ mode is supported directly in the ________.

For instance, when operating in kernel mode, a special bit is set on the _____, and if that bit is set, any instruction that directly manipulates the hardware is _______. When in user mode, the bit will _____ be set, and any attempt to perform such privileged operations will be _________.

A

Distinguishing between user and kernel mode is supported directly in the hardware.

For instance, when operating in kernel mode, a special bit is set on the CPU, and if that bit is set, any instruction that directly manipulates the hardware is allowed. When in user mode, the bit will not be set, and any attempt to perform such privileged operations will be forbidden.

17
Q

What is a trap handler in the context of kernel-user mode crossing?

A

An application (in user mode) that tries to perform a privileged operation when the hardware bit is not set will cause a trap.

The executing application will be interrupted, and the hardware will switch control back to the operating system a specific location - the trap handler.

At this point, the operating system will have a chance to determine what caused the trap and then decide if it should grant access or perhaps terminate the transgressive process.

18
Q

An application (in user mode) that tries to perform a _________ ___________ when the hardware bit is not set will cause a trap.

The executing application will be _____________, and the hardware will ________ ________ back to the operating system at specific location - the _____________

At this point, the operating system will have a chance to determine what caused the trap and then decide if it should ___________________or ________________________________.

A

An application (in user mode) that tries to perform a privileged operation when the hardware bit is not set will cause a trap

The executing application will be interrupted, and the hardware will switch control back to the operating system at specific location - the trap handler.

At this point, the operating system will have a chance to determine what caused the trap and then decide if it should grant access or perhaps terminate the transgressive process.

19
Q

Why does a cold cache slow down the system?

A

Because memory access has to come from main memory instead of cache

20
Q

When does a kernel trap happen? Give two reasons:

  1. ______________________________________________
  2. ______________________________________________
A
  1. Hardware detects an attempt to perform an unprivileged operation, which is basically any operation that occurs when the special bit is not set on the CPU.
  2. Hardware detects an attempt to access memory that requires special privileges.
21
Q

What is a kernel trap?

A

A kernel trap is a signal that the hardware sends to the operating system when it detects that something has occurred.

22
Q

What are the steps that take place during a kernel trap?

  1. OS …..
  2. OS …..
  3. OS …..
  4. OS …. or …..
A

Hardware sends a signal to the operating system

  1. OS initiates control
  2. OS invokes its trap handler.
  3. OS examines the process that caused the trap as well as the reason for the trap.
  4. OS allows the attempted operation or kills the process.
23
Q

Basically, user/kernel mode crossing occurs any time any application needs access to underlying hardware, be it ___________, ___________, or _________

Give two general reasons for kernel-user mode crossing:

  1. _________________________________________
  2. _________________________________________

Give 5 examples of actions an application might do that would trigger a kernel-user mode crossing:

  1. ______________
  2. ______________
  3. ______________
  4. ______________
  5. ______________
A

Basically, user/kernel mode crossing occurs any time any application needs access to underlying hardware, be it physical memory, storage, or I/O devices.

  1. Response to hardware trap (CPU privilege bit not set etc…)
  2. Application invoked a system call

examples

  1. read from a file
  2. write to a file
  3. listen on a socket
  4. allocate memory
  5. free memory
24
Q

What is a condition variable?

A

Condition variables are constructs used in conjunction with mutexes to control concurrent execution.

While mutexes and mutual exclusion represent binary states - either the thread can access a shared resource or it cannot - condition variables allow for more complex states.

  • Threads wait on condition variables until a condition is met.
  • Threads signal/broadcast on condition variables when a condition is met.
25
Q

Give two benefits of using condition variables:

  1. _______________________________________
  2. _______________________________________
A
  1. Avoid spinning a thread unnecessarily, save CPU cycles
  2. Allows programmer to schedule use of resources by threads

“A condition variable is used when the programmer wants to schedule the way in which multiple threads access some shared resource, and the simple one-at-a-time mutual exclusion provided by mutexes is not sufficient.” - Birrell

“For example, if you have a certain kind of thread that you want only to run after other threads have run, like in the calendar example. Say you have two task queues, important and notimportant, and a thread pool associated with each of those.
You could do something like “ - Jesse Bracho (Slack CS6200)

while(important.notEmpty)

cond_wait(&m, until_nothing_important)

pop(notimportant)

unlock(&m)

26
Q

What is a system call?

Give 3 examples of a system call

A
  • A system call is an operation that the operating system exposes that an application can directly invoke.
  • A system call gets the OS to perform privileged access for the application that normally couldn’t perform that action.

Examples of system calls:

  1. open
  2. send
  3. malloc
27
Q

Describe the steps involved in a system call:

A
  1. User process makes a system call
  2. OS does context switch from that process to the kernel.
  3. OS holds onto the arguments
  4. OS sets trap bit on the CPU, so CPU will let kernel perform the operation.
  5. Kernel jumps to the system call
  6. Kernel executes system call
  7. After the execution, the kernel must reset the trap bit in the CPU
  8. OS context switch back to the user process.
  9. Pass back the results.
28
Q

Describe the steps involved in a system call:

  1. User process makes a ______ ____
  2. OS does a _____ ______ from that process to the kernel.
  3. OS holds onto the __________
  4. OS _____________________, so CPU will let kernel perform the operation.
  5. Kernel ________ to the system call
  6. Kernel ________ system call
  7. After the execution, the kernel must ________________________
  8. OS ___________________ to the user process.
  9. Pass back the ___________.
A

Describe the steps involved in a system call:

  1. User process makes a system call
  2. OS does a context switch from that process to the kernel.
  3. OS holds onto the arguments
  4. OS sets trap bit on the CPU, so CPU will let kernel perform the operation.
  5. Kernel jumps to the system call
  6. Kernel executes system call
  7. After the execution, the kernel must reset the trap bit in the CPU
  8. OS context switch back to the user process.
  9. Pass back the results.
29
Q

What is an interrupt?

A
  • Interrupts are events to the CPU.
  • Interrupts are generated externally by components other than the CPU.
30
Q

Give 3 examples of components that can interrupt a CPU

A
  1. I/O devices
  2. Timers
  3. Other CPUs
31
Q

What is a signal?

A

Signals are events that are:

  • Triggered by the CPU

​or

  • by software running on the CPU
32
Q

Which particular interrupts can occur on a given physical platform depends on:

  1. the ___________ of that platform
  2. the ___________________ the platform comes with
  3. the _________________of the platform itself.
A
  1. the configuration of that platform
  2. the types of devices the platform comes with
  3. the hardware architecture of the platform itself.
33
Q

Do interrupts appear asynchronously or synchronously?

A

always asynchronously

34
Q

State 3 properties of signals that differ from interrupts

A
  1. notification from the CPU itself or from software running on the CPU
  2. which interrupts can occur depends on the operating system
  3. may be asynchonous or synchronous
35
Q

State 3 properties of interrupts that are not shared with signals

A
  1. notification from outside the CPU, to the CPU
  2. which interrupts can occur on platform, depends on the physical platform (configuration, types of devices, hardware architecture)
  3. asynchonous
36
Q

Which interrupts occur is a function of …..

How those interrupts are handled is a function of ….

A

Which interrupts occur is a function of the platform on which you are running.

How those interrupts are handled is a function of the OS on top of the physical system.