Skip to content

Commit c1a834d

Browse files
Ingo MolnarLinus Torvalds
authored andcommitted
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>
1 parent 9fcc15e commit c1a834d

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎Documentation/hrtimer/timer_stats.txt‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ timer_stats - timer usage statistics
22
------------------------------------
33

44
timer_stats is a debugging facility to make the timer (ab)usage in a Linux
5-
system visible to kernel and userspace developers. It is not intended for
6-
production usage as it adds significant overhead to the (hr)timer code and the
7-
(hr)timer data structures.
5+
system visible to kernel and userspace developers. If enabled in the config
6+
but not used it has almost zero runtime overhead, and a relatively small
7+
data structure overhead. Even if collection is enabled runtime all the
8+
locking is per-CPU and lookup is hashed.
89

910
timer_stats should be used by kernel and userspace developers to verify that
1011
their code does not make unduly use of timers. This helps to avoid unnecessary

‎kernel/time/timer_stats.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,15 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
236236
/*
237237
* It doesnt matter which lock we take:
238238
*/
239-
spinlock_t *lock = &per_cpu(lookup_lock, raw_smp_processor_id());
239+
spinlock_t *lock;
240240
struct entry *entry, input;
241241
unsigned long flags;
242242

243+
if (likely(!active))
244+
return;
245+
246+
lock = &per_cpu(lookup_lock, raw_smp_processor_id());
247+
243248
input.timer = timer;
244249
input.start_func = startf;
245250
input.expire_func = timerf;

‎lib/Kconfig.debug‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ config TIMER_STATS
126126
reprogrammed. The statistics can be read from /proc/timer_stats.
127127
The statistics collection is started by writing 1 to /proc/timer_stats,
128128
writing 0 stops it. This feature is useful to collect information
129-
about timer usage patterns in kernel and userspace.
129+
about timer usage patterns in kernel and userspace. This feature
130+
is lightweight if enabled in the kernel config but not activated
131+
(it defaults to deactivated on bootup and will only be activated
132+
if some application like powertop activates it explicitly).
130133

131134
config DEBUG_SLAB
132135
bool "Debug slab memory allocations"

0 commit comments

Comments
 (0)