-
Kernel -- software that manages the system by providing access to hardware and other resources (memory, network stack, scheduling cpu, etc). Runs in priveleged CPU mode -- kernel mode. It uses kernel-space stack.
-
Process -- an OS abstraction for running programs. Runs in user mode with access to kernel mode via system calls. It consists of: memory address space, file descriptors, thread stacks, registers. Process uses user-space stacks. For example, syscalls use a s kernel exception stack associated with each thread.
-
System call -- a protocol for user programs to request kernel to perform privileged operations
-
Trap -- a signal sent to kernel to request a system routine (system calls, processor exceptions, interrups)
-
Hardware interrupt -- a signal sent by devise to kernel, it is a type of trap
-
Socket -- endpoints by which user-level aplications access the network
-
Network interface -- physical device to connect to network
-
IPIs -- inter-processor interrupt which is a way to coordinate processors in multiprocessor system
-
SystemD -- service manager on Linux. Among features -- dependecy-aware service startup, analytics (
systemd-analyze
) -
KPTI -- kernel page table isolation patches to mitigate "meltdown" vulnerability. The cost is 0.1% - 6% depending on number of syscalls (context switch is more expensive)
-
Functional unit CPU component does the following: fetch instruction, decode instruction, execute and (optionaly) memory access, register write-back.
-
user-time/kernel-time
ratio is high for computationally intensive applications and low for I/O bound (web server, etc). -
MMU -- memory managment unit. Performs virtual memory management. Memory is paged and the chache for pages translation is TLB (translation lookaside buffer). If there is tlb miss, MMU goes to Page tables (main memory).
-
futex -- fast user space mutex which is using atomic integer under the hood. Basic operations are
WAIT(addr, val)
(if *addr == val => current thread sleeps
andWAKE(addr, num)
(wakes up num threads waiting for the addressaddr
. -
toplev -- tool to find bottleneck in software https://github.com/andikleen/pmu-tools/wiki/toplev-manual
ASM, control flow, etc
Watch all of these https://www.youtube.com/channel/UCmf3tLU4WzOnriEQXa638Bw
Procedure control flow
https://www.youtube.com/watch?v=XbZQ-EonR_I&t=354s
instructions: conditional
if, while, for...
and unconditional (break, continue
)How conditional codes work?
There are the following code which store results for conditional operations:
CF
cary flagZF
zero flagSF
sign flagOF
overflow flagThese are set implicitly after
add
and other operations for exampleAnd they are used as operands to some jump instructions:
jmp lavel
-- doesn't use codesje label
-- usesZF
-- jumps if some variable was set to 0 beforejl lable
-- if less (usesSF^OF
)32bits for registers:
%esp
-- stack pointer (data) (for register%rsp
)%eip
-- instruction pointer%eax
-- used for returned value of the functionSo
e
is for 32 andr
is for 64.some asm notes
movl dst, src
(for x86-64)operands types: (1) immediate (
0x400
), register (%eax
), memory (-4(%eax)
)Cannot do mem-mem in one operation -- need to use intermediate register
Memory addressing modes:
movl (%ecx), %eax
movl 8(%ebp), %edx
Suffix
l
formov
means 4bytes, for 8bytes useq
For function call args 16 registers are used, all the other args are on stack
Different address manipulations. Assume that
edx = 0xf000, ecx=0x100
0x8(%edx) = 0xf000 + 0x8
(%edx, %exc) = 0xf000 + 0x100
(%edx,%ecx, 4) = 0xf000 + 4 * 0x100
leal dst, src
-- instruction which calculates the effective address (by doing this affine arithmetics) without accessing the memoryTODO https://web.stanford.edu/class/archive/cs/cs107/cs107.1222/assign1/ -- assignments on stanford