diff --git a/pmu/evt_list.cpp b/pmu/evt_list.cpp index 28e90a62a6fb864c4d0f62e83da0ca17dab3f1f3..93fa00d96ef741badc1e51595aba74acd107783f 100644 --- a/pmu/evt_list.cpp +++ b/pmu/evt_list.cpp @@ -109,6 +109,12 @@ int KUNPENG_PMU::EvtList::Init(const bool groupEnable, const std::shared_ptrGetFd()); + if (this->pmuEvt->collectType == SAMPLING) { + std::shared_ptr perfSampler = std::dynamic_pointer_cast(perfEvt); + if (perfSampler != nullptr) { + mmapList.insert(perfSampler->GetMmap()); + } + } evtVec.emplace_back(perfEvt); } this->xyCounterArray.emplace_back(evtVec); diff --git a/pmu/evt_list.h b/pmu/evt_list.h index f27eec0d4d3759aa69f0dace374de9573538f7f0..c8ac69f0a4655e099d6bc573f04867290ed785cb 100644 --- a/pmu/evt_list.h +++ b/pmu/evt_list.h @@ -86,6 +86,11 @@ public: return fdList; } + std::set> GetMmapList() const + { + return mmapList; + } + int GetEvtType() const { return pmuEvt->collectType; @@ -120,6 +125,7 @@ private: unsigned int numCpu = 0; unsigned int numPid = 0; std::set fdList; + std::set> mmapList; int64_t ts = 0; std::unordered_map procMap; SymbolMode symMode = NO_SYMBOL_RESOLVE; diff --git a/pmu/pmu_list.cpp b/pmu/pmu_list.cpp index 34af40a2e31085cf95fb52ef1cd53f11fdd00d07..3fa70308a3d3f32d51a7bbb041ea4104290040fb 100644 --- a/pmu/pmu_list.cpp +++ b/pmu/pmu_list.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "linked_list.h" #include "cpu_map.h" #include "process_map.h" @@ -30,6 +31,7 @@ using namespace std; using namespace pcerr; +static const int PAGE_SIZE = sysconf(_SC_PAGESIZE); namespace KUNPENG_PMU { // Initializing pmu list singleton instance and global lock @@ -118,6 +120,8 @@ namespace KUNPENG_PMU { return err; } + AddToMmapInfo(pd, evtList); + err = AddToEpollFd(pd, evtList); if (err != SUCCESS) { return err; @@ -294,6 +298,7 @@ namespace KUNPENG_PMU { void PmuList::Close(const int pd) { + MunmapInfo(pd); auto evtList = GetEvtList(pd); for (auto item: evtList) { item->Close(); @@ -631,6 +636,32 @@ namespace KUNPENG_PMU { throw runtime_error(""); } + void PmuList::AddToMmapInfo(const unsigned pd, const std::shared_ptr& evtList) + { + if (GetTaskType(pd) == SAMPLING) { + lock_guard lg(pmuListMtx); + auto& mmapInfo = mmapList[pd]; + for (auto& mmapNode : evtList->GetMmapList()) { + mmapInfo.emplace_back(mmapNode); + } + } + } + + void PmuList::MunmapInfo(const unsigned pd) + { + if (GetTaskType(pd) == SAMPLING) { + lock_guard lg(pmuListMtx); + auto findMmap = mmapList.find(pd); + if (findMmap != mmapList.end()) { + for (auto& mmapNode : findMmap->second) { + munmap(mmapNode->base, mmapNode->mask + 1 + PAGE_SIZE); + mmapNode->base = nullptr; + } + mmapList.erase(pd); + } + } + } + int PmuList::AddToEpollFd(const int pd, const std::shared_ptr& evtList) { lock_guard lg(pmuListMtx); diff --git a/pmu/pmu_list.h b/pmu/pmu_list.h index 8ad2b7ddb049449dd30956dbe7be15799689ca2f..1f84f061e5d76038b22501c08f176a1dcfb86679 100644 --- a/pmu/pmu_list.h +++ b/pmu/pmu_list.h @@ -115,6 +115,8 @@ private: void FillStackInfo(EventData &eventData); void EraseUserData(PmuData* pmuData); + void AddToMmapInfo(const unsigned pd, const std::shared_ptr& evtList); + void MunmapInfo(const unsigned pd); int AddToEpollFd(const int pd, const std::shared_ptr &evtList); void RemoveEpollFd(const int pd); int GetEpollFd(const int pd); @@ -166,6 +168,9 @@ private: // Key: epoll fd // Value: epoll event list std::unordered_map> epollEvents; + // Key: pd + // Value: mmap list in SAMPLING Mode + std::unordered_map>> mmapList; // Key: pd // Value: spe sampling cpu list. diff --git a/pmu/sampler.h b/pmu/sampler.h index d69a1d02b0a396e32f66e22ab426ae19d2168203..5e8c99fc78a37a793f5373581d3e1621f6f46d56 100644 --- a/pmu/sampler.h +++ b/pmu/sampler.h @@ -44,6 +44,16 @@ namespace KUNPENG_PMU { int MapPerfAttr(const bool groupEnable, const int groupFd) override; + bool IsMainPid() const override + { + return true; + }; + + std::shared_ptr GetMmap() const + { + return sampleMmap; + } + private: int ReadInit(); int Mmap();