30
Scheduling Fixed-Priority Tasks with Preemption Threshold Yun Wang Department of Computer Science Concordia University Montreal, QC H3G 1M8, Canada y [email protected] Manas Saksena Department of Computer Science University of Pittsburgh Pittsburgh, PA 15260, USA [email protected] Abstract While it is widely believed that preemptability is a necessary requirement for developing real-time software, there are additional costs involved with preemptive scheduling, as compared to non-preemptive scheduling. Furthermore, in the context of fixed-priority scheduling, feasibility of a task set with non- preemptive scheduling does not imply feasibility with preemptive scheduling (and vice-versa). In this paper, we use the notion of preemption threshold to develop a new scheduling model, which unifies the concepts of preemptive and non-preemptive scheduling, and subsumes both as special cases. The notion of preemption threshold was introduced by Express Logic, Inc. in their ThreadX real-time operating system. It allows a task to disable preemption from tasks up to a specified threshold priority. Tasks having priorities higher than the threshold are still allowed to preempt. In our new model, each task has a regular priority and a preemptionthreshold. We show how the new scheduling model can be analyzed for response times. We also develop algorithms for optimal assignment of priorities and preemption threshold. In this paper we also provide evidence that this new scheduling model provides substantial quantitative benefits over both preemptive and non-preemptive scheduling models. We show that the new model can result in substantial improvement of schedulability by taking advantage of aspects of both preemptive and non-preemptive scheduling. Furthermore, we show that the new model provides lower run-time costs by eliminating unnecessary preemptions. This work was presented in part at RTCSA’99, Hongkong, December 1999 and a brief version of this work was published in the conference proceedings of RTCSA’99 by the IEEE Computer Society Press.

Scheduling Fixed-PriorityTasks with Preemption …regehr/reading/open_papers/preempt_thresh… · another algorithm that given a feasible assignment of priorities and preemption thresholds

Embed Size (px)

Citation preview

SchedulingFixed-Priority Taskswith PreemptionThr eshold�

Yun Wang

Departmentof ComputerScience

ConcordiaUniversity

Montreal,QC H3G1M8, Canada

y [email protected]

ManasSaksena

Departmentof ComputerScience

Universityof Pittsburgh

Pittsburgh,PA 15260,USA

[email protected]

Abstract

While it is widely believedthat preemptabilityis a necessaryrequirementfor developingreal-time

software, there are additional costsinvolvedwith preemptivescheduling,as comparedto non-preemptive

scheduling. Furthermore, in the context of fixed-priority scheduling, feasibility of a task set with non-

preemptiveschedulingdoesnot implyfeasibilitywith preemptivescheduling(andvice-versa).In thispaper,

weusethenotionof preemptionthresholdto developa new schedulingmodel,which unifiestheconceptsof

preemptiveandnon-preemptivescheduling,andsubsumesbothasspecialcases.

Thenotionof preemptionthresholdwasintroducedby ExpressLogic, Inc. in their ThreadXreal-time

operatingsystem.It allowsa taskto disablepreemptionfromtasksupto a specifiedthresholdpriority. Tasks

havingpriorities higherthanthethresholdare still allowedto preempt.In our new model,each taskhasa

regular priority anda preemptionthreshold.We showhowthenew schedulingmodelcanbeanalyzedfor

responsetimes.Wealsodevelopalgorithmsfor optimalassignmentof priorities andpreemptionthreshold.

In thispaperwealsoprovideevidencethatthisnew schedulingmodelprovidessubstantialquantitative

benefitsover both preemptiveand non-preemptiveschedulingmodels. We showthat the new modelcan

resultin substantialimprovementof schedulabilityby takingadvantageof aspectsof bothpreemptiveand

non-preemptivescheduling. Furthermore, we showthat the new modelprovideslower run-timecostsby

eliminatingunnecessarypreemptions.�This work waspresentedin partat RTCSA’99, Hongkong,December1999anda brief versionof this work waspublishedin

theconferenceproceedingsof RTCSA’99 by theIEEE ComputerSocietyPress.

1 Intr oduction

Sincethepioneeringwork of Liu andLayland[14], muchwork hasbeendonein theareaof real-time

scheduling,andin the analysistechniquesto a priori predictschedulabilityof tasksetsundera particular

schedulingdiscipline. In particular, significantprogresshasbeenmadein schedulabilityanalysisof task

setsunderfixed priority preemptive scheduling(e.g., [8, 9, 11, 12, 18]). The benefitsof fixed priority

preemptiveschedulingincluderelatively low run-timeoverheads(ascomparedto dynamicpriority schemes,

suchasearliestdeadlinefirst) andability to supporttighterdeadlinesfor urgenttasks(ascomparedto non-

preemptivescheduling).

Whilepreemptabilityis oftennecessaryin real-timescheduling,it is fallaciousto assumethatit always

resultsin higherschedulability. Indeed,it canbe shown that, in the context of fixed priority scheduling,

preemptiveschedulersdonotdominatenon-preemptiveschedulers,i.e.,theschedulabilityof atasksetunder

non-preemptive schedulingdoesnot imply the schedulabilityof the tasksetunderpreemptive scheduling

(andvice-versa). Moreover, preemptive schedulershave higherrun-timeoverheadsascomparedto non-

preemptiveschedulers.

In thispaper, weproposeageneralizedmodelof fixedpriority schedulingthatintegratesandsubsumes

bothpreemptiveandnon-preemptiveschedulers.Themodelusesthenotionof preemptionthreshold, which

wasintroducedby ExpressLogic, Inc. in their ThreadXreal-timeoperatingsystemto avoid unnecessary

preemptions[10]. In our new schedulingmodel,eachtaskhasa preemptionthreshold,in additionto its

priority. In essence,this resultsin a dual priority system. Eachtaskhasa regular priority, which is the

priority at which it is queuedwhenit is released.Oncea taskgetsthe CPU, its priority is raisedto its

preemptionthreshold.It keepsthis priority, until theendof its execution.For recurringtasks,this process

repeatseachtime thetaskis released.

Thepreemptionthresholdschedulingmodelcanbeusedto getthebestaspectsof bothpreemptiveand

non-preemptive scheduling.By choosingthepreemptionthresholdof a taskthat is higherthanits priority,

a taskavoidsgettingpreemptedfrom any taskthathasa priority lower thanits preemptionthreshold.By

varyingthepreemptionthresholdsof tasks,thedesiredamountof non-preemptabilitymaybeachieved. In

thisway, thepreemptionthresholdmodelmaybeviewedasintroducingnon-preemptabilityin acontrollable

manner. A suitablesettingfor thepreemptionthresholdscanthusbeusedtoget“just enoughpreemptability”

neededto meetthereal-timeresponsivenessrequirements;therebyeliminatingrun-timeoverheadsarising

from unnecessarypreemptabilityin theschedulingmodel.

It is alsoeasyto seethatbothpreemptiveandnon-preemptiveschedulingarespecialcasesof schedul-

Task Comp. Time Period Deadline��� ��� ���� 20 70 50 � 20 80 80�� 35 200 100

Table 1. An Example Task Set.

ing with preemptionthreshold. If the preemptionthresholdof eachtask is the sameas its priority, then

themodelreducesto purepreemptive scheduling.On the otherhand,if thepreemptionthresholdof each

taskis setto the highestpriority in thesystem,thenno preemptionsarepossible,leadingto fixedpriority

non-preemptivescheduling.

1.1 A Motivating Example

Beforewe delve into a theoreticaltreatmentof the new schedulingmodel, it is instructive to takea

look at a simpleexamplethatshows how schedulabilitycanbeimprovedwith this new schedulingmodel.

Weconsidera tasksetwith 3 independentperiodictasks,asshown in Table1. Eachtaskis characterizedby

a period( ��� ), adeadline( ��� ) anda computationtime( ��� ).Theschedulingattributesfor eachtaskincludeits priority ( ��� ) andits preemptionthreshold( ��� ). As-

sumingfixed-priorityscheduling,theoptimalpriority orderingfor this tasksetis deadlinemonotonicorder-

ing with bothpreemptivescheduling[13] andnon-preemptivescheduling[5]. Underthispriority ordering1,

theworst-caseresponsetimesfor thetasksareshown in Table2. We canseethat �� missesits deadlineun-

derpreemptivescheduling,while � missesits deadlineundernon-preemptivescheduling.Sincethepriority

orderingis optimal, this implies that the tasksetis not schedulableundereitherfixed-prioritypreemptive

scheduling,or fixed-prioritynon-preemptivescheduling.2

Whenwe usepreemptionthreshold,we canmakethe tasksetschedulableby settingthepreemption

thresholdfor � as3, and � as2. By settingthepreemptionthresholdof �� to 2, weallow it to bepreempted

by � , but not by � . This effectively improvestheresponsetimeof � (ascomparedto thenon-preemptive

case)sinceit canno longerbe blockedby �� . At the sametime, it improvesthe responsetime of �� (as

1Throughoutthispaper, weusehighernumbersto denotehigherpriorities.2Wealsonotethataslightmodificationto thisexamplewill show thatthefeasibilityunderpreemptiveschedulerdoesnot imply

feasibilityundernon-preemptivescheduler(by changingthedeadlineof ��� to 120),andviceversa(by changingthedeadlineof ���to be60).

Task � WCRT WCRT ! � WCRT

Preemptive Non-Preemptive Preemption-Threshold� ��" � � � ��"$#� 3 20 55 3 40 � 2 40 75 3 75 � 1 115 75 2 95

Table 2. Response Times for Tasks under Different Scheduler s.

comparedto the preemptive case)sinceit cannotbe preemptedby � once � hasstartedrunning. The

