Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2958986imu; Mon, 19 Nov 2018 08:38:07 -0800 (PST) X-Google-Smtp-Source: AJdET5fM9u39WfymIOKsvKe32Kzr0fUkXEba1PscTi3k7O553NGlYhQSqknJgecoWO2E63WxiFZ9 X-Received: by 2002:a17:902:bd46:: with SMTP id b6mr22941389plx.231.1542645487304; Mon, 19 Nov 2018 08:38:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542645487; cv=none; d=google.com; s=arc-20160816; b=wqlvoSNMqMk4KZFUEUfwM4LArbGHAKJuke5PclZaC3Vbk9saEQR1tEG467uJpuIN3x 08ENQlyH9L70FTlmUtsiPMUqC0hw8qQmt1czN6enSm+dqrxiwJWa5mcX9NBfRF6M154e hyYs/XL4vNqiW/TUprlhZeWG7WkZ1ILZK4WuQ5nBE42w8dBO7uswpobw/Hwcm2dUw3Ex mefFFt34mwqet3z5mNtV5ld4FamOrZx17cPDppzejYH9dwKzu7JNihJKD4zcjtdGWXdJ WG7kcAi1/+4fKoH7qCG1jRTJR29fFaTIpyuT9PCS+w1bjE0auIx01F26s9MTClLqEd9R 3AZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+VP4zxMTwCvHxieQakE/BGJb3FAUUYWM102ivOYYALw=; b=NIrSGhP5oy+QKjWFG9r+udTg0GYMDrEXm0d3V0d06dJXdFTSSRrqs0Sve0HtISxrly pVwscyGFB2eiAyURJ4IeOz/fB/uFsuTDjCJoyK8FpTrM7BGdOjZpTiGAhYsHLwph2VYl MZWvIrEIR/fWTeQiQHMus/ys4XiO46Dl0cXAMySgSWH5nkCt9Lkfo2U9XSqf8C72MiUs t7r1/TIhcI9iR4HH/m79F+UcNNFHWSKixxaQCGDFfyFha3bkICeTTD0IACfmwkkUC9lp b/ec8wyGsXSfcF+F6ni1WOayaWaizrohwntymuzRpyxpz87rl3SYgp2tJIHhlGDZg7YN OS6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="d/NpqBkI"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u3-v6si6297028pls.137.2018.11.19.08.37.51; Mon, 19 Nov 2018 08:38:07 -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=@kernel.org header.s=default header.b="d/NpqBkI"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731566AbeKTC7O (ORCPT + 99 others); Mon, 19 Nov 2018 21:59:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:58474 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730350AbeKTC7N (ORCPT ); Mon, 19 Nov 2018 21:59:13 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C6E8B21104; Mon, 19 Nov 2018 16:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542645304; bh=FRC4Ook9UnTVg/4E4JqWSyXqGm0HmXd5WPx6QrLGgHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d/NpqBkIlhUfq058MBq29B37qgx3aQDSaDzQaa9al5vrak5zl4SkxiZtC6JpSd/k4 +EAuO22HUFFXke3PZIOl7OQB95v/d8LIf48vrJ7v7YhxklCUF1drUo5DGJGKYtx9M+ 9pM3Yib6jMAwglSRBWYuknfd6gaFj6Ei6aMMVxTM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "David S. Miller" , Arnaldo Carvalho de Melo , Adrian Hunter , David Ahern , Jiri Olsa , Namhyung Kim , Souvik Banerjee , Wang Nan Subject: [PATCH 4.19 114/205] perf callchain: Honour the ordering of PERF_CONTEXT_{USER,KERNEL,etc} Date: Mon, 19 Nov 2018 17:27:01 +0100 Message-Id: <20181119162635.069236405@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162616.586062722@linuxfoundation.org> References: <20181119162616.586062722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: David S. Miller commit e9024d519d892b38176cafd46f68a7cdddd77412 upstream. When processing using 'perf report -g caller', which is the default, we ended up reverting the callchain entries received from the kernel, but simply reverting throws away the information that tells that from a point onwards the addresses are for userspace, kernel, guest kernel, guest user, hypervisor. The idea is that if we are walking backwards, for each cluster of non-cpumode entries we have to first scan backwards for the next one and use that for the cluster. This seems silly and more expensive than it needs to be but it is enough for a initial fix. The code here is really complicated because it is intimately intertwined with the lbr and branch handling, as well as this callchain order, further fixes will be needed to properly take into account the cpumode in those cases. Another problem with ORDER_CALLER is that the NULL "0" IP that is at the end of most callchains shows up at the top of the histogram because every callchain contains it and with ORDER_CALLER it is the first entry. Signed-off-by: David S. Miller Tested-by: Arnaldo Carvalho de Melo Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Souvik Banerjee Cc: Wang Nan Cc: stable@vger.kernel.org # 4.19 Link: https://lkml.kernel.org/n/tip-2wt3ayp6j2y2f2xowixa8y6y@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/machine.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2140,6 +2140,27 @@ static int resolve_lbr_callchain_sample( return 0; } +static int find_prev_cpumode(struct ip_callchain *chain, struct thread *thread, + struct callchain_cursor *cursor, + struct symbol **parent, + struct addr_location *root_al, + u8 *cpumode, int ent) +{ + int err = 0; + + while (--ent >= 0) { + u64 ip = chain->ips[ent]; + + if (ip >= PERF_CONTEXT_MAX) { + err = add_callchain_ip(thread, cursor, parent, + root_al, cpumode, ip, + false, NULL, NULL, 0); + break; + } + } + return err; +} + static int thread__resolve_callchain_sample(struct thread *thread, struct callchain_cursor *cursor, struct perf_evsel *evsel, @@ -2246,6 +2267,12 @@ static int thread__resolve_callchain_sam } check_calls: + if (callchain_param.order != ORDER_CALLEE) { + err = find_prev_cpumode(chain, thread, cursor, parent, root_al, + &cpumode, chain->nr - first_call); + if (err) + return (err < 0) ? err : 0; + } for (i = first_call, nr_entries = 0; i < chain_nr && nr_entries < max_stack; i++) { u64 ip; @@ -2260,9 +2287,15 @@ check_calls: continue; #endif ip = chain->ips[j]; - if (ip < PERF_CONTEXT_MAX) ++nr_entries; + else if (callchain_param.order != ORDER_CALLEE) { + err = find_prev_cpumode(chain, thread, cursor, parent, + root_al, &cpumode, j); + if (err) + return (err < 0) ? err : 0; + continue; + } err = add_callchain_ip(thread, cursor, parent, root_al, &cpumode, ip,