1/** 2 * \file 3 * \brief Bench library initialization. 4 */ 5 6/* 7 * Copyright (c) 2007, 2008, 2009, 2010, ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#include <barrelfish/barrelfish.h> 16#include <bench/bench.h> 17#include <bench/bench_arch.h> 18#include <barrelfish/sys_debug.h> 19 20bool rdtscp_flag = false; 21static uint64_t tscperms; 22 23/** 24 * \brief Check if rdtscp instruction is supported 25 */ 26void bench_arch_init(void) 27{ 28 uint32_t eax, ebx, ecx, edx; 29 // Check for rdtscp instruction 30 cpuid(0x80000001, &eax, &ebx, &ecx, &edx); 31 if ((edx >> 27) & 1) { 32 rdtscp_flag = true; 33 } else { 34 rdtscp_flag = false; 35 } 36 37 errval_t err = sys_debug_get_tsc_per_ms(&tscperms); 38 assert(err_is_ok(err)); 39} 40 41uint64_t bench_tsc_to_ms(cycles_t tsc) 42{ 43 return tsc / tscperms; 44} 45 46uint64_t bench_tsc_to_us(cycles_t tsc){ 47 return tsc / (tscperms/1000); 48} 49 50uint64_t bench_tsc_per_us(void) 51{ 52 return tscperms/1000; 53} 54 55uint64_t bench_tsc_per_ms(void) 56{ 57 return tscperms; 58} 59