resultantresponsetimesarealsoshown in Table2.

Figure1 illustratestherun-timebehavior of thesystemwith preemptionthreshold,andwhy it helpsin

increasingschedulability. In thefigure,thearrows indicatearrival of taskinstances.Thefigureshows the

schedulingof tasksstartingfrom the critical instantof �� , which occurswheninstancesof all tasksarrive

simultaneously(time 0). Thescenarioleadsto theworst-caseresponsetime for �� . We canseethatat time

70, a new instanceof � arrives. Sincethe priority of � is higherthanthepreemptionthresholdof �� , ��is preempted.At time 80, a new instanceof � arrives. It cannot preempttheexecutionof � . However,

at time 90, when � finishes,a purepreemptive schedulerwould have run � , delaying �� . In contrast,by

settingthepreemptionthresholdof �� to 2, we have �� scheduledat time 90 underour schedulingmodel.

Thiseffectively improvestheworst-caseresponsetimeof �� , makingit schedulable.Notehoweverthatthis

alsoaddsblockingtime to � (ascomparedto thepreemptivecase),which increasesits worst-caseresponse

time,but doesnotaffect its schedulabilityin thisexample.

The useof preemptionthresholdsalsoreducesthe run-timeoverheadsassociatedwith preemptions

andthe associatedcontext-switches. This is dueto the introductionof somenon-preemptabilityinto the

schedulingmodel.We simulatedtheexecutionof tasksin thisexamplefor oneLCM length(i.e.,2800time

units).Whenall taskswerereleasedsimultaneouslyat time0, we find thatpreemptiveschedulingresultsin

17 preemptions,while with preemptionthresholdswe get 8 preemptions.If we staggerthe releasetimes,

suchthat � is releasedat time 0, � at time 1, and at time 2, then the numberof preemptionswith

preemptiveschedulingis 30,while usingpreemptionthresholdsreducesit to 10.

200 40 70 80 9590

PSfragreplacements

� ���

Worst-CaseResponseTime for ��Figure 1. Run-time Behavior with Preemption Threshold

1.2 Contributions

Themaincontributionof thispaperis in developingtheproposedschedulingmodelusingpreemption

threshold,showing how it improvesover purepreemptive andnon-preemptive scheduling,andsystemat-

ically allocatingfeasibleschedulingattributes(priority andpreemptionthreshold)to tasksets. We begin

with developingtheresponse-timeanalysisfor thenew modelbasedon well-know techniqueusingcritical

instantsandbusyperiods [8, 9, 11,12, 18]. We thendevelopanalgorithmfor assignmentof taskpriorities

andpreemptionthresholds.Our solutioncomesin two steps.First, givenan assignmentof priorities,we

developanefficient algorithmthatcomputesanoptimalsetof preemptionthresholdsusinga searchspace

of %'&)( � * (insteadof %'&)(,+ * for anexhaustivesearch).Thealgorithmis optimalin theusualsenseof finding

a feasibleassignment,i.e., onethatmakesthetasksetschedulable,if oneexists. Usingthis algorithmasa

“sub-routine”we thenproposeanoptimalsearchalgorithmto find anoptimalassignmentof bothpriorities

andpreemptionthresholdsby extendingAudsley’soptimalpriority assignmentalgorithm[1, 18]. We also

presentanefficient (but non-optimal)greedyheuristicalgorithmthatis usedin oursimulations.

The proposedschedulingmodelprovidessomeinterestingfeaturessuchasimproved schedulability

(comparedtobothpreemptiveandnon-preemptiveschedulers)andreducedpreemptionoverhead(compared

to preemptive schedulers).We quantifythebenefitsof theproposedschedulingmodelthroughsimulations

overrandomlygeneratedtasksets.To quantifytheimprovementin schedulability,weusebreakdownutiliza-

tion [11] asameasureof schedulability. Oursimulationsshow thatdependingonthetasksetcharacteristics,

usingpreemptionthresholdcanincreasethe schedulabilityby asmuchas -/.�0214365 of processorutiliza-

tion ascomparedto preemptivescheduling,andevenmoreascomparedto non-preemptivescheduling.We

alsopresentsimulationresultsthat quantify the reductionin preemptions.For this purpose,we develop

anotheralgorithmthatgivenafeasibleassignmentof prioritiesandpreemptionthresholds(asgenerated,for

instance,by our greedyalgorithm)attemptsto assignlarger preemptionthresholdswhile still keepingthe

tasksetschedulable.Usingthis new assignment,we thensimulatetheexecutionof a tasksetandmeasure

thenumberof preemptions,andcomparethatwith purepreemptivescheduling.Ourresultsshow that,again

dependingon the tasksetcharacteristics,we cangeta significantreduction(up to 30%) in thenumberof

preemptions(averagedover multiple tasksetswith thesamecharacteristics).

1.3 PaperOrganization

The remainderof this paperis organizedas follows. Section2 describesthe proposedscheduling

model,andthe problemsthat arebeingaddressedin this paper. In Section3, we develop schedulability

analysisequationfor ournew model.Section4 focusesondevelopinganoptimalalgorithmfor assignment

of priorities andpreemptionthresholdsfor a given taskset. In Section5, we quantify the improvement

in schedulabilityusingthe preemptionthresholdschedulingmodel. Then,in Section6, we show how to

systematicallyreducethenumberof preemptions.Finally, wepresentsomeconcludingremarks.

2 ProblemDescription and Solution Overview

Theexamplepresentedin Section1.1showedthatby usingpreemptionthresholdswe canpotentially

increaseschedulabilityandat thesametime reducerun-timeoverheads.This raisesthequestionof how to

makeeffective useof the new schedulingmodelto get thesebenefits.In this section,we first presentthe

taskandrun-timemodelassumedin thispaper. Then,we givea statementof theproblemsbeingaddressed

in thispaper, followedby anoverview of oursolutionapproach.

2.1 Taskand SchedulingModel

We considera setof ( independentperiodicor sporadictasks 7 "98 : ��:/;/;�;<: �=�> . Eachtask �is characterizedby a 3-tuple ?)��� : ��� : ���A@ , where �B� is its computationtime, �C� is its period(or minimum

inter-arrival time), and � � is its relative deadline.We assumethat (a) the tasksareindependent(i.e., there

is no blockingdueto sharedresources),(b) tasksdo not suspendthemselves,otherthanat theendof their

computation,and(c) theoverheadsdueto context switching,etc.,arenegligible (i.e.,assumedto bezero).

Eachtaskwill alsobegivenapriority � �ED�F - : (HG andapreemptionthreshold� �IDJF � � : (HG . Thesevalues

areassignedoff-line andremainconstantat run-time.Weassumethatlargernumbersdenotehigherpriority,

andthatnotwo taskshavethesamepriority. Weassumethattherun-timedispatchingis preemptive,priority

based,wheretasksaredispatchedfrom anotionalreadyqueuesortedby priorities.Whena taskis released

it is insertedinto the notional readyqueueat its priority � � . When the task is dispatched,its priority is

effectively raisedto its preemptionthreshold� � , andit keepsthispriority until it finishesexecution.In other

words,it canonly bepreemptedby anothertask LK if � KNM � � . Notethatsincetasksarerecurring,they will

go throughthesedualprioritiesfor eachreleaseof a task.

2.2 ProblemStatement

In therestof thepaperourobjectiveis toshow how to effectivelyusethepreemptionthresholdschedul-

ing modelto realizeits potentialbenefits.Accordingly, we addressthefollowing inter-relatedproblems.

2.2.1 Schedulability Analysis

First,weconsidertheproblemof assessingschedulabilityof a tasksetunderthepreemptionthreshold

schedulingmodel,assumingthat the schedulingattributesarealreadyknown. For this, we develop the

worst-caseresponsetime analysisfor a tasksetby extendingthe well-known critical instant/busy-period

analysisusedin fixed-priorityscheduling.Let O bea priority assignment,and P bea preemptionthreshold

assignment.Let QR��&)O : P * denotethe worst-caseresponsetime of a task � underthe givenassignments.

Then,theschedulabilityof a tasksetis givenby thefollowing booleanpredicate:

S/T UWV/X &)7 : O : P *ZY [)\" &^]�_a`b`�-Nc2_ac2( * Q � &)O : P * c2� � (1)

2.2.2 Attrib ute Assignment

We thenconsidertheproblemof assigningschedulingattributes,i.e., priority andpreemptionthresh-

olds, to tasks.Theprimarygoalof finding the schedulingattributesis to determineif thereexistsa setof

schedulingattributesthat will makethe tasksetschedulable.That is, we wish to determinewhetherthe

following predicateis true:

&)d�O * &)d�P * `^` S�T UeV�X &)7 : O : P * (2)

If it isdeterminedthatatasksetisschedulable,thenweadditionallywanttofindasetof schedulingattributes

thatwill minimizerun-timeoverheadsby eliminatingany unnecessarypreemptions.

2.2.3 Quantitative Assessment

Sincethe preemptionthresholdschedulingmodelgeneralizesboth preemptive andnon-preemptive

