Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp538372yba; Wed, 24 Apr 2019 05:44:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxeJtwPGUI8x2pdjp17yt1BvwDSTUm5srgJ/I4S757lQK6gDGU916ruyYY+3CK4gQLzDzM X-Received: by 2002:a65:424a:: with SMTP id d10mr30064710pgq.335.1556109866955; Wed, 24 Apr 2019 05:44:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556109866; cv=none; d=google.com; s=arc-20160816; b=scwWfVB8ZPb8FD1656lnFrwjMqR6AXNCq8m7av4VQVdftQQKrcdJwXfHV6WWAFydbT aTxgdTJvqYlECC1xUGAQtyq34d49eCoF1fLDSJ4LogXvi7a1QGeuH4oNzpePwn8ZUUtx 1F1ogdyCRY1imxFVRdMQPwl55madJzdbh53zuL5dnCHFUFP0C5BWcqS/Y+rssXr8Xa8z KU8kzsZV8URphNtiDHYPMepg1NJHHXk8CBQ/JteNDOB4ERBwy5NBBes9pKPONiBfk8C/ A3zK2uLtiG/jC8Yxj75C2wk4zIMkuk6WEHdTfgZCb645HGbhRJPXaAflmHA0a4JbcA1z 5MlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=qH/I56NCmI+3may9AdNh6uFn3lE6ttyh9s1gBQhKvDQ=; b=o70J9l0hPrk6xtkm2EREpchDDdZJXWB9JOG1sZBwViAeHtAtMnSk/ouzF98nwzkQrA tmVcLNdS1xPBQILV3Vl4HV8dumhcF7q35kn7wVLIu89GR29x0OyEq4r0Q/SPLsmUSoo9 uI0+K0cUnboYfi7+NbS1It9xqlkol8Jk0I291yaNoXTPa/+EIqVZJpoAgzFF8ugUhdeC AxOJGmL973l/S3UPlODf/HtTf2FMnuh34uG7cFESqPQA8iI1/+SYaJKKJZEb3XaXmSFI BOet+2PnaiB9fePmvAO7AgTzeqaezdZry4Mx4QQQj8SBFeBYBGQgqj9vcOmkYvtR/Z/K TaPg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si17368165pgr.167.2019.04.24.05.44.11; Wed, 24 Apr 2019 05:44:26 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730080AbfDXMmx (ORCPT + 99 others); Wed, 24 Apr 2019 08:42:53 -0400 Received: from mail-it1-f196.google.com ([209.85.166.196]:54120 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726167AbfDXMmw (ORCPT ); Wed, 24 Apr 2019 08:42:52 -0400 Received: by mail-it1-f196.google.com with SMTP id z4so1798821itc.3 for ; Wed, 24 Apr 2019 05:42:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qH/I56NCmI+3may9AdNh6uFn3lE6ttyh9s1gBQhKvDQ=; b=qq7ojNIhdRydTIowX7GuTeBGSz837WT1oQxJdnyF/b4dyUWHwxrCTf6//fbAuFoz9v TMYmTfxFIh38Jl+wSYbuVfDcBuCsvHcXTik/kE+rSUyMIsj4ZWdoE0mRsMcL3R3OqJi0 ttuje8fHat0/LGyB8JKOS8pSLgMXsHLymMQoVfgelVUMxmQIxUcors4r1PpMl3MdMH5r 5HTP9a60IAUQrrMwq0jUnTe7318AWy7E1BtMMeZGuBBzt9/taj2T7g+IhnymbOi/DguU 1CXi5NuvgbGNKtsty/EGJfN8cy9qCuOcvSVGdcpeP8YpzmIyOUcNLbkojVX+ZQ/Lazxl u/Hg== X-Gm-Message-State: APjAAAUQqyfX6kFxNG2rijJSElQfzbW0gQuVozNxkFUkrJmeavZsIZxE rwGCMwGP84WXtUpMZsYZfOKzbpMTbnX1wwiKj7ZSMw== X-Received: by 2002:a02:3342:: with SMTP id k2mr20225459jak.15.1556109771692; Wed, 24 Apr 2019 05:42:51 -0700 (PDT) MIME-Version: 1.0 References: <20190422162652.15483-1-kasong@redhat.com> <20190423113501.GN11158@hirez.programming.kicks-ass.net> In-Reply-To: <20190423113501.GN11158@hirez.programming.kicks-ass.net> From: Kairui Song Date: Wed, 24 Apr 2019 08:42:40 -0400 Message-ID: Subject: Re: [RFC PATCH v4] perf/x86: make perf callchain work without CONFIG_FRAME_POINTER To: Peter Zijlstra Cc: Linux Kernel Mailing List , Josh Poimboeuf , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Alexei Starovoitov , Namhyung Kim , Thomas Gleixner , Borislav Petkov , Dave Young Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 23, 2019 at 7:35 AM Peter Zijlstra wrote: > > On Tue, Apr 23, 2019 at 12:26:52AM +0800, Kairui Song wrote: > > Currently perf callchain doesn't work well with ORC unwinder > > when sampling from trace point. We'll get useless in kernel callchain > > like this: > > > > perf 6429 [000] 22.498450: kmem:mm_page_alloc: page=0x176a17 pfn=1534487 order=0 migratetype=0 gfp_flags=GFP_KERNEL > > ffffffffbe23e32e __alloc_pages_nodemask+0x22e (/lib/modules/5.1.0-rc3+/build/vmlinux) > > 7efdf7f7d3e8 __poll+0x18 (/usr/lib64/libc-2.28.so) > > 5651468729c1 [unknown] (/usr/bin/perf) > > 5651467ee82a main+0x69a (/usr/bin/perf) > > 7efdf7eaf413 __libc_start_main+0xf3 (/usr/lib64/libc-2.28.so) > > 5541f689495641d7 [unknown] ([unknown]) > > > > The root cause is that, for trace point events, it doesn't provide a > > real snapshot of the hardware registers. Instead perf tries to get > > required caller's registers and compose a fake register snapshot > > which suppose to contain enough information for start a unwinding. > > However without CONFIG_FRAME_POINTER, if failed to get caller's BP as the > > frame pointer, so current frame pointer is returned instead. We get > > a invalid register combination which confuse the unwinder, and end the > > stacktrace early. > > > > So in such case just don't try dump BP, and let the unwinder start > > directly when the register is not a real snapshot. And Use SP > > as the skip mark, unwinder will skip all the frames until it meet > > the frame of the trace point caller. > > > > Tested with frame pointer unwinder and ORC unwinder, this make perf > > callchain get the full kernel space stacktrace again like this: > > > > perf 6503 [000] 1567.570191: kmem:mm_page_alloc: page=0x16c904 pfn=1493252 order=0 migratetype=0 gfp_flags=GFP_KERNEL > > ffffffffb523e2ae __alloc_pages_nodemask+0x22e (/lib/modules/5.1.0-rc3+/build/vmlinux) > > ffffffffb52383bd __get_free_pages+0xd (/lib/modules/5.1.0-rc3+/build/vmlinux) > > ffffffffb52fd28a __pollwait+0x8a (/lib/modules/5.1.0-rc3+/build/vmlinux) > > ffffffffb521426f perf_poll+0x2f (/lib/modules/5.1.0-rc3+/build/vmlinux) > > ffffffffb52fe3e2 do_sys_poll+0x252 (/lib/modules/5.1.0-rc3+/build/vmlinux) > > ffffffffb52ff027 __x64_sys_poll+0x37 (/lib/modules/5.1.0-rc3+/build/vmlinux) > > ffffffffb500418b do_syscall_64+0x5b (/lib/modules/5.1.0-rc3+/build/vmlinux) > > ffffffffb5a0008c entry_SYSCALL_64_after_hwframe+0x44 (/lib/modules/5.1.0-rc3+/build/vmlinux) > > 7f71e92d03e8 __poll+0x18 (/usr/lib64/libc-2.28.so) > > 55a22960d9c1 [unknown] (/usr/bin/perf) > > 55a22958982a main+0x69a (/usr/bin/perf) > > 7f71e9202413 __libc_start_main+0xf3 (/usr/lib64/libc-2.28.so) > > 5541f689495641d7 [unknown] ([unknown]) > > > > Co-developed-by: Josh Poimboeuf > > Signed-off-by: Kairui Song > > Thanks! > > > diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h > > index e47ef764f613..ab135abe62e0 100644 > > --- a/include/linux/perf_event.h > > +++ b/include/linux/perf_event.h > > @@ -1059,7 +1059,7 @@ static inline void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned lo > > * the nth caller. We only need a few of the regs: > > * - ip for PERF_SAMPLE_IP > > * - cs for user_mode() tests > > - * - bp for callchains > > + * - sp for callchains > > * - eflags, for future purposes, just in case > > */ > > static inline void perf_fetch_caller_regs(struct pt_regs *regs) > > I've extended that like so: > > --- a/include/linux/perf_event.h > +++ b/include/linux/perf_event.h > @@ -1058,12 +1058,18 @@ static inline void perf_arch_fetch_calle > #endif > > /* > - * Take a snapshot of the regs. Skip ip and frame pointer to > - * the nth caller. We only need a few of the regs: > + * When generating a perf sample in-line, instead of from an interrupt / > + * exception, we lack a pt_regs. This is typically used from software events > + * like: SW_CONTEXT_SWITCHES, SW_MIGRATIONS and the tie-in with tracepoints. > + * > + * We typically don't need a full set, but (for x86) do require: > * - ip for PERF_SAMPLE_IP > * - cs for user_mode() tests > - * - sp for callchains > - * - eflags, for future purposes, just in case > + * - sp for PERF_SAMPLE_CALLCHAIN > + * - eflags for MISC bits and CALLCHAIN (see: perf_hw_regs()) > + * > + * NOTE: assumes @regs is otherwise already 0 filled; this is important for > + * things like PERF_SAMPLE_REGS_INTR. > */ > static inline void perf_fetch_caller_regs(struct pt_regs *regs) > { Sure, the updated comments looks much better. Will the maintainer squash the comment update or should I send a V5? -- Best Regards, Kairui Song