Abstract:
A method, system and apparatus for integrating a system task scheduler with a workload manager are provided. The scheduler is used to assign default priorities to threads and to place the threads into run queues and the workload manager is used to implement policies set by a system administrator. One of the policies may be to have different classes of threads get different percentages of a system&#39;s CPU time. This policy can be reliably achieved if threads from a plurality of classes are spread as uniformly as possible among the run queues. To do so, the threads are organized in classes. Each class is associated with a priority as per a use-policy. This priority is used to modify the scheduling priority assigned to each thread in the class as well as to determine in which band or range of priority the threads fall. Then periodically, it is determined whether the number of threads in a band in a run queue exceeds the number of threads in the band in another run queue by more than a pre-determined number. If so, the system is deemed to be load-imbalanced. If not, the system is load-balanced by moving one thread in the band from the run queue with the greater number of threads to the run queue with the lower number of threads.

Description:
BACKGROUND OF THE INVENTION  
         [0001]    1. Technical Field  
           [0002]    The present invention is directed to resource allocations in a computer system. More specifically, the present invention is directed to a method and apparatus of load balancing resources of a computer system in accordance with certain constraints or use-policies set by a system administrator.  
           [0003]    2. Description of Related Art  
           [0004]    At any given processing time, there may be a multiplicity of user processes or threads waiting to be executed on a processor or CPU of a computing system. To best utilize the CPU of the system then, it is necessary that an efficient mechanism that properly queues the processes or threads for execution be used. The mechanism used by most computer systems to accomplish this task is a scheduler.  
           [0005]    Note that a process is a program. When a program is executing, it is loosely referred to as a task. In most operating systems, there is a one-to-one relationship between a task and a program. However, some operating systems allow a program to be divided into multiple tasks or threads. Such systems are called multithreaded operating systems. For the purpose of simplicity, threads and processes will henceforth be used interchangeably.  
           [0006]    A scheduler is a software program that coordinates the use of a computer system&#39;s shared resources (e.g., a CPU). The scheduler usually uses an algorithm such as a first-in, first-out (i.e., FIFO), round robin or last-in, first-out (LIFO), a priority queue, a tree etc. algorithm or a combination of a plurality of algorithms in doing so. Basically, if a computer system has three CPUs (CPU 1 , CPU 2  and CPU 3 ), each CPU will accordingly have a ready-to-be-processed queue or run queue. If the algorithm in use to assign processes to the run queue is the round robin algorithm and if the last process created was assigned to the queue associated with CPU 2 , then the next process created will be assigned to the queue of CPU 3 . The next created process will then be assigned to the queue associated with CPU 1  and so on. Thus, schedulers are designed to give each process a fair share of a computer system&#39;s resources.  
           [0007]    Sometimes a system administrator may want different processes to receive a different share of a resource. In that case, a workload manager (WLM) is used in conjunction with the scheduler. The WLM assigns a number representing a percentage of time a process may use a resource of a computer system to each process. Each time a process uses the resource, its assigned number is reduced. This scheme allows processes that have a lower assigned number to nonetheless use the resource.  
           [0008]    In some instances, this concept is applied to classes of processes. A class of processes, in this case, may be a group of processes that belongs to a particular group of users. Thus, just as in the case where a process is assigned a number, when processes of a class are using the resource, the number assigned to the class is reduced. Again, this scheme is used to ascertain that processes in classes with a lower assigned number do have opportunities to use the resource.  
           [0009]    The problem, however, is that at times a two-processor system with, for instance, two classes of processes each having a different assigned number may end up with one processor with one class of processes in its queue while the other processor with the other class of processes in its queue. When this occurs, the two processors of the computer system may not be used as efficiently as they could be or as a system administrator may have intended them to be. Specifically, processes in one run queue will receive more processing time than they are allowed to.  
           [0010]    Thus, what is needed is a system, apparatus and method of ascertaining that each queue of a system always contains a mixture of classes of processes, each one having a different assigned number, in order to ensure that processor use-policies established by a system administrator are adhered to.  
         SUMMARY OF THE INVENTION  
         [0011]    The present invention provides a method, system and apparatus for integrating a system task scheduler with a workload manager. The scheduler is used to assign default priorities to threads and to place the threads into run queues and the workload manager is used to implement policies set by a system administrator. One of the policies may be to have different classes of threads get different percentages of a system&#39;s CPU time. This policy can be reliably achieved if threads from a plurality of classes are spread as uniformly as possible among the run queues.  
           [0012]    In a particular embodiment, the threads are organized in classes, each class being made up of a group of related threads. Each class is associated with a priority as per a use-policy. This priority is used to modify the scheduling priority assigned to each thread in the class. Depending on the value of the class priority, the class, and therefore each thread in the class, may fall into one of a plurality of bands or ranges of priority. Periodically, the invention determines whether the number of threads in a band in a run queue exceeds the number of threads in the band in another run queue by more than a pre-determined number. If so, the system is deemed to be load-imbalanced. The invention then attempts to load-balance the system by moving one thread in the band from the run queue with the greater number of threads to the run queue with the lower number of threads. If the system is load balanced at the highest priority band, the invention will check to see whether the system is load-balanced at the next highest priority band and so on.  
       
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS  
       [0013]    The novel features believed characteristic of the invention are set forth in the appended claims. The invention itself, however, as well as a preferred mode of use, further objectives and advantages thereof, will best be understood by reference to the following detailed description of an illustrative embodiment when read in conjunction with the accompanying drawings, wherein:  
         [0014]    [0014]FIG. 1 is an exemplary block diagram illustrating a distributed data processing system according to the present invention.  
         [0015]    [0015]FIG. 2 is an exemplary block diagram of a server apparatus according to the present invention.  
         [0016]    [0016]FIG. 3 is an exemplary block diagram of a client apparatus according to the present invention.  
         [0017]    [0017]FIG. 4 illustrates a resource-use-policy that may be devised by a system administrator.  
         [0018]    [0018]FIG. 5 illustrates how a class priority affects a thread in a run queue.  
         [0019]    [0019]FIG. 6 illustrates run queues of a computer system share by three different groups of users.  
         [0020]    [0020]FIG. 7 is a flow chart of a software program that may be used to implement the invention.  
     
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT  
       [0021]    With reference now to the figures, FIG. 1 depicts a pictorial representation of a network of data processing systems in which the present invention may be implemented. Network data processing system  100  is a network of computers in which the present invention may be implemented. Network data processing system  100  contains a network  102 , which is the medium used to provide communications links between various devices and computers connected together within network data processing system  100 . Network  102  may include connections, such as wire, wireless communication links, or fiber optic cables.  
         [0022]    In the depicted example, server  104  is connected to network  102  along with storage unit  106 . In addition, clients  108 ,  110 , and  112  are connected to network  102 . These clients  108 ,  110 , and  112  may be, for example, personal computers or network computers. In the depicted example, server  104  provides data, such as boot files, operating system images, and applications to clients  108 ,  110  and  112 . Clients  108 ,  110  and  112  are clients to server  104 . Network data processing system  100  may include additional servers, clients, and other devices not shown. In the depicted example, network data processing system  100  is the Internet with network  102  representing a worldwide collection of networks and gateways that use the TCP/IP suite of protocols to communicate with one another. At the heart of the Internet is a backbone of high-speed data communication lines between major nodes or host computers, consisting of thousands of commercial, government, educational and other computer systems that route data and messages. Of course, network data processing system  100  also may be implemented as a number of different types of networks, such as for example, an intranet, a local area network (LAN), or a wide area network (WAN). FIG. 1 is intended as an example, and not as an architectural limitation for the present invention.  
         [0023]    Referring to FIG. 2, a block diagram of a data processing system that may be implemented as a server, such as server  104  in FIG. 1, is depicted in accordance with a preferred embodiment of the present invention. Data processing system  200  may be a symmetric multiprocessor (SMP) system including a plurality of processors  202  and  204  connected to system bus  206 . Alternatively, a single processor system may be employed. Also connected to system bus  206  is memory controller/cache  208 , which provides an interface to local memory  209 . I/O bus bridge  210  is connected to system bus  206  and provides an interface to I/O bus  212 . Memory controller/cache  208  and I/O bus bridge  210  may be integrated as depicted.  
         [0024]    Peripheral component interconnect (PCI) bus bridge  214  connected to I/O bus  212  provides an interface to PCI local bus  216 . A number of modems may be connected to PCI local bus  216 . Typical PCI bus implementations will support four PCI expansion slots or add-in connectors. Communications links to network computers  108 ,  110  and  112  in FIG. 1 may be provided through modem  218  and network adapter  220  connected to PCI local bus  216  through add-in boards. Additional PCI bus bridges  222  and  224  provide interfaces for additional PCI local buses  226  and  228 , from which additional modems or network adapters may be supported. In this manner, data processing system  200  allows connections to multiple network computers. A memory-mapped graphics adapter  230  and hard disk  232  may also be connected to I/O bus  212  as depicted, either directly or indirectly.  
         [0025]    Those of ordinary skill in the art will appreciate that the hardware depicted in FIG. 2 may vary. For example, other peripheral devices, such as optical disk drives and the like, also may be used in addition to or in place of the hardware depicted. The depicted example is not meant to imply architectural limitations with respect to the present invention.  
         [0026]    The data processing system depicted in FIG. 2 may be, for example, an IBM e-Server pSeries system, a product of International Business Machines Corporation in Armonk, N.Y., running the Advanced Interactive Executive (AIX) operating system or LINUX operating system.  
         [0027]    With reference now to FIG. 3, a block diagram illustrating a data processing system is depicted in which the present invention may be implemented. Data processing system  300  is an example of a client computer. Data processing system  300  employs a peripheral component interconnect (PCI) local bus architecture. Although the depicted example employs a PCI bus, other bus architectures such as Accelerated Graphics Port (AGP) and Industry Standard Architecture (ISA) may be used. Processor  302  and main memory  304  are connected to PCI local bus  306  through PCI bridge  308 . PCI bridge  308  also may include an integrated memory controller and cache memory for processor  302 . Additional connections to PCI local bus  306  may be made through direct component interconnection or through add-in boards. In the depicted example, local area network (LAN) adapter  310 , SCSI host bus adapter  312 , and expansion bus interface  314  are connected to PCI local bus  306  by direct component connection. In contrast, audio adapter  316 , graphics adapter  318 , and audio/video adapter  319  are connected to PCI local bus  306  by add-in boards inserted into expansion slots. Expansion bus interface  314  provides a connection for a keyboard and mouse adapter  320 , modem  322 , and additional memory  324 . Small computer system interface (SCSI) host bus adapter  312  provides a connection for hard disk drive  326 , tape drive  328 , and CD-ROM drive  330 . Typical PCI local bus implementations will support three or four PCI expansion slots or add-in connectors.  
         [0028]    An operating system runs on processor  302  and is used to coordinate and provide control of various components within data processing system  300  in FIG. 3. The operating system may be a commercially available operating system, such as Windows 2000, which is available from Microsoft Corporation. An object oriented programming system such as Java may run in conjunction with the operating system and provide calls to the operating system from Java programs or applications executing on data processing system  300 . “Java” is a trademark of Sun Microsystems, Inc. Instructions for the operating system, the object-oriented operating system, and applications or programs are located on storage devices, such as hard disk drive  326 , and may be loaded into main memory  304  for execution by processor  302 .  
         [0029]    Those of ordinary skill in the art will appreciate that the hardware in FIG. 3 may vary depending on the implementation. Other internal hardware or peripheral devices, such as flash ROM (or equivalent nonvolatile memory) or optical disk drives and the like, may be used in addition to or in place of the hardware depicted in FIG. 3. Also, the processes of the present invention may be applied to a multiprocessor data processing system.  
         [0030]    As another example, data processing system  300  may be a stand-alone system configured to be bootable without relying on some type of network communication interface, whether or not data processing system  300  comprises some type of network communication interface. As a further example, data processing system  300  may be a Personal Digital Assistant (PDA) device, which is configured with ROM and/or flash ROM in order to provide non-volatile memory for storing operating system files and/or user-generated data.  
         [0031]    The depicted example in FIG. 3 and above-described examples are not meant to imply architectural limitations. For example, data processing system  300  may also be a notebook computer or hand held computer in addition to taking the form of a PDA. Data processing system  300  also may be a kiosk or a Web appliance.  
         [0032]    The present invention provides an apparatus, system and method of ascertaining that each run queue of a multiprocessor system contains processes of different classes of threads, each class having a different priority number, thus ascertaining that established use-policies are complied with. The invention may be local to client systems  108 ,  110  and  112  of FIG. 1 or to the server  104  or to both the server  104  and clients  108 ,  110  and  112 . Consequently, the present invention may reside on any data storage medium (i.e., floppy disk, compact disk, hard disk, ROM, RAM, etc.) used by a computer system.  
         [0033]    [0033]FIG. 4 illustrates a resource-use-policy that may be devised by a system administrator. As shown in FIG. 4A, the resource-use-policy is developed for a computer system (e.g., a server) that is to be shared by three departments at a University (i.e., the Physics, Chemistry and Math Departments). According to the policy, users  400  of the Physics Department  400  are to receive 60% of the computer system&#39;s CPU time, users  412  of the Chemistry Department  410  are to receive 40% of the computer system&#39;s CPU time and users  422  of the Math Department are to receive 10%. To distinguish each group of threads from another, they are tagged as being classes. Specifically, threads belonging to users of the Physics Department are tagged as being in class A, those belonging to the users of the Chemistry Department in class B and those belonging to the users of the Math Department in class C.  
         [0034]    An adjunct to the resource-use-policy is a band distribution policy. This distribution policy is depicted in FIG. 4B. There, two bands are displayed, band 1  and band 2 . This distribution policy categorizes all classes that have a priority between 0-14 as being in band 1  and all classes whose priority falls within 15-30 in band 2 Thus, a freshly created thread belonging to a user from the Math Department will fall into band 1 , whereas one belonging to a user from either the Physics or the Chemistry Department will fall into band 2 .  
         [0035]    As in the prior art, each generated thread has a default priority. This default priority is the same for all threads. However, when the thread is placed in the run queue, its priority is adjusted in accordance with its class. For example, 30 will be added to the default priority of a class A thread. Likewise, 20 will be added to the default priority of a class B thread and 10 will be added to the default priority of a class C thread. Thus, the total priority of a thread in a run queue is: P Total =P Default +P class .  
         [0036]    [0036]FIG. 5 illustrates how a class priority affects a thread in a run queue. In FIG. 5, a priority space  500  of a processor is divided into priority numbers 0, 10, 20 and 30. A class A thread  520 , a class B thread  540  and a class C thread  560  are also displayed. P Default  of a thread is given a value of zero (0). Thus, all the threads start at the same priority level of zero (0). A priority delta ΔA  530  of 30 is added to the class A thread, a priority delta ΔB  550  of 20 is added to the class B thread and a priority delta ΔC  570  of 10 is added to the class C thread. Thus, the processor will favor a class A thread over a class B thread. Likewise, the processor will favor a class B thread over a class C thread.  
         [0037]    In the prior art, as a thread is being processed, its priority is also being reduced. This scheme allows all threads in a run queue to fairly compete for the processor&#39;s attention. The same scheme is also used in the present invention. That is, as a thread is being processed its P Default  will be reduced. This allows threads within a class to fairly compete with each other. In addition, as a class of threads is being processed, the class priority will likewise be reduced. For example, since class A threads have higher class priority than class B threads and class C threads, class A threads will be processed before the other two. But, as the class A threads are being processed, the class A priority of 30 will be reduced until it reaches 20 or below. At that point, both class A and class B threads will be processed. The priority of both classes will be reduced until it reaches 10 or below at which time the threads in all three classes will be processed.  
         [0038]    As the class priority is being reduced, the class may go from one band to another. Thus, the class priority may be regarded as being very fluent. The priority decreases when the threads of the class are being processed and increases when the threads are not being processed as much as indicated in the use-policy.  
         [0039]    [0039]FIG. 6 illustrates run queues of a shared computer system. It is assumed that the computer system has two CPUs and two run queues, each run queue being associated with a CPU (i.e., CPU 0    600  and CPU 1    650 ). It is also assumed that the priority delta of each class is already added to the threads. Three classes of threads are present in the system. Specifically, the run queue associated with CPU 0    600  contains threads from both class A  610  and class B  620 . The run queue associated with CPU 1  contains threads from class C  630 .  
         [0040]    In operation, when a thread is created, the workload manager determines the class of the thread based on the user to whom it belongs and the scheduler places the thread into a run queue using a placement algorithm (e.g., round robin). As threads are processed out of the run queues and new threads are placed into the run queues, there may be instances when the threads are distributed into the system as shown in FIG. 6.  
         [0041]    The distribution of the threads in FIG. 6 is not ideal as the use-policy (see FIG. 4A) set by the system administrator, will not be adhered to. For example, since the Class C threads are the only threads in the run queue associated with CPU 1    650 , they will receive 50% of the processing time of the system. Clearly, this is quite above the 10% that they are allowed to receive. One method of ensuring that they do not receive any more processing time than they are allowed is to have another class of threads in the run queue. This then will promote competition between the two classes of threads. Indeed, the ideal distribution of threads is to have each run queue contain threads from all three different classes.  
         [0042]    One method of ensuring that established use-policies are being adhered to is to periodically check each run queue to determine whether there are at least two different classes of threads therein (i.e., a higher and a lower priority class). If not, then a thread of a different class, with a higher class priority than the one presently in there, should be placed into the run queue. Furthermore, if despite having these two different classes of threads in the run queue, either one or both classes of threads are still receiving more processing time than allowed to, then a thread from a different class having yet a higher class priority needs to be placed into the run queue.  
         [0043]    To check all the threads in the run queues to determine whether they each contain at least two different classes of threads is time-consuming and CPU-intensive. Consequently every 0.1 second, the invention checks a portion of the threads to see whether they are well distributed throughout the run queues. The invention uses the band concept introduced earlier (see FIG. 4B) to determine which portion of the threads to investigate. Specifically, the invention defines a well-balanced system as a system that contains an equal number of threads in a particular band in each run queue. If two class A threads, two class B threads and two class C threads are in the run queue of each of the two processors (see FIG. 6B), the system will be balanced. The system will be balanced because there will be four threads in band 2  and two threads in band 1  in both run queues.  
         [0044]    If the system is not balanced (i.e., if one run queue has more threads in a particular band than the other run queue), threads will be moved from the run queue with the greater number of threads to the one with the lower number of threads in the band. It should be noted that the system is very dynamic. That is at any one time, a thread may be being placed into a run queue while one or more threads may be being processed out of run queues while a class or classes may be moving from one band into another etc. Thus, because of this dynamism, the invention only handles one band at a time and only one thread is moved from one run queue into another when the system is not balanced.  
         [0045]    Returning to FIG. 6A, when the invention checks band 2 , it will find eight (8) threads in that band, but all of them are in the run queue associated with CPU 0    610 . Hence, the system will be determined to be imbalanced. Consequently, a thread will be moved from the run queue associated with CPU 0  to the run queue associated with CPU 1  and the process will end.  
         [0046]    In this case, it will not really matter whether the thread moved is a class A or class B thread as both classes are in band 2 . If the system were balanced and in the process all the class B threads were moved from the run queue associated with CPU 0  to the one associated with CPU 1 , then the class B threads might start getting a lot of processing time (since their class priority is higher than the class C threads). When that happens, their class priority would start being reduced. If it is reduced enough to where their class priority now falls into band 1 , the system would again become imbalanced. At that point, class A threads would be moved from one run queue to another to rebalance the system.  
         [0047]    After balancing band 2 , band 1  will be scrutinized. In this case, the system would be found to be imbalanced since all the class C threads, (note that class C is the only class in band 1 ) are in the run queue associated with CPU 1 . Consequently, class C threads will be moved one at a time until both run queues contain an equal number of class C threads.  
         [0048]    In our example, an ideal thread distribution is that shown in FIG. 6B. In FIG. 6B, each run queue contains an equal number of threads from each class. Thus, assuming that threads are not being placed into the run queues nor are being processed out of the run queues, the system will always remain balanced. If a class moves from one band to another, all the threads in that class will make that migration. Hence, the system will continue to remain balanced.  
         [0049]    [0049]FIG. 7 is a flow chart of a software program that may be used in implementing the invention. The software program starts when the computer system is turned on or is reset (step  700 ). The program monitors the number of threads in each class in each run queue. The program does so by sampling the run queues 100 times per second to obtain an average number of threads in each class in each run queue. Then every 0.1 second, the process uses the thread classes to determine whether the number of threads in the highest band (e.g., band 2 ) of one run queue is on the average greater than the number of threads in the same band (i.e. band 2 ) of the other run queue by more than 1.5 threads. If so, the system is deemed to be imbalanced. The process will try to balance the system by moving a thread from the run queue with the highest number of threads in the band to the run queue with the lowest number of threads.  
         [0050]    As mentioned before, because the system is very dynamic, the process will not ensure that the system is indeed balanced (i.e., the process will not make sure that an equal number of threads exists in the band in each run queue). Furthermore, because it is time-consuming and CPU-intensive to ensure that the system is balanced in the point of view of all the bands, the process will end there.  
         [0051]    Thus, the process always starts with the highest band. If the highest band is not balanced, the process will attempt to balance the band and end there. If the highest band is balanced, the process will then investigate the next highest band. Each band will be investigated, going from the highest to the lowest, until the number of threads in one run queue is higher by more than 1.5 threads than the number of threads of another run queue. When that occurs, a thread will be moved from the run queue with the highest number of threads to the run queue with the lowest number of threads and the process will end. If the number of threads in all the bands of all the run queues is equal, the process will end without moving any thread from one queue to another (steps  700 - 714 ).  
         [0052]    The description of the present invention has been presented for purposes of illustration and description, and is not intended to be exhaustive or limited to the invention in the form disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art. The embodiment was chosen and described in order to best explain the principles of the invention, the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated.