Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-07 - decus/20-0166/cputim.mac
There are no other files named cputim.mac in the archive.
	TITLE CPUTIM
	SEARCH MONSYM
	SEARCH MACSYM	

;SIAMAK AFSOOS JAN-21-1982
;THIS PROGRAM SORTS USERS BY THE AMOUNT OF CPU TIME THEY HAVE
;TAKEN IN A GIVEN TIME.
;LAST EDIT - SIAMAK AFSOOS
;REVISED - SIAMAK AFSOOS
	.REQUIRE SYS:MACREL
	P==17
	OPDEF CALL [PUSHJ P,]		;CALL A SUBROUTINE
	OPDEF RET [POPJ P,]		;RETURN FROM A SUBROUTINE
	SALL				;CLEAN LISTING

;PROGRAM VERSION
	VWHO==2				;WRITTEN BY A NON-DEC PERSONAL
	VMAJOR==1			;MAJOR CHANGES
	VMINOR==0			;MINOR CHANGES
	VEDIT==3			;EDIT VERSION
	BYTE (3)2(9)VMAJOR(6)VMINOR(18)VEDIT

;ENTRY VECTOR
EVEC:	JRST START			;START ENTRY POINT
	JRST START			;REENTER POINT
	BYTE (3)2(9)VMAJOR(6)VMINOR(18)VEDIT
EVECL==.-EVEC
;	[2]				;SUBSYSTEM PROGRAM NAME JUN-5-82
;	[3]				;DIREC CPU.INI INSTEAD OF SYS:CPU.INI 
start:	RESET
	move p,[iowd ^d100,stack]	;INITIALIZATION
	movsi 1,(gj%old!gj%sht)
	hrroi 2,[asciz/cpu.ini/]
	gtjfn				;GET SLEEP TIME FROM CPU.INI
	 jrst default			;NO CPU.INI, DEFAULT SLEEP TIME
	movem 1,jfn			;SAVE JFN
	move 1,jfn
	move 2,[7b5+of%rd]
	openf
	 jrst default			;ERROR,NO OPEN, DEFAULT AGAIN
	move 1,jfn
	movei 3,^d10
	nin				;GET SLEEP TIME FROM CPU.INI
         jrst default			;ERROR,USE DEFAULT SLEEP TIME
	movem 2,set			;SAVE TIME FROM CPU.INI
SL2:	call old			;JOB NUM AND CPU TIME BEF SLEEP
	call intrpt			;CREATE INF PROCE AND START IT.
	call watch			;HAS ANYBODY LOGGED OUT?
	jrst .-1			;CONTINUE TILL TIMER GOES OFF
OVER:	call new			;GET JOB AND CPU AFTER SLEEP
	call subt			;CPU TIME USED DURING SLEEP.
;
COMMENT/THIS PART ADDS UP ALL CPU USED BY USERS
	ALCPU IS THE TOTAL CPU TIME IN MICRO SECONDS/
	SETZ 4,
CPLOOP:	MOVE 1,NEWCPU(4)
	ADDM 1,ALCPU
	AOJ 4,
	CAMG 4,13
	JRST CPLOOP
;
	call sort			;SORT USERS BASED ON CPU.
	call mine			;GET SOME INFO ABOUT ME
	call time			;DAYTIME AND DATE
	call sysup			;TIME SYSTEM HAS BEEN UP
	CALL JOBS			;find number of jobs on system
	call jobOUT			;output the result
	call ldaver			;load averages 1,5,15 minutes
	call header			;just a header
	CALL OUTPUT			;ouput everything about a job
	HALTF
;
comment/ this section takes care of errors and then halts the program/
ERROR:	HRROI 1,ERBLK			;ERROR HANDLING
	MOVE 2,[.FHSLF,,-1]		;CURRENT FORK,LAST ERROR
	SETZ 3,
	ERSTR
	JFCL
	JFCL
	HRROI 1,ERBLK
	ESOUT
;
ERBLK:	BLOCK ^D30
STORE:	BLOCK ^D250
STACK:	BLOCK ^D100
OLDCPU:	BLOCK ^D100
OLDJOB:	BLOCK ^D100
NEWCPU:	BLOCK ^D100
FLNAME:	BLOCK 5
JFN:	BLOCK 1
SET:	BLOCK 1
HANDLE:	BLOCK 1
RETPC:	BLOCK 1
myjob:	block 1
alcpu:	z
;
comment/sleep for desired time.sleep time is sent eighter from cpu.ini(set)
	or it is set by default time./
SLEEP:	MOVE 2,SET
	IMULI 2,^D1000
	MOVE 1,2
	DISMS					;SLEEP,stop and start
	HALTF
;
;
comment/ channel and level tables/
CHNTAB:	REPEAT ^D19,<EXP 0>
	1,,OVER
	REPEAT ^D15,<EXP 0>			;USE CH 19 ONLY
