topwaitingforreboot

waitingforreboot  时间:2021-01-14  阅读:()
LightweightIOVirtualizationOnMPUEnabledMicrocontrollersFrancescoPaciUniversityofBolognaBologna,Italyf.
paci@unibo.
itDavideBrunelliUniversityofTrentoTrento,Italydavide.
brunelli@unitn.
itLucaBeniniUniversityofBolognaBologna,ItalyETHZZürich,Switzerlandluca.
benini@unibo.
itluca.
benini@iis.
ee.
ethz.
chABSTRACTIntheeraoftheInternetofThings(IoT),millionsofde-vicesandembeddedplatformsbasedonlow-costandlim-itedresourcesmicrocontrollerunits(MCUs)willbeusedincontinuousoperation.
Evenifover-the-airrmwareupdateistodayacommonfeature,manyapplicationsmightrequirenottorebootortosupporthardwareresourcesharing.
Insuchacontextstop,updateandreboottheplatformisun-practicalanddynamicloadingofnewusercodeisrequired.
ThisinturnrequiresmechanismstoprotecttheMCUhard-wareresourcesandthecontinuouslyexecutingsystemtasksfromuncontrolledperturbationcausedbynewusercodebe-ingdynamicallyloaded.
Inthispaper,wepresentaframe-workwhichprovidesalightweightvirtualizationoftheIOandplatformperipheralsandpermitsthedynamicloadingofnewusercode.
Theaimofthisworkistosupportcriticalisolationfeaturestypicalofvirtualization-readyCPUsonlow-costlow-powermicrocontrollerswithnoMMU(Mem-oryManagementUnit),IOMMUordedicatedinstructionextensions.
OurapproachonlyleveragestheMemoryPro-tectionUnit(MPU),whichisgenerallyavailableinallARMCortex-M3andCortex-M4microcontrollers.
Experimentalevaluationsdemonstratenotonlythefeasibility,butalsoasatisfactorylevelofperformanceoftheproposedframeworkintermsofmemoryrequirementsandoverhead.
KeywordsVirtualization,MPU,Microcontrollers,DynamicLinking1.
INTRODUCTIONManyIoTapplicationsenvisionthedeploymentoflargenumbersofmicrocontroller-basedsmartsensornodesinhard-to-reachlocations[1,2].
Thisnotonlymeansthattheyaresupposedtooperateunattended,withoutdirectmain-tenance,andlikelywiththesamebatteryformanyyears;butalsothatthesoftwarecouldbeupdated(ifnecessary)onlyremotely;andinmanyscenariositisexpectedthatbugxes,functionalimprovements,recongurationwillbenecessaryoverthetime.
Clearlytheoldfashionstyleforreprogrammingembeddedsystemsbasedonstoppingthedevice,updatingthermwareandrestart,becomeunfeasi-blewhenmillionsoflowcostdevicesarespreadalloverandareexpectedtobeupdatedwithnewfunctionalitymanytimesovertheirlifespan.
Inaddition,IoTdevicesareexpectedtoprovidemoreandEWiLi'16,October6th,2016,Pittsburgh,USA.
Copyrightretainedbytheauthors.
moreservicesonthesamehardware.
Thepossibilitytohavemultiple"applicationtasks"runningonthesamehardware,possiblycomingfromdierentdevelopers,introducesthechallengeofprotectingtheresourcesfrommisusesandtoguaranteeadequatecomputingbandwidthtoallthetasksortopreventover-allocationofresourcesthatwouldleadtocollectivestarvation.
Insuchascenario,well-knownvirtualizationtechnologiesalreadyusedincomputingservers,gatewaysandotherhigh-endcomputingsystemsbecomefundamentalalsoinlow-endandultra-lowcostprogrammableend-nodesforIoT.
First,thevirtualizationofthehardwareresourcesbecomesnec-essarytoexecutesecurelymulti-functionsoftwareanddif-ferentapplicationswithwell-controlledinterference.
Then,thecapabilitytoremotelydownloadnewpartsofcode,tolinkdynamicallythebinaryandtoexecuteruntimewithinthemainapplication,avoidson-sitemaintenanceorperiodicdown-timeandreboot.
ThesetworequirementshighlighttheimportanceofIOvirtualizationanddynamiclinkingonlow-cost,low-powermicrocontrollers.
However,ifthistechnologyiswellknownandavailableinoperatingsystemsforhigh-endembeddedsystems(e.
g.
LinuxonARMCortex-Amicroprocessors),providingmechanismsfordynamiclinkinginlow-resourcemicrocontrollerbasedembeddedplatforms,suchasARMCortex-Mclass,isstillachallenge,andonlyfewandlimitedsolutionshavebeenproposedsofar.
ThedynamiclinkingproposedinthisworkexecutesontheFreeRTOS[3]operatingsystemanditisbasedontheframeworkpresentedin[4]whichaddressedthecapabilitytodownloadnewfunctionsremotely.
Themaincontributionsofthispaperare:aLightweightVirtualizationlayerwhichseparatestheuserspacefromthekernelspace,thereforenowallthephysicalperipheralsarevirtualized.
Suchavir-tualizationisaprotectiontowardssystemtamperandreadytobeextendedtoprotectpossibleconictsonthehardwareassignments;oursolutionisintegratedwithFreeRTOSandexploitsstandardcommunicationAPIprovidedbytheoperat-ingsystem.
Thus,itcanbeeasilyportedalsoonothermicrocontrollers.
weprovidethecapabilitytohavethedynamiclinkingofnewusercode,managingitslifecycleaswellasitsorderlyshutdownincaseofattemptedviolationsofprotectedmemoryregions;Thepaperisorganizedasfollows.
Section2givesanoverviewofworksrelatedtoourcontribution,Section3de-scribesindepththeframeworkarchitectureandprovidesalltechnicaldetailsofthissolution,Section4detailsourper-formanceandmemoryfootprint,whileSection5concludesthepaper.
2.
RELATEDWORKSVirtualizationsupportforembeddedsystemsbasedonhigh-endCPUs,suchastheARMCortex-Aseries,hasbeenextensivelyexploredintheacademicliteratureandhasreachedindustrialmaturity[5].
Thisclassofdevicesexploitsthehardwareaccelerationextensionstoprovidehardwareab-stractionandprotectiontocriticalresources.
RecentCortex-ACPUsfeaturenativevirtualizationsupportlikeMMUandIOMMUaddresstranslation,interruptvirtualization,Trust-Zones[6,7],etc.
Cortex-MMCUsdonotcomewithanyofthosehardwareextensions.
Furthermore,availablememoryandcomputationalresourcesaremuchmorelimited.
OurworkandtherelatedworkssurveyedbelowdealwithCortex-M3andCortex-M4classofdevices,wherevirtualizationisnotamaturetechnologyandseveralcompromiseswithre-specttofullhardware-supportedvirtualizationhavetobemade.
AbstractVirtualMachinesandInterpretersOneofthemostcommonapproachesforvirtualizationonMCUsisbasedoninterpreter-basedvirtualmachines,whichhavebeenoriginallyconceivedwiththemainpurposeofcreatinghigh-leveleasy-to-uselanguagesandrun-timesatahigherabstractionlevelthanthetraditionalClanguage.
Python[8,9],Java[10,11],Javascript[12],Lua[13]arealllightweightmulti-paradigmscriptinglanguagesemployedinVirtualMachinesforembeddedsystems.
Theirmainbene-tisthecross-platformsupport.
Theyareinterpretedbyanativevirtualmachineloadedonthemicrocontroller,thustheyintroducehighoverheadintermoflatencyofaccesstotheresourcesincomparisontovirtualizationlayerswritteninnativecode,buttheyaredesignedforeasysoftwareap-plicationdevelomentandtomeettheincreasingdemandoffastruntimecustomization,withouttheneedofcomplexordedicatedcompilingtoolchains.
Suchakindofvirtualiza-tion,usually,isfocusedonimprovingportability,extensibil-ity,ease-of-useindevelopmentandprotectionbutlacksofperformance,multipleuserlevelaccessesandlow-levelhard-warecontrol.
Onlytheexposedhighlevelresourcescanbeleveragedbytheuser.
Boglioloetal.
[14]presentedVirtualSense,asensornodewhichexecutesjava-compatiblevirtualmachinecalledDar-jeelingVM[11]ontopofContikiOS[15].
Thisworkisclosetooursintheemphasisonsupportingresourceallo-cationandprotectionformultipleindependentusertasksontheMCU.
Howeverthissolution,besidestheoverheadintroducedbytheinterpreter,isorientedtoshareonlynet-workstackbetweenDarjeelingVMtasks,whileourworkisgeneraltoallperipherals.
JustInTime/AheadofTimeCompilationAwell-exploredapproachtoreducetherun-timeoverheadofVMinterpetersisJustinTimeorAheadofTimeCompi-lation.
Micropython[8]developers,forexample,introducedintheirplatformtheconceptofdecoratortoemitARMnativeopcodeandtousenativeCtypes,butnotallna-tiveCtypesaresupportedandtheimplementationofthisoptimizationisplatformdependent.
AsolutioncanbetoextendwithCwrappedfunctionscalledfrompython,buttherearedrawbacks:marshalingandunmarshalingofdataisveryexpensiveintermsofcomputationalresourcesandwiththissolutiontheprogrammerlosesthelowlevelab-straction.
Incomparison,usingoursolution,thedeveloperimplementsCfunctionswhichwillbeexecutedinuserleveltasks.
Ingeneraltheseapproachesrequireahighermemoryfootprinttohostthejust-in-timeorahead-of-timecompileprocessanddonotachievetheperformanceofnativecodeexecution.
Furthermore,theyarediculttouseincontextswherereal-timeconstraintscannottoleratethejitterintro-ducedbyon-linecompilation.
NativeImplementationsNativevirtualizationistheclosesttohardwareandextremelydesirableforresourceandperformance-limiteddevices.
ThistechniqueusuallyreliesontheuseofMPUthatistheonlyhardwareunitavailableforsecurityinlow-endsystems.
Bhattietal.
[3]presentedacompleteoperatingsystemde-signedforWSN(WirelessSensorNetwork)andoptimizedtosimultaneousexecutionofthreadswhichcanbeloadeddynamically.
TheirworkreliesonMantisOS,acustomop-eratingsystem.
TheytargetAtmelandtheirsolutionishighlycustomized,thusisnotgeneral,whileourworkreliesonFreeRTOSthereforeitishighlyextensibleandportabletootherplatforms.
Moreovertheydonotexplicitlyaddresssecurityandprotection.
Tothebestofourknowledgewendonlyoneveryrecentworkthataddressestheprobleminabroadandgeneralsense,similarlytooursolution.
Andersenetal.
[16]pre-sentedanembeddedplatformthatreliesonTinyOS.
TheyuseamixedparadigmthatpermitstohaveLuaVMbutthecomputationalintensivepartofcodecanbewritteninnativeC.
Toaddresssecuritytheyuseataskreceivingeventbasedsystemcalls,toseparatekerneltouserspacetasks.
OurworkdierentiatesfromthelatterbypermittingtohavebothsystemcallsupportandEventbasedperipheralvir-tualization.
MoreoverAndersenetal.
donotprovideanyinformationontheperformanceoftheeventbasedsystemcallparadigm.
3.
SOFTWAREARCHITECTUREInthissectionwepresentallthesoftwarelayersinourruntimesystem,focusingonsoftwareprotection.
Figure1showsthelayerstackingfromthreeviewpoints,rstfromahardwarepointofview,thenfromaddressspaceaccess,dividedinIOandFlash/RAM.
WedividedcorehardwarefromperipheralsintwodierentstackstounderlinethattheOScanexposesystemcallstoaccesstothecorehardwareresources,whiletheVirtualIOLayerisdesignedtoaccesstotheperipherals.
Thelaststackshowsthattheaccesstomemoriesisdirectforprivilegedtasks,whiletheaccessfromusermodetasksisstrictlyregulatedbyMPU.
Twodierentkindsoftasksaredened:privilegedtasksandusermodetasks,whichwillbediscussedinnextsection.
AnotherimportantlayerdepictedinFigure1isFreeR-TOS[17],awellknownRealTimeOperatingSystemforabroadrangeofEmbeddedSystemsfrom8to32bit,includ-inglowpowerandultra-lowpowerMCUs.
WeimplementedourframeworkonanSTM32F4basedplatform,andevenifsomedetailsinthefollowingdescriptionarerelatedtothisspecicmicrocontroller,ourframeworkcanbeeasilyextendedtobeplatformindependent.
InSections3.
1and3.
2wefocusontherstandthirdstack,namelyonexploitingtheMPUandprovidingSafetyExtensions,whileinSection3.
4wediscussthesecondstack.
3.
1RealTimeOSThemainreasonforusingFreeRTOSisitsversatility:manyMCUsaresupportedandthecodeismaintainedandupgradedoftenbyRealTimeEngineersLtd.
Moreoveritismodularandtherearesomeextensionsavailable(e.
g.
MPUextension),whichcanbeaddedtothecorerelease.
Theopensourcenaturemakespossibletoextendit.
Ithasmore-overasmallmemoryfootprintandsourcesconsistofasmallnumberofles.
Theschedulersupportsreal-timeoperation,Figure1:Hardware,IOandMemorieslayers.
bothtime-triggeredbyacongurablesystemtickandwithsupportforprioritieswithpreemption.
3.
2FreeRTOSAdditionsTostrengthenthesecurityofthesystem,theFreeRTOSMPUmodulehasbeenintegratedtoenabletheusageoftheMemoryProtectionUnitimplementedonthemicrocon-trollerandtoactivatethetwolevelsofprivilegesforthetasksexecution.
However,theoriginalmoduleisanex-perimentalrelease,becauseofsomelimitationsthatwead-dressedinourwork:1.
Itdoesnothaveaproperwaytoaccesssystemre-sources.
Itprovidesonlyonesystemcall.
Thissystemcallraisestheprivilegesofthecallerfromusermodetoprivileged,executesthecallandthensetstheprivilegesbacktouserspace.
Thisbehaviorhassucientprotec-tioninanenvironmentwhereasingledeveloperwantstokeepseparationbetweentasks,i.
e.
thecasewhereasinglecompanydevelopsallthermware.
Whileinthecasewewanttogivetoathird-partyusertheca-pabilitytodevelophisowncode,theknowledgeoftheexistenceofthisbackdoorisreallydangerousforpro-tection.
2.
TheexploitationoftheMPUisstatic.
TheprotectionsectionsoftheMPUarenotrecongurableatrun-timebyprivilegedtasks.
3.
Thetaskterminationisnotcorrectlyhandled.
WhenausermodetaskraisesanMPUtraptheexceptionendsthesystemexecution.
Henceitwouldbeextremelyeasytocreatedenialofserviceattacks.
Innextsub-sectionswedescribeourproposedsolutionstotheselimitations.
3.
2.
1MPUExtensionAsalreadystated,thismodulepermitstograntdierentaccessprivilegesonatask-by-taskbasis.
ForeachtasktheMPUsettingsarestoredinthetaskdescriptor,calledTaskControlBlock(TCB)inFreeRTOS.
Whenataskiscreated,itcanbestartedwithoneoutoftwolevelsofprivileges:1.
PrivilegedTasks(similartoLinuxKernelModeexe-cution).
Thetaskexecuteswithpermissiongrantedtoaccessallsystemresources,memoriesandperipherals.
2.
UsermodeTasks(similartoLinuxKernelUserMode,alsocalledunprivilegedtasks).
ThetaskisexecutedinmorerestrictiveenvironmentandhasaccessonlytoalimitedsubsetofmemoryandIOaddresses.
STM32Cortex-M4haseightcongurableMPUregions.
Whenactivatedtheprotectionpolicyiswhite-listbased:toaccesstoaspecicpositionintheaddressspace,thetaskshouldhaveagrantononeMPUregion.
TheprivilegesonanMPUregioncanbe:NONE,READONLYANDREAD-WRITE.
InFreeRTOStheseMPUregionsareconguredasfollows:Region0FLASHprotectionProtectswholeFLASHprovidingread-onlyprivi-legestobothprivilegedandusermodetasks.
Region1OSFLASHprotectionProtectsfromaccessesbyusermodetaskstotheOScodeinFLASHRegion2OSRAMaccessProvidespermissiontoprivilegedtasktoaccesstheOSstructuresstoredinRAMRegion3PeripheralaccessUsedtoenableordisabletheaccesstoperipherals.
Region4TaskStackaccessUsedtogiveaccesstotasksownstack.
Region5-7NotusedThesethreeregionsarenotusedbyFreeRTOSMPUmodule,thustheyareopentodeveloperpurposes.
InTable1,weshowalistofMPUcongurationsusedinoursolution.
Asthereadercannotice,thereisnoaccesstoperipheralsgrantedtousermodetasks.
ThisaccesscanbeonlyallowedthroughtheIOVirtualizationArchitecture.
OneofthemainconstraintsoftheFreeRTOSMPUmod-uleisthatitpermitstocongurethelastregions(from5to7)atcompiletimeonly.
Thus,weimplementedaspecicsoftwaremoduletoreconguretheseregionsatrun-timeforeachtask.
Thisisdoneforthefollowingreasons:1.
AccesstoVirtualIOLayer(deeplyexplainedinSub-section3.
4)canberestrictedbyanMPURegionandmustbeaskedbyatask.
ThismakestheVirtualIOLayerawareaboutthenumberoftasksthatareusingit.
2.
Moreoveraccesstoheaporothermemoryregionscanbegrantedatrun-time.
Thisisopentoseveralfutureapplications.
3.
2.
2SafetyExtensionsAspreviouslystated,thesinglesystemcallparadigmisnotsafe.
Theraiseprivilegesystemcallhasbeenremovedandreplacedbymorespecicsystemcallsforrequiredcases.
ForexampletograntaccesstoFreeRTOSQueuesandDi-rectTaskNotication,thefollowinglistofsystemcallsareadded:MPUxTaskGenericNotify:DirecttasknoticationNo-tifyfunctionMPUQueueReceive:ReceiveamessageonaqueueMPUxGetCurrentTaskHandle:GetthecurrenttaskhandleIOLayerREGISTER:RegistrationtoVirtualIOLayerTable1:DefaultMPUregionsettinginFreeRTOSPrivilegedPerm.
UserModePerm.
RegionDesc.
READONLYREADONLYallFlashProtectionREADONLYNONEOSCodeSegmentinFLASHREADWRITENONEOSRAMProtectionREADWRITENONEPeripheralsREADWRITEREADWRITETaskStackNOTUSEDNOTUSEDUsercongurableNOTUSEDNOTUSEDUsercongurableNOTUSEDNOTUSEDUsercongurable3.
2.
3GracefulTaskTermination-KillerTaskFreeRTOSdoesnotprovidetasktermination.
Thus,whenanunprivilegedtasktriestoaccessamemoryaddresswith-outpermissionatrapisgeneratedfromtheMPUandtheOSendsitsexecutioninanendlessloop.
Thisisnotaccept-ableifwewanttokeepallothertasksandOSinexecution.
Thedesiredbehavioristhatthetaskcausingthetrap,isabortedwhilethesystemcontinuesitsexecution.
Thusamemorytraphandlerandaspecictask,calledKillerTask,havebeencreatedtomanagetheterminationofthetaskthatraisedthetrap.
TheKillerTaskisaprivilegedtaskcreatedatboottimeanditisinsleepstate,whentheMCUisinnormalusage.
Whenatrapoccursthetaskisactivated.
TheKillerTaskgetsthetaskhandlesofthetaskthatgen-eratedthetrapandremovesitfromtheschedulerexecutionqueue.
Thenitresumestheschedulerexecutionandgoesbackintosleep,waitingforthenexttrap.
3.
3SoftwareProtectionInasoftwareprotectionperspective,theMPUenablestheOStokeepthecontrolontheusermodetasks.
Thus,withtheMPUallusermodetaskscannottamperthewholesystem.
Ontheotherhand,ifwewanttoenableathirdpartysoftwaredevelopertoaccessonlyasmallsubsetofperipherals,anegraincontrolonaddressspacemustbeimplemented.
UsuallyinaMCUallperipheralsaddressesaregroupedfromastartingtoanendingaddress.
However,ifwewanttoprovidenegrainaccesstoasubsetofthem,threefreeMPUregionsarereallylimiting.
Moreoverthereareothertwolimitations:oneisthattheminimumareaforanMPUregionsisusually32Bytes(i.
e.
onSTM32f4)thatisusuallylargerthantheregisterpoolofaperipheral.
Theotheristhatregistersetofseveralperipheralsconsistsofbothcontrolregisters,andreading/writingports,atsubse-quentmemorypositions.
Thusitisnotpossibletogranttheaccesstoaread-onlyregisteranddenyingthepermissiontoacontiguouscongurationregister.
3.
4IOVirtualizationArchitectureTheVirtualIOLayerarchitectureconsistsoftwomainparts:(1)ataskcalledVirtualIOTaskthatinvokesthecallbackstoaccesstoIOandtoperipheralsthroughthehardwareabstractionlayer(HAL);(2)alibrarynamedVir-tualIOLibrarythatcontainsthefront-endcallsforwardedtransparentlytotheVirtualIOTaskandtheback-endcallsinvokedbytheVirtualIOTasktoaccesstheHALLibrary.
TheVirtualIOTaskisaFreeRTOStaskthathandlesalltheIOcallsfromtheusermodetaskstotheperipherals.
AsshowninFigure2:thistaskactsasatask-in-the-middlethatreceivesallcallsfromusermodetasksthatattempttoac-cesstotheperipherals,checksthepermissionsandforwardstherequeststhroughtheHALlibrary.
3.
4.
1VirtualIOLibraryFigure2:IOVirtualizationHighLevelArchitectureThelibraryconsistsoftwosubsets:afront-endfunctionssubsetandtherelativeback-endfunctionssubset.
Whenausermodetaskwantstoaccessperipherals,itneedstosubscribetotheVirtualIOLayer,usingonespe-cialfront-endfunction.
Registrationisrequiredfortwopur-poses:1.
TheusermodetaskmusthavereadonlyaccesstotheVirtualIOtaskhandle.
ThisisneededtousetheOSeventnoticationstonotifytheVirtualIOtask.
Therefore,oneoftheMPUregionsofthetaskmustberun-timeconguredtoread-onlyaccesstoVirtualIOtaskhandler.
2.
Usermodetasksarenotauthorizedtouseinterrupthandlers,becauseinterrupthandlercodeisexecutedinprivilegedmode.
Weusedaqueuesystemtocom-municatefrominterrupthandlerstousermodetasks.
Hencetheregistrationroutinecreatesanewqueueandsavesthequeuehandlerinastructure.
Thiswillbeusedafterwardsifthetaskwillrequestaccesstooneperipheralininterruptmode.
Theregistrationisdonethroughasystemcallthatwaspreviouslymentionedinsubsection3.
2.
2,hiddenbyafront-endcall.
ThesystemcallisneededtocongureanMPUregiondescribedintheformerpurpose.
Theregistrationprocedureworksasfollows:(1)Theusermodetaskin-vokestheIOLayerinit()routine,whichthrough(2)theIOLayerREGISTERsystemcall(3)setsanMPUregionofthecallertasktoaccesstoVirtualIOTaskdescriptorinread-onlymode.
ThisisneededtosendNotications.
ThentheframeworkcreateandinitializesaSystemQueue(4)forusingtheDMA(theprocedureisdescribedinBackEndSubsetsubsection).
Beforereturning,iftheprocedurewassuccessful,thetaskisaddedtothelistofVirtualIOsubscribedtasks.
FrontEndSubsetTheFrontEndsubsetisintendedtobecalledfromtheusermodetasks.
ThesecallshavethesamesignatureoftheoriginalHALlibrarycalls,besidethefunctionname,whichisextendedwithaprextomaketheprogrammerawarethatisusingtheVirtualIOLayerand,obviously,toavoidanamespaceconict.
ThusforeachHALlibraryfunctionthatwewanttoexposetothethirdpartydeveloperafunctionmustbewritten.
Eachfunctiondeclaresastructurethatcontains:1.
Theuser-modetasktaskhandler.
2.
Apointertotherelativeback-endfunctiontobecalledbytheVirtualIOTask3.
ApointerforeachoriginalHALLibraryfunctionar-gument.
4.
IftheoriginalHALfunctionreturnsanon-voidvalue,aeldtostoreit.
WerefertothisstructurewiththenameHALLibraryAr-gumentEmbeddingStructure(HAEStructure).
ThenHAEstructureisinstantiatedinthefunction,onthestack,andallstructure'seldsareassignedwiththeirvalues.
Anoti-cationissenttotheVirtualIOLayerTaskwithapointertothisstructure.
AttheendoptionallytheHALLibraryre-turnvalueisreturnedifthefunctionisnon-void.
ArecapoftheembeddingofthisfunctionisshowninrighttopcornerofFigure2.
BackEndSubsetThebackend(orcallbackfunctions)isthepartofthelibrarymeanttobecalledbytheVirtualIOTask.
Foreachfront-endfunction,thereisonecorrespondingback-endonethattakesininputasingleargument,avoidpointer.
ItsbodycontainsadeclarationoftheHAEstructurewrittenforthecorrespondingfront-endfunction.
Thevoidpointeristhencastinthisstructure,argumentsarethenusedtocalltheoriginalHALfunction.
WhentheHALLibrarycallendsup,thereturnargumentiswritteninthestructure,thatstillresidesintheuser-modestackthencontrolreturntotheVirtualIOTask.
ThentheVirtualIOTasksuspendsitsexecutionwaitingforthenextcall.
Thisarchitecturehastwoadvantages:(1)theeaseofuse,theprogrammerdoesnotneedtolearnanewinterfacetousetheHAL.
(2)Allfront-endcallsandback-endcallshavethesameformat,sotheycanbewrittenbyaprogrammerorgeneratedbyanautomatictool.
ToHandleDMAasynchronouscallsandtogetnotiedwhenaDMAtransferiscompleted,weusetheQueuere-turnedwhentheusermodetasksubscribestheVirtualIOLayer.
Forsecurityitisimportantthatalltheinterruptser-viceroutines(ISR)areimplementedbythesystem.
More-overinsideeachserviceroutinethereisaQueueSendopera-tionusedtonotifythetaskthatwantstousetheDMAthattheroutineiscalled.
Tocorrectlynotifythecorrespondingusermodequeueareferencetableisused.
Thisreferenceta-bleissetbytheback-end,whentheusermodetaskinvokesoneoftheDMAHALLibraryfunctions.
3.
4.
2VirtualIOTaskTheVirtualIOTaskisaprivilegedtaskthathandlesthecommunicationfromusermodetaskstoperipherals.
ItstartswhentheVirtualIOlayerisinitialized,typicallyatsystemboottime.
ThecommunicationishandledviaDi-rectTaskNotication.
Whenstartedthistaskhangsinsuspendedstatewaitingforacallfromoneoftheusermoderegisteredtasksthroughthefront-end.
Thepriorityofthistaskishigherthanallusermodetasks.
Thus,whenthenoticationisthrownfromthefront-end,theusermodetaskwaitsthattheVirtualIOtaskendsitsexecution.
Thereforeeveniftasknoticationsareasyn-chronous,thecalltoHALLibraryisblockingbecauseinFreeRTOSthepreemptionoftheschedulerisprioritybased.
Thebodyofthistask,besidestheTaskNotifyWait,con-sistsofanAccessControlList(ACL),showninFigure2,thatchecksthatthecalleeHALLibraryfunctioncanbein-vokedbythecaller.
ThepointertoHAEStructureiscasttoagenericstructurecommonforallHAEStructures(wealwaysknowthatthersttwoeldsarexed:theuser-modetasktaskhandlerandthepointertothecall-backfunction),thentheACLpermissioncheckoccurs.
ifthecheckingpassed,theback-endfunctionisinvoked.
3.
5DynamicLinkingThedynamiclinkingpermitsatasktobeaddedtotheruntimetaskswithoutrebootingthesystem.
Weimple-menteddynamiclinkingtodemonstratetheusageofthewholesystem.
Therefore,weimplementedaprivilegedtaskinchargeofdynamiclinkingotherusermodetasks.
Tasksarecross-compiledandunresolveddependenciestosystemlibrarycallsarerun-timelinkedandthetaskisaddedtoschedulerexecutionqueue.
Thelibraryinchargeofdynamiclinkingusermodetasksisderivedfromtheworkof[4].
InFlashmemorywereservedasectiontostorethesenewtasksbinariestobelinkedandthenaddedtoFreeRTOSschedulerreadytasklist.
4.
EXPERIMENTALRESULTSInthissectionwepresentresultsintermofperformanceandmemoryfootprint.
AlltestswereconductedonanSTM32F411RENUCLEO-64Board[18].
Thisisaplat-formbySTMicroelectronics,itembedsanARMR32-bitCortexR-M4CPUrunningupto100MHzwithFPUandMPU.
Itfeatures512KBofFlashmemoryand128KBofRAMmemory.
InoursoftwaresetupweusethenewdriverforaccessinghardwareperipheralsprovidedbySTcalledHardwareAbstractionLayerDriver(HALDriver)[19].
Weidentiedtwomainusecases,i.
e.
waystoaccesspe-ripheralsinaMicrocontrollerunit,thatmustbeconsideredseparately:1.
AtomicAction:ThisisthecaseinwhichwecallaHALDriverroutineeachtimeweaccessaperipheral.
Inotherwords,wejustwanttoaccessonceanIOaddressorwemayac-cessitinaloop,butcalldoesnotinvolveperipheraltransferafterit.
AnexampleofthisbehavioriswhenwewanttocongureorreadaGPIOPIN,orwritesomethingontheUART.
2.
ContinuousAction(orTunnelingAction):Inthissecondcaseweconsideralltheperipheralus-agesthatinvolvetheuseofDMA.
ForexamplewhenwewanttosetAnalogtoDigitalconverterandreaditatregularintervalsbytheDMA.
4.
1VirtualIOLayerTimingThetimeofaccessingaperipheralusingtheVirtualIOLayerisreportedinTable2.
Therstrowgivesthecyclestogetthetaskhandlethroughasystemcall.
TheMPU-xTaskGenericNotify()isthedirecttasknoticationsystemcall.
ThethirdrowreportsthecyclesrequiredtonotifytheVirtualIOTask.
Thelastrowgivesthenumberofcyclestoreturncontrol,aftertheHALDrivercallbacktotheUsermodetask.
ThecyclesmeasurementhasbeendonewiththeDWTCYCCNThardwarecyclecountregisteroftheCortex-M4MCU.
Itisworthmentioningthatwiththisparadigm,continu-ousmodeoperationspaytheoverheadjustonce,whenthesetupoftheperipheralorIOisperformed.
ThuswhentheDMAisworkingtheonlyoverheadisthequeueusedtosyn-chronizetheISRwiththeusermodetask.
ThecyclesoverheadtocheckifthefunctionthattheusermodetaskwantstouseispermittedbytheACLgrowslin-earlywiththenumberofchecksthatoccurs.
InTableareVirtualizationStepVIO(Cycles)getTaskHandle97MPUxTaskGenericNotify47xTaskNotify+CS490Notifywait+CSback293TOTAL926Table2:TimingoverheadofaccessingtheIOusingtheVirtualIOLayerinCyclesFigure3:OverheadofthecontrolintheACL.
wereportthetheoverheadAsexpectedthenumberofcy-clesareproportionaltothenumberoffunctionaddressestoverify.
4.
2VirtualIOLayerMemoryFootprintTheoverheadintermsofmemoryfootprintisdescribedinTable3.
WeshowthecodesizeofthelibraryandoftheVirtualIOTaskseparately,incasethecompilerisinvokedwiththeagforperformance(-O3)orspace(-OS)optimiza-tion.
TheSizeoftheVirtualIOLibraryismeasuredwithanaveragesizeof50functions(frontend+backend).
Aswecannoticefromtheresults,thememoryfootprintismin-imal,evenifitscaleswiththenumberofdriverfunctionsthatwewanttoprovidetotheusermodetasks.
OptimizationVIOTaskVIOLibrary-O3592B2876B-OS464B2314BTable3:VirtualizationLayercodesizeAsaconcludingnote,itisimportanttostressthefactthattheruntimeoftaskswhennotinteractingwiththeIOsisexactlythesameasnativeFreeRTOStasks,withnoperfor-manceoverheadformemoryprotectionastheMPUiscom-pletelytransparentfromtheperformanceviewpoint.
Thisisverysimilartowhathappensinvirtualmachineexecutionforhigh-endcores,andinsharpcontrastwithinterpretedvirtualmachinesorevenJIT-basedsystems.
5.
CONCLUSIONSInthispaperwehavepresentedavirtualizationlayerforlow-costmicrocontrollerswhichcreatesaseparationbetweenkernelmodeandusermodeandprotectsthehardwarere-sourcesfrommisuseswhenconcurrenttasksorfunctionarewrittenbydierentdevelopers.
Moreoverwedemonstratedtheeectivenessofamechanismcapabletoexecutenewrun-timecode,withouttheneedofsystemreboot.
Wehavefocusedonsmallsizeoftheframeworkandonlowerover-head,becausetargetedforlow-costandlimitedcomputingcapabilitiesmicrocontrollerssuchastheonesdesignedforIoTandWSN.
Experimentalresultsdemonstratethattheoverheadislimitedandtimedelayisnegligibleconsideringthetypicalapplicationscenarios.
Futureworkswillextenddynamiclinkingtowardmultipleuploadchannelsandwillimplementdierentpermissionpoliciestoperipheralsfromdierentusermodetasks.
6.
ACKNOWLEDGMENTSThisworkwaspartiallysupportedbyEUProjectEu-roCPSH2020-ICT-2014underGrant644090andincollab-orationwithSTMicroelectronics.
7.
REFERENCES[1]LuTanetal.
.
Futureinternet:Theinternetofthings.
In20103rdInternationalConferenceonAdvancedComputerTheoryandEngineering(ICACTE),volume5,pagesV5–376–V5–380,Aug2010.
[2]AlaAl-Fuqahaetal.
.
Internetofthings:Asurveyonenablingtechnologies,protocols,andapplications.
IEEECommunicationsSurveysTutorials,17(4):2347–2376,Fourthquarter2015.
[3]ShahBhattietal.
.
Mantisos:Anembeddedmultithreadedoperatingsystemforwirelessmicrosensorplatforms.
Mob.
Netw.
Appl.
,10(4):563–579,August2005.
[4]SimonHolmbackaetal.
Lightweightframeworkforruntimeupdatingofc-basedsoftwareinembeddedsystems.
InPresentedaspartofthe5thWorkshoponHotTopicsinSoftwareUpgrades,Berkeley,CA,2013.
USENIX.
[5]ARMVirtualizationExtension.
https://www.
arm.
com/.
[6]ARMSecurityTechnology-BuildingaSecureSystemusingTrustZoneTechnology.
Whitepaper,April2009.
[7]T.
AlvesandD.
Felton.
Trustzone:Integratedhardwareandsoftwaresecurity-enablingtrustedcomputinginembeddedsystems.
Whitepaper,arm,july2004.
[8]Micropythonwebsite.
http://micropython.
org/.
[9]PyMite.
https://wiki.
python.
org/moin/PyMite.
[10]OracleJavaMEEmbedded.
http://www.
oracle.
com/.
[11]NielsBrouwersetal.
.
Darjeeling,afeature-richvmfortheresourcepoor.
InProceedingsofthe7thACMConferenceonEmbeddedNetworkedSensorSystems,SenSys'09,pages169–182,NewYork,NY,USA,2009.
ACM.
[12]EspruinoJavascriptInterpreter.
http://www.
espruino.
com/.
[13]EmbeddedpowerdrivenbyLua.
http://www.
eluaproject.
net/.
[14]AlessandroBoglioloetal.
.
Virtualsense:Ajava-basedopenplatformforultra-low-powerwirelesssensornodes.
InternationalJournalofDistributedSensorNetworks,2012,2012.
[15]Contiki:TheOpenSourceOSfortheInternetofThings.
http://www.
contiki-os.
org/.
[16]MichaelP.
Andersenetal.
.
Systemdesignforasynergistic,lowpowermote/bleembeddedplatform.
InProceedingsofthe15thInternationalConferenceonInformationProcessinginSensorNetworks,IPSN'16,pages17:1–17:12,Piscataway,NJ,USA,2016.
IEEEPress.
[17]FreeRTOSwebsite.
http://www.
freertos.
org/.
[18]STMicroelectronicsNucleoBoards.
http://www.
st.
com/.
[19]STMicroelectronicsHardwareAbstractionLayerDriver.
http://www.
st.
com/.

