Commit e53c0994 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

perf_counter: Collapse inherit on read()

Currently the counter value returned by read() is the value of
the parent counter, to which child counters are only fed back
on child exit.

Thus read() can return rather erratic (and meaningless) numbers
depending on the state of the child processes.

Change this by always iterating the full child hierarchy on
read() and sum all counters.
Suggested-by: default avatarCorey Ashford <cjashfor@linux.vnet.ibm.com>
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 470a1396
...@@ -1688,6 +1688,18 @@ static int perf_release(struct inode *inode, struct file *file) ...@@ -1688,6 +1688,18 @@ static int perf_release(struct inode *inode, struct file *file)
return 0; return 0;
} }
static u64 perf_counter_read_tree(struct perf_counter *counter)
{
struct perf_counter *child;
u64 total = 0;
total += perf_counter_read(counter);
list_for_each_entry(child, &counter->child_list, child_list)
total += perf_counter_read(child);
return total;
}
/* /*
* Read the performance counter - simple non blocking version for now * Read the performance counter - simple non blocking version for now
*/ */
...@@ -1707,7 +1719,7 @@ perf_read_hw(struct perf_counter *counter, char __user *buf, size_t count) ...@@ -1707,7 +1719,7 @@ perf_read_hw(struct perf_counter *counter, char __user *buf, size_t count)
WARN_ON_ONCE(counter->ctx->parent_ctx); WARN_ON_ONCE(counter->ctx->parent_ctx);
mutex_lock(&counter->child_mutex); mutex_lock(&counter->child_mutex);
values[0] = perf_counter_read(counter); values[0] = perf_counter_read_tree(counter);
n = 1; n = 1;
if (counter->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) if (counter->attr.read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
values[n++] = counter->total_time_enabled + values[n++] = counter->total_time_enabled +
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment