blob: e4e100c472f77e1a5c263e6e2b70f06e9c0e4789 [file] [log] [blame]
Jens Elofssona9817a12021-05-18 11:30:35 +02001/*
Kristofer Jonsson265b7eb2022-09-29 12:01:28 +02002 * SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
Jens Elofssona9817a12021-05-18 11:30:35 +02003 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "ethosu_monitor.hpp"
Anton Moberg07cf70b2021-07-07 11:08:17 +020020#include "ethosu_log.h"
Kristofer Jonssone4f09e52021-11-26 16:13:58 +010021#include <inttypes.h>
Jens Elofssona9817a12021-05-18 11:30:35 +020022#include <stdio.h>
23
Kristofer Jonsson36426952022-12-05 14:50:45 +010024EthosUMonitor::EthosUMonitor(Backend __backend, bool _merge) : backend(__backend), merge(_merge) {}
Jens Elofssona9817a12021-05-18 11:30:35 +020025
26void EthosUMonitor::monitorSample(ethosu_driver *drv) {
Kristofer Jonsson265b7eb2022-09-29 12:01:28 +020027 switch (backend) {
28 case EVENT_RECORDER: {
Kristofer Jonsson36426952022-12-05 14:50:45 +010029 const EthosuEventRecord record = {ETHOSU_PMU_Get_CCNTR(drv),
30 ETHOSU_PMU_Get_QREAD(drv),
31 ETHOSU_PMU_Get_STATUS(drv),
32 {{ethosuEventIds[0], ETHOSU_PMU_Get_EVCNTR(drv, 0)},
33 {ethosuEventIds[1], ETHOSU_PMU_Get_EVCNTR(drv, 1)},
34 {ethosuEventIds[2], ETHOSU_PMU_Get_EVCNTR(drv, 2)},
35 {ethosuEventIds[3], ETHOSU_PMU_Get_EVCNTR(drv, 3)}}};
36
37 // Merge records if qread or status has not changed
38 if (merge && prevRecord.qread == record.qread && prevRecord.status == record.status) {
39 mergeCount++;
40 break;
41 }
42
43 prevRecord.qread = record.qread;
44 prevRecord.status = record.status;
Kristofer Jonsson265b7eb2022-09-29 12:01:28 +020045
46 EventRecordData(EventID(EventLevelDetail, EthosuEventComponentNo, 0), &record, sizeof(record));
47 break;
48 }
49 case PRINTF:
50 default:
51 for (size_t i = 0; i < numEvents; i++) {
52 LOG("ethosu_pmu_cntr%zd : %" PRIu32 "\n", i, ETHOSU_PMU_Get_EVCNTR(drv, 0));
Jens Elofssona9817a12021-05-18 11:30:35 +020053 }
54 }
55}
56
57void EthosUMonitor::release(ethosu_driver *drv) {
58 ETHOSU_PMU_Disable(drv);
59}
Kristofer Jonsson36426952022-12-05 14:50:45 +010060
61size_t EthosUMonitor::getMergeCount() const {
62 return mergeCount;
63}