Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1051472lqt; Tue, 19 Mar 2024 11:09:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUwwwkxvfMPKJZIZXWcoJ7urudonVxkSVAAF6qcE7zNO7Ns9qtdZzYf9ZoHG7TC/B90wHuM8fRk/nFSLRkaAnLvmawFRwZ16EIbt2V+ZA== X-Google-Smtp-Source: AGHT+IHHJDgZ8QK+PqL/Nr4DlvSBpGGFuBlzd0y5sXJ7tyADEwvuUM2iwavWQorf8fDHqd2yFIyT X-Received: by 2002:a05:6214:5641:b0:691:46ee:6aba with SMTP id mh1-20020a056214564100b0069146ee6abamr15403220qvb.20.1710871786617; Tue, 19 Mar 2024 11:09:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710871786; cv=pass; d=google.com; s=arc-20160816; b=n3wQcNaRDVY/jYA788EwofNfj5tUv/BOgfSE35cChpEf8mf6LnNJ0jT9m8ogvhW1mP dqnCJPKTg1I5iUAW5mQzrXTc/EOxzhzqyNnoaMBbAl3MI/2eVHTlEH09fFwX2tWe4y2w E9AUkHXCO3kHWuxXfKRqV4rEDfDXwiFeRJ7gpCCg8MxEdiMBqR6qBecsoq2WMAjlCuvs WsZFPhMpHsS0LxcI1k0WhiZB1HSl5k6H+CKrhIniLJG4wu9dGy+202km+xVja2Xv/bPf wFQFx0dP6EBW1ADPEP2xj25Nidr1VL4XP5wiBAXgtJh/6LWBmx3DV5r81ToCwtHn2Rlo yZ1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=NKo/a2KG8rP6Dx+mWz5taLr60kXgAibeZcxH5ckILHs=; fh=W3KJ4rXcu85ubgqT2134A/cdx6WzcKhVk/3nUKtpIrQ=; b=NS6nobxD84rDJtIRSXydTbi4/4EkspUAgAtU4iheYs+7ln62gQNSExiJOuvpvh5C46 lDm1EnAkSxzKYN3LHqoLQTYzyU502cNSMghMblNGsxl9mj0gsxh5gzK+QI/OoIfCVf+j Odi9xd7wrzgFjCb7FKyrpVWSqJCYtghtDSeJ47lItWD2Nmt+/dcRm4/Od6x42OVlYlz8 waWYeurSTOtFs+BcdGfUMFXPoV8/2T+WG9Uazf+Xtbv+2u1KLB8cW5s3VKObiMSB4lXc WMF29oMaQzOGEtX9GmPu6DG8pFap96NQwArzp+SfoRJbR1xYBlN7l65WIik94vMebIMY zclA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C0DENtvZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107980-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107980-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gv1-20020a056214262100b0068f44562bbasi11344152qvb.167.2024.03.19.11.09.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 11:09:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107980-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C0DENtvZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107980-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107980-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5823D1C23268 for ; Tue, 19 Mar 2024 18:09:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA46D2C19F; Tue, 19 Mar 2024 18:09:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="C0DENtvZ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F05A52D046; Tue, 19 Mar 2024 18:09:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710871778; cv=none; b=rgabei+1QW4uifKHY/st4mygLiFU9euIr8PaEtyZ+4pUb/uzoTtTth0eLklLnsvl6YDJIpqktXZT67umogMhvI7sD4d08M88+YH0zkPOgEhXnu2qnjS0QCHN1GgmWHvcglNFymxspfnaE1axGLNxGnP68lvQFrDVBmz9NGXxGCw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710871778; c=relaxed/simple; bh=ugoMpbER9K+KatX2IyLi4yOo5eMLV9vLE9hxz5xaacw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZTlRrwB7rgJDG6LLarSAlWtLpC6r+cfh9SlX8SCSIF9gWbaaHyxkQONI+07SANv+JbRWc8NCunGHM5KGI9TSDjvuAnBbgmke86l/z9XuATSdvyZQjLA2YBhAQLdm0JV3QLZ74RCrXQx3d+t9clWy0lyb3nzmLkD4YSftC9k42IY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C0DENtvZ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84A60C433C7; Tue, 19 Mar 2024 18:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710871777; bh=ugoMpbER9K+KatX2IyLi4yOo5eMLV9vLE9hxz5xaacw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=C0DENtvZOR3Om08P/g36xouiKADw24Pko0NrJeElpXbj9buRZzo69E7ryPsyiP85Q qBDMY+TurVzuvj0YEVk2K4UxIEit8SYsMnF/JLcyocglQZF8LxTZHIzwppF693HT+V SHg/pB2tV4FmduLbo6sYidSdAND0F6OVRq0+/FXxIyqs1WMNO1hYzLnufDvIB4HUku OoyJAwJrCqNrMsziDA4A+1ksYPsD7j0Y/qKoHxzJfUFQ+hawtlhhEP3Hrj8yKxB5sx Y+HiQ3WqGe2mpFZlwQxwn6vdcdZtp/owmEZ2oDnyRFk7l1kXcaI2SSUckfoQlrqfzb zmLJOqkxIG4Pg== Date: Tue, 19 Mar 2024 15:09:32 -0300 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ian Rogers , Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: Re: [PATCH 22/23] perf annotate-data: Add a cache for global variable types Message-ID: References: <20240319055115.4063940-1-namhyung@kernel.org> <20240319055115.4063940-23-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Mar 19, 2024 at 03:07:19PM -0300, Arnaldo Carvalho de Melo wrote: > On Tue, Mar 19, 2024 at 11:05:04AM -0700, Namhyung Kim wrote: > > On Mon, Mar 18, 2024 at 10:56 PM Namhyung Kim wrote: > > > > > > They are often searched by many different places. Let's add a cache > > > for them to reduce the duplicate DWARF access. > > > > > > Signed-off-by: Namhyung Kim > > > --- > > > tools/perf/util/annotate-data.c | 107 +++++++++++++++++++++++++++++++- > > > tools/perf/util/annotate-data.h | 7 +++ > > > tools/perf/util/dso.c | 2 + > > > tools/perf/util/dso.h | 6 +- > > > 4 files changed, 118 insertions(+), 4 deletions(-) > > > > > > diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c > > > index 633fe125fcd8..4b3184b7c799 100644 > > > --- a/tools/perf/util/annotate-data.c > > > +++ b/tools/perf/util/annotate-data.c > > > @@ -433,6 +433,91 @@ static struct type_state_stack *findnew_stack_state(struct type_state *state, > > > return stack; > > > } > > > > > > +/* Maintain a cache for quick global variable lookup */ > > > +struct global_var_entry { > > > + struct rb_node node; > > > + char *name; > > > + u64 start; > > > + u64 end; > > > + u64 die_offset; > > > +}; > > > + > > > +static int global_var_cmp(const void *_key, const struct rb_node *node) > > > +{ > > > + const u64 addr = (uintptr_t)_key; > > > + struct global_var_entry *gvar; > > > + > > > + gvar = rb_entry(node, struct global_var_entry, node); > > > + > > > + if (gvar->start <= addr && addr < gvar->end) > > > + return 0; > > > + return gvar->start > addr ? -1 : 1; > > > +} > > > + > > > +static bool global_var_less(struct rb_node *node_a, const struct rb_node *node_b) > > > +{ > > > + struct global_var_entry *gvar_a, *gvar_b; > > > + > > > + gvar_a = rb_entry(node_a, struct global_var_entry, node); > > > + gvar_b = rb_entry(node_b, struct global_var_entry, node); > > > + > > > + return gvar_a->start < gvar_b->start; > > > +} > > > + > > > +static struct global_var_entry *global_var__find(struct data_loc_info *dloc, u64 addr) > > > +{ > > > + struct dso *dso = map__dso(dloc->ms->map); > > > + struct rb_node *node; > > > + > > > + node = rb_find((void *)addr, &dso->global_vars, global_var_cmp); > > > > It seems to cause a build error on 32-bit systems. It needs one > > more cast to suppress the "pointer cast w/ different size" warning. > > > > node = rb_find(void *)(uintptr_tr)addr, ...); uintptr_t > > I can add that, to speed up the process, ok? Done diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c index 4b3184b7c79942b4..969e2f82079cdec5 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -469,7 +469,7 @@ static struct global_var_entry *global_var__find(struct data_loc_info *dloc, u64 struct dso *dso = map__dso(dloc->ms->map); struct rb_node *node; - node = rb_find((void *)addr, &dso->global_vars, global_var_cmp); + node = rb_find((void *)(uintptr_t)addr, &dso->global_vars, global_var_cmp); if (node == NULL) return NULL;