Skip to contentSkip to conversation

2.4.23 can run with HZ==0!

PATCH Frank van Maarseveen 3 participants 8 messages Dec 28, 2003 – Dec 29, 2003 Proc filesystem

lore
Share & tools
lore
#0 lore raw

The first thing I noticed was that a select for .2 seconds seemed to hang in a python script I was working on that time. I didn't believe it so I tried some other things including "sleep 1", "usleep 1", stracing them and it all came down to one conclusion

the clock has stopped

/proc/interrupts confirmed that the clock has stopped:

$ cat /proc/interrupts 
           CPU0       
  0:    7745428          XT-PIC  timer
  1:          2          XT-PIC  keyboard
  2:          0          XT-PIC  cascade
  8:          1          XT-PIC  rtc
  9:          0          XT-PIC  via82cxxx, usb-uhci
 11:      12106          XT-PIC  usb-uhci, usb-uhci, eth0
 12:      12079          XT-PIC  eth1
 14:       8582          XT-PIC  ide0
 15:       8623          XT-PIC  ide1
NMI:          0 
LOC:          0 
ERR:          0
MIS:          0
$ cat /proc/interrupts 
           CPU0       
  0:    7745428          XT-PIC  timer
  1:          2          XT-PIC  keyboard
  2:          0          XT-PIC  cascade
  8:          1          XT-PIC  rtc
  9:          0          XT-PIC  via82cxxx, usb-uhci
 11:      12116          XT-PIC  usb-uhci, usb-uhci, eth0
 12:      12079          XT-PIC  eth1
 14:       8582          XT-PIC  ide0
 15:       8623          XT-PIC  ide1

notice that network irqs are taking place for eth0 but no timer irqs.

halt, reboot (-f) etc didn't work because they all wanted to sleep. I had to power cycle. Now HZ is ok (1000) again. HZ has been patched but that's an unlikely cause (patch attached in case you wonder).

Hardware: VIA CL6000

At the time this happened I was also playing with /dev/ttyS3 lines on the mobo (static discharge?)

Signature · 1 line
Frank
include/asm-i386/param.h renamed from include/asm-i386/param.h.hz +2 -1
@@ -2,8 +2,9 @@
 #define _ASMi386_PARAM_H
 
 #ifndef HZ
-#define HZ 100
+#define HZ 1000
 #endif
+#define jiffies_to_clock_t(x) ((x) / (HZ / 100))
 
 #define EXEC_PAGESIZE	4096
 
kernel/sys.c renamed from kernel/sys.c.hz +9 -3
@@ -807,10 +807,16 @@
 	 *	atomically safe type this is just fine. Conceptually its
 	 *	as if the syscall took an instant longer to occur.
 	 */
-	if (tbuf)
-		if (copy_to_user(tbuf, &current->times, sizeof(struct tms)))
+	if (tbuf) {
+		struct tms tmp;
+		tmp.tms_utime = jiffies_to_clock_t(current->times.tms_utime);
+		tmp.tms_stime = jiffies_to_clock_t(current->times.tms_stime);
+		tmp.tms_cutime = jiffies_to_clock_t(current->times.tms_cutime);
+		tmp.tms_cstime = jiffies_to_clock_t(current->times.tms_cstime);
+		if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
 			return -EFAULT;
-	return jiffies;
+	}
+	return jiffies_to_clock_t(jiffies);
 }
 
 /*
kernel/timer.c renamed from kernel/timer.c.hz +9 -0
@@ -472,6 +472,15 @@
     else
 	time_adj += (time_adj >> 2) + (time_adj >> 5);
 #endif
+#if HZ == 1000
+    /* Compensate for (HZ==1000) != (1 << SHIFT_HZ).
+     * Add 1.5625% and 0.78125% to get 1023.4375; => only 0.05% error (p. 14)
+     */
+    if (time_adj < 0)
+	time_adj -= (-time_adj >> 6) + (-time_adj >> 7);
+    else
+	time_adj += (time_adj >> 6) + (time_adj >> 7);
+#endif
 }
 
 /* in the NTP reference this is called "hardclock()" */
fs/proc/array.c renamed from fs/proc/array.c.hz +5 -5
@@ -362,15 +362,15 @@
 		task->cmin_flt,
 		task->maj_flt,
 		task->cmaj_flt,
-		task->times.tms_utime,
-		task->times.tms_stime,
-		task->times.tms_cutime,
-		task->times.tms_cstime,
+		jiffies_to_clock_t(task->times.tms_utime),
+		jiffies_to_clock_t(task->times.tms_stime),
+		jiffies_to_clock_t(task->times.tms_cutime),
+		jiffies_to_clock_t(task->times.tms_cstime),
 		priority,
 		nice,
 		0UL /* removed */,
 		task->it_real_value,
-		task->start_time,
+		jiffies_to_clock_t(task->start_time),
 		vsize,
 		mm ? mm->rss : 0, /* you might want to shift this left 3 */
 		task->rlim[RLIMIT_RSS].rlim_cur,
