[Intel-gfx] [PATCH] drm/i915/pmu: Avoid using globals for per-device state
Chris Wilson
chris at chris-wilson.co.uk
Wed Feb 19 15:25:43 UTC 2020
Quoting Michał Winiarski (2020-02-19 15:08:04)
> Attempting to bind / unbind module from devices where we have both
> integrated and discreete GPU handed by i915 may lead to interesting
> results where we're keeping per-device state in per-module globals.
>
> Fixes: 05488673a4d4 ("drm/i915/pmu: Support multiple GPUs")
> Signed-off-by: Michał Winiarski <michal.winiarski at intel.com>
> Cc: Chris Wilson <chris at chris-wilson.co.uk>
> Cc: Michal Wajdeczko <michal.wajdeczko at intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
> ---
> - i915_pmu_events_attr_group.attrs = create_event_attributes(pmu);
> - if (!i915_pmu_events_attr_group.attrs)
> + pmu->events_attr_group.name = "events";
> + pmu->events_attr_group.attrs = create_event_attributes(pmu);
> + if (!pmu->events_attr_group.attrs)
> goto err_name;
>
> - pmu->base.attr_groups = i915_pmu_attr_groups;
> + pmu->base.attr_groups = kcalloc(ARRAY_SIZE(attr_groups),
> + sizeof(*attr_groups),
> + GFP_KERNEL);
> + if (!pmu->base.attr_groups)
> + goto err_attr;
> + memcpy(attr_groups, pmu->base.attr_groups,
> + ARRAY_SIZE(attr_groups) * sizeof(*attr_groups));
kmemdup(attr_groups, sizeof(attr_groups));
> diff --git a/drivers/gpu/drm/i915/i915_pmu.h b/drivers/gpu/drm/i915/i915_pmu.h
> index 6c1647c5daf2..dc1361e8e27a 100644
> --- a/drivers/gpu/drm/i915/i915_pmu.h
> +++ b/drivers/gpu/drm/i915/i915_pmu.h
> @@ -42,6 +42,10 @@ struct i915_pmu {
> * @node: List node for CPU hotplug handling.
> */
> struct hlist_node node;
> + /**
> + * @cpuhp_slot: State for CPU hotplug handling.
> + */
> + enum cpuhp_state cpuhp_slot;
Perhaps struct {
struct hlist_node node;
enum cpuhp_state slot;
} cpuhp;
Fwiw, separate this into a separate patch, so we have one to deglobal
cpuhp and one for event groups.
Just grimacing over the wasted strings that we could intern for actual
attr.
But the essence of the patch is correct, since the events group is
created at runtime from probing the device, it is not global.
Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
-Chris
More information about the Intel-gfx
mailing list