How to get the High-Resolution Timing in LS1021a CPU

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to get the High-Resolution Timing in LS1021a CPU

1,490件の閲覧回数
yuqianli
Contributor I

I am working on to porting some X86 codes to LS1021a CPU with our customized board. the X86 code calls to RDTSC to get a precise timing, it works well in X86. Absolutely, the RDTSC won't works in LS1021a, my question is, is there a way to do the same thing in LS1021a CPU.

I also saw some people are using below ARM code to get the high-resolution timing,

volatile unsigned cc;
static int init = 0;
if(!init) {
 __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 2" :: "r"(1<<31)); /* stop the cc */
 __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 0" :: "r"(5)); /* initialize */
 __asm__ __volatile__ ("mcr p15, 0, %0, c9, c12, 1" :: "r"(1<<31)); /* start the cc */
 init = 1;
}
__asm__ __volatile__ ("mrc p15, 0, %0, c9, c13, 0" : "=r"(cc));
return cc;

but it doesn't work in LS1021 and shows to me below error 

[ 3341.620682] StartSystemTimer, Timer Resolution is: 1 in jiffies
[ 3341.626616] BUG: FP instruction issued in kernel mode with FP unit disabled
[ 3341.633547] Internal error: Oops - undefined instruction: 0 [#1] SMP ARM
[ 3341.640211] Modules linked in: pikahsp(P) pikacore
[ 3341.644994] CPU: 1 PID: 469 Comm: gptest Tainted: P 4.1.30-rt34+g73b5a4e #38
[ 3341.653297] Hardware name: Freescale LS1021A
[ 3341.657541] task: ed303440 ti: ee6fa000 task.ti: ee6fa000
[ 3341.663158] PC is at HspTimerDpc+0xc/0x488 [pikahsp]
[ 3341.668100] LR is at call_timer_fn+0x24/0x9c
[ 3341.672345] pc : [<bf012598>] lr : [<c0089880>] psr: 60000013
[ 3341.672345] sp : ee6fbcac ip : ee6fa000 fp : 00000000
[ 3341.683761] r10: eefd8e5c r9 : eefd8c5c r8 : c0b16140
[ 3341.688954] r7 : 00000200 r6 : bf01258c r5 : ed68800c r4 : eefd8440
[ 3341.695444] r3 : ee6fbcd0 r2 : ed68800c r1 : bf01258c r0 : 00002754
[ 3341.701934] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user
[ 3341.709029] Control: 30c5387d Table: ad2fab40 DAC: df5fbed7
[ 3341.714741] Process gptest (pid: 469, stack limit = 0xee6fa218)
[ 3341.720625] Stack: (0xee6fbcac to 0xee6fc000)
[ 3341.724959] bca0: eefd8440 00000101 bf01258c 00000200 c0b16140
[ 3341.733094] bcc0: eefd8c5c eefd8e5c 00000000 c0089880 eefd8440 00000020 eefd8440 00000000
[ 3341.741230] bce0: ee6fbcf0 c0089e90 c0ba9018 eefd905c ee6fbcf0 ee6fbcf0 00000000 c0b16084
[ 3341.749366] bd00: 00000020 c0b16080 ee6fa000 00000101 ee6fbd20 00000001 00000004 c00429ac
[ 3341.757501] bd20: 00000000 ee6fbd34 c0ba2580 c0ba81c0 0000000a 0004a424 c0b16140 00400000
[ 3341.765637] bd40: ed68b00c 60000013 ed68800c ed68b00c ed6881bc ed68a00c ed68b00c 00000032
[ 3341.773772] bd60: 00000000 c0042b78 00000001 c0042c40 00000000 ed68800c ed68b00c bf012fb0
[ 3341.781906] bd80: ed75960c ed68800c ed68af0c bf006cfc 00000008 ed68a00c ed282780 ed759650
[ 3341.790042] bda0: 00000000 be948b34 ed68800c c004ea10 be948b34 be948b34 ee6fa000 00000000
[ 3341.798178] bdc0: 00000000 bf004494 ed824000 00000000 000000f4 ee6fbde8 c0103734 c010374c
[ 3341.806313] bde0: 00000000 c0103754 ee6fbf74 00000000 edabacc0 00080040 edabad10 00000001
[ 3341.814449] be00: 00000000 c011488c ee6fbef0 ee6fbf74 00000000 00000002 ee6fbef0 ee6fbf74
[ 3341.822584] be20: 00000000 00000002 00000000 c010a754 ee6fbe50 c010b868 00000000 ed282780
[ 3341.830719] be40: 00000026 00000000 00000000 00000000 ee5d56d0 ed824000 ee0be028 c0b554c0
[ 3341.838853] be60: ee6fbf74 ed40e318 ee6fa000 ed282780 ee6fbef0 00000000 ee6fbf74 ee72a000
[ 3341.846988] be80: ed282780 ee6fbef0 00000000 c010cf18 ee6fbeac ee72a000 00000021 ee6fbfb0
[ 3341.855123] bea0: ed303440 ee6d4e00 ed0dd0c0 00000002 ee5d56d0 edabacc0 00000055 c001d970
[ 3341.863259] bec0: 00100073 ee6fbf74 00000001 ffffff9c ee72a000 c000f484 ee6fa000 00000000
[ 3341.871394] bee0: 00000000 c010dec8 00000041 c0b253fc ee5d56d0 edabacc0 6d372858 00000007
[ 3341.879529] bf00: ee72a015 0000000b 00000000 ed817770 bf0926c0 ed68800c c004ea10 bf004e8c
[ 3341.887665] bf20: ed40e318 be948b34 ed282780 00000008 be948b34 c0110368 00000000 00000000
[ 3341.895799] bf40: 00000002 00000008 00000008 ed282780 ee72a000 ed40e318 ed282788 00000020
[ 3341.903934] bf60: 00000000 c00ff040 00000000 00000000 00000022 ed282780 00000008 ed282780
[ 3341.912070] bf80: c004ea10 be948b34 ee6fa000 c0110590 001d5138 00000000 0000646c 00000036
[ 3341.920206] bfa0: c000f484 c000f300 001d5138 00000000 00000008 c004ea10 be948b34 00000004
[ 3341.928340] bfc0: 001d5138 00000000 0000646c 00000036 be948ce0 be949118 be948ce0 00000000
[ 3341.936475] bfe0: b6865101 be948b2c b6b1e3bb b6865106 80000030 00000008 00000000 00000000
[ 3341.944614] unwind: Unhandled instruction c9

seems there is no C9 register in LS1021a Smiley Sad

The question is there a way to get a precise timing in the LS1021a?

Thank you

Yuqian

ラベル(1)
0 件の賞賛
3 返答(返信)

1,039件の閲覧回数
Pavel
NXP Employee
NXP Employee

Look at the following pages about using high resolution timer under Linux:

https://elinux.org/High_Resolution_Timers

 

and

 

https://stackoverflow.com/questions/6749621/how-to-create-a-high-resolution-timer-in-linux-to-measur...

 

and

 

https://lwn.net/Articles/167897/

 

and

 

https://linux.die.net/man/7/time

 

NXP Linux SDK for the LS1021a supports also the LS1021a FlexTimers. Use these timers for your task.


Have a great day,
Pavel Chubakov

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛

1,039件の閲覧回数
yuqianli
Contributor I

Hi Pavel,

Thanks for your quick response.

I am looking for kind of cycle count (how many cycles), not the how much time actually elapses. 

The X86 RDTSC uses the assembly instruction to get the cycle counting, here is what we are using for x86 RDTSC

unsigned cycles;

__asm__ __volatile__ ("rdtsc" : "=a" (cycles));

return cycles;

In more specific, I am looking for the ARM especial for the LS1021a supported such assembly instruction to do the cycle count.

I found someone did success for Raspberry Pi with this way in here RDTSC on ARM - Raspberry Pi Forums 

But it doesn't work for LS1021a, shown to me "unwind: Unhandled instruction c9

Thank you and looking forward your response.

Yuqian

0 件の賞賛

1,039件の閲覧回数
yuqianli
Contributor I

Also, I found the PowerPC has same cycle counting instruction like below link shows

linux/arch/powerpc/include/asm/time.h - Elixir - Bootlin 

0 件の賞賛