Skip to contentSkip to conversation

Performance analysis of i386 SMP timer interrupt

DISCUSSION Chuck Ebbert 1 participant 1 message Dec 4, 2004

lore
Share & tools
lore
#0 lore raw

Performance analysis of arch/i386/kernel/apic.c::smp_local_timer_interrupt:

{
        int cpu = smp_processor_id();

        profile_tick(CPU_PROFILING, regs);

1 -> if (--per_cpu(prof_counter, cpu) <= 0) {

                per_cpu(prof_counter, cpu) = per_cpu(prof_multiplier, cpu);
2 ->            if (per_cpu(prof_counter, cpu) !=
                                        per_cpu(prof_old_multiplier, cpu)) {
3 ->                    __setup_APIC_LVTT(
                                        calibration_result/
                                        per_cpu(prof_counter, cpu));
4 ->                    per_cpu(prof_old_multiplier, cpu) =
                                                per_cpu(prof_counter, cpu);
                }
5 ->            update_process_times(user_mode(regs));
        }
}

(1) Needs likely().

(2) Needs unlikely().

(3,4) (4) should be done before (3) to minimize register usage.
(function becomes 6 insns smaller and uses 8 bytes less stack space)

(5) The user_mode() macro is inefficient:
#define user_mode(regs) ((VM_MASK & (regs)->eflags) || (3 & (regs)->xcs))

(VM86 mode is very rare compared to normal cpu mode, so both parts of the 'or' are evaluated almost every time on most systems.)

--Chuck Ebbert 04-Dec-04 14:50:39