فهرست منبع

timer stats: speedups

Make timer-stats have almost zero overhead when enabled in the config but
not used.  (this way distros can enable it more easily)

Also update the documentation about overhead of timer_stats - it was
written for the first version which had a global lock and a linear list
walk based lookup ;-)

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Ingo Molnar 18 سال پیش
والد
کامیت
c1a834dc70
3فایلهای تغییر یافته به همراه14 افزوده شده و 5 حذف شده
  1. 4 3
      Documentation/hrtimer/timer_stats.txt
  2. 6 1
      kernel/time/timer_stats.c
  3. 4 1
      lib/Kconfig.debug

+ 4 - 3
Documentation/hrtimer/timer_stats.txt

@@ -2,9 +2,10 @@ timer_stats - timer usage statistics
 ------------------------------------
 ------------------------------------
 
 
 timer_stats is a debugging facility to make the timer (ab)usage in a Linux
 timer_stats is a debugging facility to make the timer (ab)usage in a Linux
-system visible to kernel and userspace developers. It is not intended for
-production usage as it adds significant overhead to the (hr)timer code and the
-(hr)timer data structures.
+system visible to kernel and userspace developers. If enabled in the config
+but not used it has almost zero runtime overhead, and a relatively small
+data structure overhead. Even if collection is enabled runtime all the
+locking is per-CPU and lookup is hashed.
 
 
 timer_stats should be used by kernel and userspace developers to verify that
 timer_stats should be used by kernel and userspace developers to verify that
 their code does not make unduly use of timers. This helps to avoid unnecessary
 their code does not make unduly use of timers. This helps to avoid unnecessary

+ 6 - 1
kernel/time/timer_stats.c

@@ -236,10 +236,15 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
 	/*
 	/*
 	 * It doesnt matter which lock we take:
 	 * It doesnt matter which lock we take:
 	 */
 	 */
-	spinlock_t *lock = &per_cpu(lookup_lock, raw_smp_processor_id());
+	spinlock_t *lock;
 	struct entry *entry, input;
 	struct entry *entry, input;
 	unsigned long flags;
 	unsigned long flags;
 
 
+	if (likely(!active))
+		return;
+
+	lock = &per_cpu(lookup_lock, raw_smp_processor_id());
+
 	input.timer = timer;
 	input.timer = timer;
 	input.start_func = startf;
 	input.start_func = startf;
 	input.expire_func = timerf;
 	input.expire_func = timerf;

+ 4 - 1
lib/Kconfig.debug

@@ -126,7 +126,10 @@ config TIMER_STATS
 	  reprogrammed. The statistics can be read from /proc/timer_stats.
 	  reprogrammed. The statistics can be read from /proc/timer_stats.
 	  The statistics collection is started by writing 1 to /proc/timer_stats,
 	  The statistics collection is started by writing 1 to /proc/timer_stats,
 	  writing 0 stops it. This feature is useful to collect information
 	  writing 0 stops it. This feature is useful to collect information
-	  about timer usage patterns in kernel and userspace.
+	  about timer usage patterns in kernel and userspace. This feature
+	  is lightweight if enabled in the kernel config but not activated
+	  (it defaults to deactivated on bootup and will only be activated
+	  if some application like powertop activates it explicitly).
 
 
 config DEBUG_SLAB
 config DEBUG_SLAB
 	bool "Debug slab memory allocations"
 	bool "Debug slab memory allocations"