[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

load average patches for MiNT 1.10 + patches



Here's the latest version of my uptime and load average patch for MiNT. The
patch is relative to version 1.10 with most of the patches from the last
week added.

This version now uses the 200Hz interrupt for timing so should keep the
correct time on any machine with whatever monitor. The patches affect dos.c,
intr.spp and proc.c and adds loadave.h. I'm also including below definitions
for mintbind.h.

By the way, this gives MiNT a 1 second internal timer event if anyone wants
to use it.

The load averages themselves are unsigned longs which have to be divided by
2048 to give the correct average. ie.

	load average = value / 2048

The returned uptime is in seconds since boot.

Steve

<-- mintbind.h -->

long Suptime(unsigned long *uptime, unsigned long loadaverage[3]);
/* GEMDOS 0x13f */
#define Suptime(uptime, avenrun)				\
		trap_1_wll(0x13f, (long)(uptime), (long)(avenrun))

Here come the patches...
*** ../mint.pchd/loadave.h	Tue Feb 22 20:47:58 1994
--- loadave.h	Mon Feb 21 21:50:00 1994
***************
*** 0 ****
--- 1,11 ----
+ #define TICKS_PER_TOCK		200
+ #define TOCKS_PER_SECOND	1
+ 
+ #define SAMPS_PER_MIN	12
+ #define SAMPS_PER_5MIN	SAMPS_PER_MIN * 5
+ #define SAMPS_PER_15MIN	SAMPS_PER_MIN * 15
+ 
+ #define LOAD_SCALE 2048
+ 
+ extern unsigned long uptime;
+ extern unsigned long avenrun[3];
*** ../mint.pchd/dos.c	Tue Feb 22 20:42:24 1994
--- dos.c	Mon Feb 21 21:52:52 1994
***************
*** 468,473 ****
--- 468,493 ----
  }
  
  /*
+  * Suptime: get time in seconds since boot and current load averages from
+  * kernel.
+  */
+ 
+ #include "loadave.h"
+ 
+ long ARGS_ON_STACK
+ s_uptime(cur_uptime, loadaverage)
+ 	unsigned long *cur_uptime;
+ 	unsigned long loadaverage[3];
+ {
+ 	*cur_uptime = uptime;
+ 	loadaverage[0] = avenrun[0];
+ 	loadaverage[1] = avenrun[1];
+ 	loadaverage[2] = avenrun[2];
+ 
+ 	return 0;
+ }
+ 
+ /*
   * routine for initializing DOS
   *
   * NOTE: before adding new functions, check the definition of
***************
*** 601,604 ****
--- 621,625 ----
  	dos_tab[0x13c] = s_alert;
  	dos_tab[0x13d] = t_malarm;
  	dos_tab[0x13e] = p_sigintr;
+ 	dos_tab[0x13f] = s_uptime;
  }
*** ../mint.pchd/intr.spp	Tue Feb 22 20:42:50 1994
--- intr.spp	Mon Feb 21 22:27:40 1994
***************
*** 35,43 ****
--- 35,52 ----
  	XREF	_preempt
  	XREF	_in_kernel
  
+ 	XREF	_calc_load_average
+ 	XREF	_uptimetick
+ 
  ; AKP: this code is hit once every 5ms; it updates the time fields of curproc.
  _mint_5ms:
  	move.l	a0,-(sp)
+ 	tst.l	_uptimetick
+ 	bne.s	L_no_uptime
+ 	jsr	L_uptime_update
+ L_no_uptime:
+ 	lea	_uptimetick,a0
+ 	subq.l	#1,(a0)
  	move.l	_curproc,a0
  	tst.w	_in_kernel
  	bne.s	L_systime
***************
*** 53,58 ****
--- 62,72 ----
  	move.l	_old_5ms+8,-(sp)
  	rts
  
+ L_uptime_update:
+ 	movem.l	d0-d2/a0-a2,-(sp)	; save C registers
+ 	jsr	_calc_load_average
+ 	movem.l	(sp)+,d0-d2/a0-a2
+ 	rts
  _mint_timer:
  	movem.l	d0-d2/a0-a2,-(sp)	; save C registers
  	jsr	_timeout
*** ../mint.pchd/proc.c	Tue Feb 22 20:42:28 1994
--- proc.c	Mon Feb 21 22:24:18 1994
***************
*** 655,660 ****
--- 655,672 ----
  #define qname(x) ((x >= 0 && x < NUM_QUEUES) ? qstring[x] : "unkn")
  #endif
  
+ #include "loadave.h"
+ 
+ unsigned long uptime = 0;
+ unsigned long avenrun[3] = {0,0,0};
+ unsigned long uptimetick;
+ unsigned long number_running;
+ unsigned long one_min_ptr = 0, five_min_ptr = 0, fifteen_min_ptr = 0;
+ unsigned long sum1 = 0, sum5 = 0, sum15 = 0;
+ unsigned char one_min[SAMPS_PER_MIN];
+ unsigned char five_min[SAMPS_PER_5MIN];
+ unsigned char fifteen_min[SAMPS_PER_15MIN];
+ 
  void
  DUMPPROC()
  {
***************
*** 661,666 ****
--- 673,683 ----
  #ifdef DEBUG_INFO
  	PROC *p = curproc;
  
+ 	FORCE("Uptime: %ld seconds Loads: %ld %ld %ld Processes running: %ld",
+ 		uptime,
+ 		(avenrun[0]*100)/2048 , (avenrun[1]*100)/2048, (avenrun[2]*100/2048),
+  		number_running);
+ 
  	for (curproc = proclist; curproc; curproc = curproc->gl_next) {
  	    FORCE("state %s PC: %lx BP: %lx",
  		qname(curproc->wait_q),
***************
*** 669,672 ****
--- 686,747 ----
  	}
  	curproc = p;		/* restore the real curproc */
  #endif
