This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TDA2PXEVM: ARM cycle counter

Part Number: TDA2PXEVM

Tool/software: TI C/C++ Compiler

Hi,

I am working on ARM cortex-15 processor of TDA2Px board, i want to do my function profiling, i was using this method for calculation:

start = clock();

......                       // func to be profiled

end = clock();

printf( "cpu_time_used = %d \n", ((double)(end - start)));


but the cycle count are fluctuating. I wanted to do the profiling using ARM cycle counter.

so, i have gone through this link:

e2e.ti.com/.../824156    

the code attached in this link, when i debug it gives a error:"illegal instruction" & then it get exited.

So, is their anything which i am missing?

and it is the right way to do profiling using the arm cycle counter?

Regards

Surbhi

  • Hi Surbhi,

    You can refer to TDA2Px SBL for profiling using ARM counter.

    APIs to use are ARM_CCNT_Enable and ARM_CCNT_Read.

    For implementation you should refer to PROCESSOR_SDK_VISION_03_07_00_00\ti_components\drivers\pdk_01_10_03_07\packages\ti\csl\arch\a15\cp15.h.

    Regards,

    Rishabh

  • Thanks rishabh, i got that file. But i am building my code using linaro compiler & not as a part of PROCESSOR_SDK. so if i include that header & source asm file also then my build is getting failed. Can you please guide me in this

    Regards

    Surbhi

  • Hi Surbhi,

    What is the build error you are getting?

    Regards,

    Rishabh

  • Hi rishabh,

    this is error which i am getting during the build, the out file is not generated.

    (.text+0x2ac8): undefined reference to `ARM_CCNT_Enable'
    (.text+0x2aec): undefined reference to `ARM_CCNT_Read'
    (.text+0x2b00): undefined reference to `ARM_CCNT_Read'
    (.text+0x2c34): undefined reference to `ARM_CCNT_Read'
    (.text+0x2c48): undefined reference to `ARM_CCNT_Read'
    collect2: error: ld returned 1 exit status
    Makefile:115: recipe for target 'bin' failed
    make: *** [bin] Error 1

    Regrads

    Surbhi

  • Hi Surbhi,

    It seems that you are not linking.o for asm file and hence compiler is not able to find the definition.

    I won't be able to help much as you are using a different build system and not PDK or PRSDKA.

    You can search on internet on how to add asm files to a library.

    Regards,

    Rishabh

  • Hi rishabh,

    thank you for the inputs . I am able to link that .o file but it again throws the same error as:

    "illegal Instruction". while debug i find that error is coming during "mrc p15, #0, r0, c9, c12, #0", as I am on shortage on time. I have read about a method to invoke the timer registers from the same asm method but by writing a linux kernel, which will enable the user mode. so that this all registers can be accessible. Can you tell me this is the right method to do so? i am sharing the link below:

    stackoverflow.com/.../how-to-measure-program-execution-time-in-arm-cortex-a8-processor

    Regards

    Surbhi

  • Hi Surbhi,

    I am not sure why you are getting the error as the code compiles fine for PDK.

    The code given is quite similar to the one present in PDK, although you need to make sure that you extensively test any code taken from the internet.

    Regards,

    Rishabh

  • that i get it. But what is ,it telling about this user mode & kernel mode? That i am not able to get it. can you please tell me about this from the link :

    qouted--> "@vikramtheone, The first two lines must be executed from kernel mode. They enable user-mode access to the CCNT (and related) registers. There is no way around this. The easiest way is in my opinion to write a super short kernel module that does this. Compiling these modules need the kernel-headers of the kernel you're running on your board".

    Regards

    Surbhi

  • Hi Surbhi,

    This is about user and supervisor mode of ARM, you can read more about it on ARM infocenter website.

    RTOS always works in supervisor mode and never change it to user unlike Linux.

    Are you changing to user mode of ARM in your code?

    If yes then you need to change to supervisor mode, the code for which can be found here: PROCESSOR_SDK_VISION_03_07_00_00\ti_components\drivers\pdk_01_10_03_07\packages\ti\csl\arch\a15\V1\cpu.c.

    In case you are not changing ARM's mode then it should be fine to run instructions to read A15 counter as is.

    Regards,

    Rishabh

  • as suggested in that link for that error:"Illegal Instruction", i understand that i had to switch to user mode to access this timer registers. If i an wrong please correct. If not the case then, A-15 core is in supervisor mode as you said, then this asm code should not throw that error, isn't it?

    Regards

    Surbhi

  • Hi Surbhi,

    You don't need to switch to user mode to access timer registers.

    Can you provide details on the software you are running before trying to read timer.

    Maybe this particular software is setting ARM to user mode.

    Can you try to run below code before executing the code to read counter:

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

    In case this doesn't work please share your code as a txt file attachment.

    Regards,

    Rishabh

  • the code which is shared in that link, i tried the same code in CCS with compiler version:GNU V5.3.1(Linaro). It gets build properly but when i load thta .out file on board & try to run it gives me the same error. I debugged the code & it throws the error at the 1st line only of main where this inline instruction is there:

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


    Regards
    Surbhi
  • Hi Surbhi,

    Can you check what is the ARM mode before executing these instructions.

    You can see the CPSR registers in CCS to know the arm mode.

    Regards,

    Rishabh

  • Hi rishabh,

    Using gdb i checked the CPSR register, its value is  "0x60080010".

    1. So which mode is in it?

    2. Is it specific to change the mode to make that instruction work?

    Regards

    Surbhi

  • Hi Surbhi,

    This is user mode.

    Please change bits [4:0] to b10011 or b11111 and the instruction will work.

    Regards,

    Rishabh

  • hi rishabh,

    Can you please tell me how to change this bit & where exactly in the previous code:


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

    Regards

    Surbhi

  • Hi Surbhi,

    You need to change these bits in CPSR register.

    I would suggest you look at arm infocenter for detailed documentation.

    Regards,

    Rishabh

  • Hi,

    I haven't heard back from you, I'm assuming you were able to resolve your issue.
    If not, just post a reply below (or create a new thread if the thread has locked due to time-out).

    Regards,
    Rishabh

  • Hi rishabh,

    I am not able to change the mode bits of CPSR, gone through arm info-center & other sites also. I used the "SWI" instruction, as it was suggested. If i do exception, the mode will be changed automatically but I  debugged my code,except mode bit other bits gets changed.

    --> not getting how to generate a software interrupt in my code.So that when i use SWI instruction to switch to the interrupt, mode bit of CPSR should get changed.

    --> There is any other profiling method that can be used for this function profiling as it is there for DSP & EVE  i.e _tsc.

    Regards

    Surbhi

  • Hi Surbhi,

    In order to debug can you first change the CPSR using CCS and then run the code.

    In case this works then we can work on how to update CPSR from code instead of CCS.

    Regards,

    Rishabh

  • Hi rishabh,

    i don't know how to change the CPSR register value through CCS. can we debug a code through CCS?

    I have only tried using code, which i am building it on CCS. The CCS project which i am creating on CCS has its own starup_ARMCA15.S file where the mode is set to USER mode. I tried modifying that file but nothing is getting reflected on CPSR mode bits.

    Regards

    Surbhi

  • Hi Surbhi,

    You should be able to change the CPSR through register window on CCS.

    Regards,

    Rishabh

  • Hi rishabh,

    I am able to change the register value, i.e under Supervisor_Registers , M bit value. I have also checked under the   Core Registers, M bit value, it is been already set to supervised mode.
    I am unable to load any .out file on a-15 core. So, how could i verify the changes is getting reflected or not?

    Regards

    Surbhi

  • Hi Surbhi,

    You can try updating the CPSR after loading the program while doing a single step.

    Just before reading A15 counter you can change it using CCS and see if you still get exception.

    Also you need to remove the piece of code where you are changing mode from supervisor to user from all places.

    You mentioned that you have tried this already, try clean build after changing the code as asm file might not be getting compiled again.

    Regards,

    Rishabh


  • Hi rishabh,

    I tried loading the .out file on  CortexA15_0/CortexA15_1, i get this error:

    CortexA15_1: File Loader: Verification failed: Values at address 0x00010134 do not match Please verify target memory and memory map.
    CortexA15_1: GEL: File: workspace_v6_2/dummy/Debug/dummy.out: a data verification error occurred, file load failed.
    CortexA15_1: Unable to terminate memory download: NULL buffer pointer at 0x3aa4 (Emulation package 8.0.803.0)

    how to solve this?

    Regards

    Surbhi

  • Hi Surbhi,

    Can you try the suggestion I had given previously i.e. change the CPSR after loading binary.

    Regards,

    Rishabh

  • Hi,

    I haven't heard back from you, I'm assuming you were able to resolve your issue.
    If not, just post a reply below (or create a new thread if the thread has locked due to time-out).

    Regards,
    Rishabh

  • Hi rishabh,

    sorry for late response, i get the test code with register changes done & i am able to change the mode bit through register window.


    Regards

    Surbhi



  • Hi Surbhi,

    Glad that the issue is resolved.

    Please mark the posts that helped you in resolving issue as "This resolved my issue" and close the thread.

    Regards,

    Rishabh