         PCC      0
BITS     SET      1
UFLAGS   SET      1
         SYSTEM   UTS
         TITLE    'S C H E D U L E R     S U B R O U T I N E S'
*P*************************************************************
*P*                                                           *
*M*           SCHDSUB - SCHEDULER SUBROUTINES                 *
*P*                                                           *
*P*      THIS MODULE CONTAINS SUBROUTINES FOR SCHED           *
*P*      WHICH DIFFER IN A MULTIPROCESSING SYSTEM             *
*P*      THE ASSEMBLY SWITCH, MP, SELECTS WHICH VERSION       *
*P*      IS CREATED.  MP=1 YIELDS THE MULTIPROCESSING         *
*P*      VERSION.                                             *
*P*                                                           *
*P*************************************************************
         SPACE    2
MP       SET      0
         SPACE    2
         DEF      SCHDSUB:          PATCHING DEF
SCHDSUB: RES
         PAGE
***************************************************************
*                       DEFS                                  *
***************************************************************
         SPACE    2
         DEF      T:MASTER          CHECK PSD FOR MASTER MODE
         DEF      T:MSTR            2NDARY ENTRY FROM SCHED
         DEF      T:SMPFLG          SET SLAVE ONLY FLAG
         DEF      T:SCREECHS        SLAVE CPU INITIATED RECOVERY
         DEF      T:ACCTEX          ACCOUNT FOR EXECUTION TIME AND GIVE NEW QUAN
         PAGE
***************************************************************
*                          REFS                               *
***************************************************************
*
*        CENTRAL SUBROUTINES
*
         REF      T:PULLE           PULL EXIT
*
*        JIT REFERENCES
*
         REF      J:JIT             BASE ADDRESS OF JIT
         REF      J:ASSIGN          MAX TIME FLAG
         REF      J:CALCNT          CAL COUNT
         REF      J:CTIME           I/O COMPENSATORY TIME
         REF      J:DELTAT          NEG TIME REMAINING IN QUAN
         REF      J:IDELTAT         INITIAL VALUE OF J:DELTAT
         REF      J:MRT             MAXIMUM RUN TIME
         REF      J:OVHTIM          USER SERVICE TIME
         REF,1    JB:PNR            PARTION NUMBER
         REF      J:PTIME           PROCESSOR TIME
         REF      J:RNST            RUN STATUS FLAGS
         REF      J:UTIME           USER EXECUTION TIME
         REF      J:UTIMER          TIME REMAINING FOR STIMER
         REF      TSTACK            JIT TEMP STACK
*
*        SYSTEM   LIMITS
*
         REF      SL:QUAN           QUANTUM (ONLINE AND FHOST)
         REF      PLH:QN            PARTITION QUANTA (BATCH)
*
*        USER TABLES
*
         SREF     U:CALC            CAL COUNT
         SREF     UB:CALR           CAL RATE FOR USER
         REF      UH:FLG            USER FLAGS
         SREF     UB:MPFLG          MULTI-PROCESSING FLAGS
         REF      UB:PCT            PAGE COUNT (SWAP SIZE)
*
*        SYSTEM AND SCHEDULER CELLS
*
         REF      S:CLOCK4          CLOCK4 COUNT DIRECTOR
         REF      S:CUN             CURRENT USER NUMBER
         REF      S:PNO             PROCESSOR NUMBER
         SREF     SB:RCVR           RECOVERY REQUEST
         SREF     SREGS1            SLAVE REGISTER SAVE AREA
         SREF     S:SSCRCH          SLAVE INVOKED SCREECH FLAG
*
*        PERFORMANCE MONITORING DATA
*
         REF      C:MSB             MONITOR SERVICE, BATCH
         REF      C:MSO             MONITOR SERVICE, ONLINE
         REF      C:SCB             COMPUTE,BATCH
         REF      C:SCO             COMPUTE, ONLINE
         REF      C:SCG             COMPUTE,GHOST
         SREF     C:SUSER           SLAVE USER COMPUTE TIME
*
*        PERFORMANCE MONITORING ROUTINES
*
         REF      PMSCA             COMPUTE ACCOUNTING
*
*        SLAVE MONITOR ENTRY POINTS
*
         SREF     T:SCRASH          PERFORM SLAVE CRASH
*
*        CONSTANTS
*
         REF      XN2               MINUS 2
NMASTERO EQU      M7
MASTERO  EQU      X80
         PAGE
