linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephane Eranian <eranian@google.com>
To: linux-kernel@vger.kernel.org
Cc: acme@redhat.com, peterz@infradead.org, mingo@elte.hu,
	ak@linux.intel.com, kan.liang@intel.com, jolsa@redhat.com
Subject: [PATCH v4 0/5] perf: add support for capturing skid IP
Date: Wed,  8 Nov 2017 23:57:08 -0800	[thread overview]
Message-ID: <1510214233-2074-1-git-send-email-eranian@google.com> (raw)

This patchs adds a new sample record type called
PERF_SAMPLE_SKID_IP. The goal is to record the
unmodified interrupted instruction pointer (IP) as
seen by the kernel and reflected in the machine state.

On some architectures, it is possible to avoid the IP skid using
hardware support. For instance, on Intel x86, the use of PEBS helps
eliminate the skid on Haswell and later processors. On older Intel
processor, software, i.e., the kernel,  may succeed in eliminating
the skid.

Without this patch, on Haswell processors, if you set:
 - attr.precise = 0, then you get the skid IP
 - attr.precise = 1, then you get the skid PEBS ip (off-by-1)
 - attr.precise = 2, then you get the skidless PEBS ip

The IP is captured when the event has PERF_SAMPLE_IP set in sample_type.
However, there are certain measurements where you need to have BOTH
the skidless IP and the skid IP. For instance, when studying branches,
the skid IP usually points to the target of the branch while the skidless
IP points to the branch instruction itself. Today, it is not possible to retrieve
both at the same time. This patch makes this possible by specifying
PERF_SAMPLE_IP|PERF_SAMPLE_SKID_IP.

As an example, consider the following code snipet:
 37.51 42c2ed    je     42c2f3
       42c2ef    add    $0x1,%rdx
       42c2f3    sub    $0x1,%rax

When using PEBS (precise=2) and sampling on BR_INST_RETIRED.CONDITIONAL,
the IP always points to 0x42c2ed. With precise=1, the IP would point to
0x42c2f3. It is interesting to collect both IPs in a single run to determine
how often the conditional branch is taken vs. non-taken.

Understanding the skid is also interesting for other precise events.

In V2, we rebased to 10d94ff4d558 (v4.14-rc7).

In V3, code is rebased to 4.14-rc8, LKML comments have been integrated.
The new way to specify skid ip is per event:
   $ perf record -e cpu/event=0xc5,skid-ip=1/ ....

In V4, we fix document of the ski-ip event option and move a session.c
change to the correct patch as per Jiri's remark.

Stephane Eranian (5):
  perf/core: add PERF_RECORD_SAMPLE_SKID_IP record type
  perf/x86: add PERF_SAMPLE_SKID_IP support for X86 PEBS
  perf/tools: add support for PERF_SAMPLE_SKID_IP
  perf/record: add documentation for using PERF_SAMPLE_SKID_IP
  perf/script: add support for PERF_SAMPLE_SKID_IP

 arch/x86/events/intel/ds.c               |  7 +++++++
 include/linux/perf_event.h               |  2 ++
 include/uapi/linux/perf_event.h          |  4 +++-
 kernel/events/core.c                     | 14 ++++++++++++++
 tools/include/uapi/linux/perf_event.h    |  4 +++-
 tools/perf/Documentation/perf-record.txt |  8 ++++++++
 tools/perf/Documentation/perf-script.txt |  2 +-
 tools/perf/builtin-script.c              | 10 ++++++++--
 tools/perf/util/event.h                  |  1 +
 tools/perf/util/evsel.c                  | 11 +++++++++++
 tools/perf/util/evsel.h                  |  2 ++
 tools/perf/util/parse-events.c           |  7 +++++++
 tools/perf/util/parse-events.h           |  1 +
 tools/perf/util/parse-events.l           |  1 +
 tools/perf/util/session.c                |  3 +++
 15 files changed, 72 insertions(+), 5 deletions(-)

-- 
2.7.4

             reply	other threads:[~2017-11-09  7:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-09  7:57 Stephane Eranian [this message]
2017-11-09  7:57 ` [PATCH v4 1/5] perf/core: add PERF_RECORD_SAMPLE_SKID_IP record type Stephane Eranian
2017-11-09  7:57 ` [PATCH v4 2/5] perf/x86: add PERF_SAMPLE_SKID_IP support for X86 PEBS Stephane Eranian
2017-11-09  7:57 ` [PATCH v4 3/5] perf/tools: add support for PERF_SAMPLE_SKID_IP Stephane Eranian
2017-11-09  7:57 ` [PATCH v4 4/5] perf/record: add documentation for using PERF_SAMPLE_SKID_IP Stephane Eranian
2017-11-09  7:57 ` [PATCH v4 5/5] perf/script: add support for PERF_SAMPLE_SKID_IP Stephane Eranian
2017-11-13 11:52   ` Jiri Olsa

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=1510214233-2074-1-git-send-email-eranian@google.com \
    --to=eranian@google.com \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).