From: Roman.Hodek@informatik.uni-erlangen.de (Roman Hodek)
Date: Sun, 21 Dec 1997 18:55:11 +0100 (CET)
To: linux-m68k@lists.linux-m68k.org
Subject: L68K: Dynamic heartbeat
Sender: owner-linux-m68k@phil.uni-sb.de
Reply-To: Roman.Hodek@informatik.uni-erlangen.de


The patch below makes the heartbeat speed now depending on the current
load. The higher the load, the faster you computer's heart bumps :-)

I've choosen a hyperbolic function for the calculation of the
thump-thump-pause period, that goes through the points

  f(0) = 126 (a bit slower than before)
  f(1) = 86  (a bit faster than before)
  f(5) = 51  (really fast)
  f(x) -> 30 (x -> \infty)

The function itself is 672(5*x+7)+30, if you're interested :-)

Another fix: If there was no console= option, the co->index of the vt
console was still -1, and the condition of the ?: expression of
vt_console_device() didn't catch this as IHMO it was Miquel's
intention. The result was a "Warning: unable to open initial console",
and init's output went to /dev/null (more exactly: a non-existant tty
device c 255/255) . I changed the != 0 to > 0, so that also -1 stands
for tty0.

Roman

------------------------------------------------------------------------------
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.72.orig/arch/m68k/kernel/console.c linux-2.1.72/arch/m68k/kernel/console.c
--- linux-2.1.72.orig/arch/m68k/kernel/console.c	Tue Dec 16 16:57:39 1997
+++ linux-2.1.72/arch/m68k/kernel/console.c	Sat Dec 20 00:35:55 1997
@@ -2224,7 +2224,7 @@
 
 static kdev_t vt_console_device(struct console *c)
 {
-	return MKDEV(TTY_MAJOR, c->index ? c->index : fg_console + 1);
+	return MKDEV(TTY_MAJOR, c->index > 0 ? c->index : fg_console + 1);
 }
 
 extern int keyboard_wait_for_keypress(struct console *);
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.72.orig/arch/m68k/kernel/time.c linux-2.1.72/arch/m68k/kernel/time.c
--- linux-2.1.72.orig/arch/m68k/kernel/time.c	Thu Dec 18 15:48:58 1997
+++ linux-2.1.72/arch/m68k/kernel/time.c	Fri Dec 19 23:28:31 1997
@@ -81,15 +81,21 @@
 	   for debugging -- based on the version for PReP by Cort */
 	/* acts like an actual heart beat -- ie thump-thump-pause... */
 	if (mach_heartbeat) {
-	    switch(kstat.interrupts[mach_heartbeat_irq] % 101) {
-	      case 0:
-	      case 20:
+	    static unsigned cnt = 0, period = 0, dist = 0;
+
+	    if (cnt == 0 || cnt == dist)
 		mach_heartbeat( 1 );
-		break;
-	      case 7:
-	      case 27:
+	    else if (cnt == 7 || cnt == dist+7)
 		mach_heartbeat( 0 );
-		break;
+
+	    if (++cnt > period) {
+		cnt = 0;
+		/* The hyperbolic function below modifies the heartbeat period
+		 * length in dependency of the current (5min) load. It goes
+		 * through the points f(0)=126, f(1)=86, f(5)=51,
+		 * f(inf)->30. */
+		period = ((672<<FSHIFT)/(5*avenrun[0]+(7<<FSHIFT))) + 30;
+		dist = period / 4;
 	    }
 	}
 #endif /* CONFIG_HEARTBEAT */
diff -u --recursive --exclude-from=diff-excludes --new-file linux-2.1.72.orig/drivers/char/console.c linux-2.1.72/drivers/char/console.c
--- linux-2.1.72.orig/drivers/char/console.c	Wed Dec 10 20:20:06 1997
+++ linux-2.1.72/drivers/char/console.c	Sat Dec 20 00:35:52 1997
@@ -1888,7 +1888,7 @@
 
 static kdev_t vt_console_device(struct console *c)
 {
-	return MKDEV(TTY_MAJOR, c->index ? c->index : fg_console + 1);
+	return MKDEV(TTY_MAJOR, c->index > 0 ? c->index : fg_console + 1);
 }
 
 extern int keyboard_wait_for_keypress(struct console *);

