From nobody Sun Apr 5 16:47:17 2026 Received: from mail-yx1-f53.google.com (mail-yx1-f53.google.com [74.125.224.53]) (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 222E63D7D6E for ; Mon, 9 Mar 2026 17:55:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773078960; cv=none; b=M2FR0dtA7BRXzRI4p60Vsen4nEflUpo7dpWGbvC8/73KqpkWCXklwxMWAD3salrhO0v3fANt9NnIf3BZ+NR85fykT9th4coMeCjOc/QEQEuGW5G29PII6b3r2GfD7RSmaqpb5ZCs+MtcEzks49/y5VppY2NEn8+SpTI+yq0jzFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773078960; c=relaxed/simple; bh=I0bHNrXIoabZx/3kXJ4rgQ5TfmaboCIWyV/MOFLzpcg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oQfozVdyB+K2WdVJOXITmOyuPlVjxn0anqFL89NDFe6CDG2PJKncw2nafcO+dYybNtOpFtlpTN/C8Ngj+TNw+7RrthN3dbE8Oo+tuJG4eOK28YwMAe86wEfQXYBE5oDcIwWz7DU4o7LPVY9ee8ZQ2pI/EDl4+9z43a5/D4Vef/M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ncsu.edu; spf=pass smtp.mailfrom=ncsu.edu; dkim=pass (2048-bit key) header.d=ncsu.edu header.i=@ncsu.edu header.b=fjF4P9fu; arc=none smtp.client-ip=74.125.224.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ncsu.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ncsu.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ncsu.edu header.i=@ncsu.edu header.b="fjF4P9fu" Received: by mail-yx1-f53.google.com with SMTP id 956f58d0204a3-64d5a7926cfso118980d50.2 for ; Mon, 09 Mar 2026 10:55:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1773078955; x=1773683755; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=id5lmV/YuEYOAzPj/+aTg1r+vark3Tzx2cS0LXicP3k=; b=fjF4P9fuA4286PTqBOLFzkGzZQKkFCyI15OhuFixBBCsW31YlyqVDZzZBwfHPpdvE9 46UIn20O+z0fJX889yX7+zHIq8c2FU+0TCyyoEfWkunaqzsXar6yy+EFQRcAY1NzAFSS nL7q0ht9vJPCLv0SXS35eBuKVrw9+x4kcbfLhVFvy43PjAZY9paEkDwH5hHsnPAEPAzZ 1BY+ura8szZtlQvT20oWcGokENrhSyjM8ye1z42WnmqlI6vdTsZOmP1d51QaAVswnK4I CwinkirmK4aAyCA9Z4NQWTLkIv3hERO0Ydz2bbpoTtDDzzGtqC1h2y0K1JNvZ+skywAa 0eTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773078955; x=1773683755; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=id5lmV/YuEYOAzPj/+aTg1r+vark3Tzx2cS0LXicP3k=; b=XaOlHu7sul7FOhwW71lUKt+AqF1SIkJ7UI/SrDHlTCCCrP+2ElcplKVOGfljE8mk6j qEFLbJ9V/JCaK9PBVCY8LvJeDp1dRvvXojx/P1/b3a4c2sN3Bn5CbOPiJ7AqjzJ9zzfb 2V7QgvLyL1gjW+XcFNqh4O7aus4nr7rx91ZuTtsbAksLJ/fXaSm+etVVEtUOcufiHFDm NTW8hBCYwjvGfuDR1B2k/RuHhV9Ea90N58p2+OISs1btCKhAraJWeAem9JW4U98MqhSU ODcdS/7fzSJ5V/VrJG/wyNbgwe9SCc5UL/L1JOlonEzNjY9/AU3GWJdnDLIVve67Qj6I SaGA== X-Forwarded-Encrypted: i=1; AJvYcCVBNeG/uQE+XJGCLBv69dCCdWnWZDPxkZbqobI5AX4sGxAJmgv0RoiBa4S/t33MFFpTGaWWmMtgMbOLKeQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9wOn5+Hk2DVs7PAX+10QZOsEPW/NZtR8crFndnAtf9kgew3vV /Vve/vGwxIzfFmGTDQIxp1I/xQNEhdH321rvLWvHZSAMftGcfSih1gdNKofVGuwqkw== X-Gm-Gg: ATEYQzyV4YhMsjP4MS9EH39qCdA12fCFvy68nOpQIRxmyirGBO0/7MPjvflbs64CvXF KDrzPNAxf0zkkgKXwZglLdO0s1ZYHtyrNYxmAm+GlXEUURHXBs4ORz45zx4pIJMZPBkR2SgVSO4 rpvWoJLWF3Xq2zdPJYAGxQEd6gbsLvJCM3gFxoTTbl8chqglFFXIISeqRmRwUhcX2BaQyiYpPgG djiMMEznW4ITHZXY/8j1VPculuwuYvITOv0LVaubn0OZSw5TTwP3j0N0NLeW5XtV8+LhIRX23ML VQuNLndTAJoe2X4wZNnnYlpYpcrko1adm+VkPobM61lSqg+K7gJrN0Z4OmfWdHs6uDXP7dd/epK 1wKeVXWKk2WySf8SWaCpqAOmz2qSCQadr5spi8G1ORs0lRzbN9GIAqd68KxZBOaxzQZvMsfx5ox +2+3WwJ1tDL76KDlqGIsPAfutjNlbXWkU+9cif1ORmDaVIQklTOH7wo3vW X-Received: by 2002:a05:690e:1a8d:b0:649:e4eb:cc6e with SMTP id 956f58d0204a3-64d14141211mr8245960d50.34.1773078954804; Mon, 09 Mar 2026 10:55:54 -0700 (PDT) Received: from um773-cachyos.sd.ncsu.edu ([152.7.255.206]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64d176e70e7sm4992535d50.20.2026.03.09.10.55.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 10:55:54 -0700 (PDT) From: Zecheng Li To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim Cc: Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Zecheng Li , xliuprof@google.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Zecheng Li Subject: [PATCH v2 03/11] perf dwarf-aux: Skip check_variable for variable lookup Date: Mon, 9 Mar 2026 13:55:16 -0400 Message-ID: <20260309175546.916039-4-zli94@ncsu.edu> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260309175546.916039-1-zli94@ncsu.edu> References: <20260309175546.916039-1-zli94@ncsu.edu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Zecheng Li Both die_find_variable_by_reg and die_find_variable_by_addr call match_var_offset which already performs sufficient checking and type matching. The additional check_variable call is redundant, and its need_pointer logic is only a heuristic. Since DWARF encodes accurate type information, which match_var_offset verifies, skipping check_variable improves both coverage and accuracy. Return the matched type from die_find_variable_by_reg and die_find_variable_by_addr via the existing `type` field in find_var_data, removing the need for check_variable in find_data_type_die. Signed-off-by: Zecheng Li Signed-off-by: Zecheng Li --- tools/perf/util/annotate-data.c | 42 ++++++++++++++------------------- tools/perf/util/dwarf-aux.c | 13 ++++++---- tools/perf/util/dwarf-aux.h | 5 ++-- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index cda020ea18d5..23a09bf58f86 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -814,9 +814,8 @@ bool get_global_var_type(Dwarf_Die *cu_die, struct data= _loc_info *dloc, } =20 /* Try to get the variable by address first */ - if (die_find_variable_by_addr(cu_die, var_addr, &var_die, &offset) && - check_variable(dloc, &var_die, type_die, DWARF_REG_PC, offset, - /*is_fbreg=3D*/false) =3D=3D PERF_TMR_OK) { + if (die_find_variable_by_addr(cu_die, var_addr, &var_die, type_die, + &offset)) { var_name =3D dwarf_diename(&var_die); *var_offset =3D offset; goto ok; @@ -1606,12 +1605,13 @@ static int find_data_type_die(struct data_loc_info = *dloc, Dwarf_Die *type_die) =20 if (reg =3D=3D DWARF_REG_PC) { if (!die_find_variable_by_addr(&scopes[i], dloc->var_addr, - &var_die, &type_offset)) + &var_die, &mem_die, + &type_offset)) continue; } else { /* Look up variables/parameters in this scope */ if (!die_find_variable_by_reg(&scopes[i], pc, reg, - &type_offset, is_fbreg, &var_die)) + &mem_die, &type_offset, is_fbreg, &var_die)) continue; } =20 @@ -1619,26 +1619,20 @@ static int find_data_type_die(struct data_loc_info = *dloc, Dwarf_Die *type_die) dwarf_diename(&var_die), (long)dwarf_dieoffset(&var_die), i+1, nr_scopes, (long)dwarf_dieoffset(&scopes[i])); =20 - /* Found a variable, see if it's correct */ - result =3D check_variable(dloc, &var_die, &mem_die, reg, type_offset, is= _fbreg); - if (result =3D=3D PERF_TMR_OK) { - if (reg =3D=3D DWARF_REG_PC) { - pr_debug_dtp("addr=3D%#"PRIx64" type_offset=3D%#x\n", - dloc->var_addr, type_offset); - } else if (reg =3D=3D DWARF_REG_FB || is_fbreg) { - pr_debug_dtp("stack_offset=3D%#x type_offset=3D%#x\n", - fb_offset, type_offset); - } else { - pr_debug_dtp("type_offset=3D%#x\n", type_offset); - } - - if (!found || is_better_type(type_die, &mem_die)) { - *type_die =3D mem_die; - dloc->type_offset =3D type_offset; - found =3D true; - } + if (reg =3D=3D DWARF_REG_PC) { + pr_debug_dtp("addr=3D%#"PRIx64" type_offset=3D%#x\n", + dloc->var_addr, type_offset); + } else if (reg =3D=3D DWARF_REG_FB || is_fbreg) { + pr_debug_dtp("stack_offset=3D%#x type_offset=3D%#x\n", + fb_offset, type_offset); } else { - pr_debug_dtp("failed: %s\n", match_result_str(result)); + pr_debug_dtp("type_offset=3D%#x\n", type_offset); + } + + if (!found || is_better_type(type_die, &mem_die)) { + *type_die =3D mem_die; + dloc->type_offset =3D type_offset; + found =3D true; } =20 pr_debug_location(&var_die, pc, reg); diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index 3b0fc9038f19..1484aa756826 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -1560,7 +1560,7 @@ static int __die_find_var_reg_cb(Dwarf_Die *die_mem, = void *arg) * when the variable is in the stack. */ Dwarf_Die *die_find_variable_by_reg(Dwarf_Die *sc_die, Dwarf_Addr pc, int = reg, - int *poffset, bool is_fbreg, + Dwarf_Die *type_die, int *poffset, bool is_fbreg, Dwarf_Die *die_mem) { struct find_var_data data =3D { @@ -1572,8 +1572,10 @@ Dwarf_Die *die_find_variable_by_reg(Dwarf_Die *sc_di= e, Dwarf_Addr pc, int reg, Dwarf_Die *result; =20 result =3D die_find_child(sc_die, __die_find_var_reg_cb, &data, die_mem); - if (result) + if (result) { *poffset =3D data.offset; + *type_die =3D data.type; + } return result; } =20 @@ -1617,7 +1619,8 @@ static int __die_find_var_addr_cb(Dwarf_Die *die_mem,= void *arg) * This is usually for global variables. */ Dwarf_Die *die_find_variable_by_addr(Dwarf_Die *sc_die, Dwarf_Addr addr, - Dwarf_Die *die_mem, int *offset) + Dwarf_Die *die_mem, Dwarf_Die *type_die, + int *offset) { struct find_var_data data =3D { .addr =3D addr, @@ -1625,8 +1628,10 @@ Dwarf_Die *die_find_variable_by_addr(Dwarf_Die *sc_d= ie, Dwarf_Addr addr, Dwarf_Die *result; =20 result =3D die_find_child(sc_die, __die_find_var_addr_cb, &data, die_mem); - if (result) + if (result) { *offset =3D data.offset; + *type_die =3D data.type; + } return result; } =20 diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h index 99d2735122d5..939a59c91796 100644 --- a/tools/perf/util/dwarf-aux.h +++ b/tools/perf/util/dwarf-aux.h @@ -165,12 +165,13 @@ int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *v= r_die, struct strbuf *buf); =20 /* Find a variable saved in the 'reg' at given address */ Dwarf_Die *die_find_variable_by_reg(Dwarf_Die *sc_die, Dwarf_Addr pc, int = reg, - int *poffset, bool is_fbreg, + Dwarf_Die *type_die, int *poffset, bool is_fbreg, Dwarf_Die *die_mem); =20 /* Find a (global) variable located in the 'addr' */ Dwarf_Die *die_find_variable_by_addr(Dwarf_Die *sc_die, Dwarf_Addr addr, - Dwarf_Die *die_mem, int *offset); + Dwarf_Die *die_mem, Dwarf_Die *type_die, + int *offset); =20 /* Save all variables and parameters in this scope */ void die_collect_vars(Dwarf_Die *sc_die, struct die_var_type **var_types); --=20 2.53.0