Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp6310629imd; Wed, 31 Oct 2018 09:47:29 -0700 (PDT) X-Google-Smtp-Source: AJdET5cY7qBzVHFD4iELZ8ZySUlyw6fmZLuRE7Wb4Hf5C4a21Vyyz808djHFxy+AuAqZyD7aAng5 X-Received: by 2002:a63:584a:: with SMTP id i10-v6mr3912690pgm.178.1541004449685; Wed, 31 Oct 2018 09:47:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541004449; cv=none; d=google.com; s=arc-20160816; b=fjtqmKk2YYiP5ayfnBg/7D//mKO4NvgksiahYaBXt7o7GgrtrbEHvomKuOfmgRYlN0 23N3WkL5gzGsD74PTQDJT0JNdmQu/M+R2LMq2SHVwukju7GzbHlaNGqzwSpLh5gJvbai buGaSya33cByxFHi55ZkQfxsk6W/6OGqbuDwKtBr23PnuokrA4oySnOCD5ImZ+5qy8F8 CMqrz02QHP0zErDu1ue2i/+HeUGdiANRRvQHtqc7u3cHnRnOWjxvQLZl6SgG41wAnQ2g +FNfRr8tDfaOr6mO52rv1v32GMzl04fNrL3m9ec9ZKAu2OhteYaWBWMRSmmx6+2uc1OD fCPA== 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=W9gk1N88p3qJ2U1kH6Y+zOz1EMpE/DsdQ7qYMxzST/M=; b=x+fTKiEDjbPWnKUAxm9I7o6kwHesFFOpuZPsuSysIoGM5O/qk5goEKNOgIWmYDFKNm W01yK1Xqga3K7DdLR/9xT6l4upbi+FvNoyaHh4RebLntvYJWIRfkZRB9H4XdWanpMelM iNtaecFBxYBhow/9USf80FVsdvR/S7v81Dz/S1/ZW4183jBg+XmaF+mNqSUQ1gUznh7V XhXxXXGnZghZ0SX7N5RWkPk9LcFCawmWG+9Bj2qb4dT9OUhLRLye2x0ARLTbCNlmnZR7 khxiXLr1k4HKKgJjYsoC6wo5B4KsMetRp2AN81ZKMAydB3WphbGJwWBrjO6xkWUbqGb/ Jyeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jQYjZVsJ; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3-v6si17916728pld.186.2018.10.31.09.47.14; Wed, 31 Oct 2018 09:47:29 -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=@kernel.org header.s=default header.b=jQYjZVsJ; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730105AbeKABpB (ORCPT + 99 others); Wed, 31 Oct 2018 21:45:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:59600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729810AbeKABpA (ORCPT ); Wed, 31 Oct 2018 21:45:00 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (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 77A0D2081B; Wed, 31 Oct 2018 16:46:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541004372; bh=MSBkrZ1n1C5j52pGxoXzirJu6YbOiKrE3z35YiGDe4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jQYjZVsJ62Ii8+wyEpZzg0yriyIxFwXGv3NyPyTl6zeOyqAm/GmlCsoi6w8rMdT4H BBeL/MVIfY3Oezye6mpr2sCtFX9uc37hmGVztZJOh3VLFfbHJKTeHJHZltwNtD58xi vpQlCPdUHT8dZFig/8M3Hrk0lwdTTOhP84Oamrys= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, "David S. Miller" , Adrian Hunter , David Ahern , Jiri Olsa , Namhyung Kim , Souvik Banerjee , Wang Nan , stable@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH 14/28] perf callchain: Honour the ordering of PERF_CONTEXT_{USER,KERNEL,etc} Date: Wed, 31 Oct 2018 13:44:54 -0300 Message-Id: <20181031164508.4784-15-acme@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181031164508.4784-1-acme@kernel.org> References: <20181031164508.4784-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "David S. Miller" 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 --- tools/perf/util/machine.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 111ae858cbcb..8ee8ab39d8ac 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2140,6 +2140,27 @@ static int resolve_lbr_callchain_sample(struct thread *thread, 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_sample(struct thread *thread, } 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 @@ static int thread__resolve_callchain_sample(struct thread *thread, 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, -- 2.14.4