BlueHost 周年庆典 - 美国/香港虚拟主机 美国SSD VPS低至月32元

我们对于BlueHost主机商还是比较熟悉的,早年我们还是全民使用虚拟主机的时候,大部分的外贸主机都会用到BlueHost无限虚拟主机方案,那时候他们商家只有一款虚拟主机方案。目前,商家国际款和国内款是有差异营销的,BlueHost国内有提供香港、美国、印度和欧洲机房。包括有提供虚拟主机、VPS和独立服务器。现在,BlueHost 商家周年活动,全场五折优惠。我们看看这次的活动有哪些值得选择的。 ...

atcloud:480G超高防御VPS低至$4/月,美国/新加坡等6机房,512m内存/1核/500g硬盘/不限流量

atcloud主要提供常规cloud(VPS)和storage(大硬盘存储)系列VPS,其数据中心分布在美国(俄勒冈、弗吉尼亚)、加拿大、英国、法国、德国、新加坡,所有VPS默认提供480Gbps的超高DDoS防御+不限流量,杜绝DDoS攻击骚扰,比较适合海外建站等相关业务。ATCLOUD.NET是一家成立于2020年的海外主机商,主要提供KVM架构的VPS产品、LXC容器化产品、权威DNS智能解...

天上云月付572元,起香港三网CN2直连,独立服务器88折优惠,香港沙田机房

