从内存映射寄存器读取

0 c c++ benchmarking performancecounter

我正在使用的处理器架构有一个时间标签计数器,我想读出来进行性能测量.时间标记计数器的内存映射到地址0x90000008.我使用以下例程从时间计数器读取值,但打印输出的差异始终为零.谁知道我错过了什么?

char* const ADDR = (char *) 0x90000008;

unsigned long cycle_count_val() {

   unsigned long res;

   asm volatile (

   "set ADDR, %%l0           \n\t"
   "ld [%%l0], %0            \n\t"

   : "=r" (res)
   :
   : "%l0"
  );

  return res;
} 

....
unsigned long start = cycle_count_val(); 
execute_benchmark();
unsigned long end = cycle_count_val();

printf("Benchmark performance(in clock cycles) = %ld \r\n", end-start);
Run Code Online (Sandbox Code Playgroud)

非常感谢你的帮助,菲尔

Ale*_*own 6

我认为你不需要求助 - 为什么你不能只读:

uint32_t tbr = (*((uint32_t volatile *) 0x90000008))
Run Code Online (Sandbox Code Playgroud)