From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471236; b=fT99pDXz3XrjEW8oLet7wjhan45XRCmoDeTy6DTtPgTpghb3mADTHdR02ud3QpDjoYDY AShNJkHjAK9ExnexbBRcVgl6UO/s9Y402D0gx5WBWjVa45HO9ocvAZZ8ah+m31Lukjtpc RhJ+T6Vlk7srd8Edl62A/lzNZknjAjHfRObAQ3lR+FpogrZT43y2GqxWgpp4YAEMqP3KL Pba4KrKxq9EbuAowNtQ4B1K0ensWbSBPriuM031cpne9YYbVf/UaZRVBaY9mpnEu9iuI2 GU7sQPCle1ZQATPbz8oixfRF9f41YRlelvqD+3bbtYkP7d0H+zrNebN8kIp5ry6p6Bw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471236; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=sVVVivoHslApfTcqxM1CCxGzJ/G5HGm6uVal0C5hstg=; b=5J7ELfS6IQjwwy9IsTOoJQAwjmXT6Tk2zdC2zkO1c3Hgx1w6rom+D8Vq4YLoGq+Do20H C9UsQkuVQ77eTz7RtWF9qcMdR4lnu+WPk9yc+hkt6B2CHoz6cxnGtxVFCJY9qsQtzmB7X G+gDiA1YRR+E2ioyn4hl6w3ffbwpU8+ht788hYpaVT1sdYwh49WP6Q+Paw5J5UmZ9tTMr KXzV+Rl6kcgMcO1omI00rGpZ7olA+jWOymB4Qdke/J/7aGr+0QuLDvaJNtaBmMsOW+/m4 jOUmR6SAWt4pR2ruZdmeM9m8xjSIu5qjEbItAEEXSWSlnohyzWwVw9Ehi6nr1roIQDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B4l+Q7t6; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C720606A31E; Mon, 23 Nov 2026 22:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B4l+Q7t6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E1B31F000C4; Mon, 23 Nov 2026 22:00:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471236; bh=sVVVivoHslApfTcqxM1CCxGzJ/G5HGm6uVal0C5hstg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=B4l+Q7t6eaY6p2wsLf5li3CBJmepl1BtTzv4FU3wDZpirojatiwWlDjih0u5csu35 pxgPvtCxm+3Z/2jACX/oJAXTmo/yYpUo20G2VL5rraAEpWB/Z6Og5OIzeD+ynEt0PV WVDKuy86964pmoLlXFNVnA8Km8l477vSLrax18sq23sGArwDkR6qNbcFNFGAI5KuPR u/6W28farNl2ZbssKPldSOQBATT76CUYruvIa97d3ic++psQ00WIwBtAIhal261NUk iH4NGV9w38gmuJrspwjlEq4xGue98jABgUjcN4pJGJg6CegaHxAYlrj0iUHMQ8hZAm 6df4PuNNdNn0w== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 01/19] perf build: Link the GTK UI with EXTRA_CFLAGS Date: Mon, 23 Nov 2026 19:00:06 -0300 Message-ID: <20261123220024.14891-2-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo The GTK objects are compiled with EXTRA_CFLAGS but libperf-gtk.so is linked with LDFLAGS only, so flags with link-time parts never reach it. With -fprofile-instr-generate the profiler runtime is missing at link time. Pass EXTRA_CFLAGS at link time, as the dlfilter rule does. Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile.perf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 1850ca2eeffe962a..d4b641925ab296db 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -644,7 +644,7 @@ $(GTK_IN): FORCE prepare $(Q)$(MAKE) $(build)=3Dgtk =20 $(OUTPUT)libperf-gtk.so: $(GTK_IN) $(PERFLIBS) - $(QUIET_LINK)$(CC) -o $@ -shared $(LDFLAGS) $(filter %.o,$^) $(GTK_LIBS) + $(QUIET_LINK)$(CC) -o $@ -shared $(LDFLAGS) $(EXTRA_CFLAGS) $(filter %.o,= $^) $(GTK_LIBS) =20 $(SCRIPTS) : $(OUTPUT)% : %.sh $(QUIET_GEN)$(INSTALL) '$<' '$@' --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471239; b=f3CsuvoGrXZATiPiIT3depvqR4Y05TU/GAzSNuynvITLakcLZFh3LCznobIFjZoEzD23 zV8ogFe0pgMR+t0vKFQLfiK4Vtg6yDuuBud/sxnWVkizqLU85vEv5OfxzT9IXxKlGzG9k zrl8hEcAnw12+BtoXbTYLlFT0HkqX14lphqrPMqxtV7106HTIhqbkp03CEOUhSystwmqR CJHr0iRdnodyuSMRsENc9YPjtwaUizk9kjB8rMuJHxrkRc0nNjGYeYgTsGUcealIpZLuD lFgWNWx+qxPJlcVKQnoudqsK/I4wTuhJ9eFnBgQ6fUkM3BTz901EuqNRNJTsN2jF6og== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471239; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=6tTextJCYtr4ecmZUAobFGaeQ6b0N7PqG63k5e9hyiM=; b=Nw33xWOWv0zUdvpD9iu0+GRE5C+A+3uPvBQq3Cs94CfLXkJUELH7gOSMDYLV61jejQwi xRDEGVssjhKhJFAizZoHzdCWONYDUdlFV1Tc8PZo2xHewNDXBPnlO1GxntH50KGKs0RA5 xqcgcBuLL2prsUmT4kB3DweRUTYtk6O1GzLJ2UgxmfsLTTdqsucsJl4nsxvMQMSJXY+Jx vSX1q/vCZDAX2kK+59kBFwbRPJSa3TH3KyVb+aPvr58fEUcUWhvgk/uojss8FPg1hsicd lgA+nKm1LY09OlWCyqIFPoU19RuVqPBtmwgpeSGA2eZf3HGblFETVCGSr8oRaOB7lPg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Aqi4m2P2; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3B7A606A326; Mon, 23 Nov 2026 22:00:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Aqi4m2P2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C90B1F000D1; Mon, 23 Nov 2026 22:00:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471239; bh=6tTextJCYtr4ecmZUAobFGaeQ6b0N7PqG63k5e9hyiM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Aqi4m2P27fEhYMkWIlyAwp0KHgZkFfa01j/R44ogSUfnr6xmTszgmDuQVA8RjrreL D6vab5IXFr+85HJwrW3V43FY0dbikZThQLxP4jPlQ02E0w3dsSofnGfXESM1ABNMIZ a5skMnlLBmfN5x9ywByTuT/qW1PgdUX8HFAZOBN4CC5bqmA6zuBwh1JAeEt9NB2PBb YqpqOar0GfwrRVqroyolW+OIlfSX+sIGk0Ojju39cQ0u2/GIwHjEmvqKOuzkW3hyKD MeRFfSmO+rr4ugWGMPirUyzt7DDFx78GaJ6CqSuiyYhfohhBESZAX8rxqkWP5ajbIt 8Kd/Wf7jYPZkA== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 02/19] perf annotate: Handle absolute addressing in data type profiling Date: Mon, 23 Nov 2026 19:00:07 -0300 Message-ID: <20261123220024.14891-3-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo x86 code accesses globals with absolute addresses, and 64-bit code also uses the same encoding for MMIO: the 64-bit kernel's __default_send_IPI_dest_field uses a disp32 the CPU sign extends, an absolute SIB with no base and no index. From an allmodconfig clang build, arch/x86/kernel/ipi.o: 890: 8b 04 25 00 c3 5f ff mov 0xffffffffff5fc300,%eax 8b1: 89 3c 25 10 c3 5f ff mov %edi,0xffffffffff5fc310 These accesses are local APIC MMIO, but demonstrate the absolute SIB encoding. Absolute global accesses in 32-bit code can be resolved to types as well. llvm-objdump prints the same displacements as -0xa03d00 and -0xa03cf0. The operand parser only recognized offset(reg), so the resolver skipped the access as not a memory reference. Parse a bare hex number as an absolute memory operand, including the negative disp32 llvm-objdump prints, and use the address in the resolver. The displacement is sign extended for 64-bit objects and zero extended for 32-bit ones; values that do not fit, zero and relocatable addends are skipped. An absolute global load records the type in the destination register, so the state is TSR_KIND_TYPE; a POINTER state records the address itself. Guard the comparisons that made a -1 frame base equal the -1 "no register" of an absolute operand. A no-register operand is not looked up as a variable, but the %gs:40 kernel stack canary is still recognized; other segment-relative operands are skipped. Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate-arch/annotate-x86.c | 37 ++++++++++++++++---- tools/perf/util/annotate.c | 31 ++++++++++++++-- tools/perf/util/annotate.h | 7 ++++ 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/annotate-arch/annotate-x86.c b/tools/perf/util= /annotate-arch/annotate-x86.c index e38a4e7a54d5585c..a975c39c3d6ce008 100644 --- a/tools/perf/util/annotate-arch/annotate-x86.c +++ b/tools/perf/util/annotate-arch/annotate-x86.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include #include @@ -230,6 +231,11 @@ static bool vtable_get_rettype(Dwarf_Die *class_die, i= nt offset, return die_get_real_type(&func_die, type_die) !=3D NULL; } =20 +static bool is_stack_or_fb_reg(struct type_state *state, int fbreg, int re= g) +{ + return (fbreg !=3D -1 && reg =3D=3D fbreg) || reg =3D=3D state->stack_reg; +} + static void update_insn_state_x86(struct type_state *state, struct data_loc_info *dloc, Dwarf_Die *cu_die, struct disasm_line *dl) @@ -437,7 +443,7 @@ static void update_insn_state_x86(struct type_state *st= ate, invalidate_reg_state(tsr); =20 /* Case 1: Based on stack pointer or frame pointer */ - if (sreg =3D=3D fbreg || sreg =3D=3D state->stack_reg) { + if (is_stack_or_fb_reg(state, fbreg, sreg)) { struct type_state_stack *stack; int offset =3D src->offset - fboff; =20 @@ -626,7 +632,7 @@ static void update_insn_state_x86(struct type_state *st= ate, =20 retry: /* Check stack variables with offset */ - if (sreg =3D=3D fbreg || sreg =3D=3D state->stack_reg) { + if (is_stack_or_fb_reg(state, fbreg, sreg)) { struct type_state_stack *stack; int offset =3D src->offset - fboff; =20 @@ -717,13 +723,17 @@ static void update_insn_state_x86(struct type_state *= state, pr_debug_type_name(&tsr->type, tsr->kind); } /* Or check if it's a global variable */ - else if (sreg =3D=3D DWARF_REG_PC) { + else if (sreg =3D=3D DWARF_REG_PC || + annotated_op_loc__is_abs(src, map__dso(dloc->ms->map))) { struct map_symbol *ms =3D dloc->ms; u64 ip =3D ms->sym->start + dl->al.offset; u64 addr; int offset; =20 - addr =3D annotate_calc_pcrel(ms, ip, src->offset, dl); + if (sreg =3D=3D DWARF_REG_PC) + addr =3D annotate_calc_pcrel(ms, ip, src->offset, dl); + else + addr =3D annotated_op_loc__abs_addr(src, map__dso(ms->map)); =20 if (!get_global_var_type(cu_die, dloc, ip, addr, &offset, &type_die) || @@ -737,7 +747,7 @@ static void update_insn_state_x86(struct type_state *st= ate, tsr->offset =3D 0; tsr->ok =3D true; =20 - pr_debug_dtp("mov [%x] global addr=3D%"PRIx64" -> reg%d", + pr_debug_dtp("mov [%x] global addr=3D%#"PRIx64" -> reg%d", insn_offset, addr, dst->reg1); pr_debug_type_name(&type_die, tsr->kind); } @@ -827,7 +837,7 @@ static void update_insn_state_x86(struct type_state *st= ate, /* Case 3. register to memory transfers */ if (!src->mem_ref && dst->mem_ref) { /* Check stack variables with offset */ - if (dst->reg1 =3D=3D fbreg || dst->reg1 =3D=3D state->stack_reg) { + if (is_stack_or_fb_reg(state, fbreg, dst->reg1)) { struct type_state_stack *stack; int offset =3D dst->offset - fboff; =20 @@ -960,6 +970,21 @@ static void extract_op_location_x86(const struct arch = *arch, op_loc->offset =3D strtol(s + 1, &p, 0); if (p && p !=3D s + 1) op_loc->imm =3D true; + } else if (*s =3D=3D '-' || strstarts(s, "0x")) { + u64 offset =3D strtoull(s, NULL, 0); + bool exact; + + /* + * The offset is an int: a disp32 fits it as a u32 or, + * sign extended, as an int, which is how the LLVM + * disassembler prints one that does not fit an int. + */ + exact =3D (s64)(int)offset =3D=3D (s64)offset; + if (offset !=3D 0 && (offset <=3D UINT_MAX || exact)) { + /* An absolute address: 32-bit code, or a 64-bit disp32 */ + op_loc->mem_ref =3D true; + op_loc->offset =3D offset; + } } } } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index e270d16ce1778487..c41d23d97c005abc 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2755,6 +2755,21 @@ int arch__dwarf_regnum(const struct arch *arch, cons= t char *str) return reg < 0 ? -1 : reg; } =20 +/* A relocatable object's operand is an unrelocated addend, not an address= */ +bool annotated_op_loc__is_abs(const struct annotated_op_loc *op_loc, + const struct dso *dso) +{ + return !dso__rel(dso) && op_loc->mem_ref && op_loc->reg1 =3D=3D -1 && op_= loc->reg2 =3D=3D -1 && + op_loc->segment =3D=3D INSN_SEG_NONE && op_loc->offset !=3D 0; +} + +/* The disp32 of a 64-bit object is sign extended, a 32-bit one is not */ +u64 annotated_op_loc__abs_addr(const struct annotated_op_loc *op_loc, + const struct dso *dso) +{ + return dso__is_64_bit(dso) ? (u64)(s64)op_loc->offset : (u32)op_loc->offs= et; +} + /** * annotate_get_insn_location - Get location of instruction * @arch: the architecture info @@ -2772,7 +2787,7 @@ int arch__dwarf_regnum(const struct arch *arch, const= char *str) * mov (%rax), %rcx # src_reg1 =3D rax, src_mem =3D 1, src_offset =3D= 0 * # dst_reg1 =3D rcx, dst_mem =3D 0 * - * mov 0x18, %r8 # src_reg1 =3D -1, src_mem =3D 0 + * mov 0x18, %r8 # src_reg1 =3D -1, src_mem =3D 1, src_offset =3D = 0x18 * # dst_reg1 =3D r8, dst_mem =3D 0 * * mov %rsi, 8(%rbx,%rcx,4) # src_reg1 =3D rsi, src_mem =3D 0, src_mul= ti_regs =3D 0 @@ -3046,6 +3061,13 @@ __hist_entry__get_data_type(struct hist_entry *he, c= onst struct arch *arch, dloc.var_addr =3D annotate_calc_pcrel(ms, dloc.ip, op_loc->offset, dl); } + /* An absolute address: 32-bit code, or a 64-bit disp32 */ + else if (annotated_op_loc__is_abs(op_loc, map__dso(ms->map))) { + struct dso *dso =3D map__dso(ms->map); + + dloc.var_addr =3D annotated_op_loc__abs_addr(op_loc, dso); + op_loc->reg1 =3D DWARF_REG_PC; + } =20 /* This CPU access in kernel - pretend PC-relative addressing */ if (dso__kernel(map__dso(ms->map)) && arch__is_x86(arch) && @@ -3054,7 +3076,9 @@ __hist_entry__get_data_type(struct hist_entry *he, co= nst struct arch *arch, op_loc->reg1 =3D DWARF_REG_PC; } =20 - mem_type =3D find_data_type(&dloc); + mem_type =3D NULL; + if (op_loc->reg1 !=3D -1) + mem_type =3D find_data_type(&dloc); =20 if (mem_type =3D=3D NULL && is_stack_canary(arch, op_loc)) { istat->good++; @@ -3062,6 +3086,9 @@ __hist_entry__get_data_type(struct hist_entry *he, co= nst struct arch *arch, return &canary_type; } =20 + if (op_loc->reg1 =3D=3D -1) + continue; + if (mem_type) istat->good++; else diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index e0fc48ec561225d9..58adf7f84146be5f 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -18,6 +18,7 @@ #include "branch.h" #include "evsel.h" =20 +struct dso; struct hist_browser_timer; struct hist_entry; struct map; @@ -637,6 +638,12 @@ struct annotated_insn_loc { i < INSN_OP_MAX; \ i++, op_loc++) =20 +/* Bare number operand: an absolute address, as 32-bit code and the kernel= use */ +bool annotated_op_loc__is_abs(const struct annotated_op_loc *op_loc, + const struct dso *dso); +u64 annotated_op_loc__abs_addr(const struct annotated_op_loc *op_loc, + const struct dso *dso); + /* Get detailed location info in the instruction */ int annotate_get_insn_location(const struct arch *arch, struct disasm_line= *dl, struct annotated_insn_loc *loc); --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471243; b=3FMiBgKdv2iluobzrbd3YS8h/Rs1RHKtqtknbqSNJV6YAKfWz5HyuLwsMrsL7tgw4XBJ yFc4LzVDkNFZrlsri56VqiKyinUXWQwf2mxWHWnOe5BNIoprrnCioi+2Gh+i+c0l3/lJF I78pe/6wT8L323LpX9OAjtz9U+eBWMft3n8/OZ4NwhmE16fbOOvceIgSj5VCIk0cc+FOU 5+IzangkLbyVCWlEp+Ae+xyIeWZYYrpPL+w/gHAWcTvXVIAvDI/Z6s8V6kgI5GInLi8zm rjtXU1wpp21g3sFwIAEihVNN1sjuah1epU8SZPNLITA7UkfnWNoMS6mfUSIAuYN6Bkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471243; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=Eklqjlfw+dbbmkf2E1j2lA7XU4h2qCIteDMVFESLUCg=; b=1wML2+zymAHbIWm84Kqch1s1sE7/5sEyaCjxk8ihonAZEsxVemZVQz+Jf2DJYYYZfSue J267s9e9Y0IjzunMbwKePB9uMLV/H3vnR7BPmpbu8Je8T0AbvoiJWQ1+TYhVzqRIBs4Iv upzWT6HCpLNsY5+qITCDTl0a/xYSeRJRO04hhZrYLFbDNKmN/EdmckaX9xbVYc5MyHHjz HUCtvuZd3JU1t5Jju8fSg+Qb0zdqROOzbfiuRPKFhVrZQWXqCChgs096N/s0Q68clpieT GxyY0h/scXJZMMqXYqPMNmXcdW2OYL3XvHNRdIZluPci4QdFzI+P2sdr01lKgm2ajig== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="MTND/Brn"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7B9C606A330; Mon, 23 Nov 2026 22:00:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=MTND/Brn Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB24D1F000C4; Mon, 23 Nov 2026 22:00:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471242; bh=Eklqjlfw+dbbmkf2E1j2lA7XU4h2qCIteDMVFESLUCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MTND/Brnf4B/7cvJytUjzoZeKsKW0aZ86UehstCmUOCGqIO64LtnP9cWfIKSXl9zt 9ouKXrzSkagrnILNCDRRzEGgXmTE6APWfc1efC1uejACXV+I0KMwOQ3gR6+IDEQVPW SN9ORRYdRFgjDbOGJ1aoWOhFGZKmNSF8w0CxmkERGh4HIyHvWCNVQoZUzupgQxh57c umvfcRB/9CxsbexhxmcIsR57MbHJz22/cOA53uVT27a7uXFob4lrtO4Tqt0+3zes8K /492hKxnyPOpkMQgYuth0PgEbVH1Nwin1DZfBQBta0A4hPzjR3ctTIkLG/kKcjprhA cYx47tXSss5Zg== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 03/19] perf annotate: Print the stats after the annotations Date: Mon, 23 Nov 2026 19:00:08 -0300 Message-ID: <20261123220024.14891-4-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo With --code-with-type the instruction stats are printed from hists__find_annotations() before that event is annotated: the first event reports zeros and later events can report stale counts. The data type total is only counted in --data-type mode, so --type-stat without it is incomplete too. Print the stats once after all events have been annotated, warning if --type-stat is used without --data-type. Leave the TUI's alternate screen before printing, so the stats remain on the terminal. Fixes: 58824fa0087e1cb7 ("perf annotate: Add --insn-stat option for debuggi= ng") Fixes: 61a9741e9f78c64c ("perf annotate: Add --type-stat option for debuggi= ng") Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Documentation/perf-annotate.txt | 2 +- tools/perf/builtin-annotate.c | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Docume= ntation/perf-annotate.txt index 1a90b09a12d5abb1..d27eff28ba4f6af0 100644 --- a/tools/perf/Documentation/perf-annotate.txt +++ b/tools/perf/Documentation/perf-annotate.txt @@ -169,7 +169,7 @@ include::itrace.txt[] all data types it finds. =20 --type-stat:: - Show stats for the data type annotation. + Show stats for the data type annotation (with --data-type). =20 --skip-empty:: Do not display empty (or dummy) events. diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 7cb7e03d9a21d81b..b7f71cc95c0cd4c0 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -414,11 +414,6 @@ static void hists__find_annotations(struct hists *hist= s, struct rb_node *nd =3D rb_first_cached(&hists->entries), *next; int key =3D K_RIGHT; =20 - if (ann->type_stat) - print_annotate_data_stat(&ann_data_stat); - if (ann->insn_stat) - print_annotate_item_stat(&ann_insn_stat, "Instruction"); - while (nd) { struct hist_entry *he =3D rb_entry(nd, struct hist_entry, rb_node); struct annotation *notes; @@ -663,6 +658,21 @@ static int __cmd_annotate(struct perf_annotate *ann) hists__find_annotations(hists, pos, ann); } =20 + if (use_browser =3D=3D 1 && (ann->insn_stat || ann->type_stat)) { + /* Leave the alternate screen before printing to the terminal. */ + ui__exit(false); + use_browser =3D 0; + } + + /* Here use_browser is 0 in stdio and TUI mode, so pr_warning reaches the= terminal */ + if (ann->type_stat && !ann->data_type) + pr_warning("Warning: --type-stat needs --data-type\n"); + + if (ann->data_type && ann->type_stat) + print_annotate_data_stat(&ann_data_stat); + if (ann->insn_stat) + print_annotate_item_stat(&ann_insn_stat, "Instruction"); + if (use_browser =3D=3D 2) { void (*show_annotations)(void); =20 --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471245; b=r0uhzvKpu77yS5veStIbVLalz/JNpINBHc9uq6g5T0Jt0NNfZQg5ahWsjwRK5D4v1ApE +2kR9TF/xgHTaGFLQ7E2zJq6zooqtknpoCmsNui8f5+CEZ+CCrgliCCf1P+ZhTbet3FrS +ZV37PTTdR9z/lx2KUjZvgcJflBpcMiwNcSea2XY062Uz4OS+6r2cJlk86ohggOUys4H1 SWNjD0e8hFe0DIubegu1E4D7N/Pf2AwZyWP0yVu6JMwoHzxv/etpy9LDBBbesX9je3ydf 29QAPzr7Kpk9NJvmpwQfPux2sWvca+Yowjnw91P2Bhjy2B9vgPSgVJ9EeSH97ve9+cg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471245; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=roRWIvlWqU8+3akzoi6oZQ2mr1t4JbZ7FcCva5/iuis=; b=4yh6a4e7JnVIb/zsUwytZawe3uCEHt0FAcRrxVA05a4hbdTku03bmZSWhH2Xxqa6MSa2 rMLGRM0ndhjtSxsA4/DTHMeKc0DpCPGlzANu+k3HvQdorvY3fxFjUT6kPCItPq961ZLqt mkkOJoyBVUq2ZnpUIVOXZHqmuRSpMZCVs65wOmLWSdFLe6P6MpX2EoheUougvpVkOyKPe 27iFFrZvpK/gmB5pdp/YhFjUYd/j5C6mbZPNf6hmtjE3PJWUqqlddeiAHBo0txRM5V8bJ pJH8tNn0fErl+mRoW07lN9rZN9XSSC4mUGt9iI8BeDKSZvUc6frGtBXQNaIxNtiFFmg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ap7DN1lx; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D472F606A321; Mon, 23 Nov 2026 22:00:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ap7DN1lx Received: by smtp.kernel.org (Postfix) with ESMTPSA id 059F21F000CA; Mon, 23 Nov 2026 22:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471245; bh=roRWIvlWqU8+3akzoi6oZQ2mr1t4JbZ7FcCva5/iuis=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ap7DN1lxojf32eVHVwwhGQMDsieatMb5YHyZPVPKXi/TfjBDEvpaS20lP6Ce0/GG7 V3uKIoCRCXuZY/gakhvt6dhi0oWhGsIRI03QpOaw0vonQf2EmaL8L56BrCjPEtQewv SlADp2Sw6X0AoyOlc1Jhgnh4Xy//QGOAS9V14lj5QwVMUY6oT5bcFUs/rjtslJqztv APCN7dzh/fjBr+vFDjm4wIQd4z7CriVDpV7yO2uiMVqqrU40HYGSiuNusn4cztAn48 OlX9fBNkNn06HeQeGwcXqVfi+xzGgPWTOSZijKcSarRh8qKMR96A0DKfaduDp3gQUb XU+b/e85kZF+Q== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 04/19] perf build: Record the features checked outside FEATURE_TESTS Date: Mon, 23 Nov 2026 19:00:09 -0300 Message-ID: <20261123220024.14891-5-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo llvm-perf and rust are in FEATURE_DISPLAY but not in FEATURE_TESTS, and jvmti and jvmti-cmlr are in neither list: they can't be part of the test-all fast path, which sets every FEATURE_TESTS entry to 1 when test-all.c builds. Since FEATURE-DUMP is written from FEATURE_TESTS only, a FEATURES_DUMP=3D build, as used by build-test, never sees them and silently builds without libLLVM, the rust workloads and the jvmti agent. Record these four in the dump after the regular feature checks have run, from a list of their own, so that customizing FEATURE_DISPLAY does not change what the dump carries. Fixes: 206dcfca1f5cfac3 ("perf build: Autodetect minimum required llvm-dev = version") Fixes: 3f5dfa472ea6771c ("tools build: Fix rust feature detection") Fixes: d4dfdf00d43e017d ("perf jvmti: Plug compilation into perf build") Fixes: dd1d0044dd1c1bf8 ("perf jvmti: Separate jvmti cmlr check") Cc: James Clark Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile.config | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index aed2e952c8f3710a..88b8bc13a578a24f 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -1369,3 +1369,10 @@ endif # tests. $(shell rm -f $(FEATURE_DUMP_FILENAME)) $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat= ))" >> $(FEATURE_DUMP_FILENAME))) +# Features checked outside FEATURE_TESTS aren't part of the test-all fast +# path, so they have to be checked explicitly and recorded here too, +# otherwise a FEATURES_DUMP=3D build silently disables them. +FEATURE_DUMP_EXTRA :=3D llvm-perf rust jvmti jvmti-cmlr +ifeq ($(FEATURES_DUMP),) +$(foreach feat,$(FEATURE_DUMP_EXTRA),$(shell echo "$(call feature_assign,$= (feat))" >> $(FEATURE_DUMP_FILENAME))) +endif --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471249; b=uki+TzwXU8mKRzDnywPXltiYajutvMWcSBQe6vkWVv0HBJ2Wbr2ZN/IU5xksITyL7e1E jiX7beWBTlhfPKC35v1lG8+neksSHqRgxfHDKRnUkMmVotbJKEYrOhJxsuI6HLyS8l8xs PrRK/GWo6RYRSHU9TcGFFkWFTkOcfjrq+PqHJB0icsgjIoaWiV/JAZ5lOA/vcMxYmECPI sh4lg7f1M7H39JRluQlxZZllRgS8FXKtNTpAV/7zWyAtEdMpqsJcC4gL/VhjJzw85ib3E d+DjnC9LME1lN9wHMFna9xFZk/IjEW7RnZDMK+9xUzGTdMCgFhfBKmMCtPZXVD4Ld5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471249; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=Azkx36zjbxqJYLpSaoVLe2nz1AlSWqVWOKME4todCY0=; b=D6qlb53NC7ZlYqMd9FcjySykOymPmEOcxSKaDo5pjzzpTutt5BjYy50h3tfc3OO0Z6i4 CTttVJoJT6LMRnvbNA60iu24lhCPOwZfNVYRnBeS1r5Xi65U999TyCbo4QH3Jmq226hm0 rphJMGX5ygre2hqmGL+4jA4/HK2jKHE2UknG8m5xWf1rtoluTbTxPHzH4fWJ2iDBCZsEc e6Go/J+BrKnnwqpDtSblaBgwq/03c44r2bY0CuD1zUaefXUq41+pmJmhC0W9YqPKSgM/O aG96Dz8ZcU7lC5trS7vsUlQjL8F3N8w5hBRX6BQqe/1Le/JHtVuzBJHsCEm/sDtFviA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AjIBHUrx; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6357F606A321; Mon, 23 Nov 2026 22:00:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AjIBHUrx Received: by smtp.kernel.org (Postfix) with ESMTPSA id 353DA1F000CA; Mon, 23 Nov 2026 22:00:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471248; bh=Azkx36zjbxqJYLpSaoVLe2nz1AlSWqVWOKME4todCY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AjIBHUrxGKcooL2En/XoFmXkrTBcvf6UXw8UNJSwgGiin4ujbZ0ctbUrzptu9Zaqj cLKxZZyNpFJSaM7vIjVW6HAIONFbp79WGdHxWmvpMvam+RvwaaP4MHG9n7mhsKYZBC bWRrmzemiobHlgPiNqBbq1EvT8ZLV8ewLKjI6dXa2PhMCGyetjqSJLT15e2abza9E1 llwnJf7bXaiEmnNhmvYz34mIsPIs1N5jDLqT4F+putAnJYwEa9WdbSv0tIsb3T9FOo ppKZKVETTdQt6V18RqJiYr33mLdYpNxBeYK8l8vRJeSh8xbYWVls9MI67ZSzro9CBC +Dem97TlqlB9g== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 05/19] perf annotate-x86: Record immediates in a 64-bit field Date: Mon, 23 Nov 2026 19:00:10 -0300 Message-ID: <20261123220024.14891-6-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo An x86 immediate is parsed into the int offset shared with displacements, so a constant wider than 32 bits is truncated to garbage that the register tracking then records as its value. Add a s64 imm_value to struct annotated_op_loc, fill it in extract_op_location_x86() with strtoull() and read it in the three places of update_insn_state_x86() that take an immediate as a constant. The displacement and the ARM64 and x86 %gs: immediates, which fit in 32 bits, stay in offset, and pointer offset tracking is unchanged. Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate-arch/annotate-x86.c | 13 ++++++++----- tools/perf/util/annotate.h | 6 ++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/annotate-arch/annotate-x86.c b/tools/perf/util= /annotate-arch/annotate-x86.c index a975c39c3d6ce008..94c45806029ee670 100644 --- a/tools/perf/util/annotate-arch/annotate-x86.c +++ b/tools/perf/util/annotate-arch/annotate-x86.c @@ -341,7 +341,7 @@ static void update_insn_state_x86(struct type_state *st= ate, tsr->lifetime_end =3D 0; =20 if (src->imm) - imm_value =3D src->offset; + imm_value =3D src->imm_value; else if (has_reg_type(state, src->reg1) && state->regs[src->reg1].kind =3D=3D TSR_KIND_CONST) imm_value =3D state->regs[src->reg1].imm_value; @@ -408,7 +408,7 @@ static void update_insn_state_x86(struct type_state *st= ate, tsr->lifetime_end =3D 0; =20 if (src->imm) - imm_value =3D src->offset; + imm_value =3D src->imm_value; else if (has_reg_type(state, src->reg1) && state->regs[src->reg1].kind =3D=3D TSR_KIND_CONST) imm_value =3D state->regs[src->reg1].imm_value; @@ -589,7 +589,7 @@ static void update_insn_state_x86(struct type_state *st= ate, =20 if (src->imm) { tsr->kind =3D TSR_KIND_CONST; - tsr->imm_value =3D (s64)src->offset; + tsr->imm_value =3D src->imm_value; tsr->offset =3D 0; tsr->ok =3D true; =20 @@ -967,8 +967,11 @@ static void extract_op_location_x86(const struct arch = *arch, if (*s =3D=3D arch->objdump.register_char) { op_loc->reg1 =3D arch__dwarf_regnum(arch, s); } else if (*s =3D=3D arch->objdump.imm_char) { - op_loc->offset =3D strtol(s + 1, &p, 0); - if (p && p !=3D s + 1) + const char *start =3D s + 1; + u64 imm =3D strtoull(start, &p, 0); + + op_loc->imm_value =3D imm; + if (p && p !=3D start) op_loc->imm =3D true; } else if (*s =3D=3D '-' || strstarts(s, "0x")) { u64 offset =3D strtoull(s, NULL, 0); diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 58adf7f84146be5f..71a616b5ed1e1358 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -530,7 +530,8 @@ int arch__dwarf_regnum(const struct arch *arch, const c= har *str); * struct annotated_op_loc - Location info of instruction operand * @reg1: First register in the operand * @reg2: Second register in the operand - * @offset: Memory access offset in the operand + * @imm_value: Immediate value of an x86 operand + * @offset: Memory access offset, or an ARM64 or x86 %gs: immediate * @segment: Segment selector register * @addr_mode: Addressing mode, only valid if @mem_ref is true * @extend_type: Operand extension type (enum annotated_ext_type) @@ -538,11 +539,12 @@ int arch__dwarf_regnum(const struct arch *arch, const= char *str); * @amount: Number of bits to shift * @mem_ref: Whether the operand accesses memory * @multi_regs: Whether the second register is used - * @imm: Whether the operand is an immediate value (in offset) + * @imm: Whether the operand is an immediate value */ struct annotated_op_loc { int reg1; int reg2; + s64 imm_value; int offset; u8 segment; u8 addr_mode; --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471252; b=3L6rdDWtBnmVJBeIsebeQAegokGIIQGbXdNpxOCkvkVtrxbhrrojQQxFNzYhck8eTnMu ziyAiz8HuI9F55beIm/8f0y0merhFMFdNEz2/SIqhRro229o7tP0nFVtNiiGlxuNZqi1i 3pxCi/H2gnuO64PrMEltkiMCm9QnClq6xnpP8IBXO7/LIAcxUaG3QwGo6Y8Wf59YZD9Xf VTTebZWPfksha/xeX5aABWA81nWHitmp37Umf3AVyMHXuDvjv+RZhlSzC11nMXRE88rYY Ze0u8DOeWoT2QprZM4Z62a4O8bP03ucnu+e3xSSEVuLrtHNN4nsbNLQ3WDpc8Gg+L2g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471252; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=BAilv4VoXsQ9+WVNQ6tURkpXxWXhgKWKJX5ZMQISyiE=; b=WTRTgBpZPwoA7atW4rCzEVbNZyKqpFMJRgKnM/UkwMSg5NJreWCRXbXnigq5KQ5eFfN+ h44jNJEDV3Z2oimsDmytzRD2GCu1CqifVcMshF2bflKMa9tkpOZKYg/vl8Q5I4oPkcrWq AGPC2Ob1aZ/8CKZl4WyM7hZJD49n0pJFMVudix9X/YfmoEyR+w/sNSygqQq/EhRfj88DP kgG8Df3mJ+CVq6AfwggxPP2nSCyTNodpmcoXjR1TiDD6iN/DjjYRzjkkx3V2d2DAMnkyr yccEhev1L6+fi4FXS90F+Dei3FG6qIjIdq/hmgz8M999HOwuHBdqhAezvpk/cZIZ4Hw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kBb8nUCy; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A797606A31E; Mon, 23 Nov 2026 22:00:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kBb8nUCy Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6592C1F000C0; Mon, 23 Nov 2026 22:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471252; bh=BAilv4VoXsQ9+WVNQ6tURkpXxWXhgKWKJX5ZMQISyiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kBb8nUCyzRVdbwB8HX5SdoiLQnFJEUlWuCz8zYwpDfgevQrmODokwFmf8UcAegqHX 2MuDv+WEpsAzVQ2+Mw343agvPssXdih/jC59D0LDVVvnvH2nC3kLSdfcN4Oai2eUB9 /PT0YwbIz0Xe0tGEVyTjYPnzqMB5+1Fl92KucO9/JDyyb8VA4vKNXBxIKQnrGK8tVr 524xAejs75q5kc5ztslNjp9CLPR3tV/Dlo5QsNUkn6Jjn9DLuRF/K8Dt6hoR7bqyUm EfRrlWNtFtNyVT+R2IOsIRbhiYn+Q5PPGXzAHzKwx8Zq1Cobm6h/uIaoptVJFJC+x5 9q0YMBPPQSKSw== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 06/19] perf annotate-x86: Parse movabs like a mov Date: Mon, 23 Nov 2026 19:00:11 -0300 Message-ID: <20261123220024.14891-7-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo x86__instructions[] has no movabs: ins__find() strips the size suffix of "movabsq" and still finds nothing, so mov__parse() never runs and the source and target operands of the instruction are not split. The data type tracking then sees nothing, where the same instruction as a plain mov sets the destination register. The clang allmodconfig build has plenty, 282558 in vmlinux, all with an immediate, the KASAN shadow offset: ffffffff81271e2b: movabsq $-0x2000040000000000, %r15 No movabs with a memory operand shows up in vmlinux or in any object of that build. Add it as a mov; with the previous patch recording the immediate in 64 bits, both objdump spellings of the KASAN shadow offset track the same constant. Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate-arch/annotate-x86.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/annotate-arch/annotate-x86.c b/tools/perf/util= /annotate-arch/annotate-x86.c index 94c45806029ee670..0c74266cd4b99925 100644 --- a/tools/perf/util/annotate-arch/annotate-x86.c +++ b/tools/perf/util/annotate-arch/annotate-x86.c @@ -85,6 +85,7 @@ static const struct ins x86__instructions[] =3D { { .name =3D "lea", .ops =3D &mov_ops, }, { .name =3D "lock", .ops =3D &lock_ops, }, { .name =3D "mov", .ops =3D &mov_ops, }, + { .name =3D "movabs", .ops =3D &mov_ops, }, { .name =3D "movapd", .ops =3D &mov_ops, }, { .name =3D "movaps", .ops =3D &mov_ops, }, { .name =3D "movdqa", .ops =3D &mov_ops, }, --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471255; b=T2o7G7YLI8q/BbrHBVqNgvbG7EG6tptrh6Pj+PyewTwyx79Ej3JJw59UnMDySTxOLYrl LiEzSNoRLaRJ098gzKjCoxWl7649NRZB81q5Stvg72PGibxUgvHIwrQt1JDlvBVIV2wRp PmMzJmqH7GbPHF4twAxfXhJ0nv85CxMUBZaNxrYqAGOE9cQNq35VjCWNQt6C2iN9I2IWp hRb6fi4LjQI474PmwCbr7j9bRDkxkt363A7etKgNb+ky/HueNyN5KvxRSo9+TPyPQyguZ 6ZsIWXMUq8OgQD8DzlJndY+AEJ6dOM6ss1iiVnVIoC6Qb7h4YA1VpGF9uoCIpDnXLnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471255; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=5e5v7gpNkFC6ASicQajgFI5QGmumCqEa2vHlP77bnj0=; b=eyiI2zFkSCMRO5jNYBI+xNET2OoGks6vDI3g67HKtkyqyUZghMNkQlJ3WXqh6tlzhYN7 VxbNb8zgfZ+M56Ceo11PdngIGjogbQD1W9RqVeJ2hUSq4ThWT1HahEfKd0AXDGngPIA4r Bb0AuKumcOFLOKI+99g6tuV6ocSK74t1jvPgSq8TvjcSKjExrH47+5ldNYN1Mp/zZn4VS PMWYD2E3/bP1fxhq/ml5U1fKp0pzcyf7PiA7oxyWRbFdr0Wtat7UqUoICI3NSqZPQHXEq B6k838Xe97c9oHBOv6TyNL1idVKOUGi0jfCxAzbbjbVuhwKVAfYcdmDO83bDeHVdfZA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Dn07hJNO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71991606A327; Mon, 23 Nov 2026 22:00:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Dn07hJNO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9573E1F000CA; Mon, 23 Nov 2026 22:00:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471255; bh=5e5v7gpNkFC6ASicQajgFI5QGmumCqEa2vHlP77bnj0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Dn07hJNO60QrSey/3qaGmK1PILM3vJlhpfK6GLBw7QQMaBwv9zoeSR3R7eQNw6xyW lh0VolE3GRLIVJJINimGMbxJhl2x+Tw1CRGD9iDeBB3WmHZ3LHQbOoZow+A3j+twSC kHxhqU4HQ0Lp2TS2l8oM5irBOmWLfl5OggZVrnqz878tGdJc35MeDCdtRisZdmmMaz 7ywOA/YCoUIZGTr+NB5WsP3kyXRPgeQhkFZWXfV2z8+DZ6iJE+YiMS21J7VDfgV+uC txUKf4+N8rhCh2RkMrI78xISg5wbSWo/VOjcsSGxLGMJ7uyQYeln4eMDRx7mT0QghD Bg7KcG4MXRZzw== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 07/19] perf annotate-data: Count flexible array accesses for the whole struct Date: Mon, 23 Nov 2026 19:00:12 -0300 Message-ID: <20261123220024.14891-8-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo The per-member percentage sums the histogram entries in the member's own [offset, offset + size) range. A flexible array member is resolved at or past the end of its struct, so the struct row only covered its declared size and showed 0.00% while the member row showed 100.00% and the header said N samples. Take a member's extent as the end of its furthest child as well, so the struct counts what was resolved past it. Union members all start at offset 0, so a plain union keeps its size; a member that is itself a struct with a flexible array extends the union too. The TUI browser accounts the members the same way, use the extent there as well. Fixes: aaca646915a1bb53 ("perf annotate-data: Adjust type offset for flex-a= rray") Reviewed-by: Ian Rogers Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/annotate-data.c | 7 +++---- tools/perf/util/annotate-data.c | 27 +++++++++++++++++++++++--- tools/perf/util/annotate-data.h | 8 ++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/tools/perf/ui/browsers/annotate-data.c b/tools/perf/ui/browser= s/annotate-data.c index 0f778788df4a934b..e4047e97e8a943a4 100644 --- a/tools/perf/ui/browsers/annotate-data.c +++ b/tools/perf/ui/browsers/annotate-data.c @@ -53,12 +53,11 @@ static int get_member_overhead(struct annotated_data_ty= pe *adt, struct evsel *leader) { struct annotated_member *member =3D entry->data; - int i, k; + int i, k, end =3D annotated_member__extent(member); =20 - for (i =3D 0; i < member->size; i++) { + for (i =3D member->offset; i < end; i++) { struct type_hist *h; struct evsel *evsel; - int offset =3D member->offset + i; =20 k =3D 0; for_each_group_evsel(evsel, leader) { @@ -69,7 +68,7 @@ static int get_member_overhead(struct annotated_data_type= *adt, continue; =20 h =3D &adt->histograms[evsel->core.idx]; - if (hashmap__find(&h->samples, offset, &hist)) + if (hashmap__find(&h->samples, i, &hist)) update_hist_entry(&entry->hists[k], hist); k++; } diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index 2332d465f9751ef3..c22fec349c47c495 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -2011,7 +2011,7 @@ struct annotated_data_type *find_data_type(struct dat= a_loc_info *dloc) if (result =3D=3D NULL) return NULL; =20 - if (result->flex_array && dloc->type_offset > result->self.size) { + if (result->flex_array && dloc->type_offset >=3D result->self.size) { struct annotated_member *flex_array =3D get_flex_array_member(result); =20 if (flex_array && flex_array->size > 0) { @@ -2208,6 +2208,26 @@ static void print_annotated_data_value(struct type_h= ist *h, u64 period, int nr_s color_fprintf(stdout, color, " %7.2f", percent); } =20 +/* + * A flexible array member is resolved past the end of its parent, so the + * parent's samples are not bounded by its size. A GNU extension non-last + * member with a flexible array can overlap the next member and double-cou= nt. + */ +int annotated_member__extent(struct annotated_member *member) +{ + struct annotated_member *child; + int end =3D member->offset + member->size; + + list_for_each_entry(child, &member->children, node) { + int child_end =3D annotated_member__extent(child); + + if (child_end > end) + end =3D child_end; + } + + return end; +} + static void print_annotated_data_type(struct annotated_data_type *mem_type, struct annotated_member *member, struct evsel *evsel, int indent) @@ -2215,6 +2235,7 @@ static void print_annotated_data_type(struct annotate= d_data_type *mem_type, struct annotated_member *child; struct type_hist *h; int i, nr_events =3D 0, samples =3D 0; + int end =3D annotated_member__extent(member); u64 period =3D 0; int width =3D symbol_conf.show_total_period ? 11 : 7; struct evsel *pos; @@ -2228,10 +2249,10 @@ static void print_annotated_data_type(struct annota= ted_data_type *mem_type, =20 samples =3D 0; period =3D 0; - for (i =3D 0; i < member->size; i++) { + for (i =3D member->offset; i < end; i++) { struct type_hist_entry *entry; =20 - if (!hashmap__find(&h->samples, member->offset + i, &entry)) + if (!hashmap__find(&h->samples, i, &entry)) continue; =20 samples +=3D entry->nr_samples; diff --git a/tools/perf/util/annotate-data.h b/tools/perf/util/annotate-dat= a.h index 184262c7356213fa..6e0d410929651426 100644 --- a/tools/perf/util/annotate-data.h +++ b/tools/perf/util/annotate-data.h @@ -260,6 +260,9 @@ void global_var_type__tree_delete(struct rb_root *root); /* Print data type annotation (including members) on stdout */ int hist_entry__annotate_data_tty(struct hist_entry *he, struct evsel *evs= el); =20 +/* End offset of a member, including a flexible array's children */ +int annotated_member__extent(struct annotated_member *member); + /* Get name of member field at the given offset in the data type */ int annotated_data_type__get_member_name(struct annotated_data_type *adt, char *buf, size_t sz, int member_offset); @@ -316,6 +319,11 @@ static inline int hist_entry__annotate_data_tty(struct= hist_entry *he __maybe_un return -1; } =20 +static inline int annotated_member__extent(struct annotated_member *member) +{ + return member->offset + member->size; +} + static inline int annotated_data_type__get_member_name(struct annotated_da= ta_type *adt __maybe_unused, char *buf __maybe_unused, size_t sz __maybe_unused, --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471258; b=45HvCfEj+xn0jMJJi10irE0GOhn5opzMqR2eWZWwzIZg9+sEv/+QPqKWPQX/A1QI1TNK B26ikC8Xl+vRbYO4uhBcwbg3F+mW0gFsypk4/1jpmw7iv3xcpnDSLBwlI3XU6VFUwCIqi SjyVlJVJa0Yz6YgK/iWGJXCdVK6c6duhz8bBlw+mgMneVUUuj8BtQ0YQPskmaoGgB1fQ2 Y7jNqzdq5t6c5cllqkiUn95HRtHs+9dzIL/HFnwOYZek4nEcTYfKKSNZkjz1K57JkiNKR BIhzVVyYjlTiP2Fa0vaiswPv/E4rmYn13UW6P0tfZnQdz7YOi1WVsD5DsY5ovttP8qQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471258; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=qH7xXsAwU9CECAgj7c7iuRWnGoutWALTqN+OXYtTjXc=; b=gIHdRDj+M91zw8egqPSkbUJgHwvrg97sd7wqDJvs032sN4nCUczDCY3EjZkyg5uoFaci ZqylY2IT7rWif/3E7jNcKTyFbiFb5ODnBcduJFxJdM4NbepQdH4k4pYuUQtoPA/wXgjAw DWEDrhuTU0Rvnj6PcTqiNEU/g2L5BRloW+bTS/6NehtKn92HZ59H/WBDoYy+Q8kndVgcM 3BlgLGmux77ySWl6YXtWrZgr3ujlaMDpukNQ71bgkMPPGzLaxMgSO+j3pHYnoOd0I7hRe dG+GLR+/AQwgJm5L4y+K43Z9AvMGeiprE76uZtGZpQjodLOoI5uWf2/W0xxjaV609jA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oThvgs2E; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A28B8606A332; Mon, 23 Nov 2026 22:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oThvgs2E Received: by smtp.kernel.org (Postfix) with ESMTPSA id C43231F000CA; Mon, 23 Nov 2026 22:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471258; bh=qH7xXsAwU9CECAgj7c7iuRWnGoutWALTqN+OXYtTjXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=oThvgs2EZgV9vQN72S0Y5HNeH0n3rWDWN8sufuLtKQWm0KUWzCBwiyaYNstoWy24U yOQYSF6cnL006rr6NzWXJYPdAanwvxkurGzAoNVrOpzJ7nWSHaI3QQZrIbT+YawQHo wo2JHzhsqZDCLcBHV+UIyvg35qNrJgIfYPE+nb3JtnzfzQtgPkhO7UvhpYLUaDNXdq WAlGXSWM+UCqxSO2jaZYWETB/8+tcX+1EtjG3Ol2P0MuRrEV4EFbBmzLpqcJPvRcsV e7TNWPZkoqgfsvNF9+ihq8tcDCKmQ+YN6A+wDNn/D38syO/tFZvDuZqgFE2+BW0EG4 JuaD02xMy3A8Q== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 08/19] perf test: Exercise the x86 operand parser Date: Mon, 23 Nov 2026 19:00:13 -0300 Message-ID: <20261123220024.14891-9-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo Add a unit test for x86 operand parsing. The 64-bit absolute disp32 and movabs cases are from the allmodconfig clang build in the preceding changes. Also check a 32-bit absolute address, an immediate, and values that should not become absolute addresses. Both objdump spellings of the movabs instruction must yield the KASAN shadow offset. Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/Build | 1 + tools/perf/tests/annotate-ops.c | 172 ++++++++++++++++++++++++++++++++ tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/tests.h | 1 + 4 files changed, 175 insertions(+) create mode 100644 tools/perf/tests/annotate-ops.c diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 5eebb2ec5ddefcfd..c7edd8569bbccb06 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -2,6 +2,7 @@ =20 perf-test-y +=3D builtin-test.o perf-test-y +=3D tests-scripts.o +perf-test-y +=3D annotate-ops.o perf-test-y +=3D parse-events.o perf-test-y +=3D uncore-event-sorting.o perf-test-y +=3D dso-data.o diff --git a/tools/perf/tests/annotate-ops.c b/tools/perf/tests/annotate-op= s.c new file mode 100644 index 0000000000000000..766126fc2e2f5e98 --- /dev/null +++ b/tools/perf/tests/annotate-ops.c @@ -0,0 +1,172 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * The x86 operand parser: what is a memory reference and where it points. + * + * The data type resolver follows absolute memory operands; an immediate + * is not a memory reference. + */ +#include +#include +#include +#include +#include "annotate.h" +#include "debug.h" +#include "dso.h" +#include "disasm.h" +#include "tests.h" + +struct op_case { + const char *insn; + const struct ins_ops *ops; + const char *operand; + bool mem_ref; + int offset; +}; + +static struct op_case op_cases[] =3D { + /* 32-bit absolute, and the 64-bit sign extended disp32 both ways */ + { "mov", &mov_ops, "0x8c73448", true, 0x8c73448 }, + { "mov", &mov_ops, "0xffffffffff5fc300", true, -0xa03d00 }, + { "mov", &mov_ops, "-0xa03d00", true, -0xa03d00 }, + /* An immediate is not a memory reference */ + { "mov", &mov_ops, "$0x10", false, 0 }, + /* Zero and values wider than a disp32 are not absolute addresses. */ + { "mov", &mov_ops, "0x0", false, 0 }, + { "mov", &mov_ops, "0x100000000", false, 0 }, +}; + +static int check_operand(const struct arch *arch, const struct op_case *c, + struct dso *dso64, struct dso *dso32, struct dso *dsorel) +{ + struct disasm_line dl =3D { + .ins =3D { .name =3D c->insn, .ops =3D c->ops }, + }; + struct annotated_insn_loc loc; + struct annotated_op_loc *op; + int ret =3D 0; + + dl.ops.source.raw =3D (char *)c->operand; + + if (annotate_get_insn_location(arch, &dl, &loc) < 0) + return TEST_FAIL; + + op =3D &loc.ops[INSN_OP_SOURCE]; + if (op->mem_ref !=3D c->mem_ref) { + pr_debug("'%s %s': mem_ref %d, expected %d\n", c->insn, + c->operand, op->mem_ref, c->mem_ref); + ret =3D TEST_FAIL; + } + if (op->mem_ref && op->offset !=3D c->offset) { + pr_debug("'%s %s': offset %#x, expected %#x\n", c->insn, + c->operand, op->offset, c->offset); + ret =3D TEST_FAIL; + } + if (c->mem_ref && + (!annotated_op_loc__is_abs(op, dso64) || + !annotated_op_loc__is_abs(op, dso32) || + annotated_op_loc__abs_addr(op, dso64) !=3D (u64)(s64)c->offset || + annotated_op_loc__abs_addr(op, dso32) !=3D (u32)c->offset)) { + pr_debug("'%s %s': wrong absolute address\n", c->insn, c->operand); + ret =3D TEST_FAIL; + } + /* The same operand in a relocatable object is an addend, not an address = */ + if (c->mem_ref && annotated_op_loc__is_abs(op, dsorel)) { + pr_debug("'%s %s': absolute address in a relocatable object\n", + c->insn, c->operand); + ret =3D TEST_FAIL; + } + + return ret; +} + +struct movabs_case { + const char *name; + const char *operand; + s64 imm; +}; + +/* The KASAN shadow offset movabs, as both disassemblers print it */ +static const struct movabs_case movabs_cases[] =3D { + { "movabsq", "$-0x2000040000000000, %r15 # imm =3D 0xDFFFFC0000000000", + -0x2000040000000000LL }, + { "movabs", "$0xdffffc0000000000,%r15", -0x2000040000000000LL }, +}; + +static int check_movabs(const struct arch *arch, const struct movabs_case = *c) +{ + struct disasm_line dl =3D { .ins =3D { .name =3D c->name } }; + struct annotated_insn_loc loc; + int ret =3D TEST_FAIL; + + dl.ops.raw =3D strdup(c->operand); + if (dl.ops.raw =3D=3D NULL) + return TEST_FAIL; + + dl.ins.ops =3D ins__find(arch, c->name, &dl); + if (dl.ins.ops !=3D &mov_ops || dl.ins.ops->parse(arch, &dl.ops, NULL, &d= l) < 0) { + pr_debug("'%s %s': not parsed as a mov\n", c->name, c->operand); + goto out; + } + + /* + * get_dwarf_regnum() is a stub returning -1 when perf is built + * without libdw, the target register cannot be resolved then. + */ +#ifdef HAVE_LIBDW_SUPPORT + if (annotate_get_insn_location(arch, &dl, &loc) =3D=3D 0 && + !loc.ops[INSN_OP_SOURCE].mem_ref && loc.ops[INSN_OP_SOURCE].imm && + loc.ops[INSN_OP_SOURCE].imm_value =3D=3D c->imm && + loc.ops[INSN_OP_TARGET].reg1 !=3D -1) +#else + if (annotate_get_insn_location(arch, &dl, &loc) =3D=3D 0 && + !loc.ops[INSN_OP_SOURCE].mem_ref && loc.ops[INSN_OP_SOURCE].imm && + loc.ops[INSN_OP_SOURCE].imm_value =3D=3D c->imm) +#endif + ret =3D TEST_OK; + else + pr_debug("'%s %s': not an immediate to a register\n", + c->name, c->operand); +out: + free(dl.ops.source.raw); + free(dl.ops.target.raw); + free(dl.ops.raw); + return ret; +} + +static int test__annotate_ops(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + struct e_machine_and_e_flags id =3D { .e_machine =3D EM_X86_64, }; + const struct arch *arch =3D arch__new_x86(&id, NULL); + struct dso *dso64 =3D dso__new("annotate-ops-64"); + struct dso *dso32 =3D dso__new("annotate-ops-32"); + struct dso *dsorel =3D dso__new("annotate-ops-rel"); + size_t i; + int ret =3D 0; + + if (arch =3D=3D NULL || dso64 =3D=3D NULL || dso32 =3D=3D NULL || dsorel = =3D=3D NULL) { + dso__put(dso64); + dso__put(dso32); + dso__put(dsorel); + free((void *)arch); + return TEST_FAIL; + } + + dso__set_is_64_bit(dso64, true); + dso__set_is_64_bit(dso32, false); + dso__set_rel(dsorel, ET_REL); + + for (i =3D 0; i < ARRAY_SIZE(op_cases); i++) + ret |=3D check_operand(arch, &op_cases[i], dso64, dso32, dsorel); + + for (i =3D 0; i < ARRAY_SIZE(movabs_cases); i++) + ret |=3D check_movabs(arch, &movabs_cases[i]); + + dso__put(dso64); + dso__put(dso32); + dso__put(dsorel); + free((void *)arch); + return ret; +} + +DEFINE_SUITE("Annotate operand parsing", annotate_ops); diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index 01c78ef20b97dec9..a27baf3a819ccf36 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -117,6 +117,7 @@ static struct test_suite *generic_tests[] =3D { &suite__openat_syscall_event_on_all_cpus, &suite__basic_mmap, &suite__mem, + &suite__annotate_ops, &suite__parse_events, &suite__uncore_event_sorting, &suite__expr, diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index af822885890dda73..963cb34acd345153 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -153,6 +153,7 @@ DECLARE_SUITE(sample_parsing); DECLARE_SUITE(keep_tracking); DECLARE_SUITE(parse_no_sample_id_all); DECLARE_SUITE(dwarf_unwind); +DECLARE_SUITE(annotate_ops); DECLARE_SUITE(expr); DECLARE_SUITE(hists_filter); DECLARE_SUITE(mmap_thread_lookup); --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471261; b=zThDMAtLtVuiIj8wquRn/MEe++09I+kYQ3h2xOaMLikJ4xKbundKewQvHLyNf8UPsZCJ moT8bjbPB8qQonqHjb5p7bXTS1kQjj8mv3RNmYVjlog1rcNNZKvnO1JfvRhB2O9D5Kuhq wDD6OpObGfTRiMckwnlaR/Hj/NfcppUbp2X7JVjs9n7L3LRvWLSl8qf7VQAYargViNDiC BlwbhBZxzdWd+8k8w5U0ozso+35L4gnbhW9aG6ZXdRdqsyE835Km7Jw5Dw2JEQcc2/xBl U9A8Cl2ZUJqx33d3Dk7wbuBw9HjnZzwuxSDjVFsA8Rkw63hh1LRhwYkvblbu8de0NyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471261; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=SAptmRo7VFZs3YBboXIuiBByYjCRlZPrUdwklrfyjD0=; b=zsW7R0CeMs8RRBD75zDhFjvnYh0aM7izLUkeligpBjLmqjcvckMQQlFFi08vObakdI6t macJYAGr/HKH1m/ciH7eAzeu5qIepkh9joYCZKd38niemyVkI0tecAuaUj6EMRZrVNbBW 1BoKvu6sLNpWpAp891ynhZZvKNEi1Rc1itb4cyvTrOFbGRCNWrIc3C+4YqSpNWrkj5pze QiBd/parW5syLTZsCtM9EPTXK2fA0sU6hRmmFBibfGme02rpFDGOr5NgVANos8rBftF8/ hjoc53vKsgxJI3Ely4tMsER7O89cbfUTcGAXScHhpXTyeHs9+6fimZH1N2Jc71GGX4g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hf5QoDnF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBC1B606A31E; Mon, 23 Nov 2026 22:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hf5QoDnF Received: by smtp.kernel.org (Postfix) with ESMTPSA id F34021F000C4; Mon, 23 Nov 2026 22:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471261; bh=SAptmRo7VFZs3YBboXIuiBByYjCRlZPrUdwklrfyjD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hf5QoDnFHatZHi92Wvu33sdDkJhxBHIHZUQMWmhDPImgULFPV6Pj+N9x67rGF6sk/ P0jdQupCMTWIP2jLp/bwM0fKdxQHWTRCNUc2doizP9kIGseWzoynbxT0Qousl3Aqx4 HNAZdMnzYfq3GmEUQ+q85dJOYmtww8ei5b3aHRstDPYoDj6hGrcz/6BulPrJyiLCjG xM+48Bnq0P6NN6AQ5VACAhyp/nQpuPXHZcKMM8d2OBLVDnJTMp6ViIhkj49aMUxEJm coh+60Q+mBQNsaYgDzBzAUJ17F7GAtabt976g8Ghn3pfBzoKED4bKz3Sykh4cJP6CO m+u9/HQ14nc7w== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 09/19] perf test: Exercise DW_OP_addrx global variables Date: Mon, 23 Nov 2026 19:00:14 -0300 Message-ID: <20261123220024.14891-10-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo clang emits DW_AT_location with DW_OP_addrx for globals in DWARF 5, gcc emits DW_OP_addr. The global_data workload keeps a zero initialized struct in .bss: at run time it sits past the file backed mapping, where the by-name fallback through the thread maps cannot find it, so only the DWARF address lookup resolves it. The test checks that its three member accesses are annotated, so the DW_OP_addrx path is exercised when perf is built with clang and DWARF 5 (e.g. scripts/coverage.sh with DWARF_VERSION=3D5), and the DW_OP_addr one with gcc. It skips on 32-bit PIE builds, which reach static globals relative to the GOT base register, and the resolver does not track that. Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/shell/data_type_global.sh | 73 ++++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/tests/workloads/Build | 2 + tools/perf/tests/workloads/global_data.c | 57 +++++++++++++++++ 5 files changed, 134 insertions(+) create mode 100755 tools/perf/tests/shell/data_type_global.sh create mode 100644 tools/perf/tests/workloads/global_data.c diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index a27baf3a819ccf36..42e85d1b1420f0a7 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -214,6 +214,7 @@ static struct test_workload *workloads[] =3D { &workload__deterministic, &workload__callchain, &workload__false_sharing, + &workload__global_data, =20 #ifdef HAVE_RUST_SUPPORT &workload__code_with_type, diff --git a/tools/perf/tests/shell/data_type_global.sh b/tools/perf/tests/= shell/data_type_global.sh new file mode 100755 index 0000000000000000..14f57d5a1b26a5ea --- /dev/null +++ b/tools/perf/tests/shell/data_type_global.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# perf data type profiling test for a global variable +# SPDX-License-Identifier: GPL-2.0 + +set -e + +perfdata=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX) +perfout=3D$(mktemp /tmp/__perf_test.perf.out.XXXXX) +perferr=3D$(mktemp /tmp/__perf_test.perf.err.XXXXX) + +cleanup() +{ + rm -f "$perfdata" "$perfout" "$perferr" + trap - EXIT TERM INT +} + +trap_cleanup() +{ + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +if ! perf check feature -q dwarf; then + echo "Skip: no DWARF (libdw) support" + cleanup + exit 2 +fi + +# 32-bit x86 PIE reaches static globals relative to the GOT base register, +# which the resolver does not track; e_type's low byte is at 16 on LE x86. +perf_bin=3D$(command -v perf) +if [ "$(od -An -tx1 -j4 -N1 "$perf_bin" | tr -d ' ')" =3D 01 ] && + [ "$(od -An -tx1 -j16 -N1 "$perf_bin" | tr -d ' ')" =3D 03 ]; then + echo "Skip: 32-bit PIE uses GOT-relative global accesses" + cleanup + exit 2 +fi + +# No point in recording if the PMU cannot do memory events. +if ! perf mem record -o /dev/null -- true 2>/dev/null; then + echo "Skip: cannot record memory events on this PMU" + cleanup + exit 2 +fi + +if ! perf mem record -o "$perfdata" -- perf test -w global_data 1 \ + > /dev/null 2> "$perferr"; then + echo "FAIL: perf mem record" + cat "$perferr" + cleanup + exit 1 +fi + +if ! perf annotate --code-with-type -i "$perfdata" --stdio \ + --percent-limit 1 > "$perfout"; then + echo "FAIL: perf annotate" + cleanup + exit 1 +fi + +for member in "+0 (saddr)" "+0x4 (daddr)" "+0x8 (bytes)"; do + if ! grep -Fq "# data-type: struct conn ${member}" "$perfout"; then + echo "FAIL: member ${member} not resolved" + grep 'struct conn' "$perfout" || true + cleanup + exit 1 + fi +done + +echo "global variable resolved" +cleanup diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 963cb34acd345153..63d49a960eab8f3c 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -274,6 +274,7 @@ DECLARE_WORKLOAD(context_switch_loop); DECLARE_WORKLOAD(deterministic); DECLARE_WORKLOAD(callchain); DECLARE_WORKLOAD(false_sharing); +DECLARE_WORKLOAD(global_data); =20 #ifdef HAVE_RUST_SUPPORT DECLARE_WORKLOAD(code_with_type); diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/= Build index 43cc4da6fb0786de..03017aaaaa0bec32 100644 --- a/tools/perf/tests/workloads/Build +++ b/tools/perf/tests/workloads/Build @@ -17,6 +17,7 @@ perf-test-y +=3D context_switch_loop.o perf-test-y +=3D deterministic.o perf-test-y +=3D callchain.o perf-test-y +=3D false_sharing.o +perf-test-y +=3D global_data.o =20 ifeq ($(CONFIG_RUST_SUPPORT),y) perf-test-y +=3D code_with_type.o @@ -35,3 +36,4 @@ CFLAGS_deterministic.o =3D -g -O0 -fno-inline -U_FORTI= FY_SOURCE CFLAGS_named_threads.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_callchain.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_false_sharing.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE +CFLAGS_global_data.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE diff --git a/tools/perf/tests/workloads/global_data.c b/tools/perf/tests/wo= rkloads/global_data.c new file mode 100644 index 0000000000000000..5973f7bb16fd007c --- /dev/null +++ b/tools/perf/tests/workloads/global_data.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * A zero initialized global struct, so it lands in .bss, past the file + * backed end of the last segment: at run time it sits in an anonymous + * mapping that the thread maps do not name, so only the DWARF address + * lookup finds it. clang describes its address with DW_OP_addrx in + * DWARF 5, gcc with DW_OP_addr. + * + * 'perf mem record' of this workload followed by 'perf annotate + * --code-with-type' (see tests/shell/data_type_global.sh) resolves the + * accesses to struct conn. + */ +#include +#include +#include +#include +#include "../tests.h" + +struct conn { + int saddr; + int daddr; + long bytes; +}; + +static volatile struct conn conn; +static volatile unsigned long conn_sink; +static volatile sig_atomic_t done; + +static void sighandler(int sig __maybe_unused) +{ + done =3D 1; +} + +static int global_data(int argc, const char **argv) +{ + unsigned long sum =3D 0; + unsigned int i =3D 0; + int sec =3D 1; + + if (argc > 0) + sec =3D atoi(argv[0]); + + signal(SIGINT, sighandler); + signal(SIGALRM, sighandler); + alarm(sec); + + while (!done) { + conn.saddr =3D i; + conn.daddr =3D i + 1; + sum +=3D conn.bytes; + i++; + } + conn_sink =3D sum; + return 0; +} + +DEFINE_WORKLOAD(global_data); --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471265; b=UEB+QmFNaw0nuSGxSBJs+SXypdicgQeH2jRs30S0zUgv26mV9Pl9M0Zul3szGYe0iUz9 u6sRPEfcAQTCGH56z6JgVXcaGRg4RtQxAc5lbuXwPuDk48RfCfsfTMHA9hnsfDiFT811p PpObxGWclUqUSqKb2n8NfywP7V5A54Fe/n02juUtcB/EWlwbD1/NvhHAJwggFa5VwXAQS 5C76WyxGwY3E++dd//hEA6F8sCZdNbRs7PB2/0bV8mOdGEGdRLXC6jnPMFNV+IpkMQUzR /8DqFw+ldL+FLUZENBWohnLytFxTRqZW7tnrhvoftQADoDiCpsj7z21bk0bRhdy7rlg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471265; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=87H2n7vnNz1VvHwbmKk8yzjCiBhIlsUzmV0ldIMU8As=; b=jznqiX6q2a3Eiu+V4/Z11KnyV0SVFXvqtLgq2oMM+zMyqjoIJVBx/IuJerk7SoKCu4/d CalHY5O4iVXfH5qlwlWcfI0xXRdMe/YEvreS1NVAFymATohHTF1P2lSHfQgu1atJQ57CT f6BQLHZn+wyIZgm2sJWZ3J9T9ulfTlm7OZuH/UROsEJgwX2cs379T+ueyiVLKTfqWgTTL ZMNBeTqnGQDLI2LXjh97Pfq4THf/UflirdkwLxT5ix776s57RjFgHOpY2CyYXoIy8ebae 7vcpwTkhRV0vbW5l9Go8+HTgM5O7zrEIFOoIjKzOWtkdd0PuEYol9OXMSkNZnXjvu0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eLZ9Wesz; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5548E606A321; Mon, 23 Nov 2026 22:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=eLZ9Wesz Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30F051F000C4; Mon, 23 Nov 2026 22:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471264; bh=87H2n7vnNz1VvHwbmKk8yzjCiBhIlsUzmV0ldIMU8As=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eLZ9WeszAR/JX5IQGZPS7Ol1nEXLXfguKtjBmqwzOoNabGENqaN1mc1RaZ2ps8LPv Z30nYOzCOC4hLzhKSsAp/i/DA46+qIN+oBr1ofNblgk65LGJlSjF/uZcWdqcrAXVMG 5BHAKp9iw+rwN6t4TAh00UhEDDWcktfNxpUUZkf0Dupyjy2GdxJ5gXtfaanF3bh/Sq V/TKsru7doSLLdbBnRhiID5Oi7h2LtXwss18S9E5lL0KLVrCVFkTC+dLQyCKnpE38O bbuEdBSpkm7p6ajx/iSDTeEzdghQ9evGhVt2NsTSBymvumnd3Vm7XpFkTaMTIsvz4y VYF/IFviJCYSg== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 10/19] perf test: Exercise the flexible array member path Date: Mon, 23 Nov 2026 19:00:15 -0300 Message-ID: <20261123220024.14891-11-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo No test covered find_flex_array() and get_flex_array_member(). Add a flex_array workload that keeps structs with trailing data[] members behind global pointers, and a test that checks accesses at and past the struct size are resolved and named after the flexible array member; find_data_type() folds offsets past the struct modulo the element size back to the member's offset (+0x4 for char data[] and +0xc for the padded int data[]). The test also checks that the accesses count for the struct in the percent, samples and period columns. It skips on 32-bit PIE builds, which reach static globals relative to the GOT base register. Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/builtin-test.c | 1 + .../perf/tests/shell/data_type_flex_array.sh | 135 ++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/tests/workloads/Build | 2 + tools/perf/tests/workloads/flex_array.c | 71 +++++++++ 5 files changed, 210 insertions(+) create mode 100755 tools/perf/tests/shell/data_type_flex_array.sh create mode 100644 tools/perf/tests/workloads/flex_array.c diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index 42e85d1b1420f0a7..d761758201a4b2f2 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -215,6 +215,7 @@ static struct test_workload *workloads[] =3D { &workload__callchain, &workload__false_sharing, &workload__global_data, + &workload__flex_array, =20 #ifdef HAVE_RUST_SUPPORT &workload__code_with_type, diff --git a/tools/perf/tests/shell/data_type_flex_array.sh b/tools/perf/te= sts/shell/data_type_flex_array.sh new file mode 100755 index 0000000000000000..0fb82618dc00f854 --- /dev/null +++ b/tools/perf/tests/shell/data_type_flex_array.sh @@ -0,0 +1,135 @@ +#!/bin/bash +# perf data type profiling tests for flexible array members +# SPDX-License-Identifier: GPL-2.0 + +set -e + +perfdata=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX) +perfout=3D$(mktemp /tmp/__perf_test.perf.out.XXXXX) +perferr=3D$(mktemp /tmp/__perf_test.perf.err.XXXXX) + +cleanup() +{ + rm -f "$perfdata" "$perfout" "$perferr" + trap - EXIT TERM INT +} + +trap_cleanup() +{ + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +if ! perf check feature -q dwarf; then + echo "Skip: no DWARF (libdw) support" + cleanup + exit 2 +fi + +# 32-bit x86 PIE reaches static globals relative to the GOT base register, +# which the resolver does not track; e_type's low byte is at 16 on LE x86. +perf_bin=3D$(command -v perf) +if [ "$(od -An -tx1 -j4 -N1 "$perf_bin" | tr -d ' ')" =3D 01 ] && + [ "$(od -An -tx1 -j16 -N1 "$perf_bin" | tr -d ' ')" =3D 03 ]; then + echo "Skip: 32-bit PIE uses GOT-relative global accesses" + cleanup + exit 2 +fi + +# No point in recording if the PMU cannot do memory events. +if ! perf mem record -o /dev/null -- true 2>/dev/null; then + echo "Skip: cannot record memory events on this PMU" + cleanup + exit 2 +fi + +if ! perf mem record -o "$perfdata" -- perf test -w flex_array 1 \ + > /dev/null 2> "$perferr"; then + echo "FAIL: perf mem record" + cat "$perferr" + cleanup + exit 1 +fi + +if ! perf annotate --code-with-type -i "$perfdata" --stdio \ + --percent-limit 1 > "$perfout"; then + echo "FAIL: perf annotate" + cleanup + exit 1 +fi + +if ! grep -Fq "# data-type: struct flex +0x4 (data)" "$perfout"; then + echo "FAIL: flexible array member not resolved" + tail -n 30 "$perfout" + cleanup + exit 1 +fi + +# The accesses to the flexible arrays are resolved at or past the end of +# the struct: they must count for the struct, not only for the member. +if ! perf annotate --data-type -i "$perfdata" --stdio > "$perfout"; then + echo "FAIL: perf annotate --data-type" + cleanup + exit 1 +fi + +if ! awk ' + $1 + 0 =3D=3D 100.00 && /struct flex/ { struct_ok =3D 1 } + $1 + 0 > 0 && /char\[\]/ && /data;/ { data_ok =3D 1 } + END { exit !(struct_ok && data_ok) } +' <(sed -n "/^Annotate type: 'struct flex' in/,/^Annotate type: /p" "$perf= out"); then + echo "FAIL: --data-type does not count the flexible array accesses" + tail -n 30 "$perfout" + cleanup + exit 1 +fi + +if ! awk ' + $1 + 0 =3D=3D 100.00 && /struct flex_pad/ { struct_ok =3D 1 } + $1 + 0 > 0 && /int\[\]/ && /data;/ { data_ok =3D 1 } + END { exit !(struct_ok && data_ok) } +' <(sed -n "/^Annotate type: 'struct flex_pad' in/,/^Annotate type: /p" "$= perfout"); then + echo "FAIL: --data-type does not count the padded flexible array accesses" + tail -n 30 "$perfout" + cleanup + exit 1 +fi + +# Same with the samples and period columns, the other two display modes. +for mode in --show-nr-samples --show-total-period; do + if ! perf annotate --data-type -i "$perfdata" --stdio "$mode" > "$perfout= "; then + echo "FAIL: perf annotate --data-type $mode" + cleanup + exit 1 + fi + + if ! awk ' + $1 + 0 > 0 && /struct flex/ { total =3D $1 + 0 } + /int/ && /len;/ { len =3D $1 + 0 } + /char\[\]/ && /data;/ { data =3D $1 + 0 } + END { exit !(total > 0 && data > 0 && total =3D=3D data + len) } + ' <(sed -n "/^Annotate type: 'struct flex' in/,/^Annotate type: /p" "$per= fout"); then + echo "FAIL: --data-type $mode does not count the flexible array accesses" + tail -n 30 "$perfout" + cleanup + exit 1 + fi + + if ! awk ' + $1 + 0 > 0 && /struct flex_pad/ { total =3D $1 + 0 } + /long/ && /x;/ { x =3D $1 + 0 } + /int/ && /len;/ { len =3D $1 + 0 } + /int\[\]/ && /data;/ { data =3D $1 + 0 } + END { exit !(total > 0 && data > 0 && total =3D=3D data + len + x) } + ' <(sed -n "/^Annotate type: 'struct flex_pad' in/,/^Annotate type: /p" "= $perfout"); then + echo "FAIL: --data-type $mode does not count the padded flexible array a= ccesses" + tail -n 30 "$perfout" + cleanup + exit 1 + fi +done + +echo "flexible array member resolved and counted" +cleanup diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 63d49a960eab8f3c..8621ea345b5f06ff 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -275,6 +275,7 @@ DECLARE_WORKLOAD(deterministic); DECLARE_WORKLOAD(callchain); DECLARE_WORKLOAD(false_sharing); DECLARE_WORKLOAD(global_data); +DECLARE_WORKLOAD(flex_array); =20 #ifdef HAVE_RUST_SUPPORT DECLARE_WORKLOAD(code_with_type); diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/= Build index 03017aaaaa0bec32..74a0cbe49dc93533 100644 --- a/tools/perf/tests/workloads/Build +++ b/tools/perf/tests/workloads/Build @@ -18,6 +18,7 @@ perf-test-y +=3D deterministic.o perf-test-y +=3D callchain.o perf-test-y +=3D false_sharing.o perf-test-y +=3D global_data.o +perf-test-y +=3D flex_array.o =20 ifeq ($(CONFIG_RUST_SUPPORT),y) perf-test-y +=3D code_with_type.o @@ -37,3 +38,4 @@ CFLAGS_named_threads.o =3D -g -O0 -fno-inline -U_FORTI= FY_SOURCE CFLAGS_callchain.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_false_sharing.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_global_data.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE +CFLAGS_flex_array.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE diff --git a/tools/perf/tests/workloads/flex_array.c b/tools/perf/tests/wor= kloads/flex_array.c new file mode 100644 index 0000000000000000..cc15e8cac157c337 --- /dev/null +++ b/tools/perf/tests/workloads/flex_array.c @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Flexible array member workload for data type profiling: the accesses to + * the arrays are at or past the end of their structs, where the resolver + * has to find the flexible array members. + * + * See tests/shell/data_type_flex_array.sh. + */ +#include +#include +#include +#include +#include "../tests.h" + +struct flex { + int len; + char data[]; +}; + +struct flex_pad { + long x; + int len; + int data[]; +}; + +static struct flex *gp; +static struct flex_pad *gpp; +static volatile unsigned long flex_sink; +static volatile sig_atomic_t done; + +static void sighandler(int sig __maybe_unused) +{ + done =3D 1; +} + +static int flex_array(int argc, const char **argv) +{ + unsigned long sum =3D 0; + int sec =3D 1; + + if (argc > 0) + sec =3D atoi(argv[0]); + + gp =3D calloc(1, sizeof(*gp) + 4096); + gpp =3D calloc(1, sizeof(*gpp) + 4096); + if (gp =3D=3D NULL || gpp =3D=3D NULL) { + free(gp); + free(gpp); + return 1; + } + gp->len =3D 4096; + gpp->x =3D 1; + gpp->len =3D 4096; + + signal(SIGINT, sighandler); + signal(SIGALRM, sighandler); + alarm(sec); + + while (!done) { + sum +=3D gp->data[3]; + gp->data[5] =3D 1; + sum +=3D gpp->data[1]; + gpp->data[2] =3D 1; + } + flex_sink =3D sum; + free(gp); + free(gpp); + return 0; +} + +DEFINE_WORKLOAD(flex_array); --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471268; b=atPM0UvxTMQz0rtp5Pag8QwSLt7OALM7VSjpMIDtJQ4VWxhs1ClO6Y7PIGIKv7xt7gFh OIc0L65W+i9e8f0vAAaKSWaS+Bqyu9Ed18VRzd9WCaKbDkeGPUazNFGkXDH6OxHtsNxJQ bs5GbDzWsLN3JgsXQsreocOxulfwWRYEttqYx58/rP8TP8JILZ/h8OBJQiFOWiI7Z5zFd /XikrLCb5u/wZiBQB04tnH5jKl24IGmzL0lWV/hSKoXOfsZQfp7Mjc0gAqCZe5j9sfqMu LZQIvdLKlB7tEOVosGfUxBgXUBLnuQXJsbmyoa4816ZdUtFQvPq2VOMqvlfwkjYwKIg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471268; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=aNowa5HbhL+W8dMCJ10dFLhGp6iuE6rrTmju3Z9f6Nw=; b=lkByBJX7woi4R/XC2XL6Zbd6b/UXuJR3n/L7jeaeHorKfNwkUnO7UWmwLSaC5KL923EE W41kWfBTvZCfTDsZVM4N4WTrWycctz5k7Iv4MzzHzmGkC7SNkmyis/QF6vNrsshbetLkc 3hvAcRCoBFmyLscQPL4yTL89RayeJ1B/wuB+HRQQtImp2vf0jARz+eN97Z01Qh4fZlH1p nHUCgE157u8VnHpd2c2RszMPAitUwE56loZvEDhOCT85RROQRXhFv5KHKaiZmRCDKQFHF Nx4QfA9H4kYQU0cflsCwNmJkYgX1wpkQk3L48dKlY04eJfJDIO2GNHqXi4hb8rCFE4w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Vnwh0MkW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F0A3606A321; Mon, 23 Nov 2026 22:01:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Vnwh0MkW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 623461F000EB; Mon, 23 Nov 2026 22:01:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471268; bh=aNowa5HbhL+W8dMCJ10dFLhGp6iuE6rrTmju3Z9f6Nw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Vnwh0MkW07aRnSf284WW6diynCCtsBzWOzJ1p+TLwRk+Cnz7A7/ib694KIpwWpQNf 7gR52Wulx+LyAIS+HGur6QizSpEFDCyji5m4+yRnY6m15+xCUerCale8KyrlGLLtQP NZb8tf7tWA79zAlgHtde85soMZ1Zc5knIDm05/GFxfVA0OsWwRuHVN0UI6ZJLorJRZ UQpAsYUoHAIlWWSVOFnR9OLO/Up2CkT0kTlPjaGWPuA+JMAjQ2/YQlSUIXXgTKyWYj O+UKeTF8PDIxiUWBEobefsLSpl1H8puuZwD8ZxJshGQXemjB5DkutElpZDLhW9uDJv YHy0jw5o4qDSg== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 11/19] perf test: Exercise data type resolution from a register Date: Mon, 23 Nov 2026 19:00:16 -0300 Message-ID: <20261123220024.14891-12-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo At -O2 a struct pointer lives in a register (with DWARF describing it with a register location on register-argument ABIs), while the unoptimized workloads the data type tests profile keep their variables on the stack. Add a regptr workload with a noinline function that takes the pointer from a volatile global, so the compiler cannot constant-propagate the object address, and check that its three member accesses are resolved from that register. The type statistics also verify that the instruction-tracking fallback did not resolve them. The test skips 32-bit x86, which has no register-argument ABI. Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/shell/data_type_register.sh | 86 ++++++++++++++++++++ tools/perf/tests/tests.h | 1 + tools/perf/tests/workloads/Build | 2 + tools/perf/tests/workloads/regptr.c | 60 ++++++++++++++ 5 files changed, 150 insertions(+) create mode 100755 tools/perf/tests/shell/data_type_register.sh create mode 100644 tools/perf/tests/workloads/regptr.c diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index d761758201a4b2f2..29068963b9d5bae0 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -216,6 +216,7 @@ static struct test_workload *workloads[] =3D { &workload__false_sharing, &workload__global_data, &workload__flex_array, + &workload__regptr, =20 #ifdef HAVE_RUST_SUPPORT &workload__code_with_type, diff --git a/tools/perf/tests/shell/data_type_register.sh b/tools/perf/test= s/shell/data_type_register.sh new file mode 100755 index 0000000000000000..a36e4ce8f37d3982 --- /dev/null +++ b/tools/perf/tests/shell/data_type_register.sh @@ -0,0 +1,86 @@ +#!/bin/bash +# perf data type profiling tests for register variables +# SPDX-License-Identifier: GPL-2.0 + +set -e + +perfdata=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX) +perfout=3D$(mktemp /tmp/__perf_test.perf.out.XXXXX) +perferr=3D$(mktemp /tmp/__perf_test.perf.err.XXXXX) + +cleanup() +{ + rm -f "$perfdata" "$perfout" "$perferr" + trap - EXIT TERM INT +} + +trap_cleanup() +{ + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +if ! perf check feature -q dwarf; then + echo "Skip: no DWARF (libdw) support" + cleanup + exit 2 +fi + +# 32-bit x86 passes the struct pointer in a stack slot, so nothing is +# resolved from a register; e_machine's low byte is at 18 on LE x86. +perf_bin=3D$(command -v perf) +if [ "$(od -An -tx1 -j18 -N1 "$perf_bin" | tr -d ' ')" =3D 03 ]; then + echo "Skip: 32-bit x86 keeps the argument in a stack slot" + cleanup + exit 2 +fi + +# No point in recording if the PMU cannot do memory events. +if ! perf mem record -o /dev/null -- true 2>/dev/null; then + echo "Skip: cannot record memory events on this PMU" + cleanup + exit 2 +fi + +if ! perf mem record -o "$perfdata" -- perf test -w regptr 1 \ + > /dev/null 2> "$perferr"; then + echo "FAIL: perf mem record" + cat "$perferr" + cleanup + exit 1 +fi + +if ! perf annotate --code-with-type -i "$perfdata" --stdio \ + --percent-limit 1 touch > "$perfout"; then + echo "FAIL: perf annotate" + cleanup + exit 1 +fi + +for member in "+0 (a)" "+0x8 (b)" "+0x10 (c)"; do + if ! grep -Fq "# data-type: struct node ${member}" "$perfout"; then + echo "FAIL: member ${member} not resolved from the register" + grep 'struct node' "$perfout" || true + cleanup + exit 1 + fi +done + +if ! perf annotate --data-type --type-stat -i "$perfdata" --stdio \ + touch > "$perfout"; then + echo "FAIL: perf annotate --data-type --type-stat" + cleanup + exit 1 +fi + +if grep -Eq '^[[:space:]]*[0-9]+ : insn_track$' "$perfout"; then + echo "FAIL: data type resolved by instruction tracking" + tail -n 30 "$perfout" + cleanup + exit 1 +fi + +echo "register held access resolved" +cleanup diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 8621ea345b5f06ff..6bfb30687e12eeb7 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -276,6 +276,7 @@ DECLARE_WORKLOAD(callchain); DECLARE_WORKLOAD(false_sharing); DECLARE_WORKLOAD(global_data); DECLARE_WORKLOAD(flex_array); +DECLARE_WORKLOAD(regptr); =20 #ifdef HAVE_RUST_SUPPORT DECLARE_WORKLOAD(code_with_type); diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/= Build index 74a0cbe49dc93533..17189458032c0a17 100644 --- a/tools/perf/tests/workloads/Build +++ b/tools/perf/tests/workloads/Build @@ -19,6 +19,7 @@ perf-test-y +=3D callchain.o perf-test-y +=3D false_sharing.o perf-test-y +=3D global_data.o perf-test-y +=3D flex_array.o +perf-test-y +=3D regptr.o =20 ifeq ($(CONFIG_RUST_SUPPORT),y) perf-test-y +=3D code_with_type.o @@ -39,3 +40,4 @@ CFLAGS_callchain.o =3D -g -O0 -fno-inline -U_FORTI= FY_SOURCE CFLAGS_false_sharing.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_global_data.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_flex_array.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE +CFLAGS_regptr.o =3D -g -O2 diff --git a/tools/perf/tests/workloads/regptr.c b/tools/perf/tests/workloa= ds/regptr.c new file mode 100644 index 0000000000000000..8c3ab7d316870a3b --- /dev/null +++ b/tools/perf/tests/workloads/regptr.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * A struct pointer that -O2 keeps in a register, so the member accesses + * have to be resolved from its DWARF register location and not from a + * stack slot. + * + * See tests/shell/data_type_register.sh. + */ +#include +#include +#include +#include +#include "../tests.h" + +struct node { + long long a; + long long b; + long long c; +}; + +static struct node node; +static struct node *volatile vp; +static volatile unsigned long long reg_sink; +static volatile sig_atomic_t done; + +static void sighandler(int sig __maybe_unused) +{ + done =3D 1; +} + +static noinline long long touch(struct node *p) +{ + long long sum =3D 0; + + sum +=3D p->a; + p->b +=3D sum; + sum +=3D p->c; + return sum; +} + +static int regptr(int argc, const char **argv) +{ + unsigned long long sum =3D 0; + int sec =3D 1; + + if (argc > 0) + sec =3D atoi(argv[0]); + + vp =3D &node; + signal(SIGINT, sighandler); + signal(SIGALRM, sighandler); + alarm(sec); + + while (!done) + sum +=3D touch(vp); + reg_sink =3D sum; + return 0; +} + +DEFINE_WORKLOAD(regptr); --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471271; b=qpCMWwmh+xUKMs8AsRK58F+Ib6hgeNt6lIK2nemWjE08sFmjU1HwnvdnnhW7QEjJqDWh QvCHOrngmqePkOh++CXOk02E0QAncVnRFJLm2eTDwoNNHR7uAJNdV5mrJKBqn7HUkOoRR VsLAGyd/LzLU592BmgPgylWP5SYIk9vThhs/dPeTbAYEM9dUUnl3t84+3UfuZyR5jHsBf yXcaZTGbkKctmw3oNKvrAvJTa7zy8wz5yB0Goa6CK+P5hoTXYq7FSQlfLBFUJBIDrieVX EI16zvhTRCktsnyqyaR7p0J14oydfDKh2Z+bUpvimWm+KyKD7iwMDu9uBcumFYhbHyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471271; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=1j8VXhTVKIF04Lq/RG5Pb16hiru/FP0yKgb9wxd0Glg=; b=TlmBHrp5a/BDQZbxhJjwdwgQ34HixXhI41SoFMWTKmwiK1etDN9NOAXfY6VrQiElG5G0 9RQa+2PPJpiEdBVvzDYOzjKagl9ZjpyqR0Ic6SvDsY7CtUTB2sraLDs4uSJxp6FoxIA28 +zQQ4xgGwdCWLK9keSk/jq0r+2Pw2sbNEi50ONzvs7d8qIiMVgdMPxX+GFNxZFr5ulFfn Y8rNRBkXtYOz4/H99rgK1lcZuumpIuH3MoqXNjpIZVp8bBVhG4E37Dd2lxcDATKykXqlz ZKioguVT2NSh/m6cJCE3M1IYfM1up1ORc0gIZUb+Mzjya0UVrIrHm+fCitz24Lrdpzw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KjfpFLv4; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8264D606A327; Mon, 23 Nov 2026 22:01:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=KjfpFLv4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91E0E1F000CF; Mon, 23 Nov 2026 22:01:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471271; bh=1j8VXhTVKIF04Lq/RG5Pb16hiru/FP0yKgb9wxd0Glg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KjfpFLv402VtFNT81MNjRYjMu+DLccbsyF1GEjRMbSFHUaE0mD0uJF7ZVaKoOSY3z 2aKfdHrpL665ht9SAovrPCEj5Dy8ACHgT+gqyu9ABIIbNnG/zkTTfJmUdDoL+k1HmC oeYfc852cxz4IZgA7tUMOvi+g76cIyZ1ge4NxdnJQtGT0Pu1auKSBCzzNqMNXpzU/h 6ayvvccbYgFRfHfehtRCVtuAITMGlSjliuvC/6wnoZDoSX9TrxmTng7OprslqbCRXG jl5yPNevC9+i5HQ4+9HO4TCPGl3YZJ40kL1q2KYp4W5bsIl+74XSX6TbtKEuzBHKRi iTPRbxcA0kpNw== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 12/19] perf test: Exercise the annotate stats output Date: Mon, 23 Nov 2026 19:00:17 -0300 Message-ID: <20261123220024.14891-13-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo Add a shell test for the --insn-stat and --type-stat output printed once, after the annotations, and for the warning when --type-stat is used without --data-type. The instruction stats run with one and with two events and are checked against the per-instruction rows, so a total that counts only the first event, or does not match the rows, fails; the data type total is checked against its counters. A repeated section also fails. Operand extraction is implemented only for x86, arm64 and powerpc, so other architectures skip rather than fail on the zero totals it would leave. The bad counters check compares numerically: when every access resolves no counter line is printed, and awks that follow POSIX would then compare "0" to the unset sum as strings. Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/shell/annotate_stats.sh | 184 +++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100755 tools/perf/tests/shell/annotate_stats.sh diff --git a/tools/perf/tests/shell/annotate_stats.sh b/tools/perf/tests/sh= ell/annotate_stats.sh new file mode 100755 index 0000000000000000..656a4c510a8d890f --- /dev/null +++ b/tools/perf/tests/shell/annotate_stats.sh @@ -0,0 +1,184 @@ +#!/bin/bash +# perf annotate instruction stats test +# SPDX-License-Identifier: GPL-2.0 + +set -e + +shelldir=3D$(dirname "$0") +. "${shelldir}"/lib/perf_has_symbol.sh + +skip_test_missing_symbol datasym + +perfdata=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX) +perfone=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX) +perftwo=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX) +perfout=3D$(mktemp /tmp/__perf_test.perf.out.XXXXX) +perfout2=3D$(mktemp /tmp/__perf_test.perf.out.XXXXX) +perferr=3D$(mktemp /tmp/__perf_test.perf.err.XXXXX) + +cleanup() +{ + rm -f "$perfdata" "$perfone" "$perftwo" "$perfout" "$perfout2" "$perferr" + trap - EXIT TERM INT +} + +trap_cleanup() +{ + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +if ! perf check feature -q dwarf; then + echo "Skip: no DWARF (libdw) support" + cleanup + exit 2 +fi + +# The instruction stats are counted by the data type resolver, whose +# operand extraction is implemented only for x86, arm64 and powerpc; +# elsewhere the totals are zero by design, not because of a bug. +case "$(uname -m)" in + x86_64 | i[3456]86 | aarch64 | ppc64 | ppc64le) ;; + *) + echo "Skip: no instruction operand extraction for $(uname -m)" + cleanup + exit 2 + ;; +esac + +if ! perf record -o "$perfone" -e cpu-clock -- perf test -w datasym \ + > /dev/null 2>&1 || + ! perf record -o "$perftwo" -e cpu-clock -e task-clock -- \ + perf test -w datasym > /dev/null 2>&1; then + echo "FAIL: perf record" + cleanup + exit 1 +fi + +if ! perf annotate --code-with-type --insn-stat -i "$perfone" --stdio \ + --percent-limit 1 datasym > "$perfout"; then + echo "FAIL: perf annotate" + cleanup + exit 1 +fi + +if ! perf annotate --code-with-type --insn-stat -i "$perftwo" --stdio \ + --percent-limit 1 datasym > "$perfout2"; then + echo "FAIL: perf annotate" + cleanup + exit 1 +fi + +# The instruction stats are accounted while the instructions are +# displayed; printing them before the display loop shows zeros. A single +# positive total would also accept a stale first event's total, so check +# that the section is printed once, after the annotations. +if ! awk ' + /^Annotate Instruction stats/ { sections++ } + sections && /^[[:space:]]*[0-9]+\.[0-9]+ : / { late =3D 1 } + END { exit !(sections =3D=3D 1 && !late) } +' "$perfout2"; then + echo "FAIL: instruction stats not printed once after the annotations" + tail -n 30 "$perfout2" + cleanup + exit 1 +fi + +# Each event annotates the same instructions, so the two-event total is +# twice the one-event total. +one_total=3D$(awk '/^total / { t =3D $2; sub(/,/, "", t); print t; exit }'= \ + "$perfout") +two_total=3D$(awk '/^total / { t =3D $2; sub(/,/, "", t); print t; exit }'= \ + "$perfout2") +if [ -z "$one_total" ] || [ -z "$two_total" ] || + [ "$two_total" -le 0 ] || [ "$two_total" -ne $((2 * one_total)) ]; then + echo "FAIL: instruction stats do not count every event" \ + "(one event: ${one_total:-none}, two events: ${two_total:-none})" + tail -n 30 "$perfout2" + cleanup + exit 1 +fi + +# The totals are the sums of the per-instruction rows. +if ! awk ' + /^total / { + t =3D $2; o =3D $4; b =3D $7 + sub(/,/, "", t); sub(/,/, "", o); sub(/,/, "", b) + total =3D t; ok =3D o; bad =3D b; next + } + /^ .*: +[0-9]+ +[0-9]+$/ { good +=3D $(NF - 1); bads +=3D $NF } + END { + exit !(total > 0 && total =3D=3D good + bads && + ok =3D=3D good && bad =3D=3D bads) + } +' "$perfout2"; then + echo "FAIL: instruction stats do not add up" + tail -n 30 "$perfout2" + cleanup + exit 1 +fi + +# No point in recording the data type samples if the PMU cannot do memory +# events. +if ! perf mem record -o /dev/null -- true 2>/dev/null; then + echo "Skip: cannot record memory events on this PMU" + cleanup + exit 2 +fi + +if ! perf mem record -o "$perfdata" -- perf test -w datasym > /dev/null 2>= &1; then + echo "FAIL: perf mem record" + cleanup + exit 1 +fi + +# The data type stats are only printed with --data-type, and must be +# accounted like the instruction stats above. +if ! perf annotate --data-type --type-stat -i "$perfdata" --stdio \ + > "$perfout"; then + echo "FAIL: perf annotate --data-type --type-stat" + cleanup + exit 1 +fi + +if ! awk ' + /^Annotate data type stats:/ { sections++ } + sections && /^Annotate type: / { late =3D 1 } + END { exit !(sections =3D=3D 1 && !late) } +' "$perfout"; then + echo "FAIL: data type stats not printed once after the annotations" + tail -n 30 "$perfout" + cleanup + exit 1 +fi + +# The total is the sum of the bad counters and of the good ones. +if ! awk ' + /^Annotate data type stats:/ { stats =3D 1; next } + !stats { next } + /^total / { + t =3D $2; o =3D $4; b =3D $7 + sub(/,/, "", t); sub(/,/, "", o); sub(/,/, "", b) + total =3D t; ok =3D o; bad =3D b; next + } + /^[[:space:]]*[0-9]+ : / && $3 !=3D "insn_track" { fields +=3D $1 } + END { exit !(total > 0 && total =3D=3D ok + bad && bad + 0 =3D=3D fields = + 0) } +' "$perfout"; then + echo "FAIL: data type stats do not add up" + tail -n 30 "$perfout" + cleanup + exit 1 +fi + +if ! perf annotate --type-stat -i "$perfdata" --stdio > /dev/null 2> "$per= ferr" || + ! grep -Fxq "Warning: --type-stat needs --data-type" "$perferr"; then + echo "FAIL: missing --type-stat warning" + tail -n 30 "$perferr" + cleanup + exit 1 +fi + +echo "instruction stats accounted" +cleanup --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471274; b=ZOWPEpEQgA3AkZd8qtwet0JEQL4UDdqmUQph/j/2IzQFkbQ8qb16tjiiLNGax5rBZquP 3ZE6T4bnExJYijJ2ro2o0M9cw8iA1MjO1Vb1hdYYaD4tlIsm/HMgqabC94vSJ8H/4yDOi VqOhNe33DE3bQTqR8GnjQtqaILXpg3ryB1+I2pWLaypa3jz7N4qRqeDU93s3zXAMVHSQ5 ++xeEDVddKwel+KBiuTVGdBFqfGVieL9nm1vp+c5B8MPnJqEFQPonEPq8gZ01l+7hMA6v fCCc8IQz7J66YDu+RCHgD8sF0bZyyuIo18wgp6OjUgHmcxl7bphT8ZDVIcIlGpq+Nxw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471274; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=KGmUhDDN0UG2rp9CP1JqbUp2tr3lxr0jBQoyS/TZUB4=; b=vGGaWpmtIUaJRGt3QCOYfYXaLb+sGxH6QdhugnD3jbH/GY5b/2qsVKlMebzduUlE8Zdk Kj6l46soOUr/+irUsCM2b0yXrgr2DNjKKwB/hdG9Xb2Rngrp9uIuFhZwlUGHlaC65FdA/ OzfFlI3zAyY/YFPV/spfat+yPTBxLshOLtuJcg8K3gRGCifTXD+M0ynvnHSwmV+lWXc4z UfZxjA9379y5BDuH7faObZWij8/AX3O02qpsZbHfKT53NMaX2w7KLaAE8l7mZbI4veHce /hF7YrXalytqA/ZRUQ/qndds6+lMPJY1yUfwmHDk4mEvVIIMxkrBEVaFAJgkYFv/yRQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B8DaVIG6; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5D5D606A321; Mon, 23 Nov 2026 22:01:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=B8DaVIG6 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0E301F000C0; Mon, 23 Nov 2026 22:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471274; bh=KGmUhDDN0UG2rp9CP1JqbUp2tr3lxr0jBQoyS/TZUB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=B8DaVIG6JB7JNcfGRSFVW469+My0NQDIYm1bmtd/AEsTUeFTcYfogtvVXYAUUk0kG 4O0dW3E03BvKH8KyiVcj8fTAbVbGIPyvyMndysLogMx+sHEeMjVFOfkpLO4ktETeah v4+u9y9UaiV/fTfS8XgIy2IDWolM7QnwqH6loMEgUgBjzhGHxh6ftzF5ni7Jeugqre iQANxM2p7C4PQ1aZZ6VPcocvS+T5k1D7YVzxHSI0lZMOXo3pD0nSzX7w0RmbLJ2X4j CgZYylJOoJUdzU3x7wteZvnT6lmP+gZG1B6PVhhA3q/v+F7Wo1xnQ4P1J7RnJ75yAt UqUzcX9BTwAJA== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 13/19] perf test: Fix the Intel PT virtual LBR check Date: Mon, 23 Nov 2026 19:00:18 -0300 Message-ID: <20261123220024.14891-14-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo On an Intel host the virtual LBR check failed with: Warning: Processed 29 samples and lost 100.00% The record leaves the buffer sizes to the tool defaults: the data ring follows perf_event_mlock_kb, and the runner's small value left a single page, too small for the AUX samples. Pin 4 data and 64 AUX pages, so the test does not depend on the host sysctl, and give the AUX ring room instead of the single page the tool sizes to the 4 KiB snapshot. Both fit in the default mlock allowance regardless of the CPU count. Also require the Python perf module to export session: a perf module without it, like the distro's python3-perf, made the check fail instead of skipping. Fixes: 915d6b14dc0c8971 ("perf test: Migrate Intel PT virtual LBR test to P= ython API") Cc: Adrian Hunter Cc: Ian Rogers Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/shell/test_intel_pt.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/perf/tests/shell/test_intel_pt.sh b/tools/perf/tests/she= ll/test_intel_pt.sh index c0ecece0a8255124..96f5c132cebf23e6 100755 --- a/tools/perf/tests/shell/test_intel_pt.sh +++ b/tools/perf/tests/shell/test_intel_pt.sh @@ -384,13 +384,15 @@ test_virtual_lbr() # shellcheck source=3Dlib/setup_python.sh . "${shelldir}"/lib/setup_python.sh =20 - if ! "$PYTHON" -c 'import perf' > /dev/null 2>&1; then - echo "SKIP: Python perf module not found" + if ! "$PYTHON" -c 'import perf; perf.session' > /dev/null 2>&1; then + echo "SKIP: Python perf module with session support not found" return 2 fi =20 - # Check if virtual lbr is working - perf_record_no_bpf -o "${tmpfile}" --aux-sample \ + # The default data ring follows perf_event_mlock_kb and can be too + # small for the AUX samples; pin 4 data and 64 AUX pages, which fit + # in the default allowance. + perf_record_no_bpf -m 4,64 -o "${tmpfile}" --aux-sample \ -e '{intel_pt//,cycles}:u' perf test -w brstack || return 1 perf inject --itrace=3DL -i "${tmpfile}" -o "${perfdatafile}" || return 1 output=3D$("$PYTHON" "${shelldir}/lib/perf_brstack_max.py" -i "${perfdata= file}") || return 1 --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471278; b=nSydXckiuCXEQwB8Q/sUyqXeGBakc/gwRD2ui5slPF1x6iE1uNxPRW1+xIoFXTjZWi28 k2JBgiS+5913WLHVYO5KCP+x9V/EUgT6GF/I/qp8ZVxaLL5MjE6RGmj81ezcRICKbG0iG veHXnLJsmwwp7PCNLUBR4o2Cq3ITRCr4kl6tZHjPcdfNVgiGWXQP2cUVT1w5tOXiB1kwr X9i1tRMUhIWg/HcYm7KHzumk0P/NgWD1GjJh/lRR2SrDYDZ54gWLE0Nx4QygrtZQw3Pd8 MpoXtumF60qxS/wjWVUnsCccW7bwtDWLfcOBIPmQLNs+t3iIc2xw2CJc5ddkf1GrGQQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471278; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=r9rkywW6iZzLXO5O3QcBEmkBRS6pLSLATvMPp7gmyB8=; b=OpczSqb7m1z57i6EKE2n7Hd0LN+Nxcyj1hqyhb6GcC80IfmECSKdLC5AhDgpPibqOe8X 85dVYKgG/R3ybKJn5XppV7k8nxVIWvbzXUW/ZLz2zxqIzRN57TtIBdhhLEdqQxr5NBs+6 NnoIz5WvrHV09utjzuNwSw4YZQioYHpuGkuwecg30j8SYOuYuTHzAuT4poKWVECtFSsf2 /b39i+VZe5oEX/56rXcfbOyKj55TnI/FcEWSCMyrqWZRo1dh8ckcoii/FdIC7G+pKvA7D 9xhqrkmwy6gnHnaE+LmSEN2kBfaHUxmzDzOmvOfx6Dj7x3Bslo4qlTFUGayZiJA7CuQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U1chD9g+; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05052606A326; Mon, 23 Nov 2026 22:01:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=U1chD9g+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id F09A01F000C4; Mon, 23 Nov 2026 22:01:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471277; bh=r9rkywW6iZzLXO5O3QcBEmkBRS6pLSLATvMPp7gmyB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U1chD9g+O95J7V44dZvWUIs5N8lAx1MpT0wRTwkJ1BITvRtQ706miglZO4GexP2l3 nnIDsL/7dNiaLzWp+CxkKRD4rycIq0Pl/7+xj4gp1s8QBaY2HHueMVhejfAZEpaLCa 5PBJd2KtPdFXhCofaQw8Ct34Ln1QpbUMsKjIn6m3yYac4pBMr9WM0HxwVUMuPysHiG FhrfIFYc37dP0FMGe+ol+0rF7Gj8RQwjgBNlir/mFvjgYKol10+Pvk4rjzFyNMMQLW JCG+5MHdwdJea8+PbbbZXoWyO8Av5n9FTwZ6VWKCfdtjmLBiJqihRYNnwthPhm9suz XsAVx/lErJ/Aw== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 14/19] perf test: Drop samples without an IP in the dlfilter test Date: Mon, 23 Nov 2026 19:00:19 -0300 Message-ID: <20261123220024.14891-15-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo Since v7.3 the kernel zeroes PERF_SAMPLE_IP when a user-only event skids into kernel mode, so that kernel register state is not exposed to user space: commit 166f10836a653dfa ("perf/core: Fix kernel register info leak via hardware skid"). The test records without an event modifier, which is user-only only when perf falls back to cycles:u for an unprivileged user, which is why root runs never saw it. The dlfilter keeps those ip 0 samples, and the check that nothing but test_loop survives then trips on their lines: the comm column reads "perf". Drop them, as everything except test_loop must be filtered out. Fixes: 199d5e872a9ce737 ("perf tests script dlfilter: Add a dlfilter test") Reviewed-by: Ian Rogers Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/shell/script_dlfilter.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/tests/shell/script_dlfilter.sh b/tools/perf/tests/s= hell/script_dlfilter.sh index 88222280f6094fd0..797cd9ae84141f64 100755 --- a/tools/perf/tests/shell/script_dlfilter.sh +++ b/tools/perf/tests/shell/script_dlfilter.sh @@ -46,7 +46,7 @@ int filter_event(void *data, const struct perf_dlfilter_s= ample *sample, void *ct const struct perf_dlfilter_al *al; =20 if (!sample->ip) - return 0; + return 1; =20 al =3D perf_dlfilter_fns.resolve_ip(ctx); if (!al || !al->sym || strcmp(al->sym, "test_loop")) --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471281; b=MvFqAJpHcWknPu9k9xW4WeEI9M0pEBr40HLn1Tcnn0tKbcIz+kHNgMjjk4Ll/rKZARAc dtzJmElMJ7OTYwuWxNh6/tYrgGHNSt0XtTM9p4fk1zXyiYQfQYNtxg0vrpE/jJqhWsSLN cSawuE5aCCUGj2jIu1j6AvMQ1mAy4yBFv0QLJJSgD4GnIYSdXjWpgU6QNDhQ2wNxsN9Sk VTLfYW6ZEmPptUTFHoryKeb5WJTaw3zQZVGUtjAhOYBgZWtD4mbtDw4SX630rI/PD42E3 gingl+rkLEzvgqtZ96SWJbcKRTOlammS2oZaCc5Y8G7nzRsOswsB9aS25trGRTyC4vA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471281; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=salfeQFlmGPsAyKGQjgwjrheD0amYhnaDYI9pSIJYKw=; b=HhwJXuLELoYPAxgU5aD2gOxLrfUyzp04l6JIiMAPZ3L5FVAxL2WXkiWx5RHzEMDHOzHM 92tPkhQy+tS862K2WbJF7Tj5Ne2TcXi/TaaX1TW1nE31i04/YBkr5sVSfnlfjIpRad/cX +gUVorJEBdm8INjqbQU34Hn4HwbIDgvRP4SoauvmUszXQG0VDe52wCice99Vh1F7q9MZt ICQ7hRUXoIGUm7OvT/PIqLj1IESn5t7d1SRdt9GocXeNFOL20RUEgjJ1JSHtyI+W2d5tK edjKY5P/4ZyVBEJmQwuj8ZPNFGt1hsf3G6OlICND7/tZSSBv17wlWxQnjO3z3kOhB6Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GExHF9xx; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 079CA606A31E; Mon, 23 Nov 2026 22:01:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GExHF9xx Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C8AF1F000C4; Mon, 23 Nov 2026 22:01:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471280; bh=salfeQFlmGPsAyKGQjgwjrheD0amYhnaDYI9pSIJYKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GExHF9xxfN8mZTQwssK2mOAMjWXYMLiWa5GBB47lzT1XgdH7uA+qyuGXiUU6M3p83 xO5MSSGdOlD12JpzzkxcCPAW2vCWaS2asjNd9et/P3kqCP6BA2Sagn0GHnJH9ucxU+ DMok9tCpIMX2lXmBwk7v2Tez/6+VO3J/jgmB0r+AYcS2TqQQ0DUTd4ERxcANXtbKRH RSsqNDPMuWhOQrApV2r2gKFzbN349gMa6VXJ4LxLRiVLE+E0xXZU/gkyaeNcsyizOp T/O5cF7IegiinzMBknJI0pYPWbpZv6kjDUpDXxGM33bZEbI5bb8z429oi7vTE8yQRX mz5AtDl9+Razg== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 15/19] perf test: Skip the LBR inline unwinding check when unsupported Date: Mon, 23 Nov 2026 19:00:20 -0300 Message-ID: <20261123220024.14891-16-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo The LBR check takes caps/branches as sufficient to record cycles with --call-graph lbr, but the file only says the PMU has an LBR: AMD LBRv2 rejects the call stack mode with EOPNOTSUPP, so the test fails on AMD instead of skipping. Skip when perf says the branch stack mode is unsupported, so a record that fails for another reason still shows its error and fails the test. Fixes: 446c595dc0dd1759 ("perf test addr2line_inlines: Ensure inline inform= ation shows on LBR leaves") Cc: Ian Rogers Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/shell/addr2line_inlines.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/perf/tests/shell/addr2line_inlines.sh b/tools/perf/tests= /shell/addr2line_inlines.sh index e8754ef2d7f21ac2..02a896c9d99cb2ac 100755 --- a/tools/perf/tests/shell/addr2line_inlines.sh +++ b/tools/perf/tests/shell/addr2line_inlines.sh @@ -8,6 +8,7 @@ err=3D0 test_dir=3D$(mktemp -d /tmp/perf-test-inline-addr2line.XXXXXXXXXX) perf_data=3D"${test_dir}/perf.data" perf_script_txt=3D"${test_dir}/perf_script.txt" +perf_record_err=3D"${test_dir}/perf_record.err" =20 cleanup() { rm -rf "${test_dir}" @@ -71,7 +72,23 @@ test_lbr() { fi =20 # Record data. Currently only dwarf callchains support inlined functio= ns. - perf record --call-graph lbr -e cycles:u -o "${perf_data}" -- perf tes= t -w inlineloop 1 + # caps/branches does not mean the LBR call stack is supported: AMD LBR= v2 + # rejects it with EOPNOTSUPP. Skip only when perf says the branch sta= ck + # mode is unsupported, other record failures still fail the test. + if ! perf record --call-graph lbr -e cycles:u -o "${perf_data}" -- \ + perf test -w inlineloop 1 2> "${perf_record_err}" + then + if grep -q "doesn't support branch stack sampling" "${perf_record_= err}" + then + echo "Skip: LBR call stack not supported by the PMU" + else + cat "${perf_record_err}" + echo "Inline unwinding lbr verification test [Failed to record= ]" + err=3D1 + fi + return + fi + cat "${perf_record_err}" =20 # Check output with inline (default) and srcline perf script -i "${perf_data}" --fields +srcline > "${perf_script_txt}" --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471284; b=x0F0MUGb83+D3qcq1m97r4fqHD7v9JJvP34KmkRels7dlJg/aT+xgcqqW36/d8W1PkhR fEPNMmCFoXx4GaJO/hheWoF3TTuprHJqWB5srfYmuQ873MsR4AXdsgKk0kOZLKKRICvVZ EPG6QjIrZ9syolZbDdSYtQmFFfVHzga2sThIoozStE7m2zAwbr/lS1+x3pSfLsUdQflwe YmWpdsDnFdpthZd194ln9aG4DF+mqH4znEUZIgS8m7QD9ClmqQn2La9s5IlunA+K3TEqG EyqL1jc0kKa4OR3e1sItONd9hJ2IBp/8iZro44fY70sDfNYmDIx1SEmuRLVQ5q/2j4Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471284; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=KZmqBNdphekKEEgxVAXsrHFlb1ohSo5eKZeuG1YGIXE=; b=jObl2oINmUsZNQYgoJfqyX6B950AATeZlb2V5/tHHa+VxviWDtlYlwk/IzyjDgUrZB0b /khAtEw37txJBNQAJ76DVLWvyrMGVihPn3/3wxRTkXVIxjfDJmZrxwvnQuncJ5nhqQ3mc 2AvI1aICOSb2LgEY/ynoDudmJLQPQTwxVREP1DuIAyKO1wTB4RMHAZtT/id2gUdJi1J5p j4uw+Tol7yFGp6M9qMajpLx8QuWT2StEd6GMJTcG+MqjIss84KG0Udo/3+V/5lAGy1qbA KXtoUmqIRDR8efysLinAQZTuYx7rq9JVVvWyPS+0agcQXoGoEcDdfx8umyrKF7R06Hg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QQrFtKp5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E902606A326; Mon, 23 Nov 2026 22:01:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QQrFtKp5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C0BC1F000CA; Mon, 23 Nov 2026 22:01:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471284; bh=KZmqBNdphekKEEgxVAXsrHFlb1ohSo5eKZeuG1YGIXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QQrFtKp5PULW14gobH6LW3LybYYYL4wLR4CbPLEfRuiDo0xAh6H4YRtyOSnGceeKe WilRAPBkKL4i7SXvxngHR3nghtpI2sJOyTKsUYG0mIDGp0rMP9pnh+6PzQ3nmtUdR/ 8zRbPdHg3Wm8kM/+BQLvL0SLpU5DFudgtG4VWK+jvk8okRJHlOhnq41zx/M1LPle39 J+QL+ebx79uOw5pRHAq5dETKv16AwjGuhnzyJvHL0vLTvDXZthObm0Yf68mujwmbuY LwfkiVn2jbjrzhIir3yoPqiLWbd5Y5rbMno0aHPkJlchhyezFTBK2VbGO0gR/MJaoo dhLiI1DOxJ2Dg== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 16/19] perf test: Skip the trace summary BPF tests without kernel BTF Date: Mon, 23 Nov 2026 19:00:21 -0300 Message-ID: <20261123220024.14891-17-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo The --bpf-summary tests need BTF in the running kernel; perf check feature bpf only tells whether perf was built with libbpf. Without CONFIG_DEBUG_INFO_BTF the skeleton fails to load and the test fails instead of skipping. The /sys/kernel/btf/vmlinux file indicates that the running kernel has BTF available for the tp_btf programs. Do not use an on-disk vmlinux image for this check: it can be readable even when the running kernel has no BTF loaded. Fixes: 2d099ccaadf623d3 ("perf test: Add perf trace summary test") Cc: Ian Rogers Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/shell/trace_summary.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/perf/tests/shell/trace_summary.sh b/tools/perf/tests/she= ll/trace_summary.sh index 0e603addb2a99d4d..154f85f16e6528f9 100755 --- a/tools/perf/tests/shell/trace_summary.sh +++ b/tools/perf/tests/shell/trace_summary.sh @@ -63,6 +63,15 @@ if ! perf check feature -q bpf; then exit 2 fi =20 +# The tp_btf programs need BTF in the running kernel. A vmlinux image +# on disk is not sufficient: it can be readable even when the kernel has +# no BTF loaded. +if [ ! -r /sys/kernel/btf/vmlinux ]; then + echo "Skip --bpf-summary tests as kernel BTF is missing" + rm -f ${OUTPUT} + exit 2 +fi + # summary only for system wide - per-thread summary with BPF test_perf_trace "-as --summary-mode=3Dthread --bpf-summary" =20 --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471287; b=sAtNOQTV7o6PZLAEqshJIzb1Wxt34iqfD8ue3Upw8oh1bvFGGFZviZcomJvgLCLri53f 3xwYwcypsO4BOhzHBLBi4UdNMEVY0BHGvK2/2XVFBsSptNpGqyz1sLxMm/zAzrvQzf1BS /b7Iu1QXC9bXWYE6y5pcmnxYJZb9Q+eXG0+Q6elqzNHEUEbR85H7AXsqDvjoPhg28eWhR 5hPUYi2rwzD/T2SeVSE72TWuWuhBk57KyFwi043Q5Rnq5LYZzBDM9HvcCXiOC4DFWqGjF H5dv3Nm6Io1TQegM3wSH7ID8gpi113dfHWAzoiqmvbpmHQBcDzxpvrgosAMVT4WS/lA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471287; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=szWoBBkaaybqAV8yTP+DE9/CHBddLTwI9vS5xMrLr9o=; b=MLReDZj0OSWv4FgNBdLFJoIpKdHbo8X/RAJYKpycM9+ti0b81Td5DkJs+DEA6eWWeovX LFZ52PvBqeBd9HulV3CKjqzPwy+z2dK8DbEQfaZKYtNhUGHQtgtT7ds2TrqUyXbyh/T+w QkfgBXS/Orytxdgn13TjA80oPmp1DOJiTyVcDZhbdDXHq4FNmVC7B2xeorkKTr4vKbAw4 5ZF2/rhtyIsYwLzf4U9GReAH6b38S0mlQLgyyeYUem+LCHgFrde5wuqqvxIMNZxchBMhr q2SG94sO2MyutgVlBN9a0LzQPRbR54LMSe/9amOsC3zZomWFYqeNDlQu+t2uWGgMB0w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DPfHxP9p; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65F25606A331; Mon, 23 Nov 2026 22:01:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=DPfHxP9p Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B9881F000C0; Mon, 23 Nov 2026 22:01:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471287; bh=szWoBBkaaybqAV8yTP+DE9/CHBddLTwI9vS5xMrLr9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DPfHxP9pkOYpSWi+rSjMxaD3VUS8/BWppCspQZqU9zEIXK6SuHIE9yjDGZ7PYfpqp 3uj7AdpGtgaFlbs7gHHh456GiCQgTE1yBCAwIInvF4T28aaELp4iUu2vy+HzygFOHl +jXUfvCBmpcky0MM0Cu4qflQTAeTcGgYagsVXzxuhRHg1Sg6Nc1BPfdcA8sVPMGG5n tKhMD5c/4PxmRDrUWgD4KxtUYQkZYDBAkY2cwOj5szKCElwnsFFZ4vWv0yw3gWFZvh ypMupWkVw5UXVP6qlJDZytN+86Jxp8vj4EWw8/WiEQkn9tT+R7Kx6Ki3HLtOPVHjsG XhH/2jozkWwdw== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 17/19] perf test: Avoid online CPUs in the offline stat test Date: Mon, 23 Nov 2026 19:00:22 -0300 Message-ID: <20261123220024.14891-18-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo find_offline_cpu() treats a missing cpuN/online file as an offline CPU, but kernels without CPU hotplug also lack it for online CPUs. The test then expects "No supported events found." from a working CPU. Treat a present CPU as offline only if its online file reads 0. Keep the absent cpuN case to exercise an invalid CPU, and skip if neither exists. Fixes: 5123509628e1ebe7 ("perf tests stat: Add test for error for an offlin= e CPU") Cc: Ian Rogers Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/shell/stat.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/perf/tests/shell/stat.sh b/tools/perf/tests/shell/stat.sh index ac9e031831daca9c..7cd9999fd526bbd6 100755 --- a/tools/perf/tests/shell/stat.sh +++ b/tools/perf/tests/shell/stat.sh @@ -43,21 +43,28 @@ test_null_stat() { } =20 find_offline_cpu() { - for i in $(seq 1 4096) + for i in $(seq 0 4096) do - if [[ ! -f /sys/devices/system/cpu/cpu$i/online || \ - $(cat /sys/devices/system/cpu/cpu$i/online) =3D=3D "0" ]] + if [[ ! -d /sys/devices/system/cpu/cpu$i ]] then echo $i - return + return 0 + elif [[ -f /sys/devices/system/cpu/cpu$i/online && \ + $(cat /sys/devices/system/cpu/cpu$i/online) =3D=3D "0" ]] + then + echo $i + return 0 fi done - echo "Failed to find offline CPU" - exit 1 + return 1 } =20 test_offline_cpu_stat() { - cpu=3D$(find_offline_cpu) + if ! cpu=3D$(find_offline_cpu) + then + echo "Offline CPU stat command test [Skipped - no offline CPU]" + return + fi echo "Offline CPU stat command test (cpu $cpu)" if ! perf stat "-C$cpu" -e cycles true 2>&1 | grep -E -q "No supported e= vents found." then --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471290; b=xWDTneeSwbm+MpEafwXKKGO3e4VEjfntJXlXssZt0Tcm+C46pXrAU2n427pXdb23bBAD BohRA1iLyF/jrE1kMM0MsKXCHNEXXqz1LEw0EOkrw5rjdskG6yvFOP9ykquk3Hh2nMwEw gEfySEBJufZBrUk35siyr2y/PnfGRujbqPT8ZaI4D3VPAAaszOeGvlJyouwjgFf+X/iCf i1R4Oy9zeA1MkRQX/rJrO6JRXeXW6FdtTpKrg79qsUHL9wfkLUpmzSFJKFlZiDur1LLbE iGyUj/x1E+6OLNEnERMH2roudzsl1/plmotTJnx6ybl0xAIhkNnNVcCeNOtrqRIL4iQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471290; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=/SyCbfKWp/zQ9Io6eDaSQnODKI6Nsw3B363EDeWdg+M=; b=4cXDpNhxSjMmaWtNO6RfCQ1i6P1mgA/4LCzQmJDa37hibyrV07ZI+SuPOfztv8wZBWla ExjhhWgfZJpQdy/UKR9RJDMitbr9yQmNvyTFidxtW0Pjw6Akngs7FqrgImwKM43Bjxl/o ptwnojqmq2ZhugRtFpPnMYJkh4e4HCn8K7qCmntGaYILnCbPhr3Dot4vHUM5jDQTUCdUL EfIZbEz+i/EfBBfGS2XdqNsm6JTGY27lUjD0TnT61D1N/RFfzbKXKL4eN65Ss/rpNdmoc Uu5J2XWzMq5Kone+HGZX+BGo4kPiOy1Xz9vryWa9EIKq+pDs/HtycvDRfnHfVdq6krQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=V87asJ9n; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D681B606A321; Mon, 23 Nov 2026 22:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=V87asJ9n Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAD5A1F000CA; Mon, 23 Nov 2026 22:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471290; bh=/SyCbfKWp/zQ9Io6eDaSQnODKI6Nsw3B363EDeWdg+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=V87asJ9nJA4KnrzegxriJAkYqzVcfxf2hUisMzqh6gHeE7hiykL0+MPwbDbfUXmtA amjFltWyw0kc+yml2UePJGMty3mtMRWQ2yzYdxcoToJYhBggpHuyHme62XpOGCL0/4 6wsCTemj1uhbNrrNRstH1LU8xTk2cYGwu4aPDzUqfVOsnHC5/8uUF73TO3lS21Vh6n bXg+Q3tg87wwO/O6gLzBUQm3DtsojwizaVntMOdJTaUfax+xWda8uvhXJdjQrAw6PA HPvTAxL3tR1RfvaukKeuXLraC3IY8A79+upwkz5xCe41utruH+oYg0rCCuNIhN2yhX 9URN8cadIOieA== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 18/19] perf scripts: Add a coverage harness for perf Date: Mon, 23 Nov 2026 19:00:23 -0300 Message-ID: <20261123220024.14891-19-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Arnaldo Carvalho de Melo Build perf with clang source based coverage, run the complete perf test suite, merge the raw profiles and report line and function coverage, optionally against a baseline. Wired as 'make -C tools/perf coverage' and 'coverage-prep'; coverage-prep builds the instrumented perf apart from the test run, for the root tests on the bare metal host while building in the development container. The report covers every instrumented C and C++ source, not only the paths the tests walk; the Rust workload is built and exercised, but rustc does not get coverage flags. The static libbpf build inherits EXTRA_CFLAGS, the C++ sources get the same coverage flags through EXTRA_CXXFLAGS without dropping a CXXFLAGS from the environment, and the dlopened UI, jvmti, Python and dlfilter libraries are passed to llvm-cov as separate objects. The host tools are built with clang too, so the build does not need gcc. The test suite runs in parallel by default; --sequential runs one test at a time, and --timeout SECS raises the per-test timeout, for machines with few CPUs or slow storage. 'perf test' exits 0 even when tests fail and when the test filter matches nothing, so the status comes from its "Failed tests :" and "Timed out tests :" lines and a run with every count zero is an error. The dlfilter objects and shared libraries are rebuilt on each perf build, the python extension is dropped before a build and its setuptools object cache after it, as that cache keys on timestamps only. The built extension then stays in the build dir, so a second root run of the prepared build keeps passing the python tests. Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/.gitignore | 1 + tools/perf/Makefile | 12 +- tools/perf/Makefile.config | 1 + tools/perf/Makefile.perf | 9 +- tools/perf/scripts/coverage.sh | 486 +++++++++++++++++++++++++++++++++ 5 files changed, 505 insertions(+), 4 deletions(-) create mode 100755 tools/perf/scripts/coverage.sh diff --git a/tools/perf/.gitignore b/tools/perf/.gitignore index 3b968c5158b822ce..d263877366ca1440 100644 --- a/tools/perf/.gitignore +++ b/tools/perf/.gitignore @@ -27,6 +27,7 @@ stats-*.csv cscope* config.mak config.mak.autogen +/cov/ *-bison.* *-flex.* *.pyc diff --git a/tools/perf/Makefile b/tools/perf/Makefile index 00baf90e5bda7123..d9ad8c0d796c2852 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -140,6 +140,16 @@ check-headers: sync-headers: @./scripts/sync-headers.sh $(SYNC_HEADERS_ARGS) =20 +coverage_o =3D $(if $(O),\ +$(if $(shell cd $(PWD); test -d $(O) || echo $(O)),\ +$(error O=3D$(O) does not exist),--build-dir=3D$(FULL_O))) + +coverage-prep: + @./scripts/coverage.sh --prep $(coverage_o) $(COVERAGE_ARGS) + +coverage: + @./scripts/coverage.sh $(coverage_o) $(COVERAGE_ARGS) + # # All other targets get passed through: # @@ -147,4 +157,4 @@ sync-headers: $(print_msg) $(make) =20 -.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball c= heck-headers sync-headers +.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball c= heck-headers sync-headers coverage coverage-prep diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 88b8bc13a578a24f..11043520675d2c6a 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -19,6 +19,7 @@ detected =3D $(shell echo "$(1)=3Dy" >> $(OUTPU= T).config-detected) detected_var =3D $(shell echo "$(1)=3D$($(1))" >> $(OUTPUT).config-detecte= d) =20 CFLAGS :=3D $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS= )) +CXXFLAGS :=3D $(CXXFLAGS) $(EXTRA_CXXFLAGS) HOSTCFLAGS :=3D $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) =20 # This is required because the kernel is built with this and some of the c= ode diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index d4b641925ab296db..1b4efe6254fa0370 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -779,13 +779,13 @@ $(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/fin= d-map.c $(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ p= erf-read-vdso.c endif =20 -$(OUTPUT)dlfilters/%.o: dlfilters/%.c include/perf/perf_dlfilter.h +$(OUTPUT)dlfilters/%.o: dlfilters/%.c include/perf/perf_dlfilter.h FORCE $(Q)$(MKDIR) -p $(OUTPUT)dlfilters $(QUIET_CC)$(CC) -c -Iinclude $(EXTRA_CFLAGS) -o $@ -fpic $< =20 .SECONDARY: $(DLFILTERS:.so=3D.o) =20 -$(OUTPUT)dlfilters/%.so: $(OUTPUT)dlfilters/%.o +$(OUTPUT)dlfilters/%.so: $(OUTPUT)dlfilters/%.o FORCE $(QUIET_LINK)$(CC) $(filter-out -static,$(LDFLAGS)) $(EXTRA_CFLAGS) -shar= ed -o $@ $< =20 ifndef NO_JVMTI @@ -812,7 +812,7 @@ $(LIBAPI)-clean: $(LIBBPF): FORCE | $(LIBBPF_OUTPUT) $(Q)$(MAKE) -C $(LIBBPF_DIR) FEATURES_DUMP=3D$(FEATURE_DUMP_EXPORT) \ O=3D OUTPUT=3D$(LIBBPF_OUTPUT)/ DESTDIR=3D$(LIBBPF_DESTDIR) prefix=3D su= bdir=3D \ - EXTRA_CFLAGS=3D"-fPIC" $@ install_headers + EXTRA_CFLAGS=3D"-fPIC $(EXTRA_CFLAGS)" $@ install_headers =20 $(LIBBPF)-clean: $(call QUIET_CLEAN, libbpf) @@ -877,6 +877,9 @@ help: @echo ' check-headers - check which header copies are out of sync with = the kernel' @echo ' sync-headers - sync those header copies with the kernel, creati= ng commits' @echo ' (SYNC_HEADERS_ARGS=3D"..." passes options to the script)' + @echo ' coverage-prep - build perf with clang coverage, ready for a roo= t test run' + @echo ' coverage - build perf with clang coverage, run the tests and re= port' + @echo ' (O=3DDIR uses an existing build dir; COVERAGE_ARGS=3D"..." pa= sses options)' =20 =20 DOC_TARGETS :=3D doc man html info pdf diff --git a/tools/perf/scripts/coverage.sh b/tools/perf/scripts/coverage.sh new file mode 100755 index 0000000000000000..e9a4cf807850e1c7 --- /dev/null +++ b/tools/perf/scripts/coverage.sh @@ -0,0 +1,486 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2026, Red Hat Inc, Arnaldo Carvalho de Melo +# +# Build perf with clang source based coverage, run the perf test suite and +# report line coverage. +# The build goes into tools/perf and the profiles and report into +# tools/perf/cov; -b and -c override them, following perf's O=3D layout. +# --prep stops after the instrumented build, for running the tests later as +# root with the same build directory. + +set -euo pipefail + +PERF_DIR=3D$(cd "$(dirname "$0")/.." && pwd -P) +TOOLS_DIR=3D$(cd "$PERF_DIR/.." && pwd -P) +SRC_DIR=3D$(cd "$TOOLS_DIR/.." && pwd -P) + +BUILD_DIR=3D${BUILD_DIR:-} +COV_DIR=3D${COV_DIR:-} +JOBS=3D${JOBS:-$(nproc 2>/dev/null || echo 1)} +LLVM_PROFDATA=3D${LLVM_PROFDATA:-llvm-profdata} +LLVM_COV=3D${LLVM_COV:-llvm-cov} +DWARF_VERSION=3D${DWARF_VERSION:-4} +COVERAGE_CFLAGS=3D"-fprofile-instr-generate -fcoverage-mapping -gdwarf-$DW= ARF_VERSION" + +PREP=3D0 +SKIP_BUILD=3D0 +SEQUENTIAL=3D0 +TEST_TIMEOUT=3D +USE_BASELINE=3D1 +TESTS=3D() + +ROOT=3D0 +[ "$(id -u)" =3D 0 ] && ROOT=3D1 + +say() { printf '\033[1;34m=3D=3D>\033[0m %s\n' "$*"; } +warn() { printf '\033[0;33mwarning:\033[0m %s\n' "$*" >&2; } +die() { printf '\033[0;31merror:\033[0m %s\n' "$*" >&2; exit 1; } + +usage() +{ + cat </dev/null) || + die "could not stat $PERF_DIR" + fi +fi +TRUST_GID=3D$(id -g "$TRUST_UID") || + die "could not find the group of uid $TRUST_UID" + +check_owner() +{ + local path=3D$1 uid gid mode + + [ -e "$path" ] || return 0 + read -r uid gid mode < <(stat -c '%u %g %a' "$path" 2>/dev/null) || + die "could not stat $path" + [ "$uid" =3D 0 ] || [ "$uid" =3D "$TRUST_UID" ] || + die "$path is owned by uid $uid, not by root or uid $TRUST_UID" + [ $(( 8#$mode & 8#002 )) =3D 0 ] || + die "$path is writable by another user" + # User private groups are the norm: umask 002 gives 775, where + # only the developer's own group can write. + if [ $(( 8#$mode & 8#020 )) !=3D 0 ] && + [ "$gid" !=3D "$TRUST_GID" ]; then + die "$path is writable by group $gid" + fi +} + +check_owner "$BUILD_DIR" +check_owner "$BUILD_DIR/perf" + +(umask 077 && mkdir -p "$COV_DIR") || die "could not create $COV_DIR" +check_owner "$COV_DIR" + +# A sudo run leaves the profiles and report owned by root; give them back +# to the developer so the next run can replace them. +if [ "$ROOT" =3D 1 ] && [ -n "${SUDO_UID:-}" ]; then + trap 'chown -R "$SUDO_UID:${SUDO_GID:-$SUDO_UID}" "$COV_DIR" 2>/dev/null = || true' EXIT +fi + +BUILD_LOG=3D$COV_DIR/build.log +TEST_LOG=3D$COV_DIR/tests.log +REPORT=3D$COV_DIR/report.txt +PROFDATA=3D$COV_DIR/perf.profdata +BASELINE=3D$COV_DIR/baseline.txt + +# +# Build: clang, DEBUG=3D1 gives -O0 -g, which keeps the line mapping honest +# at the cost of slower test runs. +# +build_perf() +{ + local make_args=3D() + + if [ "$SKIP_BUILD" =3D 1 ]; then + [ -x "$BUILD_DIR/perf" ] || + die "no $BUILD_DIR/perf, run coverage-prep first" + if command -v nm > /dev/null; then + # No -q: grep reads all of nm's output, so pipefail + # does not see a SIGPIPE from an early exit. + nm "$BUILD_DIR/perf" 2>/dev/null | + grep '__llvm_profile' > /dev/null || + die "$BUILD_DIR/perf was not built for coverage," \ + "run coverage-prep first" + else + warn "nm not found, cannot verify that $BUILD_DIR/perf is instrumented" + fi + return + fi + + say "Building perf in $BUILD_DIR" + # The dlfilter and GTK link rules don't track compiler flags, and + # setuptools caches util/python.c by timestamp only, so a previous + # non-coverage build would leave them out of the profile. + rm -f "$BUILD_DIR"/dlfilters/*.o "$BUILD_DIR"/dlfilters/*.so \ + "$BUILD_DIR"/libperf-gtk.so "$BUILD_DIR"/python/perf*.so + rm -rf "$BUILD_DIR"/python_ext_build + [ "$BUILD_DIR" =3D "$PERF_DIR" ] || make_args+=3D(O=3D"$BUILD_DIR") + if ! make -C "$PERF_DIR" "${make_args[@]+"${make_args[@]}"}" \ + CC=3Dclang CXX=3Dclang++ HOSTCC=3Dclang DEBUG=3D1 \ + EXTRA_CFLAGS=3D"$COVERAGE_CFLAGS" \ + EXTRA_CXXFLAGS=3D"$COVERAGE_CFLAGS" \ + -j"$JOBS" > "$BUILD_LOG" 2>&1; then + tail -20 "$BUILD_LOG" >&2 + die "build failed, full log in $BUILD_LOG" + fi + tail -1 "$BUILD_LOG" + # The extension just built is instrumented and stays in BUILD_DIR + # for the root runs on a prepared build; the setuptools object + # cache is dropped, as it keys on timestamps only and the next + # build, coverage or not, would reuse util/python.o as built here. + rm -rf "$BUILD_DIR"/python_ext_build +} + +run_tests() +{ + if [ ${#TESTS[@]} -eq 0 ]; then + say "Running the complete perf test suite" + else + say "Running perf tests: ${TESTS[*]}" + fi + rm -rf "$COV_DIR/raw" + mkdir -p "$COV_DIR/raw" + + local test_args=3D(-v) + [ "$SEQUENTIAL" =3D 0 ] || test_args+=3D(-S) + [ -z "$TEST_TIMEOUT" ] || test_args+=3D(-t "$TEST_TIMEOUT") + + set +e + # The shell tests are found from the kernel tree root. + (cd "$SRC_DIR" && + PATH=3D"$BUILD_DIR:$PATH" \ + LLVM_PROFILE_FILE=3D"$COV_DIR/raw/perf-%p-%m.profraw" \ + "$BUILD_DIR/perf" test "${test_args[@]}" \ + "${TESTS[@]+"${TESTS[@]}"}") 2>&1 | tee "$TEST_LOG" + pipe_status=3D("${PIPESTATUS[@]}") + set -e + test_status=3D${pipe_status[0]} + [ "${pipe_status[1]}" =3D 0 ] || + die "could not write $TEST_LOG" + + # 'perf test' exits 0 even when tests fail or time out, only the + # summary tells. + if [ "$test_status" =3D 0 ] && + grep -qE '^(Failed|Timed out) tests +: +[1-9]' "$TEST_LOG"; then + test_status=3D1 + fi + + # It also exits 0 when the filter matches no test: every summary + # count is zero then. + if ! grep -qE '^(Passed main tests|Passed subtests|Skipped tests|Failed t= ests|Timed out tests) +: +[1-9]' "$TEST_LOG"; then + grep -E '^(Passed|Skipped|Failed|Timed out) .*:' "$TEST_LOG" || true + die "no perf test ran, check the test filter" + fi + + grep -E '^(Passed|Skipped|Failed|Timed out) .*:' "$TEST_LOG" || true + [ "$test_status" =3D 0 ] || + warn "some tests failed, coverage is still collected" +} + +merge_profiles() +{ + local count size + + # llvm-profdata reads the list from a file: a full run leaves + # thousands of profiles, too many for the command line. + find "$COV_DIR/raw" -name '*.profraw' | sort > "$COV_DIR/profiles.txt" + count=3D$(wc -l < "$COV_DIR/profiles.txt") + size=3D$(du -sh "$COV_DIR/raw" 2>/dev/null | cut -f1) + [ "$count" -gt 0 ] || + die "no .profraw files, was perf rebuilt with -fprofile-instr-generate?" + + say "Merging $count profile files ($size)" + if ! "$LLVM_PROFDATA" merge -sparse \ + --input-files=3D"$COV_DIR/profiles.txt" \ + -o "$PROFDATA" 2> "$COV_DIR/merge.log"; then + # A profile left half written, by a perf killed at exit or by + # a full tmpfs, makes llvm-profdata drop the whole merge: + # retry without the invalid ones. + warn "some profile files are unusable, merging the rest" + "$LLVM_PROFDATA" merge -sparse --failure-mode=3Dall \ + --input-files=3D"$COV_DIR/profiles.txt" -o "$PROFDATA" \ + 2> "$COV_DIR/merge.log" || + die "llvm-profdata merge failed, see $COV_DIR/merge.log" + fi +} + +llvm_cov_objects() +{ + echo "$BUILD_DIR/perf" + local so + + # These are dlopened by perf and have to be profiled separately; + # libperf is linked into perf as a static library. + for so in libperf-gtk.so libperf-jvmti.so; do + [ -f "$BUILD_DIR/$so" ] && echo "--object=3D$BUILD_DIR/$so" + done + for so in "$BUILD_DIR"/dlfilters/*.so; do + [ -f "$so" ] && echo "--object=3D$so" + done + for so in "$BUILD_DIR"/python/perf*.so; do + [ -f "$so" ] && echo "--object=3D$so" + done +} + +render_report() +{ + local objects + + mapfile -t objects < <(llvm_cov_objects) + say "Generating report" + "$LLVM_COV" report "${objects[@]}" --instr-profile=3D"$PROFDATA" \ + > "$REPORT" || die "llvm-cov report failed" +} + +# llvm-cov strips the prefix every reported file has in common, so a +# tools/perf source can read as perf/util/evsel.c. +AWK_PERF=3D' +function perf_relpath(p) { + sub(/^.*tools\/perf\//, "", p) + sub(/^perf\//, "", p) + return p +} +function under_build(p, n) { + if (build =3D=3D "") + return 0 + n =3D length(build) + return substr(p, 1, n + 1) =3D=3D build "/" || + substr(p, 1, n + 2) =3D=3D "/" build "/" +} +function generated(p, r) { + r =3D perf_relpath(p) + if (under_build(p)) + return 1 + return r ~ /^(lib(api|bpf|perf|subcmd|symbol)|trace\/beauty\/generated)\/= / || + r ~ /^arch\/[^\/]+\/include\/generated\// || + r ~ /^pmu-events\/(pmu-events(-string)?|test-empty-pmu-events)\.c$= / || + r ~ /^util\/(intel-pt-decoder\/inat-tables\.c|.*-(bison|flex)\.[ch= ])$/ || + r ~ /^util\/bpf_skel\/(\.tmp\/|vmlinux\.h$)/ || + r ~ /\.skel\.h$/ || + r =3D=3D "common-cmds.h" +} +' + +total_cov() +{ + awk '$1 =3D=3D "TOTAL" { print $8, $9, $10 }' "$1" +} + +total_cov_perf() +{ + awk -v build=3D"$BUILD_AWK_DIR" "$AWK_PERF"' + generated($1) { next } + $1 !=3D "TOTAL" && + ($1 ~ /(^|\/)tools\/perf\// || $1 ~ /^perf\//) { + lines +=3D $8 + missed +=3D $9 + } + END { + if (lines) + printf "%d %d %.2f%%\n", lines, missed, + 100 * (lines - missed) / lines + }' "$1" +} + +since_baseline() +{ + local old cur + + [ "$USE_BASELINE" =3D 1 ] && [ -f "$BASELINE" ] && + ! cmp -s "$BASELINE" "$REPORT" || return 0 + old=3D$(awk '$1 =3D=3D "TOTAL" { print $10 }' "$BASELINE") + cur=3D$(awk '$1 =3D=3D "TOTAL" { print $10 }' "$REPORT") + [ -n "$old" ] && [ -n "$cur" ] || return 0 + awk -v old=3D"$old" -v cur=3D"$cur" 'BEGIN { + sub(/%$/, "", cur) + printf " (previous %s, %+.2f%%)", old, cur - old }' +} + +print_summary() +{ + local lines missed cover p_lines p_missed p_cover + + read -r lines missed cover < <(total_cov "$REPORT") || + die "no TOTAL row in $REPORT" + printf "\n\033[1mTotal:\033[0m %s of %s lines covered (%s)" \ + "$((lines - missed))" "$lines" "$cover" + since_baseline + printf "\n" + + read -r p_lines p_missed p_cover < <(total_cov_perf "$REPORT") || true + if [ -n "$p_lines" ]; then + printf " perf: %s of %s lines covered (%s)\n" \ + "$((p_lines - p_missed))" "$p_lines" "$p_cover" + fi +} + +update_baseline() +{ + [ "$USE_BASELINE" =3D 1 ] || return 0 + # A -t run covers a subset, saving it would poison the next run. + if [ ${#TESTS[@]} -gt 0 ]; then + printf "\nBaseline not updated, this was a subset run\n" + return 0 + fi + [ -f "$BASELINE" ] && mv "$BASELINE" "$BASELINE.prev" + cp "$REPORT" "$BASELINE" + printf "\nBaseline saved: %s\n" "$BASELINE" +} + +if [ "$PREP" =3D 0 ]; then + command -v "$LLVM_COV" > /dev/null || + die "$LLVM_COV not found (set LLVM_COV)" + command -v "$LLVM_PROFDATA" > /dev/null || + die "$LLVM_PROFDATA not found (set LLVM_PROFDATA)" +fi + +# Root does not rebuild a prepared build: use the perf already in +# BUILD_DIR, or build when there is none. +if [ "$ROOT" =3D 1 ] && [ "$PREP" =3D 0 ]; then + if [ -x "$BUILD_DIR/perf" ]; then + SKIP_BUILD=3D1 + say "Running as root, using the coverage build in $BUILD_DIR" + else + say "Running as root, building perf in $BUILD_DIR" + fi +fi + +if [ "$SKIP_BUILD" =3D 0 ]; then + command -v clang > /dev/null || + die "clang not found, it is the only compiler with -fcoverage-mapping" + command -v clang++ > /dev/null || + die "clang++ not found, it instruments the C++ sources" +fi + +test_status=3D0 + +if [ "$PREP" =3D 1 ]; then + build_perf + say "Coverage build ready: $BUILD_DIR/perf" + make_hint=3D"make -C $PERF_DIR coverage" + [ "$BUILD_DIR" =3D "$PERF_DIR" ] || make_hint+=3D" O=3D$BUILD_DIR" + printf "As root: %s\n" "$make_hint" + exit 0 +fi + +build_perf +run_tests +merge_profiles + +[ -f "$PROFDATA" ] || die "no $PROFDATA, the merge did not run" + +export LC_ALL=3DC +render_report +print_summary +update_baseline + +printf "\nReport: %s\n" "$REPORT" +exit "$test_status" --=20 2.56.0 From nobody Tue Nov 24 11:45:51 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795471294; b=pnSqi3Dybji2Acw5jYiaaYveDfumaMSv4VoimliYMG0PMC1nRAONWTVdJLxA2zl3rVQs Jfpi30EL3Mq6gnW+4uw7lGjIS4DUxnfvGqzejrJSCrw0nMoeJAEcQ8Knq5fztMfdtkhK5 kulMn/nvTZxqsR6TJGWH6yrDdJLJsT72G54ZCyKg+w+n0l5H4KZuchYvIQBOdgHraEeYS 0x0bECchiLCKm5f+Grq6+U+PvmBayHjrU2WxMt8KciDIBaF+c5a88iIfKnFy3OzT41WF7 /IOLuTmY4Fc351sKiE0D9cuFhnySMSDeQ58akpr8HS1enoqzcWt8t2BISOPPqxFi7ww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795471294; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=pt8iyayXPUi49O4SY1n2UqqeQ4eSVUj6JDIm+hhFJQM=; b=D4SuU6Ov1j/AqeF3ihuLlMVY4Zr8ZwhS9LRpTEQ/cR9zEXya3pTveV6H+emecQkupTn2 JWbJDpf8r5Bqok7iF+pxW6hE1zs/mWjQdD4UZueZDYyYyrUtCF3G03s0hzlHrvys+bB5m MdlX6jV7230JtTX4VBwgh3aom9O2B/lawcAsJ+Y/8dKhomU/qqUaYoCPW0oql0o/efi9N 0B5MK0izgr0ZS71Au3kCn7pfsUnrip1icoKnA9dGRGAiqjL+PH5u7IPxTGUMqoPW5urTU qAhYF8NCteN4IS77ymXuNyw6El/Saz4635DhbwrVeLL46u8Xchvxa53ovKqjjmdvDHA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jUbJcu1g; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 023B8606A32C; Mon, 23 Nov 2026 22:01:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jUbJcu1g Received: by smtp.kernel.org (Postfix) with ESMTPSA id 271F31F000C0; Mon, 23 Nov 2026 22:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795471293; bh=pt8iyayXPUi49O4SY1n2UqqeQ4eSVUj6JDIm+hhFJQM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jUbJcu1gX1weoIs0AZmfNce/JA7ZLE4xAqnKkvBmdht66czeAsxAGDn71kCA2pYSk dc8z6jOfbvLHz+lYDQUkHDrpToDDQ/L69tCs0c/omdZ2AUwnXEgW7JUE7wXQhCDOw4 FSkpi4Dp1c3rXGy/9qYB1+UNR1lglyb9SEou/+UqcOH+LY0H46NryX6eS279ozxWbA zUkDaey9i74MX7VLufl+gkq86me0rMWBuru20DMrFemSf7dFQjLk94KvPUernBChvw Mwt50W15zdYjt9iywmG28ucWN7axYf15q0+g6+EiVqKgn7B+ehbD+NmpYgNmTiEi+1 mzVNvzJzJbMmg== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , James Clark , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo Subject: [PATCH v12 19/19] perf scripts: Add a coverage table Date: Mon, 23 Nov 2026 19:00:24 -0300 Message-ID: <20261123220024.14891-20-acme@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261123220024.14891-1-acme@kernel.org> References: <20261123220024.14891-1-acme@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Arnaldo Carvalho de Melo Render the report of the last coverage run as a table of the files with the most uncovered lines, biggest gap first; --all lists every file and -f picks files explicitly, failing when a requested file has no coverage data. coverage.sh prints the table when a run finishes; it is also wired as 'make -C tools/perf coverage-table', to print just the table. It only reads coverage.sh's report.txt, so the measurement and the table are reviewed and changed separately. For example, with --top 4 on a full test suite run: $ make -C tools/perf coverage-table O=3D/tmp/build/coverage \ COVERAGE_ARGS=3D"--top 4" tools/perf (no tests/ or bench/), 100+ executable lines: the 4 biggest uncovered gaps, start here when adding coverage tests. --all for every file: make -C tools/perf coverage-table O=3D/tmp/build/= coverage COVERAGE_ARGS=3D"--all" =E2=94=8C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=AC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=AC=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=90 =E2=94=82 File =E2=94=82 Lines =E2= =94=82 Hit =E2=94=82 Miss =E2=94=82 Line Coverage =E2=94= =82 Funcs =E2=94=82 FuncCov =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=A4 =E2=94=82 util/intel-pt.c =E2=94=82 3237 =E2= =94=82 0 =E2=94=82 3237 =E2=94=82 =E2=96=91=E2=96=91=E2=96=91=E2=96= =91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91= =E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91 = 0.0% =E2=94=82 0/142 =E2=94=82 0.00% =E2=94=82 =E2=94=82 util/intel-pt-decoder/intel-pt-decoder.c =E2=94=82 3208 =E2= =94=82 0 =E2=94=82 3208 =E2=94=82 =E2=96=91=E2=96=91=E2=96=91=E2=96= =91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91= =E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91 = 0.0% =E2=94=82 0/119 =E2=94=82 0.00% =E2=94=82 =E2=94=82 ui/browsers/hists.c =E2=94=82 2742 =E2= =94=82 0 =E2=94=82 2742 =E2=94=82 =E2=96=91=E2=96=91=E2=96=91=E2=96= =91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91= =E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91 = 0.0% =E2=94=82 0/124 =E2=94=82 0.00% =E2=94=82 =E2=94=82 builtin-sched.c =E2=94=82 3737 =E2= =94=82 1543 =E2=94=82 2194 =E2=94=82 =E2=96=88=E2=96=88=E2=96=88=E2=96= =88=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=91=E2=96=91=E2=96=91=E2=96=91= =E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91 4= 1.3% =E2=94=82 62/141 =E2=94=82 43.97% =E2=94=82 =E2=94=9C=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=BC=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=BC=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=A4 =E2=94=82 TOTAL (perf) =E2=94=82 174097 =E2= =94=82 86374 =E2=94=82 87723 =E2=94=82 =E2=96=88=E2=96=88=E2=96=88=E2=96= =88=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=91=E2=96=91=E2=96=91= =E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91=E2=96=91 4= 9.6% =E2=94=82 5650/9358 =E2=94=82 60.38% =E2=94=82 =E2=94=94=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=B4=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=B4=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=B4=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=B4=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=B4=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=B4=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=98 Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 5 +- tools/perf/Makefile.perf | 3 +- tools/perf/scripts/coverage-table.sh | 337 +++++++++++++++++++++++++++ tools/perf/scripts/coverage.sh | 14 +- 4 files changed, 354 insertions(+), 5 deletions(-) create mode 100755 tools/perf/scripts/coverage-table.sh diff --git a/tools/perf/Makefile b/tools/perf/Makefile index d9ad8c0d796c2852..5da13faa1c18b510 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -150,6 +150,9 @@ coverage-prep: coverage: @./scripts/coverage.sh $(coverage_o) $(COVERAGE_ARGS) =20 +coverage-table: + @./scripts/coverage-table.sh $(coverage_o) $(COVERAGE_ARGS) + # # All other targets get passed through: # @@ -157,4 +160,4 @@ coverage: $(print_msg) $(make) =20 -.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball c= heck-headers sync-headers coverage coverage-prep +.PHONY: all clean tags TAGS FORCE Makefile build-test build-test-tarball c= heck-headers sync-headers coverage coverage-prep coverage-table diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 1b4efe6254fa0370..6427d3a012c465d1 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -878,7 +878,8 @@ help: @echo ' sync-headers - sync those header copies with the kernel, creati= ng commits' @echo ' (SYNC_HEADERS_ARGS=3D"..." passes options to the script)' @echo ' coverage-prep - build perf with clang coverage, ready for a roo= t test run' - @echo ' coverage - build perf with clang coverage, run the tests and re= port' + @echo ' coverage - build perf with clang coverage, run the tests, repor= t and show the table' + @echo ' coverage-table - print a text table of the last coverage run' @echo ' (O=3DDIR uses an existing build dir; COVERAGE_ARGS=3D"..." pa= sses options)' =20 =20 diff --git a/tools/perf/scripts/coverage-table.sh b/tools/perf/scripts/cove= rage-table.sh new file mode 100755 index 0000000000000000..31d23b33b8720c33 --- /dev/null +++ b/tools/perf/scripts/coverage-table.sh @@ -0,0 +1,337 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2026, Red Hat Inc, Arnaldo Carvalho de Melo +# +# Render the report of the last coverage run as a text table, like pahole's +# coverage_table.py. Without -f the default is the tool's files, not its +# tests and benches, with the most uncovered lines, biggest gap first; +# --all lists every tools/perf file, most covered first. The total is the +# tools/perf subtotal, the run summary has the whole report. + +set -euo pipefail + +PERF_DIR=3D$(cd "$(dirname "$0")/.." && pwd -P) +TOOLS_DIR=3D$(cd "$PERF_DIR/.." && pwd -P) + +BUILD_DIR=3D${BUILD_DIR:-} +COV_DIR=3D${COV_DIR:-} +TOP=3D${TOP:-20} +MIN_LINES=3D${MIN_LINES:-100} +TABLE_ALL=3D0 +FOCUS=3D() + +die() { printf '\033[0;31merror:\033[0m %s\n' "$*" >&2; exit 1; } + +usage() +{ + cat <&2 + printf ' %s\n' "${missing[@]}" >&2 + exit 1 + fi + printf '%s' "$rows" | sort -t$'\t' -k5,5gr + return + fi + + if [ "$TABLE_ALL" =3D 1 ]; then + awk -v build=3D"$BUILD_AWK_DIR" "$AWK_PERF"' + ($1 ~ /(^|\/)tools\/perf\// || $1 ~ /^perf\//) && + !generated($1) && $8 > 0 { + printf "%s\t%s\t%d\t%d\t%.2f\t%s\t%d\t%s\n", + perf_relpath($1), $8, $8 - $9, $9, $10, + $5, $5 - $6, $7 + }' "$REPORT" | + sort -t$'\t' -k5,5gr + return + fi + + awk -v min=3D"$MIN_LINES" -v build=3D"$BUILD_AWK_DIR" "$AWK_PERF"' + ($1 ~ /(^|\/)tools\/perf\// || $1 ~ /^perf\//) && + !generated($1) && $8 >=3D min && $9 > 0 && + perf_relpath($1) !~ /^(tests|bench)\// { + printf "%s\t%s\t%d\t%d\t%.2f\t%s\t%d\t%s\n", + perf_relpath($1), $8, $8 - $9, $9, $10, + $5, $5 - $6, $7 + }' "$REPORT" | + sort -t$'\t' -k4,4nr | + if [ "$TOP" -gt 0 ]; then + sed -n "1,${TOP}p" + else + cat + fi +} + +# The table is about tools/perf, so its total is the tools/perf subtotal; +# the run summary prints the whole report, generated files included. +table_total() +{ + awk -v build=3D"$BUILD_AWK_DIR" "$AWK_PERF"' + $1 !=3D "TOTAL" && !generated($1) && + ($1 ~ /(^|\/)tools\/perf\// || $1 ~ /^perf\//) { + lines +=3D $8 + missed +=3D $9 + funcs +=3D $5 + funcs_missed +=3D $6 + } + END { + printf "%d\t%d\t%d\t%.2f\t%d\t%d\t%.2f%%\n", + lines, lines - missed, missed, + lines ? 100 * (lines - missed) / lines : 0, + funcs, funcs - funcs_missed, + funcs ? 100 * (funcs - funcs_missed) / funcs : 0 + }' "$REPORT" +} + +# At most three lines: what the table shows and how to see every file. +table_caption() +{ + if [ ${#FOCUS[@]} -gt 0 ]; then + echo "files requested with -f." + elif [ "$TABLE_ALL" =3D 1 ]; then + echo "every tools/perf file, tests and benches included, most covered fi= rst." + return + elif [ "$TOP" -gt 0 ] && [ "$MIN_LINES" -gt 0 ]; then + printf "tools/perf (no tests/ or bench/), %d+ executable lines:\n" "$MIN= _LINES" + echo "the $TOP biggest uncovered gaps, start here when adding coverage t= ests." + elif [ "$TOP" -gt 0 ]; then + printf "tools/perf (no tests/ or bench/): the %d files with the\n" "$TOP" + echo "biggest uncovered gaps, start here when adding coverage tests." + elif [ "$MIN_LINES" -gt 0 ]; then + printf "tools/perf (no tests/ or bench/), %d+ executable lines:\n" "$MIN= _LINES" + echo "start here when adding coverage tests, biggest gaps first." + else + echo "tools/perf (no tests/ or bench/), biggest gaps first." + fi + local cmd=3D'make -C tools/perf coverage-table' + local cov_args=3D'--all' + [ "$BUILD_DIR" =3D "$PERF_DIR" ] || cmd+=3D" O=3D$BUILD_DIR" + [ "$COV_DIR" =3D "$BUILD_DIR/cov" ] || + cov_args=3D"--cov-dir $COV_DIR --all" + printf '%s %s COVERAGE_ARGS=3D"%s"\n' '--all for every file:' "$cmd" "$co= v_args" +} + +print_table() +{ + local rows total path lines hit missed pct funcs funcs_hit func_cov + local row_fmt w d_file d29 d13 d10 d8 + + rows=3D$(table_rows) + [ -n "$rows" ] || + die "no coverage data in $REPORT for the requested files" + total=3D$(table_total) + [ -n "$total" ] || die "no coverage data in $REPORT" + + table_caption + printf '\n' + + w=3D12 # "TOTAL (perf)" + while IFS=3D$'\t' read -r path _; do + if [ ${#path} -gt "$w" ]; then + w=3D${#path} + fi + done <<< "$rows" + + d8=3D$(dashes 8) + d10=3D$(dashes 10) + d13=3D$(dashes 13) + d29=3D$(dashes 29) + d_file=3D$(dashes $((w + 2))) + + printf '=E2=94=8C%s=E2=94=AC%s=E2=94=AC%s=E2=94=AC%s=E2=94=AC%s=E2=94=AC%= s=E2=94=AC%s=E2=94=90\n' \ + "$d_file" "$d8" "$d8" "$d8" "$d29" "$d13" "$d10" + printf '=E2=94=82 %-*s =E2=94=82 %6s =E2=94=82 %6s =E2=94=82 %6s =E2=94= =82 %s =E2=94=82 %11s =E2=94=82 %8s =E2=94=82\n' \ + "$w" "File" "Lines" "Hit" "Miss" \ + "$(center 'Line Coverage' 27)" "Funcs" "FuncCov" + printf '=E2=94=9C%s=E2=94=BC%s=E2=94=BC%s=E2=94=BC%s=E2=94=BC%s=E2=94=BC%= s=E2=94=BC%s=E2=94=A4\n' \ + "$d_file" "$d8" "$d8" "$d8" "$d29" "$d13" "$d10" + + row_fmt=3D$(printf '=E2=94=82 %%-%ds =E2=94=82 %%6s =E2=94=82 %%6s =E2=94= =82 %%6s =E2=94=82 %%s %%5.1f%%%%' "$w") + row_fmt+=3D' =E2=94=82 %5s/%-5s =E2=94=82 %8s =E2=94=82\n' + + while IFS=3D$'\t' read -r path lines hit missed pct funcs funcs_hit func_= cov; do + printf "$row_fmt" "$path" "$lines" "$hit" "$missed" \ + "$(bar "$pct" 20)" "$pct" "$funcs_hit" "$funcs" "$func_cov" + done <<< "$rows" + + printf '=E2=94=9C%s=E2=94=BC%s=E2=94=BC%s=E2=94=BC%s=E2=94=BC%s=E2=94=BC%= s=E2=94=BC%s=E2=94=A4\n' \ + "$d_file" "$d8" "$d8" "$d8" "$d29" "$d13" "$d10" + while IFS=3D$'\t' read -r lines hit missed pct funcs funcs_hit func_cov; = do + printf "$row_fmt" "TOTAL (perf)" "$lines" "$hit" "$missed" \ + "$(bar "$pct" 20)" "$pct" "$funcs_hit" "$funcs" "$func_cov" + done <<< "$total" + printf '=E2=94=94%s=E2=94=B4%s=E2=94=B4%s=E2=94=B4%s=E2=94=B4%s=E2=94=B4%= s=E2=94=B4%s=E2=94=98\n' \ + "$d_file" "$d8" "$d8" "$d8" "$d29" "$d13" "$d10" +} + +# The table code parses llvm-cov's decimal points; keep the numeric locale +# fixed. +export LC_ALL=3DC +print_table diff --git a/tools/perf/scripts/coverage.sh b/tools/perf/scripts/coverage.sh index e9a4cf807850e1c7..bb075c9a54e820cd 100755 --- a/tools/perf/scripts/coverage.sh +++ b/tools/perf/scripts/coverage.sh @@ -3,8 +3,9 @@ # # Copyright (C) 2026, Red Hat Inc, Arnaldo Carvalho de Melo # -# Build perf with clang source based coverage, run the perf test suite and -# report line coverage. +# Build perf with clang source based coverage, run the perf test suite, +# report line coverage and the table of the files with the most uncovered +# lines. coverage-table.sh renders that table from the last report alone. # The build goes into tools/perf and the profiles and report into # tools/perf/cov; -b and -c override them, following perf's O=3D layout. # --prep stops after the instrumented build, for running the tests later as @@ -44,7 +45,9 @@ usage() Usage: scripts/coverage.sh [options] [test name fragment...] =20 Builds perf with clang source based coverage, runs the complete perf test -suite and reports line coverage. Use -t to run a subset. +suite, reports line coverage and the files with the most uncovered lines. +Use -t to run a subset; scripts/coverage-table.sh renders the table again +with other options. =20 Options: -b, --build-dir DIR existing perf build directory (default: $PERF_DIR) @@ -64,6 +67,7 @@ Through make: make -C tools/perf coverage make -C tools/perf coverage-prep O=3D/tmp/build/perf-coverage sudo make -C tools/perf coverage O=3D/tmp/build/perf-coverage + make -C tools/perf coverage-table O=3D/tmp/build/perf-coverage EOF } =20 @@ -482,5 +486,9 @@ render_report print_summary update_baseline =20 +printf "\n" +"$PERF_DIR/scripts/coverage-table.sh" --build-dir "$BUILD_DIR" \ + --cov-dir "$COV_DIR" || warn "could not render the coverage table" + printf "\nReport: %s\n" "$REPORT" exit "$test_status" --=20 2.56.0