Skip to content

Commit a644fde

Browse files
tursulinunerlige
authored andcommitted
drm/i915/pmu: Change bitmask of enabled events to u32
Having it as u64 was a confusing (but harmless) mistake. Also add some asserts to make sure the internal field does not overflow in the future. v2: Fix WARN_ON firing for INTERRUPT event (Umesh) Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Signed-off-by: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com> Reviewed-by: Ashutosh Dixit <ashutosh.dixit@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20230519154946.3751971-2-umesh.nerlige.ramappa@intel.com
1 parent 2555349 commit a644fde

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

drivers/gpu/drm/i915/i915_pmu.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static u8 engine_event_instance(struct perf_event *event)
5050
return (event->attr.config >> I915_PMU_SAMPLE_BITS) & 0xff;
5151
}
5252

53-
static bool is_engine_config(u64 config)
53+
static bool is_engine_config(const u64 config)
5454
{
5555
return config < __I915_PMU_OTHER(0);
5656
}
@@ -88,9 +88,20 @@ static unsigned int config_bit(const u64 config)
8888
return other_bit(config);
8989
}
9090

91-
static u64 config_mask(u64 config)
91+
static u32 config_mask(const u64 config)
9292
{
93-
return BIT_ULL(config_bit(config));
93+
unsigned int bit = config_bit(config);
94+
95+
if (__builtin_constant_p(config))
96+
BUILD_BUG_ON(bit >
97+
BITS_PER_TYPE(typeof_member(struct i915_pmu,
98+
enable)) - 1);
99+
else
100+
WARN_ON_ONCE(bit >
101+
BITS_PER_TYPE(typeof_member(struct i915_pmu,
102+
enable)) - 1);
103+
104+
return BIT(config_bit(config));
94105
}
95106

96107
static bool is_engine_event(struct perf_event *event)
@@ -633,11 +644,10 @@ static void i915_pmu_enable(struct perf_event *event)
633644
{
634645
struct drm_i915_private *i915 =
635646
container_of(event->pmu, typeof(*i915), pmu.base);
647+
const unsigned int bit = event_bit(event);
636648
struct i915_pmu *pmu = &i915->pmu;
637649
unsigned long flags;
638-
unsigned int bit;
639650

640-
bit = event_bit(event);
641651
if (bit == -1)
642652
goto update;
643653

@@ -651,7 +661,7 @@ static void i915_pmu_enable(struct perf_event *event)
651661
GEM_BUG_ON(bit >= ARRAY_SIZE(pmu->enable_count));
652662
GEM_BUG_ON(pmu->enable_count[bit] == ~0);
653663

654-
pmu->enable |= BIT_ULL(bit);
664+
pmu->enable |= BIT(bit);
655665
pmu->enable_count[bit]++;
656666

657667
/*
@@ -698,7 +708,7 @@ static void i915_pmu_disable(struct perf_event *event)
698708
{
699709
struct drm_i915_private *i915 =
700710
container_of(event->pmu, typeof(*i915), pmu.base);
701-
unsigned int bit = event_bit(event);
711+
const unsigned int bit = event_bit(event);
702712
struct i915_pmu *pmu = &i915->pmu;
703713
unsigned long flags;
704714

@@ -734,7 +744,7 @@ static void i915_pmu_disable(struct perf_event *event)
734744
* bitmask when the last listener on an event goes away.
735745
*/
736746
if (--pmu->enable_count[bit] == 0) {
737-
pmu->enable &= ~BIT_ULL(bit);
747+
pmu->enable &= ~BIT(bit);
738748
pmu->timer_enabled &= pmu_needs_timer(pmu, true);
739749
}
740750

0 commit comments

Comments
 (0)