* Use of PMU counters inside kernel?
@ 2014-06-19 10:53 Jesper Dangaard Brouer
2014-06-19 21:11 ` Andi Kleen
0 siblings, 1 reply; 3+ messages in thread
From: Jesper Dangaard Brouer @ 2014-06-19 10:53 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Andi Kleen, linux-perf-users
Cc: Daniel Borkmann, Florian Westphal, Hannes Frederic Sowa
Hi
I want to use/read the PMU counters for 'instructions' and 'cycles',
from within the kernel, to measure the overhead of different in-kernel
functions (and calc the pipeline efficiency ala perf-stat insns per cycle).
What is the prefered way/API to read these counters, without
conflicting with the perf tool?
I've already looked at Andi Kleens "simple-pmu" kernel module
https://github.com/andikleen/simple-pmu/
Thus, I have figured out how I can hack this together open-coded. I'm
looking for advice on howto use the existing perf APIs ?
I basically just need a in-kernel API to turn in these counters, and
then I can just read them via the rdpcm instruction.
Info I already learned (correct me if I'm wrong):
The 'instructions' counter is the "Instruction Retired" counter
* Event num: 0xC0, Umask: 0x00
* Read via rdpmc 0x40000000
The 'cycles' counter is the "Unhalted core cycles" counter
* Event num: 0x3C, Umask: 0x00
* Read via rdpmc 0x40000001
I'm uncertain about the rdpmc hex values (taken from simple-pmu).
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Sr. Network Kernel Developer at Red Hat
Author of http://www.iptv-analyzer.org
LinkedIn: http://www.linkedin.com/in/brouer
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Use of PMU counters inside kernel?
2014-06-19 10:53 Use of PMU counters inside kernel? Jesper Dangaard Brouer
@ 2014-06-19 21:11 ` Andi Kleen
2014-06-20 11:04 ` Jesper Dangaard Brouer
0 siblings, 1 reply; 3+ messages in thread
From: Andi Kleen @ 2014-06-19 21:11 UTC (permalink / raw)
To: Jesper Dangaard Brouer
Cc: Arnaldo Carvalho de Melo, linux-perf-users, Daniel Borkmann,
Florian Westphal, Hannes Frederic Sowa
Jesper Dangaard Brouer <jbrouer@redhat.com> writes:
> I want to use/read the PMU counters for 'instructions' and 'cycles',
> from within the kernel, to measure the overhead of different in-kernel
> functions (and calc the pipeline efficiency ala perf-stat insns per cycle).
>
> What is the prefered way/API to read these counters, without
> conflicting with the perf tool?
>
perf_event_create_counter()
> I basically just need a in-kernel API to turn in these counters, and
> then I can just read them via the rdpcm instruction.
For RDPMC you would need extra support actually, as there is no
guarantee perf uses the fixed counter. In user space this
information is in the perf mmap page.
Also please be aware that RDPMC is not synchronizing.
-Andi
--
ak@linux.intel.com -- Speaking for myself only
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Use of PMU counters inside kernel?
2014-06-19 21:11 ` Andi Kleen
@ 2014-06-20 11:04 ` Jesper Dangaard Brouer
0 siblings, 0 replies; 3+ messages in thread
From: Jesper Dangaard Brouer @ 2014-06-20 11:04 UTC (permalink / raw)
To: Andi Kleen
Cc: Arnaldo Carvalho de Melo, linux-perf-users, Daniel Borkmann,
Florian Westphal, Hannes Frederic Sowa, Richard Fowles
On Thu, 19 Jun 2014 14:11:59 -0700
Andi Kleen <andi@firstfloor.org> wrote:
> Jesper Dangaard Brouer <jbrouer@redhat.com> writes:
>
> > I want to use/read the PMU counters for 'instructions' and 'cycles',
> > from within the kernel, to measure the overhead of different in-kernel
> > functions (and calc the pipeline efficiency ala perf-stat insns per cycle).
> >
> > What is the prefered way/API to read these counters, without
> > conflicting with the perf tool?
> >
>
> perf_event_create_counter()
Thanks, guess you mean:
perf_event_create_kernel_counter()
> > I basically just need a in-kernel API to turn in these counters, and
> > then I can just read them via the rdpcm instruction.
>
> For RDPMC you would need extra support actually, as there is no
> guarantee perf uses the fixed counter. In user space this
> information is in the perf mmap page.
Hmm, so you are saying that I cannot rely on just reading the counters
with the "rdpmc" inctruction. What should I then use?
I'm a little confused about the fixed counters, and the (to me) magic
number that is used to read them:
// From: https://github.com/andikleen/simple-pmu
enum {
FIXED_SELECT = (1U << 30), /* == 0x40000000 */
FIXED_INST_RETIRED_ANY = 0,
FIXED_CPU_CLK_UNHALTED_CORE = 1,
FIXED_CPU_CLK_UNHALTED_REF = 2,
};
> Also please be aware that RDPMC is not synchronizing.
What do you mean by "not synchronizing"?
I've read some where, that I can use the "rdmsr" instruction in the
kernel, and read the PCM register directly, to give me higher
accuracy. Is that a bad idea?
Thanks for your feedback,
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Sr. Network Kernel Developer at Red Hat
Author of http://www.iptv-analyzer.org
LinkedIn: http://www.linkedin.com/in/brouer
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-06-20 11:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-19 10:53 Use of PMU counters inside kernel? Jesper Dangaard Brouer
2014-06-19 21:11 ` Andi Kleen
2014-06-20 11:04 ` Jesper Dangaard Brouer
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.