perfcounters: implement "counter inheritance"
authorIngo Molnar <mingo@elte.hu>
Fri, 12 Dec 2008 12:49:45 +0000 (13:49 +0100)
committerIngo Molnar <mingo@elte.hu>
Sun, 14 Dec 2008 19:30:49 +0000 (20:30 +0100)
commit9b51f66dcb09ac5eb6bc68fc111d5c7a1e0131d6
treef7b3482ae284c214119efe309e356fb84de126bb
parentee06094f8279e1312fc0a31591320cc7b6f0ab1e
perfcounters: implement "counter inheritance"

Impact: implement new performance feature

Counter inheritance can be used to run performance counters in a workload,
transparently - and pipe back the counter results to the parent counter.

Inheritance for performance counters works the following way: when creating
a counter it can be marked with the .inherit=1 flag. Such counters are then
'inherited' by all child tasks (be they fork()-ed or clone()-ed). These
counters get inherited through exec() boundaries as well (except through
setuid boundaries).

The counter values get added back to the parent counter(s) when the child
task(s) exit - much like stime/utime statistics are gathered. So inherited
counters are ideal to gather summary statistics about an application's
behavior via shell commands, without having to modify that application.

The timec.c command utilizes counter inheritance:

  http://redhat.com/~mingo/perfcounters/timec.c

Sample output:

   $ ./timec -e 1 -e 3 -e 5 ls -lR /usr/include/ >/dev/null

   Performance counter stats for 'ls':

           163516953 instructions
                2295 cache-misses
             2855182 branch-misses

Signed-off-by: Ingo Molnar <mingo@elte.hu>
include/linux/perf_counter.h
kernel/exit.c
kernel/perf_counter.c