Skip to content

ptimer period sporadically too long

Host environment

  • Operating system: EndeavourOS
  • OS/kernel version: Linux 6.11.5-arch1-1 #1 SMP PREEMPT_DYNAMIC
  • Architecture: x86
  • QEMU flavor: qemu-system-x86_64
  • QEMU version: 9.1.0 (v9.1.0-27-g154e0ea1fe-dirty) // custom device added
    also tested on newest master: 9.1.50 (v9.1.0-1039-g14185e5e1a-dirty)
  • QEMU command line:
qemu-system-x86_64
        -no-reboot \
	-nodefaults \
	-nographic \
	-vga std \
	-boot order=c \
	-m 2048 \
	-machine pc \
	-cpu max \
	-smp 1 \
	-d guest_errors \
	-serial stdio \
	-rtc base=1970-01-01,clock=vm \
	-device ahci,id=ahci -drive id=disk,file=$IMAGE,format=raw,if=none -device ide-hd,drive=disk,bus=ahci.0 \
        -device customdevice \
	-chardev custom-chardev,id=c0 \
	-serial chardev:c0 \
	-icount shift=0,align=off,sleep=off

Emulated/Virtualized environment

  • Operating system: Linux
  • OS/kernel version: 5.4.255-xenomai-3.2.3
  • Architecture: x86

Description of problem

A ptimer in a custom device with a frequency of 10kHz is sporadically called after more than 100,000ns in virtual time have elapsed.

With a icount shift of 4 or 5 this happens almost everytime before the linux guest can even finish booting.

With a shift of 0 this happens very rarely, but it does occur from time to time.

Steps to reproduce

  1. setup a ptimer with a frequency of 10kHz and assert that the time passed between callbacks is exactly 100,000ns
  2. run
  3. wait for boom

Additional information

// Timer setup
ptimer_transaction_begin(state->timer);

ptimer_set_freq(state->timer, 10000);
ptimer_run(state->timer, 0);
   
ptimer_transaction_commit(state->timer);
// timer callback
int64_t now  = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
static int64_t last = 0;
if (last > 0)
{
   if (now - last != 100000)
   {
       fprintf(stderr, "error tick %ld after %ld is incorrect: %ld\n", now, last, now - last);
       assert(0);
   }
}
last = now;
error tick 47867503135 after 47867400000 is incorrect: 103135
qemu-system-x86_64: ../...file.c:119: timer_callback: Assertion `0' failed.
Edited by FabianLippoldZR
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information