日期:2014-05-16  浏览次数:20713 次

arm11下oprofile的使用
有没人在arm11下用过Oprofile?
kernel:2.6.21.5
board:s3m6400
cpu:arm1176jz

问题:
#opcontrol -e ###:##:#####//设置enent
eval: line 1: timer: not found
You cannot specify any performance counter events
because OProfile is in timer mode.

/dev/Oprofile/cpu_type :timer

我已参照maemo上的800介绍patch了Oprofile对ARM11的支持,但还是由于模式为timer interrupt,所以无法获得cpu事件,
其实也就是所有事件都无法setup.监测程序的函数调用什么的都正常.只是事件无法绑定.
有没人解决过这个问题,万分感谢.
ps:Oprofile已交叉编译,objdump,objcopy都是交叉编译的可用.kernel的Profile已打开.

------解决方案--------------------
樓主看看這個有用不
--------------------------------------------------------------
4.2. OProfile in RTC mode
Note

This section applies to 2.2/2.4 kernels only.

Some CPU types do not provide the needed hardware support to use the hardware performance counters. This includes some laptops, classic Pentiums, and other CPU types not yet supported by OProfile (such as Cyrix). On these machines, OProfile falls back to using the real-time clock interrupt to collect samples. This interrupt is also used by the rtc module: you cannot have both the OProfile and rtc modules loaded nor the rtc support compiled in the kernel.

RTC mode is less capable than the hardware counters mode; in particular, it is unable to profile sections of the kernel where interrupts are disabled. There is just one available event, "RTC interrupts", and its value corresponds to the number of interrupts generated per second (that is, a higher number means a better profiling resolution, and higher overhead). The current implementation of the real-time clock supports only power-of-two sampling rates from 2 to 4096 per second. Other values within this range are rounded to the nearest power of two.

You can force use of the RTC interrupt with the force_rtc=1 module parameter.

Setting the value from the GUI should be straightforward. On the command line, you need to specify the event to opcontrol, e.g. :

opcontrol --event=RTC_INTERRUPTS:256
4.3. OProfile in timer interrupt mode
Note

This section applies to 2.6 kernels and above only.

In 2.6 kernels on CPUs without OProfile support for the hardware performance counters, the driver falls back to using the timer interrupt for profiling. Like the RTC mode in 2.4 kernels, this is not able to profile code that has interrupts disabled. Note that there are no configuration parameters for setting this, unlike the RTC and hardware performance counter setup.

You can force use of the timer interrupt by using the timer=1 module parameter (or oprofile.timer=1 on the boot command line if OProfile is built-in).

原文連結:
http://oprofile.sourceforge.net/doc/detailed-parameters.html#rtc
------解决方案--------------------
oprofile 在Linux 上分两部分,一个是内核模块(oprofile.ko),一个为用户空间的守护进程(oprofiled)。前者负责访问性能计数器或者注册基于时间采样的函数(使用register_timer_hook注册之,使时钟中断处理程序最后执行profile_tick 时可以访问之),并采样置于内核的缓冲区内。后者在后台运行,负责从内核空间收集数据,写入文件。


1. kernel patch

完整之 patch 位于: http://people.openrays.org/~comcat/patch/patch-2.6.18-oprofile-comcat

主要是当计数器溢出(31位为1)时,触发IP6 中断,其处理程序的 godson2e_pmc_handler 的编写。

注意一下在用户空间设置的样本计数,在内核空间是怎么处理的。例如使用

opcontrol --setup --event=CYCLES:1000 设置样本计数为1000,

则计数器被初始化的值为0x8000 0000 - 1000
即: CYCLES 事件发生 1000 次后,计数溢出,触发处理程序 godson2e_pmc_handler 添加一个样本 add_sample。

diff -uNr src/arch/mips/oprofile/op_model_godson2e.c pmc/arch/mips/oprofile/op_model_godson2e.c
--- src/arch/mips/oprofile/op_model_godson2e.c 1970-01-01 08:00:00.000000000 +0800
+++ pmc/arch/mips/oprofile/op_model_godson2e.c 2007-05-25 14:59:54.000000000 +0800
@@ -0,0 +1,171 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the