WO1999046679A1 - Apparatus, method and article of manufacture for use with a priority based real-time operating system - Google Patents

Apparatus, method and article of manufacture for use with a priority based real-time operating system Download PDF

Info

Publication number
WO1999046679A1
WO1999046679A1 PCT/US1999/005112 US9905112W WO9946679A1 WO 1999046679 A1 WO1999046679 A1 WO 1999046679A1 US 9905112 W US9905112 W US 9905112W WO 9946679 A1 WO9946679 A1 WO 9946679A1
Authority
WO
WIPO (PCT)
Prior art keywords
task
unit
host processor
queue
register
Prior art date
Application number
PCT/US1999/005112
Other languages
French (fr)
Inventor
Brett Louis Lindsley
Uri Dayan
Moshe Tarrab
Original Assignee
Motorola Inc.
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Priority claimed from US09/037,692 external-priority patent/US6128672A/en
Priority claimed from US09/037,173 external-priority patent/US6430593B1/en
Priority claimed from US09/041,101 external-priority patent/US6360243B1/en
Application filed by Motorola Inc. filed Critical Motorola Inc.
Priority to AU29924/99A priority Critical patent/AU2992499A/en
Publication of WO1999046679A1 publication Critical patent/WO1999046679A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4812Task transfer initiation or dispatching by interrupt, e.g. masked
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system

