Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5430927ybp; Mon, 14 Oct 2019 22:37:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNxUldlnDPEM1w7TbH3WnuT00PfJ6xm7dv9JUnWsD2Ym/qbThaSHlSsS+wP2C806hlURME X-Received: by 2002:a50:eb4d:: with SMTP id z13mr31383325edp.175.1571117823189; Mon, 14 Oct 2019 22:37:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571117823; cv=none; d=google.com; s=arc-20160816; b=rwDD6Orc2OgiLVx/cnDhpostcyPC+XeizY2YTDHaMDeupPpH0ZZRDqChvN6ZbhvMg6 W6vgNWGk9LNbbOsnHy1sIULyjl1VCEPWqERJukNFFd6wFLJ0U06uDj3AGeyhNYiywZaa YFnIcvn8wiUibXYmBVQAOS4DlCB9mb3nr8HnWmVU8jHnwmLRHwaX60CzB+btPzyvljye HV0O+Sl57OqvXSAkRKWsKqYN6fx4JwLRsUGRx1kXJ9XD+9hcLUQSzcY90bQxMpUT0s3x KPN1IU+cmY9lxtKuHPSi0tsWsowm7HL+bgi/9+J6F9ApQu6Vfq3MJO1gdZ2DtPXnt7uU HUBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=IoqlYSn6f47iVl1XpzbZCGv/lzEESLkqVt79Fah3kvU=; b=eWilvUpY58JmMxqK5/cmPu1O+jK18ZLvnyboeeU+bE1LMOI/7g7lbuMtL5xB88T7zN ygAbNod6GX/LNYCC021T+N3OEmR1kZ4GYlKiY1s8mGC70QugBLVuAN3t2j9F19w3KN6U zPAUF/ZUy+1hthXEITVn/1IW/NyEgGElXe7rQ23MySxZnNJWhdfHk0vFV/uS5V7A69D/ q3rENp0EAjkKyFSo6H9GkURpWMQVoMUV4Q2bo6nESsaMFcoAcNYT3/efhWY2RWzPCxhv rFo0QfTIon+7rSAGYg6gHVfw6wXXGN/ZHKwAubNgQvAgVL9gvWjyXbcHFVhog0qjwIgm Zhhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r364D0CX; 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 ok21si12621067ejb.95.2019.10.14.22.36.39; Mon, 14 Oct 2019 22:37:03 -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=r364D0CX; 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 S1727939AbfJODdk (ORCPT + 99 others); Mon, 14 Oct 2019 23:33:40 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:42570 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727931AbfJODdk (ORCPT ); Mon, 14 Oct 2019 23:33:40 -0400 Received: by mail-qt1-f194.google.com with SMTP id w14so28525426qto.9 for ; Mon, 14 Oct 2019 20:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=IoqlYSn6f47iVl1XpzbZCGv/lzEESLkqVt79Fah3kvU=; b=r364D0CXUs/RIyg+BE17NPnWLo7+lJLvcslcFTnRlcBnQ15kuedlF4dvMOOBlAt7w0 wQZLONeWcT+PqpWNjjdOgMdnNDTILLcVWJV1eI8+0VinCSriBxSV7UhF0JTnOmNhYITQ AUWtX/7PTApLH/QlyvGlsfwTDm9ZdYcQ6bHzw2T09dZLRRd9+b716K7i6N/+uAJQqf3B J52NG9bCO82Zt65nvxDtuXVlRx8kPM50d+aZaUtIz15J16RJUil4WdpnTGBoRXPMxs/F /ZUIWjgGN/wW9GTUu8uyjEw1IvuORXMPZFZjbrHcr4hgr//V8hnN4Gds/UMW6FbhjtEp lfpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=IoqlYSn6f47iVl1XpzbZCGv/lzEESLkqVt79Fah3kvU=; b=muIMYO1EIOPpG1V8NFpd3V1bNcvbKGpf3h5UbTK8NJsCvanz3aXJfJj/GTaYkUuxeB Unn/WdF4Jylwz4ZuQZfXsDJzJlNDdkokn445CundlCPOGVogYflesiI9T5J7YToXy1jH nL3mmCzZWVwDcayevKfGwYJWoOw2ZpBIvzZHKqKuvq+BlKyt4KvaIzJvZBTyq+FBPSsb a9QI8dlyVBF+OACu8UCE2rfj59D4zAb9aBxGIsnO/anqa72ct51zuL4BUOHsE0LE6143 wqtmTSB71Mvc8ql+GU7+nSG5I5lmME71p3uR4jpV1SuEqSO+JUrsEh0a6XaTBnmaL7m6 vPuw== X-Gm-Message-State: APjAAAWzEDMFvjJkWQXXUONEm52j0x0nZL+NA9KhHKl+szLpSc1zxxQ/ OulVOPAGX2Z5ToHqRGUIChPq6A== X-Received: by 2002:a0c:95a5:: with SMTP id s34mr16780251qvs.72.1571110417517; Mon, 14 Oct 2019 20:33:37 -0700 (PDT) Received: from leoy-ThinkPad-X240s (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id w85sm9460755qkb.57.2019.10.14.20.33.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Oct 2019 20:33:36 -0700 (PDT) Date: Tue, 15 Oct 2019 11:33:27 +0800 From: Leo Yan To: Mathieu Poirier Cc: Arnaldo Carvalho de Melo , Suzuki K Poulose , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Coresight ML , Peter Zijlstra , Ingo Molnar Subject: Re: [PATCH v3 3/6] perf cs-etm: Support thread stack Message-ID: <20191015033327.GB6336@leoy-ThinkPad-X240s> References: <20191005091614.11635-1-leo.yan@linaro.org> <20191005091614.11635-4-leo.yan@linaro.org> <20191011175353.GA13688@xps15> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191011175353.GA13688@xps15> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Mathieu, On Fri, Oct 11, 2019 at 11:53:53AM -0600, Mathieu Poirier wrote: > On Sat, Oct 05, 2019 at 05:16:11PM +0800, Leo Yan wrote: > > Since Arm CoreSight doesn't support thread stack, the decoding cannot > > display symbols with indented spaces to reflect the stack depth. > > > > This patch adds support thread stack for Arm CoreSight, this allows > > 'perf script' to display properly for option '-F,+callindent'. > > > > Before: > > > > # perf script -F,+callindent > > main 2808 1 branches: coresight_test1 ffff8634f5c8 coresight_test1+0x3c (/root/coresight_test/libcstest.so) > > main 2808 1 branches: printf@plt aaaaba8d37ec main+0x28 (/root/coresight_test/main) > > main 2808 1 branches: printf@plt aaaaba8d36bc printf@plt+0xc (/root/coresight_test/main) > > main 2808 1 branches: _init aaaaba8d3650 _init+0x30 (/root/coresight_test/main) > > main 2808 1 branches: _dl_fixup ffff86373b4c _dl_runtime_resolve+0x40 (/lib/aarch64-linux-gnu/ld-2.28.so) > > main 2808 1 branches: _dl_lookup_symbol_x ffff8636e078 _dl_fixup+0xb8 (/lib/aarch64-linux-gnu/ld-2.28.so) > > [...] > > > > After: > > > > # perf script -F,+callindent > > main 2808 1 branches: coresight_test1 ffff8634f5c8 coresight_test1+0x3c (/root/coresight_test/libcstest.so) > > main 2808 1 branches: printf@plt aaaaba8d37ec main+0x28 (/root/coresight_test/main) > > main 2808 1 branches: printf@plt aaaaba8d36bc printf@plt+0xc (/root/coresight_test/main) > > main 2808 1 branches: _init aaaaba8d3650 _init+0x30 (/root/coresight_test/main) > > main 2808 1 branches: _dl_fixup ffff86373b4c _dl_runtime_resolve+0x40 (/lib/aarch64-linux-gnu/ld-2.28.s > > main 2808 1 branches: _dl_lookup_symbol_x ffff8636e078 _dl_fixup+0xb8 (/lib/aarch64-linux-gnu/ld-2.28.so) > > [...] > > > > Signed-off-by: Leo Yan > > --- > > tools/perf/util/cs-etm.c | 44 ++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 44 insertions(+) > > > > diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c > > index 58ceba7b91d5..780abbfd1833 100644 > > --- a/tools/perf/util/cs-etm.c > > +++ b/tools/perf/util/cs-etm.c > > @@ -1117,6 +1117,45 @@ static void cs_etm__copy_insn(struct cs_etm_queue *etmq, > > sample->insn_len, (void *)sample->insn); > > } > > > > +static void cs_etm__add_stack_event(struct cs_etm_queue *etmq, > > + struct cs_etm_traceid_queue *tidq) > > +{ > > + struct cs_etm_auxtrace *etm = etmq->etm; > > + u8 trace_chan_id = tidq->trace_chan_id; > > + int insn_len; > > + u64 from_ip, to_ip; > > + > > + if (etm->synth_opts.thread_stack) { > > + from_ip = cs_etm__last_executed_instr(tidq->prev_packet); > > + to_ip = cs_etm__first_executed_instr(tidq->packet); > > + > > + insn_len = cs_etm__instr_size(etmq, trace_chan_id, > > + tidq->prev_packet->isa, from_ip); > > + > > + /* > > + * Create thread stacks by keeping track of calls and returns; > > + * any call pushes thread stack, return pops the stack, and > > + * flush stack when the trace is discontinuous. > > + */ > > + thread_stack__event(tidq->thread, tidq->prev_packet->cpu, > > + tidq->prev_packet->flags, > > + from_ip, to_ip, insn_len, > > + etmq->buffer->buffer_nr); > > Details are a little fuzzy in my head but I'm pretty sure > we want trace_chan_id here. Thanks a lot for reviewing! This is good point. After a quick look for the code, seems TO_CS_QUEUE_NR() is the right thing to use at here for buffer number. Will look more closely to the code and apply changes in next version. Thanks, Leo Yan > > + } else { > > + /* > > + * The thread stack can be output via thread_stack__process(); > > + * thus the detailed information about paired calls and returns > > + * will be facilitated by Python script for the db-export. > > + * > > + * Need to set trace buffer number and flush thread stack if the > > + * trace buffer number has been alternate. > > + */ > > + thread_stack__set_trace_nr(tidq->thread, > > + tidq->prev_packet->cpu, > > + etmq->buffer->buffer_nr); > > Same here. > > > + } > > +} > > + > > static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, > > struct cs_etm_traceid_queue *tidq, > > u64 addr, u64 period) > > @@ -1393,6 +1432,9 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, > > tidq->period_instructions = instrs_over; > > } > > > > + if (tidq->prev_packet->last_instr_taken_branch) > > + cs_etm__add_stack_event(etmq, tidq); > > + > > if (etm->sample_branches) { > > bool generate_sample = false; > > > > @@ -2593,6 +2635,8 @@ int cs_etm__process_auxtrace_info(union perf_event *event, > > itrace_synth_opts__set_default(&etm->synth_opts, > > session->itrace_synth_opts->default_no_sample); > > etm->synth_opts.callchain = false; > > + etm->synth_opts.thread_stack = > > + session->itrace_synth_opts->thread_stack; > > } > > > > err = cs_etm__synth_events(etm, session); > > -- > > 2.17.1 > >