Software Tuning, Performance Optimization & Platform Monitoring
Discussion regarding monitoring and software tuning methodologies, Performance Monitoring Unit (PMU) of Intel microprocessors, and platform updating.

Handling Overflows in Programmable Counters

Ravitheja_G_
Beginner
428 Views

Hi Guys,

I am new to Programmable counters and i need some advice with handling overflows , i wrote a small kernel module to collect stats for each thread running on the cores and it is working well, i need some advice on how i can handle when the counters overflow.

I see that i can Performance Monitoring Interrupts when the overflow happens , it would be helpful if someone can explain how i use these interrupts to reset the counters the counters to zero once they reach a certain value so i can avoid overflows and get accurate readings

Thanks and Regards,
Ravi

0 Kudos
1 Solution
McCalpinJohn
Honored Contributor III
428 Views

The required approach depends on what you are trying to measure. 

If you want measurements by core for any running process, and you can guarantee that the counters cannot increment more than pow(2,48) times between measurements, then you simply disable overflows (by clearing bit 20 in each of the IA32_PERFEVTSEL MSRs) and leave the counters running free.   If a measurement looks smaller than a previous measurement, then add pow(2,48) to the difference to correct for the wrap-around.

View solution in original post

0 Kudos
2 Replies
McCalpinJohn
Honored Contributor III
429 Views

The required approach depends on what you are trying to measure. 

If you want measurements by core for any running process, and you can guarantee that the counters cannot increment more than pow(2,48) times between measurements, then you simply disable overflows (by clearing bit 20 in each of the IA32_PERFEVTSEL MSRs) and leave the counters running free.   If a measurement looks smaller than a previous measurement, then add pow(2,48) to the difference to correct for the wrap-around.

0 Kudos
Ravitheja_G_
Beginner
428 Views

Thank you , That helps a lot

0 Kudos
Reply