# Patent

## Title
Credit scheduler for ordering the execution of tasks

## Abstract

A method for scheduling the execution of tasks on a processor is disclosed. The purpose of the method is in part to serve the special needs of soft real-time tasks, which are time-sensitive. A parameter Δ is an estimate of the amount of time required to execute the task. Another parameter Γ is the maximum amount of time that the task is to spend in a queue before being executed. In the illustrative embodiment, the preferred wait time Γi for a newly-arrived task Ti is expected to be met though the insertion of the newly-arrived task Ti into a position k in a queue such that position k respects the task's preferred wait time Γi in light of the expected execution times of the other tasks already in the queue.

## Background
CROSS REFERENCE TO RELATED APPLICATIONS
This application claims the benefit of U.S. provisional application No. 61/232,542, filed Aug. 10, 2009, entitled “Supporting Soft Real-Time Virtual Machines.” The concepts, but not necessarily the nomenclature, of this provisional application are hereby incorporated by reference.
Furthermore, this application claims the benefit of U.S. provisional application No. 61/254,019, filed Oct. 22, 2009, entitled “Supporting Soft Real-Time Virtual Machines.” The concepts, but not necessarily the nomenclature, of this provisional application are hereby incorporated by reference.


FIELD OF THE INVENTION
The present invention relates to data processing systems in general, and, more particularly, to credit schedulers for ordering the execution of tasks on a processor.
BACKGROUND OF THE INVENTION
When two or more operating systems operate on one piece of hardware, the processes associated with each operating system contend for the hardware that is available. Without something to mediate their access, one operating system's processes could monopolize or over-use the hardware to the detriment of the other operating system's processes. Therefore, a program sits between the operating systems and the hardware to act as a mediator. This program is commonly known as a “hypervisor.”
One of the jobs performed by the hypervisor is scheduling the order of execution of tasks associated with each operating system. This is not an easy job. Some tasks are time sensitive (e.g., tasks associated with input or output, speech processing, video processing, transmission or reception of signals, etc.) and some tasks are non-time-sensitive or are less-time-sensitive. Whatever the mix of time-sensitive and non-time-sensitive tasks, the respective operating systems are always presenting to the hypervisor tasks to be performed, and if the hypervisor does not wisely choose the order for executing those tasks, the performance of the entire system can be degraded.
The portion of a hypervisor that determines the order for executing the tasks is called a “scheduler.” Schedulers in the prior art, however, do not always choose wisely, and, therefore, the need exists for an improved scheduler.
SUMMARY OF THE INVENTION
The present invention enables the scheduling of the execution of tasks on a processor without some of the costs and disadvantages associated with schedulers in the prior art. The purpose of the present invention is in part to serve the special needs of soft real-time tasks, which are time-sensitive. In the illustrative embodiment, the scheduler analyzes the time-sensitive needs of a task that is to be queued. The scheduler inserts the task into a position in the queue based on the amount of time that the task is to spend in the queue relative to other tasks already queued.
The present invention defines a parameter Γ, which is the amount of time that a newly-arrived task is to spend in a queue before being executed. The expected execution time of the tasks already queued is one of the parameters relevant to the position that the newly-arrived task will receive in the queue. By using these parameters—and others—some embodiments of the present invention are able to schedule the execution of tasks without some of the costs and disadvantages for doing so in the prior art.
The illustrative embodiment comprises:

    
    
        receiving at a queue for execution on a processor a task Ti, wherein the task Ti, has a first estimated execution time Δi and a first preferred wait time Γi, and wherein the queue comprises at least one other task with a position j and an estimated execution time Δj; and
    
    


inserting the task Ti into the queue at a position k, wherein j≦k, such that:



  
    
      Γ
      i
    
    ≥
    
      
        ∑
        
          j
          =
          1
        
        
          k
          -
          1
        
      
      ⁢
      
        Δ
        j
      
    
  




  and




  
    
      
        Γ
        i
      
      <
      
        
          ∑
          
            j
            =
            1
          
          k
        
        ⁢
        
          Δ
          j
        
      
    
    ;
  



wherein j=1 represents the position at the head of the queue.



BRIEF DESCRIPTION OF THE DRAWINGS
FIG. 1 depicts a block diagram of the salient components of data processing system 100.
FIG. 2 depicts a flowchart of the salient steps performed by data processing system 100 in accordance with the illustrative embodiment of the present invention.
FIG. 3 depicts a flowchart of the salient sub-steps performed by data processing system 100 in performing step 201 in accordance with the illustrative embodiment.
FIG. 4 depicts a flowchart of the salient sub-steps performed by data processing system 100 in performing step 202 in accordance with the illustrative embodiment.



