]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Improve accuracy of PMC sampling frequency
authorJonathan T. Looney <jtl@FreeBSD.org>
Mon, 16 Nov 2015 15:22:15 +0000 (15:22 +0000)
committerJonathan T. Looney <jtl@FreeBSD.org>
Mon, 16 Nov 2015 15:22:15 +0000 (15:22 +0000)
commit5eaa6f01f52942e7809325d6aef8b87693376305
treed707f1385b453deb1c4814c7e31352336c2c6623
parente64ba55dd29fe8ff5cd38fa614ad1a1b36effa87
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
sys/dev/hwpmc/hwpmc_mod.c