         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      1
         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
*
         DO       MP
         REF      T:SCRASH          PERFORM SLAVE CRASH
         REF      T:SPARK           PARK SLAVE USER FOR SCREECH
         FIN
*
*        EXTERNAL ROUTINES
*
         REF      T:SAVE            SAVE ENVIRONMENT
*
*        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      PULLEXIT          NOT MAPPED-> EXIT IMMEDIATELY
         AND,R0   M17               SCRUB ADDRESS
         CI,R0    J:JIT             CHECK FOR EXECUTION BELOW JIT
*                                   EG, IN MONITOR OR OVERLAY
         BL       PULLEXIT          YUP-CANT RUN MONITOR IN SLAVE CPU
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*************************************************************
*
*        MOVE EXIT TO RETURN NOW
*
PULLEXIT EQU      %
         LI,R2    T:PULLE           AFTER SETTING FLAGS
*
         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
         LH,4     UH:FLG,1
         CI,4     DIC+TIC           DON'T RUN STIMER IN TEL OR DELTA
         BANZ     %+2
         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    S:PNO             ARE WE ON A SLAVE
         BEZ      %+2
         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:  If there are at least 19 words left in
*D*               TSTACK and S:CUN is non-zero, the user is
*D*               parked with an environment pointing back to
*D*               the XPSD that got us here.  When he is
*D*               rescheduled on the master, he will execute the
*D*               XPSD again and enter recovery.  If either there
*D*               is not enough room in TSTACK or if there is no
*D*               current user, the recovery code is placed in
*D*               S:SSCRCH and the slave waits for the master to
*D*               initiate a screech.
*D*      INPUT:   S:PNO - Processor number
*D*               RCVPSD - Address of XPSD that got us here
*D*      OUTPUT:  If possible, user is passed to master and a
*D*               normal screech, sua or dump occurs.  If not,
*D*               S:SSRCH is set with the screech code which
*D*               forces the master to screech, and the slave
*D*               registers are saved in SREGS1
*
*
*D*********************************************************************
T:SCREECHS EQU    %
         DO       MP                MULTIPROCESSING
         REF      RCVPSD            SCREECH PSD
         LCI      0                 SAVE CURRENT REGISTERS
         STM,R0   SREGS1            FOR ANALYSIS
         LH,R1    TSTACK+1          SPACE LEFT IN TSTACK
         CI,R1    19
         BL       SCRCH5            NOT ENUF ROOM FOR ENVIRONMENT
         MTW,0    S:CUN
         BEZ      SCRCH5            NO USER
         LW,R1    SREGS1+1          RESTORE R1
         PUSH     6,R13             SAVE ENVIRONMENT
         LD,R0    RCVPSD            PSD
         AI,R0    -1                BACK PSD TO XPSD
         BAL,R2   T:SAVE
         B        T:SPARK           GO PARK, FORCE TO MASTER
*
SCRCH5   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

