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

Load average patch for MiNT 1.09.



Here's a patch for MiNT 1.09 which gives it an uptime counter and set of
load averages accessed by a system call Suptime().

BUGS

	The uptime and load average code uses the Vertical Blank Interrupt
	to update its values and assumes that the interrupt will happen
	60 times per second. This is a false assumption on PAL STs running
	in either ST Low or ST Medium resolutions in which case the uptime
	clock will run slow.

Anyway, here's the patch, it doesn't include a patch for the makefile as my
makefile is hacked to death.

Steve

--8<-- Cut -- Here --8<--
*** ../mint.src/loadave.h	Thu Feb 10 20:38:02 1994
--- loadave.h	Thu Feb 10 20:09:46 1994
***************
*** 0 ****
--- 1,11 ----
+ #define TICKS_PER_TOCK		60
+ #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.src/dos.c	Thu Feb 10 20:06:48 1994
--- dos.c	Thu Feb 10 20:40:04 1994
***************
*** 455,460 ****
--- 455,480 ----
  }
  
  /*
+  * 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
***************
*** 588,591 ****
--- 608,612 ----
  	dos_tab[0x13a] = p_waitpid;
  	dos_tab[0x13b] = d_getcwd;
  	dos_tab[0x13c] = s_alert;
+ 	dos_tab[0x13d] = s_uptime;
  }
*** ../mint.src/proc.c	Thu Feb 10 20:07:00 1994
--- proc.c	Thu Feb 10 20:09:14 1994
***************
*** 642,647 ****
--- 642,659 ----
  #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 int tick = 0;
+ 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()
  {
***************
*** 648,653 ****
--- 660,670 ----
  #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),
***************
*** 656,659 ****
--- 673,739 ----
  	}
  	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()
+ {
+ 	if (tick < TICKS_PER_TOCK)
+ 		tick++;
+ 	else
+ 	{
+ 		PROC *p;
+ 
+ 		uptime++;
+ 		tick = 0;
+ 
+ 		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;
+ 
+ 	}
  }
--8<-- Cut -- Here --8<--

-- 
---------------------------------------------------------------------------
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).