Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1151971lqm; Thu, 2 May 2024 06:50:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVa1pRF2GCHi+zgH+HCOl9USUvbjRfVAEgWyOwNsyyJwG8rpuHB8lKdcvO/hJKKuxUJIW1sxwPoZPLMz2XKjdW1O0lnGCyUpaey44/FTQ== X-Google-Smtp-Source: AGHT+IFWBLKKAHxKc9knUJB3LZucB6YFwXviyx+f7Xa2VVtsmZNZa/2+76LBDP5KEpDaYretGUyw X-Received: by 2002:ac8:5fc6:0:b0:43a:d386:f8eb with SMTP id k6-20020ac85fc6000000b0043ad386f8ebmr5925951qta.22.1714657825523; Thu, 02 May 2024 06:50:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714657825; cv=pass; d=google.com; s=arc-20160816; b=KFPO95BvI2kKmHfyOELlt05QZvu4KyWWW/McR2Q2jCZG30OuMStEKKuIjDSckl6Ob6 FyNVHMRI12wNpMlC6keF8fFaFRBoD/xFmsBjncCTpFfBny9J2HDF6wWR0NlfqxzCQRVL AYd9Fw2bYhyAXyAo32fE1i3DDDpwYVMZZRiPEFyesGdjIChDMMXksDEaeWoKb2ZGiqJ7 3FFo6+AafMwB8fBVuO/cQtXTQkDNd6aev8VsZwWIQotwF8jrye/8kE86liJrnjp/WSTZ GrOJfOoRi5CuszlSZxXeQzOuBnAxmiASv3zLlqhtk6PFnepUzXgB9IaGHoYqZFUpI5YX V+oQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FsyS/jOBOSlxvoGTV1hLTpbGKfKJE9X3n7PAQZNlLug=; fh=49GrrO/H3LiGmymuFnNd59pBYHHWBS2xk/6Ejg0rn8E=; b=t2XALQQ1x/8BmTgdMj7CTP6CXj7DbILja6z9dXnF4LukWU3YzVvX/L2ZKUhJJWOk5r ZMisQ5tUwkQqGhXy5OC6pymUdfqlsHwniu9Qu2spuPPNIk4cCoGfZ/4bwWtEoKlQ/PKY 573MisjuMh/2kPpAmCcsSMBCEhOnjqan3FzKr5wLX7/ZlvsGzk9CsnDlK6/5M0Oqp+ma fnr0r5KEHdGRc8tii/1eKhayUsYpn0fj96ghPq/o+fsexjQFuK58F1RxtS64IwQxa5Po lEYIEwWE6sYYx1fs6ygGrd4aQ5Ve6tLUZYDq4kxfZkIPh/c759OeQ/sTjYh/t6PLoIgK 7/3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AcMM+n2H; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-166532-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166532-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 o4-20020a05622a008400b0043af7faad59si1011624qtw.159.2024.05.02.06.50.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 06:50:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166532-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AcMM+n2H; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-166532-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166532-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 429CC1C2144D for ; Thu, 2 May 2024 13:50:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 74A5313C67E; Thu, 2 May 2024 13:50:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AcMM+n2H" 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 9AEF1219F6; Thu, 2 May 2024 13:50:18 +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=1714657818; cv=none; b=DddzT/4aXbD9AGTCjFg0B3H3SypnHAZ6st13X8DSVSfHYsVx9J97rfo/lVztxq7fBDb63lD2nsi5NXbKFlSym32+KXi4OBn0RimoHvqbZ+HyOXju/QDwV+Ha5fai52Bkvy3beYoexSsNoB+aAkuVLPtSdmGENP8FIzC1Gv/Mpoc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714657818; c=relaxed/simple; bh=CnVtUj//jjfGpdXeVZA+hatKTZhYD0wcuPbPNXJPn/Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Yp+mqCn4WOXWKcgy9CH3eplBMYb0GK5Ha+x+dAKhQ4jH+AOyh7y6vTtzY6IpGBSLC0pme2wg2ylItl9PV8KCxQ8cMNyo2qZOP8ZSkDrB7edndCIBAxBl+HoMYWk7vbl4Uc3sVA8+w9eewp1fh71DyJXG8avJ/BLxzHJnt0XsH8A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AcMM+n2H; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 791EFC113CC; Thu, 2 May 2024 13:50:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714657818; bh=CnVtUj//jjfGpdXeVZA+hatKTZhYD0wcuPbPNXJPn/Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AcMM+n2HtzRjjLn1JuoPxqNa4/bX+u/BXmbrECRET3J81DWgR/+mJlBRZAx5lp1jJ ta32APyATg1FnCqBV+Cd8S8AoCKeN9EtaMiYVMsrKCkYV5kd0a42XYeDJCbkqGpG2v dU9nTBUN1vGlONpfIxVId3PH6g0HJbMkI8PS913/Ol2c0MywNtYTz8/RAyxN6w+ypQ i0KtGXhdJqxjx0FM3NGQf+oGrHYedqfZr0xxgeL5Cgxf3iiuXLTrGoDUElZNlGl6pB y7j4oF3mJfpAou0PPmpkwAuFnMWZ4mCGzSQ9G07XxdLZYFEvdae0bZQbObXU0GyrND CKvWYtmdLhHKQ== Date: Thu, 2 May 2024 10:50:13 -0300 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ian Rogers , Kan Liang , Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: Re: [PATCH 2/6] perf annotate-data: Collect global variables in advance Message-ID: References: <20240502060011.1838090-1-namhyung@kernel.org> <20240502060011.1838090-3-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=us-ascii Content-Disposition: inline In-Reply-To: <20240502060011.1838090-3-namhyung@kernel.org> On Wed, May 01, 2024 at 11:00:07PM -0700, Namhyung Kim wrote: > Currently it looks up global variables from the current CU using address > and name. But it sometimes fails to find a variable as the variable can > come from a different CU - but it's still strange it failed to find a > declaration for some reason. > > Anyway, it can collect all global variables from all CU once and then > lookup them later on. This slightly improves the success rate of my > test data set. It would be interesting you could provide examples from your test data set, i.e. after this patch these extra global variables were considered in the test results, with some tool output, etc. This would help intersested parties to reproduce your results, validate the end result, etc. - Arnaldo > Signed-off-by: Namhyung Kim > --- > tools/perf/util/annotate-data.c | 57 +++++++++++++++++++++++++++++++-- > 1 file changed, 55 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-data.c > index 12d5faff3b7a..4dd0911904f2 100644 > --- a/tools/perf/util/annotate-data.c > +++ b/tools/perf/util/annotate-data.c > @@ -28,6 +28,8 @@ > /* register number of the stack pointer */ > #define X86_REG_SP 7 > > +static void delete_var_types(struct die_var_type *var_types); > + > enum type_state_kind { > TSR_KIND_INVALID = 0, > TSR_KIND_TYPE, > @@ -557,8 +559,8 @@ static bool global_var__add(struct data_loc_info *dloc, u64 addr, > if (gvar == NULL) > return false; > > - gvar->name = strdup(name); > - if (gvar->name == NULL) { > + gvar->name = name ? strdup(name) : NULL; > + if (name && gvar->name == NULL) { > free(gvar); > return false; > } > @@ -612,6 +614,53 @@ static bool get_global_var_info(struct data_loc_info *dloc, u64 addr, > return true; > } > > +static void global_var__collect(struct data_loc_info *dloc) > +{ > + Dwarf *dwarf = dloc->di->dbg; > + Dwarf_Off off, next_off; > + Dwarf_Die cu_die, type_die; > + size_t header_size; > + > + /* Iterate all CU and collect global variables that have no location in a register. */ > + off = 0; > + while (dwarf_nextcu(dwarf, off, &next_off, &header_size, > + NULL, NULL, NULL) == 0) { > + struct die_var_type *var_types = NULL; > + struct die_var_type *pos; > + > + if (dwarf_offdie(dwarf, off + header_size, &cu_die) == NULL) { > + off = next_off; > + continue; > + } > + > + die_collect_global_vars(&cu_die, &var_types); > + > + for (pos = var_types; pos; pos = pos->next) { > + const char *var_name = NULL; > + int var_offset = 0; > + > + if (pos->reg != -1) > + continue; > + > + if (!dwarf_offdie(dwarf, pos->die_off, &type_die)) > + continue; > + > + if (!get_global_var_info(dloc, pos->addr, &var_name, > + &var_offset)) > + continue; > + > + if (var_offset != 0) > + continue; > + > + global_var__add(dloc, pos->addr, var_name, &type_die); > + } > + > + delete_var_types(var_types); > + > + off = next_off; > + } > +} > + > static bool get_global_var_type(Dwarf_Die *cu_die, struct data_loc_info *dloc, > u64 ip, u64 var_addr, int *var_offset, > Dwarf_Die *type_die) > @@ -620,8 +669,12 @@ static bool get_global_var_type(Dwarf_Die *cu_die, struct data_loc_info *dloc, > int offset; > const char *var_name = NULL; > struct global_var_entry *gvar; > + struct dso *dso = map__dso(dloc->ms->map); > Dwarf_Die var_die; > > + if (RB_EMPTY_ROOT(&dso->global_vars)) > + global_var__collect(dloc); > + > gvar = global_var__find(dloc, var_addr); > if (gvar) { > if (!dwarf_offdie(dloc->di->dbg, gvar->die_offset, type_die)) > -- > 2.45.0.rc1.225.g2a3ae87e7f-goog