public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoffer Dall <cdall@linaro.org>
To: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: "Marc Zyngier" <marc.zyngier@arm.com>,
	tglx@linutronix.de, "Mark Rutland" <mark.rutland@arm.com>,
	"Vineet Gupta" <vgupta@synopsys.com>,
	"Patrice Chotard" <patrice.chotard@st.com>,
	"Kukjin Kim" <kgene@kernel.org>,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	"Javier Martinez Canillas" <javier@osg.samsung.com>,
	"Christoffer Dall" <christoffer.dall@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org,
	kernel@stlinux.com, linux-samsung-soc@vger.kernel.org,
	kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org
Subject: Re: [PATCH V9 1/3] irq: Allow to pass the IRQF_TIMER flag with percpu irq request
Date: Tue, 25 Apr 2017 12:22:30 +0200	[thread overview]
Message-ID: <20170425102230.GJ4104@cbox> (raw)
In-Reply-To: <20170425094927.GB16888@mai>

On Tue, Apr 25, 2017 at 11:49:27AM +0200, Daniel Lezcano wrote:

[...]

> > 
> > The idle code is very much *not* aware of anything concerning that guest
> > timer.
> 
> Just for my own curiosity, if there are two VM (VM1 and VM2). VM1 sets a timer1
> at <time> and exits, VM2 runs and sets a timer2 at <time+delta>.
> 
> The timer1 for VM1 is supposed to expire while VM2 is running. IIUC the virtual
> timer is under control of VM2 and will expire at <time+delta>.
> 
> Is the host wake up with the SW timer and switch in VM1 which in turn restores
> the timer and jump in the virtual timer irq handler?
>  
The thing that may be missing here is that a VCPU thread (more of which
in a collection is a VM) is just a thread from the point of view of
Linux, and whether or not a guest schedules a timer, should not effect
the scheduler's decision to run a given thread, if the thread is
runnable.

Whenever we run a VCPU thread, we look at its timer state (in software)
and calculate if the guest should see a timer interrupt and inject such
a one (the hardware arch timer is not involved in this process at all).

We use timers in exactly two scenarios:

 1. The hardware arch timers are used to force an exit to the host when
    the guest programmed the timer, so we can do the calculation in
    software I mentioned above and inject a virtual software-generated
    interrupt when the guest expects to see one.

 2. The guest goes to sleep (WFI) but has programmed a timer to be woken
    up at some point.  KVM handles a WFI by blocking the VCPU thread,
    which basically means making the thread interruptible and putting it
    on a waitqueue.  In this case we schedule a software timer to make
    the thread runnable again when the software timer fires (and the
    scheduler runs that thread when it wants to after that).

If you have a VCPU thread from VM1 blocked, and you run a VCPU thread
from VM2, then the VCPU thread from VM2 will program the hardware arch
timer with the context of the VM2 VCPU thread while running, and this
has nothing to do with the VCPU thread from VM1 at this point, because
it relies on the host Linux time keeping infrastructure to become
runnable some time in the future, and running a guest naturally doesn't
mess with the host's time keeping.

Hope this helps,
-Christoffer

  parent reply	other threads:[~2017-04-25 10:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-24 14:01 [PATCH V9 1/3] irq: Allow to pass the IRQF_TIMER flag with percpu irq request Daniel Lezcano
2017-04-24 14:01 ` [PATCH V9 2/3] irq: Track the interrupt timings Daniel Lezcano
2017-04-24 14:01 ` [PATCH V9 3/3] irq: Compute the periodic interval for interrupts Daniel Lezcano
2017-04-24 18:33 ` [PATCH V9 1/3] irq: Allow to pass the IRQF_TIMER flag with percpu irq request Krzysztof Kozlowski
2017-04-24 18:46 ` Marc Zyngier
2017-04-24 18:59   ` Daniel Lezcano
2017-04-24 19:14     ` Marc Zyngier
2017-04-24 19:59       ` Daniel Lezcano
2017-04-25  7:38         ` Marc Zyngier
2017-04-25  8:34           ` Daniel Lezcano
2017-04-25  9:10             ` Marc Zyngier
2017-04-25  9:49               ` Daniel Lezcano
2017-04-25 10:21                 ` Marc Zyngier
2017-04-25 12:51                   ` Daniel Lezcano
2017-04-25 13:22                     ` Marc Zyngier
2017-04-25 13:53                       ` Daniel Lezcano
2017-04-25 10:22                 ` Christoffer Dall [this message]
2017-04-25 12:52                   ` Daniel Lezcano

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=20170425102230.GJ4104@cbox \
    --to=cdall@linaro.org \
    --cc=christoffer.dall@linaro.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=javier@osg.samsung.com \
    --cc=kernel@stlinux.com \
    --cc=kgene@kernel.org \
    --cc=krzk@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-snps-arc@lists.infradead.org \
    --cc=marc.zyngier@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=patrice.chotard@st.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=vgupta@synopsys.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox