gethrtime() is returning negative value on LINUX
- From: "linux_bp" <rishabh.garg@xxxxxxxxx>
- Date: 16 Mar 2007 23:19:30 -0700
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
.
- Follow-Ups:
- Re: gethrtime() is returning negative value on LINUX
- From: David Schwartz
- Re: gethrtime() is returning negative value on LINUX
- From: Douglas Wells
- Re: gethrtime() is returning negative value on LINUX
- Prev by Date: Re: help with huge memory consumption??
- Next by Date: Re: extracting initramfs
- Previous by thread: review chapter of new OS textbook, get book and acknowledgement
- Next by thread: Re: gethrtime() is returning negative value on LINUX
- Index(es):