1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)networkdelta.c 2.2 (Berkeley) 12/23/87"; 15 #endif /* not lint */ 16 17 #include "globals.h" 18 #include <protocols/timed.h> 19 20 extern int machup; 21 22 /* 23 * `networkdelta' selects the largest set of deltas that fall within the 24 * interval RANGE, and uses them to compute the network average delta 25 */ 26 27 long networkdelta() 28 { 29 int i, j, maxind, minind; 30 int ext; 31 int tempind; 32 long tempdata; 33 long x[NHOSTS]; 34 long average; 35 36 for (i=0; i<slvcount; i++) 37 x[i] = hp[i].delta; 38 for (i=0; i<slvcount-1; i++) { 39 tempdata = x[i]; 40 tempind = i; 41 for (j=i+1; j<slvcount; j++) { 42 if (x[j] < tempdata) { 43 tempdata = x[j]; 44 tempind = j; 45 } 46 } 47 x[tempind] = x[i]; 48 x[i] = tempdata; 49 } 50 51 /* this piece of code is critical: DO NOT TOUCH IT! */ 52 /****/ 53 i=0; j=1; minind=0; maxind=1; 54 if (machup == 2) 55 goto compute; 56 do { 57 if (x[j]-x[i] <= RANGE) 58 j++; 59 else { 60 if (j > i+1) 61 j--; 62 if ((x[j]-x[i] <= RANGE) && (j-i >= maxind-minind)) { 63 minind=i; 64 maxind=j; 65 } 66 i++; 67 if(i = j) 68 j++; 69 } 70 } while (j < machup); 71 if ((x[machup-1] - x[i] <= RANGE) && (machup-i-1 >= maxind-minind)) { 72 minind=i; maxind=machup-1; 73 } 74 /****/ 75 compute: 76 ext = maxind - minind + 1; 77 average = 0; 78 for (i=minind; i<=maxind; i++) 79 average += x[i]; 80 average /= ext; 81 return(average); 82 } 83