Skip to content

tests/posix/timer.test_timer fails on nrf51_pca10028 #7891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
inakypg opened this issue May 24, 2018 · 3 comments
Closed

tests/posix/timer.test_timer fails on nrf51_pca10028 #7891

inakypg opened this issue May 24, 2018 · 3 comments
Assignees
Labels
area: ARM ARM (32-bit) Architecture bug The issue is a bug, or the PR is fixing a bug platform: nRF Nordic nRFx priority: medium Medium impact/importance bug

Comments

@inakypg
Copy link
Contributor

inakypg commented May 24, 2018

commit 4e8438b

***** delaying boot 1000ms (per build configuration) *****
***** Booting Zephyr OS 1.12.0-rc1 (delayed boot 1000ms) *****
Running test suite test_posix_timer
===================================================================
starting test - test_timer
POSIX timer test
Timer fires every 0 secs and  100000000 nsecs
Time remaining to fire 0 secs and  890000000 nsecs
Handler Signal value :20 for 1 times
Handler Signal value :20 for 2 times
Handler Signal value :20 for 3 times
Handler Signal value :20 for 4 times
Handler Signal value :20 for 5 times
Handler Signal value :20 for 6 times
Handler Signal value :20 for 7 times
Handler Signal value :20 for 8 times
Handler Signal value :20 for 9 times
Handler Signal value :20 for 10 times
Handler Signal value :20 for 11 times
Handler Signal value :20 for 12 times

    Assertion failed at tests/posix/timer/src/posix_timer.c:87: test_timer: (total_secs_timer not equal to secs_elapsed)
POSIX timer test has failed
FAIL - test_timer
===================================================================
===================================================================
RunID: ci-180524-0741-1662:knj5
PROJECT EXECUTION FAILED
@inakypg inakypg added bug The issue is a bug, or the PR is fixing a bug platform: nRF Nordic nRFx area: ARM ARM (32-bit) Architecture labels May 24, 2018
@nashif nashif added the priority: medium Medium impact/importance bug label May 24, 2018
@nashif nashif assigned pizi-nordic and unassigned carlescufi and anangl May 29, 2018
@pizi-nordic
Copy link
Collaborator

pizi-nordic commented May 30, 2018

Hi.

It looks that the problem is here:

int clock_gettime(clockid_t clock_id, struct timespec *ts)
    s64_t elapsed_msecs, elapsed_secs;
    s64_t elapsed_nsec, elapsed_cycles;

    if (clock_id != CLOCK_MONOTONIC) {
        errno = EINVAL;
        return -1;
    }

    elapsed_msecs = k_uptime_get();
    elapsed_secs = elapsed_msecs / MSEC_PER_SEC;

    elapsed_cycles = (s64_t) (k_cycle_get_32() %
                  sys_clock_hw_cycles_per_sec);
    elapsed_nsec = (s64_t) ((elapsed_cycles * NSEC_PER_SEC) /
                sys_clock_hw_cycles_per_sec);

    ts->tv_sec = (s32_t) elapsed_secs;
    ts->tv_nsec = (s32_t) elapsed_nsec;
    return 0;
}

As you see, the output of the function is calculated basing on 2 separate clock sources - the k_uptime_get() and k_cycle_get_32(). As result, the timestamp is not obtained in atomic way. There could be a timer interrupt between k_uptime_get() and k_cycle_get_32() which might result in dropping one second of time (elapsed_cycles will drop to zero but elapsed_secs will still hold old value). Disabling interrupts does not help much, as it only freezes time returned by k_uptime_get().

@nashif
Copy link
Member

nashif commented May 30, 2018

@ramakrishnapallala fyi

@nashif
Copy link
Member

nashif commented Jun 2, 2018

fixed by #8124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ARM ARM (32-bit) Architecture bug The issue is a bug, or the PR is fixing a bug platform: nRF Nordic nRFx priority: medium Medium impact/importance bug
Projects
None yet
Development

No branches or pull requests

5 participants