Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 1 | /* |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 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: |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 44 | /** Default constructor. |
| 45 | * |
| 46 | * @param[in] scale_factor Measurement scale factor; |
| 47 | */ |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 48 | MaliCounter(ScaleFactor scale_factor); |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 49 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 50 | /** Prevent instances of this class from being copy constructed */ |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 51 | MaliCounter(const MaliCounter &) = delete; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 52 | /** Prevent instances of this class from being copied */ |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 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 | |
Anthony Barbier | ab14c15 | 2017-11-09 10:29:59 +0000 | [diff] [blame] | 73 | std::map<std::string, Measurement> _counters{}; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 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 | int _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 }; |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 103 | int _scale_factor{}; |
Moritz Pflanzer | 45634b4 | 2017-08-30 12:48:18 +0100 | [diff] [blame] | 104 | }; |
| 105 | } // namespace framework |
| 106 | } // namespace test |
| 107 | } // namespace arm_compute |
| 108 | #endif /* ARM_COMPUTE_TEST_MALI_COUNTER */ |