QINNA:A COMPONENT-BASEDFRAMEWORK FOR RUNTIME SAFERESOURCE
ADAPTATION OFEMBEDDED SYSTEMS
LAURE GONNORD
∗
AND JEAN-PHILIPPE BABAU
†
Abstrat. Evenifhardwareimprovementshaveinreasedthe performaneof embeddedsystemsinthe lastyears,resoure
problems arestillaute. Thepersisting problem isthe onstantly growing omplexityof systems,whih inreasethe needfor
reusabledevelopementframeworkandpieesofode. IntheaseofPDAsandsmartphones,inadditiontolassialneeds(safety,
seurity),developersmustdealwithqualityofservie(QoS)onstraints,suhasresouremanagement.
Qinnawasdesignedtofaewiththeseproblems.Inthispaper,weproposeaompleteframeworktoexpressressoureonstraints
duringthedeveloppementproess. Weproposeaomponent-basedarhiteture,whihgeneriomponentsandalgorithms,anda
developpementmethodology,tomanageQoSissueswhiledevelopinganembeddedsoftware. Theobtainedsoftwareisthenableto
automatiallyadaptitsbehaviour tothephysialresoures, thankstodegradedmodes. Weillustratethemethodologyandthe
useofQinnawithinaasestudy.
Keywords: omponent,softwarearhiteture,resouredynamimanagement,asestudy.
1. Introdution. Whenfaedtotheproblemofdesigninghandledembeddedsystems,thedevelopermust
beawareofthemanagementoflimitedphysialresoures(CPU,Memory).
Inordertodevelopmultimediasoftwareonsuhsystemswherethequalityoftheresoure(network,battery)
anvaryduring use,thedeveloperneedstoolsto:
•
easilyadd/removefuntionality(servies)during ompilationorat runtime;•
adaptomponentfuntionalitytoresoures,namelyproposedegradedmodeswhereresouresarelow;•
evaluatethesoftware'sperformanes: qualityofprovidedservies,onsumptionrateforsomesenarios. Inthisontext,omponent-basedsoftwareengineeringappearsasapromisingsolutionforthedevelopmentofsuh kindsofsystems. Indeeditoersaneasierwaytobuildomplexsystemsfrom baseomponents([9℄),
andthemanagementofphysialresoureanbedonebyembeddingthesystemallsinhighlevelomponents.
Themainadvantagesthusappeartobethere-usabilityofodeandalsotheexibilityofsuhsystems.
TheQinnaframework( [11,12, 3℄) wasdesignedto handlethe speiationand managementofresoure
onstraints problems during the omponent-based system development. Variability is enoded into disrete
implementation levelsand links betweenthem. Quantity of resoureonstraintsanalso be enoded. Qinna
providesalgorithmstoensureresoureonstraintsanddynamiallyadapt theimplementationlevelsaording
to resoureavailabilityat runtime. The main advantageofthe methodis thenthe reusability oftheresoure
omponentsandthegeneriadaptationalgorithms.
In this journal paper, wepropose aomplete formalization of Qinna framework (algorithms and
ompo-nents),andasproofofonept,aasestudyonsistingofthedevelopmentofaremoteviewerappliationwith
thehelpofQinna'simplementationinC++. InSetion2wereallQinna'smainonepts,asintroduedin[11℄
andformalizedlaterin[3℄. InSetion3,wegiveanoverviewofQinna'sC++implementation,andthenprovide
thegeneralimplementationstepsto developaresoure-awareappliationwithQinnain Setion4. Finallywe
illustratethewholeframeworkontheviewerasestudy(Setion5).
2. Desriptionofthe Qinna framework.
2.1. Qinna'smainonepts. Theframeworkdesignedin[11℄and[12℄,andfurtherformalizedin[3℄has
thefollowingharateristis:
•
Boththeappliationpieesofodeandtheresoureareomponents. Theresoureserviesareenlosed inomponentslikeMemory,CPU,Thread.•
The variation of quality of the provided servies are enoded by the notion of implementation level. Theodeusedtoprovidetheservieisthus dierentaordingtotheurrentimplementationlevel.•
The link between the implementation levelsis made through an expliitrelation betweenthe imple-mentation levelof the provided servieand the implementationlevelsof theservies itrequires. Forinstane, the developer an express that a video omponent provides an image with highest quality
whenithasenoughmemoryandsuientbandwidth.
∗
UniversitéofLille,LIFLLaure.Gonnordlifl.fr
†
UBO,LISyC,UniversitéEuropéennedeBretagneJean.Philippe.Babauuniv- bre st.f rThisworkhasbeenpartiallysupported
•
All the alls to avariable funtion are made throughan existing ontratthat is negotiated. This negotiation is made automatially through the Qinna omponents. A ontrat for aservie at someobjetiveimplementationlevelismadeonlyifallitsrequirementsanbereservedattheorresponding
implementationlevelsandalsosatisfysomeonstraintsalledQualityofresoureonstraints(QoR).If
itnotthease,thenegotiationfails.
QoSComponentBroker1
...
QoSDomain
QoSComponentManager1
Manager2
Manager3
Broker2
Broker3
ontratmaintenane funtionalpart
admission,reservation QoSComponent
C
1
gestionpart
C
3
C
2
Fig.2.1. Arhitetureexample
These harateristis are implemented through new omponents whih are illustrated in Figure 2.1: to
eahappliationomponent(orgroupofomponents) whih provideoneormorevariableservieQinna
asso-iatesa QoSComponent
C
i
. Thevariabilityof a variableservie is made throughthe useof a orrespondingimplementation levelvariable. Then,twonewomponentsareintroduedbyQinnato managetheresoure
issuesoftheinstanes ofthisQoSComponent:
•
a QoSComponentBroker whih goal is to realize the admission of a omponent. The Brokerdeides whetherornotanewinstaneanbereated,andifaservieallanbeperformedw.r.t. thequantityofresoureonstraints(QoR).
•
aQoSComponentManager whihmanagestheadaptationfortheserviesprovidedbytheomponent. It ontainsamappingtable whih enodetherelationshipbetweentheimplementation levels ofeahoftheseserviesandtheirrequirements.
Atlast,Qinnaprovidesasingleomponentnamed QoSDomain forthewhole arhiteture. Itmanagesallthe
servierequests inside andoutsidetheappliation. Thelientof aservieasks theDomain forreservation of
someimplementationlevelandiseventuallyreturnedaontratifallonstraintsaresatised. Then,aftereah
servierequest,theDomain makesanaknowledgmentonlyoftheorrespondingontratisstillvalid.
2.2. Quantity of Resoure onstraints in Qinna. A Quantity of resoure onstraint (QRC) is a
quantitativeonstrainton aomponent
C
and theservie(s
i
)it proposes. QRCsare forinstane formulaonthetotal instane of agiven omponent type,of the totalamountof resoure(memory,CPU) alloatedto a
givenomponent. Theyaretwotypesofonstraints,depending ontheirpurpose:
•
Componenttypeonstraints(CTC)expresspropertiesofomponentsof thesametypeandtheir pro-videdservies.•
Componentinstane onstraints(CIC)express propertiesofapartiularinstaneofaomponent. Themanagementofthese onstraintsisautomatially doneatruntime, ifthedeveloperimplementstheminthefollowingway:
•
In the QoSComponent, for eah servie, implement the twofuntions: testCIC and updateCIC. The formerdeideswhetherornotthealltotheservieanbeperformed,andthelaterupdatesvariablesafterthefuntionall. Inaddition,theremustbeaninitializationoftheCICsformulasatthereation
ofeahinstane.
•
Similarly,intheQoSComponentBroker,foreahprovidedservie,implementthetwofuntionstestCTC andupdateCTC.Then,Qinnamaintainsresoureonstraintsatruntimethroughthefollowingproedure:
•
WhentheBrokerforC
isreated,theparametersused intestCTCareset.•
TheCIC
(
s
i
)
andCT C
(
s
i
)
deisionproeduresareinvokedateahfuntionall. Anegativeanswerto oneofthesedeisionproedureswillausethefailureoftheurrentontrat. Wewilldetailthenotionofontratin Setion2.4.
ExampleThe Memoryomponent provides only oneservie mallo, whih hasonly one parameter, the
numberof bloks to alloate. It hasanintegerattribute, memory,whih denotes theglobal memory sizeand
is set at thereation ofeah instane. We also supposethat we havenogarbage olletor, so the bloks are
alloatedonlyone. Figure2.2illustratesthedierenebetweentypeandinstaneonstraints.
CTC:
memory
≤
1024
CIC:
memory
≤
24
CIC:
memory
≤
1000
P
p
(
arg
(
occ
p
(
malloc
)
≤
1000
C
1
C
2
C
=GlobalMemoryFig.2.2. TypevsInstaneonstraints
•
CTCforC
=Memory: theformulaCT C
compo
(
C
)
≡
P
j
memory
(
C
j
)
≤
1024
expressesthat theglobal memoryquantityforthewhole appliationis1024
kilobytes. A newinstanewillnotbereatedifitsmemoryonstantisset toatoobignumber. Then
CT C
serv
(
malloc
)
≡
P
k
arg
(
occ
k
(
malloc
))
≤
1024
forestheallstomallostopwhenallthe
1024
kilobyteshavebeenalloated.•
CIC forMemory: if wewant to alloatesomeMemory for a partiular (groupof) omponent(s), we anexpresssimilarpropertiesinonepartiularinstane (seeC
1
ontheFigure).
Expressionofresoure onstraintsand ode generation
Qinnaalsoprovidesawaytodesribetheresoureonstraintsintoahigher-leverlanguagealledqMEDL,a
variantofMEDLeventlogidesribedin[6℄,andwhosepreisesyntaxandsemantisisdesribedin[3℄. Roughly
speaking, thelogianexpressbooleanformulaeonourenesofevents. Atomsareoftheform
Q ⊲⊳ K
, withK
onstant and⊲⊳
∈ {
6
,
=
, <, . . .
}
, andQ
is a quantity. The quantity are obtained by the use of auxiliary variablesandalls tovalueandtimespeialfuntions: toeahevente
(ornew
C
),time
(
e
)
andvalue
k
(
e
)
giverespetivelythedateofthelastourreneoftheeventandthe
k
th
argumentofthefuntionallwhenitours.
TheMemory onstraint forthewhole appliation then anbe enoded by
N
≤
1024
whereN ountsthe totalamountofmallo'sarguments: mallo -> N:=N+value_1(mallo). ThetranslationisthenmadebytheqMEDL2toC++translator,andgivesthefollowingproedures(theidentiershavebeenhangedforlisibility,
usedmemisaloalvariableto ounttheglobalamountofmemoryusedyet):
bool testCIC_mallo(int nbbloks){
return (usedmem + nbbloks <= 1024)}
bool updateCIC_mallo(int nbbloks){
usedmem = usedmem + nbbloks; }
2.3. QoS Linking onstraints. Unlike quality of resoure onstraints, linking onstraints express the
relationshipbetweenomponents,intermsofqualityofservie. Forinstane,thefollowingpropertyisalinking
onstraint: to provide the getImages at a good level of quality, the ImageBuffer omponent requires a
big amountofmemoryandafast network. ThisrelationshipbetweenthedierentQoSoflientandserver
serviesarealled QoSLinkingServieConstraints(QLSC).
ImplementationLevelToallprovidedserviesthatanvaryaordingto thedesiredQoSweassoiate
an implementation level. This implementation level (IL) enodes whih part of implementation to hoose
when supplying the servie. These implementation levels are totally ordered for a given servie. As these
implementation levels arenitely many,weanrestritourselvesto theaseof positiveintegersandsuppose
thatimplementationlevel
0
isthebest level,1
givesalesserqualityofservie,andsoon.Weassumethatrequiredserviesforagivenserviedoesn'thangeaordingtotheimplementationlevel,
Linkingonstraints expressionLetusonsideraomponent
C
whihprovidesaservies
that requiresr
1
andr
2
servies. Qinnapermits tolink thedierentimplementation levelsbetweenallersandallees. Therelationshipbetweenthe dierentimplementationlevelsanbeviewedasafuntion whih assoiatesto eah
implementationlevelof
s
animplementationlevelforr
1
andforr
2
:QLSC
s
:
N
−→
N
2
IL
7−→
(
IL
1
, IL
2
)
This funtion is statially enoded by thedeveloperwithin theappliation. Forinstane, it aneasilybe
implementedintheQoSManagerthroughamapping tablewhoselinesenodethetuplesoflinked
implemen-tationlevels:
(
IL
s
1
, IL
r
1
, IL
r
2
)
. Thenaturalorderofthelinesofthetable isusedtodeterminewhihtupletoonsideriftheurrentnegotiationfails.
linking constraint
r
2
r
1
s
1
IL
r
1
IL
r
2
IL
s
1
Fig.2.3.Implementationlevelsandlinkingonstraints
Thus,assoonasanimplementationlevelissetforthe
s
1
servie,theimplementationlevelsofallrequiredservies(and all the implementation levelsin the alltree) are set (Figure 2.3). This has aonsequenenot
onlyon theexeutedodeofall theinvolvedservies(andalso internal funtions)but also onthearguments
oftheserviealls.
Therefore,ifauserasksfortheservie
s
1
atsomeimplementationlevel,thedemandmayfailduetosomeresoureonstraint. That's whyeverydemandforaserviemustbenegotiatedandthenotionofontratwill
beauratetoimplementaset ofasatisfatoryimplementationlevelsfor(a setof)future alls.
Implementationoflinking onstraints in QinnaThelinksbetweentheprovidedQoSandtheQoSof
therequired serviesaremadethrough atable whose lines enode thetuplesof linked implementation levels:
(
IL
s
, IL
r
1
, IL
r
2
)
. Thismapping tableis enoded in the QoSManager. The naturalorder of thelines ofthetableisusedto determinewhihtupleto onsideriftheurrentnegotiationfails.
Nowwehavealltheelementstodenethenotionofontrat.
2.4. Qinna's ontrats. Qinna provides the notion of ontrat to ensure both behavioral onstraints
(TypeConstraintsandIntaneConstraintsofservies,asdesribedin Setion2.2)andlinkingonstraints.
Whenaservieallismadeatsomeimplementationlevel,allthesubserviesimplementationlevelarexed
impliitlythroughthelinking onstraints. Asalltheimplementationlevelsforasameservieareordered,the
objetiveis to ndthe best implementationlevelthat is feasible(w.r.t. the behavioral onstraints ofall the
omponentsandservieinvolvedinthealltree).
Contrat Negotiation All servie alls in Qinnaare made after negotiation. Theuser (at toplevel) of
the servie asks for the servie at some interval of satisfatory implementation levels. Qinna then is able
to nd the best implementation level in this interval that respets all the behavioral onstraints (CICs and
CTCs ofalltheserviesinvolvedin thealltree). If thereis nointersetionbetweenfeasibleand satisfatory
implementation levels, no ontrat is built. In theother ase, aontrat is made for the spei servie. A
ontratisthusatuple
(
id, s
i
, IL,
[
IL
min
, IL
max
]
, imp
)
denotingrespetivelyitsidentiantnumber,thereferredservie,theurrentimplementationlevel,theintervalofsatisfatoryimplementationlevels,andtheimportane
oftheontrat. Thislastvariableisusedtosortthelistofallurrentontratsandisusedfordegradation(see
nextparagraph). Theimportane valueisstatiallyset bythedevelopereahtimeheasksforanewontrat.
Afterontratinitialization,alltheservieallsmustrespetthetermsoftheontrat. Intheotherase,
therewillbesomerenegotiation.
Contrat Maintenane and DegradationAftereahservieallthedeisionproedureforbehavioral
Domaintriestodegradetheontratofleastimportane(whihmaybenotthesameastheurrentone). This
degradationhasonsequenesontheresoureandthusanpermitotherserviealls insidetherstontrat.
Basially,degradingaontratonsistsinsettingalesserimplementationlevelamongthesatisfatoryones,
butwhihisstillfeasible. Ifitisnotpossible,theontratisstopped.
It isimportantto notie that ontratdegradationis eetiveonlyat toplevel, and thus is performed by
theDomain. It meansthat there is nodegradationofimplementation leveloutside toplevel. That iswhy we
onlyspeakofontratforservieattoplevel.
UseofserviesEahalltoaservieattoplevelasonsequenesontheontratwhihhasbeennegoiated
forhim. Wesupposethat aontratismadebeforetherstinvoationofthedesiredservie. Theveriation
ouldautomatially bedonewith Qinna, butis notnotyet implemented. All thenotiationsof failures are
loggedforthedeveloper.
3. Qinna'somponents implementationin C++. Weimplementedin C++theQinnaomponents
andalgorithms. Theseomponentsareprovidedthroughlasseswhihwedetailinthissetion.
3.1. Qinna'somponents for the managementof servies. QoSComponentTheQoSComponent
lassprovidesgenerionstrutorsanddestrutors,andontainsaprivatestruturetosavetheurrent
imple-mentationlevelsoftheomponentprovidedservie. AllQoSomponentswillinheritfrom thislass.
QoSBrokerTheQoSBrokerlassontainsaprivatestruturetosavethereferenestoalltheorresponding
omponentsitisresponsiblefor. ItprovidesthetwofuntionsFree(QoSComponent* refQ)andReserve(...).
As testCIC and updateCIC funtions signature depends of eah omponent/servie, these funtions will be
providedin eahinstane ofQoSBroker.
QoSManager TheQoSManager lass ontainsall information forthe servie provided by its assoiated
omponent. Itprovidethefollowingpublifuntions:
•
bool SetServieInfos(int idserv, QoSComponent *ompo, int nbreq, int nbmap) initializes themanagerfortheidservservie,providedby*ompo,withnbreqrequiredserviesandnbmapdierentimplementationlevels. Returntrueifsuessful,falseotherwise.
•
bool AddLevQoSReq(int idserv, int lv, int irq, int lrq) adds the tuple(
lv, irq, lrq
)
(thelv
implementationlevelforidserv
islinkedtothelrq
implementationlevelforirq
servie)inthemappingtablefor
idserv
.•
int Reserve(int idserv, int lv) is used for the reservation of theidserv
servie at levelil
. It returns the loal number of (sub) ontrat of the Manager or0
ifthe reservation has failed (due toresoureonstraints).
QoSDomainTheQoSDomainlassprovidesfuntionsformanagingontratsattoplevel:
•
bool AddServie(int servie, int nbRq, int nbMp, QoSManager *qm) adds the servieservice
withnbRq
requiredserviesandnbM p
implementationlevels,withassoiatedmanager∗
qm
.•
int Reserve(QoSComponent *ompo,int ns , int lv, int imp)is usedforreservation ofthe ser-viens
providedby theomponent∗
compo
atlevellv
andimportaneimp
. it returnsthenumberof ontrat(in domain)ifsuessful,0
otherwise.•
bool Free(int id)freestheontratnumberid
(ofdomain).ManagerContratThislassprovidesageneristrutureforasubontratwhihenodesatupleofthe
form
< id, lv,
∗
rq, v >
whereid
istheontratnumber,lv
theurrentlevel,rq
istheomponentthat provides theservie andv
is aC++-vetorthat enode thelevelsof the requiredservies. Thislass providesaessfuntionsto thesevariablesandafuntion tohangetheimplementationlevel.
DomainContratThislass providesastruture forontratsattoplevel. A Domainontratisatuple
oftheform
< di, i, lv,
∗
rq >
wheredi
istheglobal identierofthe ontrat,∗
rq
is themanagerassoiatedto theomponent that provides theservie,i
is theloal number ofsubontrat forthe manager, andlv
is theurrentleveloftheservie.
3.2. Basiresoureomponents. Intheallgraphofoneservie,leavesarephysialresoures(Memory,
CPU, Network). As all resouresmust be enapsulated inside omponents, we need to enapsulate the base
funtionsintoQoSComponents. Forinstane,theMemoryomponentmustbeenodedasawrapperaroundthe
mallofuntion, andtheassoiatedbrokerbasiallyimplementstheCIC funtionswhih deideif theglobal
amountofalloatedmemoryisreahedornot.
Sometimes, the basi funtions are enapsulated in higher level omponents. For instane, a high level
librarymightprovideaDisplayImagefuntionwhihmakesanexpliitalltomallo,but thisallishidden
bythe use ofthe library. Inthis partiular ase, themanagement ofbasi resourefuntions anbe donein
twodierentbut equivalentways:
•
thereationofaphantomMemoryomponentwhihprovidesthetwoserviesamallo(forabstrat mallo) and afree. Eah time the developer makes a all to an impliit resoure funtion (i. e.when the alled funtion needs a signiant amount of memory, like DisplayImage), he has to all
Memory.amalllo. TheQinna's C++implementation provides somebasiomponents likeMemory,
NetworkandCPUandtheirassoiatedbrokers.
•
thereationofQoSComponentaroundthelibraryfuntionDisplayImagewhihisresponsible(through itsbroker)fortheglobalamountofquantityofresoureused fortheDisplayImagefuntion.Both solutions need a preise knowledge of the libraries funtions w.r.t the resoure onsumption. We
assumethatthedeveloperhasthis knowledgesinehedesignsaresoure-awareappliation. Inourasestudy
weusedtherstsolution.
4. Methodology to use Qinna. Wesuppose that in the appliation allresoures, inluding hardware
resoures(Memory, CPU) or software ones (viewer,buer), areenoded by omponents. Here are themain
stepsforintegratingQinnaintoanexistingappliation designedin C++:
1. Identifythevariableservieswhiharefuntionswhoseallmayfailduetosomeresourereasons.
Theyareoftwotypes:
•
simplefuntions likeMemory.mallowhoseodedoesnotvary. Theyhaveaunique implementa-tionlevel.•
adaptive funtionswhoseodeanvaryaordingto implementationlevels.Therststepisthustoidentifytheservieswhosequalityvaryandassoiatetoeahofthisserviesa
unique key,andiftheodevary,learlyidentify thevariantodethroughaodeoftheform:
swith(implLevel)
{
ase 0 :
...
}
whereimplLevelistheassoiated(variable)attributeofthehostomponentforthisservie. Wemust
identifywhihvariableserviesarerequiredforeahprovidedservie,andtherelationshipbetweenthe
dierentimplementationlevels.
2. Create Qinna omponents. First, utthe soureodeinto QoSComponents thatan provideone
ormoreQoSservies. AstheQoSnegotiation willonlybemadebetweenQoSComponentsofdierent
types, this split will have many onsequenes on the QoS management. For eah QoSComponentC
(whih inheritsfromtheQoSComponentlass), thedesigner mustenodetwolasses: QoSBrokerCand
QoSManagerCwhih respetivelyinherit from theQoSBrokerand QoSManagergenerilasses. Forthe
wholeappliation, thedesigner willdiretlyusetheQoSDomaingenerilass.
3. ImplementQuality of Resoure onstraints. These onstraintsaresetintwodierentways:
•
Thetypeonstraints(CTC)foromponentC
implementationisomposedofadditionalfuntions inQoSBrokerC
: initCTC whih isexeuted at the reationof the Broker, andwhih sets thedeisionproeduresparameters;atestCTCfuntion todeterminewhetheranewinstaneanbe
reatedornot;anupdateCTCto savemodiationsoftheresouresafterthereation. Foreah
provided QoSservie
s
i
, weadd to newfuntions: testCTC(idsi)whih is exeuted before theall of aservieand tellsifthe servieanbedone, and updateCTC(idsi)to beexeutedafter
theall.
•
The instane onstraints (CIC) forC
are also omposed of three funtions to enode in thede-ide if aservie of identiant ids an be alled, and updateCTC(idsi)to update the resoure
onstraintsafteraall tothe
s
i
funtion.4. Implementthe linking onstraints. Thelinks betweenrequiredserviesand provided servievia
implementationlevelsaresetbytheinvoationoftheSetServieandAddLevQoSReqfuntionsofthe
managers. Thesefuntions willbeinvokedattoplevel.
5. Modifythe main le to initialize Qinna omponentsat toplevel. Herearethemainsteps:
•
Foreahbaseresoure(CPU,Memory,...)(a) Invoketheonstrutor fortheassoiatedBroker. Theonstrutor'sargumentsmustontain
theinitialization of internal variables for type onstraints(the totalamount of memory for
example).
(b) CreatetheassoiatedManagerwiththeBrokerasargument.
() RegistertheQoSserviesinsidetheManagerthroughtheuseof SetServieInfosfuntion.
(d) Create QoSComponents instanes via theBroker.reserve(...) funtion. The arguments
anbeaertainamountofresoureusedbytheomponent.
•
ForalltheotherQoSComponents,therequiredomponentsrst: (a) CreatetheassoiatedBrokerand Manager.(b) Settheserviesinformation.
() Ifaservierequiresanotherservieofanotheromponent,usethefuntion Manager.AddReq
tolinktherequiredmanager. ThenuseManager.AddLevQoSReqtosetthelinkingonstraints.
(d) Create QoSComponent instanes by invoking the orresponding reservation funtion
(Broker.Reserve).
•
CreatetheQoSDomainandaddtheserviesthatareusedattoplevel(Domain.AddServie)•
ReserveserviesviatheQoSDomainandsavetheontrats'numbers.5. Viewer Implementationusing Qinna.
5.1. Speiation. Ourasestudyisaremoteviewerappliationwhosehighlevelspeiationfollows:
•
Thesystemisomposedofamobilephoneandaremoteserver.Theappliationallowsthedownloading andthevisualizationofremoteimagesviaawirelesslink.•
Theremotediretoryisreahedviaaftponnetion. Afteronnetion,twobuttonsNext and Pre-vious areusedto displayimagesonebyone. Loally,someimagesarestored inabuer. Toprovideabetterqualityofservie,someimagesaredownloadedinadvane,whiletheoldestonesareremoved
fromthephotomemory.
•
Theappliation must managedierentqualities of servies forthe resoures: shortage of bandwidth andmemory,ordisonnetionsoftheftpserver. Whenneededitandownloadimagesinlowerquality(insizeorimageompressionrate).
•
Dierentstoragepoliies arepossible,andtherearemanyparameterswhih anbemodied;likethe sizeofthebuer,orthenumberofimagesthataredownloadedeahtime. Wewanttoevaluatewhihpoliy isthebest aording toagiven senario.
WewanttouseQinnafortwoobjetives:
•
themaintenaneoftheappliationwithrespetto thedierentqualitiesofservie,•
theevaluation oftheinuene oftheparameters,onthenon-funtional behavior(timingperformane andresoureusage).5.2. Thefuntionalpart. ThefuntionalpartoftheviewerisdevelopedwithQt 1
(aC++librarywhih
providesgraphialomponentsand implementations oftheftpprotool). Figure 5.2desribesthemain parts
ofthestandaloneappliation. Wehosetomakethedownloadingpartviatheftpprotool. Thewirelesspart
isnotenoded.
•
TheFtpClientlassmakesaonnetiontoanexisting ftpserverand hasalistof alldistantimages. ItprovidesagetSomefuntion toenablethedownloadingofmanylesatone.•
TheImageBufferlass isresponsibleforthemanagementofdownloadedles inaloal diretory. As thespeiationsays,this buerhas alimitedsize anddierentpoliyfor downloadingimages. Thelassprovidesthetwofuntions donextanddopreviouswhih are asynhronousfuntions. A signal
Fig.5.1. Sreenshotoftheviewerappliation
ImageViewer
ImageBuffer
FtpClient
init()
next/previous
donext/doprevious
connect
provided
required
downloadList
getSome
connect
Main
ImageScreen
displayImage
get
setPixmap
initBuffer
Fig.5.2.Funtionalviewoftheappliation
isthrownif/whenthedesiredimageisreadytobedisplayed. Iteventuallydownloadsfuture imagesin
urrentdiretory.
•
The ImageViewer lass is a high level omponent to make the interfae between the ftp and buer lassestothegraphisomponents.•
The ImageSreen lass is responsible for the display of the image in a graphi omponent named QPixmap.•
ThemainlassprovidesallthegraphisomponentsfortheGraphialUserInterfae.5.3. IntegrationofQinna. Nowthatwehavethefuntionalpartoftheappliation,weaddthefollowing
resoureomponents: Memory,andNetworkwhihareQoSComponentsthatprovidevariableservies. Weonly
fous onthese twobasiresoures. TheNetwork omponentis onlylinkedtotheFtpClient,whereasMemory
willbesharedbetweenallomponents. ForMemory,theonlyvariableservieisamallowhihanfailifthe
globalamountofdediatedmemoryisreahed;thisfuntion hasonlyoneimplementationlevel. ForNetwork,
downloadList
setPixmap
Network
ImageScreen
ImageBuffer
FtpClient
initBuffer
connect
connect
ImageGUI
QoSComponent
QoSComponent instance
service with variable quality
provided
required
start
ScreenMemory
BufferMemory
Memory
Thread
thread
get donext
displayImage
getSome doprevious
get previous
next
...
amallo
amallo
Fig.5.3.Arhitetureexample
Identiationof the variableservies (step1)
Nowas thevariable serviesforlowlevel omponentshave been identied, welist thefollowingadaptive
serviesforthefuntionalpart:
•
ImageSreen.displayImagevariesamongmemory,ithasthreeimplementationlevelswhihorrespond tothequalityofthedisplayedimage. WeaddallstoMemory.amallofuntiontosimulatetheuseofMemory.
•
Ftplient.getsome'simplementation varies among available memory and the urrent bandwidth of network.Ifthereisnotenoughmemoryornetwork,itadaptsthepoliyofthedownloads.Ithasthreeimplementationlevels. WeaddallstoNetwork.bandwidthtosimulatethenetworkresouresthatare
neededtodownloadles.
•
ImageBuffer.donext/previousvaries among available memory: if there is notenough memory the imageissavedwithhighompression.Creation ofthe QoSComponents(step2)
The resoure omponents are QoSComponents. Then, the three omponents ImageSreen, FtpClient
and ImageBufferare QoSComponents whih provide eah one variable servie. Imageviewer and Main are
QoSComponentsaswell. Figure5.3representsnowthestrutureoftheappliation atthisstep.
Forthesakeofsimpliity,weonlyshareMemoryintotwoparts,apartforImageBufferandtheotherpart
forimageBuffer. Thatmeansthateahoftheseomponentshavetheirownamountofmemory.
Resoure onstraints (steps 3and 4)
The quantity of resoureonstraints we have xed are lassial ones (bounds for the memory instanes,
uniqueinstantiationfortheimageSreenomponent,nomorethan80perentofbandwidthfortheftpClient,
et). TheQLSC areverysimilarto thosedesribedin [11℄foravideogameappliation. Hereweshowhowwe
haveimplementedsomeoftheseonstraintsinourappliation.
•
Quantity of resoure onstraints The imageSreen omponent is responsible for the unique servie display_image(displaytheimageonthegraphivideowidget). Herearesomebehavioralonstraintsweimplementedforthisomponent:
Thereisonlyoneinstaneoftheomponentone.
Thedisplayfuntion anonlydisplayimages withsizelesserorequalto
1200
∗
800
. Thereisonlyoneallto thedisplayfuntion one.These typeonstraintsare easily implementedin theassoiatedBroker(imageSreenBroker)in the
followingway: theonstraintmaximumofinstane requires twoprivateattributes nbinstaneand
nbinstanemaxwhih are delared andinitialized at the reationof theBrokerwith values
0
and1
.Then the reservation of a new imageSreen by the Broker is done after heking whether or not
The heking of memory is done by setting the global amount of memory for ImageBuffer and
imageBuffer in loal variables whih are set to
0
at the beginning of eah ontrat, and updatedeahtimethefuntion amalloisalled.
These onstraints are rather simple but we an imagine more omplex ones, provided they an be
hekedwithboundedomplexity(thisisaonstraintomingfromthefattheQinnaomponentswill
alsobeembedded).
•
QoSLinkingonstraintsToillustrate the dierene between quality of resoureonstraints and linking onstraints, we show
heretheonstraintsfortheFtpClient.getSome:
Theimplementationlevel
0
orrespondsto3
suessivedownloadswiththeNetwork.getfuntion.Thefuntion hasauniqueimplementation levelbuteahalltoit ismadewith
60
asargument,tomodelthefatitrequires
60
%ofthetotalbandwidth. ThesethreeallsaremadethroughtheuseoftheThread.threadwithimplementationlevel
0
(quikthread,noativewait).Theimplementationlevel
1
orrespondsto2
allstothegetfuntionwith40
%ofbandwidtheahtime. ThesetwoallsaremadethroughtheuseoftheThread.threadwithimplementationlevel
1
(middlethread,fewativewait).Theimplementationlevel
2
orrespondsto1
allto thegetfuntionwith20
%bandwidth. ThisallismadethroughtheuseoftheThread.threadwithimplementationlevel
2
(moreativewait).Thus if the available bandwidth is toolow, anegotiation oran existing ontrat will fail beause of the
resoureonstraints. Thereationoftheontratmayfailbeauseathreadannotbeprovidedatthedesired
implementationlevel.
Modiation of toplevel (step 5)This partisstraightforward. Theonlyhoies wehavetomakeare
the relative amount of resoure (Memory, Network) whih are alloated to eah QoSComponents. The test
senarioisdetailed insetion5.5.
5.4. Somestatistis. Thevieweriswrittenin4350linesofode,thefuntionalparttakingroughly1800
lines. The otherlines areQinna's generi omponents (1650 lo.), 600lines of odefor the newomponents
(imagesreenBroker,imageSreenManageret.) and300linesofodeforthetestsenarios. Thebinaryisalso
muhbigger 4.7Mbytes versus2MbyteswithoutQinna.
ThusQinnaisostly,but allthesupplementarylinesofodedonotneedtoberewritten,beause:
•
GeneriQinnaomponents,algorithms,andthebasiresoureomponentsareprovidedwithQinna.•
ThedeisionfuntionsforQualityofservieonstraintsouldbeautomatiallygeneratedorbeprovided asalibraryofommononstraints.•
Theinitializationattoplevelouldbeomputed-aidedthroughuser-friendlytables.Wethink thattheostof Qinnaintermsof binaryode anbestronglyreduedbyavoidingtheexisting
redundanyinoururrentimplementation.
Moreover,Qinna'simplementationanbeviewedasaprototypetoevaluatetheresoureuseandthequality
ofserviemanagement. Afterapreliminaryphasewiththewholeimplementationusedtondthebestlinking
onstraints, wean imagine an optimized ompilation through glue ode whih neither inludes brokersnor
managers.
5.5. Results. Werealized asenariowithanew omponentwhose onlyobjetiveis to usethebasi
re-souresMemoryandNetwork. ThisTestComponentprovidesonlythefoobarfuntionattoplevel. This
fun-tionhastwoimplementationlevels,andrequirestwofuntions:SreenMemory.amalloandNetwork.get. The
wholeappliation providesfourfuntionsat toplevel: TestC.foobar,ImageViewer.donext(anddoprevious)
and ImageSreen.displayimage. Three ontratsare negotiated, in thefollowing importane order: foobar
rst,thendonextanddoprevious,thendisplayimage.Wemadethethreeontratsanddownloadand
visual-izeimagesatthehighestqualities,butatsomepointthefoobarfuntionausesthedegradationoftheontrat
fordisplayimage,andtheimagesarethenshowninadegradedversion,liketheEieltoweronFigure5.1.
Thegap betweentheharateristisoftheontratandtheeetiveresoureusageanbemakethrough
Fig.5.4. Memoryuse
6. Related works. Other works also propose to use a developmentframework to handle resoure
vari-ability. In[10℄ and[6℄,theauthorproposeamodel-basedframeworkfordeveloppingself-adaptativeprograms.
Thisapproahuseshigh-levelspeiationsbasedontemporallogiformulatogenerateprogrammonitors. At
runtime,thesemonitorsaththesystemeventsandativatesthereonguration. Thisapproahissimilarto
usexeptthatitmainlydealswithhybridautomataandthereisnonotionofontratdegradationnorgeneri
algorithmfornegoiation.
Theexpressionandmaintenaneofresoureonstraintsisalsoonsideredasafundamental issue,somuh
workdealswiththissubjet. In[5℄,theauthoruseaprobabilistiapproahtoevaluatetheresoureonsumed
bytheprogrampaths. Someotherworksinthedomainofveriationtrytoproveonformaneofoneprogram
to somespeiation: in [7℄, forinstane, theauthors usesynhronousobserversto enode and verify logial
time ontrats. At last, the QMLlanguage ( [2℄, [1℄) is now well used to express QoSproperties. This last
approah isomplementaryto our onesine itprovidesalanguagewhih ouldbeompiled into soureode
forQoSComponentsorBrokers.
7. Conlusion and future work. In this paper, we have presented a ase study using the software
arhitetureQinnawhihwasdesignedtohandleresoureonstraintsduringthedevelopmentandtheexeution
ofembeddedprograms. Wefousedmainlyonthedevelopmentpart,bygivingageneraldevelopmentshemeto
useQinna,andillustratingitonaasestudy. Theresultingappliationisaresoure-awareappliation,whose
resouresonstraintsareguaranteedatruntime,andwhoseadaptationtovariabilityofservieisautomatially
doneby theQinna omponents, throughthe notionof ontrats. Atlast, weare ableto evaluate atruntime
thethresholdbetweenontratualisedresoureandtherealamountofresoureeetivelyused.
ThisworkhasshowntheeetivityofQinnawithrespettotheprogrammingeort,andtheperformane
ofthemodiedappliation.
FutureworkinludesomeimprovementsofQinna'sC++omponents,mainlyondatastrutures,in order
todereasetheglobalostofQinnaintermsofbinarysize,andmorespeianddetailedresoureomponents,
in orderto bettert totheplatform speiations. IntegratingQinnainto amodeldrivendevelopmenttools,
suh asGaspard([8℄),anbeawaytoimprovethiseieny.
From thetheoretialpoint ofview,there is alsoaneedfor awayto managethe linking onstraints. The
developerhasstilltolinktheimplementationlevelsofrequiredandprovidedservies,andtheorderbetweenall
implementationslevelsisxedbyhimaswell. Thetuningofalltheselinksanonlybedonethoughsimulation
yet. Wethinkthat somemethods likeontrollersynthesis([4℄) ouldbeusedto disoverthe/aoptimalorder
andlinkingrelationsw.r.t. someonstraintssuhasminimalvariability,bestreativityet..
Finally, sometheoretialwork would beneessaryin orderto useQinnaasapreditiontool,andprovide
aneientompilationintoglueode.
REFERENCES
[1℄ S.FrølundandJ.Koistinen,Qml: Alanguageforqualityofserviespeiation,teh.rep.,HPL-98-10,1998.
[3℄ L.GonnordandJ.-P.Babau,QuantityofResourePropertiesExpressionandRuntimeAssuraneforEmbeddedSystems,
inACS/IEEEInternational Confereneon ComputerSystems andAppliations, AICCSA'09, Rabbat, Moroo, May
2009,pp.428435.
[4℄ F.M.K.Altisen,A.ClodiandE.Rutten,Usingontrollersynthesistobuildproperty-enforinglayers,inEuropean
SymposiumonProgramming(ESOP),April2003.
[5℄ H. Koziolek and V. Firus, Parametri Performane Contrats: Non-Markovian Loop Modelling and anExperimental
Evaluation,inFormalFoundationsofEmbeddedSoftwareandComponent-BasedSoftwareArhitetures(FESCA),
Ele-tronialNotesinComputerSiene,Vienna,Austria,2006.
[6℄ I. Lee,S. Kannan, M.Kim, O. Sokolsky, and M.Viswanathan, Runtimeassurane based onformal speiations,
inProeedings of the International Conferene on Parallel and Distributed Proessing Tehniques and Appliations
(IPDPS'99),1999.
[7℄ F.MaraninhiandL.Morel,Logial-timeontratsforreativeembeddedomponents,in30thEUROMICROConferene
onComponent-BasedSoftwareEngineeringTrak,ECBSE'04,Rennes,Frane,Aug.2004.
[8℄ I.-R.Quadri,S. Meftali,andJ.-L. Dekeyser,Anmdeapproahforimplementingpartialdynamireonguration in
fpgas,inProeedingsofthe16thInternationalConfereneonIP-BasedSystem-on-hip,Grenoble,Frane,2007.
[9℄ M.Sparling,Lessonslearnedthroughsixyearsofomponent-based development,Commun.ACM,43(2000).
[10℄ L. Tan, Model-based self-monitoring embedded systems with temporal logi speiations, in Proeedings of the 20th
IEEE/ACMInternationalConfereneonAutomatedSoftwareEngineering(ASE'05),2005.
[11℄ J.-C.Tournier,Qinna: unearhitetureà basede omposantspourlagestionde laqualitédeserviedans lessystèmes
embarquésmobiles,PhDthesis,INSA-Lyon,2005.
[12℄ J.-C.Tournier, V.Olive,andJ.-P.Babau,TowardsadynamimanagementofQoSonstraintsinembedded systems,
inWorkshopQoSCBSE,inonjuntionwithADA'03,Toulouse,Frane,June2003.
Editedby: JanuszZalewski
Reeived: September30,2009