DETAILED DESCRIPTION
For the purposes of this specification, the term “processor” is defined as a physical computing resource that is capable of executing a task.
For the purposes of this specification, the term “task” is defined as at least one operation performed by a processor.
FIG. 1 depicts a block diagram of the salient components of data processing system 100. Data processing system 100 is a machine that comprises: receiver 101, queue 102, scheduler 103, processor 104, and transmitter 105.
Although the illustrative embodiment comprises one receiver 101 and one transmitter 105, it will be clear to those skilled in the art, after reading this disclosure, how to make and use alternative embodiments of the present invention that comprise any number of receivers (e.g., two receivers, three receivers, four receivers, etc.) and any number of transmitters (e.g., one transmitter, two transmitters, three transmitters, four transmitters, etc.).
Although the illustrative embodiment comprises one scheduler 103, it will be clear to those skilled in the art, after reading this disclosure, how to make and use alternative embodiments of the present invention that comprise any number of schedulers (e.g., one scheduler, two schedulers, three schedulers, four schedulers, etc.).
Although the illustrative embodiment comprises one queue 102, it will be clear to those skilled in the art, after reading this disclosure, how to make and use alternative embodiments of the present invention that comprise any number of queues (e.g., one queue, two queues, three queues, four queues, etc.).
Although the illustrative embodiment comprises one processor 104, it will be clear to those skilled in the art after reading this disclosure how to make and use alternative embodiments of the present invention that comprise any number of processors (e.g., one processor, two processors, three processors, four processors, etc.).
Receiver 101 is hardware that receives a temporal succession of tasks to be executed by processor 104 and provides those tasks to queue 102. It will be clear to those having ordinary skill in the art, after reading the present disclosure, that in alternative embodiments of the present invention receiver 101 can be software or a combination of software and hardware.
For purposes of the present disclosure, each task is identified by Ti wherein i is an integer that represents the relative order of arrival of the task at receiver 101 with respect to other tasks. For example, task Ti arrived at receiver 101 immediately before task Ti+1, wherein i is an integer.
In accordance with the illustrative embodiment, each task arrives at receiver 101 with an estimated execution time Δ parameter. For the purposes of this specification, the phrase “estimated execution time Δi” of a task Ti is defined as an estimate of the amount of time required to execute task Ti. In accordance with the illustrative embodiment, each task Ti received by receiver 101 is accompanied by an estimated execution time Δi parameter, but it will be clear to those skilled in the art, after reading this disclosure, how to make and use alternative embodiments of the present invention in which some or all of the tasks are not accompanied by an estimated execution time Δi parameter. In those cases, it will be clear to those skilled in the art, after reading this disclosure, how to make and use alternative embodiments of the present invention in which data processing system 100 generates the estimated execution time Δi parameter for one or more tasks.
In the illustrative embodiment of the present invention, the estimated execution time parameter Δ for a task is the actual execution time of that task during the task's previous execution cycle on processor 104. It will be clear to those having ordinary skill in the art, after reading the present disclosure, how to make and use alternative embodiments of the present invention in which the estimated execution time parameter Δ is based on an average of actual execution times recorded for previous execution cycles of the task, or in which the estimated execution time parameter Δ is based on another scheme devised by those implementing the present invention.
In accordance with the illustrative embodiment, each task Ti is either a time-sensitive task or a non-time-sensitive task. In accordance with the illustrative embodiment, each time-sensitive task arrives at receiver 101 with a preferred wait time Γi parameter. For the purposes of this specification, the phrase “preferred wait time Γi” of task Ti is defined as the maximum amount of time that the task is to spend in a queue before being executed.
It will be clear to those skilled in the art, after reading this disclosure, how to make and use receiver 101.
Queue 102 is hardware that holds each task Ti and its accompanying parameters, while the task awaits execution by processor 104. It will be clear to those having ordinary skill in the art, after reading the present disclosure, that in alternative embodiments of the present invention queue 102 can be software or a combination of software and hardware. In the illustrative embodiment, each task that is already in queue 102, has a “queue index j,” wherein j is an integer that represents the relative order in which tasks are lined up in the queue, i.e., j is the position in queue of those tasks that have already been queued. In the illustrative embodiment, processor 104 selects the task at the head of the queue to be executed next. For the purposes of this specification, the head of the queue is defined as having queue index j=1. The queue index j is to be distinguished from the relative order of arrival i.
The position into which a newly-arrived task is inserted in queue 102 is determined by the present invention. For the purposes of this specification, “position k” is defined as a position in queue 102 into which scheduler 103 inserts a newly-arrived task Ti at the time of arrival. The position k is to be distinguished from the relative order of arrival i and from the position index j of tasks that we previously queued. When a newly-arrived task Ti is inserted into queue 102, it may be positioned ahead of tasks that are already queued, thus shifting their respective queue indices j. In general:

