Trailing-Edge
-
PDP-10 Archives
-
AP-D543V_SB
-
sched1.mac
There are 13 other files named sched1.mac in the archive. Click here to see a list.
TITLE SCHED1 - SCHEDULING ALGORITHM FOR SWAPPING SYSTEM (10/50) V13720
SUBTTL R.KRASIN/TH/CMF/AF/RCC/DAL/EVS/WRS 31 OCT 78
SEARCH F,S
$RELOC
$HIGH
;COPYRIGHT (C) 1973,1974,1975,1976,1977,1978 BY DIGITAL EQUIPMENT CORP., MAYNARD, MASS.
XP VSCHED,13720
;PUT VERSION NUMBER IN GLOB LISTING AND LOADER STORAGE MAP
ENTRY SCHED,SCHED1 ;THIS UNDEFINED GLOBAL IN COMMON CAUSES THIS
; ROUTINE TO BE LOADED.
SCHED1:: ;MODULE ORIGIN
;THIS SCHEDULER BASED ON WORK DONE AT WMU BY E.SMOLSKY AND N.GRANT
;NXTJOB DECREMENTS ALL JOBS' IN CORE PROTECT TIMES AND REQUEUES ANY
; JOB WHOSE ICPT GOES TO ZERO. IT REQUEUES CURRENT JOB IF ITS QUANTUM
; RUN TIME HAS GONE TO ZERO. IT THEN
;SERVICES ANY JOB REQUEUING REQUESTED AT OTHER PRIORITY
;LEVELS THEN CALLS SHUFFLER,SWAPPER AND SCHEDULAR.
;RETURNS NEXT JOB TO RUN IN J.
NXTJOB::SKIPN .C0TMF## ;CLOCK TIC?
JRST NXTJB1 ;NO
MOVE T4,TIME## ;GET TIME IN JIFFIES
TRNE T4,1B35 ;ONLY DECREMENT IN CORE TIME ON ODD TICKS
SOSGE CORSCD ;ARE WE CORE SCHEDULING?
JRST NXTJBX ;NO CORE SCHEDULING OR EVEN TICK
MOVEI T4,JS.SCN ;JOB SCANNED DURING TICK BIT
MOVEI U,DCSCAN## ;TABLE OF QUEUES TO SCAN
NXTJBL: SKIPN T2,(U) ;AT END OF LIST?
JRST NXTJBX ;YES. EXIT LOOP
HLRE J,JBTCQ##(T2) ;GET LAST JOB IN QUEUE
JUMPLE J,NXTJBG ;IF NO ONE IN QUE, GET NEXT QUE
NXTJBA: HLRE T2,JBTCQ##(J) ;GET JOB BEFORE THIS JOB
MOVEM T2,NEXTJB ;STORE IT FOR LATER. NEXT TO LOOK AT
SKIPGE JBTST2##(J) ;DECREMENT ALL JOBS THAT ARE NOT IN A PROCESSOR
;QUEUE (NORMALLY ONLY CATCHES SLP,EW)
TDNE T4,JBTST2##(J) ;OR IF JOB WAS ACTUALLY SCANNED
JRST .+2 ;WE WILL DECREMENT
JRST NXTJBF ;DO NOT DECREMENT THIS JOB
ANDCAM T4,JBTST2(J) ;CLEAR SCANNED BIT FOR NEXT TIME
IFN FTPDBS,<
PUSHJ P,FNDPDB## ;GET PDB ADDRESS
JRST NXTJBF ;NO PDB IMPLIES NO ICPT
>
IFE FTPDBS,<
HRRZ W,JBTPDB##(J) ;GET PDB ADDRESS
JUMPE W,NXTJBF ;NO ICPT IF NO PDB
>
.LDB T3,PDYIPT## ;GET ICPT
SOJG T3,NXTJBE ;IF STILL POSITIVE, JUST DEPOSIT
MOVSI T3,PDMSWP ;MARK SWAPPABLE IN PDB
.IORM T3,.PDIPT##(W) ;..
MOVE T2,JBTSTS##(J) ;JOB STATUS WORD
TLNE T2,CMWB!JRQ ;COMMAND WAIT OR REQUE?
JRST NXTJBD ;YES. GET OUT
PUSHJ P,SETIPT ;RESET ICPT SO THE JOB WILL CYCLE
; EVEN IF IT DOESN'T NEED TO SWAP
SKIPL JBTST2##(J) ;IS JOB IN A RUN QUEUE?
JRST NXTJBF ;NO. CAN'T REQUE HIM NOW.
IFN FTPSCD,<
PUSHJ P,CNTICP ;COUNT NUMBER WHO EXPIRED IN-CORE BY QUE
>
PUSH P,U ;SAVE ADDRESS OF QUEUE TABLE
MOVEI U,QTIME ;REQUE AROUND RUN QUEUES
PUSHJ P,QXFER ;DO TRANSFER
POP P,U ;GET ADDRESS OF QUEUE TABLE BACK
JRST NXTJBF ;GO TO NEXT JOB
NXTJBD: SETZ T3, ;PUT IN A ZERO FOR COMMAND WAIT, JRQ
NXTJBE: .DPB T3,PDYIPT## ;OR JUST STORE NEW VALUE
NXTJBF: SKIPLE J,NEXTJB ;GET BACK THE NEXT JOB TO LOOK AT
JRST NXTJBA ;IF ANY AND LOOP FOR THE REST OF QUEUE
NXTJBG: AOJA U,NXTJBL ;NOW LOOP OVER ALL QUEUES
NXTJBX:
IFN FTNSCHED,<
PUSHJ P,SCDQTA ;RESET SCHEDULING SCAN TABLE AT
;END OF A MICRO SCHEDULING INTERVAL
>;END IFN FTNSCHED
IFN FTRSP,< ;KEEP TRACK OF WANT-TO-RUN TIME
RQTPAT::JRST RQT3 ;PATCH TO JFCL TO INCLUDE EXPENSIVE
; WANT-TO-RUN TIME CALCULATION
MOVSI T1,WTMASK ;TO CHECK FOR RUN STATE CODE
HRRE J,JBTCQ##-PQ1 ;CHECK PQ1 IN CORE
PUSHJ P,RQT2
HRRE J,JBTCQ##-PQ2 ; PQ2 IN CORE
PUSHJ P,RQT2
HRRE J,JBCQOH##-PQ1 ;CHECK PQ1 NO CORE
PUSHJ P,RQT2
HRRE J,JBCQOH##-PQ2 ; PQ2 NO CORE
PUSHJ P,RQT2
JRST RQT3
RQT1: TDNN T1,JBTSTS##(J) ;SKIP IF NOT IN RUN STATE
AOS JBTRQT##(J) ;BUMP JBTRQT FOR ALL
HRRE J,JBTCQ##(J) ; JOBS IN THIS QUEUE
RQT2: JUMPG J,RQT1
POPJ P,
RQT3:
> ; END OF CONDITIONAL ASSEMBLY ON FTRSP
;CPU1 ENTERS HERE FROM CIP6
NXTJB1::
IFN FTMS,<
SETZM .CPDBL##(P4) ;CLEAR DOORBELL SINCE SCHEDULING NOW
>
SKIPN J,.CPJOB##(P4) ;CURRENT JOB NO., IS IT NULL JOB?
JRST CKJB1 ;YES,GO SEE IF OTHER JOBS NEED RESCHEDULING
MOVS T2,JBTSTS##(J) ;GET JOB STATUS BITS AND CODES, HALVES SWAPPED
SKIPGE JBTST2##(J) ;DID SOMEONE REQUE CURRENT JOB OUT OF RUN QUEUE?
TLNE T2,JDC!JS.DEP ;IF JOB IS WAITING FOR DAEMON, SEE IF WE
;CAN REQUE TO DAEMON QUEUE
JRST CKJB0A ;JOB SHOULD BE REQUEUED
IFN FTHPQ!FTNSCHED,<
SKIPE .CPHQU##(P4) ;IF THE CURRENT JOB JUST DID AN HPQUUO, OR
; CHANGED ITS SCHEDULER CLASS, IT IS ALWAYS
; RUNNABLE BUT IT MUST BE REQUEUED
JRST CKJB0A ;JOB SHOULD BE REQUEUED
>
ANDI T2,-1-RUNMSK-CMWB ;MASK OUT DO NOT CARE BITS
CAIE T2,RUNABLE ;IS CURRENT JOB RUNABLE?
JRST CKJB0 ;NO, REQUE CURRENT JOB
PUSHJ P,FNDPDB## ;YES. GET PDB ADR FOR CURRENT JOB
JRST CKJB1 ;GO AWAY IF NONE
.LDB T2,PDYIPT## ;GET ICPT
JUMPE T2,NXTJB4 ;ALWAYS REQUE IF ZERO
.LDB T2,PDYQNT## ;GET IN QUE TIME
JUMPN T2,CKJB1 ;EXIT IF STILL POSITIVE
IFN FTRSP,< ;RESPONSE DATA?
MOVEI T1,.CPARR##(P4) ;BASE ADR OF 3 WORDS FOR QUANTUM REQUEING
MOVSI T2,(JR.RRR) ;RECORD THIS TYPE OF RSP FOR THIS JOB
PUSHJ P,RSPRC2## ;RECORD ELAPSED TIME FOR RESPONSE
; AND FOR ANY OF TTY IN, TTY OUT, THIS
> ; END OF CONDITIONAL ASSEMBLY ON FTRSP
IFN FTPSCD,<
PUSHJ P,CNTINQ ;COUNT NUMBER WHO EXPIRED IN QUE BY QUE
JRST NXTJ4A
>
NXTJB4:
IFN FTPSCD,<
PUSHJ P,CNTICP ;COUNT NUMBER WHO EXPIRED IN-CORE BY QUE
>
NXTJ4A:
IFN FTMS,<
SETZM .CPLJU##(P4) ;IF REQUEING, ZERO THE LAST JOB TO DO A UUO WORD
;SINCE JOBQUE FOR THAT JOB WILL THEN BE WRONG
>
PUSHJ P,QARNDT ;YES - REQUEUE AND RESET QUANT TIMES.
JRST CKJB1 ;DO ONCE A CLOCK TICK STUFF
CKJB0: TRZ T2,JXPN!SHF!SWP ;JOB NOT RUNNABLE, NEED REQUEING?
CAIN T2,RUNABLE ;DOES IT REALLY NEED TO BE REQUEUED?
JRST CKJB1 ;NO, DON'T GIVE HIM EXTRA PRIORITY
CKJB0A: MOVSI T1,JRQ ;SET TO TEST JRQ
TDNN T1,JBTSTS(J) ;IS REQUE SET FOR CURRENT JOB?
PUSHJ P,QREQ ;NO, GO REQUEUE IT SINCE JRQ NOT SET
CKJB1:
IFN FTMS,<
SKPCPU (0) ;DON'T GO THROUGH REQUEUE QUEUE ON SLAVE
JRST SCHED ;THEN SCHEDULE NEXT JOB
>
CKJB1A: SKIPG JBTJRQ## ;ANY JOBS IN LINKED LIST OF REQUEUES?
JRST CKJB5 ;NO. GO ON
CONO PI,PIOFF## ;YES. DELETE FIRST JOB
MOVE J,JBTJRQ## ;THIS IS A FIRST IN - LAST OUT QUEUE
MOVE T1,JBTJRQ##(J) ;GET NEXT JOB
MOVEM T1,JBTJRQ## ;HE IS NOW FIRST
MOVSI T2,JRQ ;CLEAR JOB NEEDS REQUEING BIT
ANDCAM T2,JBTSTS##(J) ;WHICH IS USED AS AN INTERLOCK ON JBTJRQ
CONO PI,PION## ;TURN PI'S BACK ON
PUSHJ P,QREQ ;GO REQUE THE JOB
JRST CKJB1A ;YES. KEEP REQUEING
CKJB5:
IFN FTKI10!FTKL10,<
SKIPN EVAVAL## ;EV AVAILABLE AND SOMEONE WAITING?
JRST CKJB7 ;NO.
SETZM EVAVAL ;YES. CLEAR FLAG
SKIPG J,HIGHJB## ;ANY JOBS?
JRST CKJB7 ;NO. SHOULDN'T HAPPEN
MOVSI T2,WTMASK ;YES. TAKE EVERYBODY OUT OF EV WAIT
CKJB5A: LDB T1,PJBSTS## ;GET JOBS STATE CODE
CAIN T1,EVQ ;EV?
ANDCAM T2,JBTSTS##(J) ;YES. TAKE HIM OUT
SOJG J,CKJB5A ;AND LOOP FOR ALL JOBS
CKJB7:> ;END IFN <FTKI10!FTKL10>
IFN FTHPQ,<
SKIPG .C0RTF## ;IF AN HPQ JOB ON DISK WOKE UP
>
SKIPN .C0JOB## ;OR IF RUNNING NULL JOB
JRST CKJB6 ;CALL SWAP/SHUFFLE
SKIPN .C0TMF## ;ALWAYS CALL SWAP/SHUFFLE ON TICK
JRST SCHED ;NOT TICK OR OTHERWISE
CKJB6:
IFE FTSWAP,<
PUSHJ P,CHKSHF##
> ; END OF CONDITIONAL ASSEMBLY ON FTSWAP
IFN FTSWAP,<
IFN FTTRPSET,<
SKIPN STOPTS## ;DON'T SWAP IF TIMESHARING TURNED OFF.
>
PUSHJ P,SWAP
> ; END OF CONDITIONAL ASSEMBLY ON FTSWAP
IFN FTLOCK,<
SKIPA ;NOT TRYING TO LOCK A JOB, PROCEED.
PUSHJ P,LOCK0## ;SHUFFLER AND SWAPPER ARE IDLE - SO SEE IF JOB CAN BE LOCKED
JFCL ;IGNORE POSSIBLE SKIP RETURN
> ; END OF CONDITIONAL ASSEMBLY ON FTLOCK
MOVEI P4,.C0CDB## ;SHUFFLER AND SWAPPER CLOBBER P4
; SETUP CPU DATA BLOCK ADR AGAIN
;SCHEDULAR--SEARCH THRU QUEUES ACCORDING TO SSCAN TABLE
;FOR 1ST JOB IN CORE--RETURN ITS NO. IN J
SCHED:: SETZM .CPPLT##(P4) ;CLEAR POTENTIALLY LOST TIME FLAG
PJRST @.CPSCH##(P4) ;GO DO CPU DEPENDENT SCHEDULING
;EACH SCHEDULER CALLS SCHEDJ TO FIND RUNNABLE JOBS
;SCHEDJ IS CALLED TO FIND A RUNNABLE JOB
;IT RETURNS WITH THE HIGHEST PRIORITY RUNNABLE JOB IN J
;CALL: PUSHJ P,SCHEDJ
; RETURN HERE WITH J SET UP
SCHEDJ::
IFN FTTRPSET,<
SKIPE J,.CPSTS##(P4) ;TIMESHARING TURNED OFF? (TRPSET)
JRST [SKIPGE JBTSTS##(J) ;RUNNABLE?
SKIPL JBTST2##(J) ;YES, IN A RUN QUEUE?
JRST SCHD1 ;NO TO EITHER QUESTION
MOVEI T2,SCHD1 ;IN CASE HE'S NOT REALLY RUNNABLE
JRST SCHEDB ;GO SEE
]
>;END IFN FTTRPSET
SETZM UNWIND ;FLAG THAT WE ONLY UNWIND ONCE/SCAN
MOVE U,.CPSCN##(P4) ;ADDRESS OF STANDARD SCAN TABLE
MOVEM U,.CPSUD##(P4) ;RECORD WHICH SCAN WE USED
IFN FTDISK,<
SKIPE J,FORCEF ;FORCING ANYONE WITH SHAR. RESOURCE?
SKIPL JBTST2##(J) ;IS JOB IN A RUN QUEUE?
JRST SCHED2 ;NO! DON'T BOTHER CHECKING
MOVEI T2,MRNBL## ;PREPARE TO SCAN NORMALLY
;BUT START WITH JOB IN FORCEF
SKIPGE JBTSTS##(J) ;IF NOT RUNNABLE, SCHED NORMALLY. (POSSIBLE
; IF JOB HAS STOPPED AND GIVEN UP RESOURCE
JRST SCHEDB ; BUT FLAG HAS NOT YET BEEN CLEARED)
> ;END OF FTDISK CONDITIONAL
SCHED2: MOVE T1,.CPSFC##(P4) ;GET COUNT OF UNFAIR SCHEDULES
CAMGE T1,MFC##(U) ;HAS IT REACHED MAXIMUM FAIRNESS COUNT?
JRST MRNBL## ;NO, DONT USE SECONDARY SCAN TABLE
SETZM .CPSFC##(P4) ;YES, CLEAR SCHEDULER FAIRNESS COUNT
MOVE U,SSCN##(U) ;AND GET ADDRESS OF SECONDARY SCAN TABLE
; (PQ1 AND PQ2 REVERSED)
MOVEM U,.CPSUD##(P4) ;RECORD WHICH SCAN WE USED
SCHDJ1::JSP T1,QSCAN ;BEGIN SCAN
JRST SCHD1 ;NO MORE JOBS--RETURN NULLJOB
SCHEDB::
IFN FTMS,<
PUSHJ P,DXRUN## ;GO CHECK IF JOB IS RUNNABLE ON THIS PROCESSOR
JRST (T2) ;NO, GO CONTINUE SCANNING
; (ALSO SETS .CPPLT IF CAN'T RUN ON CPU1 BECAUSE HI-SEG
; BEING SHUFFLED, SWAPPED, OR EXPANDED ON CPU 0)
> ; END OF CONDITIONAL ASSEMBLY ON FTMS
MOVEI F,JS.SCN ;YES
IORM F,JBTST2(J) ;SET SCANNED BIT
LDB F,PJBSTS## ;GET STATE CODE
JUMPE F,SCHEDC ;IF ZERO, LET HIM THROUGH
MOVE T3,JBTSTS(J) ;JOB STATUS
IFN FTDISK,<
PUSHJ P,CJFRCX ;IF JOB IS EXPANDING WITH RESOURCE, IGNORE JXPN
; SO JOB CAN BE RUN AND GIVE UP RESOURCE
>
IFN FTKI10!FTKL10,<
CAIE F,EVQ ;EV IS HANDLED SEPARATELY ABOVE.
>
TLNE T3,SWP+JRQ+SHF+JXPN ;IF SWAPPED, SHUFFLING,
JRST (T2) ;REQUEING, OR EXPANDING - GIVE UP
CAIL F,MINQ ;NON-ZERO. IS HE WAITING FOR A
CAILE F,MAXQ ;SHAREABLE RESOURCE?
JRST (T2) ;NO. CAN'T HELP HIM
SKIPE AVTBMQ##(F) ;YES - IS IT FREE?
JRST SCHEDA ;YES. TRY TO GIVE IT TO HIM
SKIPE UNWIND ;SHOULD WE UNWIND?
JRST (T2) ;NO. ALREADY TRIED ONCE THIS SCAN
PUSH P,J ;SAVE J SO WE CAN CONTINUE SCAN LATER
SETOM UNWIND ;SAY WE HAVE UNWOUND ONCE
SETZ T4, ;CLEAR LEVEL COUNTER
UNWND1:
IFN FTDISK,<
CAIN F,MQQ ;MON BUF QUE?
JRST MQUNWD ;YES. #@!%$&
>
HRRZ J,USTBMQ##(F) ;GET USER OF RESOURCE WE WANT
JUMPE J,UNWNDF ;FAIL IF NO ONE.
CAMN J,(P) ;SAME AS US?
JRST UNWNDF ;SHOULD NEVER HAPPEN %&'#@!
LDB F,PJBSTS## ;GET HIS STATE CODE
JUMPE F,UNWNDS ;RUN. TRY TO RUN HIM
CAIL F,MINQ ;NOT RUN. SHAREABLE RESOURCE?
CAILE F,MAXQ
JRST UNWNDF ;NO. FAIL EXIT
IFN FTKI10!FTKL10,<
CAIN F,EVQ ;WAITING FOR EV?
JRST UNWNDF ;YES. CAN'T UNWIND THAT!
>
SKIPE AVTBMQ##(F) ;AVAILABLE?
JRST UNWNDS ;YES. TRY TO SELECT
CAIGE T4,^D10 ;LOOPING?
AOJA T4,UNWND1 ;NOT YET
JRST UNWNDF ;APPEAR TO BE LOOPING
IFN FTDISK,<
MQUNWF: POP P,P2 ;RESTORE ACS
POP P,P1
>
UNWNDF: POP P,J ;RESTORE JOB NUMBER FROM SCAN
JRST (T2) ;AND CONTINUE SCAN
IFN FTDISK,<
MQUNW5: HLRZ J,P2 ;GET NUMBER OF THE DESIRED JOB
POP P,P2 ;RESTORE ACS
POP P,P1
JUMPE J,UNWNDF ;FAIL IF FOUND NO ONE
>
UNWNDS: PUSHJ P,CHKRUN ;MAKE SURE WE CAN RUN HIM
JRST UNWNDF ;CAN'T. #%$&@!
POP P,T3 ;FIX UP PDL
MOVEI T3,JS.OOO ;FLAG FOR CLOCK1 TO STOP WHEN GIVES UP
IORM T3,JBTST2##(J) ;ALL HIS SHAREABLE RESOURCES
AOS UNWNDC## ;COUNT AN UNWIND
LDB F,PJBSTS## ;GET STATE CODE.
JUMPE F,SCHEDC ;RUN HIM IF ZERO
JRST SCHEDE ;GIVE HIM RESOURCE AND RUN
IFN FTDISK,<
MQUNWD: PUSH P,P1 ;SAVE SOME ACS
PUSH P,P2
SETZ P1, ;CLEAR P1 FOR NXTJBB
MOVEI P2,777777 ;PUT LARGE SMALLEST CHAIN SO FAR VALUE AND JOB 0
MQUNW1: SETZ T4, ;INIT LENGTH OF THIS CHAIN
MQUNW2: PUSHJ P,NXTJBB## ;GET OWNER OF NEXT MQ
JRST MQUNW5 ;NO MORE BUFFERS. EXIT
MOVE J,T3 ;PUT NUMBER IN J
MQUNW3: JUMPE J,MQUNWF ;IF ZERO, QUIT. NOT SUPPOSED TO BE
LDB F,PJBSTS## ;GET STATE CODE
JUMPE F,MQUNW4 ;END OF CHAIN IF ZERO
CAIL F,MINQ ;WAITING FOR SHAREABLE RESOURCE TOO?
CAILE F,MAXQ
JRST MQUNW1 ;NO. TRY NEXT BUFFER
CAME J,-2(P) ;SAME AS US?
CAIN F,MQQ ;OR MQ?
JRST MQUNW1 ;YES - TRY NEXT CHAIN
IFN FTKI10!FTKL10,<
CAIN F,EVQ ;WAITING FOR EV?
JRST MQUNW1 ;YES. CAN'T UNWIND THAT!
>
SKIPE AVTBMQ##(F) ;IS IT AVAILABLE?
JRST MQUNW4 ;YES. END OF CHAIN
HRRZ J,USTBMQ##(F) ;NO. TRY NEXT LEVEL
CAIGE T4,^D10 ;LOOPING?
AOJA T4,MQUNW3 ;NO. COUNT DEPTH
JRST MQUNW1 ;YES. TRY NEXT CHAIN
MQUNW4: PUSHJ P,CHKRUN ;IS HE RUNNABLE?
JRST MQUNW1 ;NO. TRY NEXT BUFFER.
CAIL T4,(P2) ;YES. WHOSE CHAIN IS SHORTER?
JRST MQUNW1 ;OLD CHAIN SHORTER
MOVE P2,T4 ;SAVE LENGTH OF NEW CHAIN
HRLI P2,(J) ;AND JOB NUMBER
JRST MQUNW1 ;AND LOOK AT CHAIN FROM NEXT BUFFER
>;END OF IFN FTDISK
; SUBROUTINE TO CHECK THAT JOB FOUND BY UNWIND CAN BE RUN
; CALL IS
; MOVE J,JOB-NUMBER
; PUSHJ P,CHKRUN
; NOT RUNNABLE RETURN
; RUNNABLE RETURN
; SETS T3 TO JBTSTS(J). MAY DESTROY F
CHKRUN: SKIPGE T3,JBTSTS##(J) ;RUN BIT ON?
SKIPL JBTST2##(J) ;YES. IS JOB IN A RUN QUEUE?
POPJ P, ;NO. CAN'T RUN IT
IFN FTDISK,<
PUSHJ P,CJFRCX ;CHECK FOR JOB EXPANDING WITH RESOURCE
;IF SO, IGNORE JXPN TEMPORARILY SO HE
; CAN GIVE UP THE RESOURCE TO GET SWAPPED
>
IFN FTLOCK,<
TRNN T3,LOK
>
TLNE T3,SWP+JRQ+SHF+JXPN+CMWB ;FLAGS THAT CAN'T USE
POPJ P, ;NOT RUNNABLE
IFE FTMS,<
JRST CPOPJ1## ;RUNNABLE!
>
IFN FTMS,<
PJRST DXRUN## ;CHECK THAT WILL RUN ON THIS CPU
;AND EXIT SKIP/NON-SKIP
>
;ROUTINE TO IGNORE JXPN FOR JOB EXPANDING WITH SHAREABLE RESOURCE
;ENTER WITH JBTSTS IN T3
;ALWAYS EXITS NONSKIP
IFN FTDISK,<
CJFRCX: TLNE T3,JXPN ;JOB EXPANDING?
PUSHJ P,FLSDR## ;DOES HE HAVE DISK RESOURCE?
POPJ P, ;NO, OK AS IS
TLZ T3,JXPN ;YES, IGNORE JXPN TEMPORARILY
POPJ P, ;RETURN
>
SCHEDA:
IFN FTDISK,<
CAME J,FORCEF ;FORCING JOB WITH SHAREABLE RESOURCE?
JRST SCHEDE ;NO. GIVE HIM RESOURCE AND RUN HIM
PUSHJ P,FLSDR## ;DOES HE STILL HAVE THE RESOURCE?
JRST (T2) ;NO - DON'T GIVE HIM ONE
;YES - LET HIM HAVE MORE
> ;END FTDISK
SCHEDE:
IFN FTDISK,<
CAIN F,MQQ ;IS THIS THE MONITOR BUFFER QUEUE?
SOSGE MQFRE1## ;YES. DON'T RESET MQAVAL IF STILL FREE MON BUF
> ;END OF FTDISK CONDITIONAL
SETZM AVTBMQ##(F) ;CLEAR AVAL FLAG
MOVEM J,USTBMQ##(F) ;REMEMBER WHO THE RESOURCE WAS GIVEN
; TO SO IT CAN BE RETURNED IN THE EVENT OF
; A CATASTROPHIC ERROR, E.G., SWAP READ ERROR
IFN FTMS,<
SOS RESOURC## ; 1 LESS JOB WAITING
>
MOVSI T3,WTMASK ;CLEAR WAIT STATE
ANDCAM T3,JBTSTS##(J)
SCHEDC: MOVEM J,.CPPLT##(P4) ;SET POTENTIALLY LOST TIME FLAG FOR CLOCK1
MOVE F,JBTSTS##(J) ;IS THIS JOB SWAPPED OUT
IFN FTDISK,<
TLNN F,JXPN ;JOB EXPANDING?
CAMN J,FORCEF ;OR JOB IN FORCEF?
JRST [PUSHJ P,FLSDR## ;YES. WITH SHAREABLE DISK RESOURCE?
JRST (T2) ;NOT ANY MORE. DON'T RUN HIM
TLZ F,JXPN ;YES. IGNORE JXPN (SOMEONE ELSE
; MUST HAVE EXPANDED OUR HIGH SEG)
JRST SCHDC1 ;CONTINUE
]
SCHDC1: ;EITHER NOT IN FORCEF, OR IS AND HAS
; RESOURCE, IN WHICH CASE JXPN CLEARED IN F
>
IFN FTLOCK,<
TRNN F,LOK ;DON'T RUN JOB CURRENTLY BEING LOCKED IN CORE
> ; END OF CONDITIONAL ASSEMBLY ON FTLOCK
TLNE F,SWP+SHF+JXPN+JRQ ;MONITOR WAITING FOR I/O TO STOP,
; OR JOB EXPANDING CORE?
; OR JOB NEEDS REQUEING (SWAP READ ERROR)?
JRST (T2) ;YES--CONTINUE SCAN,JOB CANNOT BE RUN
IFN FTKL10&FTMS,<
PUSHJ P,SCDCSH## ;IS THIS JOB RUNNABLE WITH RESPECT TO THE
; CACHE?
JRST (T2) ;NO, GO FIND ANOTHER JOB TO RUN
; NOTE THAT THIS IS DONE AFTER LOST
; TIME FLAG IS SET SO THAT CACHE LOST
; TIME IS INCLUDED IN SYSTEM LOST TIME
>;END IFN FTKL10&FTMS
CAMN J,FORCEF ;FORCING A GUY WITH SHARABLE RESOURCE?
AOS FORCFC## ;YES, COUNT A FORCED SCHEDULE
IFN FTNSCHED,<
SETZM .CPSQF##(P4) ;ASSUME NOT FROM SUBQUE
SKIPGE JBTSCD##(J) ;IN PQ2 (AND THEREFORE SUBQUEUE)?
SETOM .CPSQF##(P4) ;YES, TELL CLOCK1
> ;END IFN FTNSCHED
IFN FTRSP,< ;RESPONSE DATA?
MOVEI T1,.CPACR##(P4) ;BASE ADR FOR CPU RESPONSE DATA THIS CPU
MOVSI T2,(JR.RCR) ;RECORDED CPU RESPONSE FOR THIS JOB
PUSHJ P,RSPREC## ;RECORD RESPONSE TIME (UNLESS ALREADY REC)
MOVE T1,.CPACR##(P4) ;STORE DATA IN
MOVE T2,.CPACR##+1(P4) ; THE WRONG
MOVEM T1,.CPODA##(P4) ; PLACE FOR
MOVEM T2,.CPODA##+1(P4) ; OLD CUSPS
; (DO NOT RECORD AS ONE OF TI, TO, RN, ALSO)
> ; END OF CONDITIONAL ASSEMBLY ON FTRSP
SETZM .CPPLT##(P4) ;CLEAR POTENTIALLY LOST TIME AS A USER IS TO BE RUN
IFN FTKL10&FTMS,<
SETZM .CPCLF##(P4) ;CLEAR CACHE LOST FLAG ALSO
>;END IFN FTKL10&FTMS
MOVEI T1,JS.SCN ;AND MAKE SURE HE GETS SCANNED BIT SET
IORM T1,JBTST2##(J) ;SINCE MAY NOT HAVE COME FROM QSCAN
MOVE T2,.CPSUD##(P4) ;GET START OF SCAN TABLE USED
CAME T2,.CPSCN##(P4) ;WAS IT PRIMARY SCAN?
POPJ P, ;NO. IT WAS FAIRNESS SCAN
CAMGE U,FSCN##(T2) ;DID THIS SCAN REACH FAIR TERRITORY
AOSA .CPSFC##(P4) ;NO, COUNT UP UNFAIR SCANS
SETZM .CPSFC##(P4) ;YES, CLEAR SCHED FAIRNESS
POPJ P, ;RETURN
SCHD1:
IFE FTMS,<
SKIPE .CPPLT(P4) ;ALREADY LOST TIME?
JRST SCHDN ;YES.
>
MOVEI U,LSCAN## ;NO. SEE IF SHOULD BE
JSP T1,QSCAN
JRST SCHDN ;NO MORE JOBS
IFN FTMS,<
SKIPE .CPPLT(P4) ;SINCE DXRUN MAY SET .CPPLT, CHECK IT FIRST
JRST SCHDN ;IT GOT SET
PUSHJ P,DXRUN## ;SEE IF CAN RUN ON THIS CPU
JRST (T2) ;CAN'T. MAY SET .CPPLT
>
MOVSI T3,WTMASK ;ZERO STATE CODE?
TDNE T3,JBTSTS(J) ;...
JRST (T2) ;NO. TRY NEXT
MOVEM J,.CPPLT(P4) ;YES. LOST TIME
SCHDN: SETZB J,.CPSFC(P4) ;RETURN NULL JOB
POPJ P,
; THIS SUBROUTINE DETERMINES HOW TO REQUE THE JOB
QREQ: MOVE T2,JBTSTS##(J) ;JOB STATUS WORD
TDNE T2,[JDC+JS.DEP+(CMWB)] ;ANY STRANGE BITS ON?
JRST QREQ1 ;YES, GO DO SOME SPECIAL THINGS
QREQ0: LDB U,PJBSTS## ;GET QUEUE CODE
JUMPGE T2,QSTOPT ;IS RUN BIT ON? IF NOT, JOB GOES TO STOP Q.
IFN FTMS,<
PUSHJ P,MSRQT## ;GO CHECK IF JOB COMING OUT OF WS,TS, OR DS
; (SETS UUO COUNTER IN CASE JOB WAS DOING
; I/O UUO THAT STARTED ON SLAVE AND GOT
; SWITCHED TO MASTER.
>
HLRZ T1,QBITS(U) ;GET DISPATCH ADDRESS FOR REQUE METHOD
JRST (T1)
QREQ1: MOVEI U,QCMW ;ASSUME COMMAND WAIT
TLNN T2,CMWB ;IS JOB IN COMMAND WAIT?
JRST QREQ2 ;NO--WAIT STATE CODE DETERMINES NEW QUEUE
TLNE T2,SWP+JXPN ;YES--IS JOB ON DISK, OR TRYING TO EXPAND?
JRST QXFER ;YES--PUT JOB IN COMMAND WAIT QUEUE
QREQ2:
IFN FTDAEM,<
MOVEI U,JDCQ ;ASSUME DAEMON WAIT
TRNN T2,JDC!JS.DEP ;IS IT?
JRST QREQ0 ;NO, JUST REQUEUE BY STATE CODE
TRNE T2,JS.DEP ;ERROR LOGGING? (JDC IS BY REQUEST ONLY)
PUSHJ P,FLSDR## ;YES. PUT IN DAEMON QUEUE IF JOB HAS NO RESOURCES.
JRST QJDCT ;OWNS NO RESOURCE, SO TRANSFER AND ZERO ICPT
;HAS A RESOURCE, DON'T PUT HIM IN JDCQ
>
JRST QREQ0 ;REQUEUE BY STATE CODE
DEFINE X(A,B,C)
< XLIST
Q'A'T==QREQ6
Q'A'W==-1
LIST
>
RWAITS
QIOWT==QREQ6
QDIOWT==QREQ6
QPIOWT==QREQ6
QNAPT==QREQ6 ;IN CASE OF CONTROL C WHILE IN NAP, ETC.
REPEAT 0,<IFN FTVM,<
QPST: SKIPL JBTST2##(J) ;IS JOB IN A RUN QUEUE?
PUSHJ P,QCHNG ;NO. PUT HIM INTO A RUN QUEUE
CAMN J,VMQJOB## ;HAS JUST THIS JOB EXCEEDED PAGE RATE?
JRST QPST1 ;YES. REQUE TO REAR
SKIPGE VMQJOB ;SYSTEM PAGE RATE EXCEEDED?
SKIPN SLECNT## ;SOMEONE WANT TO USE THE SWAPPING/PAGING CHANNEL?
JRST QPSTN ;NO
QPST1: PUSHJ P,FNDPDB ;NEED PDB
JRST QPSTN ;...
SKIPGE .PDIPT##(W) ;DON'T REQUE UNTIL SWAPPABLE, ELSE CORE WILL BE
;JAMMED WITH VIRTUAL JOBS WHICH WON'T RUN
PUSHJ P,TOBACK ;PUT TO REAR OF QUEUES, DON'T RESET Q.R.T.
JRST QPSTN ;AND FALL INTO NORMAL QUEUE TRANSFER
>;END IFN FTVM
>;END REPEAT 0
IFN FTNSCHED,<
QRNT: MOVSI T2,(JS.CSQ) ;CHANGING SUB QUEUE?
TDNE T2,JBTST2##(J) ;...
SKIPL JBTSCD##(J) ;AND STILL IN PQ2?
JRST QREQ3 ;NO. NORMAL REQUE
JRST QREQX ;YES. JUST FIX SUBQUE
>
QPST:
QWST:
QDST: SKIPL JBTST2##(J) ;IS JOB IN A RUN QUEUE?
PUSHJ P,QCHNG ;NO. PUT HIM IN A RUN QUEUE
QPSTN: MOVSI T1,WTMASK ;CLEAR WAIT STATE CODE
ANDCAM T1,JBTSTS##(J)
JRST QREQX ;AND EXIT QREQ. (NO QUE TRANSFER)
QTST: MOVSI T1,WTMASK ;CLEAR WAIT STATE
ANDCAM T1,JBTSTS##(J)
; JRST QREQ3 ;AND PERFORM QUEUE TRANSFER
IFE FTNSCHED,<
QRNT:
>
QSLPT:
QEWT:
QREQ3: HRRZ U,QBITS(U) ;PICK UP TRANSFER TABLE ADDRESS
PUSHJ P,QXFER ;REQUE THE JOB
JRST QREQX ;AND EXIT QREQ.
QSTOPT: CAIE U,NULQ ;IS HE REALLY GOING TO THE NULL Q?
MOVEI U,STOPQ ;NO. STOP QUE
; JRST QREQZ ;ZERO ICPT AND REQUE
QNULT:
QJDCT:
QTIOWT:
QREQZ: PUSHJ P,ZERIPT ;ZERO ICPT
JRST QREQ3 ;DO THE REQUE
QREQ6: SKIPL JBTST2##(J) ;IS JOB IN RUN QUEUE?
PUSHJ P,QCHNG ;NO. PUT IT IN RUN QUEUE
QREQX:
IFN FTNSCHED,<
MOVSI T2,(JS.CSQ) ;GET "CHANGED SUB QUE" BIT
TDNN T2,JBTST2##(J) ;DID HE?
POPJ P, ;NO. EXIT QREQ.
ANDCAM T2,JBTST2##(J) ;YES. CLEAR BIT
SKIPGE JBTSCD##(J) ;STILL IN PQ2 AFTER OTHER REQUE CODE?
PUSHJ P,TOBACK ;PUT HIM TO BACK OF SUBQUE(AND PQ2)
>
POPJ P, ;EXIT QREQ.
; SUBROUTINE TO PUT JOB INTO A RUN QUEUE.
; DESTROYS U,T1,T2,R,W. SAVES J
QCHNG: MOVEI U,QRNW1 ;PUT IN BACK OF PQ1
PJRST QXFER ;WITHOUT ASSIGNING QUANTUM TIME
; ROUTINE TO SET ICPT. J AND W MUST BE SET UP AND PDB MUST EXIST
; PRESERVES ALL ACS
SETIPT::PUSH P,T1
MOVE T1,PROT1## ;MINIMUM ICPT FOR CYCLE TIME
LSH T1,-1 ;IPT IS DECREMENTED EVERY OTHER TICK
.DPB T1,PDYIPT##
JRST TPOPJ##
; ROUTINE TO CLEAR ICPT. SET UP W. NEEDS J
; PRESERVES ALL ACS EXCEPT W
ZERIPT::PUSHJ P,FNDPDB## ;FIND PDB
POPJ P, ;NO PDB. NOTHING TO DO.
; PJRST CLRIPT ;FALL INTO CLRIPT
; ROUTINE TO SET BIT TO EXPIRE ICPT
; PRESERVES ALL ACS
CLRIPT::PUSH P,T1
MOVSI T1,PDMSWP ;SWAPPABLE BIT
.IORM T1,.PDIPT##(W) ;SET IT
PJRST TPOPJ##
; SAME AS CLRIPT BUT EXPECTS PDB ADDRESS IN T1
CLRIP1::PUSH P,T2
MOVSI T2,PDMSWP ;SWAPPABLE BIT
.IORM T2,.PDIPT##(T1) ;SET IT
PJRST T2POPJ##
; ROUTINE TO ASSIGN ICPT.
; DESTROYS T1,T2.
ASICPT::SKIPGE CORSCD ;CORE SCHEDULING?
PJRST CLRIPT ;NO, DON'T ASSIGN PROTECT TIME
PUSHJ P,JOBSIZ## ;COMPUTE SIZE OF JOB
MOVE T1,T2 ;PUT IN T1
IMUL T1,PROT## ;ADD VARIABLE AMOUNT DEPENDING ON CORE SIZE
ADD T1,PROT0## ;ADD FIXED AMOUNT INDEPENDENT OF CORE SIZE
ADDI T1,^D8333 ;CONVERT TO TICKS FROM US
IDIVI T1,^D16667 ;CONVERT TO TICKS
CAMLE T1,PROTM## ;IN LEGAL RANGE?
MOVE T1,PROTM## ;NO. USE MAXIMUM
LSH T1,-1 ;DECREMENTED EVERY OTHER TICK
.DPB T1,PDYIPT## ;SET IN-CORE PROTECT TIME.
POPJ P, ;RETURN
;SUBROUTINE TO PUT JOB TO BACK OF PQ2
; USES SAME REGISTERS AS QCHNG
IFN FTVM!FTNSCHED,<
TOBACK: MOVEI U,QRNW2 ;TRANSFER TABLE TO BACK OF PQ2, DONT
PJRST QXFER ;CHANGE QUANTUM RUN TIME.
>
; SUBROUTINE TO REQUEUE JOB AROUND THE RUN QUEUES
QARNDT:
LDB T1,PJBST2## ;GET REAL QUEUE
CAIN T1,PQ2 ;IS IT PQ2?
JRST QARND1 ;YES. REQUE CLEARING ICPT
LDB T1,PDYIPT ;NOT PQ2. ANY ICPT LEFT?
JUMPG T1,QARND2 ;IF ANY LEFT, DON'T CHANGE IT
QARND1: PUSHJ P,CLRIPT ;SET BIT FOR NO ICPT
PUSHJ P,SETIPT ;RESET ICPT SO JOB WILL CYCLE
QARND2:
MOVEI U,QTIME ;GET TRANSFER TABLE
PJRST QXFER ;DO TRANSFER
IFN FTPSCD,<
; ROUTINE TO COUNT NUMBER OF TIMES JOB EXPIRED IN CORE PROTECT BY QUE
CNTICP: PUSH P,T1 ;SAVE T1
LDB T1,PJBST2## ;GET PHYICAL STATE CODE
CAIN T1,PQ1 ;PQ1?
AOS XPICP1 ;YES
CAIN T1,PQ2 ;PQ2?
AOS XPICP2 ;YES
CAILE T1,PQ2 ;AN HPQ?
AOS XPICHP ;YES
JRST TPOPJ ;RESTORE T1 AND EXIT
; ROUTINE TO COUNT NUMBER OF TIMES JOB EXPIRED IN QUE TIME BY QUE
CNTINQ: PUSH P,T1 ;SAVE T1
LDB T1,PJBST2## ;GET PHYSICAL STATE CODE
CAIN T1,PQ1 ;PQ1?
AOS XPQRP1 ;YES
CAIN T1,PQ2 ;PQ2?
AOS XPQRP2 ;YES
CAILE T1,PQ2 ;AN HPQ?
AOS XPQRHP ;YES
JRST TPOPJ ;RESTORE T1 AND EXIT
$LOW
SCDPER:: ;PERFORMANCE STATS TABLE
%DTASL::BLOCK 1 ;DTA GENERATED SLEEPS
%MTASL::BLOCK 1 ;DTA GENERATED SLEEPS
%EWCNT::BLOCK 1 ;MTA GENERATED SLEEPS
%TISJB::BLOCK 1 ;TTY INPUT SATISFIED
%TOSJB::BLOCK 1 ;TTY OUTPUT SATISFIED
%PISJB::BLOCK 1 ;PTY INPUT SATISFIED
%POSJB::BLOCK 1 ;PTY OUTPUT SATISFIED
REQSS:: BLOCK 1 ;NUMBER OF REQUEUES FROM SS INTO PQ1
REQWK:: BLOCK 1 ;NUMBER OF REQUEUES FROM WAKE INTO PQ1
REQJSD::BLOCK 1 ;NUMBER OF REQUEUES FROM DAEMON SATISFIED INTO PQ1
REQPQ1: BLOCK 1 ;NUMBER OF OTHER REQUEUES INTO PQ1
XPQRP1: BLOCK 1 ;NUMBER OF JOBS IN PQ1 WHICH EXPIRED QUANTUM RUN TIME
XPQRP2: BLOCK 1 ;NUMBER OF JOBS IN PQ2 WHICH EXPIRED QUANTUM RUN TIME
XPQRHP: BLOCK 1 ;NUMBER OF JOBS IN HPQ WHICH EXPIRED QUANTUM RUN TIME
XPICP1: BLOCK 1 ;NUMBER OF JOBS IN PQ1 WHICH EXPIRED INCORE PROTECT
XPICP2: BLOCK 1 ;NUMBER OF JOBS IN PQ2 WHICH EXPIRED INCORE PROTECT
XPICHP: BLOCK 1 ;NUMBER OF JOBS IN HPQ WHICH EXPIRED INCORE PROTECT
SWPKP1: BLOCK 1 ;NUMBER OF K SWAPPED IN FOR PQ1 JOBS
SWPKP2: BLOCK 1 ;NUMBER OF K SWAPPED IN FOR PQ2 JOBS
SWPKHP: BLOCK 1 ;NUMBER OF K SWAPPED IN FOR HPQ JOBS
SWPJP1: BLOCK 1 ;NUMBER OF PQ1 JOBS SWAPPED IN
SWPJP2: BLOCK 1 ;NUMBER OF PQ2 JOBS SWAPPED IN
SWPJHP: BLOCK 1 ;NUMBER OF HPQ JOBS SWAPPED IN
RNTPQ1::BLOCK 1 ;TICKS CHARGED TO PQ1
RNTPQ2::BLOCK 1 ;TICKS CHARGED TO PQ2
RNTHPQ::BLOCK 1 ;TICKS CHARGED TO HPQS
%PQ1CM: BLOCK 1 ;NUMBER OF RESPONSES PQ1/CMQ SWAPPED IN
%P1CMT: BLOCK 1 ;TOTAL TICKS OF RESPONSE TIME PQ1/CMQ SWAP IN
%P1CM2: BLOCK 2 ;SUM SQUARES (TWO WORD INTEGER) PQ1/PQ2 SWAPPED IN
%WSTCN: BLOCK 1 ;NUMBER OF MEASUREMENTS OF WASTED CORE
%WSTPS: BLOCK 1 ;TOTAL WASTED CORE SUM (PAGES)
%WSTP2: BLOCK 2 ;SUM OF SQUARES (TWO WORD INTEGER) WASTED CORE
%PERLN==:<.-1-SCDPER>B26
BLOCK 10
$HIGH
CNTSWP: PUSH P,T1 ;SAVE ACS
PUSH P,T2
PUSH P,J
LDB T1,IMGIN ;GET INPUT SIZE
LDB T2,IMGOUT ;AND OUTPUT SIZE IN T2
CAMLE T1,T2 ;GET MINIMUM IN T1
MOVE T1,T2 ;T2 WAS SMALLER
LSH T1,P2KLSH## ;IN K
PUSHJ P,FITHPQ## ;GET LOW SEG NUMBER
LDB T2,PJBST2## ;GET PHYSICAL QUE
POP P,J ;RESTORE JOB
CAIN T2,PQ1 ;PQ1?
JRST CNTSP1 ;YES
CAIN T2,PQ2 ;PQ2?
JRST CNTSP2 ;YES
CAIG T2,PQ2 ;HPQ?
JRST CNTSXT ;NO. EXIT
ADDM T1,SWPKHP ;STORE K
CAIG J,JOBMAX ;LOWSEG?
AOS SWPJHP ;YES. COUNT A JOB
CNTSXT: POP P,T2
JRST TPOPJ ;RESTORE ACS
CNTSP1: ADDM T1,SWPKP1 ;COUNT K IN PQ1
CAIG J,JOBMAX ;LOWSEG?
AOS SWPJP1 ;YES. COUNT JOB
JRST CNTSXT ;EXIT
CNTSP2: ADDM T1,SWPKP2 ;COUNT K IN PQ2
CAIG J,JOBMAX ;LOWSEG?
AOS SWPJP2 ;YES. COUNT JOB
JRST CNTSXT ;EXIT
CNTWST: PUSH P,T1 ;SAVE SOME REGISTERS
PUSH P,T2
MOVE T1,WASTSZ ;GET AMOUNT OF WASTED CORE
ADDM T1,%WSTPS ;ADD TO SUM
MUL T1,T1 ;SQUARE IT
TLO T2,400000 ;PREVENT OVERFLOW
ADD T2,%WSTP2+1 ;ADD IN LOW ORDER WORD OF SUM SQUARE
TLZN T2,400000 ;OVERFLOW?
ADDI T1,1 ;YES. INCREMENT HIGH ORDER WORD
MOVEM T2,%WSTP2+1 ;STORE LOW ORDER WORD
ADDM T1,%WSTP2 ;ADD HIGH ORDER TO STORE
AOS %WSTCN ;INCREMENT COUNT
POP P,T2 ;RESTORE REGISTERS,
PJRST TPOPJ## ;AND RETURN
> ;IFN FTPSCD
SUBTTL QCSS R. KRASIN
;THIS ROUTINE MUST BE ASSEMBLED WITH THE CONFIGURATION
;TAPE TO DEFINE NUMBER OF JOBS
;THIS SECTION CONTAINS 2 ROUTINES FOR Q MANIPULATION
;AND NECESSARY TABLES FOR SPECIFING OPERATIONS PERFORMED
;BY THEM.
;STORAGE:
;EACH Q IS A RING STRUCTURED, FOWARD AND BACKWARD
;LINKED SRING LIST. THE "FIRST" LINK IN A Q IS
;A Q-HEADER POINTING TO THE FIRST AND LAST MEMBERS OF THE Q.
;A NULL Q HAS ONE LINK--THE Q-HEADER ITSELF. THE LINKS MAKING
;UP THE QS ARE CONTAINED IN A TABLE WITH NEGATIVE
;INDICIES USED FOR Q-HEADERS AND
;POSITIVE INDICIES USED FOR MEMBERS (JOBS). THUS ONLY ONE WORD
;PER LINK IS NECESSARY--ITS RELATIVE ADDRESS GIVES THE
;JOB NO. (OR Q NO. IF NEGATIVE) WHICH IT REPRESENTS WHILE
;ITS CONTENTS CONTAINS THE LINKING POINTERS. THESE
;POINTERS ARE ALSO RELATIVE INDICIES RATHER THAN
;ABSOLUTE ADDRESSES--RH(LINK)=FORWARD POINTER;
;LH(LINK)=BACKWARD POINTER.
;A JOB IS ASSUMED TO BE IN NO MORE THAN ONE Q AT A TIME, AND
;THE NULL JOB (JOB 0) DOES NOT APPEAR IN THE QS
;ROUTINES:
;BOTH ROUTINES ARE "TABLE DRIVEN" IN THE SENSE THAT THE
;CALLING ROUTINE PROVIDES THE ADDRESS OF A TABLE WHICH
;DEFINES THE SPECIFIC OPERATIONS TO BE PERFORMED.
EQFIX==QFIX+1B0
EQLNKZ==QLNKZ+1B0
QXFER:
IFN FTHALT,<
SKIPLE J ;TRYING TO REQUE JOB 0?
CAILE J,JOBMAX## ; OR IS THE JOB NUMBER OUT OF RANGE?
STOPCD .,STOP,RJZ, ;++REQUEUE JOB ZERO
; MESSED UP AND SYSTEM WILL HANG IF ALLOWED
> ; END OF CONDITIONAL ASSEMBLY ON FTHALT
MOVE R,1(U) ;GET TRANSFER TABLE ADDRESS
JRST @(U) ;DISPATCH
;DEST-Q AS FUNCTION OF JOB QUE, QUANTUM AS FUNCTION OF JOB SIZE
QLNKZ: PUSHJ P,JOBSIZ## ;GET SIZE OF JOB
SKIPL JBTST2##(J) ;IS JOB IN A RUN QUEUE?
STOPCD .,STOP,NTE, ;NOT PROCESSOR QUE. ERROR.
LDB T1,PJBST2## ;GET PHYSICAL QUEUE JOB IS IN NOW
ADD T1,1(U) ;ADD TABLE ADDRESS TO QUE NUMBER
HRRO R,0(T1) ;GET QUE HE GOES TO
HLRZ T1,0(T1) ;GET PARAMETERS FOR QUE HE IS GOING TO
SKIPGE 1(U) ;WANT QUANTUM TIME?
JRST QFIXED ;NO - ALL FIXED
PUSHJ P,CMPQRT ;COMPUTE THE QUANTUM RUN TIME
MOVEM T2,QNTRUN ;STORE IT FOR QFIX
HRLI R,QNTRUN ;AND TELL QFIX WHERE WE PUT IT
JRST QFIXED ;DO TRANSFER
$LOW
QNTRUN: 0
$HIGH
; CALL WITH JOBSIZ IN T2, QUE IN T1
; RETURNS QUANTUM RUN TIME IN T2. USES NO OTHER ACS
CMPQRT: SKIPE W,JBTPDB##(J) ;ADDRESS OF THE PDB
SKIPGE CORSCD ;CORE SCHEDULING?
JRST CMPQR1 ;NOT CORE SCHEDULING OR NO PDB
SKIPGE .PDIPT##(W) ;SWAPPABLE?
JRST CMPQR1 ;IF CYCLING IN CORE, NO INCREMENT FOR SIZE
IMUL T2,QMLTBL##(T1) ;SIZE * MULTIPLIER
PUSH P,T3 ;SAVE T3
IDIV T2,QRANGE## ;GET IN PROPER UNITS
POP P,T3 ;GET T3 BACK
ADD T2,QADTBL##(T1) ;ADD IN BASE AMOUNT FOR QUE
CAMLE T2,QMXTBL##(T1) ;LESS THAN MAXIMUM ALLOWED?
MOVE T2,QMXTBL##(T1) ;NO. USE MAXIMUM
POPJ P, ;RETURN
CMPQR1: MOVE T2,QADTBL##(T1) ;USE BASE QUANTUM FOR THIS QUEUE
POPJ P, ;RETURN
; CALL CMPQSI WHEN SWAP IN JOB IN PROCESSOR QUE TO ASSIGN QUANTUM RUN TIME
CMPQSI: PUSH P,T1 ;SAVE TWO ACS
PUSH P,T2
PUSHJ P,JOBSIZ## ;GET SIZE OF JOB
LDB T1,PJBST2## ;GET QUE HE IS IN
PUSHJ P,CMPQRT ;COMPUTE THE QUANTUM TIME
.DPB T2,PDYQNT## ;AND STORE IT
POP P,T2 ;RESTORE TWO ACS AND RETURN
PJRST TPOPJ
;FIXED DEST-Q
QFIX:
IFN FTHPQ,<
HRRZ T2,R ;PICK UP QUEUE
CAILE T2,-PQ1 ;IS IT A RUN QUEUE?
JRST QFIXED ;NO.
LDB T2,HPQPNT## ;YES. SHOULD IT GO TO A HPQ
JUMPE T2,QFIXED ;NO. DON'T DO ANYTHING
HRR R,QTTAB##-1(T2) ;YES. GET HPQ POSITION
SKIPL R ;WAS QUANTUM TIME REQUESTED?
HRLI R,QQSTAB##-1(T2) ;YES. GIVE QUANTUM TIME
> ; END OF CONDITIONAL ASSEMBLY ON FTHPQ
QFIXED: AOS RQCNT## ;COUNT A REQUEUE
IFN FTMETR,<
SKIPL T2,MP1## ;METER QUEUE XFERS?
JRST QFIXA ;NO
HRRI T1,(J) ;YES, GET JOB NR
HRLI T1,(R) ;AND QUEUE#
CAME J,MPDPAR##(T2) ;RIGHT JOB?
SKIPGE MPDPAR##(T2) ;OR WANT ALL JOBS?
PUSHJ P,@MPDPRA##(T2) ;YES, CALL POINT ROUTINE
QFIXA:
> ;END CONDITIONAL ON FTMETR
IFN FTNSCHED,<
SKIPL JBTSCD##(J) ;JOB CURRENTLY IN PQ2?
JRST QFIXB ;NO
MOVE T2,JBTCSQ##(J) ;DELETE FROM CORE/NO-CORE SUBQUEUES
MOVS T1,T2
HRRM T2,JBTCSQ##(T1) ;NEW FORWARD LINK
HRLM T1,JBTCSQ##(T2) ;AND BACK LINK
MOVSI T1,(JS.PQ2) ;CLEAR PQ2 BIT
ANDCAM T1,JBTSCD##(J) ;KEPT IN SCD DATA TABLE
PUSHJ P,DLJILS ;DELETE FROM JBTJIL
>;END IFN FTNSCHED
QFIXB: HRRE T1,R ;PICK UP QUEUE NUMBER
MOVM T1,T1 ;ABS VALUE
LDB T2,PJBST2## ;GET PHY QUE
IFE FTNSCHED,<
CAIN T2,PQ2 ;IN PQ2?
PUSHJ P,DLJILS ;YES, DELETE FROM JBTJIL
>
CAIN T2,PQ2 ;IN PQ2?
CAIE T1,PQ2 ;AND GOING TO PQ2?
PUSHJ P,DLOLST ;NO. DELETE FROM JBTOLS (IF IN IT)
DPB T1,PJBST2## ;STORE HIS NEW REAL QUEUE
IFN FTPSCD,<
CAIN T1,PQ1 ;TO PQ1?
AOSA REQPQ1 ;YES. COUNT IT
CAIN T1,CMQ ;OR CMQ?
PUSHJ P,[MOVSI T2,SWP ;SWAPPED OUT?
TDNE T2,JBTSTS(J) ;...
PUSHJ P,FNDPDB ;YES. GET PDB
POPJ P, ;NO OR NO PDB
MOVN T2,UPTIME ;STORE -TIME WE STARTED
MOVEM T2,.PDPST##(W) ;IN PDB FOR PERFORMANCE MEASURE
POPJ P,]
>
MOVSI T2,(JS.IPQ) ;PROCESS QUEUE BIT
ANDCAM T2,JBTST2##(J) ;ASSUME NOT GOING INTO ONE
CAIGE T1,PQ1 ;IS IT GOING INTO PROCESSOR QUEUE?
JRST QFIXC ;NO. GO ON
IORM T2,JBTST2##(J) ;YES. SET PROCESSOR QUEUE BIT
CAIE T1,PQ1 ;ARE WE PUTTING HIM INTO PQ1?
JRST QFIXC2 ;NO, SEE IF GOING INTO PQ2
PUSHJ P,FNDPDB## ;FIND PDB FOR THE JOB
JRST QFIXC ;IF NONE, DON'T CHANGE ICPT
SKIPGE .PDIPT##(W) ;IF THIS JOB IS NOT ELIGIBLE FOR SWAPPING,
;DON'T MAKE HIM SO PREMATURELY
PUSHJ P,SETIPT ;YES, RESET ICPT SO IT CYCLES CORRECTLY
JRST QFIXC ;JOIN PROCESSING
QFIXC2: CAIE T1,PQ2 ;ARE WE PUTTING HIM IN PQ2?
JRST QFIXC ;NO, GO ON
PUSHJ P,INOLST ;PUT JOB IN LIST TO SWAP OUT (IF NO ICPT)
IFN FTNSCHED,<
MOVSI T1,(JS.PQ2) ;SAY JOB IS NOW IN PQ2
IORM T1,JBTSCD##(J) ;FOR SKIPS
;HERE IF WE ARE PUTTING A JOB INTO PQ2. MUST ALSO PUT IT INTO
; A PARALLEL SUBQUEUE.
LDB T1,JBYCLS## ;YES, GET HIS CLASS NUMBER
MOVNI T1,1(T1) ;GET NEGATIVE INDEX TO JBTSQ
SKIPN JBTADR##(J) ;DOES JOB HAVE CORE?
SUBI T1,M.CLSN## ;NO. OFFSET POINTER
HLRZ T2,JBTCSQ##(T1) ;GET LAST JOB IN SUB QUEUE (CORE/NOCORE)
HRRM J,JBTCSQ##(T2) ;MAKE US LAST
HRLM J,JBTCSQ##(T1) ;AND MAKE OLD LAST POINT TO US
HRL T1,T2 ;T1 = OLD LAST MEMBER,,HEADER
MOVEM T1,JBTCSQ##(J) ;SAVE AS OUR JBTCSQ ENTRY
>;END IFN FTNSCHED
SKIPE JBTJIL##(J) ;ALREADY IN LIST?
JRST QFIXC ;YES
SKIPE JBTADR##(J) ;DOES HE HAVE CORE?
PUSHJ P,FNDPDB ;YES, GET PDB
JRST QFIXC ;SWAPPED OR NO PDB
SKIPGE .PDIPT##(W) ;ANY ICPT LEFT?
JRST QFIXC ;NO, HE STAYS OFF LIST
HLRZ T1,JBTJIQ## ;LAST JOB IN QUEUE
HRLM J,JBTJIQ## ;MAKE US LAST
HRRM J,JBTJIL##(T1) ;MAKE PREVIOUS LAST POINT TO US
HRLOM T1,JBTJIL##(J) ;OLD LAST,,HEADER
QFIXC: MOVE T1,JBTCQ(J) ;DELETE JOB FROM CORE/NO-CORE QUE
MOVS T2,T1
HRLM T2,JBTCQ(T1) ;BACK. LINK SUCCESSOR
HRRM T1,JBTCQ(T2) ;FOR. LINK PREDECESSOR
SKIPL (U) ;TRYING TO REQUEUE TO BEGINNING OF QUEUE?
STOPCD (.,STOP,RBQ) ;++REQUEUEING TO BEGINNING OF QUEUE
HRRE T2,R ;END. INSERT IN CORE/NO-CORE QUE
SKIPN JBTADR(J) ;ANY CORE ASSIGNED?
SUBI T2,MXQUE## ;NO. NO-CORE QUEUE
HLRE T1,JBTCQ(T2) ;GET LAST JOB IN QUEUE
HRLM J,JBTCQ(T2) ;NOW WE ARE LAST
HRRM J,JBTCQ(T1) ;AND OLD LAST POINTS FORWARD TO US
HRL T2,T1 ;OLD LAST,,HEADER
MOVEM T2,JBTCQ(J) ;IS OUR POINTER
JUMPL R,QX3
IFE FTPDBS,< ;IF WE DO NOT SWAP PDB'S
HLRZ U,R ;GET QUANTUM TIME ADDRESS FOR DPB
MOVE U,(U) ;GET QUANTUM TIME
SKIPN W,JBTPDB##(J) ;GET PDB ADR
STOPCD .,STOP,NPC, ;++NO PDB IN CORE
.DPB U,PDYQNT## ;STORE QUANTUM RUN TIME
> ;END CONDITIONAL ON FTPDBS
IFN FTPDBS,< ;IF WE SWAP PDB'S
HLRZ T1,R ;SET UP QUANTUM RUN TIME ADDRESS
MOVE T1,(T1) ;GET QUANTUM TIME
PUSHJ P,SETQNT## ;STORE IN PDB
> ;END CONDITIONAL ON FTPDBS
QX3: POPJ P, ;RETURN
;ROUTINE TO MOVE JOB FROM "JOB HAS CORE" QUE TO "JOB DOES NOT" QUE
; IF JOB ALREADY HAS NO CORE, ROUTINE DOES NOTHING
; ALL ACS PRESERVED
DICLNK::CAIG J,JOBMAX## ;LOW SEGMENT?
SKIPN JBTADR(J) ;YES. HAVE CORE?
POPJ P, ;NO
PUSHJ P,DCCLNK ;YES. DELETE FROM CORE QUE (AND SUB-QUE)
LDB T1,PJBST2## ;GET CURRENT PHYSICAL QUE NUMBER
MOVNI T1,MXQUE##(T1) ;NEG OF (QUE NUM + OFFSET)
PUSHJ P,ICCLNK ;PUT IN NO-CORE QUE
IFN FTNSCHED,<
SKIPL JBTSCD##(J) ;IN PQ2?
POPJ P, ;NO. DONE
LDB T1,JBYCLS## ;YES. GET CLASS NUMBER
MOVNI T1,M.CLSN##+1(T1) ;NEG OF (CLASS NUMBER + OFFSET)
PUSHJ P,ICSLNK ;PUT IN NO-CORE SUB QUEUE
>
POPJ P, ;DONE. RETURN
;SUBROUTINE TO MOVE JOB FROM "NO CORE" QUE TO "JOB HAS CORE" QUE
; IF JOB ALREADY HAS CORE, ROUTINE DOES NOTHING
; ALL ACS PRESERVED
IICLNK::CAIG J,JOBMAX## ;LOW SEGMENT?
SKIPE JBTADR##(J) ;YES. NO CORE?
POPJ P, ;NO. RETURN
PUSHJ P,DCCLNK ;DELETE FROM NO-CORE QUE (AND SUB-QUE)
LDB T1,PJBST2## ;GET PHYSICAL QUEUE NUMBER
MOVNI T1,(T1) ;NEGATE
PUSHJ P,ICCLNK ;INSERT IN CORE QUE
IFN FTNSCHED,<
SKIPL JBTSCD##(J) ;IN PQ2?
POPJ P, ;NO. DONE
LDB T1,JBYCLS## ;GET CLASS NUMBER
MOVNI T1,1(T1) ;NEGATE AND OFFSET
PUSHJ P,ICSLNK ;PUT IN CORE SUB QUE
>
POPJ P, ;RETURN
DCCLNK: CPLOCK (SCD) ;LOCK THE SCHEDULER
EXCH T1,(P) ;SAVE T1 ON LIST
PUSH P,T2 ;AND T2
MOVEM T1,1(P) ;AND PUT CALLER BACK ON LIST
MOVE T1,JBTCQ(J) ;GET JOBS POINTERS
MOVS T2,T1 ;SWAP HALVES
HRRM T1,JBTCQ(T2) ;MAKE LAST POINT TO NEXT
HRLM T2,JBTCQ(T1) ;AND NEXT POINT TO LAST
IFN FTNSCHED,<
SKIPL JBTSCD##(J) ; IN PQ2?
JRST DCCLN1 ;NO
MOVE T1,JBTCSQ##(J) ;LINK AROUND JOB
MOVS T2,T1
HRRM T1,JBTCSQ(T2) ;MAKE LAST POINT TO NEXT
HRLM T2,JBTCSQ(T1) ;AND NEXT POINT TO LAST
DCCLN1:>
PUSHJ P,@1(P) ;GO BACK TO CALLER WITH T1,T2 SAVED,
;AND SCHED LOCKED
CAIA ;NON-SKIP RETURN
AOS -2(P) ;SKIP RETURN
CPUNLK (SCD) ;UNLOCK SCHEDULER
POP P,T2 ;RESTORE T2
PJRST TPOPJ ;AND T1 AND RETURN
ICCLNK: HLRZ T2,JBTCQ(T1) ;GET LAST JOB IN QUEUE
HRLM J,JBTCQ(T1) ;MAKE SELF LAST
HRRM J,JBTCQ(T2) ;MAKE OLD LAST POINT TO US
HRL T1,T2 ;MAKE US POINT TO OLD LAST,,END
MOVEM T1,JBTCQ(J) ;AND STORE IT
POPJ P,
IFN FTNSCHED,<
ICSLNK: HLRZ T2,JBTCSQ##(T1) ;GET LAST IN SUB QUE
HRLM J,JBTCSQ(T1) ;MAKE US LAST
HRRM J,JBTCSQ(T2) ;MAKE OLD LAST POINT TO US
HRL T1,T2 ;MAKE US POINT TO OLD LAST,,END
MOVEM T1,JBTCSQ(J) ;AND STORE IT
POPJ P,
>
; SUBROUTINE TO INSERT A JOB IN OUTPUT SCAN LIST, IF NOT THERE AND SHOULD BE
INOLST: CAIG J,JOBMAX ;HIGHSEG?
SKIPE JBTOLS##(J) ;OR ALREADY IN LIST?
POPJ P, ;YES. RETURN
PUSH P,T1 ;SAVE T1
SKIPE JBTADR##(J) ;DOES HE HAVE CORE?
PUSHJ P,FNDPDB ;YES. GET PDB
PJRST TPOPJ ;NO OR NO PDB
SKIPL .PDIPT##(W) ;ELIGIBLE TO SWAP OUT?
PJRST TPOPJ ;NO. DOESN'T GO ON LIST
MOVSI T1,(JS.BBJ) ;BACKGROUND BATCH BIT
TDNE T1,JBTST2##(J) ;IS JOB IN BACKGROUND BATCH?
SKIPA T1,[EXP MOBQ##] ;YES, PUT HIM IN BB OUTPUT LIST
MOVNI T1,OLQ## ;NO, PUT HIM IN REGULAR OUTPUT LIST
HLL T1,JBTOLS##(T1) ;GET LAST JOB IN QUEUE
HRLM J,JBTOLS##(T1) ;MAKE US LAST
MOVEM T1,JBTOLS##(J) ;POINT TO OLD LAST,,HEADER
MOVS T1,T1 ;GET POINTER TO OLD LAST
HRRM J,JBTOLS##(T1) ;MAKE US SUCCESSOR TO PREVIOUS LAST
PJRST TPOPJ ;AND RETURN
; SUBROUTINE TO DELETE JOB FROM OUTPUT SCAN LIST
DLOLST: PUSH P,T1 ;SAVE T1
CAIG J,JOBMAX ;HIGH SEG?
SKIPN T1,JBTOLS##(J) ;YES. IN LIST?
PJRST TPOPJ ;HIGH SEG OR NOT IN LIST. RETURN
SETZM JBTOLS##(J) ;NOT IN LIST ANY MORE
HLLM T1,JBTOLS##(T1) ;LINK AROUND
MOVS T1,T1
HLRM T1,JBTOLS##(T1)
PJRST TPOPJ
; SUBROUTINE TO DELETE JOB FROM JUST INPUT LIST
DLJILS: PUSH P,T1 ;SAVE T1
CAIG J,JOBMAX ;HIGH SEG?
SKIPN T1,JBTJIL##(J) ;IN LIST?
PJRST TPOPJ ;NO, RETURN
SETZM JBTJIL##(J) ;NOW HE'S NOT
HLLM T1,JBTJIL##(T1) ;LINK AROUND HIM
MOVS T1,T1
HLRM T1,JBTJIL##(T1)
PJRST TPOPJ
;SCANS THE QS RETURNING THE NUMBERS OF THE JOBS IN THE QS.
;THE ORDER AND MANNER IN WHICH THE QS ARE SEARCHED IS
;DETERMINED BY A "SCAN TABLE" ADDRESSED IN THE CALLING SEQ.
;THE SCAN TABLE HAS THE FORM:
;
;SCANTAB: XWD <Q1>,<CODE1> ;SCN Q1 ACCRDING TO CODE1
; ...
; XWD <QN>,<CODEN> ;QN ACCORDING TO CODEN
; Z ;ZERO TERMINATES TABLE
;
;EACH Q MAY BE SCANNED IN ONE OF SEVERAL WAYS SPECIFIED BY <CODE>
;THE CODES ARE:
;
;?QFOR SCAN Q FORWARD
;?QFOR1 SCAN FOR ONLY THE 1ST MEMBER (IF ANY)
;?QBAK SCAN Q BACKWARD
;?QBAK1 SCAN BACKWARD FOR ALL MEMBERS EXCEPT THE 1ST
;?RRFOR SCAN THE JUST SWAPPED IN QUEUE
; THEN SCAN THE ROUND ROBIN QUEUE
;?SSFOR SCAN SUBQUEUES FORWARD ACCORDING TO SSSCAN TABLE IF RRFLAG .NE. 0,
; ELSE SCAN PQ2 VIA ?QFOR ROUTINE
;?BBFOR SCAN THE BACKGROUND BATCH JUST SWAPPED IN QUEUE
; THEN SCAN THE BACKGROUND BATCH QUEUE
;SQFOR SCAN SUBQUEUES FORWARD ACCORDING TO SQSCAN TABLE IF RRFLAG .NE. 0,
; ELSE SCAN PQ2 VIA OQFOR ROUTINE
;BQFOR SCAN THE BACKGROUND BATCH QUEUE
;
; WHERE ? MAY BE "O" FOR JOBS WITH NO CORE, "I" FOR JOBS WITH CORE,
; OR NULL FOR ALL JOBS(IN WHICH CASE "HAS CORE" IS CONSIDERED
; TO BE AHEAD OF "NO CORE").
;
;CALLING SEQ.
;
; MOVEI U,SCAN TABLE ADDRESS
; JSP T1,QSCAN ;SET UP PC FOR REPEATED RETURNS
; ... ;RETURN HERE WHEN NO MORE JOBS
; ... ;RETURN HERE WITH NEXT JOB IN AC J
;
; PERFORM ANY NECESSARY TESTING OF THIS JOB
; J,U,T1,T2 MUST BE PRESERVED
;
; JRST (T2) ;RETURN TO QSCAN TO GET NEXT JOB
; ; IF THIS ONE NOT ACCEPTABLE
;
;MAJOR QUEUE SCAN ROUTINE
QSCAN:: SKIPN T2,(U) ;END OF SCAN TABLE?
JRST (T1) ;YES--RETURN TO CALL+1
HLRE J,T2 ;NO--GET NO. OF Q
JRST (T2) ;DISPATCH
;ROUTINES TO SCAN BOTH INCORE AND OUTCORE CHAINS
QFOR:: HRRE J,JBTCQ##(J) ;SCAN FORWARD ALL JOBS
JUMPG J,1(T1) ;RETURN THIS JOB NUMBER UNLESS END OF LIST
HLRE J,(U) ;GET IN-CORE HEADER
SUBI J,MXQUE## ;CHANGE TO NO-CORE HEADER
MOVEI T2,QFOR2
QFOR2: HRRE J,JBTCQ##(J) ;SCAN FORWARD ALL JOBS
JUMPG J,1(T1) ;JUMP IF GOOD JOB #
AOJA U,QSCAN ;END OF THIS Q--GET NEXT Q
QBAK:: SUBI J,MXQUE## ;ADJUST TO NO-CORE HEADER
MOVEI T2,QBAK2 ;RETURN ADDRESS
QBAK2: HLRE J,JBTCQ##(J) ;SCAN BACKWARD ALL JOBS
JUMPG J,1(T1) ;RETURN CALL+2 WITH JOB NO.
HLRE J,(U) ;GET IN-CORE HEADER
MOVEI T2,QBAK3 ;RETURN ADDRESS
QBAK3: HLRE J,JBTCQ##(J) ;GET NEXT JOB NO.
JUMPG J,1(T1) ;RETURN IF GOOD JOB
QSCANX: AOJA U,QSCAN ;BEG OF THIS Q--GET NEXT Q
;ROUTINES TO SCAN ONLY INCORE OR OUTCORE CHAIN
OQFOR1::SUBI J,MXQUE## ;TAMPER WITH INDEX SO USES NO-CORE HEADERS
;FIRST OF NO-CORE QUEUE
IQFOR1::MOVEI T2,IQFOR2 ;ONLY THE FIRST JOB
IQFOR:: HRRE J,JBTCQ##(J) ;SCAN FORWARD ALL JOBS
JUMPG J,1(T1) ;RETURN THIS JOB NUMBER CALL+2 UNLESS--
IQFOR2: AOJA U,QSCAN ;END OF QUEUE--GET NEXT QUEUE
FOQFOR::SETOM SWPFAR ;SWAPPER REACHED FAIR TERRITORY
OQFOR:: MOVEI T2,IQFOR ;ALL OF NO-CORE QUE FORWARD
SUBI J,MXQUE## ;TAMPER WITH INDEX SO USES NO-CORE HEADERS
JRST IQFOR ;AND USE OTHER CODE
OQBAK1::MOVEI T2,IQBAK1 ;ALL BUT FIRST OF NO-CORE
SUBI J,MXQUE## ;TAMPER WITH INDEX TO GET NO-CORE HEADERS
IQBAK1::HLRE J,JBTCQ##(J) ;ALL BUT FIRST OF HAS-CORE
SKIPLE JBTCQ##(J) ;FIRST JOB IN QUEUE?
JRST 1(T1) ;NO. RETURN THIS JOB
AOJA U,QSCAN ;YES. GET NEXT QUEUE
OQBAK:: MOVEI T2,IQBAK ;ALL JOBS BACKWARDS
SUBI J,MXQUE## ;FORM NO-CORE QUEUE HEADERS
IQBAK:: HLRE J,JBTCQ##(J) ;GET JOB
JUMPG J,1(T1) ;RETURN IT +2
AOJA U,QSCAN ;GET NEXT QUEUE. NO JOB
IFN FTNSCHED,<
;PQ2 CLASS SWAPIN SCAN
FSQFOR::SETOM SWPFAR ;SWAPPER REACHED FAIR TERRITORY
SQFOR:: SKIPG RRFLAG## ;ANY NON-ZERO CLASSES?
JRST OQFOR ;NO CLASSES DEFINED (OQFOR SETS UP T2)
MOVEI T2,SQFORA ;RETURN ADDRESS FOR MORE JOBS, IF ANY
SOSG SQCNT## ;ANY ENTRIES LEFT IN PRIMARY SCAN TABLE?
PUSHJ P,SQINI ;NO, RECYCLE TO FRONT OF PRIMARY TABLE
ILDB J,SQPNT## ;GET NEXT PRIMARY SUBQUEUE
SETCAM J,SQSAVJ## ;SAVE THE QUEUE WE ALREADY CHECKED
MOVNI J,M.CLSN##+1(J) ;NO-CORE HEADER FOR THIS SUB-QUEUE
SQFORA: HRRE J,JBTCSQ##(J) ;GET NEXT JOB IN QUEUE
JUMPG J,1(T1) ;RETURN TO CALL+2 IF HAVE A JOB
SETZB M,SQSUM## ;ZERO COUNT AND SUM
SETCM T2,MAXQTA## ;HEADER OFFSET FOR HIGHEST CLASS WITH QTA
SQFOR1: SKIPLE JBCSOH##(T2) ;ANYONE IN THIS CLASS WITHOUT CORE?
CAMN T2,SQSAVJ## ;YES, CHECKED THIS CLASS ALREADY?
JRST SQFOR2 ;NO ONE IN CLASS OR THIS IS PRIMARY CLASS
SETCM J,T2 ;POSITIVE CLASS NUMBER
SKIPL CLSSTS##(J) ;FIXED CLASS?
SKIPG T3,CLSQTA##(J) ;ANY SECONDARY QUOTA?
JRST SQFOR2 ;EITHER FIXED OR NO SECONDARY
ADDM T3,SQSUM## ;SUM OF ALL PERCENTS
HRL T3,T2 ;-CLASS,,QUOTA
MOVEM T3,SQSCAN##(M) ;STORE IN TABLE
AOJ M, ;BUMP COUNT OF SUBCLASSES
SQFOR2: AOJL T2,SQFOR1 ;REPEAT FOR ALL SUBCLASSES
SOJLE M,SQFOR6 ;JUMP IF ZERO OR ONE CLASSES
SQFOR3: PUSHJ P,RAND ;GET A RANDOM NUMBER IN T2
IDIV T2,SQSUM## ;MODULO SQSUM
MOVE J,M ;INITIALIZE LOOP COUNTER
SQFOR4: HRRZ T2,SQSCAN##(J) ;GET THIS CLASSES QUOTA
SUB T3,T2 ;SUBTRACT FROM RANDOM NUMBER
JUMPL T3,.+2 ;IF NEGATIVE, THIS IS THE ONE WE WANT
SOJG J,SQFOR4 ;TRY NEXT CLASS
MOVE T2,SQSCAN##(M) ;MOVE THE TOP ENTRY
EXCH T2,SQSCAN##(J) ;DOWN ONTO THE ONE WE SELECTED
HLRE J,T2 ;GET HEADER OFFSET FOR THIS CLASS
MOVNI T2,(T2) ;SUBTRACT THIS CLASS'S QUOTA...
ADDM T2,SQSUM## ;... FROM TOTAL
SQFOR5: SUBI J,M.CLSN## ;ADJUST TO NO-CORE HEADER
MOVEI T2,SQFORB ;ADDRESS OF SCAN ROUTINE
SQFORB: HRRE J,JBTCSQ##(J) ;GET NEXT JOB IN SUB-Q
JUMPG J,1(T1) ;SKIP RETURN IF GOOD JOB NUMBER
SOJG M,SQFOR3 ;ELSE SELECT NEXT SUB-Q
SQFOR6: JUMPL M,QSCANX ;IF ALL CLASSES WERE TRIED, TRY BACKGROUND BATCH
HLRE J,SQSCAN## ;SETUP FOR THE LAST CLASS
JRST SQFOR5 ;GO TRY IT
;BACKGROUND BATCH SWAPIN SCAN
BQFOR:: SKIPG RRFLAG## ;CLASS SCHEDULING?
AOJA U,QSCAN ;NO
MOVE T2,UPTIME## ;CURRENT TIME IN TICKS
SKIPL J,BBSUBQ## ;IS THERE A BB CLASS DEFINED?
CAMGE T2,SCNBBS## ;IS IT TIME TO SWAP A BB JOB YET?
AOJA U,QSCAN ;NOT YET
MOVNI J,M.CLSN##+1(J) ;HEADER FOR B B QUEUE
JRST BBFOR2 ;SCAN B B QUEUE
;ROUTINES USED BY PQ2 CLASS SWAPIN SCAN
SQINI: MOVEI T3,^D100 ;100 ENTRIES
MOVEM T3,SQCNT## ;REINITIALIZE COUNT
MOVE T3,[POINT 5,PSQTAB##]
MOVEM T3,SQPNT## ;RESET BYTE POINTER
POPJ P,
SQTEST: SKIPG RRFLAG## ;ACTUALLY CLASS SCHEDULING?
POPJ P, ;NO
PUSH P,T1 ;SAVE T1
AOS T1,SCNSWP## ;INCREMENT # TIMES THIS PRIMARY SUBCLASS SCANNED
CAMGE T1,SCDSWP## ;SCANNED IT OFTEN ENOUGH?
JRST SQTES1 ;NO, RESET PRIMARY SCAN POINTERS
SETZM SCNSWP## ;YES, ALLOW SQFOR TO GO ON TO THE NEXT CLASS
JRST TPOPJ## ;AND RETURN
SQTES1: AOS SQCNT## ;MOVE THE PRIMARY TABLE POINTER BACK ONE
IFN FTKI10!FTKL10,<
MOVSI T1,(5B5) ;SIMULATE A DBP
ADDM T1,SQPNT## ;DECREMENT BYTE POINTER
>
IFN FTKA10,<
HLRZ T1,SQPNT## ;LEFT HALF OF POINTER
ADDI T1,(5B5) ;SIMULATE A DBP
HRLM T1,SQPNT## ;RESTORE BYTE POINTER
>
JRST TPOPJ## ;RETURN
>;END IFN FTNSCHED
;RANDOM NUMBER GENERATOR
RAND:: MOVE T2,SEED## ;GET THE LAST PSEUDO-RANDOM NUMBER
MULI T2,377775 ;MULTIPLICATIVE MOD 2**35
MOVEM T3,SEED## ;SAVE THE CURRENT NUMBER FOR NEXT TIME
HLRZ T2,T3 ;THROW AWAY RIGHT 18 BITS
POPJ P, ;BACK TO CALLER
IFN FTNSCHED,<
;PQ2 CLASS SCHEDULING SCAN
ISSFOR::SKIPG RRFLAG## ;ARE THERE ANY CLASSES?
JRST IRRFOR ;NO
MOVE T2,UPTIME## ;CURRENT TIME
CAML T2,SCNJIL## ;STILL SCANNING JBTJIL?
JRST SJFORX ;NOT ANY MORE
MOVEI T2,SJFORA ;ADDRESS OF SCAN ROUTINE
MOVNI J,JIQ## ;OFFSET OF HEADER
SJFORA: HRRE J,JBTJIL##(J) ;GET NEXT JOB IN LIST
JUMPG J,1(T1) ;SKIP RETURN IF GOOD JOB NUMBER
SJFORX: MOVEI T2,SSFORA ;RETURN ADDRESS FOR MORE JOBS
MOVE M,.CPSST##(P4) ;ADDRESS OF SUB-Q SCHEDULING SCAN TABLE
SSFOR1: SKIPN J,(M) ;ANY ENTRIES LEFT IN SUBQUEUE LIST?
JRST SSFOR2 ;NO
SSFORA: HRRE J,JBTCSQ##(J) ;GET NEXT JOB IN IN-CORE SUBQUEUE
JUMPG J,1(T1) ;RETURN JOB NUMBER TO CALL+2
AOJA M,SSFOR1 ;ELSE TRY NEXT SUBQUEUE
SSFOR2: MOVE T2,UPTIME## ;GET UPTIME AGAIN
CAMGE T2,SCNJIL## ;HAVE WE SCANNED JBTJIL ALREADY?
AOJA U,QSCAN ;YES, GO TRY BACKGROUND BATCH
MOVNI J,JIQ## ;OFFSET TO JUST INPUT HEADER
MOVEI T2,SSFORJ ;RETURN ADDRESS
SSFORJ: HRRE J,JBTJIL##(J) ;NEXT JOB IN LIST
JUMPLE J,QSCANX ;GET NEXT QUEUE IF NOT A JOB
JRST 1(T1) ;RETURN THE JOB
;BACKGROUND BATCH SCHEDULING SCAN
IBBFOR::SKIPG RRFLAG## ;IS CLASS SCHEDULER IN EFFECT?
AOJA U,QSCAN ;NO
MOVNI J,BBQ## ;HEADER OFFSET FOR B B QUEUE
MOVEI T2,BBFORA ;WHERE TO RETURN TO
SETOM BBFLAG## ;INDICATE WE ARE SCANNING B B QUEUE
BBFORA: HRRE J,JBTJIL##(J) ;GET NEXT JOB
JUMPG J,1(T1) ;RETURN WITH GOOD JOB NUMBER
BBFOR1: SETCM J,BBSUBQ## ;HEADER FOR BACKGROUND BATCH SUBQUEUE
JUMPGE J,BBFORX ;EXIT IF NO BACKGROUND BATCH QUEUE
BBFOR2: MOVEI T2,BBFORB
SETOM BBFLAG## ;SCANNING BACKGROUND BATCH
BBFORB: HRRE J,JBTCSQ##(J) ;NEXT JOB ON LIST
JUMPG J,1(T1) ;JUMP IF GOOD JOB NUMBER
BBFORX: SETZM BBFLAG## ;CLEAR SCANNING B B QUEUE FLAG
AOJA U,QSCAN ;SCAN THE NEXT MAJOR QUEUE
;PQ2 CLASS LOST TIME SCAN
OSSFOR::SKIPG RRFLAG## ;ANY CLASSES?
JRST OQFOR ;NO, SCAN NO-CORE PQ2 (OQFOR SETS UP T2)
MOVEI T2,SSFORB ;RETURN ADDRESS FOR NEXT JOB
MOVE M,.CPSST##(P4) ;ADDRESS OF SCAN TABLE
SSFOR3: SKIPN J,(M) ;ANY ENTRIES LEFT?
JRST OBBFOR ;NO, SCAN BACKGROUND BATCH NO-CORE QUE
SUBI J,M.CLSN## ;ADJUST TO NO-CORE HEADER
SSFORB: HRRE J,JBTCSQ##(J) ;NEXT JOB IN LIST
JUMPG J,1(T1) ;JUMP IF REAL JOB NUMBER
AOJA M,SSFOR3 ;GO TRY NEXT SUB-CLASS
;BACKGROUND BATCH LOST TIME SCAN
OBBFOR: SKIPGE J,BBSUBQ## ;IS ANY B B QUE DEFINED?
AOJA U,QSCAN ;NO
MOVNI J,M.CLSN##+1(J) ;ADJUST TO NO-CORE HEADER
JRST BBFOR2 ;SCAN THE SUB-QUEUE
>;END IFN FTNSCHED
;PQ2 ROUND ROBIN SCHEDULING SCAN
IRRFOR::MOVEI T2,RJFORA ;ADDRESS OF SCAN ROUTINE
MOVNI J,JIQ## ;OFFSET OF JBTJIQ HEADER
RJFORA: HRRE J,JBTJIL##(J) ;NEXT JOB IS JUST SWAPPED IN LIST
JUMPG J,1(T1) ;IF GOOD JOB, RETURN TO CALLER
MOVEI T2,IQFOR ;ELSE GET READY TO CALL IQFOR
MOVNI J,PQ2 ;SEARCH PQ2 IN-CORE ONLY
JRST IQFOR
;PQ2 JUST INPUT SCAN FOR SWAPPING GETSEGS
IGFOR:: PUSHJ P,RAND ;GET A RANDOM NUMBER
IDIVI T2,^D100 ;IN THE RANGE 0-99
CAML T3,SCDIOF## ;IS IT TIME FOR A SCAN OF GETSEGGED JOBS?
AOJA U,QSCAN ;NOT YET
IGFOR1: MOVNI J,JIQ## ;OFFSET TO JUST INPUT HEADER
MOVEI T2,IGFORA ;RETURN ADDRESS
IGFORA: HRRE J,JBTJIL##(J) ;NEXT JOB IN LIST
JUMPLE J,IGFOR2 ;GET NEXT QUEUE IF NOT A JOB
MOVSI T3,(JS.HNG) ;DID THIS JOB CLEAR OUT OF FORCE?
TDNN T3,JBTST2##(J) ;IF SO, DON'T WANT IT COMING IN
JRST 1(T1) ;OK. RETURN THE JOB
JRST IGFORA ;NOT THIS JOB. FIND ANOTHER
IGFOR2: MOVNI J,PQ2 ;NOW SCAN PQ2 FORWARD FOR BROKEN JOBS
MOVEI T2,IGFORB ;WHERE TO COME BACK TO
IGFORB: HRRE J,JBTCQ##(J) ;GET NEXT JOB
JUMPLE J,QSCANX ;GET NEXT QUEUE IFNOT A JOB
MOVSI T3,SWP ;MARKED SWP BUT WITH CORE?
TDNN T3,JBTSTS##(J) ;...
JRST IGFORB ;NO, IGNORE
IFN FTNSCHED,<
MOVSI T3,(JS.BBJ) ;BACKGROUND BATCH
TDNE T3,JBTST2##(J) ;YES, SKIP HIM
JRST IGFORB ;
>
JRST 1(T1) ;YES, BROKEN (NOT IN TRANSIT)
;PQ2 OUTPUT SCAN
; SCAN OUTPUT LISTS FORWARD, THEN PQ2 BACKWARD, SAVING SUMCOR AROUND
; FIRST SO THAT IF DON'T FIND ROOM WE WILL COUNT EVERYBODY EXACTLY ONCE.
OLFOR:: MOVE T2,SUMCOR ;GET CURRENT SUMCOR
MOVEM T2,SAVSUM ;SAVE IT
IFN FTNSCHED,<
MOVNI J,OBQ## ;SEARCH BACKGROUND BATCH OUTPUT LIST
MOVEI T2,OLFORA ;SET T2
OLFORA: HRRE J,JBTOLS(J) ;GET JOB
JUMPG J,1(T1) ;GIVE IT TO USER
MOVNI J,BBQ## ;SEARCH BACKGROUND BATCH JUST INPUT LIST
MOVEI T2,OLFORB ;SET T2
OLFORB: HRRE J,JBTJIL##(J) ;GET NEXT ENTRY
JUMPG J,1(T1) ;RETURN IF LEGAL JOB NUMBER
>;END IFN FTNSCHED
MOVNI J,OLQ## ;SEARCH PQ2 OUTPUT LIST
MOVEI T2,OLFORC ;SETUP T2
OLFORC: HRRE J,JBTOLS##(J) ;NEXT ENTRY
JUMPG J,1(T1) ;JUMP IF GOOD JOB
MOVE T2,SAVSUM ;NO JOB. RESTORE SUMCOR
MOVEM T2,SUMCOR ;(DON'T COUNT PEOPLE TWICE)
MOVNI J,PQ2 ;NOW PQ2
MOVEI T2,IQBAK ;BACKWARDS
JRST IQBAK ;GO DO IT
$LOW
SAVSUM: BLOCK 1 ;ROOM FOR SUMCOR COPY
$HIGH
DEFINE X(A,B,C)
<
A'Q==:ZZ
ZZ==ZZ+1>
ZZ==0
QUEUES
XP MINQ,ZZ
DEFINE X(A,B,C)
< A'Q==:ZZ
EXTERNAL A'AVAL
ZZ==ZZ+1>
RWAITS
NQUEUE==ZZ
XP MAXQ,NQUEUE-1
XP AVLNUM,MAXQ-MINQ
DEFINE X(A,B,C)
< A'Q==:ZZ
ZZ==ZZ+1>
CODES
XP MXCODE,ZZ-1
CMQ==:ZZ
ZZ==ZZ+1
PQ1==:ZZ
ZZ==ZZ+1
PQ2==:ZZ
;CORRESPONDENCE TABLE BETWEEN JOB STATUS CODES AND QUEUE TRANSFER TABLES
;USED BY SCHEDULER
;RUNCSS SETS JOB STATUS WORD TO NEW STATE CODE.
;SCHEDULER SETS UP QUEUE TRANSFER TABLE ADDRESS FROM
;FOLLOWING TABLE USING NEW STATE CODE AS INDEX
DEFINE X(A,B,C)
< XWD Q'A'T, Q'A'W
>
QWSW==-1
QIOWW=-1
QDIOWW==-1
QDSW==-1
QPIOWW==-1
QPSW==-1
QNAPW==-1
QBITS:: QUEUES
RWAITS
CODES
;SHARABLE DEVICE REQUEST TABLE(GENERALIZED FOR OTHER QUEUES TOO)
;CONTAINS THE NUMBER OF JOB WAITING TO USE SHARBLE DEVICE
;WSREQ AND RNREQ ARE UNUSED
$LOW
DEFINE X(A,B,C)
<A'REQ:: 0
>
REQTAB::RWAITS ;GENERATE REQ TABLE
XP RQTBMQ,REQTAB-MINQ
$HIGH
$LOW
XJOB:: 0 ;NUMBER OF JOBS NEEDING EXPANSION BY SWAPOUT-IN
UNWIND: 0 ;FLAG THAT SAYS WE'VE UNWOUND ONCE THIS SCHEDULER CYCLE
$HIGH
DEFINE TTAB(FCTN,QUEUE,QUANT)
< EXP FCTN
XWD QUANT,-QUEUE
>
DEFINE PTTAB(FCTN,QUEUE,QUANT)
< EXP FCTN
XWD QUANT,QUEUE
>
QNULW: TTAB EQFIX,NULQ,-1 ;NULL QUEUE JOB NO. NOT ASSIGNED
QSTOP::QSTOPW: TTAB EQFIX,STOPQ,-1 ;UNRUNABLE JOBS TO END OF STOPQ
IFN FTDAEM,<
QJDCW: TTAB EQFIX,JDCQ,-1
> ; END OF CONDITIONAL ASSEMBLY ON FTDAEM
QCMW:: TTAB EQFIX,CMQ,-1 ;COMMAND WAIT TILL JOB IN CORE
QTSW: ;TTY IO WAIT SATISFIED(ENTER BACK OF PQ1)
QRNW: TTAB EQFIX,PQ1,QADTAB## ;JUST RUNABLE JOBS
;WHICH ARE NOT IN SOME WAIT STATE BELOW
QRNW1: TTAB EQFIX,PQ1,-1 ;PUT IN BACK OF PQ1. NO QUANTUM FOR SPECIAL TRANSFER
QRNW2: TTAB EQFIX,PQ2,-1 ;PUT IN BACK OF PQ2, NO QUANTUM CHANGE
QTIOWW: TTAB EQFIX,TIOWQ,-1 ;TTY IOW HELD IN TIOWQ
QSLPW: TTAB EQFIX,SLPQ,-1 ;SLEEP UUO
QEWW: TTAB EQFIX,EWQ,-1 ;EVENT WAIT
QTIME:: PTTAB EQLNKZ,QRQTBL##,0 ;WHEN QUANT. TIME EXCEEDED.
;WHEN QUANT. TIME EXCEEDED AND RESET QUANT. TIME
SUBTTL SWAP R. KRASIN
;SWAPPER CALLED EVERY CLOCK TIC.
;SINCE MOST OPERATIONS STARTED BY THE SWAPPER REQUIRE SEVERAL
;TICS TO RUN TO COMPLETION, SEVERAL FLAGS(FINISH,FIT,FORCE
;ARE USED TO "REMEMBER" PREVIOUS STATES.
;THE BASIC ALGORITHM:
;IS CORE SHUFFLER WAITING FOR IO TO FINISH FOR SOME JOB?
; YES--TRY AGAIN TO SHUFFLE(WHEN IO STOPS)
;IS CORE SHUFFLER STILL WAITING FOR IO TO FINISH?
; YES--RETURN AND DO NOTHING
;IS SWAPPER STILL BUSY?
; YES--RETURN AND DO NOTHING
;SCAN QS FOR 1ST JOB OUT OF CORE.
; IF NONE--RETURN
;A:
; IF ONE--WILL LOW(HIGH) SEG FIT IN LARGEST HOLE IN CORE?
; YES--START INPUT AND RETURN
; NO--IS TOTAL FREE CORE(CORTAL) ENOUGH TO ACCOMMODATE LOW(HIGH) SEG?
; YES--CALL CORE SHUFFLER
; IS SHUFFLER WAITING FOR IO TO STOP?
; YES--RETURN AND DO NOTHING
; NO--GO TO A:
; NO--"REMEMBER" THIS JOB FOR INPUT AND LOOK FOR OUTPUT:
;ANY JOBS WAITING TO XPAND CORE BY SWAP OUT/IN?
; YES--OUTPUT ONE AND RETURN
; NO--SCAN QS BACKWARD FOR JOB IN CORE WHOSE PROTECT TIME
; (SET ON INPUT) HAS GONE TO 0.
; IF NONE--RETURN
; IF ONE--IS IT SWAPPABLE(NO ACTIVE IO AND NOT CURRENT JOB)?
; YES--OUTPUT HIGH SEG(IF ANY AND NOT ON DISK) THEN LOW SEGMENT
; NO--SET SWP BIT(SO SCHEDULER WILL NOT RUN), IO WILL CONTINUE
; IN LOW SEGMENT AS LONG AS IT CAN
; IO ROUTINES NO LONGER STOP IF SWP SET, JUST SHF)
;ALL DEVICE DEPENDENT CODE MARKED WITH A "*"
SWAP::
IFN FTKI10!FTKL10,<
PUSHJ P,GETUBR## ;MAKE SURE WE HAVE USER PROCESS TABLE
>
IFN FTVM,<
PUSHJ P,SAVE3##
>
IFE FTVM,<
IFN FTSHFL,< ;SHUFFLER PRESENT?
CPUNLK (SCD) ;UNLOCK CALL TO SHUFFLER
SKIPE SHFWAT## ;IS CORE SHUFFLER WAITING FOR IO TO STOP
; FOR SOME JOB?
PUSHJ P,CHKSHF## ;YES, CALL CORE SHUFFLER TO SEE IF
; IO STOPPED YET
CPLOCK (SCD) ;LOCK CP AGAIN
SKIPN SHFWAT## ;IS SHUFFLER STILL WAITING?
> ; END OF CONDITIONAL ASSEMBLY ON FTSHFL
SKIPE SQREQ## ;*NO--IS SWAP SERV. ROUT. STILL BUSY WITH LAST JOB?
POPJ P, ;*YES--RETURN
>
IFN FTPDBS,< ;IF WE SWAP PDB'S
SKIPL SCREQ ;CAN WE GET THE SWAPPER IF WE DECIDE
; THAT WE WANT IT.
SKIPN SCUSER## ; ..
JRST SWAP0 ;YES--TRY TO SWAP
POPJ P, ;NO--RETURN NOW.
SWAP0:> ;END CONDITIONAL ON FTPDBS
IFN FTHPQ,<
SKIPE FIT ;IS FIT SET?
SKIPG J,.CPRTF##(P4) ;AND HPQ JOB ON DISK?
JRST SWAP0A ;NO. CONTINUE
LDB T4,HPQPNT## ;GET ITS HPQ NUMBER
MOVE J,FIT ;GET NUMBER FROM FIT
IFN FT2REL,<
PUSHJ P,FITHPQ ;GET LOW SEG NUMBER OF JOB IN FIT
>
LDB T2,HPQPNT ;GET HPQ NUMBER OF JOB IN FIT
CAIL T2,(T4) ;IS IT LESS THAN JOB IN .CPRTF?
JRST SWAP0A ;NO. PROCEED NORMALLY
IFN FT2REL,<
SKIPLE T1,JBTSGN##(J) ;REAL HIGH SEG?
SKIPN JBTADR(T1) ;YES. IN CORE, IF NOT, COULD BE IN FIT
>
PUSHJ P,ZERFIT ;NO. CAN CLEAR FIT AND RESELECT
SWAP0A:> ; END OF CONDITIONAL ASSEMBLY ON FTHPQ
IFE FTVM,<
MOVEI F,SWPDDB## ;POINT TO SWAP DDB
HRRZ S,DEVIOS(F) ;ERROR FLAGS
;BACK HERE AFTER SWAP OUT OR IN ERROR (ERR BITS (S) CLEARED SO DO NORMAL
; POST PROCESSING)
SWAP1: SKIPN J,FINISH## ;ANY IN/OUTPUT TO FINISH?
JRST SWP2 ;NO-
IFE FTPDBS,< ;IF WE DO NOT SWAP PDB'S
JUMPL J,FINOUT ;YES--INPUT OR OUTPUT?
> ;END CONDITIONAL ON FTPDBS
IFN FTPDBS,< ;IF WE SWAP PDB'S
SKIPN SWAPIN## ;IS THIS A SWAP IN?
JRST FINOUT ;NO--MUST BE SWAP OUT
> ;END CONDITIONAL ON FTPDBS
> ;END CONDITIONAL ON FTVM
IFN FTVM,<
SWAP1:
IFN FTIPCF,<
PUSHJ P,GVIPCP## ;RETURN ANY IPCF PAGES WHICH
; WERE SWAPPED OUT TO THE FREE CORE LIST
>
SKIPN SWPCNT## ;ANY SWAP REQUESTS COMPLETED?
JRST SWP2 ;NO, PROCEED
PUSHJ P,FNDSLE## ;FIND A COMPLETED SWPLST ENTRY
STOPCD CPOPJ,DEBUG,SMU, ;++SWPCNT MESSED UP
FININN: PUSHJ P,GETIOS## ;GET ERROR PLUS DIRECTION OF I/O BITS
TLNE S,IO ;SWAP OUT?
JRST FINOUT ;YES, FINISH UP OUTPUT
> ;END CONDITIONAL ON FTVM
JUMPN S,INERR ;JUMP IF SWAP READ ERROR
FININ0: ;HERE IF NOTHING TO SWAP IN(HIGH OR LOW SEG EXPANDING FROM 0)
IFN FTPDBS,< ;IF WE SWAP PDB'S
JUMPL J,PDBIN ;JUMP IF PDB
> ;END CONDITIONAL ON FTPDBS
IFN FT2REL,<
CAILE J,JOBMAX## ;WAS SEG JUST SWAPPED IN, A LOW SEG?
IFE FTDHIA&FT2SWP,<
JRST FININ1 ;NO, GO FINISH HIGH SEG SWAP IN
>
IFN FTDHIA&FT2SWP,<
JRST FININH
>
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
IFN FTVM,<
PUSHJ P,GIVBAK ;RETURN DISK SPACE, 4-WORD BLOCKS
FININ5:
> ; END OF CONDITIONAL ASSEMBLY ON FTVM
IFN FTKA10,<
MOVE R,JBTDAT##(J) ;SETUP LOW SEG PROTECTION,RELOCATION
MOVE F,JOBPC##(R) ;JOB STOPPED IN EXEC MODE?
TLNE F,USRMOD ;TEST PD FLAG
JRST FININ1 ;NO
HRRZ F,JOBDPG##(R) ;YES, ADJUST R AND P IN DUMP AC AREA
SUBI F,(R) ;OLD RELOC-NEW RELOC
MOVNS F ;NEW RELOC-OLD RELOC
HRRZ T2,JOBDPD##(R) ;OLD PD LIST POINTER
CAMLE T2,SYSSIZ## ;IS IT IN THE MONITOR(EXTENDED PD LIST,NULL PD LIST)
ADDM F,JOBDPD##(R) ;NO, ADJUST DUMP PUSH DOWN POINTER
MOVEM R,JOBDPG##(R) ;STORE NEW AC R
> ; END OF IFE FTKI10
IFN FTDHIA&FT2SWP,<
JRST FININ1 ;CONTINUE
FININH: MOVE T1,SWPIN## ;LOW-SEG NUMBER
CAMN T1,MIGRAT## ;SWAP IN CAUSE MIGRATING FROM BAD UNIT?
PUSHJ P,ZERSWP ;YES, GIVE UP HI-SEG SWAPPING SPACE
>
FININ1:
IFN FT2REL,<
CPUNLK (SCD) ;UNLOCK CALL TO SHUFFLER
PUSHJ P,FININ## ;IS THERE A HIGH SEG WHICH MUST BE SWAPPED IN?
IFN FTVM,<
JRST [CPLOCK (SCD) ;SWAPPING I/O IN PROGRESS FOR HI SEG
PUSHJ P,NXTSLE##
POPJ P,
JRST FININN]
>
JRST FININ2 ;YES, GO SWAP IT IN(J SET TO HIGH SEG NO,JOB # IN INPJOB)
CPLOCK (SCD) ; NO, EITHER HIGH SEG ALREADY IN FOR ANOTHER USER
; OR THERE IS NONE, J STILL JOB NO. (IE LOW SEG)
JRST FININ3 ;
FININ2: CPLOCK (SCD) ;LOCK SCHEDULER AGAIN
JRST FIT1 ;GO SWAP IN HIGH SEG
FININ3:
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
;HERE WHEN PDB IS IN CORE
PDBIN: HRRE J,J ;CLEAR BITS IN LH(J)
PUSHJ P,SEGSIZ## ;T2 = SIZE OF PDB IN PAGES
PUSHJ P,ZERSWP ;GIVE UP DISK SPACE
; ALSO FIX VIRTAL
MOVM J,J ;MAKE J POSITIVE
MOVEI T2,JS.RQR ;IF THE QUANTUM RUN TIME WAS RESET
MOVE T1,RNQUNT## ; WHILE PDB WAS ON THE DISK WE MUST
TDNE T2,JBTSTS##(J) ; DO THE ACTUAL DPB NOW.
PUSHJ P,SETQNT## ;GO STORE IN PDB
ANDCAM T2,JBTSTS##(J) ;AND CLEAR THE FLAG BIT
LDB T2,IMGIN## ;GET SIZE OF LOWSEG
JUMPE T2,SWP1 ;IF ZERO GO SCAN SWAP IN QUEUE.
MOVEM J,FIT## ;ELSE GO SWAP IN LOWSEG
CAMG T2,BIGHOL## ;IS THERE STILL ROOM IN CORE?
JRST SWAPI ;YES--GO SWAP IN LOW SEGMENT
JRST FIT1A ;NO--SWAP SOMEONE OUT. THIS HAPPENS
; ONLY IF SOME JOB DID A CORE UUO
; WHILE THE SWAPPER WAS BUSY AND GOT
; THE SPACE IN CORE.
> ;END FTPDBS
IFN FTKI10!FTKL10,<
PUSHJ P,MAPUSR## ;SETUP THE MAP INCLUDING THE TRAP LOCATIONS
; FOR THE JOB JUST SWAPPED IN
IFN FTVM,<
PUSHJ P,SXOPFH## ;MAKE PFH CONCEALED IF IT SHOULD BE
>
> ; END OF CONDITIONAL ASSEMBLY ON FTKI10
LDB F,IMGIN## ;NEW CORE SIZE
LDB T2,IMGOUT## ;OLD SIZE WHEN ON DISK
SUB T2,F ;OLD-NEW=DECREASE
; HAS USER DECREASED VIRTUAL MEMORY FROM M TO N(N GR 0)
; WHILE OUT ON DISK(R,RUN,GET,KJOB) TO 140 WORDS?
; CORE COMMAND ALWAYS FORCES SWAP IN BEFORE
; CORE REASSIGNMENT SO NOT IN THIS CATEGORY
; FRAGMENTED USER TOO HARD TO PARTIALLY
; RECLAIM DISK SPACE
; ON REDUCTION WHICH DOES NOT GO TO 0
SKIPLE T2 ;DECREASED?
ADDM T2,VIRTAL## ;YES, NOW INCREASE VIRTUAL MEMORY AVAILABLE BY
; AMOUNT OF DECREASE IN HIGH OR LOW SEG
IFE FTVM,<
PUSHJ P,ZERSWP ;RETURN LOW SEG DISK SPACE, SET IMGOUT,IMGIN
; AND SWP!SHF(JBTSTS) TO 0
>; ; END OF CONDITIONAL ON FTVM
IFN FTVM,<
PUSHJ P,UNSWAP ;MARK JOB IN CORE AGAIN
>
PUSHJ P,FNPDBS## ;FIND THE PDB OR STOP
MOVE F,[JS.HNG!JS.SCN!JS.TFO] ;CLEAR SCANNED, FORCED BY TIMER, HUNG
ANDCAM F,JBTST2##(J) ;IN SECOND STATUS TABLE
LDB T1,PJBST2## ;GET PHY QUE
IFN FTDHIA&FT2SWP,<
CAME J,MIGRAT## ;IF JUST SWAPPING IN TO GET OFF A UNIT GOING
; DOWN DONT CLEAR SWAPPABLE BIT
>
CAIGE T1,CMQ ;OR IF NOT IN RUN OR CMQ
JRST [MOVSI F,PDMSWP ;MAKE SURE CAN SWAP
IORM F,.PDIPT##(W) ;SET SWAPPABLE BIT
JRST FININ7 ] ;NOTHING MORE TO DO
MOVSI F,(JS.NNQ) ;JOB THAT DID GETSEG TO SWAPPED OUT HISEG?
TDNE F,JBTST2##(J) ;...
JRST FININ7 ;YES. LEAVE PARAMETERS AND OUTPUT LIST AS IS
PUSHJ P,ASICPT ;ASSIGN IN-CORE PROTECT TIME
MOVSI F,PDMSWP
ANDCAM F,.PDIPT##(W) ;CLEAR SWAPPABLE BIT
SKIPGE JBTST2##(J) ;JOB IN PROCESSOR QUEUE?
PUSHJ P,CMPQSI ;YES. ASSIGN NEW RUN QUANTA
PUSHJ P,DLOLST ;MAKE SURE JOB IS NOT ON OLS
IFN FTNSCHED,<
MOVSI F,(JS.BBJ) ;SET/CLEAR B B JOB BIT
SKIPN BBFIT## ;IS JOB IN BACKGROUND BATCH?
JRST FININ6 ;NO
IORM F,JBTST2##(J) ;SET THE BACKGROUND BATCH BIT
SKIPE JBTJIL##(J) ;SHOULD BE ZERO
JRST FININ7 ;OOPS
HLRZ T1,JBTBBQ## ;CURRENT LAST ENTRY IN B B QUEUE
HRLM J,JBTBBQ## ;NEW LAST ENTRY
HRRM J,JBTJIL##(T1) ;FORWARD LINK
HRLI T1,MBBQ## ;OFFSET OF BBQ HEADER
MOVSM T1,JBTJIL##(J) ;OLD LAST ENTRY,,HEADER
JRST FININ7 ;AND PROCEED
FININ6: ANDCAM F,JBTST2##(J) ;CLEAR THE BACKGROUND BATCH BIT
SKIPGE JBTSCD##(J) ;IS JOB IN PQ2?
>
IFE FTNSCHED,<
LDB T1,PJBST2## ;GET PHY QUE CODE
CAIN T1,PQ2 ;IS JOB IN PQ2?
>
SKIPE JBTJIL##(J) ;SHOULD BE ZERO SINCE HE JUST CAME IN
JRST FININ7 ;NOT IN PQ2 OR JBTJIL ALREADY SET
HLRZ T1,JBTJIQ## ;CURRENT LAST ENTRY
HRLM J,JBTJIQ## ;NEW LAST ENTRY
HRRM J,JBTJIL##(T1) ;NEW FORWARD POINTER
HRLOM T1,JBTJIL##(J) ;SETUP THIS JOBS POINTERS
FININ7: MOVSI F,(JS.NNQ) ;CLEAR NO NEW QUANTA BIT
ANDCAM F,JBTST2##(J)
IFN FTNSCHED,<
SETZM BBFIT## ;CLEAR B B FIT FLAG
>
SETZM INFLG ;CLEAR FRUSTRATION FLAGS
SETZM INFLGJ
SETZM INFLGC
IFN FTHPQ,<
.SETZM .PDHZF(W) ;CLEAR HPQ ZEROED FIT FLAG FOR THIS JOB
>
IFN FTKL10 & FTMS,<
PUSHJ P,SETCSJ##
>;
IFN FTPSCD,<
SKIPN T1,.PDPST##(W) ;BEING TIMED?
JRST SWP1 ;NO
SETZM .PDPST##(W) ;YES. CLEAR TIMER
ADD T1,UPTIME## ;GET ELAPSED TIME
ADDM T1,%P1CMT ;ADD TO TOTAL TIME SPEND WAITING
MUL T1,T1 ;COMPUTE DOUBLE WORD SQUARE SUB
TLO T2,400000 ;PREVENT OVERFLOW
ADD T2,%P1CM2+1
TLZN T2,400000 ;CARRY?
ADDI T1,1 ;YES. DO IT
MOVEM T2,%P1CM2+1 ;STORE IT
ADDM T1,%P1CM2 ;ALSO HIGH ORDER WORD
AOS %PQ1CM ;NUMBER OF RESPONSES
> ;END IFN FTPSCD
JRST SWP1
;HERE ON SWAP INPUT ERROR IN LOW OR HIGH SEG
INERR: MOVE R,JBTADR##(J) ;SETUP RELOC,PROTECTION FOR HIGH OR LOW SEG
IFN FTSWPERR,< ;SWAP READ ERROR RECOVERY CODE
IFN FT2REL,<
CAILE J,JOBMAX## ;IS THIS A HIGH SEGMENT JUST SWAPPED IN?
JRST INERR2 ;YES
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
PUSHJ P,SWPREC ;RECORD ERRORS AND DECREASE AMOUNT OF
;VIRTUAL CORE LEFT BY SIZE OF DISK SPACE LOST (IMGOUT)
MOVSI T1,JACCT ;CLEAR JACCT SO THAT A START COMMAND
ANDCAM T1,JBTSTS##(J) ; WILL NOT START A DAMAGED PROGRAM
; WITH PRIVILEDGES AND SO DAEMON WON'T
; GET RESTARTED
IFE FTVM,<
MOVEI T1,0 ;NO, PRETEND DISK SPACE WITH ERROR IN IT
DPB T1,IMGOUT## ; IS NO LONGER ON DISK (ZERSWP WILL NOT
; FREE IT UP)
>
PUSHJ P,ZAPUSR## ;CLEAR ALL DDB'S, IO CHANS
PUSHJ P,CLRJOB## ;CLEAR PROTECTED PART OF JOB DATA AREA
INERR2:
IFN FTVM,<
PUSH P,J ;SAVE SEGMENT NUMBER
>
IFN FT2REL, <
PUSHJ P,SEGERR## ;GO CHECK IF HIGH SEG WHICH HAD ERROR
; IF YES, CLEAR HIGH SEG NAME SO NO NEW
; USERS WILL USE. ALWAYS RETURN JOB NO.
;RECORD ERROR AND DECREASE VIRTUAL CORE LEFT (SWPREC) IF THIS IS
; FIRST READ ERROR ONLY.
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
PUSHJ P,ERRSWP## ;PRINT "SWAP READ ERROR"
IFN FTVM,<
POP P,J ;RESTORE SEGMENT NUMBER
LDB T1,[POINT 9,SWPLST##(P1),26] ;FIRST PAGE IN
CAILE J,JOBMAX## ;A HIGH SEGMENT?
JRST FININ0 ;NO
HLL T1,JBTUPM##(J) ;PICK UP LH FOR COMPARE
CAME T1,JBTUPM##(J) ;UPMP?
JRST FININ0 ;NO, WE'RE NOT TOO BAD OFF
PUSHJ P,GVPAGS## ;YES, WE'RE IN BAD TROUBLE
HLRZ T1,JBTSWP##(J) ;GIVE BACK ALL CORE FOR THE JOB
PUSHJ P,GVPAGS
PUSHJ P,DLTSLE## ;CLEAR THE SWPLST ENTRY
SETZM JBTADR##(J) ;THE JOB HAS NO CORE IN CORE
SETZM JBTUPM##(J)
SETZM JBTSWP##(J) ;NO CORE ON DSK EITHER
IFN FT2REL,<
SKIPLE T1,JBTSGN##(J) ;SKIP IF SPY OR NO HI SEG
TLNE T1,SHRSEG ;SHARABLE?
CAIA ;YES, LET SEGCON REMOVE IT
SETZM JBTSGN##(J) ;NO, JUST ZAP IT
PUSHJ P,KILHGH## ;ALSO REMOVE HI SEG FROM ADR SPACE
>
PJRST UNSWAP ;CLEAR SWP AND RETURN
> ;END FTVM
IFE FTVM,<
MOVEI S,0 ;CLEAR ERROR FLAGS SO CAN
; REENTER SWAPPER
JRST SWAP1 ;GO BACK AND START OVER AFTER HAVING
> ;END FTVM
> ; END OF CONDITIONAL ASSEMBLY ON FTSWPERR
; CLEARED S SO LOOK LIKE NO ERROR
IFE FTSWPERR,<
SETZM FINISH## ;CLEAR FINISH FLAG SO SWAPPING CAN CONTINUE
IFN FTPDBS,< ;IF THE SC RESOURCE EXISTS
SKIPL SCREQ ; AND IF WE OWN IT
PUSHJ P,SCFREE## ;RETURN IT.
> ;END FTPDBS
PUSHJ P,KCORE1## ;RETURN CORE
PJRST ERRSWP## ;TYPE SWAP READ ERROR MESSAGE AND STOP JOB
> ; END OF CONDITIONAL ASSEMBLY ON FTSWPERR
FINOUT:
IFE FTVM,<
IFE FTPDBS,< ;ONLY NEEDED IF WE DO NOT SWAP PDB'S
MOVNS J ;ON OUTPUT FINISH IS NEGATIVE THIS
; CONVERTS IT BACK TO POSITIVE.
> ;END FTPDBS
JUMPN S,OUTERR ;JUMP IF SWAP OUT ERROR
> ; END OF CONDITIONAL ASSEMBLY OF FTVM
IFN FTVM,<
TRNE S,-1 ;ANY ERRORS?
JRST OUTERR ;YES, PROCESS SWAP OUT ERRORS
PUSHJ P,DLTSLE## ;DELETE THE SWPLST ENTRY
> ; END OF CONDITIONAL ASSEMBLY ON FTVM
IFN FTDHIA&FT2SWP,<
CAILE J,JOBMAX## ;HI-SEG?
JRST FINOU2 ;YES, WE'LL GET IT LATER
;****************
;WHAT ABOUT HI SEGS, WILL DODELE WORK FOR ALL SHARABLE HI SEGS,
;WHAT ABOUT NON-VM NON-SHARABLE HI SEGS?
;**********************
IFE FTVM,<
MOVEI T1,JS.MIG ;LIGHT A BIT INDICATING THIS JOB
SKIPE MIGRAT## ; HAS BEEN MIGRATED TO ANOTHER UNIT
IORM T1,JBTST2##(J) ; IF WE ARE TURNING OFF A SWAPPING UNIT
> ;END IFE FTVM
IFN FTVM,<
SKIPN MIGRAT##
JRST FINOU2
PUSHJ P,PGOFF## ;INSURE ALL PAGES OF JOB ARENT ON BAD UNIT(S)
TDZA T1,T1 ;NOT COMPLETELY MIGRATED YET
MOVEI T1,JS.MIG ;COMPLETELY OFF THE BAD UNIT
IORM T1,JBTST2##(J) ;LIGHT BIT IF ALL OFF
> ;END IFN FTVM
> ;END FTDHIA&FT2SWP
FINOU2: MOVE R,JBTADR##(J) ;XWD PROTECT,,RELOC. FOR LOW SEG
CPUNLK (SCD) ;UNLOCK CALLS TO SHUFFLER
PUSHJ P,KCORE1## ;RETURN CORE FOR LOW OR HIGH SEG JUST SWAPPED OUT
; EVEN IF
; ANOTHER JOB STARTED TO SHARE HIGH SEG DURING
; SWAP OUT (GET) SINCE JOB IS MARKED WITH
; SWP BIT ON AND CANNOT RUN UNTIL HIGH SEG
; IS SWAPPED BACK IN
CPLOCK (SCD) ;LOCK SCHEDULER AGAIN
FINOU0:
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
CAILE J,JOBMAX## ;IS THIS A HISEG?
JRST FINOU1 ;YES--SEE ABT LOW SEG
JUMPL J,SWP1 ;IF THIS WAS THE PDB WE ARE DONE
MOVN J,J ;CONVERT TO PDB
MOVEM J,FORCE## ;SAVE SEG #
JRST SWAPO ;GO SWAP OUT
FINOU1:> ;END FTPDBS
IFN FT2REL,<
PUSHJ P,FINOT## ;IS THIS A HIGH SEG WHICH WAS JUST SWAPPED OUT?
JRST FORCEL ;YES, J SET TO LOW SEG NO, GO TRY SWAP IT OUT
; NO, THIS WAS A LOW SEG, ALL SWAPPING FOR THIS USER
; IS FINISHED.
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
SWP1: SETZM FINISH## ;CLEAR FINISH FLAG
IFN FTPDBS,< ;IF THE SC RESOURCE EXISTS
SKIPL SCREQ ; AND IF WE OWN IT
PUSHJ P,SCFREE## ;GIVE IT UP
> ;END FTPDBS
SWP2: SKIPE J,FORCE## ;WAITING FOR JOB TO BECOME SWAPPABLE?
JRST FORCE1 ;YES, TRY TO SWAP OUT
FIT0:
IFN FTVM,<
SKIPE SPRCNT## ;ARE THERE ALREADY SWAPS IN PROGRESS?
JRST CHKXPN ;YES, LOOK ONLY FOR EXPANDING JOBS
SKIPE SWPCNT## ;ANY SWAPPING I/O DONE (PROBABLY ONLY IF
; ONE PASS HAS ALREADY BEEN MADE THROUGH THE
; MAJOR LOOP OF THE SWAPPER)
JRST SWAP1 ;YES, GO PROCESS THAT FIRST
>
SKIPE J,FIT## ;NO-- WAITING TO FIT JOB IN CORE?
JRST FIT1 ;YES, TRY TO SWAP IN
IFN FTLOCK,<
SKIPE J,LOCK## ;WAITING TO LOCK A JOB IN CORE?
JRST CPOPJ1## ;YES, TRY TO POSITION JOB FOR LOCKING
> ; END OF CONDITIONAL ASSEMBLY ON FTLOCK
;SCAN FOR INPUT
IFN FTNSCHED,<
SETZM BBFLAG## ;WE ARE NOT SCANNING THE BACKGROUND BATCH QUEUE YET
>
SETZM SWPFAR ;ASSUME THIS SCAN WILL NOT BE FAIR
MOVEI U,ISCAN##
MOVE T1,SWPIFC ;NUMBER OF UNFAIR INPUT SCANS
CAML T1,MAXIFC ;REACH MAXIMUM?
MOVEI U,ISCAN1## ;YES, USE SECONDARY
FITPRM: JSP T1,QSCAN
JRST ZCKXPN ;NO INPUT TO DO--CK FOR EXPANDING JOBS
IFE FTVM,<
MOVE F,JBTST2##(J) ;SECOND STATUS WORD
TLNE F,(JS.XPN) ;RACE ON EXPANDING?
JRST (T2) ;YES. MUST GO OUT
>
MOVE F,JBTSTS##(J) ;JOB STATUS WORD
TLNE F,JXPN ;EXPANDING JOB?
JRST (T2) ;DON'T SELECT FOR INPUT(CAN HAPPEN IF ZERO FORCE)
IFN FT2REL,< TLNE F,SWP ;ARE ALL OF THIS JOB'S SEGS IN CORE?
PUSHJ P,CKXPN## ;NO, IS HIGH SEG EXPANDING?
JRST (T2) ;YES, CONTINUE SCAN FOR SOME OTHER JOB
MOVEM J,FIT## ;NO, REMEMBER JOB (OR HI SEG) TRYING TO FIT IN
IFN FTNSCHED,<
SKIPE BBFLAG## ;IS THIS JOB FROM BACKGROUND BATCH SCAN?
JRST FITPR1 ;YES
SETZM SCNSWP## ;NO, ALLOW SCAN POINTER TO ADVANCE
JRST FITPR2
FITPR1: MOVEM J,BBFIT## ;REMEMBER IT
FITPR2:>
CAIN U,FISCAN## ;JOB FROM PQ1 (NOT IN CORE)?
AOS SWPIFC ;YES. COUNT UP
SKIPE SWPFAR ;DID THIS SCAN REACH FAIR TERRITORY
SETZM SWPIFC ;YES. CLEAR COUNT
JRST FIT1A ; TRY TO FIT JOB INTO CORE
; (BYPASS SECOND CALL TO CKXPN FOR SPEED)
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
IFE FT2REL,<
TLNN F,SWP ;ARE ALL OF THIS JOB'S SEGS IN CORE?
JRST (T2) ;YES, CONTINUE SCAN FOR SOME OTHER JOB
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
;HERE TO TRY TO FIT A SWAPPED JOB (OR HI SEG) INTO CORE (AGAIN)
FIT1::
IFN FTRSP,<
SETOM SWPPLT## ;SET POTENTIALLY LOST TIME FLAG FOR SWAPPER
>
MOVEM J,FIT## ;REMEMBER JOB (OR HI SEG) TRYING TO FIT IN
IFN FT2REL,<
PUSHJ P,CKXPN## ;IS THIS A LOW SEG WHICH IS CONNECTED TO
; AN EXPANDING HIGH SEG? (SHOULD BE RARE)
JRST NOFITZ ;YES. DESELECT IT AND GET OUT.
FIT1A:
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
LDB P1,IMGIN## ;CORE SIZE NEEDED FOR THIS SEG(0 IF LOW SEG
; OR HIGH SEG WITH UWP OFF ALREADY IN CORE
IFN FTKI10!FTKL10,<
CAIG J,JOBMAX## ;ON LOW SEGMENT SWAP-IN, MUST ALSO ALLOCATE
ADDI P1,UPMPSZ## ; A USER PAGE MAP PAGE SO ADD THAT TO
; TOTAL CORE REQUIRED TO SWAP IN JOB OR LOW SEGMENT
> ; END OF CONDITIONAL ASSEMBLY ON FTKI10
SKIPE JBTADR##(J) ;IS LOW OR HIGH SEG ALREADY IN CORE?
MOVEI P1,0 ;YES (RARE) CAN HAPPEN IF JOB IN CORE EXPANDS
; DURING LOW SEG SWAP IN SO HIGH SEG COULD NOT
; FIT AND COUND NOT FIND ENOUGH JOBS TO SWAP OUT
;;(SO CLEARED FIT AT NOFIT).
IFE FT2REL,<
CAMLE P1,CORTAL## ;WILL LOW SEG FIT IN FREE+DORMANT CORE?
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
IFN FT2REL,<
PUSHJ P,FITSIZ## ;COMPUTE AMOUNT OF CORE NEEDED TO BRING IN
; 1. THIS JOBS LOW SEG AND HIGH SEG
; 2. THIS JOBS LOW SEG(HIGH ALREADY IN OR NONE)
; 3. THIS HIGH SEG BECAUSE LOW SEG ALREADY IN
;WILL LOW SEG FIT IN FREE+DORMANT+IDLE CORE?
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
JRST SCNOUT ;NO,WILL NOT FIT EVEN IF ALL DORMANT SEGS DELETED
; P1=TOTAL CORE NEEDED(IN K)
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
CAIG J,JOBMAX## ;SKIP IF HISEG -- NO PDB IN THAT CASE
ADDI P1,PDBPGS## ;P1=TOTAL CORE NEEDED IN PAGES INCLUDING
; THE PDB.
> ;END FTPDBS
FIT1B: CAMG P1,BIGHOL## ;YES, WILL THIS SEG FIT IN BIGGEST HOLE OF FREE CORE
; WITHOUT DELETEING ANY DORMANT OR IDLE SEGS?
; (P1 RESTORED TO SIZE FOR JUST THIS LOW OR HIGH SEG)
; BIGHOL CONTAINS THE NUMBER OF FREE PAGE ON
; THE KI10 RATHER THAN THE LARGEST SET OF
; CONTIGUOUS FREE PAGES
JRST SWAPI ;YES, GO SWAP IN THIS LOW OR HIGH SEG
IFN FT2REL,<
PUSHJ P,FRECR1## ;NO, GO DELETE ONE DORMANT OR IDLE SEG IN CORE
; (THERE MUST BE AT LEAST ONE, OTHERWISE
; CORTAL WOULD EQUAL BIGHOL).
; SKIP RETURN (USUAL) EXCEPT IF AN IDLE SEGMENT
; WAS FOUND WITH NO COPY ON DISK (UWP OFF).
JRST FORIDL ; GO SWAP OUT IDLE HIGH SEG WITH NO DSK COPY.
JRST FIT1B ; ONE DORMANT OR IDLE SEGMENT HAS BEEN DELETED, GO
; TRY TO SWAP IN NOW.
IFN FTSHFL,< ;SHUFFLER?
;TAG TO PATCH OUT SHUFFLER FOR EXPERIMENTS - PATCH TO JFCL
SHFPAT:: SKIPN HOLEF## ;NO, ARE THERE ANY HOLES IN CORE WHICH THE SHUFFLER
; COULD ELIMINATE(NOT COUNTING ONE AT TOP)?
> ; END OF CONDITIONAL ASSEMBLY ON FTSHFL
JRST SCNOUT ;MEMORY IS FRAGMENTED AND THERE ARE NO
;DORMANT HIGH SEGMENTS OR HOLES. SCAN FOR OUTPUT
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
IFN FTSHFL,< ;SHUFFLER?
CPUNLK (SCD) ;UNLOCK ALL CALLS TO SHUFFLER
PUSHJ P,CHKSHF## ;YES, CALL CORE SHUFFLER TO MOVE ONE SEG DOWN
CPLOCK (SCD) ;LOCK AGAIN
SKIPN SHFWAT## ;SHUFFLER WAITING FOR IO TO STOP?
JRST FIT0 ;NO, SEE IF JOB WILL FIT NOW.
POPJ P, ;YES, RETURN AND WAIT TILL IO STOPS
> ; END OF CONDITIONAL ASSEMBLY ON FTSHFL
;HERE ON SWAP OUT ERROR
;CANNOT BE MEMORY PARITY ON CHANNEL READ BECAUSE ARR INTERRUPTS
; OR PROCESSOR STOPS WHEN CONTROLLER ROUTINE TOUCHES BAD PARITY.
OUTERR: TRNN S,IOCHMP ;CHANNEL (READ) MEMORY PAR ERROR?
JRST OUTER1 ;NO, ERROR ON DISK (WRITE)
PUSHJ P,SWPRC1 ;RECORD ERROR FLAGS AND NO. OF SWAP ERRORS
IFN FT2REL,< ;2 RELOC REG SOFTWARE?
PUSHJ P,HGHSWE## ;IF HIGH SEG, PRINT ERROR FOR ALL JOBS USING
JRST OUTER0 ;YES, ALL JOBS USING HIGH SEG GOT ERROR MESSAGE
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
MOVEI T2,JOBPFI##+1 ;NO, TEMP UNTIL GET REL ADR OF PAR AREA?
CAIG T2,JOBPFI## ;IS ERROR IN PROTECTED PART OF JOB DATA
PUSHJ P,[PUSHJ P,CHGSWP ;YES, RETURN DISK SPACE
; CANNOT TRUST JOB DATA AREA
; INCREASE FREE VIRTUAL CORE
PJRST ZAPUSR##];CLEAR ALL HIS DDB'S, IO CHANS
PUSHJ P,SWOMES## ;PRINT ERROR MESSAGE AND STOP JOB
; "SWAP OUT CHN MEM PAR ERR"
OUTER0:
IFE FTVM,<
MOVEI S,0 ;CLEAR ERROR FLAGS
> ; END OF CONDITIONAL ASSEMBLY ON FTVM
IFN FTVM,<
MOVSI T1,(SL.CHN+SL.ERR)
ANDCAM T1,SWPLST##(P1)
> ; END OF CONDITIONAL ASSEMBLY ON FTVM
JRST SWAP1 ;REENTER SWAPPER AS IF NO ERROR
; AND FINISH SWAP OUT PROCESSING
;HERE IF SWAP OUT ERROR IS ON THE DEVICE (NOT CORE MEMORY)
OUTER1: PUSHJ P,SWPREC ;RECORD ERRORS
IFE FTVM,<
SETZ T1,
DPB T1,IMGOUT##
> ;END IFE FTVM
IFN FTVM,<
PUSHJ P,MAPBAK## ;RESET THE MAP (SETOMT WIPED IT OUT)
>
JRST SWAPO ;TRY AGAIN IN A DIFFERENT PLACE
;SUBROUTINE TO RECORD SWAP IN/OUT ERRORS - REDUCE AMOUNT OF VIRTUAL CORE
; CALLED FROM SEGERR ON FIRST HIGH SEG ERROR
SWPREC::LDB T1,IMGOUT## ;KEEP COUNT OF NO. OF OCCURANCES
ADDM T1,SWPERC## ;AND TOTAL VIRTUAL CORE LOST IN TH
IFN FTVM,<
CAIG J,JOBMAX## ;HIGH SEGMENT?
ADDI T1,UPMPSZ## ;NO, THE SPACE OCCUPIED BY THE UPMP IS LOST TOO
> ;END IFN FTVM
MOVNI T1,(T1) ;DECREASE TOTAL AMOUNT OF VIRTUAL CORE
;IF THIS IS HIGH SEG
ADDM T1,VIRTAL## ;BY THE AMOUNT BEING GIVEN UP
;FALL INTO SWPRC1
;SUBROUTINE TO RECORD SWAP OUT ERROR FROM MEMORY
SWPRC1: HRRZ T1,S
IORM T1,SWPERC## ;OR IN FLAGS FOR ERROR REPORTING (18-23)
MOVSI T1,1 ;INCREASE COUNT OF NO OF SWAP ERRORS
ADDM T1,SWPERC##
POPJ P,
;NO INPUT TO DO, CHECK FOR EXPANDING JOBS
ZCKXPN:
SETZM SWPIFC ;CLEAR SWAPPER FAIRNESS SCAN
IFN FTNSCHED,<
PUSHJ P,SQTEST ;POSSIBLY RESET THE PRIMARY SCAN POINTERS
>
CHKXPN: SKIPG XJOB ;ANY JOBS TO EXPAND?
JRST CHKMIG ;NO, NO REGULAR WORK FOR SWAPPER TO DO
SETZM SCNJBS ;ONLY SCAN EXPANDING JOBS
JRST SCNOU0 ;ENTER SCNOUT
;INPUT TO DO, CHECK TO SEF IF ANY JOBS JUST HAPPEN TO WANT TO EXPAND
SCNOUT: SETOM SCNJBS ;PERMIT SWAPPING OUT JOBS
SCNOU0: SKIPE J,FORCE## ;ALREADY SCANNED FOR OUTPUT, AND FOUND A JOB
; (BUT HAS ACTIVE IO, SO FINISH NOT SET YET)
JRST SCNOU1 ;YES, TRY TO FORCE IT OUT AGAIN INSTEAD OF
; SCANNING AGAIN AND POSSIBLY FINDING A DIFFERENT JOB
; AND LEAVE THIS JOB IN CORE WITH SWP BIT ON SO CAN NOT
; RUN (CAN HAPPEN ONLY IF JOBS IN CORE EXPAND
; WHILE SWAPPING LOW SEG, SO HIGH SEG NO LONGER FITS)
; BUT DO SOME CHECKING FIRST.
SKIPG T3,XJOB ;NO, ANY JOBS WAITING TO EXPAND?
JRST SCNJOB ;NO, SCAN ALL JOBS IN PRIORITY ORDER LOOKING
; FOR ONE TO SWAP OUT
MOVSI T4,XPNMPT## ;SET UP AOBJN WORD FOR SEARCH
FNDXPN: SKIPE T1,XPNMAP##(T4) ;ANY BITS IN THIS WORD?
FNDXP1: JFFO T1,FNDXP2 ;YES. FIND FIRST ONE
AOBJN T4,FNDXPN ;NO. CHECK NEXT WORD
IFN FTRCHK,<
STOPCD .+1,DEBUG,XTH, ;++XJOB TOO HIGH
> ; END OF CONDITIONAL ASSEMBLY ON FTRCHK
SETZM XJOB ;CLEAR XJOB SO MESSAGE WILL PRINT
JRST SCNJOB ;SCAN FOR OUTPUT
FNDXP2: MOVEI J,(T4) ;GET WORD NUMBER
LSH J,5 ;TIMES 32
ADDI J,(T2) ;PLUS BIT POSITION IN WORD
;GIVES JOB NUMBER OF EXPANDING JOB
MOVSI F,(JS.HNG) ;HAS THIS JOB HUNG IN IOACT?
TDNN F,JBTST2##(J) ;...?
JRST SCNOK ;NO. PROCEED
MOVE R,JBTADR##(J) ;MUST SET UP R BEFORE CALLING ANYDEV
CAME J,.C0JOB## ;STILL CURRENT JOB(UNLIKELY)
PUSHJ P,ANYDEV## ;OR STILL ACTIVE DEVICES?
; NOTE DESTROYS ONLY F,S(AT LAST CHECK)
SOJA T3,[
TDZ T1,BITTBL##(T2) ;YES, CLEAR BIT FOR THIS JOB
JUMPG T3,FNDXP1 ;MORE EXPANDING JOBS?
SKIPN SCNJBS ;SWAP REGULAR JOBS?
JRST CHKMIG ;NO. DONE.
JRST SCNJOB ;YES. GO DO REGULAR SCAN
]
SCNOK:
IFE FTVM,<
MOVSI F,(JS.XPN) ;REMEMBER THAT JOB WAS EXPANDING
IORM F,JBTST2##(J) ;SINCE MAY NOT GET/STAY IN FORCE
>
IFN FTVM,<
SKIPE JBTADR##(J) ;DOES THIS JOB HAVE CORE IN CORE?
JRST FORCE0 ;YES, DON'T CLEAR JXPN UNTIL THE JOB IS ON WAY OUT
> ;END IFN FTVM
SOS XJOB ;DECREMENT COUNT OF EXPANDING JOBS
PUSHJ P,XPNCLR ;CLEAR BIT IN TABLE
MOVSI F,JXPN
ANDCAM F,JBTSTS##(J) ;CLEAR EXPAND BIT IN JOB STATUS WORD
;MUST BE CLEARED AFTER BIT TABLE AND
;AFTER XJOB DECREMENTED, SINCE ACTS AS
;INTERLOCK
JRST FORCE0 ;GO TRY TO SWAP JOB OUT
CHKMIG:
IFN FTDHIA&FT2SWP,<
IFN FTVM,<
SKIPN SPRCNT## ;IF THE SWAPPER IS BUSY,
SKIPE SWPCNT## ; DONT TRY TO START ANYTHING
JRST FLGNUL
>
SKIPN J,MIGRAT## ;TRYING TO FORCE JOBS OFF A SWAPPING UNIT?
JRST FLGNUL ;NO, EXIT SWAPPER
CHKMI1: CAMLE J,HIGHJB## ;YES, DONE ALL JOBS?
JRST MIGDON ;YES, THROUGH
MOVE T1,JBTSTS##(J) ;NO, GET SOME INFO ON JOB
HRR T1,JBTST2##(J)
IFN FTVM,<
TLNE T1,SWP
JRST CHKMI2 ;IF JOB IS NOT SWAPPED,
PUSHJ P,PGOFF## ; DOES IT HAVE ANY PAGES ON UNIT GOING DOWN?
JRST [MOVEM J,MIGRAT## ;YES, SWAP IT OUT AND BACK IN TO GET
JRST FORCE0] ; PAGES OFF THE BAD UNIT
AOJA J,CHKMI1 ;NO, GO CHECK NEXT JOB
CHKMI2:> ;END FTVM
IFE FTVM,<
TLNE T1,SWP ;IF JOB IS SWAPPED,
>
TRNE T1,JS.MIG ; AND WE'RE NOT SURE IT MIGRATED FROM BAD UNIT,
AOJA J,CHKMI1
CAMN J,FINISH ; IF IT ISNT BEING SWAPPED NOW,
JRST FLGNUL
MOVEM J,MIGRAT## ; SWAP IT IN, SO IT WILL SWAP OUT ONTO
JRST FIT1 ; ANOTHER SWAPPING UNIT
MIGDON: SETZM MIGRAT## ;DONE - CLEAR FLAG
;FALL INTO FLGNUL
> ;END FTDHIA&FT2SWP
IFN FTRSP,<
FLGNUL: SETOM SWPNUF## ;TELL CLOCK1 THAT SWAPPER WILL BE
;IDLE THIS TICK
POPJ P, ;RETURN
>;END IFN FTRSP
;EXIT SWAPPER IF NO RESPONSE DATA
IFE FTRSP,<
FLGNUL: POPJ P, ;IF NO RESPONSE DATA
>
;HERE IF WE ARE TRYING TO FORCE OUT A JOB LEFT OVER FROM LAST TICK.
IFN FTDISK,<
SCNOU1: CAME J,FORCEF ;IS THIS A JOB WE MUST RUN TO FREE A SHAR. RESOURCE?
JRST FORIDL ;NO, INSURE SWAP GETS SET
JRST FORCE1 ;YES, SEE IF WE CAN GET IT BEFORE TURNING ON SWAP, WHICH
; WOULD PREVENT US FROM GETTING IT BACK
; IF THE JOB DID HAVE IT
>
IFE FTDISK,<
SCNOU1==FORIDL
>
;SCAN FOR JOB TO OUTPUT IN ORDER TO MAKE ROOM FOR JOB TO COME IN
;SIZE(IN K) NEEDED TO GET THIS USER IN CORE IS IN P1(FITSIZ)
;JUST LOW SEG SIZE IF NO HIGH OR HIGH ALREADY IN, JUST HIGH IF LOW ALREADY IN,
;OR SUM IF BOTH MUST BE SWAPPED IN
SCNJOB: MOVE F,CORTAL## ;INITIALIZE FREE CORE COUNTER
MOVEM F,SUMCOR##
IFN FTPSCD,<
SETZM WASTSZ ;CLEAR PAGES WASTED ON THIS SCAN
>
SETZM MAXJBN## ;CLEAR SWAP OUT JOB NUMBER
MOVE J,FIT## ;JOB (OR HI SEG) BEING FIT IN
IFN FT2REL,< ;2 RELOC REG SOFTWARE?
PUSHJ P,FITHPQ## ;GET JOB NO. IF TRYING TO FIT A HIGH SEG
; (IN CASE HIGH PRIORITY JOB HAMPERED BY
; USER IN CORE EXPANDING DURING HIS SWAP IN
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
MOVEM J,FITLOW ;REMEMBER JOB NUMBER WE ARE FITTING
IFN FTHPQ,< ;HIGH PRIORITY QUEUES?
LDB T4,HPQPNT## ;GET CURRENT HIGH PRIORITY Q NO, 0 IF NONE
MOVEI T1,JS.TFO ;FORCED OUT BY TIMER?
TDNE T1,JBTST2##(J) ;...
SETZ T4, ;YES. DON'T IGNORE ICPT
> ; END OF CONDITIONAL ASSEMBLY ON FTHPQ
LDB T1,PJBST2## ;GET JOB PHYSICAL QUEUE
CAIL T1,CMQ ;IS IT CMQ OR PROCESSOR QUEUE?
SKIPA T1,OSCNTQ##(T1) ;YES. GET TERMINATOR FROM TABLE
MOVE T1,OSCANT## ;NO. ALL OTHERS TERMINATE AT SAME PLACE
MOVEM T1,SCNSTP ;STORE WHERE TO STOP SCAN
MOVEI U,OSCAN## ;SCAN ALL JOBS RANKED IN PRIORITY TO BE SWAPPED OUT
JSP T1,QSCAN
JRST NOFIT ;NO MORE JOBS LEFT, CANNOT FIT JOB IN CORE
CAMLE U,SCNSTP ;YES. HAVE WE REACHED END OF SCAN?
SKIPE INFLG ;YES. IGNORE IF IMPATIENT
JRST .+2 ;NOT END OF SCAN OR TIMER WENT OFF
JRST NOFIT ;CAN'T FIT JOB IN, GO TELL TIMER
CAME J,FITLOW ;DON'T SWAP OUT SWAP-IN JOB
SKIPN JBTADR##(J) ;DOES JOB HAVE LOW SEG PHYSICAL CORE?
JRST (T2) ;NO, CONTINUE SCAN TO FIND ANOTHER JOB
; (HIGH SEG ALREADY SWAPPED OUT IF NO LOW
; SEG IN CORE)
IFE FTPDBS,< ;IF WE DO NOT SWAP PDB'S
MOVE F,JBTSTS##(J) ;NO, PICK UP JOB STATUS WORD.
SKIPE W,JBTPDB##(J) ;GET PDB
SKIPGE CORSCD ;CORE SCHEDULING?
JRST SCNJB1 ;NO PDB OR NOT CORE SCHEDULING. FORGET ICPT.
IFN FTLOCK,<
TLZN F,NSWP ;NON-SWAPPABLE?
JRST SCNJ0A ;NO, SKIP LOCK CHECK
TLNN F,SWP ;ALREADY SWAPPED?
SKIPG P3,JBTSGN##(J) ;ANY HIGH SEGMENT?
JRST (T2) ;JOB CANNOT BE SWAPPED
MOVE P3,JBTSTS##(P3) ;STATUS WORD FOR SEGMENT
TLNE P3,NSHF!NSWP ;SEGMENT LOCKED?
JRST (T2) ;YES, CONTINUE SCAN
SCNJ0A:
> ;END IFN FTLOCK
> ;END FTPDBS
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
MOVE F,JBTSTS##(J) ;NO, PICK UP JOB STATUS WORD.
PUSHJ P,FNDPDB## ;GET PDB ADDRESS
JRST SCNJB1 ;NO PDB -- NO PROTECT TIME
SKIPGE CORSCD ;CORE SCHEDULING
JRST SCNJB1 ;NO, FORGET ICPT
> ;END FTPDBS
IFN FTNSCHED,<
SKIPE BBFIT## ;IS BACKGROUND BATCH TRYING TO FIT?
JRST SCNJB0 ;YES, LOOK AT ICPT
MOVSI T3,(JS.BBJ) ;BACKGROUND BATCH BIT
TDNE T3,JBTST2##(J) ;IS SCANNED JOB IN BACKGROUND BATCH?
JRST SCNJB1 ;YES, IGNORE ICPT
>
SCNJB0: TLNN F,SWP ;NO ICPT IF SWP BIT SET
.SKPGE .PDIPT##(W) ;PROTECTED TIME PAST?
SCNJB1: TLNE F,NSWP ;YES, IS THIS JOB NOT TO BE SWAPPED?
; (DISPLAY, REAL TIME)?
IFN FTHPQ,< ;HIGH PRIORITY QUEUE
JUMPE T4,(T2) ;IF JOB BEING FIT IN IS NOT HIGH PRIORITY
; CONTINUE SCAN
TLNE F,NSWP ;IS THIS JOB NOT TO BE SWAPPED?
; (DISPLAY, LOCKED IN CORE)?
> ; END OF CONDITIONAL ASSEMBLY ON FTHPQ
JRST (T2) ;YES,CONTINUE SCAN TO FIND ANOTHER
IFN FTNSCHED,<
SKIPGE JBTST2##(J) ;IS SCANNED JOB IN A PROCESSOR QUEUE?
SKIPN BBFIT## ;ARE WE FITTING BACKGROUND BATCH?
JRST SCNJB2 ;NOT PROCESSOR QUE OR NOT BACKGROUND BATCH
MOVSI T3,(JS.BBJ) ;BACKGROUND BATCH IS TRYING TO FIT
TDNN T3,JBTST2##(J) ;SCANNING A TIMESHARE JOB?
JRST (T2) ;YES, REJECT JOB
SCNJB2:>
MOVSI T3,(JS.HNG) ;HAS THIS JOB HUNG WITH IOACT?
TDNN T3,JBTST2##(J) ;..?
JRST SCNJB3 ;NO. OK
MOVSI T3,JXPN ;YES. IS IT STILL?(IF JXPN IS ON
;IT MUST HAVE BEEN STILL STUCK AT
TDNN T3,JBTSTS##(J) ;FNDXPN. DON'T TOUCH IT)
CAMN J,.C0JOB## ;CURRENT JOB?
JRST (T2) ;PICK SOMEONE ELSE
MOVE R,JBTADR##(J) ;MUST SET UP R BEFORE CALLING ANYDEV
PUSHJ P,ANYDEV## ;SHOULDN'T BOTHER OUR ACS(JUST F,S)
JRST (T2) ;STILL STUCK
SCNJB3:
IFN FTVM,<
LDB F,IMGOUT## ;OUTPUT SIZE
JUMPN F,[SKIPN INFLG ;STILL HAVE A DISK COPY?
JRST (T2) ;IF TIMER HASN'T GONE OFF, IGNORE THIS JOB
SKIPN SPRCNT## ; OTHERWISE, WE MAY WANT TO SWAP THIS JOB ANYWAY
SKIPE SWPCNT## ;IF THE SWAPPER IS IDLE, WE CAN'T
; FINISH SWAPPING IT IN
JRST (T2)
JRST .+1] ;SO WE'D BETTER SWAP IT OUT (OR SYS WILL HANG)
;THIS COULD HAPPEN IF A JOB EXPANDED IN CORE
; BEFORE THE HIGH SEGMENT COULD SWAP IN AND
; FIT GOT CLEARED BECAUSE THERE WAS NO MORE ROOM
LDB F,IMGIN##
ADDI F,UPMPSZ##
> ;END IFN FTVM
IFE FTVM,<
HLRZ F,JBTADR##(J) ;PICK UP SIZE OF JOB
ASH F,W2PLSH## ;CONVERT TO 1K BLOCKS
ADDI F,1+UPMPSZ##
> ;END IFE FTVM
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
ADDI F,PDBPGS## ;ACCOUNT FOR CORE FREED UP BY SWAPPING
; OUT THE PDB.
> ;END FTPDBS
IFN FT2REL,<
PUSHJ P,FORSIZ## ;INCREASE SIZE(F) BY HIGH SEG SIZE/# IN CORE LO SEGS +1
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
SKIPE MAXJBN## ;PICKED ONE YET?
JRST FORCE2
IFN FTMS,<
PUSHJ P,ANYRUN## ;JOB CURRENTLY RUNNING ON CPU1?
JRST [MOVEM J,SW0JOB ;FLAG TO CPU1 NOT TO RUN NEXT
JRST (T2)] ;REJECT THE JOB
; SINCE IT MAY HAVE A HI SEG WITH
; AN IN-CORE COUNT OF 1 WHICH COULD
; GET DELETED BY FORHGH
>
PUSH P,J ;SAVE J
SKIPG J,JBTSGN##(J) ;A REAL HIGH SEGMENT?
JRST FORCE3 ;NO
PUSH P,F ;SAVE F
PUSHJ P,ANYSAV## ;MAKE SURE THIS CAN SWAP
JRST [POP P,F ;RESTORE SIZE
POP P,J ;AND JOB
JRST (T2)] ;AND REJECT JOB
POP P,F ;RESTORE SIZE
FORCE3: POP P,J
MOVEM J,MAXJBN## ;NO. SAVE JOB NUMBER
FORCE2: ADDM F,SUMCOR## ;ADD TO TOTAL
IFN FTPSCD,<
SKIPL JBTST2##(J) ;IS JOB IN A PROCESSOR QUEUE?
ADDM F,WASTSZ ;NO. TOTAL IT
>
CAMLE P1,SUMCOR## ;FOUND ENOUGH CORE FOR JOB TO BE FIT IN?
JRST (T2) ;NO. LOOK FOR MORE
IFN FTNSCHED,<
SKIPN BBFIT## ;DID WE JUST FIT A BACKGROUND BATCH JOB?
JRST FORCE4 ;NO, TIMESHARING JOBS ALREADY ZEROED SCNSWP
SETZM SCNSWP## ;YES, NOW WE CAN ALLOW SCAN POINTER TO ADVANCE
MOVEM T2,SCNBBS## ;SAVE T2
MOVE T2,UPTIME## ;CURRENT TIME
ADD T2,SCDBBS## ;PLUS TIME INTERVAL BETWEEN BB SWAPS
EXCH T2,SCNBBS## ;TIME WE CAN SWAP IN NEXT BB JOB
FORCE4:
>
IFN FTPSCD,<
PUSHJ P,CNTWST ;COUNT THE WASTE
>
MOVE J,MAXJBN## ;YES, SWAP OUT FIRST
SKIPE INFLG ;TIMER GONE OFF?
SKIPL JBTST2##(J) ;YES. IS JOB IN PROCESSOR QUEUE?
JRST FORC00 ;NO. GO AHEAD
MOVEI F,JS.TFO ;YES. SET FORCED BY TIMER BIT
IORM F,JBTST2##(J)
JRST FORC00 ;AND DO PROPER SKIP ENTER OF FORCE0
;HERE FROM SCNOUT OR LOCK
FORCE0::MOVEI T2,FLGNUL ;GET READY TO FLAG SWAPPER NULL TIME IF ACTIVE DEVICES
FORC00:
IFN FT2REL,<
PUSHJ P,ANYSAV## ;NO CAN THIS JOB BE STOPPED IN ORDER TO DO SWAP?
JRST (T2) ;NO, NSWP OR NSHF SET(DISPLAY,REAL TIME) OR
; SAVE OR GET IN PROGRESS WITH DEVICE STILL ACTIVE
; LOOK FOR AN OTHER JOB TO SWAP
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
CAILE J,JOBMAX## ;HIGH OR LOW?
JRST FORCEA ;LOW. SKIP SOME WORK
MOVSI T1,(JS.HNG) ;WAS THIS JOB HUNG IN IOACT?
TDNE T1,JBTST2##(J) ;...?
JRST [SKIPN R,JBTADR##(J) ;INCORE?
JRST FORC0A ;NO, CONTINUE CHECKING
PUSHJ P,ANYDEV## ;IS JOB HUNG?
SKIPA J,MAXJBN## ;YES, LOOK FOR ANOTHER
JRST SWAPO ;NO, SWAP IT OUT
JRST 0(T2)]
FORC0A:
IFN FTDISK,<
PUSHJ P,FLSDR## ;ANY SHAREABLE DISK RESOURCES?
JRST FORCEA ;HIGH SEG OR NO RESOURCES - SO OK
MOVEM J,FORCE## ;SET FOR LATER RETRIES
MOVEM J,FORCEF ;AND FLAG THE PROBLEM
JRST FLGNUL ;QUIT FOR NOW SINCE CAN'T SWAP HIM
> ;END OF FTDISK CONDITIONAL
FORCEA:
IFN FT2REL,<
PUSHJ P,FORHGH## ;IS THERE A HIGH SEG TO BE WRITTEN BEFORE
; TRYING TO SWAP OUT LOW SEGMENT?
; WRITE HIGH SEG IF ALL OF THE FOLLOWING ARE TRUE:
; 1. JOB HAS A HIGH SEG AND
; 2. IT HAS NOT BEEN SWAPPED FOR THIS USER
; (SWP=0 FOR JOB)
; 3. IT IS IN CORE(NOT XPANDH)
; 4. IF IN-CORE COUNT IS EXACTLY 1 MEANING
; THIS ONLY USER USING IN CORE
; 5. HIGH SEG NOT ON DISK YET
; 6. THIS HIGH SEG IS NOT THE SAME ONE AS JOB
; BEING FITTED IN IS GOING TO WANT
; RETURN HIGH SEG NO. IN J IF YES, OTHERWISE
; RETURN LOW SEG NO.
; IF JOB JUST HAS LOW SEG, SHF BIT IS SET IN JBTSTS
; FOR JOB SO IO WILL STOP NEXT BUFFER
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
;HERE FROM LOKCON TOO TO FORCE OUT IDLE HIGH SEG
FORIDL::MOVSI F,SWP!IFE FT2REL,<SHF> ;SET SWAPPED OUT BIT FOR LOW OR HIGH SEG
IORM F,JBTSTS##(J) ;SCHEDULER WILL NO LONGER RUN THIS JOB
; SET SHF BIT IF ONE SEG SOFTWARE, SO IO WILL
; STOP AFTER NEXT BUFFERFUL.
; HERE TO FORCE OUT IDLE HIGH SEG WHEN IT
; HAS NO COPY ON DISK (UWP OFF)
FORCEL: MOVEM J,FORCE## ;ASSUME NOT SWAPPABLE--IS IT?
FORCE1:
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
JUMPL J,SWAPO ;NO I/O INTO PDB
> ;END FTPDBS
IFN FTKL10&FTMS,<
PUSHJ P,SWPCSH## ;JOB MUST BE RUNNABLE W.R.T. CACHE IN ORDER
; TO SWAP IT OUT, SINCE SOME OF IT MAY
; ONLY EXIST ON ANOTHER CPU'S CACHE
JRST FLGNUL ;NO GOOD, DO NOTHING THIS TICK, WAIT
; FOR OTHER CPU TO SWEEP ITS CACHE
; (HOPE THIS DOESNT HAPPEN TOO OFTEN)
>;END IFN FTKL10&FTMS
IFN FTDISK,<
SKIPN FORCEF ;TRYING TO SWAP GUY WITH DISK RESOURCE?
JRST FORCEB ;NO. PROCEED NORMALLY
PUSHJ P,FLSDR## ;YES. DOES HE STILL HAVE IT
JRST .+2 ;NO. SWAP HIM
JRST FLGNUL ;YES. TRY LATER
SETZM FORCEF ;CLEAR FLAG
JRST FORCEA ;COMPLETE THE WORK SKIPPED EARLIER
FORCEB:> ;END OF FTDISK CONDITIONAL
SKIPN R,JBTADR##(J) ;LOC. IN PHYSICAL CORE, IS CORE
; ASSIGNED IN MEMORY?
JRST SWAPO ;NO, CANNOT HAVE ACTIVE DEVICES
CAME J,.C0JOB## ;IF THIS IS CURRENT JOB, WAIT UNTIL
; PROTECTED AREA IS MOVED BACK TO JOB DATA AREA
PUSHJ P,ANYDEV## ;ANY ACTIVE DEVICES?(2ND HALF OF ANYACT ROUT.)
JRST NOFORC ;YES--START HUNG TIMER AND WAIT FOR I/O TO STOP
;SWAP OUT LOW OR HIGH SEGMENT
SWAPO: SETZM OUFLGJ ;CLEAR TIMER
CAILE J,JOBMAX## ;IS THIS A LOW SEG?
JRST SWAPO0 ;NO
PUSHJ P,DLOLST ;DELETE JOB FROM OUTPUT SCAN LIST
PUSHJ P,DLJILS ;DELETE FROM JUST SWAPPED IN LIST
MOVSI F,(JS.XPN!JS.HNG!JS.NNQ) ;CLEAR NO NEW QUANTA BIT, ETC.
ANDCAM F,JBTST2##(J)
SWAPO0:
IFE FTVM,<
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
CAILE J,JOBMAX## ;HISEG?
JRST SWAPO2 ;YES--JUST SWAP
MOVM J,J ;YES--LOOK AT JOB
SKIPN JBTADR##(J) ;SKIP IF JOB IN CORE
SWAPO1: MOVN J,J ;JOB SWAPPED TRY PDB
SWAPO2:> ;END FTPDBS
> ; END OF CONDITIONAL ASSEMBLY ON FTVM
IFN FTTRACK,< MOVEM J,LASOUT## ;SAVE LAST SWAP OUT FOR DEBUGGING ONLY
> ; END OF CONDITIONAL ASSEMBLY ON FTTRACK
SETZM FORCE## ;CLEAR FORCE FLAG
SETZM SW0JOB ;CLEAR CPU1 SWAP FLAG
MOVE T1,SCDCOR## ;GENERALLY 6 SECONDS IN TICK PAIRS
SKIPGE JBTST2##(J) ;JOB IN PROCESSOR QUEUE?
MOVEM T1,CORSCD ;YES, NOTE CORE SCHEDULING IN PROGRESS
IFN FTLOCK,<
MOVE F,JBTSTS(J) ;GET SEGMENT STATUS
TLNE F,NSWP ;IS THIS SEGMENT LOCKED IN CORE?
IFN FTVM,<
JRST [PUSHJ P,FIXXPN ;YES, RETURN AND PRETEND IT WAS SWAPPED OUT
JRST FINOU0]
>
IFE FTVM,<
JRST FINOU0
>
> ;END IFN FTLOCK
HLRZ F,JBTADR##(J) ;COMPUTE CORE IMAGE
JUMPE F,SWP1 ;DONT OUTPUT IF 0 CORE(IMGOUT ALREADY SET TO 0
; WHEN CORE WAS RETURNED
IFE FTVM,<
LDB T2,IMGOUT## ;ASSUME SWAPING SPACE
JUMPN T2,FINOU2 ; IS NOT ALREADY ALLOCATED
HRRZ T2,JBTADR##(J)
MOVNM F,T1 ;*SAVE COUNT FOR CALL TO SQOUT
ASH F,W2PLSH## ;CONVERT TO 1K BLOCKS
ADDI F,1
DPB F,IMGOUT## ;RECORD AS OUT IMAGE
HRLI T2,-1(T1) ;*BUILD AND SAVE IOWD FOR SQOUT
PUSH P,T2 ;*
> ; END OF CONDITIONAL ASSEMBLY ON FTVM
LDB U,IMGIN## ;HAS SIZE OF CORE NEEDED WHEN NEXT SWAPPED IN
IFN FTVM,<
MOVSI F,SHF ;ASSUME A LOW SEGMENT
CAIG J,JOBMAX ;IS IT?
IORM F,JBTSTS##(J) ;YES, INDICATE SWAPPING OUTPUT IN PROGRESS
LDB F,IMGOUT## ;OUTPUT IMAGE SIZE
SKIPE F ;HAS IT BEEN SET BY XPAND?
SKIPA U,F ;YES, DON'T CHANGE IT
DPB U,IMGOUT## ;NO, SET OUTPUT IMAGE
>
IFE FTVM,<
SKIPN U ;ALREADY BEEN SET(XPAND)
DPB F,IMGIN## ;NO, SO SET TO # 1K BLOCKS OF CORE NEEDED
MOVE U,F ;*CONVERT CORE IMAGE TO 128 WD BLOCKS
> ; END OF CONDITIONAL ASSEMBLY ON FTVM
IFN FTVM,<
CAIG J,JOBMAX## ;A HIGH SEGMENT?
MOVEI U,UPMPSZ##(U) ;NO, ACCOUNT FOR THE UPMP
> ; END OF CONDITIONAL ASSEMBLY ON FTVM
LDB F,IMGOUT## ;GET OUTPUT IMAGE SIZE
MOVEI T2,0 ;ZERO IMGOUT SO IF A HIGH SEGMENT IT WON'T
DPB T2,IMGOUT## ; LOOK LIKE IT ALREADY HAS DISK SPACE TO DODELE
PUSHJ P,SWPSPC## ;*GET DEVICE STORAGE, SAVE DEVICE ADDR IN JBTSWP
JRST SWAPO3 ;DIDN'T MAKE IT
DPB F,IMGOUT## ;NOW, SAFELY STORE OUTPUT SIZE
IFE FTVM,<
IFE FTPDBS,< ;IF WE DO NOT SWAP PDB'S
MOVNM J,FINISH## ;DISK SWAP SPACE ASSIGNED, NOW SET FINISH FLAG
> ;END FTPDBS
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
SETZM SWAPIN## ;FLAG AS SWAP OUT
MOVEM J,FINISH## ;DISK SWAP SPACE ASSIGNED, NOW SET FINISH FLAG
> ;END FTPDBS
; SO THAT SWAPPER WILL KNOW WHICH SEG FINISHED
; WHEN IO COMPLETED(SQREQ BECOMES ZERO)
POP P,T2 ;*GET IOWD
IFN FTRSP,<
SETZM SWPPLT## ;CLEAR LOST TIME FLAG, WE'RE ACTIVE
>;END IFN FTRSP
JRST SQOUT## ;*START OUTPUT AND RETURN
> ; END OF CONDITIONAL ASSEMBLY ON FTVM
IFN FTVM,<
PUSH P,J ;FILSER CLOBBERS J
PUSHJ P,BOSLST## ;BUILD AN OUTPUT SWPLST ENTRY
AOS SPRCNT## ;COUNT UP THE NUMBER OF SWAPS IN PROGRESS
IFN FTRSP,<
SETZM SWPPLT## ;CLEAR LOST TIME FLAG
>;END IFN FTRSP
PUSHJ P,SQOUT## ;START I/O IF NOT ALREADY GOING
POP P,J ;RESTORE SEGMENT NUMBER
PUSHJ P,FIXXPN ;FIX JXPN BIT
JRST CHKXPN
> ;END IFN FTVM
FIXXPN::MOVSI T1,JXPN ;JOB IS EXPANDING BIT
CAIG J,JOBMAX## ;HIGH SEGMENT?
TDNN T1,JBTSTS##(J) ;NO, IS THIS JOB EXPANDING?
POPJ P, ;NO, RETURN
SOS XJOB ;YES, DECREMENT THE COUNT OF EXPANDING JOBS
PUSHJ P,XPNCLR ;CLEAR BIT IN TABLE
MOVSI T1,JXPN
ANDCAM T1,JBTSTS##(J) ;CLEAR JXPN SO JOB WON'T BE SEEN AGAIN
;MUST BE CLEARED AFTER BIT TABLE AND
;AFTER XJOB DECREMENTED, SINCE ACTS AS
;INTERLOCK
POPJ P, ;AND RETURN
SWAPO3:
IFE FTVM,<
POP P,(P) ;POP OFF JUNK
>
IFN FTVM,<
LDB T1,IMGIN## ;INPUT SIZE SET BY XPAND
CAIN T1,(F) ;INPUT AND OUTPUT SIZES DIFFERENT?
MOVEI F,0 ;NO, NOT SET OUTPUT SIZE TO ZERO
DPB F,IMGOUT## ;STORE AS OUTPUT SIZE
>
MOVEM J,FORCE## ;REMEMBER WHO WE WERE TRYING TO SWAP OUT
JRST FLGNUL ;RETURN, TRY SWAP NEXT TICK
NOFIT:
IFN FTNSCHED,<
SKIPN BBFIT## ;WAS BACKGROUND BATCH SELECTED FOR SWAPIN?
JRST NOFIT1 ;NO
SETZM FIT## ;YES, DESELECT JOB
SETZM BBFIT## ;CLEAR BACKGROUND BATCH INDICATOR
PUSHJ P,SQTEST ;RESET SCAN POINTER TO SCAN SAME CLASS
JRST FLGNUL ;AND EXIT THE SWAPPER
NOFIT1:>
MOVE J,FITLOW ;PICK UP JOB NUMBER WE COULDNT FIT IN NOW
IFN FTHPQ,<
PUSHJ P,FNDPDB## ;GET PDB ADDRESS
JRST NOFIT3 ;NONE. GO ON
.SKIPG F,.PDHZF##(W) ;WAS THIS PERSON IN FIT AND TIMING?
JRST NOFIT3 ;NO. JUST NORMAL
MOVEM J,INFLGJ ;YES. PUT HIM BACK WHERE HE WAS BEFORE
MOVEM F,INFLGC ; LAST TIME IS NEW TIMER
.SETZM .PDHZF##(W) ;CLEAR FLAG
JRST NOFIT7 ;AND PROCEED
NOFIT3:> ;END IFN FTHPQ
CAMN J,INFLGJ ;SAME JOB WE COULDNT FIT IN LAST TICK?
JRST NOFIT7 ;YES. COUNT HIS FRUSTRATION INDEX
MOVEM J,INFLGJ ;NO. REMEMBER HIM FOR FUTURE REFERENCE
MOVE F,UPTIME## ;AND START TIMER
MOVEM F,INFLGC
JRST FLGNUL ;FINISH UP
NOFIT7: MOVE F,UPTIME## ;CURRENT TIME
SUB F,INFLGC ;COMPUTE TIME WE'VE BEEN WAITING
CAIGE F,^D360 ;FRUSTRATION TIMED OUT? (ABOUT 6 SEC)
JRST NOFIT9 ;NO. PATIENCE PLEASE.
SKIPN INFLG ;TIMER STILL ON FROM LAST TICK?
AOS CINFLG ; NO. COUNT # OF TIMES INFLG WAS SET.
SETOM INFLG ;GIVE HIM A QUICKER IN
NOFIT9:
JRST FLGNUL ;RETURN AND TRY TO SWAP NEXT TICK
NOFITZ: SETZM FIT## ;CLEAR JOB BEING FIT IN
IFN FTNSCHED,<
SETZM BBFIT## ;CLEAR BACKGROUND BATCH FIT FLAG
>
JRST FLGNUL ;EXIT SWAPPER. NEW JOB WILL BE SELECTED NEXT TIME
IFN FTHPQ,<
ZERFIT: SETZM FIT## ;CLEAR FIT SO WE CAN RESELECT
IFN FTNSCHED,<
SETZM BBFIT## ;CLEAR BACKGROUND BATCH FIT FLAG
>
PUSHJ P,FNDPDB## ;GET PDB ADDRESS
POPJ P, ;OOPS
MOVE T2,INFLGC ;GET TIME THIS JOB STARTED WAITING
.MOVEM T2,.PDHZF##(W) ;AND REMEMBER THAT
MOVE J,.C0RTF## ;SELECT HPQ JOB TO SWAP IN
MOVEM J,FIT##
POPJ P,
>
NOFORC: CAILE J,JOBMAX## ;LOW SEGMENT?(HIGH SHOULD NOT GET HERE)
JRST FLGNUL ;BUTS LETS BE SURE
CAMN J,OUFLGJ ;SAME AS LAST JOB?
JRST NOFOR1 ;YES. CONTINUE TIMER
MOVEM J,OUFLGJ ;NO. START NEW TIMER
MOVE F,UPTIME## ;BASED ON ELAPSED UPTIME
MOVEM F,OUFLGC
JRST NOFOR3 ;AND SCRAM OUT OF HERE
NOFOR1: MOVE F,UPTIME## ;SAME JOB. TIMER EXPIRED?
SUB F,OUFLGC
CAIGE F,^D180
JRST NOFOR3 ;NOT YET. BE PATIENT
AOS CJHUNG ;COUNT # OF TIMES A JOB HUNG WITH ACTIVE I/O
SKIPE FORCEF ;TIMER EXPIRED. BE SURE WASN'T IN FORCEF,
; SINCE WOULD BLOW SWAPPER
STOPCD NOFOR2,DEBUG,SHU, ;TRY TO RECOVER FROM GOOF
MOVSI F,(JS.HNG) ;TIMER EXPIRED. PICK SOMEONE ELSE
IORM F,JBTST2##(J) ;MARK HUNG
NOFOR2: SETZM FORCE## ;CLEAR FORCE
SETZM FORCEF ;BE CONSISTENT
SETZM OUFLGJ ;CLEAR TIMER
IFE FTVM,<
MOVSI T1,(JS.XPN) ;WAS THIS JOB EXPANDING?
TDNN T1,JBTST2##(J) ;...?
JRST NOFOR3 ;NO. NOTHING TO DO
ANDCAM T1,JBTST2##(J) ;YES. CLEAR FLAG
MOVSI T1,JXPN ;AND RESET REGULAR FLAG
TDNE T1,JBTSTS##(J) ;UNLESS ALREADY SET?
JRST NOFOR3 ;STRANGE!!
IORM T1,JBTSTS##(J) ;SET IT
AOS XJOB ;COUNT NUMBER UP ONE
PUSHJ P,XPNSET ;SET BIT TABLE
>
NOFOR3: JRST FLGNUL ;AND EXIT SWAPPER
$LOW
SW0JOB::0 ;JOB REJECTED BY SWAPPER BECAUSE IT IS RUNNING
;ON CPU1. FLAGS CPU1 TO STOP RUNNING HIM SO HE
;CAN SWAP.
CORSCD::0 ;INDICATER HOW LONG SINCE A RUNNABLE JOB WAS
;SWAPPED OUT.
INFLGJ::0 ;FRUSTRATED JOB NUMBER WAITING TO BE SWAPPED IN
INFLGC::0 ;TIME HE STARTED WAITING
INFLG:: 0 ;HE IS FRUSTRATED
CINFLG::0 ;NUMBER OF TIMES WE GOT FRUSTRATED
SCNJBS: BLOCK 1 ;FLAG WHETHER TO SCAN NON-EXPANDING JOBS FOR SWAP OUT
OUFLGJ::0 ;FRUSTRATED JOB NUMBER WAITING TO BE SWAPPED OUT
OUFLGC::0 ;TIME HE STARTED WAITING
CJHUNG::0 ;NUMBER OF TIMES FORCE WAS CLEARED TO AVOID
;HANGING THE SWAPPER
IFN FTDISK,<
FORCEF::0
>
FITLOW: 0 ;NUMBER OF JOB BEING FIT(NEVER HIGH SEG NUMBER)
NEXTJB: 0 ;NUMBER OF NEXT JOB TO SCAN IN ICPT LOOP (NXTJOB)
SWPIFC::0 ;SWAPPER FAIRNESS COUNT
MAXIFC::IFC0## ;MAXIMUM FAIRNESS COUNT FOR SWAPPER
SWPFAR: 0 ;FLAG THAT SWAPPER REACHED FAIR TERRITORY
SCNSTP: 0 ;CONTAINS ADDRESS OF OSCAN ENTRY FOR LAST QUE TO SCAN
;IF U BECOMES GREATER, SCNOUT WILL STOP SCANNING UNLESS
;INFLG IS SET
IFN FTPSCD,<
WASTSZ: 0
>
$HIGH
;SWAP IN A JOB OR HIGH SEGMENT
SWAPI:
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
CAILE J,JOBMAX## ;IS THIS A HISEG
JRST SWAPI2 ;YES--NO PDB TO WORRY US
MOVM J,J ;GET THE PDB NUMBER
MOVN J,J ; FOR THIS JOB
SKIPE JBTADR##(J) ;IS THE PDB IN CORE?
MOVM J,J ;YES--BRING IN THE LOWSEG
SWAPI2:> ;END FTPDBS
IFN FTTRACK, < MOVEM J,LASIN## ;SAVE LAST SWAP IN FOR DEBUGGING ONLY
> ; END OF CONDITIONAL ASSEMBLY ON FTTRACK
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
SETOM SWAPIN## ;FLAG AS A SWAP IN.
> ;END FTPDBS
SETZM FIT## ;CLEAR FIT FLAG
LDB T1,IMGIN## ;SIZE OF CORE TO BE ASSIGNED WHEN SWAPPED IN (IN K)
IFE FTPDBS,< ;IF WE DO NOT SWAP PDB'S
LSH T1,P2WLSH## ;CONVERT TO HIGHEST ADR
> ;END FTPDBS
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
JUMPE T1,FININ0 ;ALL DONE IF LOWSEG SIZE IS ZERO.
LSH T1,P2WLSH## ;CONVERT TO HIGHEST ADR
> ;END FTPDBS
MOVEI T1,-1(T1) ;-1 FOR CALL TO CORGET (ALWAYS POSITIVE)
SKIPE R,JBTADR##(J) ;IS (LOW) SEG ALREADY IN CORE ?
IFE FTVM,<
JRST FININ0 ;YES, POSSIBLE IF THIS IS LOW SEG AND ONLY
; HIGH SEG WAS SWAPPED OUT.
>
IFN FTVM,<
JRST FININ5 ;YES, TREAT AS SWAP IN - GO CLEAN UP
>
MOVEM J,FINISH## ;SET FINISH FLAG TO INPUT
CPUNLK (SCD) ;UNLOCK ALL CALLS TO SHUFFLER
PUSHJ P,CORGET## ;NO, GET CORE FOR LOW OR HIGH SEG
STOPCD .,STOP,CNA, ;++CORE NOT AVAILABLE
SKIPN JBTADR##(J) ;IS SPACE IN CORE?
STOPCD .,STOP,SOD, ;++SPACE ON DISK
;SPACE IS ON THE DISK. THIS HAPPENS
; IF PDB FRAGMENTS CORE.
CPLOCK (SCD) ;LOCK AGAIN
IFN FT2REL, < PUSHJ P,FITHGH## ;INCREASE INCORE COUNT FOR THIS JOB'S HIGH SEG.
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
LDB F,IMGOUT## ;GET OUTPUT IMAGE
JUMPE F,FININ0 ;DON'T INPUT IF OUT IMAGE IS 0
IFN FTPSCD,<
PUSHJ P,CNTSWP ;RECORD DATA ON SWAPPING
>
IFE FTVM,<
LDB T2,IMGIN## ;IS SIZE OF CORE SMALLER THAN DISK SPACE ?
CAMGE T2,F ;WELL ?
MOVE F,T2 ;YES, ONLY INPUT SMALLER AMOUNT (X,RUN,GET,KJOB)
LSH F,^D18+P2WLSH## ;*BUILD IOWD FOR SQIN
MOVN T2,F ;*
HRR T2,JBTADR##(J) ;*
HLRZ T1,JBTSWP##(J) ;*GET DEVICE ADDRESS
> ; END OF CONDITIONAL ASSMBLY ON FTVM
IFN FTVM,<
PUSHJ P,BUSLST## ;SETUP TO SWAP IN THE UPMP
AOS SPRCNT## ;COUNT UP NUMBER OF SWAPPING OPERATIONS IN PROGRESS
> ; END OF CONDITIONAL ASSEMBLY ON FTVM
IFN FTRSP,<
SETZM SWPPLT## ;CLEAR POT LOST FLAG, WE'RE DOING
>;END IFN FTRSP
;SOMETHING
JRST SQIN## ;*START INPUT
;ROUTINE TO CHANGE DISK SWAPPING SPACE ALLOCATION (OR SET TO 0)
;DIFFERS FROM ZERSWP IN THAT VIRTUAL TALLY FOR SYSTEM IS ALSO CHANGED
;CALLED FROM CORE0
;CALL: MOVE J,JOB OR HIGH SEG NUMBER
; MOVE T1,#1K BLOCKS TO BE NEW ASSIGNMENT
; PUSHJ P,CHGSWP
; ALWAYS RETURN
;CALLED ONLY FROM VIRTUAL+PHYSICAL CORE ROUTINE CORE0
CHGSWP::LDB T2,IMGIN## ;SIZE WHEN SEG NEXT SWAPPED IN
JUMPE T1,CHG1 ;IS ZERO BEING ASKED FOR ?
LSH T1,W2PLSH## ;NO, CONVERT TO 1K BLOCKS
ADDI T1,1 ;BUT DO NOT ATTEMPT TO RETURN DISK SPACE
; SINCE IT MIGHT BE FRAGMENTED (SWAPPER WILL
; RETURN ALL OF DISK SPACE ON NEXT SWAPIN)
; HAPPENS ONLY ON X,RUN,GET,KJOB
DPB T1,IMGIN## ;STORE NEW SIZE WHEN NEXT SWAPPED IN
PUSH P,J ;SAVE AN AC
IFN FTVM,<
MOVNI J,UPMPSZ## ;UPMP SIZE
SKIPN T2 ;IF GOING FROM 0 TO POSITIVE CORE,
ADDM J,VIRTAL## ; DECREMENT VIRTAL FOR UPMP
>
MOVE J,0(P) ;RESTORE JOB NUMBER
LDB J,IMGOUT## ;GET OLD DISK SIZE OF THIS USER (USES ITEM)
CAMGE T2,J ;IS OLD IN-CORE SIZE BIGGER ?
MOVE T2,J ;NO, USE DISK SIZE AS USER'S OLD VIRTUAL CORE
CAMGE T1,J ;IS NEW IN-CORE SIZE BIGGER ?
MOVE T1,J ;NO, USE DISK SIZE AS USER NEW
; VIRTUAL CORE
SUB T2,T1 ;DECREASE OF USER VIRTUAL CORE=OLD-NEW
ADDM T2,VIRTAL## ;USER'S DECREASE=SYSTEM'S INCREASE OF VIRTUAL
; CORE
JRST IPOPJ## ;RESTORE J AND RETURN
;ROUTINE TO RETURN ALL OF DISK SPACE FOR A LOW OR HIGH SEG
;THIS IS A PHYSICAL DEALLOCATION ONLY AND HAS NO EFFECT ON A SEGMENTS
;VIRTUAL CORE ASSIGNMENT
;CALL: MOVE J,JOB NUMBER OR HIGH SEG NUMBER
; PUSHJ P,ZERSWP
;CALLED FROM SEGCON IN MANY PLACES (5)
;AND FININ0 HERE IN SWAP
CHG1:
IFN FTVM,<
JUMPE T2,ZERSWP ;HAVE CORE ON DISK?
CAIG J,JOBMAX## ;LOW SEGMENT?
ADDI T2,UPMPSZ## ;YES, ACCOUNT FOR THE UPMP
>
ADDM T2,VIRTAL## ;INCREASE SIZE OF VIRTUAL CORE AVAILABLE IN SYSTEM
; AND THEN RETURN ALL OF DISK SPACE (CHGSWP)
ZERSWP::PUSH P,U ;SAVE TTY OUTPUT BYTE POINTER (COMMAND DECODER)
LDB U,IMGOUT## ;*SIZE ON DISK (1K BLOCKS)
JUMPE U,CHG10 ;DID SEG HAVE ANY DISK SPACE ?
HLRZ T1,JBTSWP##(J) ;*YES, LOGICAL DISK BLOCK+FRGSEG BIT
IFN FT2REL,< PUSHJ P,ZERSWH## ;IS THIS A HIGH SEG WITH AN ERROR?
;T2 SETUP AS ARG
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
IFE FTVM,<
PUSHJ P,FXSAT## ;*NO, FREE THE DISK BLOCKS NO LONGER NEEDED
> ; END OF CONDITIONAL ASSEMBLY ON FTVM
IFN FTVM,<
PUSHJ P,GIVBKH ;GIVE BACK HIGH SEGMENT SWAPPING SPACE
> ; END CONDITIONAL ASSEMBLY OF FTVM
CHG10: POP P,U ;RESTORE U
UNSWAP: MOVSI T2,SWP!SHF ;CLEAR SWAPPED OUT BIT IN JOB OR SEG
ANDCAB T2,JBTSTS##(J) ;STATUS WORD (SHF SET IF I/O WAS TO BE STOPPED
; FOR SWAP OR CORE SHUFFLE
HRRZ T1,J ;GET JOB NUMBER IN T1
CAME T1,FORCE ;SWAPPER REMEMBERING US?
JRST UNSWP1 ;NO, CONTINUE
SETZM FORCE ;YES, CLEAR FLAGS THAT HAVE OUR NUMBER
IFN FTDISK,<
SETZM FORCEF ;FORCEF MAY HAVE OUR JOB NUMBER TOO
>
;(FORCEF SHOULD EITHER BE ZERO OR SAME AS FORCE)
UNSWP1: MOVEI T1,0 ;0 IS NEW DISK ASSIGNMENT
DPB T1,IMGOUT## ;SET DISK ASSIGNMENT TO 0
IFN FTVM,<
CAIG J,JOBMAX## ;A LOW SEGMENT?
HRRZS JBTSWP##(J) ;SO IT WONT LOOK LIKE IT HAS CORE
;WHEN IT DOESNT
>
IFE FTVM,<
DPB T1,IMGIN## ;SET NEW CORE IMAGE BLOCK SIZE WHEN NEXT SWAPPED IN
>
; HERE FROM CHGSWP IF NOT ASKING FOR 0
POPJ P, ;RETURN
IFN FTVM,<
RTNDSP::TLNE T1,(SL.ERR+SL.CHN) ;DONT GIVE BACK SWAPPING SPACE IF BAD
POPJ P, ;RETURN
LDB U,[POINT 9,T1,35] ;NUMBER OF PAGES OF SWAPPING SPACE
LDB T1,[POINT 13,T1,26] ;FIRST PHYSICAL PAGE I/O WAS DONE INTO OR OUT OF
LDB T1,[POINT 17,MEMTAB(T1),35] ;FIRST DISK ADDRESS
PJRST FXSAT1## ;RETURN THE DISK SPACE
;SUBROUTINE TO GIVE BACK DISK SPACE AND CORE BLOCKS
;CALL WITH P1=LOC OF SWPLST ENTRY
GIVBAK: LDB T1,IMGOUT## ;OUTPUT IMAGE SIZE
JUMPE T1,CPOPJ## ;RETURN IF NO OUTPUT IMAGE
PUSHJ P,ZERSLE ;RETURN THE DISK SPACE
PJRST DLTSLE## ;AND DELETE THE SWPLST ENTRY
ZERSLE::SKIPL T1,SWPLST##(P1) ;FRAGMENTED?
PJRST RTNDSP ;NO, JUST RETURN THE DISK SPACE
PUSHJ P,SAVE1## ;SAVE AN AC
HRRZ P1,T1 ;ADDRESS OF THE FRAGMENT TABLE
GIVBK1: MOVE T1,(P1) ;NEXT ENTRY IN THE FRAGMENT TABLE
JUMPLE T1,GIVBK2 ;JUMP IF A LINK WORD
PUSHJ P,RTNDSP ;RETURN THE DISK SPACE REPRESENTED IN THIS ENTRY
AOSA P1 ;STEP ON TO THE NEXT ENTRY IN THE TABLE
GIVBK2: HRRZ P1,T1 ;LINK TO NEXT ENTRY
JUMPN P1,GIVBK1 ;JUMP IF NOT THE LAST ENTRY
POPJ P, ;ALL DONE, RETURN
GIVBKH: PUSHJ P,SAVE1## ;SAVE P1
MOVSI P1,MJBTMX## ;- TOTAL NUMBER OF SEGMENTS ALLOWED
CHG4: SKIPN SWPLST##(P1) ;NON-ZERO ENTRY IN SWPLST?
JRST CHG6 ;NO, LOOK AT THE NEXT ENTRY
HRRZ T1,SW3LST##(P1) ;SEGMENT NUMBER ASSOCIATED WITH THIS ENTRY
CAIN T1,(J) ;SAME AS THE ONE WE ARE LOOKING FOR?
PJRST GIVBAK ;YES, GIVE BACK THE DISK SPACE
CHG6: AOBJN P1,CHG4 ;LOOP FOR THE NEXT ENTRY
HLRZ T1,JBTSWP##(J) ;GET SWAPPING POINTER
PJRST FXSAT## ;GIVE BACK THE DISK SPACE
>
;XPAND SETS CONDITIONS TO GET MORE CORE FOR A JOB BY SWAPPING IN OUT
;THEN BACK IN TO DESIRED AMOUNT.
;JOBS POSITION IN QS NOT AFFECTED.
;CALLED ONLY FROM CORE COMMAND
;ASSUMES CALL FOR CURRENT JOB IF EXPANDING HIGH SEG,IE ASSUME AT UUO LEVEL
;THIS IS TRUE SINCE THERE IS NO CORE COMMAND WHICH CAN EXPAND HIGH SEG
;CALL: MOVE J,[JOB NUMBER]
; MOVE T1,[HIGHEST LEGAL ADDRESS DESIRED]
; PUSHJ P,XPAND
; RETURN, T1 DESTROYED
XPAND::
IFN FTVM,<
CAILE J,JOBMAX## ;IS THIS A LOW SEG?
TLNN J,SHRSEG ;SHAREABLE HIGH SEG?
CAIA ;OK TO CHANGE JBTADR
JRST XPAND2 ;DON'T CHANGE JBTADR FOR SHR SEG
SKIPE R ;DON'T MAKE JBTADR NON-ZERO IF NO CORE IN CORE
HRLM T1,JBTADR##(J) ;MAKE JBTADR RIGHT
XPAND2:>
ADDI T1,1 ;CONVERT HIGHEST DESIRED ADDRESS
LSH T1,W2PLSH## ;TO 1K BLOCKS
IFN FTVM,<
CAILE J,JOBMAX## ;A LOW SEGMENT?
JRST XPANDP ;NO, A SHARABLE HIGH SEGMENT, DON'T CHANGE
; THE WORKING SET
JUMPE R,XPAND1 ;IF NO CORE, NO WORKING SET TO MAKE RIGHT
PUSHJ P,ADJWS## ;TURN ON BITS IN WSBTAB WHICH REPRESENT PAGES
; BEING ADDED TO THE WORKING SET
XPANDP::LDB T2,IMGIN## ;CURRENT PHYSICAL SIZE
DPB T2,IMGOUT## ;STORE AS OUTPUT IMAGE SIZE
XPAND1:>
DPB T1,IMGIN## ;STORE, SO SWAPPER WILL KNOW HOW MUCH CORE
; TO REQUEST WHEN NEXT SWAPPED IN
;ROUTINE TO FLAG JOB TO BE STOPPED AND SWAPPED OUT
;BECAUSE IT HAS JUST BEEN CONNECTED TO A HIGH SHARABLE SEG WHICH IS ON DISK
;OR ON ITW WAY IN OR OUT. THE SIZE OF THE HIGH SEG IS UNCHANGED
;THE JOB MUST BE STOPPED UNTIL HIGH SEG SWAPPED IN JUST AS IF JOB HAS
;EXPANDED HIGH SEG (MUST BE CALLED FROM UUO LEVEL FOR CURRENT JOB IF HIGH SEG)
; ALSO CALLED BY MEMORY PARITY ERROR RECOVERY
; IF JOB (LOW OR HIGH SEG) IS LOCKED OR HIGH SEG LOCKED
; NOTHING IS SWAPPED OUT (INCLUDING OTHER JOBS USING HIGH SEG)
;CALL: MOVE J,HIGH SEG NUMBER
; PUSHJ P,XPANDH
XPANDH::
IFN FT2REL,< ;2 RELOC REG SOFTWARE?
PUSH P,J ;SAVE JOB NUMBER
PUSHJ P,XPNHGH## ;CHECK IF THIS IS A HIGH SEG EXPANDING
; IF YES, SCAN OTHER JOBS, CALL XPANDH
; FOR EACH JOB WHICH IS STILL IN CORE
; SET JXPN FOR THIS HIGH SEG. THUS NO JOB
; WILL BE ABLE TO USE THIS HIGH SEG UNTIL
; IT IS SWAPPED BACK IN FOR SOME JOB.
; ALWAYS RETURN JOB NO.
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
MOVSI T2,JXPN ;SET THIS JOB EXPANDING BIT SO IT WILL NOT BE RUN
IFN FTPDBS,< ;THIS IS INCLUDED IF WE SWAP PDB'S
MOVM J,J ;MAKE SURE WE HAVE A JOB NUMBER
CAMLE J,HIGHJB## ;IS THIS NUMBER GREATER THAN THE HIGHEST
; JOB NUMBER IN THE SYSTEM.
MOVEM J,HIGHJB## ;YES--FIX UP HIGHJB. THIS HAPPENS IF
; CREPDB IS CALLED FOR A NEW PROCESS
; AND WE NEED TO PLACE THE PDB ON THE
; DISK FOR A WHILE.
> ;END FTPDBS
TDNE T2,JBTSTS##(J) ;IS IT ALREADY SET FOR THIS JOB?(UNLIKELY)
IFE FT2REL, <
POPJ P, ;RETURN
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
IFN FT2REL, <
JRST IPOPJ## ;RESTORE JOB OR HIGH SEG NUMBER (ITEM) AND RETURN
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
AOS XJOB ;NO, INCREMENT COUNT ONLY ONCE FOR EACH JOB EXPANDING
IORM T2,JBTSTS##(J) ;AND SET JOB EXPANDING BIT
PUSHJ P,XPNSET ;AND SET BIT MAP ENTRY TOO.
IFE FT2REL, <
POPJ P, ;RETURN
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
IFN FT2REL, <
JRST IPOPJ## ;RESTORE JOB OR HIGH SEG NUMBER (ITEM) AND RETURN
> ; END OF CONDITIONAL ASSEMBLY ON FT2REL
; SUBROUTINE TO SET/CLEAR ENTRY IN BIT MAP OF EXPANDING JOBS
XPNSET: SKIPA T1,[IORM T3,XPNMAP##(T2)] ;SET
XPNCLR: MOVE T1,[ANDCAM T3,XPNMAP##(T2)] ;CLEAR
CAILE J,JOBMAX## ;LOW SEGMENT?
POPJ P, ;NO. NO BIT MAP ENTRY
PUSH P,T3 ;SAVE A REGISTER
SETZ T3, ;AND CLEAR ONE
MOVE T2,J ;COPY JOB NUMBER
LSHC T2,-5 ;DIVIDE BY 32
ROT T3,5 ;ALLIGN REMAINDER
MOVE T3,BITTBL##(T3) ;GET CORRESPONDING BIT
XCT T1 ;SET/CLEAR BIT IN TABLE
PJRST T3POPJ## ;RESTORE T3 AND RETURN
SUBTTL SCHED. UUO
IFN FTNSCHED,<
;SCHED. UUO USED TO SET SCHEDULER PARAMETERS
; CALL:
; MOVE AC,[XWD N,ADDR]
; SCHED. AC, ;OR CALLI AC,150
; ERROR RETURN
; GOOD RETURN
;
; THE FORMAT OF ADDR THROUGH ADDR+N-1 IS
;
; ADDR: XWD FN CODE,BLOCK
; XWD FN CODE,BLOCK
; .
; .
; .
; WHERE FN CODE IS THE FUNCTION CODE DESIRED. BIT 0 CONTROLS WHETHER
; THE READ PART OR THE WRITE PART OF THE FUNCTION IS SELECTED, A 1 MEANING
; WRITE.
; THE FORMAT OF BLOCK DIFFERS WITH EACH FUNCTION, AND IS DESCRIBED BEFORE
; EACH FUNCTION'S SUBROUTINE.
SC.WRT==1B0 ;WRITE BIT (MUST BE SIGN BIT)
SCHED.::PUSHJ P,SAVE1## ;SAVE P1
MOVE P1,T1 ;SAVE C(AC) IN P1
PUSHJ P,PRVJ## ;PRIVILEGED?
JRST .+2 ;YES, CONTINUE
JRST SCHNPE ;NO,GIVE ERROR
HLRE T1,P1 ;GET NUMBER OF OPERATIONS
JUMPLE T1,CPOPJ1 ;DONE IF ZERO OR NEG.
MOVNS T1
HRL P1,T1 ;-N,,ADDR IS AOBJN POINTER
SCHDU1: HRR M,P1 ;GET ADDR OF BLOCK
PUSHJ P,SCHGET ;GET A FUNCTION
HRR M,T1 ;GET ADDRESS IN M
HLRZ T2,T1 ;GET FUNCTION, BITS IN T2
TRZ T2,(SC.WRT) ;CLEAR WRITE BIT (MUST BE SIGN BIT)
CAILE T2,SCDFMX ;OVER MAXIMUM FUNCTION?
JRST SCHFNE ;YES, FUNCTION NUMBER ERROR
MOVE T3,SCDDIS(T2) ;ASSUME WRITE OPERATION
JUMPL T1,.+2 ;TEST WRITE BIT
MOVSS T3 ;FUNCTION IS REALLY READ.
PUSHJ P,(T3) ;DISPATCH TO ROUTINE
POPJ P, ;ERROR - CODE IS STORED IN USER AC
AOBJN P1,SCHDU1 ;CONTINUE FOR ALL FUNCTIONS
JRST CPOPJ1 ;FINISHED. RETURN SUCCESSFULLY
;DISPATCH TABLE. LEFT HALF IS ADDRESS OF READ PART OF FUNCTION,
; RIGHT HALF IS ADDRESS OF WRITE PART.
SCDDIS: XWD SCHRSI,SCHWSI ;(0)READ/SET MICRO SCHEDULING INTERVAL
XWD SCHFNE,SCHFNE ;(1)READ/SET MCU INTERVAL
XWD SCHRQT,SCHWQT ;(2)READ/SET CLASS QUOTAS AND FLAGS
XWD SCHRTS,SCHWTS ;(3)READ/SET BASE QUANTUM RUN TIME FOR PQ1 AND PQ2
XWD SCHFNE,SCHFNE ;(4)READ/SET DCUF
XWD SCHRJC,SCHWJC ;(5)READ/SET JOB'S CLASS
XWD SCHRMC,SCHWMC ;(6)READ/SET PROT0 (MCU CONSTANT)
XWD SCHRCT,SCHFNE ;(7)READ QUOTAS USED FOR EACH CLASS SINCE STARTUP
XWD SCHFNE,SCHFNE ;(10)READ/SET EXPONENTIAL FACTOR
XWD SCHRPF,SCHWPF ;(11)READ/SET MCU MULTIPLIER (PROT)
XWD SCHRCD,SCHWCD ;(12)READ/SET NEW JOBS' DEFAULT CLASS
XWD SCHRRC,SCHWRC ;(13)READ/SET MCU REQUEUE CONSTANT (PROT1)
XWD SCHRPM,SCHWPM ;(14)READ/SET MCU MAXIMUM (PROTM)
XWD SCHRML,SCHWML ;(15)READ/SET QUANTUM MULTIPLIER FOR PQ1 AND PQ2
XWD SCHRMX,SCHWMX ;(16)READ/SET QUANTUM MAXIMUM FOR PQ1 AND PQ2
XWD SCHRSQ,SCHWSQ ;(17)READ/SET SECONDARY CLASS QUOTAS
XWD SCHRIQ,SCHWIQ ;(20)READ/SET JBTJIQ SCAN PERCENTAGE
XWD SCHRSS,SCHWSS ;(21)READ/SET SWAP SCAN TIME
XWD SCHRBB,SCHWBB ;(22)READ/SET BACKGROUND BATCH QUEUE
XWD SCHRBS,SCHWBS ;(23)READ/SET BB SWAP SCAN TIME
XWD SCHRSF,SCHWSF ;(24)READ/SET SCHEDULER FAIRNESS FACTOR
XWD SCHRSW,SCHWSW ;(25)READ/SET SWAPPER FAIRNESS FACTOR
XWD SCHRIO,SCHWIO ;(26)READ/SET INCORE FAIRNESS PERCENTAGE
XWD SCHRCS,SCHWCS ;(27)READ/SET CORE SCHEDULING INTERVAL
SCDFMX==.-SCDDIS-1 ;MAXIMUM FUNCTION NUMBER
;ROUTINES TO PERFORM SCHED. UUO FUNCTIONS. CALLED FROM SCHED. UUO
; WITH M SET TO ADDRESS OF BLOCK. THESE ROUTINES PRESERVE P1-P4, USE
; T1,T2,T3,T4
;FUNCTION 0
;READ/SET SCHEDULING INTERVAL
; READ FUNCTION RETURNS INTERVAL VALUE AT LOCATION BLOCK
; FORMAT OF ARGUMENT BLOCK ON WRITE:
;
; BLOCK: <DESIRED VALUE>
SCHRSI: MOVE T1,SCDINT## ;GET INTERVAL
SCHPVL: PUSHJ P,PUTWRD## ;SEND TO USER
JRST SCHAER ;ADDRESS PROBLEM...
JRST CPOPJ1 ;OK
SCHWSI: PUSHJ P,SCHGET ;GET ARGUMENT FROM ADDRESS IN M
MOVEM T1,SCDINT ;USE AS SCHEDULING INTERVAL
SETZM SCDTIM## ;FORCE NEW SCHEDULING INTERVAL
JUMPG T1,CPOPJ1## ;LEAVE RRFLAG ALONE IF THERE IS AN INTERVAL
SETZM RRFLAG## ;USE ROUND ROBIN IF NO INTERVAL
AOS (P) ;GIVE GOOD RETURN
;PJRST SCHCLR ;ZERO CLASS RUN IMES
;HERE TO CLEAR TABLE OF CLASS RUN TIMES
SCHCLR: SETZM SCDTIM## ;FORCE A NEW SCHED INTERVAL
MOVE T3,DATE## ;PUT UNIVERSAL DATE-TIME
MOVEM T3,SCDSTS## ;INTO TIME OF LAST CLASS RUNTIME INITIALIZATION
SKIPN RRFLAG## ;CURRENTLY CLASS SCHEDULING?
SETZ T3, ;NO, STORE ZERO INSTEAD
MOVEM T3,SCDSET## ;INTO FLAG WORD IN GETTAB TABLE 115
MOVEI T2,M.CLSN##-1 ;COMPUTE END ADDRESS
MOVE T1,[CLSRTM##,,CLSRTM##+1]
CONO PI,PIOFF## ;DON'T INTERRUPT US
SETZM CLSRTM## ;CLEAR CLSRTM
BLT T1,CLSRTM##(T2)
SETZM RTCTOT## ;CLEAR USER TIME SINCE WE LAST DID THIS
CONO PI,PION## ;PI BACK ON
POPJ P,
;FUNCTION 2
;
;HERE TO READ CLASS QUOTAS
; ARGUMENT BLOCK SETUP FOR READ CLASS QUOTA FUNCTION:
;
; BLOCK: N ;NUMBER OF CLASSES TO READ QUOTAS OF
; BLOCK+1: ;QUOTA AND BITS OF CLASS 0 RETURNED HERE
; BLOCK+2: ;QUOTA AND BITS OF CLASS 1 RETURNED HERE
; .
; BLOCK+N: ;QUOTA AND BITS OF CLASS N-1 RETURNED HERE
;
SCHRQT: PUSHJ P,SCHGET ;GET NUMBER OF CLASSES TO RETURN
SKIPLE T1 ;TOO LOW OR
CAILE T1,M.CLSN## ;TOO HIGH?
JRST SCHCLE ;YES, TELL HIM SO
MOVN T4,T1 ;GET AN AOBJN POINTER
HRLZS T4
SCHRQ1: MOVE T1,CLSSTS##(T4) ;GET QUOTA, BITS FOR CLASS
JSP T2,SCHBLK ;STORE WORD
JRST SCHRQ1 ;LOOP FOR MORE
;HERE TO SET QUOTAS FOR CLASS
;
; FORMAT OF BLOCK:
;
; BLOCK: N ;NUMBER OF WORDS FOLLOWING
; BLOCK+1: XWD <BITS>+CLASS,QUOTA
; BLOCK+2: XWD <BITS>+CLASS,QUOTA
; .
; BLOCK+N: XWD <BITS>+CLASS,QUOTA
;
SCHWQT: PUSHJ P,SCHGET ;GET NUMBER OF ARGS
JUMPLE T1,CPOPJ1 ;DONE IF LE ZERO
MOVE T4,T1 ;SAVE IN T4
SCHWQ1: PUSHJ P,SCHGT1 ;GET ARG
LDB T3,[POINT 5,T1,17] ;GET CLASS
CAIL T3,M.CLSN## ;TOO HIGH?
JRST SCHCLE ;YES, REPORT IT.
TLZ T1,(JS.CLS) ;CLEAR CLASS PART OF ARG
MOVEM T1,CLSSTS##(T3) ;JUST SAVE QUOTA AND BITS
SOJG T4,SCHWQ1 ;AND LOOP UNTIL DONE.
PUSHJ P,SCHCLR ;CLEAR CLASS RUN TIMES AND SETUP T2
SETZB T3,TOTSTS## ;INIT COUNT AND TOTAL OF NON-ZERO CLASSES
SCHWQ2: HRRZ T1,CLSSTS##(T2) ;GET QUOTA
JUMPE T1,SCHWQ3 ;JUMP IF NO QUOTA
ADDM T1,TOTSTS## ;ADD UP QUOTAS
HRRZM T2,SQSCAN##(T3) ;STORE 0,,CLASS NUMBER IN TABLE
AOJ T3, ;COUNT UP NON-ZERO CLASSES
SCHWQ3: SOJGE T2,SCHWQ2 ;LOOP OVER ALL CLASSES
MOVEM T3,CNTSTS## ;STORE COUNT OF NON-ZERO CLASSES
JUMPG T3,SCHWQ4 ;LEAVE RRFLAG ALONE IF THERE ARE ANY CLASSES
SETZM RRFLAG## ;USE ROUND ROBIN IF NO CLASSES EXIST
SETZM SCDSET## ;ZERO FOR NOT CLASS SCHEDULING
JRST CPOPJ1 ;GOOD RETURN.
SCHWQ4: MOVEI T1,^D100 ;REQUIRE PRIMARY TABLE TO ADD TO 100%
CAMN T1,TOTSTS## ;IS IT?
JRST SCHWQ5 ;YES
SETZM RRFLAG## ;NO, DO NOT CLASS SCHEDULE
SETZM CNTSTS## ;MAKE IT LOOK LIKE NO CLASSES EXIST
SETZM SCDSET## ;FLAG FOR NOT CLASS SCHEDULING
JRST SCHNHP ;NOT HUNDRED PERCENT
SCHWQ5: PUSHJ P,SAVE2## ;FREE 2 ACS
MOVE T4,[POINT 5,PSQTAB##] ;POINTER TO PRIMARY SCAN TABLE
SCHWQ6: MOVE T3,CNTSTS## ;NUMBER OF NON-ZERO CLASSES
SETZ P1, ;POINTER TO MAX ENTRY FOUND SO FAR
MOVSI P2,400000 ;SET MAX TO SMALLEST POSSIBLE INTEGER
SOJLE T3,SCHWQ9 ;JUMP IF ONLY ONE CLASS
SCHWQ7: MOVE T2,SQSCAN##(T3) ;GET NEXT ENTRY'S PRIORITY
HRR T2,CLSSTS##(T2) ;APPEND QUOTA
HRLZ T1,T2 ;ADD QUTOA
ADD T2,T1 ;TO PRIORITY
HLLM T2,SQSCAN##(T3) ;MAKING HIM MORE LIKELY TO BE PICKED
IMULI T2,(T2) ;WEIGHT PRIORITY WITH QUOTA
CAMG T2,P2 ;GREATER THAN CURRENT MAX?
JRST SCHWQ8 ;NO
MOVE P2,T2 ;SAVE MAX
MOVEI P1,(T3) ;SAVE POINTER
SCHWQ8: SOJGE T3,SCHWQ7 ;UPDATE NEXT ENTRY
SCHWQ9: MOVE T1,SQSCAN##(P1) ;GET THE ENTRY WE PICKED
IDPB T1,T4 ;STORE HIS CLASS IN PRIMARY SCAN TABLE
SUB T1,[^D100,,0] ;HE GOT HIS SHARE
HLLM T1,SQSCAN##(P1) ;SO MAKE HIM LESS LIKELY TO BE CHOSEN
SOSLE TOTSTS## ;DONE THIS 100 TIMES?
JRST SCHWQ6 ;NO, DO SOME MORE
LDB T1,[POINT 5,PSQTAB##,4] ;GET FIRST BYTE
DPB T1,[POINT 5,PSQTAB##+^D14,14] ;STORE IN BYTE 101 FOR CPU1
JRST CPOPJ1 ;GOOD RETURN
;FUNCTION 3
;
;HERE TO READ TIME SLICES FOR EITHER PQ1 OR PQ2
; FORMAT OF BLOCK:
;
; BLOCK: N ;NUMBER OF QUEUES TO READ TIME SLICES FOR
; ;(CAN ONLY BE 1 OR 2)
; BLOCK+1: ;TIME SLICE FOR PQ1 RETURNED HERE
; BLOCK+2: ;TIME SLICE FOR PQ2 RETURNED HERE
; ;(IF N WAS BIG ENOUGH)
;
SCHRTS: PUSHJ P,SCHGET ;GET N
MOVEI T4,QADTAB## ;ADDRESS WHERE DATA IS STORED
;PJRST SCHRTB ;READ THE TABLE
SCHRTB: CAIG T1,2 ;LEGAL ARG?
SCHRTC: SKIPG T1
JRST SCHQNE ;NO
SCHRTD: MOVN T1,T1
HRL T4,T1 ;AOBJN POINTER
SCHRT1: MOVE T1,(T4) ;GET SLICE
IMULI T1,^D1000 ;MILLITICKS
IDIV T1,TICSEC## ;CONVERT TO MILLISECS
JSP T2,SCHBLK
JRST SCHRT1
;HERE TO WRITE TIME SLICES FOR PQ1 OR PQ2
; FORMAT OF BLOCK:
;
; BLOCK: N ;NUMBER OF WORDS FOLLOWING
; BLOCK+1: XWD Q#,TIME SLICE(MS)
; BLOCK+2: XWD Q#,TIME SLICE(MS)
; .
; BLOCK+N: XWD Q#,TIME SLICE
;
SCHWTS: PUSHJ P,SCHGET ;GET N
JUMPLE T1,CPOPJ1 ;DONE IF LE ZERO
MOVE T4,T1 ;COPY N
SCHWT1: PUSHJ P,SCHGT1 ;GET ARG
MOVE T2,TICSEC## ;GET JIFSEC
IMULI T2,(T1) ;GET MILLITICS IN T2
IDIVI T2,^D1000 ;CONVERT TO TICKS (ARG WAS IN MS)
HLRZ T3,T1 ;GET Q NUMBER
SKIPE T3 ;ZERO IS NOT LEGAL
CAILE T3,2 ;LEGAL?
JRST SCHQNE ;NO, Q NUMBER ERROR
MOVEM T2,QADTAB##-1(T3);SAVE
SOJG T4,SCHWT1 ;AND LOOP
JRST CPOPJ1 ;FINISHED.
;FUNCTION 5
;
;HERE TO READ CLASS NUMBERS FOR ALL JOBS ON THE SYSTEM UP TO
; THE NUMBER IN ADDRESS
; FORMAT OF BLOCK:
;
; BLOCK: N ;NUMBER OFJOBS TO READ CLASS FOR
; BLOCK+1: ;RETURN CLASS OF JOB 1 HERE
; BLOCK+2: ;RETURN CLASS OF JOB 2 HERE
; .
; BLOCK+N: ;RETURN CLASS OF JOB N HERE
;
SCHRJC: PUSHJ P,SCHGET ;GET NUMBER OF JOBS TO DO
PUSHJ P,LGLPRC## ;IS THIS A LEGAL JOB NUMBER?
JRST SCHBJN ;NO
MOVN T4,T1
HRLZS T4
AOS T4 ;START WITH JOB 1
SCHRJ1: LDB T1,JBYCL4## ;GET CLASS
JSP T2,SCHBLK
JRST SCHRJ1
;HERE TO PUT A JOB INTO A CPU CLASS
; FORMAT OF BLOCK:
;
; BLOCK: N ;NUMBER OF WORDS FOLLOWING
; BLOCK+1: XWD JOB,CLASS
; BLOCK+2: XWD JOB,CLASS
; .
; BLOCK+N: XWD JOB,CLASS
;
SCHWJC: PUSHJ P,SCHGET ;GET N
JUMPLE T1,CPOPJ1 ;RETURN IF NO WORK TO DO
MOVE T4,T1 ;COPY N
SCHWJ1: PUSHJ P,SCHGT1 ;
HRRZ T2,T1 ;SAVE CLASS NUMBER IN T2
HLRZS T1 ;GET JOB NUMBER IN RHOF T1 FOR LGLPRC
CAIN T1,-1 ;US?
MOVE T1,J ;YES, USE OUR JOB NUMBER
PUSHJ P,LGLPRC## ;LEGAL JOB NUMBER?
JRST SCHBJN ;NO
MOVSI T3,JNA
TDNN T3,JBTSTS##(T1)
JRST SCHBJN ;NO GOOD IF JOB NOT ASSIGNED
CAIL T2,M.CLSN## ;BAD CLASS NUMBER?
JRST SCHCLE ;YES.
DPB T2,JBYCL1## ;DEPOSIT
SKIPL JBTSCD##(T1) ;IS JOB IN PQ2?
JRST SCHWJ3 ;NOT IN PQ2
MOVSI T2,(JS.CSQ) ;JOB IS CHANGING SUB QUEUE
IORM T2,JBTST2##(T1) ;SET BIT FOR THE JOB
CAMN T1,.C0JOB## ;IS THIS JOB US?
JRST SCHWJ2 ;YES
PUSH P,J ;SAVE OUR JOB NUMBER
MOVE J,T1 ;GET TARGET JOB IN J
PUSHJ P,REQUE## ;REQUEUE HIM SO HE WILL WIND UP IN PROPER SUBQUE
POP P,J
JRST SCHWJ3 ;GO ON
SCHWJ2: CONO PI,PIOFF## ;TURN OFF PIS
SKIPN .C0RTF## ;ALREADY REAL TIME REQUEST IN?
SETOM .C0RTF## ;NO. PUT ONE IN
CONO PI,PION## ;TURN PIS ON
SETOM .C0HQU## ;REQUEST A REQUEUE
SCHWJ3: SOJG T4,SCHWJ1 ;AND LOOP FOR NEXT SPEC.
JRST CPOPJ1
;FUNCTION 6
;
;HERE TO READ MCU CONSTANT (PROT0)
; FORMAT OF BLOCK
;
; BLOCK: ;PROT0 RETURNED HERE
;
SCHRMC: MOVE T1,PROT0##
PJRST SCHPVL ;STORE VALUE IN USERS AREA AND RETURN
;HERE TO WRITE MCU CONSTANT (PROT0)
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED VALUE OF PROT0>
SCHWMC: PUSHJ P,SCHGET
MOVEM T1,PROT0##
JRST CPOPJ1
;FUNCTION 7
;
;HERE TO READ TIME SINCE SYSTEM STARTUP EACH CLASS HAS USED.
; FORMAT OF BLOCK
;
; BLOCK: N ;NUMBER OF CLASSES TO READ RUNTIMES FOR
; BLOCK+1: ;CLASS 0 RUNTIME RETURNED HERE
; BLOCK+2: ;CLASS 1 RUNTIME RETURNED HERE
; .
; BLOCK+N: ;CLASS N-1 RUNTIME RETURNED HERE
;
SCHRCT: PUSHJ P,SCHGET
SKIPLE T1 ;BOMB IF OUT OF RANGE
CAILE T1,M.CLSN##
JRST SCHCLE
MOVN T4,T1
HRLZS T4
SCHRC1: MOVE T1,CLSRTM##(T4) ;GET TIME
JSP T2,SCHBLK
JRST SCHRC1
;FUNCTION 11
;
;HERE TO READ VALUE OF PROT (MCU MULTIPLIER)
;
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN VALUE HERE
;
SCHRPF: MOVE T1,PROT## ;GET DESIRED VALUE
PJRST SCHPVL ;STORE AND RETURN
;HERE TO WRITE PROT
;
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED VALUE OF PROT>
SCHWPF: PUSHJ P,SCHGET ;GET DESIRED VALUE
MOVEM T1,PROT## ;SAVE DESIRED VALUE (IN MICROSECS)
PJRST CPOPJ1 ;AND RETURN WELL.
;FUNCTION 12
;
;HERE TO READ VALUE OF DEFAULT CLASS FOR NEW JOBS
;
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN VALUE HERE
;
SCHRCD: MOVE T1,DEFCLS## ;GET DEFAULT CLASS
ANDI T1,37 ;JUST CLASS BITS, NO OTHER GARBAGE
PJRST SCHPVL ;STORE VALUE AND RETURN
;HERE TO WRITE THE DEFAULT CLASS OF NEW JOBS
;
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED VALUE OF DEFAULT CLASS, BITS 31-35>
;
SCHWCD: PUSHJ P,SCHGET ;GET ARG
CAIL T1,M.CLSN## ;IS IT A LEGAL CLASS?
JRST SCHCLE ;NO, GIVE ILLEGAL CLASS NUMBER ERROR
MOVEM T1,DEFCLS## ;STORE
PJRST CPOPJ1## ;AND GIVE GOOD RETURN
;FUNCTION 13
;
;HERE TO READ VALUE OF PROT1 (MCU REQUEUE CONSTANT)
;
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN VALUE OF PROT1 HERE
;
SCHRRC: MOVE T1,PROT1## ;GET DESIRED VALUE
IMUL T1,[^D1000000] ;CONVERT TO MICROTICKS
IDIV T1,TICSEC## ;THEN TO MICROSECONDS
PJRST SCHPVL ;STORE AND RETURN
;HERE TO WRITE MCU REQUEUE CONSTANT
;
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED VALUE OF PROT1 IN MICROSECONDS>
SCHWRC: PUSHJ P,SCHGET ;GET DESIRED VALUE
IMUL T1,TICSEC## ;CONVERT TO MICROTICKS
IDIV T1,[^D1000000] ;THEN TO TICKS
MOVEM T1,PROT1## ;SAVE DESIRED VALUE OF PROT1
PJRST CPOPJ1 ;AND RETURN WELL.
;FUNCTION 14
;
;HERE TO READ VALUE OF PROTM (MCU MAXIMUM)
;
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN VALUE HERE
;
SCHRPM: MOVE T1,PROTM## ;GET DESIRED VALUE
PJRST SCHPVL ;STORE AND RETURN
;HERE TO WRITE PROTM
;
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED VALUE OF PROTM>
SCHWPM: PUSHJ P,SCHGET ;GET DESIRED VALUE
MOVEM T1,PROTM## ;SAVE DESIRED VALUE (IN MICROSECS)
PJRST CPOPJ1 ;AND RETURN WELL.
;FUNCTION 15
;
;HERE TO READ QUANTUM MULTIPLIERS FOR EITHER PQ1 OR PQ2
;AND TO READ SCALE FACTOR
; FORMAT OF BLOCK:
;
; BLOCK: N ;NUMBER OF QUEUES TO READ MULTIPLIERS FOR
;(MUST BE 1-3)
; BLOCK+1: ;QUANTUM MULTIPLIER FOR PQ1 RETURNED HERE
; BLOCK+2: ;QUANTUM MULTIPLIER FOR PQ2 RETURNED HERE
; ;(IF N BIG ENOUGH)
; BLOCK+3: ;SCALE FACTOR FOR QUANTUM MULTIPLIERS RETURNED HERE
; ;(IF N BIG ENOUGH)
;
SCHRML: PUSHJ P,SCHGET ;GET N
MOVEI T4,QMLTAB## ;WHERE TO FIND THE DATA
CAIGE T1,3 ;MULTIPLIERS ONLY?
PJRST SCHRTC ;YES, GO GET THEM
CAIE T1,3 ;LEGAL?
JRST SCHQNE ;NO
MOVE T1,QRANGE## ;GET SCALE FACTOR
ADDI M,3 ;ADVANCE POINTER TO PROPER LOCATION
PUSHJ P,PUTWRD## ;STORE IT
JRST SCHAER ;ADDRESS PROBLEM
SUBI M,3 ;RESTORE POINTER
MOVEI T1,2 ;SETUP FOR 2 ARGS
PJRST SCHRTD ;DO THE REST OF THE TABLE
;HERE TO WRITE QUANTUM MULTIPLIERS FOR EITHER PQ1 OR PQ2
; FORMAT OF BLOCK:
;
; BLOCK: N ;NUMBER OF WORDS FOLLOWING
; BLOCK+1: XWD Q#,MULTIPLIER(MS)
; BLOCK+2: XWD Q#,MULTIPLIER(MS)
; BLOCK+N: XWD 3,QRANGE
SCHWML: PUSHJ P,SCHGET ;GET N
JUMPLE T1,CPOPJ1 ;RETURN IF ZERO
MOVE T4,T1 ;COPY N
SCHWM1: PUSHJ P,SCHGT1 ;GET ARG
HLRZ T3,T1 ;Q NUMBER
JUMPE T3,SCHQNE ;ZERO IS NOT ALLOWED
CAILE T3,2 ;LEGAL?
JRST SCHWM3 ;PROBABLY NOT
HRRZ T1,T1 ;CLEAR LEFT HALF
IMUL T1,TICSEC## ;MILLITICS
IDIVI T1,^D1000 ;TICS
MOVEM T1,QMLTAB##-1(T3) ;STORE IT
SCHWM2: SOJG T4,SCHWM1 ;GET NEXT ARG
JRST CPOPJ1 ;GIVE GOOD RETURN
SCHWM3: CAIE T3,3 ;LEGAL?
JRST SCHQNE ;NO
HRRZM T1,QRANGE## ;YES STORE THE SCALE FACTOR
JRST SCHWM2 ;AND PROCEED
;FUNCTION 16
;
;HERE TO READ QUANTUM MAXIMA FOR EITHER PQ1 OR PQ2
; FORMAT OF BLOCK:
;
; BLOCK: N ;NUMBER OF QUEUES TO READ MAXIMA FOR
; ;(CAN BE 1 OR 2)
; BLOCK+1: ;MAXIMUM QUANTUM RUN FOR PQ1 RETURNED HERE
; BLOCK+2: ;MAXIMUM QUANTUM RUN FOR PQ2 RETURNED HERE
; ;(IF N BIG ENUF)
;
SCHRMX: PUSHJ P,SCHGET ;GET N
MOVEI T4,QMXTAB## ;QUANTUM MAX TABLE
PJRST SCHRTB ;GO READ THE TABLE
;HERE TO WRITE QUANTUM MAXIMA FOR EITHER PQ1 OR PQ2
; FORMAT OF BLOCK:
;
; BLOCK: N ;NUMBER OF WORDS FOLLOWING
; BLOCK+1: XWD Q#,MAX TIME SLICE(MS)
; BLOCK+2: XWD Q#,MAX TIME SLICE(MS)
;
; BLOCK+N: XWD Q#,MAX TIME SLICE(MS)
;
SCHWMX: PUSHJ P,SCHGET ;GET N
JUMPLE T1,CPOPJ1 ;RETURN IF ZERO
MOVE T4,T1 ;COPY N
SCHWX1: PUSHJ P,SCHGT1 ;GET ARG
MOVE T2,TICSEC## ;GET JIFSEC
IMULI T2,(T1) ;MILLITICS
IDIVI T2,^D1000 ;TICS
HLRZ T3,T1 ;Q NUMBER
SKIPE T3 ;ZERO IS NOT ALLOWED
CAILE T3,2 ;LEGAL?
JRST SCHQNE ;Q NUMBER ERROR
MOVEM T2,QMXTAB##-1(T3) ;STORE IT
SOJG T4,SCHWX1 ;GET NEXT ARG
JRST CPOPJ1 ;GIVE GOOD RETURN
;FUNCTION 17
;
;HERE TO READ SECONDARY CLASS QUOTAS
; FORMAT OF BLOCK:
;
; BLOCK: N ;NUMBER FOR CLASSES TO READ QUOTAS OF
; BLOCK+1: ;SECONDARY QUOTA OF CLASS 0 RETURNED HERE
; BLOCK+2: ;SECONDARY QUOTA OF CLASS 1 RETURNED HERE
;
; BLOCK+N: ;SECONDARY QUOTA OF CLASS N-1 RETURNED HERE
;
SCHRSQ: PUSHJ P,SCHGET ;GET NUMBER OF CLASSES TO RETURN
SKIPLE T1 ;TOO LOW OR
CAILE T1,M.CLSN## ;TOO HIGH?
JRST SCHCLE ;YES, TELL HIM SO
MOVN T4,T1 ;GET AN AOBJN POINTER
HRLZS T4
SCHRS1: MOVE T1,CLSQTA##(T4) ;GET QUOTA
JSP T2,SCHBLK ;STORE WORD
JRST SCHRS1 ;LOOP FOR MORE
;HERE TO SET SECONDARY QUOTAS FOR CLASS
;
; FORMAT OF BLOCK:
;
; BLOCK: N ;NUMBER OF WORDS FOLLOWING
; BLOCK+1: XWD CLASS,QUOTA
; BLOCK+2: XWD CLASS,QUOTA
;
; BLOCK+N: XWD CLASS,QUOTA
SCHWSQ: PUSHJ P,SCHGET ;GET NUMBER OF ARGS
JUMPLE T1,SCHWS2 ;DONE IF LE ZERO
MOVE T4,T1 ;SAVE IN T4
SCHWS1: PUSHJ P,SCHGT1 ;GET ARG
LDB T3,[POINT 5,T1,17] ;GET CLASS
CAIL T3,M.CLSN## ;TOO HIGH?
JRST SCHCLE ;YES, REPORT IT.
HRRZM T1,CLSQTA##(T3) ;SAVE SECONDARY QUOTA
SOJG T4,SCHWS1 ;AND LOOP UNTIL DONE.
SCHWS2: SETZB T1,CNTQTA## ;ZERO MAX CLASS, COUNT OF CLASSES
SETZM TOTQTA## ;ZERO TOTAL OF ALL CLASSES QTA
MOVEI T4,M.CLSN##-1 ;HIGHEST LEGAL CLASS
SCHWS3: SKIPG T2,CLSQTA##(T4) ;ANY SECONDARY QUTOTA?
JRST SCHWS4 ;NO
AOS CNTQTA## ;BUMP COUNT OF CLASSES WITH QTA
ADDM T2,TOTQTA## ;ADD TO TOTAL OF ALL CLASSES
JUMPG T1,SCHWS4 ;JUMP IF ALREADY FOUND HIGHEST NON-ZERO CLASS
MOVE T1,T4 ;ELSE SAVE HIGHEST CLASS
SCHWS4: SOJGE T4,SCHWS3 ;REPEAT FOR ALL CLASSES
MOVEM T1,MAXQTA## ;STORE CLASS NUMBER OF TOP CLASS WITH QTA
JRST CPOPJ1 ;RETURN
;FUNCTION 20
;
;HERE TO READ SCDJIL
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN PERCENTAGE HERE
;
SCHRIQ: MOVE T1,SCDJIL## ;LOAD PERCENT TO SCAN JBTJIQ
PJRST SCHPVL ;GIVE GOOD RETURN
;HERE TO WRITE SCDJIL
;
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED PERCENTAGE TO SCAN JBTJIQ>
SCHWIQ: PUSHJ P,SCHGET ;GET VALUE
JUMPLE T1,SCHFNP ;MUST BE POSITIVE TO GUARANTEE CLEARING OF CORE
CAILE T1,^D100 ;MAX OF 100%
MOVEI T1,^D100
MOVEM T1,SCDJIL## ;SAVE NEW VALUE
PJRST CPOPJ1 ;RETURN
;FUNCTION 21
;
;HERE TO READ SWAP SCAN TIME
;
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN SWAP SCAN TIME HERE
;
SCHRSS: MOVE T1,SCDSWP## ;HOW LONG TO SCAN SAME SUBQUEUE FOR SWAP IN
PJRST SCHPVL ;PUBLISH VALUE
;HERE TO WRITE SCDSWP
;
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED VALUE OF SWAP SCAN TIME>
SCHWSS: PUSHJ P,SCHGET ;GET VALUE FROM USER
MOVEM T1,SCDSWP## ;STORE IT
JRST CPOPJ1 ;GIVE GOOD RETURN
;FUNCTION 22
;
;HERE TO READ BACKGROUND BATCH SUBQUEUE NUMBER
;
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN BACKGROUND BATCH SUBQUEUE HERE
;
SCHRBB: MOVE T1,BBSUBQ## ;BACKGROUND BATCH SUBQUEUE
PJRST SCHPVL ;PUBLISH RESULTS
;HERE TO WRITE BBSUBQ
;
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED SUBQUEUE FOR BACKGROUND BATCH>
SCHWBB: PUSHJ P,SCHGET ;GET DESIRED VALUE
CAIL T1,M.CLSN## ;TOO BIG?
JRST SCHCLE ;YES
SKIPGE T1 ;NO BACKGROUND BATCH?
SETO T1, ;YES USE -1 FOR FLAG
MOVEM T1,BBSUBQ## ;STORE NEW B B QUEUE NUMBER
JRST CPOPJ1 ;RETURN
;FUNCTION 23
;
;HERE TO READ BACKGROUND BATCH SWAP TIME INTERVAL
;
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN BB SWAP TIME HERE
;
SCHRBS: MOVE T1,SCDBBS## ;BB SWAP SCAN TIME INTERVAL
PJRST SCHPVL ;TELL USER THE VALUE (IN TICKS)
;HERE TO WRITE SCDBBS
;
; FORMAT OF BLOCK:
; BLOCK: <DESIRED # OF TICKS BETWEEN BB SWAPINS>
SCHWBS: PUSHJ P,SCHGET ;GET VALUE FROM USER
MOVEM T1,SCDBBS## ;STORE FOR SWAPPER
JRST CPOPJ1 ;GOOD RETURN
;FUNCTION 24
;
;HERE TO READ SCHEDULER FAIRNESS FACTOR
;
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN SCHEDULER FAIRNESS FACTOR HERE
;
SCHRSF: MOVE T1,.C0SCN## ;SCAN TABLE
MOVE T1,MFC(T1) ;MAXIMUM FAIRNESS COUNT
PJRST SCHPVL ;PUBLISH VALUE
;HERE TO WRITE MFC
;
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED VALUE OF SCHEDULER FAIRNESS FACTOR>
SCHWSF: PUSHJ P,SCHGET ;GET VALUE FROM USER
JUMPLE T1,SCHFNP ;MUST BE POSITIVE
MOVE T2,.C0SCN## ;SCAN TABLE FOR CPU0
MOVEM T1,MFC(T2) ;STORE MAX FAIRNESS COUNT
IFN FTMS,<
MOVE T2,SSCN(T2) ;ADDRESS OF SECOND SCAN TABLE
MOVEM T1,MFC(T2) ;MAX FAIRNESS COUNT FOR CPU1
>
JRST CPOPJ1 ;GIVE GOOD RETURN
;FUNCTION 25
;
;HERE TO READ SWAPPER FAIRNESS FACTOR
;
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN SWAPPER FAIRNESS FACTOR HERE
;
SCHRSW: MOVE T1,MAXIFC ;MAXIMUM INPUT FAIRNESS COUNT
PJRST SCHPVL ;PUBLISH VALUE
;HERE TO WRITE MAXIFC
;
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED VALUE OF SWAPPER FAIRNESS FACTOR>
SCHWSW: PUSHJ P,SCHGET ;GET VALUE FROM USER
JUMPLE T1,SCHFNP ;MUST BE POSITIVE
MOVEM T1,MAXIFC ;STORE IT
JRST CPOPJ1 ;GIVE GOOD RETURN
;FUNCTION 26
;
;HERE TO READ SWAP FAIRNESS PERCENTAGE FOR IN-CORE VS OUT-CORE
;
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN INCORE FAIRNESS HERE
;
SCHRIO: MOVE T1,SCDIOF## ;PERCENT TO SCAN IN-CORE QUEUES FIRST
PJRST SCHPVL ;PUBLISH VALUE
;HERE TO WRITE SCDIOF
;
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED VALUE OF INCORE FAIRNESS>
SCHWIO: PUSHJ P,SCHGET ;GET VALUE FROM USER
JUMPLE T1,SCHFNP ;MUST BE AT LEAST ONE PERCENT
MOVEM T1,SCDIOF## ;STORE IT
JRST CPOPJ1 ;GIVE GOOD RETURN
;FUNCTION 27
;
;HERE TO READ CORE SCHEDULING TIME INTERVAL (SCDCOR)
;
; FORMAT OF BLOCK:
;
; BLOCK: ;RETURN CORE SCHEDULING TIME HERE
;
SCHRCS: MOVE T1,SCDCOR## ;CORE SCHEDULING TIME IN TICK PAIRS
ASH T1,1 ;CONVERT TO TICKS
IDIV T1,TICSEC## ;CONVERT TO SECONDS
PJRST SCHPVL ;PUBLISH VALUE
;HERE TO WRITE SCDCOR
;
; FORMAT OF BLOCK:
;
; BLOCK: <DESIRED VALUE OF CORE SCHEDULING INTERVAL IN SECONDS>
SCHWCS: PUSHJ P,SCHGET ;GET VALUE FROM USER
JUMPLE T1,SCHFNP ;MUST BE POSITIVE
IMUL T1,TICSEC## ;CHANGE TO TICKS
ASH T1,-1 ;THEN TO TICK PAIRS
MOVEM T1,SCDCOR## ;STORE IT
JRST CPOPJ1 ;GIVE GOOD RETURN
;GET A WORD FROM USER (ERROR CODE 1 IF BAD ADDRESS)
SCHGT1: HRRI M,1(M)
SCHGET: PUSHJ P,GETWRD## ;GET WORD
JRST [POP P,(P) ;ADDRESS CHECK
JRST SCHAER]
POPJ P,0 ;GOT IT
;SUBROUTINE TO STORE A WORD INTO A BLOCK
;CALL WITH:
; T1 = WORD
; M = ADDRESS
; T4 = AOBJN WORD
; JSP T2,SCHBLK
; RETURN HERE IF MORE
SCHBLK: PUSHJ P,PUTWR1##
JRST SCHAER
AOBJP T4,CPOPJ1##
JRST (T2)
;ERROR RETURNS
ERCODE SCHAER,SCHAC% ;(1) ADDRESS CHECK ERROR
ERCODE SCHFNE,SCHUF% ;(2) BAD FUNCTION NUMBER
ERCODE SCHBJN,SCHUJ% ;(3) BAD JOB NUMBER
ERCODE SCHNPE,SCHNP% ;(4) NO PRIVILEGES
ERCODE SCHCLE,SCHUC% ;(5) BAD CLASS NUMBER
ERCODE SCHQNE,SCHUQ% ;(6) BAD QUEUE NUMBER
ERCODE SCHCNE,SCHNC% ;(7) BAD CHANNEL NUMBER
ERCODE SCHBFE,SCHEB% ;(10) BAD EXPONENTIAL FACTOR VALUE
ERCODE SCHMIS,SCHMI% ;(11) ATTEMPT TO SET PROT WHILE MCUINT NON ZERO.
ERCODE SCHNHP,SCHNH% ;(13) NOT HUNDRED PERCENT IN CLSSTS
ERCODE SCHFNP,SCHFN% ;(14) FAIRNESS NOT POSITIVE
>;END IFN FTNSCHED
SUBTTL MICRO SCHEDULING INTERVAL ROUTINES
IFN FTNSCHED,<
;HERE EVERY MICRO SCHEDULING INTERVAL TO MAINTAIN
; THE SUB-QUEUE SCHEDULING TABLES
;
;SCDQTA USES AC'S T1,T2,T3,T4.
SCDQTA::SKIPLE T1,SCDINT## ;ANY INTERVAL AT ALL?
SKIPG T2,CNTSTS## ;ANY SUBCLASSES PRESENT?
POPJ P, ;NO, DON'T DO ANYTHING
MOVEM T2,RRFLAG## ;SET RRFLAG SO THAT WE CLASS SCHEDULE
MOVE T2,SCDSTS## ;TIME CLSRTM TABLE WAS CLEARED
MOVEM T2,SCDSET## ;STORE IN FLAG WHICH INDICATES CLASS SCHEDULING
MOVE T2,UPTIME##
CAMGE T2,SCDTIM## ;TIME FOR A MSI?
POPJ P, ;NO, RETURN
ADD T2,T1 ;GET NEXT UPTIME FOR INTERVAL
MOVEM T2,SCDTIM## ;SAVE
IMUL T1,SCDJIL## ;TIMES % TO SCAN JBTJIQ
ADDI T1,^D99 ;ROUND UP
IDIVI T1,^D100 ;SCALE DOWN
ADD T1,UPTIME## ;PLUS CURRENT TIME
MOVEM T1,SCNJIL## ;SAVE FOR SCHEDULING SCAN
;HERE TO COMPUTE THE SUB QUEUE SCHEDULING TABLES FOR CPU0
; (AND POSSIBLY CPU1)
SOSLE SSCNT## ;ANY ENTRIES LEFT IN PRIMARY SCAN TABLE?
JRST SCDQT1 ;YES
MOVEI T1,^D100 ;100 ENTRIES
MOVEM T1,SSCNT## ;RESTORE COUNT
MOVE T2,[POINT 5,PSQTAB##]
MOVEM T2,SSPNT## ;POINTER FOR CPU0
IFN FTMS,<
MOVE T2,[POINT 5,PSQTAB##,4]
MOVEM T2,SSPNT1## ;POINTER FOR CPU1
>
SCDQT1: PUSHJ P,SCDSS0 ;SETUP SCAN TABLE FOR CPU0
IFN FTMS,<
PUSHJ P,SCDSS1## ;SETUP SCAN TABLE FOR CPU1
>
POPJ P,
SCDSS0::ILDB T1,SSPNT## ;INCREMENT BYTE POINTER FOR CPU0
MOVEI T4,SSSCAN## ;ADDRESS OF CPU0 SUB-Q SCAN TABLE
;PJRST SCDSST ;SETUP THE TABLE
SCDSST::MOVEI J,(T4) ;0,,ADDRESS OF SCAN TABLE
SETCAM T1,(J) ;STORE THE PRIMARY SUBCLASS HEADER OFFSET
SETZM SSSUM## ;INITIALIZE SUM OF SECONDARY PERCENTS
MOVE T2,MAXQTA## ;HIGHEST CLASS WITH NON-ZERO CLSQTA
SCDQT2: SKIPLE T3,CLSQTA##(T2) ;ANY SECONDARY QUOTA FOR THIS CLASS?
CAMN T2,T1 ;IS THIS THE PRIMARY CLASS?
JRST SCDQT3 ;PRIMARY CLASS OR NO QUOTA
ADDM T3,SSSUM## ;SUM THE PERCENTS
AOBJP J,.+1 ;BUMP THE TABLE POINTER
HRL T3,T2 ;CLASS #,,QUOTA
MOVEM T3,(J) ;STASH IN TABLE
SCDQT3: SOJGE T2,SCDQT2 ;CHECK THE OTHER CLASSES
SETCA J, ;LH(J)=-(LH(J)+1)
HRRI J,-1(T4) ;ADDRESS OF TABLE - 1
AOBJP J,SCDQT7 ;JUMP IF NO POSITIVE QUOTAS FOUND
AOBJP J,SCDQT6 ;JUMP IF ONLY ONE CLASS FOUND
SCDQT4: PUSHJ P,RAND ;GET RANDOM NUMBER
IDIV T2,SSSUM## ;MOD SSSUM
MOVE T4,J ;GET A COPY OF AOBJN POINTER
SCDQT5: HRRZ T2,(T4) ;GET HIS SECONDARY QUOTA
SUB T3,T2 ;SUBTRACT FROM SCALED RANDOM NUMBER
JUMPL T3,.+2 ;IS THIS THE CLASS WE WANT?
AOBJN T4,SCDQT5 ;NO, KEEP LOOKING
MOVE T2,(J) ;STORE THE CURRENT ENTRY
EXCH T2,(T4) ;ON TOP OF THE ONE WE SELECTED
HLRZ T1,T2 ;CLASS NUMBER
SETCAM T1,(J) ;STORE AS SUB QUE OFFSET
MOVNI T2,(T2) ;SUBTRACT QUOTA
ADDM T2,SSSUM## ;FROM TOTAL
AOBJN J,SCDQT4 ;GO PICK THE NEXT TABLE ENTRY
SCDQT6: HLRZ T1,(J) ;LAST AND CERTAINLY LEAST
SETCAM T1,(J) ;STORE HIM ALSO
SCDQT7: SETZM 1(J) ;ZERO TERMINATES SCAN LIST
POPJ P,
>;END IFN FTNSCHED
$LIT
SCHEND: END