From 265b7eb223dc23864730f3328c9a2b877cbd5a07 Mon Sep 17 00:00:00 2001 From: Kristofer Jonsson Date: Thu, 29 Sep 2022 12:01:28 +0200 Subject: Update Event Monitor Add cycle counter, QREAD and STATUS to Event Monitor record. Change-Id: I9c225558a9d46b05fe322270b4a921ead6bb0233 --- lib/ethosu_monitor/include/ethosu_monitor.hpp | 20 +++++++++++++--- lib/ethosu_monitor/src/ethosu_monitor.cpp | 33 +++++++++++++++------------ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/ethosu_monitor/include/ethosu_monitor.hpp b/lib/ethosu_monitor/include/ethosu_monitor.hpp index c2d0908..c76ee8b 100644 --- a/lib/ethosu_monitor/include/ethosu_monitor.hpp +++ b/lib/ethosu_monitor/include/ethosu_monitor.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Arm Limited. All rights reserved. + * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates * * SPDX-License-Identifier: Apache-2.0 * @@ -32,7 +32,7 @@ class EthosUMonitor { public: enum Backend { PRINTF, EVENT_RECORDER }; - EthosUMonitor(std::vector eventRecordIds, Backend backend = PRINTF); + EthosUMonitor(Backend backend = PRINTF); template void configure(ethosu_driver *drv, const T &eventIds) { @@ -50,7 +50,10 @@ public: ETHOSU_PMU_CNTR_Enable(drv, 1 << i); } + ETHOSU_PMU_CNTR_Enable(drv, ETHOSU_PMU_CCNT_Msk); + ETHOSU_PMU_EVCNTR_ALL_Reset(drv); + ETHOSU_PMU_CYCCNT_Reset(drv); } void release(ethosu_driver *drv); @@ -58,9 +61,20 @@ public: void monitorSample(ethosu_driver *drv); private: + struct EthosuEventRecord { + uint64_t cycleCount; + uint32_t qread; + uint32_t status; + struct { + uint32_t eventConfig; + uint32_t eventCount; + } event[ETHOSU_PMU_NCOUNTERS]; + }; + + static constexpr int32_t EthosuEventComponentNo = 0x00; + ethosu_pmu_event_type ethosuEventIds[ETHOSU_PMU_NCOUNTERS]; size_t numEvents; - std::vector eventRecordIds; Backend backend; }; diff --git a/lib/ethosu_monitor/src/ethosu_monitor.cpp b/lib/ethosu_monitor/src/ethosu_monitor.cpp index 0fe4b44..d13e6c2 100644 --- a/lib/ethosu_monitor/src/ethosu_monitor.cpp +++ b/lib/ethosu_monitor/src/ethosu_monitor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Arm Limited. All rights reserved. + * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates * * SPDX-License-Identifier: Apache-2.0 * @@ -21,21 +21,26 @@ #include #include -EthosUMonitor::EthosUMonitor(std::vector __eventRecordIds, Backend __backend) : - eventRecordIds(__eventRecordIds), backend(__backend) {} +EthosUMonitor::EthosUMonitor(Backend __backend) : backend(__backend) {} void EthosUMonitor::monitorSample(ethosu_driver *drv) { - // Fetch events - uint32_t eventCount[ETHOSU_PMU_NCOUNTERS] = {0}; - for (size_t i = 0; i < numEvents; i++) { - eventCount[i] = ETHOSU_PMU_Get_EVCNTR(drv, i); - switch (backend) { - case EVENT_RECORDER: - EventRecord2(eventRecordIds[i], ethosuEventIds[i], eventCount[i]); - break; - case PRINTF: - default: - LOG("ethosu_pmu_cntr%zd : %" PRIu32 "\n", i, eventCount[i]); + switch (backend) { + case EVENT_RECORDER: { + EthosuEventRecord record = {ETHOSU_PMU_Get_CCNTR(drv), + ETHOSU_PMU_Get_QREAD(drv), + ETHOSU_PMU_Get_STATUS(drv), + {{ethosuEventIds[0], ETHOSU_PMU_Get_EVCNTR(drv, 0)}, + {ethosuEventIds[1], ETHOSU_PMU_Get_EVCNTR(drv, 1)}, + {ethosuEventIds[2], ETHOSU_PMU_Get_EVCNTR(drv, 2)}, + {ethosuEventIds[3], ETHOSU_PMU_Get_EVCNTR(drv, 3)}}}; + + EventRecordData(EventID(EventLevelDetail, EthosuEventComponentNo, 0), &record, sizeof(record)); + break; + } + case PRINTF: + default: + for (size_t i = 0; i < numEvents; i++) { + LOG("ethosu_pmu_cntr%zd : %" PRIu32 "\n", i, ETHOSU_PMU_Get_EVCNTR(drv, 0)); } } } -- cgit v1.2.1