http://liuluheng.github.io/wiki/public_html/Embedded-System/Cortex-A8/Performance%20Monitor%20Control%20Register.html

目录

enable the perfromance counter

c9, User Enable Register

c9, Interrupt Enable Clear Register

access the cycle-counter from the user-mode

c9, Cycle Count Register

c9, Performance Monitor Control Register

c9, Count Enable Set Register

c9, Overflow Flag Status Register

How to use it

Footnotes:


The purpose of the Performance MoNitor Control (PMNC) Register is to control the operation of the four Performance Monitor Count Registers, and the Cycle Counter Register:1

The PMNC Register is:

  • a read/write register common to Secure and Nonsecure states
  • accessible as determined by c9, User Enable Register.2

enable the perfromance counter

Accessing the performance counters isn't difficult, but you have to enable them from kernel-mode. By default the counters are disabled.

In a nutshell you have to execute the following two lines inside the kernel. Either as a loadable module or just adding the two lines somewhere in the board-init will do:

/* enable user-mode access to the performance counter*/asm ("MCR p15, 0, %0, C9, C14, 0\n\t" :: "r"(1)); /* disable counter overflow interrupts (just in case)*/asm ("MCR p15, 0, %0, C9, C14, 2\n\t" :: "r"(0x8000000f));

Once you did this the cycle counter will start incrementing for each cycle. Overflows of the register will go unnoticed and don't cause any problems (except they might mess up your measurements).

c9, User Enable Register

asm ("MCR p15, 0, %0, C9, C14, 0\n\t" :: "r"(1));

The purpose of the USER ENable (USEREN) Register is to enable User mode to have access to the Performance Monitor Registers.3

To access the USEREN Register, read or write CP15 with:

MRC p15, 0, <Rd>, c9, c14, 0 ; Read USEREN Register

MCR p15, 0, <Rd>, c9, c14, 0 ; Write USEREN Register

c9, Interrupt Enable Clear Register

asm ("MCR p15, 0, %0, C9, C14, 2\n\t" :: "r"(0x8000000f));

The purpose of the INTerrupt ENable Clear (INTENC) Register is to determine if any of the Performance Monitor Count Registers, PMCNT0-PMCNT3 and CCNT, generate an interrupt on overflow.4

To access the INTENC Register, read or write CP15 with:

MRC p15, 0, <Rd>, c9, c14, 2 ; Read INTENC Register

MCR p15, 0, <Rd>, c9, c14, 2 ; Write INTENC Register

access the cycle-counter from the user-mode

Now you want to access the cycle-counter from the user-mode:

We start with a function that reads the register:

static inline unsigned int get_cyclecount (void)
{unsigned int value;// Read CCNT Registerasm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(value));  return value;
}

And you most likely want to reset and set the divider as well:

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;// 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));
}

do_reset will set the cycle-counter to zero. Easy as that.

enable_diver will enable the 1/64 cycle divider. Without this flag set you'll be measuring each cycle. With it enabled the counter gets increased for every 64 cycles. This is useful if you want to measure long times that would otherwise cause the counter to overflow.

c9, Cycle Count Register

asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(value));

The purpose of the Cycle CouNT (CCNT) Register is to count the number of clock cycles since the register was reset. 5

To access the CCNT Register, read or write CP15 with:

MRC p15, 0, <Rd>, c9, c13, 0 ; Read CCNT Register MCR p15, 0, <Rd>, c9, c13, 0 ; Write CCNT Register

c9, Performance Monitor Control Register

asm volatile ("MCR p15, 0, %0, c9, c12, 0\t\n" :: "r"(value));

To access the PMNC Register, read or write CP15 with:1

MRC p15, 0, <Rd>, c9, c12, 0 ; Read PMNC Register

MCR p15, 0, <Rd>, c9, c12, 0 ; Write PMNC Register

c9, Count Enable Set Register

asm volatile ("MCR p15, 0, %0, c9, c12, 1\t\n" :: "r"(0x8000000f)); The purpose of the CouNT ENable Set (CNTENS) Register is to enable or disable any of the Performance Monitor Count Registers.

When reading this register, any enable that reads as 0 indicates the counter is disabled. Any enable that reads as 1 indicates the counter is enabled.

When writing this register, any enable written with a value of 0 is ignored, that is, not updated. Any enable written with a value of 1 indicates the counter is enabled.6

To access the CNTENS Register, read or write CP15 with:

MRC p15, 0, <Rd>, c9, c12, 1 ; Read CNTENS Register

MCR p15, 0, <Rd>, c9, c12, 1 ; Write CNTENS Register

c9, Overflow Flag Status Register

asm volatile ("MCR p15, 0, %0, c9, c12, 3\t\n" :: "r"(0x8000000f)); The purpose of the Overflow Flag Status (FLAG) Register is to enable or disable any of the performance monitor counters producing an overflow flag.7

To access the FLAG Register, read or write CP15 with:

MRC p15, 0, <Rd>, c9, c12, 3 ; Read FLAG Register

MCR p15, 0, <Rd>, c9, c12, 3 ; Write FLAG Register

How to use it

// init counters:init_perfcounters (1, 0); // measure the counting overhead:unsigned int overhead = get_cyclecount();overhead = get_cyclecount() - overhead;    unsigned int t = get_cyclecount();// do some stuff here..call_my_function();t = get_cyclecount() - t;printf ("function took exactly %d cycles (including function call)", t - overhead);