schedulingmodels,it will do no worsethaneitherof themin termsof schedulability. However, we still

needto determinewhetherthereare any significantgains in schedulabilityif the preemptionthreshold

schedulingmodelis employed.To thisend,wewish to makea quantitativeassessmentof theimprovement

in schedulabilitythroughtheuseof preemptionthresholds.

Likewise, we are interestedin quantitative assessmentof run-timeoverheadsfor feasibletasksets.

Unlike schedulability, a non-preemptiveschedulerwill resultin lower run-timeoverheads.Moreover, since

non-preemptive schedulingis a specialcase,our schedulingmodelwill incur thesameoverheadasa non-

preemptive schedulerfor tasksetsthat areschedulablewith non-preemptive scheduling. Therefore,our

interestis in assessingrun-timeoverheadsdueto preemptionsandcomparethemwith a preemptivesched-

uler.

2.3 Solution Overview

Oursolutionconsistsof thefollowing parts:

(1) First, we show how givenboth the prioritiesandthe preemptionthresholds,we canfind the worst-

caseresponsetimesfor thetasks,andhencedeterminefeasibilityof aparticularpriority andthreshold

assignment.

(2) We thenconsidertheproblemof determininga feasiblepreemptionthresholdassignmentwith pre-

definedpriorities. We develop an optimal andefficient algorithmthat hasa searchspaceof %'&)( ��*(insteadof %f&)(,+ * for bruteforcesearch)to solve thisproblem.

(3) Weusetheoptimalpreemptionthresholdassignmentalgorithmto developabranchandboundsearch

algorithmto find a feasiblesetof schedulingattributes.Sincethesearchalgorithmmayresultin an

exponentialsearchspace,wealsodevelopanefficientbut non-optimalgreedyheuristicalgorithm.

(4) We usethegreedyalgorithmfor quantifyingtheimprovementin schedulability(ascomparedto both

preemptiveandnon-preemptiveschedulingmodels)usingrandomlygeneratedtasksets.Thisensures

thattheoff-line costsof usingdifferentschedulingmodelsareapproximatelysimilar resultingin fair

comparisons.

(5) To eliminateany unnecessarypreemptions,we presentan algorithm that takesa feasiblepriority

andpreemptionthresholdassignmentas input and refinesit (by increasingpreemptionthresholds

of tasks)to eliminateunnecessarypreemptionwhile maintainingfeasibility. Again, we quantifythe

improvementsusingsimulationsover randomlygeneratedtasksets.

3 Schedulability Analysis

We begin with schedulabilityanalysisof tasksetswhen the priority and the preemptionthreshold

of eachtaskarealreadyknown. The schedulabilityanalysisis basedon computationof the worst-case

responsetime of eachtask. If the worst-caseresponsetime of a task is no more than its deadline,then

the taskis schedulable.If all the tasksin a systemareschedulable,thenthesystemis calledschedulable.

The responsetime analysisemployedin this paperis an extensionof the well-known level-i busy period

analysis[8, 9,11,12,18], in whichtheresponsetimeis calculatedby determiningthelengthof busyperiod,

startingfrom a critical instant.Thebusyperiodat level-i is definedasa continuousinterval of time during

which theprocessoris continuouslyexecutingtasksof priority _ or higher.

3.1 Review of Level-i BusyPeriod Analysis

To calculatetheworst-caseresponsetime of a task,thebusyperiodanalysisessentiallysimulatesthe

effect of schedulingundera worst-casescenariofor the task. The busy periodfor task � is constructed

by startingfrom a critical instant(time0). Thecritical instantoccurswhen(1) an instanceof eachhigher

priority taskcomesat thesametime (time 0), and(2) thetaskthatcontributesthemaximumblockingtimeg & � * hasjust startedexecutingprior to time 0. Furthermore,to gettheworst-caseresponsetime,all tasks

areassumedto arrive at theirmaximumrate.

3.1.1 PreemptiveScheduling

For our taskmodeldescribedearlier, with arbitrarytaskdeadlines,the busyperiodof task � in tra-

ditional fixed-priority, preemptive schedulingcan be iteratively computedby using the following equa-

tion [18]:

h � &)i * " ikj � ��l mn K�o p�q<r�p/s t h ��&)i *� Kvu j � K (3)

In this equation,h � &wi * denotesthe lengthof a busyperiodfor task � , where i instancesof � areincluded

in thebusyperiod.Thelengthof thebusyperiodfor task � is givenby:x �y" z�{b|}�~4� <o ��o � o������ � h � &wi * `^` h � &)i * c2ikj � � (4)

where h � &)i * is the smallestvalueof h � &)i * that satisfiesEquation3. Essentiallythe equationstatesthat

duringthebusyperiodfor � , all instancesof � andhigherpriority tasksthatarrive within thebusyperiod

mustalsobeexecutedwithin thebusyperiod.Thebusyperiodlengthis computedby iteratively computingh � &)i * for i " - : 1 : # :�; ; ; usingEquation3 until wereacha i , i "�� suchthat h � & � * c � j � �The worst-caseresponsetime of � will be the longestresponsetime of all instancesthat arrive and

finish in thebusyperiod.Let usdenote�B��&)i * (q-th finish time) asthesmallestvalueof h ��&wi * thatsatisfies

equation3. Sincetheq-th instanceof � arrivesat &)ik0�- * j���� , theworst-caseresponsetime for � is given

by: Q ��" z����}�~�� <o������ o �E� &�� � &)i * 02&)ik0�- * j � � * (5)

3.1.2 Non-PreemptiveScheduling

Even thoughthe analysisdescribedabove wasdonefor preemptive scheduling,the sametechnique,

with minor modifications,canbeusedfor non-preemptive schedulingaswell [5]. However, therearetwo

importantdifferences.First, a taskmay be blockedby any lower priority task, if the lower priority task

startedexecutingjust prior to thecritical instant.Second,oncea taskgetstheCPU,it cannotbepreempted

by any higherpriority taskuntil it finishesexecution.

Theblockingtimefrom lowerpriority tasksis easyto incorporate.A taskmaybeblockedby only one

lowerpriority task.In theworstcase,this taskwouldhavestartedexecutingjustprior to thecritical instant.

Thus,theworst-caseblockingtime for task � , denotedasg � is givenby:g ��" z����n K�o p�q<��p/s � K (6)

Equation3 is modifiedfor non-preemptiveschedulingas:h � &)i * " g �el ikj � ��l mn K�o p�q<r�p/sZ� - l�� h � &)i * 0�� �� K ��� j � K (7)

Notethatthetermfor interferencefrom higherpriority tasksis modifiedto includetaskarrivalsup to (and

including)time h �<&)i * 0���� , i.e.,whentheq-th instancetask � startsexecuting.

3.2 ResponseTime Analysiswith PreemptionThresholds

Our responsetime analysiswith preemptionthresholdsfollows the sameprinciplesof the analysis

presentedin previoussection.As in thenon-preemptive case,we needto worry aboutblockingtime from

lower priority tasks.Also, asin preemptive scheduling,higherpriority tasksmaycauseinterferenceeven

aftera taskstartsexecuting.However, the interferenceis differentfrom purepreemptive scheduling,since

thetask’seffective priority changesto its preemptionthresholdonceit startsexecutingandonly taskswith

higherpriority thanthis effectivepriority maycauseinterference.Therefore,weexplicitly defineandcom-

putebothq-th starttime for a task � (denotedby   � &)i * ) andtheq-th finish time (denotedby � � &)i * ). After

we gettheq-th finish time by themodifiedbusyperiodanalysis,theworst-caseresponsetime is calculated

asbefore,following Equation5.

3.2.1 Computing Blocking Time

We begin with determiningthe blocking time for a task. The blocking is causeddueto preemption

thresholds,whena lowerpriority taskhasa preemptionthresholdhigherthanthepriority of thetaskunder

consideration.Then, if the lower priority task is alreadyrunning, it cannotbe preempted(due to higher

preemptionthreshold)by thetaskunderconsideration,leadingto blockingtime.

Definition 3.1(Blocking Range) Theblockingrangeof a task � is definedastherangeof priorities given

by F � � ,� � G .Definition 3.2(Active Task) A task(instance)is calledactiveif it hasstartedrunning,but is not finished

yet.

Proposition3.1 There is nooverlappingof blockingrangesbetweenthesetof activetasksat anyinstantof

time.

Proof: By contradiction.Suppose � and K areactive at sometime, andtheir blockingrangesoverlap.

Without lossof generalityassumethat � startedexecutionfirst. Then, for K to start runningbefore �finishes,it mustbe the casethat ���k¡¢� K . That is ���£c¤���k¡¥� K c¦� K . Thus,the blockingrangesdo not

overlap.

Proposition3.2 A task � canbeblockedbyat mostonelowerpriority task LK . Furthermore,it mustbethe

casethat � K¨§ � � .Proof: A new arriving taskinstanceof � cannotpreempta lowerpriority activetask LK only if � � falls in

theblockingrangeof LK , i.e., � K ¡�� � c©� K . FromProposition3.1,we know thatblockingrangesof active

taskswill notoverlap.Therefore, � will only fall into atmostoneof theseblockingranges,i.e.,beblocked

by theownerof thatblockingrange.Furthermore,it is easyto seethatany lowerpriority tasksthathavenot

