coreboot/src/lib/timestamp.c
Julius Werner c8127e4ac9 Add and consistently use wrapper macro for romstage static variables
x86 systems run their romstage as execute-in-place from flash, which
prevents them from having writable data segments. In several code pieces
that get linked into both romstage and ramstage, this has been worked
around by using a local variable and having the 'static' storage class
guarded by #ifndef __PRE_RAM__.

However, x86 is the only architecture using execute-in-place (for now),
so it does not make sense to impose the restriction globally. Rather
than fixing the #ifdef at every occurrence, this should really be
wrapped in a way that makes it easier to modify in a single place. The
chromeos/cros_vpd.c file already had a nice approach for a wrapper
macro, but unfortunately restricted it to one file... this patch moves
it to stddef.h and employs it consistently throughout coreboot.

BRANCH=nyan
BUG=None
TEST=Measured boot time on Nyan_Big before and after, confirmed that it
gained 6ms from caching the FMAP in vboot_loader.c.

Change-Id: Ia53b94ab9c6a303b979db7ff20b79e14bc51f9f8
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/203033
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Stefan Reinauer <reinauer@chromium.org>
2014-06-09 22:21:10 +00:00

104 lines
2.7 KiB
C

/*
* This file is part of the coreboot project.
*
* Copyright 2011 Google Inc.
*
* 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
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*/
#include <stddef.h>
#include <stdint.h>
#include <console/console.h>
#include <cbmem.h>
#include <timestamp.h>
#include <arch/early_variables.h>
#define MAX_TIMESTAMPS 30
void timestamp_init(uint64_t base)
{
struct timestamp_table* tst;
tst = cbmem_add(CBMEM_ID_TIMESTAMP,
sizeof(struct timestamp_table) +
MAX_TIMESTAMPS * sizeof(struct timestamp_entry));
if (!tst) {
printk(BIOS_ERR, "ERROR: failed to allocate timestamp table\n");
return;
}
tst->base_time = base;
tst->max_entries = MAX_TIMESTAMPS;
tst->num_entries = 0;
}
void timestamp_add(enum timestamp_id id, uint64_t ts_time)
{
struct timestamp_entry *tse;
MAYBE_STATIC struct timestamp_table *ts_table = NULL;
if (!ts_table)
ts_table = cbmem_find(CBMEM_ID_TIMESTAMP);
if (!ts_table || (ts_table->num_entries == ts_table->max_entries))
return;
tse = &ts_table->entries[ts_table->num_entries++];
tse->entry_id = id;
tse->entry_stamp = ts_time - ts_table->base_time;
}
void timestamp_add_now(enum timestamp_id id)
{
timestamp_add(id, timestamp_get());
}
#ifndef __PRE_RAM__
#define MAX_TIMESTAMP_CACHE 8
struct timestamp_cache {
enum timestamp_id id;
uint64_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
* ram stage main()
*/
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 = timestamp_get();
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