Hi,
Working on lang/rust on arm64, I experiment rustc panic due to not
monotonic timestamp. I tried to reproduce the problem in plain C.
My test program is just a loop of calling
clock_gettime(CLOCK_MONOTONIC), and it checks if the result is monotonic
(by comparing with previous value).
On amd64, it seems to work well, but on arm64 it fails quickly.
$ cat monotonic.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void
ts_abort(struct timespec *ts0, struct timespec *ts1)
{
printf("ts0=(%llu,%lu)\nts1=(%llu,%lu)\n",
ts0->tv_sec, ts0->tv_nsec,
ts1->tv_sec, ts1->tv_nsec);
abort();
}
int
main(int argc, char *argv[])
{
struct timespec ts0, ts1;
clock_gettime(CLOCK_MONOTONIC, &ts0);
for(;;) {
clock_gettime(CLOCK_MONOTONIC, &ts1);
if ((ts0.tv_sec < ts1.tv_sec) ||
((ts0.tv_sec == ts1.tv_sec) &&
(ts0.tv_nsec < ts1.tv_nsec))) {
ts0.tv_sec = ts1.tv_sec;
ts0.tv_nsec = ts1.tv_nsec;
} else
ts_abort(&ts0, &ts1);
}
}
$ cc -g -Wall monotonic.c
$ time ./a.out
ts0=(485220,477812476)
ts1=(485220,477728098)
Abort trap (core dumped)
ts0 should be <= ts1 if the result was monotonic.
dmesg below.
Thanks.
--
Sebastien Marie
OpenBSD 6.3-current (GENERIC) #281: Sat May 12 13:30:59 MDT 2018
[email protected]:/usr/src/sys/arch/arm64/compile/GENERIC
real mem = 2021466112 (1927MB)
avail mem = 1927958528 (1838MB)
mainbus0 at root: Pine64+
cpu0 at mainbus0 mpidr 0: ARM Cortex-A53 r0p4
efi0 at mainbus0: UEFI 2.7
efi0: Das U-Boot rev 0x0
psci0 at mainbus0: PSCI 0.2
agtimer0 at mainbus0: tick rate 24000 KHz
simplebus0 at mainbus0: "soc"
sxiccmu0 at simplebus0
sxipio0 at simplebus0: 103 pins
ampintc0 at simplebus0 nirq 224, ncpu 4: "interrupt-controller"
sxiccmu1 at simplebus0
sxipio1 at simplebus0: 13 pins
sximmc0 at simplebus0
sdmmc0 at sximmc0: 4-bit, sd high-speed, mmc high-speed, dma
ehci0 at simplebus0
usb0 at ehci0: USB revision 2.0
uhub0 at usb0 configuration 1 interface 0 "Generic EHCI root hub" rev 2.00/1.00
addr 1
com0 at simplebus0: ns16550, no working fifo
com0: console
sxitwi0 at simplebus0
iic0 at sxitwi0
sxirtc0 at simplebus0
dwxe0 at simplebus0: address 02:ba:b0:1b:de:88
rgephy0 at dwxe0 phy 0: RTL8169S/8110S/8211 PHY, rev. 5
rgephy1 at dwxe0 phy 1: RTL8169S/8110S/8211 PHY, rev. 5
gpio0 at sxipio0: 32 pins
gpio1 at sxipio0: 32 pins
gpio2 at sxipio0: 32 pins
gpio3 at sxipio0: 32 pins
gpio4 at sxipio0: 32 pins
gpio5 at sxipio0: 32 pins
gpio6 at sxipio0: 32 pins
gpio7 at sxipio0: 32 pins
gpio8 at sxipio1: 32 pins
scsibus0 at sdmmc0: 2 targets, initiator 0
sd0 at scsibus0 targ 1 lun 0: <SD/MMC, USD00, 0010> SCSI2 0/direct removable
sd0: 15080MB, 512 bytes/sector, 30883840 sectors
vscsi0 at root
scsibus1 at vscsi0: 256 targets
softraid0 at root
scsibus2 at softraid0: 256 targets
bootfile: sd0a:/bsd
boot device: sd0
root on sd0a (058b644e509a3f31.a) swap on sd0b dump on sd0b