linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>,
	Kim Phillips <kim.phillips@arm.com>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Suzuki Poulouse <suzuki.poulose@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	linux-kernel@vger.kernel.org,
	Adrian Hunter <adrian.hunter@intel.com>,
	linux-perf-users@vger.kernel.org,
	Peter Zijlstra <peterz@infradead.org>,
	Mike Leach <mike.leach@arm.com>,
	Namhyung Kim <namhyung@kernel.org>,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH 34/43] pert tools: Add queue management functionality
Date: Tue, 23 Jan 2018 10:12:42 -0300	[thread overview]
Message-ID: <20180123131251.28197-35-acme@kernel.org> (raw)
In-Reply-To: <20180123131251.28197-1-acme@kernel.org>

From: Mathieu Poirier <mathieu.poirier@linaro.org>

Add functionatlity to setup trace queues so that traces associated with
CoreSight auxtrace events found in the perf.data file can be classified
properly.  The decoder and memory callback associated with each queue are
then used to decode the traces that have been assigned to that queue.

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-8-git-send-email-mathieu.poirier@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cs-etm.c | 208 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 204 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index cad429ce3c00..83eb676274b5 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -196,15 +196,215 @@ static void cs_etm__free(struct perf_session *session)
 	zfree(&aux);
 }
 
