From 0c9800b205b0cbdc4aff93986f3e30755d1f18ea Mon Sep 17 00:00:00 2001 From: wuying39 Date: Mon, 24 Nov 2025 20:13:26 +0800 Subject: [PATCH] add min_latency verification in SPE mode && revise cache collect output --- include/pcerrc.h | 1 + pmu/pmu.cpp | 4 ++++ pmu/spe.cpp | 1 - python/modules/kperf/perror.py | 1 + tools/cache_collect/collect_args.cpp | 8 ++++---- util/pcerr.cpp | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/pcerrc.h b/include/pcerrc.h index a116612..e5536a1 100644 --- a/include/pcerrc.h +++ b/include/pcerrc.h @@ -127,6 +127,7 @@ extern "C" { #define LIBPERF_ERR_INVALID_BPF_PARAM 1080 #define LIBPERF_ERR_NULL_POINTER 1081 #define LIBPERF_ERR_BUFFER_CORRUPTED 1082 +#define LIBPERF_ERR_INVALID_MIN_LATENCY 1083 #define UNKNOWN_ERROR 9999 diff --git a/pmu/pmu.cpp b/pmu/pmu.cpp index 7d234f2..394e509 100644 --- a/pmu/pmu.cpp +++ b/pmu/pmu.cpp @@ -257,6 +257,10 @@ 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 (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; + } return SUCCESS; } diff --git a/pmu/spe.cpp b/pmu/spe.cpp index 9da1c12..1617439 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; diff --git a/python/modules/kperf/perror.py b/python/modules/kperf/perror.py index f0dec93..5799dba 100644 --- a/python/modules/kperf/perror.py +++ b/python/modules/kperf/perror.py @@ -126,6 +126,7 @@ class Error: LIBPERF_ERR_INVALID_BPF_PARAM = 1080 LIBPERF_ERR_NULL_POINTER = 1081 LIBPERF_ERR_BUFFER_CORRUPTED = 1082 + LIBPERF_ERR_INVALID_MIN_LATENCY = 1083 UNKNOWN_ERROR = 9999 diff --git a/tools/cache_collect/collect_args.cpp b/tools/cache_collect/collect_args.cpp index 37ac8d1..eebd8c0 100644 --- a/tools/cache_collect/collect_args.cpp +++ b/tools/cache_collect/collect_args.cpp @@ -159,7 +159,7 @@ bool CollectArgs::ParsePidList() pid = std::stoi(pidStr); } catch (const std::invalid_argument& e) { std::cerr << "Error: failed to parse pid from input parameter: '" << pidStr - << "' .Reason: " << e.what() << ". Expected an integer.\n"; + << "'. Reason: " << e.what() << ". Expected an integer.\n"; return false; } pids.push_back(pid); @@ -169,7 +169,7 @@ bool CollectArgs::ParsePidList() void CollectArgs::printUsage() { - std::cerr << "Usage: cache_collect --pid/-p [options]\n\n"; + std::cerr << "Usage: ./cache_collect --pid/-p [options]\n\n"; std::cerr << "Required:\n"; std::cerr << " --pid/-p : Target process ID(s). Multiple IDs can be separated by ','\n"; @@ -182,6 +182,6 @@ void CollectArgs::printUsage() std::cerr << " --bolt/-b