summaryrefslogtreecommitdiff
path: root/source/profiler
diff options
context:
space:
mode:
authorKshitij Sisodia <kshitij.sisodia@arm.com>2022-04-01 14:43:53 +0100
committerKshitij Sisodia <kshitij.sisodia@arm.com>2022-04-05 09:30:23 +0100
commitda2ec067da418d3d80b2829b111df25bd901eb5c (patch)
tree0ccba5c7655ad042bd21f71ffd59c0f52c163f62 /source/profiler
parent8bc863dd6a7d0937aa66df655a7fe0e235dd2d4f (diff)
downloadml-embedded-evaluation-kit-da2ec067da418d3d80b2829b111df25bd901eb5c.tar.gz
MLECO-3096: Removing "timer" from HAL profile.
Attempting to have timer functionality contained within the platform drivers "package" as it should (in line with the refactoring work done so far under HAL). This will ensure that we don't need two timer implementations under HAL "profiles" and therefore, this whole directory can be removed. This change also addressed issue with the applicatio level Profiler code knowing about how the PMU has been set up by the platform code. This link has been removed completely. This will make it much easier to add/amend the Ethos-U PMU event counters types and give each platform the capability of populating their relvant counters. The application level Profiler doesn't know which metrics it is displaying but just calculates and maintains statistics for whatever PMU counters it receives from the HAL level. A fix for timing adapter issue introduced in the last CR is also included. Change-Id: Ia46e03a06e7b8e42b9ed2ba8f2af2dcd2229c110 Signed-off-by: Kshitij Sisodia <kshitij.sisodia@arm.com>
Diffstat (limited to 'source/profiler')
-rw-r--r--source/profiler/CMakeLists.txt9
-rw-r--r--source/profiler/Profiler.cc172
-rw-r--r--source/profiler/include/Profiler.hpp15
3 files changed, 45 insertions, 151 deletions
diff --git a/source/profiler/CMakeLists.txt b/source/profiler/CMakeLists.txt
index 8fcea1f..0a9c338 100644
--- a/source/profiler/CMakeLists.txt
+++ b/source/profiler/CMakeLists.txt
@@ -31,18 +31,9 @@ target_sources(profiler
target_include_directories(profiler PUBLIC include)
-# Set the CPU profiling defintiion
-if (CPU_PROFILE_ENABLED)
- target_compile_definitions(profiler PRIVATE CPU_PROFILE_ENABLED)
-endif()
-
# Profiling API depends on the logging interface and the HAL library.
target_link_libraries(profiler PRIVATE log hal)
-# Set the CPU profiling defintiion
-target_compile_definitions(profiler PUBLIC
- $<$<BOOL:${CPU_PROFILE_ENABLED}>:CPU_PROFILE_ENABLED>)
-
# Display status
message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS "*******************************************************")
diff --git a/source/profiler/Profiler.cc b/source/profiler/Profiler.cc
index efbc64d..7e10097 100644
--- a/source/profiler/Profiler.cc
+++ b/source/profiler/Profiler.cc
@@ -40,7 +40,7 @@ namespace app {
}
if (this->m_pPlatform && !this->m_started) {
this->m_pPlatform->timer->reset();
- this->m_tstampSt = this->m_pPlatform->timer->start_profiling();
+ this->m_tstampSt = this->m_pPlatform->timer->get_counters();
this->m_started = true;
return true;
}
@@ -51,7 +51,7 @@ namespace app {
bool Profiler::StopProfiling()
{
if (this->m_pPlatform && this->m_started) {
- this->m_tstampEnd = this->m_pPlatform->timer->stop_profiling();
+ this->m_tstampEnd = this->m_pPlatform->timer->get_counters();
this->m_started = false;
this->AddProfilingUnit(this->m_tstampSt, this->m_tstampEnd, this->m_name);
@@ -99,111 +99,28 @@ namespace app {
result.name = item.first;
result.samplesNum = series.size();
- Statistics AXI0_RD {
- .name = "NPU AXI0_RD_DATA_BEAT_RECEIVED",
- .unit = "beats",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].axi0writes,
- .max = 0
- };
- Statistics AXI0_WR {
- .name = "NPU AXI0_WR_DATA_BEAT_WRITTEN",
- .unit = "beats",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].axi0reads,
- .max = 0
- };
- Statistics AXI1_RD {
- .name = "NPU AXI1_RD_DATA_BEAT_RECEIVED",
- .unit = "beats",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].axi1reads,
- .max = 0
- };
- Statistics NPU_ACTIVE {
- .name = "NPU ACTIVE",
- .unit = "cycles",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].activeNpuCycles,
- .max = 0
- };
- Statistics NPU_IDLE {
- .name = "NPU IDLE",
- .unit = "cycles",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].idleNpuCycles,
- .max = 0
- };
- Statistics NPU_Total {
- .name = "NPU TOTAL",
- .unit = "cycles",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].npuCycles,
- .max = 0,
- };
-#if defined(CPU_PROFILE_ENABLED)
- Statistics CPU_ACTIVE {
- .name = "CPU ACTIVE",
- .unit = "cycles (approx)",
- .total = 0,
- .avrg = 0.0,
- .min = series[0].cpuCycles - NPU_ACTIVE.min,
- .max = 0
- };
- Statistics TIME {
- .name = "Time",
- .unit = "ms",
- .total = 0,
- .avrg = 0.0,
- .min = static_cast<uint64_t>(series[0].time),
- .max = 0
- };
-#endif
- for(ProfilingUnit& unit: series){
-
- calcProfilingStat(unit.npuCycles,
- NPU_Total, result.samplesNum);
-
- calcProfilingStat(unit.activeNpuCycles,
- NPU_ACTIVE, result.samplesNum);
-
- calcProfilingStat(unit.idleNpuCycles,
- NPU_IDLE, result.samplesNum);
-
- calcProfilingStat(unit.axi0writes,
- AXI0_WR, result.samplesNum);
-
- calcProfilingStat(unit.axi0reads,
- AXI0_RD, result.samplesNum);
+ std::vector<Statistics> stats(series[0].counters.num_counters);
+ for (size_t i = 0; i < stats.size(); ++i) {
+ stats[i].name = series[0].counters.counters[i].name;
+ stats[i].unit = series[0].counters.counters[i].unit;
+ }
- calcProfilingStat(unit.axi1reads,
- AXI1_RD, result.samplesNum);
-#if defined(CPU_PROFILE_ENABLED)
- calcProfilingStat(static_cast<uint64_t>(unit.time),
- TIME, result.samplesNum);
+ for(ProfilingUnit& unit: series) {
+ for (size_t i = 0; i < stats.size(); ++i) {
+ calcProfilingStat(
+ unit.counters.counters[i].value,
+ stats[i],
+ result.samplesNum);
+ }
+ }
- calcProfilingStat(unit.cpuCycles - unit.activeNpuCycles,
- CPU_ACTIVE, result.samplesNum);
-#endif
+ for (Statistics& stat : stats) {
+ result.data.emplace_back(stat);
}
- result.data.emplace_back(AXI0_RD);
- result.data.emplace_back(AXI0_WR);
- result.data.emplace_back(AXI1_RD);
- result.data.emplace_back(NPU_ACTIVE);
- result.data.emplace_back(NPU_IDLE);
- result.data.emplace_back(NPU_Total);
-#if defined(CPU_PROFILE_ENABLED)
- result.data.emplace_back(CPU_ACTIVE);
- result.data.emplace_back(TIME);
-#endif
- results.emplace_back(result);
+
+ results.emplace_back(result);
}
+
this->Reset();
}
@@ -216,10 +133,11 @@ namespace app {
std::vector<ProfileResult> results{};
GetAllResultsAndReset(results);
for(ProfileResult& result: results) {
- info("Profile for %s:\n", result.name.c_str());
-
- if (printFullStat) {
- printStatisticsHeader(result.samplesNum);
+ if (result.data.size()) {
+ info("Profile for %s:\n", result.name.c_str());
+ if (printFullStat) {
+ printStatisticsHeader(result.samplesNum);
+ }
}
for (Statistics &stat: result.data) {
@@ -228,7 +146,7 @@ namespace app {
stat.name.c_str(), stat.unit.c_str(),
stat.total, stat.avrg, stat.min, stat.max);
} else {
- info("%s %s: %.0f\n", stat.name.c_str(), stat.unit.c_str(), stat.avrg);
+ info("%s: %.0f %s\n", stat.name.c_str(), stat.avrg, stat.unit.c_str());
}
}
}
@@ -239,7 +157,7 @@ namespace app {
this->m_name = std::string(str);
}
- void Profiler::AddProfilingUnit(time_counter start, time_counter end,
+ void Profiler::AddProfilingUnit(pmu_counters start, pmu_counters end,
const std::string& name)
{
if (!this->m_pPlatform) {
@@ -247,31 +165,23 @@ namespace app {
return;
}
- platform_timer * timer = this->m_pPlatform->timer;
+ struct ProfilingUnit unit = {
+ .counters = end
+ };
- struct ProfilingUnit unit;
-
- if (timer->cap.npu_cycles && timer->get_npu_cycles_diff)
- {
- const size_t size = 6;
- uint64_t pmuCounters[size] = {0};
- /* 6 values: total cc, active cc, idle cc, axi0 read, axi0 write, axi1 read*/
- if (0 == timer->get_npu_cycles_diff(&start, &end, pmuCounters, size)) {
- unit.npuCycles = pmuCounters[0];
- unit.activeNpuCycles = pmuCounters[1];
- unit.idleNpuCycles = pmuCounters[2];
- unit.axi0reads = pmuCounters[3];
- unit.axi0writes = pmuCounters[4];
- unit.axi1reads = pmuCounters[5];
- }
- }
-
- if (timer->cap.cpu_cycles && timer->get_cpu_cycle_diff) {
- unit.cpuCycles = timer->get_cpu_cycle_diff(&start, &end);
+ if (end.num_counters != start.num_counters ||
+ true != end.initialised || true != start.initialised) {
+ printf_err("Invalid start or end counters\n");
+ return;
}
- if (timer->cap.duration_ms && timer->get_duration_ms) {
- unit.time = timer->get_duration_ms(&start, &end);
+ for (size_t i = 0; i < unit.counters.num_counters; ++i) {
+ if (unit.counters.counters[i].value < start.counters[i].value) {
+ warn("Overflow detected for %s\n", unit.counters.counters[i].name);
+ unit.counters.counters[i].value = 0;
+ } else {
+ unit.counters.counters[i].value -= start.counters[i].value;
+ }
}
this->m_series[name].emplace_back(unit);
diff --git a/source/profiler/include/Profiler.hpp b/source/profiler/include/Profiler.hpp
index 503d805..b8f9089 100644
--- a/source/profiler/include/Profiler.hpp
+++ b/source/profiler/include/Profiler.hpp
@@ -45,14 +45,7 @@ namespace app {
/** A single profiling unit definition. */
struct ProfilingUnit {
- uint64_t npuCycles = 0;
- uint64_t activeNpuCycles = 0;
- uint64_t idleNpuCycles = 0;
- uint64_t axi0writes = 0;
- uint64_t axi0reads = 0;
- uint64_t axi1reads = 0;
- uint64_t cpuCycles = 0;
- time_t time = 0;
+ pmu_counters counters;
};
/* A collection of profiling units. */
@@ -108,8 +101,8 @@ namespace app {
private:
ProfilingMap m_series; /* Profiling series map. */
- time_counter m_tstampSt{}; /* Container for a current starting timestamp. */
- time_counter m_tstampEnd{}; /* Container for a current ending timestamp. */
+ pmu_counters m_tstampSt{}; /* Container for a current starting timestamp. */
+ pmu_counters m_tstampEnd{}; /* Container for a current ending timestamp. */
hal_platform * m_pPlatform = nullptr; /* Platform pointer - to get the timer. */
bool m_started = false; /* Indicates profiler has been started. */
@@ -125,7 +118,7 @@ namespace app {
* @param[in] name Name for the profiling unit series to be
* appended to.
**/
- void AddProfilingUnit(time_counter start, time_counter end,
+ void AddProfilingUnit(pmu_counters start, pmu_counters end,
const std::string& name);
};