Definitions

  • the field of the invention relates to multiple task execution processors, in particular, a multi-task execution processor having a preemptive prioritized task scheduling system.
  • Multi-tasking is the capability of a single processor t o execute multiple tasks concurrently.
  • a processor performs multi-tasking execution by switching between tasks using a defined set of multi-tasking rules.
  • real-time multi-tasking systems preferably use a set of rules where tasks are prioritized. Lower priority tasks can be preempted (forcibly switched) to execute a higher priority task if necessary. This "preemptive prioritized" system always executes the highest priority ready task.
  • a "task” is defined as an independent entity o f computing. For example, where a computer system permits many users on different terminals access to the same processor, the computer system assigns a unique task to each user's computing (where each user's computing is unrelated t o another user's computing). Generally, a task unit contains an entry for each task. Tasks are typically synchronized using "events". An event is used to indicate that an activity has taken place, such as data arrival, time-out, etc. Thus, an event may indicate execution of a task, an interrupt service routine or the like. Events are counted using semaphores. Semaphores synchronize the event producer and the event consumer as shown in FIG. 2, numeral 200.
  • ISRs interrupt service routines
  • ISRs are not allowed to consume events because ISRs are not scheduled and execute outside of the normal task scheduling environment of the processor. However, ISRs are allowed to generate events to indicate the status of the cause of the interrupt.
  • a counting semaphore 203 allows a plurality of events to be generated without being lost. Similarly, a plurality of tasks may be waiting for the same event.
  • the semaphore counter When the semaphore counter is positive, it indicates events have been produced but no tasks are waiting for the events. When the semaphore counter is zero, it indicates no events have been generated and no tasks are waiting. When the semaphore counter is negative, it indicates there are no events generated but a plurality of tasks are waiting for the events.
  • the process of generating an event to a semaphore is typically called “posting" the event 204.
  • the process of waiting for an event from a semaphore i s typically called "pending" for the event 205.
  • the task scheduling function 207 must determine if this task should be selected for execution or if it should be put in a list with other ready tasks to be executed at a later time. This decision is based on the priority of the task that is currently executing compared to the priority of the task that has just become ready.
  • the currently executing task continues executing.
  • the new ready task i s moved to a list to be executed at a later time. If the task that has just become ready is a higher priority than the currently executing task, the currently executing task is preempted to allow the new ready task to execute. Thus, the highest priority ready task 208 is always selected for execution.
  • the currently executing task completes i ts computation and becomes inactive.
  • a task becomes inactive by pending on a semaphore when the semaphore count is zero o r negative.
  • a semaphore may represent data buffers that require processing.
  • the task that processes data buffers pends for the semaphore that represents data buffers
  • the task is synchronized to the data buffer generation. If data buffers are available, the semaphore count is greater than zero. Task pend requests on the semaphore allow the task to continue. I f data buffers are not available, the semaphore count is less than or equal to zero.
  • the task pends on the semaphore with a count that is less than or equal to zero the task does not have data for processing and will block execution. At the point when a task pends on a semaphore with zero or negative count, the task that has made the request is not allowed to continue execution and must "block".
  • the task scheduling function stops this task and selects another task for execution.
  • the task scheduling function looks at other ready tasks at the same or lower priorities to determine the next highest priority ready task. If a task is found, it i s selected for execution. If a task is not found, the processor i s put into an idle state until a task becomes ready.
  • the task selection process is easy to understand, in a practical environment this can lead t o significant inefficiencies. For example, the following cause inefficiencies in a preemptive prioritized task scheduling system: • Each time a semaphore is processed, there is a potential for a task change. This causes the scheduling function to be called quite often when many times there is no change.
  • the process of searching for a task may have variable timing making task scheduling functions non- dete rm inistic . • The task scheduler must obtain control of the processor to switch tasks.
  • interrupt service routines typically require entry and exit code to flag interrupt usage and nesting.
  • the flagging i s typically used to call the scheduler to determine i f the interrupt generated an event that may have changed execution.
  • the use of entry and exit code consumes time and is undesirable when processing interrupts.
  • constraints typically involve constraining the functionality of the scheduler. These constraints may include limiting the number of tasks, limiting the number of priority levels, limiting the number of tasks at each priority level, limiting the representation range of the semaphore counter, etc. It is undesirable to have such constraints in a system because such constraints may restrict the type of system that can be supported.
  • FIG. 1 is a block diagram of one embodiment of a device in accordance with the present invention, showing data f l ow and functionality of the invention.
  • FIG. 2 is a diagrammatic representation of event processing and schedule processing with respect to the basic operation of an event driven preemptive prioritized task multitasking system in accordance with the present invention.
  • FIG. 3 shows schematic representations of examples o f special function bits in control registers for task commands, interrupt control and status in accordance with the present invention, describes.
  • FIG. 4 is a flow chart showing one embodiment of steps for implementing the operation of the state machine that controls the accelerator in accordance with the present invention.
  • FIG. 5 is a flow chart showing one embodiment of data flows for executing commands that are synchronous to the task wherein the task must allow the previous command to clear before executing the next command in accordance with the present invention.
  • FIG. 6 is a flow chart indicating one embodiment of the functions that tasks and interrupts use to control the task scheduling accelerator in accordance with the present invention.
  • FIG. 7 is a flow chart showing one embodiment of steps for adding a new task to the currently executing task set in the multi-tasking environment in accordance with the present invention.
  • FIG. 8 is a flow chart illustrating one embodiment of steps for how a task exits to remove itself from the currently executing task set in the multi-tasking environment i n accordance with the present invention.
  • FIG. 9 is a flow chart showing one embodiment of steps for how a task may modify its own priority in accordance wi t h the present invention.
  • FIG. 10 is a flow chart showing one embodiment of steps for how a task may yield to another task at the same priority level in accordance with the present invention.
  • FIG. 11 is a flow chart showing one embodiment of steps for how tasks pend for semaphores on the host processor i n accordance with the present invention.
  • FIG. 12 is a flow chart showing one embodiment of data flows for executing commands that are asynchronous to the task (commands that the task does not need to wait f o r completion or commands generated by interrupts) i n accordance with the present invention.
  • FIG. 13 is a flow chart showing one embodiment of steps for how semaphores are posted by tasks and interrupts on the host processor in accordance with the present invention.
  • FIG. 14 is a schematic representation of operation of pointer registers for assisting the queuing of semaphore posts in accordance with the present invention.
  • FIG. 15 is a flow chart showing one embodiment of steps for how the state machine requests semaphore posts to be moved from the queue on the host processor to the task scheduling accelerator in accordance with the present invention.
  • FIG. 16 is a schematic representation of the data f l ows and information for the accelerator to signal the host processor and communicate changes in the task execution i n accordance with the present invention.
  • FIG. 17 is a flow chart showing one embodiment of steps for the functions executed by the interrupt service routine on the host processor in accordance with the present invention.
  • FIG. 18 is a flow chart showing one embodiment of steps for how the interrupt service routine moves a queued semaphore post to the accelerator in accordance with the present invention.
  • FIG. 19 is a schematic representation of data structures stored on the host processor used to describe the current state of task execution in accordance with the present invention.
  • FIG. 20 is a schematic representation of how the interrupt interface communicates information that determines how the interrupt service routine switches tasks in accordance with the present invention. 10
  • FIG. 21 is a flow chart showing one embodiment of steps for how the interrupt service routine switches tasks i n accordance with the present invention.
  • FIG. 22 is a schematic representation of how processing on the host processor and task scheduling accelerator overlap to provide efficient task switching in accordance with the present invention.
  • FIG. 23 is a flow chart showing one embodiment of steps for how the state machine processes adding task requests from the host processor in accordance with the present invention.
  • FIG. 24 is a flow chart showing one embodiment of steps for how the state machine processes task exit requests from the host processor in accordance with the present invention.
  • FIG. 25 is a flow chart showing one embodiment of steps for how the state machine processes modify priority requests from the host processor in accordance with the present invention.
  • FIG. 26 is a flow chart showing one embodiment of steps for how the state machine processes task yield requests from the host processor in accordance with the present invention.
  • FIG. 27 is a flow chart showing one embodiment of steps for how the state machine processes semaphore pend requests from the host processor in accordance with the present invention.
  • FIG. 28 is a flow chart showing one embodiment of steps for how the state machine processes semaphore post requests 11
  • FIG. 29 is a flow chart showing one embodiment of steps for how the interrupt service routine moves a task between queues in accordance with the present invention.
  • FIG. 30 is a block diagram illustrating how the task scheduling accelerator is physically connected to a host processor in accordance with the present invention.
  • FIG. 31 is a block diagram schematic showing one embodiment of how the task scheduling accelerator may be implemented in a hardware configuration in accordance with the present invention.
  • FIG. 32 is a block diagram schematic showing one embodiment of the state machine that controls the hardware i n accordance with the present invention.
  • FIG. 33 is a schematic representation of examples of encoding of the instructions for the state machine i n accordance with the present invention.
  • FIG. 34 is a block diagram illustrating how data i s typically transferred between a software task or interrupt on a host processor to an external device in the prior art.
  • FIG. 35 is a block diagram illustrating the specific details of implementing an efficient data queuing method.
  • FIG. 36 is a block diagram illustrating the specific details of how hardware queue pointers operate. 12
  • FIG. 37 is a flow chart illustrating the required operations by an interface function on the host processor fo r either writing data to the external device or queuing the data.
  • FIG. 38 is a flow chart illustrating how the interrupt service routine efficiently moves data from the host processor to the external device.
  • FIG. 39 is a block diagram illustrating specific details of how the task command register is cleared.
  • FIG. 40 is a block diagram illustrating specific details of how the Task Scheduling Accelerator efficiently communicates information about a task switch to the Host Processor.
  • FIG. 41 is a flow chart illustrating how the Task Scheduling Accelerator selects a task after the task lock has been turned off and higher priority ready tasks are pending.
  • the present invention resolves the problems wi t h implementing task scheduling without the need for imposing constraints by moving a selected portion of the task scheduling functionality to an external hardware accelerator. By allowing part of the functionality to remain in software on the host processor, flexibility is maintained without the need o f constraints. By moving scheduling decisions to an external accelerator device, fast determination of scheduling decisions is performed. Since the external accelerator device may compute schedule decisions in parallel with activity on the host processor, an overlap of scheduling decisions with host processor activity allows variable or lengthy scheduling decisions to be hidden during host processor activity.
  • the present invention improves upon software task scheduling implementations because software implementations are typically slow, require interrupt service routine entry and exit functions, and execute scheduling functions in serial with task execution. The present invention also improves upon prior a rt hardware devices.
  • Prior art hardware devices store almost a l l of the information for task scheduling locally in the hardware. To minimize the amount of information stored (and reduce the hardware cost), prior art devices require restrictions to l i m i t the number of tasks, the number of tasks at the same priority level, the range of the semaphore counter, etc.
  • the present invention improves upon the prior art by providing a method of determining a ready task that i s dependent only on the number of priority levels and not the number of tasks. This allows many tasks to be added to the system without an increase in the search time for a ready task. Further, scheduling computations for determining ready tasks is overlapped with the host processor for maximum efficiency. Because scheduling computations are performed externally t o the host processor, no entry/exit code is required in interrupt service routines. The present invention is significantly faster than software schedulers. Efficient partitioning of information 14
  • the present invention utilizes a hardware accelerator, herein called a "task scheduling accelerator” (TSA), f o r improving the performance of real-time task scheduling without imposing constraints on the functionality of the system.
  • TSA task scheduling accelerator
  • An efficient partitioning between the TSA and the host processor software allows functional flexibility while providing acceleration of task scheduling functionality.
  • the TSA implements a model of task scheduling where tasks are prioritized and lower priority tasks may be preempted if a higher priority task becomes ready.
  • the TSA may execute commands to add a task, exit the current task, yield to another task at the same priority, modify the current task priority, pend for semaphores or post a semaphore. Using these basic functions, real-time operating system functionality may be developed.
  • the TSA accepts commands from tasks called "synchronous" task commands. These commands are synchronous from the point of view that the task may not issue another synchronous task command until the previous synchronous task command has been completed. It is allowable for the task to perform other activity after issuing a synchronous task command as long as the task verifies the previous synchronous task command has been completed prior to issuing another synchronous task command.
  • the TSA 15 is synchronous from the point of view that the task may not issue another synchronous task command until the previous synchronous task command has been completed. It is allowable for the task to perform other activity after issuing a synchronous task command as long as the task verifies the previous synchronous task command has been completed prior to issuing another synchronous task command.
  • Task Command register to indicate when a synchronous task command has been recognized and clears the status bit when the function is completed.
  • Interrupts perform functions on the host processor asynchronous to task execution. Since interrupts may generate events by posting semaphores, it is necessary to have a separate mechanism for issuing commands that are asynchronous to tasks. When these "asynchronous" commands are issued, there is no need to wait for them to complete.
  • An important aspect of a system using the TSA is that the TSA may request service from the host processor via an interrupt. This allows the host processor to additionally service TSA needs or to perform a task switch at the time of the interrupt. If the TSA determines the current task needs to be preempted, the TSA asserts its interrupt. This interrupt causes the host processor to enter a special mode for processing the interrupt request.
  • a task switch is performed by saving the context of the current task and loading the context of a new task.
  • the context is defined as all the registers used by the task and any shared resources.
  • a task switch involves saving all processor registers and shared resources used by the currently executing task and loading a new set of processor registers and shared resources for the new task.
  • a task command may cause the current task to be preempted.
  • An example of when this occurs is when a task 16
  • the TSA preempts the currently executing task wit h an interrupt and switches to another task. Eventually, the task that was preempted becomes ready to execute. When the task continues executing, it determines the TSA status bit is clear and continues. The task is completely unaware preemption has taken place and other tasks were executed. This transparent switching of tasks is important to minimize exposure of the task scheduling functionality to the application program. In a multi-tasking system, tasks are switched by changing the processor "context". Context is the current information representing the execution state of the task. This typically consists of all of the processor's registers and any additional globally shared resources.
  • the TSA is considered to be a globally shared resource because each task writes task commands to the TSA without regard to other tasks. This introduces a difficult problem with external task scheduling hardware that the present invention solves very effectively.
  • the problem is how . the host processor can determine if the TSA registers represent context or not.
  • the TSA registers are considered to be context similar to the host processor's registers.
  • a second case is illustrated when a task issues a task command that causes the task to be preempted.
  • the TSA's registers are saved and then restored, the command that caused the task switch would be restored causing another task switch.
  • the TSA registers should not be considered context. Further, the status bit that indicates the task command was completed needs to be cleared to indicate to the task that the command has completed.
  • the solution to the TSA "context" is to coordinate the context save/restore procedure between the TSA and the host processor interrupt service routine. This coordination adjusts the context (TSA registers) if the preemption is due to a synchronous task command but preserves the context when the task is being preempted due to an asynchronous task command. The details of this procedure are illustrated in finer detail late r.
  • the solution to this problem is to place additional semaphore posts in a queue.
  • the queuing must be efficient and allow the TSA to control the reading of the queue.
  • the present invention employs a unique solution to this problem by partitioning the storage of additional semaphore posts on the host processor while maintaining the pointers to the queue i n the TSA. This combination allows the TSA to be always aware of the state of the host processor queue without interrogating the host processor. Since the size of the queue depends on the software architecture, it is effective to store the queue in the host processor where the queue size can be determined based on the host processor software. The details of this procedure are described in finer detail later.
  • FIG. 1 shows a block diagram of a Host Processor 1 coupled to a task scheduling accelerator (TSA) 2 that is typically implemented in hardware.
  • TSA task scheduling accelerator
  • the TSA contains registers for control/status or to specify a particular integer value.
  • the control/status registers are shown in FIG. 3, numeral 300. 19
  • the Task Command register 301 indicates synchronous task commands issued by tasks on the host processor. These bits include:
  • Task Exit - This bit is set to exit the currently executing task.
  • Semaphore Pend This bit is set when a task makes a pend request.
  • Task Lock - This bit specifies a mode of operation where the TSA will not preempt the current task. This is typically used to protect critical regions o f programs that share data between multiple tasks. When the bit is cleared, the TSA is allowed to preempt the task.
  • the Interrupt Control register 302 specifies the reason for the TSA interrupt to the host processor. There are three major functions this register controls: 20
  • Task switch The task switch is qualified by fou r bits:
  • the Status register 303 specifies additional status information to the host processor or the TSA. These bits include:
  • CTX - This bit indicates if the TSA-ISR should t re at the Task Command register as context (preserve it) o r not as context (modify it). This bit is used to clear 21
  • Semaphore Post - This bit indicates a task or interrupt service routine has written a semaphore post to the asynchronous task command interface.
  • IDLE This bit is used to retain the state of the task set being in the idle (no active tasks) state.
  • Preemption Pending This bit is set to indicate the current task will be preempted when it turns off the task lock. This bit is set by the TSA if a semaphore i s posted with a higher priority ready task pending when the task lock is enabled. These bits are described in further detail when covering the functions that use them.
  • the Current Execution Priority 44 maintains the priority of the currently executing task.
  • a zero indicates the highest priority with lower prio rities increasing in value.
  • f l owcharts indicate "higher priority” to mean a lower numeric value and "lower priority” to indicate a higher numeric value for priority. Since the Current Execution
  • the first task created by starting the host processor is currently the highest priority.
  • the Ready Task Counters 43 store a plurality of integers that determines the number of ready tasks at each priority level. Since at reset there are no other ready tasks to execute, a l l Ready Task Counters 43 are set to zero.
  • the CTX Flag This bit indicates if the Synchronous Task Command Interface (STCI) 46 contains context. If the CTX bit is set, it indicates the STCI registers should be preserved because they may contain valid information written by the task that is currently executing. If the CTX bit is clear, i t indicates the STCI registers have issued a task command that caused the context switch and the STCI registers should be modified to clear the task command status bit. It is initialized to zero by default.
  • the Semaphore Post flag This bit indicates if the semaphore post registers in the Asynchronous Task Command interface 45 have been written.
  • the Preemption Pending flag This bit indicates a ready task of higher priority will preempt the current task when the task lock is turned off.
  • the Interrupt Control register 403 in the I nterrupt Service Routine Interface 40 This register is cleared because if any bit in the Interrupt Control registe r 403 is set, Interrupt Generator 404 asserts the interrupt 30. Since the TSA does not need any service at start-up, it is required to ensure the interrupt i s negated after reset.
  • the Task Command register 465 in the Synchronous Task Command Interface 46 This register is cleared to indicate there are currently no task commands t o process.
  • the State Machine 41 After initialization 41 1 1 , the State Machine 41 enters a loop checking for a function to execute with comparisons 4120, 4130, 4140, 4150, 4160, 4190 and 41 70.
  • the loop checking includes: Is Sem Pend set in the TCR (Task Command Register)? 4120; Is Sem Post set in Status? 4130; Is Add Task set in TCR? 4140; Is Task Exit set in TCR 4150; Is Task Yield set in TCR? 4160; Is Modify Priority set in TCR? 4190; Does S/W queue have sem posts and are post registers empty? 41 70 ; and, Is the task lock off and the preemption pending bit set? 4195.
  • the TSA processes the true function 4122, 4132, 4142, 4152, 4162, 4192, 4172, 4196 and returns to the beginning of the loop to check Is Sem Pend set i n 6679 pc ⁇ /US99/os ⁇ 2
  • the TSA does not have any functions to process and enters a low power mode 4180 until there is activity.
  • Activity that brings the State Machine 41 out of low power 4180 is any of the loop conditions being true. Since the state machine i s turned off when in low power, activity is detected by di rect hard-wired logic to the state machine. This is shown in detail in FIG. 32 in the Clock Activate Logic 801600 where signals Semaphore Posted 8032, Task Command 8033 and Software Queue Not Empty 8034 indicate to the Clock Activate Logic 801600 to activate the Clock Control 80161.
  • the TSA 2 contains several functional interfaces.
  • the Synchronous Task Command Interface (STCI) 46 allows tasks to issue synchronous task commands. A synchronous task command must wait until the TSA 2 has finished processing the previous synchronous task command before issuing another synchronous task command.
  • the Task Command register 465 i n the STCI 46 provides status bits that indicates the TSA 2 has recognized the command request. The status bit is cleared when the TSA 2 has completed the command.
  • the STCI 46 contains registers as shown in FIG. 5, numeral 500.
  • the Parameter register 460 i used to store values associated with synchronous task commands. Synchronous task commands that require values are Add Task, Modify Priority and Semaphore Pend. When a synchronous task writes the register to request the command, 25
  • STCI 46 registers are associated with functions f o r issuing synchronous task commands as shown in FIG. 6, numeral 600. STCI implements the following functions:
  • the Add Task register 462 is used to issue a command to add a new task to the task set.
  • the Add Task function 123 in the Task Scheduling Programming Interface 12 is described in detail in FIG. 7, numeral 700.
  • the Add task function 123 first adds a new task object to the data structures 11 via data path 21 to configure the context of the new task (task object) 1232 and links the new task object into the Ready Task Queue as specified by the new task priority 1233.
  • the Add Task function 123 then writes the priority of the new task to the Add Task register
  • Task Scheduling Programming Interface 12 is described i n detail in FIG. 8, numeral 800.
  • the task exit function 1 24 sets a bit in the Task Command register 465 to indicate the current task wishes to exit as shown in 1242. To ensure the task exit command has completed 1243, the task exit function 124 waits until the TSA has cleared the Task Exit Bit in the Task Command register 465. This task command has no apparent next step as indicated by no exit from 1 243 because when the task is preempted, it never returns.
  • the Modify Priority register 461 is used to issue a command to change the priority of the currently executing task.
  • Priority function 125 writes a new priority 1252 to the Modify Priority register 461 to issue the command.
  • the new priority is transferred to the Parameter register 460 and the Modify Priority Bit is set in the Task Command register 465. To ensure the modify priority command has completed
  • the Modify Priority function 125 waits until the TSA has cleared the Modify Priority Bit in the Task Command register 465.
  • the Task Yield function • The Task Yield function.
  • the Task Yield function 126 in the Task Scheduling Programming Interface 12 is described i n detail in FIG. 10, numeral 1000.
  • the task yield function 1 26 sets a bit in the Task Command register 465 to indicate the 27
  • the Task Yield function 126 waits until the TSA has cleared the Task Yield bit in the Task Command register 465.
  • the Semaphore Pend function • The Semaphore Pend function.
  • the Semaphore Pend Count register 463 and Semaphore Pend Index register 464 are used to pend for a semaphore specified by a semaphore index.
  • the Semaphore Pend function 122 in the Task Scheduling Programming Interface 12 is described in detail in FIG. 11 , numeral 1100.
  • the Semaphore Pend function 122 first decrements the semaphore count associated with the semaphore index 1222.
  • the semaphore index is an integer representing a particular semaphore.
  • the Semaphore Pend function 122 then writes the decremented count to the
  • Semaphore Pend Count register 463 as shown in 1223.
  • the semaphore count is transferred to the Parameter register 460.
  • the Semaphore Pend function 122 then writes the index of the semaphore to the Semaphore Pend Index register 464 and sets a flag in the Task Command register 465 as shown in 1223.
  • the Task Lock mode is a mode of operation and not a task command.
  • the Task Lock mode indicates t o the TSA that the currently executing task should not be 28
  • the TSA preempted even if a higher priority ready task becomes available. This is typically used to protect data structures accessed by multiple tasks.
  • the task lock mode When the task lock mode is set, only semaphore posts are allowed to be generated by tasks or ISRs. If the task lock mode is set and a higher priority ready task becomes available due to semaphore post, the TSA remembers this by setting the Preemption Pending b i t in the Status register but does not preempt the current task. If there is a preemption pending when the task lock i s turned off, the TSA preempts the currently executing task and selects the higher priority ready task that became available when the task lock was enabled.
  • An important aspect of the present invention is the implementation of the previously described synchronous task commands. Each command is relatively simple to implement, resulting in small memory usage in the host processor.
  • each command simply waits for the associated control bit in the Task Command register 465 to clear t o indicate the command is complete. If a task preemption occurs, it is completely transparent to the task at this time. The task does not need to implement any component of the context switch nor does it need to be aware of any other tasks in the system.
  • Data path 32 indicates the Modify Priority register 461 , the Add Task register, 462, the Semaphore Pend Count register
  • Data path 38 indicates the Parameter register 460, Semaphore Pend Index register 464 and Task Command register 465 are accessible from the Task Scheduling Accelerator Interrupt Service Routine 10 during a task switch.
  • Data path 54 indicates the state machine accesses the Parameter register 460, Semaphore Pend Index register 464 and Task Command register 465 to process scheduling decisions.
  • An asynchronous task command is issued via the Asynchronous Task Command Interface (ATCI) 45.
  • the only task command that is issued asynchronous to tasks by interrupt service routines 14 is the semaphore post.
  • the ATCI may also be used by tasks 13 for posting semaphores although the task does not need to synchronize (i.e., wait for it to complete).
  • the details of the ATCI are shown in FIG. 12, numeral 1200.
  • FIG. 1 2 shows the ATCI contains 3 registers.
  • the Semaphore Post Count register 451 is used to receive the count value of a semaphore.
  • the Semaphore Post Priority register 452 is used to receive the priority of the first task pending on the semaphore.
  • the Semaphore Post Index register 453 is used to receive the index number of the semaphore.
  • Data path 39 indicates the ATCI registers can be written from the 30
  • Semaphore Post- Interface 55 Data path 33 indicates the ATCI registers can be written from the TSA-ISR 10. Data path 53 indicates the ATCI registers may be accessed from the State Machine 41 for computing scheduling decisions. Thus, semaphore posts may be generated from three sources: Tasks 13 and Device Interrupt Service Routines 14 through the Semaphore Post Interface 55, or, from the TSA-ISR 10.
  • the TSA-ISR is the lowest priority interrupt serviced by the host processor.
  • the TSA-ISR may be the last interrupt to be serviced when multiple devices share the same interrupt level. The reason is that it is necessary that no interrupt context be on the host processor stack when a task switch is performed. This requires all interrupts to be finished prior to the TSA performing a task switch. Since interrupts at a higher priority may generate semaphore posts, it is possible for more semaphore posts to be generated than can be processed by the TSA. This is resolved using a queuing mechanism.
  • the Semaphore Post Interface 55 begins by checking the Semaphore Post bit in Status 42 to determine if the semaphore post registers in the ATCI have been written 1512. If decision 1 51 2 is true, the registers have already been written and the semaphore post request must be queued. This is performed i n 1513 by reading the Post Queue Tail register 472 in the Semaphore Post Queue Interface 47, 3 1
  • SemaphorelndexQueue[PostQueue Tail] Semlndex. This register provides an integer that is used as a queue position t o store the index in the Semaphore Index Queue 15.
  • the Semaphore Post Interface 55 increments the sema ⁇ hore count at the specified index 1514, i.e.,
  • SemaphoreCount [Semlndex]. This incremented count is w r i tte n to the Semaphore Post Count register 451 ,
  • SemaphorePostCount SemaphoreCount[Semlndex], as is shown in 1515.
  • a unique aspect of the present invention is the method for managing the Semaphore Index Queue 15. As has been indicated, semaphore indices are placed in the Semaphore Index Queue 15 if the ATCI registers are currently full. The detai ls of the interface in the TSA for managing the queue pointers are shown in FIG. 14, numeral 1400. When the Semaphore Post Interface 55 reads the Post Queue Tail register 472, tne Post Queue Tail register 472 auto-increments to then next queue 32
  • a Comparator 474 compares the Post Queue Tail register 472 to a maximum value stored in the Post Queue Max register 470. If the Comparator 474 indicates the maximum value has been reached, the Post Queue Tail register 472 i s reset.
  • a similar operation occurs for the Post Queue Head register 471 except the Post Queue Head register 471 is read by the Task Scheduling Accelerator Interrupt Service Routine 10. When the Post Queue Head register 471 is read, it auto- increments to the next queue position.
  • a Comparator 475 compares the Post Queue Head register 471 to a maximum value stored in the Post Queue Max register 470. If the Comparator 475 indicates the maximum value has been reached, the Post Queue Head register 471 is reset.
  • the Post Queue Head register 471 and Post Queue Tail register 472 are compared using Comparator 478 to determine if the two registers are equal. If they are equal, signal 51 indicates the Semaphore Index Queue 15 is empty. If the registers are unequal, signal 51 indicates the Semaphore Index Queue 15 i s not empty. When signal 51 indicates the Semaphore Index Queue 15 is non-empty and Status 42 indicates the Semaphore Post bit is clear, then the State Machine 41 determines at decision 4170 to execute the Process Move Post 4172 function, as shown in FIG. 15, numeral 1500. The Process Move Post 4172 first sets the CTX bit 41721 in the Status register 42 to indicate that when the host processor services the interrupt 33
  • the registers in the STCI are context (i.e., should be preserved).
  • the State Machine 41 then indicates to the Interrupt Service Routine Interface 40 that the ATCI can be written with a value from the Semaphore Index Queue 15 by setting the Move Post bit in Interrupt Control register (ICR) 403 as shown in 41722.
  • the Process Move Post 4172 then waits for the Task Scheduling Accelerator Interrupt Service Routine 10 to process the interrupt 41723.
  • the Process Move Post function 4172 knows the host processor has serviced the Move Post request when the Task Scheduling Accelerator Interrupt Service Routine 10 clears the Move Post bit in the Interrupt Control register 403.
  • the interrupt Status Information Interface 1601 typically includes a Move Current To register 401 , a Take New From register 402 and an Interrupt Control Register 403 that is coupled to an Interrupt Generator 404.
  • the Interrupt Generator 404 determines if any bits are set in the Interrupt Control register 403 and asserts the interrupt 30. If all bits in the Interrupt Control Register 403 are clear, the Interrupt Generator 404 negates the interrupt 30.
  • the host processor responds to the interrupt assertion 30 by activating the TSA-ISR 10 (TSA Interrupt 1 0) as shown in FIG. 17, numeral 1700.
  • TSA-ISR 10 f i rst determines the state of the CTX flag 102. Since it is known f o r a Move Post function that this bit is set, the Task Control register is not cleared. The details of this clearing action are explained in greater detail later.
  • the Interrupt Control register 34 determines if any bits are set in the Interrupt Control register 403 and asserts the interrupt 30. If all bits in the Interrupt Control
  • the TSA-ISR 10 executes the function to move a semaphore post from the Semaphore Index Queue 15 to the ATCI as shown in 104.
  • the details of the Move Semaphore Post 104 function are shown in FIG. 18, numeral 1800.
  • the Semaphore Count associated with the semaphore index i s incremented, SemaphoreCount [Semlndex], as shown in 1 043.
  • the Move Semaphore Post 104 function then obtains the priority of the first task pending (in list Semlndex) on the semaphore f rom Data Structures 11. This priority is written to the ATCI Semaphore Post Priority register 452 as shown in 1045.
  • the action of writing the Semaphore Post Index register 453 causes the ATCI to set the Semaphore Post bit in Status 42.
  • the TSA-ISR indicates the Move Semaphore Post 104 function has been completed by clearing the Move Post bit in the I nterrupt 35
  • Control register 403 as shown in 1047.
  • the ability of the TSA to request information from the semaphore post index queue by asserting its interrupt relieves the host processor from having to poll the TSA to determine when it is ready.
  • the State Machine 41 recognizes a command pending by examining the Task Command register 465 or the Status register 42.
  • the state machine makes scheduling decisions to determine if the currently executing task i s allowed to continue execution or if the currently executing task must be preempted.
  • the State Machine 41 may also request from the Host Processor 1 to move a semaphore index from the Semaphore Index Queue 15 or to make a modification to the task list. The last two functions do not change the execution of the currently executing task.
  • a unique aspect of the present invention is how the State Machine 41 efficiently communicates the task switch to the host processor by using the Interrupt Service Routine Interface 40.
  • Data Structures 11 represent the current state of the task set on the host processor as shown in FIG. 19, numeral 1900.
  • a "task object" 116 is the information representing the current 36
  • the simplest information the task object stores is the task priority and the context of the task.
  • the task object 116 is not linked into any list.
  • the task object 116 is linked into a Ready Task List 1 17 according to the task priority.
  • a task of priority zero is linked into the list at the top of the head nodes and tasks of lower priority are linked into lists further from the top of the head nodes.
  • the task object 116 is linked into a list according to the semaphore i t is waiting for.
  • Semaphore Counting semaphores allow a plurality of tasks to be waiting for a single semaphore.
  • the Semaphore Count 115 represents the number of events that have been generated or requested for each semaphore. In the situation where the semaphore is zero or positive, there are no blocked tasks on the associated Semaphore List 118. I n the situation where a Semaphore Count 115 is negative, the negative value indicates how many tasks are waiting for the semaphore and equivalently, how many tasks are linked into the Semaphore Lists 112.
  • the Head Nodes 113 and 114 are stored contiguously in memory such that a single integer can reference either list. If the integer is zero, it references the highest priority ready task queue 113. If the integer is less than the number of priorities, the integer references a lower priority list 113. If the integer is the same or greater than the 37
  • head nodes for the semaphore lists 114.
  • head nodes113 contains 64 head nodes and head nodes 114 contains 100 head nodes.
  • An index of 0 would reference the highest priority ready task l i s t in 110, an index of 63 would reference the lowest priority ready task list in 110 and an index of 100 would reference the
  • a single integer can reference tasks that are ready for execution at each priority level or tasks that are waiting for any semaphore.
  • both lists provides an efficient mechanism for specifying a task switch as shown i n FIG. 20, numeral 2000.
  • the Interrupt Service Routine Interface 40 implements two registers containing integers f o r referencing lists.
  • the Move Current To register 401 specifies an integer indicating a list to move the Currently Executing Task 111 to.
  • the Take New From register 402 indicates a l i st to take the new task object for execution to replace the Currently Executing Task 111.
  • the Host Processor 1 does not perform any computations or decisions in determining the task switch - it simply responds to the decisions made by the TSA 2 and adjusts the task lists accordingly.
  • the Interrupt Control register 403 contains three bits called Save Context, Load Context and Idle.
  • Save Context bit When the Save Context bit is set, it indicates the Move Current To register 401 contains a valid integer and the Currently Executing Task 111 should be saved. As an example, i n 38
  • this bit i s zero indicating the Currently Executing Task is no longer needed and it should not be linked into any list.
  • the Load Context bit indicates the Take New From register 402 contains a valid integer and the Currently Executing Task 1 1 1 should be replaced by the first task on the list specified by the Take New From register 402.
  • this bit is clear indicating there is no new task to execute.
  • the Idle bit is set when there is no new task to execute and the task set is idle. This functionality is similar to the Load Context bit; however, if a task exits and there is no new task to execute, both the Save Context and Load Context bits are clear. In order to indicate the idle condition, the Idle bit is set to allow the Interrupt Generator 404 to assert the interrupt 30.
  • a unique aspect of the present system is the method used to control context of the TSA. It is required for the TSA to clear command bits in the Task Command register 465 (set by synchronous commands) after the command has been processed. This is trivial when there is no change in the executing task - the TSA clears the bit and the task continues. However, when a preemptive task switch occurs, it is necessary to clear the command bit such that the task switch is transparent and when the preempted task is restarted it sees the command has been completed. This is not trivial because preemptive task switches are "transparent" to tasks - a task is never aware a preemption has taken place. Although the TSA asserts the 39
  • a realistic processor may execute several instructions after the interrupt i s asserted because the host processor hardware typically requires time to synchronize and dispatch the interrupt.
  • the command bit is not allowed to be cleared until after the host processor has begun the actual TSA-ISR. If the TSA clears the command bit prior to this time, the task may erroneously execute additional instructions because it has seen the command bit clear.
  • Another potential solution would be t o clear the command bit when the task context is reloaded. However, this does not work because if the task switch was caused by an asynchronous task command (i.e. a semaphore post from an interrupt), the bit would be cleared when in reality i t may be valid.
  • the processor does not know if the task switch that is occurring i s due to a synchronous task command (command bits should be cleared) or an asynchronous task command (command bits should be preserved) - only the TSA knows this information. This is resolved by having the TSA provide a bit called CTX f o r indicating if the Task Command register 465 represents context (and it should be preserved) or if it is not context because the task switch is due to a synchronous task command (and it should be cleared). This indication is made to the TSA- ISR as shown in FIG. 17 where the Task Control register 465 i s cleared if the CTX bit is clear 102.
  • this operation 102 is performed at the start of the interrupt service when i t can be guaranteed that the currently executing task has been preempted but before the context for the currently executing task is saved.
  • the Task Switch 107 can save the TSA registers and restore them.
  • 102 is shown as being implemented as a step in the TSA-ISR, a software implementation of this function would be slow because i t would require inquiring the CTX bit in the TSA and conditional execution.
  • the present invention provides a unique solution to this efficiently by implementing function 102 directly i n hardware of the TSA. This is implemented by realizing the Interrupt Control register 403 is accessed only by the TSA- ISR. In other words, if the Interrupt Control register 403 i s read or written, the TSA can be assured the current task has been preempted.
  • the function 102 may be implemented 41
  • the TSA-ISR 10 performs four major functions as shown in FIG. 17. The TSA-ISR 10 first adjusts the context of the Task Command register 465 if necessary as shown in 102. The second major function the TSA-ISR 10 performs is to move semaphore post indexes from the Semaphore Index Queue 15 as shown in 104 if the Move Post bit is set in the Interrupt Control register 403 according to decision 103.
  • the thi rd major function the TSA-ISR 10 performs is to adjust the task lists if the Move Task bit is set in the Interrupt Control register 403 if decision 105 is true. This function moves a task from one list to another as shown in 106. This operation does not disturb the currently executing task but simply modifies links in Data Structures 11. If TSA-ISR function i s neither the Move Task nor Move Post function, then the Interrupt Control register 403 performs its fourth major function, a task switch 107.
  • the task switch function is shown in detail in FIG. FIG. 21 , numeral 2100.
  • the task switch procedure between the host processor and the TSA is designed for maximal overlap t o minimize (and generally eliminate) the overhead of the TSA scheduling decisions.
  • the Task Switch 107 first determines i f the context of the currently executing task needs to be saved 10720. If the Save Context bit is set in the Interrupt Control 42
  • the processor registers and the TSA registers (Parameter 460, Semaphore Pend Count 463 and Task Command 465 registers) are saved as context in the currently executing task object 111 as shown in 10721.
  • the currently executing task object 111 is then moved to a list as indicated by the integer in the Move Current To register 401 as shown i n 10722.
  • the Task Switch 107 then clears the Save Context b i t in the Interrupt Control register 403 as shown in 10723. Clearing this bit implicitly handshakes with the TSA that the context has been saved. At this point, the Task Switch 1 07 waits for the TSA to determine the next ready task.
  • the TSA-ISR waits at 10724 for the TSA to clear the Busy bit in the Interrupt Control register 403. When this bit i s clear, it indicates the TSA has finished searching the task l i s t and the decision to load context 10730 may now be checked. Although the TSA has searched the task list, it is possible that no ready task was found and the processor is now idle.
  • the decision 10730 determines if the TSA has located another ready task by determining if the Load Context bit in the Interrupt Control register 403 has been set. If the Load Context bit is set, this indicates a new task has been found and should 3
  • the new task is taken from the list indicated by the Take New From register 402 as shown in 10731 .
  • the host processor then loads the context from the task object 1 0732. Loading the context involves loading the host processor registers and restoring the TSA registers (Parameter 460 , Semaphore Pend Count 463 and Task Command 465 registers) . After the context has been restored, the Load Context bit in the Interrupt Control register 403 is cleared 10733 to indicate t o the TSA that the task context has been reloaded. If there is no context to be loaded (10730 is false) , then the processor i s idle and decision 10740 is true.
  • the host processor sets up an idle loop 10741 and clears the Idle bit in the Interrupt Command register 43 as shown in 1 0742. Clearing the Idle bit handshakes with the TSA to let it know that the host processor is entering an idle mode.
  • the TSA-ISR returns. This either switches to a new task if a new task context was loaded, or, idles the processor if no task was loaded.
  • the details of the sequence of events for minimizing TSA scheduling decisions are shown in FIG. 22, numeral 2200.
  • the worst case scheduling decision is when the currently executing task blocks because the semaphore count is zero or negative. I n this situation, the TSA examines each priority level for a non- zero Ready Task Counter 43. A unique operation of the present invention effectively hides this worst case to virtually zero time. Assume the Host Processor 1 is currently executing a 44
  • the task writes the pend request to the TSA 2 and the TSA 2 recognizes the request 620 and starts the State Machine 41.
  • the State Machine 41 immediately determines the current task must be preempted.
  • the TSA 2 immediately asserts its interrupt. Note that at the time the interrupt is asserted, the State Machine 41 has not yet started looking for the next ready task. When the interrupt is asserted, the Host Processor 1 requires some time to synchronize and dispatch the interrupt 612.
  • the Host Processor 1 requires time to save the context of the current task and move the task to the list specified by the Move Current To register 401 as shown in 613. While the processor is saving the task context and adjusting the list, the TSA 2 is searching for the next ready task 621. At this point, the TSA 2 and the host processor must synchronize their activities 614. The Host Processor 2 first clears the Save Context bit in the Interrupt Control register 403 to indicate i t has completed saving the context and adjusting the lists. If the Host Processor 1 finishes first, the host processor TSA-ISR waits until the TSA 2 clears the Busy bit in the Interrupt Control register 403. Since the TSA 2 is micro-coded hardware, it generally finishes well before the Host Processor 1. If the TSA 2 finishes first, the Busy bit is already cleared when the host processor reads it. 45
  • the TSA 2 is assumed to have found a ready task after searching the list.
  • the Host Processor 1 checks the TSA 2 to ensure it is ready 614 and the TSA 2 indicates it is ready after searching the task list 622.
  • the Host Processor 1 then loads the context of the new task 615 and the TSA 2 waits for acknowledgement of the load 623 by waiting for the Load Context bit in the Interrupt Control 403 to clear.
  • the Host Processor begins execution of the new task 616 by performing a "return from interrupt" (RTI). This exits the TSA-ISR and begins execution of the new task 617. After the TSA 2 has determined the new task context has been loaded, it idles waiting for more commands to process 624.
  • RTI return from interrupt
  • the most time consuming part of task scheduling computation performed by the TSA 2 is overlapped with the operations on the Host Processor 1 to effectively hide the scheduling computation.
  • This is not possible in a software scheduler because no matter how efficiently the software scheduler is, the process of determining the next ready task must be performed serially with the task saving and loading.
  • Additional efficiency of using the TSA 2 is that the method o f searching for the next ready task is linear in the number o f priorities and is independent of the number of tasks. Adding additional tasks to the task set does not change the amount of time required to search for a ready task. The ready task search time is only dependent on the number of priority levels.
  • the State Machine 41 begins a sequence of instructions to process the newly added task (Process Add Task 4142) and is shown i n detail in FIG. 23, numeral 2300.
  • the addition of the new task i s recorded by incrementing a counter representing the number of ready tasks at the priority level where the new task was added 414212.
  • the State Machine 41 determines the priority level were the new task was added. This is obtained from the Parameter register 460 because the Add Task command 123 wrote the priority to the Add Task register 462. This value was transferred to the Parameter register 460.
  • the state machine next determines if the newly added task is at a higher priority than the currently executing task 414214.
  • the State Machine 41 sets up the task switch in 414220 by (1) clearing the CTX bit, (2) indicates the current task should be moved to the list for the current priority level by setting the Move Current To register 401 to the priority level of the currently executing task and (3) indicates the new task should be taken from the list specified by the priority level where the new task was added by setting the Take New From register 402. 47
  • both the Move Current To register 401 and the Take New From register 402 are valid, both the Save Context bit and the Load Context bit in the Interrupt Control register 403 are set 414221.
  • the Interrupt Generator 404 asserts interrupt 30.
  • the TSA performs additional functions.
  • the number of ready tasks at the priority level specified by the priority of the added task is decremented 414222 because this task is taken from the list by the TSA-ISR.
  • the number of ready tasks at the priority level specified by the current execution priority i is incremented 41223 because the task being preempted is moved to this list.
  • the state machine then waits for the TSA-ISR to indicate the task switch has taken place by waiting for the TSA-ISR to clear the Save Context and Load Context bits in the Interrupt Control register 403 as shown in 414224.
  • the TSA-ISR responds to the interrupt as shown in FIG. 17, the Task Command register 465 clears when the host processor reads the Interrupt Control register 403 because CTX is clear as shown in 102. This clears the Add Task flag bit in the Task Command Register 465. Since the Interrupt Control register 403 has the Save Context bit and Load Context bit set, decisions 103 and 105 are false. This results in the TSA-ISR executing the Task Switch 107 function. When the Task Switch 107 function clears both the Save Context and Load Context bits in the Interrupt Control register 403, the state machine continues from its wait at 414224 and the Interrupt Generator 48
  • the state machine then updates the current execution priority of the TSA to the priority of the new task that was added 414225.
  • the State Machine 41 recognizes the Task Exit bit in the Task Command register 465 is set in 4150.
  • the State Machine 41 begins a sequence of instructions to process the exiting task (Process Task Exit 4152) and is shown in detail in FIG. 24, numeral 2400.
  • the State Machine 41 determines if there i s another ready task by searching the Ready Task Counters 43 from the Current Execution Priority 44 to the lowest priority as shown in 415211. If the State Machine 41 determines there are no ready tasks, then decision 415212 is false and the processor is idle.
  • the State Machine 41 clears the CTX bit t o indicate the Task Command register currently does not contain context 415213.
  • the State Machine 41 also sets the IDLE flag in the Status register 42 to remember the state of the host processor 415213. Since there is no task to save (the current task is exiting) and no task to load (the host is now idle), the State Machine sets only the Idle bit in the Interrupt Control register 403 as shown in 415214. When the Idle bit is set i n the Interrupt Control register 403, the Interrupt Generator 404 asserts interrupt 30. The TSA has no additional computation and simply waits for the host processor to clear the IDLE bit i n the Interrupt Control register 403 as shown in 415215. When the TSA-ISR responds to the interrupt as shown in FIG. 17, the Task Command register 465 clears when the host processor 49
  • the State Machine 41 sets the Take New From register 402 to the priority level were the ready task was found 415220.
  • the TSA Current Execution Priority 44 i s updated to the priority level where the new task was found 415222.
  • the Ready Task Counter 43 at the priority of where the ready task was found 415223 is decremented. Since there is no task to save (the current task is exiting) but there is a task to load (a ready task was found), the State machine 41 sets the Load Context bit in the Interrupt Control register 403 as shown in 415224.
  • the State Machine 41 then waits for the TSA-ISR to clear the Load Context bit in the Interrupt Control register 403 as shown in 415226. When the TSA-ISR responds to the interrupt as shown i n
  • the Task Command register 465 clears when the host processor reads the Interrupt Control register 403 because the 50
  • CTX bit is clear as shown in 102. This clears the Task Exit flag bit in the Task Command register 465. Since the Interrupt Control register 403 has only the Load Context bit set, decisions 103 and 105 are false. This results in the TSA-ISR executing the Task Switch 107 function. The Task Switch 1 07 ignores the task object of the currently executing task (because it is exiting) and loads the context of the new object. When the Task Switch 107 function clears the Load Context b i t to indicate the context of the new task has been loaded, the State Machine continues from its wait at 415226 and returns to the main loop.
  • the State Machine 41 recognizes the Task Yield b i t in the Task Command register 465 is set as shown in 4160.
  • the State Machine 41 begins a sequence of instructions to process the task yield request (Process Task Yield 4162) and is shown in detail in FIG. 26, numeral 2600.
  • the Process Task Yield determines if another ready task is present at the same priority level by using the Current Execution Priority 44 and the Ready Task Counters 43 as shown in 416221. If the Ready Task Counter is zero, there are no other ready tasks at the current priority level and decision 41622 is false.
  • the State Machine 41 clears the Task Yield bit in the Task Command register 465 as shown in 41623.
  • the Task Yield function 1 26 then continues executing after verifying the Task Yield bit i s clear 1263. If the decision 41622 determines another task i s ready at the same priority level, the currently executing task 51
  • the State Machine 41 sets up the task switch i n 41624 by (1) clearing the CTX bit, (2) indicating the current task should be moved to the list for the current priority level by setting the Move Current To register 401 to the priority level of the currently executing task and (3) indicating the new task should be taken from the list specified by the current execution priority by setting the Take New From register 402. Because the Move Current To register 401 and the Take New From register 402 are set to the same value (the Current Execution Priority), the effect of the task yield function is t o rotate the ready task list at the current priority level.
  • both the Save Context bit and the Load Context bit in the Interrupt Control register 403 are set 41625.
  • the Interrupt Generator 404 asserts interrupt 30.
  • the State Machine 41 then waits for the TSA-ISR to indicate the task switch has taken place by waiting for the TSA-ISR to clear the Save Context and Load Context bits in the Interrupt Control register 403.
  • the Task Command register 465 clears when the host processor reads the interrupt Control register 403 because CTX is clear as shown in 102. This clears the Task Yield flag bit i n the Task Command Register 465. Since the Interrupt Control register 403 has the Save Context bit and Load Context bit set, decisions 103 and 105 are false. This results in the TSA-ISR 52
  • Task Switch 107 executing the Task Switch 107 function.
  • the Task Switch 107 function clears both the Save Context and Load Context bits in the Interrupt Control register 403
  • the state machine continues from its wait at 41626 and the Interrupt Generator 404 negates the interrupt 30.
  • the State Machine 41 recognizes the Modify Priority bit in the Task Command register 465 is set as shown in 4190.
  • the State machine 41 begins a sequence of instructions t o process the change in task priority (Process Modify P riority 4192) and is shown in detail in FIG. 25, numeral 2500.
  • the State Machine 41 determines the new priority level from the Parameter register 460 because the Modify Priority command 125 wrote the new priority to the Modify Priority register 461. This value was transferred to the Parameter register 460.
  • the state machine next determines if the new priority is higher o r the same as the current execution priority 41921.
  • the state machine updates the current execution priority to the new priority 41922 and clears the Modify Priority bit i n the Task Control register 41923. If the decision 41921 determines the new priority is lower, then it is possible that other ready tasks that were previously at a lower priority level are now higher priority.
  • the state machine searches the Ready Task Counters 43 from the Current Execution Priority 44 53
  • the State Machine 41 sets up the task switch in 41927 by (1 ) clearing the CTX bit, (2) indicating the current task should be moved to the list for the new priority by setting the Move Current To register 401 to the new priority level and (3) indicating the new task should be taken from the list specified by the priority level where the new task was found by setting the Take New From register 402. Since both the Move Current To register 401 and the Take New From register 402 are valid, both the Save Context bit and the Load Context bit in the Interrupt Control register 403 are set 41928. The number of tasks at the priority level where the current task is being moved to is incremented 4192810. The number of tasks at the priority level where the new task i s being taken from is decremented 4192820.
  • the State Machine 41 then waits for the TSA-ISR to clear both bits 41929.
  • the Interrupt Generator 404 asserts interrupt 30.
  • the state machine then waits for the TSA-ISR to 679 -,,-----_
  • the Task Command register 465 clears when the host processor reads the Interrupt Control register 403 because CTX is clear as shown in 102. This clears the Modify Priority flag bit in the Task Command Register 465. Since the Interrupt Control register 403 has the Save Context bit and Load Context bit set, decisions 103 and 105 are false. This results in the TSA-ISR executing the Task Switch 107 function. When the Task Switch 107 function clears both the Save Context and Load Context bits in the Interrupt Control register 403, the state machine continues from its wait at 41929 and the Interrupt Generator 404 negates the interrupt 30. The state machine then updates the current execution priority of the TSA to the priority of the new task that was found 41926.
  • the State Machine 41 recognizes the Semaphore Pend bit in the Task Command register 465 is set as shown i n 4120.
  • the State Machine 41 begins a sequence of instructions to process the semaphore pend (Process Semaphore Pend 4122) and is shown in detail in FIG. 27, numeral 2700.
  • the processing of the semaphore pend begins by examining the value of the semaphore count 412212 that was written to the Semaphore Pend Count register 463.
  • the decision 412212 determines i f the semaphore pend count is less than zero. If this is false, i t 55
  • the decision 412212 determines the semaphore pend count is less than zero then the current task i s preempted. Since the counter was decremented prior to being written to the Semaphore Post Count register 463, a value that is negative indicates the original counter was zero or negative prior to being decremented. A negative or zero count on the semaphore indicates the semaphore previously had no events. A pend request on a semaphore without events causes the task to block execution until events become available.
  • the State Machine 41 sets up the task switch in 412220 by (1 ) clearing the CTX bit, (2) indicating the current task should be moved t o the list to wait for the semaphore as specified by the Semaphore Pend Index register 464 and (3) setting the Save Context and Busy bits in the Interrupt Control register 403. A t this time it is known the current task can be preempted and i t s 56
  • the Interrupt Generator 404 asserts interrupt 30. While the host processor i s synchronizing the interrupt, the TSA looks for another ready task at the same or lower priority levels 412222.
  • the Task Command register 465 clears when the host processor reads the Interrupt Control register 403 because the CTX bit is clear as shown in 102. This clears the Semaphore Pend flag bit in the Task Command Register 465. Since the Interrupt Control register 403 has only the Save Context and Busy bit set, decisions 103 and 105 are false. This results i n the TSA-ISR executing the Task Switch 107 function. The TSA- ISR clears the Save Context bit 10723 to indicate the context of the executing task has been saved and then waits while the Busy bit 10724 in the Interrupt Control register is set. The decision 412224 determines if a ready task has been found.
  • the TSA waits 412230 for the TSA- ISR to clear the Save Context bit in the Interrupt Control register 403 to ensure the TSA-ISR does not further write the Interrupt Control Register.
  • the TSA then responds 412232 by clearing the Busy bit and setting the Idle bit in the Interrupt Control Register 403.
  • the internal IDLE bit is set to indicate the task set is now idle 412234.
  • the Task Switch 107 function idles the host processor 10741 and clears the Idle bit 10742 in the Interrupt Control register 403.
  • the state machine continues from its wait at 412236 and then exits to the main loop. If when searching for a ready task 412222 determines a ready task was found, then decision 412224 is true.
  • the Take New From register 402 is set to indicate the priority level where a new task was found 412240.
  • the TSA waits 412246 for the TSA-ISR to clear the Save Context bit in the Interrupt Control register 403 to ensure the TSA-ISR does not fu rther write the Interrupt Control Register. The TSA then responds
  • the TSA-ISR continues and determines if there is a new context to load 10730. Since the Load Context bit is set, the Task Switch 1 07 function removes the task from the list 10731 , loads the context 10732, and clears the Load Context bit 10733 in the Interrupt Control register 403.
  • the TSA i s performing other functions - the Current Execution Priority 44 is set to the priority where the new task was found 412242 and the number of ready tasks at that priority level i s decremented 412244.
  • the state machine continues from its wait at
  • the semaphore pend function is virtually transparent to the- host processor because (1) the TSA hides the determination o f the next ready task during the time the host processor i s saving the context of the current task and (2) the TSA hides i t s internal updates during the time the host processor is loading the context of the next task.
  • the task switch time i s limited only by the time it takes for the Host Processor 1 t o context switch and is not dependent on the TSA 2.
  • the State Machine 41 recognizes the Semaphore Post bit in the Status register 42 is set as shown in 4130.
  • the State machine 41 begins a sequence of instructions to process the semaphore post (Process Semaphore Post 41 32) and i s shown in detail in FIG. 28, numeral 2800.
  • the process of posting a semaphore is different than the previously described task commands because (1 ) semaphore posts can be requested by interrupts as well as tasks and (2) there is no "synchronization" with the semaphore posts (tasks/lSRs do not wait for them to complete).
  • the processing of the semaphore post begins by examining the value of the semaphore count 413212 that was written to the Semaphore Post Count register 451.
  • the decision 413212 determines i f the semaphore post count is less than or equal to zero. If th is is false, it indicates the semaphore post count is greater than zero. Since this counter was incremented prior to being 59
  • Semaphore Post Count register 451 a value that is greater than zero indicates the original counter was greater than or equal to zero prior to being incremented.
  • a semaphore count greater than or equal to zero indicates there were no tasks pending for this semaphore and therefore no new tasks have become ready.
  • the State Machine 41 clears the Semaphore Post bit in the Status register 42 as shown in 413214. If the decision 413212 is true, it indicates a task is currently pending for the semaphore and has become ready.
  • One of fou r different situations may occur: (1 ) if the host processor i s currently idle, the ready task begins execution regardless o f its priority, (2) if the ready task is the same or lower priority than the currently executing task, the task is moved to a ready list but does not preempt the currently executing task, (3) the ready task is higher priority than the currently executing task and preempts it, or (4) the ready task is a higher priority than the currently executing task but the task lock is enabled which prevents preemption.
  • the CTX bit is set 413220 to indicate that the TSA registers in the STCI are preserved. This happens because a task may be in the process of issuing a synchronous task command when then semaphore post begins processing.
  • the host processor wakes up from an idle condition. In many situations, the host processor implements a " w a i t " instruction. The "wait” places the processor in the low power state. This low power state is typically exited by an inte rrupt that the TSA provides.
  • the State Machine 41 sets the Take New From re giste r 402 to the Semaphore Post Index 453 as shown in 413250. This represents the list where the semaphore posted.
  • the Load Context bit is set in the Interrupt Control register to indicate there is only a task to load 413251. Since the host processor is no longer idle, the IDLE bit in the Status register is cleared 413252.
  • the Current Execution Priority 44 is updated to the priority of the first task that was pending on the semaphore as specified in the Semaphore Post Priority register 452 as shown in 413253.
  • the State Machine 41 then waits for the TSA-ISR to clear the Load Context bit in the Interrupt Control Register 403 as shown in 413254.
  • the I nte rrupt Generator 404 asserts interrupt 30.
  • the TSA-ISR responds to the interrupt as shown in FIG. 17, the Task Command register 465 is not cleared when the host processor reads the Interrupt Control register 403 because the CTX bit i s set as shown in 102. This preserves the value of the Task Command Register in case a task was in the process of issuing a synchronous task command. Since the Interrupt Control register 403 has only the Load Context bit set, decisions 1 03 61
  • TSA-ISR executing the Task Switch 107 function.
  • the TSA-ISR clears the Load Context 10733 to indicate the context of the new task has been loaded.
  • the state machine continues after the wait 413254 and clears the Semaphore Post bit in the Status register 42 as shown in 413214.
  • the State Machine 41 determines if the priority of the first task pending on the semaphore is higher than the current execution priority 413224. This is performed by comparing the value in the Semaphore Post Priority registe r 452 to the Current Execution Priority 44. If the decision 413224 is false, this indicates the task that was pending on the semaphore was the same or lower priority than the currently executing task. In this situation, the currently executing task remains executing (no preemption) but the task that was pending on the semaphore now becomes ready. The task needs to be moved from the semaphore list to the ready task list.
  • the State Machine 41 indicates how to move the ready task from the semaphore list to the ready task list by using the Move Current To register 401 and the Take New From register 402.
  • the roles of these registers are siightly different because they indicate a task to be moved from one list to another rather than a context switch.
  • the list where the task was pending is specified by the Semaphore Post Index register 453 and sets the Take New From register 402.
  • the Move Current To register 401 specifies the list where the task 62
  • the Move Task bit is set i n the Interrupt Control register to indicate a task move i s required 413231.
  • the number of ready tasks at the priority level where the task is being moved to is incremented 413232.
  • the State Machine 41 then waits for the TSA-ISR to clear the Move Task bit in the Interrupt Control Register 403 as shown in 413233.
  • the Interrupt Generator 404 asserts interrupt 30.
  • the Task Command register 465 is not cleared when the host processor reads the Interrupt Control register 403 because the CTX bit is set as shown in 102. This preserves the value of the Task Command register because the Move Task operation should not affect the currently executing task. Since the Interrupt Control register 403 has only the Move Task b it set, decision 105 is true. This results in the TSA-ISR executing the Move Task 106 function.
  • the TSA-ISR removes the ready task from the semaphore list as specified by the Take New From register as shown in 1062. This task is placed at the end of the ready list as specified by the Move Current To register as shown in 1063. The Move Task bit in the Interrupt Control register is then cleared 1064. The state machine continues after the wait 413233 and clears the Semaphore Post bit in the Status register 42 as shown in 413214.
  • the decision 413260 determines if the task lock mode is enabled. If the task lock mode is enabled, the TSA is not allowed to preempt the current task even though a higher priority task has become ready. If decision 413260 i s true, the task lock is set and the Preemption Pending bit is set in the status register 413261. This bit remembers that a higher priority task has become ready and that the currently executing task should be preempted when the task lock i s removed. After the Preemption Pending bit is set, the semaphore post is processed as a task move. This moves the task to a ready list using the task move operation as previously described.
  • the ready task preempts the currently executing task.
  • the currently executing task is moved to the list for its priority level by setting the Move Current To register 401 to the Current Execution Priority 44, and the new task is taken from the semaphore list by setting the Take New From register 402 to the Semaphore Post Index register 453 as shown in 413240.
  • Both the Save Context and the Load Context bits in the Interrupt Control register 403 are set to save the context of the current task and load the context of the new task 413241.
  • the number of ready tasks at the priority level of the currently executing task is incremented 413242 and the 64
  • State Machine 41 waits for the TSA-ISR to clear both the Save Context and Load Context bits in the Interrupt Control register 403 as shown in 413243.
  • the Task Command register 465 is not cleared when the host processor reads the Interrupt Control register 403 because CTX is set as shown in 102. This preserves the Task Command register of the task being preempted. Since the Interrupt Control register 403 has the Save Context bit and Load Context bit set, decisions 103 and 105 are false. This results in the TSA-ISR executing the Task Switch 1 07 function. When the Task Switch 107 function clears both the Save Context and Load Context bits in the Interrupt Control register 403, the state machine continues from its wait at 413243 and clears the Semaphore Post bit in the Status register 42 as shown in 413214.
  • the state machine determines the task lock is of f (preemption is now enabled) but the Preemption Pending bit i s set 4195, then a task that had become ready while the task lock was on must now be selected for execution.
  • This i s performed by the Reschedule function 4196 and is shown i n detail in FIG. 41 , numeral 4100.
  • the reschedule operation begins by searching from the highest priority level to the current priority level for a ready task 41961. Since it was know a preemption was pending, this search is always successful.
  • the Preemption Pending bit is then cleared 41962. Since the reschedule operation appears as a semaphore post 65
  • the CTX bit is set to preserve the task context 41963.
  • the currently executing task is moved to its priority level by setting the Move Current To register to the current execution priority.
  • the Take New From register is set to where the new highest priority ready task was found.
  • Both the Save Context and Load Context bits are set in the Interrupt Status register 41964 to save the current task and load the new task.
  • the number of ready tasks at the priority level where the highest priority task was found is decremented 41965 and the number of tasks at the priority level where the current task is being moved to is incremented 41966.
  • the TSA then waits for both the Save Context and the Load Context bits to clear 41967 indicating the task switch has taken place.
  • the current execution priority is then updated to the priority of the task that was found 41978.
  • FIG. 30, numeral 3000 A device comprising a Task Scheduling Accelerator and a host processor is shown in FIG. 30, numeral 3000.
  • the Host Processor 70 and TSA 80 are connected with a data bus 90, an address bus 91 and an interrupt line 92.
  • the TSA 80 appears as any arbitrary peripheral in the host system.
  • the TSA 80 is connected as a memory mapped device using an interrupt line 92. This is an important feature of the present invention because the TSA 80 may be connected to almost any type of Host Processor 70: RISC, CISC, DSP, microcontroller, 66
  • the TSA 80 allows the TSA 80 to be connected as an external device or a device integrated directly onto the processor chip. Since the TSA 80 does not require any specialized instructions on the Host Processor 70, the TSA 80 is independent of the type of Host Processor 70. This allows fast integration and fast time to market by not requiring any changes to the processor core for integrating the TSA 80.
  • the architecture generally comprises several functional interfaces (8021 , 8022, 8023 and 8024), an internal bus for moving registers 8040, an ALU 8014 for manipulating values and comparing values, a current execution priority register 8017 and a RAM 8010 for storing values.
  • the Synchronous Task Command interface 8021 is used for issuing synchronous commands and contains several registers. These registers are the Parameter, Modify Priority, Add Task, Sem Pend Index, Sem Pend Count and Task Command registers. Since a synchronous task command i s completed prior to another synchronous task command being issued, only one synchronous task command is active at any given time.
  • the Parameter, Sem Pend Count and Task Command registers are connected to the internal bus 8040 and are manipulated by moving the value from the register to an ALU operand register.
  • the Parameter, Sem Pend Count and Task Command registers are readable from the host processor and are saved/restored on a context switch.
  • the Asynchronous Task Command interface 8022 is used for issuing commands asynchronous to tasks. The only command that may be issued by interrupts (asynchronous to tasks) is the semaphore post. This interface allows commands to be issued without waiting for them to complete.
  • the Interrupt Control interface 8023 is used to direct the activities of the interrupt service routine on the host computer. This interface contains the Move Current To and Take New From registers t o indicate how to perform a task switch or how to move a task between lists.
  • the Interrupt Control register contains flags that indicate the reason for the interrupt (move semaphore post, move task or context switch) and additional flags f o r qualifying the operation of the context switch.
  • the Interrupt Logic is a logical-OR of all the bits in the Interrupt Control register and asserts the interrupt when any bit in the Interrupt 68
  • the Interrupt Control register is set and negates the interrupt if all bits are clear.
  • the Interrupt Control interface also contains special reset logic. This reset logic resets the Task Command register if the CTX bit in the Status register is clear and the Interrupt Control register is read. This is used to efficiently manipulate the TSA context for a context switch.
  • the Post Queue Control interface is used to assist the queuing of semaphore posts when the Asynchronous Task Command interface is currently full.
  • the Post Queue Control interface contains queue pointers that auto-increment after being read and wrap at a maximum value as specified by the Post Queue max register. Queue Logic determines if the head and tail pointers are equal and determines if the queue contains any information.
  • the OP1 register is used as a source register for ALU operations. All ALU results go to the OP1 register.
  • the OP2 register is used when the ALU needs to compare a value to the OP1 register.
  • the ALU 8014 is capable of clear, increment, decrement, bit set, bit clear, bit test, test OP1 and compare to operand register OP2. This minimal amount of functions can perform the algorithms for task scheduling.
  • a bit test, test OP1 or compare to OP2 operation sets the condition codes 8015. These condition codes can be used by conditional jump instructions in the state machine 8016.
  • the condition codes currently implemented are N (negative), Z (zero), C (carry) and A (always true).
  • the state machine executes microinstructions to execute the scheduling algorithms.
  • the Current Execution Priority 8017 stores the priority of the currently 69
  • the RAM 8010 stores the plurality of ready task counters. Addresses within the RAM are referenced w i t h the RAM Address register 8011.
  • the architecture is a "16 b i t " architecture from the point of view that most of the registers are 16 bits wide.
  • the RAM is a 64x8 RAM. This assignment o f architecture components creates the following configuration on the TSA:
  • priority levels There are 64 priority levels. This is considered to be a significant number because most commercial task schedulers typically implement 8-16 priority levels. The number of priority levels is determined by the depth of the RAM.
  • Semaphores may have up to 32767 semaphore posts.
  • Semaphores may have up to 32768 tasks pending f o r each semaphore. 70
  • This configuration is a balance of TSA silicon size verses the typical size of most multi-tasking systems. These parameters may easily be changed by changing the RAM size or the size of the architecture. Even with this preferred configuration, the TSA far exceeds the typical requirements of a single processor system.
  • the details of the State Machine 8016 are shown in FIG. 32, numeral 3200.
  • the State Machine contains a State Control ROM 80163 for storing a sequence of State Machine Instructions (SMIs) that execute the task scheduling algorithms.
  • Instruction Counter 80162 is a counter that increments sequentially or may be parallel loaded.
  • the Instruction Counter 80162 points to an address in the State Control ROM 80163 to reference an SMI for execution.
  • the State Control ROM 80163 outputs the SMI to the Instruction Decoder 80164.
  • the Instruction Decoder 80164 determines the type of SMI and routes it to the correct execution unit: jump instruction 80165, register move instruction 80166, special operation 80167 or ALU instruction 80168.
  • the jump instruction decoder 80165 determines i f the jump is executed by examining the ALU conditions 8030. I f the jump instruction is true, the instruction counter 80162 i s loaded with a new value to jump to a different SMI. If the jump instruction is false, the Instruction Counter 80162 increments to the next SMI. If the SMI is a register move instruction, the Register Move Instruction decoder 80166 determines the source and destination registers. The Register Transfer Enable 71
  • the special operation instruction decoder 80167 performs irregular operations. The only irregular instruction currently required is to disable the TSA clock to reduce power consumption.
  • Clock Control 80161 disables the clock from the Clock Generator 80160 to the Instruction Counter 80162.
  • the ALU Instruction decoder 801 68 determines the ALU operation and operand 8031 , and instructs the ALU 8014.
  • the clock has been disabled, the clock i s re-enabled when the state machine has commands to process.
  • the Clock Control 80161 is re-activated by the Clock Activate Logic 801600 whenever any of three conditions exist: (1) a semaphore is posted 8032 as indicated by Semaphore Posted bit set in the Status register, (2) a task command has been issued 8033 as indicated by any bit in the Task Command register being set, or (3) the software Semaphore Index Queue 15 is non-empty and can be transferred to the Asynchronous Task Command Interface as is indicated by the Semaphore Post bit in the Status register being cleared and the Post Queue Head counter being unequal to the Post Queue Tail counter 8034.
  • the instruction set for controlling the state machine i efficiently encoded to minimize the size of the State Control ROM 80163. The details of the encoding are shown in FIG. 33, 72
  • the instructions are encoded into 16 bits and have a plurality of reserved bits for future expansion.
  • the f i rst two bits of each instruction determine the instruction type. Since there are four types of instructions, this is efficiently encoded in two bits.
  • the ALU instruction 3301. controls the ALU to perform a function. This function may require the OP1 or OP2 registers.
  • the ALU instruction is required to encode 8 ALU operations. This is encoded into 3 bits with an extra reserved b i t for a total of 4 bits for the ALU operation field.
  • the ALU operand is used to select a bit offset for the b it test, bit set or bit clear functions. Since the TSA is a 16 bit device, the ALU Operand field can be encoded i n 4 bits. The remaining 6 bits in the ALU instruction are reserved.
  • the Transfer instruction 3302. The transfer instruction is used to move registers on the internal bus. Internally, there are 16 registers to access: Status, Parameter, Sem Pend Count, Task Control, Sem
  • the jump condition allows the state machine to jump to another SMI based on the condition codes.
  • the four condition codes Z, C, N and A are encoded into 2 bits. Another bit is used to indicate the complement of the condition. For example, the complement of "zero" is "non-zero".
  • An extra reserved bit is included for expansion of the number of condition codes for a total of 4 bits for the ALU condition field. If the resulting test is true, the Instruction Counter is loaded with the value in the State Address field. Since this is a 9 bit field, the state machine can address up to 512 SMIs. This i s more than adequate for implementing the scheduling algorithms. The remaining 1 bit is reserved.
  • the instruction set is efficient and easy to decode resulting i n an inexpensive implementation of the TSA.
  • the device of the present invention may be implemented in an article of manufacture that utilizes a processor. Examples of such articles of manufacture are: base stations, 74
  • a unique aspect of the device incorporating the TSA i s the previously discussed method for queuing data from the host processor to the TSA.
  • a simplified diagram o f only the data queuing mechanism a simplified diagram i s shown in FIG. 35, numeral 3500.
  • a prior art system i s shown in FIG. 34, numeral 3400 a prior art system i s shown in FIG. 34, numeral 3400.
  • data i s transferred from an executing algorithm 780 on a host processor 785 to a data register interface 787 in an external device 786.
  • the data register interface 781 writes data to the external device data register 787 for processing by an arbitrary data processing unit 788. If the algorithm 780 generates data faster than the data processing unit 788 can consume the data items, either the data items are queued or the algorithms must wait. In an environment where waiting i s not possible (such as data items generated by interrupt service routines), data must be efficiently queued.
  • the Data Register Interface 781 stores the data in a host processor data queue 784 and modifies pointers 783.
  • the Data Register Interface 781 must also enable the interrupt of the external device such that the external device generates an interrupt when the Data Register 787 is empty. When the data register 787 is not full, the interrupt is asserted to request 75
  • the Interrupt Service Routine 782 moves data from the queue 783 and updates the pointers 784.
  • This prior art mechanism requires many steps in the software of the host processor: • The Interrupt Service routine must move the data from the queue to the external device, update the data queue pointers, wrap the pointers according to the size o f the queue and disable the external device interrupt i f no more data is in the queue, • The host processor must store the data in the queue, update the data queue pointers, wrap the pointers according to the queue size and enable the external device interrupt. • This enabling/disabling of interrupts must be exclusive to avoid race conditions between the host processor interrupt service routine disabling interrupts and the data register interface function enabling them.
  • the host processor stores the data items but the external device stores the queue pointers.
  • the host processor is simplified by not requiring storing pointers, incrementing o r wrapping them.
  • the external device can always determine the status of the queue in the host processor by comparing the 76
  • the external device does not generate an interrupt unless it determines the host processor queue has data available and the external device can accept data.
  • the host processor data queuing and interrupt processing code i s simplified.
  • the data register interface 711 determines if the data register is full by examining the status unit 722 as shown in FIG. 37, numeral 3700. If decision 7111 is false, this indicates the data register is empty and can be written. The data registers are written with the data item 7113. If the decision 71 1 1 determines the data register 723 is full, the data item must be queued.
  • the Queue Tail pointer 7202 is read from the hardware 7112 and used as an index to the queue for storing the data item. Note the simplicity of the software in 7112 because the queue tail pointer automatically increments and wraps i n hardware, and there is no need to enable the interrupts.
  • the queue pointer unit 720 shown in detail in FIG. 36, numeral 3600, contains the queue head 7201 and the queue tail 7202. When the queue head or queue tail is read by the host processor, it is automatically incremented.
  • the head comparator 7203 and tail comparator 7204 determine if a pointer is equal to the queue max 7200 value. If a pointer increments to the maximum value, the pointer is reset. This provides the pointer incrementing and wrapping functions required for queue indexing.
  • the interrupt request unit 721 asserts its interrupt.
  • the host processor responds to the interrupt in FIG 38, numeral 3800.
  • the interrupt service routine reads the hardware queue head pointer 7201 , retrieves . the data item from the queue and writes the data item to the data register.
  • a unique aspect of the device incorporating the TSA i s the previously discussed method for clearing the register fo r issuing commands to the TSA.
  • FIG. 39 a simplified diagram is shown FIG. 39, numeral 3900.
  • the TSA has been simplified to include only the components that are involved i n issuing commands and clearing them.
  • Tasks 7501 on a host processor 7508 issue commands to the TSA 7509 by setting command bits in the Task Command register 7506.
  • the Scheduling Unit 7505 determines if the command causes a task switch. If a task switch is required, the Task Scheduling Unit 7505 asserts an interrupt request to activate the Interrupt Service Routine 7502 on the Host Processor. To switch tasks, the Interrupt Service Routine 7502 saves the context of the current task and loads the context of a new task. Since the Task Command register 7502 is used by all tasks to issue commands, the Task Command register 7502 is considered as processor context because each task believes it is the only task using the register. This is a problematic situation because of the following issues:
  • Task Command register 7502 is saved and restored by the Interrupt Service Routine 7502, then the command that caused the task switch will be reloaded when the task context is loaded. This causes the task to re-execute the same command that j u st caused the task switch. This creates the requirement that the task command register must be cleared if a task command caused the task switch. This allows the task to determine the task command has been completed and continue execution.
  • Task Command register 7506 must be preserved 79
  • Task Command register 7506 could be cleared each time the task context is loaded, this would violate the second requirement that the Task Command register 7506 must sometimes be preserved. Another assumption would be to clear the task command register as soon as the TSA recognizes the command; however, this i s problematic because the task on the host processor may assume the task command is completed when in actuality it i s not (it has only been recognized) and continue executing. This is typically due to the issue that a realistic processor typically takes a finite amount of time to respond to an interrupt. Thus, the Task Command register 7506 must be cleared after the task switch (Interrupt Service Routine 7502) has started but only if the task switch is being caused by a task command.
  • Interrupt Service Routine 7502 Interrupt Service Routine 7502
  • the unique solution to this problem is to include a special Reset Logic Unit 7504 to clear the Task Command register 7506.
  • the Interrupt Service Routine 7502 reads the Interrupt Status register 7503, it is known that the Task 7501 is now preempted. Reading the Interrupt Status register
  • the Reset Logic Unit 7504 determines if the preemption taking place is due to a task command (the Task Command register does not represent context) or if the preemption taking place is due to a non-task command (the Task Command is context and must be preserved) by using the Context Status Signal from the Task Scheduling Unit 7505. I f the Reset Logic Unit 7504 determines the Interrupt Status register 7503 is being read and the Task Scheduling Unit 7505 has indicated the preemption is due to a task command, then the Reset Logic Unit 7504 clears the Task Command registe r 7506. This operation has the following effects:
  • Interrupt Service Routine 7502 begins and reads the Interrupt Status register 7503, the Task Command register 7506 clears. The Interrupt Service Routine 7502 then saves the processor registers and the cleared Task Command register 7506. When the task context is restored, the processor registers are restored and the Task Command register 7506 i s restored. Since the Task Command register was cleared prior to saving it, restoring it effectively clears the task command. The task continues execution because it sees the task command has cleared. • If the preemption is due to a semaphore post, the Task
  • the I nterrupt Service routine saves and later restores the Task Command register 7506 without changes. This allows a completely transparent preemption.
  • FIG. 40 A unique aspect of the device incorporating the TSA i s the previously discussed method the TSA to specify and control a task switch.
  • FIG. 40 a simplified diagram is shown FIG. 40, numeral 4000.
  • the TSA has been simplified to include only the components that are involved specifying and controlling the task switch.
  • the Task Scheduling Unit 7624 determines a task switch is necessary, an interrupt request is made to the Host Processor 7610 which activates the Interrupt Service Routine 7612.
  • the Interrupt Service Routine 7612 must manipulate task lists representing 82
  • the Task Scheduling Accelerator 7620 specifies and controls the task switch using three registers: the Move Current To register 7621 , the Take New From register 7622 and the Interrupt Control register 7623.
  • the Move Current To register 7621 indicates which list to link the currently executing task into.
  • the Save Context bit in the Interrupt Control Register 7623 determines if the Move Current To register is valid. If the Save Context bit indicates the Move Current To register is valid, the Current Task is linked into the list specified by the Move Current To register. Situations such as when a task exits would cause the Save Context bit to indicate that the Move Current To register is not valid since the Current Task object would not need to be saved.
  • the Interrupt Service Routine 7612 needs to determine if there is another task to execute.
  • the Interrupt Control Register Load Context bit indicates if the Take New From register 7622 is valid. I f the Take New From register is valid, the Interrupt Service 83
  • Routine 7612 removes the task at the head of the list specified by the Take New From register and sets this as the current task for execution. If the Load Context bit is clear, it indicates the Take New From register is invalid. The Take New From register may be invalid when the task set is idle and there are no tasks available for execution. Thus, the entire task switch can be specified and controlled using two registers specifying indexes (Move Current To 7621 and the Take New From 7622 registers) and a set of bits (Load Context and Save Context) to indicate if the registers are valid. This produces a very efficient task switch on the host processor.
  • a device accelerates scheduling of a preemptive, prioritized, multi-tasking system by balancing software and hardware components in a manner that maximizes processor efficiency.
  • the multi-tasking system is typically implemented in an embedded processor system, a subscriber unit or a base station. This efficiency i s achieved by utilizing a highly efficient, predetermined interrupt service routine in a host processor to respond to a task scheduling accelerator which is implemented in hardware.
  • the task scheduling accelerator processes scheduling decisions requested by commands from tasks in the host processor.

