Commit 7da37705 authored by Junhao He's avatar Junhao He Committed by Will Deacon

drivers/perf: hisi_pcie: Merge find_related_event() and get_event_idx()

The function xxx_find_related_event() scan all working events to find
related events. During this process, we also can find the idle counters.
If not found related events, return the first idle counter to simplify
the code.
Signed-off-by: default avatarJunhao He <hejunhao3@huawei.com>
Signed-off-by: default avatarYicong Yang <yangyicong@hisilicon.com>
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/20240223103359.18669-8-yangyicong@huawei.comSigned-off-by: default avatarWill Deacon <will@kernel.org>
parent 2fbf96ed
...@@ -398,16 +398,24 @@ static u64 hisi_pcie_pmu_read_counter(struct perf_event *event) ...@@ -398,16 +398,24 @@ static u64 hisi_pcie_pmu_read_counter(struct perf_event *event)
return hisi_pcie_pmu_readq(pcie_pmu, event->hw.event_base, idx); return hisi_pcie_pmu_readq(pcie_pmu, event->hw.event_base, idx);
} }
static int hisi_pcie_pmu_find_related_event(struct hisi_pcie_pmu *pcie_pmu, /*
* Check all work events, if a relevant event is found then we return it
* first, otherwise return the first idle counter (need to reset).
*/
static int hisi_pcie_pmu_get_event_idx(struct hisi_pcie_pmu *pcie_pmu,
struct perf_event *event) struct perf_event *event)
{ {
int first_idle = -EAGAIN;
struct perf_event *sibling; struct perf_event *sibling;
int idx; int idx;
for (idx = 0; idx < HISI_PCIE_MAX_COUNTERS; idx++) { for (idx = 0; idx < HISI_PCIE_MAX_COUNTERS; idx++) {
sibling = pcie_pmu->hw_events[idx]; sibling = pcie_pmu->hw_events[idx];
if (!sibling) if (!sibling) {
if (first_idle == -EAGAIN)
first_idle = idx;
continue; continue;
}
/* Related events must be used in group */ /* Related events must be used in group */
if (hisi_pcie_pmu_cmp_event(sibling, event) && if (hisi_pcie_pmu_cmp_event(sibling, event) &&
...@@ -415,19 +423,7 @@ static int hisi_pcie_pmu_find_related_event(struct hisi_pcie_pmu *pcie_pmu, ...@@ -415,19 +423,7 @@ static int hisi_pcie_pmu_find_related_event(struct hisi_pcie_pmu *pcie_pmu,
return idx; return idx;
} }
return idx; return first_idle;
}
static int hisi_pcie_pmu_get_event_idx(struct hisi_pcie_pmu *pcie_pmu)
{
int idx;
for (idx = 0; idx < HISI_PCIE_MAX_COUNTERS; idx++) {
if (!pcie_pmu->hw_events[idx])
return idx;
}
return -EINVAL;
} }
static void hisi_pcie_pmu_event_update(struct perf_event *event) static void hisi_pcie_pmu_event_update(struct perf_event *event)
...@@ -553,27 +549,18 @@ static int hisi_pcie_pmu_add(struct perf_event *event, int flags) ...@@ -553,27 +549,18 @@ static int hisi_pcie_pmu_add(struct perf_event *event, int flags)
hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE; hwc->state = PERF_HES_STOPPED | PERF_HES_UPTODATE;
/* Check all working events to find a related event. */ idx = hisi_pcie_pmu_get_event_idx(pcie_pmu, event);
idx = hisi_pcie_pmu_find_related_event(pcie_pmu, event);
if (idx < 0) if (idx < 0)
return idx; return idx;
/* Current event shares an enabled counter with the related event */
if (idx < HISI_PCIE_MAX_COUNTERS) {
hwc->idx = idx; hwc->idx = idx;
goto start_count;
}
idx = hisi_pcie_pmu_get_event_idx(pcie_pmu); /* No enabled counter found with related event, reset it */
if (idx < 0) if (!pcie_pmu->hw_events[idx]) {
return idx;
hwc->idx = idx;
pcie_pmu->hw_events[idx] = event;
/* Reset Counter to avoid previous statistic interference. */
hisi_pcie_pmu_reset_counter(pcie_pmu, idx); hisi_pcie_pmu_reset_counter(pcie_pmu, idx);
pcie_pmu->hw_events[idx] = event;
}
start_count:
if (flags & PERF_EF_START) if (flags & PERF_EF_START)
hisi_pcie_pmu_start(event, PERF_EF_RELOAD); hisi_pcie_pmu_start(event, PERF_EF_RELOAD);
......
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