Page 258 - Embedded Microprocessor Systems Real World Design
P. 258

SEQUENTIAL SCHEDULING            TIME SLICING
                        SAY THERE ARE THREE TASKS, EACH   THE SAME THREE TASKS  EACH
                        WITH THREE OPERATIONS TO PERFORM   IS GIMNSPEC~F~C TIMESLCES
                        IN SEQUENTIAL OPERATION. EACH TASK   EACH TASK RUNS ONLY UNTIL ITS
                        RUNS UNTIL FINISHED              TIME SLICE IS UP
                                                                       ONE TIME SLICE
                                                                        -- 4 -
                        TASK 1, OPERATION 1
                            OPERATION 2                                 --f-


                                                                        --f  -
                            OPERATION 3
                                                                         TASK 3 IS HIGHER PRIORITY
                                                                         GETS TWO TIME SLICES
                                                                         EACH TIME IT RUNS
                                                       NOTE: FOR SIMPLICIM, EACH OPERATION IS
                                                       ONE TIME SLICE IN LENGTH. IN AN ACTUAL
                                                        SYSTEM, THE OPERATIONS WOULD BE OF
                                                       VARYING LENGTHS AND WOULD BE HALTED
                                                        IN MID-OPERATION AT THE END OF A
                                                       TIME SLICE
                  Figure 9.2
                 Sequential Versus Time-Sliced Operation.

                    Most  RTOSs  can  support  time  slicing  or  sequential  scheduling.  Sequential
                 scheduling also can check for and stop tasks that hog the CPU. In any scheduling
                  system, of course, only one task at a time actually has control of the CPU. Figure
                 9.2 illustrates the difference between time slicing and sequential operation.

                  Preemptive Scheduling

                 Preemptive scheduling is the most common method of scheduling tasks when using
                 an  RTOS,  and  it  is  one  of  the  primary  advantages of  using  an  RTOS.  Under
                 preemptive  scheduling,  a task  runs until  it  is  finished  or  until  a task  of  higher
                 priority preempts it. Before going into more detail about preemptive scheduling,
                 however, we  should look at RTOS’s task handling in general.


                 Activation and Deactivation of  Tasks
                 Tasks under RTOS can be ready or not ready. The RTOS keeps a list of  tasks that
                 are ready and what their execution priority is. A ready task is added to the task list
                 and executed in sequence. When a task becomes not ready, it is removed from the
                 list. Going back to the protocol converter example, the output task might go ready
                 when there is data in the FIFO buffer and become not ready when the FIFO buffer
                 is empty.
                    A ready task may be inhibited from running because something blocks further
                 execution. For example, the protocol converter output task may be ready because


                 Real-Tim Operating Systems                                           2 39
   253   254   255   256   257   258   259   260   261   262   263