1≦k≦j+1  (Eq. 1)

for all integer values of j≧1, wherein j=1 represents the position at the head of the queue.

For example, Table 1 depicts an illustrative example of queue 102 at time t=0:







TABLE 1







Example of Tasks in Queue 102












Estimated





Execution
Preferred


Queue Index J

Time Δi
Wait Time Γi


In Queue 102
Task Ti
(in msec)
(in msec)





1
T2
9
 5


2
T1
9
200


3
T3
5
250


. . .
. . .
. . .
. . .


43 
T43
8
225









The estimated execution time Δi, the preferred wait time Γi, and the queue index j for each task in queue 102 are provided to scheduler 103 for analysis. In the illustrative embodiment shown in Table 1 above, Task T2, having arrived after task T1, was placed in queue 102 ahead of task T1, because the preferred wait time Γ of task T2 (5 msec) is more urgent than the expected execution time Δ of Task T1 (9 msec). This method is explained in more detail in regards to FIG. 3 below.

It will be clear to those skilled in the art, after reading this disclosure, how to make and use queue 102.
Scheduler 103 is hardware and software that is capable of performing the functionality described in this disclosure and in the accompanying figures. It will be clear to those having ordinary skill in the art, after reading the present disclosure, how to make alternative embodiments of the present invention in which scheduler 103 is exclusively hardware, or exclusively software. For example, when scheduler 103 receives the estimated execution time Δi, the preferred wait time Γi for a newly arrived task at queue 102, and the queue index j for each task in queue 102, scheduler 103 analyzes the data and selects a specific position k in queue 102 into which to insert the task relative to the queue index j of those tasks already in queue 102.
In accordance with the illustrative embodiment, scheduler 103 is a “credit” scheduler, but it will be clear to those skilled in the art, after reading this disclosure, how to make and use alternative embodiments of the present invention in which scheduler 103 is not a “credit” scheduler. The XEN® hypervisor is an example of a hypervisor that comprises a credit scheduler, but it will be clear to those having ordinary skill in the art, after reading the present disclosure, that alternative embodiments of the present invention can use a different hypervisor. Furthermore, it will be clear to those skilled in the art that alternative well-known names for a hypervisor include, but are not limited to, a “virtual machine monitor” (VMM).
Processor 104 is hardware that executes tasks from queue 102 in the order determined by scheduler 103. It will be clear to those having ordinary skill in the art, after reading the present disclosure, that in alternative embodiments of the present invention processor 104 can be software or a combination of software and hardware. It will be clear to those skilled in the art how to make and use processor 104. In accordance with the illustrative embodiment of the present invention, processor 104 comprises one core, but it will be clear to those skilled in the art, after reading this disclosure, how to make and use alternative embodiments of the present invention in which processor 104 comprises multiple cores. Furthermore, it will be clear to those skilled in the art that alternative names for a processor include, but are not limited to, a “core” or “CPU.”
Transmitter 105 is hardware that transmits the results of each task execution. It will be clear to those skilled in the art how to make and use transmitter 105. It will be clear to those having ordinary skill in the art, after reading the present disclosure, that in alternative embodiments of the present invention transmitter 105 can be software or a combination of software and hardware.
FIG. 2 depicts a flowchart of the salient steps performed by data processing system 100 in accordance with the illustrative embodiment of the present invention.
At step 201, a temporal succession of tasks is received at receiver 101, analyzed by scheduler 103, and placed into queue 102. In accordance with the illustrative embodiment, each task Ti arrives at receiver 101 with an estimated execution time Δi parameter. For each task Ti that is time sensitive, a preferred wait time Γi parameter is also received. Step 201 is described in greater detail below and in the accompanying figures.
In some embodiments of the present invention, whether a task is treated as a time-sensitive task depends on whether it arrives from a time-sensitive or a non-time-sensitive “domain.” For purposes of this specification, a “domain” is defined as software that is an operating system or an application using the operating system that comprises tasks to be executed by processor 104. Because multiple domains can co-exist in processing system 101 and each domain requires execution of the tasks it comprises on processor 104, whether a domain is time sensitive affects the treatment of its constituent tasks. A voice processing application is an example of a time-sensitive domain. Thus, any task from the voice processing application would be characterized as time sensitive and treated accordingly by scheduler 103. It will be clear to those having ordinary skill in the art, after reading the present disclosure, how to make and use alternative embodiments of the present invention that use domains.
At step 202, processor 104 accesses queue 102 and executes the queued tasks. Step 202 is described in greater detail below and in the accompanying figures.
In accordance with the illustrative embodiment, steps 201 and 202 are continually-running asynchronous processes that operate independently of each other. However, it will be clear to those skilled in the art, after reading this disclosure, how to make and use alternative embodiments of the present invention in which steps 201 and 202 are not independent.
FIG. 3 depicts a flowchart of the salient sub-steps performed by data processing system 100 in performing step 201 in accordance with the illustrative embodiment.
At step 301, a task Ti arrives at receiver 101 for queuing at queue 102 in a manner well-known in the art.
At step 302, scheduler 103 computes position k for task Ti into which position k scheduler 103 will insert task Ti in accordance with the present invention.
In the illustrative embodiment, the preferred wait time Γi for a newly-arrived task Ti is expected to be met though the insertion or emplacement of the newly-arrived task Ti into a position k in queue 102 such that position k respects the task's preferred wait time Γi in light of the expected execution times of the other tasks already in queue 102.
A minimum value of k is computed for a newly-arrived task Ti such that:




  
    
      
        
          Γ
          i
        
        ≥
        
          
            ∑
            
              j
              =
              1
            
            
              k
              -
              1
            
          
          ⁢
          
            Δ
            j
          
        
      
    
    
      
        (
        
          Eq
          .
          
            
          
          ⁢
          2
        
        )
      
    
  
  
    
      and
    
    
      
        
      
    
  
  
    
      
        
          Γ
          i
        
        <
        
          
            ∑
            
              j
              =
              1
            
            k
          
          ⁢
          
            Δ
            j
          
        
      
    
    
      
        (
        
          Eq
          .
          
            
          
          ⁢
          3
        
        )
      
    
  




