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.

(Question Update) Sysbios Task switch hook problem???

Other Parts Discussed in Thread: SYSBIOS, TCI6638K2K

Hi all,

Im using tci6638k2k SoC(4arm+8dsp), we are using sysbios also. Task switch hook make switching between two task,

Void task_switch_hook(Task_Handle from, Task_Handle to){...}

I realize that one of tasks; "my_task" can call this, when from and to equals itself. How it is possible?

I reviewed "C:\ti\bios_6_37_03_30\packages\ti\sysbios\knl\Task.c" source file;

/*
* ======== Task_schedule ========
* Find highest priority task and invoke it.
*
* Must be called with interrupts disabled.
*/
Void Task_schedule()
{
    Queue_Handle maxQ;
    Task_Object *prevTask; 
    Task_Object *curTask;
    #ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS
    Int i;
    #endif

    do {
        Task_module->workFlag = 0;

        /* stall until a task is ready */
       while (Task_module->curSet == 0) {
       Task_allBlockedFunction();
        }

       /* Determine current max ready Task priority */
       maxQ = (Queue_Handle)((UInt8 *)(Task_module->readyQ) +
      (UInt)(Intrinsics_maxbit(Task_module->curSet)*(2*sizeof(Ptr))));

      /* if a higher priority task is ready - switch to it */
      if (maxQ > Task_module->curQ) {
      prevTask = Task_module->curTask;
      Task_module->curQ = maxQ;
      Task_module->curTask = Queue_head(maxQ);
      curTask = Task_module->curTask;

     /* It's safe to enable intrs here */
     Hwi_enable();

     #ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS
    for (i = 0; i < Task_hooks.length; i++) {
    if (Task_hooks.elem[i].switchFxn != NULL) {
    Task_hooks.elem[i].switchFxn(prevTask, curTask);
    }
}
#endif

Log_write4(Task_LM_switch, (UArg)prevTask, (UArg)prevTask->fxn,
(UArg)curTask, (UArg)curTask->fxn);

       /* Hard-disable intrs - this fxn is called with them disabled */
       Hwi_disable();

       Task_SupportProxy_swap((Ptr)&prevTask->context,
       (Ptr)&curTask->context);
       }
    } while (Task_module->workFlag);
}

Note that the "Task_hooks.elem[i].switchFxn(prevTask, curTask);" is defined "task_switch_hook(Task_Handle from, Task_Handle to)"

Note that too; Task_schedule() function needs to call between hwi_disable and hwi_enable(), so any hwi doesnt interrupt switching.

Remember, i saw task_switch_hook's two parameters is same. So im reviewing Task_schedule(). According to calling "task_switch_hook" function, We can say if (maxQ > Task_module->curQ) condition achieved. If my parameters is equal, how it is possible to achieve this condition??? Same task but different priority???

Remeber; process like that;    

    Hwi_disable();

    Task_switching();

    Hwi_enable();

Im thinking of a situation, but i dont know how to test it yet.

Think  task1 proceed and going to blocked state, idle loop will be run, If called an hwi and post a semaphore to Task1 just before Hwi_disable(), and Task_switch_hook calls, So condition looks like if(Prio_task1 > Prio_idle) but actually the current task not an idle, it is task1 actually, so task_switch_hook calls with same parameter. Is it possible?

Any suggestion would be help, Thanks.

Srt

  • Moving this thread over TI-RTOS forum for faster response. Thank you.
  • Hi Srt,

    The Task switch hook is a function that will be called (if defined and configured by the user) when the SYS/BIOS scheduler is making the context switch between Task "from" and Task "to". It does not "cause" a context switch between 2 tasks to happen. Rather, the hook function is called "in between" these two Task functions by the scheduler.

    The "from" and "to" arguments will have the handle of the Task that was previously running, and the handle of the Task that will run next, respectively.

    This function is called by the kernel; the user's app should not call this hook function.

    Steve
  • Hi Steve,

    I understand, only sysbios call task_switch_hook. but how it is possible "from" and "to" same?

    Thanks,

    Srt
  • The switch hook will be called just before the task scheduler switches to a given task.

    One possibility is that you task, let's call it taskA, was interrupted. When the ISR for that interrupt finished, the task scheduler then looked to see what the highest priority task that's ready to run is. It could be that taskA was still the highest priority task and so taskA was scheduled to run, and the switch hook function was called with both 'to' and 'from' set to taskA.

    Steve