Writing Custom Selection Rules
The Scheduler uses selection rules to sequence the request queue when it removes requests from the queue (when a resource becomes available).
Selection Rule Logic
Before you create custom selection rules and write the corresponding selection functions, you should understand the logic used by the selection function. When a resource becomes available, the selection function is called. The request queues are contained in internal lists owned by the respective resource that is initially sequenced by the sequencing rule.
When the selection function is called, it reorders this list and returns the maximum number of requests to be considered in the allocation process. If the whole list is sorted, it returns the size of the list. Thus, if the number of requests returned is less than the size of the list, the sorted list for allocation may be only part of the queue of requests.
The allocation process begins by attempting to restart the operation for the first request on the sorted list for allocation that requires the number of available units or fewer. If the allocation process fails, the next request on the sorted list for the number of available units or fewer is considered. Successive requests on the sorted list for allocation are considered until the available units have been allocated or the end of the sorted list for allocation is reached. If there are available units after the last request is considered, they remain idle.
Naming the Function
Your custom selection function can have any name that is not a standard user-callable function name.
Arguments
#include "factor.h" int myrule(rp) RESRC *rp; /* pointer to the resource */
The selection function accepts as its only argument a pointer to the component you are performing the selection for, which is a resource (Type: RESRC *).
Return Value
The function returns a value (Type: int) which is the maximum number of requests to be processed.
Here is an example of a resource selection function based on minimum setup:
int slrl (RESRC *rp) /*----------------------------------------------------------------- Selection function to process a resource request list by using the minimum setup time for this resource on the first downstream setup operation for each load. Loads that have no downstream setup operation are assumed to have a setup time of zero. NOTES: * The estimate flag is set to false for jscmsu so that it will use the current conditions to find the setup time. Since the operation could be downstream, there is no guarantee that the current conditions for the resource in question will still be appropriate when the setup actually occurs. Therefore, this rule should only be used when the structure of the model guarantees that the conditions for the downstream resource will be constant till the setup occurs. ARGS: rp - pointer to resource to resequence RETURNS: number of requests in the request list -----------------------------------------------------------------*/ { RREQ *rq; JOBSTEP *jsp; int i; for ( rq = (RREQ *) csfsls(rp->rsrqls); rq != NULL; rq = (RREQ *) csnxls((CSENTITY *) rq) ) { /* Find first downstream setup operation. */ for ( jsp = rq->rrload->lojspt, i = 0; jsp != NULL && jsp->jstype != 4 && jsp->jstype != 13 && jsp-jstype != 19 && i < 1000; jsp = jsp->jspnxt, i++); /* Compute setup time (zero if no setup operation). */ if (jsp == NULL || i >= 1000) { rq->rrprio = 0.0; } else { /* Place a tag for the resource. This allows the step time to be computed properly for the downstream operation assuming that the load allocates the resource before any other load. */ dumrtag->rtrsrc = rp; cspols(rq->rrload->lorsls, (CSENTITY *) dumrtag, CSLIFO, NULL); rq->rrprio = jscmsu(0, rq->rrload, jsp); csgpls(rq->rrload->lorsls, (CSENTITY *) dumrtag); } } /*Sort list based on rankings.*/ cssols (rp->rsrqls, serqor); /*return number in list*/ return (csszls(rp->rsrqls)); }
Installing the Custom Function
To make your custom resource selection function available to the Scheduler, you must "install" it from ucini1 by calling the function sedfsl. This function has two arguments in the following order:
- The number of the selection rule for which your selection function contains custom logic.
- The address of your selection function.
For example, to install the above example rule "slrl" in rule position 39:
sedfsl (39, slrl);
If you use one of the provided "dynamic" selection rules, the system will ignore the sequencing rule and use first-in-first-out (FIFO). If you write a dynamic selection rule, you should also emulate the system and force the use of FIFO. To do this, invoke function setosq on the applicable request list.