Fix INVARIANTS debug code in HWPMC

When HWPMC stops sampling, ps_pmc may be freed before samples
are processed. In such situation treat PMC as stopped.
Add "ifdef" to fix build without INVARIANTS code.

Submitted by: Michal Mazur <mkm@semihalf.com>
Obtained from: Semihalf
Sponsored by: Stormshield, Netgate
Differential revision: https://reviews.freebsd.org/D10912
This commit is contained in:
Zbigniew Bodek 2017-06-13 18:53:56 +00:00
parent 95ca4f5a0e
commit 6cb40391c4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=319913

View File

@ -4224,7 +4224,8 @@ pmc_capture_user_callchain(int cpu, int ring, struct trapframe *tf)
ps_end = psb->ps_write;
do {
#ifdef INVARIANTS
if (ps->ps_pmc->pm_state != PMC_STATE_RUNNING)
if ((ps->ps_pmc == NULL) ||
(ps->ps_pmc->pm_state != PMC_STATE_RUNNING))
nfree++;
#endif
if (ps->ps_nsamples != PMC_SAMPLE_INUSE)
@ -4262,9 +4263,11 @@ pmc_capture_user_callchain(int cpu, int ring, struct trapframe *tf)
ps = psb->ps_samples;
} while (ps != ps_end);
#ifdef INVARIANTS
KASSERT(ncallchains > 0 || nfree > 0,
("[pmc,%d] cpu %d didn't find a sample to collect", __LINE__,
cpu));
#endif
KASSERT(td->td_pinned == 1,
("[pmc,%d] invalid td_pinned value", __LINE__));