From f3f248d46b0d41bd258ff666c512baa1e88468b0 Mon Sep 17 00:00:00 2001 From: wuying39 Date: Tue, 2 Dec 2025 16:13:23 +0800 Subject: [PATCH] add event number verification in group mode --- pmu/pmu.cpp | 27 ++++++++++++++++++++++++++- pmu/spe.cpp | 1 - 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pmu/pmu.cpp b/pmu/pmu.cpp index 6fd27d4..3ce7ee4 100644 --- a/pmu/pmu.cpp +++ b/pmu/pmu.cpp @@ -38,6 +38,8 @@ using namespace std; static unordered_map runningStatus; static SafeHandler pdMutex; static pair uncoreEventPair; +static unordered_map groupEvtCapacity = {{HIPA, 13}, {HIPB, 9}, {HIPC, 9}, + {HIPF, 9}, {HIPE, 9}, {HIPG, 6}}; #define REQUEST_USER_ACCESS 0x2 #define HARD_WARE_METRIC 0x1 @@ -123,6 +125,29 @@ static int CheckGroupList(unsigned numEvtAttr, struct EvtAttr *evtAttr) New(LIBPERF_ERR_INVALID_EVTATTR, "Invalid evtAttr list: numEvtAttr is greater than 0, but evtAttr is null."); return LIBPERF_ERR_INVALID_EVTATTR; } + + // check whether the number of events in each group exceeds the PMU limit + CHIP_TYPE chipType = GetCpuType(); + int maxEvt; + auto findType = groupEvtCapacity.find(chipType); + if (findType == groupEvtCapacity.end()) { + return SUCCESS; + } else { + maxEvt = findType->second; + } + unordered_map cntEvtMap; + for (size_t i = 0; i < numEvtAttr; i++) { + if (evtAttr[i].groupId != -1) { + cntEvtMap[evtAttr[i].groupId]++; + } + } + for (const auto& evt : cntEvtMap) { + if (evt.second > maxEvt) { + New(LIBPERF_ERR_INVALID_EVTATTR, "Invalid evtAttr list: the number of events in group " + to_string(evt.first) + + " is: " + to_string(evt.second) + ", which exceeds the PMU collection limit: " + to_string(maxEvt)); + return LIBPERF_ERR_INVALID_EVTATTR; + } + } return SUCCESS; } @@ -287,7 +312,7 @@ static int CheckCollectTypeConfig(enum PmuTaskType collectType, struct PmuAttr * New(LIBPERF_ERR_INVALID_CGROUP_LIST, "SPE mode only support one cgroup"); return LIBPERF_ERR_INVALID_CGROUP_LIST; } - if (attr->minLatency > 4095 || attr->minLatency < 0) { + if (attr->minLatency > 4095) { New(LIBPERF_ERR_INVALID_MIN_LATENCY, "Invalid min_latency: value must be between 0 and 4095"); return LIBPERF_ERR_INVALID_MIN_LATENCY; } diff --git a/pmu/spe.cpp b/pmu/spe.cpp index ca4f9ed..6cbc359 100644 --- a/pmu/spe.cpp +++ b/pmu/spe.cpp @@ -58,7 +58,6 @@ static int OpenSpeEvent(PmuEvt *pmuAttr, int cpu) attr.config2 = pmuAttr->config2; /* min_latency */ attr.exclude_guest = 1; attr.disabled = 1; - attr.freq = pmuAttr->useFreq; attr.sample_period = pmuAttr->period; attr.sample_type = PERF_SAMPLE_TID; attr.sample_id_all = 1; -- Gitee