Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp202955ybn; Thu, 3 Oct 2019 03:58:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxsrZzfIzbDw7ntrAKXEDDH/pa7jnPzhwxD8lJ4M/+hUidTrfNxYyBUzCa4H7M2fijjBni5 X-Received: by 2002:a05:6402:1ade:: with SMTP id ba30mr8921559edb.304.1570100281187; Thu, 03 Oct 2019 03:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570100281; cv=none; d=google.com; s=arc-20160816; b=TbuhqgMmVy2ElJkJanRkLqf2bR13boWYipthfDgAH5wzaCp98xbdk/rI4TP+iOsIdI xnMlnDWgvAhj2eI2FknnB2HN8lah1eHGSUoFphSe5LKWfNckxK2LpaO0b3xNKdGG2qcc aFSLWNKMRvy1MbrC+ukYvM7CEuOa8aWIcjMuDuf8SlQZkZvACErFiFNOacvhflj00Pmu J12jikFG0KGoXE3+Nu3z32X48nbH2gvUYAbLtt5Y1wWMYtf0U5isYWw6tjTMSG2KDIV/ QiDCCZ8P19hWwGpY4lGlRz3x/Z+P1mEUhfRUwr9i8fa37EK4iNOQBTzJvzubLvlhI0u2 kFYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=6SYTZcdmT0ico5n77mD/jrBPMxoN0jgg0P4b8OVtY+s=; b=jZoc33ZRpYq/E9DbeqNJykIjjnNrdbxB7l5fdCF02n+0kFMLF5KEnU+O1O4m4DdaBQ Im+ByLn1Q1/0vbdd8PLs5oSw3yEKMieHLTwEix0rtNBLJmveh34VsN/8ojw6Wbbu7Yd5 9sPdVhTHvUi16w5scuCkM25eiCVXClBGQDfW5QzZKIQgM57i6on5O3X+n3bscI1VOIUa m/8UM8Y4ZZSxdjSem3H6vplrVWHC1gD5hjrpg4Y26omCGwBtSxTC2lTTydFEu871mfBu sSsT40EgV85JoYOPZ5UZwwSZqYJ+QGDgEDY8Y92Xs4L4xmEh6kl60hZu1J3RidLdaNJB 3TxQ== 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 c10si1288940edc.419.2019.10.03.03.57.36; Thu, 03 Oct 2019 03:58:01 -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 S1729635AbfJCK5U (ORCPT + 99 others); Thu, 3 Oct 2019 06:57:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51538 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729392AbfJCK5U (ORCPT ); Thu, 3 Oct 2019 06:57:20 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A7D9B3090FEA; Thu, 3 Oct 2019 10:57:19 +0000 (UTC) Received: from krava (unknown [10.43.17.55]) by smtp.corp.redhat.com (Postfix) with SMTP id AACCD60BF3; Thu, 3 Oct 2019 10:57:17 +0000 (UTC) Date: Thu, 3 Oct 2019 12:57:16 +0200 From: Jiri Olsa To: Steve MacLean Cc: Steve MacLean , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Stephane Eranian , linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/4] perf inject --jit: Remove //anon mmap events Message-ID: <20191003105716.GB23291@krava> References: <1570049901-115628-1-git-send-email-steve.maclean@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1570049901-115628-1-git-send-email-steve.maclean@linux.microsoft.com> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 03 Oct 2019 10:57:19 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 02, 2019 at 01:58:21PM -0700, Steve MacLean wrote: > From: Steve MacLean > > While a JIT is jitting code it will eventually need to commit more pages and > change these pages to executable permissions. > > Typically the JIT will want these colocated to minimize branch displacements. > > The kernel will coalesce these anonymous mapping with identical permissions > before sending an MMAP event for the new pages. This means the mmap event for > the new pages will include the older pages. > > These anonymous mmap events will obscure the jitdump injected pseudo events. > This means that the jitdump generated symbols, machine code, debugging info, > and unwind info will no longer be used. > > Observations: > > When a process emits a jit dump marker and a jitdump file, the perf-xxx.map > file represents inferior information which has been superseded by the > jitdump jit-xxx.dump file. > > Further the '//anon*' mmap events are only required for the legacy > perf-xxx.map mapping. it's been some time I saw the code, Stephane? I added some comments below > > Summary: > > Add rbtree to track which pids have successfully injected a jitdump file. > > During "perf inject --jit", discard "//anon*" mmap events for any pid which > has successfully processed a jitdump file. > > Committer testing: > > // jitdump case > perf record > perf inject --jit --input perf.data --output perfjit.data > > // verify mmap "//anon" events present initially > perf script --input perf.data --show-mmap-events | grep '//anon' > // verify mmap "//anon" events removed > perf script --input perfjit.data --show-mmap-events | grep '//anon' > > // no jitdump case > perf record > perf inject --jit --input perf.data --output perfjit.data > > // verify mmap "//anon" events present initially > perf script --input perf.data --show-mmap-events | grep '//anon' > // verify mmap "//anon" events not removed > perf script --input perfjit.data --show-mmap-events | grep '//anon' > > Repro: > > This issue was discovered while testing the initial CoreCLR jitdump > implementation. https://github.com/dotnet/coreclr/pull/26897. > > Cc: Peter Zijlstra > Cc: Ingo Molnar > Cc: Arnaldo Carvalho de Melo > Cc: Mark Rutland > Cc: Alexander Shishkin > Cc: Jiri Olsa > Cc: Namhyung Kim > Cc: Stephane Eranian > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Steve MacLean > --- > tools/perf/builtin-inject.c | 4 +-- > tools/perf/util/jitdump.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 65 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c > index c14f40b8..4c921e0 100644 > --- a/tools/perf/builtin-inject.c > +++ b/tools/perf/builtin-inject.c > @@ -261,7 +261,7 @@ static int perf_event__jit_repipe_mmap(struct perf_tool *tool, > * if jit marker, then inject jit mmaps and generate ELF images > */ > ret = jit_process(inject->session, &inject->output, machine, > - event->mmap.filename, sample->pid, &n); > + event->mmap.filename, event->mmap.pid, &n); > if (ret < 0) > return ret; > if (ret) { > @@ -299,7 +299,7 @@ static int perf_event__jit_repipe_mmap2(struct perf_tool *tool, > * if jit marker, then inject jit mmaps and generate ELF images > */ > ret = jit_process(inject->session, &inject->output, machine, > - event->mmap2.filename, sample->pid, &n); > + event->mmap2.filename, event->mmap2.pid, &n); > if (ret < 0) > return ret; > if (ret) { > diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c > index 22d09c4..6a1563f 100644 > --- a/tools/perf/util/jitdump.c > +++ b/tools/perf/util/jitdump.c > @@ -751,6 +751,59 @@ static int jit_repipe_debug_info(struct jit_buf_desc *jd, union jr_entry *jr) > return 0; > } > > +struct pid_rbtree > +{ > + struct rb_node node; > + pid_t pid; > +}; > + > +static void jit_add_pid(struct rb_root *root, pid_t pid) > +{ > + struct rb_node **new = &(root->rb_node), *parent = NULL; we don't use the parenthesis like that > + struct pid_rbtree* data = NULL; > + > + /* Figure out where to put new node */ > + while (*new) { > + struct pid_rbtree *this = container_of(*new, struct pid_rbtree, node); there's rb_entry macro for this > + pid_t nodePid = this->pid; > + > + parent = *new; > + if (pid < nodePid) > + new = &((*new)->rb_left); > + else if (pid > nodePid) > + new = &((*new)->rb_right); > + else > + return; > + } > + > + data = malloc(sizeof(struct pid_rbtree)); plz check every allocation anyway, I wonder if you could just use thread::priv flag for that, like: thread = machine__findnew_thread(machine, pid, pid); if (!thread) bad (int) thread->priv = 1; and check on thread->priv when ruling the pid out, should be faster then maintain rb tree thanks, jirka