freebsd-dev/sys/dev/hwpmc
Jonathan T. Looney 5eaa6f01f5 Improve accuracy of PMC sampling frequency
The code tracks a counter which is the number of events until the next
sample. On context switch in, it loads the saved counter. On context
switch out, it tries to calculate a new saved counter.

Problems:

1. The saved counter was shared by all threads in a process. However, this
means that all threads would be initially loaded with the same saved
counter. However, that could result in sampling more often than once every
X number of events.

2. The calculation to determine a new saved counter was backwards. It
added when it should have subtracted, and subtracted when it should have
added. Assume a single-threaded process with a reload count of 1000 events.
Assuming the counter on context switch in was 100 and the counter on context
switch out was 50 (meaning the thread has "consumed" 50 more events), the
code would calculate a new saved counter of 150 (instead of the proper 50).

Fix:

1. As soon as the saved counter is used to initialize a monitor for a
thread on context switch in, set the saved counter to the reload count.
That way, subsequent threads to use the saved counter will get the full
reload count, assuring we sample at least once every X number of events
(across all threads).

2. Change the calculation of the saved counter. Due to the change to the
saved counter in #1, we simply need to add (modulo the reload count) the
remaining counter time we retrieve from the CPU when a thread is context
switched out.

Differential Revision:	https://reviews.freebsd.org/D4122
Approved by:	gnn (mentor)
MFC after:	1 month
Sponsored by:	Juniper Networks
2015-11-16 15:22:15 +00:00
..
hwpmc_amd.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_amd.h
hwpmc_arm64_md.c Add Performance Monitoring Counters support for AArch64. 2015-05-19 15:25:47 +00:00
hwpmc_arm64.c Add Performance Monitoring Counters support for AArch64. 2015-05-19 15:25:47 +00:00
hwpmc_arm64.h Add Performance Monitoring Counters support for AArch64. 2015-05-19 15:25:47 +00:00
hwpmc_arm.c Rather than defining our own magic checks here use INKERNEL() for 2015-03-27 08:47:16 +00:00
hwpmc_armv7.c o Rework ARMv7 events list using aliases - same way as we have for arm64. 2015-06-10 12:42:30 +00:00
hwpmc_armv7.h o Rework ARMv7 events list using aliases - same way as we have for arm64. 2015-06-10 12:42:30 +00:00
hwpmc_core.c Fix two bugs that could result in PMC sampling effectively stopping. 2015-05-19 19:15:19 +00:00
hwpmc_core.h Remove some prototypes for undefined functions. 2014-05-15 21:19:13 +00:00
hwpmc_e500.c Convert remaining hwpmc(4) debug printfs over to KTR to unbreak the build 2015-05-09 09:21:59 +00:00
hwpmc_intel.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_logging.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_mips24k.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_mips74k.c Convert remaining hwpmc(4) debug printfs over to KTR to unbreak the build 2015-05-09 09:21:59 +00:00
hwpmc_mips.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_mod.c Improve accuracy of PMC sampling frequency 2015-11-16 15:22:15 +00:00
hwpmc_mpc7xxx.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_octeon.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_pentium.c
hwpmc_pentium.h
hwpmc_piv.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_piv.h
hwpmc_powerpc.c Implement hwpmc(4) for Freescale e500 core. 2015-04-18 21:39:17 +00:00
hwpmc_powerpc.h Implement hwpmc(4) for Freescale e500 core. 2015-04-18 21:39:17 +00:00
hwpmc_ppc970.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_ppro.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_ppro.h
hwpmc_soft.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_soft.h
hwpmc_sparc64.c
hwpmc_tsc.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_tsc.h
hwpmc_uncore.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_uncore.h Remove some prototypes for undefined functions. 2014-05-15 21:19:13 +00:00
hwpmc_x86.c Update the hwpmc driver to have the new type HASWELL_XEON. Also 2015-01-14 12:46:58 +00:00
hwpmc_xscale.c Convert hwpmc(4) debug printfs over to KTR. 2015-05-08 19:40:00 +00:00
hwpmc_xscale.h
pmc_events.h Now that we can detect the Cortex-A8 properly, fix the event list 2015-10-14 17:20:19 +00:00