Chapter 2 Flashcards
(63 cards)
Pong game, involves user input and dot bouncing, in what three ways could we combine these two separate processes?
- Insert input processing into dot bouncing loop and stop bouncing while user enters co-ordinates. (blocking)
- Rewrite as Finite State Machine (non-blocking)
- Co-operative multitasking
What are the advantages and disadvantages of the blocking approach?
A: Simple to implement
Efficient Use of CPU
DA: One of the tasks stops while the other progresses.
What are the advantages and disadvantages of the FSM approach?
A: Efficient use of CPU
DA: Major rewrite of algorithms
Hard to understand and maintain
Explain co-operative multitasking.
Dot bouncing and user input processing are treated as semi-
independent “tasks” with their own program stacks. At strategic points in their algorithms they call swtch() function, which puts execution of the current task “on hold” and resumes execution of the other task.
What is execution context?
The minimal amount of data (contents of some registers) that must be saved to allow the program to be interrupted and later resumed.
What registers are not part of execution context in RISC-V?
t0 - t6
What are the advantages and disadvantages of using co-operative multitasking?
A: Both tasks run quasi-simultaneously
Both algorithms easy to understand.
DA: Context switching takes time, so calls to swtch() need to be placed strategically.
What is a processor hardware thread? Give RISC-V name.
A piece of hardware within CPU that can fetch and perform instructions. It has its own set of registers, program counter and control circuits.
“Hart”
T or F. In modern computers there is only one “Hart” per CPU as multiple would be unable to operate simultaneously.
False.
What does IRQ stand for?
Interrupt ReQuest
Explain how an IO IRQ is set up and how an interrupt goes to trap handler.
IRQ wire between CPU and IO adapter. When a device needs attention IRQ set to 1. CPU detects it finishs current instruction and then:
1) Sets the bit corresponding to the device in the special Cause register
2) Saves the address of the next instruction in the special Exception Program Counter (ECP) register
3) Disables all interrupts by resetting the Interrupt Enable (IE) bit in the Status register
4) Jumps to the starting address of the trap handler routine
Explain trap handler operation.
1) Saves execution context
2) Determines which peripheral device caused the interrupt and why
3) Services the device (e.g. supplies or consumes device data through MMIO registers)
4) Ensures that the device sets IRQ wire back to 0
5) Restores execution context
6) Returns to the interrupted program
Give three common sources of interrupts.
External IRQ, Timer IRQ, Software of another Hart
Distinguish between interrupt and software exceptions.
A software exception is caused by the hart itself.
An interrupt is caused by an external device.
List interrupt-related status and control registers of RISC-V.
List special instructions for reading and writing interrupt related control and status registers.
Put u or s instead of m (to get User and Supervisor Versions)
mstatus - enables overall interrupt process
mepc - content of PC at time of interrupt (address of cause)
mscratch - scratch register for machine mode
mcause - cause of the interrupt
mtvec - starting address of trap handler
mie - enables or disables interrupts
mip - holds pending interrupts
Unique to supervisor
satp - supervisor address translation and protection (virtual memory)
Reading and Writing into these
csrw (puts value from normal register into above registers)
csrr (takes value from above registers into normal register)
csrrw (puts old value of above registers into register and puts new value from register into above registers) Syntax csrrw old,above,new
CPU’s are fast but peripheral devices are slower. And CPU’s waiting for peripherals leads to inefficiency. What three solutions were hypothesized for this problem?
Batch Processing
Multi-tasking batch processing
Pre-emptive multitasking.
Explain Batch processing and its advantage.
All programs and data stored in long term memory, OS loads and
executes one after another.
No waiting for user input!
Explain multi-tasking batch processing and its advantage.
OS loads several tasks into RAM and arranges them into a queue. CPU executes a task until it starts IO on a peripheral then OS switches to next task. When peripheral loading is complete, the task is put on the queue again.
No waiting for user input and greatly reduced waiting for peripheral.
Why was multi-tasking batch processing not good enough?
Inconvenient for software development wouldn’t get results of program for a full day! Single typo would ruin a days work.
Explain pre-emptive multitasking and advantage.
Each user has own terminal
Each user starts tasks manually
Each user interacts with their tasks through the terminal.
Frequent CPU switching between tasks creates illusion that all tasks are performed in parallel.
No time is wasted for peripheral or user input (as we can do other tasks while user thinks)
What is a process in OS?
In OS, a process is an instance of running program, collection of all system resources needed to run a program. E.g. CPU time, security permissions, memory occupied and files opened.
Distinguish between multiprocessing and multitasking.
Multiprocessing: Having multiple harts, which are capable of executing multiple streams of
machine instructions simultaneously.
Multitasking: Periodically switching a single hart between multiple streams of machine instructions
How can execution context be used to implement multitasking, explain with example 2 Processes? Give another name for execution context?
Process 1 is started.
Process 1 is interrupted by Kernel
Save execution context of Process 1
Load execution context of Process 2
Process 2 is started
Process 2 is interrupted by Kernel
Save execution context of Process 2
Restore execution context of Process 1
Process 1 continues where it left off……
Process Context
What is process scheduling?
Choosing which process to resume on a particular CPU hart. Many different implementations. E.g. Round robin.