All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien@xen.org>
To: xen-devel@lists.xenproject.org
Cc: julien@xen.org, "Julien Grall" <jgrall@amazon.com>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>, "Wei Liu" <wl@xen.org>
Subject: [PATCH v2 2/2] xen/x86: ioapic: Bail out from timer_irq_works() as soon as possible
Date: Mon, 11 Dec 2023 12:23:22 +0000	[thread overview]
Message-ID: <20231211122322.15815-3-julien@xen.org> (raw)
In-Reply-To: <20231211122322.15815-1-julien@xen.org>

From: Julien Grall <jgrall@amazon.com>

Currently timer_irq_works() will wait the full 100ms before checking
that pit0_ticks has been incremented at least 4 times.

However, the bulk of the BIOS/platform should not have a buggy timer.
So waiting for the full 100ms is a bit harsh.

Rework the logic to only wait until 100ms passed or we saw more than
4 ticks. So now, in the good case, this will reduce the wait time
to ~50ms.

Take the opportunity to change the prototype of timer_irq_works() to
return a bool rather than int (which was already acting as a bool because
only 0/1 could be returned).

Signed-off-by: Julien Grall <jgrall@amazon.com>

---

Note that local_irq_restore() cannot be replaced with local_irq_disable()
because the function is not consistently called with IRQs off.

Changes in v2:
    - Return bool rather than int
    - Have a single return path
    - Use 'unsigned int' rather than 'unsigned long' for msec
---
 xen/arch/x86/io_apic.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c
index 238b6c1c2837..c89fbed8d675 100644
--- a/xen/arch/x86/io_apic.c
+++ b/xen/arch/x86/io_apic.c
@@ -1506,32 +1506,41 @@ static void __init setup_ioapic_ids_from_mpc(void)
  *	- if this function detects that timer IRQs are defunct, then we fall
  *	  back to ISA timer IRQs
  */
-static int __init timer_irq_works(void)
+static bool __init timer_irq_works(void)
 {
     unsigned long t1, flags;
+    /* Wait for maximum 10 ticks */
+    unsigned int msec = (10 * 1000) / HZ;
+    bool works = false;
 
     if ( pit_irq_works )
-        return 1;
+        return true;
 
     t1 = ACCESS_ONCE(pit0_ticks);
 
     local_save_flags(flags);
     local_irq_enable();
-    /* Let ten ticks pass... */
-    mdelay((10 * 1000) / HZ);
-    local_irq_restore(flags);
 
-    /*
-     * Expect a few ticks at least, to be sure some possible
-     * glue logic does not lock up after one or two first
-     * ticks in a non-ExtINT mode.  Also the local APIC
-     * might have cached one ExtINT interrupt.  Finally, at
-     * least one tick may be lost due to delays.
-     */
-    if ( (ACCESS_ONCE(pit0_ticks) - t1) > 4 )
-        return 1;
+    while ( msec-- )
+    {
+        mdelay(1);
+        /*
+         * Expect a few ticks at least, to be sure some possible
+         * glue logic does not lock up after one or two first
+         * ticks in a non-ExtINT mode.  Also the local APIC
+         * might have cached one ExtINT interrupt.  Finally, at
+         * least one tick may be lost due to delays.
+         */
+        if ( (ACCESS_ONCE(pit0_ticks) - t1) <= 4 )
+            continue;
 
-    return 0;
+        works = true;
+        break;
+    }
+
+    local_irq_restore(flags);
+
+    return works;
 }
 
 /*
-- 
2.40.1



  parent reply	other threads:[~2023-12-11 12:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-11 12:23 [PATCH v2 0/2] xen/x86: Optimize timer_irq_works() Julien Grall
2023-12-11 12:23 ` [PATCH v2 1/2] xen/x86: io_apic: Introduce a command line option to skip timer check Julien Grall
2023-12-14 10:10   ` Jan Beulich
2023-12-14 10:14     ` Julien Grall
2023-12-14 10:35       ` Jan Beulich
2024-01-02 19:09         ` Julien Grall
2024-01-04  8:54           ` Jan Beulich
2024-01-15 12:42             ` Roger Pau Monné
2023-12-11 12:23 ` Julien Grall [this message]
2023-12-14 10:19   ` [PATCH v2 2/2] xen/x86: ioapic: Bail out from timer_irq_works() as soon as possible Jan Beulich

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=20231211122322.15815-3-julien@xen.org \
    --to=julien@xen.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=jgrall@amazon.com \
    --cc=roger.pau@citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.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.