***************************************************************
*                      REGISTER DEFINITIONS                   *
***************************************************************
         SPACE    2
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
R8       EQU      8
R9       EQU      9
R10      EQU      10
R11      EQU      11
R12      EQU      12
R13      EQU      13
R14      EQU      14
R15      EQU      15
         PAGE
*D*************************************************************
*D*                                                           *
*D*                       T:MASTER                            *
*D*                                                           *
*D*      PURPOSE: TO CHECK PSD OF TOPMOST ENVIRONMENT IN      *
*D*               TSTACK FOR MONITOR MODE, MASTER AND         *
*D*               BELOW JIT.  IF SO, AN IMMEDIATE EXIT IS     *
*D*               TAKEN VIA T:PULLE.  OTHERWISE S:CLOCK4      *
*D*               IS SET TO J:DELTAT TO ACCOUNT USER EXEC     *
*D*               AND A NORMAL RETURN IS MADE VIA THE LINK    *
*D*               REGISTER.  IN MULTIPROCESSING SYSTEMS,      *
*D*               THE MASTER-ONLY FLAG IN UB:MPFLG IS         *
*D*               ALSO RESET IN THIS CASE.                    *
*D*                                                           *
*D*      R0,R1 - VOLATILE                                     *
*D*      R2 - LINK                                            *
*D*      R4 - USER NUMBER - INPUT,UNCHANGED                   *
*D*                                                           *
*D*************************************************************
         SPACE    2
T:MASTER RES      0
         LI,R1    -17               POINT TO PSD OF TOP
         AW,R1    TSTACK            ENVIRONMENT IN TSTACK
         AND,R1   XN2               ON DOUBLEWORD BOUND
T:MSTR   RES      0                 2NDARY ENTRY FROM SCHED
         LW,R0    0,R1              GET PSW1
         CW,R0    Y008              CHECK FOR SLAVE
         BANZ     MASTER1           YES
         CW,R0    Y004              CHECK FOR MAPPED
         BAZ      T:PULLE           NO, EXIT
         AND,R0   M17               SCRUB ADDRESS
         CI,R0    J:JIT             CHECK FOR EXECUTION BELOW JIT
*                                   EG, IN MONITOR OR OVERLAY
         BL       T:PULLE           YES, EXIT
MASTER1  RES      0
         LI,R0    J:DELTAT          SET CLOCK TO ACCOUNT FOR
         STW,R0   S:CLOCK4          USER EXECUTION
         DO       MP                MULTIPROCESSING
         LW,R4    S:CUN             CURRENT USER
         LB,R1    UB:MPFLG,R4       GET MPFLAGS
         AND,R1   NMASTERO          RESET MASTERONLY FLAG
         STB,R1   UB:MPFLG,R4       AND SAVE NEW FLAG VALUE
         FIN      MP                MULTIPROCESSING
         B        0,R2              NORMAL RETURN IF USER
         PAGE
*D*************************************************************
*D*                                                           *
*D*                       T:SMPFLG                            *
*D*                                                           *
*D*      PURPOSE: TO SET MASTER-ONLY FLAG IN UB:MPFLG         *
*D*               FOR MULTIPROCESSING SYSTEMS.  THIS          *
*D*               FLAG  PREVENTS A USER FROM BEING            *
*D*               SCHEDULED FOR EXECUTION BY A SLAVE          *
*D*               CPU.                                        *
*D*                                                           *
*D*      R0 - VOLATILE                                        *
*D*      R1 - LINK                                            *
*D*      R4 - USER NUMBER - INPUT,UNCHANGED                   *
*D*                                                           *
*D*************************************************************
         SPACE    2
T:SMPFLG RES      0
         DO       MP                MULTIPROCESSING
         LW,R4    S:CUN             CURRENT USER
         LB,R0    UB:MPFLG,R4       GET MPFLGS
         OR,R0    MASTERO           SET MASTER-ONLY BIT
         STB,R0   UB:MPFLG,R4       AND SAVE NEW FLAG SETTING
         FIN      MP                MULTPROCESSING
         B        0,R2              RETURN
         PAGE
*D*************************************************************
*D*                   DUMMY T:SES                             *
*D*                                                           *
*D*      PURPOSE: DUMMY REPLACEMENT ROUTINE FOR T:SES         *
*D*               IN NON-MULTIPROCESSING SYSTEMS              *
*D*                                                           *
*D*      R11 - LINK                                           *
*D*      ALL REGISTERS VOLATILE                               *
*D*                                                           *
*D*************************************************************
         SPACE    2
         DO       MP=0              MULTIPROCESSING
T:SES    RES      0
         DEF      T:SES
         B        *R11              RETURN
         FIN      MP
         PAGE
