[RFC] increasing and masquerading HZ

Message ID 3793EDBB.6B7D7E12@geocities.com
State New, archived
Headers show
Series
  • [RFC] increasing and masquerading HZ
Related show

Commit Message

Artur Skawina July 20, 1999, 3:32 a.m. UTC
The attached patch increases HZ to 800 for kernels compiled for 686
It tries to hide the HZ change from userspace. The places I found were:

o /proc/stat
o /proc/<pid>/stat
o /proc/<pid>/cpu
o BSD Process Accounting
o siginfo
o sys_times

Not handled:
o the ip routing sysctls [defined in jiffies...:( ]

also note there are drivers that assume HZ==100 (initio scsi for one).


The numbers I've got so far doesn't look very good however,
a 3% drop in performance (HZ=1024) is a bit much.


[I did this patch from scratch so that the chance of spotting all
 places requiring updates would be greater. turned up to be a good
 thing - it handles a few more cases than the previously mentioned
 patch by Kurt Garloff]

What did I miss? :)
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/arch/i386/Makefile linux-2.3.5as/arch/i386/Makefile
--- /img/linux-2.3.5/arch/i386/Makefile	Thu May 20 01:59:04 1999
+++ linux-2.3.5as/arch/i386/Makefile	Tue Jul 20 02:13:13 1999
 endif
 
 ifdef CONFIG_M686
-CFLAGS := $(CFLAGS) -DCPU=686
+CFLAGS := $(CFLAGS) -DCPU=686 -DHZ=800
 AFLAGS := $(AFLAGS) -DCPU=686
 endif

Comments

Kurt Garloff July 20, 1999, 8:55 a.m. UTC | #1
On Tue, Jul 20, 1999 at 05:32:11AM +0200, Artur Skawina wrote:
> The attached patch increases HZ to 800 for kernels compiled for 686
> It tries to hide the HZ change from userspace. The places I found were:
> 
> o /proc/stat
> o /proc/<pid>/stat
> o /proc/<pid>/cpu
> o BSD Process Accounting
> o siginfo
> o sys_times
> 
> Not handled:
> o the ip routing sysctls [defined in jiffies...:( ]
> 
> also note there are drivers that assume HZ==100 (initio scsi for one).
> 
> 
> The numbers I've got so far doesn't look very good however,
> a 3% drop in performance (HZ=1024) is a bit much.
> 
> 
> [I did this patch from scratch so that the chance of spotting all
>  places requiring updates would be greater. turned up to be a good
>  thing - it handles a few more cases than the previously mentioned
>  patch by Kurt Garloff]
> 
> What did I miss? :)

Hi Artur,

nice work!
Yes, you spotted a few places which I missed.

Without looking into details, I saw a place, where I did HZ conversion where
you did not, but I may be completely wrong with it:
@@ -233,26 +237,26 @@
        extern unsigned long total_forks;
  	unsigned long ticks;
  
-       ticks = jiffies * smp_num_cpus;
+       ticks = jiffies * smp_num_cpus / HZ_TO_STD;
  	for (i = 0 ; i < NR_IRQS ; i++)
  		sum += kstat_irqs(i);
		
More comments on your patch:

> --- /img/linux-2.3.5/include/asm-i386/param.h	Tue Aug  1 15:08:17 1995
> +++ linux-2.3.5as/include/asm-i386/param.h	Tue Jul 20 02:14:21 1999
> @@ -1,8 +1,18 @@
>  #ifndef _ASMi386_PARAM_H
>  #define _ASMi386_PARAM_H
>  
> +#include <linux/config.h>
> +
>  #ifndef HZ
>  #define HZ 100
> +#endif
> +
> +#if HZ!=100
> +/*#define HZTOUSER(hz) (((hz)*100)/HZ) would be better, but could overflow*/
> +#define HZTOUSER(hz)    ((hz)/(HZ/100))
> +/*#define HZFROMUSER(hz)  ((hz)*(HZ/100)) hmm, these will be small values, right?*/
> +#define HZFROMUSER(hz)  (((hz)*HZ)/100)
> +#define HZ_MASQUERADING (HZ/100)    /* defined if masquerading, HZ/HZ_MASQUERADING==100 */
>  #endif
>  
>  #define EXEC_PAGESIZE	4096

