Received: by 10.223.176.5 with SMTP id f5csp2167549wra; Sun, 28 Jan 2018 14:01:48 -0800 (PST) X-Google-Smtp-Source: AH8x224hB13H8IZQNL6rL3Ao0r/3JJVcLtkO0h0JOEoPSc9aPMoKXyvxOM+0XVpjluK32ZOAqD0O X-Received: by 10.101.68.199 with SMTP id g7mr19936352pgs.21.1517176908785; Sun, 28 Jan 2018 14:01:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517176908; cv=none; d=google.com; s=arc-20160816; b=V502+9rT9oBdRGPQeKUL814M7gtAwGeylbXuWWIbOpTgUuCcEloFXcBgEK/dET6q64 Kagmln9+St1tP/B/VZI+Wcc/8Gc5VSj8e11bG4lIiYM6U+qCXbfetd4FHz57twNUV9rc q5+7WzVUvXSlEVHKjQMqbrzWJIcYUkwphrfBcHnJUnEFuQOiSGcLLxaNUTSGHjTlA/4x QgZPDJ0X5PBozFBGLOYZ6yf7JzUS/Udrg18l/U5JUiESk12G3UJ8+Yf7WNZgjBWvBoDF r8Hs+In1vIxug6U5EFphsYNQjyDx6ywSNgbmE5nWiFfv1hKCYk8pU1gndUszXULkel8l EjDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=71GXHSLtoVpoxTEaIvyj+L2IkVk3V4ZjDKi3urScV+o=; b=TvWupBb8dDX7x+qT2GUSz8Y3MVfZzOR2FufVLAjcu2I0lWvUzu5OZIs2LJJTrrKQGW r76E6Gf42M05mdW6MIEN3tBt2Tp2EDgQzqW2yz28Z/N6zYHra1JGuVp1lPVthJ5SUiQN RQyDvDYUf9O/T3oIoNACxYA9+8o4vDVPLtglHJP9p5kUwIAUIomG2XF0ouWxgmH6GKGy uKuKyzn7NpZ4Fo7NR0eFGwFb7iOrd+wauQQJrddCJTlZBYRjSBe5+CXjE/lQPLHcwN/Z rBCPuWVO9qck41iZbZEdHwVF/62vPP6zhS+QU9RTIQH7S9Ngy2DdGlhB/0M3Hss3MQdo TmyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9-v6si719747plo.697.2018.01.28.14.01.34; Sun, 28 Jan 2018 14:01:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753385AbeA1VW7 (ORCPT + 99 others); Sun, 28 Jan 2018 16:22:59 -0500 Received: from terminus.zytor.com ([65.50.211.136]:37599 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752886AbeA1VW5 (ORCPT ); Sun, 28 Jan 2018 16:22:57 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w0SLJFlf008109; Sun, 28 Jan 2018 13:19:15 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w0SLJFpS008106; Sun, 28 Jan 2018 13:19:15 -0800 Date: Sun, 28 Jan 2018 13:19:15 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Mathieu Poirier Message-ID: Cc: acme@redhat.com, alexander.shishkin@linux.intel.com, mathieu.poirier@linaro.org, linux-kernel@vger.kernel.org, tor@ti.com, tglx@linutronix.de, peterz@infradead.org, mike.leach@arm.com, hpa@zytor.com, adrian.hunter@intel.com, jolsa@redhat.com, suzuki.poulose@arm.com, kim.phillips@arm.com, namhyung@kernel.org, mingo@kernel.org Reply-To: kim.phillips@arm.com, suzuki.poulose@arm.com, namhyung@kernel.org, mingo@kernel.org, jolsa@redhat.com, peterz@infradead.org, tglx@linutronix.de, adrian.hunter@intel.com, hpa@zytor.com, mike.leach@arm.com, alexander.shishkin@linux.intel.com, acme@redhat.com, linux-kernel@vger.kernel.org, tor@ti.com, mathieu.poirier@linaro.org In-Reply-To: <1516211539-5166-9-git-send-email-mathieu.poirier@linaro.org> References: <1516211539-5166-9-git-send-email-mathieu.poirier@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Add full support for CoreSight trace decoding Git-Commit-ID: 9f878b29da969e195e106992ea8572da3d244811 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 9f878b29da969e195e106992ea8572da3d244811 Gitweb: https://git.kernel.org/tip/9f878b29da969e195e106992ea8572da3d244811 Author: Mathieu Poirier AuthorDate: Wed, 17 Jan 2018 10:52:17 -0700 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 25 Jan 2018 06:37:27 -0300 perf tools: Add full support for CoreSight trace decoding This patch adds support for complete packet decoding, allowing traces collected during a trace session to be decoder from the "report" infrastructure. Co-authored-by: Tor Jeremiassen Signed-off-by: Mathieu Poirier Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Kim Phillips Cc: Mike Leach Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Suzuki Poulouse Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/1516211539-5166-9-git-send-email-mathieu.poirier@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cs-etm.c | 166 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 160 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 83eb6762..407095a 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -70,6 +70,10 @@ struct cs_etm_queue { u64 offset; }; +static int cs_etm__update_queues(struct cs_etm_auxtrace *etm); +static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm, + pid_t tid, u64 time_); + static void cs_etm__packet_dump(const char *pkt_string) { const char *color = PERF_COLOR_BLUE; @@ -145,9 +149,25 @@ static void cs_etm__dump_event(struct cs_etm_auxtrace *etm, static int cs_etm__flush_events(struct perf_session *session, struct perf_tool *tool) { - (void) session; - (void) tool; - return 0; + int ret; + struct cs_etm_auxtrace *etm = container_of(session->auxtrace, + struct cs_etm_auxtrace, + auxtrace); + if (dump_trace) + return 0; + + if (!tool->ordered_events) + return -EINVAL; + + if (!etm->timeless_decoding) + return -EINVAL; + + ret = cs_etm__update_queues(etm); + + if (ret < 0) + return ret; + + return cs_etm__process_timeless_queues(etm, -1, MAX_TIMESTAMP - 1); } static void cs_etm__free_queue(void *priv) @@ -369,6 +389,138 @@ static int cs_etm__update_queues(struct cs_etm_auxtrace *etm) return 0; } +static int +cs_etm__get_trace(struct cs_etm_buffer *buff, struct cs_etm_queue *etmq) +{ + struct auxtrace_buffer *aux_buffer = etmq->buffer; + struct auxtrace_buffer *old_buffer = aux_buffer; + struct auxtrace_queue *queue; + + queue = &etmq->etm->queues.queue_array[etmq->queue_nr]; + + aux_buffer = auxtrace_buffer__next(queue, aux_buffer); + + /* If no more data, drop the previous auxtrace_buffer and return */ + if (!aux_buffer) { + if (old_buffer) + auxtrace_buffer__drop_data(old_buffer); + buff->len = 0; + return 0; + } + + etmq->buffer = aux_buffer; + + /* If the aux_buffer doesn't have data associated, try to load it */ + if (!aux_buffer->data) { + /* get the file desc associated with the perf data file */ + int fd = perf_data__fd(etmq->etm->session->data); + + aux_buffer->data = auxtrace_buffer__get_data(aux_buffer, fd); + if (!aux_buffer->data) + return -ENOMEM; + } + + /* If valid, drop the previous buffer */ + if (old_buffer) + auxtrace_buffer__drop_data(old_buffer); + + buff->offset = aux_buffer->offset; + buff->len = aux_buffer->size; + buff->buf = aux_buffer->data; + + buff->ref_timestamp = aux_buffer->reference; + + return buff->len; +} + +static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm, + struct auxtrace_queue *queue) +{ + struct cs_etm_queue *etmq = queue->priv; + + /* CPU-wide tracing isn't supported yet */ + if (queue->tid == -1) + return; + + if ((!etmq->thread) && (etmq->tid != -1)) + etmq->thread = machine__find_thread(etm->machine, -1, + etmq->tid); + + if (etmq->thread) { + etmq->pid = etmq->thread->pid_; + if (queue->cpu == -1) + etmq->cpu = etmq->thread->cpu; + } +} + +static int cs_etm__run_decoder(struct cs_etm_queue *etmq) +{ + struct cs_etm_auxtrace *etm = etmq->etm; + struct cs_etm_buffer buffer; + size_t buffer_used, processed; + int err = 0; + + if (!etm->kernel_start) + etm->kernel_start = machine__kernel_start(etm->machine); + + /* Go through each buffer in the queue and decode them one by one */ +more: + buffer_used = 0; + memset(&buffer, 0, sizeof(buffer)); + err = cs_etm__get_trace(&buffer, etmq); + if (err <= 0) + return err; + /* + * We cannot assume consecutive blocks in the data file are contiguous, + * reset the decoder to force re-sync. + */ + err = cs_etm_decoder__reset(etmq->decoder); + if (err != 0) + return err; + + /* Run trace decoder until buffer consumed or end of trace */ + do { + processed = 0; + + err = cs_etm_decoder__process_data_block( + etmq->decoder, + etmq->offset, + &buffer.buf[buffer_used], + buffer.len - buffer_used, + &processed); + + if (err) + return err; + + etmq->offset += processed; + buffer_used += processed; + } while (buffer.len > buffer_used); + +goto more; + + return err; +} + +static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm, + pid_t tid, u64 time_) +{ + unsigned int i; + struct auxtrace_queues *queues = &etm->queues; + + for (i = 0; i < queues->nr_queues; i++) { + struct auxtrace_queue *queue = &etm->queues.queue_array[i]; + struct cs_etm_queue *etmq = queue->priv; + + if (etmq && ((tid == -1) || (etmq->tid == tid))) { + etmq->time = time_; + cs_etm__set_pid_tid_cpu(etm, queue); + cs_etm__run_decoder(etmq); + } + } + + return 0; +} + static int cs_etm__process_event(struct perf_session *session, union perf_event *event, struct perf_sample *sample, @@ -380,9 +532,6 @@ static int cs_etm__process_event(struct perf_session *session, struct cs_etm_auxtrace, auxtrace); - /* Keep compiler happy */ - (void)event; - if (dump_trace) return 0; @@ -405,6 +554,11 @@ static int cs_etm__process_event(struct perf_session *session, return err; } + if (event->header.type == PERF_RECORD_EXIT) + return cs_etm__process_timeless_queues(etm, + event->fork.tid, + sample->time); + return 0; }