All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eugene Huang <eugeneh@nvidia.com>
To: Marc Zyngier <maz@kernel.org>
Cc: "kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>
Subject: RE: Timer delays in VM
Date: Tue, 1 Mar 2022 19:03:33 +0000	[thread overview]
Message-ID: <BYAPR12MB3192EFEBABB1B31D9751C931D9029@BYAPR12MB3192.namprd12.prod.outlook.com> (raw)
In-Reply-To: <667c9f084b2d38725369de60daef6d58@misterjones.org>

Thanks Marc for the reply. Please see inline below marked with [EH].

> -----Original Message-----
> From: Marc Zyngier <maz@kernel.org>
> Sent: Monday, February 28, 2022 1:03 PM
> To: Eugene Huang <eugeneh@nvidia.com>
> Cc: kvmarm@lists.cs.columbia.edu
> Subject: Re: Timer delays in VM
> 
> External email: Use caution opening links or attachments
> 
> 
> [Please don't send HTML email and stick to plain text]
> 
> On 2022-02-28 18:02, Eugene Huang wrote:
> > Hi,
> >
> > I am running qemu on an arm64 CentOS host. Inside a ubuntu VM, a
> 
> I assume that by this you mean QEMU as the VMM for a KVM guest, right?

[EH] Yes.

> 
> > process runs a timer created using timer_t:
> >
> > ev.sigev_notify_function = m_callback;
> >
> > …
> >
> > timer_create(CLOCK_MONOTONIC, &ev, &m_timer_t);
> >
> > This timer sometimes has significant delays. For example, the 50 ms
> > timer can have a callback delay of 100ms.
> >
> > I did a host kernel trace and see a lot of WFx kvm_exits, and  the
> > following events between kvm_exit and kvm_entry:
> >
> > kvm_exit
> >
> > kvm_wfx_arm64
> >
> > kvm_get_timer_map
> >
> > sched_switch
> >
> > kvm_timer_save_state
> >
> > kvm_timer_update_irq
> >
> > vgic_update_irq_pending
> >
> > kvm_timer_restore_state
> >
> > kvm_vcpu_wakeup
> >
> > kvm_arm_setup_debug
> >
> > kvm_arm_set_dreg32
> >
> > kvm_entry
> 
> All of this is perfectly normal (guest hits WFI from its idle loop, no interrupt is
> pending, trap to EL2, schedule out, schedule back in, reenter the guest).
> 
> >
> > I have the following questions:
> >
> >       * Why there are a lot WFx exits? Is the timer dependent on it?
> 
> That's most probably because your vcpu goes idle and execute WFI to Wait
> For an Interrupt. As no interrupt is pending, the vcpu exits so that the host
> can do something useful until it gets an interrupt that is targeted at the vcpu.
> On an idle VM, this probably happens 100s of times a second.
> 
> >       * Does this timer rely on kvm timer irq injection?
> 
> Yes. A timer interrupt is always injected in SW. But the timer interrupt can
> either come from the HW timer itself (the VM was running while the timer
> expired), or from a SW timer that KVM as setup if the guest was blocked on
> WFI.

<EH> Here for arm64, EL1Virtual Timer is used. EL1 Virtual Timer is a HW timer, correct?
There is an armvtimer implementation in QEMU 6.1+. Does this armvtimer make a difference?

> 
> >       * What can be any possible causes for the timer delay? Are there
> > some locking mechanisms which can cause the delay?
> 
> This completely depend on how loaded your host is, the respective priorities
> of the various processes, and a million of other things.
> This is no different from the same userspace running on the host.
> It also depends on the *guest* kernel, by the way.

<EH> Our guest kernel is 5.4. How is the *guest* kernel involved? Can you give an example? Do you have suggestions on the guest kernel version as well.

> 
> There are of course locks all over the place, but that's the very nature of the
> beast.
> 
> >       * What parameters can tune this timer?
> 
> None. You may want to check whether the delay is observed when the VM
> has hit WFI or not.

<EH> Yes, delay is observed after vm_exit because of WFx (not sure WFI or WFE) but only when on a different vCPU in the same VM some workload is started. Since we pin that workload to its own vCPU, in theory, it should not affect the timing of another vCPU.

> 
> You also don't mention what host kernel version you are running.
> In general, please try and reproduce the issue using the latest kernel version
> (5.16 at the moment). Please also indicate what HW you are using.

<EH> Tried 5.15 and 5.4 kernels. Both have the issue. Do you think 5.16 can make a difference? The HW is an Ampere Altra system.

> 
> Thanks,
> 
>          M.
> --
> Jazz is not dead. It just smells funny...
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

  parent reply	other threads:[~2022-03-02 14:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-28 18:02 Timer delays in VM Eugene Huang
2022-02-28 21:02 ` Marc Zyngier
2022-03-01  9:06   ` Andrew Jones
2022-03-01 19:03   ` Eugene Huang [this message]
2022-03-02  2:27     ` Eugene Huang
2022-03-02  7:28     ` Marc Zyngier
2022-03-03  5:49       ` Eugene Huang
2022-03-03 14:42         ` Marc Zyngier
2022-03-08  7:50           ` Eugene Huang
2022-03-08  9:34             ` Marc Zyngier
  -- strict thread matches above, loose matches on Subject: below --
2022-02-28  6:22 Eugene Huang
2022-02-28 11:02 ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BYAPR12MB3192EFEBABB1B31D9751C931D9029@BYAPR12MB3192.namprd12.prod.outlook.com \
    --to=eugeneh@nvidia.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=maz@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.