Subject: port-i386/11432: microtime running backwards early in boot
To: None <>
From: Lennart Augustsson <>
List: netbsd-bugs
Date: 11/06/2000 14:10:26
>Number:         11432
>Category:       port-i386
>Synopsis:       microtime running backwards early in boot
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    port-i386-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 06 14:10:01 PST 2000
>Originator:     Lennart Augustsson
>Release:        NetBSD-current 2000-11-06
System: NetBSD glissando 1.5I NetBSD 1.5I (GLISSANDO) #2: Mon Nov 6 16:52:48 EST 2000 augustss@glissando:/usr/src/sys/arch/i386/compile/GLISSANDO i386

	Sometimes when you boot a kernel with a pchb with a random number
	generator (82815 in my case) it prints a negative number for
	Kb/s generated.  The reason is that a later microtime() produces
	a value which a less than an earlier microtime().

	With a few printfs insert this can be observed:
pchb0: Intel 82815 Hub (rev. 0x02)
tv2 0,16186  tv1 0,18801
tv1 -1,997385
tv1 -1,-2615  -3059
pchb0: random number generator enabled, -3059Kb/s

	Here's the code I used:

			for (i = 0; i < 8192; i++) {
				while ((bus_space_read_1(sc->sc_st, sc->sc_sh,
				    I82802_RNG_RNGST) &
				    I82802_RNG_RNGST_DATAV) == 0)
					/* spin */;
				(void) bus_space_read_1(sc->sc_st, sc->sc_sh,


printf("tv2 %ld,%ld  tv1 %ld,%ld\n", tv2.tv_sec, tv2.tv_usec, tv1.tv_sec, tv1.tv_usec);
			timersub(&tv2, &tv1, &tv1);
printf("tv1 %ld,%ld\n", tv1.tv_sec, tv1.tv_usec);
			if (tv1.tv_sec)
				tv1.tv_usec +=
				    1000000 * tv1.tv_sec;
printf("tv1 %ld,%ld  %ld\n", tv1.tv_sec, tv1.tv_usec, 8 * 1000000 / tv1.tv_usec);
			printf("%s: random number generator enabled, %ldKb/s\n",
			    sc->sc_dev.dv_xname, 8 * 1000000 / tv1.tv_usec);

	Reboot a few times and observe the value.
	I don't know.  Perhaps some initialization is needed to make
	microtime() behave.