Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
09/24/08 18:43
Modified:
  09/24/08 19:34

Read: times


 
#158578 - Your Mileage May Vary
Responding to: ???'s previous message
Erik said:
looks impressive; however how long does it take to switch to another task?

Unfortunately, there isn't a clear answer to that question. Obviously, the time to switch tasks depends on the CPU speed. If you look carefully at the code, you will also see that it depends on the depth of the stack at the time of the context switch, since the multitasker only has to copy the currently-used portion of the stack when it does the switch.

To get a ballpark idea of the time, I measured how long it took to get through the following bit of code, where the task switch takes place.
    EnableDebugPin();                           /* DEBUG DEBUG */

    SaveStack(&(stacks[currentTask->taskNumber][0]));
    currentTask->mySP = SP;

/*  Switch to the new task  */

    currentTask = rlh.nextWait;                 /* The new current task */
    rlh.nextWait = currentTask->nextWait;       /* Unlink it from READY list */
    if (currentTask->nextWait != NULL) {
        currentTask->nextWait->prevWait = &rlh;
        }
    currentTask->prevWait = NULL;               /* Unlink it completely */
    currentTask->nextWait = NULL;

/*  Restore the new task's stack and stack pointer */

    SP = currentTask->mySP;
    RestoreStack(&(stacks[currentTask->taskNumber][0]));

    DisableDebugPin();                          /* DEBUG DEBUG */
On a 22 MHz SiLabs C8051F12, I measured about 50 microseconds for most excursions through this snippet. Unfortunately, I don't know offhand what the "typical" stack depth is in this particular program.

Perhaps more important than the absolute time to switch tasks is what fraction of the total time that represents. And once again, that's an "it depends" thing. If an application is thrashing between tasks as fast as it possibly can, then the overhead may be a deal breaker. On the other hand, if the task switches occur only when a human comes along and does something, or maybe in response to some slow timer interrupt, the overhead might not be of any concern at all.

YMMV!

-- Russ


List of 22 messages in thread
TopicAuthorDate
Multi Threading in C for 89S8253            01/01/70 00:00      
   effective?            01/01/70 00:00      
   Protothreads            01/01/70 00:00      
   What do you mean?            01/01/70 00:00      
   What actually you are looking for            01/01/70 00:00      
      Seek Help ! for Serial Communication            01/01/70 00:00      
         start a new thread            01/01/70 00:00      
            Good reply...            01/01/70 00:00      
               hehe...            01/01/70 00:00      
                  purpose            01/01/70 00:00      
                     What tasks?            01/01/70 00:00      
                        tasks            01/01/70 00:00      
                           Superloop            01/01/70 00:00      
                              ok...one more thing            01/01/70 00:00      
                                 If Key == '1' Then            01/01/70 00:00      
                                    statemachine            01/01/70 00:00      
                                       An alternative            01/01/70 00:00      
                                          why not in FAQ or personal page?            01/01/70 00:00      
                                             Yes            01/01/70 00:00      
   An alternative ?            01/01/70 00:00      
      Your Mileage May Vary            01/01/70 00:00      
   thanks alot            01/01/70 00:00      

Back to Subject List