Timestamp implementation for ARMv7

Abstract the use of rdtsc() and make the timestamps
uint64_t in the generic code.

The ARM implementation uses the monotonic timer.

Signed-off-by: Stefan Reinauer <reinauer@google.com>

BRANCH=none
BUG=chrome-os-partner:18637
TEST=See cbmem print timestamps

Change-Id: Id377ba570094c44e6895ae75f8d6578c8865ea62
Reviewed-on: https://gerrit.chromium.org/gerrit/63793
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Commit-Queue: Stefan Reinauer <reinauer@chromium.org>
Tested-by: Stefan Reinauer <reinauer@chromium.org>
This commit is contained in:
Stefan Reinauer 2013-08-01 13:31:44 -07:00 committed by ChromeBot
commit cc1a75e059
14 changed files with 149 additions and 101 deletions

View file

@ -192,6 +192,9 @@ romstage-y += memmove.S
ramstage-y += memmove.S
bootblock-y += memmove.S
romstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
ramstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
$(obj)/arch/armv7/coreboot_table.ramstage.o : $(OPTION_TABLE_H)
romstage-srcs += $(objgenerated)/crt0.s

View file

@ -0,0 +1,29 @@
/*
* This file is part of the coreboot project.
*
* Copyright 2013 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 <timestamp.h>
#include <timer.h>
uint64_t timestamp_get(void)
{
struct mono_time timestamp;
timer_monotonic_get(&timestamp);
return (uint64_t)timestamp.microseconds;
}

View file

@ -11,6 +11,7 @@ ramstage-y += ebda.c
ramstage-y += rom_media.c
ramstage-$(CONFIG_COOP_MULTITASKING) += thread.c
ramstage-$(CONFIG_COOP_MULTITASKING) += thread_switch.S
ramstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
romstage-$(CONFIG_EARLY_CONSOLE) += romstage_console.c
romstage-y += cbfs_and_run.c
@ -18,6 +19,7 @@ romstage-y += memset.c
romstage-y += memcpy.c
romstage-y += memmove.c
romstage-y += rom_media.c
romstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
smm-y += memset.c
smm-y += memcpy.c

View file

@ -0,0 +1,27 @@
/*
* This file is part of the coreboot project.
*
* Copyright 2013 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 <cpu/x86/tsc.h>
#include <timestamp.h>
uint64_t timestamp_get(void)
{
return rdtscll();
}

View file

@ -201,17 +201,16 @@ void romstage_common(const struct romstage_params *params)
struct romstage_handoff *handoff;
#if CONFIG_COLLECT_TIMESTAMPS
tsc_t start_romstage_time;
tsc_t before_dram_time;
tsc_t after_dram_time;
tsc_t base_time = {
.lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc),
.hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0)
};
uint64_t start_romstage_time;
uint64_t before_dram_time;
uint64_t after_dram_time;
uint64_t base_time =
(uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 ||
pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc);
#endif
#if CONFIG_COLLECT_TIMESTAMPS
start_romstage_time = rdtsc();
start_romstage_time = timestamp_get();
#endif
if (params->bist == 0)
@ -253,7 +252,7 @@ void romstage_common(const struct romstage_params *params)
post_code(0x3a);
params->pei_data->boot_mode = boot_mode;
#if CONFIG_COLLECT_TIMESTAMPS
before_dram_time = rdtsc();
before_dram_time = timestamp_get();
#endif
report_platform_info();
@ -264,7 +263,7 @@ void romstage_common(const struct romstage_params *params)
sdram_initialize(params->pei_data);
#if CONFIG_COLLECT_TIMESTAMPS
after_dram_time = rdtsc();
after_dram_time = timestamp_get();
#endif
post_code(0x3b);

View file

@ -1,7 +1,7 @@
/*
* This file is part of the coreboot project.
*
* Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
* 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
@ -20,6 +20,8 @@
#ifndef __TIMESTAMP_H__
#define __TIMESTAMP_H__
#include <stdint.h>
struct timestamp_entry {
uint32_t entry_id;
uint64_t entry_stamp;
@ -55,12 +57,13 @@ enum timestamp_id {
};
#if CONFIG_COLLECT_TIMESTAMPS
#include <cpu/x86/tsc.h>
void timestamp_init(tsc_t base);
void timestamp_add(enum timestamp_id id, tsc_t ts_time);
void timestamp_init(uint64_t base);
void timestamp_add(enum timestamp_id id, uint64_t ts_time);
void timestamp_add_now(enum timestamp_id id);
void timestamp_stash(enum timestamp_id id);
void timestamp_sync(void);
/* Implemented by the architecture code */
uint64_t timestamp_get(void);
#else
#define timestamp_init(base)
#define timestamp_add(id, time)

