dynamic ticks for 2.6.13-rc4 & bad gzip
Hi Tony, LKML
Since there appears to be renewed interest of late in dynamic ticks...
You didn't respond with my last patch for dynamic ticks so I assume that's because you threw up when you saw what a mess it is. Anyway I'm sorry for sending you that naive mess the first time around.
Here is a full patch for 2.6.13-rc4 pushing code out of common paths and into dyn-tick.h where possible that builds on any config I can throw on it so far. I'm having trouble with "bad gzip magic" on boot with this one so I'm not really sure what's going on. Perhaps someone on the mailing list can shed some light on it.
Cheers,
Con
arch/i386/Kconfig +32 -0
@@ -457,6 +457,38 @@ config HPET_EMULATE_RTC bool "Provide RTC interrupt" depends on HPET_TIMER && RTC=y +config NO_IDLE_HZ + bool "Dynamic Tick Timer - Skip timer ticks during idle" + help + This option enables support for skipping timer ticks when the + processor is idle. During system load, timer is continuous. + This option saves power, as it allows the system to stay in + idle mode longer. Currently supported timers are ACPI PM + timer, local APIC timer, and TSC timer. HPET timer is currently + not supported. + + Note that you need to enable dynamic tick timer either by + passing dyntick=enable command line option, or via sysfs: + + # echo 1 > /sys/devices/system/timer/timer0/dyn_tick_state + +config DYN_TICK_USE_APIC + bool "Use APIC timer instead of PIT timer" + depends on NO_IDLE_HZ + help + This option enables using APIC timer interrupt if your hardware + supports it. APIC timer allows longer sleep periods compared + to PIT timer. + + Note that on most recent hardware disabling PIT timer also + disables APIC timer interrupts, and system won't run properly. + Symptoms include slow system boot, and time running slow. + + If unsure, don't enable this option. + + Note that to you still need to pass dyntick=enable,forceapic + command line option to use APIC timer. + config SMP bool "Symmetric multi-processing support" ---help---
arch/i386/kernel/apic.c +18 -1
@@ -27,6 +27,7 @@#include <linux/kernel_stat.h> #include <linux/sysdev.h> #include <linux/cpu.h> +#include <linux/dyn-tick.h> #include <asm/atomic.h> #include <asm/smp.h>
@@ -931,6 +932,8 @@ void (*wait_timer_tick)(void) __devinitd#define APIC_DIVISOR 16 +u32 apic_timer_val; +static void __setup_APIC_LVTT (unsigned int clocks) {unsigned int lvtt_value, tmp_value, ver;
@@ -949,7 +952,12 @@ static void __setup_APIC_LVTT(unsigned i & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE)) | APIC_TDR_DIV_16); -apic_write_around (APIC_TMICT , clocks/APIC_DIVISOR ); + apic_timer_val = clocks/APIC_DIVISOR ; + +if (apic_timer_val) +set_dyn_tick_max_skip (apic_timer_val); + +apic_write_around (APIC_TMICT , apic_timer_val); }static void __devinit setup_APIC_timer (unsigned int clocks)
@@ -1062,6 +1070,8 @@ void __init setup_boot_APIC_clock(void)*/ setup_APIC_timer (calibration_result); +setup_dyn_tick_use_apic (calibration_result); +local_irq_enable (); }
@@ -1200,6 +1210,13 @@ fastcall void smp_apic_timer_interrupt(s* interrupt lock, which is the WrongThing (tm) to do. */ irq_enter (); + +/* +* Check if we need to wake up PIT interrupt handler. +* Otherwise just wake up local APIC timer. +*/ +wakeup_pit_or_apic (cpu, regs); +smp_local_timer_interrupt (regs);irq_exit (); }
arch/i386/kernel/dyn-tick.c +164 -0
164 lines not on this page · raw message
arch/i386/kernel/irq.c +3 -0
@@ -18,6 +18,7 @@#include <linux/notifier.h> #include <linux/cpu.h> #include <linux/delay.h> +#include <linux/dyn-tick.h> DEFINE_PER_CPU(irq_cpustat_t, irq_stat) ____cacheline_maxaligned_in_smp;EXPORT_PER_CPU_SYMBOL (irq_stat);
@@ -76,6 +77,8 @@ fastcall unsigned int do_IRQ(struct pt_r }#endif +dyn_tick_interrupt (irq, regs); +#ifdef CONFIG_4KSTACKS curctx = (union irq_ctx *)current_thread_info ();
arch/i386/kernel/Makefile +1 -0
@@ -32,6 +32,7 @@ obj-$(CONFIG_MODULES) += module.o obj-y += sysenter.o vsyscall.o obj-$(CONFIG_ACPI_SRAT) += srat.o obj-$(CONFIG_HPET_TIMER) += time_hpet.o +obj-$(CONFIG_NO_IDLE_HZ) += dyn-tick.o obj-$(CONFIG_EFI) += efi.o efi_stub.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
arch/i386/kernel/process.c +3 -0
@@ -39,6 +39,7 @@#include <linux/ptrace.h> #include <linux/random.h> #include <linux/kprobes.h> +#include <linux/dyn-tick.h> #include <asm/uaccess.h> #include <asm/pgtable.h>
@@ -200,6 +201,8 @@ void cpu_idle(void)if (cpu_is_offline (cpu))play_dead (); +dyn_tick_reprogram_timer (); +__get_cpu_var (irq_stat).idle_timestamp = jiffies;idle (); }
arch/i386/kernel/time.c +5 -2
@@ -46,6 +46,7 @@#include <linux/bcd.h> #include <linux/efi.h> #include <linux/mca.h> +#include <linux/dyn-tick.h> #include <asm/io.h> #include <asm/smp.h>
@@ -252,7 +253,7 @@ EXPORT_SYMBOL(profile_pc);* timer_interrupt() needs to keep up the real-time clock, * as well as call the "do_timer()" routine every clocktick */ -static inline void do_timer_interrupt (int irq,void *dev_id, +void do_timer_interrupt (int irq,void *dev_id,struct pt_regs *regs) {#ifdef CONFIG_X86_IO_APIC
@@ -423,7 +424,7 @@ static struct sysdev_class timer_sysclas/* XXX this driverfs stuff should probably go elsewhere later -john */ -static struct sys_device device_timer = { +struct sys_device device_timer = { .id =0 , .cls = &timer_sysclass, };
@@ -479,5 +480,7 @@ void __init time_init(void) cur_timer =select_timer ();printk (KERN_INFO "Using %s for high-res timesource\n" ,cur_timer->name); +dyn_tick_time_init (cur_timer); +time_init_hook (); }
arch/i386/kernel/timers/timer_pit.c +37 -0
@@ -148,6 +148,43 @@ static unsigned long get_offset_pit(voidreturn count; } +/* +* REVISIT: Looks like on P3 APIC timer keeps running if PIT mode +* is changed. On P4, changing PIT mode seems to kill +* APIC timer interrupts. Same thing with disabling PIT +* interrupt. +*/ +void disable_pit_timer (void ) +{ +extern spinlock_t i8253_lock; +unsigned long flags; +spin_lock_irqsave (&i8253_lock, flags); +outb_p (0x32 ,PIT_MODE );/* binary, mode 1, LSB/MSB, ch 0 */ +spin_unlock_irqrestore (&i8253_lock, flags); +} + +/* +* Reprograms the next timer interrupt +* PIT timer reprogramming code taken from APM code. +* Note that PIT timer is a 16-bit timer, which allows max +* skip of only few seconds. +*/ +void reprogram_pit_timer (int jiffies_to_skip) +{ +int skip; +extern spinlock_t i8253_lock; +unsigned long flags; + + skip = jiffies_to_skip *LATCH ; +if (skip >0xffff ) + skip =0xffff ; + +spin_lock_irqsave (&i8253_lock, flags); +outb_p (0x34 ,PIT_MODE );/* binary, mode 2, LSB/MSB, ch 0 */ +outb_p (skip &0xff ,PIT_CH0 );/* LSB */ +outb (skip >>8 ,PIT_CH0 );/* MSB */ +spin_unlock_irqrestore (&i8253_lock, flags); +}/* tsc timer_opts struct */ struct timer_opts timer_pit = {
arch/i386/kernel/timers/timer_pm.c +4 -0
@@ -15,6 +15,7 @@#include <linux/module.h> #include <linux/device.h> #include <linux/init.h> +#include <linux/dyn-tick.h> #include <asm/types.h> #include <asm/timer.h> #include <asm/smp.h>
@@ -168,6 +169,9 @@ static void mark_offset_pmtmr(void) monotonic_base += delta *NSEC_PER_USEC ;write_sequnlock (&monotonic_lock); +if (dyn_tick_enabled ()) +return ; +/* convert to ticks */ delta += offset_delay; lost = delta / (USEC_PER_SEC /HZ );
arch/i386/kernel/timers/timer_tsc.c +10 -0
@@ -14,6 +14,7 @@#include <linux/cpufreq.h> #include <linux/string.h> #include <linux/jiffies.h> +#include <linux/dyn-tick.h> #include <asm/timer.h> #include <asm/io.h>
@@ -367,6 +368,9 @@ static void mark_offset_tsc(void)rdtsc (last_tsc_low, last_tsc_high); +if (dyn_tick_enabled ()) + goto monotonic_base; +spin_lock (&i8253_lock);outb_p (0x00 ,PIT_MODE );/* latch the count ASAP */
@@ -434,11 +438,17 @@ static void mark_offset_tsc(void)cpufreq_delayed_get (); }else lost_count =0 ; + + monotonic_base: +/* update the monotonic base value */ this_offset = ((unsigned long long )last_tsc_high<<32 )|last_tsc_low; monotonic_base +=cycles_2_ns (this_offset - last_offset);write_sequnlock (&monotonic_lock); +if (dyn_tick_enabled ()) +return ; +/* calculate delay_at_last_interrupt */ count = ((LATCH -1 ) - count) *TICK_SIZE ; delay_at_last_interrupt = (count +LATCH /2 ) /LATCH ;
arch/i386/mach-default/setup.c +16 -0
@@ -93,6 +93,22 @@ void __init time_init_hook(void)setup_irq (0 , &irq0); } +/** +* replace_timer_interrupt - allow replacing timer interrupt handler +* +* Description: +* Can be used to replace timer interrupt handler with a more optimized +* handler. Used for enabling and disabling of CONFIG_NO_IDLE_HZ. +*/ +void replace_timer_interrupt (void * new_handler) +{ +unsigned long flags; + +write_seqlock_irqsave (&xtime_lock, flags); + irq0.handler = new_handler; +write_sequnlock_irqrestore (&xtime_lock, flags); +} +#ifdef CONFIG_MCA /** * mca_nmi_hook - hook into MCA specific NMI chain
include/asm-i386/dyn-tick.h +66 -0
66 lines not on this page · raw message
include/linux/dyn-tick.h +66 -0
66 lines not on this page · raw message
kernel/dyn-tick.c +212 -0
212 lines not on this page · raw message
kernel/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_SYSFS) += ksysfs.o obj-$(CONFIG_GENERIC_HARDIRQS) += irq/ obj-$(CONFIG_CRASH_DUMP) += crash_dump.o obj-$(CONFIG_SECCOMP) += seccomp.o +obj-$(CONFIG_NO_IDLE_HZ) += dyn-tick.o ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y) # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
Quoted 7 lines · Con Kolivas
Hi Tony, LKML
Since there appears to be renewed interest of late in dynamic ticks...
You didn't respond with my last patch for dynamic ticks so I assume that's because you threw up when you saw what a mess it is. Anyway I'm sorry for sending you that naive mess the first time around.
Hehe, my strategy of lame response and sloppy patches seems to be working then! :)
Quoted 5 lines
Here is a full patch for 2.6.13-rc4 pushing code out of common paths and into
dyn-tick.hwhere possible that builds on any config I can throw on it so far. I'm having trouble with "bad gzip magic" on boot with this one so I'm not really sure what's going on. Perhaps someone on the mailing list can shed some light on it.
Thanks a lot, I really appreciate help on getting this thing cleaned up for x86 + PPC. The ARM version is already merged to mainline, but that's did not have all the legacy issues, and ARM has nice sys_timer...
I'll try out your patch today at some point, and will post a merged patches that also integrate the PPC support.
I don't understand the "bad gzip magic", that happens while uncompressing before kernel boots, right?
Regards,
Tony
Quoted 11 lines · Tony Lindgren
Quoted 7 lines · Con Kolivas
Hi Tony, LKML
Since there appears to be renewed interest of late in dynamic ticks...
You didn't respond with my last patch for dynamic ticks so I assume that's because you threw up when you saw what a mess it is. Anyway I'm sorry for sending you that naive mess the first time around.
Hehe, my strategy of lame response and sloppy patches seems to be working then! :)
Yes you must have learnt from akpm :P He's a master of that game. Thanks for replying :)
Quoted 9 lines
Quoted 5 lines
Here is a full patch for 2.6.13-rc4 pushing code out of common paths and into
dyn-tick.hwhere possible that builds on any config I can throw on it so far. I'm having trouble with "bad gzip magic" on boot with this one so I'm not really sure what's going on. Perhaps someone on the mailing list can shed some light on it.Thanks a lot, I really appreciate help on getting this thing cleaned up for x86 + PPC. The ARM version is already merged to mainline, but that's did not have all the legacy issues, and ARM has nice
sys_timer...
You're welcome, but I'm no coding expert and just applying a few styling issues as I see them.
Quoted 5 lines
I'll try out your patch today at some point, and will post a merged patches that also integrate the PPC support.
I don't understand the "bad gzip magic", that happens while uncompressing before kernel boots, right?
Yeah, bzImage has some convoluted way of storing the gunzip code in the header and then it decompresses the image. This error implies something went horribly wrong but I have seen it before occasionally with gcc 4.0.1 - it usually goes away with reconfigure/rebuilding but this one didn't. Probably not important for this code per se.
Cheers,
Con
PF_KEY & 26Sec Documentation
In reply to Tony LindgrenHI all,
I working on IPSEC for hardware offloading.. Can some body help me from
where I can get the documentation..
Tehst