?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Accounting and Validation: SRU calculation' ??
MODULE avm$calculate_srus;

{ PURPOSE:
{   This module contains the procedure used to periodically calculate a new
{   total SRU accumulator value for a job.
{
{ DESIGN:
{   The SRU calculation has been placed in a separate module to facilitate a
{   site defined SRU algorithm.  The source for this module should be released
{   with NOS/VE so sites have a sample SRU calculation procedure to use when
{   developing their own.

?? NEWTITLE := 'Global declarations referenced by this module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc avt$sru_calculation_interval
*copyc jmt$job_statistics
*copyc ost$status
*copyc pmt$task_cp_time
*copyc sfc$unlimited
*copyc sft$limit
*copyc sft$counter
?? POP ??
?? OLDTITLE ??
?? NEWTITLE := '[XDCL, #GATE] avp$calculate_application_srus', EJECT ??
*copyc avh$calculate_application_srus

  PROCEDURE [XDCL, #GATE] avp$calculate_application_srus
    (    cpu_time: pmt$task_cp_time;
         paging_statistics: ost$paging_statistics;
     VAR accumulated_srus: sft$counter;
     VAR status: ost$status);

{ NOTES:
{   This is the default SRU calculation formula for APPLICATION SRUS.
{     (CP time = SRUS).
{
{ DESIGN:
{   The accumulated SRUs are calculated by adding the job mode and monitor mode
{   CP time from the cpu_time record together.  CPU time is kept in micro
{   seconds and SRUs are reported in micro SRUs (e.g., in order to return a value
{   of 1 SRU, the accumulated sru parameter should be returned with a value of
{   1000000).
{
{   Unlike, avp$calculate_srus, this procedure does not calculate or alter the
{   SRU calculation interval.

    status.normal := TRUE;

{ SRUs = job mode cp time + monitor mode cp time

    accumulated_srus := cpu_time.task_time + cpu_time.monitor_time;
  PROCEND avp$calculate_application_srus;
?? OLDTITLE ??
?? NEWTITLE := '[XDCL, #GATE] avp$calculate_srus', EJECT ??
*copyc avh$calculate_srus

  PROCEDURE [XDCL, #GATE] avp$calculate_srus
    (    job_statistics: jmt$job_statistics;
         sru_limit: sft$limit;
     VAR accumulated_srus: sft$counter;
     VAR calculation_interval: avt$sru_calculation_interval;
     VAR status: ost$status);

{ NOTES:
{   This is the default SRU calculation formula (CP time = SRUS).
{
{ DESIGN:
{   The accumulated SRUs are calculated by adding the job mode and monitor mode
{   CP time from the job statistics record together.  CP time is kept in micro
{   seconds and SRUs are reported in micro SRUs (e.g., in order to return a value
{   of 1 SRU, the accumulated sru parameter should be returned with a value of
{   1000000).
{
{   The calculation interval that is returned will be the smaller of:
{
{           - maximum calculation interval
{           - One half of the remaining SRUs (the calculation interval is in
{             seconds and 1 SRU = 1 CP second) -- down to the minimum calculation
{             interval.

    VAR
      remaining_srus: sft$counter;

    status.normal := TRUE;

{ SRUs = job mode cp time + monitor mode cp time

    accumulated_srus := job_statistics.cp_time.time_spent_in_job_mode +
          job_statistics.cp_time.time_spent_in_mtr_mode;

{ Determine how many SRUs are left before the job will hit the SRU resource limit.
{ Then set the calculation interval to the smaller of the maximum calculation
{ interval or one half of the remaing SRUs (to a minimum of the smallest
{ calculation interval.
{
{ The SRU limit is kept in whole SRUs -- NOT micro SRUs.

    IF sru_limit.job_resource_limit = sfc$unlimited THEN
      remaining_srus := sfc$unlimited;
    ELSE
      remaining_srus := sru_limit.job_resource_limit - (accumulated_srus DIV 1000000);
    IFEND;

    IF (remaining_srus DIV 2) >= UPPERVALUE (calculation_interval) THEN
      calculation_interval := UPPERVALUE (calculation_interval);
    ELSEIF (remaining_srus DIV 2) <= LOWERVALUE (calculation_interval) THEN
      calculation_interval := LOWERVALUE (calculation_interval);
    ELSE
      calculation_interval := remaining_srus DIV 2;
    IFEND;

  PROCEND avp$calculate_srus;
?? OLDTITLE ??
MODEND avm$calculate_srus;
