linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: tip-bot for Mathieu Poirier <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: mike.leach@arm.com, acme@redhat.com,
	alexander.shishkin@linux.intel.com, peterz@infradead.org,
	tglx@linutronix.de, namhyung@kernel.org, mingo@kernel.org,
	mathieu.poirier@linaro.org, kim.phillips@arm.com,
	adrian.hunter@intel.com, hpa@zytor.com,
	linux-kernel@vger.kernel.org, suzuki.poulose@arm.com,
	jolsa@redhat.com, tor@ti.com
Subject: [tip:perf/core] perf tools: Add mechanic to synthesise CoreSight trace packets
Date: Sun, 28 Jan 2018 13:19:41 -0800	[thread overview]
Message-ID: <tip-b12235b113cfd7e4a31f0c8bdb0d8e8588ba6683@git.kernel.org> (raw)
In-Reply-To: <1516211539-5166-10-git-send-email-mathieu.poirier@linaro.org>

Commit-ID:  b12235b113cfd7e4a31f0c8bdb0d8e8588ba6683
Gitweb:     https://git.kernel.org/tip/b12235b113cfd7e4a31f0c8bdb0d8e8588ba6683
Author:     Mathieu Poirier <mathieu.poirier@linaro.org>
AuthorDate: Wed, 17 Jan 2018 10:52:18 -0700
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 25 Jan 2018 06:37:27 -0300

perf tools: Add mechanic to synthesise CoreSight trace packets

Once decoded from trace packets information on trace range needs
to be communicated to the perf synthesis infrastructure so that it
is available to the perf tools built-in rendering tools and scripts.

Co-authored-by: Tor Jeremiassen <tor@ti.com>
Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Mike Leach <mike.leach@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: http://lkml.kernel.org/r/1516211539-5166-10-git-send-email-mathieu.poirier@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cs-etm.c | 168 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 168 insertions(+)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 407095a..b9f0a53 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -453,6 +453,157 @@ static void  cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm,
 	}
 }
 
