Google
 

Trailing-Edge - PDP-10 Archives - SRI_NIC_PERM_SRC_3_19910112 - utilities/times.mid
There are no other files named times.mid in the archive.
title times

; Copyright 1981 by Ken Harrenstien, SRI International.
; This software is quasi-public; it may be used freely with like
; software, but may NOT be sold or licensed without permission.
; (This means you, DEC!)

.decsav

ifndef chaos,chaos==0
ifn chaos,	.insrt src:<sys.system>chasym

irp ac,,[f,a,b,c,d,e,h]
ac=:.irpcnt
termin
p=:17

call==:<pushj p,>
return==:<popj p,>

hlife==1
htimo==2
fl20x==1	; LH flag, on if twenex (KL)

scntim==250.	; # millisec to sleep between scans of connections
nchklp==<10.*1000./scntim>	; # times to scan

define type &str
hrroi a,[asciz str]
psout
termin

pdl:	block 100

go:	reset
	setz f,		; clear flags
	setz a,		; determine t(w)enexness
	blt a,
	caie a,
	 tlo f,fl20x	; is a KL, assume 20X.
	movei p,pdl
	time
	movem a,tmstrt

	type "
  Site	Greenwich Mean Time ->  Local Time Zone
"

	; First get JFN's to all sites...
	movsi h,-nhsts
gtm20:	hrro 2,hgtjst(h)	; Get pointer to string for JFN
	movsi 1,(gj%sht)
	gtjfn			; Get JFN for it
	 jrst [	movem 1,herr(h)
		setz 1,
		jrst .+1]
	hrrzm 1,hjfn(h)		; Store JFN
	aobjn h,gtm20

	; Use kludge here to get local time first, etc.
	type "<local>	"
	seto b,			; indicate local, to
	pushj p,prtim		; initialize prtim.
	type "
"

	; Then fire off RFC's.
	movsi h,-nhsts
gtm30:	skipn a,hjfn(h)
	 jrst gtm35
ife chaos,	move b,[403000,,of%rd]	; Byte size 32., mode 6 = immediate return
ifn chaos,	move b,[8_30.\6_26.\of%rd]
	openf			; send RFC
	 movem a,herr(h)	; if error, store it.
gtm35:	aobjn h,gtm30

	; Now loop waiting for replies.
	movsi e,-nchklp		; Initialize # of check loops
gtm50:	movsi h,-nhsts		; each check loop, scan all sites.
	trz f,hlife		; clear at-least-one-active indicator.