*D*********************************************************************
*D*                             T:ACCTEX                              *
*D*                                                                   *
*D*      PURPOSE: TO ACCUMULATE THE TOTAL EXECUTION AND SERVICE       *
*D*               TIME IN THE APPROPRIATE ACCOUNTING CELLS IN JIT     *
*D*               AND INITIALIZE FOR A NEW QUANTUM.                   *
*D*      DESCRIPTION: SERVICE TIME WHICH ELAPSED DURING THE CURRENT   *
*D*               QUANTUM (J:OVHTIM) IS ADDED TO THE TOTAL IN EITHER  *
*D*               J:UTIME+1 OR J:PTIME+1 AS INDICATED BY THE PRO-     *
*D*               -CESSOR RUNNING FLAG IN J:RNST.  EXECUTION TIME     *
*D*               FROM THE CURRENT QUANTUM (J:DELTAT-J:IDELTAT) IS    *
*D*               ADDED TO EITHER J:UTIME OR J:PTIME AS APPROPRIATE.  *
*D*               THE CORE TIME PRODUCT (PAGES * TICS) IS COMPUTED    *
*D*               BY SUMMING THE TOTAL CPU TIME USED DURING THE       *
*D*               CURRENT QUANTUM AND MULTIPLYING BY THE SWAP SIZE    *
*D*               IN PAGES (UB:PCT). THIS PRODUCT IS THEN ADDED TO    *
*D*               J:UTIME+2 OR J:PTIME+2 AS APPROPRIATE.              *
*D*               THE USER TIMER (J:UTIMER) AND MAXIMUM RUN TIME      *
*D*               (J:MRT) ARE DECREMENT BY THE TOTAL CPU TIME USED IN *
*D*               THIS QUANTUM.  IF THE MAXIMUM RUN TIME HAS BEEN     *
*D*               EXCEEDED, THE MAX TIME FLAG IS SET IN J:ASSIGN AND  *
*D*               LIMIT EXCEEDED RUN STATUS IS SET IN J:RNST.         *
*D*               FOR MULTI-PROCESSING SYSTEMS, THE AVERAGE COMPUTE   *
*D*               INTERVAL BETWEEN CALS IS DETERMINED AND SAVED IN    *
*D*               UB:CALR.  THE PERFORMANCE MONITOR IS CALLED TO      *
*D*               RECORD THE AMOUNT OF EXECUTION AND SERVICE TIME     *
*D*               FOR STATISTICAL PURPOSES.                           *
*D*               A NEW QUANTUM OF THE PROPER SIZE FOR THE CLASS OF   *
*D*               USER IS GIVEN BY CLEARING J:OVHTIM AND J:CTIME AND  *
*D*               BY STORING THE TWOS COMPLEMENT OF THE QUANTUM IN    *
*D*               BOTH J:DELTAT AND J:IDELTAT.                        *
*D*      INPUT:                     JIT                               *
*D*               J:CALCNT - CAL COUNT                                *
*D*               J:DELTAT - NEGATIVE TIME REMAINING IN QUANTUM       *
*D*               J:IDELTAT - INITIAL VALUE OF J:DELTAT               *
*D*               J:OVHTIM - SERVICE TIME IN CURRENT QUANTUM          *
*D*               JB:PNR - PARTITION NUMBER FOR BATCH JOBS            *
*D*                              USER TABLES                          *
*D*               UH:FLG - BATCH FLAG                                 *
*D*               UB:PCT - SWAP SIZE IN PAGES                         *
*D*               U:CALC - CAL COUNTER                                *
*D*                                 LIMITS                            *
*D*               SL:QUAN - QUANTUM FOR ONLINE AND GHOST              *
*D*               PLH:QN - PARTITION QUANTA FOR BATCH                 *
*D*                          SCHEDULER DATA                           *
*D*               S:CUN - CURRENT USER NUMBER                         *
*D*                                                                   *
*D*      OUTPUT:                    JIT                               *
*D*               J:DELTAT - TWOS COMPLEMENT OF QUANTUM               *
*D*               J:CTIME - ZERO                                      *
*D*               J:IDELTAT - SAME AS J:DELTAT                        *
*D*               J:OVHTIM - ZERO                                     *
*D*               J:PTIME,+1,+2 - UPDATED AS APPROPRIATE              *
*D*               J:UTIME,+1,+2 - UPDATED AS APPROPRIATE              *
*D*               J:UTIMER - UPDATED                                  *
*D*                     PERFORMANCE MONITOR DATA                      *
*D*               C:MSB,C:MSO,C:SCB,C:SCO - UPDATED                   *
*D*               C:SUSER - UPDATED IF EXECUTING ON SLAVE CPU
*D*                    USER TABLES                                    *
*D*               UB:CALR - AVERAGE COMPUTE INTERVAL BETWEEN CALS     *
*D*                                                                   *
*D*      REGISTERS: R1,R2,R4,R5,R7,R10,R11 VOLATILE                   *
*D*                 R3 - LINK                                         *
*D*********************************************************************
T:ACCTEX EQU      %                 ACCOUNT FOR USER EXECUTION TIME
         LW,R1    S:CUN             GET INDEX FOR CURRENT USER
         LCW,R7   SL:QUAN           ASSUME ONLINE QUANTUM
         LC       J:JIT             BUT CHECK FOR BATCH
         BCS,8+4  ACCT01            NOT BATCH, GHOST OR ONLINE
         LI,R5    BA(JB:PNR)        SET UP INDEX TO PARTITION NUMBER
         LB,R5    0,R5              AND GET PARTITION NUMBER
         LCH,R7   PLH:QN,R5         NOW GET QUANTUM VALUE
