Programming & Compilers

How timer coalescing preserves permitted service windows

Compare permitted timer windows, grouped notifications and callback delays, then preserve fixed-origin or completion-relative recurrence rules.

By Republeq Editorial · 9 min read ·
Timer coalescing compares permitted service windows, common activation instants, strict timers, idle-event counts, callback-delay stages and fixed-origin versus completion-relative recurrence.

A requested timer instant and the application's permitted service window are different objects. If the application permits some postponement, several timers can sometimes share a service event without violating that timing contract.

timer coalescing uses those compatible windows to reduce distinct timer-triggered events. The policy must preserve the constrained event and selected recurrence rule while keeping service inside the granted window.

The examples use hypothetical time units and explicit event boundaries. They do not describe civil-time rules, clock accuracy or a measured battery-life benefit.

Translate timer slack into acceptable windows

Define a model in which a timer's requested instant is its earliest permitted service time. Its declared slack is the permitted additional delay. No early service is allowed in this model.

Timer A requests time ten with slack three, so its window is [10,13]. Timer B requests twelve with slack two, giving [12,14]. Timer C requests sixteen with slack one, giving [16,17]. Endpoints are included.

Service here means the timer system delivers the specified activation notification. The application callback can execute later under a separate scheduling contract. If an application instead requires the callback itself by a deadline, its coalescing policy must account for that stronger requirement.

A strict timer has slack zero. For a timer requested at ten, its acceptable service set is the single instant ten under this stipulated model.

The cancellation-safety guide supplies an event-boundary comparison for timer slack. It records a requested interruption separately from the point where it is honored, resource cleanup and any committed effect. The timer model likewise needs the particular constrained event named: notification at twelve does not establish callback execution at twelve. The cancellation guide defines no timer window or callback deadline; its separate-stage record helps avoid assigning a result to the wrong event.

The application must grant the postponement permission. A system cannot infer three units of slack merely because an observed workload happened to tolerate that delay.

Find an instant common to every grouped window

A and B can share service at twelve because twelve belongs to both [10,13] and [12,14]. A is delayed by two units from its request, while B is served at its requested instant. C cannot join that event at twelve because its earliest permitted time is sixteen. Serving it early would violate the model just as postponing A beyond thirteen would.

The latest of the grouped earliest times must be no greater than the earliest of their latest times. That common interval identifies permitted shared instants. Without a common point, one event cannot satisfy the whole group.

For A and B, the common interval is [12,13]. The policy can choose an instant within it under its rules. Choosing fourteen because B permits it would still violate A's latest time thirteen.

Now consider three windows [10,13], [12,14] and [14,16]. Adjacent pairs overlap, but the intersection of all three is empty. A chain of overlapping pairs does not establish one event suitable for the complete group.

Every grouped member must accept the chosen service instant. A successful service for one timer is not a receipt for its neighbours' timing requirements.

Count idle wakeups under an explicit activity assumption

For A, B and C alone, their separate preferred instants are ten, twelve and sixteen. The grouped schedule uses twelve for A and B and sixteen for C, reducing distinct service instants from three to two.

To call those idle wakeups, stipulate that the processor is otherwise idle at each event and the timer work finishes before the next event. Under that activity model, each distinct service batch causes one timer-triggered wakeup.

The interval before the first timer event can then last until twelve rather than ten. Combining the permitted work creates an opportunity for a longer uninterrupted idle period under these assumptions.

Other events can still wake the system, and a processor already executing work does not need another idle exit just because a timer becomes due. The service-instant count is not automatically the total number of physical wakeups.

The moving-garbage-collection guide adds a callback-resource comparison for idle wakeups. Its pin must cover the external component's actual final raw-address use, and a later use after release is uncovered. If a deferred callback uses such a resource, its protection must cover the callback's actual permitted use interval, not end merely because a nominal timer instant passed. That lifetime condition remains separate from counting grouped notifications or physical idle exits. The peer supplies no wakeup or energy formula.

No energy percentage follows from two events instead of three. Idle-state behaviour, handler work and other activity require their own observations before making a device-specific power claim.

Compare strict and deferrable requests on the same sequence

Replace A's slack three with slack zero while keeping its requested instant ten. B still has [12,14], and C still has [16,17]. The strict A window [10,10] does not intersect B's.

The system can no longer combine A and B at twelve. Serving both at ten would violate B's no-early-service rule. Under these three requests, the illustrative schedule retains separate events.

The changed permission window explains the different grouping result. An implementation reporting the same two-event grouping after making A strict would fail the stated timing contract.

