Professional Documents
Culture Documents
Design Overview
Jim Huang ( ) <jserv@0xlab.org>
Developer, 0xlab
July 17, 2012 / Julu!Dev
June 11, 2012 / "!#$, "!#$
Rights to copy
Attribution ShareAlike 3.0
ou are !ree
%o &opy, 'i(%ribu%e, 'i(play, an' per)orm %*e +or,
%o ma,e 'eriva%ive +or,(
%o ma,e &ommer&ial u(e o) %*e +or,
"n#er the !ollowing con#itions
Attribution. -ou mu(% give %*e original au%*or &re'i%.
Share Alike. #) you al%er, %ran()orm, or buil' upon %*i( +or,, you may 'i(%ribu%e %*e
re(ul%ing +or, only un'er a li&en(e i'en%i&al %o %*i( one.
.or any reu(e or 'i(%ribu%ion, you mu(% ma,e &lear %o o%*er( %*e li&en(e %erm( o) %*i( +or,.
/ny o) %*e(e &on'i%ion( &an be +aive' i) you ge% permi((ion )rom %*e &opyrig*% *ol'er.
our !air use an# other rights are in no wa$ a!!ecte# b$ the above.
0i&en(e %ex%1 *%%p1//&rea%ive&ommon(.org/li&en(e(/by2(a/3.0/legal&o'e
"opyrig*% 2012 0%lab
*%%p1//0xlab.org/
&on%a&%@0xlab.org
"orre&%ion(, (ugge(%ion(, &on%ribu%ion( an' %ran(la%ion(
are +el&ome4
0a%e(% up'a%e1 July 17, 2012
On -Kernel Construction
Jochen Liedtke (1953-2001)
15
th
ACM Symposium on Ope!tin" System
#incip$es (1995)
Use Case: Low-cost 3G Handset
Mo%i$e &!ndsets
' 5a6or appli&a%ion( run( on 0inux
' 37 5o'em (o)%+are (%a&, run( on 89!
'omain
:ir%uali;a%ion in mul%ime'ia Devi&e(
' 8e'u&e( <5 (bill o) ma%erial()
' $nable( %*e 8eu(abili%y o) lega&y
&o'e/appli&a%ion(
' 8e'u&e( %*e (y(%em 'evelopmen% %ime
#n(%rumen%a%ion, /u%oma%ion
' 8un 89! )or 5ea(uremen% an'
analy(i(
' 8un a 7=! )or 7rap*i&al #n%er)a&e
Hypervisor
(ith )itu!$i*!tion+ sin"$e chip oi"in!$ mo%i$e phone+
t(o C#,s e-uied
./oke0s ,1 2unction!$ities inc$udin" the
touch sceen is o(ned %y the Linu3
!pps (hi$e /ideo endein" uses !
endein" en"ine unnin" on 45.67
6hen ! use e-uests ! 45.6 !pp8
Linu3 communci!tes (ith 45.6 in the
othe )M to st!t up the !pp7 9he
45.6 o%t!ins !ccess to the sceen %y
usin" ! 2!me %u22e 2om ! sh!ed-
memoy m!ppin"7
Agen#a
Myths of Microernel
Characteristics of !nd generation
"icroernel
' "e"ory# thread# $%C "anage"ent
&oward 3rd generation "icroernel
Real-world 'eploy"ent
Myths of Microernel
'efinition of Kernel
9he 2und!ment!$ p!t o2 !n Ope!tin" System7
5esponsi%$e 2o po/idin" secue !ccess to the m!chine0s h!d(!e 2o
/!ious po"!ms7
5esponsi%$e 2o decidin" (hen !nd ho( $on" ! po"!m c!n use ! cet!in
h!d(!e (mu$tip$e3in")7
Monolithic (s) Microernel
Application Application
User mode
Supervisor mode
Hardware
Monolithic kernel
FS
Network stack
Driver
hread !ontrol
H"# mana$ement
S%stem call & open'File
Application Application
User mode
Supervisor mode
Hardware
S%stem call & open'File
hread !ontrol
H"# mana$ement
()!
FS
Network
Stack
Device
Driver
Monolithic (s) Microernel
Hy*rid Kernel
Com%ine the %est o2 %oth (o$ds
'
!pee' an' (imple 'e(ign o) a monoli%*i& ,ernel
'
5o'ulari%y an' (%abili%y o) a mi&ro,ernel
!%ill (imilar %o a monoli%*i& ,ernel
' Di(a'van%age( (%ill apply *ere
$xample1 >in'o+( ?9, <e!, Dragon.ly<!D
+,oernel
:o$$o(s end-to-end pincip$e
' $x%remely minimal
'
.e+e(% *ar'+are ab(%ra&%ion( a( po((ible
' Ju(% allo&a%e( p*y(i&al re(our&e( %o app(
l' name(()1 pi&o,ernel, nano,ernel
$xample1 5#9 $xo,ernel, ?eme(i(, $x!
Kernel Co"parison
Mono$ithic kene$s
' /'van%age(1 per)orman&e
' Di(a'van%age(1 'i))i&ul% %o 'ebug an' main%ain
Microkernels
' A#vantages: &ore reliable an# secure
' Disa#vantages: &ore overhea#
Hybri' @ernel(
' /'van%age(1 bene)i%( o) monoli%*i& an' mi&ro,ernel(
' Di(a'van%age(1 (ame a( monoli%*i& ,ernel(
$xo,ernel(
' /'van%age(1 minimal an' (imple
' Di(a'van%age(1 more +or, )or appli&a%ion 'eveloper(
'efinition of Microernel
A kene$ techni-ue th!t po/ides on$y the minimum
OS se/ices7
' /''re(( !pa&ing
'
#n%er2pro&e(( "ommuni&a%ion (#=")
' 9*rea' 5anagemen%
'
AniBue #'en%i)ier(
/ll o%*er (ervi&e( are 'one a% u(er (pa&e
in'epen'en%ly.
Device Drivers
User Program
Memory
Managers
User Mode
Address spacing Thread
Management
and IPC
Unique
Identifiers
Microkernel Mode
Hardare
Microernel
Microernel -d(antage
A c$e! micokene$ inte2!ce en2oces ! moe
modu$! system stuctue
!erver( &an u(e %*e me&*ani(m( provi'e' by %*e
mi&ro,ernel li,e any o%*er u(er program.
!o (erver mal)un&%ion i( a( i(ola%e' a( any o%*er u(er
program0( mal)un&%ion
9*e (y(%em i( more )lexible an' %ailorable. Di))eren%
(%ra%egie( an' /=#(, implemen%e' by 'i))eren% (ever(,
&an &oexi(% in %*e (y(%em
3 Generations of Microernel
M!ch8 Chous (19;5-199<)
' ep$!ce pipes (ith 1#C (moe "ene!$)
' impo/ed st!%i$ity (/s mono$ithic kene$s)
' poo pe2om!nce
L3 = L< (1990-2001)
' L!"e impo/ements in 1#C pe2om!nce
' 6itten in !ssem%$y8 poo pot!%i$ity
' on$y synchonus 1#C (%ui$d !sync on top o2 sync)
' /ey sm!$$ kene$+ moe 2unctions mo/ed to usesp!ce
seL<8 Coyotos8 >o/! (2000-pesent)
' p$!t2om independence
' /ei2ic!tion8 secuity8 mu$tip$e C#,s8 etc7
!upervi(or
Di(pa%&*e( %rap(, in%errup%(, an' ex&ep%ion( 'elivere' by
*ar'+are.
8eal 9ime $xe&u%ive
"on%rol( allo&a%ion o) pro&e((e( an' provi'e( preemp%ive
(&*e'uling
:ir%ual 5emory 5anager
5anipula%e( :5 *ar'+are an' memory re(our&e(.
#="
=rovi'e( me((age $x&*anging an' 8emo%e =ro&e'ure "all(
(8=").
.st Generation: Chorus /ucleus
Asynchonous 1#C
9he!ds
Schedu$in"
Memoy m!n!"ement
5esouce !ccess pemissions
?e/ice di/es (in some /!i!nts)
(A$$ othe 2unctions !e imp$emented outside kene$7 )
A#1 Si*e o2 M!ch 3+ 1<0 2unctions
.st Generation: CMU Mach
Checkin" esouce !ccess pemissions on system
c!$$s7
Sin"$e use m!chines do not need to do this7
C!che misses
Citic!$ sections (ee too $!"e7
Asynchonus 1#C
Most c!$$s on$y need synchonus 1#C7
Synchonous 1#C c!n %e 2!ste th!n !synchonous7
Asynchonous 1#C c!n %e %ui$t on top o2 synchonous7
)itu!$ memoy
&o( to pe/ent key pocesses 2om %ein" p!"ed out@
Mach "icroernel perfor"ance issues
!nd Generation: L0
A5!dic!$B !ppo!ch
CLiedtke0938 Liedtke D95E+
Stict minim!$ity
:om-sc!tch desi"n
:!st pimiti/es
3rd Generation: seL0
C.$phinstone et !$ 200F8 G$ein et !$ 2009E
Secuity-oiented desi"n
' c!p!%i$ity-%!sed !ccess conto$
' ston" iso$!tion
&!d(!e esouces su%Hect to use-de2ined po$icies
' inc$udin" kene$ memoy (no kene$ he!p)
' e3cept time
' AMicohype/isoI concept
?esi"ned 2o 2om!$ /ei2ic!tion
Classical L0 "icroernel functionality
9he!ds
Schedu$in"
Memoy m!n!"ement
(A$$ othe 2unctions !e imp$emented outside kene$)
A#1 si*e o2 L<+ F 2unctions
' Comp!e to 1<0 2unctions 2o M!ch3
L0 Mi"ni"ality %rinciple
A concept is to$e!ted inside the micokene$ on$y i2
mo/in" it outside the kene$8 i.e.8 pemittin"
competin" imp$ement!tions8 (ou$d pe/ent the
imp$ement!tion o2 the systemJs e-uied 2unction!$ity7
:ed 4ooks on conceptual integrity CMythic!$ M!n
MonthE
' ,>1K + ./eythin" is ! 2i$e
' M!ch + 1#C "ene!$i*es 2i$es
' L< + C!n it %e put outside the kene$@
25
Architecture !ersion Te"t Total
K;L L<G! 52k 9;k
1t!nium L<G! 1F3k <1Fk
A5M OGL< <;k F;k
##C-32 L<G! <1k 135k
##C-L< L<G! L0k 205k
M1#S-L< >1C9A L1k 100k
Line o2 Code in OGL<
' CD, 0" ar&*i%e&%ure2in'epen'en%
' 0.EFG, 0" ar&*i%e&%ure/pla%)orm2(pe&i)i&
5emory )oo%prin% ,ernel (no% aggre((ively minimi;e')1
' A(ing g&& (poor &o'e 'en(i%y on 8#!"/$=#" ar&*i%e&%ure()
L0 Kernel si1e
./ey system c!$$ temin!tes
>o e3ceptions tho(n
>o !ithmetic po%$ems (e7"78 o/e2$o(8 di/ide %y *eo)
>o nu$$ pointe de-e2eences
>o i$$-typed pointe de-e2eences
>o memoy $e!ks
>o %u22e o/e2$o(s
>o unchecked use !"uments
Code inHection !tt!cks !e impossi%$e
6e$$-2omed d!t! stuctues
Coect %ook-keepin"
>o t(o o%Hects o/e$!p in memoy
2hat properties do we e,pect fro"
Kernel3
Characteristics of second
generation "icroernel:
"e"ory# thread# $%C "anage"ent
&ass
5epesent unit o2 e3ecution
' .3ecute use code (!pp$ic!tion)
' .3ecute kene$ code (system c!$$s8 p!"e
2!u$ts8 inteupts8 e3ceptions)
Su%Hect to schedu$in"
' Mu!si-p!!$$e$ e3ecution on one C#,
' #!!$$e$ e3ecution on mu$tip$e C#,s
' )o$unt!i$y s(itch to !nothe the!d
possi%$e
' #eempti/e schedu$in" %y the kene$
!ccodin" to cet!in p!!metes
Associ!ted (ith !n !ddess sp!ce
' .3ecutes code in one t!sk !t one point
in time
(Mi"!tion !$$o(s the!ds mo/e to
!nothe t!sk)
' Se/e!$ the!ds c!n e3ecute in one t!sk
&hreads
5epesent dom!in o2 potection !nd iso$!tion
Cont!ine 2o code8 d!t! !nd esouces
Addess sp!ce+ c!p!%i$ities N memoy
p!"es
m!n!"ement ope!tions+
' M!p+ sh!e p!"e (ith othe !ddess
sp!ce
' O!nt+ "i/e p!"e to othe !ddess
sp!ce
' ,nm!p+ e/oke pe/ious$y m!pped
p!"e
L0 uniprocessor "icroernel
9*rea'
/b(%ra&%ion an' uni% o)
exe&u%ion
#'en%i)ie' by %*rea' #D
"on(i(% o)
#n(%ru&%ion poin%er
!%a&,
8egi(%er(, )lag(H
9*rea' (%a%e
0I manage( (pre(erve) only
#=, != an' regi(%er(
ask*s
address space
!ode
read
e+ecution
paths
Data
Stack
L0 uniprocessor "icro ernel
9*rea' (+i%&*
Micro,ernel
,ernel stack ,ernel stack
-
-
-
-
State State
!ode
-
-
Stack
!ode
-
-
Stack
!)U
( )
S )
Fla$s
hread A
hread .
!. A !. .
(nterrupt
,ernel
!ode
1#PS#P:$!"s77 1#PS#P:$!"s77
L0 uniprocessor "icro ernel
!&*e'uling
!&*e'uling implemen%e' by ,ernel, ba(e' on
priori%ie(
9ime(li&e 'ona%ion
-ddress 4pace
3 managemen% opera%ion(
5ap/Anmap
!*are/revo,e page +i%* o%*er a''re(( (pa&e
7ran%
give page %o o%*er a''re(( (pa&e
.lu(*
9*e o+ner o) an a''re(( (pa&e &an flush any o) i%( page(.
)a$er )a$er User Address space
Map
Map
Map
/rant
Recursi(e -ddress 4pace
5a*andoned *y seL06
?iect !nd indiect d!t! copy
,9C4 mess!"e (speci!$ !e!)
Speci!$ c!se+ e"iste-on$y mess!"e
#!"e2!u$ts duin" use-$e/e$ memoy !ccess possi%$e
Messages: Copy 'ata
A))
)0
)1
App :!u$t
#1 touches its
o(n p!"e !nd
2!u$ts
#0 m!ps
then #1