Abstract

A method, an article of manufacture and a multi-tasking, preemptive, priority based operating device using a host processor and a task scheduling accelerator. The host processor processes a plurality of tasks and receives interrupts and uses a predetermined task scheduling accelerator interrupt service routine for responding to the task scheduling accelerator. The task scheduling accelerator is coupled to the host processor and is used for accelerating real time multi-tasking decisions using scheduling decisions responsive to tasks in the host processor. A method, device, and article of manufacture for transfer of data items between a host processor and an external device are also disclosed.

Description

APPARATUS, METHOD AND ARTICLE
OF MANUFACTURE FOR USE WITH A
PRIORITY BASED REAL-TIME
OPERATING SYSTEM
Field of the Invention
The field of the invention relates to multiple task execution processors, in particular, a multi-task execution processor having a preemptive prioritized task scheduling system.
Background of the Invention
Multi-tasking is the capability of a single processor t o execute multiple tasks concurrently. A processor performs multi-tasking execution by switching between tasks using a defined set of multi-tasking rules. For theoretical reasons, real-time multi-tasking systems preferably use a set of rules where tasks are prioritized. Lower priority tasks can be preempted (forcibly switched) to execute a higher priority task if necessary. This "preemptive prioritized" system always executes the highest priority ready task.
A "task" is defined as an independent entity o f computing. For example, where a computer system permits many users on different terminals access to the same processor, the computer system assigns a unique task to each user's computing (where each user's computing is unrelated t o another user's computing). Generally, a task unit contains an entry for each task. Tasks are typically synchronized using "events". An event is used to indicate that an activity has taken place, such as data arrival, time-out, etc. Thus, an event may indicate execution of a task, an interrupt service routine or the like. Events are counted using semaphores. Semaphores synchronize the event producer and the event consumer as shown in FIG. 2, numeral 200.
Events are generated by tasks 201 or interrupt service routines (ISRs) 202. ISRs are not allowed to consume events because ISRs are not scheduled and execute outside of the normal task scheduling environment of the processor. However, ISRs are allowed to generate events to indicate the status of the cause of the interrupt.
A counting semaphore 203 allows a plurality of events to be generated without being lost. Similarly, a plurality of tasks may be waiting for the same event. When the semaphore counter is positive, it indicates events have been produced but no tasks are waiting for the events. When the semaphore counter is zero, it indicates no events have been generated and no tasks are waiting. When the semaphore counter is negative, it indicates there are no events generated but a plurality of tasks are waiting for the events. The process of generating an event to a semaphore is typically called "posting" the event 204. The process of waiting for an event from a semaphore i s typically called "pending" for the event 205. When an event is generated for a semaphore that has a list of tasks pending, the task 206 at the head of the l i s t becomes ready for execution. At this time, the task scheduling function 207 must determine if this task should be selected for execution or if it should be put in a list with other ready tasks to be executed at a later time. This decision is based on the priority of the task that is currently executing compared to the priority of the task that has just become ready.
If the task that has just become ready is the same o r lower priority than the currently executing task, the currently executing task continues executing. The new ready task i s moved to a list to be executed at a later time. If the task that has just become ready is a higher priority than the currently executing task, the currently executing task is preempted to allow the new ready task to execute. Thus, the highest priority ready task 208 is always selected for execution. At some time, the currently executing task completes i ts computation and becomes inactive. A task becomes inactive by pending on a semaphore when the semaphore count is zero o r negative. For example, a semaphore may represent data buffers that require processing. If the task that processes data buffers pends for the semaphore that represents data buffers, the task is synchronized to the data buffer generation. If data buffers are available, the semaphore count is greater than zero. Task pend requests on the semaphore allow the task to continue. I f data buffers are not available, the semaphore count is less than or equal to zero. When the task pends on the semaphore with a count that is less than or equal to zero, the task does not have data for processing and will block execution. At the point when a task pends on a semaphore with zero or negative count, the task that has made the request is not allowed to continue execution and must "block". The task scheduling function stops this task and selects another task for execution. The task scheduling function looks at other ready tasks at the same or lower priorities to determine the next highest priority ready task. If a task is found, it i s selected for execution. If a task is not found, the processor i s put into an idle state until a task becomes ready. Although the task selection process is easy to understand, in a practical environment this can lead t o significant inefficiencies. For example, the following cause inefficiencies in a preemptive prioritized task scheduling system: • Each time a semaphore is processed, there is a potential for a task change. This causes the scheduling function to be called quite often when many times there is no change.
• When a task pends for a semaphore and blocks, the scheduler must perform a search algorithm t o determine the next ready task. If there are a large number of tasks and priority levels, this activity may be time-consuming.
• The process of searching for a task may have variable timing making task scheduling functions non- dete rm inistic . • The task scheduler must obtain control of the processor to switch tasks.
• In a software task scheduling system, interrupt service routines typically require entry and exit code to flag interrupt usage and nesting. The flagging i s typically used to call the scheduler to determine i f the interrupt generated an event that may have changed execution. The use of entry and exit code consumes time and is undesirable when processing interrupts.
Solutions to the problems set forth above typically involve constraining the functionality of the scheduler. These constraints may include limiting the number of tasks, limiting the number of priority levels, limiting the number of tasks at each priority level, limiting the representation range of the semaphore counter, etc. It is undesirable to have such constraints in a system because such constraints may restrict the type of system that can be supported.
Thus, there is a need for a method, device and article o f manufacture that optimizes real-time multi-tasking for a processor. Brief Description of the Drawings
FIG. 1 is a block diagram of one embodiment of a device in accordance with the present invention, showing data f l ow and functionality of the invention.
FIG. 2 is a diagrammatic representation of event processing and schedule processing with respect to the basic operation of an event driven preemptive prioritized task multitasking system in accordance with the present invention. FIG. 3 shows schematic representations of examples o f special function bits in control registers for task commands, interrupt control and status in accordance with the present invention, describes.
FIG. 4 is a flow chart showing one embodiment of steps for implementing the operation of the state machine that controls the accelerator in accordance with the present invention.
FIG. 5 is a flow chart showing one embodiment of data flows for executing commands that are synchronous to the task wherein the task must allow the previous command to clear before executing the next command in accordance with the present invention.
FIG. 6 is a flow chart indicating one embodiment of the functions that tasks and interrupts use to control the task scheduling accelerator in accordance with the present invention. FIG. 7 is a flow chart showing one embodiment of steps for adding a new task to the currently executing task set in the multi-tasking environment in accordance with the present invention. FIG. 8 is a flow chart illustrating one embodiment of steps for how a task exits to remove itself from the currently executing task set in the multi-tasking environment i n accordance with the present invention.
FIG. 9 is a flow chart showing one embodiment of steps for how a task may modify its own priority in accordance wi t h the present invention.
FIG. 10 is a flow chart showing one embodiment of steps for how a task may yield to another task at the same priority level in accordance with the present invention. FIG. 11 is a flow chart showing one embodiment of steps for how tasks pend for semaphores on the host processor i n accordance with the present invention.
FIG. 12 is a flow chart showing one embodiment of data flows for executing commands that are asynchronous to the task (commands that the task does not need to wait f o r completion or commands generated by interrupts) i n accordance with the present invention.
FIG. 13 is a flow chart showing one embodiment of steps for how semaphores are posted by tasks and interrupts on the host processor in accordance with the present invention. FIG. 14 is a schematic representation of operation of pointer registers for assisting the queuing of semaphore posts in accordance with the present invention.
FIG. 15 is a flow chart showing one embodiment of steps for how the state machine requests semaphore posts to be moved from the queue on the host processor to the task scheduling accelerator in accordance with the present invention.
FIG. 16 is a schematic representation of the data f l ows and information for the accelerator to signal the host processor and communicate changes in the task execution i n accordance with the present invention.
FIG. 17 is a flow chart showing one embodiment of steps for the functions executed by the interrupt service routine on the host processor in accordance with the present invention.
FIG. 18 is a flow chart showing one embodiment of steps for how the interrupt service routine moves a queued semaphore post to the accelerator in accordance with the present invention. FIG. 19 is a schematic representation of data structures stored on the host processor used to describe the current state of task execution in accordance with the present invention.
FIG. 20 is a schematic representation of how the interrupt interface communicates information that determines how the interrupt service routine switches tasks in accordance with the present invention. 10
FIG. 21 is a flow chart showing one embodiment of steps for how the interrupt service routine switches tasks i n accordance with the present invention.
FIG. 22 is a schematic representation of how processing on the host processor and task scheduling accelerator overlap to provide efficient task switching in accordance with the present invention.
FIG. 23 is a flow chart showing one embodiment of steps for how the state machine processes adding task requests from the host processor in accordance with the present invention.
FIG. 24 is a flow chart showing one embodiment of steps for how the state machine processes task exit requests from the host processor in accordance with the present invention.
FIG. 25 is a flow chart showing one embodiment of steps for how the state machine processes modify priority requests from the host processor in accordance with the present invention.
FIG. 26 is a flow chart showing one embodiment of steps for how the state machine processes task yield requests from the host processor in accordance with the present invention.
FIG. 27 is a flow chart showing one embodiment of steps for how the state machine processes semaphore pend requests from the host processor in accordance with the present invention. FIG. 28 is a flow chart showing one embodiment of steps for how the state machine processes semaphore post requests 11
from the host processor in accordance with the present invention.
FIG. 29 is a flow chart showing one embodiment of steps for how the interrupt service routine moves a task between queues in accordance with the present invention.
FIG. 30 is a block diagram illustrating how the task scheduling accelerator is physically connected to a host processor in accordance with the present invention.
FIG. 31 is a block diagram schematic showing one embodiment of how the task scheduling accelerator may be implemented in a hardware configuration in accordance with the present invention.
FIG. 32 is a block diagram schematic showing one embodiment of the state machine that controls the hardware i n accordance with the present invention.
FIG. 33 is a schematic representation of examples of encoding of the instructions for the state machine i n accordance with the present invention.
FIG. 34 is a block diagram illustrating how data i s typically transferred between a software task or interrupt on a host processor to an external device in the prior art.
FIG. 35 is a block diagram illustrating the specific details of implementing an efficient data queuing method.
FIG. 36 is a block diagram illustrating the specific details of how hardware queue pointers operate. 12
FIG. 37 is a flow chart illustrating the required operations by an interface function on the host processor fo r either writing data to the external device or queuing the data.
FIG. 38 is a flow chart illustrating how the interrupt service routine efficiently moves data from the host processor to the external device.
FIG. 39 is a block diagram illustrating specific details of how the task command register is cleared.
FIG. 40 is a block diagram illustrating specific details of how the Task Scheduling Accelerator efficiently communicates information about a task switch to the Host Processor.
FIG. 41 is a flow chart illustrating how the Task Scheduling Accelerator selects a task after the task lock has been turned off and higher priority ready tasks are pending.
Detailed Description of a Preferred Embodiment
The present invention resolves the problems wi t h implementing task scheduling without the need for imposing constraints by moving a selected portion of the task scheduling functionality to an external hardware accelerator. By allowing part of the functionality to remain in software on the host processor, flexibility is maintained without the need o f constraints. By moving scheduling decisions to an external accelerator device, fast determination of scheduling decisions is performed. Since the external accelerator device may compute schedule decisions in parallel with activity on the host processor, an overlap of scheduling decisions with host processor activity allows variable or lengthy scheduling decisions to be hidden during host processor activity. The present invention improves upon software task scheduling implementations because software implementations are typically slow, require interrupt service routine entry and exit functions, and execute scheduling functions in serial with task execution. The present invention also improves upon prior a rt hardware devices. Prior art hardware devices store almost a l l of the information for task scheduling locally in the hardware. To minimize the amount of information stored (and reduce the hardware cost), prior art devices require restrictions to l i m i t the number of tasks, the number of tasks at the same priority level, the range of the semaphore counter, etc.
The present invention improves upon the prior art by providing a method of determining a ready task that i s dependent only on the number of priority levels and not the number of tasks. This allows many tasks to be added to the system without an increase in the search time for a ready task. Further, scheduling computations for determining ready tasks is overlapped with the host processor for maximum efficiency. Because scheduling computations are performed externally t o the host processor, no entry/exit code is required in interrupt service routines. The present invention is significantly faster than software schedulers. Efficient partitioning of information 14
stored between the hardware and in the host processor significantly reduces the system cost without imposing restrictions.
The present invention utilizes a hardware accelerator, herein called a "task scheduling accelerator" (TSA), f o r improving the performance of real-time task scheduling without imposing constraints on the functionality of the system. An efficient partitioning between the TSA and the host processor software allows functional flexibility while providing acceleration of task scheduling functionality.
The TSA implements a model of task scheduling where tasks are prioritized and lower priority tasks may be preempted if a higher priority task becomes ready. The TSA may execute commands to add a task, exit the current task, yield to another task at the same priority, modify the current task priority, pend for semaphores or post a semaphore. Using these basic functions, real-time operating system functionality may be developed.
The TSA accepts commands from tasks called "synchronous" task commands. These commands are synchronous from the point of view that the task may not issue another synchronous task command until the previous synchronous task command has been completed. It is allowable for the task to perform other activity after issuing a synchronous task command as long as the task verifies the previous synchronous task command has been completed prior to issuing another synchronous task command. The TSA 15
provides the Task Command register to indicate when a synchronous task command has been recognized and clears the status bit when the function is completed.
Interrupts perform functions on the host processor asynchronous to task execution. Since interrupts may generate events by posting semaphores, it is necessary to have a separate mechanism for issuing commands that are asynchronous to tasks. When these "asynchronous" commands are issued, there is no need to wait for them to complete. An important aspect of a system using the TSA is that the TSA may request service from the host processor via an interrupt. This allows the host processor to additionally service TSA needs or to perform a task switch at the time of the interrupt. If the TSA determines the current task needs to be preempted, the TSA asserts its interrupt. This interrupt causes the host processor to enter a special mode for processing the interrupt request. At this time, the currently executing task has been preempted and a new task can be selected simply by changing to a new context. A task switch is performed by saving the context of the current task and loading the context of a new task. The context is defined as all the registers used by the task and any shared resources. Thus, a task switch involves saving all processor registers and shared resources used by the currently executing task and loading a new set of processor registers and shared resources for the new task.
A task command may cause the current task to be preempted. An example of when this occurs is when a task 16
pends for a semaphore, but the semaphore count is zero or negative. The TSA preempts the currently executing task wit h an interrupt and switches to another task. Eventually, the task that was preempted becomes ready to execute. When the task continues executing, it determines the TSA status bit is clear and continues. The task is completely unaware preemption has taken place and other tasks were executed. This transparent switching of tasks is important to minimize exposure of the task scheduling functionality to the application program. In a multi-tasking system, tasks are switched by changing the processor "context". Context is the current information representing the execution state of the task. This typically consists of all of the processor's registers and any additional globally shared resources. The TSA is considered to be a globally shared resource because each task writes task commands to the TSA without regard to other tasks. This introduces a difficult problem with external task scheduling hardware that the present invention solves very effectively. The problem is how . the host processor can determine if the TSA registers represent context or not.
This issue is illustrated by an example. Consider the case when an interrupt posts a semaphore that readies a higher priority task. The higher priority task preempts the currently executing task. It is possible that the currently executing task was in the process of writing a task command to the TSA. I n this case, this task command should be saved and later restored when the task resumes execution. This allows the 17
task to execute the command it issued just prior to being preempted. In this situation, the TSA registers are considered to be context similar to the host processor's registers.
A second case is illustrated when a task issues a task command that causes the task to be preempted. In th i s situation, if the TSA's registers are saved and then restored, the command that caused the task switch would be restored causing another task switch. In this situation, the TSA registers should not be considered context. Further, the status bit that indicates the task command was completed needs to be cleared to indicate to the task that the command has completed.
The solution to the TSA "context" is to coordinate the context save/restore procedure between the TSA and the host processor interrupt service routine. This coordination adjusts the context (TSA registers) if the preemption is due to a synchronous task command but preserves the context when the task is being preempted due to an asynchronous task command. The details of this procedure are illustrated in finer detail late r.
Another issue with external task scheduling devices i s the host processor generating events faster than the TSA can process them. This typically happens when interrupt service routines generate interrupts and post semaphores in a non- predictable fashion. One solution is not to allow interrupts t o post semaphores. A system of this type is very seriously constrained because activity from hardware devices cannot be efficiently synchronized. Another potential solution is to have the host processor wait until the TSA can accept additional semaphore posts. This is also an unacceptable solution because it makes interrupt service routines wait and is typically not desirable or allowable.
The solution to this problem is to place additional semaphore posts in a queue. The queuing must be efficient and allow the TSA to control the reading of the queue. The present invention employs a unique solution to this problem by partitioning the storage of additional semaphore posts on the host processor while maintaining the pointers to the queue i n the TSA. This combination allows the TSA to be always aware of the state of the host processor queue without interrogating the host processor. Since the size of the queue depends on the software architecture, it is effective to store the queue in the host processor where the queue size can be determined based on the host processor software. The details of this procedure are described in finer detail later.
One embodiment of the present invention is shown in FIG. 1 , numeral 100. FIG. 1 shows a block diagram of a Host Processor 1 coupled to a task scheduling accelerator (TSA) 2 that is typically implemented in hardware. The TSA contains registers for control/status or to specify a particular integer value. The control/status registers are shown in FIG. 3, numeral 300. 19
The Task Command register 301 indicates synchronous task commands issued by tasks on the host processor. These bits include:
• Add Task - This bit is set to add a task to the current task set.
• Task Exit - This bit is set to exit the currently executing task.
• Modify Priority - This bit is set when the currently executing task changes its priority. • Task Yield - This bit is set to yield to another task at the same priority level.
• Semaphore Pend - This bit is set when a task makes a pend request.
• Task Lock - This bit specifies a mode of operation where the TSA will not preempt the current task. This is typically used to protect critical regions o f programs that share data between multiple tasks. When the bit is cleared, the TSA is allowed to preempt the task.
These bits are described in further detail when covering the functions that use them.
The Interrupt Control register 302 specifies the reason for the TSA interrupt to the host processor. There are three major functions this register controls: 20
• Move Post - This is an indication the TSA-ISR is t o move a semaphore post index from the semaphore index queue to the asynchronous task command interface. There is no change in the cu rrently executing task.
• Move Task - This is an indication to move a task f rom one task list to another. There is no change in the currently executing task.
• Task switch - The task switch is qualified by fou r bits:
* Busy - Indicates the TSA is searching for a ready task.
* Save Context - Indicates if the context of the current task should be saved. * Load Context - Indicates if the context of a new task should be loaded.
* Idle - Indicates the task set is idle.
These bits are described in further detail when covering the functions that use them.
The Status register 303 specifies additional status information to the host processor or the TSA. These bits include:
• CTX - This bit indicates if the TSA-ISR should t re at the Task Command register as context (preserve it) o r not as context (modify it). This bit is used to clear 21
command bits in the Task Command register during a context switch.
• Semaphore Post - This bit indicates a task or interrupt service routine has written a semaphore post to the asynchronous task command interface.
• IDLE - This bit is used to retain the state of the task set being in the idle (no active tasks) state.
• Preemption Pending - This bit is set to indicate the current task will be preempted when it turns off the task lock. This bit is set by the TSA if a semaphore i s posted with a higher priority ready task pending when the task lock is enabled. These bits are described in further detail when covering the functions that use them. When the system is reset, the TSA begins execution o f its internal State Machine 41 as indicated in FIG. 4, numeral 400. At initialization 4111 , the State Machine 41 clears:
• The Current Execution Priority 44. The Current Execution Priority 44 maintains the priority of the currently executing task. In this embodiment, a zero indicates the highest priority with lower prio rities increasing in value. In this embodiment f l owcharts indicate "higher priority" to mean a lower numeric value and "lower priority" to indicate a higher numeric value for priority. Since the Current Execution
Priority 44 is being initialized to zero, it indicates 22
the first task created by starting the host processor is currently the highest priority.
• The Ready Task Counters 43. The Ready Task Counters store a plurality of integers that determines the number of ready tasks at each priority level. Since at reset there are no other ready tasks to execute, a l l Ready Task Counters 43 are set to zero.
• All flags in the Status register 42. This includes
• The CTX Flag. This bit indicates if the Synchronous Task Command Interface (STCI) 46 contains context. If the CTX bit is set, it indicates the STCI registers should be preserved because they may contain valid information written by the task that is currently executing. If the CTX bit is clear, i t indicates the STCI registers have issued a task command that caused the context switch and the STCI registers should be modified to clear the task command status bit. It is initialized to zero by default. • The Semaphore Post flag. This bit indicates if the semaphore post registers in the Asynchronous Task Command interface 45 have been written.
• The IDLE flag. This bit indicates the host processor is currently idle and not processing any tasks. 23
• The Preemption Pending flag. This bit indicates a ready task of higher priority will preempt the current task when the task lock is turned off.
• The Interrupt Control register 403 in the I nterrupt Service Routine Interface 40. This register is cleared because if any bit in the Interrupt Control registe r 403 is set, Interrupt Generator 404 asserts the interrupt 30. Since the TSA does not need any service at start-up, it is required to ensure the interrupt i s negated after reset.
• The Task Command register 465 in the Synchronous Task Command Interface 46. This register is cleared to indicate there are currently no task commands t o process.
After initialization 41 1 1 , the State Machine 41 enters a loop checking for a function to execute with comparisons 4120, 4130, 4140, 4150, 4160, 4190 and 41 70. The loop checking includes: Is Sem Pend set in the TCR (Task Command Register)? 4120; Is Sem Post set in Status? 4130; Is Add Task set in TCR? 4140; Is Task Exit set in TCR 4150; Is Task Yield set in TCR? 4160; Is Modify Priority set in TCR? 4190; Does S/W queue have sem posts and are post registers empty? 41 70 ; and, Is the task lock off and the preemption pending bit set? 4195. If any comparison is true, the TSA processes the true function 4122, 4132, 4142, 4152, 4162, 4192, 4172, 4196 and returns to the beginning of the loop to check Is Sem Pend set i n 6679 pcτ/US99/osπ2
24
the TCR 4120. If all comparisons are false, the TSA does not have any functions to process and enters a low power mode 4180 until there is activity. Each of the functions of the State Machine 41 are explained in further detail later. Activity that brings the State Machine 41 out of low power 4180 is any of the loop conditions being true. Since the state machine i s turned off when in low power, activity is detected by di rect hard-wired logic to the state machine. This is shown in detail in FIG. 32 in the Clock Activate Logic 801600 where signals Semaphore Posted 8032, Task Command 8033 and Software Queue Not Empty 8034 indicate to the Clock Activate Logic 801600 to activate the Clock Control 80161.
The TSA 2 contains several functional interfaces. The Synchronous Task Command Interface (STCI) 46 allows tasks to issue synchronous task commands. A synchronous task command must wait until the TSA 2 has finished processing the previous synchronous task command before issuing another synchronous task command. The Task Command register 465 i n the STCI 46 provides status bits that indicates the TSA 2 has recognized the command request. The status bit is cleared when the TSA 2 has completed the command.
In one embodiment the STCI 46 contains registers as shown in FIG. 5, numeral 500. The Parameter register 460 i s used to store values associated with synchronous task commands. Synchronous task commands that require values are Add Task, Modify Priority and Semaphore Pend. When a synchronous task writes the register to request the command, 25
the value is transferred to this register. Since each synchronous task command must be completed prior to the issuing of another synchronous task command, only one value is written at any given time. This allows a minimization of the amount of hardware registers in the SCTI 46 and reduces context switching time by using a common register.
STCI 46 registers are associated with functions f o r issuing synchronous task commands as shown in FIG. 6, numeral 600. STCI implements the following functions:
• The Add Task function. The Add Task register 462 is used to issue a command to add a new task to the task set. The Add Task function 123 in the Task Scheduling Programming Interface 12 is described in detail in FIG. 7, numeral 700. The Add task function 123 first adds a new task object to the data structures 11 via data path 21 to configure the context of the new task (task object) 1232 and links the new task object into the Ready Task Queue as specified by the new task priority 1233. The Add Task function 123 then writes the priority of the new task to the Add Task register
462 as shown in 1234. The priority of the new task i s transferred to the Parameter register 460 and the Add Task bit is set in the Task Command register 465. To ensure the Add Task command has been completed 1235, the add task function 123 waits until the TSA has cleared the Add Task
Bit in the Task Command register 465. 26
• The Task Exit function. The task exit function 124 in the
Task Scheduling Programming Interface 12 is described i n detail in FIG. 8, numeral 800. The task exit function 1 24 sets a bit in the Task Command register 465 to indicate the current task wishes to exit as shown in 1242. To ensure the task exit command has completed 1243, the task exit function 124 waits until the TSA has cleared the Task Exit Bit in the Task Command register 465. This task command has no apparent next step as indicated by no exit from 1 243 because when the task is preempted, it never returns.
• The Modify Priority function. The Modify Priority register 461 is used to issue a command to change the priority of the currently executing task. The Modify Priority function 1 25 in the Task Scheduling Programming Interface 12 i s described in detail in FIG. 9, numeral 900. The Modify
Priority function 125 writes a new priority 1252 to the Modify Priority register 461 to issue the command. The new priority is transferred to the Parameter register 460 and the Modify Priority Bit is set in the Task Command register 465. To ensure the modify priority command has completed
1253 the Modify Priority function 125 waits until the TSA has cleared the Modify Priority Bit in the Task Command register 465.
• The Task Yield function. The Task Yield function 126 in the Task Scheduling Programming Interface 12 is described i n detail in FIG. 10, numeral 1000. The task yield function 1 26 sets a bit in the Task Command register 465 to indicate the 27
currently executing task wishes to yield to another task at the same priority level as shown in 1262. To ensure the Task Yield command has completed 1263 the Task Yield function 126 waits until the TSA has cleared the Task Yield bit in the Task Command register 465.
• The Semaphore Pend function. The Semaphore Pend Count register 463 and Semaphore Pend Index register 464 are used to pend for a semaphore specified by a semaphore index. The Semaphore Pend function 122 in the Task Scheduling Programming Interface 12 is described in detail in FIG. 11 , numeral 1100. The Semaphore Pend function 122 first decrements the semaphore count associated with the semaphore index 1222. The semaphore index is an integer representing a particular semaphore. The Semaphore Pend function 122 then writes the decremented count to the
Semaphore Pend Count register 463 as shown in 1223. The semaphore count is transferred to the Parameter register 460. The Semaphore Pend function 122 then writes the index of the semaphore to the Semaphore Pend Index register 464 and sets a flag in the Task Command register 465 as shown in 1223. To ensure the Semaphore Pend command has completed 1224 the semaphore pend function 122 w a i ts until the TSA has cleared the Sem Pend Bit in the Task Command register 465. • The Task Lock mode. The Task Lock is a mode of operation and not a task command. The Task Lock mode indicates t o the TSA that the currently executing task should not be 28
preempted even if a higher priority ready task becomes available. This is typically used to protect data structures accessed by multiple tasks. When the task lock mode is set, only semaphore posts are allowed to be generated by tasks or ISRs. If the task lock mode is set and a higher priority ready task becomes available due to semaphore post, the TSA remembers this by setting the Preemption Pending b i t in the Status register but does not preempt the current task. If there is a preemption pending when the task lock i s turned off, the TSA preempts the currently executing task and selects the higher priority ready task that became available when the task lock was enabled.
An important aspect of the present invention is the implementation of the previously described synchronous task commands. Each command is relatively simple to implement, resulting in small memory usage in the host processor.
Additionally, each command simply waits for the associated control bit in the Task Command register 465 to clear t o indicate the command is complete. If a task preemption occurs, it is completely transparent to the task at this time. The task does not need to implement any component of the context switch nor does it need to be aware of any other tasks in the system. Data path 32 indicates the Modify Priority register 461 , the Add Task register, 462, the Semaphore Pend Count register
463, the Semaphore Pend Index register 464 and the Task 29
Command register 465 are all accessible to the Task Scheduling Programming Interface 12 and its functions of Semaphore Pend 122, Add Task 123, Task Exit 124, Modify Priority 125 and Task Yield 126. Data path 38 indicates the Parameter register 460, Semaphore Pend Index register 464 and Task Command register 465 are accessible from the Task Scheduling Accelerator Interrupt Service Routine 10 during a task switch. Data path 54 indicates the state machine accesses the Parameter register 460, Semaphore Pend Index register 464 and Task Command register 465 to process scheduling decisions.
An asynchronous task command is issued via the Asynchronous Task Command Interface (ATCI) 45. The only task command that is issued asynchronous to tasks by interrupt service routines 14 is the semaphore post. The ATCI may also be used by tasks 13 for posting semaphores although the task does not need to synchronize (i.e., wait for it to complete). The details of the ATCI are shown in FIG. 12, numeral 1200. FIG. 1 2 shows the ATCI contains 3 registers. The Semaphore Post Count register 451 is used to receive the count value of a semaphore. The Semaphore Post Priority register 452 is used to receive the priority of the first task pending on the semaphore. The Semaphore Post Index register 453 is used to receive the index number of the semaphore. When the Semaphore Post Index register 453 is written, a status flag i s set in the status register 42 via path 57. Data path 39 indicates the ATCI registers can be written from the 30
Semaphore Post- Interface 55. Data path 33 indicates the ATCI registers can be written from the TSA-ISR 10. Data path 53 indicates the ATCI registers may be accessed from the State Machine 41 for computing scheduling decisions. Thus, semaphore posts may be generated from three sources: Tasks 13 and Device Interrupt Service Routines 14 through the Semaphore Post Interface 55, or, from the TSA-ISR 10.
It is important to understand the TSA-ISR is the lowest priority interrupt serviced by the host processor. Alternatively, the TSA-ISR may be the last interrupt to be serviced when multiple devices share the same interrupt level. The reason is that it is necessary that no interrupt context be on the host processor stack when a task switch is performed. This requires all interrupts to be finished prior to the TSA performing a task switch. Since interrupts at a higher priority may generate semaphore posts, it is possible for more semaphore posts to be generated than can be processed by the TSA. This is resolved using a queuing mechanism.
The details to post semaphores from the Semaphore Post Interface 55 are shown in FIG. 13, numeral 1300. The Semaphore Post Interface 55 begins by checking the Semaphore Post bit in Status 42 to determine if the semaphore post registers in the ATCI have been written 1512. If decision 1 51 2 is true, the registers have already been written and the semaphore post request must be queued. This is performed i n 1513 by reading the Post Queue Tail register 472 in the Semaphore Post Queue Interface 47, 3 1
SemaphorelndexQueue[PostQueue Tail] = Semlndex. This register provides an integer that is used as a queue position t o store the index in the Semaphore Index Queue 15.
If the decision 1512 is false, the ATCI can be writte n . The Semaphore Post Interface 55 increments the semaϋhore count at the specified index 1514, i.e.,
SemaphoreCount[Semlndex]. This incremented count is w r i tte n to the Semaphore Post Count register 451 ,
SemaphorePostCount = SemaphoreCount[Semlndex], as is shown in 1515. The Semaphore Post Interface 55 then obtains the priority of the first task pending on the semaphore 1516 f ro m Data Structures 1 1. This priority is written to the ATCI Semaphore Post Priority register 452, SemaphorePostPriority = priority of first task in list Semlndex, as shown in 1516. The Semaphore Post Interface 55 then writes the index of the semaphore to the Semaphore Post Index register 453 , SemaphorePostlndex = Semlndex, as shown in 1517. The action of writing the Semaphore Post Index register 453 causes the ATCI set the Semaphore Post bit in Status register 42. A unique aspect of the present invention is the method for managing the Semaphore Index Queue 15. As has been indicated, semaphore indices are placed in the Semaphore Index Queue 15 if the ATCI registers are currently full. The detai ls of the interface in the TSA for managing the queue pointers are shown in FIG. 14, numeral 1400. When the Semaphore Post Interface 55 reads the Post Queue Tail register 472, tne Post Queue Tail register 472 auto-increments to then next queue 32
position. A Comparator 474 compares the Post Queue Tail register 472 to a maximum value stored in the Post Queue Max register 470. If the Comparator 474 indicates the maximum value has been reached, the Post Queue Tail register 472 i s reset. A similar operation occurs for the Post Queue Head register 471 except the Post Queue Head register 471 is read by the Task Scheduling Accelerator Interrupt Service Routine 10. When the Post Queue Head register 471 is read, it auto- increments to the next queue position. A Comparator 475 compares the Post Queue Head register 471 to a maximum value stored in the Post Queue Max register 470. If the Comparator 475 indicates the maximum value has been reached, the Post Queue Head register 471 is reset. Thus, efficient software queuing is possible by not requiring the software to increment and wrap the queue pointers. The Post Queue Head register 471 and Post Queue Tail register 472 are compared using Comparator 478 to determine if the two registers are equal. If they are equal, signal 51 indicates the Semaphore Index Queue 15 is empty. If the registers are unequal, signal 51 indicates the Semaphore Index Queue 15 i s not empty. When signal 51 indicates the Semaphore Index Queue 15 is non-empty and Status 42 indicates the Semaphore Post bit is clear, then the State Machine 41 determines at decision 4170 to execute the Process Move Post 4172 function, as shown in FIG. 15, numeral 1500. The Process Move Post 4172 first sets the CTX bit 41721 in the Status register 42 to indicate that when the host processor services the interrupt 33
(CTX=1 in this -implementation), the registers in the STCI are context (i.e., should be preserved). The State Machine 41 then indicates to the Interrupt Service Routine Interface 40 that the ATCI can be written with a value from the Semaphore Index Queue 15 by setting the Move Post bit in Interrupt Control register (ICR) 403 as shown in 41722. The Process Move Post 4172 then waits for the Task Scheduling Accelerator Interrupt Service Routine 10 to process the interrupt 41723. The Process Move Post function 4172 knows the host processor has serviced the Move Post request when the Task Scheduling Accelerator Interrupt Service Routine 10 clears the Move Post bit in the Interrupt Control register 403.
As shown in FIG. 16, numeral 16, the interrupt Status Information Interface 1601 typically includes a Move Current To register 401 , a Take New From register 402 and an Interrupt Control Register 403 that is coupled to an Interrupt Generator 404. The Interrupt Generator 404 determines if any bits are set in the Interrupt Control register 403 and asserts the interrupt 30. If all bits in the Interrupt Control Register 403 are clear, the Interrupt Generator 404 negates the interrupt 30. The host processor responds to the interrupt assertion 30 by activating the TSA-ISR 10 (TSA Interrupt 1 0) as shown in FIG. 17, numeral 1700. The TSA-ISR 10 f i rst determines the state of the CTX flag 102. Since it is known f o r a Move Post function that this bit is set, the Task Control register is not cleared. The details of this clearing action are explained in greater detail later. The Interrupt Control register 34
403 in the ISR Interface 40 is read to- determine if the Move Post bit is set 103. In this scenario, this bit has been set and the TSA-ISR 10 executes the function to move a semaphore post from the Semaphore Index Queue 15 to the ATCI as shown in 104.
The details of the Move Semaphore Post 104 function are shown in FIG. 18, numeral 1800. The pointer to the semaphore queue is obtained by reading the Post Queue Head register 471 in the Semaphore Post Queue Interface 47. This pointer is used to read the head of the Semaphore Index Queue 15, Semlndex = SemaphorelndexQueue[PostQueueHead], as shown in 1042. The Semaphore Count associated with the semaphore index i s incremented, SemaphoreCount =[Semlndex], as shown in 1 043. The incremented count is written to the ATCI Semaphore Post Count 451 register, SemaphorePostCount =
SemaphoreCount[Semlndex], as shown in 1044. The Move Semaphore Post 104 function then obtains the priority of the first task pending (in list Semlndex) on the semaphore f rom Data Structures 11. This priority is written to the ATCI Semaphore Post Priority register 452 as shown in 1045. The Move Semaphore Post 104 function then writes the index of the semaphore to the ATCI 45 Semaphore Post Index register 453 , SemaphorePostlndex = Semlndex, as shown in 1046. The action of writing the Semaphore Post Index register 453 causes the ATCI to set the Semaphore Post bit in Status 42. The TSA-ISR then indicates the Move Semaphore Post 104 function has been completed by clearing the Move Post bit in the I nterrupt 35
Control register 403 as shown in 1047. The ability of the TSA to request information from the semaphore post index queue by asserting its interrupt relieves the host processor from having to poll the TSA to determine when it is ready. When a task command has been issued via the STCI 46 o r the ATCI 42, the State Machine 41 recognizes a command pending by examining the Task Command register 465 or the Status register 42. The state machine makes scheduling decisions to determine if the currently executing task i s allowed to continue execution or if the currently executing task must be preempted. The State Machine 41 may also request from the Host Processor 1 to move a semaphore index from the Semaphore Index Queue 15 or to make a modification to the task list. The last two functions do not change the execution of the currently executing task.
When the State Machine 41 processes commands, there are typically two different actions that result: (1) there is no change in the execution of the current task and the State Machine 41 simply clears the status bit indicating the command has completed, or, (2) the currently executing task i s preempted.
A unique aspect of the present invention is how the State Machine 41 efficiently communicates the task switch to the host processor by using the Interrupt Service Routine Interface 40. Data Structures 11 represent the current state of the task set on the host processor as shown in FIG. 19, numeral 1900. A "task object" 116 is the information representing the current 36
state of a single task. The simplest information the task object stores is the task priority and the context of the task. When a task object is the currently executing task 111 , the task object 116 is not linked into any list. When the task object is ready for execution 110 but not currently executing, the task object 116 is linked into a Ready Task List 1 17 according to the task priority. A task of priority zero is linked into the list at the top of the head nodes and tasks of lower priority are linked into lists further from the top of the head nodes. When the task is pending for a semaphore 112, the task object 116 is linked into a list according to the semaphore i t is waiting for. Counting semaphores allow a plurality of tasks to be waiting for a single semaphore. Associated with each head node in the Semaphore Queues 112 is a Semaphore Count 115. The Semaphore Count 115 represents the number of events that have been generated or requested for each semaphore. In the situation where the semaphore is zero or positive, there are no blocked tasks on the associated Semaphore List 118. I n the situation where a Semaphore Count 115 is negative, the negative value indicates how many tasks are waiting for the semaphore and equivalently, how many tasks are linked into the Semaphore Lists 112. The Head Nodes 113 and 114 are stored contiguously in memory such that a single integer can reference either list. If the integer is zero, it references the highest priority ready task queue 113. If the integer is less than the number of priorities, the integer references a lower priority list 113. If the integer is the same or greater than the 37
number of priority levels, it references head nodes for the semaphore lists 114. As an example, assume there are 64 priority levels and 100 semaphores. Head nodes113 contains 64 head nodes and head nodes 114 contains 100 head nodes. An index of 0 would reference the highest priority ready task l i s t in 110, an index of 63 would reference the lowest priority ready task list in 110 and an index of 100 would reference the
36 semaphore in head nodes 114. Thus, a single integer can reference tasks that are ready for execution at each priority level or tasks that are waiting for any semaphore.
Using a single integer to reference both lists provides an efficient mechanism for specifying a task switch as shown i n FIG. 20, numeral 2000. The Interrupt Service Routine Interface 40 implements two registers containing integers f o r referencing lists. The Move Current To register 401 specifies an integer indicating a list to move the Currently Executing Task 111 to. The Take New From register 402 indicates a l i st to take the new task object for execution to replace the Currently Executing Task 111. Thus, the Host Processor 1 does not perform any computations or decisions in determining the task switch - it simply responds to the decisions made by the TSA 2 and adjusts the task lists accordingly. To further qualify the task switch, the Interrupt Control register 403 contains three bits called Save Context, Load Context and Idle. When the Save Context bit is set, it indicates the Move Current To register 401 contains a valid integer and the Currently Executing Task 111 should be saved. As an example, i n 38
situations where the currently executing task exits, this bit i s zero indicating the Currently Executing Task is no longer needed and it should not be linked into any list. When the Load Context bit is set, it indicates the Take New From register 402 contains a valid integer and the Currently Executing Task 1 1 1 should be replaced by the first task on the list specified by the Take New From register 402. As an example, in situations where the task set becomes idle, this bit is clear indicating there is no new task to execute. The Idle bit is set when there is no new task to execute and the task set is idle. This functionality is similar to the Load Context bit; however, if a task exits and there is no new task to execute, both the Save Context and Load Context bits are clear. In order to indicate the idle condition, the Idle bit is set to allow the Interrupt Generator 404 to assert the interrupt 30.
A unique aspect of the present system is the method used to control context of the TSA. It is required for the TSA to clear command bits in the Task Command register 465 (set by synchronous commands) after the command has been processed. This is trivial when there is no change in the executing task - the TSA clears the bit and the task continues. However, when a preemptive task switch occurs, it is necessary to clear the command bit such that the task switch is transparent and when the preempted task is restarted it sees the command has been completed. This is not trivial because preemptive task switches are "transparent" to tasks - a task is never aware a preemption has taken place. Although the TSA asserts the 39
interrupt to preempt the current task, a realistic processor may execute several instructions after the interrupt i s asserted because the host processor hardware typically requires time to synchronize and dispatch the interrupt. Thus, the command bit is not allowed to be cleared until after the host processor has begun the actual TSA-ISR. If the TSA clears the command bit prior to this time, the task may erroneously execute additional instructions because it has seen the command bit clear. Another potential solution would be t o clear the command bit when the task context is reloaded. However, this does not work because if the task switch was caused by an asynchronous task command (i.e. a semaphore post from an interrupt), the bit would be cleared when in reality i t may be valid. This indicates the command bits f rom synchronous commands can not be cleared when restoring the context of the task. Another issue is that if the TSA-ISR saves the TSA registers as context and then restores them, the TSA is again instructed to execute the same command that j u st caused the task switch. This indicates the command bits must be cleared prior to saving the task context. The solution to satisfy all these requirements is to clear the command bits i n the Task Command register 465 for synchronous task commands after it is assured the host processor has started its interrupt procedure, but before the context for the task has been saved (note the task context includes the host processor registers and the TSA Parameter 460, Semaphore Pend Count 463 and Task Command 465 registers). However, the host 40
processor does not know if the task switch that is occurring i s due to a synchronous task command (command bits should be cleared) or an asynchronous task command (command bits should be preserved) - only the TSA knows this information. This is resolved by having the TSA provide a bit called CTX f o r indicating if the Task Command register 465 represents context (and it should be preserved) or if it is not context because the task switch is due to a synchronous task command (and it should be cleared). This indication is made to the TSA- ISR as shown in FIG. 17 where the Task Control register 465 i s cleared if the CTX bit is clear 102. Note that this operation 102 is performed at the start of the interrupt service when i t can be guaranteed that the currently executing task has been preempted but before the context for the currently executing task is saved. After the Task Command register 465 has been appropriately adjusted 102, the Task Switch 107 can save the TSA registers and restore them. Although 102 is shown as being implemented as a step in the TSA-ISR, a software implementation of this function would be slow because i t would require inquiring the CTX bit in the TSA and conditional execution. The present invention provides a unique solution to this efficiently by implementing function 102 directly i n hardware of the TSA. This is implemented by realizing the Interrupt Control register 403 is accessed only by the TSA- ISR. In other words, if the Interrupt Control register 403 i s read or written, the TSA can be assured the current task has been preempted. Thus, the function 102 may be implemented 41
directly in hardware by having the TSA clear the Task Command register 465 if the CTX bit is clear and the Interrupt Control register 403 is read. Since this solution does not require software, the TSA-ISR 10 is extremely fast. The TSA-ISR 10 performs four major functions as shown in FIG. 17. The TSA-ISR 10 first adjusts the context of the Task Command register 465 if necessary as shown in 102. The second major function the TSA-ISR 10 performs is to move semaphore post indexes from the Semaphore Index Queue 15 as shown in 104 if the Move Post bit is set in the Interrupt Control register 403 according to decision 103. The thi rd major function the TSA-ISR 10 performs is to adjust the task lists if the Move Task bit is set in the Interrupt Control register 403 if decision 105 is true. This function moves a task from one list to another as shown in 106. This operation does not disturb the currently executing task but simply modifies links in Data Structures 11. If TSA-ISR function i s neither the Move Task nor Move Post function, then the Interrupt Control register 403 performs its fourth major function, a task switch 107.
The task switch function is shown in detail in FIG. FIG. 21 , numeral 2100. The task switch procedure between the host processor and the TSA is designed for maximal overlap t o minimize (and generally eliminate) the overhead of the TSA scheduling decisions. The Task Switch 107 first determines i f the context of the currently executing task needs to be saved 10720. If the Save Context bit is set in the Interrupt Control 42
register 403, then the processor registers and the TSA registers (Parameter 460, Semaphore Pend Count 463 and Task Command 465 registers) are saved as context in the currently executing task object 111 as shown in 10721. The currently executing task object 111 is then moved to a list as indicated by the integer in the Move Current To register 401 as shown i n 10722. The Task Switch 107 then clears the Save Context b i t in the Interrupt Control register 403 as shown in 10723. Clearing this bit implicitly handshakes with the TSA that the context has been saved. At this point, the Task Switch 1 07 waits for the TSA to determine the next ready task. It should be noted that as the Task Switch 107 was saving the processor context and linking the currently executing task into the Move Current To task list, the TSA was busy looking for the next task to execute. This provides a maximal processing overlap t o effectively hide the time it takes to determine a next ready task. To ensure the TSA has completed looking for a next ready task, the TSA-ISR waits at 10724 for the TSA to clear the Busy bit in the Interrupt Control register 403. When this bit i s clear, it indicates the TSA has finished searching the task l i s t and the decision to load context 10730 may now be checked. Although the TSA has searched the task list, it is possible that no ready task was found and the processor is now idle. The decision 10730 determines if the TSA has located another ready task by determining if the Load Context bit in the Interrupt Control register 403 has been set. If the Load Context bit is set, this indicates a new task has been found and should 3
be loaded for execution to become the new Currently Executing Task 1 1 1 . The new task is taken from the list indicated by the Take New From register 402 as shown in 10731 . The host processor then loads the context from the task object 1 0732. Loading the context involves loading the host processor registers and restoring the TSA registers (Parameter 460 , Semaphore Pend Count 463 and Task Command 465 registers) . After the context has been restored, the Load Context bit in the Interrupt Control register 403 is cleared 10733 to indicate t o the TSA that the task context has been reloaded. If there is no context to be loaded (10730 is false) , then the processor i s idle and decision 10740 is true. When the task set is idle, the host processor sets up an idle loop 10741 and clears the Idle bit in the Interrupt Command register 43 as shown in 1 0742. Clearing the Idle bit handshakes with the TSA to let it know that the host processor is entering an idle mode. After the task switch procedure, the TSA-ISR returns. This either switches to a new task if a new task context was loaded, or, idles the processor if no task was loaded. The details of the sequence of events for minimizing TSA scheduling decisions are shown in FIG. 22, numeral 2200. The worst case scheduling decision is when the currently executing task blocks because the semaphore count is zero or negative. I n this situation, the TSA examines each priority level for a non- zero Ready Task Counter 43. A unique operation of the present invention effectively hides this worst case to virtually zero time. Assume the Host Processor 1 is currently executing a 44
task 610 and the task pends for a semaphore 611. Let us also assume that this semaphore is zero or negative. This causes the currently executing task to block. The task writes the pend request to the TSA 2 and the TSA 2 recognizes the request 620 and starts the State Machine 41. The State Machine 41 immediately determines the current task must be preempted. The TSA 2 immediately asserts its interrupt. Note that at the time the interrupt is asserted, the State Machine 41 has not yet started looking for the next ready task. When the interrupt is asserted, the Host Processor 1 requires some time to synchronize and dispatch the interrupt 612. Additionally, the Host Processor 1 requires time to save the context of the current task and move the task to the list specified by the Move Current To register 401 as shown in 613. While the processor is saving the task context and adjusting the list, the TSA 2 is searching for the next ready task 621. At this point, the TSA 2 and the host processor must synchronize their activities 614. The Host Processor 2 first clears the Save Context bit in the Interrupt Control register 403 to indicate i t has completed saving the context and adjusting the lists. If the Host Processor 1 finishes first, the host processor TSA-ISR waits until the TSA 2 clears the Busy bit in the Interrupt Control register 403. Since the TSA 2 is micro-coded hardware, it generally finishes well before the Host Processor 1. If the TSA 2 finishes first, the Busy bit is already cleared when the host processor reads it. 45
As shown in FIG. 22, numeral 2200, the TSA 2 is assumed to have found a ready task after searching the list. The Host Processor 1 checks the TSA 2 to ensure it is ready 614 and the TSA 2 indicates it is ready after searching the task list 622. The Host Processor 1 then loads the context of the new task 615 and the TSA 2 waits for acknowledgement of the load 623 by waiting for the Load Context bit in the Interrupt Control 403 to clear. The Host Processor begins execution of the new task 616 by performing a "return from interrupt" (RTI). This exits the TSA-ISR and begins execution of the new task 617. After the TSA 2 has determined the new task context has been loaded, it idles waiting for more commands to process 624. Thus, the most time consuming part of task scheduling computation performed by the TSA 2 is overlapped with the operations on the Host Processor 1 to effectively hide the scheduling computation. This is not possible in a software scheduler because no matter how efficiently the software scheduler is, the process of determining the next ready task must be performed serially with the task saving and loading. Additional efficiency of using the TSA 2 is that the method o f searching for the next ready task is linear in the number o f priorities and is independent of the number of tasks. Adding additional tasks to the task set does not change the amount of time required to search for a ready task. The ready task search time is only dependent on the number of priority levels.
If an add task function is requested by the Host Processor 1 , the State Machine 41 recognizes the Add Task b i t 46
in the Task Command register 465 is set as shown in 4140. The State Machine 41 begins a sequence of instructions to process the newly added task (Process Add Task 4142) and is shown i n detail in FIG. 23, numeral 2300. The addition of the new task i s recorded by incrementing a counter representing the number of ready tasks at the priority level where the new task was added 414212. The State Machine 41 determines the priority level were the new task was added. This is obtained from the Parameter register 460 because the Add Task command 123 wrote the priority to the Add Task register 462. This value was transferred to the Parameter register 460. The state machine next determines if the newly added task is at a higher priority than the currently executing task 414214. If this i s false, then there is no change in the current execution and the State Machine 41 clears the Add Task bit in the Task Command register 465 as shown in 414216. The Add Task function 1 23 then continues executing after verifying the Add Task bit i s clear 1235. If the decision 414214 is true, the newly added task is a higher priority than the currently executing task and the newly added task preempts the current task. The State Machine 41 sets up the task switch in 414220 by (1) clearing the CTX bit, (2) indicates the current task should be moved to the list for the current priority level by setting the Move Current To register 401 to the priority level of the currently executing task and (3) indicates the new task should be taken from the list specified by the priority level where the new task was added by setting the Take New From register 402. 47
Since both the Move Current To register 401 and the Take New From register 402 are valid, both the Save Context bit and the Load Context bit in the Interrupt Control register 403 are set 414221. When these bits are set in the Interrupt Control register 403, the Interrupt Generator 404 asserts interrupt 30. While the host processor is synchronizing the interrupt, the TSA performs additional functions. The number of ready tasks at the priority level specified by the priority of the added task is decremented 414222 because this task is taken from the list by the TSA-ISR. The number of ready tasks at the priority level specified by the current execution priority i s incremented 41223 because the task being preempted is moved to this list. The state machine then waits for the TSA-ISR to indicate the task switch has taken place by waiting for the TSA-ISR to clear the Save Context and Load Context bits in the Interrupt Control register 403 as shown in 414224. When the TSA-ISR responds to the interrupt as shown in FIG. 17, the Task Command register 465 clears when the host processor reads the Interrupt Control register 403 because CTX is clear as shown in 102. This clears the Add Task flag bit in the Task Command Register 465. Since the Interrupt Control register 403 has the Save Context bit and Load Context bit set, decisions 103 and 105 are false. This results in the TSA-ISR executing the Task Switch 107 function. When the Task Switch 107 function clears both the Save Context and Load Context bits in the Interrupt Control register 403, the state machine continues from its wait at 414224 and the Interrupt Generator 48
404 negates the interrupt 30. The state machine then updates the current execution priority of the TSA to the priority of the new task that was added 414225.
If a task exit function is requested by the host processor, the State Machine 41 recognizes the Task Exit bit in the Task Command register 465 is set in 4150. The State Machine 41 begins a sequence of instructions to process the exiting task (Process Task Exit 4152) and is shown in detail in FIG. 24, numeral 2400. The State Machine 41 determines if there i s another ready task by searching the Ready Task Counters 43 from the Current Execution Priority 44 to the lowest priority as shown in 415211. If the State Machine 41 determines there are no ready tasks, then decision 415212 is false and the processor is idle. The State Machine 41 clears the CTX bit t o indicate the Task Command register currently does not contain context 415213. The State Machine 41 also sets the IDLE flag in the Status register 42 to remember the state of the host processor 415213. Since there is no task to save (the current task is exiting) and no task to load (the host is now idle), the State Machine sets only the Idle bit in the Interrupt Control register 403 as shown in 415214. When the Idle bit is set i n the Interrupt Control register 403, the Interrupt Generator 404 asserts interrupt 30. The TSA has no additional computation and simply waits for the host processor to clear the IDLE bit i n the Interrupt Control register 403 as shown in 415215. When the TSA-ISR responds to the interrupt as shown in FIG. 17, the Task Command register 465 clears when the host processor 49
reads the Interrupt Control register 403 because the CTX bit i s clear as shown in 102. This clears the Task Exit flag bit in the Task Command Register 465. Since the Interrupt Control register 403 has only the Idle bit set, decisions 103 and 1 05 are false. This results in the TSA-ISR executing the Task Switch 107 function. When the Task Switch 107 function idles the host processor and clears the Idle bit in the Interrupt Control register 403, the state machine continues from i t s wait at 415215 and then exits to the main loop. If when searching for a ready task 415211 a ready task was found, decision 415212 is true. State Machine 41 clears the CTX bit to indicate the Task Command register currently does not contain context 415220. The State Machine 41 sets the Take New From register 402 to the priority level were the ready task was found 415220. The TSA Current Execution Priority 44 i s updated to the priority level where the new task was found 415222. The Ready Task Counter 43 at the priority of where the ready task was found 415223 is decremented. Since there is no task to save (the current task is exiting) but there is a task to load (a ready task was found), the State machine 41 sets the Load Context bit in the Interrupt Control register 403 as shown in 415224. The State Machine 41 then waits for the TSA-ISR to clear the Load Context bit in the Interrupt Control register 403 as shown in 415226. When the TSA-ISR responds to the interrupt as shown i n
FIG. 17, the Task Command register 465 clears when the host processor reads the Interrupt Control register 403 because the 50
CTX bit is clear as shown in 102. This clears the Task Exit flag bit in the Task Command register 465. Since the Interrupt Control register 403 has only the Load Context bit set, decisions 103 and 105 are false. This results in the TSA-ISR executing the Task Switch 107 function. The Task Switch 1 07 ignores the task object of the currently executing task (because it is exiting) and loads the context of the new object. When the Task Switch 107 function clears the Load Context b i t to indicate the context of the new task has been loaded, the State Machine continues from its wait at 415226 and returns to the main loop.
If a task yield function is requested by the host processor, the State Machine 41 recognizes the Task Yield b i t in the Task Command register 465 is set as shown in 4160. The State Machine 41 begins a sequence of instructions to process the task yield request (Process Task Yield 4162) and is shown in detail in FIG. 26, numeral 2600. The Process Task Yield determines if another ready task is present at the same priority level by using the Current Execution Priority 44 and the Ready Task Counters 43 as shown in 416221. If the Ready Task Counter is zero, there are no other ready tasks at the current priority level and decision 41622 is false. The State Machine 41 clears the Task Yield bit in the Task Command register 465 as shown in 41623. The Task Yield function 1 26 then continues executing after verifying the Task Yield bit i s clear 1263. If the decision 41622 determines another task i s ready at the same priority level, the currently executing task 51
is preempted. The State Machine 41 sets up the task switch i n 41624 by (1) clearing the CTX bit, (2) indicating the current task should be moved to the list for the current priority level by setting the Move Current To register 401 to the priority level of the currently executing task and (3) indicating the new task should be taken from the list specified by the current execution priority by setting the Take New From register 402. Because the Move Current To register 401 and the Take New From register 402 are set to the same value (the Current Execution Priority), the effect of the task yield function is t o rotate the ready task list at the current priority level. Since both the Move Current To register 401 and the Take New From register 402 are valid, both the Save Context bit and the Load Context bit in the Interrupt Control register 403 are set 41625. When these bits are set in the Interrupt Control register 403, the Interrupt Generator 404 asserts interrupt 30. The State Machine 41 then waits for the TSA-ISR to indicate the task switch has taken place by waiting for the TSA-ISR to clear the Save Context and Load Context bits in the Interrupt Control register 403.
When the TSA-ISR responds to the interrupt as shown i n FIG. 17, the Task Command register 465 clears when the host processor reads the interrupt Control register 403 because CTX is clear as shown in 102. This clears the Task Yield flag bit i n the Task Command Register 465. Since the Interrupt Control register 403 has the Save Context bit and Load Context bit set, decisions 103 and 105 are false. This results in the TSA-ISR 52
executing the Task Switch 107 function. When the Task Switch 107 function clears both the Save Context and Load Context bits in the Interrupt Control register 403, the state machine continues from its wait at 41626 and the Interrupt Generator 404 negates the interrupt 30.
If a modify priority function is requested by the host processor, the State Machine 41 recognizes the Modify Priority bit in the Task Command register 465 is set as shown in 4190. The State machine 41 begins a sequence of instructions t o process the change in task priority (Process Modify P riority 4192) and is shown in detail in FIG. 25, numeral 2500. The State Machine 41 determines the new priority level from the Parameter register 460 because the Modify Priority command 125 wrote the new priority to the Modify Priority register 461. This value was transferred to the Parameter register 460. The state machine next determines if the new priority is higher o r the same as the current execution priority 41921. If this i s true, then there is no change in the current execution because the highest priority ready task is currently executing and increasing its priority keeps the task as the highest priority task. The state machine updates the current execution priority to the new priority 41922 and clears the Modify Priority bit i n the Task Control register 41923. If the decision 41921 determines the new priority is lower, then it is possible that other ready tasks that were previously at a lower priority level are now higher priority. The state machine searches the Ready Task Counters 43 from the Current Execution Priority 44 53
to the new priority level for- a non-zero ready task counter t o determine if there is a ready task 41924. Decision 41 925 determines if a ready task was found. If no ready tasks were found, then the currently executing task is still the highest priority task. The state machine updates the current execution priority to the new priority 41922 and clears the Modify Priority bit in the Task Control register 41923. If decision 41925 determines a ready task was found, then the current task must be preempted because it is no longer the highest priority ready task. The State Machine 41 sets up the task switch in 41927 by (1 ) clearing the CTX bit, (2) indicating the current task should be moved to the list for the new priority by setting the Move Current To register 401 to the new priority level and (3) indicating the new task should be taken from the list specified by the priority level where the new task was found by setting the Take New From register 402. Since both the Move Current To register 401 and the Take New From register 402 are valid, both the Save Context bit and the Load Context bit in the Interrupt Control register 403 are set 41928. The number of tasks at the priority level where the current task is being moved to is incremented 4192810. The number of tasks at the priority level where the new task i s being taken from is decremented 4192820. The State Machine 41 then waits for the TSA-ISR to clear both bits 41929. When the Save Context and Load Context bits are set in the Interrupt Control register 403, the Interrupt Generator 404 asserts interrupt 30. The state machine then waits for the TSA-ISR to 679 -,,-----_
PCT/US99/05112
54
indicate the task switch has taken place by waiting for the TSA-ISR to clear the Save Context and Load Context bits in the Interrupt Control register 403.
When the TSA-ISR responds to the interrupt as shown i n FIG. 17, the Task Command register 465 clears when the host processor reads the Interrupt Control register 403 because CTX is clear as shown in 102. This clears the Modify Priority flag bit in the Task Command Register 465. Since the Interrupt Control register 403 has the Save Context bit and Load Context bit set, decisions 103 and 105 are false. This results in the TSA-ISR executing the Task Switch 107 function. When the Task Switch 107 function clears both the Save Context and Load Context bits in the Interrupt Control register 403, the state machine continues from its wait at 41929 and the Interrupt Generator 404 negates the interrupt 30. The state machine then updates the current execution priority of the TSA to the priority of the new task that was found 41926.
If a semaphore pend function is requested by the host processor, the State Machine 41 recognizes the Semaphore Pend bit in the Task Command register 465 is set as shown i n 4120. The State Machine 41 begins a sequence of instructions to process the semaphore pend (Process Semaphore Pend 4122) and is shown in detail in FIG. 27, numeral 2700. The processing of the semaphore pend begins by examining the value of the semaphore count 412212 that was written to the Semaphore Pend Count register 463. The decision 412212 determines i f the semaphore pend count is less than zero. If this is false, i t 55
indicates the semaphore pend count is greater than or equal t o zero. Since this counter was decremented prior to being written to the Semaphore Pend Count register 463, a value that is currently greater than or equal to zero indicates the original counter was strictly positive prior to being decremented. A positive count on the semaphore indicates the semaphore had previous recorded events. Since the pend request for the semaphore can be immediately satisfied, there is no change i n the current execution and the State Machine 41 clears the Semaphore Pend bit in the Task Command register 465 as shown in 412214. The Semaphore Pend function 122 then continues executing after verifying the Semaphore Pend bit i s clear 1224. If the decision 412212 determines the semaphore pend count is less than zero then the current task i s preempted. Since the counter was decremented prior to being written to the Semaphore Post Count register 463, a value that is negative indicates the original counter was zero or negative prior to being decremented. A negative or zero count on the semaphore indicates the semaphore previously had no events. A pend request on a semaphore without events causes the task to block execution until events become available. The State Machine 41 sets up the task switch in 412220 by (1 ) clearing the CTX bit, (2) indicating the current task should be moved t o the list to wait for the semaphore as specified by the Semaphore Pend Index register 464 and (3) setting the Save Context and Busy bits in the Interrupt Control register 403. A t this time it is known the current task can be preempted and i t s 56
context saved; but, it is not known if there is another ready task for execution. When the Busy and Save Context bits are set in the Interrupt Control register 403, the Interrupt Generator 404 asserts interrupt 30. While the host processor i s synchronizing the interrupt, the TSA looks for another ready task at the same or lower priority levels 412222.
When the TSA-ISR responds to the interrupt as shown i n FIG. 17, the Task Command register 465 clears when the host processor reads the Interrupt Control register 403 because the CTX bit is clear as shown in 102. This clears the Semaphore Pend flag bit in the Task Command Register 465. Since the Interrupt Control register 403 has only the Save Context and Busy bit set, decisions 103 and 105 are false. This results i n the TSA-ISR executing the Task Switch 107 function. The TSA- ISR clears the Save Context bit 10723 to indicate the context of the executing task has been saved and then waits while the Busy bit 10724 in the Interrupt Control register is set. The decision 412224 determines if a ready task has been found. I f this decision is false, it indicates there are no ready tasks and the task set is now idle. The TSA waits 412230 for the TSA- ISR to clear the Save Context bit in the Interrupt Control register 403 to ensure the TSA-ISR does not further write the Interrupt Control Register. The TSA then responds 412232 by clearing the Busy bit and setting the Idle bit in the Interrupt Control Register 403. The internal IDLE bit is set to indicate the task set is now idle 412234. When the Busy bit in the Interrupt Control register 403 is cleared, the TSA-ISR 57
continues and determines if there is a new context to load 10730. Since the Idle bit is set, the Task Switch 107 function idles the host processor 10741 and clears the Idle bit 10742 in the Interrupt Control register 403. The state machine continues from its wait at 412236 and then exits to the main loop. If when searching for a ready task 412222 determines a ready task was found, then decision 412224 is true. The Take New From register 402 is set to indicate the priority level where a new task was found 412240. The TSA waits 412246 for the TSA-ISR to clear the Save Context bit in the Interrupt Control register 403 to ensure the TSA-ISR does not fu rther write the Interrupt Control Register. The TSA then responds
412248 by clearing the Busy bit and setting the Load Context bit in the Interrupt Control Register 403. When the Busy bit i n the Interrupt Control register 403 is cleared, the TSA-ISR continues and determines if there is a new context to load 10730. Since the Load Context bit is set, the Task Switch 1 07 function removes the task from the list 10731 , loads the context 10732, and clears the Load Context bit 10733 in the Interrupt Control register 403. In parallel to the host processor loading the context of the new task, the TSA i s performing other functions - the Current Execution Priority 44 is set to the priority where the new task was found 412242 and the number of ready tasks at that priority level i s decremented 412244. After the TSA-ISR clears the Load Context bit, the state machine continues from its wait at
412249 and then exits to the main loop. Thus, it can be seen 58
the semaphore pend function is virtually transparent to the- host processor because (1) the TSA hides the determination o f the next ready task during the time the host processor i s saving the context of the current task and (2) the TSA hides i t s internal updates during the time the host processor is loading the context of the next task. In effect, the task switch time i s limited only by the time it takes for the Host Processor 1 t o context switch and is not dependent on the TSA 2.
If a semaphore post function is requested by the host processor, the State Machine 41 recognizes the Semaphore Post bit in the Status register 42 is set as shown in 4130. The State machine 41 begins a sequence of instructions to process the semaphore post (Process Semaphore Post 41 32) and i s shown in detail in FIG. 28, numeral 2800. The process of posting a semaphore is different than the previously described task commands because (1 ) semaphore posts can be requested by interrupts as well as tasks and (2) there is no "synchronization" with the semaphore posts (tasks/lSRs do not wait for them to complete). Once a semaphore post has been issued, the task or ISR continues execution without waiting for the TSA to process the semaphore. The processing of the semaphore post begins by examining the value of the semaphore count 413212 that was written to the Semaphore Post Count register 451. The decision 413212 determines i f the semaphore post count is less than or equal to zero. If th is is false, it indicates the semaphore post count is greater than zero. Since this counter was incremented prior to being 59
written to the Semaphore Post Count register 451 , a value that is greater than zero indicates the original counter was greater than or equal to zero prior to being incremented. A semaphore count greater than or equal to zero indicates there were no tasks pending for this semaphore and therefore no new tasks have become ready. The State Machine 41 clears the Semaphore Post bit in the Status register 42 as shown in 413214. If the decision 413212 is true, it indicates a task is currently pending for the semaphore and has become ready. One of fou r different situations may occur: (1 ) if the host processor i s currently idle, the ready task begins execution regardless o f its priority, (2) if the ready task is the same or lower priority than the currently executing task, the task is moved to a ready list but does not preempt the currently executing task, (3) the ready task is higher priority than the currently executing task and preempts it, or (4) the ready task is a higher priority than the currently executing task but the task lock is enabled which prevents preemption. The CTX bit is set 413220 to indicate that the TSA registers in the STCI are preserved. This happens because a task may be in the process of issuing a synchronous task command when then semaphore post begins processing. Transparently saving the TSA registers in the STCI ensures the task is transparently restored. Setting CTX is necessary f o r both the task preemption and the move task situation. For the wake up from idle, context is irrelevant because when the processor is in the idle state, it does not have context. The decision at 413222 determines if the host processor i s 60
currently idle. If the IDLE bit is set in the Status register 42 , the host processor wakes up from an idle condition. In many situations, the host processor implements a " w a i t " instruction. The "wait" places the processor in the low power state. This low power state is typically exited by an inte rrupt that the TSA provides.
The State Machine 41 sets the Take New From re giste r 402 to the Semaphore Post Index 453 as shown in 413250. This represents the list where the semaphore posted. The Load Context bit is set in the Interrupt Control register to indicate there is only a task to load 413251. Since the host processor is no longer idle, the IDLE bit in the Status register is cleared 413252. The Current Execution Priority 44 is updated to the priority of the first task that was pending on the semaphore as specified in the Semaphore Post Priority register 452 as shown in 413253. The State Machine 41 then waits for the TSA-ISR to clear the Load Context bit in the Interrupt Control Register 403 as shown in 413254. When the Load Context bit i s set in the Interrupt Control register 403, the I nte rrupt Generator 404 asserts interrupt 30. When the TSA-ISR responds to the interrupt as shown in FIG. 17, the Task Command register 465 is not cleared when the host processor reads the Interrupt Control register 403 because the CTX bit i s set as shown in 102. This preserves the value of the Task Command Register in case a task was in the process of issuing a synchronous task command. Since the Interrupt Control register 403 has only the Load Context bit set, decisions 1 03 61
and 105 are false. This results in the TSA-ISR executing the Task Switch 107 function. The TSA-ISR clears the Load Context 10733 to indicate the context of the new task has been loaded. The state machine continues after the wait 413254 and clears the Semaphore Post bit in the Status register 42 as shown in 413214.
If the decision 413222 indicates the host processor i s not currently idle, then the State Machine 41 determines if the priority of the first task pending on the semaphore is higher than the current execution priority 413224. This is performed by comparing the value in the Semaphore Post Priority registe r 452 to the Current Execution Priority 44. If the decision 413224 is false, this indicates the task that was pending on the semaphore was the same or lower priority than the currently executing task. In this situation, the currently executing task remains executing (no preemption) but the task that was pending on the semaphore now becomes ready. The task needs to be moved from the semaphore list to the ready task list. The State Machine 41 indicates how to move the ready task from the semaphore list to the ready task list by using the Move Current To register 401 and the Take New From register 402. The roles of these registers are siightly different because they indicate a task to be moved from one list to another rather than a context switch. The list where the task was pending is specified by the Semaphore Post Index register 453 and sets the Take New From register 402. The Move Current To register 401 specifies the list where the task 62
is moved to and is set to the priority of the pending task that was written to the Semaphore Post Priority register 452. These registers are set in 413230. The Move Task bit is set i n the Interrupt Control register to indicate a task move i s required 413231. The number of ready tasks at the priority level where the task is being moved to is incremented 413232. The State Machine 41 then waits for the TSA-ISR to clear the Move Task bit in the Interrupt Control Register 403 as shown in 413233. When the Move Task bit is set in the Interrupt Control register 403, the Interrupt Generator 404 asserts interrupt 30.
When the TSA-ISR responds to the interrupt as shown i n FIG. 17, the Task Command register 465 is not cleared when the host processor reads the Interrupt Control register 403 because the CTX bit is set as shown in 102. This preserves the value of the Task Command register because the Move Task operation should not affect the currently executing task. Since the Interrupt Control register 403 has only the Move Task b it set, decision 105 is true. This results in the TSA-ISR executing the Move Task 106 function. The TSA-ISR removes the ready task from the semaphore list as specified by the Take New From register as shown in 1062. This task is placed at the end of the ready list as specified by the Move Current To register as shown in 1063. The Move Task bit in the Interrupt Control register is then cleared 1064. The state machine continues after the wait 413233 and clears the Semaphore Post bit in the Status register 42 as shown in 413214. 79 --,^--,„
PCT/US99/05112
63
If the decision 413224 is true indicating the ready task that was pending on the semaphore has a higher priority than the currently executing task, then the current task potentially needs to be preempted. The decision 413260 determines if the task lock mode is enabled. If the task lock mode is enabled, the TSA is not allowed to preempt the current task even though a higher priority task has become ready. If decision 413260 i s true, the task lock is set and the Preemption Pending bit is set in the status register 413261. This bit remembers that a higher priority task has become ready and that the currently executing task should be preempted when the task lock i s removed. After the Preemption Pending bit is set, the semaphore post is processed as a task move. This moves the task to a ready list using the task move operation as previously described.
If the decision 413260 determines the task lock i s currently off, then the ready task preempts the currently executing task. The currently executing task is moved to the list for its priority level by setting the Move Current To register 401 to the Current Execution Priority 44, and the new task is taken from the semaphore list by setting the Take New From register 402 to the Semaphore Post Index register 453 as shown in 413240. Both the Save Context and the Load Context bits in the Interrupt Control register 403 are set to save the context of the current task and load the context of the new task 413241. The number of ready tasks at the priority level of the currently executing task is incremented 413242 and the 64
State Machine 41 waits for the TSA-ISR to clear both the Save Context and Load Context bits in the Interrupt Control register 403 as shown in 413243.
When the TSA-ISR responds to the interrupt as shown i n FIG. 17, the Task Command register 465 is not cleared when the host processor reads the Interrupt Control register 403 because CTX is set as shown in 102. This preserves the Task Command register of the task being preempted. Since the Interrupt Control register 403 has the Save Context bit and Load Context bit set, decisions 103 and 105 are false. This results in the TSA-ISR executing the Task Switch 1 07 function. When the Task Switch 107 function clears both the Save Context and Load Context bits in the Interrupt Control register 403, the state machine continues from its wait at 413243 and clears the Semaphore Post bit in the Status register 42 as shown in 413214.
If the state machine determines the task lock is of f (preemption is now enabled) but the Preemption Pending bit i s set 4195, then a task that had become ready while the task lock was on must now be selected for execution. This i s performed by the Reschedule function 4196 and is shown i n detail in FIG. 41 , numeral 4100. The reschedule operation begins by searching from the highest priority level to the current priority level for a ready task 41961. Since it was know a preemption was pending, this search is always successful. The Preemption Pending bit is then cleared 41962. Since the reschedule operation appears as a semaphore post 65
that was delayed in time, the CTX bit is set to preserve the task context 41963. The currently executing task is moved to its priority level by setting the Move Current To register to the current execution priority. The Take New From register is set to where the new highest priority ready task was found. Both the Save Context and Load Context bits are set in the Interrupt Status register 41964 to save the current task and load the new task. The number of ready tasks at the priority level where the highest priority task was found is decremented 41965 and the number of tasks at the priority level where the current task is being moved to is incremented 41966. The TSA then waits for both the Save Context and the Load Context bits to clear 41967 indicating the task switch has taken place. The current execution priority is then updated to the priority of the task that was found 41978.
A device comprising a Task Scheduling Accelerator and a host processor is shown in FIG. 30, numeral 3000. This describes the TSA 80 as connecting to any arbitrary Host Processor 70 using the standard peripheral interface, except that it includes an interrupt line 92. As shown in FIG. 30, the Host Processor 70 and TSA 80 are connected with a data bus 90, an address bus 91 and an interrupt line 92. Thus, the TSA 80 appears as any arbitrary peripheral in the host system. The TSA 80 is connected as a memory mapped device using an interrupt line 92. This is an important feature of the present invention because the TSA 80 may be connected to almost any type of Host Processor 70: RISC, CISC, DSP, microcontroller, 66
etc. This allows the TSA 80 to be connected as an external device or a device integrated directly onto the processor chip. Since the TSA 80 does not require any specialized instructions on the Host Processor 70, the TSA 80 is independent of the type of Host Processor 70. This allows fast integration and fast time to market by not requiring any changes to the processor core for integrating the TSA 80.
Although there are various methods to implement the TSA hardware, the preferred embodiment uses the hardware architecture shown in FIG. 31 , numeral 3100. The architecture generally comprises several functional interfaces (8021 , 8022, 8023 and 8024), an internal bus for moving registers 8040, an ALU 8014 for manipulating values and comparing values, a current execution priority register 8017 and a RAM 8010 for storing values. The Synchronous Task Command interface 8021 is used for issuing synchronous commands and contains several registers. These registers are the Parameter, Modify Priority, Add Task, Sem Pend Index, Sem Pend Count and Task Command registers. Since a synchronous task command i s completed prior to another synchronous task command being issued, only one synchronous task command is active at any given time. This allows registers that hold parameters to be reused for a reduction in hardware cost. When writing the Modify Priority, Add Task or Sem Pend Index register, the value is transferred to the Parameter register. Writing these registers also causes a flag to set in the Task Command register to indicate a pending command. The task exit and task 67
yield commands do not require parameters and are performed by setting a bit in the Task Command register directly. The Parameter, Sem Pend Count and Task Command registers are connected to the internal bus 8040 and are manipulated by moving the value from the register to an ALU operand register. The Parameter, Sem Pend Count and Task Command registers are readable from the host processor and are saved/restored on a context switch. The Asynchronous Task Command interface 8022 is used for issuing commands asynchronous to tasks. The only command that may be issued by interrupts (asynchronous to tasks) is the semaphore post. This interface allows commands to be issued without waiting for them to complete. To issue a semaphore post through the Asynchronous Task Command interface, the Semaphore Post Count, Semaphore Post Priority and Semaphore Post Index registers are written. When the Semaphore Post Index register is written, the Semaphore Post flag in the Status register 8020 is set. The Interrupt Control interface 8023 is used to direct the activities of the interrupt service routine on the host computer. This interface contains the Move Current To and Take New From registers t o indicate how to perform a task switch or how to move a task between lists. The Interrupt Control register contains flags that indicate the reason for the interrupt (move semaphore post, move task or context switch) and additional flags f o r qualifying the operation of the context switch. The Interrupt Logic is a logical-OR of all the bits in the Interrupt Control register and asserts the interrupt when any bit in the Interrupt 68
Control register is set and negates the interrupt if all bits are clear. The Interrupt Control interface also contains special reset logic. This reset logic resets the Task Command register if the CTX bit in the Status register is clear and the Interrupt Control register is read. This is used to efficiently manipulate the TSA context for a context switch. The Post Queue Control interface is used to assist the queuing of semaphore posts when the Asynchronous Task Command interface is currently full. The Post Queue Control interface contains queue pointers that auto-increment after being read and wrap at a maximum value as specified by the Post Queue max register. Queue Logic determines if the head and tail pointers are equal and determines if the queue contains any information.
The OP1 register is used as a source register for ALU operations. All ALU results go to the OP1 register. The OP2 register is used when the ALU needs to compare a value to the OP1 register. The ALU 8014 is capable of clear, increment, decrement, bit set, bit clear, bit test, test OP1 and compare to operand register OP2. This minimal amount of functions can perform the algorithms for task scheduling. A bit test, test OP1 or compare to OP2 operation sets the condition codes 8015. These condition codes can be used by conditional jump instructions in the state machine 8016. The condition codes currently implemented are N (negative), Z (zero), C (carry) and A (always true). The state machine executes microinstructions to execute the scheduling algorithms. The Current Execution Priority 8017 stores the priority of the currently 69
executing task. The RAM 8010 stores the plurality of ready task counters. Addresses within the RAM are referenced w i t h the RAM Address register 8011.
In a preferred embodiment the architecture is a "16 b i t " architecture from the point of view that most of the registers are 16 bits wide. The RAM is a 64x8 RAM. This assignment o f architecture components creates the following configuration on the TSA:
• There are 64 priority levels. This is considered to be a significant number because most commercial task schedulers typically implement 8-16 priority levels. The number of priority levels is determined by the depth of the RAM.
• There can be up to 255 tasks at each priority level. The number of tasks at each priority level i s determined by the width of the RAM.
• The TSA can support up to 255*64 = 16320 tasks. For a single processor, this is considered to be a significantly large value. • The total number of semaphores the device may allocate is 65536 minus the number of priority levels (64) equaling 65472.
• Semaphores may have up to 32767 semaphore posts.
• Semaphores may have up to 32768 tasks pending f o r each semaphore. 70
This configuration is a balance of TSA silicon size verses the typical size of most multi-tasking systems. These parameters may easily be changed by changing the RAM size or the size of the architecture. Even with this preferred configuration, the TSA far exceeds the typical requirements of a single processor system.
The details of the State Machine 8016 are shown in FIG. 32, numeral 3200. The State Machine contains a State Control ROM 80163 for storing a sequence of State Machine Instructions (SMIs) that execute the task scheduling algorithms. Instruction Counter 80162 is a counter that increments sequentially or may be parallel loaded. The Instruction Counter 80162 points to an address in the State Control ROM 80163 to reference an SMI for execution. The State Control ROM 80163 outputs the SMI to the Instruction Decoder 80164. The Instruction Decoder 80164 determines the type of SMI and routes it to the correct execution unit: jump instruction 80165, register move instruction 80166, special operation 80167 or ALU instruction 80168. If the SMI is a jump instruction, the jump instruction decoder 80165 determines i f the jump is executed by examining the ALU conditions 8030. I f the jump instruction is true, the instruction counter 80162 i s loaded with a new value to jump to a different SMI. If the jump instruction is false, the Instruction Counter 80162 increments to the next SMI. If the SMI is a register move instruction, the Register Move Instruction decoder 80166 determines the source and destination registers. The Register Transfer Enable 71
logic 80169 enables the source register onto the bus and reads the destination register from the bus. The special operation instruction decoder 80167 performs irregular operations. The only irregular instruction currently required is to disable the TSA clock to reduce power consumption. When the Special Operation Instruction decoder 80167 decodes a clock disable operation, Clock Control 80161 disables the clock from the Clock Generator 80160 to the Instruction Counter 80162. If the SMI is an ALU instruction, the ALU Instruction decoder 801 68 determines the ALU operation and operand 8031 , and instructs the ALU 8014. When the clock has been disabled, the clock i s re-enabled when the state machine has commands to process. The Clock Control 80161 is re-activated by the Clock Activate Logic 801600 whenever any of three conditions exist: (1) a semaphore is posted 8032 as indicated by Semaphore Posted bit set in the Status register, (2) a task command has been issued 8033 as indicated by any bit in the Task Command register being set, or (3) the software Semaphore Index Queue 15 is non-empty and can be transferred to the Asynchronous Task Command Interface as is indicated by the Semaphore Post bit in the Status register being cleared and the Post Queue Head counter being unequal to the Post Queue Tail counter 8034. Thus, it can be seen that if the TSA is inactive, disabling the state machine can save considerable power. The instruction set for controlling the state machine i s efficiently encoded to minimize the size of the State Control ROM 80163. The details of the encoding are shown in FIG. 33, 72
numeral 3300. The instructions are encoded into 16 bits and have a plurality of reserved bits for future expansion. The f i rst two bits of each instruction determine the instruction type. Since there are four types of instructions, this is efficiently encoded in two bits. There are 4 types of SMIs:
• The ALU instruction 3301. The ALU instruction controls the ALU to perform a function. This function may require the OP1 or OP2 registers. The ALU instruction is required to encode 8 ALU operations. This is encoded into 3 bits with an extra reserved b i t for a total of 4 bits for the ALU operation field. The ALU operand is used to select a bit offset for the b it test, bit set or bit clear functions. Since the TSA is a 16 bit device, the ALU Operand field can be encoded i n 4 bits. The remaining 6 bits in the ALU instruction are reserved.
• The Transfer instruction 3302. The transfer instruction is used to move registers on the internal bus. Internally, there are 16 registers to access: Status, Parameter, Sem Pend Count, Task Control, Sem
Post Count, Sem Post Priority, Sem Post Index, Move Current To, Take New From, Interrupt Control, OP1, OP2, RAM Address, Ram Data (RAM input/output) and Current Execution Priority. This efficiently encodes into 4 bits for the source and 4 bits for the destination. An extra reserved bit is included for a 73
total of 5 bits for each field. The remaining 4 bits are reserved.
• The Special Instruction 3303. Each bit in the special instruction performs an operation. The only currently encoded special instruction is to disable the clock as specified with the "nclk" bit. The remaining 13 bits are reserved.
• The Jump instruction 3304. The jump condition allows the state machine to jump to another SMI based on the condition codes. The four condition codes Z, C, N and A are encoded into 2 bits. Another bit is used to indicate the complement of the condition. For example, the complement of "zero" is "non-zero". An extra reserved bit is included for expansion of the number of condition codes for a total of 4 bits for the ALU condition field. If the resulting test is true, the Instruction Counter is loaded with the value in the State Address field. Since this is a 9 bit field, the state machine can address up to 512 SMIs. This i s more than adequate for implementing the scheduling algorithms. The remaining 1 bit is reserved.
The instruction set is efficient and easy to decode resulting i n an inexpensive implementation of the TSA. The device of the present invention may be implemented in an article of manufacture that utilizes a processor. Examples of such articles of manufacture are: base stations, 74
handheld radios, engine controllers, musical devices, security systems, cordless telephones, modems, fax machines, disk drives, cellular telephones, automotive controllers, motor controls, and the like. A unique aspect of the device incorporating the TSA i s the previously discussed method for queuing data from the host processor to the TSA. To determine a simplified diagram o f only the data queuing mechanism, a simplified diagram i s shown in FIG. 35, numeral 3500. To understand why this is a more efficient mechanism than prior art, a prior art system i s shown in FIG. 34, numeral 3400. In the prior art, data i s transferred from an executing algorithm 780 on a host processor 785 to a data register interface 787 in an external device 786. The data register interface 781 writes data to the external device data register 787 for processing by an arbitrary data processing unit 788. If the algorithm 780 generates data faster than the data processing unit 788 can consume the data items, either the data items are queued or the algorithms must wait. In an environment where waiting i s not possible (such as data items generated by interrupt service routines), data must be efficiently queued. In typical prior art, the Data Register Interface 781 stores the data in a host processor data queue 784 and modifies pointers 783. The Data Register Interface 781 must also enable the interrupt of the external device such that the external device generates an interrupt when the Data Register 787 is empty. When the data register 787 is not full, the interrupt is asserted to request 75
data from the host processor. The Interrupt Service Routine 782 moves data from the queue 783 and updates the pointers 784. This prior art mechanism requires many steps in the software of the host processor: • The Interrupt Service routine must move the data from the queue to the external device, update the data queue pointers, wrap the pointers according to the size o f the queue and disable the external device interrupt i f no more data is in the queue, • The host processor must store the data in the queue, update the data queue pointers, wrap the pointers according to the queue size and enable the external device interrupt. • This enabling/disabling of interrupts must be exclusive to avoid race conditions between the host processor interrupt service routine disabling interrupts and the data register interface function enabling them.
To reduce the complexity of the host software, it is best to balance the operation of the queue between the host processor and the external device as shown in FIG 35, numeral 3500. The host processor stores the data items but the external device stores the queue pointers. The host processor is simplified by not requiring storing pointers, incrementing o r wrapping them. The external device can always determine the status of the queue in the host processor by comparing the 76
queue pointers removing the need for enabling/disabling interrupts. Thus, the external device does not generate an interrupt unless it determines the host processor queue has data available and the external device can accept data. The host processor data queuing and interrupt processing code i s simplified. When an algorithm 710 writes a value to the data register interface 711 to transfer data to the external device, the data register interface 711 determines if the data register is full by examining the status unit 722 as shown in FIG. 37, numeral 3700. If decision 7111 is false, this indicates the data register is empty and can be written. The data registers are written with the data item 7113. If the decision 71 1 1 determines the data register 723 is full, the data item must be queued. The Queue Tail pointer 7202 is read from the hardware 7112 and used as an index to the queue for storing the data item. Note the simplicity of the software in 7112 because the queue tail pointer automatically increments and wraps i n hardware, and there is no need to enable the interrupts. The queue pointer unit 720 shown in detail in FIG. 36, numeral 3600, contains the queue head 7201 and the queue tail 7202. When the queue head or queue tail is read by the host processor, it is automatically incremented. The head comparator 7203 and tail comparator 7204 determine if a pointer is equal to the queue max 7200 value. If a pointer increments to the maximum value, the pointer is reset. This provides the pointer incrementing and wrapping functions required for queue indexing. The queue head 7201 and queue tail 77
7202 pointers are compared by the empty comparator 7205. I f the queue head 7201 and queue tail 7202 are equal, the software queue is empty. If the queue head 7201 and queue tai l 7202 are not equal, the software queue is non-empty. When the software queue is non-empty as indicated by 725 and the data register 723 is not full as indicated by status unit 722, then the interrupt request unit 721 asserts its interrupt. The host processor responds to the interrupt in FIG 38, numeral 3800. The interrupt service routine reads the hardware queue head pointer 7201 , retrieves . the data item from the queue and writes the data item to the data register. Note the simplicity of the software in 7130 because the queue head pointer automatically increments and wraps in hardware, and there i s no need to check the status of the queue and disable interrupts. It is generally important to minimize the complexity and time of an interrupt service routine. Thus, it can be seen thi s method of data queuing considerably simplifies the host software and minimizes the interrupt service routine.
A unique aspect of the device incorporating the TSA i s the previously discussed method for clearing the register fo r issuing commands to the TSA. To determine a simplified diagram of only the register clearing mechanism, a simplified diagram is shown FIG. 39, numeral 3900. The TSA has been simplified to include only the components that are involved i n issuing commands and clearing them. Tasks 7501 on a host processor 7508 issue commands to the TSA 7509 by setting command bits in the Task Command register 7506. The Task 78
Scheduling Unit 7505 determines if the command causes a task switch. If a task switch is required, the Task Scheduling Unit 7505 asserts an interrupt request to activate the Interrupt Service Routine 7502 on the Host Processor. To switch tasks, the Interrupt Service Routine 7502 saves the context of the current task and loads the context of a new task. Since the Task Command register 7502 is used by all tasks to issue commands, the Task Command register 7502 is considered as processor context because each task believes it is the only task using the register. This is a problematic situation because of the following issues:
• If the Task Command register 7502 is saved and restored by the Interrupt Service Routine 7502, then the command that caused the task switch will be reloaded when the task context is loaded. This causes the task to re-execute the same command that j u st caused the task switch. This creates the requirement that the task command register must be cleared if a task command caused the task switch. This allows the task to determine the task command has been completed and continue execution.
• If the context switch occurs for a reason other than a task command (for example, a semaphore post which does not use the task command register), then the
Task Command register 7506 must be preserved 79
(saved and restored) to ensure the preemption i s transparent to the currently executing task.
Although one may assume that the Task Command register 7506 could be cleared each time the task context is loaded, this would violate the second requirement that the Task Command register 7506 must sometimes be preserved. Another assumption would be to clear the task command register as soon as the TSA recognizes the command; however, this i s problematic because the task on the host processor may assume the task command is completed when in actuality it i s not (it has only been recognized) and continue executing. This is typically due to the issue that a realistic processor typically takes a finite amount of time to respond to an interrupt. Thus, the Task Command register 7506 must be cleared after the task switch (Interrupt Service Routine 7502) has started but only if the task switch is being caused by a task command. This is further complicated by the fact that only the Task Scheduling Unit 7505 knows the reason for the task switch, but the Interrupt Service Routine 7502 is actually performing the task switch. Although it would be possible to communicate the reason for the task switch from the Task Scheduling Unit 7505 to the Interrupt Service Routine 7502 and have the Interrupt Service Routine 7502 clear the Task Command register 7506 and adjust the context it saves for the task, this is slow in software and degrades the task switch performance of the Interrupt Service Routine 7501. 80
The unique solution to this problem is to include a special Reset Logic Unit 7504 to clear the Task Command register 7506. When the Interrupt Service Routine 7502 reads the Interrupt Status register 7503, it is known that the Task 7501 is now preempted. Reading the Interrupt Status register
7503 generates a signal that indicates to the Reset Logic Unit
7504 that the Interrupt Service Routine has taken control o f the host processor. The Reset Logic Unit determines if the preemption taking place is due to a task command (the Task Command register does not represent context) or if the preemption taking place is due to a non-task command (the Task Command is context and must be preserved) by using the Context Status Signal from the Task Scheduling Unit 7505. I f the Reset Logic Unit 7504 determines the Interrupt Status register 7503 is being read and the Task Scheduling Unit 7505 has indicated the preemption is due to a task command, then the Reset Logic Unit 7504 clears the Task Command registe r 7506. This operation has the following effects:
• If the preemption is due to a task command, when the
Interrupt Service Routine 7502 begins and reads the Interrupt Status register 7503, the Task Command register 7506 clears. The Interrupt Service Routine 7502 then saves the processor registers and the cleared Task Command register 7506. When the task context is restored, the processor registers are restored and the Task Command register 7506 i s restored. Since the Task Command register was cleared prior to saving it, restoring it effectively clears the task command. The task continues execution because it sees the task command has cleared. • If the preemption is due to a semaphore post, the Task
Command register 7506 is not cleared when the Interrupt Status register 7503 is read. The I nterrupt Service routine saves and later restores the Task Command register 7506 without changes. This allows a completely transparent preemption.
This solution allows the Task Command register 7506 to be cleared at the optimal time to ensure correct system operation and simplifies the Interrupt Service Routine 7502 because i t simply saves/restores the Task Command register 7506 as any other register in the processor context.
A unique aspect of the device incorporating the TSA i s the previously discussed method the TSA to specify and control a task switch. To determine a simplified diagram of only task switching indication, a simplified diagram is shown FIG. 40, numeral 4000. The TSA has been simplified to include only the components that are involved specifying and controlling the task switch. When the Task Scheduling Unit 7624 determines a task switch is necessary, an interrupt request is made to the Host Processor 7610 which activates the Interrupt Service Routine 7612. To make the task switch efficient, the Interrupt Service Routine 7612 must manipulate task lists representing 82
both ready tasks and tasks waiting for semaphores. This . i s illustrated in FIG. 19, numeral 1900 where the Head Nodes 1 13 for the ready task lists 117 are contiguous with the Head Nodes 114 for the Semaphore Lists 118. This allows a single integer index to access any head node in any list. These l i sts are grouped together in 7611 of FIG. 40, numeral 4000. The task that is currently executing 7613 is not linked in to any list. An efficient mechanism is required to indicate the specific details on how to manipulate the task lists 7611 and the current task 7613. The Task Scheduling Accelerator 7620 specifies and controls the task switch using three registers: the Move Current To register 7621 , the Take New From register 7622 and the Interrupt Control register 7623. The Move Current To register 7621 indicates which list to link the currently executing task into. The Save Context bit in the Interrupt Control Register 7623 determines if the Move Current To register is valid. If the Save Context bit indicates the Move Current To register is valid, the Current Task is linked into the list specified by the Move Current To register. Situations such as when a task exits would cause the Save Context bit to indicate that the Move Current To register is not valid since the Current Task object would not need to be saved. After the currently executing task has been handled, the Interrupt Service Routine 7612 needs to determine if there is another task to execute. The Interrupt Control Register Load Context bit indicates if the Take New From register 7622 is valid. I f the Take New From register is valid, the Interrupt Service 83
Routine 7612 removes the task at the head of the list specified by the Take New From register and sets this as the current task for execution. If the Load Context bit is clear, it indicates the Take New From register is invalid. The Take New From register may be invalid when the task set is idle and there are no tasks available for execution. Thus, the entire task switch can be specified and controlled using two registers specifying indexes (Move Current To 7621 and the Take New From 7622 registers) and a set of bits (Load Context and Save Context) to indicate if the registers are valid. This produces a very efficient task switch on the host processor.
A device according to the present invention accelerates scheduling of a preemptive, prioritized, multi-tasking system by balancing software and hardware components in a manner that maximizes processor efficiency. The multi-tasking system is typically implemented in an embedded processor system, a subscriber unit or a base station. This efficiency i s achieved by utilizing a highly efficient, predetermined interrupt service routine in a host processor to respond to a task scheduling accelerator which is implemented in hardware. The task scheduling accelerator processes scheduling decisions requested by commands from tasks in the host processor.
It should be understood the foregoing description of the TSA system is only illustrative of the invention. Various alternatives and modifications can be devised by those skilled in the art without departing from the current invention. One 84
such modification is the ability of the state machine t o advance its decisions incrementally as values are being written to its registers. The present invention embraces a l l such alternatives, modifications and variations falling with i n the scope of the claims.

