From: Stephane Eranian <eranian@google.com>
To: linux-kernel@vger.kernel.org
Cc: peterz@infradead.org, mingo@elte.hu, ak@linux.intel.com,
acme@redhat.com, jolsa@redhat.com, zheng.z.yan@intel.com,
bp@alien8.de, maria.n.dimakopoulou@gmail.com
Subject: [PATCH v6 0/4] perf/x86: add Intel RAPL PMU support
Date: Fri, 8 Nov 2013 20:45:59 +0100 [thread overview]
Message-ID: <1383939963-7750-1-git-send-email-eranian@google.com> (raw)
This patch adds a new uncore PMU to expose the Intel
RAPL (Running Average Power Limit) energy consumption counters.
Up to 3 counters, each counting a single RAPL event are exposed.
The RAPL counters are available on Intel SandyBridge, IvyBridge,
Haswell. The server processors add a 3rd counter to measure
DRAM power consumption.
The following events are available and exposed in sysfs:
- power/energy-cores: power consumption of all cores on socket
- power/energy-pkg : power consumption of all cores + LLC cache
- power/energy-dram : power consumption of DRAM (servers only)
The RAPL PMU is uncore by nature and is implemented such
that it only works in system-wide mode. Measuring only
one CPU per socket is sufficient.
The counters all count in the same unit. The perf_events API
exposes all RAPL counters as 64-bit integers counting in unit
of 1/2^32 Joules (about 0.23 nJ). User level tools must convert
the counts by multiplying them by the scaling factor exposed
in the correponding event .scale file in sysfs to obtain a value
expressed in Joules. The reason for this approach is that the kernel
avoids doing floating point math whenever possible because it is
expensive (user floating-point state must be saved). The method
used avoids kernel floating-point and does not incur any precision
loss. Thanks to PeterZ for suggesting this approach.
To convert the raw count in Watts: W = C * 2.3 / (1e10 * time)
The kernel exposes both the scaling factor and the unit (Joules)
in sysfs:
$ ls -1 /sys/devices/power/events/energy-*
/sys/devices/power/events/energy-cores
/sys/devices/power/events/energy-cores.scale
/sys/devices/power/events/energy-cores.unit
/sys/devices/power/events/energy-pkg
/sys/devices/power/events/energy-pkg.scale
/sys/devices/power/events/energy-pkg.unit
$ cat /sys/devices/power/events/energy-cores.scale
2.3283064365386962890625e-10
$ cat cat /sys/devices/power/events/energy-cores.unit
Joules
RAPL PMU is a new standalone PMU which registers with the
perf_event core subsystem. The PMU type (attr->type) is
dynamically allocated and is available from /sys/device/rapl/type.
Sampling is not supported by the RAPL PMU. There is no
privilege level filtering either.
The PMU exports a cpumask in /sys/devices/power/cpumask. It
is used by perf to ensure only one instance of each RAPL event
is measured per processor socket. Hotplug CPU is also supported.
The perf stat infrastrructure is enhanced to show events
units. It also applies the scaling factor. As such, perf stat prints
RAPL events in Joules (and not increments of 0.23 nJ):
# perf stat -a -e power/energy-pkg/,power/energy-cores/,cycles -I 1000 sleep 1000
# time counts unit events
1.000282860 2.51 Joules power/energy-pkg/
1.000282860 0.31 Joules power/energy-cores/
1.000282860 37765378 cycles
The patch adds a hrtimer to poll the counters given that
they do no interrupt on overflow. Hardware counters are 32-bit
wide.
In v2, we add the locking necesarry to protect the rapl_pmu
struct. We also add a description at the top of the file.
We check for Intel only processor. We improved the data
layout of the rapl_pmu struct. We also lifted the restriction
of the number of instances of RAPL counters that can be active
at the same time. RAPL is free running counters, so ought to be
able to measure events as many times as necessary in parallel
via multiple tools. There is never multiplexing among RAPL events.
In v3, we have renamed the event to be more generic power/* instead
of rapl/*. We have modified perf stat to print the event with the
unit and scaling factors.
In v4, we integrate the feedback from Jiri and rebase to 3.12-rc7+
from tip.git.
In v5, we export the full scaling factor to increase prescision.
In the perf tool, we changed the way the .unit and .scale syfs
entries are parsed. Thank to Jiri for this contribution on this.
We also fix a couple of printf() issues with perf stat and units.
Now, we print no unit symbol when the event has no unit (was ? before).
Patch is relative to 3.12 from tip.git.
In v6, we fixed a few issues in the perf tool having to do with printing
of the unit. Works for uncore events now. There is a major restructuring
of the code in the kernel because the hrtimer needs to be per-cpu and
not shared per socket because there can be multiple sessions in parallel
and also because of hotplug CPU. The hotplug cpu code was also updated.
Thanks to all contributors to this patch series: PeterZ, Jiri, Maria,
Arnaldo, Andi, Ingo.
Supported CPUs: SandyBridge, IvyBridge, Haswell.
Signed-off-by: Stephane Eranian <eranian@google.com>
Stephane Eranian (4):
perf: add active_entry list head to struct perf_event
perf stat: add event unit and scale support
perf,x86: add Intel RAPL PMU support
perf,x86: add RAPL hrtimer support
arch/x86/kernel/cpu/Makefile | 2 +-
arch/x86/kernel/cpu/perf_event_intel_rapl.c | 677 +++++++++++++++++++++++++++
include/linux/perf_event.h | 5 +-
kernel/events/core.c | 1 +
tools/perf/builtin-stat.c | 114 +++--
tools/perf/util/evsel.c | 2 +
tools/perf/util/evsel.h | 3 +
tools/perf/util/parse-events.c | 28 +-
tools/perf/util/pmu.c | 139 +++++-
tools/perf/util/pmu.h | 3 +-
10 files changed, 928 insertions(+), 46 deletions(-)
create mode 100644 arch/x86/kernel/cpu/perf_event_intel_rapl.c
--
1.7.9.5
next reply other threads:[~2013-11-08 19:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-08 19:45 Stephane Eranian [this message]
2013-11-08 19:46 ` [PATCH v6 1/4] perf: add active_entry list head to struct perf_event Stephane Eranian
2013-11-08 19:46 ` [PATCH v6 2/4] perf stat: add event unit and scale support Stephane Eranian
2013-11-08 19:46 ` [PATCH v6 3/4] perf,x86: add Intel RAPL PMU support Stephane Eranian
2013-11-11 15:59 ` Peter Zijlstra
2013-11-11 16:07 ` Stephane Eranian
2013-11-11 16:16 ` Peter Zijlstra
2013-11-12 14:14 ` Stephane Eranian
2013-11-12 15:02 ` Andi Kleen
2013-11-08 19:46 ` [PATCH v6 4/4] perf,x86: add RAPL hrtimer support Stephane Eranian
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=1383939963-7750-1-git-send-email-eranian@google.com \
--to=eranian@google.com \
--cc=acme@redhat.com \
--cc=ak@linux.intel.com \
--cc=bp@alien8.de \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maria.n.dimakopoulou@gmail.com \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=zheng.z.yan@intel.com \
/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®