fs/proc/proc_misc.c renamed from fs/proc/proc_misc.c.hz +10 -7
@@ -325,18 +325,21 @@
 	}
 
 	proc_sprintf(page, &off, &len,
-		      "cpu  %u %u %u %lu\n", user, nice, system,
-		      jif * smp_num_cpus - (user + nice + system));
+		      "cpu  %u %u %u %lu\n",
+			jiffies_to_clock_t(user),
+			jiffies_to_clock_t(nice),
+			jiffies_to_clock_t(system),
+			jiffies_to_clock_t(jif * smp_num_cpus - (user + nice + system)));
 	for (i = 0 ; i < smp_num_cpus; i++)
 		proc_sprintf(page, &off, &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)],
-			jif - (  kstat.per_cpu_user[cpu_logical_map(i)] \
+			jiffies_to_clock_t(kstat.per_cpu_user[cpu_logical_map(i)]),
+			jiffies_to_clock_t(kstat.per_cpu_nice[cpu_logical_map(i)]),
+			jiffies_to_clock_t(kstat.per_cpu_system[cpu_logical_map(i)]),
+			jiffies_to_clock_t(jif - (  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)])));
 	proc_sprintf(page, &off, &len,
 		"page %u %u\n"
 		"swap %u %u\n"
#1 lore raw
Quoted 3 lines · Frank van Maarseveen

halt, reboot (-f) etc didn't work because they all wanted to sleep. I had to power cycle. Now HZ is ok (1000) again. HZ has been patched but that's an unlikely cause

not all motherboards can deal with HZ=1000.... seems yours is one of thise.

Quoted 3 lines

(patch attached in case you wonder).

your patch is *highly* inadequate to get HZ=1000 working well in 2.4.... it needs to be about 10x bigger with fixing more userspace api's...

#2 lore raw
Quoted 3 lines · Arjan van de Ven

not all motherboards can deal with HZ=1000.... seems yours is one of thise.

But it seems to work. I would expect it to fail quite soon right at or after boot, not after a day once every few weeks (assuming it was the cause).

Quoted 2 lines

your patch is *highly* inadequate to get HZ=1000 working well in 2.4.... it needs to be about 10x bigger with fixing more userspace api's...

Can you give me an example?

HZ for x386 is 100 by definition and there aren't that many system calls and /proc files which expose jiffies to userspace.

The uptime will be rather limited with 32 bits jiffies ;-) but I can live with that.

Signature · 1 line
Frank
#3 lore raw
Quoted 8 lines · Frank van Maarseveen
Quoted 3 lines · Arjan van de Ven

not all motherboards can deal with HZ=1000.... seems yours is one of thise.

But it seems to work. I would expect it to fail quite soon right at or after boot, not after a day once every few weeks (assuming it was the cause).

Quoted 7 lines
Quoted 2 lines

your patch is *highly* inadequate to get HZ=1000 working well in 2.4.... it needs to be about 10x bigger with fixing more userspace api's...

Can you give me an example?

HZ for x386 is 100 by definition and there aren't that many system calls and /proc files which expose jiffies to userspace.

there are quite a few you missed; scsi ioctls is one, firewall rules are another.... there's a long list (2.6 has most if not all of them fixed)

#4 lore raw
In reply to Frank van Maarseveen
Quoted 1 line · Frank van Maarseveen

Can you give me an example?

Sure, as this has already been done:

	http://www.kernel.org/pub/linux/kernel/people/rml/variable-HZ/v2.4/

As you see, that has a ton of fixups, primarily to ensure that user-space is always exported jiffies in terms of USER_HZ==100.

Quoted 1 line

The uptime will be rather limited with 32 bits jiffies ;-) but I can live with that.

There is a patch at that same place that adds 64-bit jiffies.

Rob Love

#5 lore raw
Quoted 7 lines · Rob Love
Quoted 1 line · Frank van Maarseveen

Can you give me an example?

Sure, as this has already been done:

	http://www.kernel.org/pub/linux/kernel/people/rml/variable-HZ/v2.4/

That looks more complete and its cleaner. When I needed the HZ patch I deliberately didn't care about #ifdef __KERNEL__ in the header files. It was a tmp hack anyway.

it doesn't contain the #if HZ==1000 fix in timer.c. I'm not sure if it is that important and this one is broke since it fixes yet another HZ value instead of all.

Quoted 3 lines

As you see, that has a ton of fixups, primarily to ensure that user-space is always exported jiffies in terms of USER_HZ==100.

I missed a two or three cases. Hoever, no sign of the tenfold size increase or any fixes inside SCSI ioctls or firewall rules (netfilter code I presume).

Arjan, are you sure?

Signature · 1 line
Frank
#6 lore raw
Quoted 2 lines · Frank van Maarseveen

I missed a two or three cases. Hoever, no sign of the tenfold size increase or any fixes inside SCSI ioctls or firewall rules (netfilter code I presume).

Robert's patchkit is quite incomplete too.

Quoted 1 line

Arjan, are you sure?

Yes.

#7 lore raw
In reply to Frank van Maarseveen
Quoted 4 lines · Frank van Maarseveen

I missed a two or three cases. Hoever, no sign of the tenfold size increase or any fixes inside SCSI ioctls or firewall rules (netfilter code I presume).

Arjan, are you sure?

I am probably missing places, too. There are quite a bit.

Rob Love