startedexecutionbeforethearrival of � will notblock � .

Proposition3.2shows thatin computingtheblockingtime for a task � , we needto considerblocking

from only onelower priority task LK suchthat � K�§ � � . Furthermore,this is true for theentirebusyperiod

of a task � sinceduring the busy perioda lower priority taskcannotstartexecution(dueto the pending

instancesof � ). Therefore,themaximumblockingtimeof a task � , denotedbyg & � * , is givenby:g & � * " z����n K�o ª<q<«�p/swr�p�q � K (8)

3.2.2 Computing q-th Start Time:

Beforea task � startsexecution,thereis blocking from lower priority tasksand interferencefrom

higherpriority tasks.Amongall lowerpriority tasks,only onelowerpriority taskcancauseblockingaswe

showedin Proposition3.2. This taskmusthave arrivedandbegunexecutingbeforethebusyperiodstarts.

In theworstcase,it just startsexecutingbeforetime 0. All higherpriority tasksthatcomebeforethestart

time   � &)i * andany earlierinstancesof task � beforeinstancei shouldbefinishedbeforetheq-thstarttime.

Therefore,  � &)i * canbecomputediteratively usingthefollowing equation.

  � &wi * " g & � * l &wi�02- * j�� ��l mn K�o p�q<r�p/s � - l �   � &)i *� K ��� j � K (9)

3.2.3 Computing q-th Finish Time:

Oncethe q-th instanceof taskstartsexecution,we have to considerthe interferenceto computeits

finish time. Fromthedefinitionof preemptionthreshold,we know thatonly taskswith higherpriority than

thepreemptionthresholdof � canpreemptandgettheCPUbefore � finishes.Furthermore,we only need

to considernew arrivalsof thesetasks,i.e.,arrivalsafter   � &)i * . Basedonthis,wegetthefollowingequation

for computing� � &)i * :����&)i * "  ��<&)i * l ��� l mn K�o p�q�r�ª�s¬� t �B��&)i *� K u 0 � - l �  ­��&)i *� K¦���k� j � K (10)

4 FeasibleAssignmentof Priority and PreemptionThr eshold

In the previous section,we showed how to computethe worst-caseresponsetimeswhenpriorities

andpreemptionthresholdsof tasksareknown. In this section,we developanalgorithmto systematically

assignprioritiesandpreemptionthresholdsto tasks,suchthattheassignmentensuresschedulability. Wefirst

presentsometheoreticalresultsaboutourmodel.Then,wepresentanalgorithmmotivatedby theseresults

for optimalpreemptionthresholdassignmentto tasksetswith predefinedpriority. After that,we proposea

systematicapproachto find theoptimalpriority andpreemptionthresholdassignmentusingthis algorithm

asasub-routine.Finally, wemodify theoptimalalgorithmandpresentanefficient,but approximate,greedy

algorithm.Thegreedyalgorithmis usedin oursimulationsto enablea fair comparisonwith preemptiveand

non-preemptiveschedulingstrategies.

4.1 Propertiesof the Model

With the responsetime analysiswe have doneabove, we notice that this generalizedfixed-priority

schedulingmodelhassomeinterestingproperties. Assumingthat the priorities of tasksarefixed, these

propertieshelpus reasonabouttheeffect of changingpreemptionthresholdsof tasks.Furthermore,these

propertieswill helpusto reducethesearchspacefor finding theoptimalpreemptionthresholdassignment.

Therefore,wewill usethesepropertiesasguidelineswhile designinganalgorithmfor preemptionthreshold

assignment.

Lemma 4.1 Changingthe preemptionthresholdof a task � from � to � � mayonly affect the worst-case

responsetimeof task � andthosetaskswhosepriority is between� and � � .This canbeseenby examiningthe equationsdevelopedfor calculationof responsetimes. The pre-

emptionthresholdof a task � determineswhich (higherpriority) tasksmaybeblockedby � . Thesetasks

arethosewhoseprioritiesfall in therangeF � � : � � G . Therefore,theresponsetimeof all thesetasksmaybeaf-

fectedwhen � ’spreemptionthresholdis modified.It alsomayaffect its own responsetimesinceit changes

the setof tasksthat canpreemptit onceit hasstartedrunning. Note that, the preemptionthresholdof �doesn’t affect theinterferencefrom � on any lower priority task LK (which dependson LK ’s threshold,and � ’spriority). Therefore,changingthepreemptionthresholddoesn’t affect any lowerpriority task.A useful

propositiondirectly followsfrom this lemma,andis presentedbelow.

Proposition4.1 Theworst-caseresponsetime of task � will not be affectedby the preemptionthreshold

assignmentof anytask LK with � K®M � � .Proposition4.1 is usefulin developinga strategy for optimalassignmentof preemptionthresholds.It

shows that theschedulabilityof a taskis independentof thepreemptionthresholdsettingof any taskwith

higherpriority. Therefore,this suggeststhat thethresholdassignmentshouldstartfrom thelowestpriority

taskto highestpriority task.

Furthermore,Theorem4.1,presentedbelow, helpsusdeterminetheoptimalpreemptionthresholdas-

signmentfor aspecifictask.Thepreemptionthresholdof ataskcanrangefrom its ownpriority to thehighest

priority in thetaskset.Fromtheequationsfor worst-caseresponsetimeanalysis,wecanseethatataskmay

reduceits worst-caseresponsetimeby increasingits preemptionthreshold,whichrestrictsthesetof (higher

priority) tasksthatcanpreemptit. However, this is doneat thecostof a possibleincreasein theblocking

time of higherpriority taskswhich may leadto increasedworst-caseresponsetime of the higherpriority

task.Therefore,if thereis a setof preemptionthresholdvaluesthatcanmakea taskschedulable,choosing

theminimumof themwill maximizethechancesof findinga feasiblepreemptionthresholdassignment.

Theorem 4.1 Considera set of ( tasks 7 "¯8 � : � :/;�;/;<: = > , and a set of schedulingattributes O "?°� :�;/;/;L: � = @ and P " ?w� :/;�;/;<: � = @ , such that thetasksetis schedulablewith O and P (i.e., S�T UeV/X &)7 : O : P *is true). Then,if changingonly the preemptionthresholdof LK from � K to ��±K ( �C±K ¡¦� K ), canstill make LKschedulable,thenthewholesystemis alsoschedulablebysetting� ±K asthepreemptionthresholdof LK . That

is, Q K &)O : P²&�� K�³ � ±K *L* c�´ K¶µ·S�T UeV�X &)7 : O : P²&¸� K�³ � ±K *<*Proof: Whenthepreemptionthresholdof LK changesfrom � K to � ±K ( � KRM � ±K ), theworst-caseresponse

timeof any task �¹ with � ¹ ¡2� K or � ¹�M � K will notchange.Theworst-caseresponsetimeof atask �¹ such

that � ±K § � ¹fM � K will alsostaythesame.Furthermore,any task �¹ with priority � ±K ¡�� K c©� K will have

noworseworst-caseresponsetime with � ±K thanwith � K . Moreover, we alreadyknow that LK is schedulable

with � ±K . Therefore,if thewholesystemis schedulablewith � K , it is alsoschedulablewith � ±K .A given tasksetmay be unschedulablewith any preemptionthresholdassignment.The following

theoremgivesasufficientconditionto claimatasksetto beunschedulable.

Theorem 4.2 For any givenpriority assignmentif there existsa task � , such that settingthe preemption

thresholdof a task � equalto thehighestpriority in thesystemcannotmakea specifictask � schedulable,

thenthetasksetis unschedulable.

Proof: ComparingEquation10with Equation3, wecanseethatpreemptionthresholdreducestheworst-

caseresponsetime of a task � by preventingtheinterferencefrom somehigherpriority tasksafter � starts

execution.By settingthepreemptionthresholdof � to thehighestpriority in thesystemgivesthemaximum

reductionto theworst-caseresponsetimeof � . If � is still notschedulable,sincethepriority is predefined,

thereis nowayto makeit schedulable.Furthermore,thetasksetwill alsobeunschedulable.

Algorithm: AssignThresholds

// Assumesthat taskpriorities are alreadyknown

(1) for ( º := 1 to » )

(2) ¼/½C¾À¿6½ // start fromlowestvalue

// Find worst-caseresponsetimebasedon thetentativeassignment

(3) ÁN½ = WCRT( Â�½ ,¼�½ ) ;

(4) while ( Á ½CÃÅÄB½ ) do // whilenotschedulable

(5) ¼ ½ ++ ; // increasepreemptionthreshold

(6) if ¼ ½CÃ » then

(7) return FAIL; // systemnotschedulable.

(8) endif

(9) ÁN½e¾ WCRT( Â�½ ,¼�½ ) ;

(10) end

(11) end

(12) return SUCCESS

Figure 2. Algorithm for Preemption Threshold Assignment

4.2 Optimal PreemptionThresholdAssignmentwith Given Priorities

Basedon theresultsdevelopedin theprevioussection,we have developedanalgorithmthatfindsan

optimalpreemptionthresholdassignmentassumingthat theprioritiesareknown andfixed. Thealgorithm

is optimalin thesensethatif thereexistsafeasiblepreemptionthresholdassignmentthenthealgorithmwill

alsofind afeasibleassignment.

Figure2 gives the pseudocodeof the preemptionthresholdassignmentalgorithm. The algorithm

