@@ -191,8 +191,8 @@ MaliHWInfo get_mali_hw_info(const char *path)
191191 hw_info.p_value = props.minor_revision ;
192192 for (uint32_t i = 0 ; i < props.num_core_groups ; i++)
193193 hw_info.core_mask |= props.core_mask [i];
194- hw_info.mp_count = __builtin_popcountll (hw_info.core_mask );
195- // hw_info.l2_slices = props.l2_slices;
194+ hw_info.mp_count = __builtin_popcountll (hw_info.core_mask );
195+ hw_info.l2_slices = props.l2_slices ;
196196
197197 close (fd);
198198 }
@@ -204,20 +204,15 @@ MaliHWInfo get_mali_hw_info(const char *path)
204204
205205MaliCounter::MaliCounter ()
206206{
207- _counters =
208- {
209- {" GPU_ACTIVE" , Measurement (0 , " cycles" )},
210- {" JS0_JOBS" , Measurement (0 , " jobs" )},
211- {" JS1_JOBS" , Measurement (0 , " jobs" )},
212- {" L2_READ_LOOKUP" , Measurement (0 , " cache lookups" )},
213- {" L2_EXT_READ" , Measurement (0 , " transactions" )},
214- {" L2_EXT_AR_STALL" , Measurement (0 , " stall cycles" )},
215- {" L2_WRITE_LOOKUP" , Measurement (0 , " cache lookups" )},
216- {" L2_EXT_WRITE" , Measurement (0 , " transactions" )},
217- {" L2_EXT_W_STALL" , Measurement (0 , " stall cycles" )},
218- {" L2_EXT_READ_BEATS" , Measurement (0 , " bus cycles" )},
219- {" L2_EXT_WRITE_BEATS" , Measurement (0 , " bus cycles" )}
220- };
207+ for (const auto &jm_counter : _jm_counter_names)
208+ {
209+ _counters.emplace (std::make_pair (jm_counter.first , Measurement{0 , jm_counter.second }));
210+ }
211+
212+ for (const auto &mmu_counter : _mmu_counter_names)
213+ {
214+ _counters.emplace (std::make_pair (mmu_counter.first , Measurement{0 , mmu_counter.second }));
215+ }
221216
222217 init ();
223218}
@@ -233,7 +228,8 @@ void MaliCounter::init()
233228
234229 MaliHWInfo hw_info = get_mali_hw_info (_device);
235230
236- _num_cores = hw_info.mp_count ;
231+ _num_cores = hw_info.mp_count ;
232+ _num_l2_slices = hw_info.l2_slices ;
237233
238234 _fd = open (_device, O_RDWR | O_CLOEXEC | O_NONBLOCK); // NOLINT
239235
@@ -443,23 +439,30 @@ const uint32_t *MaliCounter::get_counters() const
443439 return _raw_counter_buffer.data ();
444440}
445441
446- const uint32_t *MaliCounter::get_counters (mali_userspace::MaliCounterBlockName block, int core ) const
442+ const uint32_t *MaliCounter::get_counters (mali_userspace::MaliCounterBlockName block, int index ) const
447443{
448444 switch (block)
449445 {
450446 case mali_userspace::MALI_NAME_BLOCK_JM:
451447 return _raw_counter_buffer.data () + mali_userspace::MALI_NAME_BLOCK_SIZE * 0 ;
452448 case mali_userspace::MALI_NAME_BLOCK_MMU:
453- return _raw_counter_buffer.data () + mali_userspace::MALI_NAME_BLOCK_SIZE * 2 ;
449+ if (index < 0 || index >= _num_l2_slices)
450+ {
451+ throw std::runtime_error (" Invalid slice number." );
452+ }
453+
454+ // If an MMU counter is selected, index refers to the MMU slice
455+ return _raw_counter_buffer.data () + mali_userspace::MALI_NAME_BLOCK_SIZE * (2 + index);
454456 case mali_userspace::MALI_NAME_BLOCK_TILER:
455457 return _raw_counter_buffer.data () + mali_userspace::MALI_NAME_BLOCK_SIZE * 1 ;
456458 default :
457- if (core < 0 )
459+ if (index < 0 || index >= _num_cores )
458460 {
459461 throw std::runtime_error (" Invalid core number." );
460462 }
461463
462- return _raw_counter_buffer.data () + mali_userspace::MALI_NAME_BLOCK_SIZE * (3 + _core_index_remap[core]);
464+ // If a shader core counter is selected, index refers to the core index
465+ return _raw_counter_buffer.data () + mali_userspace::MALI_NAME_BLOCK_SIZE * (2 + _num_l2_slices + _core_index_remap[index]);
463466 }
464467}
465468
@@ -491,19 +494,29 @@ void MaliCounter::stop()
491494 wait_next_event ();
492495
493496 const uint32_t *jm_counter = get_counters (mali_userspace::MALI_NAME_BLOCK_JM);
494- _counters.at (" GPU_ACTIVE" ) = Measurement (jm_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_JM, " GPU_ACTIVE" )], _counters.at (" GPU_ACTIVE" ).unit ());
495- _counters.at (" JS0_JOBS" ) = Measurement (jm_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_JM, " JS0_JOBS" )], _counters.at (" JS0_JOBS" ).unit ());
496- _counters.at (" JS1_JOBS" ) = Measurement (jm_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_JM, " JS1_JOBS" )], _counters.at (" JS1_JOBS" ).unit ());
497-
498- const uint32_t *mmu_counter = get_counters (mali_userspace::MALI_NAME_BLOCK_MMU);
499- _counters.at (" L2_READ_LOOKUP" ) = Measurement (mmu_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_MMU, " L2_READ_LOOKUP" )], _counters.at (" L2_READ_LOOKUP" ).unit ());
500- _counters.at (" L2_EXT_READ" ) = Measurement (mmu_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_MMU, " L2_EXT_READ" )], _counters.at (" L2_EXT_READ" ).unit ());
501- _counters.at (" L2_EXT_AR_STALL" ) = Measurement (mmu_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_MMU, " L2_EXT_AR_STALL" )], _counters.at (" L2_EXT_AR_STALL" ).unit ());
502- _counters.at (" L2_WRITE_LOOKUP" ) = Measurement (mmu_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_MMU, " L2_WRITE_LOOKUP" )], _counters.at (" L2_WRITE_LOOKUP" ).unit ());
503- _counters.at (" L2_EXT_WRITE" ) = Measurement (mmu_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_MMU, " L2_EXT_WRITE" )], _counters.at (" L2_EXT_WRITE" ).unit ());
504- _counters.at (" L2_EXT_W_STALL" ) = Measurement (mmu_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_MMU, " L2_EXT_W_STALL" )], _counters.at (" L2_EXT_W_STALL" ).unit ());
505- _counters.at (" L2_EXT_READ_BEATS" ) = Measurement (mmu_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_MMU, " L2_EXT_READ_BEATS" )], _counters.at (" L2_EXT_READ_BEATS" ).unit ());
506- _counters.at (" L2_EXT_WRITE_BEATS" ) = Measurement (mmu_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_MMU, " L2_EXT_WRITE_BEATS" )], _counters.at (" L2_EXT_WRITE_BEATS" ).unit ());
497+
498+ for (const auto &jm_counter_name : _jm_counter_names)
499+ {
500+ _counters.at (jm_counter_name.first ) = Measurement (jm_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_JM, jm_counter_name.first )], _counters.at (jm_counter_name.first ).unit ());
501+ }
502+
503+ // We have one MMU counter per L2 cache slice
504+ std::vector<const uint32_t *> mmu_counters;
505+ for (int i = 0 ; i < _num_l2_slices; i++)
506+ {
507+ mmu_counters.push_back (get_counters (mali_userspace::MALI_NAME_BLOCK_MMU, i));
508+ }
509+
510+ // We iterate over counter names and accumulate data from all L2 cache slices
511+ for (const auto &mmu_counter_name : _mmu_counter_names)
512+ {
513+ uint32_t mmu_counter_value = 0 ;
514+ for (const auto &mmu_counter : mmu_counters)
515+ {
516+ mmu_counter_value += mmu_counter[find_counter_index_by_name (mali_userspace::MALI_NAME_BLOCK_MMU, mmu_counter_name.first )];
517+ }
518+ _counters.at (mmu_counter_name.first ) = Measurement (mmu_counter_value, _counters.at (mmu_counter_name.first ).unit ());
519+ }
507520
508521 _stop_time = _timestamp;
509522}
0 commit comments