mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 2.6.x] Faster i386 SMP timer interrupts
@ 2004-12-23  5:36 Chuck Ebbert
  0 siblings, 0 replies; only message in thread
From: Chuck Ebbert @ 2004-12-23  5:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds

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 <76306.1226@compuserve.com>
#
--- 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);
--- 2.6.9.1/arch/i386/kernel/apic.c
+++ 2.6.9.2/arch/i386/kernel/apic.c
@@ -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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-12-23  5:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-23  5:36 [PATCH 2.6.x] Faster i386 SMP timer interrupts Chuck Ebbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®