Skip to contentSkip to conversation

Faster i386 SMP timer interrupts

PATCH New Chuck Ebbert 1 participant 1 message Dec 23, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Faster i386 SMP timer interrupts

I've been using this one for a while now. It fixes the slow user_mode() macro in ptrace.h, adds likely/unlikely to the timer interrupt code and reorders two lines of code to take advantage of recently-used values.

Saves about 20-30 CPU clocks per interrupt and uses less stack space.

# i386_smp_timer_speedup_2.patch
#       include/asm-i386/ptrace.h -1 +1
#       arch/i386/kernel/apic.c -5 +5
#
#       Speed up i386 SMP timer interrupt.
#
#       Signed-off-by: Chuck Ebbert <[email protected]>
#
--- 2.6.9.1/include/asm-i386/ptrace.h
+++ 2.6.9.2/include/asm-i386/ptrace.h
@@ -55,7 +55,7 @@ struct pt_regs {
 #define PTRACE_SET_THREAD_AREA    26

#ifdef __KERNEL__
-#define user_mode(regs) ((VM_MASK & (regs)->eflags) || (3 & (regs)->xcs)) +#define user_mode(regs) !!((VM_MASK & (regs)->eflags) | (3 & (regs)->xcs))
#define instruction_pointer(regs) ((regs)->eip)
#if defined(CONFIG_SMP) && defined(CONFIG_FRAME_POINTER) extern unsigned long profile_pc(struct pt_regs *regs);

arch/i386/kernel/apic.c +5 -5
@@ -1082,7 +1082,7 @@ inline void smp_local_timer_interrupt(st
        int cpu = smp_processor_id();
 
        profile_tick(CPU_PROFILING, regs);
-       if (--per_cpu(prof_counter, cpu) <= 0) {
+       if (likely(--per_cpu(prof_counter, cpu) <= 0)) {
                /*
                 * The multiplier may have changed since the last time we got
                 * to this point as a result of the user writing to
@@ -1092,13 +1092,13 @@ inline void smp_local_timer_interrupt(st
                 * Interrupts are already masked off at this point.
                 */
                per_cpu(prof_counter, cpu) = per_cpu(prof_multiplier, cpu);
-               if (per_cpu(prof_counter, cpu) !=
-                                       per_cpu(prof_old_multiplier, cpu)) {
+               if (unlikely(per_cpu(prof_counter, cpu) !=
+                                       per_cpu(prof_old_multiplier, cpu))) {
+                       per_cpu(prof_old_multiplier, cpu) =
+                                               per_cpu(prof_counter, cpu);
                        __setup_APIC_LVTT(
                                        calibration_result/
                                        per_cpu(prof_counter, cpu));
-                       per_cpu(prof_old_multiplier, cpu) =
-                                               per_cpu(prof_counter, cpu);
                }
 
 #ifdef CONFIG_SMP

--
Please take it as a sign of my infinite respect for you, that I insist on you doing all the work.
-- Rusty Russell