[Olsr-users] Broadcast Packets & Windows Routin
Thu Mar 13 19:53:40 CET 2008
On Mar 13, 2008, at 7:02 PM, Juliusz Chroboczek wrote:
>>> According to the man page of select(2):
>>> "The select function may update the timeout parameter to indicate
>>> how much time was left."
>>> What worries me here is the word "may". It would be quite useful
>>> to know the time left. But that is a worry for the implementor.
> No, don't do that, it's not portable and error-prone. Just call
> gettimeofday before and after select, and subtract the two.
> (If you *really* want to be correct, call clock_gettime
> but that's not portable.)
I would throw in the following neat trick which only works on totally
non-portable pentium 3 minimum systems:
(But you do get true nanosec resolution)
#define CPUFREQ 22113730000 /* 2.2 GHz */
#define kHz 1000ULL
#define MHz kHz*1000ULL
#define GHz MHz*1000ULL
static inline unsigned long long read_tsc(void)
unsigned long high, low;
__asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high));
return ((unsigned long long)high << 32) | low;
int main(int argc, char **argv)
unsigned long long t1,t2;
unsigned long long t3;
long double d;
t3 = t2-t1;
d = (long double)t3/(long double)CPUFREQ;
printf("%Lf (sec), %Lf (ms), %Lf (usec), %Lf (nsec)\n", d,
d*kHz, d*MHz, d*GHz);
Take that swiss watchmakers ;-))))
>> BTW the select(2) sys-call is dying out and now sometimes just a
>> (e.g. in the GNU-libc) function of poll(2).
> I believe you are wrong. Select is a native system call (it doesn't
> call poll) on both Linux and BSD-derived systems.
More information about the Olsr-users