gtm51:	skipe a,hjfn(h)		; has jfn? (active)
	 jrst gtm55		; yes, go there.
	skipn b,herr(h)		; no, does it have unreported error?
	 jrst gtm59		; If not, this site is all done.

	; Report an error (# in B)
gtm52:	hlro a,hname(h)
	psout			; output name, followed by
	movei a,40
	pbout			; space
	jumpl b,[move a,b
		psout
		jrst gtm54]
	setz a,		; now find string for error.
	cain b,opnx20	; host dead?
	 hrroi a,[asciz /is down/]
	cain b,opnx21
	 hrroi a,[asciz /is refusing/]
	cain b,opnx10
	 hrroi a,[asciz /cannot be reached due to local lossage/]
	jumpn a,[psout ? jrst gtm54]
	hrroi a,[asciz / - /]
	psout
	movei a,.priou
	hrli b,.fhslf
	setz c,
	erstr
	 jrst [	hrroi a,[asciz /unknown error/]
		psout
		jrst gtm54]
	 halt

gtm54:	hrroi a,[asciz /.
/]
	psout
	setzm herr(h)
	jrst gtm59	; Done reporting error.


	; Check still-active connection, JFN in A
gtm55:	trne f,htimo	; time to time out?
	 jrst [	closf
		 jfcl
		hrroi b,[asciz /timed out/]
		jrst gtm52]
	gdsts		; Get status

ife chaos,[
	rot b,4
	andi b,17	; mask out connection state
	xct cstab(b)
	closf
	 jfcl
	setzm hjfn(h)
	jrst gtm52	; if didn't jump, have an error; go print out.

cstab:	hrroi b,[asciz /host is disconnected/]	; 0 DEAD
	hrroi b,[asciz /impossible error 1/]	; 1 CLZD
	hrroi b,[asciz /impossible error 2/]	; 2 PNDG
	hrroi b,[asciz /error - listening??/]	; 3 LSNG
	hrroi b,[asciz /error - unsolicited RFC?/]	; 4 RFCR
	hrroi b,[asciz /impossible error 5/]	; 5 CLW2
	jrst gtm58				; 6 RFCS - still waiting
	jrst gtm56				; 7 OPND - aha!
	hrroi b,[asciz /local system timeout/]	; 10 CLSW - sys gave up.
	hrroi b,[asciz /impossible error 11/]	; 11 DATW
	hrroi b,[asciz /impossible error 12/]	; 12 RFN1
	hrroi b,[asciz /connection closed by foreign host/]	; 13 CLZW
	hrroi b,[asciz /host closed conn while RFNM active/]	; 14 RFN2
	hrroi b,[asciz /impossible error 15/]	; 15 ?
	hrroi b,[asciz /connection refused/]	; 16 FREE

	; jump here for opened connection!
gtm56:	bin		; get the 32 bit byte into B.
	move c,b	; save
	time		; find current realtime quickly
	movem a,chkrlt	; and save for checking.
	hlro a,hname(h)
	psout
	type "	"
	move b,c	; restore net time
	pushj p,prtim	; print time...
	type "
"
	move a,hjfn(h)	; retrieve JFN
	closf		; and close connection.
	 jfcl
	setzm hjfn(h)	; and indicate inactive now.
	jrst gtm59	; and continue for more sites.
]; ife chaos
ifn chaos,[
	cain b,.csrfs
	 jrst gtm58
	caie b,.cscls
	 jrst [	hrroi b,[asciz "unknown state"]
		jrst gtm57
		]
.vector pktbuf(chpmxw)
	movei b,.mopkr
	movei c,pktbuf
	mtopr
	ldb a,[pktbuf+$cpkop]	;get opcode for giggles
	ldb b,[pktbuf+$cpknb]	;and get total byte count of data
	cain a,.coans		;an ANS?
	 caie b,4		;with 4 bytes of data?
	  jrst [ hrroi b,[asciz "bad reply"]
		 jrst gtm57
		 ]
	move a,[441000,,pktbuf+chpkdt]	;point to data portion of answer
	ildb c,a
	ildb b,a
	lsh b,8
	ior c,b
	ildb b,a
	lsh b,16.
	ior c,b
	ildb b,a
	lsh b,24.
	ior c,b

	time		; find current realtime quickly
	movem a,chkrlt	; and save for checking.
	hlro a,hname(h)
	psout
	type "	"
	move b,c
	pushj p,prtim	; print time...
	type "
"
	move a,hjfn(h)	; retrieve JFN
	closf		; and close connection.
	 jfcl
	setzm hjfn(h)	; and indicate inactive now.
	jrst gtm59	; and continue for more sites.

gtm57:	closf
	 jfcl
	setzm hjfn(h)
	jrst gtm52
]

	; Come here if must still wait for this connection.
gtm58:	tro f,hlife	; set flag.

gtm59:	aobjn h,gtm51	; and continue scanning connections

	; completed connection scan...
	trnn f,hlife	; must wait for connections?
	 jrst gtm70	; No, all done.
	movei a,scntim	; Get # millisec to sleep between scans.
	disms		; zzzz...
	aobjn e,gtm50	; back to try again.
	tro f,htimo	; time to give up, loop once more with this flag.
	jrst gtm50

	; All done, now type out final summary.
gtm70:	skipn c,difcnt
	 jrst gtm80		; If no diffs added in, just give realtime.
	type "	    Average difference  "
	movei a,.priou
	move b,difsum
	idiv b,c		; Find average diff.
	push p,b
	addm b,loctim		; add to loc time to find average time.
	pushj p,preltm		; print out avg diff in rel fmt.

	type "
	    Standard deviation  "
	movei a,.priou
	move b,difsqs
	idiv b,difcnt
	pop p,c
	imul c,c
	sub b,c
	pushj p,sqrt
	pushj p,preltm

	type "
	          Average time  "
	move b,loctim		; retrieve what is now average time.
	pushj p,cvneti		; cvt net to internal fmt.
	movei a,.priou
	setz d,			; and split using local savings time
	odcnv			; and time zone etc...
	movsi e,(ot%tmz)	; and for output add local time zone.
	odtnc
	type "
"

gtm80:	type "Realtime used = "
	time
	move b,a
	sub b,tmstrt
	idivi b,1000.
	push p,c
	movei a,.priou
	movei c,10.
	nout
	 halt
	movei a,".
	pbout
	movei a,.priou
	pop p,b
	nout
	 halt
	type " secs
"
	movei a,.fhslf
	rpcap			; Check our caps
	trne c,sc%whl+sc%opr	; Are we enabled as wheel/oper?
	 call settim		; If so, ask about setting time.
	haltf
	jrst .-1

ife chaos,[
define tsite num,name
[asciz /name/],,[asciz /NET:.!num!-45;T/]
nhsts==nhsts+1
termin
]
ifn chaos,[
define tsite num,name
[asciz "name"],,[asciz "CHA:!num!.TIME"]
nhsts==nhsts+1
termin
]

nhsts==0
hname:
hgtjst:
ife chaos,[
	tsite 106,MIT-DM
	tsite 206,MIT-AI
	tsite 306,MIT-ML
	tsite 354,MIT-MC
	tsite 013,SU-AI
	tsite 020,AMES-67
	tsite 006,MULTICS
	tsite 017,I4-TNX
	tsite 1200000137,S1-GATE
	tsite 1200200137,S1-A
]
ifn chaos,[
	tsite 1440,MIT-MC
	tsite 2026,MIT-AI
	tsite 3114,MIT-ML
	tsite 5542,MIT-EE
	tsite 2420,MIT-XX
	tsite 435,SPEECH
	tsite 3120,MIT-VAX
;	tsite 400,PLASMA
;	tsite 10404,S1-GATE
]

herr:	block nhsts
hjfn:	block nhsts

tmstrt:	0	; time at start of pgm
sqrt:	jumpe b,[popj p,]
	push p,c
	push p,d
	push p,b
	movei d,2
sqrtl:	move b,(p)
	idiv b,d
	caie b,(d)
	 cain b,1(d)
	  jrst sqrtx
	add d,b
	lsh d,-1
	jrst sqrtl
sqrtx:	pop p,d
	pop p,d
	pop p,c
	popj p,
; CVNETI and CVINET use different actions depending on whether system is
; 10X or 20X since the internal time format is different (god knows why)

tmbdif==<365.*41.+55.>	; Time base difference (1858 vs 1900)

	; Given 32-bit network time in B, converts to internal time in B.
cvneti:	push p,c
	tlnn f,fl20x
	 jrst [	idivi b,24.*3600.	; 10X is very simple, it uses
		movsi b,tmbdif(b)	; <# days>,,<# secs>
		hrri b,(c)
		pop p,c
		popj p,]
	push p,d
	idivi b,24.*60.*60.	; Get # days in B, rem secs in C
	addi b,tmbdif		; add time base difference
	mul c,[1,,]		; This is how 20X converts # secs to internal.
	divi c,24.*3600.
	cail d,<24.*3600.>/2
	 addi c,
	movsi b,(b)
	hrri b,(c)		; now have internal format date in B.
	pop p,d
	pop p,c
	popj p,

	; Convert from internal time in B to 32-bit network time in B.
cvinet:	push p,c
	tlnn f,fl20x
	 jrst [	hlrz c,b	; 10X is simple...
		subi c,tmbdif
		imuli c,24.*3600.
		addi c,(b)
		move b,c
		pop p,c
		popj p,]
	push p,d
	movei c,(b)
	hlrzs b
	subi b,tmbdif		; bring down to 1900 as base.
	muli c,24.*3600.	; This is how 20X converts from internal.
	div c,[1,,]
	cail d,400000
	 aoj c,
	cail c,24.*3600.
	 jrst [	setz c,
		aoja b,.+1]

	imuli b,24.*3600.
	addi b,(c)
	pop p,d
	pop p,c
	popj p,
.scalar loctim		; net fmt time of local machine, at startup.
.scalar begrlt		; system time when get local-time value.
.scalar chkrlt		; sys time when receive net-time value.
.scalar adjrlt		; difference chkrlt-begrlt in whole secs.
.scalar difsum		; total time differences among remote sites
.scalar difsqs		; sum of squares of differences
.scalar difcnt		; # differences added in.

	; Given 32-bit network time in B, output it on a line
	; (initialize by calling with B = -1)
prtim:	jumpge b,prtm20
	time			; get millisec of realtime
	movem a,begrlt		; save for adjustments.
	gtad			; Get current time in internal fmt.
	move b,a
	pushj p,cvinet		; convert to network time fmt.
	movem b,loctim		; save local time for compares.
	setzm chkrlt		; zap these so hack specially later.
	setzm adjrlt
	setzm difsum
	setzm difsqs
	setzm difcnt

prtm20:	movei a,.priou
	push p,e
	push p,b		; save net fmt 
	pushj p,cvneti		; Convert net to internal fmt
	push p,b		; save internal fmt

	move d,[ic%dsa+ic%utz]	; Don't use savings time, use GMT time zone
	odcnv			; split up into variousness.
	setz e,
	odtnc			; output...

	hrroi b,[asciz /  ->  /]
	setz c,
	sout

	skipn d,chkrlt		; Get realtime when net time rcvd,
	 jrst prtm40		; (with hack here to skip if local time)
	sub d,begrlt		; find millisec of realtime since loc time,
	idivi d,1000.		; and find whole sec's worth, to
	movem d,adjrlt		; find # secs to adjust.
	move b,-1(p)		; Get back time in net fmt,
	sub b,loctim		; find difference in secs,
	subi b,(d)		; and subtract secs of realtime since loctim.
	addm b,difsum		; Add to sum of diffs so far,
	push p,b
	imul b,b
	addm b,difsqs
	pop p,b
	aos difcnt		; and increment cnt of # samples.
	movm d,b		; Get magnitude, and
	caml d,[60.*60.*24.]	; if difference greater than 1 day,
	 jrst prtm40		; go print out full time.

	pushj p,preltm		; print relative time.
	pop p,b			; flush saved times off stack.
	pop p,b
	jrst prtm60		; Now go output adjustment if any.

prtm40:	pop p,b			; restore time,
	pop p,d
	setz d,			; and split again using local savings time
	odcnv			; and time zone etc...
	movsi e,(ot%tmz)	; and for output add local time zone.
	odtnc

	; output adjustment in secs if any.
prtm60:	skipn b,adjrlt
	 jrst prtm80		; if none, forget it.
	move c,[no%sgn+no%lfl+no%oov+<4,,10.>]
	nout
	 jfcl
prtm80:	pop p,e
	popj p,


	; print relative time.  Clobbers A-E.
preltm:	move e,b		; Argument in B
	hrroi b,[asciz /         /]	; 9 spaces to take up DD-MMM-YY
	setz c,
	sout
	cain e,
	 movei b,40
	caile e,
	 movei b,"+
	caige e,
	 movei b,"-
	bout				; output appropriate sign.
	movm d,e
	caige d,60.		; can we output seconds only?
	 jrst [	hrroi b,[asciz /     :/]
		setz c,
		sout
		jrst prtm35]
	caige d,60.*60.		; can we output minutes & secs only?
	 jrst [	hrroi b,[asciz /   /]
		setz c,
		sout
		jrst prtm34]
	idivi d,60.*60.		; find # hours
	movei b,(d)
	move c,[no%lfl+no%zro+<2,,10.>]
	nout
	 jfcl
	movei b,":
	bout
	movei d,(e)
prtm34:	idivi d,60.		; find # minutes
	movei b,(d)
	move c,[no%lfl+no%zro+<2,,10.>]
	nout
	 jfcl
	movei b,":
	bout
	skipa b,e
prtm35:	 movei b,(d)
	move c,[no%lfl+no%zro+<2,,10.>]
	nout
	 jfcl
	hrroi b,[asciz /    /]	; Take care of -ZON
	setz c,
	sout
	popj p,
; SETTIM - ask whether to set time, and do so if asked.

settim:	skipg difcnt		; No point if no average.
	 popj p,
	hrroi a,[asciz /Set system time to average?/]
	psout
	pbin
	trz a,40		; Flush case distinction
	caie a,"Y		; Only accept "y".
	 popj p,
	hrroi a,[asciz /
Setting time to /]
	psout

	time			; Get realtime
	sub a,begrlt		; find millisec of realtime since loc time,
	addi a,500.
	idivi a,1000.		; and find whole sec's worth, to
	add a,loctim
	move b,a
	call cvneti		; Convert to internal time
	move a,b
	stad			; set the time!
	 jrst [	hrroi a,[asciz /Error, time not set!
/]
		psout
		popj p,]
	movei a,.priou
	seto b,		; Ask for current time in order to verify...
	setz c,
	odtim
	hrroi a,[asciz /
/]
	psout
	popj p,

end go