Claims

85I claim:
1 . A multi-tasking, preemptive, priority based operating device comprising: a host processor, for processing a plurality of tasks, receiving interrupts and using a predetermined task scheduling accelerator interrupt service routine unit for responding to a task scheduling accelerator; and the task scheduling accelerator, coupled to the host processor, for accelerating real time multi-tasking decisions using scheduling decisions responsive to tasks in the host processor.
2. The multi-tasking, preemptive, priority based operating device of claim 1 wherein the task scheduling accelerator comprises: an interrupt service routine interface, coupled to the task scheduling accelerator interrupt service routine unit and a state machine of the task scheduling accelerator, for asserting an interrupt and indicating a status of the interrupt; a semaphore post queue interface, coupled to the task scheduling accelerator interrupt service routine unit and a semaphore post interface, for efficient determination of semaphore index queue status; a status unit, coupled to the state machine of the task scheduling accelerator and an asynchronous task command interface, for providing a status of an asynchronous task 86
command interface; the asynchronous task command interface, coupled to the task scheduling accelerator interrupt service routine unit and the semaphore post interface, for receiving commands from tasks and device interrupt service routines of the host processor; a synchronous task command interface, coupled to the task scheduling accelerator interrupt service routine unit, a task scheduling programming interface and to the state machine, for receiving commands from tasks of the host processor; a current execution priority storage unit, coupled to the state machine, for storing a priority of a currently executing task on the host processor; a plurality of ready task counters, coupled to the state machine, for storing counts of ready tasks at each priority level; and the state machine, coupled to the interrupt service routine interface, the semaphore post-queue interface, the status unit, the asynchronous task command interface, the synchronous task command interface, the plurality of ready task counters, and the current execution priority storage unit, for determining scheduling decisions.
3. The multi-tasking, preemptive, priority based operating device of claim 1 wherein the host processor comprises: a semaphore index queue unit, coupled to a semaphore 87
post interface, for storing pending semaphore post requests; a data structures unit, coupled to a task scheduling accelerator interrupt service routine unit, a semaphore post interface and a task scheduling programming interface, for storing a current state of multiple tasks; a task unit, for executing predetermined functions on the host processor and generating task scheduling commands; a device interrupt service routine unit, for implementing predetermined service routines for devices on the host processor and generating task scheduling commands; the task scheduling accelerator interrupt service routine unit, coupled to an interrupt service routine interface, a semaphore post queue interface, a status unit, the data structures unit and the semaphore index queue unit, for processing interrupt requests from the task scheduling accelerator; the task scheduling programming interface unit, coupled to the task unit, the data structures unit and a synchronous task command interface, responsive to tasks, for controlling the task scheduling accelerator; the semaphore post interface, coupled to the data structures unit, the device interrupt service routines unit, the semaphore post queue interface unit, the status unit and the . task unit, for controlling the task scheduling accelerator.
4. A multi-tasking, preemptive, priority based operating device comprising: 88
a host processor, for processing a plurality of tasks and receiving interrupts, for using a task scheduling accelerator interrupt service routine unit for responding to a task scheduling accelerator; and the task scheduling accelerator, coupled to the host processor by at least a data bus, an address bus and an interrupt line, for accelerating real time multi-tasking decisions using scheduling decisions responsive to tasks in the host processor wherein the task scheduling accelerator comprises: an interrupt service routine interface, coupled to the task scheduling accelerator interrupt service routine unit and a state machine of the task scheduling accelerator, for asserting an interrupt and indicating a status of the interrupt; a semaphore post queue interface, coupled to the task scheduling accelerator interrupt service routine unit and a semaphore post interface, for efficient determination of semaphore index queue status; a status unit, coupled to the state machine of the task scheduling accelerator and an asynchronous task command interface, for providing a status of the asynchronous task command interface; the asynchronous task command interface, coupled to the task scheduling accelerator interrupt service routine unit and the semaphore post interface, for receiving commands from tasks and device interrupt service routines of the host 89
processor; a synchronous task command interface, coupled to the task scheduling accelerator interrupt service routine unit, a task scheduling programming interface and to the state machine, for receiving commands from tasks of the host processor; a current execution priority storage unit, coupled to the state machine, for storing a priority of a currently executing task on the host processor; a plurality of ready task counters, coupled to the state machine, for storing counts of ready tasks at each priority level; and the state machine, coupled to the interrupt service routine interface, the semaphore post-queue interface, the status unit, the asynchronous task command interface, the synchronous task command interface, the plurality of ready task counters, and the current execution priority storage unit, for determining scheduling decisions.
5. A method for implementing a multi-tasking, preemptive, priority based operating device for operating system functions comprising the steps of: processing a plurality of tasks and received interrupts by a host processor using a predetermined task scheduling accelerator interrupt service routine to respond to a task scheduling accelerator; and 90
accelerating, by a task scheduling accelerator, real time multi-tasking decisions using scheduling decisions responsive to tasks in the host processor.
6. The method of claim 5 wherein accelerating, by the task scheduling accelerator, includes the steps of: using an interrupt service routine interface for asserting an interrupt and indicating a status of the interrupt; utilizing a semaphore post queue interface for efficient determination of semaphore index queue status; using a status unit for providing a status of a asynchronous task command interface; utilizing the asynchronous task command interface for receiving commands from tasks and device interrupt service routines of the host processor; using a synchronous task command interface for receiving commands from tasks of the host processor; utilizing a current execution priority storage unit for storing a priority of a currently executing task on the host processor; using a plurality of ready task counters for storing counts of ready tasks at each priority level; and utilizing a state machine for determining scheduling decisions.
7. An article of manufacture having a multi-tasking, 91
preemptive, priority based operating processing device wherein the device comprises: a host processor, for processing a plurality of tasks, receiving interrupts and using a task scheduling accelerator interrupt service routine unit for responding to a task scheduling accelerator; and the task scheduling accelerator, coupled to the host processor, for accelerating real time multi-tasking decisions using scheduling decisions responsive to tasks in the host processor.
8. A device for transfer of data items between a host processor and an external device comprising: the host processor, coupled to external queue pointers, for queuing a plurality of data items and transferring the plurality of data items to the external device using an interrupt service routine unit, and the external device, coupled to the host processor for storing and incrementing/decrementing the external queue pointers, and processing the data items.
9. The device of claim 8 wherein the external device further comprises: a data register unit, coupled to the interrupt service routine unit and a data register interface, for storing at least one data item of the plurality of data items, a data processing unit, coupled to the data register unit, 92
for processing the at least one data item stored in the data register unit, a status unit, coupled to the data register unit, for storing a data register status flag, an interrupt request unit, coupled to the status unit and a queue pointer unit, for asserting an interrupt, and the queue pointer unit, coupled to the interrupt service routine unit and the data register interface, for storing queue head and queue tail pointers and determining a queue status.
1 0. The device of claim 1 wherein the host processor comprises: an algorithm unit for processing functions on the host processor, a data register interface, coupled to the algorithm unit, a queue pointer unit and a status unit, for writing selected data items to a data queue unit and writing other selected data items to a data register unit, the data queue unit, coupled to the data register interface, for storing a plurality of the selected data items, and the interrupt service routine unit, coupled to the data queue unit, the queue pointer unit and an interrupt request unit, for transferring the selected data items from the data queue unit to the data register unit.
1 1 . A method for transfer of data items between a 93
host processor and an external device comprising using a host processor, coupled to external queue pointers, for queuing a plurality of data items and transferring the plurality of data items to the external device using an interrupt service routine unit, and using the external device, coupled to the host processor for storing and manipulating the external queue pointers, and processing the data items.
12. The method of claim 11 further including: using a data register unit, coupled to the interrupt service routine unit and a data register interface, for storing at least one data item of the plurality of data items, using a data processing unit, coupled to the data register unit for processing the at least one data item stored in the data register unit, using a status unit, coupled to the data register unit, for storing a data register status flag, using an interrupt request unit, coupled to the status unit and a queue pointer unit, for asserting an interrupt, and using the queue pointer unit, coupled to the interrupt service routine unit and the data register interface, for storing queue head and queue tail pointers and determining a queue status.
1 3. The method of claim 1 1 further including: using a queue max unit for storing a predetermined 94
threshold, using a queue head unit, coupled to a head compare unit and an interrupt service routine unit, for storing an integer value representing the offset to a head of a queue, using a queue tail unit, coupled to a tail compare unit and data register interface, for storing an integer value representing the offset to a tail of a queue, using the head compare unit, coupled to the queue max unit and the queue head unit, for determining if a queue head unit value has reached a first predetermined value and setting the queue head unit value to a second predetermined value if the first predetermined value is reached, using the tail compare unit, coupled to the queue max unit and the queue tail unit, for determining if a queue tail unit value has reached a first predetermined value and setting the queue tail unit value to a second predetermined value if the first predetermined value is reached, and using an empty compare unit, coupled to the queue head unit and queue tail unit, for determining if a queue status is software queue empty when the queue head unit value is equal to the queue tail unit value and the queue status is software queue data available when the queue head unit value is unequal to the queue tail unit value.
14. A task scheduling accelerator device for determining and controlling multi-tasking, comprising: a synchronous task command interface, coupled to a host 95
processor, an interrupt service routine interface and a bus, for receiving commands from tasks on the host processor; an asynchronous task command interface, coupled to the host processor and the bus, for receiving commands from tasks and interrupt service routines on the host processor; an interrupt service routine interface, coupled to the host processor, a status register and the bus, for specifying and controlling a task switch; a semaphore post queue interface, coupled to the host processor, for specifying and determining, to a computational unit, a status of a data queue stored in the host processor; the status register, coupled to the host processor and the bus, for specifying a status of the task scheduling accelerator device; the computational unit, coupled to the bus, the status register, the synchronous task command interface and the semaphore post queue interface for computing task scheduling decisions; and a bus, coupled to the synchronous task command interface, the asynchronous task command interface, the interrupt service routine interface, the status register and the computational unit, for moving data between registers/ interfaces and the computational unit.
15. The task scheduling accelerator device of claim 14 wherein the synchronous task command interface comprises: a parameter register, coupled to the host processor, a 96
modify, priority register, an add task register, a semaphore pend index register and the bus, for storing synchronous task command values; the modify priority register, coupled to the host processor, for receiving a new task priority from the host processor and setting a modify priority status flag in a task command register; the add task register, coupled to the host processor, for receiving a priority of a new task from the host processor and setting an add task status flag in the task command registe r; a semaphore pend count register, coupled to the host processor for receiving a count of a semaphore; the semaphore pend index register, coupled to a host processor, for receiving an index of the semaphore and setting a semaphore pend status flag in the task command register; and, the task command register, coupled to the host processor, the modify priority register, the add task register, the semaphore pend index register, a reset logic unit and the bus, for storing flags indicating task commands consisting of add task, modify priority, semaphore pend, task exit and task yield.
16. An article of manufacture having a task scheduling accelerator device for determining and controlling multitasking, the task scheduling accelerator device comprising: 97
a plurality of interfaces, each coupled to a host processor and a bus, wherein each interface executes at least one of: receiving commands from tasks on the host processor; receiving commands from tasks and interrupt service routines on the host processor; and specifying and controlling a task switch; a semiphore post queue interface, coupled to the host processor, for specifying and determining a status of a data queue stored in the host processor; a status register, coupled to the host processor and the bus, the interface for receiving commands from tasks and interrupt service routines on the host processor, and the bus, for specifying a status of the task scheduling accelerator device; a computational unit, coupled to the bus, the status register, the interface for receiving commands from tasks on the host processor, and the interface for specifying and determining a status of a data queue stored in the host processor, wherein the computational unit computes task scheduling decisions; and wherein the bus is utilized for moving data between registers/interfaces and the computational unit.
PCT/US1999/005112 1998-03-10 1999-03-09 Apparatus, method and article of manufacture for use with a priority based real-time operating system WO1999046679A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
AU29924/99A AU2992499A (en) 1998-03-10 1999-03-09 Apparatus, method and article of manufacture for use with a priority based real-time operating system

