Received: by 10.223.176.5 with SMTP id f5csp2166347wra; Sun, 28 Jan 2018 14:00:31 -0800 (PST) X-Google-Smtp-Source: AH8x224299vzXROY+cQGfq5pZIxYIAzxTnrnpKSv+aEul4Cfoy7QC7QUBKaaFB/GOzIaZNudwbPe X-Received: by 10.98.197.3 with SMTP id j3mr24610541pfg.93.1517176830989; Sun, 28 Jan 2018 14:00:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517176830; cv=none; d=google.com; s=arc-20160816; b=YW6U0WP4EVUQw+KNpPvkhyBPtPWS6oBz5D7w7mMqSKCA0tgcM9z1UMTPMf0aO3UZjT m/HFJ25nD7hT0SCyqhnVujksBDNhqSeyB9U9tsYxrLVVr3awHbxpD4DP88P5Xz1ZCHfi nU4VYyEHfluHU/rwJ5QMij5gY40vceLW3cc6vo1EvBq4q5+UTkhtEHPFuoxrs+FfJ2Hx AX79QueTHheHnWeccJIuEWSKZty4p0ghPVCUdiwudPIvinZ+y7gxd8VpKJ19R9HZONbK 1XV7UAOggf5+ey3xho7vH6dGhHTzzVdwjIxGuMG7c2/YIKasOAA0c8mh7gD60vjiMPWu 09Zw== 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=7g/FjzXMa8JXeqcYIXZcNDXIlgYYZLR1acgctmBWWPw=; b=AdFvF9aybhkswAIq3MUE1mmyLmjhcVZtd8BKWCnFsit9CEihmn+fZwesTmjPYGAtac i5y6M7qDTwVQGW69Iq5WiMJIJ4OS6i+zmqq06GSlkIj81ZaIaCALr3R0s9mTJPDH3z3U VszgX/euCknZZxKA27YghLAu/V/zXmb/ICi5bKSSRypOU4MyZqZJSsKboEb/VDkde562 6jC+e0amjW0T2j7nkDCU6m1HPbob7r4G4EXnCopnCf6A6OxDKnSoImTGAtmiuu+IUYaT 3SW0jnMXg4KIDIFkG8pW2FZR105ttWhkrITO4n+vmkEUL/wZuOULP7FqUVDAybHd9OLx mFUA== 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 w81si8275528pfj.67.2018.01.28.14.00.16; Sun, 28 Jan 2018 14:00:30 -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 S1753352AbeA1VWe (ORCPT + 99 others); Sun, 28 Jan 2018 16:22:34 -0500 Received: from terminus.zytor.com ([65.50.211.136]:52421 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752724AbeA1VWc (ORCPT ); Sun, 28 Jan 2018 16:22:32 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w0SLIocR008061; Sun, 28 Jan 2018 13:18:50 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w0SLInO3008057; Sun, 28 Jan 2018 13:18:49 -0800 Date: Sun, 28 Jan 2018 13:18:49 -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: jolsa@redhat.com, suzuki.poulose@arm.com, tor@ti.com, mathieu.poirier@linaro.org, mingo@kernel.org, alexander.shishkin@linux.intel.com, acme@redhat.com, hpa@zytor.com, linux-kernel@vger.kernel.org, adrian.hunter@intel.com, peterz@infradead.org, mike.leach@arm.com, namhyung@kernel.org, tglx@linutronix.de, kim.phillips@arm.com Reply-To: alexander.shishkin@linux.intel.com, acme@redhat.com, mathieu.poirier@linaro.org, jolsa@redhat.com, tor@ti.com, suzuki.poulose@arm.com, mingo@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org, adrian.hunter@intel.com, peterz@infradead.org, tglx@linutronix.de, kim.phillips@arm.com, mike.leach@arm.com, namhyung@kernel.org In-Reply-To: <1516211539-5166-8-git-send-email-mathieu.poirier@linaro.org> References: <1516211539-5166-8-git-send-email-mathieu.poirier@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] pert tools: Add queue management functionality Git-Commit-ID: 20d9c478b01aa1a652db54c1fe867dc92636bc70 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: 20d9c478b01aa1a652db54c1fe867dc92636bc70 Gitweb: https://git.kernel.org/tip/20d9c478b01aa1a652db54c1fe867dc92636bc70 Author: Mathieu Poirier AuthorDate: Wed, 17 Jan 2018 10:52:16 -0700 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 25 Jan 2018 06:37:26 -0300 pert tools: Add queue management functionality 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 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-8-git-send-email-mathieu.poirier@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- 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 cad429c..83eb6762 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; }