From patchwork Sat Oct 5 09:16:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 175266 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp1791068ill; Sat, 5 Oct 2019 02:17:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqwARwCrzgW1mORuqRtdfFEn15ACYQPIKAcBzYqccce8+BuxjPyh0ge5ySerzgmU1p2E3SaS X-Received: by 2002:a05:6402:1426:: with SMTP id c6mr20249937edx.53.1570267032837; Sat, 05 Oct 2019 02:17:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570267032; cv=none; d=google.com; s=arc-20160816; b=qM9pDDTNSPqC7Oblg8M4KkCqQBLuuGcC04ukhJjj9nBRdmw63Xv5jsQGZiat8brzpq NrNsSHo8S/1AMJSdgVyyUXnrGhxW7j9QhkkUfvIWv0S79q6EfYmFD/Lp+KwJ6bbJfBR+ gK/2q8+VkB8RYXS2evuQLNt80vsP/A0pZPHedS04e5dEr1TJeDXK7f//DbZGCt0LW2bk Yip7/+EqVPszK4V0zMy5enl81ywcT5PwuxwQZTDY4KBCq4vPiJwPrwdYXXLOzAo+UbeE tXlYyKCZ7XdhgmUvgX8wp2ZNqdZkNeOcFLWEaPRpc/oSxlU+dgpD5VDnr6/DfTwIIwO4 dMjg== 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=MASENXtjvjrGt9RAiM0XMBiZxBBH7YBJCk7GCr7TS68=; b=q6nWsELredZ5MtWIwxc7lBiwGy7Sa5CO62lLur/af1W2mNyILgQVevqDv2eWydWO+i 9Ot1KJMqVcD8oV7ICS5ezYWYLTfFnRunIkFRIKdVF9KqpMPze9kpC9/Z23NqZtAL99g5 VQEyJOud/3f1SW4J3TxT83llnWfImCiowiDX/ZgabXMHh7F6ZqcLbJLDOasDEbp+dcfQ vdFqwDw91xR4QIxI2yOenWSKddOytHNhgA11MpJhVydWQ7qmRH43BHqcq0FEdbXuFs8O VMYHR1wRQ8Ab74otu86RFN3Z9PSyDHClvm6XbNriBx/11/T0KVLHohrOhFVbaIWY+ifT GI1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BOZAQaCt; 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.12; Sat, 05 Oct 2019 02:17:12 -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=BOZAQaCt; 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 S1727881AbfJEJRL (ORCPT + 27 others); Sat, 5 Oct 2019 05:17:11 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:43081 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbfJEJRJ (ORCPT ); Sat, 5 Oct 2019 05:17:09 -0400 Received: by mail-qk1-f194.google.com with SMTP id h126so8143467qke.10 for ; Sat, 05 Oct 2019 02:17:09 -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=MASENXtjvjrGt9RAiM0XMBiZxBBH7YBJCk7GCr7TS68=; b=BOZAQaCtY3VPwH+2WpEjt6kSfv/nQ8w6QKgJreO5w8ha6Xch0n3Gz1CSS4U+u65pnF qjwyPDVvQd5HttZYsi6omNZiaPcmbInsUs9rDSDwQeDwKbbBAM547VNDrnk+HRFifbRI k2idWM85mMwtcLNM/GiWrYbEstXYFyFTGBIp7IPWVnyz2ItuUZdsWfftzgAolt81wQiV /zJq4O79Y7ezXfnqwNAG0SHpsI3FvqEh65vnZkG9GRW3B+o2zgFyNJRMKZo7k3Oz1YmV KwCc55v63Likpj+nSVG2NPQJmbDLO1HRr1afjRQnfKieML/oAJXkHTjNZOgwuM+5snrV UYSg== 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=MASENXtjvjrGt9RAiM0XMBiZxBBH7YBJCk7GCr7TS68=; b=X95iZvpuoF3cx+Qdlg6JPGhlhNYWZe6aUeu+MHvbnogaxqYWs2WvVPdFEp7ReOFtwI y+6jF+P3SiIzJJtx+ri6KaksupOwNs0zIg8yHnpiDjyYBRoeLDbx9a88drfLhH3B/2ae RazyKgBUTFWL6w17WsGZIobwq1lzTJuF9yrTlVLN0DraETPVMRMzT0I7NEKfoec2mFQc AUvDJys9Bf+WQ2PF6Hs369wXe4OZ0/+A/q3ynwHHl9TgbyyceU4BXejKSVofk5d6wFYl 8Fal3dYX37dsl+Yg1fOhHEmwr6bnWI4eKzg+T6V0d3YF9yVKkVopR1fXwh0PdcPN3bD1 jyHg== X-Gm-Message-State: APjAAAVG4cRpjhl39lM0LZBQS1gwiFnIHPCIMIzjpZuk5utF4YfPUPVx wpOILeX1vET+l3mPRh2oRjKZug== X-Received: by 2002:a37:4e48:: with SMTP id c69mr14232654qkb.182.1570267028692; Sat, 05 Oct 2019 02:17:08 -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.17.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 02:17:08 -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 6/6] perf cs-etm: Synchronize instruction sample with the thread stack Date: Sat, 5 Oct 2019 17:16:14 +0800 Message-Id: <20191005091614.11635-7-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 The synthesized flow use 'tidq->packet' for instruction samples; on the other hand, 'tidp->prev_packet' is used to generate the thread stack and the branch samples, this results in the instruction samples using one packet ahead than thread stack and branch samples ('tidp->prev_packet' vs 'tidq->packet'). This leads to an instruction's callchain error as shows in below example: main 1579 100 instructions: ffff000010214854 perf_event_update_userpage+0x4c ([kernel.kallsyms]) ffff000010214850 perf_event_update_userpage+0x48 ([kernel.kallsyms]) ffff000010219360 perf_swevent_add+0x88 ([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]) In the callchain log, for the two continuous lines the up line contains one child function info and the followed line contains the caller function info, and so forth. So the first two lines are: perf_event_update_userpage+0x4c => the sampled instruction perf_event_update_userpage+0x48 => the parent function's calling The child function and parent function both are the same function perf_event_update_userpage(), but this isn't a recursive function, thus the sequence for perf_event_update_userpage() calling itself shouldn't never happen. This callchain error is caused by the instruction sample using an ahead packet than the thread stack, the thread stack is deferred to process the new packet and misses to pop stack if it is just a return packet. To fix this issue, we can simply change to use 'tidq->prev_packet' to generate the instruction samples, this allows the thread stack to push and pop synchronously with instruction sample. Finally, the callchain can be displayed correctly as below: main 1579 100 instructions: ffff000010214854 perf_event_update_userpage+0x4c ([kernel.kallsyms]) ffff000010219360 perf_swevent_add+0x88 ([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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 56e501cd2f5f..fa969dcb45d2 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1419,7 +1419,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, struct cs_etm_packet *tmp; int ret; u8 trace_chan_id = tidq->trace_chan_id; - u64 instrs_executed = tidq->packet->instr_count; + u64 instrs_executed = tidq->prev_packet->instr_count; tidq->period_instructions += instrs_executed; @@ -1450,7 +1450,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, */ s64 offset = (instrs_executed - instrs_over - 1); u64 addr = cs_etm__instr_addr(etmq, trace_chan_id, - tidq->packet, offset); + tidq->prev_packet, offset); ret = cs_etm__synth_instruction_sample( etmq, tidq, addr, etm->instructions_sample_period);