From patchwork Fri Dec 15 16:44:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 122127 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp707385qgn; Fri, 15 Dec 2017 08:46:20 -0800 (PST) X-Google-Smtp-Source: ACJfBousPaD8ipv3atlsHu9ln509xq95T9ArHajz9srmPyPkNJG9217Zb+xjGXzU81VQPM3jpnO3 X-Received: by 10.98.8.210 with SMTP id 79mr14127751pfi.204.1513356380692; Fri, 15 Dec 2017 08:46:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513356380; cv=none; d=google.com; s=arc-20160816; b=JfoMCyksSwQu6swgwZeM8kyV81xKJ1CiDksepBibCoDd7bhhrcAaVOD5EnPgQOJ5/t BImnKILYSf+h4/OBNwdhbQiyG58rcf0G7/8jvd/UgomjX3AQAd9UO/QBVa/gA3yHikP5 L9IAnzYji7E8qHnbxVA6AsYmeqYXxwzsz5ENV8viXLhgnYjYvxsvisOw+nqZQF+WfpQL Z0S/Exj/qmp9h6SafG9v19ukcqOOiZb/e0WzYryb7PQ1qvy7ANXZg2SB22m4hJTWn+wV hPS/yHgMmkMPwumGtfzsk3eW5MBOODaad4TERwGlyNB02PXAJtVfwLhBOyNmLo5NlZFD ritg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=BR7xt2VJtmDUTrTdEJiMj3kNwmYfv+/f0h+P8K5mO8Q=; b=m2gR+iiO1N64x4dMAmEBYpLm13bPsOAmuvmKyWqvbOx/z1WEDS6jP//Br1cfHpfuJ2 r+tZ+yDDHDaFyec1Nh9s6D0IhkruP67DmZrddes3QKoeHlJfYbCIZKC5jMCEDW77hLcY bzZIb+krBIoQqxdR4Ws3Xl+iEAl4p0KfIk1VhaEljQmQ+kZXTWDTgNcjQWGjFpL1aloE 1asrMQH8rGf83Qk+mZZ6ibhhRYSM1/KZnzut36nC3yMQzpkhRmpnEgZ18fGacLP9HRJM FViJj3v0p2jqXFmwdKIJNHsiXUxqaa1qyppQC7QeV70zLOPW/x8tSpmBIQSvmFDAm4+o K1qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g02U4Syz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3si5239597plb.293.2017.12.15.08.46.20; Fri, 15 Dec 2017 08:46:20 -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; dkim=pass header.i=@linaro.org header.s=google header.b=g02U4Syz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757016AbdLOQqR (ORCPT + 24 others); Fri, 15 Dec 2017 11:46:17 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:38010 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756908AbdLOQpW (ORCPT ); Fri, 15 Dec 2017 11:45:22 -0500 Received: by mail-it0-f65.google.com with SMTP id r6so20324254itr.3 for ; Fri, 15 Dec 2017 08:45:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BR7xt2VJtmDUTrTdEJiMj3kNwmYfv+/f0h+P8K5mO8Q=; b=g02U4SyzF4zGbmYNXKr5dyo8me+hIXb5gFFr4ZNnZ3G5mqDps6agYFoY/LP7fbZ+9V lAdvBfnSZ3W8aRAlQW8Bf+glU7ZzpznyEIGNGt6vbTW9j0Zg6+GL2B2K+6B5WAjzhmiM wTZ2uguN6bHrAfzn6B7f7EKf3SncQuDPgaIxs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BR7xt2VJtmDUTrTdEJiMj3kNwmYfv+/f0h+P8K5mO8Q=; b=XS7ayh5WGe70iS/CVCLKgXLiBWVsKryoC0Y+zmu5ABqdfCXKhJ4uWcEZyMWFDYFOK8 ZP+FOa1omKjuFFNHn8fnNRW81uO8v3su3a0q3gHWykVryM3h5z5qs8PT/z4e70MbvQTe 3sWfHrZwCpHsPEhCj86T8Gv0xNM7KbwbCeWQByLFk7R486Xx6oXOdB1hO8zDjPyhyLoM o8shq/k52NkgOivTOeBjbIki8ddhR32Ic3QYM75skJMVuvQI7ZLPATDwv2wjcZ0fay5F fWNPoqEXLVJpoBQkO5G+Jpb3rI+K+ue23e2R6ldwoJhfkgnobx50WbF/xKZWoJbxSPG/ otng== X-Gm-Message-State: AKGB3mIjW+YG8BCPkXccjlySrP1E7Ph2ge+GKSSvfK3gwxxf6dE61Oy0 jgD20cra8VypHFPgKPhBNPEkRfKqhSQ= X-Received: by 10.36.7.12 with SMTP id f12mr8515711itf.86.1513356321983; Fri, 15 Dec 2017 08:45:21 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id q132sm3631732iod.26.2017.12.15.08.45.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Dec 2017 08:45:20 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, adrian.hunter@intel.com, mike.leach@arm.com, suzuki.poulosi@arm.com, tor@ti.com, jolsa@redhat.com, mathieu.poirier@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 08/10] perf tools: Add full support for CoreSight trace decoding Date: Fri, 15 Dec 2017 09:44:57 -0700 Message-Id: <1513356299-26274-9-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513356299-26274-1-git-send-email-mathieu.poirier@linaro.org> References: <1513356299-26274-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- tools/perf/util/cs-etm.c | 166 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 160 insertions(+), 6 deletions(-) -- 2.7.4 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 83eb676274b5..407095af1456 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; }