From c03aa5026ac561f3b50b4b24903ee2d0bac8520e Mon Sep 17 00:00:00 2001 From: "lijindong (C)" <2220386943@qq.com> Date: Fri, 12 Sep 2025 12:45:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E8=83=BD=E8=8E=B7=E5=8F=96=E5=88=B0=E6=9C=AA=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=9A=84=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pmu/pmu_event_list.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pmu/pmu_event_list.cpp b/pmu/pmu_event_list.cpp index a1577cc..f5c7cb9 100644 --- a/pmu/pmu_event_list.cpp +++ b/pmu/pmu_event_list.cpp @@ -100,6 +100,24 @@ static void GetTraceSubFolder(const std::string& traceFolder, const string& devN closedir(dir); } +static bool PerfEventSupported(__u64 type, __u64 config) +{ + perf_event_attr attr{}; + memset(&attr, 0, sizeof(attr)); + attr.size = sizeof(struct perf_event_attr); + attr.type = type; + attr.config = config; + attr.disabled = 1; + attr.inherit = 1; + attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING | PERF_FORMAT_ID; + int fd = KUNPENG_PMU::PerfEventOpen(&attr, -1, 0, -1, 0); + if (fd < 0 && errno == ENOENT) { + return false; + } + close(fd); + return true; +} + const char** QueryCoreEvent(unsigned *numEvt) { if (!coreEventList.empty()) { @@ -109,6 +127,9 @@ const char** QueryCoreEvent(unsigned *numEvt) auto coreEventMap = KUNPENG_PMU::CORE_EVENT_MAP.at(GetCpuType()); for (auto& pair : coreEventMap) { auto eventName = pair.first; + if (!PerfEventSupported(pair.second.type, pair.second.config)) { + continue; + } char* eventNameCopy = new char[eventName.length() + 1]; strcpy(eventNameCopy, eventName.c_str()); coreEventList.emplace_back(eventNameCopy); -- Gitee