Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1051846lqt; Tue, 19 Mar 2024 11:10:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV32QrEp7TZ+o28JdAZgN2Gvi1sN1o0oipE8jY5xs3yeHPDXJgzYxo6Z3U1ycwFZO/SNaf8vCJREtH+11T+OQrsisre7zhGO3sW3mviXg== X-Google-Smtp-Source: AGHT+IGCeDytDdh/MiXdvy+u6jJMaMKxh/xkj2BdBE+XuDkC62VFnXs3TTt87mMdkDazTs3h0Unz X-Received: by 2002:a05:6808:312:b0:3c3:9457:3557 with SMTP id i18-20020a056808031200b003c394573557mr3104375oie.15.1710871818609; Tue, 19 Mar 2024 11:10:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710871818; cv=pass; d=google.com; s=arc-20160816; b=Cr29oxCvVtQ/5fqKVtdaTQvWh+44ukCtzHB0PNn22NMCkayxe4NE07o6QpRJOa3slq YUMYIixqYSeZQ8QjnY7Kj/OK+LEetw2X6tHIwB03YRFm1IWbyBo90PW6xpYfkiPHzXwk 6fRggh2eK/sgWgeQzH+BK9hbFBtAh1vsGsbo7fuln7SqJkvkb110nuLuCK0oGtTxMNJ0 KrMXvlWgLawKWs5IXrzLafEPHCekon6jfW6rvXYsBgwoykERWl46yK0bRRXieM93xzE7 NEbHbovPCkM6/Zilh8zoRlwex1ghrDdj/QK3bLxmeaEoiRuIHN1zMhZU8Q6mZ8nCP5FR zd3g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=mIMLYVE6CyTm+xoNKJoABJx7QmXwGTxTuG4FdhVieQQ=; fh=Pq1n41BJF6GqYkqI5OmrsJ+jN6/ropTtY7XzAUjmulE=; b=VaYCx8FLmnFMWKzQz2ITy8jVnAdGiRxFCeb/LgrxSWzYiMG94EvOvMogaOwedDwjXY DyTnsyYfxTt3XG5+udmKy5fllE7ANKhg3EHO919EB2R+mEVL0jAdc6aroKEte9w5rlzI yz6zpFq/PNkdJqnLVV9II/RmXKPDP/ER78zxRMKcX2IkDWL3P/5aGdN0jKSJuMMgOKve B7AkWJk7RQenEUtAK2DJ7bwSv4u926W9qn3o5Uz4/pWNPcaBABdVlmqxKxNH9PrTOA6L cCWZejTuEG7Zp5x2GVzCEyXhaAWMsZA1zr7G1LRh38GfgLNbQw9YIk5dhysDsFLcCOeE mbGQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-107981-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107981-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id h4-20020a05622a170400b00430ed15ab91si1336071qtk.715.2024.03.19.11.10.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 11:10:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107981-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-107981-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107981-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 573561C22634 for ; Tue, 19 Mar 2024 18:10:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D4DA92C1A7; Tue, 19 Mar 2024 18:10:11 +0000 (UTC) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E80652E401; Tue, 19 Mar 2024 18:10:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710871811; cv=none; b=rvh9x0zFR4PJmeT4piKzbT6av48b3TDy57OMPpj9dYf2UTLAi5kvkPsvbf3o9r4BC/v7LYsFx7D7NHjMs/iF85hA2zFRyr5Ivd2U6sN7CYBlIxydjAx4RC1vgCKl4qWtV/MSZSzSVFxLe2KPMqWo4HYoesDxHoEVoqCL7IHsN2E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710871811; c=relaxed/simple; bh=xD4aOHRhHuw1j3plQj9V4WOL6Uu7nCb+GdWr5HHMcyw=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=unvJmKqBCjr8f7hYcTRbwtZ6S3dc/uV/2Zp0LXMIyylku+8HVZSUd4D/9ebB/Dt+DnQymdpBbuM/KmPVnT1m0zR3l5nL15B1y9Ed6+mbRcjdMq6PXVN7nHYlJR8dQwT6Rkv5fJbjMTiyi/O6zg39VLRs/H/wgHquSmdquAaBn+A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e6afb754fcso5585583b3a.3; Tue, 19 Mar 2024 11:10:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710871809; x=1711476609; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mIMLYVE6CyTm+xoNKJoABJx7QmXwGTxTuG4FdhVieQQ=; b=xFaXjMd/WzhMpfORKoRpa7kG31lnXij+VtqdZRWTnZE/ETJ/HEvKo2ntrKBdJ4j40s clWDfKZGgQeHcrlxul9YFxZotIpkp79XOzx80s8z7tg3EF1lwtV4H5Vk0C1VHIDFTmEo FBhT3DVWsanv9NhbdL1G8DVOUxQs89chET8Jk2vao16xATayRgf9OPmOtpgB1vRb2SVG 4Ti5fiUF2V0xhdKppMQ7sBxo55oNAYTXs/uYDT2CBrQfUj0JosvDau44wViorEEvaERP WmTGsaEdgHvoPfRKI9TuDHcjcwbltRbfYWfHMntMf3610orqHE22XV+hArKMU7z0KVdU IShA== X-Forwarded-Encrypted: i=1; AJvYcCWp1j/XgZaF3ZEmM6rGf8/WpBxagVk4vdkUtbBq+9cqYXp0yLLHnGVz0R8Q9NDcGiUYhHPYKAM9hPiSaTSomIJDpIXazjS/TwbMCbJEKRZQpXt+23GooYRfukOxE676xENfySi4LSjztKx1gLjjnaz2Yj2XIkR3fV7uG1oIyOe6a4rr//kjPh+HBg1ZIUGuCNV6CLCGQib+VjYKGeIEYFkxNfMo3m2Se4bl9DK11aNZPkdwQw== X-Gm-Message-State: AOJu0YwL8d+pJFe4oDMwjEN598nEzREZpQcLRpBe/2yc5dZ29PNNRLTS uCeq4m59AJfc59bXvc9DbcqbI+USOEBtCtscnq4mqOnj4jDi6PE2hx3mF/l7MGJiN89YBoZiMA4 XDL0DXnF8EpTh/mWA5vwP0Cg1hXZ/EW3U X-Received: by 2002:a05:6a20:dd86:b0:1a3:4670:fbbf with SMTP id kw6-20020a056a20dd8600b001a34670fbbfmr15636738pzb.50.1710871809147; Tue, 19 Mar 2024 11:10:09 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240319055115.4063940-1-namhyung@kernel.org> <20240319055115.4063940-23-namhyung@kernel.org> In-Reply-To: From: Namhyung Kim Date: Tue, 19 Mar 2024 11:09:58 -0700 Message-ID: Subject: Re: [PATCH 22/23] perf annotate-data: Add a cache for global variable types To: Arnaldo Carvalho de Melo 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 19, 2024 at 11:07=E2=80=AFAM 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=E2=80=AFPM 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/annota= te-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_st= ate(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 *no= de) > > > +{ > > > + const u64 addr =3D (uintptr_t)_key; > > > + struct global_var_entry *gvar; > > > + > > > + gvar =3D rb_entry(node, struct global_var_entry, node); > > > + > > > + if (gvar->start <=3D 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 =3D rb_entry(node_a, struct global_var_entry, node); > > > + gvar_b =3D 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_inf= o *dloc, u64 addr) > > > +{ > > > + struct dso *dso =3D map__dso(dloc->ms->map); > > > + struct rb_node *node; > > > + > > > + node =3D 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 =3D rb_find(void *)(uintptr_tr)addr, ...); > > I can add that, to speed up the process, ok? That would be great! Thanks, Namhyung