ACCT01   LCW,R10  J:IDELTAT         SUBTRACT J:IDELTAT
         AW,R10   J:DELTAT          FROM J:DELTAT
         STW,R7   J:DELTAT          NOW GIVE NEW QUANTUM
         STW,R7   J:IDELTAT         BY SETTING J:DELTAT=J:IDELTAT=-QUAN
         LW,R5    R10               COMPUTE TOTAL CPU TIME
         AW,R5    J:OVHTIM          BY ADDING SERVICE TIME
         LI,R11   0                 RESET COMPENSATORY
         STW,R11  J:CTIME           TIME COUNTER
         XW,R11   J:OVHTIM          CLEAR OVERHEAD TIME COUNTER
         LB,R7    UB:PCT,R1         GET SWAP SIZE IN PAGES
         MW,R7    R5                AND COMPUTE PAGES*TICS
         LH,R4    J:RNST            TEST FOR PROCESSOR RUNNING
         AND,R4   X10               TO PROPERLY DISTRIBUTE TIME
         BNEZ     1A1               NOT PROCESSOR
         AWM,R10  J:PTIME           ACCUMULATE EXECUTION TIME
         AWM,R11  J:PTIME+1         AND SERVICE TIME
         AWM,R7   J:PTIME+2         CORE-TIME PRODUCT
         B        1A2
1A1      AWM,R10  J:UTIME           ADD EXECUTION TIME FOR USER
         AWM,R11  J:UTIME+1         AND SERVICE TIME
         AWM,R7   J:UTIME+2         CORE-TIME PRODUCT
1A2      LCW,R7   R5                DECREMENT STIMER VALUE
         AWM,R7   J:UTIMER          BY CPU TIME IN THIS QUANTUM
         LW,R4    J:MRT             CHECK FOR CPU TIME LIMIT
         BEZ      ACCT1             NONE, DONT MAX TIME
         AWM,R7   J:MRT             ALSO DECREMENT MAX RUN TIME REMAINING
         BGZ      ACCT1             NOT TO LIMIT YET
         LI,R7    0                 ONLY MAX ONCE
         STW,R7   J:MRT             SO RESET LIMIT NOW
         LI,R7    X'80'             SET MAX TIME
         STS,R7   J:ASSIGN          FLAG
         LI,R7    4                 AND SET RUN STATUS TO LIMIT EXCEEDED
         STB,R7   J:RNST            TO TRIGGER ABORT OF USER
ACCT1    LW,R7    R10               GET SLAVE CPU TIME
         DO       MP                MULTIPROCESSING
         LW,R4    J:CALCNT          COMPUTE CALS DONE THIS QUAN
         SW,R4    U:CALC,R1         TO COMPUTE
         DW,R7    R4                SLAVE TICS PER CAL
         LB,R4    UB:CALR,R1        AVERAGE NEW VALUE
         AW,R4    R7                WITH PREVIOUS
         SLS,R4   -1                TO YIELD INTER-CAL INTERVAL
         STB,R4   UB:CALR,R1
         LW,R4    J:CALCNT          SAVE CURRENT CAL COUNT
         STW,R4   U:CALC,R1         FOR NEXT CALCULATION
         LW,R4    S:PNO             ARE WE ON A SLAVE
         BEZ      %+3
         AWM,R11  C:SUSER,R4        YES, ACCUMULATE TIME
         AWM,R5   C:SUSER,R4
         FIN      MP
         BAL,R4   PMSCA             CALL PM TO MEASURE COMPUTE TIME
         LI,R4    C:SCG             GHOST TABLE
         LC       J:JIT             TEST FOR ONLINE
         BCS,4    ACCT2             GHOST
         LI,R4    C:SCO             ASSUME ONLINE
         BCS,8    %+2               YES, ONLINE
         LI,R4    C:SCB             NO, BATCH
