Corrected gettimeofday() test code

From: Kris Kennaway <kris_at_obsecurity.org>
Date: Sat, 29 Nov 2003 15:07:14 -0800
I forwarded the reports of timecounter problems to phk, and he asked
that people who are seeing timecounter problems provide FULL details
of their system configuration, including:

* dmesg

* kernel configuration

* compiler options

* time-related system configuration (whether ntpd/timed/ntpdate is
running, and if so whether it's correcting for a seriously drifting
clock)

* The kernel timecounter configuration, e.g. the
kern.timecounter.method and kern.timecounter.hardware sysctls, and
whether changing them has any effect.

* The exact output of the corrected test program below (the original
would give spurious errors if it didn't run at least once a second,
which may have been confusing some people if their systems were
sufficiently loaded).

* The system status when the problem is observed (i.e. does it only
occur under load; what else is running at the time)

It's hard to track down this kind of problem when people don't provide
this level of detail, and half-reports just confuse the issue.

Thanks,

Kris

----- Forwarded message from Poul-Henning Kamp <phk_at_phk.freebsd.dk> -----

X-Original-To: kkenn_at_localhost
Delivered-To: kkenn_at_localhost.obsecurity.org
Delivered-To: kris_at_freebsd.org
Date: Sat, 29 Nov 2003 23:48:12 +0100
From: Poul-Henning Kamp <phk_at_phk.freebsd.dk>
Subject: Re: gettimeofday() test code
In-reply-to: "Your message of Sat, 29 Nov 2003 14:21:24 PST."
 <20031129222124.GA10022_at_xor.obsecurity.org>
To: Kris Kennaway <kris_at_obsecurity.org>
X-UIDL: 1f9b02cde6c0ab3cc62d0309b681fcc3
X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.15.7


Have them run this one instead...

#include <stdio.h>
#include <sys/time.h>

int
main()
{
	struct timeval prevtime;
	struct timeval curtime;
	double last, now;

	gettimeofday(&prevtime, NULL);
	last = prevtime.tv_sec + prevtime.tv_usec * 1e-6;

	for (;;)
	{
		gettimeofday(&curtime, NULL);
		now = curtime.tv_sec + curtime.tv_usec * 1e-6;

		if (now < last) {
			printf("%f %f %d.%06d %d.%06d\n", now, last,
			    curtime.tv_sec, curtime.tv_usec,
			    prevtime.tv_sec, prevtime.tv_usec);
		}
		last = now;
		prevtime = curtime;
	}

	return 0;
}

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk_at_FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.

----- End forwarded message -----

Received on Sat Nov 29 2003 - 14:07:17 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:31 UTC