Applications Claiming Priority (6)

Application Number Priority Date Filing Date Title
US09/037,692 1998-03-10
US09/041,101 1998-03-10
US09/037,173 1998-03-10
US09/037,692 US6128672A (en) 1998-03-10 1998-03-10 Data transfer using software interrupt service routine between host processor and external device with queue of host processor and hardware queue pointers on external device
US09/037,173 US6430593B1 (en) 1998-03-10 1998-03-10 Method, device and article of manufacture for efficient task scheduling in a multi-tasking preemptive priority-based real-time operating system
US09/041,101 US6360243B1 (en) 1998-03-10 1998-03-10 Method, device and article of manufacture for implementing a real-time task scheduling accelerator

Publications (1)

Publication Number Publication Date
WO1999046679A1 true WO1999046679A1 (en) 1999-09-16

Family

ID=27365161

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/US1999/005112 WO1999046679A1 (en) 1998-03-10 1999-03-09 Apparatus, method and article of manufacture for use with a priority based real-time operating system

Country Status (2)

Country Link
AU (1) AU2992499A (en)
WO (1) WO1999046679A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7444635B2 (en) 2002-06-20 2008-10-28 Nokia Corporation Multi-task system for controlling execution of application sessions and reservation of resources
CN102063336A (en) * 2011-01-12 2011-05-18 国网电力科学研究院 Distributed computing multiple application function asynchronous concurrent scheduling method
CN112749006A (en) * 2019-10-31 2021-05-04 爱思开海力士有限公司 Data storage device and operation method thereof

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP0403229A1 (en) * 1989-06-13 1990-12-19 Digital Equipment Corporation Method and apparatus for scheduling tasks in repeated iterations in a digital data processing system having multiple processors
EP0551191A1 (en) * 1992-01-09 1993-07-14 Digital Equipment Corporation Apparatus and method for transferring data to and from host system
EP0602769A2 (en) * 1992-12-18 1994-06-22 Fujitsu Limited A multiprocessor system
US5379428A (en) * 1993-02-01 1995-01-03 Belobox Systems, Inc. Hardware process scheduler and processor interrupter for parallel processing computer systems

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP0403229A1 (en) * 1989-06-13 1990-12-19 Digital Equipment Corporation Method and apparatus for scheduling tasks in repeated iterations in a digital data processing system having multiple processors
EP0551191A1 (en) * 1992-01-09 1993-07-14 Digital Equipment Corporation Apparatus and method for transferring data to and from host system
EP0602769A2 (en) * 1992-12-18 1994-06-22 Fujitsu Limited A multiprocessor system
US5379428A (en) * 1993-02-01 1995-01-03 Belobox Systems, Inc. Hardware process scheduler and processor interrupter for parallel processing computer systems

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
COOLING J E ET AL: "TASK SCHEDULER CO-PROCESSOR FOR HARD REAL-TIME SYSTEMS", MICROPROCESSORS AND MICROSYSTEMS, vol. 20, no. 9, 1 May 1997 (1997-05-01), pages 553 - 566, XP000655410, ISSN: 0141-9331 *
ORTIZ D ET AL: "A preliminary performance study of architectural support for multithreading", PROCEEDINGS OF THE THIRTIETH HAWAII INTERNATIONAL CONFERENCE ON SYSTEM SCIENCES (CAT. NO.97TB100234), PROCEEDINGS OF THE THIRTIETH HAWAII INTERNATIONAL CONFERENCE ON SYSTEM SCIENCES, WAILEA, HI, USA, 7-10 JAN. 1997, 1997, Los Alamitos, CA, USA, IEEE Comput. Soc. Press, USA, pages 227 - 233 vol.1, XP002109960, ISBN: 0-8186-7743-0 *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7444635B2 (en) 2002-06-20 2008-10-28 Nokia Corporation Multi-task system for controlling execution of application sessions and reservation of resources
CN102063336A (en) * 2011-01-12 2011-05-18 国网电力科学研究院 Distributed computing multiple application function asynchronous concurrent scheduling method
CN102063336B (en) * 2011-01-12 2013-02-27 国网电力科学研究院 Distributed computing multiple application function asynchronous concurrent scheduling method
CN112749006A (en) * 2019-10-31 2021-05-04 爱思开海力士有限公司 Data storage device and operation method thereof
CN112749006B (en) * 2019-10-31 2024-04-16 爱思开海力士有限公司 Data storage device and method of operating the same

