193 lines
7.5 KiB
Diff
193 lines
7.5 KiB
Diff
From 8fcb0cd364de2d4957e36d4206058bff7d723f1b Mon Sep 17 00:00:00 2001
|
|
From: fly_1997 <flylove7@outlook.com>
|
|
Date: Mon, 16 Dec 2024 23:34:32 +0800
|
|
Subject: [PATCH 3/3] add pmu check
|
|
|
|
---
|
|
src/plugin/collect/pmu/CMakeLists.txt | 1 +
|
|
src/plugin/collect/pmu/pmu_common.cpp | 33 +++++++++++++++++++
|
|
src/plugin/collect/pmu/pmu_common.h | 17 ++++++++++
|
|
.../collect/pmu/pmu_counting_collector.cpp | 4 +++
|
|
.../collect/pmu/pmu_sampling_collector.cpp | 4 +++
|
|
src/plugin/collect/pmu/pmu_spe_collector.cpp | 3 ++
|
|
src/plugin/collect/pmu/pmu_spe_collector.h | 1 +
|
|
.../collect/pmu/pmu_uncore_collector.cpp | 3 ++
|
|
src/plugin/collect/pmu/pmu_uncore_collector.h | 1 +
|
|
9 files changed, 67 insertions(+)
|
|
create mode 100644 src/plugin/collect/pmu/pmu_common.cpp
|
|
create mode 100644 src/plugin/collect/pmu/pmu_common.h
|
|
|
|
diff --git a/src/plugin/collect/pmu/CMakeLists.txt b/src/plugin/collect/pmu/CMakeLists.txt
|
|
index ba3cb6a..000e26e 100644
|
|
--- a/src/plugin/collect/pmu/CMakeLists.txt
|
|
+++ b/src/plugin/collect/pmu/CMakeLists.txt
|
|
@@ -22,6 +22,7 @@ set(pmu_src
|
|
pmu_uncore_collector.cpp
|
|
pmu_uncore.cpp
|
|
pmu_collector.cpp
|
|
+ pmu_common.cpp
|
|
)
|
|
|
|
add_library(pmu SHARED ${pmu_src})
|
|
diff --git a/src/plugin/collect/pmu/pmu_common.cpp b/src/plugin/collect/pmu/pmu_common.cpp
|
|
new file mode 100644
|
|
index 0000000..caf453a
|
|
--- /dev/null
|
|
+++ b/src/plugin/collect/pmu/pmu_common.cpp
|
|
@@ -0,0 +1,33 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
|
|
+ * oeAware is licensed under Mulan PSL v2.
|
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
|
+ * http://license.coscl.org.cn/MulanPSL2
|
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
+ * See the Mulan PSL v2 for more details.
|
|
+ ******************************************************************************/
|
|
+#include "pmu_common.h"
|
|
+#include <string>
|
|
+#include <dirent.h>
|
|
+#include "oeaware/utils.h"
|
|
+
|
|
+static const std::string DEVICES_PATH = "/sys/bus/event_source/devices/";
|
|
+
|
|
+bool IsSupportPmu()
|
|
+{
|
|
+ DIR *dir = opendir(DEVICES_PATH.data());
|
|
+ if (dir == nullptr) {
|
|
+ return false;
|
|
+ }
|
|
+ struct dirent *dent = nullptr;
|
|
+ while (dent = readdir(dir)) {
|
|
+ std::string armPmuPath = DEVICES_PATH + dent->d_name + "/cpus";
|
|
+ if (oeaware::FileExist(armPmuPath)) {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ return false;
|
|
+}
|
|
diff --git a/src/plugin/collect/pmu/pmu_common.h b/src/plugin/collect/pmu/pmu_common.h
|
|
new file mode 100644
|
|
index 0000000..3ba5a2d
|
|
--- /dev/null
|
|
+++ b/src/plugin/collect/pmu/pmu_common.h
|
|
@@ -0,0 +1,17 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
|
|
+ * oeAware is licensed under Mulan PSL v2.
|
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
|
+ * http://license.coscl.org.cn/MulanPSL2
|
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
+ * See the Mulan PSL v2 for more details.
|
|
+ ******************************************************************************/
|
|
+#ifndef PMU_COMMON_H
|
|
+#define PMU_COMMON_H
|
|
+
|
|
+bool IsSupportPmu();
|
|
+
|
|
+#endif
|
|
diff --git a/src/plugin/collect/pmu/pmu_counting_collector.cpp b/src/plugin/collect/pmu/pmu_counting_collector.cpp
|
|
index 9227d67..281c61d 100644
|
|
--- a/src/plugin/collect/pmu/pmu_counting_collector.cpp
|
|
+++ b/src/plugin/collect/pmu/pmu_counting_collector.cpp
|
|
@@ -14,6 +14,7 @@
|
|
#include <iostream>
|
|
#include <securec.h>
|
|
#include "oeaware/data/pmu_counting_data.h"
|
|
+#include "pmu_common.h"
|
|
|
|
PmuCountingCollector::PmuCountingCollector(): oeaware::Interface()
|
|
{
|
|
@@ -119,6 +120,9 @@ void PmuCountingCollector::CloseTopic(const oeaware::Topic &topic)
|
|
oeaware::Result PmuCountingCollector::Enable(const std::string ¶m)
|
|
{
|
|
(void)param;
|
|
+ if (!IsSupportPmu()) {
|
|
+ return oeaware::Result(FAILED, "the system does not support PMU.");
|
|
+ }
|
|
return oeaware::Result(OK);
|
|
}
|
|
|
|
diff --git a/src/plugin/collect/pmu/pmu_sampling_collector.cpp b/src/plugin/collect/pmu/pmu_sampling_collector.cpp
|
|
index f1f99eb..b4cf037 100644
|
|
--- a/src/plugin/collect/pmu/pmu_sampling_collector.cpp
|
|
+++ b/src/plugin/collect/pmu/pmu_sampling_collector.cpp
|
|
@@ -14,6 +14,7 @@
|
|
#include <iostream>
|
|
#include <securec.h>
|
|
#include "oeaware/data/pmu_sampling_data.h"
|
|
+#include "pmu_common.h"
|
|
|
|
PmuSamplingCollector::PmuSamplingCollector(): oeaware::Interface()
|
|
{
|
|
@@ -123,6 +124,9 @@ void PmuSamplingCollector::CloseTopic(const oeaware::Topic &topic)
|
|
oeaware::Result PmuSamplingCollector::Enable(const std::string ¶m)
|
|
{
|
|
(void)param;
|
|
+ if (!IsSupportPmu()) {
|
|
+ return oeaware::Result(FAILED, "the system does not support PMU.");
|
|
+ }
|
|
return oeaware::Result(OK);
|
|
}
|
|
|
|
diff --git a/src/plugin/collect/pmu/pmu_spe_collector.cpp b/src/plugin/collect/pmu/pmu_spe_collector.cpp
|
|
index 19ad8de..dc7e0fb 100644
|
|
--- a/src/plugin/collect/pmu/pmu_spe_collector.cpp
|
|
+++ b/src/plugin/collect/pmu/pmu_spe_collector.cpp
|
|
@@ -133,6 +133,9 @@ void PmuSpeCollector::CloseTopic(const oeaware::Topic &topic)
|
|
oeaware::Result PmuSpeCollector::Enable(const std::string ¶m)
|
|
{
|
|
(void)param;
|
|
+ if (!oeaware::FileExist(spePath)) {
|
|
+ return oeaware::Result(FAILED, "the system does not support SPE.");
|
|
+ }
|
|
return oeaware::Result(OK);
|
|
}
|
|
|
|
diff --git a/src/plugin/collect/pmu/pmu_spe_collector.h b/src/plugin/collect/pmu/pmu_spe_collector.h
|
|
index c913e43..d54a204 100644
|
|
--- a/src/plugin/collect/pmu/pmu_spe_collector.h
|
|
+++ b/src/plugin/collect/pmu/pmu_spe_collector.h
|
|
@@ -35,6 +35,7 @@ private:
|
|
int attrPeriod = 2048;
|
|
std::string topicStr = "spe";
|
|
std::chrono::time_point<std::chrono::high_resolution_clock> timestamp;
|
|
+ const std::string spePath = "/sys/bus/event_source/devices/arm_spe_0";
|
|
const int timeoutMs = 50;
|
|
const int notTimeoutMs = 10;
|
|
const int periodThreshold = 2;
|
|
diff --git a/src/plugin/collect/pmu/pmu_uncore_collector.cpp b/src/plugin/collect/pmu/pmu_uncore_collector.cpp
|
|
index ba00ebc..74c2901 100644
|
|
--- a/src/plugin/collect/pmu/pmu_uncore_collector.cpp
|
|
+++ b/src/plugin/collect/pmu/pmu_uncore_collector.cpp
|
|
@@ -151,6 +151,9 @@ void PmuUncoreCollector::CloseTopic(const oeaware::Topic &topic)
|
|
oeaware::Result PmuUncoreCollector::Enable(const std::string ¶m)
|
|
{
|
|
(void)param;
|
|
+ if (!oeaware::FileExist(uncorePath)) {
|
|
+ return oeaware::Result(FAILED, "the system does not support uncore events.");
|
|
+ }
|
|
return oeaware::Result(OK);
|
|
}
|
|
|
|
diff --git a/src/plugin/collect/pmu/pmu_uncore_collector.h b/src/plugin/collect/pmu/pmu_uncore_collector.h
|
|
index 175026f..a01d138 100644
|
|
--- a/src/plugin/collect/pmu/pmu_uncore_collector.h
|
|
+++ b/src/plugin/collect/pmu/pmu_uncore_collector.h
|
|
@@ -32,6 +32,7 @@ private:
|
|
std::vector<std::string> eventStr;
|
|
std::vector<std::string> hhaDir;
|
|
std::chrono::time_point<std::chrono::high_resolution_clock> timestamp;
|
|
+ const std::string uncorePath = "/sys/bus/event_source/devices/hisi_sccl1_hha2";
|
|
void InitUncoreAttr(struct PmuAttr &attr);
|
|
int OpenUncore();
|
|
};
|
|
--
|
|
2.33.0
|
|
|