From patchwork Fri Aug 30 06:24:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 172677 Delivered-To: patch@linaro.org Received: by 2002:a92:d204:0:0:0:0:0 with SMTP id y4csp187646ily; Thu, 29 Aug 2019 23:25:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCT18qVT1dKRY7odmTfDqE+teWaQzEdhPJH+LyCnFKuAld+dqORKVZq3+EKA8VGor+vIZs X-Received: by 2002:aa7:9591:: with SMTP id z17mr16333160pfj.215.1567146302193; Thu, 29 Aug 2019 23:25:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567146302; cv=none; d=google.com; s=arc-20160816; b=p8fzZwvoWpydrQDEyyLh51ADjeDZUGw0aqaOFUTehByejDgnCW0hnklgCXU0Mq8BD5 hkJzmUuDDSmK7LrjVccoNsBzFiYlthEnqDxEQ6CkOglJxuYWlDlz2P4FpVrrwq+EITzS ceaRdk11HwFWE7xboBZYFiF8owyQn8aZNxxdYzpI4pUurhyu0AquZDB2C+YRH3BX5R8S szhAUbgjRtPugFdNW0hBa+AmLK+xbTp6atneYOEOXTqW+mwqPllZ0WvPY608Ft5N03VT QN13KvHnqPyGvGk0kjZPPwZY91HkD8NAopBN+MHJU8Kg+/VrTnvEOnLRgO/BVTe6lZeY 1ObA== 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=LW/cyVok2Jx1Gl00HhV8gtiT8RMfRuMvrAfcIARqkHQ=; b=0Eh9iAYae4ZsI2hV4maOiwyvHO5Cf8I7v0AhzS1v7yp5d+TUu5xz9MNy5gMmFoq3v1 vsfrz9PazRczhNNk2fS1Lv+C4k5ow1QAkVG41DAX8Hm8xsSZGYDy1uJ2hnZ94705yv8W oGZdvcYaTOFgvjIG5/jctOl/uRogjS+rmoL9af8tMdU47krKmkaKvS8L5GX/lJAdrJVx cwh6G9Bx8/s/w52R63yCu8XGPBrTf93Uin06gTtR1kHVpcL8MUg6TyQjUdcMp8Wg32hz ER341CGhapVYu5Otu0hOpIqso1c5Jtb//6YvZ/DPHdutMUd/sV07soGjYzbtFfheR68y qwFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=anOoup8N; 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 o93si4179681pje.38.2019.08.29.23.25.01; Thu, 29 Aug 2019 23:25:02 -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=anOoup8N; 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 S1728160AbfH3GZA (ORCPT + 28 others); Fri, 30 Aug 2019 02:25:00 -0400 Received: from mail-yb1-f196.google.com ([209.85.219.196]:39068 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726023AbfH3GZA (ORCPT ); Fri, 30 Aug 2019 02:25:00 -0400 Received: by mail-yb1-f196.google.com with SMTP id s142so2084995ybc.6 for ; Thu, 29 Aug 2019 23:24:59 -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=LW/cyVok2Jx1Gl00HhV8gtiT8RMfRuMvrAfcIARqkHQ=; b=anOoup8NEzR708g9QLZe0LlLW1dHoyJlaY4aiva0hYfwdnh/25lhlp6WWCRuVqfDDK dJrpirug7Wvl1oNUStKASkVBltOaFvN/8PjGmFx3GMU9ptP/VgRaS673M+3oQyKJZ9g/ XiG5ZQYvUkV4JsYMChF0y+xq0opTxWZI7lTtP7A8X0jXlG7ymholngnzlPFOc/WIm4D4 0O63FdN51BBL4rrEewu4y0ErkJ7aSiT/YCl0a68k2bDep7HyagVbrQbPJ7ANfulPycqR 1fANyvSx1HcIUW4qUqrJrCLufB1EXHolBJ04sAfeSq/+baTPSIxL+C1JlPkZevF1lXkh N1ag== 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=LW/cyVok2Jx1Gl00HhV8gtiT8RMfRuMvrAfcIARqkHQ=; b=efvkJOTlPwo9G9n0d/pnbKPSkFa7vo0cGJ+UZGFNcxvfhMOTK4Gi5gFWzq62ToiUBL tMDsDbZEZwaCIKJFRPSxQbEPPF0fm4XTYEbuEiCxwyalYptcMUKaCLJqjFwzKbh99puu y4V7n3o6PbQV2gNfo1V5nkqXTRq8Ks7t+5zQIck3ab/wj+TwdN3BIt4CEGiVN91Gmgzq 0fZcO6EBPbEvP0rWiyJHJfy5P8yHhVrvi9uAsq/FnDGG8UHLYpwYK9toOA4tFkuV5vRC daXsYN7tSwb9PLHTrA3mAGcADTjnV0vZGiAOi4L6KsSPk24wlvzU8ZNzF0/E/C0HrLZ0 xydQ== X-Gm-Message-State: APjAAAUZZykWbxmvWQo3XJ+/HkU+1lX2eef0TbXo8oUQWUvtAHqU+frm OW1Xx4HszRH2uUi3lwiyRVUr+A== X-Received: by 2002:a25:2f85:: with SMTP id v127mr9400791ybv.95.1567146299428; Thu, 29 Aug 2019 23:24:59 -0700 (PDT) Received: from localhost.localdomain (li1320-244.members.linode.com. [45.79.221.244]) by smtp.gmail.com with ESMTPSA id r193sm976784ywe.8.2019.08.29.23.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2019 23:24:58 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mike Leach , Robert Walker , Adrian Hunter Cc: Leo Yan Subject: [PATCH v1 3/3] perf cs-etm: Correct the packet usage for instruction sample Date: Fri, 30 Aug 2019 14:24:21 +0800 Message-Id: <20190830062421.31275-4-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190830062421.31275-1-leo.yan@linaro.org> References: <20190830062421.31275-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It uses 'tidq->packet' rather than 'tidq->prev_packet' to generate instruction sample, comparing against the thread stack and the branch samples which are using the 'tidp->prev_packet', thus this leads the instruction sample to use one ahead packet than thread stack and branch samples. As result, the instruction's call chain can be wrongly displayed as below: 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 this log, the continuous two lines includes two functions, the up line contains the child function info and the bottom line contains its parent function, and so forth. But if review the first two lines: perf_event_update_userpage+0x4c => the sampled instruction perf_event_update_userpage+0x48 => the parent function's calling The child function and parent function is the same function perf_event_update_userpage(), but perf_event_update_userpage() isn't a recursive function, thus this calling sequence shouldn't never happen. This is caused by the instruction sample using the 'tidq->packet', but this packet is not handled yet by thread stack, the thread stack is delayed to handle one return packet for stack popping. To fix this issue, we can simply to use 'tidq->prev_packet' to generate the instruction sample, this allows the thread stack to push/pop properly for instruction sample. Finally, we can get below result: 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 ad573d3bd305..0bd2b3c48394 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -1414,7 +1414,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; @@ -1445,7 +1445,7 @@ static int cs_etm__sample(struct cs_etm_queue *etmq, */ u64 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);