Received: by 10.223.176.46 with SMTP id f43csp632372wra; Wed, 24 Jan 2018 03:41:40 -0800 (PST) X-Google-Smtp-Source: AH8x224imqNinOyTmNwGksXXn+CmQXiRm590oPYKBSmaRhoqhLFiTbTVjznKDCIPVEGQQkbtWBQT X-Received: by 2002:a17:902:147:: with SMTP id 65-v6mr5425833plb.128.1516794100490; Wed, 24 Jan 2018 03:41:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516794100; cv=none; d=google.com; s=arc-20160816; b=WjFdQLZKId8QY3GeOYTFSLfuoP5Nx4U0y+2MEiEvVwide4R2zStp/0OdmzU+KekRVS D6vYagHHHDuBGv8Q7WbVjmdFc3//5RO4ERxgm5xRdWD/KLhZFOuWY2d1RlcosyrZgeMA cBPd8QO1XRYUXMDBnDa0DPLKcvytzxeJ9gl8mR6Cjv9qNJ1SFnWZWgGNcuDHUiblvoLS K3OTULzWaEmZIFeu11Qegw368Wiy20UTeVU1Z+yx4JGZdMaipNNLi2cJEfZXoT45+AdG usP5W1U1RvywtM2XR+2SuxAWP4LsAjXaLyJu8+Ta61RXaxB4t41PgsWZpEDhghMBFE2K 8b7A== 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=GW+iQPLTpBLEIyJJpDii/RfCYKY029eYIZ9eBtk6Bgw=; b=0NxolR+p5XqyEZy9ApAhI3QCW0kG2TMtu+FwL8UiLV+Zk/+WVDtKU+Oy+KOYisCr3L 43uwe8KprEcMOe2K+RZW2DQeRKBZDWMkZICDXrh77E2dirtLvGV8uio14ooVXFZZKbKx tjEJcgMc3r4WqlI2eFkwGhv9i8vBszCcMN1vGLu/goGEjPeJgfUGm0vSGQQrSXM1Ju0v b0ldoaGSa2t8+Rj9JEAg6u+khIHNBvCbRnPdSX7mAUxOU3zqJYizCMX5kwpkytEml2h3 6UKzZXPF0nbZ3dSombHW/w4q5gWBHwehjzntRnzhwr1WngWeHuZjN6SYO+RsZMWpV5xZ iWgg== 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 g34-v6si69007pld.328.2018.01.24.03.41.26; Wed, 24 Jan 2018 03:41:40 -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 S933510AbeAXLjj (ORCPT + 99 others); Wed, 24 Jan 2018 06:39:39 -0500 Received: from terminus.zytor.com ([65.50.211.136]:54743 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933354AbeAXLje (ORCPT ); Wed, 24 Jan 2018 06:39:34 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w0OBZrI8029004; Wed, 24 Jan 2018 03:35:53 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w0OBZrwC029000; Wed, 24 Jan 2018 03:35:53 -0800 Date: Wed, 24 Jan 2018 03:35:53 -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: suzuki.poulose@arm.com, mingo@kernel.org, kim.phillips@arm.com, peterz@infradead.org, alexander.shishkin@linux.intel.com, tglx@linutronix.de, adrian.hunter@intel.com, linux-kernel@vger.kernel.org, acme@redhat.com, mathieu.poirier@linaro.org, namhyung@kernel.org, mike.leach@arm.com, jolsa@redhat.com, tor@ti.com, hpa@zytor.com Reply-To: suzuki.poulose@arm.com, mingo@kernel.org, kim.phillips@arm.com, namhyung@kernel.org, acme@redhat.com, mathieu.poirier@linaro.org, mike.leach@arm.com, jolsa@redhat.com, tor@ti.com, hpa@zytor.com, peterz@infradead.org, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com, tglx@linutronix.de, linux-kernel@vger.kernel.org In-Reply-To: <1516211539-5166-10-git-send-email-mathieu.poirier@linaro.org> References: <1516211539-5166-10-git-send-email-mathieu.poirier@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Add mechanic to synthesise CoreSight trace packets Git-Commit-ID: 38ddaba83c00633c37432663a19faff7c42bc4b7 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: 38ddaba83c00633c37432663a19faff7c42bc4b7 Gitweb: https://git.kernel.org/tip/38ddaba83c00633c37432663a19faff7c42bc4b7 Author: Mathieu Poirier AuthorDate: Wed, 17 Jan 2018 10:52:18 -0700 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 23 Jan 2018 09:51:49 -0300 perf tools: Add mechanic to synthesise CoreSight trace packets Once decoded from trace packets information on trace range needs to be communicated to the perf synthesis infrastructure so that it is available to the perf tools built-in rendering tools and scripts. 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-10-git-send-email-mathieu.poirier@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cs-etm.c | 168 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 407095a..b9f0a53 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -453,6 +453,157 @@ static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm, } } +/* + * The cs etm packet encodes an instruction range between a branch target + * and the next taken branch. Generate sample accordingly. + */ +static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq, + struct cs_etm_packet *packet) +{ + int ret = 0; + struct cs_etm_auxtrace *etm = etmq->etm; + struct perf_sample sample = {.ip = 0,}; + union perf_event *event = etmq->event_buf; + u64 start_addr = packet->start_addr; + u64 end_addr = packet->end_addr; + + event->sample.header.type = PERF_RECORD_SAMPLE; + event->sample.header.misc = PERF_RECORD_MISC_USER; + event->sample.header.size = sizeof(struct perf_event_header); + + sample.ip = start_addr; + sample.pid = etmq->pid; + sample.tid = etmq->tid; + sample.addr = end_addr; + sample.id = etmq->etm->branches_id; + sample.stream_id = etmq->etm->branches_id; + sample.period = 1; + sample.cpu = packet->cpu; + sample.flags = 0; + sample.cpumode = PERF_RECORD_MISC_USER; + + ret = perf_session__deliver_synth_event(etm->session, event, &sample); + + if (ret) + pr_err( + "CS ETM Trace: failed to deliver instruction event, error %d\n", + ret); + + return ret; +} + +struct cs_etm_synth { + struct perf_tool dummy_tool; + struct perf_session *session; +}; + +static int cs_etm__event_synth(struct perf_tool *tool, + union perf_event *event, + struct perf_sample *sample __maybe_unused, + struct machine *machine __maybe_unused) +{ + struct cs_etm_synth *cs_etm_synth = + container_of(tool, struct cs_etm_synth, dummy_tool); + + return perf_session__deliver_synth_event(cs_etm_synth->session, + event, NULL); +} + +static int cs_etm__synth_event(struct perf_session *session, + struct perf_event_attr *attr, u64 id) +{ + struct cs_etm_synth cs_etm_synth; + + memset(&cs_etm_synth, 0, sizeof(struct cs_etm_synth)); + cs_etm_synth.session = session; + + return perf_event__synthesize_attr(&cs_etm_synth.dummy_tool, attr, 1, + &id, cs_etm__event_synth); +} + +static int cs_etm__synth_events(struct cs_etm_auxtrace *etm, + struct perf_session *session) +{ + struct perf_evlist *evlist = session->evlist; + struct perf_evsel *evsel; + struct perf_event_attr attr; + bool found = false; + u64 id; + int err; + + evlist__for_each_entry(evlist, evsel) { + if (evsel->attr.type == etm->pmu_type) { + found = true; + break; + } + } + + if (!found) { + pr_debug("No selected events with CoreSight Trace data\n"); + return 0; + } + + memset(&attr, 0, sizeof(struct perf_event_attr)); + attr.size = sizeof(struct perf_event_attr); + attr.type = PERF_TYPE_HARDWARE; + attr.sample_type = evsel->attr.sample_type & PERF_SAMPLE_MASK; + attr.sample_type |= PERF_SAMPLE_IP | PERF_SAMPLE_TID | + PERF_SAMPLE_PERIOD; + if (etm->timeless_decoding) + attr.sample_type &= ~(u64)PERF_SAMPLE_TIME; + else + attr.sample_type |= PERF_SAMPLE_TIME; + + attr.exclude_user = evsel->attr.exclude_user; + attr.exclude_kernel = evsel->attr.exclude_kernel; + attr.exclude_hv = evsel->attr.exclude_hv; + attr.exclude_host = evsel->attr.exclude_host; + attr.exclude_guest = evsel->attr.exclude_guest; + attr.sample_id_all = evsel->attr.sample_id_all; + attr.read_format = evsel->attr.read_format; + + /* create new id val to be a fixed offset from evsel id */ + id = evsel->id[0] + 1000000000; + + if (!id) + id = 1; + + if (etm->synth_opts.branches) { + attr.config = PERF_COUNT_HW_BRANCH_INSTRUCTIONS; + attr.sample_period = 1; + attr.sample_type |= PERF_SAMPLE_ADDR; + err = cs_etm__synth_event(session, &attr, id); + if (err) + return err; + etm->sample_branches = true; + etm->branches_sample_type = attr.sample_type; + etm->branches_id = id; + } + + return 0; +} + +static int cs_etm__sample(struct cs_etm_queue *etmq) +{ + int ret; + struct cs_etm_packet packet; + + while (1) { + ret = cs_etm_decoder__get_packet(etmq->decoder, &packet); + if (ret <= 0) + return ret; + + /* + * If the packet contains an instruction range, generate an + * instruction sequence event. + */ + if (packet.sample_type & CS_ETM_RANGE) + cs_etm__synth_branch_sample(etmq, &packet); + } + + return 0; +} + static int cs_etm__run_decoder(struct cs_etm_queue *etmq) { struct cs_etm_auxtrace *etm = etmq->etm; @@ -494,6 +645,12 @@ more: etmq->offset += processed; buffer_used += processed; + + /* + * Nothing to do with an error condition, let's hope the next + * chunk will be better. + */ + err = cs_etm__sample(etmq); } while (buffer.len > buffer_used); goto more; @@ -828,6 +985,17 @@ int cs_etm__process_auxtrace_info(union perf_event *event, return 0; } + if (session->itrace_synth_opts && session->itrace_synth_opts->set) { + etm->synth_opts = *session->itrace_synth_opts; + } else { + itrace_synth_opts__set_default(&etm->synth_opts); + etm->synth_opts.callchain = false; + } + + err = cs_etm__synth_events(etm, session); + if (err) + goto err_free_queues; + err = auxtrace_queues__process_index(&etm->queues, session); if (err) goto err_free_queues;