[pe.cust.sources] uptime and load averages for Edition7

srd@peora.UUCP (Steve Davies) (04/16/85)

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
-----cut here-----cut here-----cut here-----cut here-----
#!/bin/sh
# shar:	Shell Archiver
#	Run the following text with /bin/sh to create:
#	README
#	clock.pat
#	sys4.pat
#	w.pat
# This archive created: Mon Apr 15 23:57:30 1985
cat << \SHAR_EOF > README
It is relatively easy to add system uptime and load average statistics to
Edition7 2.4.  The w(1) command already has the code in it to printout these
statistics if only the kernel collected them.  The output of the uptime(1)
command and the first line of the w(1) command will appear as follows if the
following changes are made:

 11:21pm  up 2 days, 17 mins,  4 users,  load average: 1.12, 1.20, 1.20

The uptime is the time since the system date/time was last modified using
date.

The three numbers following the load average are the number of jobs in the
run queue, averaged over the last 1, 5, and 15 minutes.

Two system source files need to be changed, and one include file.  The w(1)
command also needs to be modified.

Add the line 

	#define UCB_LOAD

somewhere in /usr/include/sys/local.h

Then run the patch program using the files in this shar archive.  If you don't
have patch, then you can use the ed(1) program.  The manual page for ed(1)
gives an example of using a diff file to generate a new, updated file.

	patch /usr/src/sys/sys/clock.c clock.pat
	patch /usr/src/sys/sys/sys4.c sys4.pat
	patch /usr/src/sys/cmd/w.c w.pat

Besides the code for calculating the load average, clock.c contains some
minor performance improvements.

Of course, you should save the original files before modifiying them.

Then compile clock.c, main.c, sys4.c and update /usr/sys/sys/LIB1.  Also remake w(1)
SHAR_EOF
cat << \SHAR_EOF > clock.pat
27a28,32
> 
> #ifdef UCB_LOAD
> double avenrun[3] = {0.0, 0.0, 0.0};
> int fltused;
> #endif
54c59
< 	int a;
---
> 	register int a;
74a80
> #ifndef M3240		/* this doesn't take care of 3205 or 3220 */
76a83
> #endif
166a174,177
> #ifdef UCB_LOAD
> 		register int timemod5;
> 		register int nrun=0;
> #endif
182a194,196
> #ifdef UCB_LOAD
> 		timemod5 = (unsigned)time % 5;
> #endif
205a220,234
> 
> #ifdef UCB_LOAD
> 			if (timemod5 == 0 && !(pp->p_flag & SSYS))
> 				switch(pp->p_stat) {
> 				case SSLEEP:
> 				case SSTOP:
> 					if (pp->p_pri > PZERO)
> 						break;
> 					/*FALLTHROUGH*/
> 				case SRUN:
> 				case SIDL:
> 					nrun++;
> 				}
> #endif
> 				
206a236,257
> #ifdef UCB_LOAD
> #define cexp0 0.9200444146293232	/* exp(-1/12) */
> #define cexp1 0.9834714538216174	/* exp(-1/60) */
> #define cexp2 0.9944598480048967	/* exp(-1/180) */
> #define mcex0 0.0799555853706768	/* 1.0 - cexp0 */
> #define mcex1 0.0165285461783826	/* 1.0 - cexp1 */
> #define mcex2 0.0055401519951033	/* 1.0 - cexp2 */
> 
> 		if (timemod5 == 0) {
> 			register int s;
> 			double fnrun;
> 			int fpsave[(8*4) + (8*8)];
> 			s = spl6();
> 			savfp(fpsave);
> 			fnrun = nrun;
> 			avenrun[0] = cexp0 * avenrun[0] + fnrun * mcex0;
> 			avenrun[1] = cexp1 * avenrun[1] + fnrun * mcex1;
> 			avenrun[2] = cexp2 * avenrun[2] + fnrun * mcex2;
> 			restfp(fpsave);
> 			splx(s);
> 		}
> #endif
237c288
< 	int s;
---
> 	register int s;
SHAR_EOF
cat << \SHAR_EOF > sys4.pat
107a108,110
> #ifdef UCB_LOAD				/* srd 4/12/85 */
> 			bootime =	/* srd 4/12/85 */
> #endif					/* srd 4/12/85 */
113a117,119
> #ifdef UCB_LOAD				/* srd 4/12/85 */
> 			bootime =	/* srd 4/12/85 */
> #endif					/* srd 4/12/85 */
SHAR_EOF
cat << \SHAR_EOF > w.pat
68a69,71
> #ifdef UCB_LOAD
> double	avenrun[3];
> #else
70a74
> #endif
232a237
> #ifndef UCB_LOAD
233a239
> #endif
235a242,244
> #ifdef UCB_LOAD
> 				printf(" %.2f", avenrun[i]);
> #else
236a246
> #endif
SHAR_EOF
#	End of shell archive
exit 0