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)