Werner Zeh has uploaded this change for review. ( https://review.coreboot.org/21516
Change subject: timestamp: Add function to get time since boot ......................................................................
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 --- M src/include/timestamp.h M src/lib/timestamp.c 2 files changed, 22 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/16/21516/1
diff --git a/src/include/timestamp.h b/src/include/timestamp.h index 95470f5..f8a5297 100644 --- a/src/include/timestamp.h +++ b/src/include/timestamp.h @@ -40,11 +40,20 @@ /* 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 30f7c13..76a9aca 100644 --- a/src/lib/timestamp.c +++ b/src/lib/timestamp.c @@ -327,6 +327,19 @@ } }
+/* + * 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) + 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)