diff --git a/pmu/perf_counter.cpp b/pmu/perf_counter.cpp index e3640ff2e5ee68c9f4b931114f501168938e170b..ed6f19a1c923a85a60b9864d08ffb86369333636 100644 --- a/pmu/perf_counter.cpp +++ b/pmu/perf_counter.cpp @@ -331,16 +331,7 @@ int KUNPENG_PMU::PerfCounter::MapPerfAttr(const bool groupEnable, const int grou attr.read_format |= PERF_FORMAT_GROUP; this->fd = PerfEventOpen(&attr, this->pid, this->cpu, groupFd, flags); } else { -#ifdef IS_X86 - if (this->evt->pmuType == KUNPENG_PMU::UNCORE_TYPE && !StartWith(this->evt->name, "cpu/")) { - this->fd = PerfEventOpen(&attr, -1, this->cpu, groupFd, flags); -#else - if (this->evt->pmuType == KUNPENG_PMU::UNCORE_TYPE && !StartWith(this->evt->name, "armv8_")) { - this->fd = PerfEventOpen(&attr, -1, this->cpu, groupFd, 0); -#endif - } else { - this->fd = PerfEventOpen(&attr, this->pid, this->cpu, groupFd, flags); - } + this->fd = PerfEventOpen(&attr, this->pid, this->cpu, groupFd, flags); groupStatus = GroupStatus::NO_GROUP; } this->groupFd = groupFd; diff --git a/pmu/pmu.cpp b/pmu/pmu.cpp index 2c8ef8bd9a08fe3b05203117892ee50e9d0e9447..a4b0dddcd325fe7d29b3ff92fb2df05b83f5c5e0 100644 --- a/pmu/pmu.cpp +++ b/pmu/pmu.cpp @@ -509,8 +509,6 @@ static void PmuTaskAttrFree(PmuTaskAttr *taskAttr) { auto node = taskAttr; while (node) { - delete[] node->pidList; - delete[] node->cpuList; auto current = node; node = node->next; current->pmuEvt = nullptr; @@ -558,6 +556,7 @@ int PmuOpen(enum PmuTaskType collectType, struct PmuAttr *attr) break; } + PmuList::GetInstance()->FillPidList(pd, copiedAttr.numPid, copiedAttr.pidList); PmuList::GetInstance()->SetSymbolMode(pd, attr->symbolMode); PmuList::GetInstance()->SetBranchSampleFilter(pd, attr->branchSampleFilter); PmuList::GetInstance()->SetAnalysisStatus(pd, GOING_RESOLVE); @@ -901,32 +900,23 @@ static struct PmuEvt* GetPmuEvent(const char* pmuName, int collectType) static void PrepareCpuList(PmuAttr *attr, PmuTaskAttr *taskParam, PmuEvt* pmuEvt) { if (!pmuEvt->cpuMaskList.empty()) { - taskParam->numCpu = pmuEvt->cpuMaskList.size(); - taskParam->cpuList = new int[pmuEvt->cpuMaskList.size()]; - for(int i = 0; i < pmuEvt->cpuMaskList.size(); i++) { - taskParam->cpuList[i] = pmuEvt->cpuMaskList[i]; + for (int i : pmuEvt->cpuMaskList) { + taskParam->cpuList.push_back(i); } + taskParam->pidList.clear(); + taskParam->pidList.push_back(-1); } else if (attr->cpuList == nullptr && attr->pidList != nullptr && pmuEvt->collectType == COUNTING) { // For counting with pid list for system wide, open fd with cpu -1 and specific pid. - taskParam->numCpu = 1; - taskParam->cpuList = new int[taskParam->numCpu]; - taskParam->cpuList[0] = -1; + taskParam->cpuList.push_back(-1); } else if (attr->cpuList == nullptr) { // For null cpulist, open fd with cpu 0,1,2...max_cpu const set &onLineCpus = GetOnLineCpuIds(); - int cpuNum = onLineCpus.size(); - taskParam->numCpu = cpuNum; - taskParam->cpuList = new int[cpuNum]; - int i = 0; for (const auto &cpuId : onLineCpus) { - taskParam->cpuList[i] = cpuId; - i++; + taskParam->cpuList.push_back(cpuId); } } else { - taskParam->numCpu = attr->numCpu; - taskParam->cpuList = new int[attr->numCpu]; for (int i = 0; i < attr->numCpu; i++) { - taskParam->cpuList[i] = attr->cpuList[i]; + taskParam->cpuList.push_back(attr->cpuList[i]); } } } @@ -947,10 +937,8 @@ static struct PmuTaskAttr* AssignTaskParam(PmuTaskType collectType, PmuAttr *att /** * Assign pids to collect */ - taskParam->numPid = attr->numPid; - taskParam->pidList = new int[attr->numPid]; for (int i = 0; i < attr->numPid; i++) { - taskParam->pidList[i] = attr->pidList[i]; + taskParam->pidList.push_back(attr->pidList[i]); } PmuEvt* pmuEvt = nullptr; diff --git a/pmu/pmu_list.cpp b/pmu/pmu_list.cpp index 31b131b7b3b0bfc5f984421388ad42cd08fee96f..855f417a7658c65580dd414eb30fb686d556f01e 100644 --- a/pmu/pmu_list.cpp +++ b/pmu/pmu_list.cpp @@ -56,7 +56,6 @@ namespace KUNPENG_PMU { int PmuList::Register(const int pd, PmuTaskAttr* taskParam) { - this->FillPidList(taskParam, pd); /* Use libpfm to get the basic config for this pmu event */ struct PmuTaskAttr* pmuTaskAttrHead = taskParam; // Init collect type for pmu data, @@ -917,15 +916,15 @@ namespace KUNPENG_PMU { int PmuList::PrepareCpuTopoList( const unsigned& pd, PmuTaskAttr* pmuTaskAttrHead, std::vector& cpuTopoList) { - for (int i = 0; i < pmuTaskAttrHead->numCpu; i++) { - if (pmuTaskAttrHead->pmuEvt->collectType == SPE_SAMPLING && IsCpuInList(pmuTaskAttrHead->cpuList[i])) { + for (int cpuId : pmuTaskAttrHead->cpuList) { + if (pmuTaskAttrHead->pmuEvt->collectType == SPE_SAMPLING && IsCpuInList(cpuId)) { // For SPE sampling, one core can only be used by one pd. // Therefore, check if core is in sampling. return LIBPERF_ERR_DEVICE_BUSY; } - struct CpuTopology* cpuTopo = GetCpuTopology(pmuTaskAttrHead->cpuList[i]); + struct CpuTopology* cpuTopo = GetCpuTopology(cpuId); if (pmuTaskAttrHead->pmuEvt->collectType == SPE_SAMPLING) { - AddSpeCpu(pd, pmuTaskAttrHead->cpuList[i]); + AddSpeCpu(pd, cpuId); } cpuTopoList.emplace_back(shared_ptr(cpuTopo)); } @@ -934,16 +933,16 @@ namespace KUNPENG_PMU { int PmuList::PrepareProcTopoList(PmuTaskAttr* pmuTaskAttrHead, std::vector& procTopoList) const { - if (pmuTaskAttrHead->numPid == 0) { + if (pmuTaskAttrHead->pidList.empty() || (pmuTaskAttrHead->pidList.size() == 1 && pmuTaskAttrHead->pidList[0] == -1)) { struct ProcTopology* procTopo = GetProcTopology(-1); if (procTopo == nullptr) { New(LIBPERF_ERR_FAIL_GET_PROC); return LIBPERF_ERR_FAIL_GET_PROC; } procTopoList.emplace_back(unique_ptr(procTopo, FreeProcTopo)); + return SUCCESS; } - for (int i = 0; i < pmuTaskAttrHead->numPid; i++) { - int masterPid = pmuTaskAttrHead->pidList[i]; + for (int masterPid : pmuTaskAttrHead->pidList) { int numChild = 0; int* childTidList = GetChildTid(masterPid, &numChild); if (childTidList == nullptr) { @@ -963,7 +962,7 @@ namespace KUNPENG_PMU { } delete[] childTidList; if (!foundProc) { - New(LIBPERF_ERR_FAIL_GET_PROC, "process not found: " + std::to_string(pmuTaskAttrHead->pidList[i])); + New(LIBPERF_ERR_FAIL_GET_PROC, "process not found: " + std::to_string(masterPid)); return LIBPERF_ERR_FAIL_GET_PROC; } } @@ -1014,7 +1013,7 @@ namespace KUNPENG_PMU { if (taskParam->pmuEvt->collectType != COUNTING) { return; } - if (taskParam->numPid <= 0) { + if (taskParam->pidList.empty()) { return; } auto* dummyEvent = new DummyEvent(GetEvtList(pd), ppidList.at(pd), GetDataEvtGroupList(pd)); @@ -1022,11 +1021,11 @@ namespace KUNPENG_PMU { dummyList[pd] = dummyEvent; } - void PmuList::FillPidList(KUNPENG_PMU::PmuTaskAttr* taskParam, const unsigned int pd) + void PmuList::FillPidList(const unsigned pd, unsigned numPid, int *pidList) { std::vector ppids; - for (int i = 0; i < taskParam->numPid; i++) { - ppids.push_back(taskParam->pidList[i]); + for (int i = 0; i < numPid; i++) { + ppids.push_back(pidList[i]); } ppidList[pd] = ppids; } diff --git a/pmu/pmu_list.h b/pmu/pmu_list.h index 0798f0f41abeebc31690ec4968c1463c934bf9ab..61a02425b485896026bff548589fb323270e1107 100644 --- a/pmu/pmu_list.h +++ b/pmu/pmu_list.h @@ -31,12 +31,9 @@ enum AnalysisStatus { }; struct PmuTaskAttr { - int numCpu; // number of cpu to be collected - int* cpuList; // list of core ids to be collected - // list length has to be as the same as numCpu - int numPid; // number of (parent) processes to be collected - int* pidList; // list of pids(tids) to be collected - // list length has to be as the same as numPid + std::vector cpuList; // list of core ids to be collected + std::vector pidList; // list of pids(tids) to be collected + std::shared_ptr pmuEvt; // which pmu to be collected int groupId; // event group id @@ -83,6 +80,7 @@ public: void StoreSplitData(unsigned pd, std::pair& previousEventList, std::unordered_map& eventSplitMap); bool IsAllPidExit(const unsigned pd); + void FillPidList(const unsigned pd, unsigned numPid, int* pidList); int ResolvePmuDataSymbol(struct PmuData* iPmuData); std::vector GetMetaData(PmuData* pmuData) const; @@ -137,7 +135,6 @@ private: SymbolMode GetSymbolMode(const unsigned pd); unsigned GetAnalysisStatus(const int pd); unsigned long GetBranchSampleFilter(const unsigned pd); - void FillPidList(PmuTaskAttr* taskParam, const unsigned pd); void OpenDummyEvent(PmuTaskAttr* taskParam, const unsigned pd); void EraseDummyEvent(const unsigned pd); int InitSymbolRecordModule(const unsigned pd, PmuTaskAttr* taskParam);