+static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address,
+			      size_t size, u8 *buffer)
+{
+	u8  cpumode;
+	u64 offset;
+	int len;
+	struct	 thread *thread;
+	struct	 machine *machine;
+	struct	 addr_location al;
+
+	if (!etmq)
+		return -1;
+
+	machine = etmq->etm->machine;
+	if (address >= etmq->etm->kernel_start)
+		cpumode = PERF_RECORD_MISC_KERNEL;
+	else
+		cpumode = PERF_RECORD_MISC_USER;
+
+	thread = etmq->thread;
+	if (!thread) {
+		if (cpumode != PERF_RECORD_MISC_KERNEL)
+			return -EINVAL;
+		thread = etmq->etm->unknown_thread;
+	}
+
+	thread__find_addr_map(thread, cpumode, MAP__FUNCTION, address, &al);
+
+	if (!al.map || !al.map->dso)
+		return 0;
+
+	if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
+	    dso__data_status_seen(al.map->dso, DSO_DATA_STATUS_SEEN_ITRACE))
+		return 0;
+
+	offset = al.map->map_ip(al.map, address);
+
+	map__load(al.map);
+
+	len = dso__data_read_offset(al.map->dso, machine, offset, buffer, size);
+
+	if (len <= 0)
+		return 0;
+
+	return len;
+}
+
+static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm,
+						unsigned int queue_nr)
+{
+	int i;
+	struct cs_etm_decoder_params d_params;
+	struct cs_etm_trace_params  *t_params;
+	struct cs_etm_queue *etmq;
+
+	etmq = zalloc(sizeof(*etmq));
+	if (!etmq)
+		return NULL;
+
+	etmq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE);
+	if (!etmq->event_buf)
+		goto out_free;
+
+	etmq->etm = etm;
+	etmq->queue_nr = queue_nr;
+	etmq->pid = -1;
+	etmq->tid = -1;
+	etmq->cpu = -1;
+
+	/* Use metadata to fill in trace parameters for trace decoder */
+	t_params = zalloc(sizeof(*t_params) * etm->num_cpu);
+
+	if (!t_params)
+		goto out_free;
+
+	for (i = 0; i < etm->num_cpu; i++) {
+		t_params[i].protocol = CS_ETM_PROTO_ETMV4i;
+		t_params[i].etmv4.reg_idr0 = etm->metadata[i][CS_ETMV4_TRCIDR0];
+		t_params[i].etmv4.reg_idr1 = etm->metadata[i][CS_ETMV4_TRCIDR1];
+		t_params[i].etmv4.reg_idr2 = etm->metadata[i][CS_ETMV4_TRCIDR2];
+		t_params[i].etmv4.reg_idr8 = etm->metadata[i][CS_ETMV4_TRCIDR8];
+		t_params[i].etmv4.reg_configr =
+					etm->metadata[i][CS_ETMV4_TRCCONFIGR];
+		t_params[i].etmv4.reg_traceidr =
+					etm->metadata[i][CS_ETMV4_TRCTRACEIDR];
+	}
+
+	/* Set decoder parameters to simply print the trace packets */
+	d_params.packet_printer = cs_etm__packet_dump;
+	d_params.operation = CS_ETM_OPERATION_DECODE;
+	d_params.formatted = true;
+	d_params.fsyncs = false;
+	d_params.hsyncs = false;
+	d_params.frame_aligned = true;
+	d_params.data = etmq;
+
+	etmq->decoder = cs_etm_decoder__new(etm->num_cpu, &d_params, t_params);
+
+	zfree(&t_params);
+
+	if (!etmq->decoder)
+		goto out_free;
+
+	/*
+	 * Register a function to handle all memory accesses required by
+	 * the trace decoder library.
+	 */
+	if (cs_etm_decoder__add_mem_access_cb(etmq->decoder,
+					      0x0L, ((u64) -1L),
+					      cs_etm__mem_access))
+		goto out_free_decoder;
+
+	etmq->offset = 0;
+
+	return etmq;
+
+out_free_decoder:
+	cs_etm_decoder__free(etmq->decoder);
+out_free:
+	zfree(&etmq->event_buf);
+	free(etmq);
+
+	return NULL;
+}
+
+static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm,
+			       struct auxtrace_queue *queue,
+			       unsigned int queue_nr)
+{
+	struct cs_etm_queue *etmq = queue->priv;
+
+	if (list_empty(&queue->head) || etmq)
+		return 0;
+
+	etmq = cs_etm__alloc_queue(etm, queue_nr);
+
+	if (!etmq)
+		return -ENOMEM;
+
+	queue->priv = etmq;
+
+	if (queue->cpu != -1)
+		etmq->cpu = queue->cpu;
+
+	etmq->tid = queue->tid;
+
+	return 0;
+}
+
+static int cs_etm__setup_queues(struct cs_etm_auxtrace *etm)
+{
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < etm->queues.nr_queues; i++) {
+		ret = cs_etm__setup_queue(etm, &etm->queues.queue_array[i], i);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int cs_etm__update_queues(struct cs_etm_auxtrace *etm)
+{
+	if (etm->queues.new_data) {
+		etm->queues.new_data = false;
+		return cs_etm__setup_queues(etm);
+	}
+
+	return 0;
+}
+
 static int cs_etm__process_event(struct perf_session *session,
 				 union perf_event *event,
 				 struct perf_sample *sample,
 				 struct perf_tool *tool)
 {
-	(void) session;
-	(void) event;
-	(void) sample;
-	(void) tool;
+	int err = 0;
+	u64 timestamp;
+	struct cs_etm_auxtrace *etm = container_of(session->auxtrace,
+						   struct cs_etm_auxtrace,
+						   auxtrace);
+
+	/* Keep compiler happy */
+	(void)event;
+
+	if (dump_trace)
+		return 0;
+
+	if (!tool->ordered_events) {
+		pr_err("CoreSight ETM Trace requires ordered events\n");
+		return -EINVAL;
+	}
+
+	if (!etm->timeless_decoding)
+		return -EINVAL;
+
+	if (sample->time && (sample->time != (u64) -1))
+		timestamp = sample->time;
+	else
+		timestamp = 0;
+
+	if (timestamp || etm->timeless_decoding) {
+		err = cs_etm__update_queues(etm);
+		if (err)
+			return err;
+	}
+
 	return 0;
 }
 
-- 
2.14.3

  parent reply	other threads:[~2018-01-23 13:12 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-23 13:12 [GIT PULL 00/43] perf/core improvements and changes Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 01/43] perf intel-pt/bts: Do not swap when synthesizing samples Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 02/43] perf evsel: Ensure reserved member of PERF_SAMPLE_CPU is zero in perf_event__synthesize_sample() Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 03/43] perf tools: Get rid of unused 'swapped' parameter from perf_event__synthesize_sample() Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 04/43] perf tools: Use ui__error() for reporting --fields errors Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 05/43] perf bpf: Don't warn about unavailability of builtin clang, just fallback Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 06/43] perf tools: Move conditional O_CLOEXEC to util.h Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 07/43] perf symbols: Using O_CLOEXEC in do_open Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 08/43] perf report: Fix regression when decoding intel_pt traces Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 09/43] perf build: Display EXTRA features for VF=1 build Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 10/43] tools include arch: Grab a copy of errno.h for arch's supported by perf Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 11/43] tools include asm-generic: Grab errno.h and errno-base.h Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 12/43] perf util: Introduce architecture specific errno/name mapping Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 13/43] perf trace: Obtain errno strings by using arch_syscalls__strerrno() Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 14/43] perf trace: Remove audit-libs dependency if syscall tables are present Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 15/43] perf vendor events intel: Update Broadwell events to V22 Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 16/43] perf vendor events intel: Update BroadwellX events to V13 Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 17/43] perf vendor events intel: Update Goldmont events to V12 Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 18/43] perf vendor events intel: Update Haswell events to V27 Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 19/43] perf vendor events intel: Update HaswellX events to V19 Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 20/43] perf vendor events intel: Update IvyBridge events to V20 Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 21/43] perf vendor events intel: Update IvyTown " Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 22/43] perf vendor events intel: Update Silvermont events to V14 Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 23/43] perf vendor events intel: Update Skylake events to V36 Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 24/43] perf vendor events intel: Update SkylakeX events to V1.06 Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 25/43] perf vendor events intel: Update BroadwellDE events to V7 Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 26/43] perf vendor events intel: Update IvyBridge files to V20 Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 27/43] perf vendor events intel: Update IvyTown " Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 28/43] perf tools: Integrating the CoreSight decoding library Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 29/43] perf tools: Add initial entry point for decoder CoreSight traces Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 30/43] perf tools: Add processing of coresight metadata Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 31/43] perf tools: Add decoder mechanic to support dumping trace data Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 32/43] perf tools: Add support for decoding CoreSight " Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 33/43] perf tools: Add functionality to communicate with the openCSD decoder Arnaldo Carvalho de Melo
2018-01-23 13:12 ` Arnaldo Carvalho de Melo [this message]
2018-01-23 13:12 ` [PATCH 35/43] perf tools: Add full support for CoreSight trace decoding Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 36/43] perf tools: Add mechanic to synthesise CoreSight trace packets Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 37/43] MAINTAINERS: Adding entry for CoreSight trace decoding Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 38/43] perf bpf: Remove misplaced __maybe_unused attribute Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 39/43] perf trace: Add --print-sample Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 40/43] perf trace: Do not print from time delta for interrupted syscall lines Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 41/43] perf trace beauty futex: Beautify FUTEX_BITSET_MATCH_ANY Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 42/43] perf evlist: Remove fcntl.h from evlist.h Arnaldo Carvalho de Melo
2018-01-23 13:12 ` [PATCH 43/43] perf trace beauty flock: Move to separate object file Arnaldo Carvalho de Melo
2018-01-24 11:15 ` [GIT PULL 00/43] perf/core improvements and changes Ingo Molnar

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=20180123131251.28197-35-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=kim.phillips@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@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 \
    /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).