From 1d5ffdeb7332c98cdfbf305a66b4ac33a4742450 Mon Sep 17 00:00:00 2001 From: doublefree Date: Tue, 15 Jul 2025 15:40:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=B0=91=E9=87=87=E6=A0=B7=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E6=97=B6=E5=86=97=E4=BD=99=E7=9A=84mmap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pmu/evt_list.cpp | 4 +-- pmu/evt_list.h | 2 +- pmu/pmu_list.cpp | 76 +++++------------------------------------------- pmu/pmu_list.h | 4 +-- 4 files changed, 13 insertions(+), 73 deletions(-) diff --git a/pmu/evt_list.cpp b/pmu/evt_list.cpp index 63a8be1..3f2e6e8 100644 --- a/pmu/evt_list.cpp +++ b/pmu/evt_list.cpp @@ -66,7 +66,7 @@ int KUNPENG_PMU::EvtList::CollectorXYArrayDoTask(std::vector evtLeader, bool isMemoryEnough) +int KUNPENG_PMU::EvtList::Init(const bool groupEnable, const std::shared_ptr evtLeader) { // Init process map. for (auto& proc: pidList) { @@ -84,7 +84,7 @@ int KUNPENG_PMU::EvtList::Init(const bool groupEnable, const std::shared_ptr 0 && !evtVec.empty()) { + if (col > 0 && !evtVec.empty()) { resetOutPutFd = evtVec[0]->GetFd(); } perfEvt->SetSymbolMode(symMode); diff --git a/pmu/evt_list.h b/pmu/evt_list.h index 5aabc03..6902167 100644 --- a/pmu/evt_list.h +++ b/pmu/evt_list.h @@ -63,7 +63,7 @@ public: this->prevStat = OPEN; this->evtStat = OPEN; } - int Init(const bool groupEnable, const std::shared_ptr evtLeader, bool isMemoryEnough); + int Init(const bool groupEnable, const std::shared_ptr evtLeader); int Pause(); int Close(); int Start(); diff --git a/pmu/pmu_list.cpp b/pmu/pmu_list.cpp index f7b88a0..340bee1 100644 --- a/pmu/pmu_list.cpp +++ b/pmu/pmu_list.cpp @@ -39,64 +39,6 @@ namespace KUNPENG_PMU { std::mutex PmuList::dataListMtx; std::mutex PmuList::dataParentMtx; - static uint64_t PredictRequiredMemory(int collectType, uint64_t cpuNum, uint64_t pidNum) { - if (collectType == SAMPLING) { - uint64_t predictMmapNum = cpuNum * pidNum; - uint64_t reservedSpace = 2 * 1024 * 1024; - uint64_t mmapSpaceSize = sizeof(struct PerfMmap) * predictMmapNum; - // copiedEvent memory and mmap memory and reserved space memory, mmap memory 528384 is PAGE_SIZE * (pages + 1) - uint64_t needBytesNum = predictMmapNum * (PERF_SAMPLE_MAX_SIZE) + predictMmapNum * (SAMPLE_PAGES + 1) * SAMPLE_PAGE_SIZE + reservedSpace + mmapSpaceSize; - return needBytesNum; - } - return 0; - } - - static bool PredictRemainSpaceIsEnough(uint64_t needBytesNum) { - if (needBytesNum == 0) { - return true; - } - - ifstream file("/proc/meminfo"); - if (!file.is_open()) { - DBG_PRINT("failed to open /proc/meminfo, unable to predict\n"); - return false; - } - - string line; - const int strLen = 1024; - while(std::getline(file, line)) { - if (line.empty() || !strstr(line.c_str(), "MemFree")) { - continue; - } - char memoryUint[strLen]; - uint64_t memoryFreeNum; - if (sscanf(line.c_str(), "%*s %lu %s", &memoryFreeNum, &memoryUint) != 2) { - DBG_PRINT("failed to open parse MemFree data, unable to predict\n"); - break; - } - - char firstUint = tolower(memoryUint[0]); - switch (firstUint) { - case 'k': - memoryFreeNum = memoryFreeNum * 1024; - break; - case 'm': - memoryFreeNum = memoryFreeNum * 1024 * 1024; - break; - case 'g': - memoryFreeNum = memoryFreeNum * 1024 * 1024 * 1024; - break; - default: - break; - } - if (needBytesNum < memoryFreeNum) { - return true; - } - DBG_PRINT("Predict memory is not enough\n"); - } - return false; - } - int PmuList::CheckRlimit(const unsigned fdNum) { return RaiseNumFd(fdNum); @@ -129,7 +71,6 @@ namespace KUNPENG_PMU { } unsigned fdNum = 0; - uint64_t needBytesNum = 0; while (pmuTaskAttrHead) { /** * Create cpu topology list @@ -151,7 +92,6 @@ namespace KUNPENG_PMU { fdNum += CalRequireFd(cpuTopoList.size(), procTopoList.size(), taskParam->pmuEvt->collectType); std::shared_ptr evtList = std::make_shared(GetSymbolMode(pd), cpuTopoList, procTopoList, pmuTaskAttrHead->pmuEvt, pmuTaskAttrHead->groupId); - needBytesNum += PredictRequiredMemory(taskParam->pmuEvt->collectType, cpuTopoList.size(), procTopoList.size()); evtList->SetBranchSampleFilter(GetBranchSampleFilter(pd)); InsertEvtList(pd, evtList); pmuTaskAttrHead = pmuTaskAttrHead->next; @@ -162,7 +102,7 @@ namespace KUNPENG_PMU { return err; } - err = Init(pd, PredictRemainSpaceIsEnough(needBytesNum)); + err = Init(pd); if (err != SUCCESS) { return err; @@ -172,9 +112,9 @@ namespace KUNPENG_PMU { return SUCCESS; } - int PmuList::EvtInit(const bool groupEnable, const std::shared_ptr evtLeader, const int pd, const std::shared_ptr &evtList, bool isMemoryEnough) + int PmuList::EvtInit(const bool groupEnable, const std::shared_ptr evtLeader, const int pd, const std::shared_ptr &evtList) { - auto err = evtList->Init(groupEnable, evtLeader, isMemoryEnough); + auto err = evtList->Init(groupEnable, evtLeader); if (err != SUCCESS) { return err; } @@ -187,19 +127,19 @@ namespace KUNPENG_PMU { return SUCCESS; } - int PmuList::Init(const int pd, bool isMemoryEnough) + int PmuList::Init(const int pd) { std::unordered_map eventGroupInfoMap; for (auto& evtList : GetEvtList(pd)) { if (evtList->GetGroupId() == -1) { - auto err = EvtInit(false, nullptr, pd, evtList, isMemoryEnough); + auto err = EvtInit(false, nullptr, pd, evtList); if (err != SUCCESS) { return err; } continue; } if (eventGroupInfoMap.find(evtList->GetGroupId()) == eventGroupInfoMap.end()) { - auto err = EvtInit(true, nullptr, pd, evtList, isMemoryEnough); + auto err = EvtInit(true, nullptr, pd, evtList); if (err != SUCCESS) { return err; } @@ -225,9 +165,9 @@ namespace KUNPENG_PMU { int err = 0; if (eventGroupInfoMap[evtChild->GetGroupId()].uncoreState == static_cast(UncoreState::HasUncore)) { SetWarn(LIBPERF_WARN_INVALID_GROUP_HAS_UNCORE); - err = EvtInit(false, nullptr, pd, evtChild, isMemoryEnough); + err = EvtInit(false, nullptr, pd, evtChild); } else { - err = EvtInit(true, eventGroupInfoMap[evtChild->GetGroupId()].evtLeader, pd, evtChild, isMemoryEnough); + err = EvtInit(true, eventGroupInfoMap[evtChild->GetGroupId()].evtLeader, pd, evtChild); } if (err != SUCCESS) { return err; diff --git a/pmu/pmu_list.h b/pmu/pmu_list.h index 8f88ff5..5e95054 100644 --- a/pmu/pmu_list.h +++ b/pmu/pmu_list.h @@ -96,8 +96,8 @@ private: void EraseSymModeList(const unsigned pd); void ErasePpidList(const unsigned pd); - int EvtInit(const bool groupEnable, const std::shared_ptr evtLeader, const int pd, const std::shared_ptr &evtList, bool isMemoryEnough); - int Init(const int pd, bool isMemoryEnough); + int EvtInit(const bool groupEnable, const std::shared_ptr evtLeader, const int pd, const std::shared_ptr &evtList); + int Init(const int pd); void InsertDataEvtGroupList(const unsigned pd, groupMapPtr evtGroupList); void EraseDataEvtGroupList(const unsigned pd); -- Gitee