History log of /freebsd-10-stable/sys/dev/hwpmc/hwpmc_mod.c
Revision Date Author Comments
# 325757 13-Nov-2017 kib

MFC r325671:
Check that the pmc index is less than the number of hardware PMCs,
instead of asserting the condition.


# 310063 14-Dec-2016 avg

MFC r308480: pmc_process_csw_out: ignore deleted counters


# 300060 17-May-2016 pfg

MFC r298931, r298981, r299375:

Minor spelling fixes in:
sys/dev, sys/sys

Many of these have user-visible strings.


# 296730 12-Mar-2016 kib

MFC r295352:
Do not call vn_fullpath(9) (through the pmc_getfilename() wrapper)
when its result is immediately ignored, i.e. for kernel processes
forked from the user process. Do not test for non-null before freeing
string.


# 294046 14-Jan-2016 jtl

MFC r290811:
Fix hwpmc "stalled" behavior

Currently, there is a single pm_stalled flag that tracks whether a
performance monitor was "stalled" due to insufficent ring buffer
space for samples. However, because the same performance monitor
can run on multiple processes or threads at the same time, a single
pm_stalled flag that impacts them all seems insufficient.

In particular, you can hit corner cases where the code fails to stop
performance monitors during a context switch out, because it thinks
the performance monitor is already stopped. However, in reality,
it may be that only the monitor running on a different CPU was stalled.

This patch attempts to fix that behavior by tracking on a per-CPU basis
whether a PM desires to run and whether it is "stalled". This lets the
code make better decisions about when to stop PMs and when to try to
restart them. Ideally, we should avoid the case where the code fails
to stop a PM during a context switch out.

MFC r290813:
Optimizations to the way hwpmc gathers user callchains

Changes to the code to gather user stacks:
* Delay setting pmc_cpumask until we actually have the stack.
* When recording user stack traces, only walk the portion of the ring
that should have samples for us.

MFC r290929:
Change the driver stats to what they really are: unsigned values.

When pmcstat exits after some samples were dropped, give the user an
idea of how many were lost. (Granted, these are global numbers, but
they may still help quantify the scope of the loss.)

MFC r290930:
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.

MFC r291016:
Support a wider history counter in pmcstat(8) gmon output

pmcstat(8) contains an option to output sampling data in a gmon format
compatible with gprof(1). Currently, it uses the default histcounter,
which is an (unsigned short). With large sets of sampling data, it
is possible to overflow the maximum value provided by an (unsigned
short).

This change adds the -e argument to pmcstat. If -e and -g are both
specified, pmcstat will use a histcounter type of uint64_t.

MFC r291017:
Fix the date on the pmcstat(8) man page from r291016.


# 288499 02-Oct-2015 vangyzen

MFC r283924

Provide vnode in memory map info for files on tmpfs

When providing memory map information to userland, populate the vnode pointer
for tmpfs files. Set the memory mapping to appear as a vnode type, to match
FreeBSD 9 behavior.

This fixes the use of tmpfs files with the dtrace pid provider,
procstat -v, procfs, linprocfs, pmc (pmcstat), and ptrace (PT_VM_ENTRY).

Submitted by: Eric Badger <eric@badgerio.us> (initial revision)
Obtained from: Dell Inc.
PR: 198431


# 283886 01-Jun-2015 jhb

MFC 283123:
Fix two bugs that could result in PMC sampling effectively stopping.
In both cases, the the effect of the bug was that a very small positive
number was written to the counter. This means that a large number of
events needed to occur before the next sampling interrupt would trigger.
Even with very frequently occurring events like clock cycles wrapping all
the way around could take a long time. Both bugs occurred when updating
the saved reload count for an outgoing thread on a context switch.

First, the counter-independent code compares the current reload count
against the count set when the thread switched in and generates a delta
to apply to the saved count. If this delta causes the reload counter
to go negative, it would add a full reload interval to wrap it around to
a positive value. The fix is to add the full reload interval if the
resulting counter is zero.

