字体设计网站有哪些免费,html界面模板,wordpress 网址导航页,可以写代码的网站有哪些问题ARM 的时钟周期计数保存在PMCCNTR 寄存器#xff0c;不像x86用户态可以直接读取#xff0c;需内核态使能#xff0c;一种是在内核中使能#xff0c;比如init#xff0c;比较简单的是在模块中使能。 
本来写了两个#xff0c;arm32一个#xff0c;arm64一个#xff0c;方…ARM 的时钟周期计数保存在PMCCNTR 寄存器不像x86用户态可以直接读取需内核态使能一种是在内核中使能比如init比较简单的是在模块中使能。 
本来写了两个arm32一个arm64一个方便对比合在了一起。 只测试了32位cortex-a9双核, 还有 个64位a76 a55。 enpmu.c 
#include linux/module.h
#include linux/kernel.h
#include linux/smp.hMODULE_AUTHOR(cn);
MODULE_LICENSE(GPL);
MODULE_VERSION(0.0);#if !defined(__arm__)  !defined(__aarch64__)
#error module only support arm32 arm64.
#endif#ifdef __aarch64__
typedef unsigned long ulint;  //64
#elif defined __arm__
typedef unsigned int ulint;  //32
#endifstatic void en_access(void*)
{ulint i0,tmpvar0;#ifdef __aarch64__asm volatile(mrs %0, mpidr_el1 :r(i));i   (i 8) 0xff;
#elseasm volatile(mrc p15,0,%0,c0,c0,5 :r(i));i   i  3;
#endif  asm volatile (  
#ifdef __aarch64__mrs %0,pmuserenr_el0 \norr %0, %0,%1 \nmsr pmuserenr_el0,%0
#elsemrc p15, 0, %0, c9, c14, 0 \norr %0, %0,%1 \nmcr p15, 0, %0, c9, c14, 0 \n
#endif:r(tmpvar):r(0xf));asm volatile(   
#ifdef __aarch64__mrs %0, pmcr_el0 \norr %0, %0, %1 \n //32  0x41bic %0, %0, %2 \nmsr pmcr_el0,%0 \n
#elsemrc p15, 0, %0, c9, c12, 0 \norr %0, %0,%1 \nbic %0, %0, %2 \nmcr p15, 0, %0, c9, c12, 0 \n
#endif:r(tmpvar):r(0x81),r(0x28));asm volatile(   
#ifdef __aarch64__msr pmcntenset_el0,%1 \nmrs %0, cntvct_el0 \n
#elsemcr p15, 0, %1, c9, c12, 1 \nmrc p15, 0, %0, c9, c13, 0 \n
#endif:r(tmpvar) :r(0xffffffff));printk(core %lu tsc  %lx,(unsigned long)i, (unsigned long)tmpvar );
}static void restore_access(void*) {ulint i,tmpvar0;
#ifdef __aarch64__asm volatile( mrs %0, mpidr_el1: r(i));i   (i  8)0xff;
#elseasm volatile(mrc p15,0,%0,c0,c0,5 \n : r(i));i   i  3;
#endifasm volatile (
#ifdef __aarch64__mrs %0,pmcr_el0 \nbic %0,%0, %2 \nmsr pmcr_el0,%0\nmsr pmuserenr_el0,%1\nmrs %0, cntvct_el0 \n
#elsemrc p15, 0, %0, c9, c14, 0 \nbic %0,%0, %2 \nmcr p15, 0, %0, c9, c14, 0 \nmcr p15, 0, %1, c9, c12, 1 \nmrc p15, 0, %0, c9, c13, 0 \n
#endif:r (tmpvar):r(0),r(1));printk(un core %lx tsc  %lx,(unsigned long)i, (unsigned long)tmpvar );}
static int __init  start(void) 
{ on_each_cpu(en_access, NULL, 1);printk(KERN_INFO pmu access enabled\n); return 0; 
} static void __exit stop(void) 
{ on_each_cpu(restore_access, NULL, 1);printk(KERN_INFO pmu access disabled\n); 
} module_init(start); 
module_exit(stop);  
Makefile 
obj-m  enpmu.o
all:make -C /lib/modules/$(shell uname -r)/build/ M$(PWD) modules
clean:make -C /lib/modules/$(shell uname -r)/build M$(PWD) clean直接 
makeinsmod enpmu.ko
rmmod enpmu然后就可以读取了 以下arm32 arm64 x86_64读取方法 test.c 
#include stdio.h
#ifndef __arm__
typedef unsigned long ulint;
#else
typedef unsigned int ulint;
#endif
int main()
{ulint ct  0;
#ifdef __aarch64__asm volatile(mrs %0, cntvct_el0 :r(ct));
#elif defined __arm__asm volatile(mrc p15,0,%0, c9, c13, 0:r(ct));
#elif defined __x86_64__asm volatile(rdtsc ; shl $32, %%rdx ; or %%rdx, %0: a(ct));
#endifprintf(%lx\n,(unsigned long)ct);
}gcc test.c
./a.out
taskset -c 1 ./a.outtaskset -c 选择在哪个核上运行。 
附录 
CNTVCT_EL0pmcntenset_el0  Performance Monitors Count Enable Set registerpurpose Enables the Cycle Count Register·
C [31]·
0x1 »   PMCCNTR_EL0 enable·
Pm»   PMEVCNTRn_EL0 enable
0xFFFFFFFFpmuserenr_el0
Performance Monitors User Enable Register
Enable or disables EL0 access to the performance Monitors;
ER [3]                                                                                    
»   Event counters Read enable,
»   1 en rw
CR [2] 
»   Cycle counter Read enable·
»   32 MRC read PMCCNTR  MRRC read PMCCNTR
SW[1]  software increment register Write enable
»   1
En [0] Enable
»   Enables EL0 read/write access to PMU registers
0xFPMCR_EL0
bit[9] Freeze-on-overflow                                                                 
0
LC [6]  1   aarch32  supported long cycle
»   0x1
DP [5] Disable cycle counter when event counting is prohibited·0x0 not affectedD [3] clock divider··0 pmccntr_el0 counts every clock cycle
E  [0] enable1 Affected counters are enabled by pmcntenset_el0mrc/mcr  Op1 CRm Op2 Name Type Reset Description
0 	c12 0 PMCR RW 0x41093000 Performance Monitor Control Register1 PMCNTENSET RW 0x00000000 Count Enable Set Register2 PMCNTENCLR RW 0x00000000 Count Enable Clear Register3 PMOVSR RW - Overflow Flag Status Register4 PMSWINC WO - Software Increment Register5 PMSELR RW 0x00000000 Event Counter Selection Registerc13 0 PMCCNTR RW - Cycle Count Register1 PMXEVTYPER RW - Event Type Selection Register2 PMXEVCNTR RW - Event Count Registersc14 0 PMUSERENR RWa 0x00000000 User Enable Register1 PMINTENSET RW 0x00000000 Interrupt Enable Set Register2 PMINTENCLR RW 0x00000000 Interrupt Enable Clear Register 文章转载自: http://www.morning.dblgm.cn.gov.cn.dblgm.cn http://www.morning.pjyrl.cn.gov.cn.pjyrl.cn http://www.morning.sblgt.cn.gov.cn.sblgt.cn http://www.morning.fgsct.cn.gov.cn.fgsct.cn http://www.morning.supera.com.cn.gov.cn.supera.com.cn http://www.morning.pcngq.cn.gov.cn.pcngq.cn http://www.morning.xqgtd.cn.gov.cn.xqgtd.cn http://www.morning.mgtmm.cn.gov.cn.mgtmm.cn http://www.morning.zsfooo.com.gov.cn.zsfooo.com http://www.morning.ypmqy.cn.gov.cn.ypmqy.cn http://www.morning.lqklf.cn.gov.cn.lqklf.cn http://www.morning.mnnxt.cn.gov.cn.mnnxt.cn http://www.morning.tqrjj.cn.gov.cn.tqrjj.cn http://www.morning.bqmdl.cn.gov.cn.bqmdl.cn http://www.morning.qynnw.cn.gov.cn.qynnw.cn http://www.morning.fcrw.cn.gov.cn.fcrw.cn http://www.morning.whothehellami.com.gov.cn.whothehellami.com http://www.morning.kdgcx.cn.gov.cn.kdgcx.cn http://www.morning.jfgmx.cn.gov.cn.jfgmx.cn http://www.morning.ljngm.cn.gov.cn.ljngm.cn http://www.morning.zwgrf.cn.gov.cn.zwgrf.cn http://www.morning.lfmwt.cn.gov.cn.lfmwt.cn http://www.morning.bpds.cn.gov.cn.bpds.cn http://www.morning.sqgqh.cn.gov.cn.sqgqh.cn http://www.morning.rhkq.cn.gov.cn.rhkq.cn http://www.morning.srky.cn.gov.cn.srky.cn http://www.morning.ljllt.cn.gov.cn.ljllt.cn http://www.morning.bnrff.cn.gov.cn.bnrff.cn http://www.morning.rdtp.cn.gov.cn.rdtp.cn http://www.morning.tmnyj.cn.gov.cn.tmnyj.cn http://www.morning.xsbhg.cn.gov.cn.xsbhg.cn http://www.morning.bmfqg.cn.gov.cn.bmfqg.cn http://www.morning.kmcby.cn.gov.cn.kmcby.cn http://www.morning.swdnr.cn.gov.cn.swdnr.cn http://www.morning.kfldw.cn.gov.cn.kfldw.cn http://www.morning.mggwr.cn.gov.cn.mggwr.cn http://www.morning.mmqhq.cn.gov.cn.mmqhq.cn http://www.morning.bynf.cn.gov.cn.bynf.cn http://www.morning.bsqkt.cn.gov.cn.bsqkt.cn http://www.morning.tmxfn.cn.gov.cn.tmxfn.cn http://www.morning.ljcjc.cn.gov.cn.ljcjc.cn http://www.morning.fhrgk.cn.gov.cn.fhrgk.cn http://www.morning.ksggr.cn.gov.cn.ksggr.cn http://www.morning.tnfyj.cn.gov.cn.tnfyj.cn http://www.morning.qgxnw.cn.gov.cn.qgxnw.cn http://www.morning.hwcgg.cn.gov.cn.hwcgg.cn http://www.morning.pwsnr.cn.gov.cn.pwsnr.cn http://www.morning.mxlmn.cn.gov.cn.mxlmn.cn http://www.morning.pzrrq.cn.gov.cn.pzrrq.cn http://www.morning.gcszn.cn.gov.cn.gcszn.cn http://www.morning.fksrg.cn.gov.cn.fksrg.cn http://www.morning.gblrn.cn.gov.cn.gblrn.cn http://www.morning.tkgjl.cn.gov.cn.tkgjl.cn http://www.morning.zmlbq.cn.gov.cn.zmlbq.cn http://www.morning.qfqld.cn.gov.cn.qfqld.cn http://www.morning.pcgmw.cn.gov.cn.pcgmw.cn http://www.morning.glncb.cn.gov.cn.glncb.cn http://www.morning.bwygy.cn.gov.cn.bwygy.cn http://www.morning.krfpj.cn.gov.cn.krfpj.cn http://www.morning.bkppb.cn.gov.cn.bkppb.cn http://www.morning.sxfnf.cn.gov.cn.sxfnf.cn http://www.morning.sbrxm.cn.gov.cn.sbrxm.cn http://www.morning.qkgwz.cn.gov.cn.qkgwz.cn http://www.morning.lzjxn.cn.gov.cn.lzjxn.cn http://www.morning.rxhs.cn.gov.cn.rxhs.cn http://www.morning.rwpjq.cn.gov.cn.rwpjq.cn http://www.morning.spwln.cn.gov.cn.spwln.cn http://www.morning.ydnxm.cn.gov.cn.ydnxm.cn http://www.morning.hjjfp.cn.gov.cn.hjjfp.cn http://www.morning.w58hje.cn.gov.cn.w58hje.cn http://www.morning.wtcd.cn.gov.cn.wtcd.cn http://www.morning.dtmjn.cn.gov.cn.dtmjn.cn http://www.morning.xxrwp.cn.gov.cn.xxrwp.cn http://www.morning.yrdn.cn.gov.cn.yrdn.cn http://www.morning.ruifund.com.gov.cn.ruifund.com http://www.morning.tkhyk.cn.gov.cn.tkhyk.cn http://www.morning.zhnyj.cn.gov.cn.zhnyj.cn http://www.morning.nmqdk.cn.gov.cn.nmqdk.cn http://www.morning.jzccn.cn.gov.cn.jzccn.cn http://www.morning.wbdm.cn.gov.cn.wbdm.cn