Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp280974ybv; Wed, 19 Feb 2020 21:29:44 -0800 (PST) X-Google-Smtp-Source: APXvYqwkCwLYYtlpvuh5n5+OGS9dJrPAZCQVfnApxSIvukeIaR0tKPOOQWJZCkcm6J2h8W9usnVf X-Received: by 2002:aca:e084:: with SMTP id x126mr832031oig.97.1582176584732; Wed, 19 Feb 2020 21:29:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582176584; cv=none; d=google.com; s=arc-20160816; b=vPFk6WaaJBWlN9G5M6WGYEpsCuj8xUWwR91RoUTRlR4Y/+0i1HfxVUrns6Z0pMDCsD JgxdK+CiBJVuD0TxHqRkpa5+CsIliZJACpoH+tDOmWxp5V4wTwmZOVKfsJ1KzFiaarrl 5AqU6hn+GPlojT7Gltuk1GcqcIY0fqBOL4nClDkzahjAtKVhHX9bhT37snYiugNOSFoQ dX4y4jm522Q/wwU3cDSc1FdZyjPMaUa29L8SyISLYV0Ir0rbuwXSnNXhKiGQYBND5dBf F/LrCwAfJK8odT2BLo20dJyxir5qZPP3IyuNy0GeE9dXS8wlPTQ3zYCou1WpfMPTP+wJ +5lw== 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=Qm7dOX6BJPU8t8EeV5guhioxUn3G/S82qxut/ZQCG/Y=; b=tsKG0orQKg/B0+xAyQ9aXt+aEqPKNyKpErXGvmJqnNsuJwswDx2HbZVaW1EbVaaXYe OvMwLLchH1gJ7PfqKQVsF078uXL6At/HYoyD1KEe/G4q79BFcWWDgPicq7u3QBkjbvrR LHnTykYuFUWpwr8BsH/j4+18OdauVp0sULb1ScPx3B76ASdRVUvM6tGh4zvcOui46dVs txLxPPgwlgN60LDEmitdGs7S/OC4+0UBW9ZwwDIoFEMMht/NH6cxaqWV21BUw92fn+tV UZN7RYAfYSGt90Wly8fBHbn7cKCusZpLLGpQXnRgBwxCCnb24Eq39+I1uq4teCOxWP7u 3Gtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YMJWJ76P; 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 z15si9784277oih.41.2020.02.19.21.29.32; Wed, 19 Feb 2020 21:29:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YMJWJ76P; 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 S1726877AbgBTF2i (ORCPT + 99 others); Thu, 20 Feb 2020 00:28:38 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:45902 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726851AbgBTF2i (ORCPT ); Thu, 20 Feb 2020 00:28:38 -0500 Received: by mail-pf1-f193.google.com with SMTP id 2so1307291pfg.12 for ; Wed, 19 Feb 2020 21:28:37 -0800 (PST) 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=Qm7dOX6BJPU8t8EeV5guhioxUn3G/S82qxut/ZQCG/Y=; b=YMJWJ76PiWBpfKwBtY8n224agzsTTrpvlIh1EsZtXyIRZtGFoXj2+ruqGUJ3mQxvFm nAI7m/LvA/Qx7/ydA9uI4gl+cQXG2QOxF1DKy8xA8Ng2h8dvLAsEj93WZ3JUJgB5TPBl ftl0OLn47eRr/getcCwiSvKZi75qCrkfmu3mUxMRfO2olgiBmsc7BjM/ED9GyUunWGQo 0r1NOGJE4q2a/umAg4MvWunk6uuOwtC/019bczrehXplTfwgCYTYE9yV+OvXbVXJ/nX4 QPOSD214OHcJQMLrrO5vtbXh0WYZexx0oMvbZCKcPqwHv993tOGZ9PvLzkaEfZcI+4NX 4Mbw== 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=Qm7dOX6BJPU8t8EeV5guhioxUn3G/S82qxut/ZQCG/Y=; b=BH52kKF+OyXlcz8S9T7N6Zt1117xIT/rLKule9zdq4qHL/KQNzk+kok02kRTZz+/kZ YcERCwg+CyVbAZDcaR9A78ms/q/EephUngapNCWQGhFPSMLAAdoyKC/sGIFtkSYdKkhh OHAEOF9dk9Rg0aL+UnzN5EPq+Rmmt3GNKT6mt0RDofv6P3I9hEKEKQPC7gdWhZmbX1M/ A6Wylm3U2+/pwgDAGaditHWQinnm5JPr+zFSxYC5eeZIIGFDos+8EkC6NrfKIB1xat7t AuEM0qFfA1gh/QjOtm3MT+8CJy/H6BGVsT799rimmlaXHx3wZG/6z8kLALJIDKM/bw/i qsyw== X-Gm-Message-State: APjAAAXVpR1DtZTNaamYxm/D9fAowe1C56B0cPUP0z4o16Ejwrzt/B/8 4VbdHq6z239LcYCgJhQKCiF31Q== X-Received: by 2002:a63:9856:: with SMTP id l22mr29974631pgo.344.1582176516647; Wed, 19 Feb 2020 21:28:36 -0800 (PST) Received: from localhost.localdomain (li1441-214.members.linode.com. [45.118.134.214]) by smtp.gmail.com with ESMTPSA id l69sm1535663pgd.1.2020.02.19.21.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 21:28:36 -0800 (PST) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mark Rutland , Mike Leach , Robert Walker , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Coresight ML Cc: Leo Yan Subject: [PATCH v5 5/9] perf cs-etm: Support branch filter Date: Thu, 20 Feb 2020 13:26:57 +0800 Message-Id: <20200220052701.7754-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200220052701.7754-1-leo.yan@linaro.org> References: <20200220052701.7754-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If user specifies option '-F,+callindent' or call chain related options, it means users only care about function calls and returns; for these cases, it's pointless to generate samples for the branches within function. But unlike other hardware trace handling (e.g. Intel's pt or bts), Arm CoreSight doesn't filter branch types for these options and generate samples for all branches, this causes Perf to output many spurious blanks if the branch is not a function call or return. To only output pairs of calls and returns, this patch introduces branch filter and the filter is set according to synthetic options. Finally, Perf can output only for calls and returns and avoid to output other unnecessary blanks. Before: # perf script -F,+callindent main 2808 1 branches: coresight_test1@plt aaaaba8d37d8 main+0x14 (/root/coresight_test/main) main 2808 1 branches: coresight_test1@plt aaaaba8d367c coresight_test1@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) main 2808 1 branches: ffff8636a3f4 _dl_lookup_symbol_x+0x5c (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: ffff8636a3f4 _dl_lookup_symbol_x+0x5c (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: ffff8636a3f4 _dl_lookup_symbol_x+0x5c (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: ffff8636a3f4 _dl_lookup_symbol_x+0x5c (/lib/aarch64-linux-gnu/ld-2.28.s main 2808 1 branches: ffff8636a3f4 _dl_lookup_symbol_x+0x5c (/lib/aarch64-linux-gnu/ld-2.28.s [...] After: # perf script -F,+callindent main 2808 1 branches: coresight_test1@plt aaaaba8d37d8 main+0x14 (/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) main 2808 1 branches: do_lookup_x ffff8636a49c _dl_lookup_symbol_x+0x104 (/lib/aarch64-linux-gnu/ld-2.28. main 2808 1 branches: check_match ffff86369bf0 do_lookup_x+0x238 (/lib/aarch64-linux-gnu/ld-2.28.so) main 2808 1 branches: strcmp ffff86369888 check_match+0x70 (/lib/aarch64-linux-gnu/ld-2.28.so) main 2808 1 branches: printf@plt aaaaba8d37ec main+0x28 (/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) main 2808 1 branches: do_lookup_x ffff8636a49c _dl_lookup_symbol_x+0x104 (/lib/aarch64-linux-gnu/ld-2.28. main 2808 1 branches: _dl_name_match_p ffff86369af0 do_lookup_x+0x138 (/lib/aarch64-linux-gnu/ld-2.28.so) main 2808 1 branches: strcmp ffff8636f7f0 _dl_name_match_p+0x18 (/lib/aarch64-linux-gnu/ld-2.28.so) [...] Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 08ca919aa2b1..1b08b650b090 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -56,6 +56,7 @@ struct cs_etm_auxtrace { int num_cpu; u32 auxtrace_type; + u32 branches_filter; u64 branches_sample_type; u64 branches_id; u64 instructions_sample_type; @@ -1239,6 +1240,10 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq, } dummy_bs; u64 ip; + if (etm->branches_filter && + !(etm->branches_filter & tidq->prev_packet->flags)) + return 0; + ip = cs_etm__last_executed_instr(tidq->prev_packet); event->sample.header.type = PERF_RECORD_SAMPLE; @@ -2776,6 +2781,13 @@ int cs_etm__process_auxtrace_info(union perf_event *event, session->itrace_synth_opts->thread_stack; } + if (etm->synth_opts.calls) + etm->branches_filter |= PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC | + PERF_IP_FLAG_TRACE_END; + if (etm->synth_opts.returns) + etm->branches_filter |= PERF_IP_FLAG_RETURN | + PERF_IP_FLAG_TRACE_BEGIN; + err = cs_etm__synth_events(etm, session); if (err) goto err_delete_thread; -- 2.17.1