I am using an the AM3359 processor and we see a jump of roughly 36 hours at least once a week. We are using 3.2.0 Linux with the build from linux-3.2.0-psp04.06.00.11. I have seen the post on
https://groups.google.com/forum/#!topic/beagleboard/PLIroG3SVOU
where a jump of 2^17 seconds is discussed with the dmtimer and a patch for 3.2. I verified that the patch posted by Vaibhav Hiremath was the code that we have running but we are still seeing the jump in time. I have checked the timer and it is running at 32kHz.
root@am335x-evm:/# grep -i clock /var/log/messages
Apr 22 15:28:24 am335x-evm user.info kernel: [ 0.000000] OMAP clockevent source: GPTIMER2 at 24000000 Hz
Apr 22 15:28:24 am335x-evm user.info kernel: [ 0.000000] OMAP clocksource: GPTIMER1 at 32768 Hz
Apr 22 15:28:24 am335x-evm user.info kernel: [ 0.000000] sched_clock: 32 bits at 32kHz, resolution 30517ns, wraps every 131071999ms
Apr 22 15:28:24 am335x-evm user.info kernel: [ 0.138671] Switching to clocksource gp timer
Apr 22 15:28:24 am335x-evm user.info kernel: [ 1.338287] clock: disabling unused clocks to save power
Apr 22 15:28:24 am335x-evm user.info kernel: [ 1.483184] omap_rtc am33xx-rtc: setting system clock to 2015-04-22 15:28:13 UTC (1429716493)
root@am335x-evm:/# grep -i timer /var/log/messages
Apr 22 15:28:24 am335x-evm user.info kernel: [ 0.000000] OMAP clockevent source: GPTIMER2 at 24000000 Hz
Apr 22 15:28:24 am335x-evm user.info kernel: [ 0.000000] OMAP clocksource: GPTIMER1 at 32768 Hz
Apr 22 15:28:24 am335x-evm user.info kernel: [ 0.138671] Switching to clocksource gp timer
Apr 22 15:28:24 am335x-evm user.info kernel: [ 1.082641] OMAP Watchdog Timer Rev 0x01: initial timeout 60 sec
Apr 22 15:28:24 am335x-evm user.info kernel: [ 1.215393] oprofile: using timer interrupt.
What needs to be done to keep the CLOCK_MONOTONIC from jumping? We already have an investment in time in the release we are using.
Here is a copy of the code that shows the jump.
#include <iostream>
#include <unistd.h>
#include <signal.h>
#include <termios.h>
#include <cerrno>
#include <string>
#include <algorithm>
#include "MsTimer.h"
#include <time.h>
#include <stdio.h>
#include <sys/sysinfo.h>
namespace CONST {
const char Application[] = "TimerChk";
const char Version[] = "0.0.2";
const char BuiltOn[] = __DATE__ " " __TIME__ ;
}
int main (int argc, char *argv[]) {
bool bDone = false;
time_t rawtime, oldrawtime;
uint32_t monotime, oldmonotime;
uint32_t oldinfotime;
uint32_t oldrealtime;
uint32_t oldrawmono;
struct timespec realtime, rawmono;
struct sysinfo info;
{
struct timespec monotimesample, realtimesample;
clock_getres(CLOCK_REALTIME, &realtimesample);
clock_getres(CLOCK_MONOTONIC, &monotimesample);
std::cerr << "Real Time data: sec " << realtimesample.tv_sec << " nsec " << realtimesample.tv_nsec;
std::cerr << " Mono Time data: sec " << monotimesample.tv_sec << " nsec " << monotimesample.tv_nsec;
std::cerr << std::endl << std::endl;
}
sysinfo(&info);
clock_gettime(CLOCK_REALTIME, &realtime);
clock_gettime(CLOCK_MONOTONIC_RAW, &rawmono);
oldrawmono = rawmono.tv_sec;
oldrealtime = realtime.tv_sec;
oldinfotime = info.uptime;
std::cerr << "Raw Monotonic, Up Time, Monotonic Timer, Real-Time timer, time Timer" << std::endl;
time(&oldrawtime);
oldmonotime = SecTimer();
while (!bDone)
{
time(&rawtime);
monotime = SecTimer();
sysinfo(&info);
clock_gettime(CLOCK_REALTIME, &realtime);
clock_gettime(CLOCK_MONOTONIC_RAW, &rawmono);
if ((abs(monotime - oldmonotime) > 2) || (abs(rawtime - oldrawtime) > 2) ||
(abs(info.uptime - oldinfotime) > 2) || (abs(realtime.tv_sec - oldrealtime) > 2) || (abs(rawmono.tv_sec - oldrawmono) > 2))
{
bDone = true;
}
oldmonotime = monotime;
oldrawtime = rawtime;
oldrawmono = rawmono.tv_sec;
oldrealtime = realtime.tv_sec;
oldinfotime = info.uptime;
std::cerr << rawmono.tv_sec << ", " << info.uptime << ", " << monotime << ", " <<
realtime.tv_sec << ", " << rawtime << ", " << ctime(&rawtime);
// printf("date: %s", ctime(&rawtime));
sleep(1);
}
return 0;
}