Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1920695pxk; Sun, 13 Sep 2020 22:40:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyBcYv4rOWoc7W72Mep6wylx8DO9y6pz4eP0IauEsI7DNNMgT+l/oE5MvzgGg30O+Oya2r X-Received: by 2002:a17:906:c289:: with SMTP id r9mr13637152ejz.402.1600062038624; Sun, 13 Sep 2020 22:40:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600062038; cv=none; d=google.com; s=arc-20160816; b=Hv6zH8o72cAM7GBpBTTgiLqKu9glgAlOYdCnzytrOB4P9dyawX1fLwxhForI1ETwL+ rniOjJ6VSwhVpE4d8a+sENV9UoSvEAxcql2EQOhJmR5ZZU71nVjyY8w+SUbbv3uJeay3 3/lChHlKwjYStVPP6jQFzsTIodqacUNL8WNo05vFSzK+FDIrSEOoR10zdzLlIgLeRyNP sIWyA2VC6vyadDwxSDfBwMueBwm7QzN3UwYg9enrCt3cjhOJh8mDuAxu6gFs/GRDJf6E XYZBWXmyPxZ9ioB9bdOjtjoaOVCePMcodJxVDrqfzSNv7Snzg/9gimG/ZC79e6TVAqlI mk2Q== 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=H8QFwCG5mYnHRxaGdvZtDFz1aJ8Aevr6zjHyKrFYWKk=; b=K+hK4TwDAdvBSEW35WQYqdZNZ2h0GecpgcK6RUPHmys5DZ2QHK82m/pKSATPy6W32X 6lKwsUlUhRGwnTQ4gBlnlnWiKVJQz41fi1X4X8KGDM94YAGRpOpPLzWZqg0EbFPweCs3 eZXDu0TAS94a4/CXd7OKhf25AqQShUw3Z7uvUrofT18famiKzwpVnCaXAYGHWPcoYnSE pT9zKle6JCtTKL1sQOoxmq7MrxDfup3rPNkmLYYKX2GogBOf6L3gJ1yd3G/WvLTgvNj1 pWfTMXGOMHls0ir23AKN+UhSaupxOIqZk7ed415BBm/RMP52QVB02W3r9kTGVQbBXfSN ocyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id ga23si6264185ejb.691.2020.09.13.22.40.16; Sun, 13 Sep 2020 22:40:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726052AbgINFi2 (ORCPT + 99 others); Mon, 14 Sep 2020 01:38:28 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52183 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726003AbgINFiZ (ORCPT ); Mon, 14 Sep 2020 01:38:25 -0400 Received: by mail-wm1-f67.google.com with SMTP id w2so9377639wmi.1 for ; Sun, 13 Sep 2020 22:38:39 -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=H8QFwCG5mYnHRxaGdvZtDFz1aJ8Aevr6zjHyKrFYWKk=; b=lOwk70hecvbosD+VfgQZO9ERCEKElA5d9zNOc4UjWvKRuPs6yhkYvEhghFV0TCOzva 3S6uOqIx6/bcvNwsq9qi7Apoe3Ea+Pn3NgZTsp7vyFNhxsEKLbiU+SCWtZ/E61K49CYG jxW9G+bj9pT1Jq1Ava6Qh+hxIl514DbzQEWRU3I3rigXfyKrKPcPny8p1UEE27Se/ZwO 4PxMumKbPfRARiXNqaRAF/HSoBg9DPT5QcI1V9awESjTp59NB5kAlej5UopEFR2iRKGK Ev84I3udybVnbE7rZS06uAaFLRrpHYjVj/rcdek+yrJ+iZ8eZHH8dgj0fMpZ2r97R7xS 01eQ== X-Gm-Message-State: AOAM531tqu9kKas9Lg7eBd+iGJdjs0uVKpxou3Ej0LfJOuWzhkO1THi8 xoSPaYsDc6Dn1eB9ieHf0mxdXwcB/qWldZfmkvY= X-Received: by 2002:a7b:c404:: with SMTP id k4mr13171238wmi.168.1600061918945; Sun, 13 Sep 2020 22:38:38 -0700 (PDT) MIME-Version: 1.0 References: <20200913210313.1985612-1-jolsa@kernel.org> <20200913210313.1985612-3-jolsa@kernel.org> In-Reply-To: <20200913210313.1985612-3-jolsa@kernel.org> From: Namhyung Kim Date: Mon, 14 Sep 2020 14:38:27 +0900 Message-ID: Subject: Re: [PATCH 02/26] perf: Introduce mmap3 version of mmap event To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Michael Petlan , Song Liu , "Frank Ch. Eigler" , Ian Rogers , Stephane Eranian , Alexey Budankov , Andi Kleen , Adrian Hunter 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 Mon, Sep 14, 2020 at 6:03 AM Jiri Olsa wrote: > > Add new version of mmap event. The MMAP3 record is an > augmented version of MMAP2, it adds build id value to > identify the exact binary object behind memory map: > > struct { > struct perf_event_header header; > > u32 pid, tid; > u64 addr; > u64 len; > u64 pgoff; > u32 maj; > u32 min; > u64 ino; > u64 ino_generation; > u32 prot, flags; > u32 reserved; > u8 buildid[20]; Do we need maj, min, ino, ino_generation for mmap3 event? I think they are to compare binaries, then we can do it with build-id (and I think it'd be better).. > char filename[]; > struct sample_id sample_id; > }; > > Adding 4 bytes reserved field to align buildid data to 8 bytes, > so sample_id data is properly aligned. > > The mmap3 event is enabled by new mmap3 bit in perf_event_attr > struct. When set for an event, it enables the build id retrieval > and will use mmap3 format for the event. > > Keeping track of mmap3 events and calling build_id_parse > in perf_event_mmap_event only if we have any defined. > > Having build id attached directly to the mmap event will help > tool like perf to skip final search through perf data for > binaries that are needed in the report time. Also it prevents > possible race when the binary could be removed or replaced > during profiling. > > Signed-off-by: Jiri Olsa > --- > include/uapi/linux/perf_event.h | 27 ++++++++++++++++++++++- > kernel/events/core.c | 38 +++++++++++++++++++++++++++------ > 2 files changed, 57 insertions(+), 8 deletions(-) > > diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h > index 077e7ee69e3d..facfc3c673ed 100644 > --- a/include/uapi/linux/perf_event.h > +++ b/include/uapi/linux/perf_event.h > @@ -384,7 +384,8 @@ struct perf_event_attr { > aux_output : 1, /* generate AUX records instead of events */ > cgroup : 1, /* include cgroup events */ > text_poke : 1, /* include text poke events */ > - __reserved_1 : 30; > + mmap3 : 1, /* include bpf events */ ??? > + __reserved_1 : 29; > > union { > __u32 wakeup_events; /* wakeup every n events */ > @@ -1060,6 +1061,30 @@ enum perf_event_type { > */ > PERF_RECORD_TEXT_POKE = 20, > > + /* > + * The MMAP3 records are an augmented version of MMAP2, they add > + * build id value to identify the exact binary behind map > + * > + * struct { > + * struct perf_event_header header; > + * > + * u32 pid, tid; > + * u64 addr; > + * u64 len; > + * u64 pgoff; > + * u32 maj; > + * u32 min; > + * u64 ino; > + * u64 ino_generation; > + * u32 prot, flags; > + * u32 reserved; > + * u8 buildid[20]; > + * char filename[]; > + * struct sample_id sample_id; > + * }; > + */ > + PERF_RECORD_MMAP3 = 21, > + > PERF_RECORD_MAX, /* non-ABI */ > }; > [SNIP] > @@ -8098,6 +8116,9 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event) > mmap_event->prot = prot; > mmap_event->flags = flags; > > + if (atomic_read(&nr_mmap3_events)) > + build_id_parse(vma, mmap_event->buildid); What about if it failed? We should zero out the build-id.. Thanks Namhyung > + > if (!(vma->vm_flags & VM_EXEC)) > mmap_event->event_id.header.misc |= PERF_RECORD_MISC_MMAP_DATA; > > @@ -8241,6 +8262,7 @@ void perf_event_mmap(struct vm_area_struct *vma) > /* .ino_generation (attr_mmap2 only) */ > /* .prot (attr_mmap2 only) */ > /* .flags (attr_mmap2 only) */ > + /* .buildid (attr_mmap3 only) */ > }; > > perf_addr_filters_adjust(vma); > @@ -11040,6 +11062,8 @@ static void account_event(struct perf_event *event) > inc = true; > if (event->attr.mmap || event->attr.mmap_data) > atomic_inc(&nr_mmap_events); > + if (event->attr.mmap3) > + atomic_inc(&nr_mmap3_events); > if (event->attr.comm) > atomic_inc(&nr_comm_events); > if (event->attr.namespaces) > -- > 2.26.2 >