天上云怎么样?天上云隶属于成都天上云网络科技有限公司,是一家提供云服务器及物理服务器的国人商家,目前商家针对香港物理机在做优惠促销,香港沙田机房采用三网直连,其中电信走CN2,带宽为50Mbps,不限制流量,商家提供IPMI,可以自行管理,随意安装系统,目前E3-1225/16G的套餐低至572元每月,有做大规模业务的朋友可以看看。点击进入:天上云官方网站天上云香港物理机服务器套餐:香港沙田数据中...

waitingforreboot为你推荐
独立ip空间如何给网站申请独立的IP空间电信主机租用主机代管有什么特点?域名代理我想申请域名代理。直接在国家域名管理中心申请,应该有什么一些手续?中文域名注册查询如何注册中文域名?请问个人怎样注册中文域名。cn的,个人注册别人公司的可以吗?违法吗?或者怎样才能注册虚拟主机申请现在做网站申请虚拟主机选择哪种合适?台湾主机台湾的第一台电脑万网虚拟主机万网免费虚拟主机和收费虚拟主机有什么区别虚拟主机软件常见的虚拟机软件有哪几种?四川虚拟主机222.214.218.100 请问这个IP是哪个服务商提供的?花生壳域名怎么用花生壳做域名解析
贝锐花生壳域名 注册cn域名 华为云服务 linode日本 Vultr 外国服务器 gomezpeer Hello图床 外国域名 183是联通还是移动 双线主机 共享主机 php空间购买 如何用qq邮箱发邮件 美国独立日 摩尔庄园注册 空间服务器 重庆服务器 tracker服务器 开心online 更多