diff options
author | Vineet Gupta <vgupta@synopsys.com> | 2015-10-08 12:47:48 -0400 |
---|---|---|
committer | Vineet Gupta <vgupta@synopsys.com> | 2017-11-21 18:20:55 -0500 |
commit | 5b9027d6d044d4917992119d184ab0bb616489cc (patch) | |
tree | 80b05c4295140b9d1828c1fb0475c3d5bd04f214 | |
parent | 4d431290402c8d867af7ba45ee75407d68748c4a (diff) |
ARCv2: perf: optimize given that num counters <= 32
use ffz primitive which maps to ARCv2 instruction, vs. non atomic
__test_and_set_bit
It is unlikely if we will even have more than 32 counters, but still add
a BUILD_BUG to catch that
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
-rw-r--r-- | arch/arc/kernel/perf_event.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/arch/arc/kernel/perf_event.c b/arch/arc/kernel/perf_event.c index 0eaa132a2c90..8aec462d90fb 100644 --- a/arch/arc/kernel/perf_event.c +++ b/arch/arc/kernel/perf_event.c | |||
@@ -336,15 +336,12 @@ static int arc_pmu_add(struct perf_event *event, int flags) | |||
336 | struct hw_perf_event *hwc = &event->hw; | 336 | struct hw_perf_event *hwc = &event->hw; |
337 | int idx = hwc->idx; | 337 | int idx = hwc->idx; |
338 | 338 | ||
339 | if (__test_and_set_bit(idx, pmu_cpu->used_mask)) { | 339 | idx = ffz(pmu_cpu->used_mask[0]); |
340 | idx = find_first_zero_bit(pmu_cpu->used_mask, | 340 | if (idx == arc_pmu->n_counters) |
341 | arc_pmu->n_counters); | 341 | return -EAGAIN; |
342 | if (idx == arc_pmu->n_counters) | 342 | |
343 | return -EAGAIN; | 343 | __set_bit(idx, pmu_cpu->used_mask); |
344 | 344 | hwc->idx = idx; | |
345 | __set_bit(idx, pmu_cpu->used_mask); | ||
346 | hwc->idx = idx; | ||
347 | } | ||
348 | 345 | ||
349 | write_aux_reg(ARC_REG_PCT_INDEX, idx); | 346 | write_aux_reg(ARC_REG_PCT_INDEX, idx); |
350 | 347 | ||
@@ -465,6 +462,7 @@ static int arc_pmu_device_probe(struct platform_device *pdev) | |||
465 | pr_err("This core does not have performance counters!\n"); | 462 | pr_err("This core does not have performance counters!\n"); |
466 | return -ENODEV; | 463 | return -ENODEV; |
467 | } | 464 | } |
465 | BUILD_BUG_ON(ARC_PERF_MAX_COUNTERS > 32); | ||
468 | BUG_ON(pct_bcr.c > ARC_PERF_MAX_COUNTERS); | 466 | BUG_ON(pct_bcr.c > ARC_PERF_MAX_COUNTERS); |
469 | 467 | ||
470 | READ_BCR(ARC_REG_CC_BUILD, cc_bcr); | 468 | READ_BCR(ARC_REG_CC_BUILD, cc_bcr); |