From d00f180812279144ce09e2ad046973f3a384456c Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Mon, 13 Jul 2015 16:53:50 +0200 Subject: cbmem: convert x86 timestamps on OpenBSD Change-Id: I16bfe42a00d73209307655601edaa3a8ffc9c902 Signed-off-by: Patrick Georgi Reviewed-on: http://review.coreboot.org/10905 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- util/cbmem/cbmem.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'util') diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index 3bc0fcd1a7..aa73c6a67a 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -35,6 +35,11 @@ #include #include +#ifdef __OpenBSD__ +#include +#include +#endif + #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define MAP_BYTES (1024*1024) #define IS_ENABLED(x) (defined (x) && (x)) @@ -294,7 +299,7 @@ static int parse_cbtable(u64 address, size_t table_size) return found; } -#if defined(__i386__) || defined(__x86_64__) +#if defined(linux) && (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. @@ -349,6 +354,18 @@ u64 arch_convert_raw_ts_entry(u64 ts) return ts / cpu_freq_mhz; } +#elif defined(__OpenBSD__) && (defined(__i386__) || defined(__x86_64__)) +u64 arch_convert_raw_ts_entry(u64 ts) +{ + int mib[2] = { CTL_HW, HW_CPUSPEED }; + static int value = 0; + size_t value_len = sizeof(value); + + if ((value == 0) && (sysctl(mib, 2, &value, &value_len, NULL, 0) == -1)) + return ts; + + return ts / value; +} #else /* On non-x86 platforms the timestamp entries -- cgit v1.2.3