Timer Management Design Patterns

来源:百度文库 编辑:神马文学网 时间:2024/07/03 12:30:10

Timer Management Design Patterns

In this article we shall be covering different timer management designpatterns used in Real-time and Embedded system design.

The following timer management design patterns are used very frequently inReal-time systems:

  • Recovering from Message Loss
  • Recovering from Software Faults
  • Sequencing Operations
  • Polling
  • Periodic Operations
  • Failure Detection
  • Collecting Messages
  • Inactivity Detection

Recovering from Message Loss

Usually a timer is kept while awaiting for a message. If the message isreceived, timer is stopped. If the timer expires, message loss is registered. Insuch a case, a retry logic is implemented by restarting the timer and awaitingfor the message again. If the number of retries reaches a threshold, theactivity is aborted and appropriate recovery action is initiated.

Recovering from Software Faults

Whenever a feature is initiated, a feature wide timer is kept to ensurefeature success. If some software or hardware module involved in the featurehits recovery, the feature will fail and the timer expiry will be the onlymethod to detect the feature failure. On expiry of the feature wide timer, thefeature may be reinitiated or recovery action might be taken.

It is a good design practice to keep at least one timer active during theexecution of a feature. The timer guards the system against unforeseen failureconditions.

Sequencing Operations

Timers are used for sequencing time based state transitions. Consider thetraffic light controller where after each light operation, the controller has towait for some defined amount of time. For example, timers can manage thetransition between green, yellow and red. When a timer expires, the trafficlight is moved to its next logical condition and a timer is started for the nexttransition. 

Polling

In most systems, events are reported via messages. But sometimes it may notbe practical to report the occurrence of an event via a message. So a timer iskept and the system polls for that condition on every timeout.

Consider the implementation of a congestion control system. The software runsa periodic congestion polling timer that polls for the CPU utilization and othercongestion triggers. When the CPU utilizations reaches a threshold, thecongestion control action is taken.

Periodic Operations

For implementing audits, periodic timers are kept. On each timer expiry,software audit is initiated. Another example where periodic timers are usedcould be implementing periodic billing of calls in telecom systems. When thecall enters conversation, the periodic timer is started. On every timeout, thesubscriber meter is incremented.

Failure Detection

For monitoring the health of other modules, a module runs a timer. It expectsa sanity punch message periodically from all the other modules before the expiryof the timer. If certain number of sanity punches are missed in succession froma module, module failure is declared as failed.

Collecting Messages

Many times timers are used to collect messages. For example, in the digitcollection procedure for a call, the system restarts a timer each time a digitmessage is received. The end of dialing is either received in the message or thetimer expiry indicates it. No timer is started after the end of dialing isdetected. Partial dialing is reported if the end of dialing is detected beforethe receipt of minimum number of digits required to route the call

Inactivity Detection

Timers are also used for detecting the inactivity in a session. Consider thecase of a user session on the internet. Each time there is any kind of action bythe user, the inactivity timer is restarted by the ISP. If the timer expires,the ISP terminates the user session and the internet connection is lost.