Second, occasionally the raw counter value read during a context switch
has actually wrapped, but an interrupt has not yet triggered. In this
case the existing logic would return a very large reload count (e.g.
2^48 - 2 if the counter had overflowed by a count of 2). This was seen
both for fixed-function and programmable counters on an E5-2643.
Workaround this case by returning a reload count of zero.

PR: 198149
Sponsored by: Norse Corp, Inc.


# 283884 01-Jun-2015 jhb

MFC 282641,282658:
- Move hwpmc(4) debugging code under a new HWPMC_DEBUG option instead of
the broader DEBUG option.
- Convert hwpmc(4) debug printfs over to KTR.

Sponsored by: Norse Corp, Inc.


# 280455 24-Mar-2015 rrs

MFC of r277177 and r279894 with the fixes for the PMC for Haswell.

Sponsored by: Netflix Inc.


# 278813 15-Feb-2015 emaste

Clamp too large hwpmc callchaindepth to maximum

If the depth requested by the user is too large, it's better to provide
the maximum than the smaller default.

MFC of: r274766
Sponsored by: The FreeBSD Foundation


# 274155 05-Nov-2014 markj

MFC r273236:
Use pmc_destroy_pmc_descriptor() to actually free the pmc, which is
consistent with pmc_destroy_owner_descriptor(). Also be sure to destroy
PMCs if a process exits or execs without explicitly releasing them.


# 288499 02-Oct-2015 vangyzen

MFC r283924

Provide vnode in memory map info for files on tmpfs

When providing memory map information to userland, populate the vnode pointer
for tmpfs files. Set the memory mapping to appear as a vnode type, to match
FreeBSD 9 behavior.

This fixes the use of tmpfs files with the dtrace pid provider,
procstat -v, procfs, linprocfs, pmc (pmcstat), and ptrace (PT_VM_ENTRY).

Submitted by: Eric Badger <eric@badgerio.us> (initial revision)
Obtained from: Dell Inc.
PR: 198431


# 283886 01-Jun-2015 jhb

MFC 283123:
Fix two bugs that could result in PMC sampling effectively stopping.
In both cases, the the effect of the bug was that a very small positive
number was written to the counter. This means that a large number of
events needed to occur before the next sampling interrupt would trigger.
Even with very frequently occurring events like clock cycles wrapping all
the way around could take a long time. Both bugs occurred when updating
the saved reload count for an outgoing thread on a context switch.

First, the counter-independent code compares the current reload count
against the count set when the thread switched in and generates a delta
to apply to the saved count. If this delta causes the reload counter
to go negative, it would add a full reload interval to wrap it around to
a positive value. The fix is to add the full reload interval if the
resulting counter is zero.

Second, occasionally the raw counter value read during a context switch
has actually wrapped, but an interrupt has not yet triggered. In this
case the existing logic would return a very large reload count (e.g.
2^48 - 2 if the counter had overflowed by a count of 2). This was seen
both for fixed-function and programmable counters on an E5-2643.
Workaround this case by returning a reload count of zero.

PR: 198149
Sponsored by: Norse Corp, Inc.


# 283884 01-Jun-2015 jhb

MFC 282641,282658:
- Move hwpmc(4) debugging code under a new HWPMC_DEBUG option instead of
the broader DEBUG option.
- Convert hwpmc(4) debug printfs over to KTR.

Sponsored by: Norse Corp, Inc.


# 280455 24-Mar-2015 rrs

MFC of r277177 and r279894 with the fixes for the PMC for Haswell.

Sponsored by: Netflix Inc.


# 278813 15-Feb-2015 emaste

Clamp too large hwpmc callchaindepth to maximum

If the depth requested by the user is too large, it's better to provide
the maximum than the smaller default.

MFC of: r274766
Sponsored by: The FreeBSD Foundation


# 274155 05-Nov-2014 markj

MFC r273236:
Use pmc_destroy_pmc_descriptor() to actually free the pmc, which is
consistent with pmc_destroy_owner_descriptor(). Also be sure to destroy
PMCs if a process exits or execs without explicitly releasing them.