From patchwork Mon May 28 08:45:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 137032 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2560024lji; Mon, 28 May 2018 01:45:52 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrJ6XYj1tMUD4hPPLpsWBV9oKG2c26lr1zY0ZgUmI0qnvsqzkF4ATlkvoBXt1ci9V0SKQys X-Received: by 2002:a63:8a4a:: with SMTP id y71-v6mr9613731pgd.291.1527497151875; Mon, 28 May 2018 01:45:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527497151; cv=none; d=google.com; s=arc-20160816; b=d+bNXH6cIW6c+JvE0Cm9k2tSirRHGa8rnGDx8dHW3TdxEeC0PYU5jo2dd4Wi0j1sDQ 9QJtK51izN0/2o32EUZQDE80nZuo9hBTDzjlq0jRt/calxA2t0vJmWwtSarsADjjOQkG 4lmgPHD3Sm3TVLbmPIZEn2iUpY68znCYt0T39sqAKomPaOOS4vtSI3RtUVEQfxSzY7IA lUy0QN2aYAtlmeoHYKkqf3pI26HwAkbCZm+IkPwa4KhrxgKxf0XzYgKTW/sHUtHhAQ+8 Pzov99oA7EegsQVH1VQBcYa7dDNPM/SnbJnkAuhDPsZB6qjFewtWctgvnO3fVkgpxXfE MT9Q== 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=Lji3vyYRuIF5z4NfQhW1RnWAxHyPoIpzDIEswsoWVp4=; b=XrpBNqmila30EDWjSImUODJcOcS4/QepxMIA1fBVOxEqFJhx9sdoEa6I0WWfWjewl8 p1qN8YvQ9wVdkWLlzUjjN0yzVD4leYHLNwnKlRZFUk9rRnSB4zMGngny0agcmKnFI61C r7FLf3tuC9OZvALX0ElibsPG0qkDRUKc2c9xcnE8oS3sG9AKL4c6cN3G4cxPmx29kmAz 5Y1JjVUBiF9YCvGmucO+NsJ/vbEZGa/Lwu+Xv8i5E+JtAgHYHYP0JGC+XyMTZKpnrOSd MoF9iojUziZP+VNeToL2SIJJ+ntrp+Kbq2pn5B2bSDzaQP2SnUqX6wWuXx0ZROWb1CCx z3jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WW+eEcGy; 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 l4-v6si5702765pgq.65.2018.05.28.01.45.51; Mon, 28 May 2018 01:45:51 -0700 (PDT) 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=WW+eEcGy; 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 S932105AbeE1Ipu (ORCPT + 30 others); Mon, 28 May 2018 04:45:50 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:50907 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754125AbeE1Ipn (ORCPT ); Mon, 28 May 2018 04:45:43 -0400 Received: by mail-wm0-f68.google.com with SMTP id t11-v6so30094146wmt.0 for ; Mon, 28 May 2018 01:45:43 -0700 (PDT) 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=Lji3vyYRuIF5z4NfQhW1RnWAxHyPoIpzDIEswsoWVp4=; b=WW+eEcGyCWeBef21OlxgVGrVRY0JrUSYpwUYryP9DwNie2RnnC10cn/vF9cCOsDJnX RA6kiEYtWInbK1Y/AS/2rPsb7ZxXgmNdshKZAQk3kdQUBmHqbBDUE4pIau+SqgQmI8YE rNa6QaFMqBrNtyKPOCKcxm1icUtgeMb0MTLEI= 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=Lji3vyYRuIF5z4NfQhW1RnWAxHyPoIpzDIEswsoWVp4=; b=n0i/B29R7OAkvb+rdC0lKxXZpHKK0T95VrvSF6s/PG3om3K/PrI3aRQ4DJqPLg2fRf AFCtZSt+wFSl9RYGhSjPGLQOU5/VB0cUA3rrHIPIPDs+zhB4p1ZMBlez6gFPkswvbl5M xIuvoCP+hPxn/b88VZzrOm8ZDluKD5cyVkWGhS3UCjcKPxSCXV6GRqfwoEMvhkzktkxm SJlemRAqdyeWsv9ml5sdf63A5BZly1+LvyHQxsdvvtrQD0PZx6/NThzc3HstVbeIqHmy voazie94XNRKL4ETqhjxdB9ARQ+t9RqXrOM1ER7hP1EjfC0alYFnRfTV+U2pfBPFnyyJ uu9A== X-Gm-Message-State: ALKqPwcj/bbomANNxS4LgBIrRxBcy2duk7hg/xuwfBZK8JPADrezq0YI QOVEgCFQ+VD1+s8GKF5lSsivIw== X-Received: by 2002:a1c:a54e:: with SMTP id o75-v6mr1723268wme.157.1527497142290; Mon, 28 May 2018 01:45:42 -0700 (PDT) Received: from localhost.localdomain ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id 123-v6sm21783013wmt.19.2018.05.28.01.45.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 May 2018 01:45:41 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Jonathan Corbet , Robert Walker , mike.leach@linaro.org, kim.phillips@arm.co, Tor Jeremiassen Cc: Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, Leo Yan Subject: [RFT v3 1/4] perf cs-etm: Generate branch sample for missed packets Date: Mon, 28 May 2018 16:45:00 +0800 Message-Id: <1527497103-3593-2-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527497103-3593-1-git-send-email-leo.yan@linaro.org> References: <1527497103-3593-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit e573e978fb12 ("perf cs-etm: Inject capabilitity for CoreSight traces") reworks the samples generation flow from CoreSight trace to match the correct format so Perf report tool can display the samples properly. But the change has side effect for branch packet handling, it only generate branch samples by checking previous packet flag 'last_instr_taken_branch' is true, this results in below three kinds packets are missed to generate branch samples: - The start tracing packet at the beginning of tracing data; - The exception handling packet; - If one CS_ETM_TRACE_ON packet is inserted, we also miss to handle it for branch samples. CS_ETM_TRACE_ON packet itself can give the info that there have a discontinuity in the trace, on the other hand we also miss to generate proper branch sample for packets before and after CS_ETM_TRACE_ON packet. This patch is to add branch sample handling for up three kinds packets: - In function cs_etm__sample(), check if 'prev_packet->sample_type' is zero and in this case it generates branch sample for the start tracing packet; furthermore, we also need to handle the condition for prev_packet::end_addr is zero in the cs_etm__last_executed_instr(); - In function cs_etm__sample(), check if 'prev_packet->exc' is true and generate branch sample for exception handling packet; - If there has one CS_ETM_TRACE_ON packet is coming, we firstly generate branch sample in the function cs_etm__flush(), this can save complete info for the previous CS_ETM_RANGE packet just before CS_ETM_TRACE_ON packet. We also generate branch sample for the new CS_ETM_RANGE packet after CS_ETM_TRACE_ON packet, this have two purposes, the first one purpose is to save the info for the new CS_ETM_RANGE packet, the second purpose is to save CS_ETM_TRACE_ON packet info so we can have hint for a discontinuity in the trace. For CS_ETM_TRACE_ON packet, its fields 'packet->start_addr' and 'packet->end_addr' equal to 0xdeadbeefdeadbeefUL which are emitted in the decoder layer as dummy value. This patch is to convert these values to zeros for more readable; this is accomplished by functions cs_etm__last_executed_instr() and cs_etm__first_executed_instr(). The later one is a new function introduced by this patch. Reviewed-by: Robert Walker Fixes: e573e978fb12 ("perf cs-etm: Inject capabilitity for CoreSight traces") Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 93 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 20 deletions(-) -- 2.7.4 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 822ba91..8418173 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -495,6 +495,20 @@ static inline void cs_etm__reset_last_branch_rb(struct cs_etm_queue *etmq) static inline u64 cs_etm__last_executed_instr(struct cs_etm_packet *packet) { /* + * The packet is the start tracing packet if the end_addr is zero, + * returns 0 for this case. + */ + if (!packet->end_addr) + return 0; + + /* + * The packet is the CS_ETM_TRACE_ON packet if the end_addr is + * magic number 0xdeadbeefdeadbeefUL, returns 0 for this case. + */ + if (packet->end_addr == 0xdeadbeefdeadbeefUL) + return 0; + + /* * The packet records the execution range with an exclusive end address * * A64 instructions are constant size, so the last executed @@ -505,6 +519,18 @@ static inline u64 cs_etm__last_executed_instr(struct cs_etm_packet *packet) return packet->end_addr - A64_INSTR_SIZE; } +static inline u64 cs_etm__first_executed_instr(struct cs_etm_packet *packet) +{ + /* + * The packet is the CS_ETM_TRACE_ON packet if the start_addr is + * magic number 0xdeadbeefdeadbeefUL, returns 0 for this case. + */ + if (packet->start_addr == 0xdeadbeefdeadbeefUL) + return 0; + + return packet->start_addr; +} + static inline u64 cs_etm__instr_count(const struct cs_etm_packet *packet) { /* @@ -546,7 +572,7 @@ static void cs_etm__update_last_branch_rb(struct cs_etm_queue *etmq) be = &bs->entries[etmq->last_branch_pos]; be->from = cs_etm__last_executed_instr(etmq->prev_packet); - be->to = etmq->packet->start_addr; + be->to = cs_etm__first_executed_instr(etmq->packet); /* No support for mispredict */ be->flags.mispred = 0; be->flags.predicted = 1; @@ -701,7 +727,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq) sample.ip = cs_etm__last_executed_instr(etmq->prev_packet); sample.pid = etmq->pid; sample.tid = etmq->tid; - sample.addr = etmq->packet->start_addr; + sample.addr = cs_etm__first_executed_instr(etmq->packet); sample.id = etmq->etm->branches_id; sample.stream_id = etmq->etm->branches_id; sample.period = 1; @@ -897,13 +923,28 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) etmq->period_instructions = instrs_over; } - if (etm->sample_branches && - etmq->prev_packet && - etmq->prev_packet->sample_type == CS_ETM_RANGE && - etmq->prev_packet->last_instr_taken_branch) { - ret = cs_etm__synth_branch_sample(etmq); - if (ret) - return ret; + if (etm->sample_branches && etmq->prev_packet) { + bool generate_sample = false; + + /* Generate sample for start tracing packet */ + if (etmq->prev_packet->sample_type == 0 || + etmq->prev_packet->sample_type == CS_ETM_TRACE_ON) + generate_sample = true; + + /* Generate sample for exception packet */ + if (etmq->prev_packet->exc == true) + generate_sample = true; + + /* Generate sample for normal branch packet */ + if (etmq->prev_packet->sample_type == CS_ETM_RANGE && + etmq->prev_packet->last_instr_taken_branch) + generate_sample = true; + + if (generate_sample) { + ret = cs_etm__synth_branch_sample(etmq); + if (ret) + return ret; + } } if (etm->sample_branches || etm->synth_opts.last_branch) { @@ -922,11 +963,16 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) static int cs_etm__flush(struct cs_etm_queue *etmq) { int err = 0; + struct cs_etm_auxtrace *etm = etmq->etm; struct cs_etm_packet *tmp; - if (etmq->etm->synth_opts.last_branch && - etmq->prev_packet && - etmq->prev_packet->sample_type == CS_ETM_RANGE) { + if (!etmq->prev_packet) + return 0; + + if (etmq->prev_packet->sample_type != CS_ETM_RANGE) + return 0; + + if (etmq->etm->synth_opts.last_branch) { /* * Generate a last branch event for the branches left in the * circular buffer at the end of the trace. @@ -939,18 +985,25 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) err = cs_etm__synth_instruction_sample( etmq, addr, etmq->period_instructions); + if (err) + return err; etmq->period_instructions = 0; + } - /* - * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for - * the next incoming packet. - */ - tmp = etmq->packet; - etmq->packet = etmq->prev_packet; - etmq->prev_packet = tmp; + if (etm->sample_branches) { + err = cs_etm__synth_branch_sample(etmq); + if (err) + return err; } - return err; + /* + * Swap PACKET with PREV_PACKET: PACKET becomes PREV_PACKET for + * the next incoming packet. + */ + tmp = etmq->packet; + etmq->packet = etmq->prev_packet; + etmq->prev_packet = tmp; + return 0; } static int cs_etm__run_decoder(struct cs_etm_queue *etmq) From patchwork Mon May 28 08:45:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 137033 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2560090lji; Mon, 28 May 2018 01:45:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrPQRHWVJyvRBWFLg5zM6JQeIk7dfdrsPkGL5gJu3anZFQ+9kGV+SgMpNtOo1/EsMNnwuxa X-Received: by 2002:a17:902:5c6:: with SMTP id f64-v6mr12694189plf.50.1527497158344; Mon, 28 May 2018 01:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527497158; cv=none; d=google.com; s=arc-20160816; b=YNdjDUD9lCsm8oOo8V0X2S4Nt+7sDA3dfpDxvc/qmIf0wySqGO00TbmGReqmZqt/vN 2qZZwELoP77b60j+8wHkoiUIBFwxj6gsPrUxdLtrPuUdHf1Nh0PrbeEzJj5Mx02MVMAT quqKpX3lBfDBfj8TilgLTy5wYDlBVXbNBY6Oc1NGUnMaYISE8wteXTFxKwzLh9l867fG cmMqUrjk64UKdJmOkIXJkPMt7+zoN7ZmA9W8VLuQUmFvIRwzSNnFTGj3kADatD/i1JtZ vVNiEhSbZRsbkwG9yKhJDmnePdqrI0irXhs43YDmYbGrKSbi15UAQF2QggClNoCEVzEy obRQ== 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=g2s0qKAeszFhKKHrQ+56mjV/yVHzAXmicKjIaEfOtZk=; b=W59tNB57wInzBpuu/xyHcq17cjkj3WVu3Y/l3/GZUG9aWebXwA2dCsQmz4IxTXF173 nOAjB5vghV5sxwuIDU+F2weNEl2g3dx7sA3PHEPyzuqZqsVw8CnACkVWaD4E4ssbaGck R976nlBSnXpRB5Wrv1RT+dyBhuVnNvbs44wd+4xqtR/bgtkS9QkJRh7vgCbQmJtoT+U4 qu2IMmLWe+Xr/40W64D4oAoRfgTFI3Mc80qdljv3ZQAS0Tpo92v5tuEVUHBsUswb6b2e th1iIBYxRX2oAOU+36FXCRJ3oFZzsGZq43EMg60KstAb41kOqidnB0xH5Z8ToaJxilGv GVuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S0hLWFsg; 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 g1-v6si23565221pgo.637.2018.05.28.01.45.58; Mon, 28 May 2018 01:45:58 -0700 (PDT) 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=S0hLWFsg; 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 S932149AbeE1Ip4 (ORCPT + 30 others); Mon, 28 May 2018 04:45:56 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:41868 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932106AbeE1Ipu (ORCPT ); Mon, 28 May 2018 04:45:50 -0400 Received: by mail-wr0-f195.google.com with SMTP id u12-v6so18927799wrn.8 for ; Mon, 28 May 2018 01:45:50 -0700 (PDT) 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=g2s0qKAeszFhKKHrQ+56mjV/yVHzAXmicKjIaEfOtZk=; b=S0hLWFsgE3mmA3xopC+6pgFgANkdef1gSr3NR5eGgGGtXjM4wPBjKa93Oc9tNJXOIt JH2MlVlPySkHPlNrslrc6JrzNZzaqevOpUQ92zVDW5C20ficnGXxn5Be4HNE3rjPDsuy 9lrimUSKk8sWGosAn6OdnDUZQuTmttfyMHOhg= 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=g2s0qKAeszFhKKHrQ+56mjV/yVHzAXmicKjIaEfOtZk=; b=O6lCSXYGgfrpyM0lBecc6hOZGGfcZtEyJKsZVgqssXKCo0UJh6Zjn3Dc+3xUp49QD7 d4QmJXYDLgTHC07wdxhPdA5aj8cWBjLtgESsOZhX+xUq5461yYkiQub1zAY9RZG6dSP5 UbVJuAb725l8WQcvMDoI5HAyN0e7VnRuBkHlWzJGoOmoh51099y4hrM9n+5+repqQG3P cZ0fgFARCJtFlIoI1YxEpxYkTz/7zVg0VdtBI68Nt7Mo6EcrlQRDPMk9/xncne7qPkdO HFV1TVpGIajyahve/n9LTXRgy4ieD/YjdCa76JhJgvPXymUl/rmf11X+2tvx9En+LzT8 DrUg== X-Gm-Message-State: ALKqPwepMJe3baXD8+w3XyVleH0Zus2ItslKPyyRkRmiWd6EZBrAqJQQ B12XcDCs7XHfTVYIfkEdyph8GA== X-Received: by 2002:adf:af6b:: with SMTP id z98-v6mr9416956wrc.250.1527497149509; Mon, 28 May 2018 01:45:49 -0700 (PDT) Received: from localhost.localdomain ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id 123-v6sm21783013wmt.19.2018.05.28.01.45.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 May 2018 01:45:48 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Jonathan Corbet , Robert Walker , mike.leach@linaro.org, kim.phillips@arm.co, Tor Jeremiassen Cc: Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, Leo Yan Subject: [RFT v3 2/4] perf script python: Add addr into perf sample dict Date: Mon, 28 May 2018 16:45:01 +0800 Message-Id: <1527497103-3593-3-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527497103-3593-1-git-send-email-leo.yan@linaro.org> References: <1527497103-3593-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ARM CoreSight auxtrace uses 'sample->addr' to record the target address for branch instructions, so the data of 'sample->addr' is required for tracing data analysis. This commit collects data of 'sample->addr' into perf sample dict, finally can be used for python script for parsing event. Signed-off-by: Leo Yan --- tools/perf/util/scripting-engines/trace-event-python.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.7.4 diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 10dd5fc..7f8afac 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -531,6 +531,8 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, PyLong_FromUnsignedLongLong(sample->period)); pydict_set_item_string_decref(dict_sample, "phys_addr", PyLong_FromUnsignedLongLong(sample->phys_addr)); + pydict_set_item_string_decref(dict_sample, "addr", + PyLong_FromUnsignedLongLong(sample->addr)); set_sample_read_in_dict(dict_sample, sample, evsel); pydict_set_item_string_decref(dict, "sample", dict_sample); From patchwork Mon May 28 08:45:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 137034 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2560186lji; Mon, 28 May 2018 01:46:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp+STAntEO+tHpumDdrQeHiL8+5/GZMbPQY7ASYbnBD3QN6mtjsFzcM8ZztB0GHzS24JgWv X-Received: by 2002:a17:902:b692:: with SMTP id c18-v6mr12617569pls.307.1527497165433; Mon, 28 May 2018 01:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527497165; cv=none; d=google.com; s=arc-20160816; b=mlbmI52fmapARACblj+7OBydv1q2Xb4iYbqIS8kv2j+6aSWcJmTCe+q5JldFo9caWk sXGZc9MEAIuZw/z0mCQtwKaxhGr2dwEWspWoX2aVDJrEgBTCV07vjK91oR0RkdT9jGoH pNFsfkOl1RWOybw+ur7pNEsp1DbiDknHpXK/6C7DV5vq5SyMc4uEPgKYvKcs7QWvoGG5 Wd0FstcyV0hee06JW0Z+qq3qgjC0p0Mc2Q/E5V1B6PobYSfsdS+P9XE0HBB1x1FotEgw iRd/HxHL4KVap5H1/tc9spPHJM0OzjBlCBbmaJa/g/5XYrqn2uVyussmxLB4B6XQJUQH ziQA== 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=bnFJIkGvsla0t6vZjJXMeOziRo9NX0tsf7NGf5P/aP4=; b=HeEVF1Y028YrIScLoy9oVb/xasnhUuNuSXygRFgyWzNg3bgf88r8wNnwNsuvNx8PbR DdjwbXHENsViChGuofB3kmrr2LdaeKmSnlQ399Q4KXcIFFOhTCeDm1QGjNHf/wCnYIML 5oX2n1ccBIydzPun+At+7TNGcmfOcjn/Db/wHwfqQakQiKuSSVJCWAuB/INcDrY5WP9H CoxHvf5j7KWhj3yR2joQeIuOgUDM1QrY2mNo1zb6Bc2PBE+LMm+PqAKm5UcVy3R4vIva e9OflX8diwJtLTrIZHM1nLGP6DLwSTzw7u8Mf4OFPD80k7C6ngDwUmY1B+c6YcwxLC9R uemA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NGWVKBQ2; 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 g1-v6si23565221pgo.637.2018.05.28.01.46.05; Mon, 28 May 2018 01:46:05 -0700 (PDT) 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=NGWVKBQ2; 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 S933159AbeE1IqD (ORCPT + 30 others); Mon, 28 May 2018 04:46:03 -0400 Received: from mail-wr0-f196.google.com ([209.85.128.196]:34929 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932106AbeE1Ip6 (ORCPT ); Mon, 28 May 2018 04:45:58 -0400 Received: by mail-wr0-f196.google.com with SMTP id i14-v6so18954770wre.2 for ; Mon, 28 May 2018 01:45:57 -0700 (PDT) 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=bnFJIkGvsla0t6vZjJXMeOziRo9NX0tsf7NGf5P/aP4=; b=NGWVKBQ2uS52XhIR22X9hGAmObXWpn6goO3rnJNZU7lx8Q25QC47d7NXkDLNa49GpQ L01Y9bYUnmM/JIY4pohX+vOlk685oFH21P36XlS9nJd/b4ToSmRNEIcWVAtZqzkbqy9O 6vQRdewujqPOvPsGA4EiCho4tCzUsyvGDgEgs= 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=bnFJIkGvsla0t6vZjJXMeOziRo9NX0tsf7NGf5P/aP4=; b=OLiVYRUn9WssfppadlkVj2ycm9NirhGo8ArrXGUEykY99mdBCqd/UsYwJnUQD+QwgU foSBUuY/7WBiHz+YV1voh980rj4Z7USzA5fy2RPLOsPQ6GoWa7C+FEedz39C+hslBUql IJvFQS20Ou9LjNdAV27+lO4obGL0gL5RRm3MTBDIV2wTZeyGZDkPM7IKr6iHFd02hyKr 2VDH10PpbXd+5945j8H8iPgVLEdz1UoJTzFj0pbdcaTPbqF2qerpkCuXjGlLOruH0mzv OOUwvtCkF6v1HVzYgg4PD7OkCT/WXE27Fry1ThL/DclPcvx+ZP6477YypSufym7xfYNN 18dg== X-Gm-Message-State: ALKqPwffl4u9jUkUqFMJI5SiVaHBTuQmljlL6BP1OUcNyoM/IlrxBs1W ygCjGGKELzfpCk1HtRfPQHJS2w== X-Received: by 2002:adf:988c:: with SMTP id w12-v6mr8807873wrb.215.1527497156688; Mon, 28 May 2018 01:45:56 -0700 (PDT) Received: from localhost.localdomain ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id 123-v6sm21783013wmt.19.2018.05.28.01.45.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 May 2018 01:45:55 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Jonathan Corbet , Robert Walker , mike.leach@linaro.org, kim.phillips@arm.co, Tor Jeremiassen Cc: Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, Leo Yan Subject: [RFT v3 3/4] perf script python: Add script for CoreSight trace disassembler Date: Mon, 28 May 2018 16:45:02 +0800 Message-Id: <1527497103-3593-4-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527497103-3593-1-git-send-email-leo.yan@linaro.org> References: <1527497103-3593-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit adds python script to parse CoreSight tracing event and use command 'objdump' for disassembled lines, finally we can generate readable program execution flow for reviewing tracing data. The script receives CoreSight tracing packet with below format: +------------+------------+------------+ packet(n): | addr | ip | cpu | +------------+------------+------------+ packet(n+1): | addr | ip | cpu | +------------+------------+------------+ packet::ip is the last address of current branch instruction and packet::addr presents the start address of the next coming branch instruction. So for one branch instruction which starts in packet(n), its execution flow starts from packet(n)::addr and it stops at packet(n+1)::ip. As results we need to combine the two continuous packets to generate the instruction range, this is the rationale for the script implementation: [ sample(n)::addr .. sample(n+1)::ip ] Credits to Tor Jeremiassen who have written the script skeleton and provides the ideas for reading symbol file according to build-id, creating memory map for dso and basic packet handling. Mathieu Poirier contributed fixes for build-id and memory map bugs. The detailed development history for this script you can find from [1]. Based on Tor and Mathieu work, the script is updated samples handling for the corrected sample format. Another minor enhancement is to support for without build-id case, the script can parse kernel symbols with option '-k' for vmlinux file path. [1] https://github.com/Linaro/perf-opencsd/commits/perf-opencsd-v4.15/tools/perf/scripts/python/cs-trace-disasm.py Co-authored-by: Tor Jeremiassen Co-authored-by: Mathieu Poirier Signed-off-by: Leo Yan --- tools/perf/scripts/python/arm-cs-trace-disasm.py | 235 +++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 tools/perf/scripts/python/arm-cs-trace-disasm.py -- 2.7.4 diff --git a/tools/perf/scripts/python/arm-cs-trace-disasm.py b/tools/perf/scripts/python/arm-cs-trace-disasm.py new file mode 100644 index 0000000..1239ab4 --- /dev/null +++ b/tools/perf/scripts/python/arm-cs-trace-disasm.py @@ -0,0 +1,235 @@ +# arm-cs-trace-disasm.py: ARM CoreSight Trace Dump With Disassember +# SPDX-License-Identifier: GPL-2.0 +# +# Tor Jeremiassen is original author who wrote script +# skeleton, Mathieu Poirier contributed +# fixes for build-id and memory map; Leo Yan +# updated the packet parsing with new samples format. + +import os +import sys +import re +from subprocess import * +from optparse import OptionParser, make_option + +# Command line parsing + +option_list = [ + # formatting options for the bottom entry of the stack + make_option("-k", "--vmlinux", dest="vmlinux_name", + help="Set path to vmlinux file"), + make_option("-d", "--objdump", dest="objdump_name", + help="Set path to objdump executable file"), + make_option("-v", "--verbose", dest="verbose", + action="store_true", default=False, + help="Enable debugging log") +] + +parser = OptionParser(option_list=option_list) +(options, args) = parser.parse_args() + +if (options.objdump_name == None): + sys.exit("No objdump executable file specified - use -d or --objdump option") + +# Initialize global dicts and regular expression + +build_ids = dict() +mmaps = dict() +disasm_cache = dict() +cpu_data = dict() +disasm_re = re.compile("^\s*([0-9a-fA-F]+):") +disasm_func_re = re.compile("^\s*([0-9a-fA-F]+)\s\<.*\>:") +cache_size = 32*1024 +prev_cpu = -1 + +def parse_buildid(): + global build_ids + + buildid_regex = "([a-fA-f0-9]+)[ \t]([^ \n]+)" + buildid_re = re.compile(buildid_regex) + + results = check_output(["perf", "buildid-list"]).split('\n'); + for line in results: + m = buildid_re.search(line) + if (m == None): + continue; + + id_name = m.group(2) + id_num = m.group(1) + + if (id_name == "[kernel.kallsyms]") : + append = "/kallsyms" + elif (id_name == "[vdso]") : + append = "/vdso" + else: + append = "/elf" + + build_ids[id_name] = os.environ['PERF_BUILDID_DIR'] + \ + "/" + id_name + "/" + id_num + append; + # Replace duplicate slash chars to single slash char + build_ids[id_name] = build_ids[id_name].replace('//', '/', 1) + + if ((options.vmlinux_name == None) and ("[kernel.kallsyms]" in build_ids)): + print "kallsyms cannot be used to dump assembler" + + # Set vmlinux path to replace kallsyms file, if without buildid we still + # can use vmlinux to prase kernel symbols + if ((options.vmlinux_name != None)): + build_ids['[kernel.kallsyms]'] = options.vmlinux_name; + +def parse_mmap(): + global mmaps + + # Check mmap for PERF_RECORD_MMAP and PERF_RECORD_MMAP2 + mmap_regex = "PERF_RECORD_MMAP.* -?[0-9]+/[0-9]+: \[(0x[0-9a-fA-F]+)\((0x[0-9a-fA-F]+)\).*:\s.*\s(\S*)" + mmap_re = re.compile(mmap_regex) + + results = check_output("perf script --show-mmap-events | fgrep PERF_RECORD_MMAP", shell=True).split('\n') + for line in results: + m = mmap_re.search(line) + if (m != None): + if (m.group(3) == '[kernel.kallsyms]_text'): + dso = '[kernel.kallsyms]' + else: + dso = m.group(3) + + start = int(m.group(1),0) + end = int(m.group(1),0) + int(m.group(2),0) + mmaps[dso] = [start, end] + +def find_dso_mmap(addr): + global mmaps + + for key, value in mmaps.items(): + if (addr >= value[0] and addr < value[1]): + return key + + return None + +def read_disam(dso, start_addr, stop_addr): + global mmaps + global build_ids + + addr_range = start_addr + ":" + stop_addr; + + # Don't let the cache get too big, clear it when it hits max size + if (len(disasm_cache) > cache_size): + disasm_cache.clear(); + + try: + disasm_output = disasm_cache[addr_range]; + except: + try: + fname = build_ids[dso]; + except KeyError: + sys.exit("cannot find symbol file for " + dso) + + disasm = [ options.objdump_name, "-d", "-z", + "--start-address="+start_addr, + "--stop-address="+stop_addr, fname ] + + disasm_output = check_output(disasm).split('\n') + disasm_cache[addr_range] = disasm_output; + + return disasm_output + +def dump_disam(dso, start_addr, stop_addr): + for line in read_disam(dso, start_addr, stop_addr): + m = disasm_func_re.search(line) + if (m != None): + print "\t",line + continue + + m = disasm_re.search(line) + if (m == None): + continue; + + print "\t",line + +def dump_packet(sample): + print "Packet = { cpu: 0x%d addr: 0x%x phys_addr: 0x%x ip: 0x%x " \ + "pid: %d tid: %d period: %d time: %d }" % \ + (sample['cpu'], sample['addr'], sample['phys_addr'], \ + sample['ip'], sample['pid'], sample['tid'], \ + sample['period'], sample['time']) + +def trace_begin(): + print 'ARM CoreSight Trace Data Assembler Dump' + parse_buildid() + parse_mmap() + +def trace_end(): + print 'End' + +def trace_unhandled(event_name, context, event_fields_dict): + print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]) + +def process_event(param_dict): + global cache_size + global options + global prev_cpu + + sample = param_dict["sample"] + + if (options.verbose == True): + dump_packet(sample) + + # If period doesn't equal to 1, this packet is for instruction sample + # packet, we need drop this synthetic packet. + if (sample['period'] != 1): + print "Skip synthetic instruction sample" + return + + cpu = format(sample['cpu'], "d"); + + # Initialize CPU data if it's empty, and directly return back + # if this is the first tracing event for this CPU. + if (cpu_data.get(str(cpu) + 'addr') == None): + cpu_data[str(cpu) + 'addr'] = format(sample['addr'], "#x") + prev_cpu = cpu + return + + # The format for packet is: + # + # +------------+------------+------------+ + # sample_prev: | addr | ip | cpu | + # +------------+------------+------------+ + # sample_next: | addr | ip | cpu | + # +------------+------------+------------+ + # + # We need to combine the two continuous packets to get the instruction + # range for sample_prev::cpu: + # + # [ sample_prev::addr .. sample_next::ip ] + # + # For this purose, sample_prev::addr is stored into cpu_data structure + # and read back for 'start_addr' when the new packet comes, and we need + # to use sample_next::ip to calculate 'stop_addr', plusing extra 4 for + # 'stop_addr' is for the sake of objdump so the final assembler dump can + # include last instruction for sample_next::ip. + + start_addr = cpu_data[str(prev_cpu) + 'addr'] + stop_addr = format(sample['ip'] + 4, "#x") + + # Record for previous sample packet + cpu_data[str(cpu) + 'addr'] = format(sample['addr'], "#x") + prev_cpu = cpu + + # Handle CS_ETM_TRACE_ON packet if start_addr=0 and stop_addr=4 + if (int(start_addr, 0) == 0 and int(stop_addr, 0) == 4): + print "CPU%s: CS_ETM_TRACE_ON packet is inserted" % cpu + return + + # Sanity checking dso for start_addr and stop_addr + prev_dso = find_dso_mmap(int(start_addr, 0)) + next_dso = find_dso_mmap(int(stop_addr, 0)) + + # If cannot find dso so cannot dump assembler, bail out + if (prev_dso == None or next_dso == None): + print "Address range [ %s .. %s ]: failed to find dso" % (start_addr, stop_addr) + return + elif (prev_dso != next_dso): + print "Address range [ %s .. %s ]: isn't in same dso" % (start_addr, stop_addr) + return + + dump_disam(prev_dso, start_addr, stop_addr) From patchwork Mon May 28 08:45:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 137035 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2560357lji; Mon, 28 May 2018 01:46:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoWUjZT/+4oY/MUFuimSwRdRgQ6kNnGgEloQukpIQgNyOixRC1N2oFKM1WxYnWT2WvT2/Ka X-Received: by 2002:a17:902:2d24:: with SMTP id o33-v6mr12813042plb.14.1527497177260; Mon, 28 May 2018 01:46:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527497177; cv=none; d=google.com; s=arc-20160816; b=sKMEon1c+ZupiUO+ihObnwxRxwvKX6aAyK/XIZoizjw/okfOQqGs3JjBcHAr+yPiSg PXyGuIgKnYWLShDSYXLBlnlgxYJa+pDybnEMnviy/8hNqYNBJrzep8r7H/GL2HvtAPFq 6jT1jJ6hu2UPcPxPCGUm5HbzpRTAf9w0HygGP0CuKN7by85rTKvIdaMSoE16upuc7opY YdyGYezw3nfiNrvh7v8tq3FNZ7NYaHJ1oUGip5vqM7PvdBF1Tc/6CxLfbb+kiGnw+UON 4jTRDLq7gBMYRntolxDLCv8+kx0qFgVWar3x8rIg7v/zqMOU1YPNqFsTp8I4Xo6h2Iqi ueZA== 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=NnN/fhGrSR8SrEds0HmRI/5r4C+zJoMVSRbsuhZ0Y3Y=; b=qRTrCHfdNdOMOBF4q/n9Wd+llY/BUP1xGOHxe5Jv3XYybBhJNGawXLkZHN9fxtxBf6 saaXTOYFKmOm9ess8EyfWKF1p9WwtSNhVKfB+d7YAnYEztXTgj0LaUZiwqaOslbbyQfS woHFqbbqseQYJLsecbt3CZ/cMMJLMOKFkdY9heoFo6rgsTao/L7I8buPwxASMvWCo0Rd dQS3p+Yx7djxQFvHr5NceCrKy1yP50Afp52zSipxmEZtSddCgvP6ec46k4GR02qkvteg IET6cf8FKMZ8NGyocydm+JmLV7qHdASARho1rMp843BlnrTJNVRdKrzsTGjDKXMOkZ8k tTzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b1orCH8M; 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 l70-v6si30287773pfk.129.2018.05.28.01.46.16; Mon, 28 May 2018 01:46:17 -0700 (PDT) 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=b1orCH8M; 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 S1754130AbeE1IqP (ORCPT + 30 others); Mon, 28 May 2018 04:46:15 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:37109 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933163AbeE1IqE (ORCPT ); Mon, 28 May 2018 04:46:04 -0400 Received: by mail-wm0-f67.google.com with SMTP id l1-v6so30021499wmb.2 for ; Mon, 28 May 2018 01:46:04 -0700 (PDT) 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=NnN/fhGrSR8SrEds0HmRI/5r4C+zJoMVSRbsuhZ0Y3Y=; b=b1orCH8MJwaXP08XQQNpfqozC/WlgS86Zjhn020ibietnYcIa0mzJPKcXpguquzIaj 6C1qUczNM6P3v2Q+iAhOfE9eoGSLy317ULJ5hBYidaBrxomBtJtkOurr4BOXDx2uWx11 bakhbqiAWmuYxJ0XyRdYhzn85Xwb5WepY9HtE= 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=NnN/fhGrSR8SrEds0HmRI/5r4C+zJoMVSRbsuhZ0Y3Y=; b=UvkGbFEjoEHQCdWHTYALLMwnwVj8/hGsecCKitJXTyGCxo/XpgDBmD3qyOdpylFuos oR+hQGaUC+9unHvin3+WaNMCevXOMcsVu5rC8TW2EE37R2bMCZtYxXvuim/XN169xk9v wXWjd+o7MFs77x72rJ6YZsyd2C9U10Dsxj1wcFEYlDgN1NWNTVJ3GjGIodniZgSJSkhf r3Ohe1bowgUjgp9GaTidAtdMAapGmubvhfioE0dERC33FjLgwR36QrKenVNT/4cpHXEv 6Z8cUt1nTgL6/8McIk+lCw3VuEsGZkHhjrtHzlYyVRLdymaonT9eOBoSgplR30PuiTfC APYA== X-Gm-Message-State: ALKqPwfUguLMF3AX5pBtLu5HEnXsmwrd9r4GPQWw0XU4/UobGm7i7uyt 8I2oZv9QcWqvijdb60QNOLDfRQ== X-Received: by 2002:a1c:da13:: with SMTP id r19-v6mr9019079wmg.2.1527497163176; Mon, 28 May 2018 01:46:03 -0700 (PDT) Received: from localhost.localdomain ([45.76.138.171]) by smtp.gmail.com with ESMTPSA id 123-v6sm21783013wmt.19.2018.05.28.01.45.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 May 2018 01:46:02 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Jonathan Corbet , Robert Walker , mike.leach@linaro.org, kim.phillips@arm.co, Tor Jeremiassen Cc: Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, Leo Yan Subject: [RFT v3 4/4] coresight: Document for CoreSight trace disassembler Date: Mon, 28 May 2018 16:45:03 +0800 Message-Id: <1527497103-3593-5-git-send-email-leo.yan@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527497103-3593-1-git-send-email-leo.yan@linaro.org> References: <1527497103-3593-1-git-send-email-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit documents CoreSight trace disassembler usage and gives example for it. Signed-off-by: Leo Yan --- Documentation/trace/coresight.txt | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) -- 2.7.4 diff --git a/Documentation/trace/coresight.txt b/Documentation/trace/coresight.txt index 6f0120c..b8f2359 100644 --- a/Documentation/trace/coresight.txt +++ b/Documentation/trace/coresight.txt @@ -381,3 +381,55 @@ sort example is from the AutoFDO tutorial (https://gcc.gnu.org/wiki/AutoFDO/Tuto $ taskset -c 2 ./sort_autofdo Bubble sorting array of 30000 elements 5806 ms + + +Tracing data disassembler +------------------------- + +'perf script' supports to use script to parse tracing packet and rely on +'objdump' for disassembled lines, this can convert tracing data to readable +program execution flow for easily reviewing tracing data. + +The CoreSight trace disassembler is located in the folder: +tools/perf/scripts/python/arm-cs-trace-disasm.py. This script support below +options: + + -d, --objdump: Set path to objdump executable, this option is + mandatory. + -k, --vmlinux: Set path to vmlinux file. + -v, --verbose: Enable debugging log, after enable this option the + script dumps every event data. + +Below is one example for using python script to dump CoreSight trace +disassembler: + + $ perf script -s arm-cs-trace-disasm.py -i perf.data \ + -F cpu,event,ip,addr,sym -- -d objdump -k ./vmlinux > cs-disasm.log + +Below is one example for the disassembler log: + +ARM CoreSight Trace Data Assembler Dump + ffff000008a5f2dc : + ffff000008a5f2dc: 340000a0 cbz w0, ffff000008a5f2f0 + ffff000008a5f2f0 : + ffff000008a5f2f0: f9400260 ldr x0, [x19] + ffff000008a5f2f4: d5033f9f dsb sy + ffff000008a5f2f8: 913ec000 add x0, x0, #0xfb0 + ffff000008a5f2fc: b900001f str wzr, [x0] + ffff000008a5f300: f9400bf3 ldr x19, [sp, #16] + ffff000008a5f304: a8c27bfd ldp x29, x30, [sp], #32 + ffff000008a5f308: d65f03c0 ret + ffff000008a5fa18 : + ffff000008a5fa18: 14000025 b ffff000008a5faac + ffff000008a5faac : + ffff000008a5faac: b9406261 ldr w1, [x19, #96] + ffff000008a5fab0: 52800015 mov w21, #0x0 // #0 + ffff000008a5fab4: f901ca61 str x1, [x19, #912] + ffff000008a5fab8: 2a1503e0 mov w0, w21 + ffff000008a5fabc: 3940e261 ldrb w1, [x19, #56] + ffff000008a5fac0: f901ce61 str x1, [x19, #920] + ffff000008a5fac4: a94153f3 ldp x19, x20, [sp, #16] + ffff000008a5fac8: a9425bf5 ldp x21, x22, [sp, #32] + ffff000008a5facc: a94363f7 ldp x23, x24, [sp, #48] + ffff000008a5fad0: a8c47bfd ldp x29, x30, [sp], #64 + ffff000008a5fad4: d65f03c0 ret