Skip to content

Dead code in aon_timer.c: aon_timer_enable_alarm function (the implementation for the powman timer) #3273

Open

Description

@NanoExplorer

ts_adjusted.tv_nsec += 999999;
if (ts_adjusted.tv_nsec > 1000000000) {
ts_adjusted.tv_nsec -= 1000000000;
ts_adjusted.tv_sec++;
}
if (ts_adjusted.tv_nsec) ts_adjusted.tv_sec++;
if (wakeup_from_low_power) {
powman_enable_alarm_wakeup_at_ms(timespec_to_ms(ts));

In the function for setting alarms using the POWMAN timer, the variable ts_adjusted is declared to (it appears) round the time up to the nearest ms*. But then the timer is set using the ts that was passed to the function originally, discarding the value of ts_adjusted.

*that isn't what would actually happen if ts_adjusted were used to set the alarm, but it looks to me like the intended behavior.

I'm happy to make a pull request that fixes this issue, but I'd like to know what the intended behavior is. Should the alarm time be rounded up to the nearest ms (appears to be the intended behavior), or rounded down to the nearest ms (appears to be the actual current behavior)?

Activity

  1. NanoExplorer commented on Oct 20, 2026

    @NanoExplorer
    Author

    If the intended behavior is to round down, I'd delete lines 128-133 and the declaration of ts_adjusted, and if the intended behavior is to round up I'd probably replace lines 128-133 with something like:

    if (ts_adjusted.tv_nsec % 1000000) ts_adjusted.tv_nsec += 1000000;

    That way if tv_nsec is an exact number of ms, the alarm will be set to exactly the time requested, but if not, the time will be incremented by 1 ms and then the trailing digits will be truncated by timespec_to_ms (for example if tv_nsec = 999999 it will be incremented to 1999999, and then later truncated to 1 ms)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions