Writing Custom Resource Allocation Rules

Resource allocation rules are used to decide which resources from a resource group the Scheduler will use when it allocates resources to a load. They are also used for reallocating resources if reallocation has been enabled for the group.
Note:  See Writing a Custom Scheduler Rule for a summary of the steps required to create custom rules. For more details about the functions described in this topic, see the Scheduling Customization Guide, available for download from our Support site.

Naming the Function

The function can have any name that is not a standard user-callable function name.

Arguments


#include "factor.h"
void myrule(gp, nu, ldp, mlist)
RESGRP    *gp;   /* pointer to resource group. */
int        nu;   /* number of units required.  */
LOAD     *ldp;   /* pointer to the load.       */
CSLIST *mlist;   /* current selection list.    */

The function must accept four arguments in the following order:

  1. A pointer to the resource group (Type: RESGRP*).
  2. An integer for the number of resources to be selected from that group for allocation (Type: int).
  3. A pointer to the load requesting to allocate from the resource group (Type: LOAD*).
  4. A list to be populated with RMTAGS of resources selected for allocation from the group (Type: CSLIST*).

Adding and Removing Group Members

Group members can be added and removed from the list of selected resources (mlist) using the system support functions seadsl and sermsl, respectively. To add group members to the list, use function seadsl as follows:


void seadsl(CSLIST *mlist, RESMEMB *rmp)

To remove group members from the list, use function sermsl as follows:


void sermsl(CSLIST *mlist, RMTAG *rmt)

Return Values

The function should return nothing (Type: void).

Here is an example of a rule to select available resource group members on the basis of least mean utilization:


void rgsr (RESGRP *gp, int nu, LOAD *ldp, CSLIST *mlist)
/*-----------------------------------------------------------------
     Function to process resource group selection code 3, select
     required number of member resources that have the least mean
     utilizations (as a fraction of capacity).
     NOTES:
     * Ties are broken by selecting the first in the order listed
       in the group.
     * This function requires that resource statistics be enabled.
       Any resource which does not have statistics enabled is
       assumed to have a utilization of zero.   Thus if all
       resource statistics are disabled, this defaults to
       rule 0.
     * This function uses seaars, which includes must complete and
       maxOT in its considerations, to determine the availability
       of each member resource.
     ARGS:
       gp    - pointer to resource group to select member from
       nu    - number of units required from selected member
       ldp   - pointer to load to which resource will be allocated
       mlist - list to hold selected RESMEMB's
     RETURNS:  void
-----------------------------------------------------------------*/
{
     int i, j, *avail;
     double min, *util;
     RESMEMB *minp, *rmp;
     /* Allocate arrays for availability and utilization.  */
     avail = (int *) malloc(sizeof(int) * csszls(gp->rgrsls));
     if ( avail == NULL )
     {
         seferr(0, "Out of Memory");
     }
     util = (double *) malloc(sizeof(double) * csszls(gp->rgrsls));
     if ( util == NULL )
     {
         seferr(0, "Out of Memory");
     }
     /* Compute availability and utilization.  */
     for ( rmp = (RESMEMB *) csfsls(gp->rgrsls), j = 0;
           rmp != NULL;
           rmp = (RESMEMB *) csnxls((CSENTITY *) rmp), j++ )
     {
         avail[j] = seaars(rmp->rmres, ldp);
         util[j] = seutrs(rmp->rmres);
     }
     /* For the required number of units */
     for ( i = csszls(mlist); i &LT nu; i++ )
     {
         /* For each resource which is available.  */
         minp = NULL;
         for ( rmp = (RESMEMB *) csfsls(gp->rgrsls), j = 0;
               rmp != NULL;
               rmp = (RESMEMB *) csnxls((CSENTITY *) rmp), j++ )
         {
             if ( (! rmp->rmres->rsselfg) && (avail[j] > 0) )
             {
               /* Save if min.  */
                 if ( (minp == NULL) || (util[j] &LT min) )
                 {
                     minp = rmp;
                     min = util[j];
                 }
             }
         }
         if ( minp == NULL )
         {
             break;
         }
         seadsl(mlist, minp);
     }
     free(avail);
     free(util);
     return;
}

Installing the Custom Function

To make your custom resource allocation function available to the Scheduler, you must "install" it from the ucini1 function by calling the function sedfgs. The function sedfgs has two arguments in the following order:

  • The number of the resource allocation rule for which your function contains custom logic.
  • The address of your resource allocation function.

For example, to install the above example rule "rgsr" in rule position 39:


sedfgs (39, rgsr);