From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754225AbdFNCvJ (ORCPT ); Tue, 13 Jun 2017 22:51:09 -0400 Received: from mga04.intel.com ([192.55.52.120]:27920 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754201AbdFNCvI (ORCPT ); Tue, 13 Jun 2017 22:51:08 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,340,1493708400"; d="scan'208";a="1182176071" From: Jin Yao To: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com Cc: Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com, Jin Yao Subject: [PATCH v1 1/2] perf report: Check for fused instruction pair Date: Wed, 14 Jun 2017 10:53:40 +0800 Message-Id: <1497408821-3211-2-git-send-email-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497408821-3211-1-git-send-email-yao.jin@linux.intel.com> References: <1497408821-3211-1-git-send-email-yao.jin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Macro fusion merges two instructions to a single micro-op. Intel core platform performs this hardware optimization under limited circumstances. For example, CMP + JCC can be "fused" and executed /retired together. While with sampling this can result in the sample sometimes being on the JCC and sometimes on the CMP. So for the fused instruction pair, they could be considered together. In general, the fused instruction pairs are: cmp/test/add/sub/and/inc/dec + jcc. This patch adds a new function which checks if 2 x86 instructions are in a "fused" pair. For non-x86 arch, the function just returns false. Signed-off-by: Jin Yao --- tools/perf/arch/x86/util/Build | 1 + tools/perf/arch/x86/util/fused.c | 20 ++++++++++++++++++++ tools/perf/util/Build | 1 + tools/perf/util/fused.c | 11 +++++++++++ tools/perf/util/fused.h | 8 ++++++++ 5 files changed, 41 insertions(+) create mode 100644 tools/perf/arch/x86/util/fused.c create mode 100644 tools/perf/util/fused.c create mode 100644 tools/perf/util/fused.h diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build index f95e6f4..3809348 100644 --- a/tools/perf/arch/x86/util/Build +++ b/tools/perf/arch/x86/util/Build @@ -4,6 +4,7 @@ libperf-y += pmu.o libperf-y += kvm-stat.o libperf-y += perf_regs.o libperf-y += group.o +libperf-y += fused.o libperf-$(CONFIG_DWARF) += dwarf-regs.o libperf-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o diff --git a/tools/perf/arch/x86/util/fused.c b/tools/perf/arch/x86/util/fused.c new file mode 100644 index 0000000..be28d22 --- /dev/null +++ b/tools/perf/arch/x86/util/fused.c @@ -0,0 +1,20 @@ +#include +#include "../../util/fused.h" + +bool fused_insn_pair(const char *insn1, const char *insn2) +{ + if (strstr(insn2, "jmp")) + return false; + + if ((strstr(insn1, "cmp") && !strstr(insn1, "xchg")) || + strstr(insn1, "test") || + strstr(insn1, "add") || + strstr(insn1, "sub") || + strstr(insn1, "and") || + strstr(insn1, "inc") || + strstr(insn1, "dec")) { + return true; + } + + return false; +} diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 79dea95..b83757d 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -93,6 +93,7 @@ libperf-y += drv_configs.o libperf-y += units.o libperf-y += time-utils.o libperf-y += expr-bison.o +libperf-y += fused.o libperf-$(CONFIG_LIBBPF) += bpf-loader.o libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o diff --git a/tools/perf/util/fused.c b/tools/perf/util/fused.c new file mode 100644 index 0000000..2cf56fa --- /dev/null +++ b/tools/perf/util/fused.c @@ -0,0 +1,11 @@ +#include +#include +#include + +#include "fused.h" + +bool __weak fused_insn_pair(const char *insn1 __maybe_unused, + const char *insn2 __maybe_unused) +{ + return false; +} diff --git a/tools/perf/util/fused.h b/tools/perf/util/fused.h new file mode 100644 index 0000000..fa26714 --- /dev/null +++ b/tools/perf/util/fused.h @@ -0,0 +1,8 @@ +#ifndef __PERF_FUSED_H +#define __PERF_FUSED_H + +#include + +bool fused_insn_pair(const char *insn1, const char *insn2); + +#endif /* __PERF_FUSED_H */ -- 2.7.4