blob: b7c3483817b4f4ba59761e7e4dbdc4b8f8fc1fc3 [file] [log] [blame]
Moritz Pflanzer45634b42017-08-30 12:48:18 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
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:
44 /** Default constructor. */
Giorgio Arenace58a9f2017-10-31 17:59:17 +000045 MaliCounter(ScaleFactor scale_factor);
Moritz Pflanzer45634b42017-08-30 12:48:18 +010046
47 MaliCounter(const MaliCounter &) = delete;
48 MaliCounter &operator=(const MaliCounter &) = delete;
49
50 /** Default destructor */
51 ~MaliCounter();
52
53 std::string id() const override;
54 void start() override;
55 void stop() override;
56 MeasurementsMap measurements() const override;
57
58private:
59 void init();
60 void term();
61
62 void sample_counters();
63 void wait_next_event();
64 const uint32_t *get_counters() const;
65 const uint32_t *get_counters(mali_userspace::MaliCounterBlockName block, int core = -1) const;
66 int find_counter_index_by_name(mali_userspace::MaliCounterBlockName block, const char *name);
67
Anthony Barbierab14c152017-11-09 10:29:59 +000068 std::map<std::string, Measurement> _counters{};
Moritz Pflanzer45634b42017-08-30 12:48:18 +010069
70 struct core_counters
71 {
72 std::string name;
73 std::map<int, uint64_t> values;
74 std::string unit;
75 };
76
77 std::map<std::string, core_counters> _core_counters{};
78 uint64_t _start_time{ 0 };
79 uint64_t _stop_time{ 0 };
80
81 const char *const _device
82 { "/dev/mali0"
83 };
84 int _num_cores{ 0 };
85 uint32_t _hw_ver{ 0 };
86 int _buffer_count{ 16 };
87 size_t _buffer_size{ 0 };
88 uint8_t *_sample_data{ nullptr };
89 uint64_t _timestamp{ 0 };
90 const char *const *_names_lut
91 {
92 nullptr
93 };
94 std::vector<uint32_t> _raw_counter_buffer{};
95 std::vector<unsigned int> _core_index_remap{};
96 int _fd{ -1 };
97 int _hwc_fd{ -1 };
Giorgio Arenace58a9f2017-10-31 17:59:17 +000098 int _scale_factor{};
Moritz Pflanzer45634b42017-08-30 12:48:18 +010099};
100} // namespace framework
101} // namespace test
102} // namespace arm_compute
103#endif /* ARM_COMPUTE_TEST_MALI_COUNTER */