ACCT2    AWM,R5   0,R4              ADD COMPUTE TIME
         AWM,R11  C:MSB-C:SCB,R4    AND SERVICE TIME
         AI,R2    0                 CHECK FOR SHARED PROC MEASUREMENT
         BEZ      %+2               NO
         AWM,R5   *R2,R4            YES, ADD CPU TIME
PMSCOUT  B        0,R3              RETURN
         PAGE
*D*********************************************************************
*D*                                 T:SCREECHS                        *
*D*      PURPOSE: TO INITIATE A RECOVERY OPERATION FROM A SLAVE       *
*D*               CPU IN A MULTIPROCESSING SYSTEM.                    *
*D*      DESCRIPTION: THE ERROR CODE INDICATING THE CAUSE FOR THE     *
*D*               RECOVERY IS STORED IN S:SSCRCH TO SIGNAL THE MASTER *
*D*               CPU AND RECORD THE REASON.  CURRENT REGISTERS OF    *
*D*               THE SLAVE CPU ARE SAVED FOR ANALYSIS IN SREG1       *
*D*               CONTROL OF THE SLAVE CPU THEN PASSES TO T:SCRASH    *
*D*               TO AWAIT COMPLETION OF THE RECOVERY PROCESS.        *
*D*               IF T:SCREECHS IS REACHED IN A MONOPROCESSOR SYSTEM, *
*D*               AN UNCONDITIONAL SOFTWARE CHECK 78 WILL OCCUR.      *
*D*      INPUT:   S:PNO - PROCESSOR NUMBER                            *
*D*               RCVPSD - POINTS AT ERROR CODE                       *
*D*      OUTPUT:  S:SSCRCH - ERROR CODE AND PROCESSOR NUMBER          *
*D*               SREGS1 - REGISTERS FOR ANALYSIS
*D*      CALL:    SAME CALLING SEQUENCE AS RECOVERY                   *
*D*               E.G., SCREECH,SUA,DUMP HOWEVER NO ATTEMPT IS        *
*D*               MADE TO DIFFERENTIATE THESE.                        *
*D*********************************************************************
T:SCREECHS EQU    %
         DO       MP                MULTIPROCESSING
         REF      RCVPSD            SCREECH PSD
         LCI      0                 SAVE CURRENT REGISTERS
         STM,R0   SREGS1            FOR ANALYSIS
         LW,R2    S:PNO             GET PROCESSOR INDEX
         LW,R3    RCVPSD            GET SCREECH PSD
         AND,R3   M17               SCRUB TO INSTRUCTION ADDRESS
         LW,R4    0,R3              GET SUBCODE AND CODE
         SLD,R4   -8                SAVE SUBCODE
         LH,R4    *R3               GET MAJOR CODE
         SLD,R4   8                 AND MERGE WITH SUBCODE
         STH,R1   R2                COMBINE MAJOR AND MINOR CODES
         STW,R2   S:SSCRCH          TRIGGER RECOVERY BY MASTER
         LW,R2    SB:RCVR           TEST RECOVERY REQUEST
         BEZ      %-1               NO, WAIT UNTIL MASTER NOTICES
         B        T:SCRASH          AND WAIT
         PAGE
         ELSE
         PAGE
         SCREECH  X'78',X'7F'       MASTER TOOK SLAVE PATH ON
*                                   MONOPROCESSOR SYSTEM.
*S*********************************************************************
*S*      SCREECH CODE: 78-7F        CALLED FROM ENTRY                 *
*S*      MESSAGE: SLAVE INVOKED CRASH ON MONOPROCESSOR                *
*S*      SIGNIFICANT REGISTERS:                                       *
*S*               ALL REGISTERS ARE THOSE AT THE TIME OF THE TRAP     *
*S*      REMARKS: THE TYPE OF TRAP MAY BE IDENTIFIED BY THE INDEX     *
*S*               SAVED IN PULLE1.  THE PSD IS SAVE IN TRAPPSD.     *
*S*               GENERALLY THIS SCREECH INDICATES A TRAP PRIOR TO    *
*S*               TO SCHEDULING ANY USERS WITH S:PNO CLOBBERED        *
*S*********************************************************************
         FIN      MP
         END

