From b766b1c76aa2258bf66569f429fb092c23813bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ky=C3=B6sti=20M=C3=A4lkki?= Date: Sat, 7 Sep 2013 17:26:08 +0300 Subject: timestamps: Use stash before CBMEM is usable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I9e927abdb1d7d9c233de5620a9a65b419e803ebf Signed-off-by: Kyösti Mälkki Reviewed-on: http://review.coreboot.org/3909 Tested-by: build bot (Jenkins) Reviewed-by: Paul Menzel Reviewed-by: Aaron Durbin --- src/lib/timestamp.c | 62 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 19 deletions(-) (limited to 'src/lib/timestamp.c') diff --git a/src/lib/timestamp.c b/src/lib/timestamp.c index 3f8a7bd621..7e2f7011e6 100644 --- a/src/lib/timestamp.c +++ b/src/lib/timestamp.c @@ -17,27 +17,26 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA */ +#include #include #include #include #include -#ifndef __PRE_RAM__ -/* For CAR_GLOBAL... This should move out of x86 specific code */ #include -#endif #define MAX_TIMESTAMPS 30 -#ifndef __PRE_RAM__ -static struct timestamp_table* ts_table; -#endif +static struct timestamp_table* ts_table CAR_GLOBAL = NULL; +static tsc_t ts_basetime CAR_GLOBAL = { .lo = 0, .hi =0 }; + +static void timestamp_stash(enum timestamp_id id, tsc_t ts_time); static uint64_t tsc_to_uint64(tsc_t tstamp) { return (((uint64_t)tstamp.hi) << 32) + tstamp.lo; } -void timestamp_init(tsc_t base) +static void timestamp_real_init(tsc_t base) { struct timestamp_table* tst; @@ -53,18 +52,19 @@ void timestamp_init(tsc_t base) tst->base_time = tsc_to_uint64(base); tst->max_entries = MAX_TIMESTAMPS; tst->num_entries = 0; + + ts_table = tst; } void timestamp_add(enum timestamp_id id, tsc_t ts_time) { struct timestamp_entry *tse; -#ifdef __PRE_RAM__ - struct timestamp_table *ts_table = cbmem_find(CBMEM_ID_TIMESTAMP); -#else - if (!ts_table) - ts_table = cbmem_find(CBMEM_ID_TIMESTAMP); -#endif - if (!ts_table || (ts_table->num_entries == ts_table->max_entries)) + + if (!ts_table) { + timestamp_stash(id, ts_time); + return; + } + if (ts_table->num_entries == ts_table->max_entries) return; tse = &ts_table->entries[ts_table->num_entries++]; @@ -77,8 +77,6 @@ void timestamp_add_now(enum timestamp_id id) timestamp_add(id, rdtsc()); } -#ifndef __PRE_RAM__ - #define MAX_TIMESTAMP_CACHE 8 struct timestamp_cache { enum timestamp_id id; @@ -95,18 +93,18 @@ static int timestamp_entries CAR_GLOBAL = 0; * ram stage main() */ -void timestamp_stash(enum timestamp_id id) +static void timestamp_stash(enum timestamp_id id, tsc_t ts_time) { if (timestamp_entries >= MAX_TIMESTAMP_CACHE) { printk(BIOS_ERR, "ERROR: failed to add timestamp to cache\n"); return; } timestamp_cache[timestamp_entries].id = id; - timestamp_cache[timestamp_entries].time = rdtsc(); + timestamp_cache[timestamp_entries].time = ts_time; timestamp_entries++; } -void timestamp_sync(void) +static void timestamp_do_sync(void) { int i; for (i = 0; i < timestamp_entries; i++) @@ -114,4 +112,30 @@ void timestamp_sync(void) timestamp_entries = 0; } +void timestamp_init(tsc_t base) +{ +#ifndef __PRE_RAM__ + struct timestamp_table* tst; + + /* Locate and use an already existing table. */ + tst = cbmem_find(CBMEM_ID_TIMESTAMP); + if (tst) { + ts_table = tst; + return; + } +#endif + + timestamp_real_init(base); + if (ts_table) + timestamp_do_sync(); + else + ts_basetime = base; +} + +#ifndef __PRE_RAM__ +void timestamp_sync(void) +{ + if (!ts_table) + timestamp_init(ts_basetime); +} #endif -- cgit v1.2.3