remove contention on profile_lock
PATCH 1/1 remove contention on profile_lock
profile_hook unconditionally takes a read lock on profile_lock if kernel profiling is enabled. The lock protects the profile_hook notifier chain from being written while it's being called. The routine profile_hook is called in a very hot path though: every timer tick on every CPU. As you can imagine, on a large system, this makes the cacheline containing profile_lock pretty hot. Since oprofile was the only user of the profile_hook, I removed the notifier chain altogether in favor of a simple function pointer with the help of John Levon. This removes all of the contention in the hot path since the variable is very seldom written and simplifies things a little to boot.
Thanks,
Jesse
===== drivers/oprofile/timer_int.c 1.8 vs edited =====
drivers/oprofile/timer_int.c +3 -10
@@ -15,31 +15,24 @@#include <linux/init.h> #include <asm/ptrace.h> -static int timer_notify (struct notifier_block * self,unsigned long val,void * data) +static int timer_notify (struct pt_regs *regs) { -struct pt_regs * regs = (struct pt_regs *)data;int cpu =smp_processor_id ();unsigned long eip =profile_pc (regs);oprofile_add_sample (eip, !user_mode (regs),0 , cpu);return 0 ; } - - -static struct notifier_block timer_notifier = { - .notifier_call = timer_notify, -}; -static int timer_start (void ) { -return register_profile_notifier (&timer_notifier); +return register_timer_hook (timer_notify); }static void timer_stop (void ) { -unregister_profile_notifier (&timer_notifier); +unregister_timer_hook (timer_notify); }
===== include/linux/profile.h 1.11 vs edited =====
include/linux/profile.h +8 -10
@@ -53,13 +53,13 @@int profile_event_register (enum profile_type ,struct notifier_block * n);int profile_event_unregister (enum profile_type ,struct notifier_block * n); -int register_profile_notifier (struct notifier_block * nb); -int unregister_profile_notifier (struct notifier_block * nb); +int register_timer_hook (int (*hook)(struct pt_regs *)); +void unregister_timer_hook (int (*hook)(struct pt_regs *)); -struct pt_regs ; +/* Timer based profiling hook */ +extern int (*timer_hook)(struct pt_regs *); -/* profiling hook activated on each timer interrupt */ -void profile_hook (struct pt_regs * regs); +struct pt_regs ;#else
@@ -87,17 +87,15 @@#define profile_handoff_task (a) (0)#define profile_munmap (a) do { } while (0) -static inline int register_profile_notifier (struct notifier_block * nb) +static inline int register_timer_hook (int (*hook)(struct pt_regs *)) {return -ENOSYS ; } -static inline int unregister_profile_notifier (struct notifier_block * nb) +static inline void unregister_timer_hook (int (*hook)(struct pt_regs *)) { -return -ENOSYS ; +return ; } - -#define profile_hook (regs) do { } while (0)#endif /* CONFIG_PROFILING */
===== kernel/profile.c 1.14 vs edited =====
kernel/profile.c +17 -28
69 lines not on this page · raw message