Compute Library
 21.05
MaliCounter.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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 
34 namespace arm_compute
35 {
36 namespace test
37 {
38 namespace framework
39 {
40 /** Instrument implementation for mali hw counters. */
41 class MaliCounter : public Instrument
42 {
43 public:
44  /** Default constructor.
45  *
46  * @param[in] scale_factor Measurement scale factor;
47  */
48  MaliCounter(ScaleFactor scale_factor);
49 
50  /** Prevent instances of this class from being copy constructed */
51  MaliCounter(const MaliCounter &) = delete;
52  /** Prevent instances of this class from being copied */
53  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 
63 private:
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 
73  std::map<std::string, Measurement> _counters{};
74 
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  };
89  uint32_t _num_cores{ 0 };
90  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 };
103  int _scale_factor{};
104 };
105 } // namespace framework
106 } // namespace test
107 } // namespace arm_compute
108 #endif /* ARM_COMPUTE_TEST_MALI_COUNTER */
void stop() override
Stop measuring.
std::string id() const override
Identifier for the instrument.
MeasurementsMap measurements() const override
Return the latest measurements.
Copyright (c) 2017-2021 Arm Limited.
MaliCounter(ScaleFactor scale_factor)
Default constructor.
Instrument implementation for mali hw counters.
Definition: MaliCounter.h:41
const char * name
Interface for classes that can be used to measure performance.
Definition: Instrument.h:50
void start() override
Start measuring.
std::map< std::string, Measurement > MeasurementsMap
Map of measurements.
Definition: Instrument.h:109
MaliCounter & operator=(const MaliCounter &)=delete
Prevent instances of this class from being copied.