View file

@ -1,7 +1,7 @@
/*
* This file is part of the coreboot project.
*
* Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
* 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
@ -22,22 +22,14 @@
#include <cbmem.h>
#include <timestamp.h>
#ifndef __PRE_RAM__
/* For CAR_GLOBAL... This should move out of x86 specific code */
#include <arch/early_variables.h>
static struct timestamp_table* ts_table;
#endif
#define MAX_TIMESTAMPS 30
#ifndef __PRE_RAM__
static struct timestamp_table* ts_table;
#endif
static uint64_t tsc_to_uint64(tsc_t tstamp)
{
return (((uint64_t)tstamp.hi) << 32) + tstamp.lo;
}
void timestamp_init(tsc_t base)
void timestamp_init(uint64_t base)
{
struct timestamp_table* tst;
@ -50,12 +42,12 @@ void timestamp_init(tsc_t base)
return;
}
tst->base_time = tsc_to_uint64(base);
tst->base_time = base;
tst->max_entries = MAX_TIMESTAMPS;
tst->num_entries = 0;
}
void timestamp_add(enum timestamp_id id, tsc_t ts_time)
void timestamp_add(enum timestamp_id id, uint64_t ts_time)
{
struct timestamp_entry *tse;
#ifdef __PRE_RAM__
@ -69,12 +61,12 @@ void timestamp_add(enum timestamp_id id, tsc_t ts_time)
tse = &ts_table->entries[ts_table->num_entries++];
tse->entry_id = id;
tse->entry_stamp = tsc_to_uint64(ts_time) - ts_table->base_time;
tse->entry_stamp = ts_time - ts_table->base_time;
}
void timestamp_add_now(enum timestamp_id id)
{
timestamp_add(id, rdtsc());
timestamp_add(id, timestamp_get());
}
#ifndef __PRE_RAM__
@ -82,7 +74,7 @@ void timestamp_add_now(enum timestamp_id id)
#define MAX_TIMESTAMP_CACHE 8
struct timestamp_cache {
enum timestamp_id id;
tsc_t time;
uint64_t time;
} timestamp_cache[MAX_TIMESTAMP_CACHE] CAR_GLOBAL;
static int timestamp_entries CAR_GLOBAL = 0;
@ -102,7 +94,7 @@ void timestamp_stash(enum timestamp_id id)
return;
}
timestamp_cache[timestamp_entries].id = id;
timestamp_cache[timestamp_entries].time = rdtsc();
timestamp_cache[timestamp_entries].time = timestamp_get();
timestamp_entries++;
}

View file

@ -119,13 +119,12 @@ void main(unsigned long bist)
u16 pm1_sts;
#if CONFIG_COLLECT_TIMESTAMPS
tsc_t start_romstage_time;
tsc_t before_dram_time;
tsc_t after_dram_time;
tsc_t base_time = {
.lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc),
.hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0)
};
uint64_t start_romstage_time;
uint64_t before_dram_time;
uint64_t after_dram_time;
uint64_t base_time =
(uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 ||
pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc);
#endif
struct pei_data pei_data = {
pei_version: PEI_VERSION,
@ -175,7 +174,7 @@ void main(unsigned long bist)
};
#if CONFIG_COLLECT_TIMESTAMPS
start_romstage_time = rdtsc();
start_romstage_time = timestamp_get();
#endif
if (bist == 0)
@ -242,12 +241,12 @@ void main(unsigned long bist)
post_code(0x3a);
pei_data.boot_mode = boot_mode;
#if CONFIG_COLLECT_TIMESTAMPS
before_dram_time = rdtsc();
before_dram_time = timestamp_get();
#endif
sdram_initialize(&pei_data);
#if CONFIG_COLLECT_TIMESTAMPS
after_dram_time = rdtsc();
after_dram_time = timestamp_get();
#endif
post_code(0x3c);

