From d8ef9e9e9b8f7e4685fc1cbad0b1f6d82799712c Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Wed, 31 Jul 2013 15:44:37 -0700 Subject: Fix timestamp output in cbmem utility on ARM On ARM the timestamps are already in micro seconds, so no need to convert them. Signed-off-by: Stefan Reinauer Change-Id: If7363b0703e144bde62d9dab4ba845e1ace5bd18 Reviewed-on: https://gerrit.chromium.org/gerrit/63991 Reviewed-by: Vadim Bendebury Commit-Queue: Stefan Reinauer Tested-by: Stefan Reinauer Reviewed-on: http://review.coreboot.org/4313 Tested-by: build bot (Jenkins) Reviewed-by: Ronald G. Minnich --- util/cbmem/cbmem.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'util/cbmem/cbmem.c') diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index 48918b3877..520a4866e7 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -243,6 +243,7 @@ static int parse_cbtable(u64 address) return found; } +#if defined(__i386__) || defined(__x86_64__) /* * read CPU frequency from a sysfs file, return an frequency in Kilohertz as * an int or exit on any error. @@ -282,6 +283,32 @@ static u64 get_cpu_freq_KHz(void) exit(1); } +/* On x86 platforms timestamps are stored + * in CPU cycles (from rdtsc). Hence the + * timestamp divider is the CPU frequency + * in MHz. + */ +u64 arch_convert_raw_ts_entry(u64 ts) +{ + static u64 cpu_freq_mhz = 0; + + if (!cpu_freq_mhz) + cpu_freq_mhz = get_cpu_freq_KHz() / 1000; + + return ts / cpu_freq_mhz; +} + +#else + +/* On non-x86 platforms the timestamp entries + * are not in clock cycles but in usecs + */ +u64 arch_convert_raw_ts_entry(u64 ts) +{ + return ts; +} +#endif + /* * Print an integer in 'normalized' form - with commas separating every three * decimal orders. The 'comma' parameter indicates if a comma is needed after @@ -308,7 +335,6 @@ static void print_norm(u64 v, int comma) static void dump_timestamps(void) { int i; - u64 cpu_freq_MHz = get_cpu_freq_KHz() / 1000; struct timestamp_table *tst_p; if (timestamps.tag != LB_TAG_TIMESTAMPS) { @@ -324,12 +350,11 @@ static void dump_timestamps(void) const struct timestamp_entry *tse_p = tst_p->entries + i; printf("%4d:", tse_p->entry_id); - print_norm(tse_p->entry_stamp / cpu_freq_MHz, 0); + print_norm(arch_convert_raw_ts_entry(tse_p->entry_stamp), 0); if (i) { printf(" ("); - print_norm((tse_p->entry_stamp - - tse_p[-1].entry_stamp) / - cpu_freq_MHz, 0); + print_norm(arch_convert_raw_ts_entry(tse_p->entry_stamp + - tse_p[-1].entry_stamp), 0); printf(")"); } printf("\n"); -- cgit v1.2.3