;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 129.1
;;; Reason:
;;;  Fix package lossage from system 125, whereby ZL:ZUNDERFLOW got interned
;;;  into NETWORK.  Also reload (recompiled) network functions that
;;;  referenced the bogus NET:ZUNDERFLOW.  All this so package structure is
;;;  correct when I remake cold load.
;;; Written 9-Nov-88 18:15:37 by keith at site Gigamos Cambridge
;;; while running on Breaking Glass from band 3
;;; with Experimental ZWEI 126.28, Experimental ZMail 74.14, Experimental Local-File 76.0, Experimental File-Server 25.0, Experimental Lambda-Diag 18.0, Experimental Unix-Interface 15.0, Experimental Tape 26.4, Experimental System 129.0, Microcode 1762, SDU Boot Tape 3.14, SDU ROM 103, 11/04.


; From modified buffer *Buffer-1* at 9-Nov-88 18:16:09
#10R USER#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "USER")))
  (COMPILER::PATCH-SOURCE-FILE NIL

(unintern :zunderflow :net)

))

; From file DJ: L.NETWORK.KERNEL; LIBRARY.LISP#56 at 9-Nov-88 18:17:16
#10R NETWORK#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "NETWORK")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERNEL; LIBRARY  "

(defun network-clock (n)
  (when *network-clock-enabled*
    (when (>= (incf *accumulated-60ths* n) *minimum-60ths*)
      (without-floating-underflow-traps
	(let* ((alpha *averaging-constant*)
	       (1-alpha (- 1s0 alpha))
	       (interval (short-float *accumulated-60ths*)))
	  (dolist (array *network-statistics-blocks*)
	    (dotimes (stat 4)
	      (let* ((current (aref array stat STAT-CURR))
		     (last (aref array stat STAT-LAST))
		     (instant (if (= current last)
				  0s0
				(/ (short-float (- current (aref array stat STAT-LAST)))
				   (/ interval 60s0)))))
		(setf (aref array stat STAT-INST) instant)
		(setf (aref array stat STAT-AVRG)
		      (+ (* alpha (aref array stat STAT-AVRG))
			 (* 1-alpha instant)))
		(if (> instant (aref array stat STAT-MAX))
		    (setf (aref array stat STAT-MAX) instant))
		(setf (aref array stat STAT-LAST) current)))))
	(setf *accumulated-60ths* 0)))))

))

; From file DJ: L.NETWORK.KERNEL; LIBRARY.LISP#56 at 9-Nov-88 18:17:23
#10R NETWORK#: 
(COMPILER-LET ((*PACKAGE* (GLOBAL:PKG-FIND-PACKAGE "NETWORK")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERNEL; LIBRARY  "

(defun pps->gauge (pps array stat bytes?)
  "Convert a Packets-Per-Second figure in range of 0 - RANGE into range -1 to 1
Auto-scaling -- statistics array maximum value used to determine RANGE"
  (without-floating-underflow-traps
    (let* ((max (aref array stat STAT-MAX))
	   (limit (if (zerop max)
		      1.0
		    (/ (if bytes? (/ (* 8.0 max) 1000.0) max) 2.0))))
      (min 1.0
	   (max -1.0
		(- (/ pps limit) 1.0))))))

))
