Documente Academic
Documente Profesional
Documente Cultură
0
Microkernel
Third USENIX MACH Symposium
Santa Fe, New Mexico
April 19, 1993
Bob Wheeler
Carnegie Mellon University
Carnegie
Mellon
Carnegie
Mellon
Overview
Part I - Getting Started
Source Code Layout
Build Tools
Miscellaneous routines
Debugging
Sources of Information
Source Code Layout
C Shell Tricks
Build Tools
Cong
MiG - The Mach Interface Generator
Makeboot
Getting Started
Carnegie
Mellon
Build Magic
Kernel Bootstrap
Miscellaneous Routines
Debugging
Carnegie
Mellon
Sources of Information
mach3
Technical questions
mach3@cs.cmu.edu
Read by CMU, OSF, and 300 other people
To be added contact mach3-request@cs.cmu.edu
Administrative questions
mach@cs.cmu.edu
Read by Mach distribution people
Documentation
All documentation mentioned is available via
anonymous ftp from mach.cs.cmu.edu in the
doc directory
Carnegie
Mellon
obj
release
parisc_mach
parisc_mach
mk user
ux
obj
release
src
build tools
mk
user
ux
parisc mach
Carnegie
Mellon
ux
include
bootstrap
micro kernel
mach user programs
single server
machine dependent area for
Hewlett-Packard pa-risc machine
libmach threads ddb sys src conf mach kern vm device ipc parisc parisc parisc mach
libmach
threads
ddb
sys
src
conf
mach
kern
vm
device
ipc
bootstrap
parisc
mk
kernel
build_tools
ux
lib special
Carnegie
Mellon
user
src
mk user
emulator
include
parisc
parisc
server
bsd conf sys ufs uxkern vm parisc
emulator
include
server
bsd
conf
sys
ufs
uxkern
vm
parisc
bsd sources
conguration les
UNIX include les
UNIX le system
Mach glue code
virtual memory
machine dependent code for
Hewlett-Packard pa-risc machine
Carnegie
Mellon
C Shell Tricks
mk/Makeconf
set cdpath=($M3SRC/mk n
$M3SRC/mk/kernel n
$M3SRC/ux n
$M3SRC/ux/server n
$M3SRC/ux/emulator)
Carnegie
Mellon
Carnegie
Mellon
10
Porting Cong
doconf
cong
MiG
makeboot
11
Carnegie
Mellon
12
A
Species
Syntax:
<OPTIONS j directory>lename n
<optional opt j standard> n
# <hp700>
# <hp700>
conftype
platform
cong
"parisc"
HP700
mach kernel
options
device
device
device
device
device
pseudo-device
sd0
sd1
sd2
sd3
lan
bpf
Carnegie
Mellon
16
# <scsi>
# <scsi>
# <scsi>
# <scsi>
# <lan>
# <lan>
13
Example:
OPTIONS/trap counters
parisc/locore.s
parisc/context.s
parisc/trap.c
parisc/pmap.c
standard ordered
standard j -fvolatile
standard
standard
parisc/sd.c
parisc/lan.c
parisc/bpf.c
optional sd device-driver
optional lan device-driver
optional bpf device-driver
Carnegie
Mellon
14
Specifying Options
Cong Output
All output from cong is in the object area
Makele.internal
ioconf.c
platforms.h
#dene HP700 1
trap counters.h
#dene TRAP COUNTERS 0
sd.h
#dene NSD 4
lan.h
#dene NLAN 1
bpf.h
#dene NBPF 16
Carnegie
Mellon
15
Carnegie
Mellon
16
Makeboot
kernel object
file header
kernel object
file header
kernel text
kernel text
kernel data
boot_info
structure
kernel symbol
table header
boot_info.sym_size
kernel symbol
table data
pager text
kernel data
pager data
boot_info.boot_size
pager symbol
table header
pager symbol
table data
boot_info.load_info_size
Carnegie
Mellon
17
Carnegie
Mellon
19
boot_header
Carnegie
Mellon
18
Getting Started
Get build tools working
Fake include les
Fake conguration les
Fake genassym.c
See what comes up undened
Use grep and etags
Write small utilities like ndsym
#!/bin/sh
for le in *.o
do
echo $le
nm $le j grep $1
done
Carnegie
Mellon
20
Bootstrap Routines
Kernel Bootstrap
locore
idle thread
reaper thread
startup
swapin thread
sched_thread
pmap_bootstrap()
bootstrap_task
init()
setup_main()
pagout deamon
init()
setup main()
locore.s
Virtual Memory
Disabled
boot loader
Carnegie
Mellon
21
Carnegie
Mellon
22
Miscellaneous Routines
Device Drivers
void startrtclock()
void resettodr()
23
Carnegie
Mellon
24
links
Kernel loads and toggles lights
Printf works
Debugger works
Pmap initialized
Virtual memory enabled (rst VM fault)
First user process (bootstrap)
First system call (from bootstrap)
Server loads
Paging le found
Init doesn't die
First signal (from /bin/sh)
Single user # prompt
Multi-user
Network works
Compiles lisp
Carnegie
Mellon
Debugging
Two schools of thought
\Hell yes, I'm from Texas"
core dumps
printf
adb
Carnegie
Mellon
25
26
Sophisticated Debugging
GNU gdb
Mach Kernel
Investment
symbol table
source code
execution target
Debugging Tips
RS232 line
tty
stub
Test Machine
Stable Machine
Stable machine
Test machine
Carnegie
Mellon
In Kernel Testing
Simple Counters
Carnegie
Mellon
27
28
Use assert
assert(addr != 0)
Carnegie
Mellon
29
Recommended Reading
Machine-Independent Virtual Memory Management
for Paged Uniprocessors and Multiprocessor Architectures
Richard Rashid et.al.
CMU technical report CMU-CS-87-140
(also in ASPLOS II, October 1987)
Architecture-Independent Virtual Memory Management
for Parallel and Distributed Environments: The
Mach Approach
Avadis Tevanian Jr.'s Ph.D. Thesis
CMU technical report CMU-CS-88-106
Exporting a User Interface to Memory Management
from a Communication-Oriented Operating System
Michael Youngs's Ph.D. Thesis
CMU technical report CMU-CS-89-202
30
vm object
vm map entry
pmap
vm map
Carnegie
Mellon
Carnegie
Mellon
31
32
vm page Structure
Simple VM Example
vm_map
pmap
vm_map_entry
vm_page
backing
store
Physical address
Flags
inactive, active and free
Page list page is on
vm_object
Key points
Carnegie
Mellon
busy
Page in transit from pager
tabled
vm page is in object/o
set table
ctitious
vm page is placeholder in object
Carnegie
Mellon
33
34
Memory Object
Size of object
Reference count
can persist
Object can persist after last reference
internal
Created by kernel managed by default pager
Carnegie
Mellon
Carnegie
Mellon
35
36
Mapping Entry
Reference count
Miscellaneous ags
needs copy
Region marked as copy-on-write
Carnegie
Mellon
Carnegie
Mellon
37
38
Copy-on-write
Carnegie
Mellon
Two forms
Symmetric copy-on-write
Both source and destination treated the same
Asymmetric copy-on-write
Used when an external memory manager is
involved
Carnegie
Mellon
39
40
Write to Page
Symmetric Copy-on-write
Source
Source
Source
address
map entry
Destination
address
map entry
address
map entry
(needs copy)
(needs copy)
Destination
address
map entry
address
map entry
(needs copy)
contains
modified
pages
Copy Operation
shadow
object
memory
object
memory
object
contains
unmodified
pages
memory
object
Copy operation
Point destination mapping entry at source object
Write operation
Carnegie
Mellon
Carnegie
Mellon
41
42
address
map entry
copy
operation
memory
object
address
map entry
Problem
Object is backed by an external memory
manager
copy
operation
shadow
object
shadow
object
memory
object
shadow
object
memory
object
Carnegie
Mellon
Solution
Make original object a \copy object"
Copy objects push pages up to a shadow
object before they are modied
Copy objects reects all changes
Carnegie
Mellon
43
44
Asymmetric Copy-on-write
Source
Source
address
map entry
address
map entry
Destination
lookup
insert
remove
modify
address
map entry
operating
system
hardware
Copy Operation
memory
object
shadow
object
modify
(dirty bit)
lookup
(tlb fault)
shadow link
Original object
managed by
external pager
copy
object
"copy of" link
Write operation
If rst write to page in copy object then
push an unmodied copy to shadow and then
modify page in copy object
If rst write to page in shadow object then
pull an unmodied copy from copy object and
then modify page in shadow object
Carnegie
Mellon
pmaps
A pmap is simply a dictionary structure that
supports the following operations:
insert
remove
modify
lookup
Both hardware and the operating system query
and modify the dictionary
Hardware usually dictates the internal format of
the dictionary
Carnegie
Mellon
45
46
virtual address
directory
pte entry
page offset
root pointer
Physical address
Protection
read/write/execute
Modied ag
pte
page table
directory
Page Table Entry (pte)
page table
valid bit
modified bit
referenced bit
wired bit
Referenced ag
Wired ag
protection
Carnegie
Mellon
Carnegie
Mellon
47
48
all mappings to
the same physical
address
pmap, VA
pmap, VA
pmap, VA
physical to
virtual table
A Word on Addresses
All addresses, both virtual and physical, are byte
addresses unless specically stated otherwise
Virtual addresses are always qualied by the pmap
module they are in
A range of addresses, whether specied as a start and
end address or a start and length, always includes the
rst address and excludes the last address
The addresses for a page of memory will be given as
the rst address in the page
The page size must be a multiple of the physical page
size but need not be the same
Carnegie
Mellon
49
50
vm o
set t pmap steal memory(size)
Carnegie
Mellon
Carnegie
Mellon
51
52
Carnegie
Mellon
Carnegie
Mellon
53
54
55
Carnegie
Mellon
56
Miscellaneous Routines
Carnegie
Mellon
57
Carnegie
Mellon
58
Carnegie
Mellon
59
Carnegie
Mellon
60
Change Protection
Attributes
MATTR CACHE
Cachability
Value
Carnegie
Mellon
61
Carnegie
Mellon
62
Carnegie
Mellon
63
Carnegie
Mellon
64
Alternate method
Hard code start and ending addressed of copyin
and copyout routines and the recovery routine
Carnegie
Mellon
65
Carnegie
Mellon
66
Zone Package
67
vm oset t zalloc(zone)
vm oset t zget(zone)
Carnegie
Mellon
68
Continuations
State routines
Trap handlers
Carnegie
Mellon
Carnegie
Mellon
69
task
pcb
kernel stack
user
registers
kernel
state and
runtime
stack
map
pmap
70
active_stacks[cpu]
Trap
Interrupt
kernel
registers
thread
pcb
kernel regs
kernel stack
task
map
pmap
Calling conventions
Caller saves registers
Callee saves registers
71
Carnegie
Mellon
72
System Calls
direction of code flow
user syscall stub kernel entry kernel code kernel exit syscall stub user
(C)
(assembly) (assembly) code
code (assembly) (assembly)
caller-saves
trap into
registers saved kernel
on user stack
callee-saves
registers saved
and restored on
kernel stack
return to
user mode
caller-saves
registers
restored from
user stack
user
code
kernel entry
(assembly)
trap into
kernel
caller-saves
registers saved
kernel code
(C)
kernel exit
(assembly)
callee-saves
registers saved
and restored on
runtime stack
user
code
return to
user mode
caller-saves
registers restored
Carnegie
Mellon
73
kernel
code
trap into
kernel
caller-saves
registers saved
kernel code
(C)
callee-saves
registers saved
and restored on
runtime stack
kernel exit
(assembly)
kernel
code
return to
kernel mode
caller-saves
registers restored
74
Carnegie
Mellon
75
Carnegie
Mellon
76
Carnegie
Mellon
77
event
syscall
trap
interrupt
user
pcb
pcb
pcb
kernel can't happen current stack interrupt stack
interrupt can't happen current stack current stack
event
syscall
trap
interrupt
user
kernel stack kernel stack interrupt stack
kernel can't happen current stack interrupt stack
interrupt can't happen current stack current stack
Carnegie
Mellon
78
Continuations
Problem
Solution
Complication
typedef struct f
int mach trap arg count
int (*mach trap function)()
boolean t mach trap stack
int mach trap unused
g mach trap t
79
Carnegie
Mellon
80
Continuation Routines
Carnegie
Mellon
81
Carnegie
Mellon
82
PCB Routines
Context Switch
Move the stack from the old thread to the new one
Carnegie
Mellon
83
Carnegie
Mellon
84
Trap Handlers
Clock interrupt
Exceptions
Carnegie
Mellon
85
Carnegie
Mellon
86
asto(cpu)
aston(cpu)
Carnegie
Mellon
87
Carnegie
Mellon
88
Libmach
Libmach
Cthread locks
Cthread routines
Emulator routines
fork
Special fork that calls mach init() in child
Signals
crt0.s
Special version that calls mach init() and
cthread init() routines
Carnegie
Mellon
89
Carnegie
Mellon
90
Cthread Locks
spin lock t
spin unlock(s)
Carnegie
Mellon
91
Spin unlock
Carnegie
Mellon
92
Cthread Routines
emulation
library
Carnegie
Mellon
93
server
kernel
1.
2.
3.
4.
94
Emulator Routines
void emul setup(task)
Call task set emulation(task, routine,
syscall number) for each system call
Most syscalls are redirected to emul common
except e fork which is directed to emul save regs
Positive syscall numbers are UNIX syscalls
negative numbers are CMU extensions
Carnegie
Mellon
95
Carnegie
Mellon
96
Emul common
1.
2.
3.
4.
5.
8.
9.
10.
Carnegie
Mellon
97
Carnegie
Mellon
Emul syscall
Signals
98
sigreturn
Called by signal handler
if using mapped U area
call e shared sigreturn()
else
call bsd sigreturn()
The server may need assistance from the kernel to
restore the state
Carnegie
Mellon
99
Carnegie
Mellon
100
Carnegie
Mellon
101