gethrtime() is returning negative value on LINUX



hi
we had implemented gethrtime on LINUX machine using the following
code:
long long gethrtime(void)
{

// Try to get the cpu frequency by reading
// /proc/cpuinfo. Look for field "cpu Mhz".
FILE *cpuInfo = fopen ("/proc/cpuinfo", "r");
if (cpuInfo != NULL)
{
char buf[256];
double mhertz = 0;
while (fgets(buf, sizeof(buf), cpuInfo))
{
if (sscanf(buf, "cpu MHz : %lf\n", &mhertz) ==
1)
{
scaleFactor = (int)(mhertz + 0.5);
printf("mhertz = %lf, scaleFactor = %d
\n", mhertz, scaleFactor);
long long now;
asm volatile ("rdtsc" : "=A" (now) : :
"memory");
now = (now*1000)/scaleFactor;
return now;
}
}
}
}
Now on our customer setup this function starts returning negative
value after sometime i.e after couple of days.
from the logs we can find the scale factor to be 3060 and the returned
value -2940642805558051. What could be the reason of this negative
value? Though the system was up only for 40 days.
regards,
rishabh

.