maxikrie commented on PR #22027:
URL: https://github.com/apache/nuttx/pull/22027#issuecomment-7022321443
Thanks for the detailed review. You're right about the invariant, so I'm
closing this PR.
Agreed:
- `expired <= now` has to stay. With this patch, an adjustment above the
best-case latency makes callbacks run early instead of costing extra
interrupts. There's a second problem: a timer due within the adjustment *after*
the one that raised the interrupt runs in the same pass without any latency of
its own, so it can run early even when the value is set correctly.
- "It has no effect" was too strong. Master works whenever the latency up to
the time read in the ISR is at least the adjustment. That's your virtualized
case: $t_{hyp}$ happens before $t_{gettime}$.
One point on the model. The gate compares the deadline with `now` as read at
$t_{gettime}$, not with the callback time. On master, the early interrupt is
therefore only useful when $t_{hyp} + t_{ctxsave} + t_{dispatch} \ge t_{adj}$:
the latency up to the clock read, not up to the callback. On bare metal that
part is short. On the H753 the ISR reads the same tick the alarm was armed for
(trace in the description), and even an adjustment of 2 µs (about the measured
ISR-to-callback latency) finds nothing due on the early interrupt. But in that
regime master doesn't cost "a few extra interrupts". The re-arm target `expired
- adj` has already passed, so the alarm fires back to back until the deadline:
2 wasted interrupts for one `usleep(100)` at 7000 ns in the trace, and more
with a larger adjustment or a shorter ISR.
I measured this again on the H753 (alarm mode, 1 µs tick, `-O2`, 200 ×
`usleep()`, average overshoot):
| `CONFIG_TIMER_ADJUST_NSEC` | timer interrupts per `usleep(100)` |
overshoot |
|---|---|---|
| 0 | 1 | +8 µs |
| 2000 | 2 | +10 µs |
| 7000 | 3 | +8 µs |
So on this kind of target the right value is 0, and the option's help text
could say so: the value must not exceed the latency from the timer interrupt to
the time read in the ISR. A larger value only adds interrupts. Happy to send
that as a doc-only change if it helps.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]