Everything Y ou Alw a ys W anted T o Kno w Ab out MIG - - PDF document

everything y ou alw a ys w anted t o kno w ab out mig but
SMART_READER_LITE
LIVE PREVIEW

Everything Y ou Alw a ys W anted T o Kno w Ab out MIG - - PDF document

Everything Y ou Alw a ys W anted T o Kno w Ab out MIG But W ere Afraid T o Ask Richa rd P Draves rpdcscmuedu Scho ol of Computer Science Ca rnegie Mellon Universit y Pittsburgh P A


slide-1
SLIDE 1 Everything Y
  • u
Alw a ys W anted T
  • Kno
w Ab
  • ut
MIG
  • But
W ere Afraid T
  • Ask
Richa rd P
  • Draves
rpdcscmuedu Scho
  • l
  • f
Computer Science Ca rnegie Mellon Universit y Pittsburgh P A
slide-2
SLIDE 2 Mig
  • Stub
generato r fo r Mach IPC
  • P
ack unpack demultiplex messages
  • NOT
transpa rent languagelevel RPCs
  • Do
esnt hide IPC features
  • Assumes
clientserver mo del
slide-3
SLIDE 3 Mig Histo ry

late Matchmaker

Mike Jones real types Lisp, Pascal, C

early Matchmaker

Mary Thompson Keith Wright Mike Jones - exceptions Mike Young - C

MIG

Mike Young Rich Draves - rewrote Draves & Golub - features

slide-4
SLIDE 4 Mig Programming Mo del
  • Clients
call stubs machpo rt t server po rt kr
  • getbalan
ce s er ve rp
  • r
t balanc e
  • Server
lo
  • p
p ro cesses requests extern boolean t bankserv er
  • machpo
rt t server po rt define MAXSIZ E
  • void
machmsg s er ve rb an k se rv er
  • MAXSIZE
  • server
po rt
  • kernre
tu rn t getbala nce s er ve r po rt
  • balance
machpo rt t serverp
  • r
t int balanc e
  • ut
slide-5
SLIDE 5 Mig Example
  • file
example d ef s
  • subsystem
example
  • include
machst d ty pe s de fs
  • manipula
te a bank account
  • routine
getbala nc e server
  • machpo
rt t
  • ut
balance
  • int
Client call include example h
  • machport
t server int balance
  • kernretu
rn t kr kr
  • getbalan
ce s er ve r balanc e
  • Server
function kernretu rn t getbala nc e se rv er
  • balance
machport t server int balanc e
  • ut
  • balance
  • serverb
al an ce
  • return
KERNSUC CE SS
slide-6
SLIDE 6 T yp e Denitions
  • from
machst d ty pe s de fs
  • type
machpor t t
  • MACHMSG
T YP E CO PY S END
  • type
int
  • MACHMSG
T YP E IN TE GE R
  • type
kernret ur n t
  • int
  • pointer
to
  • utof
li ne memory
  • type
pointer t
  • array
  • f
MACHMSG T YPE B YT E
  • a
byte structur e
  • type
machpor t st at us t
  • struct
  • f
int
  • C
declarat io ns for these types
  • import
machst d ty pe s h
slide-7
SLIDE 7 Asynchronous Messages
  • file
example d ef s
  • subsystem
example
  • include
machst d ty pe s de fs
  • set
bank account balance
  • routine
setbala nc e server
  • machpo
rt t
  • in
balance
  • int
  • set
it with an asynchr
  • n
  • u
s message
  • simplerou
ti ne asetbal an ce
  • server
  • machpo
rt t
  • in
balance
  • int
  • Client
and server co de lo
  • ks
lik e RPC
  • Messageo
rdering p roblems in multithreaded servers
  • Controlo
w w
  • rries
  • Not
recommended fo r general use
slide-8
SLIDE 8 Asynchronous Messages Client call include example h
  • machport
t server int balance
  • kernretu
rn t kr kr
  • setbalan
ce s er ve r balance
  • kr
  • asetbala
nc e se rv er
  • balance
  • Server
function kernretu rn t setbala nc e se rv er
  • balance
machport t server int balance
  • in
  • serverba
la nc e
  • balance
return KERNSUC CE SS
  • kernretu
rn t asetbal an ce s er ve r balance machport t server int balance
  • in
  • serverba
la nc e
  • balance
return KERNSUC CE SS
slide-9
SLIDE 9 Structure Arguments
  • file
example d ef s
  • subsystem
example
  • include
machst d ty pe s de fs
  • include
example t yp es d ef s routine structd em
  • server
  • machpo
rt t
  • in
arg
  • smalls
tr uc t t
  • ut
arg
  • smalls
tr uc t t inout arg
  • smalls
tr uc t t
  • file
example t yp es d ef s
  • include
machst d ty pe s de fs
  • type
smallst ru ct t
  • struct
  • f
int import example t yp es h
  • file
example t yp es h
  • ifndef
