mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Linux Weekly News <lwn@lwn.net>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 03/68] perf intel-pt/bts: Tidy instruction buffer size usage
Date: Tue, 11 Oct 2016 14:30:58 -0300	[thread overview]
Message-ID: <1476207123-21791-4-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1476207123-21791-1-git-send-email-acme@kernel.org>

From: Adrian Hunter <adrian.hunter@intel.com>

Tidy instruction buffer size usage in preparation for copying the
instruction bytes onto samples.

The instruction buffer is presently used for debugging, so rename its
size macro from INTEL_PT_INSN_DBG_BUF_SZ to INTEL_PT_INSN_BUF_SZ, and
use it everywhere.

Note that the maximum instruction size is 15 which is a less efficient size
to copy than 16, which is why a separate buffer size is used.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Link: http://lkml.kernel.org/r/1475847747-30994-2-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/intel-bts.c                              |  8 +++-----
 tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c | 13 ++++++-------
 tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h |  6 ++----
 tools/perf/util/intel-pt-decoder/intel-pt-log.c          |  4 ++--
 tools/perf/util/intel-pt.c                               |  8 +++-----
 5 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c
index f545ec1e758a..8bc7fec817d7 100644
--- a/tools/perf/util/intel-bts.c
+++ b/tools/perf/util/intel-bts.c
@@ -319,15 +319,12 @@ static int intel_bts_get_next_insn(struct intel_bts_queue *btsq, u64 ip)
 	struct machine *machine = btsq->bts->machine;
 	struct thread *thread;
 	struct addr_location al;
-	unsigned char buf[1024];
-	size_t bufsz;
+	unsigned char buf[INTEL_PT_INSN_BUF_SZ];
 	ssize_t len;
 	int x86_64;
 	uint8_t cpumode;
 	int err = -1;
 
-	bufsz = intel_pt_insn_max_size();
-
 	if (machine__kernel_ip(machine, ip))
 		cpumode = PERF_RECORD_MISC_KERNEL;
 	else
@@ -341,7 +338,8 @@ static int intel_bts_get_next_insn(struct intel_bts_queue *btsq, u64 ip)
 	if (!al.map || !al.map->dso)
 		goto out_put;
 
-	len = dso__data_read_addr(al.map->dso, al.map, machine, ip, buf, bufsz);
+	len = dso__data_read_addr(al.map->dso, al.map, machine, ip, buf,
+				  INTEL_PT_INSN_BUF_SZ);
 	if (len <= 0)
 		goto out_put;
 
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
index d23138c06665..5f95cd442075 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.c
@@ -27,6 +27,10 @@
 
 #include "intel-pt-insn-decoder.h"
 
+#if INTEL_PT_INSN_BUF_SZ < MAX_INSN_SIZE
+#error Instruction buffer size too small
+#endif
+
 /* Based on branch_type() from perf_event_intel_lbr.c */
 static void intel_pt_insn_decoder(struct insn *insn,
 				  struct intel_pt_insn *intel_pt_insn)
@@ -166,10 +170,10 @@ int intel_pt_get_insn(const unsigned char *buf, size_t len, int x86_64,
 	if (!insn_complete(&insn) || insn.length > len)
 		return -1;
 	intel_pt_insn_decoder(&insn, intel_pt_insn);
-	if (insn.length < INTEL_PT_INSN_DBG_BUF_SZ)
+	if (insn.length < INTEL_PT_INSN_BUF_SZ)
 		memcpy(intel_pt_insn->buf, buf, insn.length);
 	else
-		memcpy(intel_pt_insn->buf, buf, INTEL_PT_INSN_DBG_BUF_SZ);
+		memcpy(intel_pt_insn->buf, buf, INTEL_PT_INSN_BUF_SZ);
 	return 0;
 }
 
@@ -211,11 +215,6 @@ int intel_pt_insn_desc(const struct intel_pt_insn *intel_pt_insn, char *buf,
 	return 0;
 }
 