+/*
+ * The cs etm packet encodes an instruction range between a branch target
+ * and the next taken branch. Generate sample accordingly.
+ */
+static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq,
+				       struct cs_etm_packet *packet)
+{
+	int ret = 0;
+	struct cs_etm_auxtrace *etm = etmq->etm;
+	struct perf_sample sample = {.ip = 0,};
+	union perf_event *event = etmq->event_buf;
+	u64 start_addr = packet->start_addr;
+	u64 end_addr = packet->end_addr;
+
+	event->sample.header.type = PERF_RECORD_SAMPLE;
+	event->sample.header.misc = PERF_RECORD_MISC_USER;
+	event->sample.header.size = sizeof(struct perf_event_header);
+
+	sample.ip = start_addr;
+	sample.pid = etmq->pid;
+	sample.tid = etmq->tid;
+	sample.addr = end_addr;
+	sample.id = etmq->etm->branches_id;
+	sample.stream_id = etmq->etm->branches_id;
+	sample.period = 1;
+	sample.cpu = packet->cpu;
+	sample.flags = 0;
+	sample.cpumode = PERF_RECORD_MISC_USER;
+
+	ret = perf_session__deliver_synth_event(etm->session, event, &sample);
+
+	if (ret)
+		pr_err(
+		"CS ETM Trace: failed to deliver instruction event, error %d\n",
+		ret);
+
+	return ret;
+}
+
+struct cs_etm_synth {
+	struct perf_tool dummy_tool;
+	struct perf_session *session;
+};
+
+static int cs_etm__event_synth(struct perf_tool *tool,
+			       union perf_event *event,
+			       struct perf_sample *sample __maybe_unused,
+			       struct machine *machine __maybe_unused)
+{
+	struct cs_etm_synth *cs_etm_synth =
+		      container_of(tool, struct cs_etm_synth, dummy_tool);
+
+	return perf_session__deliver_synth_event(cs_etm_synth->session,
+						 event, NULL);
+}
+
+static int cs_etm__synth_event(struct perf_session *session,
+			       struct perf_event_attr *attr, u64 id)
+{
+	struct cs_etm_synth cs_etm_synth;
+
+	memset(&cs_etm_synth, 0, sizeof(struct cs_etm_synth));
+	cs_etm_synth.session = session;
+
+	return perf_event__synthesize_attr(&cs_etm_synth.dummy_tool, attr, 1,
+					   &id, cs_etm__event_synth);
+}
+
+static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
+				struct perf_session *session)
+{
+	struct perf_evlist *evlist = session->evlist;
+	struct perf_evsel *evsel;
+	struct perf_event_attr attr;
+	bool found = false;
+	u64 id;
+	int err;
+
+	evlist__for_each_entry(evlist, evsel) {
+		if (evsel->attr.type == etm->pmu_type) {
+			found = true;
+			break;
+		}
+	}
+
+	if (!found) {
+		pr_debug("No selected events with CoreSight Trace data\n");
+		return 0;
+	}
+
+	memset(&attr, 0, sizeof(struct perf_event_attr));
+	attr.size = sizeof(struct perf_event_attr);
+	attr.type = PERF_TYPE_HARDWARE;
+	attr.sample_type = evsel->attr.sample_type & PERF_SAMPLE_MASK;
+	attr.sample_type |= PERF_SAMPLE_IP | PERF_SAMPLE_TID |
+			    PERF_SAMPLE_PERIOD;
+	if (etm->timeless_decoding)
+		attr.sample_type &= ~(u64)PERF_SAMPLE_TIME;
+	else
+		attr.sample_type |= PERF_SAMPLE_TIME;
+
+	attr.exclude_user = evsel->attr.exclude_user;
+	attr.exclude_kernel = evsel->attr.exclude_kernel;
+	attr.exclude_hv = evsel->attr.exclude_hv;
+	attr.exclude_host = evsel->attr.exclude_host;
+	attr.exclude_guest = evsel->attr.exclude_guest;
+	attr.sample_id_all = evsel->attr.sample_id_all;
+	attr.read_format = evsel->attr.read_format;
+
+	/* create new id val to be a fixed offset from evsel id */
+	id = evsel->id[0] + 1000000000;
+
+	if (!id)
+		id = 1;
+
+	if (etm->synth_opts.branches) {
+		attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS;
+		attr.sample_period = 1;
+		attr.sample_type |= PERF_SAMPLE_ADDR;
+		err = cs_etm__synth_event(session, &attr, id);
+		if (err)
+			return err;
+		etm->sample_branches = true;
+		etm->branches_sample_type = attr.sample_type;
+		etm->branches_id = id;
+	}
+
+	return 0;
+}
+
+static int cs_etm__sample(struct cs_etm_queue *etmq)
+{
+	int ret;
+	struct cs_etm_packet packet;
+
+	while (1) {
+		ret = cs_etm_decoder__get_packet(etmq->decoder, &packet);
+		if (ret <= 0)
+			return ret;
+
+		/*
+		 * If the packet contains an instruction range, generate an
+		 * instruction sequence event.
+		 */
+		if (packet.sample_type & CS_ETM_RANGE)
+			cs_etm__synth_branch_sample(etmq, &packet);
+	}
+
+	return 0;
+}
+
 static int cs_etm__run_decoder(struct cs_etm_queue *etmq)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
@@ -494,6 +645,12 @@ more:
 
 		etmq->offset += processed;
 		buffer_used += processed;
+
+		/*
+		 * Nothing to do with an error condition, let's hope the next
+		 * chunk will be better.
+		 */
+		err = cs_etm__sample(etmq);
 	} while (buffer.len > buffer_used);
 
 goto more;
@@ -828,6 +985,17 @@ int cs_etm__process_auxtrace_info(union perf_event *event,
 		return 0;
 	}
 
