• No results found

Interrupt Routine of RTOS

N/A
N/A
Protected

Academic year: 2021

Share "Interrupt Routine of RTOS"

Copied!
6
0
0

Loading.... (view fulltext now)

Full text

(1)

INTERRUPT ROUTINES IN AN RTOS ENVIRONMENT

INTERRUPT ROUTINES IN AN RTOS ENVIRONMENT

INTRODUCTION INTRODUCTION

Lik

Like e stanstand-ad-alonlone e syssystemtems, s, embembeddedded ed appapplicalicatiotions ns runrunninning g on on top top of of realreal-tim-timee operating systems (RTOSes) require Interrupt Serice Routines (ISRs) to !andle interrupts operating systems (RTOSes) require Interrupt Serice Routines (ISRs) to !andle interrupts generated by e"ternal eents# $"ternal eents can be caused by %ust about anyt!ing, from an generated by e"ternal eents# $"ternal eents can be caused by %ust about anyt!ing, from an async!ronous c!aracter arrial on a &'RT to a periodic timer interrupt# ISRs !ae t!e async!ronous c!aracter arrial on a &'RT to a periodic timer interrupt# ISRs !ae t!e responsibility of acknoledging t!e !ardare condition and proide t!e initial !andling of  responsibility of acknoledging t!e !ardare condition and proide t!e initial !andling of  data sent or receied as required by t!e interrupt# 'n ISR often is responsible for proiding data sent or receied as required by t!e interrupt# 'n ISR often is responsible for proiding t!e RT

t!e RTOS it! information necessaOS it! information necessary to proide serices ry to proide serices to application t!reads#to application t!reads# $"amples include moing data into a buffer for processing, adding an

$"amples include moing data into a buffer for processing, adding an entry to a queueentry to a queue for processing, setting a alue to indicate t!at an eent !as occurred, and so on# Since for processing, setting a alue to indicate t!at an eent !as occurred, and so on# Since application code e"ecution is interrupted (delayed) during t!e e"ecution of an ISR, most application code e"ecution is interrupted (delayed) during t!e e"ecution of an ISR, most applications minimie t!e amount of code in t!e ISR and rely instead on non-ISR code (an applications minimie t!e amount of code in t!e ISR and rely instead on non-ISR code (an application *T!read+ or

application *T!read+ or *T*Task+) to complete ask+) to complete t!e processing#t!e processing# SYNOPSIS

SYNOPSIS

 RTOS IT$RR&T 'R./IT$.T&R$SRTOS IT$RR&T 'R./IT$.T&R$S

 T$R0IOLO12T$R0IOLO12

 'R./IT$.T&R$'R./IT$.T&R$

 TOT'L S2ST$0 O3$R/$'4 .O0'RISOTOT'L S2ST$0 O3$R/$'4 .O0'RISO

 .O.L&SIO.O.L&SIO

R$5$R$.$S R$5$R$.$S

RTOS INTERRUPT ARCHITECTURES

RTOS INTERRUPT ARCHITECTURES

'

' funfundamdamentental al c!ac!allenllenge ge in in RRTOTOS S desdesign ign is is supsupporportinting g asynasync!rc!ronoonous us acceaccess ss toto internal RTOS data structures by interrupt routines and RTOS serices# It cannot be alloed internal RTOS data structures by interrupt routines and RTOS serices# It cannot be alloed

6 6

(2)

t!at, !ile modifying a data structure, a serice or ISR gets interrupted and a different serice or ISR makes unrelated modifications to t!e same structure, leaing it in a c!anged state for  t!e original code to (unknoingly) continue modifying# T!e results can be catastrop!ic#

'll RTOSes must address t!is c!allenge and preent multiple ISRs (or system calls) from modifying t!e same structure at t!e same time# T!is allos t!e !ig!est priority application code to be e"ecuted as quickly as possible, and delayed as little as possible, een in situations it! intense interrupt actiity# T!ere are at least to approac!es, one used by t!e ma%ority of RTOSes, and anot!er used by a fe# T!e more popular approac! is to briefly lockout interrupts !ile an ISR or system serice is modifying critical data structures inside t!e RTOS# T!is reliably preents any ot!er program from %umping in and making uncoordinated c!anges to t!e critical area being used by t!e e"ecuting code#

'not!er, less popular approac! is not to disable interrupts in system serice routines,  but instead (by rule or conention) not allo any async!ronous access to critical data structures by ISRs or ot!er serice calls# Serice call access to critical data structures from an ISR is *deferred+ to a secondary routine e denote *ISR7,+ !ic! gets e"ecuted along it! application t!reads under sc!eduler control# T!is approac! also reliably preents interference it! t!e actions of an e"ecuting system serice call, by not alloing any t!reads or ISR7 routines, !ic! mig!t make system serice calls, to e"ecute until processing of critical data structures is completed# T!is approac! is called a *Segmented Interrupt 'rc!itecture,+  because it breaks up t!e processing required in response to an interrupt into multiple (usually 7) *segments+ e"ecuted at different priorities# In t!is paper, e e"amine t!e performance implications of eac! approac! on real-time system responsieness#

TERMINOLOGY

T!e folloing is a list of symbols used to represent t!e processing performed in eac! type of RTOS interrupt arc!itecture8

Symbo l

Meaning

