[PATCH 15/15] efi: payload: use ktime_to_us to avoid plain 64-bit division

Ahmad Fatoum a.fatoum at barebox.org
Tue May 27 14:23:00 PDT 2025


From: Ahmad Fatoum <ahmad at a3f.at>

The nanosecond time is a 64-bit quantity and dividing them by 1000
worked out so far, because we only did EFI on 64-bit systems.
Now that we want to start compiling it for 32-bit as well, make
the division work there as well.

Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 efi/payload/image.c | 3 ++-
 efi/payload/init.c  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/efi/payload/image.c b/efi/payload/image.c
index f039b8a8d26a..33c5e18dac27 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -8,6 +8,7 @@
 #include <clock.h>
 #include <common.h>
 #include <linux/sizes.h>
+#include <linux/ktime.h>
 #include <memory.h>
 #include <command.h>
 #include <magicvar.h>
@@ -302,7 +303,7 @@ static int do_bootm_efi(struct image_data *data)
 	}
 
 	efi_set_variable_usec("LoaderTimeExecUSec", &efi_systemd_vendor_guid,
-			      get_time_ns()/1000);
+			      ktime_to_us(ktime_get()));
 
 	shutdown_barebox();
 	linux_efi_handover(handle, boot_header);
diff --git a/efi/payload/init.c b/efi/payload/init.c
index 6a616161e884..239c5ce9ec18 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -14,6 +14,7 @@
 #include <linux/linkage.h>
 #include <common.h>
 #include <linux/sizes.h>
+#include <linux/ktime.h>
 #include <memory.h>
 #include <clock.h>
 #include <command.h>
@@ -310,7 +311,7 @@ static int efi_postcore_init(void)
 		EFI_LOADER_FEATURE_DEVICETREE;
 
 	efi_set_variable_usec("LoaderTimeInitUSec", &efi_systemd_vendor_guid,
-			      get_time_ns()/1000);
+			      ktime_to_us(ktime_get()));
 
 	efi_set_variable_printf("LoaderInfo", &efi_systemd_vendor_guid,
 			"barebox-" UTS_RELEASE);
-- 
2.39.5




More information about the barebox mailing list