Also Published As

Publication number Publication date
AU2992499A (en) 1999-09-27

Similar Documents

Publication Publication Date Title
US6430593B1 (en) Method, device and article of manufacture for efficient task scheduling in a multi-tasking preemptive priority-based real-time operating system
US6360243B1 (en) Method, device and article of manufacture for implementing a real-time task scheduling accelerator
US6128672A (en) Data transfer using software interrupt service routine between host processor and external device with queue of host processor and hardware queue pointers on external device
JP4693326B2 (en) System and method for multi-threading instruction level using zero-time context switch in embedded processor
US7120783B2 (en) System and method for reading and writing a thread state in a multithreaded central processing unit
US7802255B2 (en) Thread execution scheduler for multi-processing system and method
US5291614A (en) Real-time, concurrent, multifunction digital signal processor subsystem for personal computers
US8566828B2 (en) Accelerator for multi-processing system and method
US7412590B2 (en) Information processing apparatus and context switching method
US20050015768A1 (en) System and method for providing hardware-assisted task scheduling
CN112416546A (en) Multitask scheduling method, electronic device and computer storage medium
US20140089936A1 (en) Multi-core device and multi-thread scheduling method thereof
JPWO2009022371A1 (en) Task processing device
US7565659B2 (en) Light weight context switching
JPH07175666A (en) Data processor and interruption request processing method for the same
WO2005048009A2 (en) Method and system for multithreaded processing using errands
WO1999046679A1 (en) Apparatus, method and article of manufacture for use with a priority based real-time operating system
US20030014558A1 (en) Batch interrupts handling device, virtual shared memory and multiple concurrent processing device
WO2004061663A2 (en) System and method for providing hardware-assisted task scheduling
Wada et al. Fast interrupt handling scheme by using interrupt wake-up mechanism
KR20040101260A (en) Method and arrangement for virtual direct memory access
JP7331768B2 (en) Real-time processor
Labrosse Operating systems
Takeyama et al. Design and implementation of the ITRON specification—an embedded industrial realtime OS
CN116360941A (en) Multi-core DSP-oriented parallel computing resource organization scheduling method and system

Legal Events

Date Code Title Description
AK Designated states

Kind code of ref document: A1

Designated state(s): AL AM AT AU AZ BA BB BG BR BY CA CH CN CU CZ DE DK EE ES FI GB GE GH GM HR HU ID IL IN IS JP KE KG KP KR KZ LC LK LR LS LT LU LV MD MG MK MN MW MX NO NZ PL PT RO RU SD SE SG SI SK SL TJ TM TR TT UA UG UZ VN YU ZW

AL Designated countries for regional patents

Kind code of ref document: A1

Designated state(s): GH GM KE LS MW SD SL SZ UG ZW AM AZ BY KG KZ MD RU TJ TM AT BE CH CY DE DK ES FI FR GB GR IE IT LU MC NL PT SE BF BJ CF CG CI CM GA GN GW ML MR NE SN TD TG

121 Ep: the epo has been informed by wipo that ep was designated in this application
DFPE Request for preliminary examination filed prior to expiration of 19th month from priority date (pct application filed before 20040101)
REG Reference to national code

Ref country code: DE

Ref legal event code: 8642

122 Ep: pct application non-entry in european phase