mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] efi: loader: coalesce overdue periodic timers
@ 2026-07-09  8:11 Ahmad Fatoum
  2026-07-10 21:50 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2026-07-09  8:11 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-10 21:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-09  8:11 [PATCH] efi: loader: coalesce overdue periodic timers Ahmad Fatoum
2026-07-10 21:50 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox