x86: Reduce the default HZ value
Quoted 26 lines · On Tue, 2009-05-12 at 12:45 -0700, [email protected] wrote:
Quoted 16 lines
Quoted 16 lines
Quoted 10 lines
Quoted 5 lines
As a side note Red Hat ships runtime configurable tick behaviour in RHEL these days. HZ is fixed but the ticks can be bunched up. That was done as a quick fix to keep stuff portable but its a lot more sensible than randomly messing with the HZ value and its not much code either.
Hi Alan,
I guess you are talking about the
tick_dividerpatch ?
And that's still same as reducing the HZ value only that it can be done dynamically (boot time), right ?Yes - which has the advantage that you can select different behaviours rather than distributions having to build with HZ=1000 either for compatibility or responsiveness can still allow users to drop to a lower HZ value if doing stuff like HPC.
Quoted 4 lines
Quoted 2 lines
Basically it removes the need to argue about it at build time and lets the user decide.
any reason why this did not reach mainline?
I think it is because during the time when this was implemented for RHEL 5, mainline was moving towards the tickless approach, which might have prompted people to think that it would no more be useful for mainline.
Quoted 5 lines
Since Alan was the one who implemented those patches, I guess he would have a better say on this. Alan, are there any plans for mainlining this now ?
Alok
anyway, just fyi or for some additional transparency, here`s the 4 tick-divider related patches from "recent" RHEL5 kernel
(-> http://isoredirect.centos.org/centos/5/os/SRPMS/kernel-2.6.18-128.el5.src.rpm)
regards
roland
cat ./linux-2.6-docs-update-kernel-parameters-with-tick-divider.patch
From: Chris Lalancette <[email protected]>
Date: Wed, 17 Sep 2008 17:14:19 +0200
Subject: [docs] update kernel-parameters with tick-divider
Message-id: [email protected]
O-Subject: [RHEL5.3 PATCH v2]: Update kernel-parameters with tick-divider
Bugzilla: 454792
We have a request to better document the tick divider patch that went into 5.1.
Towards this end, I came up with the following patch toDocumentation/kernel-parameters.txt. Not sure if it needs ACKs or anything, but I wanted to make sure dzickus saw it. This will resolve BZ 454792. This version doesn't tell the user to divide by zero (thanks Alan).
--
Chris Lalancette
Documentation/kernel-parameters.txt +4 -0
@@ -470,6 +470,10 @@ running once the system is up. See drivers/char/README.epca and Documentation/digiepca.txt. + divider= [IA-32,X86-64] + divide kernel HZ rate by given value. + Format: <num>, where <num> is between 1 and 25 + dmascc= [HW,AX25,SERIAL] AX.25 Z80SCC driver with DMA support available. Format: <io_dev0>[,<io_dev1>[,..<io_dev32>]]
cat ./linux-2.6-x86_64-fix-casting-issue-in-tick-divider-patch.patch
From: Prarit Bhargava <[email protected]>
Subject: [RHEL 5.1 PATCH]: Fix casting issue in tick divider patch
Date: Wed, 20 Jun 2007 14:16:29 -0400
Bugzilla: 244861
Message-Id: <[email protected]>
Changelog: [x86_64] Fix casting issue in tick divider patch
Fix a casting bug in the tick divider patch.
Successfully tested by me on a variety of systems that were exhibiting slow boot behaviour.
Resolves BZ 244861.
arch/x86_64/kernel/time.c 2007-06-20 04:28:58.000000000 -0400 renamed from arch/x86_64/kernel/time.c.orig 2007-06-20 04:21:58.000000000 -0400 +1 -1
@@ -433,7 +433,7 @@ void main_timer_handler(struct pt_regs * (((long) offset << US_SCALE) / vxtime.tsc_quot) - 1; } /* SCALE: We expect tick_divider - 1 lost, ie 0 for normal behaviour */ - if (lost > tick_divider - 1) { + if (lost > (int)tick_divider - 1) { handle_lost_ticks(lost, regs); jiffies += lost - (tick_divider - 1); }
cat ./linux-2.6-x86-fixes-for-the-tick-divider-patch.patch
From: Chris Lalancette <[email protected]>
Subject: Re: [RHEL 5.1.z PATCH]: Fixes for the tick divider patch
Date: Tue, 02 Oct 2007 16:53:22 -0400
Bugzilla: 315471
Message-Id: <[email protected]>
Changelog: [x86] Fixes for the tick divider patch
All,
While testing the tick divider patch under VMware, a number of issues were
found with it:
1) On i386, when specifying "divider=10 apic=verbose", a bogus value was printed for the CPU MHz and the host bus speed. This is because during APIC calibration, we were using "HZ/10" loops instead of "REAL_HZ/10", causing the calculation to go out of bounds.
2) On x86_64, when using the tick divider, it wasn't dividing the local APIC as well as the external timer. This causes problems under VMware since the hypervisor (ESX server) has to deliver 1000 local APIC interrupts per second to each logical processor, which can end up causing time drift. By properly dividing the local APIC as well as the external time source, it significantly reduces the load on the HV, and the guests have less tendency to drift.
3) On x86_64, we weren't looping during smp_local_timer_interrupt(), so we were losing profiling ticks.
3) On x86_64, when using the tick divider with PM-Timer, lost tick compensation wasn't being calculated properly. In particular, we would count ticks as lost when they really weren't, because we were using HZ instead of REAL_HZ in the lost calculation.
4) On x86_64, TSC suffers from the same problem as PM-Timer.
The attached patch fixes all 4 of these problems. Additionally, this patch also adds a "hz=" command-line parameter for both i386 and x86_64. This is nicer way to specify the divider from a user point-of-view; they don't have to know the current value of HZ in order to specify the HZ value they want.
These patches are not upstream, since upstream has since gone with the tickless kernel.
Patches successfully tested by myself (just for verifying basic correctness), and HP and VMware using ESX server.
This fixes BZ 305011. Please review and ACK.
Chris Lalancette
Quoted 5 lines
ACK less the hz= bits for 5.1.z, per Alan's concern about only certain values in the currently accepted range actually being valid. I'd say fully bake that part for 5.2 and just take the fixes for 5.1.z.
Same patch, with hz= bits removed for the z-stream.
Chris Lalancette
arch/i386/kernel/apic.c 2007-10-02 16:47:00.000000000 -0400 renamed from arch/i386/kernel/apic.c 2007-10-02 16:42:24.000000000 -0400 +5 -5
@@ -1027,7 +1027,7 @@ static int __init calibrate_APIC_clock(v long tt1, tt2; long result; int i; - const int LOOPS = HZ/10; + const int LOOPS = REAL_HZ/10; apic_printk(APIC_VERBOSE, "calibrating APIC timer ...\n");
@@ -1076,13 +1076,13 @@ static int __init calibrate_APIC_clock(v if (cpu_has_tsc) apic_printk(APIC_VERBOSE, "..... CPU clock speed is " "%ld.%04ld MHz.\n", - ((long)(t2-t1)/LOOPS)/(1000000/HZ), - ((long)(t2-t1)/LOOPS)%(1000000/HZ)); + ((long)(t2-t1)/LOOPS)/(1000000/REAL_HZ), + ((long)(t2-t1)/LOOPS)%(1000000/REAL_HZ)); apic_printk(APIC_VERBOSE, "..... host bus clock speed is " "%ld.%04ld MHz.\n", - result/(1000000/HZ), - result%(1000000/HZ)); + result/(1000000/REAL_HZ), + result%(1000000/REAL_HZ)); return result; }
arch/x86_64/kernel/apic.c 2007-10-02 16:47:00.000000000 -0400 renamed from arch/x86_64/kernel/apic.c 2007-10-02 16:42:30.000000000 -0400 +6 -3
@@ -811,7 +811,7 @@ static int __init calibrate_APIC_clock(v printk(KERN_INFO "Detected %d.%03d MHz APIC timer.\n", result / 1000 / 1000, result / 1000 % 1000); - return result * APIC_DIVISOR / HZ; + return result * APIC_DIVISOR / REAL_HZ; } static unsigned int calibration_result;
@@ -941,10 +941,13 @@ void setup_APIC_extened_lvt(unsigned cha void smp_local_timer_interrupt(struct pt_regs *regs) { - profile_tick(CPU_PROFILING, regs); + int i; + for (i = 0; i < tick_divider; i++) { + profile_tick(CPU_PROFILING, regs); #ifdef CONFIG_SMP - update_process_times(user_mode(regs)); + update_process_times(user_mode(regs)); #endif + } if (apic_runs_main_timer > 1 && smp_processor_id() == boot_cpu_id) main_timer_handler(regs); /*
arch/x86_64/kernel/pmtimer.c 2007-10-02 16:47:00.000000000 -0400 renamed from arch/x86_64/kernel/pmtimer.c 2006-09-19 23:42:06.000000000 -0400 +2 -2
@@ -64,8 +64,8 @@ int pmtimer_mark_offset(void) delta += offset_delay; - lost = delta / (USEC_PER_SEC / HZ); - offset_delay = delta % (USEC_PER_SEC / HZ); + lost = delta / (USEC_PER_SEC / REAL_HZ); + offset_delay = delta % (USEC_PER_SEC / REAL_HZ); rdtscll(tsc); vxtime.last_tsc = tsc - offset_delay * (u64)cpu_khz / 1000;
arch/x86_64/kernel/time.c 2007-10-02 16:47:43.000000000 -0400 renamed from arch/x86_64/kernel/time.c 2007-10-02 16:42:31.000000000 -0400 +8 -6
@@ -65,6 +65,8 @@ static int notsc __initdata = 0; #define NSEC_PER_TICK (NSEC_PER_SEC / HZ) #define FSEC_PER_TICK (FSEC_PER_SEC / HZ) +#define USEC_PER_REAL_TICK (USEC_PER_SEC / REAL_HZ) + #define NS_SCALE 10 /* 2^10, carefully chosen */ #define US_SCALE 32 /* 2^32, arbitralrily chosen */
@@ -304,7 +306,7 @@ unsigned long long monotonic_clock(void) this_offset = hpet_readl(HPET_COUNTER); } while (read_seqretry(&xtime_lock, seq)); offset = (this_offset - last_offset); - offset *= NSEC_PER_TICK / hpet_tick; + offset *= NSEC_PER_TICK / hpet_tick_real; } else { do { seq = read_seqbegin(&xtime_lock);
@@ -406,7 +408,7 @@ void main_timer_handler(struct pt_regs * } monotonic_base += - (offset - vxtime.last) * NSEC_PER_TICK / hpet_tick; + (offset - vxtime.last) * NSEC_PER_TICK / hpet_tick_real; vxtime.last = offset; #ifdef CONFIG_X86_PM_TIMER
@@ -415,14 +417,14 @@ void main_timer_handler(struct pt_regs * #endif } else { offset = (((tsc - vxtime.last_tsc) * - vxtime.tsc_quot) >> US_SCALE) - USEC_PER_TICK; + vxtime.tsc_quot) >> US_SCALE) - USEC_PER_REAL_TICK; if (offset < 0) offset = 0; - if (offset > USEC_PER_TICK) { - lost = offset / USEC_PER_TICK; - offset %= USEC_PER_TICK; + if (offset > USEC_PER_REAL_TICK) { + lost = offset / USEC_PER_REAL_TICK; + offset %= USEC_PER_REAL_TICK; } /* FIXME: 1000 or 1000000? */
cat ./linux-2.6-x86-tick-divider.patch
From: Alan Cox <[email protected]>
Subject: [RHEL5]: Tick Divider (Bugzilla #215403]
Date: Wed, 18 Apr 2007 16:39:15 -0400
Bugzilla: 215403
Message-Id: <[email protected]>
Changelog: [x86] Tick Divider
The following patch implements a tick divider feature that allows you to boot the kernel with HZ at 1000 but the real timer tick rate lower (thus not breaking all the modules and kABI).
The selection is done at boot to minimize risk and the patch has been reworked so that you can do an informal attempt at a proof that it doesn't cause regression for the non dividing case.
The patch interleaved with notes follows, and below that the actual patch proper.
Xen kernels remain at 250HZ because
a) Xen guests have a 'tickless mode'
b) Xen itself has issues with multiple differing guest GZ rates
Not queued for upstream as the upstream path is Ingo's tickless kernel, which is not viable as a RHEL5 tweak
arch/i386/kernel/apic.c +5 -2
@@ -1185,10 +1185,13 @@ EXPORT_SYMBOL(switch_ipi_to_APIC_timer);inline void smp_local_timer_interrupt (struct pt_regs * regs) { -profile_tick (CPU_PROFILING , regs); +int i; +for (i =0 ; i < tick_divider; i++) { +profile_tick (CPU_PROFILING , regs);#ifdef CONFIG_SMP -update_process_times (user_mode_vm (regs)); +update_process_times (user_mode_vm (regs));#endif + }/* * We take the 'long' return path, and there every subsystem
arch/i386/kernel/apm.c +1 -1
@@ -1189,7 +1189,7 @@ static void reinit_timer(void)unsigned long flags;spin_lock_irqsave (&i8253_lock, flags); -/* set the clock to 100 Hz */ +/* set the clock to HZ */ outb_p (0x34 ,PIT_MODE );/* binary, mode 2, LSB/MSB, ch 0 */ udelay (10 );outb_p (LATCH &0xff ,PIT_CH0 );/* LSB */
arch/i386/kernel/i8253.c +6 -2
@@ -26,6 +26,7 @@ void setup_pit_timer(void)spin_lock_irqsave (&i8253_lock, flags);outb_p (0x34 ,PIT_MODE );/* binary, mode 2, LSB/MSB, ch 0 */ udelay (10 ); +/* Physical HZ */ outb_p (LATCH &0xff ,PIT_CH0 );/* LSB */ udelay (10 );outb (LATCH >>8 ,PIT_CH0 );/* MSB */
@@ -94,8 +95,11 @@ static cycle_t pit_read(void)spin_unlock_irqrestore (&i8253_lock, flags); count = (LATCH -1 ) - count; - -return (cycle_t)(jifs *LATCH ) + count; +/* Adjust to logical ticks */ + count *= tick_divider; + +/* Keep the jiffies in terms of logical ticks not physical */ +return (cycle_t)(jifs *LOGICAL_LATCH ) + count; }static struct clocksource clocksource_pit = {
arch/i386/kernel/time.c +19 -0
@@ -366,3 +367,22 @@ void __init time_init(void)time_init_hook (); } + +#ifdef CONFIG_TICK_DIVIDER + +unsigned int tick_divider =1 ; + +static int __init divider_setup (char *s) +{ +unsigned int divider =1 ; +get_option (&s, ÷r); +if (divider >=1 &&HZ /divider >=25 ) + tick_divider = divider; +else +printk (KERN_ERR "tick_divider: %d is out of range.\n" , divider); +return 1 ; +} + +__setup ("divider=" , divider_setup); + +#endif
arch/i386/kernel/time_hpet.c +3 -1
@@ -24,6 +24,7 @@static unsigned long hpet_period;/* fsecs / HPET clock */ unsigned long hpet_tick;/* hpet clks count per tick */ +unsigned long hpet_tick_real;/* hpet clocks per interrupt */ unsigned long hpet_address;/* hpet memory map physical address */ int hpet_use_timer;
@@ -156,7 +157,8 @@ int __init hpet_enable(void) hpet_use_timer = id &HPET_ID_LEGSUP ; -if (hpet_timer_stop_set_go (hpet_tick)) + hpet_tick_real = hpet_tick * tick_divider; +if (hpet_timer_stop_set_go (hpet_tick_real))return -1 ; use_hpet =1 ;
arch/x86_64/Kconfig +7 -0
@@ -443,6 +443,13 @@ config HPET_EMULATE_RTC bool "Provide RTC interrupt" depends on HPET_TIMER && RTC=y +config TICK_DIVIDER + bool "Support clock division" + default n + help + Supports the use of clock division allowing the real interrupt + rate to be lower than the HZ setting. + # Mark as embedded because too many people got it wrong. # The code disables itself when not needed. config IOMMU
arch/x86_64/kernel/i8259.c +1 -0
@@ -498,6 +498,7 @@ static void setup_timer_hardware(void) {outb_p (0x34 ,0x43 );/* binary, mode 2, LSB/MSB, ch 0 */ udelay (10 ); +/* LATCH is in physical clocks */ outb_p (LATCH &0xff ,0x40 );/* LSB */ udelay (10 );outb (LATCH >>8 ,0x40 );/* MSB */
arch/x86_64/kernel/time.c +61 -26
191 lines not on this page · raw message
include/asm-i386/mach-default/do_timer.h +7 -3
@@ -16,17 +16,21 @@static inline void do_timer_interrupt_hook (struct pt_regs *regs) { -do_timer (regs); +int i; +for (i =0 ; i < tick_divider; i++) { +do_timer (regs);#ifndef CONFIG_SMP -update_process_times (user_mode_vm (regs)); +update_process_times (user_mode_vm (regs));#endif + }/* * In the SMP case we use the local APIC timer interrupt to do the * profiling, except when we simulate SMP mode on a uniprocessor * system, in that case we have to call the local interrupt handler. */ #ifndef CONFIG_X86_LOCAL_APIC -profile_tick (CPU_PROFILING , regs); +for (i =0 ; i < tick_divider; i++) +profile_tick (CPU_PROFILING , regs);#else if (!using_apic_timer)smp_local_timer_interrupt (regs);
include/asm-i386/mach-visws/do_timer.h +7 -3
@@ -6,20 +6,24 @@static inline void do_timer_interrupt_hook (struct pt_regs *regs) { +int i;/* Clear the interrupt */ co_cpu_write (CO_CPU_STAT ,co_cpu_read (CO_CPU_STAT ) & ~CO_STAT_TIMEINTR ); -do_timer (regs); +for (i =0 ; i < tick_divider; i++) { +do_timer (regs);#ifndef CONFIG_SMP -update_process_times (user_mode_vm (regs)); +update_process_times (user_mode_vm (regs));#endif + }/* * In the SMP case we use the local APIC timer interrupt to do the * profiling, except when we simulate SMP mode on a uniprocessor * system, in that case we have to call the local interrupt handler. */ #ifndef CONFIG_X86_LOCAL_APIC -profile_tick (CPU_PROFILING , regs); +for (i =0 ; i < tick_divider; i++) +profile_tick (CPU_PROFILING , regs);#else if (!using_apic_timer)smp_local_timer_interrupt (regs);
include/asm-i386/mach-voyager/do_timer.h +6 -4
@@ -3,12 +3,14 @@static inline void do_timer_interrupt_hook (struct pt_regs *regs) { -do_timer (regs); +int i; +for (i =0 ; i < tick_divider; i++) { +do_timer (regs);#ifndef CONFIG_SMP -update_process_times (user_mode_vm (regs)); +update_process_times (user_mode_vm (regs));#endif - -voyager_timer_interrupt (regs); +voyager_timer_interrupt (regs); + } }static inline int do_timer_overflow (int count)
include/linux/jiffies.h +15 -4
@@ -33,10 +33,21 @@# error You lose.#endif +#ifndef CONFIG_TICK_DIVIDER +#define tick_divider 1 +#else +extern unsigned int tick_divider; +#endif + +#define REAL_HZ (HZ/tick_divider)/* LATCH is used in the interval timer and ftape setup. */ -#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ)/* For divider */ +#define LATCH ((CLOCK_TICK_RATE + REAL_HZ/2) / REAL_HZ)/* For divider */ + +#define LATCH_HPET ((HPET_TICK_RATE + REAL_HZ/2) / REAL_HZ) + +#define LOGICAL_LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ)/* For divider */ -#define LATCH_HPET ((HPET_TICK_RATE + HZ/2) / HZ) +#define LOGICAL_LATCH_HPET ((HPET_TICK_RATE + HZ/2) / HZ)/* Suppose we want to devide two numbers NOM and DEN: NOM/DEN, the we can * improve accuracy by shifting LSH bits, hence calculating:
@@ -51,9 +62,9 @@ + ((((NOM) % (DEN)) << (LSH)) + (DEN) / 2) / (DEN))/* HZ is the requested value. ACTHZ is actual HZ ("<< 8" is for accuracy) */ -#define ACTHZ (SH_DIV (CLOCK_TICK_RATE, LATCH, 8)) +#define ACTHZ (SH_DIV (CLOCK_TICK_RATE, LOGICAL_LATCH, 8)) -#define ACTHZ_HPET (SH_DIV (HPET_TICK_RATE, LATCH_HPET, 8)) +#define ACTHZ_HPET (SH_DIV (HPET_TICK_RATE, LOGICAL_LATCH_HPET, 8))/* TICK_NSEC is the time between ticks in nsec assuming real ACTHZ */ #define TICK_NSEC (SH_DIV (1000000UL * 1000, ACTHZ, 8))
init/calibrate.c +9 -6
@@ -26,7 +26,6 @@ __setup("lpj=", lpj_setup);* Also, this code tries to handle non-maskable asynchronous events * (like SMIs) */ -#define DELAY_CALIBRATION_TICKS ((HZ < 100) ? 1 : (HZ/100))#define MAX_DIRECT_CALIBRATION_RETRIES 5static unsigned long __devinit calibrate_delay_direct (void )
@@ -37,6 +36,7 @@ static unsigned long __devinit calibrateunsigned long tsc_rate_min, tsc_rate_max;unsigned long good_tsc_sum =0 ;unsigned long good_tsc_count =0 ; +unsigned long delay_calibration_ticks = ((REAL_HZ <100 ) ?1 : (REAL_HZ /100 ));int i;if (read_current_timer (&pre_start) <0 )
@@ -65,7 +65,7 @@ static unsigned long __devinit calibrate pre_start =0 ;read_current_timer (&start); start_jiffies = jiffies; -while (jiffies <= (start_jiffies +1 )) { +while (jiffies <= (start_jiffies + tick_divider)) { pre_start = start;read_current_timer (&start); }
@@ -74,15 +74,18 @@ static unsigned long __devinit calibrate pre_end =0 ; end = post_start;while (jiffies <= - (start_jiffies +1 +DELAY_CALIBRATION_TICKS )) { + (start_jiffies + tick_divider * (1 + delay_calibration_ticks))) { pre_end = end;read_current_timer (&end); }read_current_timer (&post_end); - tsc_rate_max = (post_end - pre_start) /DELAY_CALIBRATION_TICKS ; - tsc_rate_min = (pre_end - post_start) /DELAY_CALIBRATION_TICKS ; - + tsc_rate_max = (post_end - pre_start) / delay_calibration_ticks; + tsc_rate_min = (pre_end - post_start) / delay_calibration_ticks; + + tsc_rate_max /= tick_divider; + tsc_rate_min /= tick_divider; +/* * If the upper limit and lower limit of the tsc_rate is * >= 12.5% apart, redo calibration.
arch/i386/Kconfig +7 -0
@@ -238,6 +238,13 @@ config HPET_EMULATE_RTC depends on HPET_TIMER && RTC=y default y +config TICK_DIVIDER + bool "Support clock division" + default n + help + Supports the use of clock division allowing the real interrupt + rate to be lower than the HZ setting. + config NR_CPUS int "Maximum number of CPUs (2-255)" range 2 255
______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT! Jetzt freischalten unter http://movieflat.web.de
It was done as a back compatible option and with tickless the future it wasn't really planned for upstreaming. No reason I can see it shouldn't be however.
Alan