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

Handling Overflows in Programmable Counters

Ravitheja_G_
Beginner
179 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
Black Belt
179 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

2 Replies
McCalpinJohn
Black Belt
180 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.

Ravitheja_G_
Beginner
179 Views

Thank you , That helps a lot

Reply