From patchwork Fri Dec 15 16:44:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 122123 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp706642qgn; Fri, 15 Dec 2017 08:45:33 -0800 (PST) X-Google-Smtp-Source: ACJfBotabMLthPtZX0zcgfq9gydbNuuUPBarYK3KABwcufCoX1n16rTeC3HCxAZCu3uPm1xCQ248 X-Received: by 10.99.180.11 with SMTP id s11mr12160651pgf.174.1513356333743; Fri, 15 Dec 2017 08:45:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513356333; cv=none; d=google.com; s=arc-20160816; b=pKhpkvlKMnGASuCHONszWUVCo62FqBjn/sFZzJGM/s1iGckf0QV5LjXoX5lIYMFH/z mEMfxpFxUz4rXrfyElxPFt7bwrRt6dA6rFik/3hAvSY8nswSqEN6NcPi+G6K3UHMHuaG 18/PmCxsmecuhx+Nc5UwjoLMVnOT81wAvIXn6qwgAHBbD0UN6Y7NlZw5gNpTx6DqCrDd zj7UMboklAu/yk5MmHW+bJBZZTrXIzX2RBN1msPh2NFILYlTMqFdwqL076h3O/eSPPAF 3DqBxYf8nN1E9W9IJJhAXHKqmvPv6Ve00Ze81Hp+CjiAO6V7J3SFAt3BfbxOB2qeo5a0 I24g== 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=nse+24OctCfX1/9soi5qNADvKvzH+f65AljLKc2a034=; b=Nm1V2zGYLgQRR+AUMIsCoMSLitsfgy/6P1dyjOt6j0O+P4j2RyeF2g7wkkSILBK3u3 1oPSm491O6Z/Q5o/E7Y01WWq1NlPnfsc7Wyj/Hv2u/A6abDhn+UbLyZdUfGhV4TKaRsL jMX9ikAr/9wcaIHG/QHAT1hekndEos7pF+b919dpjedS6m055r6jQ0y8N8fwgCFGz+0Q dVr8DaVxewMk4Y5R5jhb2YlPcBpUgMIEdSkmwCcXmLk3TRkCyjIVJJ35o+7rXYQrcBH6 jGWjmqpGheDGRlnA4Hc2AF69Ngjwc0Nt24SdAt239wpPJJUAZ/+a/O79FR6kvfxIz5sQ lfkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WVtD6uZF; 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 z6si4837219pgz.111.2017.12.15.08.45.33; Fri, 15 Dec 2017 08:45:33 -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=WVtD6uZF; 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 S1756940AbdLOQpa (ORCPT + 24 others); Fri, 15 Dec 2017 11:45:30 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:37991 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756767AbdLOQpU (ORCPT ); Fri, 15 Dec 2017 11:45:20 -0500 Received: by mail-it0-f65.google.com with SMTP id r6so20323955itr.3 for ; Fri, 15 Dec 2017 08:45:20 -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=nse+24OctCfX1/9soi5qNADvKvzH+f65AljLKc2a034=; b=WVtD6uZFoJrtgpvVoLsCh9EOV7Ey2Gh8SztesaAVtZkqYNTfcumObOeLHeWGbKwwLX CbInSoBweyffX8ymoHakahPG6o3kuVkvbwqpY8dBh89Oy3T/akbgdgKkH53qUeVUaJzS LK3vboMSwlMMQTPW1sKjf9xuL3WOyR76bJ5EA= 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=nse+24OctCfX1/9soi5qNADvKvzH+f65AljLKc2a034=; b=MvYAyNGZU2A9wH5cOleaPstMFqxEi8rCpt5J8Ho3bsNh6/RFgi4l0VdrMEXS8aGbCg YfzmUO960oz+lLamhO6DwfPh4h1xyUTPUOwH21DJwIoAmrtHA1sKkSqRjx5Qn2c5fl+8 bP5lnlYooOIcLLz4Lyd32Wa/Ihp1tq5FVXE3yMvN2UF0wgXnTULlVWP6qSRD5/UtqXdD npNtT+11zt6PoblWcj0oyHDyqzwAmhXZmCHOYQTCsQpLk09CVqpuuKG3XU7m1OQtvFUS c0U6DsTHT2MUP0s3LbpPnAH5VJ3YywX8mT4LZFu99W2zSwrmSsc4jxLr8jg6MOky8X6i 1UIg== X-Gm-Message-State: AKGB3mLjdnLpRq/MQiYdpCj2dZ8sUCBCqOYKqv1A8M4R/7v6Cgc1XIq4 mtQRE5Sb/UljGS3D9/AfwuM30w== X-Received: by 10.36.116.135 with SMTP id o129mr8390035itc.119.1513356319617; Fri, 15 Dec 2017 08:45:19 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Dec 2017 08:45:18 -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 07/10] pert tools: Add queue management functionality Date: Fri, 15 Dec 2017 09:44:56 -0700 Message-Id: <1513356299-26274-8-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 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 Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 208 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 4 deletions(-) -- 2.7.4 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; }