Skip to contentSkip to conversation

increasing and masquerading HZ

RFC In review Artur Skawina 2 participants 3 messages Jul 20, 1999 Proc filesystem

lore
Share & tools
lore
#0 lore raw

RFC 1/1 increasing and masquerading HZ

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? :)

arch/i386/Makefile renamed from img/linux-2.3.5/arch/i386/Makefile +0 -0
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/arch/i386/Makefile linux-2.3.5as/arch/i386/Makefile

endif

ifdef CONFIG_M686
-CFLAGS := $(CFLAGS) -DCPU=686
+CFLAGS := $(CFLAGS) -DCPU=686 -DHZ=800
AFLAGS := $(AFLAGS) -DCPU=686
endif

arch/i386/kernel/irq.c renamed from img/linux-2.3.5/arch/i386/kernel/irq.c +1 -1
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
@@ -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 */
fs/proc/array.c renamed from img/linux-2.3.5/fs/proc/array.c +22 -22

80 lines not on this page · raw message

include/asm-i386/param.h renamed from img/linux-2.3.5/include/asm-i386/param.h +10 -0
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
@@ -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
include/linux/param.h renamed from img/linux-2.3.5/include/linux/param.h +6 -0
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/include/linux/param.h linux-2.3.5as/include/linux/param.h
@@ -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
kernel/acct.c renamed from img/linux-2.3.5/kernel/acct.c +3 -3
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/kernel/acct.c linux-2.3.5as/kernel/acct.c
@@ -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;
kernel/signal.c renamed from img/linux-2.3.5/kernel/signal.c +2 -2
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/kernel/signal.c linux-2.3.5as/kernel/signal.c
@@ -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) {
kernel/sys.c renamed from img/linux-2.3.5/kernel/sys.c +7 -1
diff -urNp --exclude-from /usr/src/lkdontdiff /img/linux-2.3.5/kernel/sys.c linux-2.3.5as/kernel/sys.c
@@ -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);
 }
 
 /*
#1 lore raw
Quoted 20 lines · Artur Skawina

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.

Quoted 6 lines

[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:

Quoted 11 lines
include/asm-i386/param.h renamed from img/linux-2.3.5/include/asm-i386/param.h +3 -0
@@ -1,8 +1,18 @@
 #ifndef _ASMi386_PARAM_H
 #define _ASMi386_PARAM_H
 
+#include <linux/config.h>
+
 #ifndef HZ
 #define HZ 100
+#endif

include/asm-i386/param.h line 18

Quoted 10 lines
include/asm-i386/param.h renamed from img/linux-2.3.5/include/asm-i386/param.h +7 -0
+
+#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 <[email protected]>
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,

Signature · 2 lines
Kurt Garloff  <[email protected]>           SuSE GmbH, Nürnberg, FRG
Linux kernel development;      SCSI drivers: tmscsim(DC390), DC395
#2 lore raw
Quoted 3 lines · Kurt Garloff

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.

Quoted 7 lines

You may want to merge your patch with one from
Harald Koerfgen <[email protected]>
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".

Quoted 1 line

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 [email protected]
Please read the FAQ at http://www.tux.org/lkml/