Skip to content

Commit 3e27cd9

Browse files
committed
benchmark: add cycle counter reading for x86
This adds the physical TSC reading for CPU utilisation measurement. Signed-off-by: Terry Bai <tianyi.bai@unsw.edu.au>
1 parent afdf76f commit 3e27cd9

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

benchmark/idle.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ struct bench *b;
2020

2121
static inline uint64_t read_cycle_count()
2222
{
23-
uint64_t cycle_count;
23+
uint64_t cycle_count = 0;
2424
#if defined(CONFIG_ARCH_ARM)
2525
SEL4BENCH_READ_CCNT(cycle_count);
2626
#elif defined(CONFIG_ARCH_RISCV)
2727
asm volatile("rdcycle %0" : "=r"(cycle_count));
2828
#elif defined(CONFIG_ARCH_X86_64)
29-
// Do nothing only for build atm
29+
uint32_t lo, hi, unused;
30+
__asm__ __volatile__("rdtscp" : "=a"(lo), "=d"(hi), "=c"(unused));
31+
__asm__ __volatile__("lfence" ::: "memory");
32+
cycle_count = ((uint64_t)hi << 32) | lo;
3033
#else
3134
#error "read_cycle_count: unsupported architecture"
3235
#endif

include/sddf/benchmark/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* on non-benchmarking configurations.
1616
* This defines whether we actually try to benchmark, setup the PMU etc.
1717
*/
18-
#if defined(CONFIG_ENABLE_BENCHMARKS) && (defined(CONFIG_ARCH_ARM) || defined(CONFIG_ARCH_RISCV))
18+
#if defined(CONFIG_ENABLE_BENCHMARKS) && (defined(CONFIG_ARCH_ARM) || defined(CONFIG_ARCH_RISCV) || defined(CONFIG_ARCH_X86_64))
1919
#define ENABLE_BENCHMARKING 1
2020
#else
2121
#define ENABLE_BENCHMARKING 0

0 commit comments

Comments
 (0)