Skip to content
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

System clock sometimes jumps back ~54secs (IDFGH-396) #2513

Closed
snoutmate opened this issue Oct 3, 2018 · 6 comments
Closed

System clock sometimes jumps back ~54secs (IDFGH-396) #2513

snoutmate opened this issue Oct 3, 2018 · 6 comments

Comments

@snoutmate
Copy link

Hello,

i noticed that the system clock (esp_timer_get_time()) on our app sometimes(1-2xhour) jumps back ~54 secs.
Looking through the esp-idf timer code, i see the rollover of the internal 32-bit usecs clock is around the same value, so my guess is rollover happens without all the rollover-handling code firing, though at a glance i don't understand how that could be the case.
I'm running on ESP32 with Unicore, with multiple threads. NTP is disabled. Happens on all master/v3.1/v3.0.
My sdkconfig: https://pastebin.com/6L4DcMiH

Main thread code:

...
typedef int64_t timestamp_t;
timestamp_t esp_timestamp = 0;
timestamp_t esp_timestamp_lastframe = 0;

for(;;) { // frame start
  esp_timestamp_lastframe = esp_timestamp;
  esp_timestamp = esp_timer_get_time();

  if (esp_timestamp < esp_timestamp_lastframe) {
    timestamp_t shift_us = esp_timestamp - esp_timestamp_lastframe;

    ESP_LOGE(TAG, "ESP system clock SHIFT: %lli usecs", shift_us);
  }

 ...

 vTaskDelay(20 / portTICK_PERIOD_MS);
}
/* not reached */

Output:
E (355905) Main: ESP system clock SHIFT: -53666211 usecs
...
E (815595) Main: ESP system clock SHIFT: -53666244 usecs

@Alvin1Zhang Alvin1Zhang changed the title System clock sometimes jumps back ~54secs [TW#26647] System clock sometimes jumps back ~54secs Oct 8, 2018
@snoutmate
Copy link
Author

As a followup, this seems to be happening only when the CPU is running at 160 or 240Mhz, not on 80. The investigation continues.

@NateBowen
Copy link

I'm experiencing the same thing on my application using v3.0-rc1, clocked at 160MHz. What's interesting is that there have been a number of commits to esp_timer_esp32.c since that version to address the overflow capture behavior.

I haven't been able to reproduce the time-shifting behavior. When it does happen, it will jump backwards, then increment as expected for 54 seconds, then jump back 54 seconds, then increment 54 seconds, etc.

@snoutmate You've seen the issue occur even on master?

@KonstantinKondrashov
Copy link
Collaborator

@snoutmate and @NateBowen thanks for reporting. Could you describe which also tasks are running at the time? Perhaps you have your frequent interruptions or something else (which peripherals are used). Please help me understand what happened.

Thanks.

@KonstantinKondrashov
Copy link
Collaborator

@NateBowen Do you also use CONFIG_FREERTOS_UNICORE=y mode? Could you provide your sdkconfig file?

@projectgus projectgus changed the title [TW#26647] System clock sometimes jumps back ~54secs System clock sometimes jumps back ~54secs (IDFGH-396) Mar 12, 2019
@Alvin1Zhang
Copy link
Collaborator

@NateBowen @snoutmate Hi, would you help share if any updates for this issue? Thanks.

@NateBowen
Copy link

We're no longer using the esp_timer library for our basic application clock, so I have no updates on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants