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.

Task Scheduling

Expert 1005 points


Hello,

I created a program with two tasks. The source code is as follow:

#include <std.h>
#include <log.h>
#include "TestTaskcfg.h"

 void main()
{
 LOG_printf(&trace,"Program started\n");
}

 

Void Task_1(Arg id_arg)
{
 int i;
 for(i=0;i<10;i++)
 {
  LOG_printf(&trace,"In Task 1- %d\n",i);
  TSK_disable();
  IDL_run();
  TSK_enable();
 }

}

Void Task_2(Arg id_arg)
{

 int i;
 for(i=0;i<10;i++)
 {
  LOG_printf(&trace,"In Task 2- %d\n",i);
  TSK_disable();
  IDL_run();
  TSK_enable();
 }
}

and the tcf is as follow:

utils.loadPlatform("ti.platforms.sim62xx");

/* The following DSP/BIOS Features are enabled.  */
bios.enableMemoryHeaps(prog);
bios.enableRealTimeAnalysis(prog);
bios.enableRtdx(prog);
bios.enableTskManager(prog);

bios.MEM.instance("SDRAM0").createHeap = 1;
bios.MEM.BIOSOBJSEG = prog.get("SDRAM0");
bios.MEM.MALLOCSEG = prog.get("SDRAM0");
bios.LOG.create("trace");
bios.TSK.create("Task1");
bios.TSK.instance("Task1").order = 1;
bios.TSK.instance("Task1").allocateTaskName = 1;
bios.TSK.instance("Task1").fxn = prog.extern("Task_1");

bios.TSK.create("Task2");
bios.TSK.instance("Task2").order = 1;
bios.TSK.instance("Task2").allocateTaskName = 1;
bios.TSK.instance("Task2").fxn = prog.extern("Task_2");

 

bios.TSK.instance("TSK_idle").order = 1;

// !GRAPHICAL_CONFIG_TOOL_SCRIPT_INSERT_POINT!

prog.gen();

and the output is as follow:

5 In Task 1- 4

6 In Task 1- 5

7 In Task 1- 6

8 In Task 1- 7

9 In Task 1- 8

10 In Task 1- 9

11 In Task 2- 0

12 In Task 2- 1

13 In Task 2- 2

14 In Task 2- 3

15 In Task 2- 4

16 In Task 2- 5

17 In Task 2- 6

18 In Task 2- 7

19 In Task 2- 8

20 In Task 2- 9

 

here are my questions:

1- Why the two tasks are not scheduled correctly? My understanding is that since they are time sliced, there should be some output from task 1 and then some output from task 2, but it seems that, task 1 prints all outputs and then task 2 does it. How can I see the time slice effect?

2- How can I change the trace window so I can see all of the outputs, It seems that I can only see some part of the output ( the last 20 line or so).

Best regards

 

  •  

    Hi mans,

    mans said:
    1- Why the two tasks are not scheduled correctly? My understanding is that since they are time sliced, there should be some output from task 1 and then some output from task 2, but it seems that, task 1 prints all outputs and then task 2 does it. How can I see the time slice effect?

    Please read chapter 4.4 of the document:

    http://focus.ti.com/lit/ug/spru303b/spru303b.pdf

    A task does not interrupt another task of the same priority. The only way for a task of the same priority can run is if:

    1) There is no task of the same priority

    2) The is a task of the same priority created but it finished running

    3) The is a task of the same priority created but it it blocked

    4) Of course, a Task can just run if there is no other task of a higher priority running

    This is well explained on the document I mentioned. Notice that DSP/BIOS is not like any other OS in therms of time sharing.

     

     

  • Hi Mariana,

    Correct me if I am wrong, but my understanding is that DSP Bios is NOT time-sliced, but is instead a cooperative preemption task sharing model....ie - Each Task must yield or suspend in order for the other tasks to run.  The priority of tasks comes into play as far as which task is selected to run next once the existing task has yielded or suspended, giving up control back to the DSP Bios scheduler engine.

     

    Am I wrong?

     

     

  • JRasmussen said:
    Correct me if I am wrong, but my understanding is that DSP Bios is NOT time-sliced, but is instead a cooperative preemption task sharing model....ie - Each Task must yield or suspend in order for the other tasks to run.  The priority of tasks comes into play as far as which task is selected to run next once the existing task has yielded or suspended, giving up control back to the DSP Bios scheduler engine.

    I had to re-read this, but your explanation is correct. The scheduler does not force any sort of time-sharing between same priority 'threads' the way other OSes do (such as Linux). If you have two tasks of the same priority the first will always run until it gives up the CPU. You could force a sort of task ping-pong by using something like TSK_yield().

  •  

    Just a clarification...

    JRasmussen said:
    Each Task must yield or suspend in order for the other tasks to run. 

    This is true for tasks of the same priority. But a TSK of priority 1 does not have to yield or block for a TSK of priority 2 to run.  The higher priority TSK will preempt the lowest priority TSK.