Question

I want to calculate the execution time of a series of tasks, I initiate a task and then activate it, I use taskCreateHookAdd to start the timer and on every switch on each task I will recalculate the time using taskSwitchHookAdd. After the tasks are deleted. I calculate the time one last time in taskDeleteHookAdd.

I created 4 tasks in my system, they are Insert, Traverse,Delete,Search for Binary trees.at the end the task execution time I calculate doesn't seem ok for two of my tasks, some times they are 0. and the rest of the time the have the exact same value. I have checked the priorities of the tasks but they seem to be ok. all the tasks have implementation and they are not empty. you can see switch part of my code below, I'm sure the other parts work fine (by debugging), but I'm not so sure about the switch hook. I would appreciate it if you could help me with this.thanks in advance.

` void switchtaskHook(WIND_TCB *pOldTcb, WIND_TCB *pNewTcb ) {

if((int)pOldTcb == tidInsert)
{
    inserttotal+=tickGet()-inserttick;

}
else if((int)pOldTcb == tidTraverse)
{
    traversetotal+=tickGet()-traversetick;

}
else if((int)pOldTcb == tidSearch)
{
    searchtotal+=tickGet()-searchtick;//;count++;

}
else if((int)pOldTcb == tidDelete)
{
    deletetotal+=tickGet()-deletetick;

}

if((int)pNewTcb == tidInsert)
{
    inserttick=tickGet();

else if((int)pNewTcb == tidTraverse)
    {
        traversetick=tickGet();

    }
else if((int)pNewTcb == tidSearch)
    {
        searchtick=tickGet();

    }
else if((int)pNewTcb == tidDelete)
    {
        deletetick=tickGet();   
    }

}

`

Was it helpful?

Solution

please read the manual entry for tickGet().

It returns the system tick count which typically runs at 60 to 2KHz. Much too coarse to do performance measurements. This is controlled by the BSP and you really don't want to change it without good reasons (and the upper rate is typically 8KHz, which is still too coarse) since it can impact the system overhead.

A better approach is to use the timestamp driver which typically has microsecond resolution. Look for sysTimestamp* function in the documentation.

OTHER TIPS

If you want to measure the execution time of the code inside your task, you could try to separate the code in question into separately callable subroutines and then measure the performance of each individual subroutine via the vxWorks timexLib, see for example its timexN() method. timexN() is very accurate. If you can modularize your code to allow per-subroutine benchmarking, your design might benefit overall, but it may not always be possible.

If you cannot perform this type of modular testing, and need a timer that is finer than the tickLib, your options can depend on your target platform. In the sysLib.c file of your BSP you will typically find a routine sysUsDelay() that uses a time of much higher detail than tickGet(). Look for code that reads a "Time Base Lower Register" tick count, which increments close to the CPU speed. Unfortunately, the details are specific to your target platform (CPU, ..). Still, as long as you stay on the same target, you can look in there how to obtain that higher resolution tick counter for your execution time analysis.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top