Re: perf_counters issue with PERF_SAMPLE_GROUP

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Peter Zijlstra
Date: Tuesday, August 11, 2009 - 9:05 am

On Tue, 2009-08-11 at 17:41 +0200, stephane eranian wrote:

Could have broken somewhere along the line, the group stuff doesn't get
tested a lot, if at all.

perf used to have some support for it, not sure what the current state
is.

You seem to have forgotten to append your test.c though :-)


Right, so something like the below, possibly complemented with having
PERF_COUNTER_IOC_RESET also reset the run-times?

---
 include/linux/perf_counter.h |    3 +++
 kernel/perf_counter.c        |   20 ++++++++++++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/include/linux/perf_counter.h b/include/linux/perf_counter.h
index 2b36afe..44a056b 100644
--- a/include/linux/perf_counter.h
+++ b/include/linux/perf_counter.h
@@ -365,10 +365,13 @@ enum perf_event_type {
 	 * 	{ u64			period;   } && PERF_SAMPLE_PERIOD
 	 *
 	 *	{ u64			nr;
+	 *	  { u64		time_enabled; } && PERF_FORMAT_ENABLED
+	 *	  { u64		time_running; } && PERF_FORMAT_RUNNING
 	 *	  { u64 id, val; }	cnt[nr];  } && PERF_SAMPLE_GROUP
 	 *
 	 *	{ u64			nr,
 	 *	  u64			ips[nr];  } && PERF_SAMPLE_CALLCHAIN
+	 *
 	 *	{ u32			size;
 	 *	  char                  data[size];}&& PERF_SAMPLE_RAW
 	 * };
diff --git a/kernel/perf_counter.c b/kernel/perf_counter.c
index e26d2fc..e61e701 100644
--- a/kernel/perf_counter.c
+++ b/kernel/perf_counter.c
@@ -2636,6 +2636,7 @@ void perf_counter_output(struct perf_counter *counter, int nmi,
 {
 	int ret;
 	u64 sample_type = counter->attr.sample_type;
+	u64 read_format = counter->attr.read_format;
 	struct perf_output_handle handle;
 	struct perf_event_header header;
 	u64 ip;
@@ -2703,6 +2704,10 @@ void perf_counter_output(struct perf_counter *counter, int nmi,
 	if (sample_type & PERF_SAMPLE_GROUP) {
 		header.size += sizeof(u64) +
 			counter->nr_siblings * sizeof(group_entry);
+		if (read_format & PERF_FORMAT_ENABLED)
+			header.size += sizeof(u64);
+		if (read_format & PERF_FORMAT_RUNNING)
+			header.size += sizeof(u64);
 	}
 
 	if (sample_type & PERF_SAMPLE_CALLCHAIN) {
@@ -2765,9 +2770,20 @@ void perf_counter_output(struct perf_counter *counter, int nmi,
 	 */
 	if (sample_type & PERF_SAMPLE_GROUP) {
 		struct perf_counter *leader, *sub;
-		u64 nr = counter->nr_siblings;
+		u64 val;
+
+		val = counter->nr_siblings;
+		perf_output_put(&handle, val);
 
-		perf_output_put(&handle, nr);
+		if (read_format & PERF_FORMAT_ENABLED) {
+			val = counter->total_time_enabled;
+			perf_output_put(&handle, val);
+		}
+
+		if (read_format & PERF_FORMAT_RUNNING) {
+			val = counter->total_time_running;
+			perf_output_put(&handle, val);
+		}
 
 		leader = counter->group_leader;
 		list_for_each_entry(sub, &leader->sibling_list, list_entry) {


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
perf_counters issue with PERF_SAMPLE_GROUP, stephane eranian, (Tue Aug 11, 8:41 am)
Re: perf_counters issue with PERF_SAMPLE_GROUP, Peter Zijlstra, (Tue Aug 11, 9:05 am)
Re: perf_counters issue with PERF_SAMPLE_GROUP, stephane eranian, (Tue Aug 11, 12:40 pm)
Re: perf_counters issue with PERF_SAMPLE_GROUP, Peter Zijlstra, (Tue Aug 11, 1:55 pm)
Re: perf_counters issue with PERF_SAMPLE_GROUP, stephane eranian, (Tue Aug 11, 2:08 pm)
Re: perf_counters issue with PERF_SAMPLE_GROUP, Peter Zijlstra, (Wed Aug 12, 1:32 am)
Re: perf_counters issue with PERF_SAMPLE_GROUP, Ingo Molnar, (Wed Aug 12, 2:02 am)
Re: perf_counters issue with PERF_SAMPLE_GROUP, stephane eranian, (Wed Aug 12, 5:22 am)
Re: perf_counters issue with PERF_SAMPLE_GROUP, stephane eranian, (Wed Aug 12, 1:54 pm)
Re: perf_counters issue with PERF_SAMPLE_GROUP, Ingo Molnar, (Thu Aug 13, 2:46 am)
Re: perf_counters issue with PERF_SAMPLE_GROUP, stephane eranian, (Thu Aug 13, 12:15 pm)
Re: perf_counters issue with PERF_SAMPLE_GROUP, Corey Ashford, (Thu Aug 13, 4:13 pm)
Re: perf_counters issue with PERF_SAMPLE_GROUP, Paul Mackerras, (Thu Aug 13, 4:49 pm)