LEVTAB:	RETPC
	0
	0
	SUBTTL SUBROUTINE TO ENABLE INTRUPT SYSTEM



;
;subroutine to enable software intrupt system on channel 19 for inferior
; process termination and then create and start on inferior process as
;timer

intrpt:	movx 1,.fhslf
	move 2,[levtab,,chntab]
	sir				;set level and channel tabale
	movx 2,1b<.icift>
	aic				;activate chan 19 for inferior
	eir				;process termination

;create and then start the inferior process

	movx 1,cr%map+cr%st+sleep
	cfork
	jrst [jshlt]			;fatal jsys error,print,halt
	movem 1,handle
	ret
;
	SUBTTL SUBROUTINE TO GET INFORMATION ON USERS



;subroutine to get all users job number and cpu since they been
;on system

old:	setz 13,
	movei 1,^d250
again2:	cain 1,1
	jrst again6
	soj 1,
	movem 1,5
	move 2,[-250,,store]
	setz 3,
	getji
	jrst[move 1,5
	jrst again2]
	move 2,store+.jirt			;get cpu
	jumpe 2,again2
	movem 2,oldcpu(13)			;save cpu
	movem 5,oldjob(13)
	aoj 13,
	move 1,5
	jrst again2
again6:	ret
;
	SUBTTL SUBROUTINE TO WATCH USERS



;subroutine to watch the connection of users to system and take them
;off the list in the case of disconnection

watch:	setz 4,
wloop:	move 1,oldjob(4)
	move 2,[-250,,store]
	setz 3,
	getji
	jrst[ setzm oldjob(4)		;is job logged out?set cpu to zero
	setzm oldcpu(4)
	jrst find]
FIND:	aoj 4,
	camg 4,13
	jrst wloop
	ret
;
	SUBTTL SUBROUTINE TO GET INFO ON USERS



;subroutine to get all users job and cpu after time goes off

new:	setz 4,
nloop:	move 1,oldjob(4)
	jumpe 1,yes
	move 2,[-250,,store]
	setz 3,
	getji
	jrst yes
	move 2,store+.jirt			;get new cpu
	movem 2,newcpu(4)
yes:	aoj 4,
	camg 4,13
	jrst nloop
	ret
;
	SUBTTL SUBROUTINE TO FIND CPU



;subroutine to find cpu time for each users during sleep time.

subt:	setz 4,
sloop:	move 1,oldjob(4)
	jumpe 1,syes
	move 2,newcpu(4)
	sub 2,oldcpu(4)
	movem 2,newcpu(4)
syes:	aoj 4,
	camg 4,13
	jrst sloop
	ret

	SUBTTL SUBROUTINE TO GET ME



;SUBROUTINE TO GET SOME INFO ABOUT CONNECTED DIRECTORY

MINE:	GJINF
	MOVEM 3,MYJOB			;save my job number
	RET

	SUBTTL SUBROUTINE TO FINE SYSUP TIME



;SUBROUTINE TO RETURN THE TIME THAT SYSTEM HAS BEEN UP IN FORM
;HR:MIN:SEC

SYSUP:	TMSG<  Up >
	TIME				;sys time up in micro seconds
	IDIVI 1,^D1000			;MICRO SEC
	MOVEM 1,TOTAL#			;SAVE IT
	IDIVI 1,^D3600			;CONVERT TO HOUR
	MOVEM 1,SAVHO#			;SAVE IT
	IMULI 1,^D3600
	MOVE 2,TOTAL
	SUB 2,1
	IDIVI 2,^D60			;CONVERT TO MINUTE
	MOVEM 2,SAVMN#
	IMULI 2,^D60
	MOVE 1,SAVHO
	IMULI 1,^D3600
	ADD 2,1
	MOVE 3,TOTAL
	SUB 3,2
	MOVEM 3,SAVSE#
	MOVE 2,SAVHO
	MOVEI 1,.PRIOU
	MOVEI 3,^D10
	NOUT				;HOUR
	ERJMP ERROR
	TMSG<:>
	MOVE 2,SAVMN
	MOVEI 1,.PRIOU
	NOUT				;MINUTE
	ERJMP ERROR
	TMSG<:>
	MOVE 2,SAVSE
	MOVEI 1,.PRIOU
	NOUT				;SECOND
	ERJMP ERROR
	RET

	SUBTTL SUBROUTINE TO FIND TIME OF DAY



;SUBROUTINE TO SHOW DAYTIME 

	TMSG<
>
TIME:	TMSG< >
	MOVEI 1,.PRIOU
	MOVNI 2,1
	MOVE 3,[1B1]
	ODTIM
	RET

	SUBTTL SUBROUTINE TO SORT



;subroutine to sort all the users in ascending order
;a simple methode is ueds so it takes a lot of time

