Using Fine Granularity Timer Services and Structures

The talloc, tstart, tstop, and tfree services provide fine-resolution timing functions.

The talloc, tstart, tstop, and tfree timer services should be used when the following conditions are required:

  • Timing requests for less than one second
  • Critical timing
  • Absolute timing

A kernel extension uses the talloc service to allocate a timer request block (struct trb). The kernel extension initializes the fields in the trb structure to specify the timer completion function, when the function is to receive control, and how the function is to receive control. The tstart service is used to schedule the timer event. The timer completion handler is called when the specified time is reached. The address of the timer request block is passed to the completion handler function. The timer completion handler can initialize and reschedule the timer request block using the tstart service. The tstop service is used to cancel a pending timer request. The tfree service is used to return a previously allocated timer request block to the system. Be sure that the trb structure is not active when it is freed by the tstop service.

Use the talloc service to allocate a timer request block. Do not allocate your own memory to contain timer request blocks.

Do not access or modify any fields of the trb structure between the time when a timer request block is started by the tstart service and the time when the completion handler runs, or a call to the tstop service is completed against the timer request block.

If you use the tstart service in the completion handler to reschedule the timer request block that was passed to the completion handler, be sure to initialize the t->timeout field and the appropriate T_INCTERVAL, T_ABSOLUTE, and T_LOWRES bits in the t->flags field. Use an OR operation to set the t->flags bits because the AIX® kernel timer service is using other bits in the t->flags field when the completion handler is called.

The AIX® kernel timer service accesses the timer request block that was passed to the completion handler after the completion handler returned. A race condition might occur if a completion handler makes the timer request block that was passed to the completion handler available for the reuse by another processor. A system outage might occur if the other processor uses the tstart service to reschedule the timer request block before the AIX® kernel timer service has completed its access to the block. The other processor can avoid the system outage using the tstop service to ensure that the timer request block is stopped before using the tstart service to reschedule the timer request block.

Note:
  1. If a timer request block is rescheduled anywhere other than its completion handler, use the tstop service to ensure that the timer request block is not scheduled or running in its completion handler. Failure to do so might result in a system outage.
  2. Use the tstop service against the timer request block before calling the tstart service if a timer request block is restarted using the tstart service anywhere other than its completion handler. Failure to do so can result in system stops.
  3. Always use the tstop service to cancel a timer request before calling the tfree service. This is necessary to ensure that the timer request block is not on a system timer queue, running the completion handler, or returning to the system from a completion handler when the timer request block is freed. Failure to do so might result in a system outage.

Do not use the tfree service in a timer completion handler to free the timer request block that was passed to the completion handler.

The Watchdog timer services can be used for noncritical times having a one-second resolution. The timeout service can be used for noncritical times having a clock-tick resolution.