View file

@ -155,13 +155,12 @@ void main(unsigned long bist)
u16 pm1_sts;
#if CONFIG_COLLECT_TIMESTAMPS
tsc_t start_romstage_time;
tsc_t before_dram_time;
tsc_t after_dram_time;
tsc_t base_time = {
.lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc),
.hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0)
};
uint64_t start_romstage_time;
uint64_t before_dram_time;
uint64_t after_dram_time;
uint64_t base_time =
(uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 ||
pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc);
#endif
struct pei_data pei_data = {
pei_version: PEI_VERSION,
@ -210,7 +209,7 @@ void main(unsigned long bist)
};
#if CONFIG_COLLECT_TIMESTAMPS
start_romstage_time = rdtsc();
start_romstage_time = timestamp_get();
#endif
if (bist == 0)
@ -284,12 +283,12 @@ void main(unsigned long bist)
post_code(0x3a);
pei_data.boot_mode = boot_mode;
#if CONFIG_COLLECT_TIMESTAMPS
before_dram_time = rdtsc();
before_dram_time = timestamp_get();
#endif
sdram_initialize(&pei_data);
#if CONFIG_COLLECT_TIMESTAMPS
after_dram_time = rdtsc();
after_dram_time = timestamp_get();
#endif
post_code(0x3c);

View file

@ -120,13 +120,12 @@ void main(unsigned long bist)
u16 pm1_sts;
#if CONFIG_COLLECT_TIMESTAMPS
tsc_t start_romstage_time;
tsc_t before_dram_time;
tsc_t after_dram_time;
tsc_t base_time = {
.lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc),
.hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0)
};
uint64_t start_romstage_time;
uint64_t before_dram_time;
uint64_t after_dram_time;
uint64_t base_time =
(uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 ||
pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc);
#endif
struct pei_data pei_data = {
pei_version: PEI_VERSION,
@ -175,7 +174,7 @@ void main(unsigned long bist)
};
#if CONFIG_COLLECT_TIMESTAMPS
start_romstage_time = rdtsc();
start_romstage_time = timestamp_get();
#endif
if (bist == 0)
@ -242,12 +241,12 @@ void main(unsigned long bist)
post_code(0x3a);
pei_data.boot_mode = boot_mode;
#if CONFIG_COLLECT_TIMESTAMPS
before_dram_time = rdtsc();
before_dram_time = timestamp_get();
#endif
sdram_initialize(&pei_data);
#if CONFIG_COLLECT_TIMESTAMPS
after_dram_time = rdtsc();
after_dram_time = timestamp_get();
#endif
post_code(0x3c);

View file

@ -159,13 +159,12 @@ void main(unsigned long bist)
u16 pm1_sts;
#if CONFIG_COLLECT_TIMESTAMPS
tsc_t start_romstage_time;
tsc_t before_dram_time;
tsc_t after_dram_time;
tsc_t base_time = {
.lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc),
.hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0)
};
uint64_t start_romstage_time;
uint64_t before_dram_time;
uint64_t after_dram_time;
uint64_t base_time =
(uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 ||
pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc);
#endif
struct pei_data pei_data = {
pei_version: PEI_VERSION,
@ -219,7 +218,7 @@ void main(unsigned long bist)
};
#if CONFIG_COLLECT_TIMESTAMPS
start_romstage_time = rdtsc();
start_romstage_time = timestamp_get();
#endif
if (bist == 0)
@ -291,12 +290,12 @@ void main(unsigned long bist)
post_code(0x3a);
pei_data.boot_mode = boot_mode;
#if CONFIG_COLLECT_TIMESTAMPS
before_dram_time = rdtsc();
before_dram_time = timestamp_get();
#endif
sdram_initialize(&pei_data);
#if CONFIG_COLLECT_TIMESTAMPS
after_dram_time = rdtsc();
after_dram_time = timestamp_get();
#endif
post_code(0x3b);
/* Perform some initialization that must run before stage2 */

View file

