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/.

GreenCloudVPS($30/年),500G大硬盘VPS,10Gbps带宽

GreenCloudVPS最近在新加坡DC2节点上了新机器,Dual Xeon Silver 4216 CPU,DDR4内存,10Gbps网络端口,推出了几款大硬盘VPS套餐,基于KVM架构,500GB磁盘起年付30美元。除了大硬盘套餐外,还加推了几款采用NVMe硬盘的常规套餐,最低年付20美元。不过需要提醒的是,机房非直连中国,尤其是电信用户ping值感人,包括新加坡DC1也是如此。大硬盘VPS...

LOCVPS(29.6元/月)KVM架构 香港/美国机房全场8折

LOCVPS商家我们还是比较熟悉的老牌的国内服务商,包括他们还有其他的产品品牌。这不看到商家的信息,有新增KVM架构轻量/迷你套餐,提供的机房包括香港云地和美国洛杉矶,适用全场8折优惠,月付29.6元起。LOCVPS是一家成立于2011年的稳定老牌国人商家,主要从事XEN、KVM架构的国外VPS销售,主推洛杉矶MC、洛杉矶C3、香港邦联、香港沙田电信、香港大埔、日本东京、日本大阪、新加坡等数据中心...

老薛主机入门建站月付34/月,年付345元,半价香港VPS主机

老薛主机怎么样?老薛主机这个商家有存在有一些年头。如果没有记错的话,早年老薛主机是做虚拟主机业务的,还算不错在异常激烈的市场中生存到现在,应该算是在众多商家中早期积累到一定的用户群的,主打小众个人网站业务所以能持续到现在。这不,站长看到商家有在进行夏季促销,比如我们很多网友可能有需要的香港vps主机季度及以上可以半价优惠,如果有在选择不同主机商的香港机房的可以看看老薛主机商家的香港vps。点击进入...

waitingforreboot为你推荐
海外主机租用国外服务器租用有几十块钱一年的么vps主机什么是vps主机云服务器租用云服务器租用费用是多少香港虚拟空间香港虚拟空间哪家好?网站空间商域名空间商怎么做虚拟主机评测网求推荐一些适合个人博客网站的虚拟主机的服务商虚拟主机管理系统虚拟主机管理系统那一家好?下载虚拟主机虚拟机怎么使用和下载虚拟主机测评哪一种虚拟主机比较好用?华众虚拟主机管理系统华众虚拟主机管理系统怎么样?
南通服务器租用 oneasiahost godaddy主机 kdata unsplash 新世界电讯 中国特价网 秒杀预告 hkg php空间购买 国外ip加速器 个人免费邮箱 大化网 免费主页空间 新网dns 九零网络 windowssever2008 远程登录 香港打折信息 德国代理ip 更多