This seems to be the right thing to do, IMO. You should put a comment about
the fact, that only multiples of 100 are allowed, 1024 eg. is not.
(You would get very inaccurate results.)

You may want to merge your patch with one from 
 Harald Koerfgen <Harald.Koerfgen@home.ivm.de>
on
 ftp://ftp.linux.sgi.com/pub/linux/mips/test/hz_patch.gz

He mailed me about necessary changes for his MIPS work. I did not yet find
time to answer him, but maybe you can contact him and get the changes merged.

Basically, independance of userspace from the internal HZ is good. This is
also Linus' opinion, IIRC, and you have got good chances that your patch will
go into the kernel (without the Makefile change, of course) if you submit it
to him. But look at it again in order to not miss anything ...

Regards,
Artur Skawina July 20, 1999, 11:21 a.m. UTC | #2
Kurt Garloff wrote:
> 

> Without looking into details, I saw a place, where I did HZ conversion where

i did that conversion after doing the math, to avoid doing it twice, iirc.


> You may want to merge your patch with one from
>  Harald Koerfgen <Harald.Koerfgen@home.ivm.de>
> on
>  ftp://ftp.linux.sgi.com/pub/linux/mips/test/hz_patch.gz
> 
> He mailed me about necessary changes for his MIPS work. I did not yet find
> time to answer him, but maybe you can contact him and get the changes merged.

except the mips-only change, the only thing missing is one #include "param.h".
 

> Basically, independance of userspace from the internal HZ is good. This is

yes, it's a requirement. There are still a few issues left:

o stability - the machine i tried this on locked up hard while running
  a kernel with this patch. It's otherwise rock solid... Hmm, was there
  a known (scheduling) bug in 2.3.5 that could get triggered by a big HZ?
  Will try to reproduce...
