qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: "Alex Züpke" <alexander.zuepke@hs-rm.de>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] QEMU ARM SMP: IPI delivery delayed until next main loop event // how to improve IPI latency?
Date: Fri, 12 Jun 2015 19:03:37 +0100	[thread overview]
Message-ID: <CAFEAcA8iCmgwgmhTkRryTyVBSxS+Cbh6bGSLqt7EPM028F1tUg@mail.gmail.com> (raw)
In-Reply-To: <557B0B21.2030009@hs-rm.de>

On 12 June 2015 at 17:38, Alex Züpke <alexander.zuepke@hs-rm.de> wrote:
> Hi,
>
> I'm benchmarking some IPI (== inter-processor-interrupt) synchronization stuff of my custom kernel on QEMU ARM (qemu-system-arm -M vexpress-a15 -smp 2) and ran into the following problem: pending IPIs are delayed until the QEMU main loop receives an event (for example the timer interrupt expires or I press a key on the console).
>
> The following timing diagram tries to show this:
>
>   CPU #0                       CPU #1
>   ======                       ======
>   ... other stuff ...          WFI (wait for interrupt, like x86 "HLT")
>   send SGI in MPCore
>   polls for completeness
>                  <time passes ...>
>   polls ...
>                  <... and passes ...>
>   still polls ...
>                  <... and passes ...>
>   still polls ...
>                  <... and passes ...>
>
>
>                  <timer interrupt expires>
>                  <now QEMU switches to CPU #1>
>                                receives IPI
>                                signals completeness
>                                WFI
>                  <QEMU switches to CPU #0>
>   polling done
>   process timer interrupt
>   ...

Right. The problem is that we don't have any way of telling
that CPU 0 is just sat busy waiting for CPU 1.

> It works as expects (I get thousands of IPIs per second now), but
> it does not "feel right", so is there a better way to improve the
> responsiveness of IPI handling in QEMU?

Probably the best approach would be to have something in
arm_cpu_set_irq() which says "if we are CPU X and we've
just caused an interrupt to be set for CPU Y, then we
should ourselves yield back to the main loop".

Something like this, maybe, though I have done no more testing
than checking it doesn't actively break kernel booting :-)

--- a/target-arm/cpu.c
+++ b/target-arm/cpu.c
@@ -325,6 +325,18 @@ static void arm_cpu_set_irq(void *opaque, int
irq, int level)
     default:
         hw_error("arm_cpu_set_irq: Bad interrupt line %d\n", irq);
     }
+
+    /* If we are currently executing code for CPU X, and this
+     * CPU we've just triggered an interrupt on is CPU Y, then
+     * make CPU X yield control back to the main loop at the
+     * end of the TB it's currently executing.
+     * This avoids problems where the interrupt was an IPI
+     * and CPU X would otherwise sit busy looping for the rest
+     * of its timeslice because Y hasn't had a chance to run.
+     */
+    if (current_cpu && current_cpu != cs) {
+        cpu_exit(current_cpu);
+    }
 }

 static void arm_cpu_kvm_set_irq(void *opaque, int irq, int level)


-- PMM

  reply	other threads:[~2015-06-12 18:04 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12 16:38 [Qemu-devel] QEMU ARM SMP: IPI delivery delayed until next main loop event // how to improve IPI latency? Alex Züpke
2015-06-12 18:03 ` Peter Maydell [this message]
2015-06-15 14:44   ` Alex Züpke
2015-06-15 14:51     ` Peter Maydell
2015-06-15 15:05       ` Alex Züpke
2015-06-15 18:41         ` Peter Maydell
2015-06-15 18:58         ` Peter Maydell
2015-06-15 20:03           ` Alex Zuepke
2015-06-16 10:33             ` Peter Maydell
2015-06-16 10:59               ` Peter Maydell
2015-06-16 11:11                 ` Alex Züpke
2015-06-16 11:53                   ` Peter Maydell
2015-06-16 12:21                     ` Alex Züpke
2015-06-19 15:53                     ` Peter Maydell
2015-06-23  7:31                       ` Frederic Konrad
2015-06-23  8:09                         ` Peter Maydell
2015-06-23  8:33                           ` Frederic Konrad
2015-06-23 18:15                         ` Peter Maydell
2015-06-25 17:13                           ` Peter Maydell
2015-06-15 15:04 ` Peter Maydell
2015-06-15 15:07   ` Alex Züpke
2015-06-15 15:18     ` Peter Maydell
2015-06-15 15:36       ` Alex Züpke
2015-06-15 15:49         ` Peter Maydell
2015-06-15 16:12           ` Alex Züpke
2015-06-15 21:39           ` Peter Crosthwaite
2015-06-19 16:57 ` Paolo Bonzini
2015-06-19 17:25   ` 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=CAFEAcA8iCmgwgmhTkRryTyVBSxS+Cbh6bGSLqt7EPM028F1tUg@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=alexander.zuepke@hs-rm.de \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).