sort:	setz 12,
AGAIN:	MOVEI 4,0
	SETZM FLAG#
	SETZ 8,
LOOP3S:	ADDI 8,1
	CAMGE 8,13			;INNER LOOP
	JRST CONTIS
	JRST CHECKS
CONTIS:	MOVE 6,NEWCPU(4)
	MOVE 15,OLDJOB(4)
	AOJ 4,
	MOVE 7,NEWCPU(4)
	MOVE 14,OLDJOB(4)
	CAML 6,7
	JRST LOOP3S
	EXCH 6,7
	EXCH 15,14
	SUBI 4,1
	MOVEM 6,NEWCPU(4)
	MOVEM 15,OLDJOB(4)
	ADDI 4,1
	MOVEM 7,NEWCPU(4)
	MOVEM 14,OLDJOB(4)
	MOVEI 16,1
	MOVEM 16,FLAG
CHECKS: MOVE 5,FLAG
	CAIE 5,0			;has any exechange made?
	JRST AGAIN			;yes go through data again
OUT2S:	RET

	SUBTTL SUBROUTINE TO FIND SYSTEM USERS



;SUBROUTINE TO RETURN NUMBER OF USERS
;AC6 HAS NUMBER OF NON-OPERATOR USERS, AND AC5 HAS NUMBER OF
;OPERATORS

JOBOUT:	TMSG<
>
	MOVE 2,6
	TMSG< >
	MOVEI 1,.PRIOU
	MOVEI 3,^D10
	NOUT				;OUTPUT NUMBER OF USERS
	ERJMP ERROR
	TMSG<+>
	MOVE 2,5
	MOVEI 1,.PRIOU
	NOUT				;OUTPUT NUMBER OF OPERATORS
	ERJMP ERROR
	TMSG< Jobs >
	RET

	SUBTTL SUBROUTINE TO FIND LOAD AVERAGE



;SUBROUTINE TO RETURN 1,5,AND 15 MINUTES AVRERAGE OF RUNNABLE 
;PROCESS

LDAVER:	tmsg< Load Av>
	movsi 1,14			;ld ave in 1 min
	hrri 1,.systa
	getab
	erjmp error
	move 2,1
	movei 1,.priou
	MOVX 3,1B1+1B4+1B6+37B17+1B22+1B28
	flout
	erjmp error
	tmsg<  >
	movsi 1,15			;ld ave in 5 minu
	hrri 1,.systa
	getab
	erjmp error
	move 2,1
	movei 1,.priou
	movx 3,1b1+1b4+1b6+37b17+4b23+2b29
	flout
	erjmp error
	tmsg<  >
	movsi 1,16			;ld ave in 15 min
	hrri 1,.systa
	getab
	erjmp error
	move 2,1
	movei 1,.priou
	movx 3,1b1+1b4+1b6+37b17+4b23+2b29
	flout
	erjmp error
	TMSG<
>
	RET
;
comment/ THIS PART SETS DEFAULT TIME IF PROGRAM FAILS TO FIND
	 CPU.INI OR EVEN FAILS TO OPEN IT TO GET SLEEP TIME. 
	 DEFAULT SLEEP TIME IS 120 SECONDS. /

DEFAULT: MOVX 1,^D120
	MOVEM 1,SET
	 JRST SL2
;

	SUBTTL SUBROUTINE TO PUT A HEADER



;SUBROUTINE TO OUT PUT A HEADER

HEADER:	TMSG<
Job	Line	Program	State	Time             %Cpu             User
>
	RET

	SUBTTL SUBROUTINE TO FIND SYSTEM USERS



;SUBROUTINE TO FIND NUMBER OF NON-OPERATOR AND OPERATORS WHO
;ARE CURRENTLY ON SYSTEM

JOBS:	SETZB 2,3
	SETZB 6,4
	SETZ 5,
	MOVEI 1,^D250
GOSY2:	CAIN 1,1
	JRST LINE2
	SOJ 1,
	MOVEM 1,HOLD2#
	MOVE 2,[-250,,STORE]
	SETZ 3,
	GETJI
	JRST[MOVE 1,HOLD2
	JRST GOSY2]
	SETZ 2,
	MOVE 2,STORE+.JIUNO		;USER NUMBER
	CAIN 2,0
	JRST GOSY2
	HRR 4,2
	CAIE 4,5			;CHECK FOR OPER DIR NUM
	JRST USECOU
	AOJ 5,				;COUNTER FOR OPERATOR
	JRST GOSY2
USECOU:	AOJ 6,				;COUNTER FOR USER(NOT OPER)
	JRST GOSY2
LINE2:	RET

	SUBTTL SUBROUTINE TO FIND INFO ABOUT A JOB



;	SUBROUTINE TO OUTPUT ALL INFO ABOUT A JOB

