Commit 0426c046 authored by Tvrtko Ursulin's avatar Tvrtko Ursulin

drm/i915/pmu: Only allow running on a single CPU

We do two things, both of which are purely to simplify and clarify the
implementation:

1.

Simplify the CPU online callback so it is more obvious that the purpose
there is to set a single CPU mask bit for the first CPU which comes
online. Using cpumask_weight for this reads more obvious than the trick
with cpumask_and_any.

2.

Modify the event init so that events can be created only on a single CPU.

This removes looking at the requested CPU thread siblings, and only allows
creating on the current active CPU.
Signed-off-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
Tested-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20171123123432.25035-2-tvrtko.ursulin@linux.intel.com
parent 141a0895
...@@ -344,7 +344,7 @@ static int i915_pmu_event_init(struct perf_event *event) ...@@ -344,7 +344,7 @@ static int i915_pmu_event_init(struct perf_event *event)
{ {
struct drm_i915_private *i915 = struct drm_i915_private *i915 =
container_of(event->pmu, typeof(*i915), pmu.base); container_of(event->pmu, typeof(*i915), pmu.base);
int cpu, ret; int ret;
if (event->attr.type != event->pmu->type) if (event->attr.type != event->pmu->type)
return -ENOENT; return -ENOENT;
...@@ -359,9 +359,8 @@ static int i915_pmu_event_init(struct perf_event *event) ...@@ -359,9 +359,8 @@ static int i915_pmu_event_init(struct perf_event *event)
if (event->cpu < 0) if (event->cpu < 0)
return -EINVAL; return -EINVAL;
cpu = cpumask_any_and(&i915_pmu_cpumask, /* only allow running on one cpu at a time */
topology_sibling_cpumask(event->cpu)); if (!cpumask_test_cpu(event->cpu, &i915_pmu_cpumask))
if (cpu >= nr_cpu_ids)
return -ENODEV; return -ENODEV;
if (is_engine_event(event)) { if (is_engine_event(event)) {
...@@ -396,7 +395,6 @@ static int i915_pmu_event_init(struct perf_event *event) ...@@ -396,7 +395,6 @@ static int i915_pmu_event_init(struct perf_event *event)
if (ret) if (ret)
return ret; return ret;
event->cpu = cpu;
if (!event->parent) if (!event->parent)
event->destroy = i915_pmu_event_destroy; event->destroy = i915_pmu_event_destroy;
...@@ -773,13 +771,11 @@ static const struct attribute_group *i915_pmu_attr_groups[] = { ...@@ -773,13 +771,11 @@ static const struct attribute_group *i915_pmu_attr_groups[] = {
static int i915_pmu_cpu_online(unsigned int cpu, struct hlist_node *node) static int i915_pmu_cpu_online(unsigned int cpu, struct hlist_node *node)
{ {
struct i915_pmu *pmu = hlist_entry_safe(node, typeof(*pmu), node); struct i915_pmu *pmu = hlist_entry_safe(node, typeof(*pmu), node);
unsigned int target;
GEM_BUG_ON(!pmu->base.event_init); GEM_BUG_ON(!pmu->base.event_init);
target = cpumask_any_and(&i915_pmu_cpumask, &i915_pmu_cpumask);
/* Select the first online CPU as a designated reader. */ /* Select the first online CPU as a designated reader. */
if (target >= nr_cpu_ids) if (!cpumask_weight(&i915_pmu_cpumask))
cpumask_set_cpu(cpu, &i915_pmu_cpumask); cpumask_set_cpu(cpu, &i915_pmu_cpumask);
return 0; return 0;
......
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