]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-boot: split out TSC/time API
authorLennart Poettering <lennart@poettering.net>
Tue, 8 Feb 2022 10:18:44 +0000 (11:18 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 8 Feb 2022 12:46:02 +0000 (13:46 +0100)
These are a whole family of functions, let's give them their own .c/.h
file.

No code changes, just splitting things out.

src/boot/efi/boot.c
src/boot/efi/meson.build
src/boot/efi/ticks.c [new file with mode: 0644]
src/boot/efi/ticks.h [new file with mode: 0644]
src/boot/efi/util.c
src/boot/efi/util.h

index c431c38e9f83f0b2e0ff6154c6becc00597804e8..b2f4f873c3d1e63a6912f8b1bfd0d3c0b6c5df24 100644 (file)
@@ -18,6 +18,7 @@
 #include "random-seed.h"
 #include "secure-boot.h"
 #include "shim.h"
+#include "ticks.h"
 #include "util.h"
 #include "xbootldr.h"
 
index d23352d48e54d73787b8df833f90cf9eb277dfea..f6004e47ecc0f61e663aab8c3657426fd241eaf2 100644 (file)
@@ -322,6 +322,7 @@ efi_headers = files(
         'secure-boot.h',
         'shim.h',
         'splash.h',
+        'ticks.h',
         'util.h',
         'xbootldr.h',
 )
@@ -334,6 +335,7 @@ common_sources = files(
         'measure.c',
         'pe.c',
         'secure-boot.c',
+        'ticks.c',
         'util.c',
 )
 
diff --git a/src/boot/efi/ticks.c b/src/boot/efi/ticks.c
new file mode 100644 (file)
index 0000000..68b2d58
--- /dev/null
@@ -0,0 +1,67 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include <efi.h>
+#include <efilib.h>
+
+#include "ticks.h"
+
+#ifdef __x86_64__
+UINT64 ticks_read(void) {
+        UINT64 a, d;
+        __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
+        return (d << 32) | a;
+}
+#elif defined(__i386__)
+UINT64 ticks_read(void) {
+        UINT64 val;
+        __asm__ volatile ("rdtsc" : "=A" (val));
+        return val;
+}
+#elif defined(__aarch64__)
+UINT64 ticks_read(void) {
+        UINT64 val;
+        __asm__ volatile ("mrs %0, cntpct_el0" : "=r" (val));
+        return val;
+}
+#else
+UINT64 ticks_read(void) {
+        UINT64 val = 1;
+        return val;
+}
+#endif
+
+#if defined(__aarch64__)
+UINT64 ticks_freq(void) {
+        UINT64 freq;
+        __asm__ volatile ("mrs %0, cntfrq_el0": "=r" (freq));
+        return freq;
+}
+#else
+/* count TSC ticks during a millisecond delay */
+UINT64 ticks_freq(void) {
+        UINT64 ticks_start, ticks_end;
+
+        ticks_start = ticks_read();
+        BS->Stall(1000);
+        ticks_end = ticks_read();
+
+        return (ticks_end - ticks_start) * 1000UL;
+}
+#endif
+
+UINT64 time_usec(void) {
+        UINT64 ticks;
+        static UINT64 freq;
+
+        ticks = ticks_read();
+        if (ticks == 0)
+                return 0;
+
+        if (freq == 0) {
+                freq = ticks_freq();
+                if (freq == 0)
+                        return 0;
+        }
+
+        return 1000UL * 1000UL * ticks / freq;
+}
diff --git a/src/boot/efi/ticks.h b/src/boot/efi/ticks.h
new file mode 100644 (file)
index 0000000..389c705
--- /dev/null
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <efi.h>
+#include <efilib.h>
+
+UINT64 ticks_read(void);
+UINT64 ticks_freq(void);
+UINT64 time_usec(void);
index 257646551c52d52fe45fd0ac90d27808a2a2b22d..e6250207f68b9c4287df7cae3d21b500f6f15361 100644 (file)
@@ -3,69 +3,9 @@
 #include <efi.h>
 #include <efilib.h>
 
+#include "ticks.h"
 #include "util.h"
 
-#ifdef __x86_64__
-UINT64 ticks_read(void) {
-        UINT64 a, d;
-        __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
-        return (d << 32) | a;
-}
-#elif defined(__i386__)
-UINT64 ticks_read(void) {
-        UINT64 val;
-        __asm__ volatile ("rdtsc" : "=A" (val));
-        return val;
-}
-#elif defined(__aarch64__)
-UINT64 ticks_read(void) {
-        UINT64 val;
-        __asm__ volatile ("mrs %0, cntpct_el0" : "=r" (val));
-        return val;
-}
-#else
-UINT64 ticks_read(void) {
-        UINT64 val = 1;
-        return val;
-}
-#endif
-
-#if defined(__aarch64__)
-UINT64 ticks_freq(void) {
-        UINT64 freq;
-        __asm__ volatile ("mrs %0, cntfrq_el0": "=r" (freq));
-        return freq;
-}
-#else
-/* count TSC ticks during a millisecond delay */
-UINT64 ticks_freq(void) {
-        UINT64 ticks_start, ticks_end;
-
-        ticks_start = ticks_read();
-        BS->Stall(1000);
-        ticks_end = ticks_read();
-
-        return (ticks_end - ticks_start) * 1000UL;
-}
-#endif
-
-UINT64 time_usec(void) {
-        UINT64 ticks;
-        static UINT64 freq;
-
-        ticks = ticks_read();
-        if (ticks == 0)
-                return 0;
-
-        if (freq == 0) {
-                freq = ticks_freq();
-                if (freq == 0)
-                        return 0;
-        }
-
-        return 1000UL * 1000UL * ticks / freq;
-}
-
 EFI_STATUS parse_boolean(const CHAR8 *v, BOOLEAN *b) {
         assert(b);
 
index 3d659f7043f96d62cd0689fc0cbec9c63db9268b..33b17d04fbb78e826ebe98d4f3f11deed528c7b1 100644 (file)
 
 EFI_STATUS parse_boolean(const CHAR8 *v, BOOLEAN *b);
 
-UINT64 ticks_read(void);
-UINT64 ticks_freq(void);
-UINT64 time_usec(void);
-
 EFI_STATUS efivar_set(const EFI_GUID *vendor, const CHAR16 *name, const CHAR16 *value, UINT32 flags);
 EFI_STATUS efivar_set_raw(const EFI_GUID *vendor, const CHAR16 *name, const void *buf, UINTN size, UINT32 flags);
 EFI_STATUS efivar_set_uint_string(const EFI_GUID *vendor, const CHAR16 *name, UINTN i, UINT32 flags);