+	if (session->itrace_synth_opts && session->itrace_synth_opts->set) {
+		etm->synth_opts = *session->itrace_synth_opts;
+	} else {
+		itrace_synth_opts__set_default(&etm->synth_opts);
+		etm->synth_opts.callchain = false;
+	}
+
+	err = cs_etm__synth_events(etm, session);
+	if (err)
+		goto err_free_queues;
+
 	err = auxtrace_queues__process_index(&etm->queues, session);
 	if (err)
 		goto err_free_queues;

  parent reply	other threads:[~2018-01-28 21:23 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-17 17:52 [PATCH v3 00/10] perf tools: Add support for CoreSight trace decoding Mathieu Poirier
2018-01-17 17:52 ` [PATCH v3 01/10] perf tools: Integrating the CoreSight decoding library Mathieu Poirier
2018-01-22 15:40   ` [PATCH] perf tools: Adding missing test file for libopencsd Mathieu Poirier
2018-01-22 16:34     ` Arnaldo Carvalho de Melo
2018-01-24 11:32     ` [tip:perf/core] perf tools: Integrating the CoreSight decoding library tip-bot for Mathieu Poirier
2018-01-28 21:16     ` tip-bot for Mathieu Poirier
2018-01-17 17:52 ` [PATCH v3 02/10] perf tools: Add initial entry point for decoder CoreSight traces Mathieu Poirier
2018-01-24 11:32   ` [tip:perf/core] " tip-bot for Mathieu Poirier
2018-01-28 21:16   ` tip-bot for Mathieu Poirier
2018-01-17 17:52 ` [PATCH v3 03/10] perf tools: Add processing of coresight metadata Mathieu Poirier
2018-01-24 11:33   ` [tip:perf/core] " tip-bot for Tor Jeremiassen
2018-01-28 21:17   ` tip-bot for Tor Jeremiassen
2018-01-17 17:52 ` [PATCH v3 04/10] perf tools: Add decoder mechanic to support dumping trace data Mathieu Poirier
2018-01-24 11:33   ` [tip:perf/core] " tip-bot for Mathieu Poirier
2018-01-28 21:17   ` tip-bot for Mathieu Poirier
2018-01-17 17:52 ` [PATCH v3 05/10] perf tools: Add support for decoding CoreSight " Mathieu Poirier
2018-01-24 11:34   ` [tip:perf/core] " tip-bot for Mathieu Poirier
2018-01-28 21:17   ` tip-bot for Mathieu Poirier
2018-01-17 17:52 ` [PATCH v3 06/10] perf tools: Add functionality to communicate with the openCSD decoder Mathieu Poirier
2018-01-24 11:34   ` [tip:perf/core] " tip-bot for Mathieu Poirier
2018-01-28 21:18   ` tip-bot for Mathieu Poirier
2018-01-17 17:52 ` [PATCH v3 07/10] pert tools: Add queue management functionality Mathieu Poirier
2018-01-22 17:25   ` Robert Walker
2018-01-22 20:14     ` Mathieu Poirier
2018-01-24 11:34   ` [tip:perf/core] " tip-bot for Mathieu Poirier
2018-01-28 21:18   ` tip-bot for Mathieu Poirier
2018-01-17 17:52 ` [PATCH v3 08/10] perf tools: Add full support for CoreSight trace decoding Mathieu Poirier
2018-01-24 11:35   ` [tip:perf/core] " tip-bot for Mathieu Poirier
2018-01-28 21:19   ` tip-bot for Mathieu Poirier
2018-01-17 17:52 ` [PATCH v3 09/10] perf tools: Add mechanic to synthesise CoreSight trace packets Mathieu Poirier
2018-01-24 11:35   ` [tip:perf/core] " tip-bot for Mathieu Poirier
2018-01-28 21:19   ` tip-bot for Mathieu Poirier [this message]
2018-01-17 17:52 ` [PATCH v3 10/10] MAINTAINERS: Adding entry for CoreSight trace decoding Mathieu Poirier
2018-01-24 11:36   ` [tip:perf/core] " tip-bot for Tor Jeremiassen
2018-01-28 21:20   ` tip-bot for Tor Jeremiassen
2018-01-17 20:04 ` [PATCH v3 00/10] perf tools: Add support " Arnaldo Carvalho de Melo
2018-01-18 13:36   ` Arnaldo Carvalho de Melo
2018-01-19 15:01 ` 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=tip-b12235b113cfd7e4a31f0c8bdb0d8e8588ba6683@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=kim.phillips@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mike.leach@arm.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=suzuki.poulose@arm.com \
    --cc=tglx@linutronix.de \
    --cc=tor@ti.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;
as well as URLs for NNTP newsgroup(s).