linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* perf_event: rdpmc self-monitoring overhead issue
@ 2013-08-30 17:55 Vince Weaver
  2013-08-30 18:05 ` Stephane Eranian
  0 siblings, 1 reply; 9+ messages in thread
From: Vince Weaver @ 2013-08-30 17:55 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, Peter Zijlstra, mingo, acme,
	Stephane Eranian

Hello,

I've finally found time to track down why perf_event/rdpmc self-monitoring 
overhead was so bad.

To summarize, a test which does:

   perf_event_open()
   ioctl(PERF_EVENT_IOC_ENABLE)
   read() /* either via syscall or  the rdpmc code listed in 
             include/uapi/linux/perf_event.h */
   ioctl(PERF_EVENT_IOC_DISABLE)

is done, and the number of cycles for each routine is taken using
rdtsc().

On a Core2 Processor the results look something like this for read:

                              | read time for 1 event
                              | median of 1024 runs
                              |     (cycles)
 -----------------------------|-------------------------
   2.6.32-perfctr (rdpmc)     |       133
   2.6.30-perfmon2            |      1264
   3.10                       |      1482
   3.10 (rdpmc)               |      3062

As you can see, using the userspace-only rdpmc code is twice as slow as 
just using the read() syscall.


I've tracked down the cause of this, and apparently it's due to
the first access to the event's struct perf_event_mmap_page.  If 
outside of the read timing code I do an unrelated read of the mmap() page
to fault it in, then the result is much more believable:

  3.10 (rdpmc)                 |      123

So the question is, why do I have to explicitly in advance fault the
page in?  Is there a way to force this to happen automatically?

The perfctr code as far as I can tell doesn't touch its mmap page in 
advance.
It uses vm_insert_page() to insert the page rather than the
rb tree stuff that perf_event uses.

I know part of this overhead is due to the construction of my benchmark
and in theory would be mitigated if you were doing a large number
of measurements in a program, but at the same time this is also a common
pattern when self-monitoring: putting calipers around one chunk of code
and taking one measurement (often in a timing-critical area where
overhead matters).

Vince

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-09-02 17:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-30 17:55 perf_event: rdpmc self-monitoring overhead issue Vince Weaver
2013-08-30 18:05 ` Stephane Eranian
2013-08-30 18:35   ` Vince Weaver
2013-08-31 10:06     ` Mikael Pettersson
2013-09-02  2:50   ` Andi Kleen
2013-09-02  8:24     ` Stephane Eranian
2013-09-02  9:23       ` Andi Kleen
2013-09-02 13:15       ` Vince Weaver
2013-09-02 17:26         ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).