wolfcw / libfaketime

libfaketime modifies the system time for a single application
https://github.com/wolfcw/libfaketime
GNU General Public License v2.0
2.64k stars 321 forks source link

Using libfaketime to change guest O/S time on QEMU: x86_64 vs arm64 #414

Open RobertHenry6bev opened 1 year ago

RobertHenry6bev commented 1 year ago

I am running QEMU on top of libfaketime so that the QEMU guest O/S perceives time (guest instructions per real time clock) at the same rate as the guest would on real hardware. In my case, QEMU is tracing instructions, and time scales by ~200. This software composition mostly works, assuming the guest O/S doesn't network off to some ntp server.

For host=x86-64+ubuntu 22.04, guest=arm64+ubuntu 22.04, libfaketime correctly translates and scales.

For host=arm64+ubuntu 22.04, guest=arm64+ubuntu 22.04, libfaketime correctly translates time, but does not scale it.

I believe everything is identical between the different host platforms: the version of QEMU, the invocation of QEMU, the bios.

Has anybody else experienced this kind of behavior?

The libfaketime test suite passes on both hosts.

My own test program also passes on both hosts. My test program is (it prints out the real time and the faketime on the same line, so you can see translation and dilation)

(export LD_PRELOAD=${LIB_FAKETIME}; export FAKETIME="+20d x0.05"; sh -c "while true ; do echo -n ' XXX ' ; /usr/bin/date ; /usr/bin/sleep 1 ; done") | /usr/bin/ts
RobertHenry6bev commented 1 year ago

If I change all symbols __ARM_ARCH in libfaketime.c to be FOO_ARM_ARCH then using libfaketime on an ARMv8 (aarch64) processor running modern ubuntu 22.04 linux, then libfaketime behaves identically as running on legacy amd64 (aka x86_64).

I don't know what bug the ifdefs are trying to compensate for, or if it is only relevant to legacy ARMv7, or ...