where j=1 represents the head of the queue, and where Δj represents the expected execution time of the task queued at position j.

At step 303, task Ti is inserted into queue 102 at position k counting from the head of the queue. The process continues indefinitely as more tasks arrive at receiver 101.
In the illustrative embodiment, a task Ti, once placed into a position in queue 102, is not re-positioned, except insofar as a subsequent task Tn, where n>i, may be placed in a position in queue 102 ahead of Ti. A newly-arrived task may receive a position ahead of other queued tasks depending on the sum of the expected execution times of the already-queued tasks as compared to the preferred wait time for the newly-arrived task.
It should be noted that in some embodiments of the present invention, the expected execution time Δi of newly-arrived task Ti is not material to the calculation of position k for task Ti. Furthermore, it will be clear to those having ordinary skill in the art, after reading the present disclosure, that the use of the preferred wait time parameter Γ is for those tasks that are time sensitive or otherwise categorized as soft-real-time tasks. Likewise, for a domain categorized as time sensitive or soft-real-time, the tasks it comprises also are treated as time-sensitive with a respective preferred execution time parameter Γ.
It will be clear to those having ordinary skill in the art, after reading the present disclosure, that in alternative embodiments of the present invention, a task Ti+1 with a preferred wait time Δi+1 will be executed on processor 104 ahead of an already queued task Ti when Γi+1<Δi, because positioning a newly-arrived task ahead of an already-queued task based on the preferred wait time of the newly-arrived task results, in the illustrative embodiment, in its being executed before an earlier-arrived task already in queue 102.
It will be clear to those having ordinary skill in the art, after reading the present disclosure, that generally, a newly-arrived task goes to the end of queue 102 by default, unless the preferred wait time parameter Γ overrules this arrangement under the conditions and circumstances described above.
It will be clear to those having ordinary skill in the art, after reading the present disclosure, how to enable step 201 of the present invention.
FIG. 4 depicts a flowchart of the salient sub-steps performed by data processing system 100 in performing step 202 in accordance with the illustrative embodiment.
At step 401, processor 104 accesses queue 102 to select the next task for execution in a manner well-known in the art.
At step 402, processor 104 selects the task at the head of the queue for execution, in accordance with the illustrative embodiment. In the illustrative embodiment, position 1 represents the head of the queue, but it will be clear to those having ordinary skill in the art, after reading the present disclosure, how to make and use alternative embodiments of the present invention in which processor 104 selects the next task from any queue such that the selection meets the criteria described above for honoring the preferred wait time Γi of task Ti. It will be clear to those having ordinary skill in the art, after reading the present disclosure, how to enable step 402.
At step 403, processor 104 executes the selected task. How to execute a queued task at a processor is well-known in the art.
It is understood that this disclosure teaches just some examples of how the tasks of processing system 100 are ordered and organized and that many different variations can be devised by those skilled in the art after reading this disclosure. The scope of the present invention is to be determined by the following claims.

