mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH] efi: loader: coalesce overdue periodic timers
Date: Thu,  9 Jul 2026 10:11:05 +0200	[thread overview]
Message-ID: <20260709081106.550595-1-a.fatoum@barebox.org> (raw)

EFI timer events are polled by the loader instead of being driven from
an interrupt. If a periodic timer is serviced late, advancing the next
deadline by only one period leaves old deadlines pending.

Advance periodic timers past the current time when they fire. This keeps
each poll to one notification and avoids consumers draining stale timer
ticks in a tight loop.

This fixes an issue of the Fedora-Workstation-Live-44-1.7.aarch64.iso
GRUB going through its countdown way too fast on a Google Corsola.

Assisted-by: Codex:gpt-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 efi/loader/boot.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/efi/loader/boot.c b/efi/loader/boot.c
index d34de119f4e7..503b44073886 100644
--- a/efi/loader/boot.c
+++ b/efi/loader/boot.c
@@ -735,6 +735,27 @@ static efi_status_t EFIAPI efi_create_event_ext(
 					 notify_context, NULL, event), *event);
 }
 
+/**
+ * efi_timer_rearm_periodic() - re-arm a periodic timer after it fired
+ * @evt:	timer event
+ * @now:	current time in ns
+ *
+ * Timers are polled. If a periodic timer is serviced late, signal it once
+ * and skip missed intervals so clients do not drain a backlog of stale ticks.
+ */
+static void efi_timer_rearm_periodic(struct efi_event *evt, u64 now)
+{
+	u64 periods;
+
+	if (!evt->trigger_time) {
+		evt->trigger_next = now;
+		return;
+	}
+
+	periods = div64_u64(now - evt->trigger_next, evt->trigger_time) + 1;
+	evt->trigger_next += periods * evt->trigger_time;
+}
+
 /**
  * efi_timer_check() - check if a timer event has occurred
  *
@@ -760,7 +781,7 @@ void efi_timer_check(void)
 			evt->trigger_type = EFI_TIMER_CANCEL;
 			break;
 		case EFI_TIMER_PERIODIC:
-			evt->trigger_next += evt->trigger_time;
+			efi_timer_rearm_periodic(evt, now);
 			break;
 		default:
 			continue;
-- 
2.47.3




             reply	other threads:[~2026-07-09 11:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09  8:11 Ahmad Fatoum [this message]
2026-07-10 21:50 ` Sascha Hauer

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=20260709081106.550595-1-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.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