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.

TMS320C6657: OS kernel: Task_sleep and resolution of nticks

Part Number: TMS320C6657
Other Parts Discussed in Thread: SYSBIOS

Hi TI

Can you please help:

1. I have problem to understand the OS kernel interface using the Task_sleep.

More exactly: to understand the "nticks" in relation to the "system clock" mentioned in the description of the kernel interface.

I'm using the keystone C6657 DSP with 1GHz as input clock . What is the "system clock" in this case?

If I would like to have a Task_sleep of, let's say, 1ms: what is the correct value of "nticks"

2. Another question: for the context of task switch's  how many clock cycles (or micro sec.) do SYSBIOS take to do a task switch between 2 tasks ?

Can you please help to clarify these problems.

Attached: TI's implementation of Task_sleep(UInt32 nticks

BR

Tam Tran

******************* SYSBIOS intf. ********************

Void Task_sleep(UInt32 nticks);

ARGUMENTS

nticks — number of system clock ticks to sleep

 

DETAILS

Task_sleep changes the current task's mode from Mode_RUNNING to Mode_BLOCKED, and delays its execution for nticks increments of the system clock. The actual time delayed can be up to 1 system clock tick less than nticks due to granularity in system timekeeping and the time elapsed per tick is determined by Clock_tickPeriod.

After the specified period of time has elapsed, the task reverts to the Mode_READY mode and is scheduled for execution.

A task switch always occurs when calling Task_sleep if nticks > 0.

CONSTRAINTS

Task_sleep cannot be called from a Swi or Hwi, or within a disable / restore block.

Task_sleep cannot be called from the program's main() function.

Task_sleep should not be called from within an Idle function. Doing so prevents analysis tools from gathering run-time information.

nticks cannot be BIOS_WAIT_FOREVER.

  • Tam tran,

    Your understanding on the "Task_sleep" is correct.

    -----

    For example, If we pass "1" as a parameter to the Task_sleep function, it "will delay the execution of the current task by 1 ms".

    Task_sleep(1); ---> It will block the current Running task for 1 ms..and allow the main task to run...

    For Task_sleep ( 2 )  -->  It will block the current Running task for 2 ms..and allow the main task to run...

    ----

    nticks means the number of ticks.

    For example, -----Time tick----- calculation for DSP running 1 GHz...

    Total no of CPU cycles =    cycles or ticks

    DSP core frequency = 1000 MHz ---- that is --> 1 GHz

     

    Time = 1 / Freq ( General formula )

              = 1 / 1000 MHz ( DSP core frequency )

              = 0.001 us ( Micro seconds) 

     

    1000000000 cycles = 1 sec 

    ( Please note, cycles and ticks are one and the same)  

    AND hence, 1000000000 ticks per second

    ------------------

    If you are looking for the exact time stamp,

    1. you can use utilReadTime32() before and after the code

    2. subtract the two values.

    3. Convert the cycles/ticks into time like below:

    1000000000 cycles = 1 sec

    =>32149501  cycles =  0.032 sec

    Regards

    Shankari G

  • Many thanks for you support Shankari

    Can you please answer my 2. question as well:

    2. Another question: for the context of task switch's  how many clock cycles (or micro sec.) in average do SYSBIOS take to do a task switch between 2 tasks ?

    BR

    Tam Tran

  • Tam tran,

    Second question was also answered. 

    We have to calculate that --- > clock cycles that the SYSBIOS take during the task switch....

    Use utilReadTime32() and calculate the clock cycles, during the task switch.

    ----

    For cycle time, I use the following methods.

    ================

    This will make use of the clock ticks/cycles of DSP core running at  1000  MHz and it will be precise...

    Here you go.....

    =================

    Code snippet: 

    //Shankari-Start-Declaration  for time ticks

    #include "C:\ti\pdk_keystone2_3_01_04_07\packages\ti\csl\csl_tsc.h"

    //<ti/csl/csl_tsc.h>

    extern uint32_t utilReadTime32();

    //Shankari-End-Declaration  for time ticks

    ......

    /*Throughput calculation initialization */


    unsigned int StartTime = 0;
    unsigned int EndTime = 0;
    unsigned int Total_cycle_ticks = 0;

    /*Throughput calculation initialization Ends */

    .......

    //Usage 

    StartTime = utilReadTime32(); // ----------------------- Start time 

    // Please insert your code here  ------------

    sauConnDmPktTest(tf, pat,
    100, /* Number of packets per connection */
    512, /* initial payload length */
    0, /* payload llength increment step */
    SAU_PAYLOAD_INC8 /* payload pattern */
    );


    EndTime = utilReadTime32(); // -------------------------- End time

    Total_cycle_ticks = EndTime-StartTime; // -------------------Subtract End time and start time ---- you will get the clock cycles ----- convert into seconds...


     System_printf("StartTime = %d \n", StartTime);
     System_printf("EndTime = %d \n", EndTime);

     System_printf("Total_cycle_ticks = %d \n", Total_cycle_ticks);


    // System_printf(" sauConnDmPktTest 2048 PacketSize, 100 packets -Total_cycle_ticks = %d \n", Total_cycle_ticks);

    ------------------

    Time tick calculation , you can use according to the number of Total_cycle_ticks, you get......

    Total no of CPU cycles =    cycles 

    DSP core frequency = 1000 MHz

     

    Time = 1 / Freq ( General formula )

              = 1 / 1000 MHz ( DSP core frequency )

              = 0.001 us ( Micro seconds) 

     

    1000000000 cycles = 1 sec

    =>32149501  cycles =  0.032 sec

    ---------------------------

    Regards

    Shankari G