-size_t intel_pt_insn_max_size(void)
-{
-	return MAX_INSN_SIZE;
-}
-
 int intel_pt_insn_type(enum intel_pt_insn_op op)
 {
 	switch (op) {
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h
index b0adbf37323e..37ec5627ae9b 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-insn-decoder.h
@@ -20,7 +20,7 @@
 #include <stdint.h>
 
 #define INTEL_PT_INSN_DESC_MAX		32
-#define INTEL_PT_INSN_DBG_BUF_SZ	16
+#define INTEL_PT_INSN_BUF_SZ		16
 
 enum intel_pt_insn_op {
 	INTEL_PT_OP_OTHER,
@@ -47,7 +47,7 @@ struct intel_pt_insn {
 	enum intel_pt_insn_branch	branch;
 	int				length;
 	int32_t				rel;
-	unsigned char			buf[INTEL_PT_INSN_DBG_BUF_SZ];
+	unsigned char			buf[INTEL_PT_INSN_BUF_SZ];
 };
 
 int intel_pt_get_insn(const unsigned char *buf, size_t len, int x86_64,
@@ -58,8 +58,6 @@ const char *intel_pt_insn_name(enum intel_pt_insn_op op);
 int intel_pt_insn_desc(const struct intel_pt_insn *intel_pt_insn, char *buf,
 		       size_t buf_len);
 
-size_t intel_pt_insn_max_size(void);
-
 int intel_pt_insn_type(enum intel_pt_insn_op op);
 
 #endif
diff --git a/tools/perf/util/intel-pt-decoder/intel-pt-log.c b/tools/perf/util/intel-pt-decoder/intel-pt-log.c
index 319bef33a64b..e02bc7b166a0 100644
--- a/tools/perf/util/intel-pt-decoder/intel-pt-log.c
+++ b/tools/perf/util/intel-pt-decoder/intel-pt-log.c
@@ -119,8 +119,8 @@ void __intel_pt_log_insn(struct intel_pt_insn *intel_pt_insn, uint64_t ip)
 	if (intel_pt_log_open())
 		return;
 
-	if (len > INTEL_PT_INSN_DBG_BUF_SZ)
-		len = INTEL_PT_INSN_DBG_BUF_SZ;
+	if (len > INTEL_PT_INSN_BUF_SZ)
+		len = INTEL_PT_INSN_BUF_SZ;
 	intel_pt_print_data(intel_pt_insn->buf, len, ip, 8);
 	if (intel_pt_insn_desc(intel_pt_insn, desc, INTEL_PT_INSN_DESC_MAX) > 0)
 		fprintf(f, "%s\n", desc);
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index dc041d4368c8..815a14d8904b 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -428,8 +428,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 	struct machine *machine = ptq->pt->machine;
 	struct thread *thread;
 	struct addr_location al;
-	unsigned char buf[1024];
-	size_t bufsz;
+	unsigned char buf[INTEL_PT_INSN_BUF_SZ];
 	ssize_t len;
 	int x86_64;
 	u8 cpumode;
@@ -440,8 +439,6 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 	if (to_ip && *ip == to_ip)
 		goto out_no_cache;
 
-	bufsz = intel_pt_insn_max_size();
-
 	if (*ip >= ptq->pt->kernel_start)
 		cpumode = PERF_RECORD_MISC_KERNEL;
 	else
@@ -493,7 +490,8 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
 
 		while (1) {
 			len = dso__data_read_offset(al.map->dso, machine,
-						    offset, buf, bufsz);
+						    offset, buf,
+						    INTEL_PT_INSN_BUF_SZ);
 			if (len <= 0)
 				return -EINVAL;
 
-- 
2.7.4

  parent reply	other threads:[~2016-10-11 18:03 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-11 17:30 [GIT PULL 00/68] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-10-11 17:30 ` [PATCH 01/68] perf list: Add support for listing only json events Arnaldo Carvalho de Melo
2016-10-11 17:30 ` [PATCH 02/68] perf tools: Handle completion of upper case events Arnaldo Carvalho de Melo
2016-10-11 17:30 ` Arnaldo Carvalho de Melo [this message]
2016-10-11 17:30 ` [PATCH 04/68] perf intel-pt/bts: Report instruction bytes and length in sample Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 05/68] perf top: Fix refreshing hierarchy entries on TUI Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 06/68] perf tools: Sync copy of x86's syscall table Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 07/68] perf c2c: Introduce c2c_decode_stats function Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 08/68] perf c2c: Introduce c2c_add_stats function Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 09/68] perf c2c: Add c2c command Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 10/68] perf c2c: Add record subcommand Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 11/68] perf c2c: Add report subcommand Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 12/68] perf c2c report: Add dimension support Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 13/68] perf c2c report: Add sort_entry " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 14/68] perf c2c report: Fallback to standard dimensions Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 15/68] perf c2c report: Add sample processing Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 16/68] perf c2c report: Add cacheline hists processing Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 17/68] perf c2c report: Decode c2c_stats for hist entries Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 18/68] perf c2c report: Add header macros Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 19/68] perf c2c report: Add 'dcacheline' dimension key Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 20/68] perf c2c report: Add 'offset' " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 21/68] perf c2c report: Add 'iaddr' " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 22/68] perf c2c report: Add hitm related dimension keys Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 23/68] perf c2c report: Add stores " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 24/68] perf c2c report: Add loads " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 25/68] perf c2c report: Add llc and remote " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 26/68] perf c2c report: Add llc load miss dimension key Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 27/68] perf c2c report: Add total record sort key Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 28/68] perf c2c report: Add total loads " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 29/68] perf c2c report: Add hitm percent " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 30/68] perf c2c report: Add hitm/store percent related sort keys Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 31/68] perf c2c report: Add dram " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 32/68] perf c2c report: Add 'pid' sort key Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 33/68] perf c2c report: Add 'tid' " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 34/68] perf c2c report: Add 'symbol' and 'dso' sort keys Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 35/68] perf c2c report: Add 'node' sort key Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 36/68] perf c2c report: Add stats related sort keys Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 37/68] perf c2c report: Add 'cpucnt' sort key Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 38/68] perf c2c report: Add src line " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 39/68] perf c2c report: Setup number of header lines for hists Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 40/68] perf c2c report: Set final resort fields Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 41/68] perf c2c report: Add stdio output support Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 42/68] perf c2c report: Add main TUI browser Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 43/68] perf c2c report: Add TUI cacheline browser Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 44/68] perf c2c report: Add global stats stdio output Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 45/68] perf c2c report: Add shared cachelines " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 46/68] perf c2c report: Add c2c related " Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 47/68] perf c2c report: Allow to report callchains Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 48/68] perf c2c report: Limit the cachelines table entries Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 49/68] perf c2c report: Add support to choose local HITMs Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 50/68] perf c2c report: Allow to set cacheline sort fields Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 51/68] perf c2c report: Recalc width of global sort entries Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 52/68] perf c2c report: Add cacheline index entry Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 53/68] perf c2c report: Add support to manage symbol name length Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 54/68] perf c2c report: Iterate node display in browser Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 55/68] perf c2c report: Add help windows Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 56/68] perf c2c: Add man page and credits Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 57/68] tools lib traceevent: Add install_headers target Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 58/68] tools lib traceevent: Add do_install_mkdir Makefile function Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 59/68] tools lib traceevent: Rename LIB_FILE to LIB_TARGET Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 60/68] tools lib traceevent: Add version for traceevent shared object Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 61/68] tools lib: Add for_each_clear_bit macro Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 62/68] perf report: Move captured info to generic header info Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 63/68] perf header: Display missing features Arnaldo Carvalho de Melo
2016-10-11 17:31 ` [PATCH 64/68] perf header: Display feature name on write failure Arnaldo Carvalho de Melo
2016-10-11 17:32 ` [PATCH 65/68] perf header: Set nr_numa_nodes only when we parsed all the data Arnaldo Carvalho de Melo
2016-10-11 17:32 ` [PATCH 66/68] perf c2c report: Add --no-source option Arnaldo Carvalho de Melo
2016-10-11 17:32 ` [PATCH 67/68] perf c2c report: Add --show-all option Arnaldo Carvalho de Melo
2016-10-11 17:32 ` [PATCH 68/68] perf jevents: Handle events including .c and .o Arnaldo Carvalho de Melo

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=1476207123-21791-4-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lwn@lwn.net \
    --cc=mingo@kernel.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

Powered by JetHome