A mixture of strict and deferrable timers can still contain compatible groups elsewhere. The policy should test actual intervals rather than assume one strict request forbids all grouping.

The deadline comparison also needs the requested stage. If A is strict about notification at ten but its callback is merely queued at ten, that is not evidence of callback execution at ten.

Separate intentional postponement from scheduling residence

Return to deferrable A served at twelve. It intentionally waits two units under its [10,13] activation contract. Suppose its activated task then waits for execution and begins the callback at fifteen.

The callback's five-unit distance from requested ten has two components: two units of permitted timer postponement and three units after activation. Assigning all five to the coalescer would describe the wrong boundary. The timer service at twelve fits the activation window. Whether callback start fifteen is acceptable depends on the application's separate execution requirement. The first passing window check cannot answer that second question.

Service fourteen misses A's latest activation time thirteen even if the callback runs immediately afterward. The timing record must retain both the window and the event it constrains.

For a callback deadline, the admission or policy analysis must include the allowed downstream delay and work. It cannot silently redefine the deadline as notification time merely to make grouping appear valid.

Fixed-origin recurrence preserves its nominal phase

Use a separate recurrence history with origin zero, period ten and slack three. Its first windows are [10,13], [20,23] and [30,33]. They come from the fixed origin and period.

Suppose the first activation occurs at twelve and its work completes at fourteen. The next requested instant remains twenty under this recurrence rule, not twenty-four.

If the second activation occurs at twenty-three, the third requested instant still remains thirty. Permitted postponement of an occurrence does not automatically shift the later fixed-origin requests.

The recurrence contract also needs rules for an occurrence whose work overlaps a later one. The example does not invent catch-up, omission or overlapping-execution policies. Those choices must be specified rather than inferred from the word recurring.

Completion-relative recurrence follows a different anchor

Now use a recurrence rule that schedules the next requested instant ten units after the previous operation completes. Keep the first activation at twelve and completion at fourteen.

The next request is twenty-four, with window [24,27] under the same slack three. If that occurrence activates at twenty-seven and completes at twenty-nine, the next request is thirty-nine. Completion supplies this rule's next anchor. Its timing is different even though both timers use period ten and each occurrence respects three units of slack.

The selected recurrence anchor is part of the application's timing contract. Changing it changes future requested instants, so the coalescer must retain the caller's selected rule.

After the same first activation twelve and completion fourteen, the fixed-origin next request is twenty while the completion-relative request is twenty-four. That four-unit difference is a recurrence-policy difference, not evidence that either occurrence exceeded its three-unit slack. Comparing only the first activation would miss it.

The completion boundary also includes whatever work the recurrence rule defines. Scheduling from activation rather than completion would be a third policy, not an interchangeable interpretation.

Evaluate the tradeoff with the permitted error

For the three-timer example, preserve both the reduced event count and each timer's delay. A has delay two within allowed three, B has delay zero within allowed two, and C can use sixteen with delay zero.

Those observations establish the selected schedule's acceptability under the activation contract. They do not establish a general energy result or that every timer sequence offers a grouping opportunity.

A policy can compare fewer service events against the granted postponements. It should not reduce event count by discarding a timer or moving it beyond its latest instant unless the application explicitly permits that different outcome.

Check the future requested instants separately for each recurrence rule. A first occurrence inside its window can still be followed by an incorrect phase or wrong completion-relative anchor.

Verify windows and event boundaries before claiming improvement

Record each request, slack, acceptable service stage, chosen instant and recurrence rule. For every grouped event, check that the instant lies inside every member's window.

Keep timer activation, callback start and callback completion separately so scheduling residence does not become hidden coalescing error. If the requirement constrains a later stage, check that stage under its own bounds.

Place each closed service window beside the proposed shared instant on the Lenovo IdeaPad touchscreen laptop, listed with a 15.6-inch FHD display. Storage for saved timing records is listed as a 512GB PCIe SSD; the same entry identifies 16GB DDR4 and an i5-1334U processor. Record A[10,13], B[12,14] and service12 before counting one combined event. An instant accepted only by B does not settle A's obligation, and the equipment specification supplies no battery measurement.

Keep activation, callback start and completion in separate columns on the ASUS Vivobook 14 FHD laptop. The product description specifies 16GB DDR4 memory and a Core 5 120U processor. Record request10, activation12 and callback start15 for the delay example. In the separate recurrence history, record activation12 and completion14, then next request20 for fixed origin or24 for completion-relative scheduling. Those different records prevent a permitted first activation from certifying the wrong later anchor.

Timer coalescing: slack, wakeup grouping and recurrence