From 5f4e14ad324a032a53c4d6ac6c773e3a9efad7f1 Mon Sep 17 00:00:00 2001 From: Junyi Ye <294572668@qq.com> Date: Sat, 25 May 2024 09:18:55 +0800 Subject: [PATCH] Check core event during pmu event list using perf_event_open. --- pmu/pfm/core.cpp | 16 ++++++++++++++++ pmu/pfm/pfm_name.cpp | 2 ++ pmu/pfm/pfm_name.h | 2 ++ pmu/pmu_event_list.cpp | 22 ++++++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/pmu/pfm/core.cpp b/pmu/pfm/core.cpp index 20be590..d4edc60 100644 --- a/pmu/pfm/core.cpp +++ b/pmu/pfm/core.cpp @@ -111,6 +111,22 @@ const std::unordered_map HIP_A_CORE_PMU_MA KUNPENG_PMU::COMMON::L1_DCACHE_LOADS } }, + { + KUNPENG_PMU::COMMON::L1_DCACHE_STORE_MISSES, + { + PERF_TYPE_HW_CACHE, + 0x10100, + KUNPENG_PMU::COMMON::L1_DCACHE_STORE_MISSES + } + }, + { + KUNPENG_PMU::COMMON::L1_DCACHE_STORES, + { + PERF_TYPE_HW_CACHE, + 0x100, + KUNPENG_PMU::COMMON::L1_DCACHE_STORES + } + }, { KUNPENG_PMU::COMMON::IDLE_CYCLES_BACKEND, { diff --git a/pmu/pfm/pfm_name.cpp b/pmu/pfm/pfm_name.cpp index 1b66f8b..179dceb 100644 --- a/pmu/pfm/pfm_name.cpp +++ b/pmu/pfm/pfm_name.cpp @@ -32,6 +32,8 @@ const char* KUNPENG_PMU::COMMON::STALLED_CYCLES_BACKEND = "stalled-cycles-backen const char* KUNPENG_PMU::COMMON::STALLED_CYCLES_FRONTEND = "stalled-cycles-frontend"; const char* KUNPENG_PMU::COMMON::L1_DCACHE_LOAD_MISSES = "L1-dcache-load-misses"; const char* KUNPENG_PMU::COMMON::L1_DCACHE_LOADS = "L1-dcache-loads"; +const char* KUNPENG_PMU::COMMON::L1_DCACHE_STORE_MISSES = "L1-dcache-store-misses"; +const char* KUNPENG_PMU::COMMON::L1_DCACHE_STORES = "L1-dcache-stores"; const char* KUNPENG_PMU::COMMON::IDLE_CYCLES_BACKEND = "idle-cycles-backend"; const char* KUNPENG_PMU::COMMON::L1_ICACHE_LOAD_MISSES = "L1-icache-load-misses"; const char* KUNPENG_PMU::COMMON::IDLE_CYCLES_FRONTEND = "idle-cycles-frontend"; diff --git a/pmu/pfm/pfm_name.h b/pmu/pfm/pfm_name.h index bd4ae04..740e59f 100644 --- a/pmu/pfm/pfm_name.h +++ b/pmu/pfm/pfm_name.h @@ -32,6 +32,8 @@ extern const char* STALLED_CYCLES_BACKEND; extern const char* STALLED_CYCLES_FRONTEND; extern const char* L1_DCACHE_LOAD_MISSES; extern const char* L1_DCACHE_LOADS; +extern const char* L1_DCACHE_STORE_MISSES; +extern const char* L1_DCACHE_STORES; extern const char* IDLE_CYCLES_BACKEND; extern const char* L1_ICACHE_LOAD_MISSES; extern const char* IDLE_CYCLES_FRONTEND; diff --git a/pmu/pmu_event_list.cpp b/pmu/pmu_event_list.cpp index 0f6bb80..a90861c 100644 --- a/pmu/pmu_event_list.cpp +++ b/pmu/pmu_event_list.cpp @@ -21,6 +21,7 @@ #include #include #include "core.h" +#include "evt.h" #include "pcerr.h" #include "pmu.h" #include "common.h" @@ -92,6 +93,24 @@ static void GetTraceSubFolder(const string& devName, vector& eventL 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) { + return false; + } + close(fd); + return true; +} + const char** QueryCoreEvent(unsigned *numEvt) { if (!coreEventList.empty()) { @@ -101,6 +120,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