element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
Software Application Development Execution time measurement
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Avnet Boards Forums to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 7 replies
  • Subscribers 328 subscribers
  • Views 1880 views
  • Users 0 members are here
Related

Execution time measurement

Former Member
Former Member over 11 years ago

Hello,
I am using zedboard for my project and I want to measure my algorithm process time. The problem is that I can not use the clock() or gettimeofday() function, it says "undefined reference to _gettimeofday" or " undefined reference to _time", but in fact, I have already included the <sys/time.h> and <time.h>. I really need this problem to be fixed or any idea to measure the execution time.

P.S. My programmm is based on C and neon intrinsics, and the The Project is running on standalone. 

  • Sign in to reply
  • Cancel
Parents
  • Former Member
    0 Former Member over 11 years ago

    This stack overflow article seems to describe the problem.
    http://stackoverflow.com/questions/15030123/how-does-the-clock-function-in-ctime-access-the-system-clock

    It might just be easier to use one of the PS timers; Adam Taylor has a nice intro:
    http://forums.xilinx.com/t5/Xcell-Daily-Blog/Implementing-the-Zynq-SoC-s-Private-Timer-Adam-Taylor-s-MicroZed/ba-p/402203

    This gave me an excuse to play with the timer stuff, the attached is a working 100 microsecond timer with a stub function that seems to satisfy _that one particular_ missing library function (ie: ymmv); two files 'substitute_times.h' and 'substitute_times.cpp'

    **/// snip ///**

    /*
    * substitute_times.h
    *
    *  simple interrupt driven timer to stand-in for standard lib
    *  function 'times'
    */

    #ifndef SUBSTITUTE_TIMES_H_
    #define SUBSTITUTE_TIMES_H_

    #include <xscugic.h>

    ///@note the arm-xilinx-eabi library function '_times' itself already declared; we won't do it again

    /** Installs a timer interrupt handler and initialize the system timer to generate a timer interrupt every 100 microseconds.
    * The interrupt routine maintains a software divider to generate CLOCKS_PER_SEC frequency.
    * and install a handler to process the interrupt and increment a counter.
    * @note call from your interrupt configuration routine, before you globally enable interrupts.
    * @note enables timer interrupt and also GIC interrupt for timer.
    * @param pInterruptControllertreference to interrupt controller
    */
    void init_substitute_times(XScuGic *pInterruptController);

    /** stop the interrupts, kill the timer */
    void kill_substitute_times();

    /** elapsed microseconds since boot */
    uint64_t getMicroseconds();

    /** elapsed CLOCKS_PER_SEC since boot */
    clock_t getClocks();

    #endif /* SUBSTITUTE_TIMES_H_ */

    **/// snip ///**

    /*
    * substitute_times.cpp
    */

    #include <stdint.h>
    #include <ctime>
    #include <sys/times.h>

    #include <xil_types.h>
    #include <xparameters.h>
    #include <xscutimer.h>
    #include <xscugic.h>

    /**tTimer interrupt period in microseconds.
    *
    * from "xparameters.h" we know that
    * XPAR_PS7_CORTEXA9_0_CPU_CLK_FREQ_HZ is system clock (~667MHz on my microZed)
    *
    * from the Zynq-700 SoC reference we know that:
    * tt8.2.1 Clocking
    *ttAll private timers and watchdog timers are always clocked at 1/2 of the CPU frequency (CPU_3x2x).
    *
    * from "time.h" we know CLOCKS_PER_SEC = 100.
    *
    * so for example we can use 3333333 as a divisor for 100.00001305 Hz
    *
    * From <http://forums.xilinx.com/t5/Xcell-Daily-Blog/Implementing-the-Zynq-SoC-s-Private-Timer-Adam-Taylor-s-MicroZed/ba-p/402203>
    * twe steal code liberally...
    *
    */
    const uint32_t timer_period_microseconds = 100;

    const uint32_t timer_freq = 1000000/timer_period_microseconds;

    /**tTimer divisor to give us 'timer_period_microseconds' intervals
    */
    const uint32_t divisor_for_timer = (XPAR_PS7_CORTEXA9_0_CPU_CLK_FREQ_HZ/2) / timer_freq;

    const uint32_t timer_periods_per_CLOCK = timer_freq/CLOCKS_PER_SEC;


    /// incremented at CLOCKS_PER_SEC by timer interrupt
    volatile clock_t clock_value = 0;


    /// will contain ref to ARM 'private' timer
    static XScuTimer substitute_tick_timer;

    /// incremented every 'timer_period_microseconds' by timer interrupt; not necessarily incremented by 1 !!
    volatile uint64_t microsecond_counter = 0;

    // incremented each timer interrupt, when it equals timer_periods_per_CLOCK then 'clock_value' is incremented
    volatile uint64_t CLOCK_counter = 0;

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    extern "C"
    {
    t/** substitute for missing arm-xilinx-eabi library '_times' symbol.
    t * @note the '_times' function itself already declared; we won't do it again
    t */
    tclock_t _times(tms * ptms)
    t{
    ttif (ptms)
    tt{
    ttt// fill in struct in vaguely appropriate fashion
    tttptms->tms_utime = 0;  /* user time */
    tttptms->tms_stime = clock_value;  /* system time */
    tttptms->tms_cutime = 0; /* user time of children */
    tttptms->tms_cstime = 0; /* system time of children */
    tt}
    ttreturn clock_value;
    t}
    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    uint64_t getMicroseconds() { return microsecond_counter; }
    clock_t getClocks() { return clock_value; }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /** timer interrupt handler
    * @param CallBackRefta reference to our XScuTimer
    */
    static void handler_substitue_times(void *CallBackRef)
    {
    tXScuTimer *pTimer = (XScuTimer *) CallBackRef;t// ideally, equal to 'substitute_tick_timer'

    tmicrosecond_counter += timer_period_microseconds;

    tCLOCK_counter += 1;
    tif (CLOCK_counter == timer_periods_per_CLOCK)
    t{
    ttclock_value += 1;
    ttCLOCK_counter = 0;
    t}

    tXScuTimer_ClearInterruptStatus(pTimer);
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    void init_substitute_times(XScuGic *pInterruptController)
    {
        //timer initialization

    tXScuTimer_Config* pTimerConfig = XScuTimer_LookupConfig(XPAR_XSCUTIMER_0_DEVICE_ID);

    tif (pTimerConfig)
    t{
    ttXScuTimer_CfgInitialize(&substitute_tick_timer, pTimerConfig, pTimerConfig->BaseAddr);

    ttXScuTimer_SelfTest(&substitute_tick_timer); // hmmm

    tt//load the timer

    ttXScuTimer_LoadTimer(&substitute_tick_timer, divisor_for_timer);
    t tXScuTimer_EnableAutoReload(&substitute_tick_timer);

    t t//set up the interrupts
    ttXScuGic_Connect(pInterruptController, XPAR_SCUTIMER_INTR, (Xil_ExceptionHandler)handler_substitue_times, (void *)&substitute_tick_timer);

    tt//enable the interrupt for the Timer at GIC
    ttXScuGic_Enable(pInterruptController, XPAR_SCUTIMER_INTR);
    tt//enable interrupt on the timer
    ttXScuTimer_EnableInterrupt(&substitute_tick_timer);

    t t//start timer
    t tXScuTimer_Start(&substitute_tick_timer);
    t}
    telse
    t{
    tt// whoops, no timer? bad ID?
    t}
    }

    void kill_substitute_times()
    {
    t//disable interrupt on the timer
    tXScuTimer_DisableInterrupt(&substitute_tick_timer);
    tXScuTimer_Stop(&substitute_tick_timer);
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    Thanks so much for the reply.
    I want to try your header file, but the funny thing is that when I include xscugic.h header, it say "no such file or directory". And also the xscutimer.h and xil_types.h . But the fact is that I can find these files in the Myproject_bsp folder.
    Do you know the reason?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 11 years ago in reply to Former Member

    Thanks so much for the reply.
    I want to try your header file, but the funny thing is that when I include xscugic.h header, it say "no such file or directory". And also the xscutimer.h and xil_types.h . But the fact is that I can find these files in the Myproject_bsp folder.
    Do you know the reason?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube