From dd19ffd03b27539e21c411c826e1fba634682fcd Mon Sep 17 00:00:00 2001 From: wuying39 Date: Mon, 1 Dec 2025 20:22:14 +0800 Subject: [PATCH] add evtFilter and dataFilter verification in SPE mode --- include/pcerrc.h | 2 ++ pmu/pmu.cpp | 63 ++++++++++++++++++++++++++++------ python/modules/kperf/perror.py | 2 ++ 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/include/pcerrc.h b/include/pcerrc.h index 71efd6e..47e797b 100644 --- a/include/pcerrc.h +++ b/include/pcerrc.h @@ -130,6 +130,8 @@ extern "C" { #define LIBPERF_ERR_NOT_SUPPORT_HWMETRIC 1083 #define LIBPERF_ERR_INVALID_HWMETRIC_ATTR 1084 #define LIBPERF_ERR_INVALID_MIN_LATENCY 1085 +#define LIBPERF_ERR_INVALID_EVT_FILTER 1086 +#define LIBPERF_ERR_INVALID_DATA_FILTER 1087 #define UNKNOWN_ERROR 9999 diff --git a/pmu/pmu.cpp b/pmu/pmu.cpp index 0a76a2f..6fd27d4 100644 --- a/pmu/pmu.cpp +++ b/pmu/pmu.cpp @@ -204,6 +204,36 @@ static int CheckCgroupNameList(unsigned numCgroup, char** cgroupName) return SUCCESS; } +static bool CheckValidSpeEvtFilter(SpeEventFilter val) { + switch (val) { + case SPE_EVENT_NONE: + case SPE_EVENT_RETIRED: + case SPE_EVENT_L1DMISS: + case SPE_EVENT_TLB_WALK: + case SPE_EVENT_MISPREDICTED: + return true; + default: + return false; + } +} + +static bool CheckValidSpeFilter(SpeFilter val) { + switch (val) { + case SPE_FILTER_NONE: + case TS_ENABLE: + case PA_ENABLE: + case PCT_ENABLE: + case JITTER: + case BRANCH_FILTER: + case LOAD_FILTER: + case STORE_FILTER: + case SPE_DATA_ALL: + return true; + default: + return false; + } +} + static int CheckCollectTypeConfig(enum PmuTaskType collectType, struct PmuAttr *attr) { if (collectType < 0 || collectType >= MAX_TASK_TYPE) { @@ -243,21 +273,32 @@ static int CheckCollectTypeConfig(enum PmuTaskType collectType, struct PmuAttr * } } } - if (collectType == SPE_SAMPLING && attr->evtAttr != nullptr) { - New(LIBPERF_ERR_INVALID_GROUP_SPE); - return LIBPERF_ERR_INVALID_GROUP_SPE; - } if (attr->cgroupNameList != nullptr && attr->pidList != nullptr) { New(LIBPERF_ERR_INVALID_CGROUP_LIST, "Cannot specify both cgroup and pid. Please use only one."); return LIBPERF_ERR_INVALID_CGROUP_LIST; } - if (collectType == SPE_SAMPLING && attr->numCgroup > 1) { - New(LIBPERF_ERR_INVALID_CGROUP_LIST, "SPE mode only support one cgroup"); - return LIBPERF_ERR_INVALID_CGROUP_LIST; - } - if (collectType == SPE_SAMPLING && (attr->minLatency > 4095 || attr->minLatency < 0)) { - New(LIBPERF_ERR_INVALID_MIN_LATENCY, "Invalid min_latency: value must be between 0 and 4095"); - return LIBPERF_ERR_INVALID_MIN_LATENCY; + + if (collectType == SPE_SAMPLING) { + if( attr->evtAttr != nullptr) { + New(LIBPERF_ERR_INVALID_GROUP_SPE); + return LIBPERF_ERR_INVALID_GROUP_SPE; + } + if (attr->numCgroup > 1) { + 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) { + New(LIBPERF_ERR_INVALID_MIN_LATENCY, "Invalid min_latency: value must be between 0 and 4095"); + return LIBPERF_ERR_INVALID_MIN_LATENCY; + } + if (!CheckValidSpeEvtFilter(attr->evFilter)) { + New(LIBPERF_ERR_INVALID_EVT_FILTER, "Invalid evt filter in SPE mode"); + return LIBPERF_ERR_INVALID_EVT_FILTER; + } + if (!CheckValidSpeFilter(attr->dataFilter)) { + New(LIBPERF_ERR_INVALID_DATA_FILTER, "Invalid data filter in SPE mode"); + return LIBPERF_ERR_INVALID_DATA_FILTER; + } } return SUCCESS; } diff --git a/python/modules/kperf/perror.py b/python/modules/kperf/perror.py index 8c29f5a..fa41a4d 100644 --- a/python/modules/kperf/perror.py +++ b/python/modules/kperf/perror.py @@ -129,6 +129,8 @@ class Error: LIBPERF_ERR_NOT_SUPPORT_HWMETRIC = 1083 LIBPERF_ERR_INVALID_HWMETRIC_ATTR = 1084 LIBPERF_ERR_INVALID_MIN_LATENCY = 1085 + LIBPERF_ERR_INVALID_EVT_FILTER = 1086 + LIBPERF_ERR_INVALID_DATA_FILTER = 1087 UNKNOWN_ERROR = 9999 -- Gitee