+ }
+ 
+ unsigned long gen_average(sum, cur_load, load_array, ptr, max_size)
+ long *sum;
+ unsigned long cur_load;
+ unsigned char load_array[];
+ unsigned long ptr;
+ int max_size;
+ {
+ 	unsigned long retval;
+ 	long old_load, new_load;
+ 
+ 	old_load = (long)load_array[ptr];
+ 
+ 	new_load = (long)cur_load;
+ 	load_array[ptr] = (char)new_load; 
+ 
+ 	*sum += ((new_load - old_load) * LOAD_SCALE);
+ 
+ 	retval = (unsigned long)(*sum / max_size);
+ 
+ 	return retval;
+ }
+ 
+ void calc_load_average()
+ {
+ 	PROC *p;
+ 
+ 	uptime++;
+ 	uptimetick = 200;
+ 
+ 	if (uptime % 5) return;
+ 
+ 	number_running = 0;
+ 	
+ 	for (p = proclist; p; p = p->gl_next)
+ 		if (p != rootproc)
+ 			if ((p->wait_q == 0) || (p->wait_q == 1))
+ 				number_running++;
+ 
+ 	avenrun[0] = gen_average(&sum1, number_running,
+ 		one_min, one_min_ptr++, SAMPS_PER_MIN);
+ 
+ 	if (one_min_ptr == SAMPS_PER_MIN)
+ 		one_min_ptr = 0;
+ 
+ 	avenrun[1] = gen_average(&sum5, number_running,
+ 		five_min, five_min_ptr++, SAMPS_PER_5MIN);
+ 
+ 	if (five_min_ptr == SAMPS_PER_5MIN)
+ 		five_min_ptr = 0;
+ 
+ 	avenrun[2] = gen_average(&sum15, number_running,
+ 		fifteen_min, fifteen_min_ptr++, SAMPS_PER_15MIN);
+ 
+ 	if (fifteen_min_ptr == SAMPS_PER_15MIN)
+ 		fifteen_min_ptr = 0;
+ 
  }

-- 
---------------------------------------------------------------------------
Computer Systems Administrator, Dept. of Earth Sciences, Oxford University.
E-Mail: steve@uk.ac.ox.earth (JANET) steve@earth.ox.ac.uk (Internet).
Tel:- Oxford (0865) 282110 (UK) or +44 865 282110 (International).