;;; -*- Mode:Lisp; Readtable:CL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 125.19
;;; Reason:
;;;  The NETWORK package doesn't really want to import/export the
;;;  implementation specific variable ZUNDERFLOW -- better it
;;;  should use the macro WITHOUT-FLOATING-UNDERFLOW-TRAPS,
;;;  which is implemented in terms of ZUNDERFLOW on the Lambda,
;;;  but need not be on other machines...
;;; Written 22-Jul-88 16:18:27 by pld (Peter L. DeWolf) at site Gigamos Cambridge
;;; while running on Cthulhu from band 3
;;; with System 125.17, ZWEI 125.2, ZMail 73.0, Local-File 75.0, File-Server 24.0, Unix-Interface 13.0, Tape 24.1, Lambda-Diag 17.0, Experimental Kermit 36.5, microcode 1761, SDU Boot Tape 3.14, SDU ROM 8.



(import (intern "WITHOUT-FLOATING-UNDERFLOW-TRAPS" pkg-global-package)
	(find-package "NETWORK"))
(export (intern "WITHOUT-FLOATING-UNDERFLOW-TRAPS" (find-package "NETWORK"))
	(find-package "NETWORK"))

; From modified file DJ: L.NETWORK.KERNEL; LIBRARY.LISP#55 at 22-Jul-88 16:18:51
#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 modified file DJ: L.NETWORK.KERNEL; LIBRARY.LISP#55 at 22-Jul-88 16:18:54
#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))))))

))
