summaryrefslogtreecommitdiff
path: root/src/boot
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-02-08 11:26:49 +0100
committerLennart Poettering <lennart@poettering.net>2022-02-08 13:46:20 +0100
commitfb63526f726772f8fea64830ec05d69c1a48a74e (patch)
tree9217f1d2c2881a2e83975e4bc658833d09bcfcbf /src/boot
parentefbb86797df10ac72fe5ae29afc856d94700e2da (diff)
downloadsystemd-fb63526f726772f8fea64830ec05d69c1a48a74e.tar.gz
sd-boot: encapsulate freq cache in ticks_freq()
It's usually nicer to abstract a cache away in the provider of a value, hence do so.
Diffstat (limited to 'src/boot')
-rw-r--r--src/boot/efi/ticks.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/boot/efi/ticks.c b/src/boot/efi/ticks.c
index ec6a6fd13e..3e7ff68823 100644
--- a/src/boot/efi/ticks.c
+++ b/src/boot/efi/ticks.c
@@ -40,6 +40,10 @@ static UINT64 ticks_freq(void) {
/* count TSC ticks during a millisecond delay */
static UINT64 ticks_freq(void) {
UINT64 ticks_start, ticks_end;
+ static UINT64 cache = 0;
+
+ if (cache != 0)
+ return cache;
ticks_start = ticks_read();
BS->Stall(1000);
@@ -49,23 +53,21 @@ static UINT64 ticks_freq(void) {
* archs the value is 32bit) */
return 0;
- return (ticks_end - ticks_start) * 1000UL;
+ cache = (ticks_end - ticks_start) * 1000UL;
+ return cache;
}
#endif
UINT64 time_usec(void) {
- UINT64 ticks;
- static UINT64 freq;
+ UINT64 ticks, freq;
ticks = ticks_read();
if (ticks == 0)
return 0;
- if (freq == 0) {
- freq = ticks_freq();
- if (freq == 0)
- return 0;
- }
+ freq = ticks_freq();
+ if (freq == 0)
+ return 0;
return 1000UL * 1000UL * ticks / freq;
}