From nobody Fri Dec 19 16:13:32 2025 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 C55C114601F; Fri, 16 Aug 2024 23:58:41 +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=1723852721; cv=none; b=jlV9EaQA5jv94piXJKKJOC1CXXXfV/EUhLz6lYFx0BkA7fLRk6LUKQ6fjR9gTM/2jAj5mqdwW3tWLlck/jLxagwoP6OWbj+Gix0Ecaf8VCmHT9qFo8tgyIbiGTpxDGB+Ec3sWndkb19gQroaGGiJCqmLXJ/+Q9Y8+anVtMzwgms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723852721; c=relaxed/simple; bh=gQYWHT2iv2QpIDygwPCmKISsf64+h3O6hd8st6xxcVM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k3uAi3SXF4lr4aCLFHI89nhyrb9Pb2joSJH2AklZAVouxO11Zg1ySDDgj0gPyOWfFGd8acBAK+1e5FUWb4sNBI9HocUlZPchCNzuHDEygMJK70S8XBXa/fmuN1km62LmvIBiroAaDg4ztvbhA810OWIKrMpw2LnI+mF+7tR9bls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MrQYfm9j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MrQYfm9j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38F4DC4AF11; Fri, 16 Aug 2024 23:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723852721; bh=gQYWHT2iv2QpIDygwPCmKISsf64+h3O6hd8st6xxcVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MrQYfm9je7f0Oh93OaldgbUYVTPIHlSikymL6sgRYOSgd3kEzERBpNgXl2/R90Cog N+pdOWwB0fwF5ysZPbAQcmbeLBKyAcEJkfuUVp9jQTVvfePeJw4UThb57vCtNMB94w 1PCTK0i+sBgiNwIY9gAaRUwtfWwU3lGrKmSqOWcOSBc+MXu98ZCHcTkPOicFw409sO ccG0ahfWWLkOUjy0ijcO4nvY/8x19zYy2HcQ3CBHalfldpIYF9Mb8wYVE66eFabrap AIOfSknIKkR7M8Wxswt3MXv8BLnknT0dcSHEIRxOp8aVwH3vZhQkw/Y1g+RSTk2y1o MIkepsynR/jRg== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev , Masami Hiramatsu Subject: [PATCH 1/9] perf dwarf-aux: Check allowed location expressions when collecting variables Date: Fri, 16 Aug 2024 16:58:31 -0700 Message-ID: <20240816235840.2754937-2-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240816235840.2754937-1-namhyung@kernel.org> References: <20240816235840.2754937-1-namhyung@kernel.org> 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" It missed to call check_allowed_ops() in __die_collect_vars_cb() so it can take variables with complex location expression incorrectly. For example, I found some variable has this expression. 015d8df8 ffffffff81aacfb3 (base address) 015d8e01 v000000000000004 v000000000000000 views at 015d8df2 for: ffffffff81aacfb3 ffffffff81aacfd2 (DW_OP_fbreg: -176; DW_OP_de= ref; DW_OP_plus_uconst: 332; DW_OP_deref_size: 4; DW_OP_lit1; DW_OP_shra; DW_OP_const1u: 64; DW_OP_minus; DW_OP_stack_value) 015d8e14 v000000000000000 v000000000000000 views at 015d8df4 for: ffffffff81aacfd2 ffffffff81aacfd7 (DW_OP_reg3 (rbx)) 015d8e19 v000000000000000 v000000000000000 views at 015d8df6 for: ffffffff81aacfd7 ffffffff81aad020 (DW_OP_fbreg: -176; DW_OP_de= ref; DW_OP_plus_uconst: 332; DW_OP_deref_size: 4; DW_OP_lit1; DW_OP_shra; DW_OP_const1u: 64; DW_OP_minus; DW_OP_stack_value) 015d8e2c It looks like '((int *)(-176(%rbp) + 332) >> 1) - 64' but the current code thought it's just -176(%rbp) and processed the variable incorrectly. It should reject such a complex expression if check_allowed_ops() doesn't like it. :) Fixes: 932dcc2c39ae ("perf dwarf-aux: Add die_collect_vars()") Cc: Masami Hiramatsu Signed-off-by: Namhyung Kim Acked-by: Masami Hiramatsu (Google) --- tools/perf/util/dwarf-aux.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index 5e080d7e22c2..beb632153a74 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -1598,6 +1598,9 @@ static int __die_collect_vars_cb(Dwarf_Die *die_mem, = void *arg) if (dwarf_getlocations(&attr, 0, &base, &start, &end, &ops, &nops) <=3D 0) return DIE_FIND_CB_SIBLING; =20 + if (!check_allowed_ops(ops, nops)) + return DIE_FIND_CB_SIBLING; + if (die_get_real_type(die_mem, &type_die) =3D=3D NULL) return DIE_FIND_CB_SIBLING; =20 --=20 2.46.0.184.g6999bdac58-goog From nobody Fri Dec 19 16:13:32 2025 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 B59AE1487CE; Fri, 16 Aug 2024 23:58:42 +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=1723852722; cv=none; b=KYgJEB5fF4O7/KHgcGfC9vL0VWq1V+H5omW7ny62VaNnnkQPo72S9VHb8mJCjv4QVMqLPZr5+EUS7KgP0RGGYd/HxiM9Njal/OVIgOkVtP1x1MGJPKvEJtksHUS+ERYOcEgejDK07pfa7jf4qbtH7YEuR1bqtzTHTgRGY7n1NKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723852722; c=relaxed/simple; bh=QEdfiXXWPPSs97vHd/yHxLt8ReSrwGvcutiOuI4ry94=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b8SstIff4fPDznh0IRW5qS+MkZMXk9Z2g3Y48goFh+GIpYd57yJpjeTkNNUSO6TRnk9fILgU/RieTAl+6kclyHlX6Yp0mBNrxn2lzClyo6EtCuyoyAIfN5boJ0br1H4OPiaO3cE+1+6X4UCRUPMK4eJ2Ty466tanPdxGudvjm5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lMJ81mBs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lMJ81mBs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFFB7C4AF14; Fri, 16 Aug 2024 23:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723852722; bh=QEdfiXXWPPSs97vHd/yHxLt8ReSrwGvcutiOuI4ry94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lMJ81mBsCea5ljP3X7QVdDsUu3E13MWxTi7dwSBPMvUgG+sIz0+6eRqT/c43SpLum J7wEMGYQG7hulACcREytWwPauVWMiDqn86uD1Tux97OEdM0cgXhkSO/2mPDfrO21mE LPLbFyzTxIBqB2PrC7t/hPBBdMZ668sNb412IwsKq5iWzLVYvzCyqcMgwQoi1FupY4 820+GHhhwolZsP7zeoF6cKz7hCheLhx79fpwq5zP7XUogIo9pH/OWHb0IC2XXvQIeF D4Aynk4zO9bHw41l7cnJgVSwQ813RlW5CVYTbAZXnOYjN6FmH1vLVs/iz43d9cL/lL vy/TvBrIJOaLw== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev , Masami Hiramatsu Subject: [PATCH 2/9] perf annotate-data: Fix off-by-one in location range check Date: Fri, 16 Aug 2024 16:58:32 -0700 Message-ID: <20240816235840.2754937-3-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240816235840.2754937-1-namhyung@kernel.org> References: <20240816235840.2754937-1-namhyung@kernel.org> 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" The location list will have entries with half-open addressing like [start, end) which means it doesn't include the end address. So it should skip entries at the end address and match to the next entry. An example location list looks like this: 00237876 ffffffff8110d32b (base address) 0023787f v000000000000000 v000000000000002 views at 00237868 for: ffffffff8110d32b ffffffff8110d4eb (DW_OP_reg3 (rbx)) <<<--= - 1 00237885 v000000000000002 v000000000000000 views at 0023786a for: ffffffff8110d4eb ffffffff8110d50b (DW_OP_reg14 (r14)) <<<--= - 2 0023788c v000000000000000 v000000000000001 views at 0023786c for: ffffffff8110d50b ffffffff8110d7c4 (DW_OP_reg3 (rbx)) 00237893 v000000000000000 v000000000000000 views at 0023786e for: ffffffff8110d806 ffffffff8110d854 (DW_OP_reg3 (rbx)) 0023789a v000000000000000 v000000000000000 views at 00237870 for: ffffffff8110d876 ffffffff8110d88e (DW_OP_reg3 (rbx)) The first entry at 0023787f has [8110d32b, 8110d4eb) (omitting the ffffffff at the beginning), and the second one has [8110d4eb, 8110d50b). Fixes: 2bc3cf575a16 ("perf annotate-data: Improve debug message with locati= on info") Cc: Masami Hiramatsu Signed-off-by: Namhyung Kim Reviewed-by: Masami Hiramatsu (Google) --- tools/perf/util/annotate-data.c | 2 +- tools/perf/util/dwarf-aux.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index ff85d190e3ac..fd8d3cdead5a 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -95,7 +95,7 @@ static void pr_debug_location(Dwarf_Die *die, u64 pc, int= reg) return; =20 while ((off =3D dwarf_getlocations(&attr, off, &base, &start, &end, &ops,= &nops)) > 0) { - if (reg !=3D DWARF_REG_PC && end < pc) + if (reg !=3D DWARF_REG_PC && end <=3D pc) continue; if (reg !=3D DWARF_REG_PC && start > pc) break; diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index beb632153a74..0151a8d14350 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -1444,7 +1444,7 @@ static int __die_find_var_reg_cb(Dwarf_Die *die_mem, = void *arg) =20 while ((off =3D dwarf_getlocations(&attr, off, &base, &start, &end, &ops,= &nops)) > 0) { /* Assuming the location list is sorted by address */ - if (end < data->pc) + if (end <=3D data->pc) continue; if (start > data->pc) break; --=20 2.46.0.184.g6999bdac58-goog From nobody Fri Dec 19 16:13:32 2025 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 3AC5B1494DB; Fri, 16 Aug 2024 23:58:42 +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=1723852723; cv=none; b=sPMWmNEIjFO4L1okReYVCeJmV3+Wx2aAzgepP2OeE3dc9OZPviZxkjN3RGJxeCHt5FBzu72wPD7elj0qhIgUItS5nWkgQHp4VWDt0drwuW9yLkmZikpZGqHlkpvDl0C0SwM3WZY/2X5Zt9Nleutmgk6tf1Lo7Axp2EhSQi48thg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723852723; c=relaxed/simple; bh=qAsQm8iWb0RyWNE4stpu0Prg2j6/cF+goHITQqqkfYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ivV3VML4xTZruoPgmQUbdQS23nM1ojMXWiT5ZciwPVaHPLY3zyIczDt3vZxnUYaBOziNjdvjeujZ3KD+UcZIurExUoY7sH2GJhCc/EK1SVxini8Ic8EaaFAm+wxb1Q6AkqjGKdX2nIknImRXv72j2scmpfCOZsjSUiuVb34lMLI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qQ06jIOc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qQ06jIOc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 547FFC4AF18; Fri, 16 Aug 2024 23:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723852722; bh=qAsQm8iWb0RyWNE4stpu0Prg2j6/cF+goHITQqqkfYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qQ06jIOciObesF+CbY3aQz2LHNzdHKcV9VLWMw2L8Hyp/5RTnctV1QDn7I4QOS8Re pq9eRBe5D6oN/TnlRdgze5Akgw63l4OKR+FVSEFVBs1amCszeYK4KAsmwyqudOodgn zFCR6R7sfUokVI7P5eb93V4lD4RTPSZ4kZ5uDc8wRvtAtCpvlmTbEJLjenx9L6IqrJ W5uvnP43nHk5a5FByxvAQyKnCPNwW4GQYrpCj5amWvw8abBHeCp05umTS0lrvKwmDF vdLBpp4qKiUV9Bldh1FwMaKHMTcx7BQWS1aq3Qo7Z63RJM6XUcDTJgfQJP63lh0B5Y TASIIL0C04SFQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 3/9] perf annotate-data: Add enum type_match_result Date: Fri, 16 Aug 2024 16:58:33 -0700 Message-ID: <20240816235840.2754937-4-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240816235840.2754937-1-namhyung@kernel.org> References: <20240816235840.2754937-1-namhyung@kernel.org> 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" And let check_variable() return the enum value so that callers can know what was the problem. This will be used by the later patch to update the statistics correctly and print the error message in a right place. Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 36 +++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index fd8d3cdead5a..8e3b422eca22 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -345,9 +345,20 @@ static bool find_cu_die(struct debuginfo *di, u64 pc, = Dwarf_Die *cu_die) return false; } =20 +enum type_match_result { + PERF_TMR_UNKNOWN =3D 0, + PERF_TMR_OK, + PERF_TMR_NO_TYPE, + PERF_TMR_NO_POINTER, + PERF_TMR_NO_SIZE, + PERF_TMR_BAD_OFFSET, +}; + /* The type info will be saved in @type_die */ -static int check_variable(struct data_loc_info *dloc, Dwarf_Die *var_die, - Dwarf_Die *type_die, int reg, int offset, bool is_fbreg) +static enum type_match_result check_variable(struct data_loc_info *dloc, + Dwarf_Die *var_die, + Dwarf_Die *type_die, int reg, + int offset, bool is_fbreg) { Dwarf_Word size; bool is_pointer =3D true; @@ -364,7 +375,7 @@ static int check_variable(struct data_loc_info *dloc, D= warf_Die *var_die, if (__die_get_real_type(var_die, type_die) =3D=3D NULL) { pr_debug_dtp("variable has no type\n"); ann_data_stat.no_typeinfo++; - return -1; + return PERF_TMR_NO_TYPE; } =20 /* @@ -378,7 +389,7 @@ static int check_variable(struct data_loc_info *dloc, D= warf_Die *var_die, __die_get_real_type(type_die, type_die) =3D=3D NULL) { pr_debug_dtp("no pointer or no type\n"); ann_data_stat.no_typeinfo++; - return -1; + return PERF_TMR_NO_POINTER; } } =20 @@ -391,7 +402,7 @@ static int check_variable(struct data_loc_info *dloc, D= warf_Die *var_die, if (dwarf_aggregate_size(&sized_type, &size) < 0) { pr_debug_dtp("type size is unknown\n"); ann_data_stat.invalid_size++; - return -1; + return PERF_TMR_NO_SIZE; } =20 /* Minimal sanity check */ @@ -399,10 +410,10 @@ static int check_variable(struct data_loc_info *dloc,= Dwarf_Die *var_die, pr_debug_dtp("offset: %d is bigger than size: %"PRIu64"\n", offset, size); ann_data_stat.bad_offset++; - return -1; + return PERF_TMR_BAD_OFFSET; } =20 - return 0; + return PERF_TMR_OK; } =20 struct type_state_stack *find_stack_state(struct type_state *state, @@ -652,7 +663,7 @@ bool get_global_var_type(Dwarf_Die *cu_die, struct data= _loc_info *dloc, /* 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 0) { + /*is_fbreg=3D*/false) =3D=3D PERF_TMR_OK) { var_name =3D dwarf_diename(&var_die); *var_offset =3D offset; goto ok; @@ -666,7 +677,7 @@ bool get_global_var_type(Dwarf_Die *cu_die, struct data= _loc_info *dloc, /* Try to get the name of global variable */ if (die_find_variable_at(cu_die, var_name, pc, &var_die) && check_variable(dloc, &var_die, type_die, DWARF_REG_PC, *var_offset, - /*is_fbreg=3D*/false) =3D=3D 0) + /*is_fbreg=3D*/false) =3D=3D PERF_TMR_OK) goto ok; =20 return false; @@ -1205,6 +1216,7 @@ static int find_data_type_die(struct data_loc_info *d= loc, Dwarf_Die *type_die) bool is_fbreg =3D false; u64 pc; char buf[64]; + enum type_match_result result; =20 if (dloc->op->multi_regs) snprintf(buf, sizeof(buf), "reg%d, reg%d", dloc->op->reg1, dloc->op->reg= 2); @@ -1299,8 +1311,8 @@ static int find_data_type_die(struct data_loc_info *d= loc, Dwarf_Die *type_die) } =20 /* Found a variable, see if it's correct */ - ret =3D check_variable(dloc, &var_die, type_die, reg, offset, is_fbreg); - if (ret =3D=3D 0) { + result =3D check_variable(dloc, &var_die, type_die, reg, offset, is_fbre= g); + if (result =3D=3D PERF_TMR_OK) { pr_debug_dtp("found \"%s\" in scope=3D%d/%d (die: %#lx) ", dwarf_diename(&var_die), i+1, nr_scopes, (long)dwarf_dieoffset(&scopes[i])); @@ -1315,12 +1327,14 @@ static int find_data_type_die(struct data_loc_info = *dloc, Dwarf_Die *type_die) } pr_debug_location(&var_die, pc, reg); pr_debug_type_name(type_die, TSR_KIND_TYPE); + ret =3D 0; } else { pr_debug_dtp("check variable \"%s\" failed (die: %#lx)\n", dwarf_diename(&var_die), (long)dwarf_dieoffset(&var_die)); pr_debug_location(&var_die, pc, reg); pr_debug_type_name(type_die, TSR_KIND_TYPE); + ret =3D -1; } dloc->type_offset =3D offset; goto out; --=20 2.46.0.184.g6999bdac58-goog From nobody Fri Dec 19 16:13:32 2025 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 AFDB014A62A; Fri, 16 Aug 2024 23:58:43 +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=1723852723; cv=none; b=QTGALBPS0tIL6FhlykyVUy8mskxJXJ/x8AlJnMZKXrRy06Vj5GAEF33lnjGVytMCtSYi9DYvJRyUz37jqLoqw5xkhmi/PB3KFyAgV3oTCix86q9dRqNHvsksw/M3XPI3AIq6O3KbW+rds8ErZBZt/ANpuZwMQ4FCYLCH65t5UTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723852723; c=relaxed/simple; bh=C9lHbeYRNAwoTKyMISt6eqSmOtp2+n5T/vIDIWLfjew=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oWjhhXp9rabnoMSIKc6aPISxy8hcjHWsDB85scg3KexBZkdAerkbtU38V8Xs/goAyCn+15gz+HiFhzbX7Fyba5e63INL24fp8/zbb7Ayg4o+aWHpIR+IAwJcJHEs8HUyIpufMPQJdLN0gyo/sYKFYsDdktmxj2V3r2S35EytspE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GA/TUmTW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GA/TUmTW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6A6EC32782; Fri, 16 Aug 2024 23:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723852723; bh=C9lHbeYRNAwoTKyMISt6eqSmOtp2+n5T/vIDIWLfjew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GA/TUmTW7lQ0V9jN5MjwXgBRSLRSOp+4i//wtjAY1V4X3yGflHR9YSCQJEgBpaSUN bfbckY4KBU07sZiXF0nC+nUuiYeA9yMjYP7A5iM3ueCA12MTVl3qc5YbSzz9RbcxY8 DaETmjTjozRDFsHmc+w6GA6oxZL4Y0VH6dmv1rKuJT6DPdmPLCs+eENTTgruOBAakm Ny0eScDKgJJJjPMKuFxIW/X20EuXXvCxuyxeNNZOx0VzlLoimqVXBxWomi0sARn/tC lm9zHjx76AqMWvmM82UCP8p9+hrYVyMatsA/WJv2jNcmVyAnxvSjF38heW84C4Kaan lmUWH8b+oCfAQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 4/9] perf annotate-data: Add variable_state_str() Date: Fri, 16 Aug 2024 16:58:34 -0700 Message-ID: <20240816235840.2754937-5-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240816235840.2754937-1-namhyung@kernel.org> References: <20240816235840.2754937-1-namhyung@kernel.org> 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" So that it can show a proper debug message in the right place. The check_variable() is used in other places which don't want to print the message. $ perf --debug type-profile annotate --data-type Before: ----------------------------------------------------------- find data type for 0x140(reg14) at update_blocked_averages+0x2db CU for kernel/sched/fair.c (die:0x12dd892) frame base: cfa=3D1 fbreg=3D7 no pointer or no type <<<--- remo= ved check variable "__mptr" failed (die: 0x13022f1) variable location: base=3Dreg14, offset=3D0x140 type=3D'void*' size=3D0x8 (die:0x12dd8f9) After: ----------------------------------------------------------- find data type for 0x140(reg14) at update_blocked_averages+0x2db CU for kernel/sched/fair.c (die:0x12dd892) frame base: cfa=3D1 fbreg=3D7 found "__mptr" (die: 0x13022f1) in scope=3D4/4 (die: 0x13022e8) failed: n= o/void pointer <<<--- here variable location: base=3Dreg14, offset=3D0x140 type=3D'void*' size=3D0x8 (die:0x12dd8f9) Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 41 +++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index 8e3b422eca22..332254da49be 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -354,6 +354,25 @@ enum type_match_result { PERF_TMR_BAD_OFFSET, }; =20 +static const char *match_result_str(enum type_match_result tmr) +{ + switch (tmr) { + case PERF_TMR_OK: + return "Good!"; + case PERF_TMR_NO_TYPE: + return "no type information"; + case PERF_TMR_NO_POINTER: + return "no/void pointer"; + case PERF_TMR_NO_SIZE: + return "type size is unknown"; + case PERF_TMR_BAD_OFFSET: + return "offset bigger than size"; + case PERF_TMR_UNKNOWN: + default: + return "invalid state"; + } +} + /* The type info will be saved in @type_die */ static enum type_match_result check_variable(struct data_loc_info *dloc, Dwarf_Die *var_die, @@ -373,7 +392,6 @@ static enum type_match_result check_variable(struct dat= a_loc_info *dloc, =20 /* Get the type of the variable */ if (__die_get_real_type(var_die, type_die) =3D=3D NULL) { - pr_debug_dtp("variable has no type\n"); ann_data_stat.no_typeinfo++; return PERF_TMR_NO_TYPE; } @@ -387,7 +405,6 @@ static enum type_match_result check_variable(struct dat= a_loc_info *dloc, if ((dwarf_tag(type_die) !=3D DW_TAG_pointer_type && dwarf_tag(type_die) !=3D DW_TAG_array_type) || __die_get_real_type(type_die, type_die) =3D=3D NULL) { - pr_debug_dtp("no pointer or no type\n"); ann_data_stat.no_typeinfo++; return PERF_TMR_NO_POINTER; } @@ -400,15 +417,12 @@ static enum type_match_result check_variable(struct d= ata_loc_info *dloc, =20 /* Get the size of the actual type */ if (dwarf_aggregate_size(&sized_type, &size) < 0) { - pr_debug_dtp("type size is unknown\n"); ann_data_stat.invalid_size++; return PERF_TMR_NO_SIZE; } =20 /* Minimal sanity check */ if ((unsigned)offset >=3D size) { - pr_debug_dtp("offset: %d is bigger than size: %"PRIu64"\n", - offset, size); ann_data_stat.bad_offset++; return PERF_TMR_BAD_OFFSET; } @@ -1310,12 +1324,13 @@ static int find_data_type_die(struct data_loc_info = *dloc, Dwarf_Die *type_die) continue; } =20 + pr_debug_dtp("found \"%s\" (die: %#lx) in scope=3D%d/%d (die: %#lx) ", + dwarf_diename(&var_die), (long)dwarf_dieoffset(&var_die), + i+1, nr_scopes, (long)dwarf_dieoffset(&scopes[i])); + /* Found a variable, see if it's correct */ result =3D check_variable(dloc, &var_die, type_die, reg, offset, is_fbre= g); if (result =3D=3D PERF_TMR_OK) { - pr_debug_dtp("found \"%s\" in scope=3D%d/%d (die: %#lx) ", - dwarf_diename(&var_die), i+1, nr_scopes, - (long)dwarf_dieoffset(&scopes[i])); if (reg =3D=3D DWARF_REG_PC) { pr_debug_dtp("addr=3D%#"PRIx64" type_offset=3D%#x\n", dloc->var_addr, offset); @@ -1325,17 +1340,13 @@ static int find_data_type_die(struct data_loc_info = *dloc, Dwarf_Die *type_die) } else { pr_debug_dtp("type_offset=3D%#x\n", offset); } - pr_debug_location(&var_die, pc, reg); - pr_debug_type_name(type_die, TSR_KIND_TYPE); ret =3D 0; } else { - pr_debug_dtp("check variable \"%s\" failed (die: %#lx)\n", - dwarf_diename(&var_die), - (long)dwarf_dieoffset(&var_die)); - pr_debug_location(&var_die, pc, reg); - pr_debug_type_name(type_die, TSR_KIND_TYPE); + pr_debug_dtp("failed: %s\n", match_result_str(result)); ret =3D -1; } + pr_debug_location(&var_die, pc, reg); + pr_debug_type_name(type_die, TSR_KIND_TYPE); dloc->type_offset =3D offset; goto out; } --=20 2.46.0.184.g6999bdac58-goog From nobody Fri Dec 19 16:13:32 2025 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 24AE814D2B8; Fri, 16 Aug 2024 23:58:43 +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=1723852724; cv=none; b=EyLp7JhrszwNAfz3/d+iEeA6zxCO4AeoyM+xr5pUayRG2HvNlUehgNA6cvoRwgDnAeFMBioX8iEhBdHszMONZ6dIcIpavcC2mJX2r5q7RNPN3mC+H3SET8u5NAQLjYnEebw6krhHydFYcLDnsyGRkjlnf4mkFHW0rqWZ5e4akD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723852724; c=relaxed/simple; bh=WFqLrUsJ90ZZBi2rRNTqQUEvO6udoH82ef5MZBqnMCA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wfol/UKVK/Fxod8v1qQGddbxCj5QTvS2RpREVQw+HTnM9/EUwOs5IWemLPAVSCDgO6vnNpzzQJBK2+YWp3+/n5QDT6p8CrSaFbEvVAX0IHJdoz0d9w3Cc4f9m9wZIdr9ibe5T3Pa0nlmPCAo0DKg2rZqG2hWHuoXSVtfY2jxAGs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o7g6GFtR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o7g6GFtR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 637E4C4AF09; Fri, 16 Aug 2024 23:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723852723; bh=WFqLrUsJ90ZZBi2rRNTqQUEvO6udoH82ef5MZBqnMCA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o7g6GFtRBCqdz+ABbzaiBg5N/cti+AgbeoTBvQ8SOWx2OQfdnh7LuDemyM4Y9IZ30 vWnjKCbAMfmLm7M8IkeBGFbtwls6DIxkewV1qlzjD6sV6Yfp8v9qf7zrezwLTJriTq 47+qUsvbB+wSRK+Tybd4LAEqnMiRWzqBMnVUjjiWBSTRsujGsLNzIys5KeeKImUWLX l1E481GWFOl+bNgy9GnV4UHlVnA2t8Zviqa+z+7pPQyT/wgiiT20XB4yaUiD0TgDLI OaXEn9BA+mSCL6qwznGuQCHkkb/AFJ57aAlwQBkG1dM5v9z7MsF4re/CmZQwtEO+Jy EnsSQdV/HAU7A== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 5/9] perf annotate-data: Change return type of find_data_type_block() Date: Fri, 16 Aug 2024 16:58:35 -0700 Message-ID: <20240816235840.2754937-6-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240816235840.2754937-1-namhyung@kernel.org> References: <20240816235840.2754937-1-namhyung@kernel.org> 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" So that it can return enum variable_match_type to be propagated to the find_data_type_die(). Also update the debug message to show the result of the check_matching_type(). chk [dd] reg0 offset=3D0 ok=3D1 kind=3D1 : Good! or chk [177] reg4 offset=3D0x138 ok=3D0 kind=3D0 cfa : no type information Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 117 ++++++++++++++++---------------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index 332254da49be..5548cd8e84ba 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -352,6 +352,7 @@ enum type_match_result { PERF_TMR_NO_POINTER, PERF_TMR_NO_SIZE, PERF_TMR_BAD_OFFSET, + PERF_TMR_BAIL_OUT, }; =20 static const char *match_result_str(enum type_match_result tmr) @@ -368,6 +369,7 @@ static const char *match_result_str(enum type_match_res= ult tmr) case PERF_TMR_BAD_OFFSET: return "offset bigger than size"; case PERF_TMR_UNKNOWN: + case PERF_TMR_BAIL_OUT: default: return "invalid state"; } @@ -868,19 +870,19 @@ static void setup_stack_canary(struct data_loc_info *= dloc) =20 /* * It's at the target address, check if it has a matching type. - * It returns 1 if found, 0 if not or -1 if not found but no need to - * repeat the search. The last case is for per-cpu variables which + * It returns PERF_TMR_BAIL_OUT when it looks up per-cpu variables which * are similar to global variables and no additional info is needed. */ -static int check_matching_type(struct type_state *state, - struct data_loc_info *dloc, - Dwarf_Die *cu_die, Dwarf_Die *type_die) +static enum type_match_result check_matching_type(struct type_state *state, + struct data_loc_info *dloc, + Dwarf_Die *cu_die, + Dwarf_Die *type_die) { Dwarf_Word size; u32 insn_offset =3D dloc->ip - dloc->ms->sym->start; int reg =3D dloc->op->reg1; =20 - pr_debug_dtp("chk [%x] reg%d offset=3D%#x ok=3D%d kind=3D%d", + pr_debug_dtp("chk [%x] reg%d offset=3D%#x ok=3D%d kind=3D%d ", insn_offset, reg, dloc->op->offset, state->regs[reg].ok, state->regs[reg].kind); =20 @@ -896,15 +898,12 @@ static int check_matching_type(struct type_state *sta= te, if (dloc->op->offset < 0 && reg !=3D state->stack_reg) goto check_kernel; =20 - pr_debug_dtp("\n"); - return -1; + return PERF_TMR_NO_POINTER; } =20 - pr_debug_dtp("\n"); - /* Remove the pointer and get the target type */ if (__die_get_real_type(&state->regs[reg].type, type_die) =3D=3D NULL) - return -1; + return PERF_TMR_NO_POINTER; =20 dloc->type_offset =3D dloc->op->offset; =20 @@ -916,33 +915,33 @@ static int check_matching_type(struct type_state *sta= te, /* Get the size of the actual type */ if (dwarf_aggregate_size(&sized_type, &size) < 0 || (unsigned)dloc->type_offset >=3D size) - return -1; + return PERF_TMR_BAD_OFFSET; =20 - return 1; + return PERF_TMR_OK; } =20 if (reg =3D=3D dloc->fbreg) { struct type_state_stack *stack; =20 - pr_debug_dtp(" fbreg\n"); + pr_debug_dtp("fbreg"); =20 stack =3D find_stack_state(state, dloc->type_offset); if (stack =3D=3D NULL) - return 0; + return PERF_TMR_NO_TYPE; =20 if (stack->kind =3D=3D TSR_KIND_CANARY) { setup_stack_canary(dloc); - return -1; + return PERF_TMR_BAIL_OUT; } =20 if (stack->kind !=3D TSR_KIND_TYPE) - return 0; + return PERF_TMR_NO_TYPE; =20 *type_die =3D stack->type; /* Update the type offset from the start of slot */ dloc->type_offset -=3D stack->offset; =20 - return 1; + return PERF_TMR_OK; } =20 if (dloc->fb_cfa) { @@ -950,38 +949,38 @@ static int check_matching_type(struct type_state *sta= te, u64 pc =3D map__rip_2objdump(dloc->ms->map, dloc->ip); int fbreg, fboff; =20 - pr_debug_dtp(" cfa\n"); + pr_debug_dtp("cfa"); =20 if (die_get_cfa(dloc->di->dbg, pc, &fbreg, &fboff) < 0) fbreg =3D -1; =20 if (reg !=3D fbreg) - return 0; + return PERF_TMR_NO_TYPE; =20 stack =3D find_stack_state(state, dloc->type_offset - fboff); if (stack =3D=3D NULL) - return 0; + return PERF_TMR_NO_TYPE; =20 if (stack->kind =3D=3D TSR_KIND_CANARY) { setup_stack_canary(dloc); - return -1; + return PERF_TMR_BAIL_OUT; } =20 if (stack->kind !=3D TSR_KIND_TYPE) - return 0; + return PERF_TMR_NO_TYPE; =20 *type_die =3D stack->type; /* Update the type offset from the start of slot */ dloc->type_offset -=3D fboff + stack->offset; =20 - return 1; + return PERF_TMR_OK; } =20 if (state->regs[reg].kind =3D=3D TSR_KIND_PERCPU_BASE) { u64 var_addr =3D dloc->op->offset; int var_offset; =20 - pr_debug_dtp(" percpu var\n"); + pr_debug_dtp("percpu var"); =20 if (dloc->op->multi_regs) { int reg2 =3D dloc->op->reg2; @@ -997,14 +996,14 @@ static int check_matching_type(struct type_state *sta= te, if (get_global_var_type(cu_die, dloc, dloc->ip, var_addr, &var_offset, type_die)) { dloc->type_offset =3D var_offset; - return 1; + return PERF_TMR_OK; } /* No need to retry per-cpu (global) variables */ - return -1; + return PERF_TMR_BAIL_OUT; } =20 if (state->regs[reg].ok && state->regs[reg].kind =3D=3D TSR_KIND_POINTER)= { - pr_debug_dtp(" percpu ptr\n"); + pr_debug_dtp("percpu ptr"); =20 /* * It's actaully pointer but the address was calculated using @@ -1017,13 +1016,13 @@ static int check_matching_type(struct type_state *s= tate, /* Get the size of the actual type */ if (dwarf_aggregate_size(type_die, &size) < 0 || (unsigned)dloc->type_offset >=3D size) - return -1; + return PERF_TMR_BAIL_OUT; =20 - return 1; + return PERF_TMR_OK; } =20 if (state->regs[reg].ok && state->regs[reg].kind =3D=3D TSR_KIND_CANARY) { - pr_debug_dtp(" stack canary\n"); + pr_debug_dtp("stack canary"); =20 /* * This is a saved value of the stack canary which will be handled @@ -1032,7 +1031,7 @@ static int check_matching_type(struct type_state *sta= te, */ setup_stack_canary(dloc); =20 - return -1; + return PERF_TMR_BAIL_OUT; } =20 check_kernel: @@ -1043,16 +1042,16 @@ static int check_matching_type(struct type_state *s= tate, /* Direct this-cpu access like "%gs:0x34740" */ if (dloc->op->segment =3D=3D INSN_SEG_X86_GS && dloc->op->imm && arch__is(dloc->arch, "x86")) { - pr_debug_dtp(" this-cpu var\n"); + pr_debug_dtp("this-cpu var"); =20 addr =3D dloc->op->offset; =20 if (get_global_var_type(cu_die, dloc, dloc->ip, addr, &offset, type_die)) { dloc->type_offset =3D offset; - return 1; + return PERF_TMR_OK; } - return -1; + return PERF_TMR_BAIL_OUT; } =20 /* Access to global variable like "-0x7dcf0500(,%rdx,8)" */ @@ -1061,31 +1060,30 @@ static int check_matching_type(struct type_state *s= tate, =20 if (get_global_var_type(cu_die, dloc, dloc->ip, addr, &offset, type_die)) { - pr_debug_dtp(" global var\n"); + pr_debug_dtp("global var"); =20 dloc->type_offset =3D offset; - return 1; + return PERF_TMR_OK; } - pr_debug_dtp(" negative offset\n"); - return -1; + return PERF_TMR_BAIL_OUT; } } =20 - pr_debug_dtp("\n"); - return 0; + return PERF_TMR_UNKNOWN; } =20 /* Iterate instructions in basic blocks and update type table */ -static int find_data_type_insn(struct data_loc_info *dloc, - struct list_head *basic_blocks, - struct die_var_type *var_types, - Dwarf_Die *cu_die, Dwarf_Die *type_die) +static enum type_match_result find_data_type_insn(struct data_loc_info *dl= oc, + struct list_head *basic_blocks, + struct die_var_type *var_types, + Dwarf_Die *cu_die, + Dwarf_Die *type_die) { struct type_state state; struct symbol *sym =3D dloc->ms->sym; struct annotation *notes =3D symbol__annotation(sym); struct annotated_basic_block *bb; - int ret =3D 0; + enum type_match_result ret =3D PERF_TMR_UNKNOWN; =20 init_type_state(&state, dloc->arch); =20 @@ -1111,6 +1109,7 @@ static int find_data_type_insn(struct data_loc_info *= dloc, if (this_ip =3D=3D dloc->ip) { ret =3D check_matching_type(&state, dloc, cu_die, type_die); + pr_debug_dtp(" : %s\n", match_result_str(ret)); goto out; } =20 @@ -1137,24 +1136,25 @@ static int arch_supports_insn_tracking(struct data_= loc_info *dloc) * Construct a list of basic blocks for each scope with variables and try = to find * the data type by updating a type state table through instructions. */ -static int find_data_type_block(struct data_loc_info *dloc, - Dwarf_Die *cu_die, Dwarf_Die *scopes, - int nr_scopes, Dwarf_Die *type_die) +static enum type_match_result find_data_type_block(struct data_loc_info *d= loc, + Dwarf_Die *cu_die, + Dwarf_Die *scopes, + int nr_scopes, + Dwarf_Die *type_die) { LIST_HEAD(basic_blocks); struct die_var_type *var_types =3D NULL; u64 src_ip, dst_ip, prev_dst_ip; - int ret =3D -1; + enum type_match_result ret =3D PERF_TMR_UNKNOWN; =20 /* TODO: other architecture support */ if (!arch_supports_insn_tracking(dloc)) - return -1; + return PERF_TMR_BAIL_OUT; =20 prev_dst_ip =3D dst_ip =3D dloc->ip; for (int i =3D nr_scopes - 1; i >=3D 0; i--) { Dwarf_Addr base, start, end; LIST_HEAD(this_blocks); - int found; =20 if (dwarf_ranges(&scopes[i], 0, &base, &start, &end) < 0) break; @@ -1185,9 +1185,9 @@ static int find_data_type_block(struct data_loc_info = *dloc, fixup_var_address(var_types, start); =20 /* Find from start of this scope to the target instruction */ - found =3D find_data_type_insn(dloc, &basic_blocks, var_types, + ret =3D find_data_type_insn(dloc, &basic_blocks, var_types, cu_die, type_die); - if (found > 0) { + if (ret =3D=3D PERF_TMR_OK) { char buf[64]; =20 if (dloc->op->multi_regs) @@ -1199,11 +1199,10 @@ static int find_data_type_block(struct data_loc_inf= o *dloc, pr_debug_dtp("found by insn track: %#x(%s) type-offset=3D%#x\n", dloc->op->offset, buf, dloc->type_offset); pr_debug_type_name(type_die, TSR_KIND_TYPE); - ret =3D 0; break; } =20 - if (found < 0) + if (ret =3D=3D PERF_TMR_BAIL_OUT) break; =20 /* Go up to the next scope and find blocks to the start */ @@ -1357,11 +1356,11 @@ static int find_data_type_die(struct data_loc_info = *dloc, Dwarf_Die *type_die) } =20 if (reg !=3D DWARF_REG_PC) { - ret =3D find_data_type_block(dloc, &cu_die, scopes, + result =3D find_data_type_block(dloc, &cu_die, scopes, nr_scopes, type_die); - if (ret =3D=3D 0) { + if (result =3D=3D PERF_TMR_OK) { ann_data_stat.insn_track++; - goto out; + ret =3D 0; } } =20 --=20 2.46.0.184.g6999bdac58-goog From nobody Fri Dec 19 16:13:32 2025 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 C515F13D51B; Fri, 16 Aug 2024 23:58:44 +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=1723852724; cv=none; b=GYE6kRg18YeviLt7bPVjRq/sT8totye/fCJgyneiYBFeR59jWLkP2yzpuUMD2qIfaoaYEwGsBP9gHy2ZB34UgHyz8hXiCuwVBOB0j11jDqYlLxiR/p22KtINbujkwgatUMBZOr9ew440/1rseS/WpEKOHO+Qb+xIMJKRxE5EEEo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723852724; c=relaxed/simple; bh=OoqgGDfXJTydY97bMo4SdpTXavrvCBBCpnszshPk/mY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MXRYrfye5G8MOKAlb0fOdJVJG+na31k5N0GYJIp94lkvzkfshsZShp6OUcynE1NvCE6gLp1VCaynLDBQAJmeGzYrKvJh0fYogSPOf3ZIfaAhFTovrbFwmUq2oT6m/zn0J8aQIfEZ8+gficlx1mxZALitIoVfIu+qIstIlpRlI8w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tNyb2oDB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tNyb2oDB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBBBBC4AF0E; Fri, 16 Aug 2024 23:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723852724; bh=OoqgGDfXJTydY97bMo4SdpTXavrvCBBCpnszshPk/mY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tNyb2oDB6cdvoIX7Z6OiR2r9BzWRmwtsP2YskSRZQBArirv8yekFZVFlTwubHMTKV HwKwdTPtwovFffaVsp2Z/wcCVBYHUurnh9Fks92qqQJ6fhSD9yCa6APB3JB+z9ZxF+ 6/bXESQ0zL8lt+nH9PJRvKc1Xp0M33sf4oFK/7aA3XpXATYGmrNlVe38KaIfa/5pLh uMcTGFITXynAmmPPPoks3GJHsKRH9MlTZF1NqomGfjeAbJ4HQbtYF3bvVvHHH8AduM lBtA7Ljem7i1bcXuq9sHiZAC29H5oSY43hVJ3sKyP81pARdFT1AeucEI1nkXiNlpZ0 rA0VFFugeWaFA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 6/9] perf annotate-data: Add is_pointer_type() helper Date: Fri, 16 Aug 2024 16:58:36 -0700 Message-ID: <20240816235840.2754937-7-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240816235840.2754937-1-namhyung@kernel.org> References: <20240816235840.2754937-1-namhyung@kernel.org> 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" It treats pointers and arrays in the same way. Let's add the helper and use it when it checks if it needs a pointer. Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index 5548cd8e84ba..b2414747cdeb 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -375,6 +375,13 @@ static const char *match_result_str(enum type_match_re= sult tmr) } } =20 +static bool is_pointer_type(Dwarf_Die *type_die) +{ + int tag =3D dwarf_tag(type_die); + + return tag =3D=3D DW_TAG_pointer_type || tag =3D=3D DW_TAG_array_type; +} + /* The type info will be saved in @type_die */ static enum type_match_result check_variable(struct data_loc_info *dloc, Dwarf_Die *var_die, @@ -382,15 +389,15 @@ static enum type_match_result check_variable(struct d= ata_loc_info *dloc, int offset, bool is_fbreg) { Dwarf_Word size; - bool is_pointer =3D true; + bool needs_pointer =3D true; Dwarf_Die sized_type; =20 if (reg =3D=3D DWARF_REG_PC) - is_pointer =3D false; + needs_pointer =3D false; else if (reg =3D=3D dloc->fbreg || is_fbreg) - is_pointer =3D false; + needs_pointer =3D false; else if (arch__is(dloc->arch, "x86") && reg =3D=3D X86_REG_SP) - is_pointer =3D false; + needs_pointer =3D false; =20 /* Get the type of the variable */ if (__die_get_real_type(var_die, type_die) =3D=3D NULL) { @@ -403,9 +410,8 @@ static enum type_match_result check_variable(struct dat= a_loc_info *dloc, * Convert to a real type it points to. But global variables * and local variables are accessed directly without a pointer. */ - if (is_pointer) { - if ((dwarf_tag(type_die) !=3D DW_TAG_pointer_type && - dwarf_tag(type_die) !=3D DW_TAG_array_type) || + if (needs_pointer) { + if (!is_pointer_type(type_die) || __die_get_real_type(type_die, type_die) =3D=3D NULL) { ann_data_stat.no_typeinfo++; return PERF_TMR_NO_POINTER; @@ -887,14 +893,13 @@ static enum type_match_result check_matching_type(str= uct type_state *state, state->regs[reg].ok, state->regs[reg].kind); =20 if (state->regs[reg].ok && state->regs[reg].kind =3D=3D TSR_KIND_TYPE) { - int tag =3D dwarf_tag(&state->regs[reg].type); Dwarf_Die sized_type; =20 /* * Normal registers should hold a pointer (or array) to * dereference a memory location. */ - if (tag !=3D DW_TAG_pointer_type && tag !=3D DW_TAG_array_type) { + if (!is_pointer_type(&state->regs[reg].type)) { if (dloc->op->offset < 0 && reg !=3D state->stack_reg) goto check_kernel; =20 --=20 2.46.0.184.g6999bdac58-goog From nobody Fri Dec 19 16:13:32 2025 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 0A05315380A; Fri, 16 Aug 2024 23:58:45 +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=1723852725; cv=none; b=oM0UB70+7KH2t/Ay0K+kBLMViE71xNILfmiUvoArVF8A1t3HJn4rb7kayMl/9zT3JH7mXOyChtWg9Nq1j9twcZfvApiOJ1hxUKdYbndbgfQOtEHawW2NPdvBoJwM0mDl+59k0k14CyiBGinb8U60+klolI/HWx6cG3jWi9FeYTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723852725; c=relaxed/simple; bh=SwbCiTE6qWd50qP+TjB2e7IR1OYwVHpD2mKCyGVMPx0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uzl+uupSUj9njL2BtAVRL2q0TmjoNTm+T90Yhxbj+nFGEIL+a4P725RFGCx3U/C+gCSWpsynxejBNe8z5Hjh7sY1ep76AHlAqi/tKCV1W6LvtvPKICwMIOKOIGDpBtU78POd3XQOA1ex8lzoJohlHdFFZu5txO7fpfYiPmhJKX8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W/GEEUHv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W/GEEUHv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AB92C4AF13; Fri, 16 Aug 2024 23:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723852724; bh=SwbCiTE6qWd50qP+TjB2e7IR1OYwVHpD2mKCyGVMPx0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W/GEEUHv1dWqijbA/zsrwVRIdjXjHr0GC7E9rtSf21WYfwp/qNNaQ+0vtCUDzxqxU JO2P3H5prk1UaX8iB4F8JQbTlIlsYajK8HouQ+s3zCDPAx3716HPhuMlbKOA3DMe8y QpQ7FAKKYtRZqPhFSYNJDHZw7mKRanUdsdYRHjRLWzvmTOCUH+LX56hJy5uNtq86dZ Llq7NS7lx59dhe3H7C+p5qHS7iIXntPFZa/qkap7BSp2e65aCs6bFfUFb4NlFXw/67 TGbYCB9EicU5tgB0AMrQdAF3Idjd8oOEwj2DNuR97Ul/w615oP2v9DWRMlSSR3o8+H zi0iomprAUVog== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 7/9] perf annotate-data: Add is_better_type() helper Date: Fri, 16 Aug 2024 16:58:37 -0700 Message-ID: <20240816235840.2754937-8-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240816235840.2754937-1-namhyung@kernel.org> References: <20240816235840.2754937-1-namhyung@kernel.org> 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" Sometimes more than one variables are located in the same register or a stack slot. Or it can overwrite existing information with others. I found this is not helpful in some cases so it needs to update the type information from the variable only if it's better. But it's hard to know which one is better, so we needs heuristics. :) As it deals with memory accesses, the location should have a pointer or something similar (like array or reference). So if it had an integer type and a variable is a pointer, we can take the variable's type to resolve the target of the access. If it has a pointer type and a variable with the same location has a different pointer type, it'll take one with bigger target type. This can be useful when the target type embeds a smaller type (like list header or RB-tree node) at the beginning so their location is same. Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 61 +++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index b2414747cdeb..916d26bfb9eb 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -382,6 +382,38 @@ static bool is_pointer_type(Dwarf_Die *type_die) return tag =3D=3D DW_TAG_pointer_type || tag =3D=3D DW_TAG_array_type; } =20 +/* returns if Type B has better information than Type A */ +static bool is_better_type(Dwarf_Die *type_a, Dwarf_Die *type_b) +{ + Dwarf_Word size_a, size_b; + Dwarf_Die die_a, die_b; + + /* pointer type is preferred */ + if (is_pointer_type(type_a) !=3D is_pointer_type(type_b)) + return is_pointer_type(type_b); + + if (is_pointer_type(type_b)) { + /* + * We want to compare the target type, but 'void *' can fail to + * get the target type. + */ + if (die_get_real_type(type_a, &die_a) =3D=3D NULL) + return true; + if (die_get_real_type(type_b, &die_b) =3D=3D NULL) + return false; + + type_a =3D &die_a; + type_b =3D &die_b; + } + + /* bigger type is preferred */ + if (dwarf_aggregate_size(type_a, &size_a) < 0 || + dwarf_aggregate_size(type_b, &size_b) < 0) + return false; + + return size_a < size_b; +} + /* The type info will be saved in @type_die */ static enum type_match_result check_variable(struct data_loc_info *dloc, Dwarf_Die *var_die, @@ -741,24 +773,33 @@ static void update_var_state(struct type_state *state= , struct data_loc_info *dlo if (!dwarf_offdie(dloc->di->dbg, var->die_off, &mem_die)) continue; =20 - if (var->reg =3D=3D DWARF_REG_FB) { - findnew_stack_state(state, var->offset, TSR_KIND_TYPE, - &mem_die); + if (var->reg =3D=3D DWARF_REG_FB || var->reg =3D=3D fbreg) { + int offset =3D var->offset; + struct type_state_stack *stack; =20 - pr_debug_dtp("var [%"PRIx64"] -%#x(stack)", - insn_offset, -var->offset); - pr_debug_type_name(&mem_die, TSR_KIND_TYPE); - } else if (var->reg =3D=3D fbreg) { - findnew_stack_state(state, var->offset - fb_offset, - TSR_KIND_TYPE, &mem_die); + if (var->reg !=3D DWARF_REG_FB) + offset -=3D fb_offset; + + stack =3D find_stack_state(state, offset); + if (stack && stack->kind =3D=3D TSR_KIND_TYPE && + !is_better_type(&stack->type, &mem_die)) + continue; + + findnew_stack_state(state, offset, TSR_KIND_TYPE, + &mem_die); =20 pr_debug_dtp("var [%"PRIx64"] -%#x(stack)", - insn_offset, -var->offset + fb_offset); + insn_offset, -offset); pr_debug_type_name(&mem_die, TSR_KIND_TYPE); } else if (has_reg_type(state, var->reg) && var->offset =3D=3D 0) { struct type_state_reg *reg; =20 reg =3D &state->regs[var->reg]; + + if (reg->ok && reg->kind =3D=3D TSR_KIND_TYPE && + !is_better_type(®->type, &mem_die)) + continue; + reg->type =3D mem_die; reg->kind =3D TSR_KIND_TYPE; reg->ok =3D true; --=20 2.46.0.184.g6999bdac58-goog From nobody Fri Dec 19 16:13:32 2025 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 D85D915533F; Fri, 16 Aug 2024 23:58:45 +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=1723852725; cv=none; b=lvvSKvH5svIPqgPqQIVUdd3iqphsoTrvNslF01adnsr7TopfzauirvXr2mswCnEFgoynoEdjvvfBu4sa1Eu2eSv1r9u6+iFLqP7fWvNPXIzjotGVyT7b2xdgKluCSxvvZS7alPN+bbZLJu8VzP+SpgnPwPbQmbH1yUgZlNHGnoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723852725; c=relaxed/simple; bh=gz0UmCdJs9jShwr5ENMPky04B9rwbyy9PU/CsFkc5aI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KYN7Vx3PABN7W2HXffkJqlCZDJRDqkyJAIHfDxNXUV5G2YRO/149rmdyd39JTS7/lOuLOwLwfRhe3VR6PGXX3VBSf0vh+oNLQ0+318Ltadd5RWttAaXM/NC+S4fOGfuLg1+moiDIbMVhc4j8QProWzJkpP5xHxSgofhs76pqbI0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MQO/8JCp; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MQO/8JCp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B055C4AF11; Fri, 16 Aug 2024 23:58:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723852725; bh=gz0UmCdJs9jShwr5ENMPky04B9rwbyy9PU/CsFkc5aI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MQO/8JCpt/Db31GLkMRFMbBzVIu1cIe0JNlruvGsta8HKldlmSkKqer32mizjs2AQ 3N/pHeFEQ5XJnlJ1DIIXANgNLyjdJBY0ekNNzsswB2LFeVaZqAKKPd75Dv8hp8obBQ TPi7y5k2eTTCkKwihrEdK+FM4e/xyXu9PaMjIk0FL1IdiHtoFbrcNEWeNEKRoUt46M j5WtyujfnEfWoj1SzcBfCNm7LiNaDI8Genjs7Dc/QyuQnx2qwi6kvKlYSIgXcbG3nE LQIac85y17zxEgYG74LMLxqcdPEK1eTw5h7n8g4sN+/mPqngWLWahmYSvAyEn59Q7d 7qo3NqamIKRGA== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 8/9] perf annotate-data: Check variables in every scope Date: Fri, 16 Aug 2024 16:58:38 -0700 Message-ID: <20240816235840.2754937-9-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240816235840.2754937-1-namhyung@kernel.org> References: <20240816235840.2754937-1-namhyung@kernel.org> 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" Sometimes it matches a variable in the inner scope but it fails because the actual access can be on a different type. Let's try variables in every scope and choose the best one using is_better_type(). I have an example with update_blocked_averages(), at first it found a variable (__mptr) but it's a void pointer. So it moved on to the upper scope and found another variable (cfs_rq). $ perf --debug type-profile annotate --data-type --stdio ... ----------------------------------------------------------- find data type for 0x140(reg14) at update_blocked_averages+0x2db CU for kernel/sched/fair.c (die:0x12dd892) frame base: cfa=3D1 fbreg=3D7 found "__mptr" (die: 0x13022f1) in scope=3D4/4 (die: 0x13022e8) failed: n= o/void pointer variable location: base=3Dreg14, offset=3D0x140 type=3D'void*' size=3D0x8 (die:0x12dd8f9) found "cfs_rq" (die: 0x1301721) in scope=3D3/4 (die: 0x130171c) type_offs= et=3D0x140 variable location: reg14 type=3D'struct cfs_rq' size=3D0x1c0 (die:0x12e37e5) final type: type=3D'struct cfs_rq' size=3D0x1c0 (die:0x12e37e5) IIUC the scope is like below: 1: update_blocked_averages 2: __update_blocked_fair 3: for_each_leaf_cfs_rq_safe 4: list_entry -> (container_of) The container_of is implemented like: #define container_of(ptr, type, member) ({ \ void *__mptr =3D (void *)(ptr); \ static_assert(__same_type(*(ptr), ((type *)0)->member) || \ __same_type(*(ptr), void), \ "pointer type mismatch in container_of()"); \ ((type *)(__mptr - offsetof(type, member))); }) That's why we see the __mptr variable first but it failed since it has no type information. Then for_each_leaf_cfs_rq_safe() is defined as #define for_each_leaf_cfs_rq_safe(rq, cfs_rq, pos) \ list_for_each_entry_safe(cfs_rq, pos, &rq->leaf_cfs_rq_list, \ leaf_cfs_rq_list) Note that the access was 0x140(r14). And the cfs_rq has leaf_cfs_rq_list at the 0x140. So it converts the list_head pointer to a pointer to struct cfs_rq here. $ pahole --hex -C cfs_rq vmlinux | grep 140 struct cfs_rq struct list_head leaf_cfs_rq_list; /* 0x140 = 0x10 */ Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 44 ++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index 916d26bfb9eb..e86f40fed323 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -1244,7 +1244,6 @@ static enum type_match_result find_data_type_block(st= ruct data_loc_info *dloc, =20 pr_debug_dtp("found by insn track: %#x(%s) type-offset=3D%#x\n", dloc->op->offset, buf, dloc->type_offset); - pr_debug_type_name(type_die, TSR_KIND_TYPE); break; } =20 @@ -1273,6 +1272,7 @@ static int find_data_type_die(struct data_loc_info *d= loc, Dwarf_Die *type_die) int fbreg =3D -1; int fb_offset =3D 0; bool is_fbreg =3D false; + bool found =3D false; u64 pc; char buf[64]; enum type_match_result result; @@ -1358,14 +1358,17 @@ static int find_data_type_die(struct data_loc_info = *dloc, Dwarf_Die *type_die) =20 /* Search from the inner-most scope to the outer */ for (i =3D nr_scopes - 1; i >=3D 0; i--) { + Dwarf_Die mem_die; + int type_offset =3D offset; + if (reg =3D=3D DWARF_REG_PC) { if (!die_find_variable_by_addr(&scopes[i], dloc->var_addr, - &var_die, &offset)) + &var_die, &type_offset)) continue; } else { /* Look up variables/parameters in this scope */ if (!die_find_variable_by_reg(&scopes[i], pc, reg, - &offset, is_fbreg, &var_die)) + &type_offset, is_fbreg, &var_die)) continue; } =20 @@ -1374,43 +1377,50 @@ static int find_data_type_die(struct data_loc_info = *dloc, Dwarf_Die *type_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, type_die, reg, offset, is_fbre= g); + 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, offset); + 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, offset); + fb_offset, type_offset); } else { - pr_debug_dtp("type_offset=3D%#x\n", offset); + 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; } - ret =3D 0; } else { pr_debug_dtp("failed: %s\n", match_result_str(result)); - ret =3D -1; } + pr_debug_location(&var_die, pc, reg); - pr_debug_type_name(type_die, TSR_KIND_TYPE); - dloc->type_offset =3D offset; - goto out; + pr_debug_type_name(&mem_die, TSR_KIND_TYPE); } =20 - if (loc->multi_regs && reg =3D=3D loc->reg1 && loc->reg1 !=3D loc->reg2) { + if (!found && loc->multi_regs && reg =3D=3D loc->reg1 && loc->reg1 !=3D l= oc->reg2) { reg =3D loc->reg2; goto retry; } =20 - if (reg !=3D DWARF_REG_PC) { + if (!found && reg !=3D DWARF_REG_PC) { result =3D find_data_type_block(dloc, &cu_die, scopes, - nr_scopes, type_die); + nr_scopes, type_die); if (result =3D=3D PERF_TMR_OK) { ann_data_stat.insn_track++; - ret =3D 0; + found =3D true; } } =20 - if (ret < 0) { + if (found) { + pr_debug_dtp("final type:"); + pr_debug_type_name(type_die, TSR_KIND_TYPE); + ret =3D 0; + } else { pr_debug_dtp("no variable found\n"); ann_data_stat.no_var++; } --=20 2.46.0.184.g6999bdac58-goog From nobody Fri Dec 19 16:13:32 2025 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 190301553A3; Fri, 16 Aug 2024 23:58:46 +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=1723852726; cv=none; b=VGuMztvbD2sAz8LTUJVtnpr7VQ0nt8tp5SfcQNts6uMu3RBGovzyjMIqF4FYnQJLh/RYiWhfkrlalXTrPevbIjVeH8OMZcteCj3fnEXCzOEO76mtL0Qy/U8YXxwtPObNsZ0rFHrJ/uAD3ypuoNHOMhwoeEqeFgTye+bR09OLm40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723852726; c=relaxed/simple; bh=bVwU8VTS7qfB6LIa6XnvFuKDHO0RzgTfbyXDJAdcTdY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OdguynwZ4cmAknOVUNVmuT9telYeEipebsHAZHabQJsxvkOFUoQBLNzR2BZppsE6l/wXebZaXg+VVbuYvEbmRHfGI6tBHSHPKqnGJsPpWrTfKJKdngfrvJ8QKImiSB4ZYFp6oD5knu1OyqTe5ogEudG0kKw9tsFOdydE1YET+Mk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s9u7P7pq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s9u7P7pq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C51DC4AF09; Fri, 16 Aug 2024 23:58:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723852725; bh=bVwU8VTS7qfB6LIa6XnvFuKDHO0RzgTfbyXDJAdcTdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s9u7P7pqv6Q+nJRJlb2bvCokLoc5eoRXOSePx2m9uV1zikirp9yNiSVuWB6H8y5ws +b3fzRL9wKcCnWU/JvjEDemG0YcSe1jbHdfRmBs2gzBQT2ZhKMl3grd1zzM4IQjELa 3Pos8xjRBWBmnHBsbY8Dh02pos0iF3ch13jWpF8+ImN79vRWUO6kUJpO+mcGG4g2/N nKQsi43NpYkuMjsfqr/6ICEWclLLnJdJMQmZkd8Kb7tOB5vYZ7OoqHx4+bzyHhbVnJ b2SZIc2hwdyAQQc8kjMzAa2NWX2gxZ11wrFD9y12fohmwTdJ29HOEqjqW44Z9ubaCw 5obW7SXI52L7Q== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Athira Rajeev Subject: [PATCH 9/9] perf annotate-data: Update type stat at the end of find_data_type_die() Date: Fri, 16 Aug 2024 16:58:39 -0700 Message-ID: <20240816235840.2754937-10-namhyung@kernel.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240816235840.2754937-1-namhyung@kernel.org> References: <20240816235840.2754937-1-namhyung@kernel.org> 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" after trying all possibilities with DWARF and instruction tracking. Signed-off-by: Namhyung Kim --- tools/perf/util/annotate-data.c | 47 +++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index e86f40fed323..aa330c7d8edd 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -432,10 +432,8 @@ static enum type_match_result check_variable(struct da= ta_loc_info *dloc, needs_pointer =3D false; =20 /* Get the type of the variable */ - if (__die_get_real_type(var_die, type_die) =3D=3D NULL) { - ann_data_stat.no_typeinfo++; + if (__die_get_real_type(var_die, type_die) =3D=3D NULL) return PERF_TMR_NO_TYPE; - } =20 /* * Usually it expects a pointer type for a memory access. @@ -444,10 +442,8 @@ static enum type_match_result check_variable(struct da= ta_loc_info *dloc, */ if (needs_pointer) { if (!is_pointer_type(type_die) || - __die_get_real_type(type_die, type_die) =3D=3D NULL) { - ann_data_stat.no_typeinfo++; + __die_get_real_type(type_die, type_die) =3D=3D NULL) return PERF_TMR_NO_POINTER; - } } =20 if (dwarf_tag(type_die) =3D=3D DW_TAG_typedef) @@ -456,16 +452,12 @@ static enum type_match_result check_variable(struct d= ata_loc_info *dloc, sized_type =3D *type_die; =20 /* Get the size of the actual type */ - if (dwarf_aggregate_size(&sized_type, &size) < 0) { - ann_data_stat.invalid_size++; + if (dwarf_aggregate_size(&sized_type, &size) < 0) return PERF_TMR_NO_SIZE; - } =20 /* Minimal sanity check */ - if ((unsigned)offset >=3D size) { - ann_data_stat.bad_offset++; + if ((unsigned)offset >=3D size) return PERF_TMR_BAD_OFFSET; - } =20 return PERF_TMR_OK; } @@ -1275,7 +1267,7 @@ static int find_data_type_die(struct data_loc_info *d= loc, Dwarf_Die *type_die) bool found =3D false; u64 pc; char buf[64]; - enum type_match_result result; + enum type_match_result result =3D PERF_TMR_UNKNOWN; =20 if (dloc->op->multi_regs) snprintf(buf, sizeof(buf), "reg%d, reg%d", dloc->op->reg1, dloc->op->reg= 2); @@ -1317,7 +1309,7 @@ static int find_data_type_die(struct data_loc_info *d= loc, Dwarf_Die *type_die) pr_debug_dtp("found by addr=3D%#"PRIx64" type_offset=3D%#x\n", dloc->var_addr, offset); pr_debug_type_name(type_die, TSR_KIND_TYPE); - ret =3D 0; + found =3D true; goto out; } } @@ -1416,16 +1408,37 @@ static int find_data_type_die(struct data_loc_info = *dloc, Dwarf_Die *type_die) } } =20 +out: if (found) { pr_debug_dtp("final type:"); pr_debug_type_name(type_die, TSR_KIND_TYPE); ret =3D 0; } else { - pr_debug_dtp("no variable found\n"); - ann_data_stat.no_var++; + switch (result) { + case PERF_TMR_NO_TYPE: + case PERF_TMR_NO_POINTER: + pr_debug_dtp("%s\n", match_result_str(result)); + ann_data_stat.no_typeinfo++; + break; + case PERF_TMR_NO_SIZE: + pr_debug_dtp("%s\n", match_result_str(result)); + ann_data_stat.invalid_size++; + break; + case PERF_TMR_BAD_OFFSET: + pr_debug_dtp("%s\n", match_result_str(result)); + ann_data_stat.bad_offset++; + break; + case PERF_TMR_UNKNOWN: + case PERF_TMR_BAIL_OUT: + case PERF_TMR_OK: /* should not reach here */ + default: + pr_debug_dtp("no variable found\n"); + ann_data_stat.no_var++; + break; + } + ret =3D -1; } =20 -out: free(scopes); return ret; } --=20 2.46.0.184.g6999bdac58-goog