Domain Specific Languages: Ad Do Ti ST Advanced Operating Systems
Domain Specific Languages: Ad Do Ti ST Advanced Operating Systems
AdvancedOperatingSystems Ad dO ti S t (263380000)
Outline
Introduction Interfacedefinitionlanguages H d Hardwareinterfacelanguages i f l FiletofFish Hamlet References
Highlevellanguagestothe rescue?
Write your OS in Java/Eiffel/C#/etc. WriteyourOSinJava/Eiffel/C#/etc.
Hasbeentried.Severaltimes.
Problems:
Loseallcontroloverresourcemanagement Explicit layout / memory access becomes hard Explicitlayout/memoryaccessbecomeshard Stillcantexpresshighlevelsemantics
(OScodeishighlyspecialized)
Sufficientlyexpressivelanguagestooslowandtooabstract
(e.g.Haskell)
ExtendC? Extend C?
Promisingapproach: Promising approach: NesC:TinyOSs Cdialectwithsupportformodules, events[Gay2003] events [Gay 2003] Deputy:extensionstoCusingtypeinferencefor staticchecks[e.g.Anderson2009] static checks [e g Anderson 2009] Ivy:evolvingCasalanguage[Brewer2005] Sofar,littleuptake(poortoolchain support?)
Forallourexamples:
C compiler
Binary i
Advantages
Highlyspecialized:capturetheexactsemanticsyouwant! Cancheckandenforceusefulinvariants Small,easytolearn Canbeveryfast(fasterthanaprogrammercouldwrite) C b f t (f t th ld it ) Dramaticallyreducesdevel/debugtime
Outline
Introduction Interfacedefinitionlanguages H d Hardwareinterfacelanguages i f l FiletofFish Hamlet References
Userclientcode Cfunctioncall
Transmit stub
Receive stub t b
Thisisnotenoughlocally,inanOSwith:
Sharedmemorytransport Nogarbagecollection Values (like arrays) bigger than a register or machine word Values(likearrays)biggerthanaregisterormachineword
Thisisnotenoughlocally,inanOSwith:
Sharedmemorytransport Nogarbagecollection Values (like arrays) bigger than a register or machine word Values(likearrays)biggerthanaregisterormachineword
MemorymanagementinIDLs
[HamiltonandKougiouris,1994]
TheIDLfortheSpringOSmodifiedCORBAIDLforanOS The IDL for the Spring OS modified CORBA IDL for an OS setting:
copy:Argumentiscopiedtotheserver. py g p consume:Argumentissentfromclienttoserver,and destroyedatclient. produce:Argumentisgeneratedattheserverandsentback (destroyedatserver) borrow:Likeinout,butcan tbemodifiedbyclientinthe borrow: Like inout but cant be modified by client in the meantime.
Performance
FornetworkIDLs (CORBA,ANSA,DCE,SunRPC,etc.) For network IDLs (CORBA, ANSA, DCE, SunRPC, etc.) stubperformancenotcritical
Networklatencydominates y Callsareinfrequent Callsmusttraversenetworkstackanyway
ItsverydifferentforlocalOSstubs:
IPCsystemhighlyoptimized stubperformancecritical Callsarefrequent(particularlyinamicrokernel)
Performance
FornetworkIDLs (CORBA,ANSA,DCE,SunRPC,etc.) For network IDLs (CORBA, ANSA, DCE, SunRPC, etc.) stubperformancenotcritical
Networklatencydominates y Callsareinfrequent Callsmusttraversenetworkstackanyway
ItsverydifferentforlocalOSstubs:
IPCsystemhighlyoptimized stubperformancecritical Callsarefrequent(particularlyinamicrokernel)
Flick
[Eide etal.,1997]
Flickperformance
[Eide etal.,1997]
Showseffectofcompileroptimizationsonmarshallingcode: p p g
Outline
Introduction Interfacedefinitionlanguages H d Hardwareinterfacelanguages i f l FiletofFish Hamlet References
Consequencesoferrorsarebad
Veryhardtofindbugs Frequently hangs entire machine Frequentlyhangsentiremachine
Ccodetomanipulateregistersistedioustowrite
DevilExample:LogitechBusmouse
[Mrillon etal.,2000]
DevilExample:LogitechBusmouse
[Mrillon etal.,2000]
Programmerusageidioms:
DevilExample:LogitechBusmouse
[Mrillon etal.,2000] DevicespecifiedintheDevilDSL: p
DevilExample:LogitechBusmouse
[Mrillon etal.,2000]
WhatsDevilgenerating?
DevilExample:LogitechBusmouse
[Mrillon etal.,2000]
Whattheprogrammergetstowrite:
Variables
valueswhichcombinations(usuallyconcatenations)of registervalues
Mackerel
Barrelshs answertoDevil
Things havechangessomewhatinthemeantime: g g
Lotsofaddressspace Indexregistersarelessfrequent
preconditionslessimportant Registeraddressspacesmoreuseful(PCI,memory,IO)
Registersarewider(32or64bits)
meaningfulvaluesrarelysplitacrosshardwarefields
Mackerel
Example:Intele1000Ethernetcontroller Fragmentshowingaregisterdefinition:
register status rw addr(base, 0x0008) "Device status" { g ( , ) fd 1 "Link full duplex configuration"; lu 1 "Link up"; lan_id 2 "LAN ID"; txoff 1 "Transmission paused"; Transmission paused ; tbimode 1 "TBI mode"; speed 2 type(linkspeed) "Link speed setting"; asdv 2 type(linkspeed) "Auto speed detection val"; phyra 1 "PHY reset asserted"; PHY asserted ; _ 8 mbz; gio_mes 1 "GIO master enable status"; _ 12; };
BuildingaDSL:whatdoesit take? k
DSLs are basically simple compilers: arebasicallysimplecompilers:
BuildingaDSL:whatdoesit take? k
DSLs are basically simple compilers: arebasicallysimplecompilers: 1. Parser
U d t b t di Usedtobetedioustowrite t it Gloriouseasythesedays E g combinatorbased Monadic parsing in Haskell E.g.combinator basedMonadicparsinginHaskell
BuildingaDSL:whatdoesit take? k
DSLs are basically simple compilers: arebasicallysimplecompilers: 1. Parser
U d t b t di Usedtobetedioustowrite t it Gloriouseasythesedays E g combinatorbased Monadic parsing in Haskell E.g.combinator basedMonadicparsinginHaskell
2. BackendCcodegenerator
Rather more difficult Rathermoredifficult...
FiletoFish
[Dagand etal.,2009]
FiletoFishis... ToolforwritingCcodegenerators Embedding of a subset of C in Haskell EmbeddingofasubsetofCinHaskell NotationforexpressingDSLsemantics Lib LibraryforcreatingprovablycorrectCcodefrom f ti bl tC d f semanticspecifications UsedinBarrelfish for(todate)2DSLs: Used in Barrelfish for (to date) 2 DSLs:
Fugu defineserrorcodesandanerrorstack Hamlet defines capability type system definescapabilitytypesystem
WecaptureallthisinformationinaHamletspecification.
HowFiletoFishcompilesHamlet
[Dagand etal.,2009]
HowFiletoFishcompilesHamlet
[Dagand etal.,2009]
UsingQuickCheck totestDSLs
[Dagand etal.,2009]
Typesystemenforcespagetablecorrectness
Can encode multiple physical address spaces etc Canencodemultiplephysicaladdressspaces,etc. Weexpecttopushfurtherfunctionalityintocapability system
Summary
Usedappropriately: pp p y Reducecodecomplexity
Though rarely if never actually evaluated Thoughrarely,ifnever,actuallyevaluated DSLs perhapsseenmoreasameanstoanend...
Reducebugs
Capture(andcheck)highlevelsemanticsofthedomain
Facilitateautomatedtestingand/orcorrectness proofs
References
Birrell,A.D.andNelson,B.J.(1984).Implementingremoteprocedure calls. ACMTrans.Comput.Syst.,2(1):3959. calls ACM Trans Comput Syst 2(1) 39 59 Dagand,P.E.,Baumann,A.,andRoscoe,T.(2009).FiletoFish:Practical andDependableDomainSpecificLanguagesforOSDevelopment.In Proc.5thWorkshoponProgrammingLanguagesandOperatingSystems Proc. 5th Workshop on Programming Languages and Operating Systems (PLOS2009). Eide,E.,Frei,K.,Ford,B.,Lepreau,J.,and Lindstrom,G.(1997).Flick:A flexible,optimizingIDLcompiler.InPLDI,pages4456. Hamilton,G.andKougiouris,P.(1994).TheSpringnucleus:Amicrokernel forobjects.Technicalreport,SunMicrosystemsLaboratories. Mrillon,F.,Rveillre,L.,Consel,C.,Marlet,R.,andMuller,G.(2000). Devil:AnIDLforhardwareprogramming.InProceedingsofthe4th il f h d i di f h h USENIXSymposiumonOperatingSystemsDesignandImplementation.
References
DavidGay,PhilipLevis,RobertvonBehren,MattWelsh,EricBrewer, andDavidCuller.2003.ThenesC l d D id C ll 2003 Th C language:Aholisticapproachto A h li ti ht networkedembeddedsystems.InProceedingsoftheACM SIGPLAN2003conferenceonProgramminglanguagedesignand implementation(PLDI'03).ACM,NewYork,NY,USA,111 p ( ) , , , , ZacharyR.Anderson,DavidGay,andMayur Naik.2009.Lightweight annotationsforcontrollingsharinginconcurrentdatastructures. InProceedingsofthe2009ACMSIGPLANconferenceon g Programminglanguagedesignandimplementation(PLDI'09) EricBrewer,JeremyCondit,BillMcCloskey,andFeng Zhou.2005. Thirtyyearsislongenough:gettingbeyondC.InProceedingsof the10thconferenceonHotTopicsinOperatingSystems Volume h h f l 10(HOTOS'05),Vol.10.USENIXAssociation,Berkeley,CA,USA,14 14.