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.

SYSBIOS - Task Status of all tasks, semaphores, etc..

Other Parts Discussed in Thread: SYSBIOS

Processor: Gauss c6657 

SYSBIOS: 6.34.4.22

I am trying to display all the tasks (like taskStatus() in Vxworks or linux etc..). 

Is there a way to implement using Task_stat()? If already available could you point me to the right API. 

Also interested in listing all the Semaphores, mailbox and others. 

Regards,

Hari

  • Hi Hari,

    I believe SYS/BIOS does not have any API that will return a list of all tasks. Same is true for Semaphore and mailbox too.

    Task_stat() will only return the status (stack size,  priority, stack base, etc) of a single task whose handle has been passed as an argument.

    You can always use ROV to view the list of all Tasks, Semaphore, Mailboxes, etc. for debug purposes.

    Best,

    Ashish

  • We are on a real platform without using JTAG. We need to have our own debug commands. similar to linux/vxworks relevant to task, semaphores, mailboxes etc.. 

    Is there any way I can get information on currently running tasks information? similarly others? 

    Regards,

    Hari

  • All modules have APIs similar to the Task APIs below.   Use Task_Object_getCount() to get the number of static (config-time) tasks.  Use Task_Object_get(NULL, index) to retrieve static handle.   Use Task_first() and Task_next() to iterate through the dynamic tasks.

    To save memory, the static objects are allocated in an array while dynamic objects are put on a linked list.

    Int Task_Object_count();

    // The number of statically-created instance objects
     
    Task_Handle Task_Object_get(Task_Object *array, Int i);
    // The handle of the i-th statically-created instance object (array == NULL)
     
    Task_Handle Task_Object_first();
    // The handle of the first dynamically-created instance object, or NULL
     
    Task_Handle Task_Object_next(Task_Handle handle);
    // The handle of the next dynamically-created instance object, or NULL
     
    IHeap_Handle Task_Object_heap();
    // The heap used to allocate dynamically-created instance objects
     
    Types_Label *Task_Handle_label(Task_Handle handle, Types_Label *buf);
    // The label associated with this instance object
     
    String Task_Handle_name(Task_Handle handle);
    // The name of this instance object
  • Here's a simple example. You can follow the pattern for other SYS/BIOS objects. Obviously, adjust dumpTask() to output the data to where it's actually needed.

    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    #include <ti/sysbios/knl/Task.h>

    void dumpTask(Task_Handle task)
    {
        Task_Stat stat;

        Task_stat(task, &stat);
        System_printf("0x%x: %s %d %d %d %d\n", task, Task_Handle_name(task), stat.priority,
                      stat.mode, stat.stackSize, stat.used);
    }

    void listTasks()
    {
        Task_Object * task;
        Int i;

        for (i = 0; i < Task_Object_count(); i++) {
            task = Task_Object_get(NULL, i);
            dumpTask(task);
        }

        task = Task_Object_first();
        while (task) {
            dumpTask(task);
            task = Task_Object_next(task);
        }
    }

  • Thank you. I shall implement based on your suggestion. I also found Semaphore_object_xxxx functions. 

    Regards,

    Hari

  • Mark,

      I am looking for Semaphore and Mailbox statistics like the following parameters. On Semaphore, I am unable to get any other info other than "count" using Semaphore_getCount(). Whenever I try to use Semaphore_Object in the application program, it comes with compilation problem when I access elements of this Object. casted to Handle. Pl. advise. 

    Regards,

    Hari

  • Hello Hari --

    Those data structures are not documented or readily accessible by the application code.  We might change them in a future release.   You should only use APIs to reference the state.

    If you must access the internals you can use:

    #define ti_sysbios_knl_Semaphore__internalaccess

    before the #include <ti/sysbios/knl/Semaphore.h>

    But, be aware that these structure elements can change between this release and the next.

    -Karl-

  • Hari,

    Karl's right, but you can get most of the status from public APIs without resorting to looking "inside". Here's a (compile-tested) version for the the Mailbox module:

    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    #include <ti/sysbios/knl/Mailbox.h>

    void dumpMailbox(Mailbox_Handle mbox)
    {
        System_printf("0x%x: %s %d %d %d\n", mbox, Mailbox_Handle_name(mbox),
                      Mailbox_getMsgSize(mbox), Mailbox_getNumFreeMsgs(mbox),
                      Mailbox_getNumPendingMsgs(mbox));
    }

    void listMailboxes()
    {
        Mailbox_Object * mbox;
        Int i;

        for (i = 0; i < Mailbox_Object_count(); i++) {
            mbox = Mailbox_Object_get(NULL, i);
            dumpMailbox(mbox);
        }

        mbox = Mailbox_Object_first();
        while (mbox) {
            dumpMailbox(mbox);
            mbox = Mailbox_Object_next(mbox);
        }
    }

    For the Semaphore module, looks like all you can get are the name and count: Semaphore_Handle_name(sem) and Semaphore_getCount(sem).

    Mark

  • I tried Semaphore module. I get a problem with name. 

    Semaphores List():
    semaphore count event eventId , mode
    {unknown-instance-name} 0x8112d780 0x0 0x0 0x1 COUNTING
    {unknown-instance-name} 0x8112d798 0x0 0x0 0x1 COUNTING

    void dumpSemaphore(Semaphore_Handle sem, int dynSem)
    {
    Semaphore_Object *semobj;
    semobj = (Semaphore_Object *) sem;
    st_dpf("%s\t\t0x%p\t\t 0x%X\t0x%X\t0x%X\t%s\n", Semaphore_Handle_name(sem), sem, Semaphore_getCount(sem), semobj->event, semobj->eventId, &semmode[0x1 & (semobj->mode)][0]);
    }

    2. When I create a semaphore, how do I fill name using the APIs?

    Semaphore_Handle semCCreate (int options, int initialCount, char *name)
    {
    Semaphore_Params semParams;

    /* create a Semaphore Instance */
    Semaphore_Params_init(&semParams);
    semParams.mode = Semaphore_Mode_COUNTING;// FIFO
    return(Semaphore_create(initialCount, &semParams, NULL));
    }

  • Hari,

    For any SYS/BIOS object, you use the instance->name field of the Params structure. So for your example, add

    semParams.instance->name = name;

    With this in place, the "unknown-instance-name" will be replaced by your (specified) name.

    Mark

  • Mark,

      Thanks.

        For static definition in the cfg file, how do we get it displayed? (as I showed in the previous picture of .cfg)

       And also is there a API function look for mbx or sem search by Name field? 

    Regards,

    Hari

  • Hari,

    It's the same for statically created SYS/BIOS objects in the .cfg file. Use the instance.name field of the Params structure:

    var task0Params = new Task.Params();
    task0Params.instance.name = "task";
    task0Params.vitalTaskFlag = true;
    Program.global.task = Task.create("&taskFxn", task0Params);

    No, there are not any functions to "search" for named instances.

    Mark

  • I able to get for TASKs. But for Semaphores, mailboxes I do not get any name displayed even though I use Semaphore_Handle_name(sem). The problem is for statically defined in .cfg file.

  • Hari,

    The default for static instances is to not include the string name on the target. You will need to enable that for each module you want to keep the names. This was done to minimize (by default) the memory usage on the target. Here are examples for Semaphore and Mailbox instances created in the .cfg file. Note that you only need to enable "namedInstances = true" once. Why does Task work without this? For some reason, a different SYS/BIOS module (Load) is enabling this but only for Task.

    Semaphore.common$.namedInstance = true;
    var semParams = new Semaphore.Params();
    semParams.instance.name = "example";
    Program.global.esem = Semaphore.create(0, semParams);

    Mailbox.common$.namedInstance = true;
    var mailboxParams = new Mailbox.Params();
    mailboxParams.instance.name = "super";
    Program.global.mbox = Mailbox.create(16, 8, mailboxParams);

    Mark

  • Thank you. I am almost done with the display. Finally I could get the following as runtime display. 

    Semaphores List():
    semaphore count event eventId , mode
    semLed 0x8112dc90 0x0 0x0 0x1 COUNTING
    semMcbspTxRx 0x8112dcac 0x0 0x0 0x1 COUNTING
    semHapiTest 0x8112dcc8 0x0 0x0 0x1 COUNTING
    sem0 0x8112dce4 0x0 0x0 0x1 COUNTING
    semMcBspDone 0x8112dd00 0x0 0x0 0x1 BINARY
    semThrd040CB 0x8112dd1c 0x0 0x0 0x1 COUNTING
    semThrd080CB 0x8112dd38 0x0 0x0 0x1 COUNTING
    semThrd160CB 0x8112dd54 0x0 0x0 0x1 COUNTING
    semThrd240CB 0x8112dd70 0x0 0x0 0x1 COUNTING
    semSpiEdmaRun 0x8112dd8c 0x0 0x0 0x1 BINARY
    {empty-instance-name} 0x8046c8 0x1 0x0 0x1 COUNTING
    {empty-instance-name} 0x80b4d0 0x1 0x0 0x1 BINARY
    {empty-instance-name} 0x80b4f8 0x1 0x0 0x1 COUNTING

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

    task name priority mode stackSize used fxn arg0 arg1
    0x8112d1c0: tsk0FxnHandle 1 BLOCKED 16384 372 0x8104c4d8 , 0x0 , 0x0
    0x8112d208: uartTaskHandle 1 RUNNING 16384 1708 0x8104f254 , 0x0 , 0x0
    0x8112d250: bakerMcbspTxRxTaskhandle 10 BLOCKED 32768 964 0x810143f4 , 0x0 , 0x0
    0x8112d298: main_hal_initTaskHandle 1 TERMINATED 32768 1500 0x81046074 , 0x0 , 0x0
    0x8112d2e0: Thrd040CBhandle 9 BLOCKED 16384 1336 0x81067204 , 0x0 , 0x0
    0x8112d328: Thrd080CBhandle 8 BLOCKED 16384 876 0x8106724c , 0x0 , 0x0
    0x8112d370: Thrd160CBhandle 7 BLOCKED 16384 800 0x8106728c , 0x0 , 0x0
    0x8112d3b8: Thrd240CBhandle 6 BLOCKED 16384 800 0x810672cc , 0x0 , 0x0
    0x8112d400: ti.sysbios.knl.Task.IdleTask 0 READY 2048 980 0x810716e0 , 0x0 , 0x0
    0x8005d0: {empty-instance-name} 1 TERMINATED 16384 1580 0x81016a14 , 0x0 , 0x0
    0x807460: test_pipes 10 TERMINATED 16384 1660 0x81020a14 , 0x807428 , 0x81020A14
    DynTask Arguments = arg[0]:0x0 arg[1]:0x0 arg[2]:0x0 arg[3]:0x0 arg[4]:0x0 arg[5]:0x0 arg[6]:0x0 arg[7]:0x0 arg[8]:0x0 arg[9]:0x0

    0x80b558: dummyTask 1 READY 2048 68 0x81047228 , 0x80B520 , 0x81047228

    DynTask Arguments = arg[0]:0x1 arg[1]:0x14 arg[2]:0x64 arg[3]:0x0 arg[4]:0x0 arg[5]:0x0 arg[6]:0x0 arg[7]:0x0 arg[8]:0x0 arg[9]:0x0

    ------------------------------------------------------------------------------------------------------------------------------------
    Mailbox list:
    mbx name MsgSize FreeMsgs PendingMsgs
    0x8112e910, staticmailbox0 0xA 0x2 0x0
    0x806f08, testp_0 0xA 0x32 0x0
    0x80be58, Dynamic_Mailbox 0x8 0x2 0x0

  • Sorry one more question:

      Is there a way to find out which task has post/Pend Held for Semaphore, mailbox etc.. I see Semaphore displays in the ROV tool as PendedTasks. Is it possible to display these pendedTasks ?

    Thanks

    Hari

  • Hari,

    No, there is currently not a target runtime API to get this info. We'll consider adding this in the future.

    Mark

  • Hi,

    Even after giving the name like "semParams.instance->name = name;" I am not getting the name, still its printing the name as Task handle name: {unknown-instance-name}

    in code 

    Task_Handle task1,task2,task3;
    Error_Block eb,eb2;
    Task_Params params;


    System_printf("enter main()\n");

    Error_init(&eb);
    Task_Params_init(&params);
    // params.instance->name
    params.instance->name = "First_Task";
    task1 = Task_create(First_Fxn, &params, &eb);
    if (task1 == NULL) {
    System_printf("1:Task_create() failed!\n");
    BIOS_exit(0);
    }
    Error_init(&eb2);
    Task_Params_init(&params);
    params.instance->name = "second_Task";
    task2 = Task_create(second_Fxn, &params, &eb);
    if (task2 == NULL) {
    System_printf("2:Task_create() failed!\n");
    BIOS_exit(0);
    }

    ----

    ----

    ----

    BIOS_start();

    Please help.

  • Hi Ramesh,

    Have you enabled named instances for the Task module ? If not, you can do so by adding the following code to your application's cfg file:

    var Task = xdc.useModule('ti.sysbios.knl.Task');
    Task.common$.namedInstance = true;

    With named instances enabled, you should start seeing the Task name you set instead of {unknown-instance-name}.

    Best,
    Ashish

  • Hi Ashish,

    I made the changes and now its displaying the names. Thanks for your help.

    With regards,

    Remesh

  • Hi Ashish,

    With this method we will get the names of  dynamically created task in their order of creation. Is there any way to know what is the next task scheduled (each task have different priority settings ) ?

    With regards,

    Remesh N

  • Hi Remesh,

    I am not sure I completely understand your question. Since SYS/BIOS scheduler is priority based, higher priority tasks will run first. Therefore, the next highest priority task is likely to run next. One thing to note is that since SYS/BIOS scheduler is pre-emptive, it is possible that an interrupt comes in and readies a higher priority blocked task. This would result in an immediate switch to the higher priority task. There is no way to predict this before hand, so it is difficult to predict which task will be scheduled next.

    Best,

    Ashish