..8 .onte"t .reate# .reate conte"t for ISR7# T!is typically inoles creating a stack  frame and alerting t!e sc!eduler to sc!edule it ne"t#

(3)

.R8 .onte"t Restore# Restore conte"t of sc!eduled entity .S8 .onte"t Sae# Saes t!e conte"t of t!e running t!read#

I48 Interrupt 4ispatc!er# 'pplicable in single interrupt ector arc!itectures like oer., 0IS, and 'R0# On arc!itectures like .old5ire, t!is item is done in !ardare#

ISR8 Interrupt Serice Routine# Traditional ISR, alloed to interact it! application t!reads t!roug! RTOS serices#

ISR68 Interrupt Serice Routine, art-6# Similar to traditional ISR, but not alloed to interact it! RTOS#

ISR78 Interrupt Serice Routine, art-7# Sc!eduled entity run in a t!read or super-t!read conte"t# 'lloed to interact it! RTOS serices and t!reads#

ITR'8 Interrupted T!read Running 'gain# L8 Lockout# Interrupt lockout time#

S8 Sc!eduler# Sc!edule t!e most important t!read or ISR7#  T8 e T!read running#

68 Start of ISR processing# 78 $nd of ISR processing#

98 e t!read running : preemption case# ;8 Return to interrupted t!read#

<OL48 Items t!at are purely application code#

The Unifie In!e""#$! A"%hi!e%!#"e

RTOSes t!at employ a unified arc!itecture treat t!e ISR no differently t!an an ISR in a stand-alone application# In t!is arc!itecture, t!e ISR is alloed to make RTOS calls to modify kernel data structures and to interact it! application t!reads and ot!er resources# To do t!is, t!e RTOS disables interrupts oer certain (typically ery s!ort) code segments, t!ereby protecting common resources against async!ronous access from multiple ISRs or  system serice calls#

(4)

ARCHITECTURE

RTOSes t!at do not disable interrupts during system serices cannot make modifications to RTOS data structures from it!in an ISR, because t!e ISR mig!t be interrupted by anot!er interrupt, !ic! t!en mig!t attempt to use t!e same data structure# To  preent t!is, segmented arc!itectures basically disable t!e application sc!eduler, and diide

t!e interrupt processing into to (or more) pieces# T!e first piece (ISR6) be!aes like a traditional ISR but performs no interaction it! RTOS data structures# T!is enables it to run it! interrupts enabled#

T!e second piece (ISR7) is a *sc!eduled entity+ t!at makes all necessary RTOS data structure updates at t!e application leel, and is inoked t!roug! t!e processing in ISR6# 5inally, application t!read processing can be performed once bot! ISR6 and ISR7 !ae been completed# T!is effectiely disables applications !ile ISR6 and ISR7 are operating, and defers conte"t sitc!ing !ile RTOS data structures are being modified# T!e performance obserations in t!is section are some!at abstract#

T!e amount of time for RTOS performance ob%ects (e#g# .S, .., .R, etc#) on most RTOS products ill be some!at similar# /oeer, t!e segmented arc!itecture products are typically larger operating systems so t!eir actual processing times for eac! RTOS  performance ob%ect ould most likely be greater t!an a simpler unified interrupt arc!itecture RTOS# In addition, if memory protection or irtual addresses are supported, t!e time required to process an RTOS block ill most definitely be greater# T!e succeeding comparisons assume t!at t!e arious RTOSes take t!e same amount of time to perform t!e same RTOS operation# It is furt!er assumed t!at t!e time to perform ISR processing in t!e unified approac! is equal to t!e sum of t!e times to perform ISR6 and ISR7 in t!e segmented approac!#

(5)

In bot! preemption and non-preemption cases, t!e segmented approac! takes longer# TOTAL SYSTEM OVERHEAD COMPARISON

Ironically, as can be seen in 5igure-9, t!e total system oer!ead is greater in t!e RTOS it! a segmented interrupt arc!itecture# In bot! t!e non-preemption and preemption cases t!e segmented interrupt arc!itecture RTOS introduces an additional (6=.S, 6=.R, 7=S, and 6=..) of oer!ead#

CONCLUSION

T!e segmented RTOS arc!itecture is claimed to !ae an adantage in its ability to respond to interrupts# 'fter all, if interrupts are disabled, response s!ould be negatiely impacted, rig!t> T!e !ole idea be!ind not disabling interrupts is to make interrupt response faster# /oeer, !ile it sounds good, t!ere are seeral practical problems introduced by t!is approac!# 'lt!oug! t!e segmented interrupt RTOS doesn?t disable interrupts !en manipulating RTOS data structures inside serice routines, t!e !ardare itself does !en  processing ot!er interrupts# So t!e orst case L in t!e segmented interrupt RTOS is actually

t!e time interrupts are locked out during t!e processing of anot!er interrupt# RE&ERENCES  !ttp8@@rtos#com@articles@6AA9B  !ttps8@@#csun#edu@C%eff@[email protected]BDA$'@Lectures@OSSerices@OSSer icesE!tml@te"t7F#!tml  !ttp8@@stackoerflo#com@questions@B9GBFG@!o-do-real-time-operating-systems-ork   !ttp8@@#slides!are#net@HOLL&S&4'RS/'R$442@munni-;9A6BF  !ttps8@@sites#google#com@site@rtosmifmim@!ome@interrupt-routines-in-an-rtos-enironment---part-6 B

(6)

References

Related documents