Professional Documents
Culture Documents
status, when restoring, increment instruction to go to next one, each processor needs its own interrupt stack, but sometimes each process has its own kernel interrupt stack -> disable
interrupts only defers interrupts-> for system call, locate parameters and validate, then copy into kernel memory and copy results back into user memory -> upcalls = signal or
asynchronous event can be used for preemptive user-level threads or async i/o or reception handling at the user level, virtualized interrupt/exception to make app be like OSThe one
program running at all times on the computer is the kernel. Bootstrap program is loaded at power-up or reboot Typically stored in ROM or EPROM, generally known as firmware
Initializes all aspects of system Loads operating system kernel and starts executionChapter 3 (programming interface) One or more CPUs, device controllers connect through
common bus providing access to shared
memory;;;I/O devices and the CPU can execute
Schemes
Average Response Time
Throughput
Fairness
Starvation
concurrently Each device controller is in charge
of a particular device type Each device
FIFO
no guarantee, but can be
good, no overhead
in some sense
none
controller has a local buffer CPU moves data
pessimal
from/to main memory to/from
local buffers I/O is from the device to local
Shortest Job First
optimal
can be pessimal
in some sense
longer jobs can have
buffer of controller Device controller informs
starvation
CPU that it has finished its operation by causing
an interrupt A trap is a software-generated
Round Robin
average
not good because of
yes
none
interrupt caused either by an error or a user
context switches, large
request Program is a passive entity, process is
overhead
an active entity OS does the following in
process management: Creating and deleting
Multi-level Feedback
average
low overhead, balanced
scheduler monitors
none
both user and system processes Suspending
Queue
with average response time processes to ensure fair
and resuming processes Providing
share of resources
mechanisms for process synchronization
Providing mechanisms for process
communication Providing mechanisms for deadlock handling;;can implement OS functionality flexibility modify without changing apps UNIX thin waist = system call interface is simple
and powerful, most innovations are in user code, and highly portable (OS new hardware) thin waist because innovations in software and hardware. Now we allow user programs to create
and manage their own processes, shell is a job control system - Windows has a system call: createProcess() which
Task Length
Arrival Time Completion Time Response Time
creates and initializes the PCB in kernel, create
and initialize a new address space, load program
0
85
0
220
220
Task Length
Arrival Time Completion Time Response Time pro into address space, copy args into memory,
initialize hardware to start, inform scheduler a new
1
30
10
40
30
0
85
0
85
85 process is ready -UNIX fork() and exec();;;fork()
creates a complete copy of parent, takes no args
2
35
15
75
60
1
30
10
115
105
and returns an int:;;fork creates and initializes
PCB, create a new address space, initialize
3
20
80
100
20
2
35
15
150
135
address space with parents address space, inherit
4
50
85
150
65
3
20
80
170
90 execution context of parent, and inform scheduler
process is ready, but fork returns twice the parent
SJF
Average:
79
4
50
85
220
135 gets returned the PID of the child, on failure, it
returns -1 to parent the child it returns zero {int
child_pid = fork(); if child_pid == 0 it is child, else it is parent exec() FIFO
Average:
110 loads prog into address space, and copies args
into memory and initializes hardware to start at start() wait wait
for a process to finish signal send a notification
to another process a shell is interactive command interpreter, run in a loop and forks execs for processes, signal() is used for terminating an application or suspect temporarily for debug,
UNIX I/O all have open(), close(), read(), and write() system calls, open always returns a file descriptor, read always has a kernel buffer and blocks until data is available to be read, same
with kernel-buffered writes UNIX pipe is kernel buffer with 2 file descriptors for read and write, stdin and stdout 0 is reserved for standard input 1 is reserved for standard output 2 is
reserved for standard error output, shell forks to execute command and parent waits for child to finish, producer-consumer relationship = output of one program can be input to another
program and communication is one-way producer writes and consumers reads, client-server is two-way;;Windows, Linux, Mac have monolithic kernel, where most of the OS functionality
is inside the OS kernel hardware abstraction layer is interface to machine configuration and processor operations in kernel dynamically loadable device is software to manage a specific
hardware after kernel starts running, but can cause bugs in the OS Ch 4 (threads): threads allow programmer create as many as he wants without worrying about the exact number of
processors, can express logically concurrent task, exploit many processors, manage I/O, and shift work to run in the bg for responsiveness, thread is a sequence that can be run
suspended or resumed at any time by thread schedulerthread is WITHIN a process, each thread runs on a dedicated virtual processor with unpredictable and variable speed, an
interrupt handler is not a thread, it is not independently schedulable, and cannot be interrupted, why is some I/O print not in order, creating and scheduling threads are separate
operations, thread_join checks in order though, thread_exit returns the param as the return value fork-join parallelism has thread create child threads to perform work and wait for their
results, data shared between threads only if parent wrote it or written by child and read by parent TCB has computation and metadataperthread computation has thread star, with local
vars params and return address, each thread needs stack and copy of processors registers in order to suspend a thread, resume a thread store thread registersper-thread metadata
has thread ID, scheduling priority and status shared state is program code, static global variables and dynamic heap variables;;;thread creation puts it in INIT state and then READY
state on the ready list, in READY, register values are stored in the TCB to go form ready to running, put register values from TCB into processor registers, to go from RUNNING back to
READY is thread_yield() or preempted by scheduler, thread_join goes to WAITING state until another thread is ready, or I/O request, thread in FINISHED never runs again; a kernel
thread executes kernel code and modifies kernel registers, to create a thread, you need to allocate per-thread state, initialize per-thread state and
put TCB on the ready list, a thread never deletes its own state when it is finished, another thread dress the state, thread context switch can be
voluntary (i.r. thread_yield fro processor or thread_join) or involuntary interrupt saves the state of the running thread and executes the handlers
code. a switch between kernel threads means there is no need to switch modes/stacks and handler can resume any thread on the ready list;; a
process is more than a thread because it has its own address space heap, code, PCB therefore needs processor registers, each thread has
user level stack, kernel interrupt stack and kernel TCB Chapter 8 (virtual address): segmentation array of pairs of base and bound
registers, virtual addresses go from 0 to bound and physical address go from base to base + bound, the number of segment is determined by
the number of bits for the segment number that are set aside in the virtual address, segmented memory has gaps, program memory is a set of
regionshigher order bits of the virtual address are used to index into the array, the rest of the address is added to the base and checked
against the bound at that index. If a program branches into or tries to load data from one of these gaps, hardware generates an exception
segmentation fault if programs are sharing code, you can share some regions of memory but protect others Internal fragmentation is the
wasted space within each allocated block because of rounding up from the actual requested allocation to the allocation granularity. External
fragmentation is the various free spaced holes that are generated in either your memory or disk space. External fragmented blocks are available
for allocation, but may be too small to be of any use. Internal fragmentation occurs when the last allocation unit is not full. External
fragmentation occurs when space is wasted between two allocation units. In a paging system, the wasted space in the last page is lost to
internal fragmentation. In a pure segmentation system, some space is invariably lost between the segments. This is due to external
fragmentation. Page memory means memory is allocated in fixed-sized chunks called page frames. Page frames are fixed-sized and power of
2
Q: A computer with a 32-bit address uses a two level page table. Virtual addresses are split into a 9-bit top-level page table field, an 11-bit
second-level page table field, and an offset. How large are the pages and how many are there in the virtual address space?
A:Twenty bits are used for the virtual page numbers, leaving 12 over for the offset. This yields a 4K page. Twenty bits for the virtual page implies
2^20 pages.
Q:A machine has 48-bit virtual addresses and 32-bit physical addresses. Pages are 8K. How many entries are needed for a conventional page
table? For an inverted page table?
A:With 8K pages and a 48-bit virtual address space, the number of virtual pages is (2^48)/(2^13), which is 2^35 (about 34 billion). An inverted
page table needs as many entries as there are page frames in memory, in this case, 524,288. Clearly, this is a lot more manageable.
Virtual address under paging 4 bit | 10 bit (virtual page number | page offset) If page offset is 10 bits long, how big is a page? 2^10 bytes, how many pages can each process have? 2 ^ 4
(page number), max memory space for each process is 2^14 PageTable[virtual page # in virtual address]. Paged memory management, physical memory is allocated in the unit of the
page frame (eg. 1024kb, 2048kb 2^10 is 1024 bytes since kilobyte is 1024 4 kb is 4 * 2^10 or 2^2 * 2^10) page frame size is always 2th power
paged segmentation = memory is segmented, but each table entry point to a page table, which point to the memory backing that segment
20 base 16 -> convert to binary = 00100000 pad the zeros, the 0000|000000100000 then look at table, decimal representation.