assumesthat the tasksarenumbered- : 1 :/;/;�;�: ( , andthat � �²" _ . Thealgorithmconsidersthepreemption

thresholdassignmentof onetaskat a time startingfrom thelowestpriority task. For eachtaskconsidered,

it finds the lowestpreemptionthresholdassignmentthat will makethe taskschedulable.This is doneby

computingtheresponsetimeof thetaskusingthefunctionWCRT(task, threshold), andcomparingit with

its deadline.Note that, the responsetime calculationis possibleeven with a partial assignmentsincewe

considertasksfrom low priority to highpriority.

It is easyto seetheworst-casesearchspacefor this algorithmis %f&)( � * . Thealgorithmis optimal in

thesensethat if thereexistsa preemptionthresholdassignmentthatcanmakethesystemschedulable,our

algorithmwill alwaysfind anassignmentthatensurestheschedulability. Theoptimalityof thealgorithmis

givenin thefollowing Theorem4.3.

Theorem 4.3 Givena fixedpriority assignment,thealgorithmAssignThresholdswill find a feasiblepre-

emptionthresholdassignment,if thereexistsone.

Proof: Assumea setof ( tasks 7 "Æ8 �ÈÇ -fcÉ_¨c¢( > , with a priority assignmentO " ?°� � :�;/;�;�: � = @ .Without lossof generality, assumethat the taskshave beenlabeledsuchthat � �Ê" _ . Furthermore,let the

tasksetbeschedulablewith asetof preemptionthresholdvaluesP "Ë8 � �EÇ &�-¨c2_Ec2( * > .Thealgorithmassignspreemptionthresholdsto thetasksstartingfrom � andgoingupto = . Let the

preemptionthresholdsfound by the algorithmbe labeled� ± : � ±� , etc. Assumethat task � is the first task

suchthat thepreemptionthresholdfoundby thealgorithmis differentfrom thegivenfeasibleassignment,

thatis, � ±�ÊÌ" � � . Then,it mustbethecasethat � ±� ¡�� � , otherwise,ouralgorithmwill find � � ratherthan � � ’.Basedon Theorem4.1,we know that thetasksetwill still beschedulableif we use � ±� to replace� � in the

above feasiblepreemptionthresholdassignment.

By repeatedlyusingtheabove argument,we canseethat thealgorithmwill alsofind a feasiblepre-

emptionthresholdassignment8 �C±� Ç �C±� c���� : -¨c2_Ec2( > .4.3 Optimal Assignmentof Priorities and PreemptionThresholds

In thissection,weaddressthegeneralproblemof determininganoptimal(i.e.,onethatensuresschedu-

lability) priority andpreemptionthresholdassignmentfor a given taskset. We give a branch-and-bound

searchalgorithmthatsearchesfor theoptimalassignment.Whethermoreefficientalgorithmscanbefound

for this problem,remainsan openquestionat this time. Our algorithmborrows the basicideasfrom the

optimalpriority assignmentalgorithmpresentedin [1, 18] for preemptive priority schedulingof a taskset.

Unfortunately, the introductionof preemptionthresholdsnot only addsanotherdimensionto the search

spacebut alsobringsmorebranchesinto thesearch,makingthesearchspaceexponentialin size.

Our searchalgorithm, presentedin Figure 3, proceedsby performinga heuristicguidedsearchon

“good” priority orderings,andthenwhena priority orderingis complete,it usesthealgorithmpresentedin

theprevioussectionto find afeasiblethresholdassignment.If a feasiblethresholdassignmentis foundthen

wearedone.If not,thealgorithmbacktracksto find anotherpriority ordering.

The algorithmworks by dividing the taskset into two parts: a sortedpart, consistingof the lower

priority tasks,andanunsortedpart, containingthe remaininghigherpriority tasks. The priorities for the

tasksin thesortedlist areall assigned.Theprioritiesfor thetasksin theunsortedlist areunassigned,but are

Algorithm: AssignSchedAttributes(Í , ¿ )

/* TerminatingCondition;assignpreemptionthresholds*/

(1) if ( Í == Î�Ï ) then

/* Usealgorithmin Figure2 for preemptionthresholdassignment*/

(2) return AssignThresholds()

(3) endif

/* Heuristicallygeneratea priority assignment*/

/* AssignHeuristicValueto Each Task*/

(4) L := Î/Ï ;

(5) foreach Â�ÐkÑ�Í do

(6) ¿6Ð := ¿ ; ¼�ШÒÓ¾�» ; ÁNÐ := WCRT( Â�Ð );(7) if ÁNÐ Ã�Ä Ð then Continue ; /* prune*/

(8) ¼/ÐkÒÓ¾Ô¿4Ð ; ÁNÐ := WCRT( Â�Ð );(9) if ÁNÐkÕ Ä Ð then

(10) Ö Ð ÒÓ¾ GetBlockingLimit(Â Ð ); /* positivevalue*/

(11) else

(12) Ö Ð ÒÓ¾Å× ÐÙØ Á Ð ; /* negativevalue*/

(13) endif

(14) L := L + Â�Ð ;(15) ¿6Ð := » ; /* reset*/

(16) end

/* Recursivelyperformdepthfirst search */

(17) while (L != Î/Ï ) do

/* Selectthetaskwith thelargestheuristicvaluenext */

(18) Â�ÐkÒÓ¾ GetNextCandidate(L);

(19) ¿6УÒÓ¾�¿ ;

(20) if AssignSchedAttributes(Í Ø Â�Ð , ¿ +1) == SUCCESSthen

(21) return SUCCESS;

(22) endif

(23) L := L - �Р;(24) end

(25) return FAIL

Figure 3. Search Algorithm for Optimal Assignment of Priority and Preemption Threshold

all assumedto behigherthanthehighestpriority in thesortedlist. Initially, thesortedpart is emptyandall

tasksarein theunsortedpart.Thealgorithmrecursively movesonetaskfrom theunsortedlist to thesorted

list, by choosinga candidatetaskbasedon heuristics,asdescribedbelow. Whenall tasksarein thesorted

list, a completepriority orderinghasbeengenerated,andthethresholdassignmentalgorithmis called.

Whenconsideringthe next candidateto move into the sortedlist, all tasksin the unsortedlist are

examinedin turn. To makethesearchmoreefficient,we selectthe“most promising”candidatefirst, using

a heuristicfunction,describedbelow. If thealgorithmfails to find a solutionwith thatpartialassignment,

it will backtrackandthenselectthenext task. Additionally, we pruneinfeasiblepathsby not considering

tasksthatcannotbemadeschedulableat thecurrentpriority level.

Figure 3 givesthepseudocodeof thesearchalgorithm,which is presentedasa recursive algorithm.

It takestwo parameters:7 , which is theunsortedpart(containingall thetaskswaiting for priority assign-

ment),and � , which is the next priority to assign. The tasksthat have beenassignedpriorities arekept

separately(andnot explicitly shown in thepseudo-code)for preemptionthresholdassignmentat theendof

thealgorithm.Thelist of candidatesto searchis createdin Ú . Thecomputationof worst-caseresponsetimes

assumesthatall taskswith unassignedprioritieshavethehighestpriority, andthatall unassignedpreemption

thresholdsareequalto thetaskpriority.

Pruning Infeasible Paths. First, we tentatively assigna task the currentpriority andcomputeits

responsetimewith its preemptionthresholdsetto thehighestpriority in thesystem.If its computedresponse

timeexceedsits deadline,thenthetaskcannotbemadeschedulableat thispriority level (Theorem4.2).This

is because,we assumeat this stagethatall othertaskshave preemptionthresholdsequalto their priorities.

Therefore,weprunesuchabranchto makethesearchmoreefficient.

Heuristic Function. To computetheheuristicfunction,we computetheresponsetime for the task

by tentativelyassigningit thecurrentpriority andassumingthatthepreemptionthresholdequalsits priority.

Let Q ¹ bethecomputedresponsefor a task �¹ in thismanner. Then,theheuristicfunctionis givenby:

Û ¹ " ÜÝ Þ g Ú ¹ ß^à Q ¹ c2� ¹Q ¹ 0À� ¹âá�ãAä�á (11)

whereg Ú ¹ denotesthe blocking limit for �¹ . The blocking limit representsthe maximumblocking that

the taskcanget while still meetingits responsetime. Note that at this stagesincewe have assumedthat

prioritiesequalpreemptionthresholds,thereis noblocking.However, oncetheprioritiesarefully assigned,

it is possiblethat in the preemptionthresholdassignmentstagea lower priority taskmay be assigneda

thresholdthat is higherthanthis task,andcancauseblocking. Theblocking limit capturesthe maximum

blocking that a task can toleratewhile still meetingits deadline. This can be computedby assigninga

blockingtermto thetask,repeatingtheworst-caseresponsetimecomputation,andcheckingif it still meets

thedeadline.

Theblocking limit is meaningfulif Q ¹ c¢� ¹ . Otherwise,it is still possiblethat ¹ maybeschedu-

lableat this priority with anappropriatepreemptionthreshold.Thustasksthatneeda smallerreductionin

interferencefrom higherpriority tasksarebettercandidatesfor selection.Accordingly, weassignaheuristic

valueof � ¹ 0åQ ¹ for eachtask.Notethatthesevaluesarenegative,whileg Ú ¹ is positive.Thus,suchtasks

have a lowerheuristicvalue,which is asdesired.

4.4 A GreedyAlgorithm

Theefficiency of theoptimalalgorithmshown abovedependsheavily onthecharacteristicsof thetask

set.In theworstcase,it hasexponentialsearchspacein termof thenumberof tasks.Clearly, thisalgorithm

becomesinfeasibleto use,even with a modestnumberof tasks. Therefore,we have developeda greedy-

heuristicalgorithm,which we usein our simulationsfor schedulabilitycomparison.Thebasicideaof this

greedyalgorithmis thesameastheoptimalalgorithm.Theonly differencelies in thebranchingpart. The

optimalalgorithmwill try all possiblebranchesbeforeit find a solution. However, theheuristicalgorithm

will only try theonethatis mostpromising,or in anotherword,theoneat theheadof thecandidatelist.

This heuristicalgorithmdominatesthe preemptive schedulingalgorithm,i.e., if a tasksetis schedu-

lable with preemptive scheduling,then the algorithm will be able to find a feasibleassignmentaswell.

This is not surprisingsincethealgorithmextendsAudsley’soptimalalgorithmfor priority assignment.On

the otherhand,therearecaseswhenthe algorithmis not ableto find a feasibleassignment,whena non-

preemptive priority assignmentalgorithm is able to find a feasibleassignment.Sincea non-preemptive

priority assignmentis alsoa feasiblesolutionfor our model,thealgorithmcanbetrivially extendedto use

thenon-preemptivepriority assignmentalgorithmfirst, andthenusethis algorithm.Without actuallydoing

so,we assumethatthis is thecase,andthis extendedalgorithmis usedin our simulations.In this way, our

extendedalgorithmdominatesbothpreemptiveandnon-preemptiveschedulingalgorithms.

5 Schedulability Impr ovement

Sinceour schedulingmodelsubsumesbothpreemptive andnon-preemptive scheduling,any taskset

that is schedulablewith eithera purepreemptive or a non-preemptive scheduleris alsoschedulablein our

model.In section1.1,we gavea simpleexampletaskset,which is not schedulableundereitherpreemptive

or non-preemptive scheduling,but canbescheduledwith our model. Nonetheless,it maybethecasethat

any suchschedulabilityimprovementcomesonly in exceptionalcases,andany suchimprovementmayonly

bemarginal. Accordingly, in this sectionwe wantto quantifytheschedulabilityimprovementthatmaybe

achieved by usingthis new model. Our strategy is to userandomlygeneratedtasksetsandtest for their

schedulabilityunderthedifferentschedulingmodels.

To comparetheschedulabilityof a tasksetunderdifferentschedulingpolicies,we needa quantitative

measurement.Onepossibilityis to usethebinarymeasureof schedulability, i.e.,eithera tasksetis schedu-

lableor not. A bettermeasure,andonethat is commonlyusedis thenotionof breakdownutilization [11].

Thebreakdown utilizationof a tasksetis definedastheassociatedutilizationof a tasksetat which a dead-

line is first missedwhenthecomputationtimeof eachtaskin thetasksetis scaledby a factor. In thispaper

weusebreakdown utilizationsto measureschedulability.

5.1 Simulation Design

We userandomlygeneratedperiodictasksetsfor our simulations.Eachtaskis characterizedby its

computationtime � � andits period � � . To keepthenumberof variablessmall,we assumethat � ��" � � for

all tasks.We vary two parametersin our simulations:(1) numberof tasks (W�£æ S/ç�S , from 5 to 50; and(2)

maximumperiodfor tasks� æ�èeé V�ê _�ë X , from 10 to 1000.For any givenpair of (W�£æ S�ç�S and � æ�èWé V/ê _°ë X ,werandomlygenerate100tasksets.

A tasksetis generatedby randomlyselectinga periodandcomputationtime for eachof the (W�£æ S�ç�S .First,a period �C� is assignedrandomlyin therangeF - : � æ�èeé V�ê _°ë X G with auniformprobabilitydistribution

function.Then,weassignautilization ìI� in therangeF 3 ; 34. : 3 ; .�G ,againwith uniformprobabilitydistribution

function.Thecomputationtimeof thetaskis thenassignedas ��� " �C�Wí�ìI� .For eachrandomlygeneratedtaskset,we measurethebreakdown utilization for eachof (1) purepre-

emptive scheduling,(2) non-preemptive scheduling,and(3) schedulingwith preemptionthreshold.We do

thisby scalingthecomputationtimesto getdifferenttasksetutilization,andthentestingfor schedulability.

Sincetherandomlygeneratedtasksetsmayhave utilization greaterthan1 to begin with, we initially scale

theutilization to 100%.We thenusebinarysearchto find themaximumutilization at which thetasksetis

schedulableunderaparticularschedulingalgorithm.

5.2 Attrib ute Assignment

Beforewe cando theresponsetime analysiswith a particularschedulingalgorithm,we mustderive

the schedulingattributes. In the caseof preemptive andnon-preemptive schedulingalgorithms,the only

schedulingattribute is taskpriority, while for the preemptionthresholdscheduling,both taskpriority and

preemptionthresholdmustbe derived. We derive optimal priority assignmentsfor both preemptive and

non-preemptive schedulingalgorithms. For the preemptive case,the optimal priority assignmentis sim-

ply therate-monotonicassignment[14]. For thegeneralcase,with arbitrarydeadlines,Audsley’s optimal

priority assignmentalgorithm[1] canbeused.For non-preemptivescheduling,we useoptimalpriority as-

signmentalgorithmpresentedin [5] which is basicallythe sameasAudsley’s algorithm,but adaptedfor

non-preemptive scheduling.For schedulingwith preemptionthresholds,we usethegreedy-heuristicalgo-

rithm presentedin lastsectionasanefficient approximationto assignprioritiesandpreemptionthresholds.

Thetime complexity of this algorithmis thesameasAudsley’salgorithm. This providesa fair groundfor

comparisonbetweenthealgorithms.

5.3 Simulation Results

In this section,we describethe resultsfor schedulabilityimprovement(asmeasuredby breakdown

utilization) usingpreemptionthresholds.As mentionedearlier, we controlledtwo parameters:(1) num-

ber of tasks( (W�£æ S/ç�S ), and (2) maximumperiod( � æ�èeé V/ê _�ë X ). We did the simulationsfor (W�£æ S/ç�S D8 . : -/3 : -/. : 143 : 1�. : # 3 : # . :<î 3 : .43 > and � æ�èWé V/ê _°ë X Dï8 -/3 : 143 : .43 : - 343 : .4363 : - 34343 > . For eachtaskset, we

measuredthebreakdownutilizationfor eachof thethreecases:purepreemptivescheduling,non-preemptive

scheduling,andpreemptiveschedulingwith preemptionthreshold.

In Figures4 and5weshow theschedulabilityimprovementasthenumberof tasksisvaried.Theresults

areshown for � æ�èWé V/ê _°ë X " 10 and100;theresultsaresimilar for othervalues.In eachcase,we plot the

averageandmaximumincreasein breakdown utilizationwhenusingpreemptionthresholds.Figure4 shows

schedulabilityimprovementascomparedto purepreemptive priority scheduling.As theplot shows, when

looking at averageimprovement,thereis a modestimprovementin schedulability(3%-6%), depending

on the numberof tasks. As the numberof tasksincreases,the improvementtendsto decrease.Perhaps,

moreinterestingis the plot for maximumincrease,which shows that the schedulabilityimprovementcan

be ashigh as18% improvementin breakdown utilization for selectedtasksets,althoughonceagainthe

improvementdecreasesasthenumberof tasksis increased.

Theresultsshowing theschedulabilityimprovementwith non-preemptiveschedulingaremorevaried.

First, for mostrangesof theparameters,theschedulabilityimprovementis muchmorethanthepreemptive

case(whichalsomeansthatpreemptiveschedulinggiveshigherbreakdown utilization,ascomparedto non-

preemptivescheduling).Theresultshouldnotbesurprisingsincenon-preemptiveschedulingperformsvery

badlyeven if onetaskhasa tight deadline,andany othertaskhasa largecomputationtime. In suchcases,

thebreakdown utilizationcanbearbitrarily low, ascanbeseenin Figure5(b).

Whilenon-preemptiveschedulingperformspoorlyin general,thereareselectedcaseswhenit performs

betterthanpreemptive scheduling,andbetterthanour heuristicalgorithmfor preemptionthreshold.Note,

however, thatweassumethatourheuristicalgorithmis augmentedwith theschedulabilitycheckusingnon-

preemptive scheduleraswell, andsoin theplotsthosecasessimply show upaszeropercentimprovement.

Theseresultscanbe seenin Figure5(a),wherenon-preemptive schedulingperformsthe bestof all three

when (W�£æ S/ç�S¬§ 143 ; similarresultsareobtainedfor othersmallervaluesof � æ�èeé V�ê _�ë X , but thiseffectgoes

awaywhen � æ�èWé V/ê _°ë X " -/363 or more.Thereasonfor this is thatwith largenumberof tasks,anda small

valueof � æ�èWé V/ê _°ë X , thecomputationtimesfor all tasksaresmall. This meansthatany blockingcaused

by non-preemptionhaslittle effect onschedulability, whichgivesriseto higherbreakdown utilization.

6 PreemptionOverheads

The applicationof our fixed priority schedulingmodelwith preemptionthresholdnot only provides

betterschedulability, but also may reducethe numberof preemptionsas comparedto pure preemptive

scheduling.Indeed,this wasoneof theprimarymotivationsbehindthedevelopmentof preemptionthresh-

old in theThreadXoperatingsystem[10]. Certainly, in theextremecaseif a tasksetis schedulableusing

non-preemptive scheduling,thenthereareno preemptions.Evenotherwise,we expectthat theuseof pre-

emptionthresholdsshouldpreventsomeunnecessarypreemptions.

Onepossiblebenefitbroughtby reducedpreemptionsis further improvementin schedulabilitywhen

theschedulingoverheadcausedbypreemptionsis takeninto account.Typically, suchanalysisassociatestwo

context switchespertask,andthatoverheadis addedto thecomputationtimeof a task[18]. Unfortunately,

it doesnot seemthatthis canbereduced(in theworst-case)with theuseof preemptionthresholds.On the

otherhand,if we canshow that therearereducednumberof preemptions(on anaverage),thenany such

timesavingsimpliesthattheprocessoris availablefor otherbackground/soft-real-timejobs,whichcanonly

bebeneficial.

In this section,we first show how thenumberof preemptionsin a given(schedulable)tasksetcanbe

reducedin a systematicmanner, while maintainingschedulability. We thenusesimulationresultsto seeif

thereis any substantialreductionin thenumberof preemptions.

6.1 PreemptionThresholdAssignmentto ReducePreemptions

Clearly, any feasibleassignmentof priorities andpreemptionthresholdswill be no worsethanpure

preemptive scheduling.However, for a given taskset(andassumingthat priorities aregiven), theremay

0

5

10

15

20

25

5 10 15 20 25 30 35 40 45 50

Incr

ease

in B

reak

dow

n U

tiliz

atio

n

ðNumber of Tasks

AverageMaximum

(a)MaximumPeriod= 10

0

5

10

15

20

25

5 10 15 20 25 30 35 40 45 50

Incr

ease

in B

reak

dow

n U

tiliz

atio

n

ðNumber of Tasks

AverageMaximum

(a)MaximumPeriod= 100

Figure 4. Schedulability Improvement with Preemption Threshold as compared to Preemptive

Scheduling.

beseveral feasiblethresholdassignments,andsomewill reducepreemptionsmorethanothers.Earlier in

this paper, we presentedanoptimalalgorithmto assignpreemptionthresholds(Figure 2). Thealgorithm

attemptsto assignthesmallestfeasiblepreemptionthresholdvalues,which wasnecessaryto ensureits op-

timality. However, it is possiblethatthereareotherfeasibleassignmentswith largerpreemptionthresholds

thatwill incur fewer preemptions.

Our approachto reducepreemptionsis to usethe assignmentgeneratedby our optimal threshold

assignmentasa startingpoint. Then,we iterateover thesolutionandattemptto assignthelargestfeasible

preemptionthresholdvaluesto taskssuchthatthetasksetremainsschedulable.Clearly, largerpreemption

0

20

40

60

80

100

5 10 15 20 25 30 35 40 45 50

Incr

ease

in B

reak

dow

n U

tiliz

atio

n

ðNumber of Tasks

AverageMaximum

(a)MaximumPeriod= 10

0

20

40

60

80

100

5 10 15 20 25 30 35 40 45 50

Incr

ease

in B

reak

dow

n U

tiliz

atio

n

ðNumber of Tasks

AverageMaximum

(a)MaximumPeriod= 100

Figure 5. Schedulability Improvement with Preemption Threshold as compared to Non-

Preemptive Scheduling.

thresholdvaluesreducethechancesof preemptions,andtherefore,shouldresultin lesspreemptions.

Figure6 givesthealgorithmthatattemptsto assignlargerpreemptionthresholdvaluesto tasks.The

algorithmconsidersonetaskatatime,startingfrom thehighestpriority task,andtriesto assignit thelargest

thresholdvaluethat will maintainthe feasibility of the system.We do this onestepat a time, andcheck

the responsetime of the affectedtaskto ensurethat the systemstaysschedulable.By goingfrom highest

priority taskto the lowestpriority task,we ensurethatany changein thepreemptionthresholdassignment

in latter(lowerpriority) taskscannotincreasetheassignmentof a former(higherpriority) task,andthuswe

only needto go throughthelist of tasksonce.

Algorithm: AssignMaximum PreemptionThresholds

/* Assumesthat taskpriorities arefixed,anda */

/* setof feasiblepreemptionthresholdsareassigned*/

(1) for (i := n down to 1)

(2) while (schedulable== TRUE) && ( � � ¡�( )

(3) � � += 1; /* try a largervalue*/

(4) Let LK bethetasksuchthat � K " � � ./* Calculatetheworst-caseresponsetimeof taskj

andcompare it with deadline*/

(5) Q K := WCRT( LK );(6) if ( Q K£M � K ) then // Taskj is not schedulable.

(7) schedulable:= FALSE

(8) ��� -= 1;

(9) endif

(10) end

(11) schedulable:= TRUE

(12) end

(13) return

Figure 6. Algorithm for Finding Maxim um Preemption Threshold

6.2 Simulation Designand Results

We usethesamerandomlygeneratedtasksetsthatwe usedin theprevioussection.We simulatethe

executionof a tasksetfor 100000time units,andtrack thenumberof preemptions.With � æ�èeé V�ê _�ë X "-/34363 , this givesat least1000 instancesof eachtask in a simulationrun. We want to seethe savings in

preemptionswhenusingpreemptionthresholdsascomparedto purepreemptive scheduling.Accordingly,

weusepercentagereductionin thenumberof preemptionsasthemetric,which is definedas:ñ�ò � é ê�V�V ��ó�ô _°ë�( S<õ 0 ñ�ò � é êöV�V ��ó�ô _°ë�( S<õ ÷ñ�ò � é ê�V/V ��ó�ô _�ëö( SLõ ÷ ík-/343

0

5

10

15

20

25

30

35

40

45

50

5 10 15 20 25 30 35 40 45 50

Per

cent

age

Red

uctio

n in

Pre

empt

ions

ø

Number of Tasks

MaxPeriod = 10MaxPeriod = 20MaxPeriod = 50

MaxPeriod = 100MaxPeriod = 500

MaxPeriod = 1000

Figure 7. Average Percentage Reduction in Number of Preemptions for Preemption Threshold

Scheduling as compared to Pure Preemptive Scheduling

whereñ�ò � é ê�V�V ��ó�ô _°ë�( S<õ and

ñ�ò � é ê�V/V ��ó�ô _�ë�( SLõ ÷ are the numberof preemptionsencounteredin a

particularsimulationrunwith preemptiveschedulingandpreemptionthresholdschedulingrespectively.

Wedid onesimulationrunfor eachtasksetgeneratedin thesimulationsof Section3. Thecomputation

timesfor the taskswerechosenby scalingthemto the largestvalueat which the tasksetwasschedulable

underpreemptivescheduling(i.e. thebreakdown utilization). We assignedprioritiesto thesetasksetsusing

therate-monotonic(optimal)algorithm. We usethesamepriorities for thepreemptionthresholdcase,but

additionallyassignedpreemptionthresholdsto the tasksasdescribedabove. That is, we first generateda

feasibleassignmentof preemptionthresholds.Then,we usedthealgorithmin Figure6 to assigna new set

of preemptionthresholds.During thesimulation,we randomlyassignedtheinitial arrival time of eachtask � in therangeF 3 : � � G .We plot the averagepercentagereductionin the numberof preemptionsfor preemptionthreshold

schedulingascomparedto preemptivescheduling.Theresultsareshown in Figure7. As canbeseenin the

figure, thereis a significantreductionin preemptionsfor smallnumberof tasks,but it tapersdown to less

than5%asthenumberof tasksis increased.Also, for any givennumberof tasks,thenumberof reductions

is largerfor largervaluesof � æ�èeé V/ê _�ë X , i.e.,whentheperiodrangeis larger.

7 RelatedWork

Like many papersin real-timeliterature,ourwork hasrootsin real-timescheduling.In thelasttwenty

years,schedulingtheoryhasbeenwidely studiedto provide guidelinesfor developinghardreal-timesys-

tems. Many resultshave beenproducedfor non-idling schedulingover a singleprocessor. Theseresults

fall into two categories: fixed-priority schedulersanddynamicpriority schedulers.Alternatively, onecan

categorizetheschedulersaspreemptive or non-preemptive. While dynamicpriority schedulerscanachieve

higherschedulabilityfor tasksets,fixed priority schedulersarecommonlypreferreddue to lower over-

headsin implementation.Moreover, mostcontemporaryreal-timeoperatingsystemsprovidedirectsupport

for fixedpriority preemptive scheduling,andalmostnoneprovide supportfor dynamicpriority scheduling

algorithmssuchasearliestdeadlinefirst (although,thepriority canbechangedfrom theapplication).

Schedulabilityanalysisin fixedpriority preemptiveschedulingis oftenbasedoncomputingtheworst-

caseresponsetimesandby comparingthemwith deadlines.Thenotionof level-i busyperiodwasintroduced

by Lehoczky [12] andcomputationof theworst-caseresponsetime for generaltasksetsis shown in [9, 8,

12, 18].

With fixed-priority preemptive scheduling,the deadlinemonotonicorderinghasbeenshown to be

optimal[13] for tasksetswith relativedeadlineslessthanor equalto periods.A specialcaseof thedeadline

monotonicorderingis the rate monotonicorderingwhen deadlinesequalperiods[14]. However, for a

generaltaskset,wheredeadlinesarenot relatedto the periods,Lehoczky [12] pointedout that deadline

monotonicorderingis not optimal. Audsley [1, 18] givesan optimal priority assignmentprocedurewith

complexity of ù'ú)ûCü ý .Deadlinemonotonicpriority orderingis no longeroptimal in the context of non-preemptive fixed-

priority schedulingof generaltaskset. However, it is optimal for a tasksetwith deadlineslessthanor

equalto periodsif smallerdeadlineimpliessmalleror equalcomputationtime[5]. Furthermore,theoptimal

priority assignmentalgorithmproposedby Audsley [1] is shown to bestill valid [5]. Thefeasibility is still

closelyrelatedwith computationof worst-caseresponsetime. Moreover, thelevel-i busyperiodanalysisis

alsovalid in thecontext of non-preemptivescheduling[5].

The schedulingwork that comesclosestto ours is the schedulingof taskswith varying execution

priorities [8, 4]. In [8], schedulabilityanalysisfor taskswith varyingexecutionpriorities is given,andin

fact it is recognizedthat the schedulabilityof a tasksetcanbe improved by increasinga task’s priority

sometimeduring its execution. The samegeneralideais usedin [4] with dual priority schedulingexcept

that the taskpriority is raisedaftera fixedamountof (real) time. The notionof preemptionthresholdcan

beviewedasaspecialcaseof schedulingwith varyingexecutionpriorities.However, ourwork differsfrom

thesein thatwegobeyondresponsetimeanalysis,andfocusonschedulingattributeassignment.

Our work on priority andpreemptionthresholdassignmentfor tasksis relatedto thegeneralproblem

of assigningfeasibletaskattributes. Besidesthe priority assignmentalgorithmsmentionedabove, several

researchershaveaddressedthisproblemin differentcontexts. In [6] feasibletaskattributessuchasperiods,

deadlines,andoffsetswerederived from end-to-endtiming requirementsspecifiedon systeminputsand

outputs.Thework hasbeenfollowedupby anumberof otherresearchers,addressingdifferentvariationsof

feasibletaskattributeassignmentproblem[3, 15, 16, 7].

Thenotionof preemptionthresholdis usedin variousothercontexts. Mostnotably, it is usedto avoid

unboundedpriority inversionsin priority ceilingprotocols[17, 2] by raisingthepriority of a taskwhile in a

critical section.

8 Concluding Remarks

We presenta generalizedfixed-priority schedulingmodelwith the notion of preemptionthreshold.

This modelbridgesthegapbetweenpreemptive andnon-preemptiveschedulingandincludesbothof them

as specialcases. It capturesthe bestof both models,and as a result it can feasibly scheduletask sets

whicharenot feasiblewith eitherpurepreemptivescheduling,or non-preemptivescheduling.In this paper,

we presentsimulationresultsover randomlygeneratedtasksetsshowing our modelachievessubstantial

improvementof the schedulableutilization of tasksetsover both preemptive andnon-preemptive cases.

Furthermore,usingtheconceptof level-i busyperiod,we derive theequationfor computingtheworst-case

responsetime of periodicor sporadictasksin thisgeneralmodel.

Usingthis analysis,we addressedtheproblemof findinganoptimalpriority orderingandpreemption

thresholdassignmentthatensuresschedulability. Basedon the theoreticalresultswe developedunderthe

model,we proposedanefficient algorithmfor finding optimalpreemptionthresholdassignmentfor a task

set with predefinedpriority. Finally using this thresholdassignmentalgorithm, we develop an optimal

searchalgorithmto find theoptimalprioritiesandpreemptionthresholds.A heuristicalgorithm,whichwill

dominatebothpreemptiveandnon-preemptiveschedulingis alsoproposedto achieve betterefficiency.

Oneinterestingaspectof this new schedulingmodelis that it achievesbetterschedulabilitywithout

increasingthe overheads.This is in sharpcontrastto dynamicpriority schemes,suchasearliestdeadline

first, which achievehigherschedulableutilizationat thecostof significantlyhigheroverheadsascompared

to fixed priority scheduling.The only additionalcostof this new schedulingmodelis anextra field to be

associatedwith tasks(for keepingtheirpreemptionthresholdvalues).With aminormodification,thekernel

canswitchbetweenthe normalpriority andthe preemptionthresholdof a task,asdictatedby the model.

Contrastthis with the dual-priorityschemeof Burns [4], wherethe implementationcostsarenon-trivial.

We alsonotethat the modelcanbeeasilyemulatedat userlevel, whenit is not supportedby a real-time

kernel.Of course,thereis anadditionalcostin thiscaseto changepriorities.

Not only doesthisnew schedulingmodelnotaddany additionaloverheads,it canreduceoverheadsby

incorporatingthebestaspectsof non-preemptive schedulinginto thepreemptive schedulingmodel. Thus,

themodelcanbeusedto introduceonly enoughpreemptabilityasis necessaryto achieve feasibility. In this

way, it canbeusedto reduceschedulingoverheadsby reducingthenumberof preemptions.Oursimulation

resultssupportthisconjecture,andshow thatin many casestherecanbeamarkedreductionin preemptions,

makingtheCPUbandwidthavailablefor backgroundandsoft real-timepriority tasks.

References

[1] N. Audsley. Optimal priority assignmentand feasibility of staticpriority taskswith arbitrarystart

times. TechnicalReportYCS 164,Departmentof ComputerScience,Universityof York, England,

December1991.

[2] T. Baker. A stack-basedresourceallocationpolicy for realtimeprocesses.In Proceedingsof IEEE

Real-TimeSystemsSymposium, pages191–200.IEEEComputerSocietyPress,December1990.

[3] I. BateandA. Burns.An approachto taskattributeassignmentfor uniprocessorsystems.In Proceed-

ingsof the11thEuromicro ConferenceonRealTimeSystems, 1999.

[4] A. BurnsandA. J.Wellings. A practicalmethodfor increasingprocessorutilization. In Proceedings,

5th Euromicro WorkshoponReal-TimeSystems, June1993.

[5] L. George,N. Rivierre,andM. Spuri.Preemptiveandnon-preemptivereal-timeuni-processorschedul-

ing. TechnicalReportþZÿ 2966,INRIA, France,sep1996.

[6] R. Gerber, S. Hong, andM. Saksena.GuaranteeingReal-Time Requirementswith Resource-based

Calibrationof PeriodicProcesses.IEEE Transactionson Software Engineering, 21:579–592,July

1995.

[7] S.GoddardandK. Jeffay. Analyzingthereal-timepropertiesof a dataflow executionparadigmusing

a syntheticapertureradarapplication.In Proceedings,IEEE Real-TimeTechnologyandApplications

Symposium, June1997.

[8] M. Harbour, M. Klein, andJ. Lehoczky. Fixed Priority Schedulingof PeriodicTaskswith Varying

ExecutionPriority. In Proceedings,IEEE Real-TimeSystemsSymposium, pages116–128,December

1991.

[9] M. JosephandP. Pandya.Findingresponsetimesin areal-timesystem.ComputerJournal, 29(5):390–

395,1986.

[10] William Lamie. Preemption-threshold. White Paper, Express Logic Inc. Available at

http://www.threadx.com/preemption.html.

[11] J. Lehoczky, L. Sha,andY. Ding. The ratemonotonicschedulingalgorithm: Exactcharacterization

andaveragecasebehavior. In Proceedingsof IEEE Real-TimeSystemsSymposium, pages166–171.

IEEEComputerSocietyPress,December1989.

[12] J.P. Lehoczky. Fixedpriority schedulingof periodictasksetswith arbitrarydeadlines.In Proceedings

of IEEE Real-Time SystemsSymposium, pages201–209.IEEE ComputerSocietyPress,December

1990.

[13] J.LeungandJ.Whitehead.Onthecomplexity of fixed-priorityschedulingof periodic,real-timetasks.

PerformanceEvaluation, 2:237–250,1982.

[14] C. Liu andJ. Layland. Schedulingalgorithmfor multiprogrammingin a hardreal-timeenvironment.

Journalof theACM, 20(1):46–61,January1973.

[15] M. Ryu, S. Hong,andM. Saksena.StreamliningReal-Time ControllerDesign- From Performance

Specificationsto End-to-EndTiming Constraints. In ProceedingsIEEE Real-Time Technologyand

ApplicationsSymposium, June1997.

[16] M. SaksenaandS. Hong. Resourceconsciousdesignof distributedreal-timesystems:An end-to-

endapproach.In Proceedings,IEEE InternationalConferenceonEngineeringof Complex Computer

Systems, October1996.

[17] L. Sha,R. Rajkumar, andJ. Lehoczky. Priority inheritanceprotocols:An approachto real-timesyn-

chronization.IEEETransactionsonComputers, 39:1175–1185,September1990.

[18] K. Tindell, A. Burns,andA. Wellings. An extendibleapproachfor analysingfixedpriority hardreal-

time tasks.TheJournalof Real-TimeSystems, 6(2):133–152,March1994.