summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWerner Zeh <werner.zeh@siemens.com>2017-09-12 07:42:54 +0200
committerWerner Zeh <werner.zeh@siemens.com>2017-09-14 18:12:39 +0000
commit35cceb861c90083ea5dd6ad084141280d905aa36 (patch)
treec66e5e39613aa122471603a32904231974a1bd0c /src
parent653f019d0d4de5e50281edae2f1d88af58e53388 (diff)
downloadcoreboot-35cceb861c90083ea5dd6ad084141280d905aa36.tar.xz
timestamp: Add function to get time since boot
Add a function to retrieve the elapsed time since boot. For that purpose use the base time in the timestamp table among with the current timestamp at call time of the function. So more precise the returned time is the elapsed time since the timestamp was initialized scaled in microseconds. This was chosen to get a reliable value even on platforms where the TSC might not be reset on software reset or warm start. Change-Id: Ib93ad89078645c0ebe256048cb48f9622c90451f Signed-off-by: Werner Zeh <werner.zeh@siemens.com> Reviewed-on: https://review.coreboot.org/21516 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src')
-rw-r--r--src/include/timestamp.h10
-rw-r--r--src/lib/timestamp.c14
2 files changed, 24 insertions, 0 deletions
diff --git a/src/include/timestamp.h b/src/include/timestamp.h
index 95470f53d6..db675b5d2b 100644
--- a/src/include/timestamp.h
+++ b/src/include/timestamp.h
@@ -2,6 +2,7 @@
* This file is part of the coreboot project.
*
* Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
+ * Copyright 2017 Siemens AG.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -40,11 +41,20 @@ void timestamp_add_now(enum timestamp_id id);
/* Apply a factor of N/M to all timestamps recorded so far. */
void timestamp_rescale_table(uint16_t N, uint16_t M);
+/*
+ * Get the time since boot scaled in microseconds. Therefore use the base time
+ * of the timestamps to get the initial value which is subtracted from
+ * current timestamp at call time. This will provide a more reliable value even
+ * if the TSC is not reset on soft reset or warm start.
+ */
+uint32_t get_us_since_boot(void);
+
#else
#define timestamp_init(base)
#define timestamp_add(id, time)
#define timestamp_add_now(id)
#define timestamp_rescale_table(N, M)
+#define get_us_since_boot() 0
#endif
/* Implemented by the architecture code */
diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c
index 30f7c13fb8..2e14fdd647 100644
--- a/src/lib/timestamp.c
+++ b/src/lib/timestamp.c
@@ -2,6 +2,7 @@
* This file is part of the coreboot project.
*
* Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
+ * Copyright 2017 Siemens AG.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -327,6 +328,19 @@ void timestamp_rescale_table(uint16_t N, uint16_t M)
}
}
+/*
+ * Get the time in microseconds since boot (or more precise: since timestamp
+ * table was initialized).
+ */
+uint32_t get_us_since_boot(void)
+{
+ struct timestamp_table *ts = timestamp_table_get();
+
+ if (ts == NULL || ts->tick_freq_mhz == 0)
+ return 0;
+ return (timestamp_get() - ts->base_time) / ts->tick_freq_mhz;
+}
+
ROMSTAGE_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem)
RAMSTAGE_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem)