使用硬件计数器测量 ARM Cortex-A8 上的执行时间 [英] Measure executing time on ARM Cortex-A8 using hardware counter
问题描述
我使用的是 Exynos 3110 处理器(1 GHz 单核 ARM Cortex-A8,例如用于 Nexus S)并尝试测量特定功能的执行时间.我在 Nexus S 上运行 Android 4.0.3.我尝试了
I'm using a Exynos 3110 processor (1 GHz Single-core ARM Cortex-A8, e.g. used in the Nexus S) and try to measure execution times of particular functions. I have an Android 4.0.3 running on the Nexus S. I tried the method from
[1] 如何在 ARM Cortex-A8 处理器中测量程序执行时间?
我加载了内核模块以允许在用户模式下读取寄存器值.我正在使用以下程序来测试计数器:
I loaded the kernel module to allow reading the register values in user mode. I am using the following program to test the counter:
static inline unsigned int get_cyclecount (void)
{
unsigned int value;
// Read CCNT Register
asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(value));
return value;
}
static inline void init_perfcounters (int do_reset, int enable_divider)
{
// in general enable all counters (including cycle counter)
int value = 1;
// peform reset:
if (do_reset)
{
value |= 2; // reset all counters to zero.
value |= 4; // reset cycle counter to zero.
}
if (enable_divider)
value |= 8; // enable "by 64" divider for CCNT.
value |= 16;
// program the performance-counter control-register:
asm volatile ("MCR p15, 0, %0, c9, c12, 0\t\n" :: "r"(value));
// enable all counters:
asm volatile ("MCR p15, 0, %0, c9, c12, 1\t\n" :: "r"(0x8000000f));
// clear overflows:
asm volatile ("MCR p15, 0, %0, c9, c12, 3\t\n" :: "r"(0x8000000f));
}
int main(int argc, char **argv)
{
int i = 0;
unsigned int start = 0;
unsigned int end = 0;
printf("Hello Counter\n");
init_perfcounters(1,0);
for(i=0;i<10;i++)
{
start = get_cyclecount();
sleep(1); // sleep one second
end = get_cyclecount();
printf("%u %u %u\n", start, end, end - start);
}
return 0;
}
根据[1],计数器随着每个时钟周期递增.我将 scaling_governor 切换到用户空间并将 CPU 频率设置为 1GHz,以确保时钟频率不会被 Android 更改.
According to [1] the counter is incremented with each clock cycle. I switched the scaling_governor to userspace and set the CPU frequency to 1GHz to make sure that the clock frequency is not change by Android.
如果我运行程序,会执行 1 秒的睡眠,但计数器值在 ~200e6 的范围内,而不是预期的 1e9.我在这里缺少任何特定于处理器的东西吗?计数器的时钟频率与处理器的时钟频率不同吗?
If I run the program the sleeps of 1 second are executed, but the counter values are in the range of ~200e6, instead of the expected 1e9. Is there anything processor specific I am missing here? Is the clock rate of the counters different to the clock rate of the processor ?
推荐答案
查看这个教授的页面:http://users.ece.utexas.edu/~valvano/arm/他有多个与时间/周期性定时器/测量执行时间有关的完整示例程序,它们是为基于 ARM Cortex-M3 的微控制器开发的.我希望这与您正在从事的工作没有太大不同.我想你会对 Performance.c
Check out this professor's page: http://users.ece.utexas.edu/~valvano/arm/ He has multiple full example programs that have to do with time/periodic-timers/measuring-execution-time, they are developed for ARM Cortex-M3 based microcontrollers. I hope this isn't very different from what you are working on. I think you would be interested in Performance.c
这篇关于使用硬件计数器测量 ARM Cortex-A8 上的执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!