Add method for delaying adding of timestamps

In hardwaremain() we can't add timestamps before we actually
reinitialized the cbmem area. Hence we kept the timestamps in
an array and added them later. This is ugly and intrusive and
helped hiding a bug that prevented any timestamps to be logged
in hardwaremain() when coming out of an S3 resume.

The problem is solved by moving the logic to keep a few timestamps
around into the timestamp code. This also gets rid of a lot of ugly
ifdefs in hardwaremain.c

Change-Id: I945fc4c77e990f620c18cbd054ccd87e746706ef
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/1785
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
This commit is contained in:
Stefan Reinauer 2012-10-15 15:23:20 -07:00 committed by Ronald G. Minnich
parent 7004b7c9e6
commit 4221a19574
3 changed files with 55 additions and 26 deletions

View File

@ -58,10 +58,8 @@ void hardwaremain(int boot_complete);
void hardwaremain(int boot_complete) void hardwaremain(int boot_complete)
{ {
struct lb_memory *lb_mem; struct lb_memory *lb_mem;
#if CONFIG_COLLECT_TIMESTAMPS
tsc_t timestamps[6]; timestamp_stash(TS_START_RAMSTAGE);
timestamps[0] = rdtsc();
#endif
post_code(POST_ENTRY_RAMSTAGE); post_code(POST_ENTRY_RAMSTAGE);
/* console_init() MUST PRECEDE ALL printk()! */ /* console_init() MUST PRECEDE ALL printk()! */
@ -83,37 +81,27 @@ void hardwaremain(int boot_complete)
/* FIXME: Is there a better way to handle this? */ /* FIXME: Is there a better way to handle this? */
init_timer(); init_timer();
#if CONFIG_COLLECT_TIMESTAMPS timestamp_stash(TS_DEVICE_ENUMERATE);
timestamps[1] = rdtsc();
#endif
/* Find the devices we don't have hard coded knowledge about. */ /* Find the devices we don't have hard coded knowledge about. */
dev_enumerate(); dev_enumerate();
post_code(POST_DEVICE_ENUMERATION_COMPLETE); post_code(POST_DEVICE_ENUMERATION_COMPLETE);
#if CONFIG_COLLECT_TIMESTAMPS timestamp_stash(TS_DEVICE_CONFIGURE);
timestamps[2] = rdtsc();
#endif
/* Now compute and assign the bus resources. */ /* Now compute and assign the bus resources. */
dev_configure(); dev_configure();
post_code(POST_DEVICE_CONFIGURATION_COMPLETE); post_code(POST_DEVICE_CONFIGURATION_COMPLETE);
#if CONFIG_COLLECT_TIMESTAMPS timestamp_stash(TS_DEVICE_ENABLE);
timestamps[3] = rdtsc();
#endif
/* Now actually enable devices on the bus */ /* Now actually enable devices on the bus */
dev_enable(); dev_enable();
post_code(POST_DEVICES_ENABLED); post_code(POST_DEVICES_ENABLED);
#if CONFIG_COLLECT_TIMESTAMPS timestamp_stash(TS_DEVICE_INITIALIZE);
timestamps[4] = rdtsc();
#endif
/* And of course initialize devices on the bus */ /* And of course initialize devices on the bus */
dev_initialize(); dev_initialize();
post_code(POST_DEVICES_INITIALIZED); post_code(POST_DEVICES_INITIALIZED);
#if CONFIG_COLLECT_TIMESTAMPS timestamp_stash(TS_DEVICE_DONE);
timestamps[5] = rdtsc();
#endif
#if CONFIG_WRITE_HIGH_TABLES #if CONFIG_WRITE_HIGH_TABLES
cbmem_initialize(); cbmem_initialize();
@ -121,13 +109,7 @@ void hardwaremain(int boot_complete)
cbmemc_reinit(); cbmemc_reinit();
#endif #endif
#endif #endif
timestamp_sync();
timestamp_add(TS_START_RAMSTAGE, timestamps[0]);
timestamp_add(TS_DEVICE_ENUMERATE, timestamps[1]);
timestamp_add(TS_DEVICE_CONFIGURE, timestamps[2]);
timestamp_add(TS_DEVICE_ENABLE, timestamps[3]);
timestamp_add(TS_DEVICE_INITIALIZE, timestamps[4]);
timestamp_add(TS_DEVICE_DONE, timestamps[5]);
#if CONFIG_HAVE_ACPI_RESUME #if CONFIG_HAVE_ACPI_RESUME
suspend_resume(); suspend_resume();

View File

@ -57,10 +57,14 @@ enum timestamp_id {
void timestamp_init(tsc_t base); void timestamp_init(tsc_t base);
void timestamp_add(enum timestamp_id id, tsc_t ts_time); void timestamp_add(enum timestamp_id id, tsc_t ts_time);
void timestamp_add_now(enum timestamp_id id); void timestamp_add_now(enum timestamp_id id);
void timestamp_stash(enum timestamp_id id);
void timestamp_sync(void);
#else #else
#define timestamp_init(base) #define timestamp_init(base)
#define timestamp_add(id, time) #define timestamp_add(id, time)
#define timestamp_add_now(id) #define timestamp_add_now(id)
#define timestamp_stash(id)
#define timestamp_sync()
#endif #endif
#endif #endif

View File

@ -21,6 +21,10 @@
#include <console/console.h> #include <console/console.h>
#include <cbmem.h> #include <cbmem.h>
#include <timestamp.h> #include <timestamp.h>
#ifndef __PRE_RAM__
/* For CAR_GLOBAL... This should move out of x86 specific code */
#include <cpu/x86/car.h>
#endif
#define MAX_TIMESTAMPS 30 #define MAX_TIMESTAMPS 30
@ -72,3 +76,42 @@ void timestamp_add_now(enum timestamp_id id)
{ {
timestamp_add(id, rdtsc()); timestamp_add(id, rdtsc());
} }
#ifndef __PRE_RAM__
#define MAX_TIMESTAMP_CACHE 8
struct timestamp_cache {
enum timestamp_id id;
tsc_t time;
} timestamp_cache[MAX_TIMESTAMP_CACHE] CAR_GLOBAL;
static int timestamp_entries CAR_GLOBAL = 0;
/**
* timestamp_stash() allows to temporarily cache time stamps.
* This is needed when time stamping before the CBMEM area
* is initialized. The function timestamp_sync() is used to
* write the time stamps to the CBMEM area. This is done in
* hardwaremain()
*/
void timestamp_stash(enum timestamp_id id)
{
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_entries++;
}
void timestamp_sync(void)
{
int i;
for (i = 0; i < timestamp_entries; i++)
timestamp_add(timestamp_cache[i].id, timestamp_cache[i].time);
timestamp_entries = 0;
}
#endif