Chinaunix首页 | 论坛 | 博客
  • 博客访问: 423088
  • 博文数量: 115
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 393
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-26 12:10
个人简介

踏实做事,认真做人

文章分类

全部博文(115)

文章存档

2017年(1)

2016年(2)

2015年(14)

2014年(63)

2013年(35)

分类: 嵌入式

2013-06-09 11:37:20

Platform:ARM A9
Linux:3.0.8

Notes:
1)Android4.0.x external support oprofile,after android compile successfully,it will generate opcontrol (oprofile CLI) and oprofiled(daemon)
2)cross-compile oprofile with static link which generate opreport for Target platform for analysis oprofile report

Porting Guide:
1)
--- /work/kernel/drivers/oprofile/timer_int.c 2013-02-26 11:08:04.712305138 +0800
+++ drivers/oprofile/timer_int.c 2013-06-08 10:07:54.743559350 +0800
@@ -97,6 +97,50 @@
  .notifier_call = oprofile_cpu_notify,
 };
 
+#ifndef OP_COUNTER_H
+#define OP_COUNTER_H
+
+/* Per performance monitor configuration as set via
+ * oprofilefs.
+ */
+struct op_counter_config {
+ unsigned long count ;
+ unsigned long enabled;
+ unsigned long event;
+ unsigned long unit_mask;
+ unsigned long kernel;
+ unsigned long user;
+};
+
+#endif /* OP_COUNTER_H */
+
+struct op_counter_config dummy_config = {.count = 4};
+
+static int op_create_files(struct super_block *sb, struct dentry *root)
+{
+ unsigned int i;
+
+ for (i = 0; i < 1; i++) {
+  struct dentry *dir;
+  char buf[4];
+
+  snprintf(buf, sizeof buf, "%d", i);
+  dir = oprofilefs_mkdir(sb, root, buf);
+  oprofilefs_create_ulong(sb, dir, "enabled",
+      &dummy_config.enabled);
+  oprofilefs_create_ulong(sb, dir, "event", &dummy_config.event);
+  oprofilefs_create_ulong(sb, dir, "count", &dummy_config.count);
+  oprofilefs_create_ulong(sb, dir, "unit_mask",
+      &dummy_config.unit_mask);
+  oprofilefs_create_ulong(sb, dir, "kernel",
+      &dummy_config.kernel);
+  oprofilefs_create_ulong(sb, dir, "user", &dummy_config.user);
+ }
+
+ return 0;
+}
+
+
 int oprofile_timer_init(struct oprofile_operations *ops)
 {
  int rc;
@@ -104,12 +148,13 @@
  rc = register_hotcpu_notifier(&oprofile_cpu_notifier);
  if (rc)
   return rc;
- ops->create_files = NULL;
+ ops->create_files = op_create_files;
  ops->setup = NULL;
  ops->shutdown = NULL;
  ops->start = oprofile_hrtimer_start;
  ops->stop = oprofile_hrtimer_stop;
  ops->cpu_type = "timer";
+ printk(KERN_INFO "oprofile: using timer interrupt.\n");
  return 0;
 }
 

2)
--- /work/kernel/drivers/oprofile/oprof.c 2013-02-26 11:08:04.712305138 +0800
+++ drivers/oprofile/oprof.c 2013-06-04 16:10:29.862179338 +0800
@@ -33,7 +33,8 @@
    0 - use performance monitoring hardware if available
    1 - use the timer int mechanism regardless
  */
-static int timer = 0;
+/* static int timer = 0; */
+static int timer = 1;
 
 int oprofile_setup(void)
 {

3)Kernel OPROFILE support
CONFIG_PROFILING=y
CONFIG_OPROFILE=y
CONFIG_HAVE_OPROFILE=y

4)copy vmlinux to /system/xxx/ and helloworld.ko to target
5)in Target platform,./start_oprofile.sh

#!/system/bin/sh
#.oprofile directory
mount -o remount,rw system /system

if [ ! -d "/dev/oprofile" ]; then
 cd  /dev
 mkdir oprofile
 cd /
 mount -t oprofilefs nodev /dev/oprofile
fi

#helloworld symbolic for opreport
if [ ! -h "/helloworld" ]; then
 mount -o remount,rw rootfs /
 cd  /system/xxx/
 busybox ln -s /system/xxx/helloworld.ko /helloworld
fi

KERNEL_BEG=`busybox grep " _stext" /proc/kallsyms | busybox awk '{print $1}'`
KERNEL_END=`busybox grep " _etext" /proc/kallsyms | busybox awk '{print $1}'`

chmod 777 /system/oprofile/bin/
echo 16 > /dev/oprofile/backtrace_depth
opcontrol --shutdown
opcontrol --reset
opcontrol --setup
opcontrol --vmlinux=/system/xxx/vmlinux --callgraph=16 --kernel-range=0x$KERNEL_BEG,0x$KERNEL_END --event=CPU_CYCLES:10000::1:0
opcontrol --start

6)insmod helloworld.ko
7)sleep 180s,use app to acces driver ,samples directory should exist {kern}/helloworld directory
8)opcontrol --stop
9) ./opreport image:/helloworld --session-dir=/data/oprofile/ -g -d -l --output-file /system/xxx/report.txt

阅读(1991) | 评论(0) | 转发(0) |
0

上一篇:Linux Perf

下一篇:单向度的人

给主人留下些什么吧!~~