1/** 2 * \file 3 * \brief Architecture-specific microbenchmarks. 4 */ 5 6/* 7 * Copyright (c) 2007, 2008, 2009, 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, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#include <kernel.h> 16#include <microbenchmarks.h> 17#include <x86.h> 18 19// address space switch (mov to cr3) 20static int asswitch_func(struct microbench *mb) 21{ 22 uint64_t start, end; 23 uint64_t asvalue; 24 25 // Put the cr3 value in the asvalue register for now 26 __asm__ __volatile__("mov %%cr3, %0" : "=r" (asvalue)); 27 28 start = rdtscp(); 29 for (int i = 0; i < MICROBENCH_ITERATIONS; i++) { 30 __asm__ __volatile__( 31 "mov %0, %%cr3" 32 : 33 : "r" (asvalue)); 34 } 35 end = rdtscp(); 36 37 mb->result = end - start; 38 39 return 0; 40} 41 42static int wrmsr_func(struct microbench *mb) 43{ 44 uint64_t start, end; 45 46 start = rdtscp(); 47 for (int i = 0; i < MICROBENCH_ITERATIONS; i++) { 48 wrmsr(MSR_IA32_FSBASE, 0); 49 } 50 end = rdtscp(); 51 52 mb->result = end - start; 53 54 return 0; 55} 56 57struct microbench arch_benchmarks[] = { 58 { 59 .name = "wrmsr", 60 .run_func = wrmsr_func 61 }, 62 { 63 .name = "address space switch (mov to cr3)", 64 .run_func = asswitch_func 65 } 66}; 67 68size_t arch_benchmarks_size = sizeof(arch_benchmarks) / sizeof(struct microbench); 69