EXAMPL E TY PE S H define EXAMPL E TY PE S H typedef struct smallst ru ct
  • int
  • ne
int two
  • smallstr
uc t t endif EXAMPL E TY PE S H
slide-10
SLIDE 10 Structure Arguments Client call include example h
  • machport
t server smallstr uc t t arg arg arg kernretu rn t kr kr
  • structde
mo s er ve r arg arg arg Server function kernretu rn t structd em
  • se
rv er
  • arg
arg arg machport t server smallstr uc t t arg
  • in
  • smallstr
uc t t arg
  • ut
  • smallstr
uc t t arg
  • inout
  • arg
  • arg
arg
  • arg
return KERNSUC CE SS
slide-11
SLIDE 11 OutOfLine Arguments
  • file
example d ef s
  • subsystem
example
  • include
machst d ty pe s de fs
  • include
example t yp es d ef s routine
  • olmemo
ry de mo
  • server
  • machpo
rt t
  • in
arg
  • someme
mo ry t
  • ut
arg
  • someme
mo ry t
  • file
example t yp es d ef s
  • Variable
s iz ed
  • utof
li ne memory
  • Mig
type name is someme mo ry t
  • C
type name is vmaddr es s t
  • type
somemem
  • r
y t
  • array
  • f
MACHMSG TY PE B YT E ctype vmaddre ss t
  • for
C declarat io n
  • f
vmaddr es s t
  • import
machma ch in e vm t yp es h
slide-12
SLIDE 12 OutOfLine Arguments Client call include example h
  • machport
t server vmaddres s t arg arg vmsizet size size kernretu rn t kr void vmalloc at e ma ch t as k se lf
  • arg
size TRUE kr
  • olmemor
yd em
  • se
rv er
  • arg
size arg size
  • void
vmdeall
  • c
at e ma ch t as k se lf
  • arg
size void vmdeall
  • c
at e ma ch t as k se lf
  • arg
size Server function kernretu rn t
  • olmemo
ry de mo s er ve r arg size arg size machport t server vmaddres s t arg
  • in
  • vmsizet
size
  • in
  • vmaddres
s t arg
  • ut
  • vmsizet
size
  • ut
  • arg
  • arg
size
  • size
return KERNSUC CE SS
slide-13
SLIDE 13 Deallo cation
  • file
example d ef s
  • subsystem
example
  • include
machst d ty pe s de fs
  • include
example t yp es d ef s
  • dealloca
te arg while sending the reply
  • routine
  • olmemo
ry de mo
  • server
  • machpo
rt t
  • in
arg
  • someme
mo ry t
  • ut
arg
  • someme
mo ry t
  • dealloc
  • Server
function kernretu rn t
  • olmemo
ry de mo s er ve r arg size arg size machport t server vmaddres s t arg
  • in
  • vmsizet
size
  • in
  • vmaddres
s t arg
  • ut
dealloc
  • vmsizet
size
  • ut
  • Outof
li ne memory from the client in arg is
  • returne
d to the client with automati c dealloca ti
  • n
  • arg
  • arg
size
  • size
return KERNSUC CE SS
slide-14
SLIDE 14 Dynamic Deallo cation
  • file
example d ef s
  • subsystem
example
  • include
machst d ty pe s de fs
  • include
example t yp es d ef s
  • generate
extra dealloc argumen t for arg always dealloc at e arg while sending the reply
  • routine
  • olmemo
ry de mo
  • server
  • machpo
rt t
  • in
arg
  • someme
mo ry t
  • dealloc
  • ut
arg
  • someme
mo ry t
  • dealloc
  • Client
call include example h
  • machport
t server vmaddres s t arg arg vmsizet size size kernretu rn t kr void vmalloc at e ma ch t as k se lf
  • arg
size TRUE
  • dealloca
te arg while sending the request
  • kr
  • olmemor
yd em
  • se
rv er
  • arg
size TRUE arg size
  • void
vmdeall
  • c
at e ma ch t as k se lf
  • arg
size
slide-15
SLIDE 15 P
  • rt
Arguments
  • No
rmal p
  • rt
rights
  • MACHMSG
TY PE CO PY SE ND
  • MACHMSG
TY PE MA KE SE ND
  • MACHMSG
TY PE MO VE SE ND
  • MACHMSG
TY PE MA KE SE ND ON CE
  • MACHMSG
TY PE MO VE SE ND ON CE
  • MACHMSG
TY PE MO VE RE CE IVE
  • P
  • lymo
rphic p
  • rt
rights
  • MACHMSG
TY PE PO RT SE ND
  • MACHMSG
TY PE PO RT SE ND ON CE
  • MACHMSG
TY PE PO RT RE CE IVE subsystem example
  • routine
portdem
  • server
  • machpo
rt t
  • in
arg
  • machpo
rt t
  • MACHMS
GT YP E PO RT S EN D
  • ut
arg
  • machpo