o the ip routing sysctls (i'd rather not touch these)
o /proc/net/tcp and friends (look at the "netstat -to" output...),
   this one will be easy to fix.

artur


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

Patch

diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/arch/i386/kernel/irq.c linux-2.3.5as/arch/i386/kernel/irq.c
--- /img/linux-2.3.5/arch/i386/kernel/irq.c	Wed May 12 19:30:30 1999
+++ linux-2.3.5as/arch/i386/kernel/irq.c	Tue Jul 20 01:39:25 1999
@@ -1104,7 +1108,7 @@  __initfunc(void init_IRQ(void))
 	request_region(0xa0,0x20,"pic2");
 
 	/*
-	 * Set the clock to 100 Hz, we already have a valid
+	 * Set the clock to HZ Hz, we already have a valid
 	 * vector now:
 	 */
 	outb_p(0x34,0x43);		/* binary, mode 2, LSB/MSB, ch 0 */
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/fs/proc/array.c linux-2.3.5as/fs/proc/array.c
--- /img/linux-2.3.5/fs/proc/array.c	Sat May 15 13:08:42 1999
+++ linux-2.3.5as/fs/proc/array.c	Tue Jul 20 00:58:23 1999
@@ -240,19 +241,19 @@  static int get_kstat(char * buffer)
 #ifdef __SMP__
 	len = sprintf(buffer,
 		"cpu  %u %u %u %lu\n",
-		kstat.cpu_user,
-		kstat.cpu_nice,
-		kstat.cpu_system,
-		jiffies*smp_num_cpus - (kstat.cpu_user + kstat.cpu_nice + kstat.cpu_system));
+		HZTOUSER(kstat.cpu_user),
+		HZTOUSER(kstat.cpu_nice),
+		HZTOUSER(kstat.cpu_system),
+		HZTOUSER(jiffies*smp_num_cpus - (kstat.cpu_user + kstat.cpu_nice + kstat.cpu_system)));
 	for (i = 0 ; i < smp_num_cpus; i++)
 		len += sprintf(buffer + len, "cpu%d %u %u %u %lu\n",
 			i,
-			kstat.per_cpu_user[cpu_logical_map(i)],
-			kstat.per_cpu_nice[cpu_logical_map(i)],
-			kstat.per_cpu_system[cpu_logical_map(i)],
-			jiffies - (  kstat.per_cpu_user[cpu_logical_map(i)] \
+			HZTOUSER(kstat.per_cpu_user[cpu_logical_map(i)]),
+			HZTOUSER(kstat.per_cpu_nice[cpu_logical_map(i)]),
+			HZTOUSER(kstat.per_cpu_system[cpu_logical_map(i)]),
+			HZTOUSER(jiffies - (  kstat.per_cpu_user[cpu_logical_map(i)] \
 			           + kstat.per_cpu_nice[cpu_logical_map(i)] \
-			           + kstat.per_cpu_system[cpu_logical_map(i)]));
+			           + kstat.per_cpu_system[cpu_logical_map(i)])));
 	len += sprintf(buffer + len,
 		"disk %u %u %u %u\n"
 		"disk_rio %u %u %u %u\n"
@@ -273,10 +274,10 @@  static int get_kstat(char * buffer)
 		"page %u %u\n"
 		"swap %u %u\n"
 		"intr %u",
-		kstat.cpu_user,
-		kstat.cpu_nice,
-		kstat.cpu_system,
-		ticks - (kstat.cpu_user + kstat.cpu_nice + kstat.cpu_system),
+		HZTOUSER(kstat.cpu_user),
+		HZTOUSER(kstat.cpu_nice),
+		HZTOUSER(kstat.cpu_system),
+		HZTOUSER(ticks - (kstat.cpu_user + kstat.cpu_nice + kstat.cpu_system)),
 #endif
 		kstat.dk_drive[0], kstat.dk_drive[1],
 		kstat.dk_drive[2], kstat.dk_drive[3],
@@ -910,15 +911,15 @@  static int get_stat(int pid, char * buff
 		tsk->cmin_flt,
 		tsk->maj_flt,
 		tsk->cmaj_flt,
-		tsk->times.tms_utime,
-		tsk->times.tms_stime,
-		tsk->times.tms_cutime,
-		tsk->times.tms_cstime,
+		HZTOUSER(tsk->times.tms_utime),
+		HZTOUSER(tsk->times.tms_stime),
+		HZTOUSER(tsk->times.tms_cutime),
+		HZTOUSER(tsk->times.tms_cstime),
 		priority,
 		nice,
 		0UL /* removed */,
 		tsk->it_real_value,
-		tsk->start_time,
+		HZTOUSER(tsk->start_time),
 		vsize,
 		tsk->mm ? tsk->mm->rss : 0, /* you might want to shift this left 3 */
 		tsk->rlim ? tsk->rlim[RLIMIT_RSS].rlim_cur : 0,
@@ -1229,14 +1230,14 @@  static int get_pidcpu(int pid, char * bu
 
 	len = sprintf(buffer,
 		"cpu  %lu %lu\n",
-		tsk->times.tms_utime,
-		tsk->times.tms_stime);
+		HZTOUSER(tsk->times.tms_utime),
+		HZTOUSER(tsk->times.tms_stime));
 		
 	for (i = 0 ; i < smp_num_cpus; i++)
 		len += sprintf(buffer + len, "cpu%d %lu %lu\n",
 			i,
-			tsk->per_cpu_utime[cpu_logical_map(i)],
-			tsk->per_cpu_stime[cpu_logical_map(i)]);
+			HZTOUSER(tsk->per_cpu_utime[cpu_logical_map(i)]),
+			HZTOUSER(tsk->per_cpu_stime[cpu_logical_map(i)]));
 
 	return len;
 }
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/include/asm-i386/param.h linux-2.3.5as/include/asm-i386/param.h
--- /img/linux-2.3.5/include/asm-i386/param.h	Tue Aug  1 15:08:17 1995
+++ linux-2.3.5as/include/asm-i386/param.h	Tue Jul 20 02:14:21 1999
@@ -1,8 +1,18 @@ 
 #ifndef _ASMi386_PARAM_H
 #define _ASMi386_PARAM_H
 
+#include <linux/config.h>
+
 #ifndef HZ
 #define HZ 100
