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.

change task execution time

Hello

I am new to DSP/BIOS. Suppose i have two tasks of equal priority having very long running loops in them. I want to change the execution time of task 1 to say 350 ms and that of task 2 to 1sec how can i do that. It can be compared to as changing the execution time (time slice) of a task in round robin like scheduling.

 

Thank you

Vishrav

  • Vishrav,

    There are probably a few ways that you can accomplish this.  Let me ask you a few questions first.  I understand that you need both of these to periodically run, and I assume that these two tasks are fairly high priority since you you're dedicating so many CPU cycles to them. 

    So, the first question is, so long as they both execute periodically, why are we limiting them to 350ms/1sec?  I assume that each of these loops needs to complete in some specified period of time.  Why would you want to say "I want task 2 to execute now, but I want to give up task's 2 execution in 1 second, regardless if it has completed, and not really caring whether there are any other tasks needing to execute".  I guess the question really is, why are these priorities set this way? At some point don't we need one of these task to complete?  Which is really the most important? 

    One way to accomplish this is to just do a TSK_Yield() at various points of your algorithm.  This is a way to give other tasks a chance to execute if a task takes too long.  If there are no others that are ready to execute, then the currently executing task will continue.  I would suggest that if one of these algorithms is the most time critical one, don't let that one yield.  So, essentially, if task 1 is the most time critical and needs to complete, you allow it to complete.  But if task 2 runs, at some point in the middle, it will call TSK_Yield() and if Task 1 is waiting to execute, it will execute. 

    Another way might be to do something similar with semaphores.  You could have 2 semaphores , where Task 1 will periodically post Semaphore 2 and then pend on Semaphore 1, and Task 2 will post Semaphore 1 and then pend on Sem 2.  This will implement an alternating execution fashion. 

    If you need very accurate timing, you could use a few timer interrupts to update the priorities.  After Task 2 has been executing for a second, you could lower it's priority, and then raise it from within Task 1 whenever task 1 has completed. 

    You also might consider breaking your tasks down into smaller chunks, 1 second execution for a task is a long time.  You'll get much better control over execution time if the tasks are more granular.  However, this comes at the expense of Program Memory, so if memory is tight, it's understandable why this wouldn't be an option.

    If you want to supply more information about your specific application, we can try to analyze a bit more.

    Regards,

    Dan

     

     

     

  • Hello Dan

    Thank you so much for your reply. I think it will be better if i tell you the original problem that i have to do.

    My task is to implement multitasking of video capture processing and display procedure on DM6437. I have already implemented this task linearly in which firstly the video frames are captured, now they are being resized to cif using the resizer then they are converted to YUV422 format using edma and then i am applying some edge detection algorithm like sobel (using the dsp) and then these steps are being carried out in reverse order and then finally display. I built this application on top of video preview example i.e. i am calling these functions sequentially in the while loop.

    Now when i create the tasks to implement them in a sort of pipeline i have the following problems.

    sometimes the resizing is done before and then capture . sometimes the edma is used before resizing.

    now i want to implement this sort of pipeline and i also want that a task should not get context switched until and unless it is completed.

     

    Thank you

    Vishrav

  • Vishrav,

    This seems like a perfect case for the use of semaphores.  So, you have a while loop that looks like this

    while (1){

    Capture Video();

    Resize();

    ConvertToYUV();

    EdgeDetect();

    ..

    ..

    Display()

    }

     

    This seems like the perfect case to use a Bios Semaphore.  I'd recommend breaking up your while loop into individual tasks. (One for each function that you are calling).  The Bios Semaphore works like a token, and you can use the token to implement this pipelining .  Assume your loop is like the one above (neglect the .. .. functions.).  You would do this 4 Semaphores (Assume they are called SEM_vidCaptured, SEM_resized, SEM_convertedYUV, and SEM_edgeDetected.)  A semaphore works like a resource counter.  When you post it, it increments by one.  When you Pend on it, if the value is greater than one, it is decremented and the code continues.  If it is zero, the task blocks until the value has been incremented. 

    So, your CaptureVideo task would run first, and when one frame of data was ready, it would post the SEM_vidCaptured.

    Your resize function would look like this.  (The others would be similar)

    void resize(){

    SEM_pend(SEM_vidCaptured);  // Wait until the vidCatured Semaphore gets incremented, meaning that a full frame has been captured

    .....

    ....  // Resize Algorithm

    ....

    SEM_post(SEM_resized);  // Post the resized semaphore.  The Convert to YUV task will pend on this until the resize has been completed.

    }

     

    So, you see what we are doing here.  Even though these tasks might be all the same priority, if one of them gets initiated out of order, it will simply block until a frame has completed from the task before it in the pipeline.  Note that you can do multiple buffers this way.  The CaptureVideo task is likely the highest priority task, because if this is streaming data, you have to be sure that you capture it, or you miss it.  So you could make this task a higher priority, meaning that it will execute whenever there is data ready to be captured, and the others will block automatically in order to allow it to execute.  Then, once the data is captured, it posts the vidCaptured semaphore and pends on whatever semaphore tells it that data is ready to be captured. 

    I hope this helps a little.


    Regards,

    Dan

     

     

     

  • Hello Dan

    Thanks for your reply . I will work on the solution you gave.

     

    Vishrav