blob: c2d1849423941d1829d450923ee695b1bd515ad6 [file] [log] [blame]
Moritz Pflanzer45634b42017-08-30 12:48:18 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2019 Arm Limited.
Moritz Pflanzer45634b42017-08-30 12:48:18 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef ARM_COMPUTE_TEST_MALI_COUNTER
25#define ARM_COMPUTE_TEST_MALI_COUNTER
26
27#include "Instrument.h"
28#include "Measurement.h"
29#include "hwc.hpp"
30
31#include <map>
32#include <vector>
33
34namespace arm_compute
35{
36namespace test
37{
38namespace framework
39{
40/** Instrument implementation for mali hw counters. */
41class MaliCounter : public Instrument
42{
43public:
Alex Gildayc357c472018-03-21 13:54:09 +000044 /** Default constructor.
45 *
46 * @param[in] scale_factor Measurement scale factor;
47 */
Giorgio Arenace58a9f2017-10-31 17:59:17 +000048 MaliCounter(ScaleFactor scale_factor);
Moritz Pflanzer45634b42017-08-30 12:48:18 +010049
Alex Gildayc357c472018-03-21 13:54:09 +000050 /** Prevent instances of this class from being copy constructed */
Moritz Pflanzer45634b42017-08-30 12:48:18 +010051 MaliCounter(const MaliCounter &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000052 /** Prevent instances of this class from being copied */
Moritz Pflanzer45634b42017-08-30 12:48:18 +010053 MaliCounter &operator=(const MaliCounter &) = delete;
54
55 /** Default destructor */
56 ~MaliCounter();
57
58 std::string id() const override;
59 void start() override;
60 void stop() override;
61 MeasurementsMap measurements() const override;
62
63private:
64 void init();
65 void term();
66
67 void sample_counters();
68 void wait_next_event();
69 const uint32_t *get_counters() const;
70 const uint32_t *get_counters(mali_userspace::MaliCounterBlockName block, int core = -1) const;
71 int find_counter_index_by_name(mali_userspace::MaliCounterBlockName block, const char *name);
72
Anthony Barbierab14c152017-11-09 10:29:59 +000073 std::map<std::string, Measurement> _counters{};
Moritz Pflanzer45634b42017-08-30 12:48:18 +010074
75 struct core_counters
76 {
77 std::string name;
78 std::map<int, uint64_t> values;
79 std::string unit;
80 };
81
82 std::map<std::string, core_counters> _core_counters{};
83 uint64_t _start_time{ 0 };
84 uint64_t _stop_time{ 0 };
85
86 const char *const _device
87 { "/dev/mali0"
88 };
Michalis Spyroufae513c2019-10-16 17:41:33 +010089 uint32_t _num_cores{ 0 };
Moritz Pflanzer45634b42017-08-30 12:48:18 +010090 uint32_t _hw_ver{ 0 };
91 int _buffer_count{ 16 };
92 size_t _buffer_size{ 0 };
93 uint8_t *_sample_data{ nullptr };
94 uint64_t _timestamp{ 0 };
95 const char *const *_names_lut
96 {
97 nullptr
98 };
99 std::vector<uint32_t> _raw_counter_buffer{};
100 std::vector<unsigned int> _core_index_remap{};
101 int _fd{ -1 };
102 int _hwc_fd{ -1 };
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000103 int _scale_factor{};
Moritz Pflanzer45634b42017-08-30 12:48:18 +0100104};
105} // namespace framework
106} // namespace test
107} // namespace arm_compute
108#endif /* ARM_COMPUTE_TEST_MALI_COUNTER */