+#endif
+
+#if HZ!=100
+/*#define HZTOUSER(hz) (((hz)*100)/HZ) would be better, but could overflow*/
+#define HZTOUSER(hz)    ((hz)/(HZ/100))
+/*#define HZFROMUSER(hz)  ((hz)*(HZ/100)) hmm, these will be small values, right?*/
+#define HZFROMUSER(hz)  (((hz)*HZ)/100)
+#define HZ_MASQUERADING (HZ/100)    /* defined if masquerading, HZ/HZ_MASQUERADING==100 */
 #endif
 
 #define EXEC_PAGESIZE	4096
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/include/linux/param.h linux-2.3.5as/include/linux/param.h
--- /img/linux-2.3.5/include/linux/param.h	Tue Aug 15 13:25:06 1995
+++ linux-2.3.5as/include/linux/param.h	Tue Jul 20 02:14:42 1999
@@ -3,4 +3,10 @@ 
 
 #include <asm/param.h>
 
+/* if userspace sees the same HZ as the kernel then these are noops */
+#ifndef HZ_MASQUERADING
+#define HZTOUSER(hz)    (hz)
+#define HZFROMUSER(hz)  (hz)
+#endif
+
 #endif
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/kernel/acct.c linux-2.3.5as/kernel/acct.c
--- /img/linux-2.3.5/kernel/acct.c	Sat May  1 16:36:01 1999
+++ linux-2.3.5as/kernel/acct.c	Tue Jul 20 00:59:49 1999
@@ -292,9 +292,9 @@  static int do_acct_process(long exitcode
 	ac.ac_comm[ACCT_COMM - 1] = '\0';
 
 	ac.ac_btime = CT_TO_SECS(current->start_time) + (xtime.tv_sec - (jiffies / HZ));
-	ac.ac_etime = encode_comp_t(jiffies - current->start_time);
-	ac.ac_utime = encode_comp_t(current->times.tms_utime);
-	ac.ac_stime = encode_comp_t(current->times.tms_stime);
+	ac.ac_etime = encode_comp_t(HZTOUSER(jiffies - current->start_time));
+	ac.ac_utime = encode_comp_t(HZTOUSER(current->times.tms_utime));
+	ac.ac_stime = encode_comp_t(HZTOUSER(current->times.tms_stime));
 	ac.ac_uid = current->uid;
 	ac.ac_gid = current->gid;
 	ac.ac_tty = (current->tty) ? kdev_t_to_nr(current->tty->device) : 0;
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/kernel/signal.c linux-2.3.5as/kernel/signal.c
--- /img/linux-2.3.5/kernel/signal.c	Tue Jun  1 10:21:01 1999
+++ linux-2.3.5as/kernel/signal.c	Tue Jul 20 00:36:17 1999
@@ -583,8 +583,8 @@  notify_parent(struct task_struct *tsk, i
 	info.si_pid = tsk->pid;
 
 	/* FIXME: find out whether or not this is supposed to be c*time. */
-	info.si_utime = tsk->times.tms_utime;
-	info.si_stime = tsk->times.tms_stime;
+	info.si_utime = HZTOUSER(tsk->times.tms_utime);
+	info.si_stime = HZTOUSER(tsk->times.tms_stime);
 
 	why = SI_KERNEL;	/* shouldn't happen */
 	switch (tsk->state) {
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/kernel/sys.c linux-2.3.5as/kernel/sys.c
--- /img/linux-2.3.5/kernel/sys.c	Sat May 15 13:08:47 1999
+++ linux-2.3.5as/kernel/sys.c	Tue Jul 20 00:41:43 1999
@@ -614,7 +616,13 @@  asmlinkage long sys_times(struct tms * t
 	if (tbuf)
 		if (copy_to_user(tbuf, &current->times, sizeof(struct tms)))
 			return -EFAULT;
-	return jiffies;
+#if HZ_MASQUERADING
+	tbuf->tms_utime  /= HZ_MASQUERADING;
+	tbuf->tms_stime  /= HZ_MASQUERADING;
+	tbuf->tms_cutime /= HZ_MASQUERADING;
+	tbuf->tms_cstime /= HZ_MASQUERADING;
+#endif
+	return HZTOUSER(jiffies);
 }
 
 /*