## Claims

1. A method comprising:
receiving at time ti at a queue for execution on a processor a first task T1, wherein the first task T1 has a first estimated execution time Δi, and a first preferred wait time Γi, and wherein the queue comprises at least one other task with a position j and an estimated execution time Δj;
receiving at time t2 at the queue for execution on the processor a second task T2 for execution on the processor, wherein time ti is before time t2, and wherein the second task T2 has a second estimated execution time Δm and a second preferred wait time Γ2;
inserting the first task T1 into the queue at a position k, wherein j≦k, such that:




  
    
      Γ
      i
    
    ≥
    
      
        Δ
        m
      
      +
      
        
          ∑
          
            j
            =
            1
          
          
            k
            -
            1
          
        
        ⁢
        
          Δ
          j
        
      
    
  




  and




  
    
      
        Γ
        i
      
      <
      
        
          Δ
          m
        
        +
        
          
            ∑
            
              j
              =
              1
            
            k
          
          ⁢
          
            Δ
            j
          
        
      
    
    ;
  


 and
executing the second task T2 on the processor before executing the first task T1 when Γ2<Δi,
wherein j=1 represents the position at the head of the queue.

2. The method of claim 1 wherein the first task Ti is a time-sensitive task.

3. The method of claim 1 wherein the position k is independent of the first estimated execution time Δi.

4. The method of claim 1 wherein a time-sensitive domain comprises the first task T1.

5. The method of claim 1 further comprising: executing on the processor the task at the head of the queue with the position j=1.

6. The method of claim 5 wherein the first task T1 is a time-sensitive task.

7. The method of claim 6 wherein the position k is independent of the first estimated execution time Δi.

8. The method of claim 5 wherein a time-sensitive domain comprises the first task T1.

9. The method of claim 8 wherein the position k is independent of the first estimated execution time Δi.

10. The method of claim 1 wherein the second task T2 is a time-sensitive task.

11. The method of claim 10 wherein the order of execution of the first task T1 and the second task T2 is independent of the second estimated execution time Δ2.

12. The method of claim 1 wherein a time-sensitive domain comprises the second task T2.

13. The method of claim 12 wherein the order of execution of the first task T1 and the second task T2 is independent of the second estimated execution time Δ2.

14. A method comprising:
receiving at a queue for execution on a processor a first task Ti, wherein the first task Ti has a first estimated execution time Δi and a first preferred wait time Γi, and wherein the queue comprises at least one other task with a position j and an estimated execution time Δj;
inserting the first task Ti into the queue at a position k, wherein j≦k, such that:




  
    
      Γ
      i
    
    ≥
    
      
        ∑
        
          j
          =
          1
        
        
          k
          -
          1
        
      
      ⁢
      
        Δ
        j
      
    
  




  and




  
    
      
        Γ
        i
      
      <
      
        
          ∑
          
            j
            =
            1
          
          k
        
        ⁢
        
          Δ
          j
        
      
    
    ,
  


wherein j=1 represents the position at the head of the queue; and
executing the first task Ti on the processor before executing a second task Tn when Γi<Δn,
wherein the first task Ti, was received at the queue after the second task Tn, and wherein the second task Tn has a second estimated execution time Δn.

15. The method of claim 14 wherein the first task Ti, is a time-sensitive task.

16. The method of claim 15 wherein the order of execution of the first task Ti, and the second task Tn is independent of the first estimated execution time Δi.

17. The method of claim 14 wherein a time-sensitive domain comprises the first task Ti.

18. The method of claim 17 wherein the order of execution of the first task Ti, and the second task Tn is independent of the first estimated execution time Δi.