cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
6,273 Views
Registered: ‎07-15-2009

Hello,

 

  Does the microblaze processor have a method (or set of instructions) to produce the same functionality as the x86 rdtsc() function?  I don't seem to see anything in the microblaze ISA.

 

Thanks,

 

  crono

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Xilinx Employee
Xilinx Employee
7,815 Views
Registered: ‎04-23-2008

Re: rdtsc()

Jump to solution

The microblaze does not have an internal timer counter.  Your EDK system needs to include an XPS Timer peripheral to provide this functionality.

 

-Brian

View solution in original post

0 Kudos
6 Replies
Highlighted
Xilinx Employee
Xilinx Employee
7,816 Views
Registered: ‎04-23-2008

Re: rdtsc()

Jump to solution

The microblaze does not have an internal timer counter.  Your EDK system needs to include an XPS Timer peripheral to provide this functionality.

 

-Brian

View solution in original post

0 Kudos
Highlighted
Visitor
Visitor
6,144 Views
Registered: ‎08-03-2009

Re: rdtsc()

Jump to solution

Hi, sorry.  I know I marked this as solved, but could someone please post some sample code on how to access the timer and any header files or libraries I would need to include?  I'm using XPS 11.1  I assume you just do a read from the timer, I just don't know the function call used.  Thanks alot!

 

 

Message Edited by crono123 on 08-03-2009 10:11 AM
0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
6,140 Views
Registered: ‎04-23-2008

Re: rdtsc()

Jump to solution

There are various ways to use the timer depending on what your want to accomplish, ranging from "run forever" with polling, to a timer tick interrupts, to anything in between.  The easiest is to just intialize it to run "forever" and then poll the current timer value.

 

Example one-time "run forever" initialization:

 

=====

    #include "xparameters.h"
    #include "xtmrctr.h"

 

    XTmrCtr TimerCounter;

=====

 

    Status = XTmrCtr_Initialize(&TimerCounter, XPAR_XPS_TIMER_0_DEVICE_ID);
    if (Status != XST_SUCCESS) {
        return XST_FAILURE;
    }

    /*
     * Enable the Autoreload mode of the timer counters.
     */
    XTmrCtr_SetOptions(&TimerCounter, 0, XTC_AUTO_RELOAD_OPTION);

    /*
     * Start the timer counter such that it's incrementing by default
     */
    XTmrCtr_Start(&TimerCounter, XPAR_XPS_TIMER_0_DEVICE_ID);

 

=====

Thereafter you can poll the present value like this (note that the 32 bit value will roll over):

 

    TheTime = XTmrCtr_GetValue(&TimerCounter,
                               XPAR_XPS_TIMER_0_DEVICE_ID);

-Brian
0 Kudos
Highlighted
Visitor
Visitor
6,124 Views
Registered: ‎08-03-2009

Re: rdtsc()

Jump to solution

Brian,

 

  Thanks for the code examples. When I try to initialize the timer I get an XST_FAILURE. 

 

    Status = XTmrCtr_Initialize(&TimerCounter, XPAR_XPS_TIMER_0_DEVICE_ID);
    if (Status != XST_SUCCESS) {

 

//added a printline here

 

xil_printf("Timer Initialization Failure!\r\n");

 

        return XST_FAILURE;
    }

 

I have an xps_timer in my design.  Do you know what I should check on to see why I'm getting this error?

 

thanks,

 

  crono

Message Edited by crono123 on 08-03-2009 01:47 PM
0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
6,121 Views
Registered: ‎04-23-2008

Re: rdtsc()

Jump to solution

The comments for XTmrCtr_Initialize indicate it can return one of these three values:

 

*               - XST_SUCCESS if initialization was successful
*               - XST_DEVICE_IS_STARTED if the device has already been started
*               - XST_DEVICE_NOT_FOUND if the device doesn't exist


Id begin with that. Is XPAR_XPS_TIMER_0_DEVICE_ID correct in xparameters.h (have you tried regenerating the BSP from scratch?). Otherwise.... ?

0 Kudos
Highlighted
Visitor
Visitor
6,119 Views
Registered: ‎08-03-2009

Re: rdtsc()

Jump to solution

The following code snippet shows that the timer device is already started.  I borrowed from your examples, thanks.   The program seems to stop at the line before the print statement "Fails here?".  I checked the xparameters.h file and the XPAR_XPS_TIMER_0_DEVICE_ID seems to refer to the correct timer instance.  (I only have one timer in my design).  I have not tried regenerating the BSP from scratch....will try now.

 

main()

{

 

   /* Initialize RS232_Uart - Set baudrate and number of stop bits */

   XUartNs550_SetBaud(XPAR_RS232_UART_BASEADDR, XPAR_XUARTNS550_CLOCK_HZ, 9600);

   XUartNs550_mSetLineControlReg(XPAR_RS232_UART_BASEADDR, XUN_LCR_8_DATA_BITS);

   print("-- Entering Accumulator Test Main() --\r\n");

           

   XTmrCtr xps_timer_0;

            XStatus Status;

   Xuint32 BeginTime;

            Xuint32 EndTime;

            Xuint32 Calibration;

            Xuint32 TimeRun;

           

            //Status = XTmrCtr_Initialize(&xps_timer_0, XPAR_XPS_TIMER_0_DEVICE_ID);

  

            if (Status != XST_SUCCESS) {

                 xil_printf("Timer Status Failure!\r\n");

        //return XST_FAILURE;

    }

             

             if (Status == XST_DEVICE_IS_STARTED){

                        xil_printf("Timer is already started!\r\n");

             }

             

             if(Status == XST_DEVICE_NOT_FOUND){

               xil_printf("Timer Device is not found!\r\n");

             }

 

             /*

     * Enable the Autoreload mode of the timer counters.

     */

    XTmrCtr_SetOptions(&xps_timer_0, 0, XTC_AUTO_RELOAD_OPTION);

             xil_printf("Fails here?");

             

             /*

     * Start the timer counter such that it's incrementing by default

     */

    XTmrCtr_Start(&xps_timer_0, XPAR_XPS_TIMER_0_DEVICE_ID);

0 Kudos