@ -171,13 +171,12 @@ void main(unsigned long bist)
u16 pm1_sts;
#if CONFIG_COLLECT_TIMESTAMPS
tsc_t start_romstage_time;
tsc_t before_dram_time;
tsc_t after_dram_time;
tsc_t base_time = {
.lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc),
.hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0)
};
uint64_t start_romstage_time;
uint64_t before_dram_time;
uint64_t after_dram_time;
uint64_t base_time =
(uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 ||
pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc);
#endif
struct pei_data pei_data = {
pei_version: PEI_VERSION,
@ -224,7 +223,7 @@ void main(unsigned long bist)
};
#if CONFIG_COLLECT_TIMESTAMPS
start_romstage_time = rdtsc();
start_romstage_time = timestamp_get();
#endif
if (bist == 0)
@ -290,12 +289,12 @@ void main(unsigned long bist)
post_code(0x3a);
pei_data.boot_mode = boot_mode;
#if CONFIG_COLLECT_TIMESTAMPS
before_dram_time = rdtsc();
before_dram_time = timestamp_get();
#endif
sdram_initialize(&pei_data);
#if CONFIG_COLLECT_TIMESTAMPS
after_dram_time = rdtsc();
after_dram_time = timestamp_get();
#endif
post_code(0x3b);
/* Perform some initialization that must run before stage2 */

View file

@ -138,13 +138,12 @@ void main(unsigned long bist)
u16 pm1_sts;
#if CONFIG_COLLECT_TIMESTAMPS
tsc_t start_romstage_time;
tsc_t before_dram_time;
tsc_t after_dram_time;
tsc_t base_time = {
.lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc),
.hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0)
};
uint64_t start_romstage_time;
uint64_t before_dram_time;
uint64_t after_dram_time;
uint64_t base_time =
(uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 ||
pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc);
#endif
struct pei_data pei_data = {
@ -197,7 +196,7 @@ void main(unsigned long bist)
#if CONFIG_COLLECT_TIMESTAMPS
start_romstage_time = rdtsc();
start_romstage_time = timestamp_get();
#endif
if (bist == 0)
@ -312,12 +311,12 @@ void main(unsigned long bist)
post_code(0x39);
pei_data.boot_mode = boot_mode;
#if CONFIG_COLLECT_TIMESTAMPS
before_dram_time = rdtsc();
before_dram_time = timestamp_get();
#endif
sdram_initialize(&pei_data);
#if CONFIG_COLLECT_TIMESTAMPS
after_dram_time = rdtsc();
after_dram_time = timestamp_get();
#endif
post_code(0x3a);
/* Perform some initialization that must run before stage2 */

View file

@ -174,13 +174,12 @@ void main(unsigned long bist)
u16 pm1_sts;
#if CONFIG_COLLECT_TIMESTAMPS
tsc_t start_romstage_time;
tsc_t before_dram_time;
tsc_t after_dram_time;
tsc_t base_time = {
.lo = pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc),
.hi = pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0)
};
uint64_t start_romstage_time;
uint64_t before_dram_time;
uint64_t after_dram_time;
uint64_t base_time =
(uint64_t)pci_read_config32(PCI_DEV(0, 0x1f, 2), 0xd0) << 32 ||
pci_read_config32(PCI_DEV(0, 0x00, 0), 0xdc);
#endif
struct pei_data pei_data = {
mchbar: DEFAULT_MCHBAR,
@ -225,7 +224,7 @@ void main(unsigned long bist)
};
#if CONFIG_COLLECT_TIMESTAMPS
start_romstage_time = rdtsc();
start_romstage_time = timestamp_get();
#endif
if (bist == 0)
@ -317,12 +316,12 @@ void main(unsigned long bist)
post_code(0x39);
pei_data.boot_mode = boot_mode;
#if CONFIG_COLLECT_TIMESTAMPS
before_dram_time = rdtsc();
before_dram_time = timestamp_get();
#endif
sdram_initialize(&pei_data);
#if CONFIG_COLLECT_TIMESTAMPS
after_dram_time = rdtsc();
after_dram_time = timestamp_get();
#endif
post_code(0x3a);
/* Perform some initialization that must run before stage2 */