Quantcast
Channel: Processors forum - Recent Threads
Viewing all articles
Browse latest Browse all 17527

RTOS/TMS320C6678: TSCL and time.h

$
0
0

Part Number:TMS320C6678

Tool/software: TI-RTOS

Hi,

I was roughly measuring the execution time of some function on my C6678 on one core and I am getting some time difference measuring in two ways. To do so, I included the following in my .cfg file:


var BIOS = xdc.useModule('ti.sysbios.BIOS');
var Clock = xdc.useModule('ti.sysbios.knl.Clock');
var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');

In my C-file I included:


#include <ti/sysbios/knl/Clock.h>
#include <pthread.h>
#include <time.h>
#include <sys/time.h>

The function is embedded in a task which is called after BIOS_start. I am measuring the time in the following two ways:

    clock_gettime(CLOCK_MONOTONIC, &tic);
    t1 = TSCL;
    // long function call
    t2 = TSCL;
    clock_gettime(CLOCK_MONOTONIC, &toc);
    elapsed_time = calc_time(&tic, &toc);
    elapsed_tscl_time = ((double)t2-(double)t1)/(1000000000.0); // running at 1GHz

where I pasted the function calc_time() below.

I read on software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/sysbios/6_21_01_16/exports/docs/docs/cdoc/ti/sysbios/knl/Clock.html#tick

that I should use constant Clock_tickPeriod to calculate the elapsed time. On that website, it says that Clock_tickPeriod is defined in MICROseconds.

In some post in this forum, I read that TSCL returns the number of elapsed cycles. I therefore have to use the processor frequency of 1GHz in order to extract the elapsed time.

The output of my code is the following:

TSCL elapsed time = 0.89283968 seconds
clock_gettime elapsed time: 0.000893 seconds

The results from TSCL and clock_gettime seem to be different by a factor of 1000. I measured 10 functions runs and compared it with my watch (~8 seconds), and the TSCL measurement seems to be correct. From that, I follow that either Clock_tickPeriod is defined in MILLIseconds or that the function calc_time() below does something wrong. Can someone confirm my observation? Thank you very much.

calc_time:

float calc_time(struct timespec *tic, struct timespec *toc)
{
    struct timespec temp;
    if ((toc->tv_nsec - tic->tv_nsec) < 0) {
      temp.tv_sec  = toc->tv_sec - tic->tv_sec - 1;
      temp.tv_nsec = 1e9 + toc->tv_nsec - tic->tv_nsec;
    } else {
      temp.tv_sec  = toc->tv_sec - tic->tv_sec;
      temp.tv_nsec = toc->tv_nsec - tic->tv_nsec;
    }
    // Clock_tickPeriod in microseconds
    return ((float)temp.tv_sec + (float)temp.tv_nsec / 1e9)*((float)Clock_tickPeriod)*1.0e-6;
}


Viewing all articles
Browse latest Browse all 17527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>