From: Peter Zijlstra <peterz@infradead.org>
To: Vince Weaver <vincent.weaver@maine.edu>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: Re: perf: rdpmc and PERF_EVENT_IOC_RESET
Date: Wed, 17 Aug 2016 17:26:16 +0200 [thread overview]
Message-ID: <20160817152616.GT30192@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <alpine.DEB.2.20.1608170047500.13865@macbook-air>
On Wed, Aug 17, 2016 at 12:53:01AM -0400, Vince Weaver wrote:
> Hello
>
> so using rdpmc() and the mmap page to do fast perf_event reads seems to
> interact poorly with the PERF_EVENT_IOC_RESET ioctl.
Hurm.. I never considered using RESET with rdpmc(). The typical usage of
rdpmc() I considered is something like:
u64 start = rdpmc();
/* code goes here */
delta = rdpmc() - start;
That said; I don't object to fixing the interaction if it doesn't have
downsides.
> From what I can tell, on reset event->count is set to zero, but
> event->hw.prev_count is not, so the userpg->offset field ends up negative
> and weird things happen.
_perf_event_reset()
perf_event_read() /* updates prev_count */
local64_set(count, 0);
after that, like you say: userpg->offset = perf_event_count() -
prev_count, which does indeed end up negative.
But the rdpmc user function should:
u64 mmap_read_self(void *addr)
{
struct perf_event_mmap_page *pc = addr;
u32 seq, idx, time_mult = 0, time_shift = 0, width = 0;
u64 count, cyc = 0, time_offset = 0, enabled, running, delta;
s64 pmc = 0;
do {
seq = pc->lock;
barrier();
/* enabled/running muck */
idx = pc->index;
count = pc->offset;
if (pc->cap_user_rdpmc && idx) {
width = pc->pmc_width;
pmc = rdpmc(idx - 1);
}
barrier();
} while (pc->lock != seq);
if (idx) {
pmc <<= 64 - width;
pmc >>= 64 - width; /* shift right signed */
count += pmc;
}
/* more enabled/running muck */
return count;
}
Which sign-extends the RDPMC result and adds it to userpg->offset,
resulting in a positive number again.
So I think it should work..
next prev parent reply other threads:[~2016-08-17 15:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-17 4:53 Vince Weaver
2016-08-17 15:26 ` Peter Zijlstra [this message]
2016-08-18 4:32 ` Vince Weaver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160817152616.GT30192@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=vincent.weaver@maine.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®