diff --git a/example/case/falsesharing_demo.c b/example/case/falsesharing_demo.cpp similarity index 92% rename from example/case/falsesharing_demo.c rename to example/case/falsesharing_demo.cpp index 969d320fed142f6627bc8345c028207e8a965fd9..340403be2bd6fbbd6a2560e9ec9efbce201129d9 100644 --- a/example/case/falsesharing_demo.c +++ b/example/case/falsesharing_demo.cpp @@ -50,7 +50,7 @@ void *inc_b(void*) } if (CPU_ISSET(cpu_num, &get)) { - printf("sum_a is running in %d cpu_id: %d\n", get, cpu_num); + printf("inc_b is running in %d cpu_id: %d\n", get, cpu_num); } int s = 0; diff --git a/example/pmu_datasrc.cpp b/example/pmu_datasrc.cpp index 96c910116c7109661848b339c5f7ae53d1443bd4..ef558f8ee42ba651f5667233454b044c0e4e15dd 100644 --- a/example/pmu_datasrc.cpp +++ b/example/pmu_datasrc.cpp @@ -52,11 +52,12 @@ static std::map HIP_STR_MAP = { {HIP_L1, "HIP_L1"}, }; -const char* SHORT_OPS = "p:d:h"; +const char* SHORT_OPS = "p:d:c:h"; const struct option LONG_OPS[] = { {"pid", required_argument, nullptr, 'p'}, {"duration", required_argument, nullptr, 'd'}, + {"cgroupName", required_argument, nullptr, 'c'}, {"help", required_argument, nullptr, 'h'}, {nullptr, required_argument, nullptr, 0}, }; @@ -86,7 +87,7 @@ int ExecCommand(std::vector& comms) return -1; } -int ParseArgv(int argc, char** argv, int& pid, int& duration, bool& isLaunch) +int ParseArgv(int argc, char** argv, int& pid, int& duration, bool& isLaunch, char** cgroupName) { int longIndex; int ret; @@ -111,6 +112,10 @@ int ParseArgv(int argc, char** argv, int& pid, int& duration, bool& isLaunch) return -1; } break; + case 'c': + curIndex += 2; + *cgroupName = optarg; + break; case 'h': curIndex += 2; std::cout << "usage pmu_datasrc -d 2 -p 10001 or pmu_datasrc -d 2 /home/test/falsesharing_demo" << std::endl; @@ -150,38 +155,67 @@ int main(int argc, char** argv) int pid = -1; int duration = 10; bool isLaunch = false; + char* cgroupName = nullptr; - int err = ParseArgv(argc, argv, pid, duration, isLaunch); + int err = ParseArgv(argc, argv, pid, duration, isLaunch, &cgroupName); if (err == -1) { return -1; } - if (pid == -1) { + if (pid == -1 && cgroupName == nullptr) { std::cout << "usage pmu_datasrc -d 2 -p 10001 or pmu_datasrc -d 2 /home/test/falsesharing_demo" << std::endl; return -1; } + if (pid > 0 && cgroupName != nullptr) { + if (isLaunch) { + kill(pid, 9); + } + std::cout << "Cannot specify both cgroup and pid. Please use only one" << std::endl; + return -1; + } + PmuAttr attr = {0}; - int pidList[1]; - pidList[0] = pid; - attr.pidList = pidList; - attr.numPid = 1; - attr.period = 1024; + if (cgroupName != nullptr) { + char* cgroupNameList[1] = {cgroupName}; + attr.cgroupNameList = cgroupNameList; + attr.numCgroup = 1; + } else { + int pidList[1]; + pidList[0] = pid; + attr.pidList = pidList; + attr.numPid = 1; + } + attr.period = 256; attr.dataFilter = SPE_DATA_ALL; attr.evFilter = SPE_EVENT_RETIRED; attr.symbolMode = SymbolMode::RESOLVE_ELF_DWARF; + int pd = PmuOpen(SPE_SAMPLING, &attr); if (pd == -1) { + if (isLaunch) { + kill(pid, 9); + } std::cout << "kperf pmu open spe failed, err is: " << Perror() << std::endl; return -1; } - PmuEnable(pd); - sleep(duration); - PmuDisable(pd); - + + int num = duration * 10; PmuData* data = nullptr; - int len = PmuRead(pd, &data); + int len = 0; + for (int i = 0; i < num; i++) { + PmuEnable(pd); + usleep(100 * 1000); + PmuDisable(pd); + PmuData* fromData = nullptr; + PmuRead(pd, &fromData); + int curLen = PmuAppendData(fromData, &data); + if (curLen) { + len = curLen; + } + } + std::map sourceList; std::map> sourceSymList; diff --git a/pmu/spe.cpp b/pmu/spe.cpp index 9da1c123680501920b57248aab4cd930a1821ea8..ca4f9ed46d25cacc3e7caa77b46e49a5eebc5020 100644 --- a/pmu/spe.cpp +++ b/pmu/spe.cpp @@ -36,7 +36,7 @@ constexpr unsigned SPE_RECORD_MAX = 100000; constexpr unsigned BUFF_SIZE = 64; /* Should align to 2^n size in pages */ constexpr unsigned RING_BUF_SIZE = 64 * 1024; -constexpr unsigned AUX_BUF_SIZE = 256 * 1024; +constexpr unsigned AUX_BUF_SIZE = 256 * 1024 * 4; struct AuxContext { diff --git a/util/cpu_map.h b/util/cpu_map.h index 61f20b282e1a58bc498bbd634b823329f6e6ca79..8696161445625e9e25d8abbcac2e23af3268d7eb 100644 --- a/util/cpu_map.h +++ b/util/cpu_map.h @@ -14,7 +14,6 @@ ******************************************************************************/ #ifndef CPU_MAP_H #define CPU_MAP_H -#include #include #include #include "pmu.h"