From patchwork Sat Oct 5 09:16:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 175265 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1791020ill; Sat, 5 Oct 2019 02:17:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7ZBXnH6RdpuP1io3kedZB1XGbuA82vN403h0WwfWF4eW5R3/aczu8ONy/uWFP0VKMxneb X-Received: by 2002:a50:be87:: with SMTP id b7mr19877993edk.37.1570267029893; Sat, 05 Oct 2019 02:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570267029; cv=none; d=google.com; s=arc-20160816; b=idI172/wnO5W9ZoFtW/10ezahaIOGZ0yR212mQk/g7wMPuuBd0BspRLGWwZ2A7Hz0x c/53px01YYU4xoQdI1Uyhwq0VUN/vamaHr0ccTRA61RitXkmSnGhH7L/GDfZWnSCgipL R7ihAkQANh6Fb3QBOW6QuJqKRipX/VzonaW9mPifIHbqRY0nsJ3K8LYkkOpWFAoZSP0U +yMP9vt7CxvX0vh8tbeENsn9gEpbBeTr0WavCGw6dL/kMND6zsCyL/KtEkMjC2qZKN5A sZyQS4RvJzdfklplX/pRTIs09nIJUGt5Vf4IMU+icJtRuw9SETGqqeTMMWqMb84kbTmz 2QEA== 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=vKe+RbONBbtsSEscZalEdBXt7OSCg1h7S1CJqx/C4I8=; b=j4i/0JIPTjSzUnBInH98GT+sar08X6j3kXzSUvrTwu0RBJTNsMSGg7KOwb4HYpV8pw W+pnK7sExllPvDbw++1SVoJU4hUHDi9r3eUzOwJqnqs2HnZrzVBeHMhXW4/48R2AjyDc cp7HDnoJiqTgj8urn2oahJcijt9yB/00p9RgL0etGgWxWhEoywYf6mBzvxpZ2EM0RYad Q81AvwOSRMQQaMVYOY3J4Bv8eHviCY3rMxHyVFDo8oW9a8URc5s10Ig0vQK5jPyQSBw/ QpIAh8y/9wu5HQo/go6gjkogEdP+L1uN7gQHaazpP0AxWBTAjbtBxsD+c2TST0A8q93B Vpqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Lm4kUtl9; 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 y27si5431412edd.249.2019.10.05.02.17.09; Sat, 05 Oct 2019 02:17:09 -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=Lm4kUtl9; 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 S1727839AbfJEJRG (ORCPT + 27 others); Sat, 5 Oct 2019 05:17:06 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:33610 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfJEJRE (ORCPT ); Sat, 5 Oct 2019 05:17:04 -0400 Received: by mail-qt1-f193.google.com with SMTP id r5so12215568qtd.0 for ; Sat, 05 Oct 2019 02:17:03 -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=vKe+RbONBbtsSEscZalEdBXt7OSCg1h7S1CJqx/C4I8=; b=Lm4kUtl9jA8j3ivLXcwP7K8BKLshypBI7RUHI3Xnzp7uCFEVJ3bgfDM7PRxQ2xRR1A V7kogDQ8J4+eAxu7HQnZr/qR/ksOvQx1SbfHz/seX56uN8psAmwiUNzX1L37RZEcECWP f+Xgbx030dGDRJIlBHVcsUUOCQFp3wp7uL1JG4hvgHgCp/CcQ1O7DjLD6YjjYwsz52CM sl3ILW23Qzqv/9LygkMFvn2N98i7cfWmhCY9qfgA56jTK6qdReAn7tZai08jasMpKUqh zHYeB9WQJlMFiz7EGV8RybsYir+NRZlUH25ythvFOq5FltlsayVh7HetjDT4momcDcKI BTpQ== 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=vKe+RbONBbtsSEscZalEdBXt7OSCg1h7S1CJqx/C4I8=; b=a8/K/RFNJeDciFUbHvBM5j4epfvInCXvv/rEnma/h0u3vZGsVPAhLpkokhMBuYbRt9 qB+6U//R6mi8JKfc+KrzI1LRIeU2Sxfc3MS58TjtVMAZasDRO8u5t6Ahh5qpmFlJ/Cqh Q9USNasIxJ90P7Jc9/BHFoXzNW4MKIR0iTL8IYdcxyMjYJVMrUNgtyWRHvxelm0+68Tk GmnBAQTjvI8OeZCH3TRbsl+nUNYCoYuwPTRRUtwZ9NNpxdYokxWaCFffc7N0mjfFUSVZ AqdFRD1GvsDONAJYJ6iZMGoeW5nd50wgDAomM0b/pgPdvlnkzPQag0YebNAMTEAY50Pv s7rQ== X-Gm-Message-State: APjAAAU1z/Ng2doMyMcSuuyPU4EyRT+VLFMdJSqeUEgdLMO/F8QBRFgP 173UkotDwRKUGlq0uwsyJ/lQtA== X-Received: by 2002:aed:22cc:: with SMTP id q12mr20936122qtc.232.1570267023107; Sat, 05 Oct 2019 02:17:03 -0700 (PDT) Received: from localhost.localdomain (li937-157.members.linode.com. [45.56.119.157]) by smtp.gmail.com with ESMTPSA id u132sm4384621qka.50.2019.10.05.02.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 02:17:02 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , 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 Cc: Leo Yan Subject: [PATCH v3 5/6] perf cs-etm: Support callchain for instruction sample Date: Sat, 5 Oct 2019 17:16:13 +0800 Message-Id: <20191005091614.11635-6-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191005091614.11635-1-leo.yan@linaro.org> References: <20191005091614.11635-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now CoreSight has supported the thread stack; based on the thread stack we can synthesize call chain for the instruction sample; the call chain can be injected by option '--itrace=g'. Before: # perf script --itrace=g16l64i100 main 1579 100 instructions: ffff0000102137f0 group_sched_in+0xb0 ([kernel.kallsyms]) main 1579 100 instructions: ffff000010213b78 flexible_sched_in+0xf0 ([kernel.kallsyms]) main 1579 100 instructions: ffff0000102135ac event_sched_in.isra.57+0x74 ([kernel.kallsyms]) main 1579 100 instructions: ffff000010219344 perf_swevent_add+0x6c ([kernel.kallsyms]) main 1579 100 instructions: ffff000010214854 perf_event_update_userpage+0x4c ([kernel.kallsyms]) [...] After: # perf script --itrace=g16l64i100 main 1579 100 instructions: ffff000010213b78 flexible_sched_in+0xf0 ([kernel.kallsyms]) ffff00001020c0b4 visit_groups_merge+0x12c ([kernel.kallsyms]) main 1579 100 instructions: ffff0000102135ac event_sched_in.isra.57+0x74 ([kernel.kallsyms]) ffff0000102137a0 group_sched_in+0x60 ([kernel.kallsyms]) ffff000010213b84 flexible_sched_in+0xfc ([kernel.kallsyms]) ffff00001020c0b4 visit_groups_merge+0x12c ([kernel.kallsyms]) main 1579 100 instructions: ffff000010219344 perf_swevent_add+0x6c ([kernel.kallsyms]) ffff0000102135f4 event_sched_in.isra.57+0xbc ([kernel.kallsyms]) ffff0000102137a0 group_sched_in+0x60 ([kernel.kallsyms]) ffff000010213b84 flexible_sched_in+0xfc ([kernel.kallsyms]) ffff00001020c0b4 visit_groups_merge+0x12c ([kernel.kallsyms]) [...] Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 4b42f9c9bd34..56e501cd2f5f 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -17,6 +17,7 @@ #include #include "auxtrace.h" +#include "callchain.h" #include "color.h" #include "cs-etm.h" #include "cs-etm-decoder/cs-etm-decoder.h" @@ -74,6 +75,7 @@ struct cs_etm_traceid_queue { size_t last_branch_pos; union perf_event *event_buf; struct thread *thread; + struct ip_callchain *chain; struct branch_stack *last_branch; struct branch_stack *last_branch_rb; struct cs_etm_packet *prev_packet; @@ -251,6 +253,16 @@ static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq, if (!tidq->prev_packet) goto out_free; + if (etm->synth_opts.callchain) { + size_t sz = sizeof(struct ip_callchain); + + /* Add 1 to callchain_sz for callchain context */ + sz += (etm->synth_opts.callchain_sz + 1) * sizeof(u64); + tidq->chain = zalloc(sz); + if (!tidq->chain) + goto out_free; + } + if (etm->synth_opts.last_branch) { size_t sz = sizeof(struct branch_stack); @@ -275,6 +287,7 @@ static int cs_etm__init_traceid_queue(struct cs_etm_queue *etmq, zfree(&tidq->last_branch); zfree(&tidq->prev_packet); zfree(&tidq->packet); + zfree(&tidq->chain); out: return rc; } @@ -546,6 +559,7 @@ static void cs_etm__free_traceid_queues(struct cs_etm_queue *etmq) zfree(&tidq->last_branch_rb); zfree(&tidq->prev_packet); zfree(&tidq->packet); + zfree(&tidq->chain); zfree(&tidq); /* @@ -1126,7 +1140,7 @@ static void cs_etm__add_stack_event(struct cs_etm_queue *etmq, int insn_len; u64 from_ip, to_ip; - if (etm->synth_opts.thread_stack) { + if (etm->synth_opts.callchain || etm->synth_opts.thread_stack) { from_ip = cs_etm__last_executed_instr(tidq->prev_packet); to_ip = cs_etm__first_executed_instr(tidq->packet); @@ -1182,6 +1196,14 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, cs_etm__copy_insn(etmq, tidq->trace_chan_id, tidq->packet, &sample); + if (etm->synth_opts.callchain) { + thread_stack__sample(tidq->thread, tidq->packet->cpu, + tidq->chain, + etm->synth_opts.callchain_sz + 1, + sample.ip, etm->kernel_start); + sample.callchain = tidq->chain; + } + if (etm->synth_opts.last_branch) { cs_etm__copy_last_branch_rb(etmq, tidq); sample.branch_stack = tidq->last_branch; @@ -1369,6 +1391,8 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm, attr.sample_type &= ~(u64)PERF_SAMPLE_ADDR; } + if (etm->synth_opts.callchain) + attr.sample_type |= PERF_SAMPLE_CALLCHAIN; if (etm->synth_opts.last_branch) attr.sample_type |= PERF_SAMPLE_BRANCH_STACK; @@ -2639,7 +2663,6 @@ int cs_etm__process_auxtrace_info(union perf_event *event, } else { 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; } @@ -2651,6 +2674,14 @@ int cs_etm__process_auxtrace_info(union perf_event *event, etm->branches_filter |= PERF_IP_FLAG_RETURN | PERF_IP_FLAG_TRACE_BEGIN; + if (etm->synth_opts.callchain && !symbol_conf.use_callchain) { + symbol_conf.use_callchain = true; + if (callchain_register_param(&callchain_param) < 0) { + symbol_conf.use_callchain = false; + etm->synth_opts.callchain = false; + } + } + err = cs_etm__synth_events(etm, session); if (err) goto err_delete_thread;