rt t
  • MACHMS
GT YP E PO RT S EN D ON CE
  • in
arg
  • machpo
rt t
  • MACHMS
GT YP E MO VE R EC EI VE
slide-16
SLIDE 16 P
  • rt
Arguments Client call include example h
  • machport
t server machport t arg arg arg kernretu rn t kr kr
  • portdemo
s er ve r arg MACHMS GT YP E MO VE S EN D arg arg Server function kernretu rn t portdem
  • se
rv er
  • arg
arg argtyp e arg machport t server machport t arg
  • in
  • machport
t arg
  • ut
  • machmsg
ty pe n am e t argtyp e
  • ut
  • machport
t arg
  • in
  • dispose
  • f
the port rights we received
  • if
MACHPO RT V AL ID a rg
  • void
machpor t de al lo ca te m ac ht as k se lf
  • arg
if MACHPO RT V AL ID a rg
  • void
machpor t mo d re fs m ac h tas k se lf
  • arg
MACHPO RT RI GH T RE CE IV E
  • return
a sendon ce right to the server port
  • arg
  • server
argtype
  • MACHMS
G TY PE M AK E SE ND ON CE
  • return
KERNSUC CE SS
slide-17
SLIDE 17 PseudoArgumen ts subsystem example
  • include
machst d ty pe s de fs
  • ServerPre
fi x do
  • give
the server the reply port and sequence number from the request message header
  • routine
pseudod em
  • server
  • machpo
rt t
  • SReplyP
  • r
t reply machpo rt t
  • MACHMS
GT YP E MA KE S EN D ON CE
  • MsgSeqn
  • seqno
  • machpo
rt s eq no t in realarg
  • int
Client call machport t server kr
  • pseudode
mo s er ve r
  • Server
function kernretu rn t dopseu do de mo s er ve r reply seqno realarg machport t server machport t reply machport s eq no t seqno int realarg
  • printfR
ec ei ve d dn realarg
  • return
KERNSUC CE SS
slide-18
SLIDE 18 Cho
  • sing
Subsystem Ranges subsystem name msgid
  • request
msg is msgid
  • reply
is msgid
  • routine
first
  • skip
  • skip
msgid
  • request
msg is msgid
  • reply
is msgid
  • routine
second
  • F
  • r
bina ry compatibili t y
  • MsgIDs
and real inout a rguments should b e p reserved
  • MsgID
ranges handled b y a single server should not
  • verlap
  • Helpful
but not essential to k eep interfaces under
  • routines
slide-19
SLIDE 19 Message La y
  • ut
  • file
example d ef s
  • subsystem
example
  • include
machst d ty pe s de fs
  • routine
layoutd em
  • server
  • machpo
rt t
  • in
arg
  • int
  • ut
arg
  • int
inout arg
  • int
  • from
file exampleU se r c
  • typedef
struct
  • machms
g he ad er t Head machms g ty pe t argTyp e int arg machms g ty pe t argTyp e int arg
  • Request
typedef struct
  • machms
g he ad er t Head machms g ty pe t RetCode Ty pe
  • kernre
tu rn t RetCode
  • machms
g ty pe t argTyp e int arg machms g ty pe t argTyp e int arg
  • Reply
slide-20
SLIDE 20 Server Lo
  • p
kernretu rn t machmsgs er ver d emu x maxsize rcvname Given the name
  • f
a p
  • rt
  • r
p
  • rt
set lo
  • ps
receiving request messages and sending replies Uses Miggenerated demux functions to p ro cess request messages and generate replies Needs maximum size fo r request and reply messages booleant demuxreq ue st ms g replymsg
  • Returns
TRUE if this demux function p ro cessed the request In any case must initiali ze the reply message Desired p rop erties
  • Uses
RPC fo rm
  • f
machmsg fo r p erfo rmance
  • Do
esnt leak p
  • rt
rights
  • r
memo ry regions
slide-21
SLIDE 21 ConsumeOnSuccess What happ ens to resources lik e p
  • rt
rights and
  • utofline
memo ry in request messages
  • The
server function is resp
  • nsible
if it returns success What happ ens to resources in reply messages
  • machmsgserver
is resp
  • nsible
A server function should
  • nly
p ro duce
  • utgoing
resources when it returns success Return co de from asynchronous server functions is imp
  • rtant
slide-22
SLIDE 22 Mig Hints
  • Asynchronous
messages not recommended
  • InOut
a rguments not recommended
  • Put
t yp e decla rations in a sepa rate le
  • Use
ServerPrex
  • Use
p
  • lymo
rphic p
  • rt
t yp es
  • Use
dynamic deallo c ag
slide-23
SLIDE 23 Mig Problems
  • Confusion
b et w een interface and implementation
  • Only
  • p
enco ded stubs no descripto rbased stubs
  • Nits
  • Message
size info rmation not exp
  • rted
  • Demultiplexi
ng multiple interfaces
  • MsgID
assignment