DIAPMRTAI-Beginner’sGuide~rtai/documentation/articles/guide.html1of1109/30/200412:46PMDIAPMRTAIDipartimentodiIngegneriaAerospaziale-PolitecnicodiMilanoRealTimeApplicationInterfaceHomeRTAIHomeInfoAboutRTAINewsArchiveDocumentationApplicationsandLinksTheRTAITeamDownloadDownloadRTAIContactMailingListReportBugDIAPMRTAI-Beginner’sGuideWhatisarealtimesystem?Arealtimesystemcanbedefinedasasystemcapableofguaranteeingtimingrequirementsoftheprocessesunderitscontrol.Itmustbefastandpredictable.Fastmeansthatithasalowlatency,i.e.itrespondstoexternal,asynchronouseventsinashorttime.Thelowerthelatency,thebetterthesystemwillrespondtoeventswhichrequireimmediateattention.Predictablemeansthatitisabletodeterminetask’scompletiontimewithcertainty.Typicallyarealtimesystemrepresentsthecomputercontrollingsystemthatmanagesandcoordinatestheactivitiesofacontrolledsystem,thatcanbeviewedastheenvironmentwithwhichthecomputerinteracts.Theinteractionisbidirectional,saythroughvarioussensors(environment-computer)andactuators(computer-environment),andischaracterizedbytimingcorrectnessconstraints.Itisdesirablethattime-criticalandnontime-criticalactivitiescoexistinarealtimesystem.Botharecalledtasksandataskwithatimelinessrequirementiscalledarealtimetask.Typicallyrealtimetaskshavethefollowingtypesofrequirementsand/orconstraints.-Timingconstraints.Themostcommonareeitherperiodicoraperiodic.Anaperiodictaskhasadeadlinebywhichitmustfinishorstart,oritmayhaveaconstraintonbothstartandfinishtimes.Aperiodictaskhastoberepeatedonceperperiod.Mostsensoryprocessingisperiodic,whileaperiodicrequirementscanarisefromdynamicevents.Resourcerequirements.ArealtimetaskmayrequireaccesstocertainresourcessuchasI/Odevices,datastructures,filesanddatabases.Communicationrequirements.Tasksshouldbeallowedtocommunicatewithmessages.Concurrencyconstraints.Tasksshouldbeallowedconcurrentaccesstocommonresourcesprovidingtheconsistencyoftheresourceisnotviolated.WhatisRTAI?RTAImeansRealTimeApplicationInterface.Strictlyspeaking,itisnotarealtimeoperatingsystem,suchasVXworksorQNX.ItisbasedontheLinuxkernel,providingtheabilitytomakeitfullypre-emptable.Linuxisastandardtime-sharingoperatingsystemwhichprovidesgoodaverageperformanceandhighlysophisticatedservices.LikeotherOS,itofferstotheapplicationsatleastthefollowingservices:hardwaremanagementlayerdealingwitheventpollingorprocessor/peripheralinterruptsschedulerclassesdealingwithprocessactivation,priorities,timeslicecommunicationsmeansamongapplications.Linuxsuffersfromalackofrealtimesupport.Toobtainatimingcorrectnessbehaviour,itisnecessarytomakesomechangesinthekernelsources,i.e.intheinterrupthandlingandschedulingpolicies.Inthisway,youcanhavearealtimeplatform,withlowlatencyandhighpredicatbilityrequirements,withinfullnonrealtimeLinuxenvironment(accesstoTCP/IP,graphicaldisplayandwindowingsystems,fileanddatabasesystems,etc.).RTAIoffersthesameservicesoftheLinuxkernelcore,addingthefeaturesofanindustrialrealtimeoperatingsystem.Itconsistsbasicallyofaninterruptdispatcher:RTAImainlytrapstheperipheralsinterruptsandifnecessaryre-routesthemtoLinux.Itisnotanintrusivemodificationofthekernel;itusestheconceptofHAL(hardwareabstractionlayer)togetinformationfromLinuxandtotrapsomefundamentalfunctions.ThisHALprovidesfewdependenciestoLinuxKernel.ThisleadstoasimpleadaptationintheLinuxkernel,aneasyRTAIportfromversiontoversionofLinuxandaneasieruseofotheroperatingsystemsinsteadofRTAI.RTAIconsidersLinuxasabackgroundtaskrunningwhennorealtimeactivityoccurs.DIAPMRTAI-Beginner’sGuide~rtai/documentation/articles/guide.html2of1109/30/200412:46PMInstallingRTAIPleasehavealookattheREADME.INSTALLfileintheRTAIdistributionfordetailedinstructionshowtoinstallRTAI.KernelModulesRTAIisverymuchmoduleoriented.SotounderstandandbeabletouseRTAIisnecessarytoknowthedynamicallyloadablemodulesforLinux.TheLinuxkerneldesignissimilartothatofclassicUnixsystems:itusesamonolithicarchitecturewithfilesystems,devicedrivers,andotherpiecesstaticallylinkedintothekernelimagetobeusedatboottime.Theuseofdynamickernelmodulesallowsyoutowriteportionsofthekernelasseparateobjectsthatcanbeloadedandunloadedonarunningsystem.Akernelmoduleissimplyanobjectfilecontainingroutinesand/ordatatoloadintoarunningkernel.Whenloaded,themodulecoderesidesinthekernel’saddressspaceandexecutesentirelywithinthecontextofthekernel.Technically,amodulecanbeanysetofroutines,withtheonerestrictionthattwofunctions,init_module()andcleanup_module(),mustbeprovided.Thefirstisexecutedoncethemoduleisloaded,andthesecond,beforethemoduleisunloadedfromthekernel.Themainfunctionstousetoload/unloadandinspectkernelmodulesarecontainedinthemodutilspackage.Theyare:/sbin/insmod(insertamoduleintotherunningkernel)/sbin/rmmod(removeamodulefromtherunningkernel)/sbin/lsmod(inspectmodulesintherunningcodes)Notethattomanagewithkernelmodulesyouhavetoberoot.Onceamoduleisloaded,itpassestoformpartoftheoperatingsystem,henceitcanuseallthefunctionsandaccessallvariablesandstructuresofthekernel.Similarlytheglobalsymbolscreatedaremadeava