Skip to contentSkip to conversation

efi: loader: coalesce overdue periodic timers

PATCH Applied Ahmad Fatoum 2 participants 2 messages Jul 9 – Jul 10

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi: loader: coalesce overdue periodic timers

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
---
 efi/loader/boot.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
efi/loader/boot.c +22 -1
index d34de119f4e7..503b44073886 100644
@@ -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;
Signature · 1 line
2.47.3
Applied
#1 lore raw
Quoted 9 lines · 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.

[...]

Applied, thanks!

[1/1] efi: loader: coalesce overdue periodic timers
https://git.pengutronix.de/cgit/barebox/commit/?id=501bfbe6f1ec (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>