<p>Werner Zeh has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/21516">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">timestamp: Add function to get time since boot<br><br>Add a function to retrieve the elapsed time since boot. For that purpose<br>use the base time in the timestamp table among with the current<br>timestamp at call time of the function. So more precise the returned<br>time is the elapsed time since the timestamp was initialized scaled<br>in microseconds. This was chosen to get a reliable value even on<br>platforms where the TSC might not be reset on software reset or warm<br>start.<br><br>Change-Id: Ib93ad89078645c0ebe256048cb48f9622c90451f<br>Signed-off-by: Werner Zeh <werner.zeh@siemens.com><br>---<br>M src/include/timestamp.h<br>M src/lib/timestamp.c<br>2 files changed, 22 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/16/21516/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/src/include/timestamp.h b/src/include/timestamp.h<br>index 95470f5..f8a5297 100644<br>--- a/src/include/timestamp.h<br>+++ b/src/include/timestamp.h<br>@@ -40,11 +40,20 @@<br> /* Apply a factor of N/M to all timestamps recorded so far. */<br> void timestamp_rescale_table(uint16_t N, uint16_t M);<br> <br>+/*<br>+ * Get the time since boot scaled in microseconds. Therefore use the base time<br>+ * of the timestamps to get the initial value which is subtracted from<br>+ * current timestamp at call time.This will provide a more reliable value even<br>+ * if the TSC is not reset on soft reset or warm start.<br>+ */<br>+uint32_t get_us_since_boot(void);<br>+<br> #else<br> #define timestamp_init(base)<br> #define timestamp_add(id, time)<br> #define timestamp_add_now(id)<br> #define timestamp_rescale_table(N, M)<br>+#define get_us_since_boot() 0<br> #endif<br> <br> /* Implemented by the architecture code */<br>diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c<br>index 30f7c13..76a9aca 100644<br>--- a/src/lib/timestamp.c<br>+++ b/src/lib/timestamp.c<br>@@ -327,6 +327,19 @@<br>  }<br> }<br> <br>+/*<br>+ * Get the time in microseconds since boot (or more precise: since timestamp<br>+ * table was initialized).<br>+ */<br>+uint32_t get_us_since_boot(void)<br>+{<br>+       struct timestamp_table *ts = timestamp_table_get();<br>+<br>+       if (ts == NULL)<br>+              return 0;<br>+    return ((timestamp_get() - ts->base_time) / ts->tick_freq_mhz);<br>+}<br>+<br> ROMSTAGE_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem)<br> RAMSTAGE_CBMEM_INIT_HOOK(timestamp_sync_cache_to_cbmem)<br> <br></pre><p>To view, visit <a href="https://review.coreboot.org/21516">change 21516</a>. To unsubscribe, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/21516"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ib93ad89078645c0ebe256048cb48f9622c90451f </div>
<div style="display:none"> Gerrit-Change-Number: 21516 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Werner Zeh <werner.zeh@siemens.com> </div>