我正在使用一个名为i.MX515的基于ARM Cortex-A8的处理器.有Linux Ubuntu 9.10发行版.我正在运行一个用C编写的非常大的应用程序,我正在利用gettimeofday();函数来衡量我的应用程序所需的时间.
main()
{
gettimeofday(start);
....
....
....
gettimeofday(end);
}
Run Code Online (Sandbox Code Playgroud)
这个方法足以让我看看我的应用程序块占用了多少时间.但是,现在,我正在尝试使用gettimeofday()计算时间的方法彻底优化我的代码,我看到连续运行之间有很多波动(在我的优化之前和之后运行),所以我不能确定实际执行时间,从而影响我的改进.
谁能告诉我应该怎么做?
如果通过访问循环计数器(在ARM网站上为Cortex-M3建议的想法),任何人都可以向我指出一些代码,它给出了我在Cortex-A8上访问定时器寄存器时必须遵循的步骤吗?
如果这种方法不是很准确,那么请提出一些替代方案.
谢谢
跟进1:在Code Sorcery上编写了以下程序,生成了可执行文件,当我尝试在主板上运行时,我得到了 - 非法指令消息:(
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 (int32_t do_reset, int32_t enable_divider)
{
// in general enable all counters (including cycle counter)
int32_t value = 1;
// …Run Code Online (Sandbox Code Playgroud) 我使用的是Exynos 3110处理器(1 GHz单核ARM Cortex-A8,例如在Nexus S中使用),并尝试测量特定功能的执行时间.我在Nexus S上运行了Android 4.0.3.我尝试了这个方法
[1] 如何测量ARM Cortex-A8处理器中的程序执行时间?
我加载了内核模块以允许在用户模式下读取寄存器值.我使用以下程序来测试计数器:
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 …Run Code Online (Sandbox Code Playgroud)