diff mbox

[i-g-t] lib/igt_perf: Find active perf CPU

Message ID 20180221102957.6334-1-tvrtko.ursulin@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Tvrtko Ursulin Feb. 21, 2018, 10:29 a.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Instead of assuming PMU runs on CPU0, try all possible CPUs if that is not
the case. This makes the callers handle fallout from broken tests better,
as well as sysadmin interventions where callers are not tests.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/igt_perf.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Chris Wilson Feb. 21, 2018, 10:34 a.m. UTC | #1
Quoting Tvrtko Ursulin (2018-02-21 10:29:57)
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> Instead of assuming PMU runs on CPU0, try all possible CPUs if that is not
> the case. This makes the callers handle fallout from broken tests better,
> as well as sysadmin interventions where callers are not tests.
> 
> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>

As a bonus it also helps document the perf_open() call.
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

Are we not allowed to pass cpu=-1 for any/all cpus?
-Chris
Tvrtko Ursulin Feb. 21, 2018, 10:45 a.m. UTC | #2
On 21/02/2018 10:34, Chris Wilson wrote:
> Quoting Tvrtko Ursulin (2018-02-21 10:29:57)
>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>
>> Instead of assuming PMU runs on CPU0, try all possible CPUs if that is not
>> the case. This makes the callers handle fallout from broken tests better,
>> as well as sysadmin interventions where callers are not tests.
>>
>> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> 
> As a bonus it also helps document the perf_open() call.
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

Thanks!

> Are we not allowed to pass cpu=-1 for any/all cpus?

No, that is documented to return -EINVAL from perf core. I guess it 
comes from the per-CPU nature of perf.

Regards,

Tvrtko
diff mbox

Patch

diff --git a/lib/igt_perf.c b/lib/igt_perf.c
index 0221461e918f..99d82ea51c9b 100644
--- a/lib/igt_perf.c
+++ b/lib/igt_perf.c
@@ -4,6 +4,7 @@ 
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <sys/sysinfo.h>
 
 #include "igt_perf.h"
 
@@ -31,6 +32,8 @@  static int
 _perf_open(uint64_t type, uint64_t config, int group, uint64_t format)
 {
 	struct perf_event_attr attr = { };
+	int nr_cpus = get_nprocs_conf();
+	int cpu = 0, ret;
 
 	attr.type = type;
 	if (attr.type == 0)
@@ -42,7 +45,11 @@  _perf_open(uint64_t type, uint64_t config, int group, uint64_t format)
 	attr.read_format = format;
 	attr.config = config;
 
-	return perf_event_open(&attr, -1, 0, group, 0);
+	do {
+		ret = perf_event_open(&attr, -1, cpu++, group, 0);
+	} while ((ret < 0 && errno == EINVAL) && (cpu < nr_cpus));
+
+	return ret;
 }
 
 int perf_i915_open(uint64_t config)