OUTPUT:	SETZ 4,
OUT:	MOVE 1,OLDJOB(4)
	MOVE 2,[-250,,STORE]
	SETZ 3,
	GETJI
	JRST GOSH2
	MOVE 2,OLDJOB(4)
	JUMPE 2,GOSH2
	TMSG< >
	MOVEI 1,.PRIOU
	MOVEI 3,^D10
	NOUT				;JOB NUMBER
	ERJMP ERROR
	CAMN 2,MYJOB			;IS IT ME
	TMSG<*>				;YES.PUT A "*"
	MOVEI 1,^D9
	PBOUT				;TAB OVER
	ERJMP ERROR
	MOVEI 1,.PRIOU
	MOVE 2,STORE+.JITNO		;OCTAL LINE NUMBER
	MOVS 2,2
	CAIGE 2,0			;IS LINE NOT DETTACHED
	JRST OH				;YES IT IS
	HLRZ 2,2
	MOVEI 3,^D8
	NOUT				;TAB OVER
	ERJMP ERROR
	JRST OH3
OH:	TMSG<Det>			;LINE IS DETTACHED
OH3:	MOVEI 1,^D9
	PBOUT
	SETZ 5,
	skipn 1,store+.jipnm		;[2] get program name 
	JRST[move 2,[point 6,store+.jisnm]	;if none use subsy name
	JRST LOOPS2]
	MOVE 2,[POINT 6,STORE+.JIPNM]	;ASCII PROGRAM NAME
LOOPS2:	ILDB 1,2
	JUMPE 1,CONTS2
	ADDI 1,^D32
	PBOUT				;CONVERT TO ASCIZ
	JRST LOOPS2
CONTS2:	MOVEI 1,^D9
	PBOUT
	CALL STATE			;is job running or waiting for input?
	MOVEI 1,^D9
	PBOUT
	MOVE 5,NEWCPU(4)
	MOVEM 5,8
	MOVE 1,5
	MOVEM 1,CPTOT#			;TOTAL MICROM SEC
	IDIVI 1,^D1000
	MOVEM 1,CPSEC#			;SAVE SEC
	IDIVI 1,^D60
	MOVEM 1,CPMIN#			;SAVE MIN
	IMULI 1,^D60
	MOVE 2,CPSEC
	SUB 2,1
	MOVEM 2,CPSEC2#
	MOVE 2,CPSEC
	IMULI 2,^D1000
	MOVE 1,CPTOT
	SUB 1,2
	MOVEM 1,CPMIC#
	MOVE 2,CPMIN			;MINUTES
	movei 1,.priou
	movei 3,^d10
	nout
	erjmp error
	tmsg<:>
	MOVE 2,CPSEC2
	caige 2,^d10
	tmsg<0>
	movei 1,.priou			;SECONDS
	movei 3,^d10
	nout
	erjmp error
	TMSG<:>
	MOVE 2,CPMIC
	CAIGE 2,^D10
	JRST[ TMSG<00>
	JRST TWO]
	CAIGE 2,^D100
	TMSG<0>
TWO:	MOVEI 1,.PRIOU
	MOVEI 3,^D10
	NOUT
	ERJMP ERROR
	TMSG< >
	MOVEI 1,^D9
	PBOUT
	MOVE 2,ALCPU				;GET ALL CPU
	FLTR 2,2				;CONVERT TO REAL
	MOVE 1,8
	IMULI 1,^D100
	FLTR 1,1				;CONVERT TO REAL
	FDVR 1,2
	MOVE 2,1
	MOVEI 1,.PRIOU
	MOVX 3,1B1+1B4+1B6+37B17+4B23+3B29
	FLOUT
	ERJMP ERROR
	MOVEI 1,^D9
	PBOUT
	TMSG<  >
	MOVE 2,STORE+.JIUNO			;USER 36 BIT NUMBER
	CAIE 2,0				;IS IT LOGGED IN?
	JRST PISH2
	TMSG<Not Logged In>
	JRST GOSH2
PISH2:	MOVEI 1,.PRIOU
	DIRST					;CONVERT USER NUM TO STRING
	ERJMP ERROR
GOSH2:	AOJ 4,
	CAML 4,13
	RET
	TMSG<
>
	JRST OUT
	RET

	SUBTTL SUBROUTINE TO RETURN STATE OF A JOB



;SUBROUTINE TO RETURN THE STATE OF A TERMINAL
;RUN,TERMINAL IS RUNNING
;TI,TERMINAL IS IN TERMINAL INPUT MODE

STATE:	MOVE 2,STORE+.JITNO
	MOVSI 1,(2)
	IORI 1,.TTYJO
	GETAB
	ERJMP ERROR
	ANDI 1,-1				;keep left side
	CAIN 1,-1
	JRST [TMSG<RUN>
	RET]
	TMSG<TI>
	RET
	HALTF
	END <EVECL,,EVEC>