From patchwork Fri May 24 17:34:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165160 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3886962ili; Fri, 24 May 2019 10:36:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzC/UJ/KtAabIvrfh3DRYKLf/wYBYxQAFI6S0IhnGAzEqi+nHZX52OKFY2gMukp4jo0C88J X-Received: by 2002:a17:902:290b:: with SMTP id g11mr632860plb.26.1558719417917; Fri, 24 May 2019 10:36:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719417; cv=none; d=google.com; s=arc-20160816; b=c+oZs1fWkMR99R7R0d1IFMNRyQ3y6WS+bkcnHOC0VRJIXyn7xY8aMH4miOpDSMISya w0Xd9YM3N87g0WqpU8u7Ch5T+kZN27+BBtIK/qJL5tGI5FHyH2OmegeGXG8kHvAx6rjq r+HjEQavlmrwDBqoJjMRYytEkr9aMjrKZLXM/wmXvSo4JvG1IylSCCT63DlufZOd1I3s kSJRE1pQVDuSnaZVkXPvE/j3TOpl7cEw6e22Z0k9kndrdzPFDg+VfKrrMHajAdR9pT0Z EXX/HbftKJQKoZnXErl+nZbsOgdjrWia+WSklFj0lDcCRC8gMCoTGXnxYTqeNRethY6f 1sgA== 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; bh=BWB6eRLRrW09Jmtj58um2VDPR3CNKPhCszqXJSm+Dmk=; b=p2RajfshVWWimoQGHSJEm4AT9zc+0JKBvm4BgRemHOflQG5OOpfVY1+1HN2L1kjvCF lkzx5whQwtQr17Nt/bZpZHAFlx6EeS6HtEU7/oVdXBIUuy29tJ1EZJ9ZizmTM+yyzoSc Ur8AgRplwY/DOnkIoNCAJ7jEBqLFxq+0vqPpZroXc06Y68GaFeEHtFwWjzlI/2ohGkBy agTPMng0gJsN6BBs1SjHyV+Bv+6hDw+bfr7hpTrWuiCNqSL+LADfxUm2W/Ph+AV4WexQ ZiVIWPL/SRKreQwTrzDuYVyVEssjHNqUmd3+5+I+hVWjKDsE93dmS8ACS8Lzablb2dY3 j1Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GXkWbZ+N; 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 p61si5376215plb.266.2019.05.24.10.36.57; Fri, 24 May 2019 10:36:57 -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=GXkWbZ+N; 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 S2391408AbfEXRfO (ORCPT + 30 others); Fri, 24 May 2019 13:35:14 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37152 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391077AbfEXRfM (ORCPT ); Fri, 24 May 2019 13:35:12 -0400 Received: by mail-pg1-f194.google.com with SMTP id n27so5419348pgm.4 for ; Fri, 24 May 2019 10:35:11 -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=BWB6eRLRrW09Jmtj58um2VDPR3CNKPhCszqXJSm+Dmk=; b=GXkWbZ+NheHeIFUhuT8VcOsE4YVdLMSJOeDxOcX/3Ice4/hwLnosQ83zB3nGKQ04PK r/4puoli9IPCcOGB/jAn5Hx6r70r4Uxq3yEfo40yDl2RA5ODFCn7LSguzdWj2Xd6+bti WVRYeNouLoscxEnn59araoOtd7pCqO9Xy2gWz/v3aW5snziNw0MDhBWzkiStYm9WKKYz PPGs+PPQR5+91CpI0g/R/fV/hph9ZSm/0zsQJ6+zgGW+bn9QBcLAAhOOR+QMJZN+Vyj5 h7smvSeZA3vGn2IqVeZR0kKnIPrZhDjvlziOWS376JpurSiD/W2ZnKSI81p4DhwOZ/K/ LP0Q== 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=BWB6eRLRrW09Jmtj58um2VDPR3CNKPhCszqXJSm+Dmk=; b=rSXCVpb/uNGZSaSyePh6m+suOJ9KLYX0eKKVpKddMh/vBaCbdJGE0+ifBS4m4n0BMA VucpbeRxnsXXXmAatyNi17mjzNovuzJFUx0eAS56m/ozJpK97szghyyi+cfN4jWGO3Zi CkhEjlgfNTim4WmngLIXJAv7KbFo4k9WXnMILcthv7e734FMVjNvEOv/A1wtXrYe+LnT YXBiNTEZ2rrW93ThkMOQ3ifFZBXg7xPdh9zw7UXUdaJ0a5qhJpq6uTtn5cuZqDpZ9wcn /fy6FZcXLDngm5dVkeE9Qyys7PnkFwTLee34QB7YkSvF09WL8NIfZkx6Cbh1FbWzYLHy MqSg== X-Gm-Message-State: APjAAAXwB7t78QdPBHhClt+Eo2Id2VQfxJnnLnJsFMsL0NeU2iW/f4Of s7pKTSXmfeupW2EfiX7tC/4M0w== X-Received: by 2002:a17:90a:650c:: with SMTP id i12mr10978396pjj.44.1558719311167; Fri, 24 May 2019 10:35:11 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:10 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 01/17] perf tools: Configure contextID tracing in CPU-wide mode Date: Fri, 24 May 2019 11:34:52 -0600 Message-Id: <20190524173508.29044-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When operating in CPU-wide mode being notified of contextID changes is required so that the decoding mechanic is aware of the process context switch. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- tools/perf/arch/arm/util/cs-etm.c | 126 +++++++++++++++++++++++++----- tools/perf/util/cs-etm.h | 12 +++ 2 files changed, 119 insertions(+), 19 deletions(-) -- 2.17.1 Reviewed-by: Mathieu Poirier diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index 911426721170..3912f0bf04ed 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -35,8 +35,100 @@ struct cs_etm_recording { size_t snapshot_size; }; +static const char *metadata_etmv3_ro[CS_ETM_PRIV_MAX] = { + [CS_ETM_ETMCCER] = "mgmt/etmccer", + [CS_ETM_ETMIDR] = "mgmt/etmidr", +}; + +static const char *metadata_etmv4_ro[CS_ETMV4_PRIV_MAX] = { + [CS_ETMV4_TRCIDR0] = "trcidr/trcidr0", + [CS_ETMV4_TRCIDR1] = "trcidr/trcidr1", + [CS_ETMV4_TRCIDR2] = "trcidr/trcidr2", + [CS_ETMV4_TRCIDR8] = "trcidr/trcidr8", + [CS_ETMV4_TRCAUTHSTATUS] = "mgmt/trcauthstatus", +}; + static bool cs_etm_is_etmv4(struct auxtrace_record *itr, int cpu); +static int cs_etm_set_context_id(struct auxtrace_record *itr, + struct perf_evsel *evsel, int cpu) +{ + struct cs_etm_recording *ptr; + struct perf_pmu *cs_etm_pmu; + char path[PATH_MAX]; + int err = -EINVAL; + u32 val; + + ptr = container_of(itr, struct cs_etm_recording, itr); + cs_etm_pmu = ptr->cs_etm_pmu; + + if (!cs_etm_is_etmv4(itr, cpu)) + goto out; + + /* Get a handle on TRCIRD2 */ + snprintf(path, PATH_MAX, "cpu%d/%s", + cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR2]); + err = perf_pmu__scan_file(cs_etm_pmu, path, "%x", &val); + + /* There was a problem reading the file, bailing out */ + if (err != 1) { + pr_err("%s: can't read file %s\n", + CORESIGHT_ETM_PMU_NAME, path); + goto out; + } + + /* + * TRCIDR2.CIDSIZE, bit [9-5], indicates whether contextID tracing + * is supported: + * 0b00000 Context ID tracing is not supported. + * 0b00100 Maximum of 32-bit Context ID size. + * All other values are reserved. + */ + val = BMVAL(val, 5, 9); + if (!val || val != 0x4) { + err = -EINVAL; + goto out; + } + + /* All good, let the kernel know */ + evsel->attr.config |= (1 << ETM_OPT_CTXTID); + err = 0; + +out: + + return err; +} + +static int cs_etm_set_option(struct auxtrace_record *itr, + struct perf_evsel *evsel, u32 option) +{ + int i, err = -EINVAL; + struct cpu_map *event_cpus = evsel->evlist->cpus; + struct cpu_map *online_cpus = cpu_map__new(NULL); + + /* Set option of each CPU we have */ + for (i = 0; i < cpu__max_cpu(); i++) { + if (!cpu_map__has(event_cpus, i) || + !cpu_map__has(online_cpus, i)) + continue; + + switch (option) { + case ETM_OPT_CTXTID: + err = cs_etm_set_context_id(itr, evsel, i); + if (err) + goto out; + break; + default: + goto out; + } + } + + err = 0; +out: + cpu_map__put(online_cpus); + return err; +} + static int cs_etm_parse_snapshot_options(struct auxtrace_record *itr, struct record_opts *opts, const char *str) @@ -105,8 +197,9 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, container_of(itr, struct cs_etm_recording, itr); struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu; struct perf_evsel *evsel, *cs_etm_evsel = NULL; - const struct cpu_map *cpus = evlist->cpus; + struct cpu_map *cpus = evlist->cpus; bool privileged = (geteuid() == 0 || perf_event_paranoid() < 0); + int err = 0; ptr->evlist = evlist; ptr->snapshot_mode = opts->auxtrace_snapshot_mode; @@ -241,19 +334,24 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, /* * In the case of per-cpu mmaps, we need the CPU on the - * AUX event. + * AUX event. We also need the contextID in order to be notified + * when a context switch happened. */ - if (!cpu_map__empty(cpus)) + if (!cpu_map__empty(cpus)) { perf_evsel__set_sample_bit(cs_etm_evsel, CPU); + err = cs_etm_set_option(itr, cs_etm_evsel, ETM_OPT_CTXTID); + if (err) + goto out; + } + /* Add dummy event to keep tracking */ if (opts->full_auxtrace) { struct perf_evsel *tracking_evsel; - int err; err = parse_events(evlist, "dummy:u", NULL); if (err) - return err; + goto out; tracking_evsel = perf_evlist__last(evlist); perf_evlist__set_tracking_event(evlist, tracking_evsel); @@ -266,7 +364,8 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, perf_evsel__set_sample_bit(tracking_evsel, TIME); } - return 0; +out: + return err; } static u64 cs_etm_get_config(struct auxtrace_record *itr) @@ -314,6 +413,8 @@ static u64 cs_etmv4_get_config(struct auxtrace_record *itr) config_opts = cs_etm_get_config(itr); if (config_opts & BIT(ETM_OPT_CYCACC)) config |= BIT(ETM4_CFG_BIT_CYCACC); + if (config_opts & BIT(ETM_OPT_CTXTID)) + config |= BIT(ETM4_CFG_BIT_CTXTID); if (config_opts & BIT(ETM_OPT_TS)) config |= BIT(ETM4_CFG_BIT_TS); if (config_opts & BIT(ETM_OPT_RETSTK)) @@ -363,19 +464,6 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused, (etmv3 * CS_ETMV3_PRIV_SIZE)); } -static const char *metadata_etmv3_ro[CS_ETM_PRIV_MAX] = { - [CS_ETM_ETMCCER] = "mgmt/etmccer", - [CS_ETM_ETMIDR] = "mgmt/etmidr", -}; - -static const char *metadata_etmv4_ro[CS_ETMV4_PRIV_MAX] = { - [CS_ETMV4_TRCIDR0] = "trcidr/trcidr0", - [CS_ETMV4_TRCIDR1] = "trcidr/trcidr1", - [CS_ETMV4_TRCIDR2] = "trcidr/trcidr2", - [CS_ETMV4_TRCIDR8] = "trcidr/trcidr8", - [CS_ETMV4_TRCAUTHSTATUS] = "mgmt/trcauthstatus", -}; - static bool cs_etm_is_etmv4(struct auxtrace_record *itr, int cpu) { bool ret = false; diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 0e97c196147a..826c9eedaf5c 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -103,6 +103,18 @@ struct intlist *traceid_list; #define KiB(x) ((x) * 1024) #define MiB(x) ((x) * 1024 * 1024) +/* + * Create a contiguous bitmask starting at bit position @l and ending at + * position @h. For example + * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. + * + * Carbon copy of implementation found in $KERNEL/include/linux/bitops.h + */ +#define GENMASK(h, l) \ + (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) + +#define BMVAL(val, lsb, msb) ((val & GENMASK(msb, lsb)) >> lsb) + #define CS_ETM_HEADER_SIZE (CS_HEADER_VERSION_0_MAX * sizeof(u64)) #define __perf_cs_etmv3_magic 0x3030303030303030ULL From patchwork Fri May 24 17:34:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165145 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3885119ili; Fri, 24 May 2019 10:35:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNpgZDrXKzjRTQJiRM7QqJgMUGguPzFdLDp0Kd0bpcdBv3snOPezFqvEhYA9miAObbhvMC X-Received: by 2002:a65:5241:: with SMTP id q1mr12066407pgp.298.1558719316875; Fri, 24 May 2019 10:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719316; cv=none; d=google.com; s=arc-20160816; b=AFErJioMeONJ1dfcijSVQojyU9i574KivZg5S95kVLQYc/u6DVelh0bEETjKCdiaEp eLYvGvbPIxAbG2ME7dUvTZWIlCkQH5ejlHHWDJRr3Nib8/Hv3UFkkm2fcCsGG4PxKQIE emjmqQYbxuPRPD3DNbWjXPNarzHkCzy/bu1NSQSuo+GrAL1ymMAOViWHhRX4CPve5LdO i6UK7GsvzZrYEGSmer+YZoXUIyJ/NyXhpQfAtIc9KO5hFJlpCNANWlYq6sg2mgkvhdn+ vzdk9oDZRQee1w8PBIjSNgc32IwzMkK6FOJ6Jdz0eLzJMjQdszkhLcGAOWhot53ZBluJ 5FhA== 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; bh=AZrEN/YdY4eKrQn36wY+GaRgnWiV23bSY81bJ8wnh7E=; b=VjA78ZdXO/2yElFBNh/WpaGNLDnUQm/t022bDybutaVeAXS5MhRGkwMEx1zRX0AA3S kjmS2iapwbVOsTTLMzpCCdXJkNjkNGDo2qUmXckNgFxu14r+drPrEEtm4nC2X0kNWBZq e24+SLxq9QwH8BDaXZwmnlnAeYTlnEkRsaqKFrbPyGRBBG7Za2oDoQF4FcKNqKk1fS/Q hLyC74fxiv0Q6wxKfWcLiKvFrK7PUSO2WVS/YwgMZJ9/pJdJKuYeuVrt4WM9Og8zEcMr eFlISfVQQLyme8PGMOdvKsIUPjiJDMB5JB6NS2864yCcogCLYreyd4KZjch7yCOedONx xljQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D22qwMvx; 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 f17si5078321pgv.338.2019.05.24.10.35.16; Fri, 24 May 2019 10:35:16 -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=D22qwMvx; 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 S2391527AbfEXRfP (ORCPT + 30 others); Fri, 24 May 2019 13:35:15 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:44711 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391301AbfEXRfN (ORCPT ); Fri, 24 May 2019 13:35:13 -0400 Received: by mail-pl1-f194.google.com with SMTP id c5so4434417pll.11 for ; Fri, 24 May 2019 10:35:12 -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=AZrEN/YdY4eKrQn36wY+GaRgnWiV23bSY81bJ8wnh7E=; b=D22qwMvxOv68Jbk8yGerAluLOCfagxSd4heu50CTNyczmf41/1BNWjQMJwAiayGx2w qna3aSLLtC3xLyupFWvVT7naW+d+e1y5Jb6lFKfizD75fsj9V76HNrx0EFkc59NmO6kS AURwwe0cV2bsPjZZTMNQhrO5T3YXKt1KvZq41Hs/XBgPWU4PdtApkKWnl/wGSazNJOgL Wq1U7spG/CMFNPo0fFMCCBTYui7aKgYhJG3HsJdYrT2P92gO25WICbl0fmzR1i/oiSjK XcsCe9xrrWhkZDqkGbGB++UPBC1yyr7dpNn5+Qt/s2k3zN40BWcdgkPKJsid2aSBYyFs 6c1w== 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=AZrEN/YdY4eKrQn36wY+GaRgnWiV23bSY81bJ8wnh7E=; b=mh+63u/hw7KYK/jEynp6TOuB5TogfDho47I0NR30hqnbhpVwOAg0htRPPBEhsxOltk cUDZ6hlzMMBXhxwWkmZqdyrJyhQz4kwxMa6j+s0Q2VfQXFwjfImGbWomDUBsI27u5FER TsWfUIriJLvopOM8ZBh9+Q3ZlxrSzX06WYpHIqvUM1NKFHYAB6sVU95CYyxNgqVhVB0o 7WpZr3WX92tydEgSXqDMek+heYXw88U5R1p46bI42cKOi5Amag1mQ+pN1MaN5hTtOofV idxDiht+djkbimPTNYz1/Fl5JF2d9Q/8/D8UNSiSMd/Am0/NThYph+2mZpbAZOgCbCKh 8FBA== X-Gm-Message-State: APjAAAXWmAN2HDHnXEwPEncJu2lCk/pNxb0VBGe1ruNvzQgK93nwEhWQ jhImxyjjRhRjnflZScUjz89guw== X-Received: by 2002:a17:902:a70f:: with SMTP id w15mr38056183plq.222.1558719312533; Fri, 24 May 2019 10:35:12 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:11 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 02/17] perf tools: Configure timestsamp generation in CPU-wide mode Date: Fri, 24 May 2019 11:34:53 -0600 Message-Id: <20190524173508.29044-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When operating in CPU-wide mode tracers need to generate timestamps in order to correlate the code being traced on one CPU with what is executed on other CPUs. Signed-off-by: Mathieu Poirier --- tools/perf/arch/arm/util/cs-etm.c | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) -- 2.17.1 diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index 3912f0bf04ed..be1e4f20affa 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -99,6 +99,54 @@ static int cs_etm_set_context_id(struct auxtrace_record *itr, return err; } +static int cs_etm_set_timestamp(struct auxtrace_record *itr, + struct perf_evsel *evsel, int cpu) +{ + struct cs_etm_recording *ptr; + struct perf_pmu *cs_etm_pmu; + char path[PATH_MAX]; + int err = -EINVAL; + u32 val; + + ptr = container_of(itr, struct cs_etm_recording, itr); + cs_etm_pmu = ptr->cs_etm_pmu; + + if (!cs_etm_is_etmv4(itr, cpu)) + goto out; + + /* Get a handle on TRCIRD0 */ + snprintf(path, PATH_MAX, "cpu%d/%s", + cpu, metadata_etmv4_ro[CS_ETMV4_TRCIDR0]); + err = perf_pmu__scan_file(cs_etm_pmu, path, "%x", &val); + + /* There was a problem reading the file, bailing out */ + if (err != 1) { + pr_err("%s: can't read file %s\n", + CORESIGHT_ETM_PMU_NAME, path); + goto out; + } + + /* + * TRCIDR0.TSSIZE, bit [28-24], indicates whether global timestamping + * is supported: + * 0b00000 Global timestamping is not implemented + * 0b00110 Implementation supports a maximum timestamp of 48bits. + * 0b01000 Implementation supports a maximum timestamp of 64bits. + */ + val &= GENMASK(28, 24); + if (!val) { + err = -EINVAL; + goto out; + } + + /* All good, let the kernel know */ + evsel->attr.config |= (1 << ETM_OPT_TS); + err = 0; + +out: + return err; +} + static int cs_etm_set_option(struct auxtrace_record *itr, struct perf_evsel *evsel, u32 option) { @@ -118,6 +166,11 @@ static int cs_etm_set_option(struct auxtrace_record *itr, if (err) goto out; break; + case ETM_OPT_TS: + err = cs_etm_set_timestamp(itr, evsel, i); + if (err) + goto out; + break; default: goto out; } @@ -343,6 +396,10 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, err = cs_etm_set_option(itr, cs_etm_evsel, ETM_OPT_CTXTID); if (err) goto out; + + err = cs_etm_set_option(itr, cs_etm_evsel, ETM_OPT_TS); + if (err) + goto out; } /* Add dummy event to keep tracking */ From patchwork Fri May 24 17:34:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165161 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3887019ili; Fri, 24 May 2019 10:37:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvFPYWxAL451acKtIjw5O8UeS+9nNVrIO1hoeypSaP+G+NORB7NlP4vY4c2sVIX9yGGM0R X-Received: by 2002:a17:90a:718c:: with SMTP id i12mr10968082pjk.32.1558719421495; Fri, 24 May 2019 10:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719421; cv=none; d=google.com; s=arc-20160816; b=bJJCicRMj0h0/FHVLAfzytKkOOTiG3l4KmzLqWnjZjwUF7dCKxfGE+RUPPKWc+OXKV FljaViWsfFZRdXqQAFeIjfh9e26ghfPMPNaEBdMymW9+Oizgv+Sui9yj68bkkbBSvc+5 k0shv8u6dDnkyGOaAkx3PjUrZUtidPpxgwVyPebeDkCX+ZrRx0i7t4jqBKl9Pjr/2sgR eo+3UWk9tr7TngFFgHHFNHUom3xBfhBh8iHN+CDPn0GpX9KthJ4eM3cnNjFcLrqdyPL+ /AR2Qf2Dmqw+PCvYQc3KOe1UUaj4I6TYpJngrcKS1Icg6BkhKxi1wAM4TNm2jMbggeHO vRgw== 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; bh=WjG/oYBVCTJ2cGSnVCWqwlxIc3B5k8jAV6xmXnGg2uk=; b=mGqSC3J56nZybe59k/VcuHAAUI4QDTW4VlJ74Vb28/XxcVaf+/Y5cSTwyOjhbGnKH7 o6RgbZPSH/F86E1KYV6YJH7WSlbbTGssAtWtVlePyvgmnxuxC4lAsFXQ3FxIvQsDi9XH CbW6/A+M6ogOczzsB11KMWut4O+tyrAe4uWGCw6o/xn3KOO7FUK5p9RJuGaBH9aaHqvX NRtuX/DSIKaYmlYjQufpdtk0fx/FM1o7b+SX3rrUFnniedE5sVB5c0AyCS6Sd5psN0TC GnctkelDOOSPePtX6eAoMRg69DLmt3ET8uhRSiIansRzybQSPA/1iGyfDAdZIwX55dMS h+/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DWnMfzRx; 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 p61si5376215plb.266.2019.05.24.10.37.01; Fri, 24 May 2019 10:37:01 -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=DWnMfzRx; 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 S2391788AbfEXRhA (ORCPT + 30 others); Fri, 24 May 2019 13:37:00 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:41216 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391362AbfEXRfO (ORCPT ); Fri, 24 May 2019 13:35:14 -0400 Received: by mail-pg1-f196.google.com with SMTP id z3so800041pgp.8 for ; Fri, 24 May 2019 10:35:14 -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=WjG/oYBVCTJ2cGSnVCWqwlxIc3B5k8jAV6xmXnGg2uk=; b=DWnMfzRx8uWzIrexmTH6icT77P0bzj4A6Bl6Me/8fyKJ8+Eh3WN52ltUnTzvTw5zRC HqrcyTxeWw74Fbnf4SkuWYKwDcySDL0v94ERXknwIAdQeEPQRTsFFy3CDrDfEMrsobFu +u6eSxb32WMlbSljrRidcbVprKanMJhy03X3qbq8Oad4e4OzTBhD7CyEW9JdLKtYDhhn vdKgLO8Ndg/mEc0nizAxhj4aLYpounInK92BylqJ4S8KAb4IaOEx2GtsMfkVQA54T0sK 9bb6sTPJaVA4Z6ZIDVcJhHa4666uS8PNjQM4icyA/sRqP7SZb86pbQUM1wNKkcdjxGpW XFbQ== 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=WjG/oYBVCTJ2cGSnVCWqwlxIc3B5k8jAV6xmXnGg2uk=; b=KycMgtk8SdDUy0c4iV9Qkfx5V/fh1cOSOgbGJUB3mQ6Syn5AYn4nHTgUmeGw7y/WRO bwkm+nWPcHW5L59umoiC+WJowttFXAUejMM2QTVvBkE6kgpDGOhVuCfVuAx48rBqV2Ei EiJuMesnSrahn+FG2lUYpcAHOsJaP6NdK4ncv/aHLteVHEgZNsJxCEeSZBGRBId3H9tb 3xpz9vxyJs9QJSdM9nExuugtVD3ZF4Hl2DXFdDrq0F1GzyArFyMekUtvNDTQSCSSM17B oUqm58J6CZqJMD4Zfpqyy8R63xsDriCEp6PIpOjmXXmzBbHcc2L6UqZNi+9xD7wqHjiV Sl6g== X-Gm-Message-State: APjAAAVtJmcWQMiLSGvqhnxWaL8QwV1kv38AxMBMGwENFiq2BYRUAZ4j a++bO77X4uzO0xlM4uu0tFMz3w== X-Received: by 2002:a17:90a:d992:: with SMTP id d18mr10956709pjv.74.1558719313700; Fri, 24 May 2019 10:35:13 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:13 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 03/17] perf tools: Configure SWITCH_EVENTS in CPU-wide mode Date: Fri, 24 May 2019 11:34:54 -0600 Message-Id: <20190524173508.29044-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ask the perf core to generate an event when processes are swapped in/out of context. That way proper action can be taken by the decoding code when faced with such event. Signed-off-by: Mathieu Poirier --- tools/perf/arch/arm/util/cs-etm.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.17.1 diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index be1e4f20affa..cc7f1cd23b14 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -257,6 +257,9 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, ptr->evlist = evlist; ptr->snapshot_mode = opts->auxtrace_snapshot_mode; + if (perf_can_record_switch_events()) + opts->record_switch_events = true; + evlist__for_each_entry(evlist, evsel) { if (evsel->attr.type == cs_etm_pmu->type) { if (cs_etm_evsel) { From patchwork Fri May 24 17:34:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165158 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3886650ili; Fri, 24 May 2019 10:36:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqyD/NeAzmZd1a70zZ0It5jHSGE5zupdwDhIqTCh1w+oO9qMziBGxnkRNn1K8n7Cn3v7wquV X-Received: by 2002:a17:902:b704:: with SMTP id d4mr37740419pls.217.1558719401628; Fri, 24 May 2019 10:36:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719401; cv=none; d=google.com; s=arc-20160816; b=fHjgEpOtF+xUbGtjaP2ryJ/FeoYaFep5EbKwyvj89Cp74YxybDFJg37gipbE3ORxUV 08O6ehxHOpDQmBXuy2L+L7mP7fTks1QyTBRGU7iNtpHoB3u0jlL0JmBDiP5k4RGaiNm1 RFDZa7vWh051o/QpcRv1Feq5lv+PThghebdEp5c/HZo00Ytwkl9/Ug3QnWwjHnL58mEi upHD4MWZaopX5IMMwqcHJnbc/eORXSOPcGEXYtnIqPDgmMpTPjEzxI8I1rCqsdsfVaPm m2cBWdLvXe/I3dUHeonUvwnVM1DucCJlduFsmCQvbl4x/5DJ3PHxNPO/mwFUaDlcTJxx vRXg== 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; bh=bHfFo/ORpsa03SvyTpjVHtc4WYRwtr5BeZCOvFgzYZo=; b=03Gj4B2ZViKZY5wvjZ6A9wXBuptTG3x1/vZuIfs26f4f+k2elgQvE0tvCKCGNNJY4B Fd+TJcM6bksHMEzCo/wbq4FTI+zaDVV/SwVnHrggsySGSr4yIzWnXpo2OcSReWUHEsSw pKlp99njFpTw5oheEYhOl8FB305nbsLvymPgQXpdSEpPPDAQaO2PtDeMpldUWGzjZaxM Q52gaUANHbJGKMaZ22YTd3jaHfQ6HSxc7TWLzRf+ZdMA04KONuieDAXZrCcJAuP9MmBN TozL55aISToL/O6L1G+HIkO69k3Ddr5vVyY00HonI2kYETkevnkLxj0tlDmcENIzxaAe 38Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hSBPmd0y; 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 b11si4451495pgq.455.2019.05.24.10.36.41; Fri, 24 May 2019 10:36:41 -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=hSBPmd0y; 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 S2391641AbfEXRfT (ORCPT + 30 others); Fri, 24 May 2019 13:35:19 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36368 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391421AbfEXRfP (ORCPT ); Fri, 24 May 2019 13:35:15 -0400 Received: by mail-pl1-f196.google.com with SMTP id d21so4439635plr.3 for ; Fri, 24 May 2019 10:35:15 -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=bHfFo/ORpsa03SvyTpjVHtc4WYRwtr5BeZCOvFgzYZo=; b=hSBPmd0yHRq5YPvvnYa5Gx0AuXkJSH3B/lf9UvmmoD/BV8lpht4l4I20wq2uLPOEPs u7ufCc6pRQ3OIj5ikzw7wj6tCJb8XA05l+3Ag8o3CxvMzdRYsLnd4zvezjzSjKixKYF9 tCi1s+z/0fQW6n6IyymDffRnqsMm0576GcSIFZko3qMfIcB7H2Yn1EIFnLBxojtntpDI up25DcEbYTZjo+CzyW8v3n6/ZyYz/e/SGmtK8MXqs7PkzM0602OyS2k2oNGTq/ntRLDa 9thUJP0L0kIiwr1tfYWkIzSUvthKBLIhli1z9zahMaCO5znW4HJDhWd/ywN2Z6EnDT0n do3g== 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=bHfFo/ORpsa03SvyTpjVHtc4WYRwtr5BeZCOvFgzYZo=; b=Cm+GQC/PbgYaMjnm5rd8cALxFZx/M3Noc1nl3NWjtuEcKaWG856wE1LYSKyh2iM0gw ayT2N1DP9Jb/SbaQZ+D/m+Wp4Pg2qB0IdH04qlMDOHTpFOJqDo+MRFgScEafdIc02Uh2 LhqS5o7YAUsVVJSw0Tvx0+ZcZfKbe9HUJqYiH2+KOGAb5mLRzq4/VHfPDps28gvBS0C4 gMTZeLoiJ0LQ5O6xYfUmTr3b7kIx4nu8rkEqAXNUoLKVIgAyHS7fCRkYiiLt2mIfhB9Z nbS7RXBca9lhnejZCqK4WppfJzIz2RwVGtU+FET8ObsQIm6aD73vMwHjdNZFkaJxGhbx Z2Xw== X-Gm-Message-State: APjAAAUprWX43ySPIqGLV6JGgEl0gOdBFctnP8egogjCtFwGp5C6Up9P iqh8Drw7JHkY98SfASFag/JUcw== X-Received: by 2002:a17:902:2e81:: with SMTP id r1mr91812796plb.0.1558719314882; Fri, 24 May 2019 10:35:14 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:14 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 04/17] perf tools: Add handling of itrace start events Date: Fri, 24 May 2019 11:34:55 -0600 Message-Id: <20190524173508.29044-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add handling of ITRACE events in order to add the tid/pid of the executing process to the perf tools machine infrastructure. This information is later retrieved when a contextID packet is found in the trace stream. Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index de488b43f440..0742c50fce46 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1657,6 +1657,29 @@ static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm, return 0; } +static int cs_etm__process_itrace_start(struct cs_etm_auxtrace *etm, + union perf_event *event) +{ + struct thread *th; + + if (etm->timeless_decoding) + return 0; + + /* + * Add the tid/pid to the log so that we can get a match when + * we get a contextID from the decoder. + */ + th = machine__findnew_thread(etm->machine, + event->itrace_start.pid, + event->itrace_start.tid); + if (!th) + return -ENOMEM; + + thread__put(th); + + return 0; +} + static int cs_etm__process_event(struct perf_session *session, union perf_event *event, struct perf_sample *sample, @@ -1694,6 +1717,9 @@ static int cs_etm__process_event(struct perf_session *session, return cs_etm__process_timeless_queues(etm, event->fork.tid); + if (event->header.type == PERF_RECORD_ITRACE_START) + return cs_etm__process_itrace_start(etm, event); + return 0; } From patchwork Fri May 24 17:34:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165159 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3886813ili; Fri, 24 May 2019 10:36:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHrfBTQqlrtm4vQhRLm9dgvHjpvjdYAKrtBXouCJ98AmUEwyeO+JYss4KuD7Twl8LTySVF X-Received: by 2002:a62:7995:: with SMTP id u143mr114357895pfc.61.1558719410407; Fri, 24 May 2019 10:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719410; cv=none; d=google.com; s=arc-20160816; b=uWYZGPpho7JSt3NqU34XDXbpY76/HTy+f0ZvuSQUjJXKluw4b3vACM8ASlBYFXYCXU ur/3Pq3YqGvvyxTr5nakik02hjjCSE1SNVXVwIU1bXeoHAYCJAyVRb/iwbQHEZvzuRYc pLl2FwT3MBbTP6Zok+eQhVHuE1qCntWwAfrtWy5I+AJNRHiMeCt9rSs73PSk33r8n3sy XPxmZeyNRit4i3gGHk7rcpV+lS3wORIM8CgWDewEA9LtW+VvrUtoxDGAxUumBp0rnGDv iWSxxS5WwWepV8ErC4DcVbW2Q0hNR3ct/Z7HUvDfs7J/4jrHmGJL6FfryGqZ9gTvw7cA X5Sw== 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; bh=jTlQzYqrjzzW1MYnyuDkipJisTZbubvkU14bVoe0t14=; b=AuFtzxn/QR0j8qcbTY71hgnQLv3/Yz0BnwHtbaR1XKfK8jhmfjj8eRfxTRhAwyEg8u Rzea4uqlk/+SjGgWxgAeLoBFldYui+yjT4MpKssuVwA3jVYuKtMd62612TKgavoGA/6s klsCkO7RSHp8Zd/6kR9shpH6mA+2svyYZ9+le3a5VxMD6gHNQkSWOEgnmBkO6rblKoGm 8C5wQIETQp48JBbGAUjxyCU93y4YGfPrQKtlzI2H0ujk8vmTuLiG3FxtUL8r15fsQpx4 tUrFPd6ANN+TPpRe53F8ErMGidt9rslUJqSgpk/BzYVwly1DcW6yqbTN7LNKC3edWkZJ YMSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MC93AIIp; 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 b3si5130847pgt.583.2019.05.24.10.36.50; Fri, 24 May 2019 10:36:50 -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=MC93AIIp; 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 S2391791AbfEXRgt (ORCPT + 30 others); Fri, 24 May 2019 13:36:49 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34252 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391530AbfEXRfR (ORCPT ); Fri, 24 May 2019 13:35:17 -0400 Received: by mail-pf1-f195.google.com with SMTP id n19so5738842pfa.1 for ; Fri, 24 May 2019 10:35:16 -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=jTlQzYqrjzzW1MYnyuDkipJisTZbubvkU14bVoe0t14=; b=MC93AIIpGvqvxr8KRwqE/rWvPO816+lg1ETrCvK8D6sHxJvYJ7kjPT01pyAH/9YLHW rKBhBxiBcCRxSMwlhyztMxeq546Q44yGeKEORvrc/Z1TcGFvOlAwvRLLfqhNc8bSnfrM IBDJWi+NIUGrO2UtFv9kqJiTeF32OiaBBsmmFhiUjd5PkXdHYmEjRE6G+RJ8mjJQLnCP 142m+uRG7sJQcCztbeuvD4QrM7baoBZOVVq7YYf88ndLv1TsuRyouvxttcIK8BWn6Vtj Vtsea2KMHWfQPN7Hzv+8Y0oC1WGILNqZcTcekCR6Bo1vJ3hC1zi5d5X5XL1O4rQN2ywf OPzw== 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=jTlQzYqrjzzW1MYnyuDkipJisTZbubvkU14bVoe0t14=; b=VJWslzMBjKbFcpNx7GLI2gQ3pMqaRHp57ItuTyH8LBonMUCsvZs8f9ChHvg5MTSlpe ImtN5um57YUUnPCvv/mqs2aX3DWComUAYtcDsw6Qe77HAbXlJT7rPABJk9OWdjY2trrl iWrJbHT7yY62QBvQW3616D9cea58vy7YeXMkIH+PjUZs6K3PhQd7RJMKegOHKY4G88th V4ng7UF0fQgjNUgSFEGCmLb1Oq8FD2ZqVrqEGFyq8j+WuUL5C5VTntUGjO9sS+WYHuxH 8xaswn9njHWzWXir4Z3aQ08eJUCYYocd3BOt5O5CHNgdkKKVSKRvxkjx8fAXXYy8yea+ xa5A== X-Gm-Message-State: APjAAAVPoooKMBQf0Dfquixz94KoLIPWdIBwrLGHXR3LUkgXg5hOMi6F qVbH+1409rIYOvD5fK0iFqTfqw== X-Received: by 2002:a65:494a:: with SMTP id q10mr12264479pgs.201.1558719316187; Fri, 24 May 2019 10:35:16 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:15 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 05/17] perf tools: Add handling of switch-CPU-wide events Date: Fri, 24 May 2019 11:34:56 -0600 Message-Id: <20190524173508.29044-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add handling of SWITCH-CPU-WIDE events in order to add the tid/pid of the incoming process to the perf tools machine infrastructure. This information is later retrieved when a contextID packet is found in the trace stream. Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 0742c50fce46..5322dcaaf654 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1680,6 +1680,42 @@ static int cs_etm__process_itrace_start(struct cs_etm_auxtrace *etm, return 0; } +static int cs_etm__process_switch_cpu_wide(struct cs_etm_auxtrace *etm, + union perf_event *event) +{ + struct thread *th; + bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT; + + /* + * Context switch in per-thread mode are irrelevant since perf + * will start/stop tracing as the process is scheduled. + */ + if (etm->timeless_decoding) + return 0; + + /* + * SWITCH_IN events carry the next process to be switched out while + * SWITCH_OUT events carry the process to be switched in. As such + * we don't care about IN events. + */ + if (!out) + return 0; + + /* + * Add the tid/pid to the log so that we can get a match when + * we get a contextID from the decoder. + */ + th = machine__findnew_thread(etm->machine, + event->context_switch.next_prev_pid, + event->context_switch.next_prev_tid); + if (!th) + return -ENOMEM; + + thread__put(th); + + return 0; +} + static int cs_etm__process_event(struct perf_session *session, union perf_event *event, struct perf_sample *sample, @@ -1719,6 +1755,8 @@ static int cs_etm__process_event(struct perf_session *session, if (event->header.type == PERF_RECORD_ITRACE_START) return cs_etm__process_itrace_start(etm, event); + else if (event->header.type == PERF_RECORD_SWITCH_CPU_WIDE) + return cs_etm__process_switch_cpu_wide(etm, event); return 0; } From patchwork Fri May 24 17:34:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165146 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3885222ili; Fri, 24 May 2019 10:35:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxNLpwMUCT+xVIlOzAtJfAnX8a91T603zNYhEFDNuf7v8HV3hF1tsMuVSVxGqMSmELR1cz X-Received: by 2002:a17:90a:808a:: with SMTP id c10mr10590586pjn.67.1558719322595; Fri, 24 May 2019 10:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719322; cv=none; d=google.com; s=arc-20160816; b=UOxayRGKEZDVvJbSI2+4oR2b9Li4Va+F0vL1vjcyiXir/PovyzVWukzZ8BfZ7LQwRJ 78wg+2LiTmYep0jEPXHjgXFEiAnNhwDENENhzV97DFGfq6/LEqLzH/wJsZWJwUw+W7Tl Q2RlVOoNmMXtpTPEEJJm5Yuphxk2FmNaahJA+YyiiGLTesCvq9jUxtulAEZ7BSwYjmoe qJoJWl3Ui77jfO4uiLhPBLUiKOyLGwjxnm4P8dWxDmXll2xjm37ZRkHnOs1txF/d47vh fNmME2lM50Sx5gAONzmekJktpXJiV+oCa8Q2rA9UpF+Ypl9FgHkSXSn+5jY/p/noLBwK JJvw== 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; bh=TdCUaEZ68qpQ0pkU47NzIQOhdzi0053++FFZ3/d/RGQ=; b=Tk2HYAQi4lV7DSCiJe/rMehQrC8HMY0j4il2aId/QTngs+8snYzvCxozB70RxYBjbB dEehrmkWL8Bl9Bptu0JS8hZd+VPd1FAlBDaQNI0ZTml8WUTvm4MlmLEDCMmXabRdpB+l PnZ1Px/Vf314RjPXnwhKh/Z8Z45Kig8aTK/YKJ7zFMfz5dbQaDjuulJU64s9gh0dWWqS USxfNoHan6YWK7MgcADj0SztBMxVENNRHlVUZpWNegxqX5pQJEeN63G13ODzyNDJiEET JUCDEn4DzjZHA20MmmWiz/RtzD8NsueGg47smSjMLplXSV6xP7JEdoQ6X7c9n/3GqJGq xGjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FntvYFIA; 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 f17si5078321pgv.338.2019.05.24.10.35.22; Fri, 24 May 2019 10:35:22 -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=FntvYFIA; 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 S2391682AbfEXRfV (ORCPT + 30 others); Fri, 24 May 2019 13:35:21 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:33802 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391578AbfEXRfS (ORCPT ); Fri, 24 May 2019 13:35:18 -0400 Received: by mail-pl1-f194.google.com with SMTP id w7so4439523plz.1 for ; Fri, 24 May 2019 10:35:17 -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=TdCUaEZ68qpQ0pkU47NzIQOhdzi0053++FFZ3/d/RGQ=; b=FntvYFIAvQYhJ/apol1z9vxNQ/Gm+qEaV5pe3mOV5Y8mHC+C5tsGFzFRRfqZTSGr7U /+pIlw5zaR4AJttsxs6LqPHz7SWDIog4iUePidyBdPLxGuZzuZKqrGyYUt5CsP7S6K68 IlSI7YP7ffh/pa97PS/2rI13ECfIUXnk3gi770orY5/xU2N02CUGrhc3Q0pVRaYYUHx+ 5owFn1/THbD834pSoGhKBWJieUVjmcC9YrPdosTVIcCE+fo0qMNbQS9GDMzHw/LFAQyF lWm9Cm1/xI++8KnAZa2riSRk0In388mG/bpRUJvp17Bkpxgzrl8BxMSxc4+dc8hVBsrx 8QEg== 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=TdCUaEZ68qpQ0pkU47NzIQOhdzi0053++FFZ3/d/RGQ=; b=df47Gj9ELMaSluowFsPPtHzjq40rI/qQlWJZS/qkCz9UVK5c2oCP9hA0vhZ4RHtWKa Bfe7z3Fj6qMJY5cbkdeoIWK7uiWtXtGGvD6/TqfNXb9SRGaeXTGej/00YwfKZPFdW0L9 pBunrelhsrweuaR6C1kL2LPcI/eh7FX9Hmy+oEbNOpOaP592qZygFQrcCGQbHxIpOeCx 1eUfW3jaOAFmPiu6JWW4OVg2GG/oat5N26X8JD9dqB0s88AkHN2ekE2Qc7oN94Suhk0e JFeDvCplMEiOZmfIc9RlAthBefWC70Nft8ph8JafblmB07VExG/NbDZ/fAsVqe8f0tvr 9RYQ== X-Gm-Message-State: APjAAAVo4zkdy+wO4bOtEg5WHFc75RDWHun3X0sRZNuSZMegSdqHDEEn P7FqIJI9c4a+UxG/n/s6bovHdQ== X-Received: by 2002:a17:902:2a28:: with SMTP id i37mr19562156plb.52.1558719317327; Fri, 24 May 2019 10:35:17 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:16 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 06/17] perf tools: Refactor error path in cs_etm_decoder__new() Date: Fri, 24 May 2019 11:34:57 -0600 Message-Id: <20190524173508.29044-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no point in having two different error goto statement since the openCSD API to free a decoder handles NULL pointers. As such function cs_etm_decoder__free() can be called to deal with all aspect of freeing decoder memory. Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index 39fe21e1cf93..5dafec421b0d 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -577,7 +577,7 @@ cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, /* init library print logging support */ ret = cs_etm_decoder__init_def_logger_printing(d_params, decoder); if (ret != 0) - goto err_free_decoder_tree; + goto err_free_decoder; /* init raw frame logging if required */ cs_etm_decoder__init_raw_frame_logging(d_params, decoder); @@ -587,15 +587,13 @@ cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, &t_params[i], decoder); if (ret != 0) - goto err_free_decoder_tree; + goto err_free_decoder; } return decoder; -err_free_decoder_tree: - ocsd_destroy_dcd_tree(decoder->dcd_tree); err_free_decoder: - free(decoder); + cs_etm_decoder__free(decoder); return NULL; } From patchwork Fri May 24 17:34:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165157 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3886332ili; Fri, 24 May 2019 10:36:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwUgG/dF5rxctznmOHNYWnsezn7WdmJ+4Y0jqJ80Nn2lEBxIh8hMUPKCHrNqM2L4s5pNB+3 X-Received: by 2002:a63:6848:: with SMTP id d69mr108803506pgc.0.1558719382476; Fri, 24 May 2019 10:36:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719382; cv=none; d=google.com; s=arc-20160816; b=AUvPM9KHXxyaHuFypD9U/LAnNtR+6DEp0P0vtNsDu4rDXpaZLt0D56tifZCGHnzHnd aQSi8ofAP6Em3PPmXfbkNWFNguYPqdavpKLZvU5U7dzHTrnozqnHl/PEhuldhv9wtIEY MAL95vBzf4eOMx+nZ3mM9HP4BYLH7LxFUKslfQedChkWXywiuXzU5WZaJUDn1kUGePIf R9YGI4RSCWNwQ3OTapTBGAuq9ZuMuDEfovz/2EYafg0u1x++mQJrOIUf4KIuFO+K5KMe s0UVxb2K2eCCq+2x02STO10x+hVDS4fBWqD+qHKnxXwEldGHM5J6Qe7rYytQCK+BBOH5 Tk3A== 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; bh=ytMC6TdM6wDqrBi+Nfv5ei0LCN6ZkEkffev9cyB2DXk=; b=RO/65ebB1eCGwsApn3fj08zHaKCkxDAp/iR3uaZAJQGnJv5XSXrdJbfR1nwszpgf0o 2LpT8S1ZGWhiQUzO1rvynyNqftzVg2kE79aE71LpRPOPKy6KtodfJ8cZoeiic82YecNK NNUcP566PPZMH5u1W9B02B6kRx6NVYcPNkqecp/GrDHx4egyiHzvDAtOMRyAxQwJbxZx o3Dsp45eEfOJzpJHJgmtNYUOYgiXrYTC7UiRcHQ3mGSKa48Sp3Y+g7YITki58NMVamPm f8RPaH5hFSsaJPOxWszz9XRWXMOUb4xCKB3t24U5U/KOQDwYXOyZbDL6Ofw/WUUQVJXH 7vYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bU26Wliw; 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 f14si5010331plr.1.2019.05.24.10.36.22; Fri, 24 May 2019 10:36:22 -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=bU26Wliw; 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 S2391757AbfEXRgV (ORCPT + 30 others); Fri, 24 May 2019 13:36:21 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38582 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391644AbfEXRfU (ORCPT ); Fri, 24 May 2019 13:35:20 -0400 Received: by mail-pf1-f194.google.com with SMTP id b76so5722731pfb.5 for ; Fri, 24 May 2019 10:35:19 -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=ytMC6TdM6wDqrBi+Nfv5ei0LCN6ZkEkffev9cyB2DXk=; b=bU26Wliw7eZFqa7WQ/4OjoEU0ia1hmH2ieQLSIueMHSxUO3OtbEqN0qyslTaZwqo0h 8zscQOxjpH0wToJ8/EIpP7Ny2bwAsyzfq8iJlixA9JnQvYt2skdIvD9MLoOYyApzLlcN 0Ku1P/sL8/cqRHP4HmF+3ZalXMBjDmIb3sZFYqqs0OQ7lWyt0m0/UntrBBvxd7wxyv6t bkSJY9sYktgfZ/ca4qDG1d4/vD+eCtILTJCBxOJVjHdl7x9IwuKZoya4xhJG45fu/hqW ROoJJ7zlu8i0Qfzecr7qdqmahPKWnGCZrZj1BxwSma11Eoh8wvOFNAghLm2ltylAFjti 8Yuw== 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=ytMC6TdM6wDqrBi+Nfv5ei0LCN6ZkEkffev9cyB2DXk=; b=Ap9a1F1pY/MUyqbkpBEpRxlBQxXCEshzY44XLq8HqmBWottzaH7lv6U317Epw89Kxo nKs8mgDBREebh01I70JyUcccMQ2bywIv22ZL/M3fDpE6s6Llkh4P7EYaj3Mg3lAGbZhN 9wVwAjPDxki47jESsr5mHDkrsrMYRTns5t/P35kQ+48hGUA2+7Sjahd+5L/cRMNpqAgd Rj4CzmK0DVhJPAvHUHMibk3FsBxn2Ev8Z/uTqelb9P+RybCduhlKHu4LIjDj/jpz4fnV WFeC/68qHWjAGqDVkQzHmAoZx+EbRb/qEKyt3Rb+FbBbKZA3CS5NdoUHSCl5DQI/xcu8 QCXw== X-Gm-Message-State: APjAAAUR35FG9KXA0t1ojMmq4R9Zn2YMcx+hwExP1TBJF4wEkB4a5mJe yDtqyc+IWbWW+wlqaWF+dFu5Mg== X-Received: by 2002:a17:90a:2401:: with SMTP id h1mr10835522pje.123.1558719318805; Fri, 24 May 2019 10:35:18 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:18 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 07/17] perf tools: Move packet queue out of decoder structure Date: Fri, 24 May 2019 11:34:58 -0600 Message-Id: <20190524173508.29044-8-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The decoder needs to work with more than one traceID queue if we want to support CPU-wide scenarios with N:1 source/sink topologies. As such move the packet buffer and related fields out of the decoder structure and into the cs_etm_queue structure. Signed-off-by: Mathieu Poirier --- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 129 +++++++----------- .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 36 +---- tools/perf/util/cs-etm.c | 37 ++++- tools/perf/util/cs-etm.h | 53 +++++++ 4 files changed, 144 insertions(+), 111 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index 5dafec421b0d..3ac238e58901 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -18,8 +18,6 @@ #include "intlist.h" #include "util.h" -#define MAX_BUFFER 1024 - /* use raw logging */ #ifdef CS_DEBUG_RAW #define CS_LOG_RAW_FRAMES @@ -31,18 +29,12 @@ #endif #endif -#define CS_ETM_INVAL_ADDR 0xdeadbeefdeadbeefUL - struct cs_etm_decoder { void *data; void (*packet_printer)(const char *msg); dcd_tree_handle_t dcd_tree; cs_etm_mem_cb_type mem_access; ocsd_datapath_resp_t prev_return; - u32 packet_count; - u32 head; - u32 tail; - struct cs_etm_packet packet_buffer[MAX_BUFFER]; }; static u32 @@ -88,14 +80,14 @@ int cs_etm_decoder__reset(struct cs_etm_decoder *decoder) return 0; } -int cs_etm_decoder__get_packet(struct cs_etm_decoder *decoder, +int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue, struct cs_etm_packet *packet) { - if (!decoder || !packet) + if (!packet_queue || !packet) return -EINVAL; /* Nothing to do, might as well just return */ - if (decoder->packet_count == 0) + if (packet_queue->packet_count == 0) return 0; /* * The queueing process in function cs_etm_decoder__buffer_packet() @@ -106,11 +98,12 @@ int cs_etm_decoder__get_packet(struct cs_etm_decoder *decoder, * value. Otherwise the first element of the packet queue is not * used. */ - decoder->head = (decoder->head + 1) & (MAX_BUFFER - 1); + packet_queue->head = (packet_queue->head + 1) & + (CS_ETM_PACKET_MAX_BUFFER - 1); - *packet = decoder->packet_buffer[decoder->head]; + *packet = packet_queue->packet_buffer[packet_queue->head]; - decoder->packet_count--; + packet_queue->packet_count--; return 1; } @@ -276,84 +269,60 @@ cs_etm_decoder__create_etm_packet_printer(struct cs_etm_trace_params *t_params, trace_config); } -static void cs_etm_decoder__clear_buffer(struct cs_etm_decoder *decoder) -{ - int i; - - decoder->head = 0; - decoder->tail = 0; - decoder->packet_count = 0; - for (i = 0; i < MAX_BUFFER; i++) { - decoder->packet_buffer[i].isa = CS_ETM_ISA_UNKNOWN; - decoder->packet_buffer[i].start_addr = CS_ETM_INVAL_ADDR; - decoder->packet_buffer[i].end_addr = CS_ETM_INVAL_ADDR; - decoder->packet_buffer[i].instr_count = 0; - decoder->packet_buffer[i].last_instr_taken_branch = false; - decoder->packet_buffer[i].last_instr_size = 0; - decoder->packet_buffer[i].last_instr_type = 0; - decoder->packet_buffer[i].last_instr_subtype = 0; - decoder->packet_buffer[i].last_instr_cond = 0; - decoder->packet_buffer[i].flags = 0; - decoder->packet_buffer[i].exception_number = UINT32_MAX; - decoder->packet_buffer[i].trace_chan_id = UINT8_MAX; - decoder->packet_buffer[i].cpu = INT_MIN; - } -} - static ocsd_datapath_resp_t -cs_etm_decoder__buffer_packet(struct cs_etm_decoder *decoder, +cs_etm_decoder__buffer_packet(struct cs_etm_packet_queue *packet_queue, const u8 trace_chan_id, enum cs_etm_sample_type sample_type) { u32 et = 0; int cpu; - if (decoder->packet_count >= MAX_BUFFER - 1) + if (packet_queue->packet_count >= CS_ETM_PACKET_MAX_BUFFER - 1) return OCSD_RESP_FATAL_SYS_ERR; if (cs_etm__get_cpu(trace_chan_id, &cpu) < 0) return OCSD_RESP_FATAL_SYS_ERR; - et = decoder->tail; - et = (et + 1) & (MAX_BUFFER - 1); - decoder->tail = et; - decoder->packet_count++; - - decoder->packet_buffer[et].sample_type = sample_type; - decoder->packet_buffer[et].isa = CS_ETM_ISA_UNKNOWN; - decoder->packet_buffer[et].cpu = cpu; - decoder->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR; - decoder->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR; - decoder->packet_buffer[et].instr_count = 0; - decoder->packet_buffer[et].last_instr_taken_branch = false; - decoder->packet_buffer[et].last_instr_size = 0; - decoder->packet_buffer[et].last_instr_type = 0; - decoder->packet_buffer[et].last_instr_subtype = 0; - decoder->packet_buffer[et].last_instr_cond = 0; - decoder->packet_buffer[et].flags = 0; - decoder->packet_buffer[et].exception_number = UINT32_MAX; - decoder->packet_buffer[et].trace_chan_id = trace_chan_id; - - if (decoder->packet_count == MAX_BUFFER - 1) + et = packet_queue->tail; + et = (et + 1) & (CS_ETM_PACKET_MAX_BUFFER - 1); + packet_queue->tail = et; + packet_queue->packet_count++; + + packet_queue->packet_buffer[et].sample_type = sample_type; + packet_queue->packet_buffer[et].isa = CS_ETM_ISA_UNKNOWN; + packet_queue->packet_buffer[et].cpu = cpu; + packet_queue->packet_buffer[et].start_addr = CS_ETM_INVAL_ADDR; + packet_queue->packet_buffer[et].end_addr = CS_ETM_INVAL_ADDR; + packet_queue->packet_buffer[et].instr_count = 0; + packet_queue->packet_buffer[et].last_instr_taken_branch = false; + packet_queue->packet_buffer[et].last_instr_size = 0; + packet_queue->packet_buffer[et].last_instr_type = 0; + packet_queue->packet_buffer[et].last_instr_subtype = 0; + packet_queue->packet_buffer[et].last_instr_cond = 0; + packet_queue->packet_buffer[et].flags = 0; + packet_queue->packet_buffer[et].exception_number = UINT32_MAX; + packet_queue->packet_buffer[et].trace_chan_id = trace_chan_id; + + if (packet_queue->packet_count == CS_ETM_PACKET_MAX_BUFFER - 1) return OCSD_RESP_WAIT; return OCSD_RESP_CONT; } static ocsd_datapath_resp_t -cs_etm_decoder__buffer_range(struct cs_etm_decoder *decoder, +cs_etm_decoder__buffer_range(struct cs_etm_packet_queue *packet_queue, const ocsd_generic_trace_elem *elem, const uint8_t trace_chan_id) { int ret = 0; struct cs_etm_packet *packet; - ret = cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + ret = cs_etm_decoder__buffer_packet(packet_queue, trace_chan_id, CS_ETM_RANGE); if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT) return ret; - packet = &decoder->packet_buffer[decoder->tail]; + packet = &packet_queue->packet_buffer[packet_queue->tail]; switch (elem->isa) { case ocsd_isa_aarch64: @@ -400,36 +369,36 @@ cs_etm_decoder__buffer_range(struct cs_etm_decoder *decoder, } static ocsd_datapath_resp_t -cs_etm_decoder__buffer_discontinuity(struct cs_etm_decoder *decoder, - const uint8_t trace_chan_id) +cs_etm_decoder__buffer_discontinuity(struct cs_etm_packet_queue *queue, + const uint8_t trace_chan_id) { - return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + return cs_etm_decoder__buffer_packet(queue, trace_chan_id, CS_ETM_DISCONTINUITY); } static ocsd_datapath_resp_t -cs_etm_decoder__buffer_exception(struct cs_etm_decoder *decoder, +cs_etm_decoder__buffer_exception(struct cs_etm_packet_queue *queue, const ocsd_generic_trace_elem *elem, const uint8_t trace_chan_id) { int ret = 0; struct cs_etm_packet *packet; - ret = cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + ret = cs_etm_decoder__buffer_packet(queue, trace_chan_id, CS_ETM_EXCEPTION); if (ret != OCSD_RESP_CONT && ret != OCSD_RESP_WAIT) return ret; - packet = &decoder->packet_buffer[decoder->tail]; + packet = &queue->packet_buffer[queue->tail]; packet->exception_number = elem->exception_number; return ret; } static ocsd_datapath_resp_t -cs_etm_decoder__buffer_exception_ret(struct cs_etm_decoder *decoder, +cs_etm_decoder__buffer_exception_ret(struct cs_etm_packet_queue *queue, const uint8_t trace_chan_id) { - return cs_etm_decoder__buffer_packet(decoder, trace_chan_id, + return cs_etm_decoder__buffer_packet(queue, trace_chan_id, CS_ETM_EXCEPTION_RET); } @@ -441,6 +410,13 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( { ocsd_datapath_resp_t resp = OCSD_RESP_CONT; struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context; + struct cs_etm_queue *etmq = decoder->data; + struct cs_etm_packet_queue *packet_queue; + + /* First get the packet queue */ + packet_queue = cs_etm__etmq_get_packet_queue(etmq); + if (!packet_queue) + return OCSD_RESP_FATAL_SYS_ERR; switch (elem->elem_type) { case OCSD_GEN_TRC_ELEM_UNKNOWN: @@ -448,19 +424,19 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( case OCSD_GEN_TRC_ELEM_EO_TRACE: case OCSD_GEN_TRC_ELEM_NO_SYNC: case OCSD_GEN_TRC_ELEM_TRACE_ON: - resp = cs_etm_decoder__buffer_discontinuity(decoder, + resp = cs_etm_decoder__buffer_discontinuity(packet_queue, trace_chan_id); break; case OCSD_GEN_TRC_ELEM_INSTR_RANGE: - resp = cs_etm_decoder__buffer_range(decoder, elem, + resp = cs_etm_decoder__buffer_range(packet_queue, elem, trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION: - resp = cs_etm_decoder__buffer_exception(decoder, elem, + resp = cs_etm_decoder__buffer_exception(packet_queue, elem, trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION_RET: - resp = cs_etm_decoder__buffer_exception_ret(decoder, + resp = cs_etm_decoder__buffer_exception_ret(packet_queue, trace_chan_id); break; case OCSD_GEN_TRC_ELEM_PE_CONTEXT: @@ -554,7 +530,6 @@ cs_etm_decoder__new(int num_cpu, struct cs_etm_decoder_params *d_params, decoder->data = d_params->data; decoder->prev_return = OCSD_RESP_CONT; - cs_etm_decoder__clear_buffer(decoder); format = (d_params->formatted ? OCSD_TRC_SRC_FRAME_FORMATTED : OCSD_TRC_SRC_SINGLE); flags = 0; diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h index 3ab11dfa92ae..6ae7ab4cf5fe 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -14,38 +14,8 @@ #include struct cs_etm_decoder; - -enum cs_etm_sample_type { - CS_ETM_EMPTY, - CS_ETM_RANGE, - CS_ETM_DISCONTINUITY, - CS_ETM_EXCEPTION, - CS_ETM_EXCEPTION_RET, -}; - -enum cs_etm_isa { - CS_ETM_ISA_UNKNOWN, - CS_ETM_ISA_A64, - CS_ETM_ISA_A32, - CS_ETM_ISA_T32, -}; - -struct cs_etm_packet { - enum cs_etm_sample_type sample_type; - enum cs_etm_isa isa; - u64 start_addr; - u64 end_addr; - u32 instr_count; - u32 last_instr_type; - u32 last_instr_subtype; - u32 flags; - u32 exception_number; - u8 last_instr_cond; - u8 last_instr_taken_branch; - u8 last_instr_size; - u8 trace_chan_id; - int cpu; -}; +struct cs_etm_packet; +struct cs_etm_packet_queue; struct cs_etm_queue; @@ -119,7 +89,7 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder, u64 start, u64 end, cs_etm_mem_cb_type cb_func); -int cs_etm_decoder__get_packet(struct cs_etm_decoder *decoder, +int cs_etm_decoder__get_packet(struct cs_etm_packet_queue *packet_queue, struct cs_etm_packet *packet); int cs_etm_decoder__reset(struct cs_etm_decoder *decoder); diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 5322dcaaf654..a74c53a45839 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -78,6 +78,7 @@ struct cs_etm_queue { struct cs_etm_packet *packet; const unsigned char *buf; size_t buf_len, buf_used; + struct cs_etm_packet_queue packet_queue; }; static int cs_etm__update_queues(struct cs_etm_auxtrace *etm); @@ -125,6 +126,36 @@ int cs_etm__get_cpu(u8 trace_chan_id, int *cpu) return 0; } +static void cs_etm__clear_packet_queue(struct cs_etm_packet_queue *queue) +{ + int i; + + queue->head = 0; + queue->tail = 0; + queue->packet_count = 0; + for (i = 0; i < CS_ETM_PACKET_MAX_BUFFER; i++) { + queue->packet_buffer[i].isa = CS_ETM_ISA_UNKNOWN; + queue->packet_buffer[i].start_addr = CS_ETM_INVAL_ADDR; + queue->packet_buffer[i].end_addr = CS_ETM_INVAL_ADDR; + queue->packet_buffer[i].instr_count = 0; + queue->packet_buffer[i].last_instr_taken_branch = false; + queue->packet_buffer[i].last_instr_size = 0; + queue->packet_buffer[i].last_instr_type = 0; + queue->packet_buffer[i].last_instr_subtype = 0; + queue->packet_buffer[i].last_instr_cond = 0; + queue->packet_buffer[i].flags = 0; + queue->packet_buffer[i].exception_number = UINT32_MAX; + queue->packet_buffer[i].trace_chan_id = UINT8_MAX; + queue->packet_buffer[i].cpu = INT_MIN; + } +} + +struct cs_etm_packet_queue +*cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq) +{ + return &etmq->packet_queue; +} + static void cs_etm__packet_dump(const char *pkt_string) { const char *color = PERF_COLOR_BLUE; @@ -513,6 +544,7 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, etmq->pid = -1; etmq->offset = 0; etmq->period_instructions = 0; + cs_etm__clear_packet_queue(&etmq->packet_queue); out: return ret; @@ -1542,10 +1574,13 @@ static int cs_etm__decode_data_block(struct cs_etm_queue *etmq) static int cs_etm__process_decoder_queue(struct cs_etm_queue *etmq) { int ret; + struct cs_etm_packet_queue *packet_queue; + + packet_queue = cs_etm__etmq_get_packet_queue(etmq); /* Process each packet in this chunk */ while (1) { - ret = cs_etm_decoder__get_packet(etmq->decoder, + ret = cs_etm_decoder__get_packet(packet_queue, etmq->packet); if (ret <= 0) /* diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 826c9eedaf5c..75385e2fd283 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -97,12 +97,57 @@ enum { CS_ETMV4_EXC_END = 31, }; +enum cs_etm_sample_type { + CS_ETM_EMPTY, + CS_ETM_RANGE, + CS_ETM_DISCONTINUITY, + CS_ETM_EXCEPTION, + CS_ETM_EXCEPTION_RET, +}; + +enum cs_etm_isa { + CS_ETM_ISA_UNKNOWN, + CS_ETM_ISA_A64, + CS_ETM_ISA_A32, + CS_ETM_ISA_T32, +}; + /* RB tree for quick conversion between traceID and metadata pointers */ struct intlist *traceid_list; +struct cs_etm_queue; + +struct cs_etm_packet { + enum cs_etm_sample_type sample_type; + enum cs_etm_isa isa; + u64 start_addr; + u64 end_addr; + u32 instr_count; + u32 last_instr_type; + u32 last_instr_subtype; + u32 flags; + u32 exception_number; + u8 last_instr_cond; + u8 last_instr_taken_branch; + u8 last_instr_size; + u8 trace_chan_id; + int cpu; +}; + +#define CS_ETM_PACKET_MAX_BUFFER 1024 + +struct cs_etm_packet_queue { + u32 packet_count; + u32 head; + u32 tail; + struct cs_etm_packet packet_buffer[CS_ETM_PACKET_MAX_BUFFER]; +}; + #define KiB(x) ((x) * 1024) #define MiB(x) ((x) * 1024 * 1024) +#define CS_ETM_INVAL_ADDR 0xdeadbeefdeadbeefUL + /* * Create a contiguous bitmask starting at bit position @l and ending at * position @h. For example @@ -126,6 +171,8 @@ struct intlist *traceid_list; int cs_etm__process_auxtrace_info(union perf_event *event, struct perf_session *session); int cs_etm__get_cpu(u8 trace_chan_id, int *cpu); +struct cs_etm_packet_queue +*cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq); #else static inline int cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, @@ -139,6 +186,12 @@ static inline int cs_etm__get_cpu(u8 trace_chan_id __maybe_unused, { return -1; } + +static inline struct cs_etm_packet_queue *cs_etm__etmq_get_packet_queue( + struct cs_etm_queue *etmq __maybe_unused) +{ + return NULL; +} #endif #endif From patchwork Fri May 24 17:34:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165147 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3885270ili; Fri, 24 May 2019 10:35:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxza4ijdebuXgFWSiSq2eoC2KlmNW8ovkOs3OnB6Mt7ozPnQRiWZrI9ieemB8SpgKbfTgJn X-Received: by 2002:aa7:8683:: with SMTP id d3mr68615675pfo.145.1558719324829; Fri, 24 May 2019 10:35:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719324; cv=none; d=google.com; s=arc-20160816; b=tZ20i9IrRpcgXEB8Gs74X2zFBuwQaQqJ4MAf/O1pN5H+DFMTVWxD7nLFS8H6FE8hjh L3rGSOx6Q7hxFpF3oRRcNyQrEFDIUamd2QpA+mZioboWs5DF570bbsfZ24r7PscAiOMk vnd24AHRbLeqEN8oWU6TlURtI9as9SbweCOsdeueJnZJI3/AH0OgwDQdC94Dww2OaDUB nyul7JZ7rw4L4H0ppqcFCasZLW5odp63KJ5rfP/IjTtR2eFYznQyGqTVGrMX5Zx6clH7 5X1zJ9u2AZFtk12yxpOym2Kree1t6fnS2Zrl+qg54X1TCgdHa6c/CuPYe2LmJ2+JSXJb WI2Q== 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; bh=7YTfrf6ViED9PHS/WoXTw1GGLuSsLDg5zA9R4pOhAT0=; b=gp5VM0Riz4LiafKj/NL8H9a9E8O3tbyZsImPAzW6fqpukYpvTVG6uHSCTejRnrCHa0 jVWTsnzPRT66VIilNv11Mlao705hB66oIFIFie8RSPrAaArmoCn88NIt9c8eOWkAIUXl rsWocQpPToWCZ88oLlUSu7V3tZRGg9gXluY5IWtuuhvShrHTO1ZabjgmHJSdRaT1Pk/7 RjCIyqcXD3aoUbEcwV9CmSvldBz3mFr0dLNPk8Wb3egm4S/Skau304XH91hz9ORV2Jcx lWHYH2z+75B5Bb0mUJS763vtw/IO+ykNhQsYBJVPCjH/r0+3PCp5uYXeo1TwVSBZylBa nt9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m9E8LQQ0; 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 f17si5078321pgv.338.2019.05.24.10.35.24; Fri, 24 May 2019 10:35:24 -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=m9E8LQQ0; 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 S2391707AbfEXRfX (ORCPT + 30 others); Fri, 24 May 2019 13:35:23 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39119 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391665AbfEXRfV (ORCPT ); Fri, 24 May 2019 13:35:21 -0400 Received: by mail-pf1-f194.google.com with SMTP id z26so5725610pfg.6 for ; Fri, 24 May 2019 10:35:20 -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=7YTfrf6ViED9PHS/WoXTw1GGLuSsLDg5zA9R4pOhAT0=; b=m9E8LQQ0ybYokosZ3FSWl1NYHaoqKBGO55JdtR6b2j3oJPAh2zWI/+9SV+B04nUOmw uFYT4ipZZ6J4Rm3Vly6dQxTffTpuUeitYvmKsjHeXGqajJvyeQTRtmo9IssPppm6kxrR JQ951ByVITyZUq/x2q6BWNBukN9XTjUCFiA2pr/+KbWsZ3p5qQK2f4resF+5uEN1ASS+ Txv8DMke5Wiio4bPoYD5syR2CWeEX2VvAKnVQOu9ATh7KZNnoigkP20IU//nVD76sQ0I vg1txyvZrw4Zsl9BiwrFWCTi+w2yJx4fzmllJiZBakHyC+XFLlD3UiqBARB2cN3T+bQS RvLg== 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=7YTfrf6ViED9PHS/WoXTw1GGLuSsLDg5zA9R4pOhAT0=; b=CY1z9Szu9mqtCDmTFFQjdDiSBsz29wpNSVKNyS+yxrJ2K4ZAQhJfiuC/zTsh93Kak6 bDjhFNDtPktBdp8EOQjOVEojyBvcMoDQZ+mTJsjTwr6cEBBLUYTs+nWteYMYgCm/KNng gF9/K5wDQ2Ch/hLzrYxudlavsPivLjDqEQqU6u5WKtXhgTMAd4XNiBPHaC9QLeYIxPsK uaKSyH9GQE/tbCE4u8SfYOCYaGweUoUi9XrFft/XJDWK3Iiv5SLrnh5ige8tvaP4RKy7 sWae09DqjKUzLFqEHbg7w94V6MLwzsnrjRGGiygwPPiGOOo2fm6AsoDXzyX9XLjTNUjj SLZg== X-Gm-Message-State: APjAAAVs3hXzk4NHYTuwZ0JJNJlKbsDWtQyOwi8IvFgXU2eb80J5BhWA yB4XoeEKc8W1TjZ2ISguAF4Y0Q== X-Received: by 2002:a17:90a:1a84:: with SMTP id p4mr11101867pjp.15.1558719320267; Fri, 24 May 2019 10:35:20 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:19 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 08/17] perf tools: Fix indentation in function cs_etm__process_decoder_queue() Date: Fri, 24 May 2019 11:34:59 -0600 Message-Id: <20190524173508.29044-9-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fixing wrong indentation of the while() loop - no change of functionality. Fixes: 3fa0e83e2948 ("perf cs-etm: Modularize main packet processing loop") Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 108 +++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 54 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index a74c53a45839..68fec6f019fe 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1578,64 +1578,64 @@ static int cs_etm__process_decoder_queue(struct cs_etm_queue *etmq) packet_queue = cs_etm__etmq_get_packet_queue(etmq); - /* Process each packet in this chunk */ - while (1) { - ret = cs_etm_decoder__get_packet(packet_queue, - etmq->packet); - if (ret <= 0) - /* - * Stop processing this chunk on - * end of data or error - */ - break; + /* Process each packet in this chunk */ + while (1) { + ret = cs_etm_decoder__get_packet(packet_queue, + etmq->packet); + if (ret <= 0) + /* + * Stop processing this chunk on + * end of data or error + */ + break; + + /* + * Since packet addresses are swapped in packet + * handling within below switch() statements, + * thus setting sample flags must be called + * prior to switch() statement to use address + * information before packets swapping. + */ + ret = cs_etm__set_sample_flags(etmq); + if (ret < 0) + break; + switch (etmq->packet->sample_type) { + case CS_ETM_RANGE: /* - * Since packet addresses are swapped in packet - * handling within below switch() statements, - * thus setting sample flags must be called - * prior to switch() statement to use address - * information before packets swapping. + * If the packet contains an instruction + * range, generate instruction sequence + * events. */ - ret = cs_etm__set_sample_flags(etmq); - if (ret < 0) - break; - - switch (etmq->packet->sample_type) { - case CS_ETM_RANGE: - /* - * If the packet contains an instruction - * range, generate instruction sequence - * events. - */ - cs_etm__sample(etmq); - break; - case CS_ETM_EXCEPTION: - case CS_ETM_EXCEPTION_RET: - /* - * If the exception packet is coming, - * make sure the previous instruction - * range packet to be handled properly. - */ - cs_etm__exception(etmq); - break; - case CS_ETM_DISCONTINUITY: - /* - * Discontinuity in trace, flush - * previous branch stack - */ - cs_etm__flush(etmq); - break; - case CS_ETM_EMPTY: - /* - * Should not receive empty packet, - * report error. - */ - pr_err("CS ETM Trace: empty packet\n"); - return -EINVAL; - default: - break; - } + cs_etm__sample(etmq); + break; + case CS_ETM_EXCEPTION: + case CS_ETM_EXCEPTION_RET: + /* + * If the exception packet is coming, + * make sure the previous instruction + * range packet to be handled properly. + */ + cs_etm__exception(etmq); + break; + case CS_ETM_DISCONTINUITY: + /* + * Discontinuity in trace, flush + * previous branch stack + */ + cs_etm__flush(etmq); + break; + case CS_ETM_EMPTY: + /* + * Should not receive empty packet, + * report error. + */ + pr_err("CS ETM Trace: empty packet\n"); + return -EINVAL; + default: + break; } + } return ret; } From patchwork Fri May 24 17:35:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165156 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3886196ili; Fri, 24 May 2019 10:36:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/Y86eU2OQ6FqJT7aSKWlbn5oM67Pehdxi5JC2Cpb+ADAPdgUxzuHfVnhf7y+cBVLYKgLC X-Received: by 2002:aa7:96ec:: with SMTP id i12mr101410654pfq.82.1558719375105; Fri, 24 May 2019 10:36:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719375; cv=none; d=google.com; s=arc-20160816; b=xXKVpt6z6khKpx7uBEd3nLGP+YoxL333/yd5AcvyRELi7baw6RJ4n2Vnb5iDhxjNcD jUDU2l2Q8d3FEXwZWPAwDKyr7B5b4dP5TaiRKcJNsrb+32IXExAtGc2QphvkVwc28D1A SbAXlZE6vC5bjUfaiQ62Y0UTyshtwhobATiykNnjZTVTUiRbEx4TYJIPmsIok8a5Vj4E BBQ5pDU+7zoCup3QGB7sGyBIoLgDQFlEn1iaEFBTvVDdB+nP5fH8dgDq3T/e0HcaswWz FUdJsc1qwj3zs22pz1YZhkQMEXatqN29KrWaH2d9A30WCGTDaQON7nSMPIBxPJaWn9I2 m5tQ== 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; bh=rRUHT6Wkk0DrFLANuTkLpa+nJ1yBGRvRL/7DBxuJ6/8=; b=SsbBuo4tcAiSy+JUL6adSsUBFfv3NJaZ32Yx6KnH20yelno5asMJ/GtWXNKGos2z10 sfBiNnUdqfGeJg+8Yz4l8Mrl3FyFfxv5kFtSG5GHR5ic1/R/7DzjfYLw1tXfqK9e/lmN nXEYgu/7EDxKA0j2nia2EAkT3VI6QaGJlXfhR84BdqoTCXwHegNBXKBGzwJ8Kxj84k7Q nZTugnq4hDulx95Tq7Aql87OqW/bJzEQIGki2QC0lexammKvm2i/PzKuFDTIrwsJNd6E C0x7AvrJq0s7Anxxpi5fKlCHSDPstme/U2NuBWq28Erny2CmQvfEsKlbU8FWTzIemsMh edRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NOAjVq7d; 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 w187si5475698pfw.221.2019.05.24.10.36.14; Fri, 24 May 2019 10:36:15 -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=NOAjVq7d; 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 S2391742AbfEXRgO (ORCPT + 30 others); Fri, 24 May 2019 13:36:14 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46365 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391693AbfEXRfX (ORCPT ); Fri, 24 May 2019 13:35:23 -0400 Received: by mail-pf1-f194.google.com with SMTP id y11so872215pfm.13 for ; Fri, 24 May 2019 10:35:22 -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=rRUHT6Wkk0DrFLANuTkLpa+nJ1yBGRvRL/7DBxuJ6/8=; b=NOAjVq7dgoF+1IETcFuY26kCJTNpagGmLET4Rhb51prOseBJpAb+UjxSD/riJ0/e5p u/6aoRHeP7JVk/c5nEXWpW+OJ/FFv048ELSrTS9M7MnzzLFApXtU/Eh+24niVYG6VAKK zjYagiseYYY2mvdes2j6HvKb8mJwZAyzrfeDV+f0UY4spNh0wTxU9HHdhfwxC5gdTzMq WukZot3C07E0Hs5LxCh1JUY3bXTIARkXzQXAOV5y7XrtdQTNpB3vScVZV0jZ4UYilWjK hSYXXY+RkVcPW1eQjdA1SOaMIfMPrfZlKM/vIV/bSg0SAOhR5kRQ99INL3bc9Qo7gmg0 mjWw== 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=rRUHT6Wkk0DrFLANuTkLpa+nJ1yBGRvRL/7DBxuJ6/8=; b=XZb0Gxw8PweIk0z/8u80nn42ugudkerKH5gjDrMsKyfUPyp9DYu1eLUpksGiB15oA4 dHPKHaTXRUafVh4GhpekVtZ9dk7Sldi5TvtEMI3v+AeOBtDCTsWdRbpkG7E7cMpX/nBY w9+5nDVfgdaWDGkCeNqcO0AI8/Zxse0vnschBQeqrEgS9gV4vjojTkwPcX6sVvUzkxCz i7zDhGKMzSf7H4474Df1POs9iSUuMOEtcQFFlFsaePwRnUYMLtvDkv5pcbtuOwu0ngJ9 y++rlPvLzVwk5i6i/bBxtn0AOW1CqcHda64iz6BQzT5LL8Bg5NVwIeyeqPbdnI3w0srF ttGQ== X-Gm-Message-State: APjAAAWC0WgpXJoPWaqwg3HcCQnidLxRr4CDRoZCF2Bs+EBYxmZL+YIr AXsINg328Vsd9qBma/Mv66vzyA== X-Received: by 2002:a17:90a:fa09:: with SMTP id cm9mr10772033pjb.137.1558719321669; Fri, 24 May 2019 10:35:21 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:21 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 09/17] perf tools: Introduce the concept of trace ID queues Date: Fri, 24 May 2019 11:35:00 -0600 Message-Id: <20190524173508.29044-10-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In an ideal world there is one CPU per cs_etm_queue and as such, one trace ID per cs_etm_queue. In the real world CoreSight topologies allow multiple CPUs to use the same sink, which translates to multiple trace IDs per cs_etm_queue. To deal with this a new cs_etm_traceid_queue structure is introduced to enclose all the information related to a single trace ID, allowing a cs_etm_queue to handle traces generated by any number of CPUs. Signed-off-by: Mathieu Poirier --- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 4 +- tools/perf/util/cs-etm.c | 360 +++++++++++------- tools/perf/util/cs-etm.h | 15 +- 3 files changed, 234 insertions(+), 145 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index 3ac238e58901..4303d2d00d31 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -413,8 +413,8 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( struct cs_etm_queue *etmq = decoder->data; struct cs_etm_packet_queue *packet_queue; - /* First get the packet queue */ - packet_queue = cs_etm__etmq_get_packet_queue(etmq); + /* First get the packet queue for this traceID */ + packet_queue = cs_etm__etmq_get_packet_queue(etmq, trace_chan_id); if (!packet_queue) return OCSD_RESP_FATAL_SYS_ERR; diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 68fec6f019fe..9e8212c74055 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -60,25 +60,30 @@ struct cs_etm_auxtrace { unsigned int pmu_type; }; +struct cs_etm_traceid_queue { + u8 trace_chan_id; + u64 period_instructions; + size_t last_branch_pos; + union perf_event *event_buf; + struct branch_stack *last_branch; + struct branch_stack *last_branch_rb; + struct cs_etm_packet *prev_packet; + struct cs_etm_packet *packet; + struct cs_etm_packet_queue packet_queue; +}; + struct cs_etm_queue { struct cs_etm_auxtrace *etm; struct thread *thread; struct cs_etm_decoder *decoder; struct auxtrace_buffer *buffer; - union perf_event *event_buf; unsigned int queue_nr; pid_t pid, tid; int cpu; u64 offset; - u64 period_instructions; - struct branch_stack *last_branch; - struct branch_stack *last_branch_rb; - size_t last_branch_pos; - struct cs_etm_packet *prev_packet; - struct cs_etm_packet *packet; const unsigned char *buf; size_t buf_len, buf_used; - struct cs_etm_packet_queue packet_queue; + struct cs_etm_traceid_queue *traceid_queues; }; static int cs_etm__update_queues(struct cs_etm_auxtrace *etm); @@ -150,10 +155,96 @@ static void cs_etm__clear_packet_queue(struct cs_etm_packet_queue *queue) } } +static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq, + u8 trace_chan_id) +{ + int rc = -ENOMEM; + struct cs_etm_auxtrace *etm = etmq->etm; + + cs_etm__clear_packet_queue(&tidq->packet_queue); + + tidq->trace_chan_id = trace_chan_id; + + tidq->packet = zalloc(sizeof(struct cs_etm_packet)); + if (!tidq->packet) + goto out; + + tidq->prev_packet = zalloc(sizeof(struct cs_etm_packet)); + if (!tidq->prev_packet) + goto out_free; + + if (etm->synth_opts.last_branch) { + size_t sz = sizeof(struct branch_stack); + + sz += etm->synth_opts.last_branch_sz * + sizeof(struct branch_entry); + tidq->last_branch = zalloc(sz); + if (!tidq->last_branch) + goto out_free; + tidq->last_branch_rb = zalloc(sz); + if (!tidq->last_branch_rb) + goto out_free; + } + + tidq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE); + if (!tidq->event_buf) + goto out_free; + + return 0; + +out_free: + zfree(&tidq->last_branch_rb); + zfree(&tidq->last_branch); + zfree(&tidq->prev_packet); + zfree(&tidq->packet); +out: + return rc; +} + +static struct cs_etm_traceid_queue +*cs_etm__etmq_get_traceid_queue(struct cs_etm_queue *etmq, u8 trace_chan_id) +{ + struct cs_etm_traceid_queue *tidq; + struct cs_etm_auxtrace *etm = etmq->etm; + + if (!etm->timeless_decoding) + return NULL; + + tidq = etmq->traceid_queues; + + if (tidq) + return tidq; + + tidq = malloc(sizeof(*tidq)); + if (!tidq) + return NULL; + + memset(tidq, 0, sizeof(*tidq)); + + if (cs_etm__init_traceid_queue(etmq, tidq, trace_chan_id)) + goto out_free; + + etmq->traceid_queues = tidq; + + return etmq->traceid_queues; + +out_free: + free(tidq); + + return NULL; +} + struct cs_etm_packet_queue -*cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq) +*cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id) { - return &etmq->packet_queue; + struct cs_etm_traceid_queue *tidq; + + tidq = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id); + if (tidq) + return &tidq->packet_queue; + + return NULL; } static void cs_etm__packet_dump(const char *pkt_string) @@ -327,11 +418,12 @@ static void cs_etm__free_queue(void *priv) thread__zput(etmq->thread); cs_etm_decoder__free(etmq->decoder); - zfree(&etmq->event_buf); - zfree(&etmq->last_branch); - zfree(&etmq->last_branch_rb); - zfree(&etmq->prev_packet); - zfree(&etmq->packet); + zfree(&etmq->traceid_queues->event_buf); + zfree(&etmq->traceid_queues->last_branch); + zfree(&etmq->traceid_queues->last_branch_rb); + zfree(&etmq->traceid_queues->prev_packet); + zfree(&etmq->traceid_queues->packet); + zfree(&etmq->traceid_queues); free(etmq); } @@ -443,37 +535,11 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm) struct cs_etm_decoder_params d_params; struct cs_etm_trace_params *t_params = NULL; struct cs_etm_queue *etmq; - size_t szp = sizeof(struct cs_etm_packet); etmq = zalloc(sizeof(*etmq)); if (!etmq) return NULL; - etmq->packet = zalloc(szp); - if (!etmq->packet) - goto out_free; - - etmq->prev_packet = zalloc(szp); - if (!etmq->prev_packet) - goto out_free; - - if (etm->synth_opts.last_branch) { - size_t sz = sizeof(struct branch_stack); - - sz += etm->synth_opts.last_branch_sz * - sizeof(struct branch_entry); - etmq->last_branch = zalloc(sz); - if (!etmq->last_branch) - goto out_free; - etmq->last_branch_rb = zalloc(sz); - if (!etmq->last_branch_rb) - goto out_free; - } - - etmq->event_buf = malloc(PERF_SAMPLE_MAX_SIZE); - if (!etmq->event_buf) - goto out_free; - /* Use metadata to fill in trace parameters for trace decoder */ t_params = zalloc(sizeof(*t_params) * etm->num_cpu); @@ -508,12 +574,6 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm) out_free_decoder: cs_etm_decoder__free(etmq->decoder); out_free: - zfree(&t_params); - zfree(&etmq->event_buf); - zfree(&etmq->last_branch); - zfree(&etmq->last_branch_rb); - zfree(&etmq->prev_packet); - zfree(&etmq->packet); free(etmq); return NULL; @@ -543,8 +603,6 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, etmq->tid = queue->tid; etmq->pid = -1; etmq->offset = 0; - etmq->period_instructions = 0; - cs_etm__clear_packet_queue(&etmq->packet_queue); out: return ret; @@ -577,10 +635,12 @@ static int cs_etm__update_queues(struct cs_etm_auxtrace *etm) return 0; } -static inline void cs_etm__copy_last_branch_rb(struct cs_etm_queue *etmq) +static inline +void cs_etm__copy_last_branch_rb(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq) { - struct branch_stack *bs_src = etmq->last_branch_rb; - struct branch_stack *bs_dst = etmq->last_branch; + struct branch_stack *bs_src = tidq->last_branch_rb; + struct branch_stack *bs_dst = tidq->last_branch; size_t nr = 0; /* @@ -600,9 +660,9 @@ static inline void cs_etm__copy_last_branch_rb(struct cs_etm_queue *etmq) * two steps. First, copy the branches from the most recently inserted * branch ->last_branch_pos until the end of bs_src->entries buffer. */ - nr = etmq->etm->synth_opts.last_branch_sz - etmq->last_branch_pos; + nr = etmq->etm->synth_opts.last_branch_sz - tidq->last_branch_pos; memcpy(&bs_dst->entries[0], - &bs_src->entries[etmq->last_branch_pos], + &bs_src->entries[tidq->last_branch_pos], sizeof(struct branch_entry) * nr); /* @@ -615,14 +675,15 @@ static inline void cs_etm__copy_last_branch_rb(struct cs_etm_queue *etmq) if (bs_src->nr >= etmq->etm->synth_opts.last_branch_sz) { memcpy(&bs_dst->entries[nr], &bs_src->entries[0], - sizeof(struct branch_entry) * etmq->last_branch_pos); + sizeof(struct branch_entry) * tidq->last_branch_pos); } } -static inline void cs_etm__reset_last_branch_rb(struct cs_etm_queue *etmq) +static inline +void cs_etm__reset_last_branch_rb(struct cs_etm_traceid_queue *tidq) { - etmq->last_branch_pos = 0; - etmq->last_branch_rb->nr = 0; + tidq->last_branch_pos = 0; + tidq->last_branch_rb->nr = 0; } static inline int cs_etm__t32_instr_size(struct cs_etm_queue *etmq, @@ -675,9 +736,10 @@ static inline u64 cs_etm__instr_addr(struct cs_etm_queue *etmq, return packet->start_addr + offset * 4; } -static void cs_etm__update_last_branch_rb(struct cs_etm_queue *etmq) +static void cs_etm__update_last_branch_rb(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq) { - struct branch_stack *bs = etmq->last_branch_rb; + struct branch_stack *bs = tidq->last_branch_rb; struct branch_entry *be; /* @@ -686,14 +748,14 @@ static void cs_etm__update_last_branch_rb(struct cs_etm_queue *etmq) * buffer down. After writing the first element of the stack, move the * insert position back to the end of the buffer. */ - if (!etmq->last_branch_pos) - etmq->last_branch_pos = etmq->etm->synth_opts.last_branch_sz; + if (!tidq->last_branch_pos) + tidq->last_branch_pos = etmq->etm->synth_opts.last_branch_sz; - etmq->last_branch_pos -= 1; + tidq->last_branch_pos -= 1; - be = &bs->entries[etmq->last_branch_pos]; - be->from = cs_etm__last_executed_instr(etmq->prev_packet); - be->to = cs_etm__first_executed_instr(etmq->packet); + be = &bs->entries[tidq->last_branch_pos]; + be->from = cs_etm__last_executed_instr(tidq->prev_packet); + be->to = cs_etm__first_executed_instr(tidq->packet); /* No support for mispredict */ be->flags.mispred = 0; be->flags.predicted = 1; @@ -777,11 +839,12 @@ static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm, } static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq, u64 addr, u64 period) { int ret = 0; struct cs_etm_auxtrace *etm = etmq->etm; - union perf_event *event = etmq->event_buf; + union perf_event *event = tidq->event_buf; struct perf_sample sample = {.ip = 0,}; event->sample.header.type = PERF_RECORD_SAMPLE; @@ -794,14 +857,14 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, sample.id = etmq->etm->instructions_id; sample.stream_id = etmq->etm->instructions_id; sample.period = period; - sample.cpu = etmq->packet->cpu; - sample.flags = etmq->prev_packet->flags; + sample.cpu = tidq->packet->cpu; + sample.flags = tidq->prev_packet->flags; sample.insn_len = 1; sample.cpumode = event->sample.header.misc; if (etm->synth_opts.last_branch) { - cs_etm__copy_last_branch_rb(etmq); - sample.branch_stack = etmq->last_branch; + cs_etm__copy_last_branch_rb(etmq, tidq); + sample.branch_stack = tidq->last_branch; } if (etm->synth_opts.inject) { @@ -819,7 +882,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, ret); if (etm->synth_opts.last_branch) - cs_etm__reset_last_branch_rb(etmq); + cs_etm__reset_last_branch_rb(tidq); return ret; } @@ -828,19 +891,20 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, * 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) +static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq) { int ret = 0; struct cs_etm_auxtrace *etm = etmq->etm; struct perf_sample sample = {.ip = 0,}; - union perf_event *event = etmq->event_buf; + union perf_event *event = tidq->event_buf; struct dummy_branch_stack { u64 nr; struct branch_entry entries; } dummy_bs; u64 ip; - ip = cs_etm__last_executed_instr(etmq->prev_packet); + ip = cs_etm__last_executed_instr(tidq->prev_packet); event->sample.header.type = PERF_RECORD_SAMPLE; event->sample.header.misc = cs_etm__cpu_mode(etmq, ip); @@ -849,12 +913,12 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq) sample.ip = ip; sample.pid = etmq->pid; sample.tid = etmq->tid; - sample.addr = cs_etm__first_executed_instr(etmq->packet); + sample.addr = cs_etm__first_executed_instr(tidq->packet); sample.id = etmq->etm->branches_id; sample.stream_id = etmq->etm->branches_id; sample.period = 1; - sample.cpu = etmq->packet->cpu; - sample.flags = etmq->prev_packet->flags; + sample.cpu = tidq->packet->cpu; + sample.flags = tidq->prev_packet->flags; sample.cpumode = event->sample.header.misc; /* @@ -997,33 +1061,34 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm, return 0; } -static int cs_etm__sample(struct cs_etm_queue *etmq) +static int cs_etm__sample(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq) { struct cs_etm_auxtrace *etm = etmq->etm; struct cs_etm_packet *tmp; int ret; - u64 instrs_executed = etmq->packet->instr_count; + u64 instrs_executed = tidq->packet->instr_count; - etmq->period_instructions += instrs_executed; + tidq->period_instructions += instrs_executed; /* * Record a branch when the last instruction in * PREV_PACKET is a branch. */ if (etm->synth_opts.last_branch && - etmq->prev_packet->sample_type == CS_ETM_RANGE && - etmq->prev_packet->last_instr_taken_branch) - cs_etm__update_last_branch_rb(etmq); + tidq->prev_packet->sample_type == CS_ETM_RANGE && + tidq->prev_packet->last_instr_taken_branch) + cs_etm__update_last_branch_rb(etmq, tidq); if (etm->sample_instructions && - etmq->period_instructions >= etm->instructions_sample_period) { + tidq->period_instructions >= etm->instructions_sample_period) { /* * Emit instruction sample periodically * TODO: allow period to be defined in cycles and clock time */ /* Get number of instructions executed after the sample point */ - u64 instrs_over = etmq->period_instructions - + u64 instrs_over = tidq->period_instructions - etm->instructions_sample_period; /* @@ -1032,31 +1097,31 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) * executed, but PC has not advanced to next instruction) */ u64 offset = (instrs_executed - instrs_over - 1); - u64 addr = cs_etm__instr_addr(etmq, etmq->packet, offset); + u64 addr = cs_etm__instr_addr(etmq, tidq->packet, offset); ret = cs_etm__synth_instruction_sample( - etmq, addr, etm->instructions_sample_period); + etmq, tidq, addr, etm->instructions_sample_period); if (ret) return ret; /* Carry remaining instructions into next sample period */ - etmq->period_instructions = instrs_over; + tidq->period_instructions = instrs_over; } if (etm->sample_branches) { bool generate_sample = false; /* Generate sample for tracing on packet */ - if (etmq->prev_packet->sample_type == CS_ETM_DISCONTINUITY) + if (tidq->prev_packet->sample_type == CS_ETM_DISCONTINUITY) generate_sample = true; /* Generate sample for branch taken packet */ - if (etmq->prev_packet->sample_type == CS_ETM_RANGE && - etmq->prev_packet->last_instr_taken_branch) + if (tidq->prev_packet->sample_type == CS_ETM_RANGE && + tidq->prev_packet->last_instr_taken_branch) generate_sample = true; if (generate_sample) { - ret = cs_etm__synth_branch_sample(etmq); + ret = cs_etm__synth_branch_sample(etmq, tidq); if (ret) return ret; } @@ -1067,15 +1132,15 @@ static int cs_etm__sample(struct cs_etm_queue *etmq) * 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; + tmp = tidq->packet; + tidq->packet = tidq->prev_packet; + tidq->prev_packet = tmp; } return 0; } -static int cs_etm__exception(struct cs_etm_queue *etmq) +static int cs_etm__exception(struct cs_etm_traceid_queue *tidq) { /* * When the exception packet is inserted, whether the last instruction @@ -1088,24 +1153,25 @@ static int cs_etm__exception(struct cs_etm_queue *etmq) * swap PACKET with PREV_PACKET. This keeps PREV_PACKET to be useful * for generating instruction and branch samples. */ - if (etmq->prev_packet->sample_type == CS_ETM_RANGE) - etmq->prev_packet->last_instr_taken_branch = true; + if (tidq->prev_packet->sample_type == CS_ETM_RANGE) + tidq->prev_packet->last_instr_taken_branch = true; return 0; } -static int cs_etm__flush(struct cs_etm_queue *etmq) +static int cs_etm__flush(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq) { int err = 0; struct cs_etm_auxtrace *etm = etmq->etm; struct cs_etm_packet *tmp; /* Handle start tracing packet */ - if (etmq->prev_packet->sample_type == CS_ETM_EMPTY) + if (tidq->prev_packet->sample_type == CS_ETM_EMPTY) goto swap_packet; if (etmq->etm->synth_opts.last_branch && - etmq->prev_packet->sample_type == CS_ETM_RANGE) { + tidq->prev_packet->sample_type == CS_ETM_RANGE) { /* * Generate a last branch event for the branches left in the * circular buffer at the end of the trace. @@ -1113,21 +1179,21 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) * Use the address of the end of the last reported execution * range */ - u64 addr = cs_etm__last_executed_instr(etmq->prev_packet); + u64 addr = cs_etm__last_executed_instr(tidq->prev_packet); err = cs_etm__synth_instruction_sample( - etmq, addr, - etmq->period_instructions); + etmq, tidq, addr, + tidq->period_instructions); if (err) return err; - etmq->period_instructions = 0; + tidq->period_instructions = 0; } if (etm->sample_branches && - etmq->prev_packet->sample_type == CS_ETM_RANGE) { - err = cs_etm__synth_branch_sample(etmq); + tidq->prev_packet->sample_type == CS_ETM_RANGE) { + err = cs_etm__synth_branch_sample(etmq, tidq); if (err) return err; } @@ -1138,15 +1204,16 @@ static int cs_etm__flush(struct cs_etm_queue *etmq) * 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; + tmp = tidq->packet; + tidq->packet = tidq->prev_packet; + tidq->prev_packet = tmp; } return err; } -static int cs_etm__end_block(struct cs_etm_queue *etmq) +static int cs_etm__end_block(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq) { int err; @@ -1160,20 +1227,20 @@ static int cs_etm__end_block(struct cs_etm_queue *etmq) * the trace. */ if (etmq->etm->synth_opts.last_branch && - etmq->prev_packet->sample_type == CS_ETM_RANGE) { + tidq->prev_packet->sample_type == CS_ETM_RANGE) { /* * Use the address of the end of the last reported execution * range. */ - u64 addr = cs_etm__last_executed_instr(etmq->prev_packet); + u64 addr = cs_etm__last_executed_instr(tidq->prev_packet); err = cs_etm__synth_instruction_sample( - etmq, addr, - etmq->period_instructions); + etmq, tidq, addr, + tidq->period_instructions); if (err) return err; - etmq->period_instructions = 0; + tidq->period_instructions = 0; } return 0; @@ -1272,10 +1339,11 @@ static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, return false; } -static bool cs_etm__is_syscall(struct cs_etm_queue *etmq, u64 magic) +static bool cs_etm__is_syscall(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq, u64 magic) { - struct cs_etm_packet *packet = etmq->packet; - struct cs_etm_packet *prev_packet = etmq->prev_packet; + struct cs_etm_packet *packet = tidq->packet; + struct cs_etm_packet *prev_packet = tidq->prev_packet; if (magic == __perf_cs_etmv3_magic) if (packet->exception_number == CS_ETMV3_EXC_SVC) @@ -1296,9 +1364,10 @@ static bool cs_etm__is_syscall(struct cs_etm_queue *etmq, u64 magic) return false; } -static bool cs_etm__is_async_exception(struct cs_etm_queue *etmq, u64 magic) +static bool cs_etm__is_async_exception(struct cs_etm_traceid_queue *tidq, + u64 magic) { - struct cs_etm_packet *packet = etmq->packet; + struct cs_etm_packet *packet = tidq->packet; if (magic == __perf_cs_etmv3_magic) if (packet->exception_number == CS_ETMV3_EXC_DEBUG_HALT || @@ -1321,10 +1390,12 @@ static bool cs_etm__is_async_exception(struct cs_etm_queue *etmq, u64 magic) return false; } -static bool cs_etm__is_sync_exception(struct cs_etm_queue *etmq, u64 magic) +static bool cs_etm__is_sync_exception(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq, + u64 magic) { - struct cs_etm_packet *packet = etmq->packet; - struct cs_etm_packet *prev_packet = etmq->prev_packet; + struct cs_etm_packet *packet = tidq->packet; + struct cs_etm_packet *prev_packet = tidq->prev_packet; if (magic == __perf_cs_etmv3_magic) if (packet->exception_number == CS_ETMV3_EXC_SMC || @@ -1367,10 +1438,11 @@ static bool cs_etm__is_sync_exception(struct cs_etm_queue *etmq, u64 magic) return false; } -static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) +static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq) { - struct cs_etm_packet *packet = etmq->packet; - struct cs_etm_packet *prev_packet = etmq->prev_packet; + struct cs_etm_packet *packet = tidq->packet; + struct cs_etm_packet *prev_packet = tidq->prev_packet; u64 magic; int ret; @@ -1472,7 +1544,7 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) return ret; /* The exception is for system call. */ - if (cs_etm__is_syscall(etmq, magic)) + if (cs_etm__is_syscall(etmq, tidq, magic)) packet->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_SYSCALLRET; @@ -1480,7 +1552,7 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) * The exceptions are triggered by external signals from bus, * interrupt controller, debug module, PE reset or halt. */ - else if (cs_etm__is_async_exception(etmq, magic)) + else if (cs_etm__is_async_exception(tidq, magic)) packet->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | @@ -1489,7 +1561,7 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq) * Otherwise, exception is caused by trap, instruction & * data fault, or alignment errors. */ - else if (cs_etm__is_sync_exception(etmq, magic)) + else if (cs_etm__is_sync_exception(etmq, tidq, magic)) packet->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_CALL | PERF_IP_FLAG_INTERRUPT; @@ -1571,17 +1643,18 @@ static int cs_etm__decode_data_block(struct cs_etm_queue *etmq) return ret; } -static int cs_etm__process_decoder_queue(struct cs_etm_queue *etmq) +static int cs_etm__process_traceid_queue(struct cs_etm_queue *etmq, + struct cs_etm_traceid_queue *tidq) { int ret; struct cs_etm_packet_queue *packet_queue; - packet_queue = cs_etm__etmq_get_packet_queue(etmq); + packet_queue = &tidq->packet_queue; /* Process each packet in this chunk */ while (1) { ret = cs_etm_decoder__get_packet(packet_queue, - etmq->packet); + tidq->packet); if (ret <= 0) /* * Stop processing this chunk on @@ -1596,18 +1669,18 @@ static int cs_etm__process_decoder_queue(struct cs_etm_queue *etmq) * prior to switch() statement to use address * information before packets swapping. */ - ret = cs_etm__set_sample_flags(etmq); + ret = cs_etm__set_sample_flags(etmq, tidq); if (ret < 0) break; - switch (etmq->packet->sample_type) { + switch (tidq->packet->sample_type) { case CS_ETM_RANGE: /* * If the packet contains an instruction * range, generate instruction sequence * events. */ - cs_etm__sample(etmq); + cs_etm__sample(etmq, tidq); break; case CS_ETM_EXCEPTION: case CS_ETM_EXCEPTION_RET: @@ -1616,14 +1689,14 @@ static int cs_etm__process_decoder_queue(struct cs_etm_queue *etmq) * make sure the previous instruction * range packet to be handled properly. */ - cs_etm__exception(etmq); + cs_etm__exception(tidq); break; case CS_ETM_DISCONTINUITY: /* * Discontinuity in trace, flush * previous branch stack */ - cs_etm__flush(etmq); + cs_etm__flush(etmq, tidq); break; case CS_ETM_EMPTY: /* @@ -1643,6 +1716,11 @@ static int cs_etm__process_decoder_queue(struct cs_etm_queue *etmq) static int cs_etm__run_decoder(struct cs_etm_queue *etmq) { int err = 0; + struct cs_etm_traceid_queue *tidq; + + tidq = cs_etm__etmq_get_traceid_queue(etmq, CS_ETM_PER_THREAD_TRACEID); + if (!tidq) + return -EINVAL; /* Go through each buffer in the queue and decode them one by one */ while (1) { @@ -1661,13 +1739,13 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq) * an error occurs other than hoping the next one will * be better. */ - err = cs_etm__process_decoder_queue(etmq); + err = cs_etm__process_traceid_queue(etmq, tidq); } while (etmq->buf_len); if (err == 0) /* Flush any remaining branch stack entries */ - err = cs_etm__end_block(etmq); + err = cs_etm__end_block(etmq, tidq); } return err; diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 75385e2fd283..f16082d37ab5 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -136,6 +136,16 @@ struct cs_etm_packet { #define CS_ETM_PACKET_MAX_BUFFER 1024 +/* + * When working with per-thread scenarios the process under trace can + * be scheduled on any CPU and as such, more than one traceID may be + * associated with the same process. Since a traceID of '0' is illegal + * as per the CoreSight architecture, use that specific value to + * identify the queue where all packets (with any traceID) are + * aggregated. + */ +#define CS_ETM_PER_THREAD_TRACEID 0 + struct cs_etm_packet_queue { u32 packet_count; u32 head; @@ -172,7 +182,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, struct perf_session *session); int cs_etm__get_cpu(u8 trace_chan_id, int *cpu); struct cs_etm_packet_queue -*cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq); +*cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id); #else static inline int cs_etm__process_auxtrace_info(union perf_event *event __maybe_unused, @@ -188,7 +198,8 @@ static inline int cs_etm__get_cpu(u8 trace_chan_id __maybe_unused, } static inline struct cs_etm_packet_queue *cs_etm__etmq_get_packet_queue( - struct cs_etm_queue *etmq __maybe_unused) + struct cs_etm_queue *etmq __maybe_unused, + u8 trace_chan_id __maybe_unused) { return NULL; } From patchwork Fri May 24 17:35:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165153 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3885841ili; Fri, 24 May 2019 10:35:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVFd3I6k754i52kPaqYM32QtAEbBVUxn6auXL1fb1LSK6kUvSq9D5JXFFSRV86CAI7nvnY X-Received: by 2002:a17:902:347:: with SMTP id 65mr96054294pld.232.1558719356496; Fri, 24 May 2019 10:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719356; cv=none; d=google.com; s=arc-20160816; b=SjNundZAmr3PvQwF7E3MJlRvhzKlNm6Ev9b4jme1CznvypGb9ybE8vxgk6ZGX9dqSx 5cnA7fdOBwSoSxSUqJWM6JnCBdMrE0WYS0k1okyXJJ+xjMnBj8SqyQIWm7T5cOIEu/zc Rk/RYWZrNyQRJxnKcHtu1KEBoRAuk1IgS306jerapVRtDDwbJHaeIFInhUX09/4oex6+ k9Wls3p9qMgtsDH+xd0vibOHWEX23nHo451NDPDRVsEiLrk8FEvzl7IJOGidDDsYmEgU vvbOqdoGd2ultFSm3CiLH/NGiTQTe2PJEu2ulEYm/TOOlgrQ1J/tbkh12qshOPIVcj0R 7ePg== 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; bh=lhIIAcqMYF91fEeMtO+5Bx5waRYhYv5nfW6t1irEE4g=; b=hy0r6vCo7VjFX/8h+r6/7hChP1cSJqslR5NF7RR1ZvStXDIkRpU0krClrTPT3cVdw7 An/SO7w49Pp3SDKN8puMhy4caZPKqDTiiB8sQx7Rte7Ci5u4m0CYpy8crXSQ6V4ZP50r duPTJcKfrSrfRkEi6ZScjkVe6FJDra5mKFZtRqagZ7Xfujs2R2+fkn8hcGlX7gxOrxGf Rx4yt/rLwKpZKE6c0uA127XK7HahYWP/ybJk2MdEvfKNL7BnsES9kFt5Q7mTR5SNtyC3 Ldb0T4J6PotXPjhZ3kRVxmiTt31GusnpbY3igBCnZNtDJs1txKdaS9iA0iWgMgONjacI H2Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wYww6fnn; 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 ce12si5598280plb.410.2019.05.24.10.35.56; Fri, 24 May 2019 10:35:56 -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=wYww6fnn; 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 S2403860AbfEXRf1 (ORCPT + 30 others); Fri, 24 May 2019 13:35:27 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:38171 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391702AbfEXRfX (ORCPT ); Fri, 24 May 2019 13:35:23 -0400 Received: by mail-pl1-f193.google.com with SMTP id f97so4446541plb.5 for ; Fri, 24 May 2019 10:35:23 -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=lhIIAcqMYF91fEeMtO+5Bx5waRYhYv5nfW6t1irEE4g=; b=wYww6fnnhGNHiIplyjMggWqEHnKDZ+6g2AFzNWB7CAYKb806lbqsb66g3Q+Qj2l1CG lxE5Ksd6Y3XuyIUrUpdb55Kgd3V5G/aGpuK7YPCslS/ZdGzm4xYgJKSwpzOYdlTZDeSp k/LzzsHlxhqtfyofe6xlIefGjoStrQZWfDJAeW3BrTS6xz4H+J9bnGmfgSnqvjiIlIQP 1ci587Bb+g/X7SOGH/zbxj0A3N8F86Bz/X/04Pt0HqFWHuIW2qCm1iRuEhks1DTZiZ5Z WO7+GylOXqZ/z2TnIzuyxqhOU57gRjrvXsacYHyxtOFpCT81KwmN2he9haaLsX3ighkx 43mg== 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=lhIIAcqMYF91fEeMtO+5Bx5waRYhYv5nfW6t1irEE4g=; b=UPO/FIMa590cdyRwdg7ehCgpJD4j4RzPEfc0T0RRPB89WOhmw4gHXioX72h2hkSWaI LBt/X2KPZ8p+raNJtDxRNu+pFJFiL0BaOsBqaooaG+wb7qbCvStqP3EjQCVVxG68LmBe EEyWYcKAmWwjoi9AOqTz0vYCnN/m6QyiBCSQT8aYx0LF/pqCn6Fuh68efCOV3shqzkUS lr+l4fr3pkiDNEGiuIVCAXR3Jj6syNDVfzdXhNa9Dey6MgSQuWc+l/FkDOrYnlL6qt4v ipBMIv9K13LTj6+dLhCmd6Ga6bTGZ3+D4Z8S4yXrBrxjOn8vleLej+xTR9I0SuodI3Qm ZzCA== X-Gm-Message-State: APjAAAVYMvKlC4E642bdrCLdST2kEmzqlx3OjOLKjyLxX7CGbTE/snYV CXcKi0xX54sP68UMquczqhOurw== X-Received: by 2002:a17:902:ca:: with SMTP id a68mr83329085pla.7.1558719322941; Fri, 24 May 2019 10:35:22 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:22 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 10/17] perf tools: Get rid of unused cpu in struct cs_etm_queue Date: Fri, 24 May 2019 11:35:01 -0600 Message-Id: <20190524173508.29044-11-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nowadays the synthesize code is using the packet's cpu information, making cs_etm_queue::cpu useless. As such simply remove it. Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 9e8212c74055..531bbb355ba4 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -79,7 +79,6 @@ struct cs_etm_queue { struct auxtrace_buffer *buffer; unsigned int queue_nr; pid_t pid, tid; - int cpu; u64 offset; const unsigned char *buf; size_t buf_len, buf_used; @@ -599,7 +598,6 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, queue->priv = etmq; etmq->etm = etm; etmq->queue_nr = queue_nr; - etmq->cpu = queue->cpu; etmq->tid = queue->tid; etmq->pid = -1; etmq->offset = 0; @@ -831,11 +829,8 @@ static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm, etmq->thread = machine__find_thread(etm->machine, -1, etmq->tid); - if (etmq->thread) { + if (etmq->thread) etmq->pid = etmq->thread->pid_; - if (queue->cpu == -1) - etmq->cpu = etmq->thread->cpu; - } } static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, From patchwork Fri May 24 17:35:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165155 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3886015ili; Fri, 24 May 2019 10:36:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXGKLc7o6ThPr5UeLsgiDdImSwvXuBxeD5Qwva2bl95PssPU+AAAlrXGqrIGpIkVlyxc5o X-Received: by 2002:a17:90a:d16:: with SMTP id t22mr10984652pja.130.1558719366032; Fri, 24 May 2019 10:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719366; cv=none; d=google.com; s=arc-20160816; b=d8SFe2NXRl4CPQuHku+zHytd0zbplo/2ucdKrArX3oI+spexX5B2K3d9CWqdQLwGaA IWRdtHNQmBg8QtkuTcUMpDvj3q9EIyWCTlSEtE0FYzrTYwqTeL2UOCSjnX1DegZ9WKEr FdQdnoStew2+WVZq7W9ZFlpiLEfhnuyL5Agrb5CLuMq1AQxTiw2Wml2b7f0U7v5NhVjg uYtcGtXgtDvqvzr9GGiGe2UzPDb3QKwogFTeF9cm3dxW4hqunmsoD6OvBHYMPBoSs2pz Ee6pw43RnxAdBjsiMN8a01RMGvytbE3xP6jY3Gw9TBZQwW7IbhDZdVD2gXPXMixp9gCQ Z7Zg== 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; bh=J3KXvvmyZI4M9TGLwpGRYcqjyy4iZs8aqIvbJ4YnMAg=; b=ZiFOWMfKweZz+lBQX0noWuMYnG5UJp1QvuZcE/cijp/CRVm2iDRONcCnJAj8l/cdti WlJXtdRLnG2dqdvJQbIQYeGCXOpWzSJ+k2qCXXDgpf2lNyT2vVtBH24yLW+ZLbLcpTgY V63h2dyJchhJt9H/j161tlBfUwrBG18tA3/R5fVQnHipmvFd/7I6pmCDnWs46eHHnuUa CajHUpAvgLKlflAaoZVbhx3qVWG2Br3vtPbbQrwv+gFxBJJEsCzrriu5k7NqUD/klXIa 1flLH2iNGEpx3QcRlBTCCiCGBri+kWj6hDgDo1lEo1B+2PYflNl4FZBAiygXFRzUu9bR yAWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PxeotkVs; 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 ce12si5598280plb.410.2019.05.24.10.36.05; Fri, 24 May 2019 10:36:06 -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=PxeotkVs; 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 S2391729AbfEXRgE (ORCPT + 30 others); Fri, 24 May 2019 13:36:04 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:32872 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391691AbfEXRfY (ORCPT ); Fri, 24 May 2019 13:35:24 -0400 Received: by mail-pl1-f193.google.com with SMTP id g21so4458013plq.0 for ; Fri, 24 May 2019 10:35:24 -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=J3KXvvmyZI4M9TGLwpGRYcqjyy4iZs8aqIvbJ4YnMAg=; b=PxeotkVsdudTZ5DzfbDSWNGHXZFlizeQMtK9EnDTDtk3701NQsI0BL6K8GGLqdOFlS lQDesgnT9B211Eosr0u2MEaAt35hY9zdOr4zpF4NH+uI2g+f/Y9zKI/5gpwNWwIYpobi LMWB0GKpOp72zMvvLIYvikUZ+24dwfkdyQdxCpINpPbH2XpzpOM8raL5MXpz9nV+kPXu f635YZt7ygq+iP2HIRJ5sArUuVi9NsC1R+ko/5r+diZRFgxRl3inS7A76ngKmGyNu6It YDSupMpR0bHcKsWNRHIBwbC70u3X3KHAqRtmfOBMi+aP1iae511n5i9/RVoA+nZF7UJR Svaw== 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=J3KXvvmyZI4M9TGLwpGRYcqjyy4iZs8aqIvbJ4YnMAg=; b=aUeLsXEg9QsbWjzzpHkfqszl95Nt+XoFACdt5vDKj6XW1+yj4HsSPS233MsKcwuUPW 6HwAi8TrUpVicEhyFA6cE23CciETMsfY9wieOmWzr5WbFbfMSAKk8tcpxfwEnMbJf2rC 7anJVpRjps0iED0o/B3IKq29/k0x/Pst8NxcTku9XLNokCzkx7S8/EqnSkYmQGG3h2Ni J3EYYpVejEUrXf3t6pD3bMd66Q5iuQnYLLKySAqIWva92c0lntrPHRgf9stG0AmweLzZ PbXFXvoojue/nIurmGuLNKkuMjoAC6y6OaNlVjKV+E6JOHIBy7s4ov6m7jHkGuqMLjAl PGww== X-Gm-Message-State: APjAAAWPGyzjtnnfo2zHjN5wp6hFDnmmNjZsBnPpnpqdcM8NXsLalndI /gFUe5a9qrR6u1B5QUsBQisuCw== X-Received: by 2002:a17:902:d715:: with SMTP id w21mr92505236ply.234.1558719324246; Fri, 24 May 2019 10:35:24 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:23 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 11/17] perf tools: Move thread to traceid_queue Date: Fri, 24 May 2019 11:35:02 -0600 Message-Id: <20190524173508.29044-12-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The thread field of structure cs_etm_queue is CPU dependent and as such need to be part of the cs_etm_traceid_queue in order to support CPU-wide trace scenarios. Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 531bbb355ba4..0d51d6d9a594 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -65,6 +65,7 @@ struct cs_etm_traceid_queue { u64 period_instructions; size_t last_branch_pos; union perf_event *event_buf; + struct thread *thread; struct branch_stack *last_branch; struct branch_stack *last_branch_rb; struct cs_etm_packet *prev_packet; @@ -74,7 +75,6 @@ struct cs_etm_traceid_queue { struct cs_etm_queue { struct cs_etm_auxtrace *etm; - struct thread *thread; struct cs_etm_decoder *decoder; struct auxtrace_buffer *buffer; unsigned int queue_nr; @@ -415,7 +415,7 @@ static void cs_etm__free_queue(void *priv) if (!etmq) return; - thread__zput(etmq->thread); + thread__zput(etmq->traceid_queues->thread); cs_etm_decoder__free(etmq->decoder); zfree(&etmq->traceid_queues->event_buf); zfree(&etmq->traceid_queues->last_branch); @@ -503,7 +503,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address, machine = etmq->etm->machine; cpumode = cs_etm__cpu_mode(etmq, address); - thread = etmq->thread; + thread = etmq->traceid_queues->thread; if (!thread) { if (cpumode != PERF_RECORD_MISC_KERNEL) return 0; @@ -819,18 +819,21 @@ cs_etm__get_trace(struct cs_etm_queue *etmq) static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm, struct auxtrace_queue *queue) { + struct cs_etm_traceid_queue *tidq; struct cs_etm_queue *etmq = queue->priv; + tidq = cs_etm__etmq_get_traceid_queue(etmq, CS_ETM_PER_THREAD_TRACEID); + /* 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, + if ((!tidq->thread) && (etmq->tid != -1)) + tidq->thread = machine__find_thread(etm->machine, -1, etmq->tid); - if (etmq->thread) - etmq->pid = etmq->thread->pid_; + if (tidq->thread) + etmq->pid = tidq->thread->pid_; } static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, From patchwork Fri May 24 17:35:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165148 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3885388ili; Fri, 24 May 2019 10:35:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqatUAjRIsYZ9Xdaw72I7SuJQLASUlycpYwnxi6iZaOdChMHZzZudeNZu8vSNPgqnYJv2h X-Received: by 2002:a17:90a:9f90:: with SMTP id o16mr11069756pjp.72.1558719331031; Fri, 24 May 2019 10:35:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719331; cv=none; d=google.com; s=arc-20160816; b=MSU1URetPaEbrQS7AY1qEfCQqAo9adoKyEHPWOMBABPEdZ02///RnHg4pygN4RiNCX if2lZ9HEt9oKzTZsiAL917w6em78o7OT7/KTuiBU8WB+QCa1icFbZfYZrG3nOBFt55FA 9jOh0uJx0JIHpKD6hJEe4JhPmbkTKzDHdLiTbjWXUTabRncIjrE3h94xeTaehfBfmitR LIS9w26/DHWF68/IGD7NvtB5CDOfv3WtC29KA7efTrxLw+fJBpnr9ZOuEqKKdg4AcebO hnwfCcT8Y2Fr+AA1bvf2u0TIrOZWe95vKF6eGR6UDNvZQzGU3J46IYTmAvw+n1zM4NZV JwEw== 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; bh=eTGrl1VwMHPMcZROfgPIL9cYLAfm7e1gifTctdhMIag=; b=feoO9Pxbp1URa4bjcmeYFxq7+RNNuXaYWKtNyLxqZn+yKoA9bkyaHRYezAeB1CZTwM DAkpe0V/Fn9iNqPGTFJocp15T++ncGB4KONhGkbkNIimgEb1OkIEaVU1MeyeXBByw9wM dtqCTF3estI1Bewwt2btr8mSta9i8bFxWqkeXtEuwFPvOW1oo/6+gsfHxKi0UwhONLVU RH02BsPfof7/Z2b4HuWscx0UmGAcimI2cVF+LPsbWvu0HWEDQKyCvitzYJctqK1hJJfK qDPFY7Y3COVKkxn0iFJSSSTyzqwSgydGqUfBJ5Tqb6kZWPDEBcyDpdxyAuK5/cAihJcX +FQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uexRFuRC; 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 f17si5078321pgv.338.2019.05.24.10.35.30; Fri, 24 May 2019 10:35:31 -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=uexRFuRC; 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 S2403966AbfEXRf3 (ORCPT + 30 others); Fri, 24 May 2019 13:35:29 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:41218 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403760AbfEXRf0 (ORCPT ); Fri, 24 May 2019 13:35:26 -0400 Received: by mail-pf1-f195.google.com with SMTP id q17so877645pfq.8 for ; Fri, 24 May 2019 10:35:25 -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=eTGrl1VwMHPMcZROfgPIL9cYLAfm7e1gifTctdhMIag=; b=uexRFuRCUMiVTKpuY4H6ZXEoKfbokTfvLGUjC/jwLmemjjK+9N08UN2R450MQzMQFS SDYZUWqYuwiEWmCasHAcniqKd8VZ1P9qLod4b26Q3GLCZniJsQc8MPQjnN5JxRgQdtX0 +BSF0I69lK+hyZyucAN5AmDmmVYB9bGjevMr73ySf1a5aXZPRdECjJHyvinKVAw4AOqQ z9D++HcFUhruKpxEn3SksqcIh5wZAf0QWLZRdtKmqPtO5Z5YCA08an7r7P/RqcQI7d5t x1Qeaar+Gxem++wi2r0RFocbzTW/ZaEaLfO2QRxBjq9syIms/TNaxDjUyWMA1jDMufq0 U03Q== 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=eTGrl1VwMHPMcZROfgPIL9cYLAfm7e1gifTctdhMIag=; b=ZjGmEIZiDaklM+b270rpHfsAhEG1GHwQ0ipKDwsivoVvyi9hnu7qEzV+HPDngSJJTj Le6eAJYt1hBjjSt9MxSGKThCJDCWJqB3x+IQpUNMfXVBcrrfkg0vZ1HXMV9WeXt5rrBm yc+8LiK3GM0ZqsatRqyV5UcQf/JOmb/MWGBKJpHZOtwW61rr8aTHYlH2nekvDFt7qeOD 01Ud/DcgZuHWpO5eEbPNcEsoCZL3rIbQJvoUZbFtquqPNg7QsrPemK9AESn6vBjNvQJ3 O2geVvBxJP3Qj2aR8KbjwXa7HTwIzGcl8RamUr4iuH+LQSWrit7v0B/cu85fh9sPN3hd KkZQ== X-Gm-Message-State: APjAAAXRLagSMvAAXcEc4s00JdpX9Q+AcP+mB5khJdSk+5Fdn9WiRdmB FHElSFrb+3SFKr3oDZx87KADDw== X-Received: by 2002:a63:6ac3:: with SMTP id f186mr107175814pgc.326.1558719325379; Fri, 24 May 2019 10:35:25 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:24 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 12/17] perf tools: Move tid/pid to traceid_queue Date: Fri, 24 May 2019 11:35:03 -0600 Message-Id: <20190524173508.29044-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The tid/pid fields of structure cs_etm_queue are CPU dependent and as such need to be part of the cs_etm_traceid_queue in order to support CPU-wide trace scenarios. Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 44 ++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 18 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 0d51d6d9a594..7e3b4d10f5c4 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -62,6 +62,7 @@ struct cs_etm_auxtrace { struct cs_etm_traceid_queue { u8 trace_chan_id; + pid_t pid, tid; u64 period_instructions; size_t last_branch_pos; union perf_event *event_buf; @@ -78,7 +79,6 @@ struct cs_etm_queue { struct cs_etm_decoder *decoder; struct auxtrace_buffer *buffer; unsigned int queue_nr; - pid_t pid, tid; u64 offset; const unsigned char *buf; size_t buf_len, buf_used; @@ -159,10 +159,14 @@ static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq, u8 trace_chan_id) { int rc = -ENOMEM; + struct auxtrace_queue *queue; struct cs_etm_auxtrace *etm = etmq->etm; cs_etm__clear_packet_queue(&tidq->packet_queue); + queue = &etmq->etm->queues.queue_array[etmq->queue_nr]; + tidq->tid = queue->tid; + tidq->pid = -1; tidq->trace_chan_id = trace_chan_id; tidq->packet = zalloc(sizeof(struct cs_etm_packet)); @@ -598,8 +602,6 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, queue->priv = etmq; etmq->etm = etm; etmq->queue_nr = queue_nr; - etmq->tid = queue->tid; - etmq->pid = -1; etmq->offset = 0; out: @@ -817,23 +819,19 @@ cs_etm__get_trace(struct cs_etm_queue *etmq) } static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm, - struct auxtrace_queue *queue) + struct auxtrace_queue *queue, + struct cs_etm_traceid_queue *tidq) { - struct cs_etm_traceid_queue *tidq; - struct cs_etm_queue *etmq = queue->priv; - - tidq = cs_etm__etmq_get_traceid_queue(etmq, CS_ETM_PER_THREAD_TRACEID); - /* CPU-wide tracing isn't supported yet */ if (queue->tid == -1) return; - if ((!tidq->thread) && (etmq->tid != -1)) + if ((!tidq->thread) && (tidq->tid != -1)) tidq->thread = machine__find_thread(etm->machine, -1, - etmq->tid); + tidq->tid); if (tidq->thread) - etmq->pid = tidq->thread->pid_; + tidq->pid = tidq->thread->pid_; } static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, @@ -850,8 +848,8 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, event->sample.header.size = sizeof(struct perf_event_header); sample.ip = addr; - sample.pid = etmq->pid; - sample.tid = etmq->tid; + sample.pid = tidq->pid; + sample.tid = tidq->tid; sample.id = etmq->etm->instructions_id; sample.stream_id = etmq->etm->instructions_id; sample.period = period; @@ -909,8 +907,8 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq, event->sample.header.size = sizeof(struct perf_event_header); sample.ip = ip; - sample.pid = etmq->pid; - sample.tid = etmq->tid; + sample.pid = tidq->pid; + sample.tid = tidq->tid; sample.addr = cs_etm__first_executed_instr(tidq->packet); sample.id = etmq->etm->branches_id; sample.stream_id = etmq->etm->branches_id; @@ -1758,9 +1756,19 @@ static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm, for (i = 0; i < queues->nr_queues; i++) { struct auxtrace_queue *queue = &etm->queues.queue_array[i]; struct cs_etm_queue *etmq = queue->priv; + struct cs_etm_traceid_queue *tidq; + + if (!etmq) + continue; + + tidq = cs_etm__etmq_get_traceid_queue(etmq, + CS_ETM_PER_THREAD_TRACEID); + + if (!tidq) + continue; - if (etmq && ((tid == -1) || (etmq->tid == tid))) { - cs_etm__set_pid_tid_cpu(etm, queue); + if ((tid == -1) || (tidq->tid == tid)) { + cs_etm__set_pid_tid_cpu(etm, queue, tidq); cs_etm__run_decoder(etmq); } } From patchwork Fri May 24 17:35:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165154 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3885900ili; Fri, 24 May 2019 10:35:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxOw8Rk398IMu6096rt1WsBsjftl7agh5yVJOfu/j7SlJOfXepYeuvZTWBKUO6SafPnTjk3 X-Received: by 2002:a17:902:b584:: with SMTP id a4mr71863745pls.333.1558719359826; Fri, 24 May 2019 10:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719359; cv=none; d=google.com; s=arc-20160816; b=nPfAAxfTKgw/5LxeYivEJZ09vyB0+JS2XOu2TZJHVrjH688/r1ru72Y9eeCjt9OpSM wpusC4W/jJyQ/n1xT1UaX/7HKro4QazfOdeyJgA8pWXEXHkXokkn/uDVG2XAeYnS8V50 TuBRIEhXH6JUTR5fZZ7AbKLEfK7xRU2ol1q7NmzGGlwtgfS5ib/WemaKL4C7ZXFpB+ne bRlxYDtb/e9MLNLTq23SbEyH66GspF0XYEtk7mw3pZ/FiyBsn86B4acSAUNsDb/tlazV n3Ur4CB8QpPm4xytaG+eVwPDsb7xXmai9oP3E1/6tC1crwamgq8p6veuDIJ7Q0jI6vYi Bsdw== 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; bh=cq0t+PSXn//LvYjO2sa6TunhyuzsYVmdu9JbEFprU14=; b=yUy8+T6crQMQp5cM+uO3XVLlUkWPCJw1/5SM8iXliR/IQ2gw7Npedv2JwsyE/34xWD JEumc4DpnDuGfa2rmRt8PVKQl3S2ER0LYyi8/yqNEYH8htbB2bp3tJsCmXNgslsAOLRU J7nZO0lpjrel5ZtkzFqBvdWlQ7vnqWZuHgOXRg5kABwE9d07pBKEvxTmyaDoPKWjFoEm UCR9RoqQE2jVmlJjHZ95OMQjfPoy7YIsFS1Uv3BXtAZZbTOU7MhuFfE1sfV8M8lxh+RW ia5177nRySTopyg6BfW1zJuT+tSnokm4LqrPYgqvVtAeX3ko90mPg30uXpcaSwA8cKpc Bvcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q1n5NJxB; 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 ce12si5598280plb.410.2019.05.24.10.35.59; Fri, 24 May 2019 10:35:59 -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=q1n5NJxB; 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 S2404170AbfEXRf6 (ORCPT + 30 others); Fri, 24 May 2019 13:35:58 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45068 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403826AbfEXRf1 (ORCPT ); Fri, 24 May 2019 13:35:27 -0400 Received: by mail-pg1-f194.google.com with SMTP id w34so747985pga.12 for ; Fri, 24 May 2019 10:35:27 -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=cq0t+PSXn//LvYjO2sa6TunhyuzsYVmdu9JbEFprU14=; b=q1n5NJxBc1CxN3THW31CYCMIMZLFrJTdSaNuXZvcSYYalZjyR37nIzgV0zsDoveRIM s9nu2yOj0h4pYn3lqUYNXAFmnpU+kOn7uTiybF7lv8C3cAP3nm7DfXYijD1tltccuh3K TYUT4V+deACoAp+3uASEbCkS4aLQCdLByV/9+LY37NNQs74rwCyuM23Q57H0rYHb+QC2 4Ft/kq8nCaoXSLCFnF+mkxten+bnX+pOpUItzGAGSjXLHFCWttfg08/x8aIL2jDJ5mCo E/qpTrmvZHzm3NcjWl1ZmxRliOLO4MmVe2JgScpi0N7y0sR2IcYVWu58o4styRLdec+o +WDg== 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=cq0t+PSXn//LvYjO2sa6TunhyuzsYVmdu9JbEFprU14=; b=pdWHuRTvRNOxNcACaerdBhRRABhFW2ITUun5Su6pPht572O10OiqtH1P2+7El/Ryc9 NgBhXjzUnyBsm1xSrx57m+nryaT3kim1oWeqVW58e1LE8S1TtycUmExKRDdfKiYpr+Gu PO5yJcTsZJN2hnLBQsmUHqf9utCL0V8uBnpxxZ3m97E3TkVIc9n8f9ckH52BOipTi5aN ucxgT/JVwnvEwD0+niJYu8y1+5RBoNOeLbTDHg2g7Liln8pyqJXbSvC/nqa0fYrdh0Ci 4zSG+ucoaPqBfpTDqmHLOhhE/P42ud7ogTzFmdSGAnpKcugGDisEhWS07gfXAWpWptTF wb9w== X-Gm-Message-State: APjAAAXwnlZvGE/CiTSCGYQ3OHuSuRCUjO2QTM+HafFCDTgubrmdFIrJ 1lvMgO/b5fhle/5yzfG4nUUFaQ== X-Received: by 2002:a65:4786:: with SMTP id e6mr22058580pgs.85.1558719326690; Fri, 24 May 2019 10:35:26 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:26 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 13/17] perf tools: Use traceID aware memory callback API Date: Fri, 24 May 2019 11:35:04 -0600 Message-Id: <20190524173508.29044-14-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When working with CPU-wide traces different traceID may be found in the same stream. As such we need to use the decoder callback that provides the traceID in order to know the thread context being decoded. Signed-off-by: Mathieu Poirier --- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 14 +++---- .../perf/util/cs-etm-decoder/cs-etm-decoder.h | 3 +- tools/perf/util/cs-etm.c | 41 +++++++++++++------ 3 files changed, 36 insertions(+), 22 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index 4303d2d00d31..87264b79de0e 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -41,15 +41,14 @@ static u32 cs_etm_decoder__mem_access(const void *context, const ocsd_vaddr_t address, const ocsd_mem_space_acc_t mem_space __maybe_unused, + const u8 trace_chan_id, const u32 req_size, u8 *buffer) { struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context; - return decoder->mem_access(decoder->data, - address, - req_size, - buffer); + return decoder->mem_access(decoder->data, trace_chan_id, + address, req_size, buffer); } int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder, @@ -58,9 +57,10 @@ int cs_etm_decoder__add_mem_access_cb(struct cs_etm_decoder *decoder, { decoder->mem_access = cb_func; - if (ocsd_dt_add_callback_mem_acc(decoder->dcd_tree, start, end, - OCSD_MEM_SPACE_ANY, - cs_etm_decoder__mem_access, decoder)) + if (ocsd_dt_add_callback_trcid_mem_acc(decoder->dcd_tree, start, end, + OCSD_MEM_SPACE_ANY, + cs_etm_decoder__mem_access, + decoder)) return -1; return 0; diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h index 6ae7ab4cf5fe..11f3391d06f2 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -19,8 +19,7 @@ struct cs_etm_packet_queue; struct cs_etm_queue; -typedef u32 (*cs_etm_mem_cb_type)(struct cs_etm_queue *, u64, - size_t, u8 *); +typedef u32 (*cs_etm_mem_cb_type)(struct cs_etm_queue *, u8, u64, size_t, u8 *); struct cs_etmv3_trace_params { u32 reg_ctrl; diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 7e3b4d10f5c4..2483293266d8 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -491,8 +491,8 @@ static u8 cs_etm__cpu_mode(struct cs_etm_queue *etmq, u64 address) } } -static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address, - size_t size, u8 *buffer) +static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id, + u64 address, size_t size, u8 *buffer) { u8 cpumode; u64 offset; @@ -501,6 +501,8 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address, struct machine *machine; struct addr_location al; + (void)trace_chan_id; + if (!etmq) return 0; @@ -687,10 +689,12 @@ void cs_etm__reset_last_branch_rb(struct cs_etm_traceid_queue *tidq) } static inline int cs_etm__t32_instr_size(struct cs_etm_queue *etmq, - u64 addr) { + u8 trace_chan_id, u64 addr) +{ u8 instrBytes[2]; - cs_etm__mem_access(etmq, addr, ARRAY_SIZE(instrBytes), instrBytes); + cs_etm__mem_access(etmq, trace_chan_id, addr, + ARRAY_SIZE(instrBytes), instrBytes); /* * T32 instruction size is indicated by bits[15:11] of the first * 16-bit word of the instruction: 0b11101, 0b11110 and 0b11111 @@ -719,6 +723,7 @@ u64 cs_etm__last_executed_instr(const struct cs_etm_packet *packet) } static inline u64 cs_etm__instr_addr(struct cs_etm_queue *etmq, + u64 trace_chan_id, const struct cs_etm_packet *packet, u64 offset) { @@ -726,7 +731,8 @@ static inline u64 cs_etm__instr_addr(struct cs_etm_queue *etmq, u64 addr = packet->start_addr; while (offset > 0) { - addr += cs_etm__t32_instr_size(etmq, addr); + addr += cs_etm__t32_instr_size(etmq, + trace_chan_id, addr); offset--; } return addr; @@ -1063,6 +1069,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, struct cs_etm_auxtrace *etm = etmq->etm; struct cs_etm_packet *tmp; int ret; + u8 trace_chan_id = tidq->trace_chan_id; u64 instrs_executed = tidq->packet->instr_count; tidq->period_instructions += instrs_executed; @@ -1093,7 +1100,8 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, * executed, but PC has not advanced to next instruction) */ u64 offset = (instrs_executed - instrs_over - 1); - u64 addr = cs_etm__instr_addr(etmq, tidq->packet, offset); + u64 addr = cs_etm__instr_addr(etmq, trace_chan_id, + tidq->packet, offset); ret = cs_etm__synth_instruction_sample( etmq, tidq, addr, etm->instructions_sample_period); @@ -1268,7 +1276,7 @@ static int cs_etm__get_data_block(struct cs_etm_queue *etmq) return etmq->buf_len; } -static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, +static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, u8 trace_chan_id, struct cs_etm_packet *packet, u64 end_addr) { @@ -1291,7 +1299,8 @@ static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, * so below only read 2 bytes as instruction size for T32. */ addr = end_addr - 2; - cs_etm__mem_access(etmq, addr, sizeof(instr16), (u8 *)&instr16); + cs_etm__mem_access(etmq, trace_chan_id, addr, + sizeof(instr16), (u8 *)&instr16); if ((instr16 & 0xFF00) == 0xDF00) return true; @@ -1306,7 +1315,8 @@ static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, * +---------+---------+-------------------------+ */ addr = end_addr - 4; - cs_etm__mem_access(etmq, addr, sizeof(instr32), (u8 *)&instr32); + cs_etm__mem_access(etmq, trace_chan_id, addr, + sizeof(instr32), (u8 *)&instr32); if ((instr32 & 0x0F000000) == 0x0F000000 && (instr32 & 0xF0000000) != 0xF0000000) return true; @@ -1322,7 +1332,8 @@ static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, * +-----------------------+---------+-----------+ */ addr = end_addr - 4; - cs_etm__mem_access(etmq, addr, sizeof(instr32), (u8 *)&instr32); + cs_etm__mem_access(etmq, trace_chan_id, addr, + sizeof(instr32), (u8 *)&instr32); if ((instr32 & 0xFFE0001F) == 0xd4000001) return true; @@ -1338,6 +1349,7 @@ static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, static bool cs_etm__is_syscall(struct cs_etm_queue *etmq, struct cs_etm_traceid_queue *tidq, u64 magic) { + u8 trace_chan_id = tidq->trace_chan_id; struct cs_etm_packet *packet = tidq->packet; struct cs_etm_packet *prev_packet = tidq->prev_packet; @@ -1352,7 +1364,7 @@ static bool cs_etm__is_syscall(struct cs_etm_queue *etmq, */ if (magic == __perf_cs_etmv4_magic) { if (packet->exception_number == CS_ETMV4_EXC_CALL && - cs_etm__is_svc_instr(etmq, prev_packet, + cs_etm__is_svc_instr(etmq, trace_chan_id, prev_packet, prev_packet->end_addr)) return true; } @@ -1390,6 +1402,7 @@ static bool cs_etm__is_sync_exception(struct cs_etm_queue *etmq, struct cs_etm_traceid_queue *tidq, u64 magic) { + u8 trace_chan_id = tidq->trace_chan_id; struct cs_etm_packet *packet = tidq->packet; struct cs_etm_packet *prev_packet = tidq->prev_packet; @@ -1415,7 +1428,7 @@ static bool cs_etm__is_sync_exception(struct cs_etm_queue *etmq, * (SMC, HVC) are taken as sync exceptions. */ if (packet->exception_number == CS_ETMV4_EXC_CALL && - !cs_etm__is_svc_instr(etmq, prev_packet, + !cs_etm__is_svc_instr(etmq, trace_chan_id, prev_packet, prev_packet->end_addr)) return true; @@ -1439,6 +1452,7 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq, { struct cs_etm_packet *packet = tidq->packet; struct cs_etm_packet *prev_packet = tidq->prev_packet; + u8 trace_chan_id = tidq->trace_chan_id; u64 magic; int ret; @@ -1519,7 +1533,8 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq, if (prev_packet->flags == (PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_INTERRUPT) && - cs_etm__is_svc_instr(etmq, packet, packet->start_addr)) + cs_etm__is_svc_instr(etmq, trace_chan_id, + packet, packet->start_addr)) prev_packet->flags = PERF_IP_FLAG_BRANCH | PERF_IP_FLAG_RETURN | PERF_IP_FLAG_SYSCALLRET; From patchwork Fri May 24 17:35:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165152 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3885681ili; Fri, 24 May 2019 10:35:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPeg7d11G/gUcvnm0fhMzhKYDBwbUas+GQWR/pRzGFlCEemdvISEnzo6pqe2XXv2ynMEtE X-Received: by 2002:a17:90a:9a8a:: with SMTP id e10mr10856815pjp.109.1558719348132; Fri, 24 May 2019 10:35:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719348; cv=none; d=google.com; s=arc-20160816; b=i5tBIrtqjHjaAHJZvCcm8SVLLHhT1cFMZ/Uq4HxfHqXHkUF25JeHHidrSoIQ8+Qa0w cVCMxNFYq6QMd8+9Gm8/xUpLu08MxnjuHndXIKdT5hCifyUWKLZitXgRSBIX+sq1zT+V uz8Py4LN/hYQK/DsX6w3L42Ur3EsC6dU2iJkPX0MY8ZdT8Q88msOcu4JhfzK6lTw18T3 56jVsbhlEoI1LSF3PXAbge8MB01XisEmS0E7d85q/yBwq6bS2MX4uW8W+I/5VRMUHM1k IocLqyTMrtxKAUqKacNwQD3QWcT9jqAVeB9m02JhJ0Ys0wZEmR9bx8p78PMCI/zpD6lF fpFA== 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; bh=sLeIs2ht3Bexy615KPYvuA1gjE4ZvABeyxgkVxsxj04=; b=yROtbE2D6NfT3Pqoni3+B0bRvHagFb+p7ZSzAksVeCa9dYNSzbQK2aDKvCWyUVsdz4 5/KpNT+cuNMrE3jLF6XdJnoS7qoR/Gl4TE8GThRI4iB1ZbrQJu1SMeUZCi8Np9ndOuR4 dbRGyUryNBT75E19kLT7A3OpH/+5X1RgAliNcSvd/OOdhojvHeKCExE10m3/AYXFEuZW ekuMT8sFzynwXg2/z+2DKANznI3keNdh5rGM7z5z/ss4eshc9obaF5cDl1Enb5sUIivs OGA6QtCvnPyzNsMruE4563FlOynQSrQOIa6XwZF92z4tyMmATGd1Z4gLZrnsmupmJ/KO 8ZjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yWSgtcfv; 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 m2si4870297pgv.89.2019.05.24.10.35.47; Fri, 24 May 2019 10:35:48 -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=yWSgtcfv; 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 S2404128AbfEXRfr (ORCPT + 30 others); Fri, 24 May 2019 13:35:47 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:37177 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403898AbfEXRf2 (ORCPT ); Fri, 24 May 2019 13:35:28 -0400 Received: by mail-pg1-f194.google.com with SMTP id n27so5419709pgm.4 for ; Fri, 24 May 2019 10:35:28 -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=sLeIs2ht3Bexy615KPYvuA1gjE4ZvABeyxgkVxsxj04=; b=yWSgtcfvNEzSucZd2HObaLO8RWQcceH4AX+g6zfH930jotOnk6YMB5pQ/SLW4ipjhJ jZ5iI7gJfpoSYQtQUcZ79lBPaNPG+hbO2hs4QYVeDM7GG+D8UhlGkg4IwoFS/GymgbHf lm3l8Rz829dZxNiy3CRzcoX8x69OUkaFafZq681COCJ81z2pXxwUW2/iWULdJsICdI5n 6AYDsGP+qVK/YeCmljvY0U3ZMXj4yA8XmpwqYCiu1NEMSNnk0ZobahU98vScCjkqCUf6 u3tZRBZnKTaTIrtQlGjp7AC2DoG2GAM3gFXJiKR5h511V0HeFOVIUvDbVKCJqIlmOLm2 gopw== 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=sLeIs2ht3Bexy615KPYvuA1gjE4ZvABeyxgkVxsxj04=; b=feCacX2YeinEi1jOkcXr27InURrqIQ+Vgd6jDBQeah79s5A5yI61t3uVkQGKpYZP8Q lLufzRtHo3AYqpcRXB4+dl4TeDhdvse1akYV/KNE/uOOZ6/pfI2oH5MDeH3+hPgx6ABT VKm0Gsv75s0KMr9XR7Xz3XgeTlwCG5uJPfh3JNB4ja7RZP12YX5fDIOuOOeV4yzBUOO+ Wg3ns0TcWK2Mo2eOTAkwgid5xRM/fFsMAmqGWmto8HFXrYaEqetNj5qpXW5jZJ/0ota7 lYG3DkF12DyBzsFDCidYHqctXFSxftcJQRiiRq2EugRqoGqjiQBOTsIzOFfaz7zYBei+ q+kQ== X-Gm-Message-State: APjAAAXdEUpORYwYYCpbOux2bLzJgEX5mjrUUS4+kj4ywQZkfbkEMbRh a1zc8Ns0fgmmpAlSvMb4bFAL8w== X-Received: by 2002:a63:2a06:: with SMTP id q6mr20337812pgq.290.1558719327903; Fri, 24 May 2019 10:35:27 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:27 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 14/17] perf tools: Add support for multiple traceID queues Date: Fri, 24 May 2019 11:35:05 -0600 Message-Id: <20190524173508.29044-15-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When operating in CPU-wide trace mode with a source/sink topology of N:1 packets with multiple traceID will end up in the same cs_etm_queue. In order to properly decode packets they need to be split in different queues, i.e one queue per traceID. As such add support for multiple traceID per cs_etm_queue by adding a new cs_etm_traceid_queue every time a new traceID is discovered in the trace stream. Signed-off-by: Mathieu Poirier --- tools/perf/Makefile.config | 3 + tools/perf/util/cs-etm.c | 131 ++++++++++++++++++++++++++++++------- 2 files changed, 110 insertions(+), 24 deletions(-) -- 2.17.1 diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index e1bb5288ab1f..feb2d1b85087 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -412,6 +412,9 @@ ifdef CORESIGHT $(call feature_check,libopencsd) ifeq ($(feature-libopencsd), 1) CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS) + ifeq ($(feature-reallocarray), 0) + CFLAGS += -DCOMPAT_NEED_REALLOCARRAY + endif LDFLAGS += $(LIBOPENCSD_LDFLAGS) EXTLIBS += $(OPENCSDLIBS) $(call detected,CONFIG_LIBOPENCSD) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 2483293266d8..afc2491f9f2a 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -29,6 +29,7 @@ #include "thread.h" #include "thread_map.h" #include "thread-stack.h" +#include #include "util.h" #define MAX_TIMESTAMP (~0ULL) @@ -82,7 +83,9 @@ struct cs_etm_queue { u64 offset; const unsigned char *buf; size_t buf_len, buf_used; - struct cs_etm_traceid_queue *traceid_queues; + /* Conversion between traceID and index in traceid_queues array */ + struct intlist *traceid_queues_list; + struct cs_etm_traceid_queue **traceid_queues; }; static int cs_etm__update_queues(struct cs_etm_auxtrace *etm); @@ -208,31 +211,71 @@ static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq, static struct cs_etm_traceid_queue *cs_etm__etmq_get_traceid_queue(struct cs_etm_queue *etmq, u8 trace_chan_id) { - struct cs_etm_traceid_queue *tidq; + int idx; + struct int_node *inode; + struct intlist *traceid_queues_list; + struct cs_etm_traceid_queue *tidq, **traceid_queues; struct cs_etm_auxtrace *etm = etmq->etm; - if (!etm->timeless_decoding) - return NULL; + if (etm->timeless_decoding) + trace_chan_id = CS_ETM_PER_THREAD_TRACEID; - tidq = etmq->traceid_queues; + traceid_queues_list = etmq->traceid_queues_list; - if (tidq) - return tidq; + /* + * Check if the traceid_queue exist for this traceID by looking + * in the queue list. + */ + inode = intlist__find(traceid_queues_list, trace_chan_id); + if (inode) { + idx = (int)(intptr_t)inode->priv; + return etmq->traceid_queues[idx]; + } + /* We couldn't find a traceid_queue for this traceID, allocate one */ tidq = malloc(sizeof(*tidq)); if (!tidq) return NULL; memset(tidq, 0, sizeof(*tidq)); + /* Get a valid index for the new traceid_queue */ + idx = intlist__nr_entries(traceid_queues_list); + /* Memory for the inode is free'ed in cs_etm_free_traceid_queues () */ + inode = intlist__findnew(traceid_queues_list, trace_chan_id); + if (!inode) + goto out_free; + + /* Associate this traceID with this index */ + inode->priv = (void *)(intptr_t)idx; + if (cs_etm__init_traceid_queue(etmq, tidq, trace_chan_id)) goto out_free; - etmq->traceid_queues = tidq; + /* Grow the traceid_queues array by one unit */ + traceid_queues = etmq->traceid_queues; + traceid_queues = reallocarray(traceid_queues, + idx + 1, + sizeof(*traceid_queues)); + + /* + * On failure reallocarray() returns NULL and the original block of + * memory is left untouched. + */ + if (!traceid_queues) + goto out_free; + + traceid_queues[idx] = tidq; + etmq->traceid_queues = traceid_queues; - return etmq->traceid_queues; + return etmq->traceid_queues[idx]; out_free: + /* + * Function intlist__remove() removes the inode from the list + * and delete the memory associated to it. + */ + intlist__remove(traceid_queues_list, inode); free(tidq); return NULL; @@ -412,6 +455,44 @@ static int cs_etm__flush_events(struct perf_session *session, return cs_etm__process_timeless_queues(etm, -1); } +static void cs_etm__free_traceid_queues(struct cs_etm_queue *etmq) +{ + int idx; + uintptr_t priv; + struct int_node *inode, *tmp; + struct cs_etm_traceid_queue *tidq; + struct intlist *traceid_queues_list = etmq->traceid_queues_list; + + intlist__for_each_entry_safe(inode, tmp, traceid_queues_list) { + priv = (uintptr_t)inode->priv; + idx = priv; + + /* Free this traceid_queue from the array */ + tidq = etmq->traceid_queues[idx]; + thread__zput(tidq->thread); + zfree(&tidq->event_buf); + zfree(&tidq->last_branch); + zfree(&tidq->last_branch_rb); + zfree(&tidq->prev_packet); + zfree(&tidq->packet); + zfree(&tidq); + + /* + * Function intlist__remove() removes the inode from the list + * and delete the memory associated to it. + */ + intlist__remove(traceid_queues_list, inode); + } + + /* Then the RB tree itself */ + intlist__delete(traceid_queues_list); + etmq->traceid_queues_list = NULL; + + /* finally free the traceid_queues array */ + free(etmq->traceid_queues); + etmq->traceid_queues = NULL; +} + static void cs_etm__free_queue(void *priv) { struct cs_etm_queue *etmq = priv; @@ -419,14 +500,8 @@ static void cs_etm__free_queue(void *priv) if (!etmq) return; - thread__zput(etmq->traceid_queues->thread); cs_etm_decoder__free(etmq->decoder); - zfree(&etmq->traceid_queues->event_buf); - zfree(&etmq->traceid_queues->last_branch); - zfree(&etmq->traceid_queues->last_branch_rb); - zfree(&etmq->traceid_queues->prev_packet); - zfree(&etmq->traceid_queues->packet); - zfree(&etmq->traceid_queues); + cs_etm__free_traceid_queues(etmq); free(etmq); } @@ -497,19 +572,21 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u8 trace_chan_id, u8 cpumode; u64 offset; int len; - struct thread *thread; - struct machine *machine; - struct addr_location al; - - (void)trace_chan_id; + struct thread *thread; + struct machine *machine; + struct addr_location al; + struct cs_etm_traceid_queue *tidq; if (!etmq) return 0; machine = etmq->etm->machine; cpumode = cs_etm__cpu_mode(etmq, address); + tidq = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id); + if (!tidq) + return 0; - thread = etmq->traceid_queues->thread; + thread = tidq->thread; if (!thread) { if (cpumode != PERF_RECORD_MISC_KERNEL) return 0; @@ -545,6 +622,10 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm) if (!etmq) return NULL; + etmq->traceid_queues_list = intlist__new(NULL); + if (!etmq->traceid_queues_list) + goto out_free; + /* Use metadata to fill in trace parameters for trace decoder */ t_params = zalloc(sizeof(*t_params) * etm->num_cpu); @@ -579,6 +660,7 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm) out_free_decoder: cs_etm_decoder__free(etmq->decoder); out_free: + intlist__delete(etmq->traceid_queues_list); free(etmq); return NULL; @@ -1280,8 +1362,9 @@ static bool cs_etm__is_svc_instr(struct cs_etm_queue *etmq, u8 trace_chan_id, struct cs_etm_packet *packet, u64 end_addr) { - u16 instr16; - u32 instr32; + /* Initialise to keep compiler happy */ + u16 instr16 = 0; + u32 instr32 = 0; u64 addr; switch (packet->isa) { From patchwork Fri May 24 17:35:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165149 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3885442ili; Fri, 24 May 2019 10:35:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNrBKcqnJ3bq+nyNEuEX8WvP0joqbOq4LTtRpxql4Wo+zCls917Rqq8kblUl2YdklONauZ X-Received: by 2002:a63:d70b:: with SMTP id d11mr104487596pgg.178.1558719334588; Fri, 24 May 2019 10:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719334; cv=none; d=google.com; s=arc-20160816; b=FsXVhafKzJx1X/9B4Akd2uEcynoUnijwD4zsku+5N8BoGwVg3vqmOYUlf99AKCBeje Xy8aknnp+o9RbS9e8hvJOlhCHWG762nbbnVcCW5LABfxwdLFpPC7QVGM/0EmgApmaE8t 5ncrBuy+o+ijON5YCL30DHal/JWsweP1E0NWN/d1y3ofkxQu2yMcg2NSr2y0PbEjslEf 8fSY4e7OAgnb77gCQcCRhiYH+FS8fK1GIytcvKZQ3kSN23K9G/rxRMI62+dgrsGzS0TG Yc2gH7cHKAzx+piOaMXf4DO7/jxEj83P8N5YHVd+dQJWL0MJhMBvxxDQIdjMTObOGYdN sqoA== 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; bh=YLacy1WPwP51koJcLQmVsZoOnuNjPchkGCoMeaoSKY0=; b=Aj8/vvvEdy0k0a/i1AO02+0noHBGJHqQVewZmKxv+N77rXqAcmg1gCJI/6ddaS8VSC RH78jcD3wlGe931BhYMvkM56QSfUaHSnmri2Ijfdxfieg9IESO/47yGZBvnpBTecKIbL YmklE617vaRj/oxbaUj8VUzlHMokNdLFDW4Z0Qszstr9bIO1nkAUdZZy5Vy2zGc/hKPv 8PDPmmMVXOzlQdnOwhvMSjYNGHjp/gpUSu0GEzXyVS+nWmWfC8SCrE0N0wJPMsdC1YjR OOfmw+5PkgE5zn8kbd8NzW4cqfw3zEVIZLtNMLzESS0gt3Ek00iuSduRE0qcvdt17Jf+ p+Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PbMf7J/q"; 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 b21si5608091pfp.109.2019.05.24.10.35.34; Fri, 24 May 2019 10:35:34 -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="PbMf7J/q"; 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 S2404041AbfEXRfc (ORCPT + 30 others); Fri, 24 May 2019 13:35:32 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:39925 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403760AbfEXRfa (ORCPT ); Fri, 24 May 2019 13:35:30 -0400 Received: by mail-pl1-f194.google.com with SMTP id g9so4428410plm.6 for ; Fri, 24 May 2019 10:35:29 -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=YLacy1WPwP51koJcLQmVsZoOnuNjPchkGCoMeaoSKY0=; b=PbMf7J/qOFFHjE14/KNNPvY5OfVNXGAe0ZimeRsh0+rhLDvruXtj++2+flmB2aGIaC s9IJ4Q07SsfQ0xgio00zDFvPj04UUUwFfL2LAk3O66Ap8wxFMqF/d3OXCMQpafm0tCHM FgZEG9btQkW6KQsNFbFWhBsijEyH9j+cCvnkdNzUOwt83fDO3QC2DTAO1QCt0zZIHQnh B3OfDA+GZvx5L3HchUBTZIUHB8wvcq1YktzCW9t5ZDB4awLNqgYxfn1UoET7UMavxAde WeaIBdbapBVQriocvrZnP5kONla55nKGETkfkzVPYaGxZkUTkEwl3iv8Qw9/sDpM0E8F SOgA== 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=YLacy1WPwP51koJcLQmVsZoOnuNjPchkGCoMeaoSKY0=; b=sd/B6iVdcvRWrvWwHuyO8GiOTvoTgAsW0xb3ksyeyskpMymozc8v1onIZx8pv0wfN8 /AZY/Q26/bNO20KwzEhY8PuVIRyiwVE92/raT2tI3yIKzb9gKwsFRiRyDzamyUXi0lX1 1yKlYhwBZIeRGdCbGee5Jgu/tYDlXFQitGbWhbLhq/WSFBeLHicHKFylr7imjrTZlV9p cpQD1fLuxELCyBt7275Shw3AFrYKl8VQRiOCahd04CVLJklOnubMKYvP1OjEDHDzQpFi dJD9V/CW99qOmumlCuxdRGK9QZ26Bm1iBX+VytaP2y9n78NTfBDtkT79OQB9JWCLTF4j byGQ== X-Gm-Message-State: APjAAAVVKJCvXyu+i2MdjX6pgkPopeOcD/gtxDcLhEKPmhxmoFSWUCaz NVTHxVhYxGJxhi1nfocSijWxBA== X-Received: by 2002:a17:902:b095:: with SMTP id p21mr56107478plr.270.1558719329130; Fri, 24 May 2019 10:35:29 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:28 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 15/17] perf tools: Linking PE contextID with perf thread mechanic Date: Fri, 24 May 2019 11:35:06 -0600 Message-Id: <20190524173508.29044-16-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Link contextID packets received from the decoder with the perf tool thread mechanic so that we know the specifics of the process currently executing. Signed-off-by: Mathieu Poirier --- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 20 ++++++++++++ tools/perf/util/cs-etm.c | 32 +++++++++++++++---- tools/perf/util/cs-etm.h | 10 ++++++ 3 files changed, 56 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index 87264b79de0e..ce85e52f989c 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -402,6 +402,24 @@ cs_etm_decoder__buffer_exception_ret(struct cs_etm_packet_queue *queue, CS_ETM_EXCEPTION_RET); } +static ocsd_datapath_resp_t +cs_etm_decoder__set_tid(struct cs_etm_queue *etmq, + const ocsd_generic_trace_elem *elem, + const uint8_t trace_chan_id) +{ + pid_t tid; + + /* Ignore PE_CONTEXT packets that don't have a valid contextID */ + if (!elem->context.ctxt_id_valid) + return OCSD_RESP_CONT; + + tid = elem->context.context_id; + if (cs_etm__etmq_set_tid(etmq, tid, trace_chan_id)) + return OCSD_RESP_FATAL_SYS_ERR; + + return OCSD_RESP_CONT; +} + static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( const void *context, const ocsd_trc_index_t indx __maybe_unused, @@ -440,6 +458,8 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( trace_chan_id); break; case OCSD_GEN_TRC_ELEM_PE_CONTEXT: + resp = cs_etm_decoder__set_tid(etmq, elem, trace_chan_id); + break; case OCSD_GEN_TRC_ELEM_ADDR_NACC: case OCSD_GEN_TRC_ELEM_TIMESTAMP: case OCSD_GEN_TRC_ELEM_CYCLE_COUNT: diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index afc2491f9f2a..17adf554b679 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -907,13 +907,8 @@ cs_etm__get_trace(struct cs_etm_queue *etmq) } static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm, - struct auxtrace_queue *queue, struct cs_etm_traceid_queue *tidq) { - /* CPU-wide tracing isn't supported yet */ - if (queue->tid == -1) - return; - if ((!tidq->thread) && (tidq->tid != -1)) tidq->thread = machine__find_thread(etm->machine, -1, tidq->tid); @@ -922,6 +917,31 @@ static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm, tidq->pid = tidq->thread->pid_; } +int cs_etm__etmq_set_tid(struct cs_etm_queue *etmq, + pid_t tid, u8 trace_chan_id) +{ + int cpu, err = -EINVAL; + struct cs_etm_auxtrace *etm = etmq->etm; + struct cs_etm_traceid_queue *tidq; + + tidq = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id); + if (!tidq) + return err; + + if (cs_etm__get_cpu(trace_chan_id, &cpu) < 0) + return err; + + err = machine__set_current_tid(etm->machine, cpu, tid, tid); + if (err) + return err; + + tidq->tid = tid; + thread__zput(tidq->thread); + + cs_etm__set_pid_tid_cpu(etm, tidq); + return 0; +} + static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, struct cs_etm_traceid_queue *tidq, u64 addr, u64 period) @@ -1866,7 +1886,7 @@ static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm, continue; if ((tid == -1) || (tidq->tid == tid)) { - cs_etm__set_pid_tid_cpu(etm, queue, tidq); + cs_etm__set_pid_tid_cpu(etm, tidq); cs_etm__run_decoder(etmq); } } diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index f16082d37ab5..b2a7628620bf 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -181,6 +181,8 @@ struct cs_etm_packet_queue { int cs_etm__process_auxtrace_info(union perf_event *event, struct perf_session *session); int cs_etm__get_cpu(u8 trace_chan_id, int *cpu); +int cs_etm__etmq_set_tid(struct cs_etm_queue *etmq, + pid_t tid, u8 trace_chan_id); struct cs_etm_packet_queue *cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id); #else @@ -197,6 +199,14 @@ static inline int cs_etm__get_cpu(u8 trace_chan_id __maybe_unused, return -1; } +static inline int cs_etm__etmq_set_tid( + struct cs_etm_queue *etmq __maybe_unused, + pid_t tid __maybe_unused, + u8 trace_chan_id __maybe_unused) +{ + return -1; +} + static inline struct cs_etm_packet_queue *cs_etm__etmq_get_packet_queue( struct cs_etm_queue *etmq __maybe_unused, u8 trace_chan_id __maybe_unused) From patchwork Fri May 24 17:35:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165150 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3885525ili; Fri, 24 May 2019 10:35:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxZgbXiADs0em6rr+C42pAxg2zohqHtxA6sn/noTPYALXVqSEFMSQq3s/c9w+YvsMNyz/u X-Received: by 2002:aa7:9356:: with SMTP id 22mr12646699pfn.188.1558719339520; Fri, 24 May 2019 10:35:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719339; cv=none; d=google.com; s=arc-20160816; b=qBzRrLvI/xyNrFeXvjPVzhBReUf0vYCi9p924EhNz9Y/N3sRGhciFMLlTx6vDbay5g PYrId0VTUK7JIwhLCY96zZXpmeYKklFFpUdjadXK98+TD82kBmkfu/xJw3Mh8SyBD4jL Wogt/hJkd3e6bpcjbWu04IAzl/VVL7urQ/5J3wEmM3h+Txz8mU9KpKlvgiOJqyy3vTVR r4FkmcN5zxQky7+cpFliGNchRJ52uLK08wEchLW0u8byU3D6j8lfiqc2Tcs/tqcCuesD 7k4Eji4e8S4z5XA+D79O6Juozqyels06/6/U0KEt84S+vi8vKAsU/pwUVFUTnL60YGM4 f3fA== 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; bh=TcueIJVjFnLykFgMSjp27lPW+9DE4r6pPvomdOZtTnM=; b=JwpyCn/qs5CYkGjNEdKR/gIvOJ59+yink1BLlirBW0xEBheaUOdebk+0OlMLVuanVX 26FjQcs/MiZqZ9l5hq3epwxKzIEcRpapJtuF7m1aMAHWAdmOm8+hBdLV/Ole4KbgRgKI QPixoiwPPca1vCy4amOLsvFUEurU0cY68yz+x+rZb6N37jwmDBWaU0i9uNTL7v2bWRcp LHWraJIQnWfIjHw2nS2MX1lLZGYTcroS9EQfZri8W1J0kIzwNI4Iuw6e294BEXIKWtKE QoIYYVdqwwXx7mgKxySIoe1ESOebtx32kFFoodUj4j4jpfMEw5dfs/uU/5MkqqT6xgFY OjQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=emGCqNKt; 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 b21si5608091pfp.109.2019.05.24.10.35.39; Fri, 24 May 2019 10:35:39 -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=emGCqNKt; 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 S2404114AbfEXRfi (ORCPT + 30 others); Fri, 24 May 2019 13:35:38 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:41240 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403986AbfEXRfb (ORCPT ); Fri, 24 May 2019 13:35:31 -0400 Received: by mail-pg1-f195.google.com with SMTP id z3so800386pgp.8 for ; Fri, 24 May 2019 10:35:30 -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=TcueIJVjFnLykFgMSjp27lPW+9DE4r6pPvomdOZtTnM=; b=emGCqNKtTJalfThxnAoLwnMgxJmSsue6enOXFLCNWjlsZtwrGnBIVJMadeKoNQxggH djSKPPrGCwvGxy2aCIVh8sx8hNZta1DeAjbacL9JnQet4FNEp416lG/WrVdvRqtpo485 +0YPLNj+i3ylDuMcs3LbeoNJWTGOoP8/E0najIq6f5CbbmAZt0xLiYxX0F0pHTyWtDeV 8e0+Thv4QsRa2DQAFLhLAGjN20Ng9pZdPENyjYE+leDOKOtyls5iURFjshw2z54gskTX yBEW5WLD+6cNN+iZA8ShiaUZaYt2nUni6JbgeZrgDa7mExfMhPY5Hx9HiamfWQLpyVr0 DhSw== 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=TcueIJVjFnLykFgMSjp27lPW+9DE4r6pPvomdOZtTnM=; b=fZUvLJGzOhF9pqcnPlowWX+GddhHM/5sKyDO6m7yZYfCKsTl0iCRQcY90FkMXdw1nT AkLQLf0iY36AxWLaEwvBZ57teLWhQkETODCMZ1yDr9h51mC5oSRbk0/JDBcWGfPOmu1Z IsJ+V6aURWD/D4DaZ8Xai6Y7yWWskkTAFp67wWXMk8HgNrPPe8GdpMbxvDfWvMsm3R0/ uEye9mfDp6xA9+6JklOuYhl9BgJYQAIYkTfd2P5OEGKJUFg53OmX3N41buiDMsi5F8Kq PBZi/Ul4ZNrKLpeVwvZhQt1HHeHhLYGTRymb4yVYeQIoHOjaQDpIesS2Ety80xEW2XjC 7vOA== X-Gm-Message-State: APjAAAV6dc4xS/tu65zYjqnK8gOGYgKlpUw1M1AMMDzFd2AUXUmoCsDd 5JxbjnjIMZ81W9HPJ1tGrDODxw== X-Received: by 2002:a63:4c1c:: with SMTP id z28mr15815648pga.122.1558719330383; Fri, 24 May 2019 10:35:30 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:29 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 16/17] perf tools: Add notion of time to decoding code Date: Fri, 24 May 2019 11:35:07 -0600 Message-Id: <20190524173508.29044-17-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-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 deals with timestamp packets received from the decoding library in order to give the front end packet processing loop a handle on the time instruction conveyed by range packets have been executed at. Signed-off-by: Mathieu Poirier --- .../perf/util/cs-etm-decoder/cs-etm-decoder.c | 112 +++++++++++++++++- tools/perf/util/cs-etm.c | 19 +++ tools/perf/util/cs-etm.h | 17 +++ 3 files changed, 144 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index ce85e52f989c..33e975c8d11b 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -269,6 +269,76 @@ cs_etm_decoder__create_etm_packet_printer(struct cs_etm_trace_params *t_params, trace_config); } +static ocsd_datapath_resp_t +cs_etm_decoder__do_soft_timestamp(struct cs_etm_queue *etmq, + struct cs_etm_packet_queue *packet_queue, + const uint8_t trace_chan_id) +{ + /* No timestamp packet has been received, nothing to do */ + if (!packet_queue->timestamp) + return OCSD_RESP_CONT; + + packet_queue->timestamp = packet_queue->next_timestamp; + + /* Estimate the timestamp for the next range packet */ + packet_queue->next_timestamp += packet_queue->instr_count; + packet_queue->instr_count = 0; + + /* Tell the front end which traceid_queue needs attention */ + cs_etm__etmq_set_traceid_queue_timestamp(etmq, trace_chan_id); + + return OCSD_RESP_WAIT; +} + +static ocsd_datapath_resp_t +cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq, + const ocsd_generic_trace_elem *elem, + const uint8_t trace_chan_id) +{ + struct cs_etm_packet_queue *packet_queue; + + /* First get the packet queue for this traceID */ + packet_queue = cs_etm__etmq_get_packet_queue(etmq, trace_chan_id); + if (!packet_queue) + return OCSD_RESP_FATAL_SYS_ERR; + + /* + * We've seen a timestamp packet before - simply record the new value. + * Function do_soft_timestamp() will report the value to the front end, + * hence asking the decoder to keep decoding rather than stopping. + */ + if (packet_queue->timestamp) { + packet_queue->next_timestamp = elem->timestamp; + return OCSD_RESP_CONT; + } + + /* + * This is the first timestamp we've seen since the beginning of traces + * or a discontinuity. Since timestamps packets are generated *after* + * range packets have been generated, we need to estimate the time at + * which instructions started by substracting the number of instructions + * executed to the timestamp. + */ + packet_queue->timestamp = elem->timestamp - + packet_queue->instr_count; + packet_queue->next_timestamp = elem->timestamp; + packet_queue->instr_count = 0; + + /* Tell the front end which traceid_queue needs attention */ + cs_etm__etmq_set_traceid_queue_timestamp(etmq, trace_chan_id); + + /* Halt processing until we are being told to proceed */ + return OCSD_RESP_WAIT; +} + +static void +cs_etm_decoder__reset_timestamp(struct cs_etm_packet_queue *packet_queue) +{ + packet_queue->timestamp = 0; + packet_queue->next_timestamp = 0; + packet_queue->instr_count = 0; +} + static ocsd_datapath_resp_t cs_etm_decoder__buffer_packet(struct cs_etm_packet_queue *packet_queue, const u8 trace_chan_id, @@ -310,7 +380,8 @@ cs_etm_decoder__buffer_packet(struct cs_etm_packet_queue *packet_queue, } static ocsd_datapath_resp_t -cs_etm_decoder__buffer_range(struct cs_etm_packet_queue *packet_queue, +cs_etm_decoder__buffer_range(struct cs_etm_queue *etmq, + struct cs_etm_packet_queue *packet_queue, const ocsd_generic_trace_elem *elem, const uint8_t trace_chan_id) { @@ -365,6 +436,23 @@ cs_etm_decoder__buffer_range(struct cs_etm_packet_queue *packet_queue, packet->last_instr_size = elem->last_instr_sz; + /* per-thread scenario, no need to generate a timestamp */ + if (cs_etm__etmq_is_timeless(etmq)) + goto out; + + /* + * The packet queue is full and we haven't seen a timestamp (had we + * seen one the packet queue wouldn't be full). Let the front end + * deal with it. + */ + if (ret == OCSD_RESP_WAIT) + goto out; + + packet_queue->instr_count += elem->num_instr_range; + /* Tell the front end we have a new timestamp to process */ + ret = cs_etm_decoder__do_soft_timestamp(etmq, packet_queue, + trace_chan_id); +out: return ret; } @@ -372,6 +460,11 @@ static ocsd_datapath_resp_t cs_etm_decoder__buffer_discontinuity(struct cs_etm_packet_queue *queue, const uint8_t trace_chan_id) { + /* + * Something happened and who knows when we'll get new traces so + * reset time statistics. + */ + cs_etm_decoder__reset_timestamp(queue); return cs_etm_decoder__buffer_packet(queue, trace_chan_id, CS_ETM_DISCONTINUITY); } @@ -404,6 +497,7 @@ cs_etm_decoder__buffer_exception_ret(struct cs_etm_packet_queue *queue, static ocsd_datapath_resp_t cs_etm_decoder__set_tid(struct cs_etm_queue *etmq, + struct cs_etm_packet_queue *packet_queue, const ocsd_generic_trace_elem *elem, const uint8_t trace_chan_id) { @@ -417,6 +511,12 @@ cs_etm_decoder__set_tid(struct cs_etm_queue *etmq, if (cs_etm__etmq_set_tid(etmq, tid, trace_chan_id)) return OCSD_RESP_FATAL_SYS_ERR; + /* + * A timestamp is generated after a PE_CONTEXT element so make sure + * to rely on that coming one. + */ + cs_etm_decoder__reset_timestamp(packet_queue); + return OCSD_RESP_CONT; } @@ -446,7 +546,7 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( trace_chan_id); break; case OCSD_GEN_TRC_ELEM_INSTR_RANGE: - resp = cs_etm_decoder__buffer_range(packet_queue, elem, + resp = cs_etm_decoder__buffer_range(etmq, packet_queue, elem, trace_chan_id); break; case OCSD_GEN_TRC_ELEM_EXCEPTION: @@ -457,11 +557,15 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( resp = cs_etm_decoder__buffer_exception_ret(packet_queue, trace_chan_id); break; + case OCSD_GEN_TRC_ELEM_TIMESTAMP: + resp = cs_etm_decoder__do_hard_timestamp(etmq, elem, + trace_chan_id); + break; case OCSD_GEN_TRC_ELEM_PE_CONTEXT: - resp = cs_etm_decoder__set_tid(etmq, elem, trace_chan_id); + resp = cs_etm_decoder__set_tid(etmq, packet_queue, + elem, trace_chan_id); break; case OCSD_GEN_TRC_ELEM_ADDR_NACC: - case OCSD_GEN_TRC_ELEM_TIMESTAMP: case OCSD_GEN_TRC_ELEM_CYCLE_COUNT: case OCSD_GEN_TRC_ELEM_ADDR_UNKNOWN: case OCSD_GEN_TRC_ELEM_EVENT: diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 17adf554b679..91496a3a2209 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -80,6 +80,7 @@ struct cs_etm_queue { struct cs_etm_decoder *decoder; struct auxtrace_buffer *buffer; unsigned int queue_nr; + u8 pending_timestamp; u64 offset; const unsigned char *buf; size_t buf_len, buf_used; @@ -133,6 +134,19 @@ int cs_etm__get_cpu(u8 trace_chan_id, int *cpu) return 0; } +void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, + u8 trace_chan_id) +{ + /* + * Wnen a timestamp packet is encountered the backend code + * is stopped so that the front end has time to process packets + * that were accumulated in the traceID queue. Since there can + * be more than one channel per cs_etm_queue, we need to specify + * what traceID queue needs servicing. + */ + etmq->pending_timestamp = trace_chan_id; +} + static void cs_etm__clear_packet_queue(struct cs_etm_packet_queue *queue) { int i; @@ -942,6 +956,11 @@ int cs_etm__etmq_set_tid(struct cs_etm_queue *etmq, return 0; } +bool cs_etm__etmq_is_timeless(struct cs_etm_queue *etmq) +{ + return !!etmq->etm->timeless_decoding; +} + static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, struct cs_etm_traceid_queue *tidq, u64 addr, u64 period) diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index b2a7628620bf..33b57e748c3d 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -150,6 +150,9 @@ struct cs_etm_packet_queue { u32 packet_count; u32 head; u32 tail; + u32 instr_count; + u64 timestamp; + u64 next_timestamp; struct cs_etm_packet packet_buffer[CS_ETM_PACKET_MAX_BUFFER]; }; @@ -183,6 +186,9 @@ int cs_etm__process_auxtrace_info(union perf_event *event, int cs_etm__get_cpu(u8 trace_chan_id, int *cpu); int cs_etm__etmq_set_tid(struct cs_etm_queue *etmq, pid_t tid, u8 trace_chan_id); +bool cs_etm__etmq_is_timeless(struct cs_etm_queue *etmq); +void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, + u8 trace_chan_id); struct cs_etm_packet_queue *cs_etm__etmq_get_packet_queue(struct cs_etm_queue *etmq, u8 trace_chan_id); #else @@ -207,6 +213,17 @@ static inline int cs_etm__etmq_set_tid( return -1; } +static inline bool cs_etm__etmq_is_timeless( + struct cs_etm_queue *etmq __maybe_unused) +{ + /* What else to return? */ + return true; +} + +static inline void cs_etm__etmq_set_traceid_queue_timestamp( + struct cs_etm_queue *etmq __maybe_unused, + u8 trace_chan_id __maybe_unused) {} + static inline struct cs_etm_packet_queue *cs_etm__etmq_get_packet_queue( struct cs_etm_queue *etmq __maybe_unused, u8 trace_chan_id __maybe_unused) From patchwork Fri May 24 17:35:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 165151 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3885577ili; Fri, 24 May 2019 10:35:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLsY575wXA4ANKgclht+sle9nLPJp3kCaWhrJQJqhx47KbvzUgumS1iLODY04F0L6bWJG4 X-Received: by 2002:a62:e0cb:: with SMTP id d72mr21155470pfm.242.1558719342051; Fri, 24 May 2019 10:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558719342; cv=none; d=google.com; s=arc-20160816; b=XHgoZPrYcGZKz2G+iLzn/lEMl+9YQE4QvLixEkMlYqTgZQ8/t3EXj42wa7S5U5i4Dk 4GPogDnJd9OXMnMekug1b4Tkc/mmY8+iVURet5KgvAT0/JbWr+Mp3rIGwuUpdZkW66XP xmF63BH5dc+l0PstYSbxJFs/cu8mEhoPclvIsWAkFhofDgDyxh6Aee+L9ITSR71Li/k3 DH6lLZclaHHO3rGQ9nH9TUrsMOH5gzKd0uakDuIX6KOw888ZmtwDeaBFOW8A1XHqz2B+ OatLpAsyZKl1f4xiLjxUmLEBiS4EbWbUDiCKgIV/eYfrpazNSe4rF1oOH7gYi+QYrF6+ qLVQ== 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; bh=kCvwFMGwRnGuZeRHJ6YgvFt4aJih6OXfy9LKk/iBWu0=; b=lU7NGZHZWKO+HWOxKnafl7mGhVMutvrf/LpN/5pa0ol+gxp2jPwqR66nMfU/jdgGzH GbPOnLYT9ikTAbzqHEJZXLhS+LjTEdDmlmaJXNLPB4bQ1qDuLuguciLYH0BeGlsCh3C3 kGqmuZFqlqRFvkB8G4C/55LvSJX3Qd1b2VSMqia/noN1hsoq+ovpp+gjmsfxLEJdDz+p /JF+ONLpXU5OcVSw9mV61bCXbvG4awuqb9j9pNjvupgp+Uo28F28QA76YQ4yEGm5UJnx az1IcOnbDIGiBj0tR/qGYHnd6gk+zuouE5Oz2l6bTKWeMjtFR7psHaYwls2yaAh9lq6r JwnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YQ7y26+f; 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 m2si4870297pgv.89.2019.05.24.10.35.41; Fri, 24 May 2019 10:35:42 -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=YQ7y26+f; 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 S2404093AbfEXRff (ORCPT + 30 others); Fri, 24 May 2019 13:35:35 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:39930 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404038AbfEXRfc (ORCPT ); Fri, 24 May 2019 13:35:32 -0400 Received: by mail-pl1-f195.google.com with SMTP id g9so4428466plm.6 for ; Fri, 24 May 2019 10:35:32 -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=kCvwFMGwRnGuZeRHJ6YgvFt4aJih6OXfy9LKk/iBWu0=; b=YQ7y26+fKhvVQjSu+oATI8VWV5sKICSnn1gYagomwkRM5EM0xTvt8dx8FFsnXt6Cx2 vH8qWqmfDGIoJyZGTapGgbLNAqw1RfOQjPKsNiKLjMG73JIX+nXuiZvZ7vOQbyQHrRrl Yhw82DHWeUyC76mE51BiQZQIbs0q0UMapGnOz26tR07jh/cXlOqbXwblPRN4agvY/z06 Gwg18gWvOMVt8Zl5tcflXwtXYwgRBgWwsUJKFQXMkKc945syyTd9RY8eumUxwTRAYcUv bD5aW0olejWezjqDFzxIxsDb9h4CPR/WVb9PpfWGRSGZHrBFkyNt8gV0iNSGQfP4S114 AWBg== 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=kCvwFMGwRnGuZeRHJ6YgvFt4aJih6OXfy9LKk/iBWu0=; b=iW0CswO6gTy1Op8DvopKOq5uPGUzIKV9LGWpJW59PLjA1y9T4zFDNuFVPmQSEO5z7o SGJ8gnTAcJKcLfvCQ+FlPVb2ahZL4UJ24R/rz8nGg1nkhMVaAgQ7dxITJ6hiYTSr/uvH rjPPs4EUbH9ad17Lusua7ErZRsIjAMOLlmbnsC0XuHca+Rn+lehS/8ewUCs+Ydkr+D3y nulUKddz+d7MsHz6j8lOzXIBLiL63ZzxooGA1XDkK/o2pN7QhM/IvUJgoYIl62Yv+q8X 3cTx3q+tq44SPljO0qf3WKd9UZ4OGWx7KCJmBFdHGdYY8bhCSdTPCkB1vqr4t0FGSnWA CP9A== X-Gm-Message-State: APjAAAV+bb5Gy36ksZ29ZY8TMHEfEBkgK345Fr44YLAGff2Jflf5GTyX AYUcvTdwgjYjntIS6/+jjdDKgg== X-Received: by 2002:a17:902:bf4a:: with SMTP id u10mr3881439pls.56.1558719331612; Fri, 24 May 2019 10:35:31 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id k13sm2809575pgr.90.2019.05.24.10.35.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 May 2019 10:35:31 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Subject: [PATCH v2 17/17] perf tools: Add support for CPU-wide trace scenarios Date: Fri, 24 May 2019 11:35:08 -0600 Message-Id: <20190524173508.29044-18-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190524173508.29044-1-mathieu.poirier@linaro.org> References: <20190524173508.29044-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for CPU-wide trace scenarios by correlating range packets with timestamp packets. That way range packets received on different ETMQ/traceID channels can be processed and synthesized in chronological order. Signed-off-by: Mathieu Poirier --- tools/perf/util/cs-etm.c | 254 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 246 insertions(+), 8 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 91496a3a2209..0c7776b51045 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -90,12 +90,26 @@ struct cs_etm_queue { }; static int cs_etm__update_queues(struct cs_etm_auxtrace *etm); +static int cs_etm__process_queues(struct cs_etm_auxtrace *etm); static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm, pid_t tid); +static int cs_etm__get_data_block(struct cs_etm_queue *etmq); +static int cs_etm__decode_data_block(struct cs_etm_queue *etmq); /* PTMs ETMIDR [11:8] set to b0011 */ #define ETMIDR_PTM_VERSION 0x00000300 +/* + * A struct auxtrace_heap_item only has a queue_nr and a timestamp to + * work with. One option is to modify to auxtrace_heap_XYZ() API or simply + * encode the etm queue number as the upper 16 bit and the channel as + * the lower 16 bit. + */ +#define TO_CS_QUEUE_NR(queue_nr, trace_id_chan) \ + (queue_nr << 16 | trace_chan_id) +#define TO_QUEUE_NR(cs_queue_nr) (cs_queue_nr >> 16) +#define TO_TRACE_CHAN_ID(cs_queue_nr) (cs_queue_nr & 0x0000ffff) + static u32 cs_etm__get_v7_protocol_version(u32 etmidr) { etmidr &= ETMIDR_PTM_VERSION; @@ -147,6 +161,29 @@ void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq, etmq->pending_timestamp = trace_chan_id; } +static u64 cs_etm__etmq_get_timestamp(struct cs_etm_queue *etmq, + u8 *trace_chan_id) +{ + struct cs_etm_packet_queue *packet_queue; + + if (!etmq->pending_timestamp) + return 0; + + if (trace_chan_id) + *trace_chan_id = etmq->pending_timestamp; + + packet_queue = cs_etm__etmq_get_packet_queue(etmq, + etmq->pending_timestamp); + if (!packet_queue) + return 0; + + /* Acknowledge pending status */ + etmq->pending_timestamp = 0; + + /* See function cs_etm_decoder__do_{hard|soft}_timestamp() */ + return packet_queue->timestamp; +} + static void cs_etm__clear_packet_queue(struct cs_etm_packet_queue *queue) { int i; @@ -171,6 +208,20 @@ static void cs_etm__clear_packet_queue(struct cs_etm_packet_queue *queue) } } +static void cs_etm__clear_all_packet_queues(struct cs_etm_queue *etmq) +{ + int idx; + struct int_node *inode; + struct cs_etm_traceid_queue *tidq; + struct intlist *traceid_queues_list = etmq->traceid_queues_list; + + intlist__for_each_entry(inode, traceid_queues_list) { + idx = (int)(intptr_t)inode->priv; + tidq = etmq->traceid_queues[idx]; + cs_etm__clear_packet_queue(&tidq->packet_queue); + } +} + static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq, struct cs_etm_traceid_queue *tidq, u8 trace_chan_id) @@ -458,15 +509,15 @@ static int cs_etm__flush_events(struct perf_session *session, 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); + if (etm->timeless_decoding) + return cs_etm__process_timeless_queues(etm, -1); + + return cs_etm__process_queues(etm); } static void cs_etm__free_traceid_queues(struct cs_etm_queue *etmq) @@ -685,6 +736,9 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, unsigned int queue_nr) { int ret = 0; + unsigned int cs_queue_nr; + u8 trace_chan_id; + u64 timestamp; struct cs_etm_queue *etmq = queue->priv; if (list_empty(&queue->head) || etmq) @@ -702,6 +756,67 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm, etmq->queue_nr = queue_nr; etmq->offset = 0; + if (etm->timeless_decoding) + goto out; + + /* + * We are under a CPU-wide trace scenario. As such we need to know + * when the code that generated the traces started to execute so that + * it can be correlated with execution on other CPUs. So we get a + * handle on the beginning of traces and decode until we find a + * timestamp. The timestamp is then added to the auxtrace min heap + * in order to know what nibble (of all the etmqs) to decode first. + */ + while (1) { + /* + * Fetch an aux_buffer from this etmq. Bail if no more + * blocks or an error has been encountered. + */ + ret = cs_etm__get_data_block(etmq); + if (ret <= 0) + goto out; + + /* + * Run decoder on the trace block. The decoder will stop when + * encountering a timestamp, a full packet queue or the end of + * trace for that block. + */ + ret = cs_etm__decode_data_block(etmq); + if (ret) + goto out; + + /* + * Function cs_etm_decoder__do_{hard|soft}_timestamp() does all + * the timestamp calculation for us. + */ + timestamp = cs_etm__etmq_get_timestamp(etmq, &trace_chan_id); + + /* We found a timestamp, no need to continue. */ + if (timestamp) + break; + + /* + * We didn't find a timestamp so empty all the traceid packet + * queues before looking for another timestamp packet, either + * in the current data block or a new one. Packets that were + * just decoded are useless since no timestamp has been + * associated with them. As such simply discard them. + */ + cs_etm__clear_all_packet_queues(etmq); + } + + /* + * We have a timestamp. Add it to the min heap to reflect when + * instructions conveyed by the range packets of this traceID queue + * started to execute. Once the same has been done for all the traceID + * queues of each etmq, redenring and decoding can start in + * chronological order. + * + * Note that packets decoded above are still in the traceID's packet + * queue and will be processed in cs_etm__process_queues(). + */ + cs_queue_nr = TO_CS_QUEUE_NR(queue_nr, trace_id_chan); + ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, timestamp); out: return ret; } @@ -1846,6 +1961,28 @@ static int cs_etm__process_traceid_queue(struct cs_etm_queue *etmq, return ret; } +static void cs_etm__clear_all_traceid_queues(struct cs_etm_queue *etmq) +{ + int idx; + struct int_node *inode; + struct cs_etm_traceid_queue *tidq; + struct intlist *traceid_queues_list = etmq->traceid_queues_list; + + intlist__for_each_entry(inode, traceid_queues_list) { + idx = (int)(intptr_t)inode->priv; + tidq = etmq->traceid_queues[idx]; + + /* Ignore return value */ + cs_etm__process_traceid_queue(etmq, tidq); + + /* + * Generate an instruction sample with the remaining + * branchstack entries. + */ + cs_etm__flush(etmq, tidq); + } +} + static int cs_etm__run_decoder(struct cs_etm_queue *etmq) { int err = 0; @@ -1913,6 +2050,105 @@ static int cs_etm__process_timeless_queues(struct cs_etm_auxtrace *etm, return 0; } +static int cs_etm__process_queues(struct cs_etm_auxtrace *etm) +{ + int ret = 0; + unsigned int cs_queue_nr, queue_nr; + u8 trace_chan_id; + u64 timestamp; + struct auxtrace_queue *queue; + struct cs_etm_queue *etmq; + struct cs_etm_traceid_queue *tidq; + + while (1) { + if (!etm->heap.heap_cnt) + goto out; + + /* Take the entry at the top of the min heap */ + cs_queue_nr = etm->heap.heap_array[0].queue_nr; + queue_nr = TO_QUEUE_NR(cs_queue_nr); + trace_chan_id = TO_TRACE_CHAN_ID(cs_queue_nr); + queue = &etm->queues.queue_array[queue_nr]; + etmq = queue->priv; + + /* + * Remove the top entry from the heap since we are about + * to process it. + */ + auxtrace_heap__pop(&etm->heap); + + tidq = cs_etm__etmq_get_traceid_queue(etmq, trace_chan_id); + if (!tidq) { + /* + * No traceID queue has been allocated for this traceID, + * which means something somewhere went very wrong. No + * other choice than simply exit. + */ + ret = -EINVAL; + goto out; + } + + /* + * Packets associated with this timestamp are already in + * the etmq's traceID queue, so process them. + */ + ret = cs_etm__process_traceid_queue(etmq, tidq); + if (ret < 0) + goto out; + + /* + * Packets for this timestamp have been processed, time to + * move on to the next timestamp, fetching a new auxtrace_buffer + * if need be. + */ +refetch: + ret = cs_etm__get_data_block(etmq); + if (ret < 0) + goto out; + + /* + * No more auxtrace_buffers to process in this etmq, simply + * move on to another entry in the auxtrace_heap. + */ + if (!ret) + continue; + + ret = cs_etm__decode_data_block(etmq); + if (ret) + goto out; + + timestamp = cs_etm__etmq_get_timestamp(etmq, &trace_chan_id); + + if (!timestamp) { + /* + * Function cs_etm__decode_data_block() returns when + * there is no more traces to decode in the current + * auxtrace_buffer OR when a timestamp has been + * encountered on any of the traceID queues. Since we + * did not get a timestamp, there is no more traces to + * process in this auxtrace_buffer. As such empty and + * flush all traceID queues. + */ + cs_etm__clear_all_traceid_queues(etmq); + + /* Fetch another auxtrace_buffer for this etmq */ + goto refetch; + } + + /* + * Add to the min heap the timestamp for packets that have + * just been decoded. They will be processed and synthesized + * during the next call to cs_etm__process_traceid_queue() for + * this queue/traceID. + */ + cs_queue_nr = TO_CS_QUEUE_NR(queue_nr, trace_chan_id); + ret = auxtrace_heap__add(&etm->heap, cs_queue_nr, timestamp); + } + +out: + return ret; +} + static int cs_etm__process_itrace_start(struct cs_etm_auxtrace *etm, union perf_event *event) { @@ -1991,9 +2227,6 @@ static int cs_etm__process_event(struct perf_session *session, return -EINVAL; } - if (!etm->timeless_decoding) - return -EINVAL; - if (sample->time && (sample->time != (u64) -1)) timestamp = sample->time; else @@ -2005,7 +2238,8 @@ static int cs_etm__process_event(struct perf_session *session, return err; } - if (event->header.type == PERF_RECORD_EXIT) + if (etm->timeless_decoding && + event->header.type == PERF_RECORD_EXIT) return cs_etm__process_timeless_queues(etm, event->fork.tid); @@ -2014,6 +2248,10 @@ static int cs_etm__process_event(struct perf_session *session, else if (event->header.type == PERF_RECORD_SWITCH_CPU_WIDE) return cs_etm__process_switch_cpu_wide(etm, event); + if (!etm->timeless_decoding && + event->header.type == PERF_RECORD_AUX) + return cs_etm__process_queues(etm); + return 0; }