Should work on all Cortex-A8 CPUs.

some notes:

Using these counters you'll measure the exact time between the two calls to get_cyclecount() including everything spent in other processes or in the kernel. There is no way to restrict the measurement to your process or a single thread.

Also calling get_cyclecount() isn't free. It will compile to a single asm-instruction, but moves from the co-processor will stall the entire ARM pipeline. The overhead is quite high and can skew your measurement. Fortunately the overhead is also fixed, so you can measure it and subtract it from your timings.

In this example I did that for every measurement. Don't do this in practice. An interrupt will sooner or later occur between the two calls and skew your measurements even further. I suggest that you measure the overhead a couple of times on an idle system, ignore all outsiders and use a fixed constant instead.8

Footnotes:

1

c9, Performance Monitor Control Register

2

Cortex-A8 Technical Reference Manua

3

c9, User Enable Register

4

c9, Interrupt Enable Clear Register

5

c9, Cycle Count Register

6

c9, Count Enable Set Register

7

c9, Overflow Flag Status Register

8

stackoverflow

Author: Shi Shougang

Created: 2015-03-05 Thu 23:20

Emacs 24.3.1 (Org mode 8.2.10)

Validate

c9, Performance Monitor Control Register相关推荐

  1. 使用Windows Performance Monitor进行SQL Server性能调整

    Windows Performance Monitor basics article, we described the most important Windows Performance Moni ...

  2. SQL Server2005重装Performance Monitor Counter 的问题解决

    SQL Server2005重装Performance Monitor Counter 的问题解决 SQL Server2005重装Performance Monitor Counter Requir ...

  3. 【Paper】2012_Design of high performance multimedia control system for UAV/UGV based on SoC/FPGA Core

    Design of high performance multimedia control system for UAV/UGV based on SoC/FPGA Core OpenWrt Open ...

  4. Orion Network Performance Monitor 软件在网络管理中的应用

    Orion Network Performance Monitor 软件在网络管理中的应用 Orion Network Performance Monitor是完全的带宽性能和故障管理软件,从路由器. ...

  5. 使用performance monitor 查看 每一个cpu core的cpu time

    使用performance monitor 查看 每一个cpu core的cpu time: 打开performance monitor,添加 counter 如下 运行一段cpu bound 的代码 ...

  6. 利用vSAN Performance Monitor可视化监控vSAN性能指标

    利用vSAN Performance Monitor可视化监控vSAN性能指标 https://blog.51cto.com/4674157/2608479 说明: vSAN Performance ...

  7. 借助zabbix和mysql performance monitor模板实现mysql数据库的监控

    1.安装mpm需要的相关依赖包:[保险起见,agent端也安装下面的依赖包] [root@client141 ~]# yum -y install perl-File-Which perl-libww ...

  8. performance monitor for mysql_借助zabbix和mysqlperformancemonitor模板实现mysql数据库的监控...

    更多博文请关注:没有伞的孩子必须努力奔跑(www.xuchanggang.cn)1.安装mpm需要的相关依赖包:[保险起见,agent端也安装下面的依赖包][root@client141~]#yum- ...

  9. 性能监视器(Performance Monitor)指标说明

    性能监视器(Performance Monitor)和任务管理器(Task Manager)是Windows观察内存使用的工具: 1. 性能监视器的"Working Set":本进 ...

最新文章

  1. 盘点 15 个好用的 API 接口管理神器
  2. 初等数论--整除--带余除法
  3. 如何在 ASP.NET Core 中使用 Quartz.NET 执行任务调度
  4. 实例29:python
  5. 计算机专业能不能转音乐系,中国音乐学院可以转专业吗,中国音乐学院新生转专业政策...
  6. 一种简单的可控并发粒度的TaskScheduler的实现
  7. 讲座笔记:图匹配 Graph Matching 问题 | 机器学习组合优化
  8. Codeforces_448C 分治
  9. springboot开启缓存_springBoot与缓存使用
  10. Linux--vmlinuz、vmlinux、initrd
  11. linux用vi查找字符串替换,Linux中vi进行字符替换
  12. 如何反编译微信小程序前端,30分钟教你学会
  13. ENVI 工具箱汉翻译汉化
  14. git gui :Updating the Git index failed. A rescan will be automatically started to res
  15. 各版本iphone重要参数
  16. read函数和write函数
  17. 3D打印机Marlin 固件 改12864引脚 不显示白屏的问题
  18. 应用检查后台启动权限方法(小米官方给出的)
  19. 使用Prometheus监控web站点及证书过期
  20. 从0开始一步一步部署walle

热门文章

  1. Xpath string()提取多个子节点中的文本
  2. Second easyui框架学习
  3. 每天学一点ubuntu指令
  4. 数据库设计 Assignment 02
  5. css实现文字太长,显示省略号
  6. 手机程序开发和测试关注点整理
  7. python编程胡牌将是什么意思_OpenCV+Python识别车牌和字符分割的实现
  8. c# linux 效率,c# – linux / mono上的HTTP性能
  9. nginx反代web页面没有正常显示_web漏洞-SSI注入漏洞深入详解
  10. 计算机专业术语的通俗解释,计算机专业术语解释