From nobody Sat Feb 7 21:24:55 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C5ED3933E4 for ; Thu, 22 Jan 2026 07:31:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067100; cv=none; b=da4yNDIpt9dYXX70cdqcFsZ3W3Wkl48sSrN+i2QNp4LuWnE/6YTPWRANegD+Npkn2FmYI4iR5pnG3aH3DyNzroMfAm7OhkW7dn/ypM0mTBZ7bX0OfMY/ILcPGY67C/4j48Dio7FghUuCwNw60tRRpoLpRemsBjPkoSjI6XE7yLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067100; c=relaxed/simple; bh=WqOiFcX/heg3IGph3C/ogbRzFLpcL0diaA21e5ry5lo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=bJS8kx+LDrZ2Ks0KfKM0JUObEuanoCEOBuSDyUNx1/zHYmRYfH3pOvzK4wWUODGUetZT+0Zwzx2gF9r4DRtCBriPrSI2x18kpEdHWL2O0VCKXS179XTcNHi6wJCU78DcfXbQbmtEbcCqWXhF6uNpANShWHRewxEEJCaRnEHN0HM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=22z2F6bI; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="22z2F6bI" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-11b9786fb51so4678849c88.1 for ; Wed, 21 Jan 2026 23:31:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067092; x=1769671892; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=DnbHjkP7sr2MY8dvLIuI6wPgadGKGFiX6WTYohRo5Kw=; b=22z2F6bInp6cZhvQ9Em21c3XK/Yk+8bxjkaGoHOr+ypQIMd5qS6M8YmO/ig4cTtQA5 UKsY4BqUMT4kSZOvGIpH2bJRvZ6hgpPf3XJixF4OtNHqDwjK55UWPlkj6pcw3dz5gUOV TcoAsOSNTlGUTOHNUn4wItzdpmMIOUY6z7BoKdUzoLVBFXv7XSgR/4zW7qk+U5xYvLvP zXfjy3KmjHNtznRpcbnYN3pq6ggvdT6g3mzciVKGCcOqmWzQDxxCHIPrU8wO+52JZyTH voQBqvQvlIfsPHU/XqOKYb62o1jr19O6PnVPv5J0DysTs82jFGRaRl5fzLbQWE9YjCLk JHIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067092; x=1769671892; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DnbHjkP7sr2MY8dvLIuI6wPgadGKGFiX6WTYohRo5Kw=; b=Z/TZq72cfcPXooN5Lsn4oNj4Ef6azaxhikTREQtG1uh91x6v9HmkhOi1tklAP/fn0r /CoB1mQwyIqOWhIvATblHJQskRF0NaGXVTY5M/vqS2YS1vuZP/lnzobzScJCr4BNWHcB AWdTbBk1OsTWJ2Pqim/wn5SLiTnaBWMAYOJakLjpls9lwVuXfKoUetXLYn6h7bSaufUe 35iPl1z1DejYd5eCVAQFBu5D9BFfYZaWOOc0z8e+HjD3to6hEvB3BblSt+m0m3nMH6l+ CRKng+UP67a/ESWQNT0Igyk3egKahcCDFKNuI/w3weesaWG7kUXhegq0qf6k58/x5D54 pCgQ== X-Forwarded-Encrypted: i=1; AJvYcCX1rYjrxT7EjifNT0k2wLGF6yZ0vnGhC1kcRNlj2LNAgDCa2CkYncayyRJPT6nBvg1UG1Bq2WXAJ4AJZU0=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8fgW0WZzp2t6OLhHlJSI30zrAf/HRi1HizJ2fdt2jnMNuPLTf YQiX4jPtvSSjKU7WO0EYOQU5ZgP8CWULWRO2siZeCC7OCxT8YSwSZSS5aU7l5+oC1JCdfX8uPRh Oa4qEkOogZA== X-Received: from dlg15.prod.google.com ([2002:a05:7022:78f:b0:11f:330d:ed15]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:225:b0:11b:f056:a1b3 with SMTP id a92af1059eb24-1244a728dc0mr16430933c88.11.1769067091900; Wed, 21 Jan 2026 23:31:31 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:17 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-2-irogers@google.com> Subject: [PATCH v1 01/11] perf maps: Fix reference count leak in maps__find_ams From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ams and so ams->ms.map is an in argument, however, it is also overwritten. As a map is reference counted, ensure a map__put is done before overwriting it. Signed-off-by: Ian Rogers Fixes: 42fd623b58db ("perf maps: Get map before returning in maps__find") --- tools/perf/util/maps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 8ccc46d515b6..4092211cff62 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -708,6 +708,7 @@ int maps__find_ams(struct maps *maps, struct addr_map_s= ymbol *ams) if (ams->addr < map__start(ams->ms.map) || ams->addr >=3D map__end(ams->m= s.map)) { if (maps =3D=3D NULL) return -1; + map__put(ams->ms.map); ams->ms.map =3D maps__find(maps, ams->addr); if (ams->ms.map =3D=3D NULL) return -1; --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 21:24:55 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C89A1480DCA for ; Thu, 22 Jan 2026 07:31:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067101; cv=none; b=fd+8qmeMc3kwaKHGyggR/iknaV50+b7tBLQtVd9KtIGgXFYQWU9klzYmj8Q4Aymz87iLzVBYCfuSaPGuoJLcjwm/ThhBww12S7NpZrkGZhHtIqoAL/3qThCKpycDA819S8P5NJJYXhez3WKrO+aQ6xQ8bFYbanrm4wFK+wjSHMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067101; c=relaxed/simple; bh=g07mjdPPiRfUbpif4I7O+jPiAdpwj1ojeHWcOHwHmJ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Cq2QVyFAc102tc2jBT+BN3cXMHM9UjQ5n80oULZSTnkVCopIjd2HLZunCBIkGi1FVWF9bQPAmnpEOW4QDO60rrsjixldUkYPbXmgjAewWMX3+C0RbGvq6o1oTBCT8/oHGaa0J2F/L+TDtCl6BCWkiJOlbych3isJgcBx9b35I6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xGUJv975; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xGUJv975" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-12338749ea9so908754c88.0 for ; Wed, 21 Jan 2026 23:31:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067094; x=1769671894; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=7SyQiS0lnXgAvEhozlNZ8ceN/SCct+/3Su0Yxs9eoEA=; b=xGUJv975qe1pESzwD6ZJ5olyGwM9PxvudWqIPDlUtdU/8ZPiFsq6ku+WIYf0MLEnDM cOFXjpQhoTgk11tu9FffB7DVzrRXwtI43Df449FU9VnBTViXgJUrreCHIiaBiJhJggPe ImyHEQj59YEVTJRopX6GlnKCM2Q6HmFozB+PRh4A0k9S5dtpi7lHybBlSgNBn2n2aPJr gMxJFz9Gp8S8nsfCOPJ0EfbLrJQIPl4qdJ/5qVlFWxlHDtVaFQVGq365scQCEWxkkMSG ylzJYZRR1aZBAM2TEjOmLgJ4TjtFPCbIBMPZCg7YGPR0VmMDXP5Sw6ShqyuX4FcVbcrG RFww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067094; x=1769671894; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7SyQiS0lnXgAvEhozlNZ8ceN/SCct+/3Su0Yxs9eoEA=; b=ESVnuortBYZKVIekySM0WGBRCifVv9n+azZlkQp28x9PzysJpMAAA2CFkNCrhCwBb/ BYC9DlAjCprbKnIYmu2hUSdW8TY76UbE5dJ2hpkildATuQ8PrmCp7LKprlpMGOAaOb0n /yY96QSLtVkOJaC9qKy7taR54JV+oalTi6yqhHzId7bcbyipmPMe7kLZVBEcEVt5p058 qfbAxgzMXqgLUk4AYScIhwUHWXVy2Khv3nSk2iBOU+fzK4iDoLmGiENL6wU+LgmfrhCu D/JZu+Sry7FRd6KfAVWgZjyV1lx7/+zYpSTsy6DDWVt1Wi/6xWy3UZ9/cE1NNP5xyJqc OmoA== X-Forwarded-Encrypted: i=1; AJvYcCUpsgzOoNXQRu8Wiupc7nyicWCR2ktf9UOJdlZWofzXIkvmYucv8AQx7FpE3ruhZB8E47N5rubasxnqNyU=@vger.kernel.org X-Gm-Message-State: AOJu0YwjT9oBMVHgiNMa6cWwU9cPlRD4koJNv6W9ZC1zy6UinjBzxMUK K8W71NKL6043hyVVHDUH1gPhrexbZcJn2o/FAx1v6bYl19uSYzk8ugvmE26WxrQG3ryqtrz2RQm BgDtfqDLMJg== X-Received: from dlbcm22.prod.google.com ([2002:a05:7022:6896:b0:11e:60ad:95af]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:4584:b0:11b:c2fd:3960 with SMTP id a92af1059eb24-1244b35fd1amr12854378c88.28.1769067093485; Wed, 21 Jan 2026 23:31:33 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:18 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-3-irogers@google.com> Subject: [PATCH v1 02/11] perf annotate: Fix args leak of map_symbol From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" map_symbol__exit needs calling on an annotate_args.ms, however, rather than introduce proper reference count handling to symbol__annotate just switch to passing the map_symbol pointer parameter around, making the puts the caller's responsibility. Signed-off-by: Ian Rogers Fixes: 56e144fe9826 ("perf mem_info: Add and use map_symbol__exit and addr_= map_symbol__exit") --- tools/perf/util/annotate.c | 2 +- tools/perf/util/capstone.c | 14 +++++++------- tools/perf/util/disasm.c | 32 +++++++++++++++++--------------- tools/perf/util/disasm.h | 2 +- tools/perf/util/llvm.c | 6 +++--- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index cc7764455faf..791d60f97c23 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1031,7 +1031,7 @@ int symbol__annotate(struct map_symbol *ms, struct ev= sel *evsel, return 0; =20 args.arch =3D arch; - args.ms =3D *ms; + args.ms =3D ms; =20 if (notes->src =3D=3D NULL) { notes->src =3D annotated_source__new(); diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c index be5fd44b1f9d..2c7feab61b7b 100644 --- a/tools/perf/util/capstone.c +++ b/tools/perf/util/capstone.c @@ -143,7 +143,7 @@ static void print_capstone_detail(cs_insn *insn, char *= buf, size_t len, struct annotate_args *args, u64 addr) { int i; - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct symbol *sym; =20 /* TODO: support more architectures */ @@ -222,7 +222,7 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, { #ifdef HAVE_LIBCAPSTONE_SUPPORT struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); u64 start =3D map__rip_2objdump(map, sym->start); u64 offset; @@ -256,7 +256,7 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) @@ -268,7 +268,7 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(args->ms.maps), &handle, is_64bit, disass= embler_style) < 0) + if (capstone_init(maps__machine(args->ms->maps), &handle, is_64bit, disas= sembler_style) < 0) goto err; =20 needs_cs_close =3D true; @@ -345,7 +345,7 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, { #ifdef HAVE_LIBCAPSTONE_SUPPORT struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); struct nscookie nsc; u64 start =3D map__rip_2objdump(map, sym->start); @@ -382,7 +382,7 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(args->ms.maps), &handle, is_64bit, disass= embler_style) < 0) + if (capstone_init(maps__machine(args->ms->maps), &handle, is_64bit, disas= sembler_style) < 0) goto err; =20 needs_cs_close =3D true; @@ -408,7 +408,7 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 50b9433f3f8e..96c78b01e17a 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -269,9 +269,7 @@ static int call__parse(struct arch *arch, struct ins_op= erands *ops, struct map_s { char *endptr, *tok, *name; struct map *map =3D ms->map; - struct addr_map_symbol target =3D { - .ms =3D { .map =3D map, }, - }; + struct addr_map_symbol target; =20 ops->target.addr =3D strtoull(ops->raw, &endptr, 16); =20 @@ -296,12 +294,16 @@ static int call__parse(struct arch *arch, struct ins_= operands *ops, struct map_s if (ops->target.name =3D=3D NULL) return -1; find_target: - target.addr =3D map__objdump_2mem(map, ops->target.addr); + target =3D (struct addr_map_symbol) { + .ms =3D { .map =3D map__get(map), }, + .addr =3D map__objdump_2mem(map, ops->target.addr), + }; =20 if (maps__find_ams(ms->maps, &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 + addr_map_symbol__exit(&target); return 0; =20 indirect_call: @@ -366,7 +368,7 @@ static int jump__parse(struct arch *arch, struct ins_op= erands *ops, struct map_s struct map *map =3D ms->map; struct symbol *sym =3D ms->sym; struct addr_map_symbol target =3D { - .ms =3D { .map =3D map, }, + .ms =3D { .map =3D map__get(map), }, }; const char *c =3D strchr(ops->raw, ','); u64 start, end; @@ -440,7 +442,7 @@ static int jump__parse(struct arch *arch, struct ins_op= erands *ops, struct map_s } else { ops->target.offset_avail =3D false; } - + addr_map_symbol__exit(&target); return 0; } =20 @@ -1046,7 +1048,7 @@ static size_t disasm_line_size(int nr) struct disasm_line *disasm_line__new(struct annotate_args *args) { struct disasm_line *dl =3D NULL; - struct annotation *notes =3D symbol__annotation(args->ms.sym); + struct annotation *notes =3D symbol__annotation(args->ms->sym); int nr =3D notes->src->nr_events; =20 dl =3D zalloc(disasm_line_size(nr)); @@ -1064,7 +1066,7 @@ struct disasm_line *disasm_line__new(struct annotate_= args *args) } else if (disasm_line__parse(dl->al.line, &dl->ins.name, &dl->ops.raw) = < 0) goto out_free_line; =20 - disasm_line__init_ins(dl, args->arch, &args->ms); + disasm_line__init_ins(dl, args->arch, args->ms); } =20 return dl; @@ -1119,7 +1121,7 @@ static int symbol__parse_objdump_line(struct symbol *= sym, struct annotate_args *args, char *parsed_line, int *line_nr, char **fileloc) { - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct annotation *notes =3D symbol__annotation(sym); struct disasm_line *dl; char *tmp; @@ -1151,7 +1153,7 @@ static int symbol__parse_objdump_line(struct symbol *= sym, args->line =3D parsed_line; args->line_nr =3D *line_nr; args->fileloc =3D *fileloc; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); (*line_nr)++; @@ -1172,7 +1174,7 @@ static int symbol__parse_objdump_line(struct symbol *= sym, .ms =3D { .map =3D map, }, }; =20 - if (!maps__find_ams(args->ms.maps, &target) && + if (!maps__find_ams(args->ms->maps, &target) && target.ms.sym->start =3D=3D target.al_addr) dl->ops.target.sym =3D target.ms.sym; } @@ -1338,7 +1340,7 @@ static int symbol__disassemble_raw(char *filename, st= ruct symbol *sym, struct annotate_args *args) { struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); u64 start =3D map__rip_2objdump(map, sym->start); u64 end =3D map__rip_2objdump(map, sym->end); @@ -1375,7 +1377,7 @@ static int symbol__disassemble_raw(char *filename, st= ruct symbol *sym, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) @@ -1501,7 +1503,7 @@ static int symbol__disassemble_objdump(const char *fi= lename, struct symbol *sym, struct annotate_args *args) { struct annotation_options *opts =3D &annotate_opts; - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); char *command; FILE *file; @@ -1644,7 +1646,7 @@ static int symbol__disassemble_objdump(const char *fi= lename, struct symbol *sym, int symbol__disassemble(struct symbol *sym, struct annotate_args *args) { struct annotation_options *options =3D args->options; - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); char symfs_filename[PATH_MAX]; bool delete_extract =3D false; diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index d2cb555e4a3b..a3ea9d676281 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -97,7 +97,7 @@ struct ins_ops { =20 struct annotate_args { struct arch *arch; - struct map_symbol ms; + struct map_symbol *ms; struct annotation_options *options; s64 offset; char *line; diff --git a/tools/perf/util/llvm.c b/tools/perf/util/llvm.c index 2ebf1f5f65bf..4ada9a10bd93 100644 --- a/tools/perf/util/llvm.c +++ b/tools/perf/util/llvm.c @@ -118,7 +118,7 @@ int symbol__disassemble_llvm(const char *filename, stru= ct symbol *sym, { #ifdef HAVE_LIBLLVM_SUPPORT struct annotation *notes =3D symbol__annotation(sym); - struct map *map =3D args->ms.map; + struct map *map =3D args->ms->map; struct dso *dso =3D map__dso(map); u64 start =3D map__rip_2objdump(map, sym->start); /* Malloc-ed buffer containing instructions read from disk. */ @@ -184,7 +184,7 @@ int symbol__disassemble_llvm(const char *filename, stru= ct symbol *sym, args->line =3D disasm_buf; args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 dl =3D disasm_line__new(args); if (dl =3D=3D NULL) @@ -242,7 +242,7 @@ int symbol__disassemble_llvm(const char *filename, stru= ct symbol *sym, &line_storage_len); args->line_nr =3D 0; args->fileloc =3D NULL; - args->ms.sym =3D sym; + args->ms->sym =3D sym; =20 llvm_addr2line(filename, pc, &args->fileloc, (unsigned int *)&args->line_nr, false, NULL); --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 21:24:55 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F7A648167E for ; Thu, 22 Jan 2026 07:31:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067108; cv=none; b=ELO3uOEPBIJZFSpJBOpb08SLyIqir16ekfrPTZYrXEtpD0bQD+cTqdxEY6hJcGmFpqD987fYUJ5zkyMX1VnnIym6GK2UO+ls9QGNXH3KuL4EEzSK6UeH/Qar9/5qUbNt7z/5tr9bT1tLMdstCcxiOY5+EL7GkfdiHZb+Ph38KU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067108; c=relaxed/simple; bh=Z2Z1CNYL+JGQpEAglddwhhjQLplFdYsGvVBBauh3Bto=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Qm9oteA/3bulvvZ9tMl+6lCkStxULB5hToltYtxPDp8E2IVq7kBvl4WBkkjIucAFmHwQ9sjpR2KGqe7+Xe8sQcGT8bx59uftgkKy0XP7wjP2XnNeo+y6g826M/sKOifcqZ/gbOW+/oGLGPmTLb3PVNLloZSWi/k297hsO37aoI4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mmYt/0ty; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mmYt/0ty" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-124743cf760so4725291c88.1 for ; Wed, 21 Jan 2026 23:31:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067096; x=1769671896; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=JZ50YiJoEVxCgYjte6CjV+ls97az2nN7mWUZv3Wr1mA=; b=mmYt/0tyeETjxqJVC3Rv/Bcu/5XryV+pJ8ktPapvzqp8EJHaqFQpqTxY1/DwQ8wnma 7fLcD20bRvG9UsKcayKXTRzTdi1PVN4W6JPfLQQRBBsAgT/0Tthk1EVksf341asTT7vM 8wJXqyVanqejESqkf74iQ7RvWQw6Z7kvlt9Xto2S3YeFnweWsvS2jkoCdQB3J3mei2JA SNkP98AKD/wPbr8ps/in/O8qOyKrX2y/hZLyapB1aXYKpFVeg+RYCmflYuu/oIKSnLo2 XfrzcBo/HTGE/wP7/vOpvA+6rjJuZCm+2qZIFU7SzmDyonWk++2PgDIAV/WfRc03svyr pWjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067096; x=1769671896; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JZ50YiJoEVxCgYjte6CjV+ls97az2nN7mWUZv3Wr1mA=; b=iI+sx2X3WoAOIF6m1mfZ5ab6LbKMBkEtG1HWcyc9tK2R+LjvJAE6b9blkwLix42AW+ hP8nEM/GBEtOryjXPrV1ADo2i9Yh1XXRB5XgMDYVg7Uam/c5rILTHsUD4+Vmx+ZZww/i toEco+pNzgTVuNy1kZcwk0JMiG+J3UrcjaIH3DlfzusYuBIUskKoYROSsMXbneKGsnaM YPIJLQkl30fkWMLTfCMDQutA7wNYGN1WnbdB+hbsOcsN4jPcOUcbV95Y0D7KJ3zfSzIj MbKPlG8oSjT9t6Z7Gi2E2TA1atUZpC5zmyeCPlw/8r+7VFGI99VzXWaSP6lcikEuuMYm YwfQ== X-Forwarded-Encrypted: i=1; AJvYcCUfYI0/oxexzpPpbuHPGAqQ/jJFgzQQVvvsWMTgR+ewgiezeWJ1v6JWADZB9DFWwNyCQwHMcXgZ08EOn6w=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1EloLSUl4eZ1KAY3eRk2dFxtT3OmnSfbRXBuucqBO29fvdp55 JQgYAtbQj2arIwe1p69E5ghVBsOYpNOWjloKGAoeyVuxXTaFq87bL9QBl2SXQZMu7CgPfcaOMVp 5XwW6rPPKcg== X-Received: from dll12.prod.google.com ([2002:a05:7022:20c:b0:123:17b9:69c2]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:f86:b0:11c:b397:2657 with SMTP id a92af1059eb24-1246aa90798mr5597076c88.22.1769067095464; Wed, 21 Jan 2026 23:31:35 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:19 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-4-irogers@google.com> Subject: [PATCH v1 03/11] perf disasm: Constify use of struct arch From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The struct arch holds variables that are read but not written, except during some initialization. Change most uses to be for a "const struct arch *" version to capture this immutability. Signed-off-by: Ian Rogers --- tools/perf/arch/arm64/annotate/instructions.c | 2 +- .../arch/loongarch/annotate/instructions.c | 12 ++++-- tools/perf/arch/s390/annotate/instructions.c | 7 ++-- tools/perf/arch/x86/annotate/instructions.c | 4 +- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/util/annotate-data.c | 2 +- tools/perf/util/annotate-data.h | 2 +- tools/perf/util/annotate.c | 28 ++++++------- tools/perf/util/annotate.h | 10 ++--- tools/perf/util/disasm.c | 42 ++++++++++--------- tools/perf/util/disasm.h | 14 +++---- 11 files changed, 67 insertions(+), 58 deletions(-) diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/arc= h/arm64/annotate/instructions.c index 16cb62d40bd9..5099fa36180d 100644 --- a/tools/perf/arch/arm64/annotate/instructions.c +++ b/tools/perf/arch/arm64/annotate/instructions.c @@ -10,7 +10,7 @@ struct arm64_annotate { jump_insn; }; =20 -static int arm64_mov__parse(struct arch *arch __maybe_unused, +static int arm64_mov__parse(const struct arch *arch __maybe_unused, struct ins_operands *ops, struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unused) diff --git a/tools/perf/arch/loongarch/annotate/instructions.c b/tools/perf= /arch/loongarch/annotate/instructions.c index 70262d5f1444..4ca4fb6bbcf9 100644 --- a/tools/perf/arch/loongarch/annotate/instructions.c +++ b/tools/perf/arch/loongarch/annotate/instructions.c @@ -5,8 +5,10 @@ * Copyright (C) 2020-2023 Loongson Technology Corporation Limited */ =20 -static int loongarch_call__parse(struct arch *arch, struct ins_operands *o= ps, struct map_symbol *ms, - struct disasm_line *dl __maybe_unused) +static int loongarch_call__parse(const struct arch *arch, struct ins_opera= nds *ops, + struct map_symbol *ms, + struct disasm_line *dl __maybe_unused) + { char *c, *endptr, *tok, *name; struct map *map =3D ms->map; @@ -52,8 +54,10 @@ static struct ins_ops loongarch_call_ops =3D { .scnprintf =3D call__scnprintf, }; =20 -static int loongarch_jump__parse(struct arch *arch, struct ins_operands *o= ps, struct map_symbol *ms, - struct disasm_line *dl __maybe_unused) +static int loongarch_jump__parse(const struct arch *arch, struct ins_opera= nds *ops, + struct map_symbol *ms, + struct disasm_line *dl __maybe_unused) + { struct map *map =3D ms->map; struct symbol *sym =3D ms->sym; diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/arch= /s390/annotate/instructions.c index c61193f1e096..8d66c0ea3810 100644 --- a/tools/perf/arch/s390/annotate/instructions.c +++ b/tools/perf/arch/s390/annotate/instructions.c @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 #include =20 -static int s390_call__parse(struct arch *arch, struct ins_operands *ops, - struct map_symbol *ms, struct disasm_line *dl __maybe_unused) +static int s390_call__parse(const struct arch *arch, struct ins_operands *= ops, + struct map_symbol *ms, + struct disasm_line *dl __maybe_unused) { char *endptr, *tok, *name; struct map *map =3D ms->map; @@ -50,7 +51,7 @@ static struct ins_ops s390_call_ops =3D { .scnprintf =3D call__scnprintf, }; =20 -static int s390_mov__parse(struct arch *arch __maybe_unused, +static int s390_mov__parse(const struct arch *arch __maybe_unused, struct ins_operands *ops, struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unused) diff --git a/tools/perf/arch/x86/annotate/instructions.c b/tools/perf/arch/= x86/annotate/instructions.c index 803f9351a3fb..24b388bacdae 100644 --- a/tools/perf/arch/x86/annotate/instructions.c +++ b/tools/perf/arch/x86/annotate/instructions.c @@ -119,7 +119,7 @@ static struct ins x86__instructions[] =3D { { .name =3D "xorps", .ops =3D &mov_ops, }, }; =20 -static bool amd__ins_is_fused(struct arch *arch, const char *ins1, +static bool amd__ins_is_fused(const struct arch *arch, const char *ins1, const char *ins2) { if (strstr(ins2, "jmp")) @@ -142,7 +142,7 @@ static bool amd__ins_is_fused(struct arch *arch, const = char *ins1, return false; } =20 -static bool intel__ins_is_fused(struct arch *arch, const char *ins1, +static bool intel__ins_is_fused(const struct arch *arch, const char *ins1, const char *ins2) { if (arch->family !=3D 6 || arch->model < 0x1e || strstr(ins2, "jmp")) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 36aca8d6d003..3df61cd46652 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -30,7 +30,7 @@ struct annotate_browser { struct rb_root entries; struct rb_node *curr_hot; struct annotation_line *selection; - struct arch *arch; + const struct arch *arch; /* * perf top can delete hist_entry anytime. Callers should make sure * its lifetime. diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index 07cf9c334be0..edfcd6e9df9c 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -160,7 +160,7 @@ bool has_reg_type(struct type_state *state, int reg) return (unsigned)reg < ARRAY_SIZE(state->regs); } =20 -static void init_type_state(struct type_state *state, struct arch *arch) +static void init_type_state(struct type_state *state, const struct arch *a= rch) { memset(state, 0, sizeof(*state)); INIT_LIST_HEAD(&state->stack_vars); diff --git a/tools/perf/util/annotate-data.h b/tools/perf/util/annotate-dat= a.h index 869307c7f130..9b222869e42d 100644 --- a/tools/perf/util/annotate-data.h +++ b/tools/perf/util/annotate-data.h @@ -117,7 +117,7 @@ extern struct annotated_data_type canary_type; */ struct data_loc_info { /* These are input field, should be filled by caller */ - struct arch *arch; + const struct arch *arch; struct thread *thread; struct map_symbol *ms; u64 ip; diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 791d60f97c23..132af2556aec 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -761,7 +761,7 @@ static int disasm_line__print(struct disasm_line *dl, u= 64 start, int addr_fmt_wi } =20 static struct annotated_data_type * -__hist_entry__get_data_type(struct hist_entry *he, struct arch *arch, +__hist_entry__get_data_type(struct hist_entry *he, const struct arch *arch, struct debuginfo *dbg, struct disasm_line *dl, int *type_offset); =20 @@ -980,11 +980,11 @@ void symbol__calc_percent(struct symbol *sym, struct = evsel *evsel) annotation__calc_percent(notes, evsel, symbol__size(sym)); } =20 -int evsel__get_arch(struct evsel *evsel, struct arch **parch) +int evsel__get_arch(struct evsel *evsel, const struct arch **parch) { struct perf_env *env =3D evsel__env(evsel); const char *arch_name =3D perf_env__arch(env); - struct arch *arch; + const struct arch *arch; int err; =20 if (!arch_name) { @@ -999,7 +999,7 @@ int evsel__get_arch(struct evsel *evsel, struct arch **= parch) } =20 if (arch->init) { - err =3D arch->init(arch, env ? env->cpuid : NULL); + err =3D arch->init((struct arch *)arch, env ? env->cpuid : NULL); if (err) { pr_err("%s: failed to initialize %s arch priv area\n", __func__, arch->name); @@ -1010,14 +1010,14 @@ int evsel__get_arch(struct evsel *evsel, struct arc= h **parch) } =20 int symbol__annotate(struct map_symbol *ms, struct evsel *evsel, - struct arch **parch) + const struct arch **parch) { struct symbol *sym =3D ms->sym; struct annotation *notes =3D symbol__annotation(sym); struct annotate_args args =3D { .options =3D &annotate_opts, }; - struct arch *arch =3D NULL; + const struct arch *arch =3D NULL; int err, nr; =20 err =3D evsel__get_arch(evsel, &arch); @@ -2204,7 +2204,7 @@ void annotation_line__write(struct annotation_line *a= l, struct annotation *notes } =20 int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel, - struct arch **parch) + const struct arch **parch) { struct symbol *sym =3D ms->sym; struct annotation *notes =3D symbol__annotation(sym); @@ -2457,7 +2457,7 @@ int annotate_check_args(void) * to revisit the format when it handles different architecture. * Fills @reg and @offset when return 0. */ -static int extract_reg_offset(struct arch *arch, const char *str, +static int extract_reg_offset(const struct arch *arch, const char *str, struct annotated_op_loc *op_loc) { char *p; @@ -2538,7 +2538,7 @@ static int extract_reg_offset(struct arch *arch, cons= t char *str, * # dst_reg1 =3D rbx, dst_reg2 =3D rcx, dst_= mem =3D 1 * # dst_multi_regs =3D 1, dst_offset =3D 8 */ -int annotate_get_insn_location(struct arch *arch, struct disasm_line *dl, +int annotate_get_insn_location(const struct arch *arch, struct disasm_line= *dl, struct annotated_insn_loc *loc) { struct ins_operands *ops; @@ -2673,7 +2673,7 @@ static struct annotated_item_stat *annotate_data_stat= (struct list_head *head, return istat; } =20 -static bool is_stack_operation(struct arch *arch, struct disasm_line *dl) +static bool is_stack_operation(const struct arch *arch, struct disasm_line= *dl) { if (arch__is(arch, "x86")) { if (!strncmp(dl->ins.name, "push", 4) || @@ -2686,7 +2686,7 @@ static bool is_stack_operation(struct arch *arch, str= uct disasm_line *dl) return false; } =20 -static bool is_stack_canary(struct arch *arch, struct annotated_op_loc *lo= c) +static bool is_stack_canary(const struct arch *arch, struct annotated_op_l= oc *loc) { /* On x86_64, %gs:40 is used for stack canary */ if (arch__is(arch, "x86")) { @@ -2702,7 +2702,7 @@ static bool is_stack_canary(struct arch *arch, struct= annotated_op_loc *loc) * Returns true if the instruction has a memory operand without * performing a load/store */ -static bool is_address_gen_insn(struct arch *arch, struct disasm_line *dl) +static bool is_address_gen_insn(const struct arch *arch, struct disasm_lin= e *dl) { if (arch__is(arch, "x86")) { if (!strncmp(dl->ins.name, "lea", 3)) @@ -2791,7 +2791,7 @@ void debuginfo_cache__delete(void) } =20 static struct annotated_data_type * -__hist_entry__get_data_type(struct hist_entry *he, struct arch *arch, +__hist_entry__get_data_type(struct hist_entry *he, const struct arch *arch, struct debuginfo *dbg, struct disasm_line *dl, int *type_offset) { @@ -2895,7 +2895,7 @@ struct annotated_data_type *hist_entry__get_data_type= (struct hist_entry *he) { struct map_symbol *ms =3D &he->ms; struct evsel *evsel =3D hists_to_evsel(he->hists); - struct arch *arch; + const struct arch *arch; struct disasm_line *dl; struct annotated_data_type *mem_type; struct annotated_item_stat *istat; diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index d4990bff29a7..58eaf4b2fa65 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -202,7 +202,7 @@ struct annotation_write_ops { struct annotation_print_data { struct hist_entry *he; struct evsel *evsel; - struct arch *arch; + const struct arch *arch; struct debuginfo *dbg; /* save data type info keyed by al->offset */ struct hashmap *type_hash; @@ -441,10 +441,10 @@ void symbol__annotate_zero_histograms(struct symbol *= sym); =20 int symbol__annotate(struct map_symbol *ms, struct evsel *evsel, - struct arch **parch); + const struct arch **parch); int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel, - struct arch **parch); + const struct arch **parch); =20 enum symbol_disassemble_errno { SYMBOL_ANNOTATE_ERRNO__SUCCESS =3D 0, @@ -546,7 +546,7 @@ struct annotated_insn_loc { i++, op_loc++) =20 /* Get detailed location info in the instruction */ -int annotate_get_insn_location(struct arch *arch, struct disasm_line *dl, +int annotate_get_insn_location(const struct arch *arch, struct disasm_line= *dl, struct annotated_insn_loc *loc); =20 /* Returns a data type from the sample instruction (if any) */ @@ -586,5 +586,5 @@ int annotation_br_cntr_entry(char **str, int br_cntr_nr= , u64 *br_cntr, int num_aggr, struct evsel *evsel); int annotation_br_cntr_abbr_list(char **str, struct evsel *evsel, bool hea= der); =20 -int evsel__get_arch(struct evsel *evsel, struct arch **parch); +int evsel__get_arch(struct evsel *evsel, const struct arch **parch); #endif /* __PERF_ANNOTATE_H */ diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 96c78b01e17a..d41a0f96a6f6 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -213,7 +213,7 @@ static void arch__sort(void) qsort(architectures, nmemb, sizeof(struct arch), arch__cmp); } =20 -struct arch *arch__find(const char *name) +const struct arch *arch__find(const char *name) { const int nmemb =3D ARRAY_SIZE(architectures); static bool sorted; @@ -226,7 +226,7 @@ struct arch *arch__find(const char *name) return bsearch(name, architectures, nmemb, sizeof(struct arch), arch__key= _cmp); } =20 -bool arch__is(struct arch *arch, const char *name) +bool arch__is(const struct arch *arch, const char *name) { return !strcmp(arch->name, name); } @@ -256,7 +256,7 @@ static int ins__scnprintf(struct ins *ins, char *bf, si= ze_t size, return ins__raw_scnprintf(ins, bf, size, ops, max_ins_name); } =20 -bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2) +bool ins__is_fused(const struct arch *arch, const char *ins1, const char *= ins2) { if (!arch || !arch->ins_is_fused) return false; @@ -264,7 +264,7 @@ bool ins__is_fused(struct arch *arch, const char *ins1,= const char *ins2) return arch->ins_is_fused(arch, ins1, ins2); } =20 -static int call__parse(struct arch *arch, struct ins_operands *ops, struct= map_symbol *ms, +static int call__parse(const struct arch *arch, struct ins_operands *ops, = struct map_symbol *ms, struct disasm_line *dl __maybe_unused) { char *endptr, *tok, *name; @@ -362,7 +362,7 @@ static inline const char *validate_comma(const char *c,= struct ins_operands *ops return c; } =20 -static int jump__parse(struct arch *arch, struct ins_operands *ops, struct= map_symbol *ms, +static int jump__parse(const struct arch *arch, struct ins_operands *ops, = struct map_symbol *ms, struct disasm_line *dl __maybe_unused) { struct map *map =3D ms->map; @@ -525,7 +525,7 @@ static int comment__symbol(char *raw, char *comment, u6= 4 *addrp, char **namep) return 0; } =20 -static int lock__parse(struct arch *arch, struct ins_operands *ops, struct= map_symbol *ms, +static int lock__parse(const struct arch *arch, struct ins_operands *ops, = struct map_symbol *ms, struct disasm_line *dl __maybe_unused) { ops->locked.ops =3D zalloc(sizeof(*ops->locked.ops)); @@ -592,7 +592,7 @@ static struct ins_ops lock_ops =3D { * But it doesn't care segment selectors like %gs:0x5678(%rcx), so just ch= eck * the input string after 'memory_ref_char' if exists. */ -static bool check_multi_regs(struct arch *arch, const char *op) +static bool check_multi_regs(const struct arch *arch, const char *op) { int count =3D 0; =20 @@ -613,8 +613,9 @@ static bool check_multi_regs(struct arch *arch, const c= har *op) return count > 1; } =20 -static int mov__parse(struct arch *arch, struct ins_operands *ops, struct = map_symbol *ms __maybe_unused, - struct disasm_line *dl __maybe_unused) +static int mov__parse(const struct arch *arch, struct ins_operands *ops, + struct map_symbol *ms __maybe_unused, + struct disasm_line *dl __maybe_unused) { char *s =3D strchr(ops->raw, ','), *target, *comment, prev; =20 @@ -719,7 +720,7 @@ static int arithmetic__scnprintf(struct ins *ins, char = *bf, size_t size, * - Add to Zero Extended XO-form ( Ex: addze, addzeo ) * - Subtract From Zero Extended XO-form ( Ex: subfze ) */ -static int arithmetic__parse(struct arch *arch __maybe_unused, struct ins_= operands *ops, +static int arithmetic__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, struct map_symbol *ms __maybe_unused, struct disasm_line *dl) { int opcode =3D PPC_OP(dl->raw.raw_insn); @@ -756,7 +757,7 @@ static int load_store__scnprintf(struct ins *ins, char = *bf, size_t size, * used by powerpc and since binary instruction code is used to * extract opcode, regs and offset, no other parsing is needed here */ -static int load_store__parse(struct arch *arch __maybe_unused, struct ins_= operands *ops, +static int load_store__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unu= sed) { ops->source.mem_ref =3D true; @@ -776,8 +777,9 @@ static struct ins_ops load_store_ops =3D { .scnprintf =3D load_store__scnprintf, }; =20 -static int dec__parse(struct arch *arch __maybe_unused, struct ins_operand= s *ops, struct map_symbol *ms __maybe_unused, - struct disasm_line *dl __maybe_unused) +static int dec__parse(const struct arch *arch __maybe_unused, struct ins_o= perands *ops, + struct map_symbol *ms __maybe_unused, + struct disasm_line *dl __maybe_unused) { char *target, *comment, *s, prev; =20 @@ -867,7 +869,8 @@ static void ins__sort(struct arch *arch) qsort(arch->instructions, nmemb, sizeof(struct ins), ins__cmp); } =20 -static struct ins_ops *__ins__find(struct arch *arch, const char *name, st= ruct disasm_line *dl) +static struct ins_ops *__ins__find(const struct arch *arch, const char *na= me, + struct disasm_line *dl) { struct ins *ins; const int nmemb =3D arch->nr_instructions; @@ -885,8 +888,8 @@ static struct ins_ops *__ins__find(struct arch *arch, c= onst char *name, struct d } =20 if (!arch->sorted_instructions) { - ins__sort(arch); - arch->sorted_instructions =3D true; + ins__sort((struct arch *)arch); + ((struct arch *)arch)->sorted_instructions =3D true; } =20 ins =3D bsearch(name, arch->instructions, nmemb, sizeof(struct ins), ins_= _key_cmp); @@ -913,17 +916,18 @@ static struct ins_ops *__ins__find(struct arch *arch,= const char *name, struct d return ins ? ins->ops : NULL; } =20 -struct ins_ops *ins__find(struct arch *arch, const char *name, struct disa= sm_line *dl) +struct ins_ops *ins__find(const struct arch *arch, const char *name, struc= t disasm_line *dl) { struct ins_ops *ops =3D __ins__find(arch, name, dl); =20 if (!ops && arch->associate_instruction_ops) - ops =3D arch->associate_instruction_ops(arch, name); + ops =3D arch->associate_instruction_ops((struct arch *)arch, name); =20 return ops; } =20 -static void disasm_line__init_ins(struct disasm_line *dl, struct arch *arc= h, struct map_symbol *ms) +static void disasm_line__init_ins(struct disasm_line *dl, const struct arc= h *arch, + struct map_symbol *ms) { dl->ins.ops =3D ins__find(arch, dl->ins.name, dl); =20 diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index a3ea9d676281..273a9c906514 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -30,7 +30,7 @@ struct arch { unsigned int model; unsigned int family; int (*init)(struct arch *arch, char *cpuid); - bool (*ins_is_fused)(struct arch *arch, const char *ins1, + bool (*ins_is_fused)(const struct arch *arch, const char *ins1, const char *ins2); struct { char comment_char; @@ -89,14 +89,14 @@ struct ins_operands { =20 struct ins_ops { void (*free)(struct ins_operands *ops); - int (*parse)(struct arch *arch, struct ins_operands *ops, struct map_symb= ol *ms, + int (*parse)(const struct arch *arch, struct ins_operands *ops, struct ma= p_symbol *ms, struct disasm_line *dl); int (*scnprintf)(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); }; =20 struct annotate_args { - struct arch *arch; + const struct arch *arch; struct map_symbol *ms; struct annotation_options *options; s64 offset; @@ -105,14 +105,14 @@ struct annotate_args { char *fileloc; }; =20 -struct arch *arch__find(const char *name); -bool arch__is(struct arch *arch, const char *name); +const struct arch *arch__find(const char *name); +bool arch__is(const struct arch *arch, const char *name); =20 -struct ins_ops *ins__find(struct arch *arch, const char *name, struct disa= sm_line *dl); +struct ins_ops *ins__find(const struct arch *arch, const char *name, struc= t disasm_line *dl); =20 bool ins__is_call(const struct ins *ins); bool ins__is_jump(const struct ins *ins); -bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2); +bool ins__is_fused(const struct arch *arch, const char *ins1, const char *= ins2); bool ins__is_ret(const struct ins *ins); bool ins__is_lock(const struct ins *ins); =20 --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 21:24:55 2026 Received: from mail-dl1-f73.google.com (mail-dl1-f73.google.com [74.125.82.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CBB4480DDC for ; Thu, 22 Jan 2026 07:31:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067107; cv=none; b=Qx/fnwVHgpgUujenh/WZlD5DQeFjvDGhrlDA9BY9TAsDbCh0witbNPsA2P07ql4nUY0ZggZ1mBTEydqJMX01jZpVhyaVOCDJtkjBt+vJVA7zhaPsxPDfvSn1Cox5UZENjGTMeGSw8XckrZlSmdXkX/5oFDivbif55ey0rZRF6nk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067107; c=relaxed/simple; bh=1bW1Peu/3bHriuNX0VZiSQoCul8ziTpIqzATgln7d90=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=nMPoNcvceVVPp2Vt9ZKTbYocZnlTNrunM8GY/xLyLbYsoVowsXZ/BoQF6ZJae1/ZNiMGv6aNATb69Oyuk//yFNa6W6/hGz4zyusZzuRIoeEJJgo8GJAg863myN6Hx8/d0qkELeodARi9lc+qBdB3Zkg9mP0e0FgwR9bKIzae4F8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=q430DyJ1; arc=none smtp.client-ip=74.125.82.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="q430DyJ1" Received: by mail-dl1-f73.google.com with SMTP id a92af1059eb24-124627fc58dso1350364c88.1 for ; Wed, 21 Jan 2026 23:31:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067098; x=1769671898; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=G3Q6y9uuDnZT4fchJSYQvOs3qoNM/plkLt24+BhC4KM=; b=q430DyJ1JzMiGC27Gnhb6Zzjv9Xwt7Cs3VXudQxo3LrgCa1g+WgAmmcvH5KE8wWutn mOdzH58wtunyEwAN0TPtsvPfut5UVxjRbq2KlJe9/ECg74pXGOXyi8IXNmffEI3tM/YI zglhBk3Wwh/tSpdgzHUiwdo9SUGpTE+NSQbHy8mivQyDjFPkSrCsV2nEIipX5coKIjPs RiS4quIGJpg0flVPlyOFEf+N/RvQSesd8fqDX6mFjtBzVVCUaxmJzUixJipjO+Resewq Sjevi00jSw7mBNoFx/qG4CxY52ZDCHtM9TJSDPnpJWujqckqDPuNUQli7VpJSVW4cBf8 GfCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067098; x=1769671898; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=G3Q6y9uuDnZT4fchJSYQvOs3qoNM/plkLt24+BhC4KM=; b=ePhCGVBWWpgBvIhqnucWLB4Ale7zuXY6V5kQPF5dYZwrR/1dU8GBtApkggIvVcOfer BbfnDpMF8nj66Mc4x03aBYsyqlm3c16RSQtgaLFGXEyYL0S8ZeYFmi9lPFimXvhBPK/w z2KJlRof8OSU/MFa84eyxOz87L+Wuiy6tXExSl/OO+/M9IZXSAUyQ0PUDS00knv7e8Xj buG07VPtxh82kUkpipq+FtFPGZaID8UQXrRI/r37kEA5LQoOM6B0jisaWN4qwBbadXwk javFWPPG7diGLfJbQHXSqj5M9BSS1hMkpXnEcfnFjHtGRxGLYs5D0N+OoTMYdqvChdB8 gjQQ== X-Forwarded-Encrypted: i=1; AJvYcCVcFBDZ/66mqLmUisxbNBuq5adH7ZCuEep1qhCgcH1IE+ufanptN3yISQvmh/r2C40z3bWAx9gZ1LIwN1c=@vger.kernel.org X-Gm-Message-State: AOJu0YxbLuvfzF2FcofxSpZd9MdhA+GxqAgPInUJF7caljUqSapOmnSY caZe1M+Dw07ufdfTYvmEBBaErzLSjniz89kBH90zSRu41vfWFgmJJWmc1yoz/3B/cx4EyxCkSU+ LUs8mGd627A== X-Received: from dlbvv19.prod.google.com ([2002:a05:7022:5f13:b0:119:9f33:34a6]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:6b93:b0:122:3a5:fc42 with SMTP id a92af1059eb24-1246aa67352mr4639077c88.20.1769067097397; Wed, 21 Jan 2026 23:31:37 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:20 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-5-irogers@google.com> Subject: [PATCH v1 04/11] perf disasm: Constify use of struct ins_op From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The struct ins_op holds variables to function pointers that are read but not written. Change uses to be for a "const struct ins_op *" version to capture this immutability. Signed-off-by: Ian Rogers --- tools/perf/arch/arm/annotate/instructions.c | 4 +- tools/perf/arch/arm64/annotate/instructions.c | 6 +-- tools/perf/arch/csky/annotate/instructions.c | 6 +-- .../arch/loongarch/annotate/instructions.c | 8 ++-- tools/perf/arch/mips/annotate/instructions.c | 4 +- .../perf/arch/powerpc/annotate/instructions.c | 6 +-- .../perf/arch/riscv64/annotate/instructions.c | 4 +- tools/perf/arch/s390/annotate/instructions.c | 8 ++-- tools/perf/arch/sparc/annotate/instructions.c | 4 +- tools/perf/util/disasm.c | 46 +++++++++---------- tools/perf/util/disasm.h | 6 +-- 11 files changed, 51 insertions(+), 51 deletions(-) diff --git a/tools/perf/arch/arm/annotate/instructions.c b/tools/perf/arch/= arm/annotate/instructions.c index 5e667b0f5512..b997d127fedd 100644 --- a/tools/perf/arch/arm/annotate/instructions.c +++ b/tools/perf/arch/arm/annotate/instructions.c @@ -11,10 +11,10 @@ struct arm_annotate { jump_insn; }; =20 -static struct ins_ops *arm__associate_instruction_ops(struct arch *arch, c= onst char *name) +static const struct ins_ops *arm__associate_instruction_ops(struct arch *a= rch, const char *name) { struct arm_annotate *arm =3D arch->priv; - struct ins_ops *ops; + const struct ins_ops *ops; regmatch_t match[2]; =20 if (!regexec(&arm->call_insn, name, 2, match, 0)) diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/arc= h/arm64/annotate/instructions.c index 5099fa36180d..363af2f55122 100644 --- a/tools/perf/arch/arm64/annotate/instructions.c +++ b/tools/perf/arch/arm64/annotate/instructions.c @@ -63,15 +63,15 @@ static int arm64_mov__parse(const struct arch *arch __m= aybe_unused, static int mov__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); =20 -static struct ins_ops arm64_mov_ops =3D { +static const struct ins_ops arm64_mov_ops =3D { .parse =3D arm64_mov__parse, .scnprintf =3D mov__scnprintf, }; =20 -static struct ins_ops *arm64__associate_instruction_ops(struct arch *arch,= const char *name) +static const struct ins_ops *arm64__associate_instruction_ops(struct arch = *arch, const char *name) { struct arm64_annotate *arm =3D arch->priv; - struct ins_ops *ops; + const struct ins_ops *ops; regmatch_t match[2]; =20 if (!regexec(&arm->jump_insn, name, 2, match, 0)) diff --git a/tools/perf/arch/csky/annotate/instructions.c b/tools/perf/arch= /csky/annotate/instructions.c index 14270311d215..4a55c84a320a 100644 --- a/tools/perf/arch/csky/annotate/instructions.c +++ b/tools/perf/arch/csky/annotate/instructions.c @@ -3,10 +3,10 @@ =20 #include =20 -static struct ins_ops *csky__associate_ins_ops(struct arch *arch, - const char *name) +static const struct ins_ops *csky__associate_ins_ops(struct arch *arch, + const char *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 /* catch all kind of jumps */ if (!strcmp(name, "bt") || diff --git a/tools/perf/arch/loongarch/annotate/instructions.c b/tools/perf= /arch/loongarch/annotate/instructions.c index 4ca4fb6bbcf9..ee360faad420 100644 --- a/tools/perf/arch/loongarch/annotate/instructions.c +++ b/tools/perf/arch/loongarch/annotate/instructions.c @@ -49,7 +49,7 @@ static int loongarch_call__parse(const struct arch *arch,= struct ins_operands *o return 0; } =20 -static struct ins_ops loongarch_call_ops =3D { +static const struct ins_ops loongarch_call_ops =3D { .parse =3D loongarch_call__parse, .scnprintf =3D call__scnprintf, }; @@ -98,15 +98,15 @@ static int loongarch_jump__parse(const struct arch *arc= h, struct ins_operands *o return 0; } =20 -static struct ins_ops loongarch_jump_ops =3D { +static const struct ins_ops loongarch_jump_ops =3D { .parse =3D loongarch_jump__parse, .scnprintf =3D jump__scnprintf, }; =20 static -struct ins_ops *loongarch__associate_ins_ops(struct arch *arch, const char= *name) +const struct ins_ops *loongarch__associate_ins_ops(struct arch *arch, cons= t char *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 if (!strcmp(name, "bl")) ops =3D &loongarch_call_ops; diff --git a/tools/perf/arch/mips/annotate/instructions.c b/tools/perf/arch= /mips/annotate/instructions.c index b50b46c613d6..0fbe0a7df95a 100644 --- a/tools/perf/arch/mips/annotate/instructions.c +++ b/tools/perf/arch/mips/annotate/instructions.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 =20 static -struct ins_ops *mips__associate_ins_ops(struct arch *arch, const char *nam= e) +const struct ins_ops *mips__associate_ins_ops(struct arch *arch, const cha= r *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 if (!strncmp(name, "bal", 3) || !strncmp(name, "bgezal", 6) || diff --git a/tools/perf/arch/powerpc/annotate/instructions.c b/tools/perf/a= rch/powerpc/annotate/instructions.c index ca567cfdcbdb..d1be55425e35 100644 --- a/tools/perf/arch/powerpc/annotate/instructions.c +++ b/tools/perf/arch/powerpc/annotate/instructions.c @@ -1,10 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 #include =20 -static struct ins_ops *powerpc__associate_instruction_ops(struct arch *arc= h, const char *name) +static const struct ins_ops *powerpc__associate_instruction_ops(struct arc= h *arch, const char *name) { int i; - struct ins_ops *ops; + const struct ins_ops *ops; =20 /* * - Interested only if instruction starts with 'b'. @@ -189,7 +189,7 @@ static int cmp_offset(const void *a, const void *b) return (val1->value - val2->value); } =20 -static struct ins_ops *check_ppc_insn(struct disasm_line *dl) +static const struct ins_ops *check_ppc_insn(struct disasm_line *dl) { int raw_insn =3D dl->raw.raw_insn; int opcode =3D PPC_OP(raw_insn); diff --git a/tools/perf/arch/riscv64/annotate/instructions.c b/tools/perf/a= rch/riscv64/annotate/instructions.c index 55cf911633f8..a34798864fab 100644 --- a/tools/perf/arch/riscv64/annotate/instructions.c +++ b/tools/perf/arch/riscv64/annotate/instructions.c @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0 =20 static -struct ins_ops *riscv64__associate_ins_ops(struct arch *arch, const char *= name) +const struct ins_ops *riscv64__associate_ins_ops(struct arch *arch, const = char *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 if (!strncmp(name, "jal", 3) || !strncmp(name, "jr", 2) || diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/arch= /s390/annotate/instructions.c index 8d66c0ea3810..38f7e918ebf8 100644 --- a/tools/perf/arch/s390/annotate/instructions.c +++ b/tools/perf/arch/s390/annotate/instructions.c @@ -46,7 +46,7 @@ static int s390_call__parse(const struct arch *arch, stru= ct ins_operands *ops, return 0; } =20 -static struct ins_ops s390_call_ops =3D { +static const struct ins_ops s390_call_ops =3D { .parse =3D s390_call__parse, .scnprintf =3D call__scnprintf, }; @@ -100,14 +100,14 @@ static int s390_mov__parse(const struct arch *arch __= maybe_unused, } =20 =20 -static struct ins_ops s390_mov_ops =3D { +static const struct ins_ops s390_mov_ops =3D { .parse =3D s390_mov__parse, .scnprintf =3D mov__scnprintf, }; =20 -static struct ins_ops *s390__associate_ins_ops(struct arch *arch, const ch= ar *name) +static const struct ins_ops *s390__associate_ins_ops(struct arch *arch, co= nst char *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 /* catch all kind of jumps */ if (strchr(name, 'j') || diff --git a/tools/perf/arch/sparc/annotate/instructions.c b/tools/perf/arc= h/sparc/annotate/instructions.c index 68c31580ccfc..a08d8734c883 100644 --- a/tools/perf/arch/sparc/annotate/instructions.c +++ b/tools/perf/arch/sparc/annotate/instructions.c @@ -117,9 +117,9 @@ static int is_branch_float_cond(const char *cond) return 0; } =20 -static struct ins_ops *sparc__associate_instruction_ops(struct arch *arch,= const char *name) +static const struct ins_ops *sparc__associate_instruction_ops(struct arch = *arch, const char *name) { - struct ins_ops *ops =3D NULL; + const struct ins_ops *ops =3D NULL; =20 if (!strcmp(name, "call") || !strcmp(name, "jmp") || diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index d41a0f96a6f6..dbeb89047fd1 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -33,15 +33,15 @@ static regex_t file_lineno; =20 /* These can be referred from the arch-dependent code */ -static struct ins_ops call_ops; -static struct ins_ops dec_ops; -static struct ins_ops jump_ops; -static struct ins_ops mov_ops; -static struct ins_ops nop_ops; -static struct ins_ops lock_ops; -static struct ins_ops ret_ops; -static struct ins_ops load_store_ops; -static struct ins_ops arithmetic_ops; +static const struct ins_ops call_ops; +static const struct ins_ops dec_ops; +static const struct ins_ops jump_ops; +static const struct ins_ops mov_ops; +static const struct ins_ops nop_ops; +static const struct ins_ops lock_ops; +static const struct ins_ops ret_ops; +static const struct ins_ops load_store_ops; +static const struct ins_ops arithmetic_ops; =20 static int jump__scnprintf(struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); @@ -85,7 +85,7 @@ static int arch__grow_instructions(struct arch *arch) goto out_update_instructions; } =20 -static int arch__associate_ins_ops(struct arch* arch, const char *name, st= ruct ins_ops *ops) +static int arch__associate_ins_ops(struct arch *arch, const char *name, co= nst struct ins_ops *ops) { struct ins *ins; =20 @@ -334,7 +334,7 @@ static int call__scnprintf(struct ins *ins, char *bf, s= ize_t size, return scnprintf(bf, size, "%-*s *%" PRIx64, max_ins_name, ins->name, ops= ->target.addr); } =20 -static struct ins_ops call_ops =3D { +static const struct ins_ops call_ops =3D { .parse =3D call__parse, .scnprintf =3D call__scnprintf, }; @@ -487,7 +487,7 @@ static void jump__delete(struct ins_operands *ops __may= be_unused) */ } =20 -static struct ins_ops jump_ops =3D { +static const struct ins_ops jump_ops =3D { .free =3D jump__delete, .parse =3D jump__parse, .scnprintf =3D jump__scnprintf, @@ -579,7 +579,7 @@ static void lock__delete(struct ins_operands *ops) zfree(&ops->target.name); } =20 -static struct ins_ops lock_ops =3D { +static const struct ins_ops lock_ops =3D { .free =3D lock__delete, .parse =3D lock__parse, .scnprintf =3D lock__scnprintf, @@ -688,7 +688,7 @@ static int mov__scnprintf(struct ins *ins, char *bf, si= ze_t size, ops->target.name ?: ops->target.raw); } =20 -static struct ins_ops mov_ops =3D { +static const struct ins_ops mov_ops =3D { .parse =3D mov__parse, .scnprintf =3D mov__scnprintf, }; @@ -738,7 +738,7 @@ static int arithmetic__parse(const struct arch *arch __= maybe_unused, struct ins_ return 0; } =20 -static struct ins_ops arithmetic_ops =3D { +static const struct ins_ops arithmetic_ops =3D { .parse =3D arithmetic__parse, .scnprintf =3D arithmetic__scnprintf, }; @@ -772,7 +772,7 @@ static int load_store__parse(const struct arch *arch __= maybe_unused, struct ins_ return 0; } =20 -static struct ins_ops load_store_ops =3D { +static const struct ins_ops load_store_ops =3D { .parse =3D load_store__parse, .scnprintf =3D load_store__scnprintf, }; @@ -813,7 +813,7 @@ static int dec__scnprintf(struct ins *ins, char *bf, si= ze_t size, ops->target.name ?: ops->target.raw); } =20 -static struct ins_ops dec_ops =3D { +static const struct ins_ops dec_ops =3D { .parse =3D dec__parse, .scnprintf =3D dec__scnprintf, }; @@ -824,11 +824,11 @@ static int nop__scnprintf(struct ins *ins __maybe_unu= sed, char *bf, size_t size, return scnprintf(bf, size, "%-*s", max_ins_name, "nop"); } =20 -static struct ins_ops nop_ops =3D { +static const struct ins_ops nop_ops =3D { .scnprintf =3D nop__scnprintf, }; =20 -static struct ins_ops ret_ops =3D { +static const struct ins_ops ret_ops =3D { .scnprintf =3D ins__raw_scnprintf, }; =20 @@ -869,7 +869,7 @@ static void ins__sort(struct arch *arch) qsort(arch->instructions, nmemb, sizeof(struct ins), ins__cmp); } =20 -static struct ins_ops *__ins__find(const struct arch *arch, const char *na= me, +static const struct ins_ops *__ins__find(const struct arch *arch, const ch= ar *name, struct disasm_line *dl) { struct ins *ins; @@ -880,7 +880,7 @@ static struct ins_ops *__ins__find(const struct arch *a= rch, const char *name, * For powerpc, identify the instruction ops * from the opcode using raw_insn. */ - struct ins_ops *ops; + const struct ins_ops *ops; =20 ops =3D check_ppc_insn(dl); if (ops) @@ -916,9 +916,9 @@ static struct ins_ops *__ins__find(const struct arch *a= rch, const char *name, return ins ? ins->ops : NULL; } =20 -struct ins_ops *ins__find(const struct arch *arch, const char *name, struc= t disasm_line *dl) +const struct ins_ops *ins__find(const struct arch *arch, const char *name,= struct disasm_line *dl) { - struct ins_ops *ops =3D __ins__find(arch, name, dl); + const struct ins_ops *ops =3D __ins__find(arch, name, dl); =20 if (!ops && arch->associate_instruction_ops) ops =3D arch->associate_instruction_ops((struct arch *)arch, name); diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index 273a9c906514..dc5233f2a773 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -22,7 +22,7 @@ struct arch { struct ins *instructions; size_t nr_instructions; size_t nr_instructions_allocated; - struct ins_ops *(*associate_instruction_ops)(struct arch *arch, const ch= ar *name); + const struct ins_ops *(*associate_instruction_ops)(struct arch *arch, co= nst char *name); bool sorted_instructions; bool initialized; const char *insn_suffix; @@ -52,7 +52,7 @@ struct arch { =20 struct ins { const char *name; - struct ins_ops *ops; + const struct ins_ops *ops; }; =20 struct ins_operands { @@ -108,7 +108,7 @@ struct annotate_args { const struct arch *arch__find(const char *name); bool arch__is(const struct arch *arch, const char *name); =20 -struct ins_ops *ins__find(const struct arch *arch, const char *name, struc= t disasm_line *dl); +const struct ins_ops *ins__find(const struct arch *arch, const char *name,= struct disasm_line *dl); =20 bool ins__is_call(const struct ins *ins); bool ins__is_jump(const struct ins *ins); --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 21:24:55 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E4911DFD8B for ; Thu, 22 Jan 2026 07:31:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067111; cv=none; b=sziwPVV1Mc3lm3SV56Ii0Htr/rPrN8uH2YsT1lM7LSw4dwpUO0blkdguyVakAENoAClkPrynATdIMKAHTUdakYxHfQYdxzT/RPtGl1/NrZ/Yg4au/GgK5DIRM5/XfmRvENhyHN1BGFCuvqJD8wmwXFJOILTYOzDAz6EjpBeu60o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067111; c=relaxed/simple; bh=b/qs3vQHVRuaWbgpwf4fh4a1LBiSVuL3Xr+iFzLUw6Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=QXqdgnzgJtY1U2/9mVPW4QG+gasa/l9ghijNOH4vus/Xsn6rRJHVJw3H13M32/IQTJt+qZMgQRiOuIeiws7sMH0gkZ+h+WwKM9EWYbvhKL3zgKto0guKAxpF/DLnfUbqEaEfouuPzJvBWm4TwPi+BFUa8ejYz1fQYkMPuADaIAw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lKLDgBZ4; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lKLDgBZ4" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b704019c98so768878eec.0 for ; Wed, 21 Jan 2026 23:31:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067099; x=1769671899; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=1NhvuInpc7eqBNv/e0P4EBfwFbvwk538QrbOwOslQR4=; b=lKLDgBZ4e3EMPwORd83n/2XgVNycvfXE7Ks+PQpHFp00hZ2zvIBI3OOh+5gXaZrJyk rl/p/JwE93EhdE6OVcziwHL7yNsFH1JcG2SZ4YQrO7WjFyTodewUmuMlUzgKdSUuE+Kt SIlivDzP156KFPtAa2+CSoToBNrAaDt3U2WW2uobM+l/Lk+1PQZ+mqoOr8AkDS/7DvTe S9OjnaEgtO1KbLAC/aXQxCxQ+pwT/pGVMAyMg4RZQsycHrb++w2WZwHmjTs0Lnp4rClI sIGWp47YSVYf7CWAHZt+45JvVwTM/dO5y5BX/KmOWEbMqg3l1OFw0ln82ZrvASl7NLni Ckuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067099; x=1769671899; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1NhvuInpc7eqBNv/e0P4EBfwFbvwk538QrbOwOslQR4=; b=rOlrNTZjHc7+PBhr1vlub2ZiirX//2wUAT4Q8FS2gbYEaXobO684m141qpWc2B+GNN Y8d3ovcwT9tOyquWv+Za46n3u7cZNxeLENlLsA/8ZLDv7w6oQDiIEozHBXBPyR0bRxjj ed5rmD7ajuNTQgwtOPCJmERiOnnWniXW2kKy9SqulnAJupuQn/W2PcbQvsTsjveU5Ez5 /7Ez1Phm4tCFqhBVNpdJq64gqs0NIrknn7XRo+JgJHnFXsF5oZPkdtWT2Pufl9Veqzlw 2dN6Fjd3pVFY1/NA1m+3XRQKAjTbaCyYHFKapajG8nnhKwC8Ftv7LRJjB9vHuouCyimq N8lw== X-Forwarded-Encrypted: i=1; AJvYcCVGqIQZGgmQeyocOGCSUx7hylfswHVuXxLgGaY+RPCo38/t2Zu7aI+wKCBP4J2fHHhQii7Os+EFlEwnb9s=@vger.kernel.org X-Gm-Message-State: AOJu0YxiCpHDRZQush08VPqLHbtZ4CykXdDO08Pe6jjOjHeNKIBm6kU0 TX/A7dDbeWSynf2w8DAkBwNdaubNWKCU8Tze2b5y6N/eg7CgjBsJ1VOr/DsWTYg9mIoiSx6m1j/ oF+nPS9vI3w== X-Received: from dyaw19-n2.prod.google.com ([2002:a05:693c:4153:20b0:2b4:549f:c73b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:2c17:b0:2b7:1e8f:c83a with SMTP id 5a478bee46e88-2b71e8fcdc4mr1945394eec.32.1769067099123; Wed, 21 Jan 2026 23:31:39 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:21 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-6-irogers@google.com> Subject: [PATCH v1 05/11] perf disasm: Constify use of struct ins From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The struct ins holds variables that are read but not written, except during some initialization. Change most uses to be for a "const struct ins *" version to capture this immutability. So the x86__instructions can be const pre-sort it and make the sorted variable true. Signed-off-by: Ian Rogers --- tools/perf/arch/arm64/annotate/instructions.c | 2 +- tools/perf/arch/x86/annotate/instructions.c | 26 +++++++++++---- tools/perf/util/disasm.c | 32 ++++++++++--------- tools/perf/util/disasm.h | 4 +-- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/arc= h/arm64/annotate/instructions.c index 363af2f55122..44db33854dba 100644 --- a/tools/perf/arch/arm64/annotate/instructions.c +++ b/tools/perf/arch/arm64/annotate/instructions.c @@ -60,7 +60,7 @@ static int arm64_mov__parse(const struct arch *arch __may= be_unused, return -1; } =20 -static int mov__scnprintf(struct ins *ins, char *bf, size_t size, +static int mov__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); =20 static const struct ins_ops arm64_mov_ops =3D { diff --git a/tools/perf/arch/x86/annotate/instructions.c b/tools/perf/arch/= x86/annotate/instructions.c index 24b388bacdae..ffca3029388b 100644 --- a/tools/perf/arch/x86/annotate/instructions.c +++ b/tools/perf/arch/x86/annotate/instructions.c @@ -7,7 +7,7 @@ * So this table should not have entries with the suffix unless it's * a complete different instruction than ones without the suffix. */ -static struct ins x86__instructions[] =3D { +static const struct ins x86__instructions[] =3D { { .name =3D "adc", .ops =3D &mov_ops, }, { .name =3D "add", .ops =3D &mov_ops, }, { .name =3D "addsd", .ops =3D &mov_ops, }, @@ -19,9 +19,9 @@ static struct ins x86__instructions[] =3D { { .name =3D "btr", .ops =3D &mov_ops, }, { .name =3D "bts", .ops =3D &mov_ops, }, { .name =3D "call", .ops =3D &call_ops, }, + { .name =3D "cmovae", .ops =3D &mov_ops, }, { .name =3D "cmovbe", .ops =3D &mov_ops, }, { .name =3D "cmove", .ops =3D &mov_ops, }, - { .name =3D "cmovae", .ops =3D &mov_ops, }, { .name =3D "cmp", .ops =3D &mov_ops, }, { .name =3D "cmpxch", .ops =3D &mov_ops, }, { .name =3D "cmpxchg", .ops =3D &mov_ops, }, @@ -73,23 +73,23 @@ static struct ins x86__instructions[] =3D { { .name =3D "movaps", .ops =3D &mov_ops, }, { .name =3D "movdqa", .ops =3D &mov_ops, }, { .name =3D "movdqu", .ops =3D &mov_ops, }, + { .name =3D "movsb", .ops =3D &mov_ops, }, { .name =3D "movsd", .ops =3D &mov_ops, }, + { .name =3D "movsl", .ops =3D &mov_ops, }, { .name =3D "movss", .ops =3D &mov_ops, }, - { .name =3D "movsb", .ops =3D &mov_ops, }, { .name =3D "movsw", .ops =3D &mov_ops, }, - { .name =3D "movsl", .ops =3D &mov_ops, }, { .name =3D "movupd", .ops =3D &mov_ops, }, { .name =3D "movups", .ops =3D &mov_ops, }, { .name =3D "movzb", .ops =3D &mov_ops, }, - { .name =3D "movzw", .ops =3D &mov_ops, }, { .name =3D "movzl", .ops =3D &mov_ops, }, + { .name =3D "movzw", .ops =3D &mov_ops, }, { .name =3D "mulsd", .ops =3D &mov_ops, }, { .name =3D "mulss", .ops =3D &mov_ops, }, { .name =3D "nop", .ops =3D &nop_ops, }, { .name =3D "or", .ops =3D &mov_ops, }, { .name =3D "orps", .ops =3D &mov_ops, }, - { .name =3D "pand", .ops =3D &mov_ops, }, { .name =3D "paddq", .ops =3D &mov_ops, }, + { .name =3D "pand", .ops =3D &mov_ops, }, { .name =3D "pcmpeqb", .ops =3D &mov_ops, }, { .name =3D "por", .ops =3D &mov_ops, }, { .name =3D "rcl", .ops =3D &mov_ops, }, @@ -202,6 +202,20 @@ static int x86__annotate_init(struct arch *arch, char = *cpuid) if (x86__cpuid_parse(arch, cpuid)) err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; } + +#ifndef NDEBUG + { + static bool sorted_check; + + if (!sorted_check) { + for (size_t i =3D 0; i < arch->nr_instructions - 1; i++) { + assert(strcmp(arch->instructions[i].name, + arch->instructions[i + 1].name) <=3D 0); + } + sorted_check =3D true; + } + } +#endif arch->e_machine =3D EM_X86_64; arch->e_flags =3D 0; arch->initialized =3D true; diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index dbeb89047fd1..7cfea3419041 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -43,9 +43,9 @@ static const struct ins_ops ret_ops; static const struct ins_ops load_store_ops; static const struct ins_ops arithmetic_ops; =20 -static int jump__scnprintf(struct ins *ins, char *bf, size_t size, +static int jump__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); -static int call__scnprintf(struct ins *ins, char *bf, size_t size, +static int call__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); =20 static void ins__sort(struct arch *arch); @@ -66,7 +66,8 @@ static int arch__grow_instructions(struct arch *arch) goto grow_from_non_allocated_table; =20 new_nr_allocated =3D arch->nr_instructions_allocated + 128; - new_instructions =3D realloc(arch->instructions, new_nr_allocated * sizeo= f(struct ins)); + new_instructions =3D realloc((void *)arch->instructions, + new_nr_allocated * sizeof(struct ins)); if (new_instructions =3D=3D NULL) return -1; =20 @@ -93,7 +94,7 @@ static int arch__associate_ins_ops(struct arch *arch, con= st char *name, const st arch__grow_instructions(arch)) return -1; =20 - ins =3D &arch->instructions[arch->nr_instructions]; + ins =3D (struct ins *)&arch->instructions[arch->nr_instructions]; ins->name =3D strdup(name); if (!ins->name) return -1; @@ -146,6 +147,7 @@ static struct arch architectures[] =3D { .init =3D x86__annotate_init, .instructions =3D x86__instructions, .nr_instructions =3D ARRAY_SIZE(x86__instructions), + .sorted_instructions =3D true, .insn_suffix =3D "bwlq", .objdump =3D { .comment_char =3D '#', @@ -241,13 +243,13 @@ static void ins_ops__delete(struct ins_operands *ops) zfree(&ops->target.name); } =20 -static int ins__raw_scnprintf(struct ins *ins, char *bf, size_t size, +static int ins__raw_scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, ops->raw); } =20 -static int ins__scnprintf(struct ins *ins, char *bf, size_t size, +static int ins__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { if (ins->ops->scnprintf) @@ -319,7 +321,7 @@ static int call__parse(const struct arch *arch, struct = ins_operands *ops, struct goto find_target; } =20 -static int call__scnprintf(struct ins *ins, char *bf, size_t size, +static int call__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { if (ops->target.sym) @@ -446,7 +448,7 @@ static int jump__parse(const struct arch *arch, struct = ins_operands *ops, struct return 0; } =20 -static int jump__scnprintf(struct ins *ins, char *bf, size_t size, +static int jump__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { const char *c; @@ -551,7 +553,7 @@ static int lock__parse(const struct arch *arch, struct = ins_operands *ops, struct return 0; } =20 -static int lock__scnprintf(struct ins *ins, char *bf, size_t size, +static int lock__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { int printed; @@ -680,7 +682,7 @@ static int mov__parse(const struct arch *arch, struct i= ns_operands *ops, return -1; } =20 -static int mov__scnprintf(struct ins *ins, char *bf, size_t size, +static int mov__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s,%s", max_ins_name, ins->name, @@ -699,7 +701,7 @@ static const struct ins_ops mov_ops =3D { #define ADD_ZERO_EXT_XO_FORM 202 #define SUB_ZERO_EXT_XO_FORM 200 =20 -static int arithmetic__scnprintf(struct ins *ins, char *bf, size_t size, +static int arithmetic__scnprintf(const struct ins *ins, char *bf, size_t s= ize, struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, @@ -743,7 +745,7 @@ static const struct ins_ops arithmetic_ops =3D { .scnprintf =3D arithmetic__scnprintf, }; =20 -static int load_store__scnprintf(struct ins *ins, char *bf, size_t size, +static int load_store__scnprintf(const struct ins *ins, char *bf, size_t s= ize, struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, @@ -806,7 +808,7 @@ static int dec__parse(const struct arch *arch __maybe_u= nused, struct ins_operand return 0; } =20 -static int dec__scnprintf(struct ins *ins, char *bf, size_t size, +static int dec__scnprintf(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, @@ -818,7 +820,7 @@ static const struct ins_ops dec_ops =3D { .scnprintf =3D dec__scnprintf, }; =20 -static int nop__scnprintf(struct ins *ins __maybe_unused, char *bf, size_t= size, +static int nop__scnprintf(const struct ins *ins __maybe_unused, char *bf, = size_t size, struct ins_operands *ops __maybe_unused, int max_ins_name) { return scnprintf(bf, size, "%-*s", max_ins_name, "nop"); @@ -866,7 +868,7 @@ static void ins__sort(struct arch *arch) { const int nmemb =3D arch->nr_instructions; =20 - qsort(arch->instructions, nmemb, sizeof(struct ins), ins__cmp); + qsort((void *)arch->instructions, nmemb, sizeof(struct ins), ins__cmp); } =20 static const struct ins_ops *__ins__find(const struct arch *arch, const ch= ar *name, diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index dc5233f2a773..4f5c9a985786 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -19,7 +19,7 @@ struct disasm_line; =20 struct arch { const char *name; - struct ins *instructions; + const struct ins *instructions; size_t nr_instructions; size_t nr_instructions_allocated; const struct ins_ops *(*associate_instruction_ops)(struct arch *arch, co= nst char *name); @@ -91,7 +91,7 @@ struct ins_ops { void (*free)(struct ins_operands *ops); int (*parse)(const struct arch *arch, struct ins_operands *ops, struct ma= p_symbol *ms, struct disasm_line *dl); - int (*scnprintf)(struct ins *ins, char *bf, size_t size, + int (*scnprintf)(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); }; =20 --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 21:24:55 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC844480DF9 for ; Thu, 22 Jan 2026 07:31:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067117; cv=none; b=vFPAIZxRfv/IRHK+JaryuWIg264TTXQ0RSjSG/7Y9N9B6S3hmyP3Q2/WOlyebzxFtKcQv2g7RZAu02S4F9cC6g+qshS894UnE6AIGIfFKiIT4a3fXbssS+1wDAgwS27Acv6ocCUJxfMnQ1wDIPG09+ojKAWnldhs/DypZ1BNllk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067117; c=relaxed/simple; bh=sGYJ80zb+odIeZsPqSh9Z6jfiKodLGQ+R7PjMI4z2k4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=BMUfDjKYGHksD7NoUJGrnjUe3//BWQL8/vpFV10cYM0ErCSLBaOPdmVmo75Tu3ZVQh/VewV3qsBvQzK+4MA40nzRZJOgkXJ94cRiO7qnr3PfzL1ASxLXNmiM9+CFapIZGVdW8lTtkPqQ3Fsh62l34Q5iL/m0rpURL4r/+8LO8qw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QZAggZIi; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QZAggZIi" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b71d3ac508so741401eec.0 for ; Wed, 21 Jan 2026 23:31:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067101; x=1769671901; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=eELKbKMV3ddq32Z1Vp6GPW9GgpbguHI2Z4sdCa/Txxg=; b=QZAggZIiQ30dLfzCf1K80/cu5ZrcTNKPCFvFdH2HthmT1wiIL0Xaz2+u30kBjFdTir JX5XVW1WeQD9SsbWrgU/SQW/Pmm0klZW6nNiDNCvzRhGrWlVN63++4ZilBsMwR8V61pU ijzP9o9IPsG+VClpWMWGo5HisgO+zoSufZC4dEOJscDo1llgwxGXtoKAeBGzkykf3q3l hz0OYcAncXGJCofOUTd/60BDsB2QxDWZA6zGj8UkE8+ADBOIFT/b0NExN2NO8L/YEpSX +e+u0ntDj0eyUVueeBLJFbHISIj9SLG4AzfSiZ9nUYM1wYRiNQ5pK311qIxEP25y84M2 2eRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067101; x=1769671901; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eELKbKMV3ddq32Z1Vp6GPW9GgpbguHI2Z4sdCa/Txxg=; b=I/rcJi5D5FDgqPE1qywMfaqyXLypb5ic+s5akvPeR5hY6fHtAmPQfqMfbnxGFOSkw+ +VWlHEW5IdTuexn64QPx5xYYh4OQkyVmaLHdUkiFsajkZwb6ZnGyXlFYtPFBAey3TU1I 18xie61KAbUV2cCW111WeVmK3yCNfLyQhS6sy7UHQS6J5CcTIJ1/cRhGEksa9gWTpsYR fCPUDS0YGyJU3//Rwi8tuxC5wRA5DlYaXlbZ8jdSuw2WilwPlYJGMNTyTL4ATZPB+/pA 51c6kulR0CRf7O9o6X3iYWNIOMVa2V7e/dH6YMgs7EVrXTaM5gTwfQsmDu1YYMGqiUc0 Rzlw== X-Forwarded-Encrypted: i=1; AJvYcCX/eUTXxFnwlQ1VWmLuzghQbnF2ChxsqVHm4BnANAsgwN8p0mhAFkFIV2ErQh/pEr5D5WBx4QGfnWQh3To=@vger.kernel.org X-Gm-Message-State: AOJu0YwX6HHw9gNqH8wHdF8kbdWdKNgq2rp5bo+U9hJNi7cMh55Ayg1W eeEMAO4DSFtwmdWE6FKEBW1LJWSLQ0Nl22O4UENsTl3A8m+BB6Y+TB+4Zo+vWmm+CisIo1HDQMq otoUIarPf2w== X-Received: from dlbcm36.prod.google.com ([2002:a05:7022:68a4:b0:123:2821:f02]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:2d94:b0:2b1:7486:3a06 with SMTP id 5a478bee46e88-2b6fd74750dmr4713049eec.18.1769067101320; Wed, 21 Jan 2026 23:31:41 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:22 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-7-irogers@google.com> Subject: [PATCH v1 06/11] perf disasm: Rework the string arch__is to use the ELF machine From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add new arch__is_x86 and arch__is_powerpc functions that avoid string comparisons and use the ELF machine. Remove arch__is that is no longer used. Signed-off-by: Ian Rogers --- tools/perf/util/annotate-data.c | 10 +++++----- tools/perf/util/annotate.c | 16 ++++++++-------- tools/perf/util/capstone.c | 2 +- tools/perf/util/disasm.c | 15 ++++++++++----- tools/perf/util/disasm.h | 3 ++- tools/perf/util/llvm.c | 2 +- 6 files changed, 27 insertions(+), 21 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index edfcd6e9df9c..44fbd41e3845 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -165,7 +165,7 @@ static void init_type_state(struct type_state *state, c= onst struct arch *arch) memset(state, 0, sizeof(*state)); INIT_LIST_HEAD(&state->stack_vars); =20 - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { state->regs[0].caller_saved =3D true; state->regs[1].caller_saved =3D true; state->regs[2].caller_saved =3D true; @@ -526,7 +526,7 @@ static enum type_match_result check_variable(struct dat= a_loc_info *dloc, needs_pointer =3D false; else if (reg =3D=3D dloc->fbreg || is_fbreg) needs_pointer =3D false; - else if (arch__is(dloc->arch, "x86") && reg =3D=3D X86_REG_SP) + else if (arch__is_x86(dloc->arch) && reg =3D=3D X86_REG_SP) needs_pointer =3D false; =20 /* Get the type of the variable */ @@ -1071,7 +1071,7 @@ static void delete_var_types(struct die_var_type *var= _types) /* should match to is_stack_canary() in util/annotate.c */ static void setup_stack_canary(struct data_loc_info *dloc) { - if (arch__is(dloc->arch, "x86")) { + if (arch__is_x86(dloc->arch)) { dloc->op->segment =3D INSN_SEG_X86_GS; dloc->op->imm =3D true; dloc->op->offset =3D 40; @@ -1311,7 +1311,7 @@ static enum type_match_result check_matching_type(str= uct type_state *state, =20 /* Direct this-cpu access like "%gs:0x34740" */ if (dloc->op->segment =3D=3D INSN_SEG_X86_GS && dloc->op->imm && - arch__is(dloc->arch, "x86")) { + arch__is_x86(dloc->arch)) { pr_debug_dtp("this-cpu var"); =20 addr =3D dloc->op->offset; @@ -1397,7 +1397,7 @@ static enum type_match_result find_data_type_insn(str= uct data_loc_info *dloc, =20 static int arch_supports_insn_tracking(struct data_loc_info *dloc) { - if ((arch__is(dloc->arch, "x86")) || (arch__is(dloc->arch, "powerpc"))) + if ((arch__is_x86(dloc->arch)) || (arch__is_powerpc(dloc->arch))) return 1; return 0; } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 132af2556aec..79702072568b 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2474,7 +2474,7 @@ static int extract_reg_offset(const struct arch *arch= , const char *str, * %gs:0x18(%rbx). In that case it should skip the part. */ if (*str =3D=3D arch->objdump.register_char) { - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { /* FIXME: Handle other segment registers */ if (!strncmp(str, "%gs:", 4)) op_loc->segment =3D INSN_SEG_X86_GS; @@ -2571,7 +2571,7 @@ int annotate_get_insn_location(const struct arch *arc= h, struct disasm_line *dl, op_loc->reg2 =3D -1; =20 if (insn_str =3D=3D NULL) { - if (!arch__is(arch, "powerpc")) + if (!arch__is_powerpc(arch)) continue; } =20 @@ -2580,7 +2580,7 @@ int annotate_get_insn_location(const struct arch *arc= h, struct disasm_line *dl, * required fields for op_loc, ie reg1, reg2, offset from the * raw instruction. */ - if (arch__is(arch, "powerpc")) { + if (arch__is_powerpc(arch)) { op_loc->mem_ref =3D mem_ref; op_loc->multi_regs =3D multi_regs; get_powerpc_regs(dl->raw.raw_insn, !i, op_loc); @@ -2591,7 +2591,7 @@ int annotate_get_insn_location(const struct arch *arc= h, struct disasm_line *dl, } else { char *s, *p =3D NULL; =20 - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { /* FIXME: Handle other segment registers */ if (!strncmp(insn_str, "%gs:", 4)) { op_loc->segment =3D INSN_SEG_X86_GS; @@ -2675,7 +2675,7 @@ static struct annotated_item_stat *annotate_data_stat= (struct list_head *head, =20 static bool is_stack_operation(const struct arch *arch, struct disasm_line= *dl) { - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { if (!strncmp(dl->ins.name, "push", 4) || !strncmp(dl->ins.name, "pop", 3) || !strncmp(dl->ins.name, "call", 4) || @@ -2689,7 +2689,7 @@ static bool is_stack_operation(const struct arch *arc= h, struct disasm_line *dl) static bool is_stack_canary(const struct arch *arch, struct annotated_op_l= oc *loc) { /* On x86_64, %gs:40 is used for stack canary */ - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { if (loc->segment =3D=3D INSN_SEG_X86_GS && loc->imm && loc->offset =3D=3D 40) return true; @@ -2704,7 +2704,7 @@ static bool is_stack_canary(const struct arch *arch, = struct annotated_op_loc *lo */ static bool is_address_gen_insn(const struct arch *arch, struct disasm_lin= e *dl) { - if (arch__is(arch, "x86")) { + if (arch__is_x86(arch)) { if (!strncmp(dl->ins.name, "lea", 3)) return true; } @@ -2847,7 +2847,7 @@ __hist_entry__get_data_type(struct hist_entry *he, co= nst struct arch *arch, } =20 /* This CPU access in kernel - pretend PC-relative addressing */ - if (dso__kernel(map__dso(ms->map)) && arch__is(arch, "x86") && + if (dso__kernel(map__dso(ms->map)) && arch__is_x86(arch) && op_loc->segment =3D=3D INSN_SEG_X86_GS && op_loc->imm) { dloc.var_addr =3D op_loc->offset; op_loc->reg1 =3D DWARF_REG_PC; diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c index 2c7feab61b7b..ce06cfd253ef 100644 --- a/tools/perf/util/capstone.c +++ b/tools/perf/util/capstone.c @@ -147,7 +147,7 @@ static void print_capstone_detail(cs_insn *insn, char *= buf, size_t len, struct symbol *sym; =20 /* TODO: support more architectures */ - if (!arch__is(args->arch, "x86")) + if (!arch__is_x86(args->arch)) return; =20 if (insn->detail =3D=3D NULL) diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 7cfea3419041..bc6cc7a60e3c 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -228,9 +228,14 @@ const struct arch *arch__find(const char *name) return bsearch(name, architectures, nmemb, sizeof(struct arch), arch__key= _cmp); } =20 -bool arch__is(const struct arch *arch, const char *name) +bool arch__is_x86(const struct arch *arch) { - return !strcmp(arch->name, name); + return arch->e_machine =3D=3D EM_386 || arch->e_machine =3D=3D EM_X86_64; +} + +bool arch__is_powerpc(const struct arch *arch) +{ + return arch->e_machine =3D=3D EM_PPC || arch->e_machine =3D=3D EM_PPC64; } =20 static void ins_ops__delete(struct ins_operands *ops) @@ -877,7 +882,7 @@ static const struct ins_ops *__ins__find(const struct a= rch *arch, const char *na struct ins *ins; const int nmemb =3D arch->nr_instructions; =20 - if (arch__is(arch, "powerpc")) { + if (arch__is_powerpc(arch)) { /* * For powerpc, identify the instruction ops * from the opcode using raw_insn. @@ -1066,7 +1071,7 @@ struct disasm_line *disasm_line__new(struct annotate_= args *args) goto out_delete; =20 if (args->offset !=3D -1) { - if (arch__is(args->arch, "powerpc")) { + if (arch__is_powerpc(args->arch)) { if (disasm_line__parse_powerpc(dl, args) < 0) goto out_free_line; } else if (disasm_line__parse(dl->al.line, &dl->ins.name, &dl->ops.raw) = < 0) @@ -1698,7 +1703,7 @@ int symbol__disassemble(struct symbol *sym, struct an= notate_args *args) * and typeoff, disassemble to mnemonic notation is not required in * case of powerpc. */ - if (arch__is(args->arch, "powerpc")) { + if (arch__is_powerpc(args->arch)) { extern const char *sort_order; =20 if (sort_order && !strstr(sort_order, "sym")) { diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index 4f5c9a985786..db7f1ee3d8e7 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -106,7 +106,8 @@ struct annotate_args { }; =20 const struct arch *arch__find(const char *name); -bool arch__is(const struct arch *arch, const char *name); +bool arch__is_x86(const struct arch *arch); +bool arch__is_powerpc(const struct arch *arch); =20 const struct ins_ops *ins__find(const struct arch *arch, const char *name,= struct disasm_line *dl); =20 diff --git a/tools/perf/util/llvm.c b/tools/perf/util/llvm.c index 4ada9a10bd93..0d126d233c01 100644 --- a/tools/perf/util/llvm.c +++ b/tools/perf/util/llvm.c @@ -146,7 +146,7 @@ int symbol__disassemble_llvm(const char *filename, stru= ct symbol *sym, return errno; =20 init_llvm(); - if (arch__is(args->arch, "x86")) { + if (arch__is_x86(args->arch)) { const char *triplet =3D is_64bit ? "x86_64-pc-linux" : "i686-pc-linux"; =20 disasm =3D LLVMCreateDisasm(triplet, &storage, /*tag_type=3D*/0, --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 21:24:55 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE8DA481664 for ; Thu, 22 Jan 2026 07:31:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067114; cv=none; b=nwrsAlgKyZyipUSv8ZuXYBB++JQrisIK6REvT5zmIoujSunJ/H9NdK6i8vwAyap3RsfMlvqxvoYNeFXmlj6IkJXEGBERU6IP0GBdM3qSnXfwQr9R0MTV5h9J7IjmTeq5HMEPxd6nzmNm6/8duEHDI0KZswColAI86b8ZGHjM8EU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067114; c=relaxed/simple; bh=2GEq2uGlZak3EgP0bLh7VMuXSq1oblPbD0IJ1qr0VMQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ehyvpFAAQ33YyfI4rrAmZj82nIte97nArbdKTG75rkAeSacmEX+9zAtbvzhftT9pv91r/Cknp4Eh86SDTO98QV9DnJqaQ5RI/7FHIJLYj0fcfGaZENTPcSreewgeUxj/tF5mZ8Ycf4hZr+vMvVTO3NloL7f8vfR3b11P5Qp04NM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NSfHB9T/; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NSfHB9T/" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b71d3ac508so741423eec.0 for ; Wed, 21 Jan 2026 23:31:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067103; x=1769671903; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=i9j1+WJLbXytN79X7IJ2Xii1Iy6qSIPvyAIybyoQBvM=; b=NSfHB9T/58t7wuJVwlbkAJ+r9aX4k4p3NZQ3R5ysoaz/PzcaZovn/IwQc0qLLsLIN9 FrYCxtdGPaPxOZSOWRZjrbCE3EZmUjViTHpzjVZO7sHrz3e62HSH/GU0k6y0hn0XHstN OO7rlF/Q4Bgh0WFxD/eGXXQBY2yNq8Nc6jmGMDOgqylGiaiZktF7qlzSU+e5cqRt1yTx NbF3fLanPHMO8o8G3M5wmNeLoNxnSYoMI4prErKxaD5RfGB1G3Qurmi7WvX6KUjiVGL0 tRZUMPQsK8h85VJY5sBA9NG5uFyfp92yRa4Ekk022HSIa/NqDEU1BX2I4VLLrrhgP1cx euMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067103; x=1769671903; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=i9j1+WJLbXytN79X7IJ2Xii1Iy6qSIPvyAIybyoQBvM=; b=F9AYMNK5ZYFUxQ6uvqvy5vnLJ+7cRACZ24LpVUBEbY64pkr26e1dgPWBv+Qb7IkB5I 6czBHnUCQoMmUMcJkWpI22arObf0nrTIq/Qh95FKsihl0PUNwUa9M0H2660jKs4XWOFc PRKQ44wh3l3pHeWzxmIr+jUXhMXofTt5M1vfLC8Eh9vUMeTp4pW0LnBsrwqWd5Oc16vy bz+7aUloNpJpQhx75OO+ycQ7rXh5qey9BikO4fJgGlVpCJvVWrhFetQH3WRDAWb/meVl XLVvT+ZMpdbbWkaLXfCy52Q8Z1rhj/VakpwOCJLx2R8kmB0ETtZvDRpv95EMmjViNo2q EhyQ== X-Forwarded-Encrypted: i=1; AJvYcCVs1ssO4ytEYGuEVLpW3l7uLBKPwI7OKWIZ5G3uFv3xKTQX9W0ZIoDDzQcE98bSKT4brwOwIQ4Gkif08N0=@vger.kernel.org X-Gm-Message-State: AOJu0YxOjlBs7Jswr839Od1gozOumw/pfHnNkmOcbuDqWnQDooC7a8Hq ObaPCmcX7WWlSTCpNsKLT5eqNYLjpKlcXIudG2bjZVLZaruqEGVTlHBpLW46QgYvcPKLZ47ej0R XXwtoqKQNdQ== X-Received: from dybtv7.prod.google.com ([2002:a05:7300:f487:b0:2a4:612e:b41f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:60d6:b0:2b7:2ae8:9b0d with SMTP id 5a478bee46e88-2b72ae8a816mr511795eec.3.1769067103279; Wed, 21 Jan 2026 23:31:43 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:23 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-8-irogers@google.com> Subject: [PATCH v1 07/11] perf disasm: Don't include C files from the arch directory From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the arch instructions.c files into appropriately named files in annotate-arch in the util directory. Don't #include to compile the code, switch to building the files and fix up the #includes accordingly. Move powerpc specific disasm code out of disasm.c and into annotate-powerpc.c. Declarations and static removed as appropriate for the code to compile as separate compilation units. The e_machine and e_flags set up is moved to the disasm.c architectures array so that later patches can sort by them. Signed-off-by: Ian Rogers --- tools/perf/util/Build | 1 + tools/perf/util/annotate-arch/Build | 11 + .../annotate-arch/annotate-arc.c} | 5 +- .../annotate-arch/annotate-arm.c} | 9 +- .../annotate-arch/annotate-arm64.c} | 14 +- .../annotate-arch/annotate-csky.c} | 11 +- .../annotate-arch/annotate-loongarch.c} | 15 +- .../annotate-arch/annotate-mips.c} | 6 +- .../annotate-arch/annotate-powerpc.c} | 105 ++++++++- .../annotate-arch/annotate-riscv64.c} | 6 +- .../annotate-arch/annotate-s390.c} | 15 +- .../annotate-arch/annotate-sparc.c} | 7 +- .../annotate-arch/annotate-x86.c} | 85 +++++--- tools/perf/util/disasm.c | 199 ++++-------------- tools/perf/util/disasm.h | 38 ++++ 15 files changed, 289 insertions(+), 238 deletions(-) create mode 100644 tools/perf/util/annotate-arch/Build rename tools/perf/{arch/arc/annotate/instructions.c =3D> util/annotate-arc= h/annotate-arc.c} (53%) rename tools/perf/{arch/arm/annotate/instructions.c =3D> util/annotate-arc= h/annotate-arm.c} (90%) rename tools/perf/{arch/arm64/annotate/instructions.c =3D> util/annotate-a= rch/annotate-arm64.c} (90%) rename tools/perf/{arch/csky/annotate/instructions.c =3D> util/annotate-ar= ch/annotate-csky.c} (83%) rename tools/perf/{arch/loongarch/annotate/instructions.c =3D> util/annota= te-arch/annotate-loongarch.c} (93%) rename tools/perf/{arch/mips/annotate/instructions.c =3D> util/annotate-ar= ch/annotate-mips.c} (94%) rename tools/perf/{arch/powerpc/annotate/instructions.c =3D> util/annotate= -arch/annotate-powerpc.c} (76%) rename tools/perf/{arch/riscv64/annotate/instructions.c =3D> util/annotate= -arch/annotate-riscv64.c} (91%) rename tools/perf/{arch/s390/annotate/instructions.c =3D> util/annotate-ar= ch/annotate-s390.c} (91%) rename tools/perf/{arch/sparc/annotate/instructions.c =3D> util/annotate-a= rch/annotate-sparc.c} (96%) rename tools/perf/{arch/x86/annotate/instructions.c =3D> util/annotate-arc= h/annotate-x86.c} (97%) diff --git a/tools/perf/util/Build b/tools/perf/util/Build index c30ff257f8b4..b9925c6902ca 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -1,6 +1,7 @@ include $(srctree)/tools/scripts/Makefile.include include $(srctree)/tools/scripts/utilities.mak =20 +perf-util-y +=3D annotate-arch/ perf-util-y +=3D arm64-frame-pointer-unwind-support.o perf-util-y +=3D addr2line.o perf-util-y +=3D addr_location.o diff --git a/tools/perf/util/annotate-arch/Build b/tools/perf/util/annotate= -arch/Build new file mode 100644 index 000000000000..23316743fdc5 --- /dev/null +++ b/tools/perf/util/annotate-arch/Build @@ -0,0 +1,11 @@ +perf-util-y +=3D annotate-arc.o +perf-util-y +=3D annotate-arm.o +perf-util-y +=3D annotate-arm64.o +perf-util-y +=3D annotate-csky.o +perf-util-y +=3D annotate-loongarch.o +perf-util-y +=3D annotate-mips.o +perf-util-y +=3D annotate-x86.o +perf-util-y +=3D annotate-powerpc.o +perf-util-y +=3D annotate-riscv64.o +perf-util-y +=3D annotate-s390.o +perf-util-y +=3D annotate-sparc.o diff --git a/tools/perf/arch/arc/annotate/instructions.c b/tools/perf/util/= annotate-arch/annotate-arc.c similarity index 53% rename from tools/perf/arch/arc/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-arc.c index e5619770a1af..d7ca08ca5600 100644 --- a/tools/perf/arch/arc/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-arc.c @@ -1,11 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include "../disasm.h" =20 -static int arc__annotate_init(struct arch *arch, char *cpuid __maybe_unuse= d) +int arc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { arch->initialized =3D true; arch->objdump.comment_char =3D ';'; - arch->e_machine =3D EM_ARC; - arch->e_flags =3D 0; return 0; } diff --git a/tools/perf/arch/arm/annotate/instructions.c b/tools/perf/util/= annotate-arch/annotate-arm.c similarity index 90% rename from tools/perf/arch/arm/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-arm.c index b997d127fedd..08c49067c3c9 100644 --- a/tools/perf/arch/arm/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-arm.c @@ -1,10 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include #include -#include #include -#include +#include "../annotate.h" +#include "../disasm.h" =20 struct arm_annotate { regex_t call_insn, @@ -28,7 +29,7 @@ static const struct ins_ops *arm__associate_instruction_o= ps(struct arch *arch, c return ops; } =20 -static int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unuse= d) +int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { struct arm_annotate *arm; int err; @@ -54,8 +55,6 @@ static int arm__annotate_init(struct arch *arch, char *cp= uid __maybe_unused) arch->associate_instruction_ops =3D arm__associate_instruction_ops; arch->objdump.comment_char =3D ';'; arch->objdump.skip_functions_char =3D '+'; - arch->e_machine =3D EM_ARM; - arch->e_flags =3D 0; return 0; =20 out_free_call: diff --git a/tools/perf/arch/arm64/annotate/instructions.c b/tools/perf/uti= l/annotate-arch/annotate-arm64.c similarity index 90% rename from tools/perf/arch/arm64/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-arm64.c index 44db33854dba..d2ea32984b0d 100644 --- a/tools/perf/arch/arm64/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-arm64.c @@ -1,9 +1,12 @@ // SPDX-License-Identifier: GPL-2.0 #include #include -#include -#include #include +#include +#include +#include +#include "../annotate.h" +#include "../disasm.h" =20 struct arm64_annotate { regex_t call_insn, @@ -60,9 +63,6 @@ static int arm64_mov__parse(const struct arch *arch __may= be_unused, return -1; } =20 -static int mov__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name); - static const struct ins_ops arm64_mov_ops =3D { .parse =3D arm64_mov__parse, .scnprintf =3D mov__scnprintf, @@ -87,7 +87,7 @@ static const struct ins_ops *arm64__associate_instruction= _ops(struct arch *arch, return ops; } =20 -static int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unu= sed) +int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { struct arm64_annotate *arm; int err; @@ -114,8 +114,6 @@ static int arm64__annotate_init(struct arch *arch, char= *cpuid __maybe_unused) arch->associate_instruction_ops =3D arm64__associate_instruction_ops; arch->objdump.comment_char =3D '/'; arch->objdump.skip_functions_char =3D '+'; - arch->e_machine =3D EM_AARCH64; - arch->e_flags =3D 0; return 0; =20 out_free_call: diff --git a/tools/perf/arch/csky/annotate/instructions.c b/tools/perf/util= /annotate-arch/annotate-csky.c similarity index 83% rename from tools/perf/arch/csky/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-csky.c index 4a55c84a320a..0b0b09b068ec 100644 --- a/tools/perf/arch/csky/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-csky.c @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 // Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. - +#include #include +#include "../disasm.h" =20 static const struct ins_ops *csky__associate_ins_ops(struct arch *arch, const char *name) @@ -38,16 +39,10 @@ static const struct ins_ops *csky__associate_ins_ops(st= ruct arch *arch, return ops; } =20 -static int csky__annotate_init(struct arch *arch, char *cpuid __maybe_unus= ed) +int csky__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { arch->initialized =3D true; arch->objdump.comment_char =3D '/'; arch->associate_instruction_ops =3D csky__associate_ins_ops; - arch->e_machine =3D EM_CSKY; -#if defined(__CSKYABIV2__) - arch->e_flags =3D EF_CSKY_ABIV2; -#else - arch->e_flags =3D EF_CSKY_ABIV1; -#endif return 0; } diff --git a/tools/perf/arch/loongarch/annotate/instructions.c b/tools/perf= /util/annotate-arch/annotate-loongarch.c similarity index 93% rename from tools/perf/arch/loongarch/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-loongarch.c index ee360faad420..4bd651b63652 100644 --- a/tools/perf/arch/loongarch/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-loongarch.c @@ -4,11 +4,17 @@ * * Copyright (C) 2020-2023 Loongson Technology Corporation Limited */ +#include +#include +#include +#include "../disasm.h" +#include "../map.h" +#include "../maps.h" +#include "../symbol.h" =20 static int loongarch_call__parse(const struct arch *arch, struct ins_opera= nds *ops, struct map_symbol *ms, struct disasm_line *dl __maybe_unused) - { char *c, *endptr, *tok, *name; struct map *map =3D ms->map; @@ -49,7 +55,7 @@ static int loongarch_call__parse(const struct arch *arch,= struct ins_operands *o return 0; } =20 -static const struct ins_ops loongarch_call_ops =3D { +const struct ins_ops loongarch_call_ops =3D { .parse =3D loongarch_call__parse, .scnprintf =3D call__scnprintf, }; @@ -98,7 +104,7 @@ static int loongarch_jump__parse(const struct arch *arch= , struct ins_operands *o return 0; } =20 -static const struct ins_ops loongarch_jump_ops =3D { +const struct ins_ops loongarch_jump_ops =3D { .parse =3D loongarch_jump__parse, .scnprintf =3D jump__scnprintf, }; @@ -128,15 +134,12 @@ const struct ins_ops *loongarch__associate_ins_ops(st= ruct arch *arch, const char return ops; } =20 -static int loongarch__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { if (!arch->initialized) { arch->associate_instruction_ops =3D loongarch__associate_ins_ops; arch->initialized =3D true; arch->objdump.comment_char =3D '#'; - arch->e_machine =3D EM_LOONGARCH; - arch->e_flags =3D 0; } =20 return 0; diff --git a/tools/perf/arch/mips/annotate/instructions.c b/tools/perf/util= /annotate-arch/annotate-mips.c similarity index 94% rename from tools/perf/arch/mips/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-mips.c index 0fbe0a7df95a..f14b34ed77d3 100644 --- a/tools/perf/arch/mips/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-mips.c @@ -1,4 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include "../disasm.h" =20 static const struct ins_ops *mips__associate_ins_ops(struct arch *arch, const cha= r *name) @@ -33,15 +36,12 @@ const struct ins_ops *mips__associate_ins_ops(struct ar= ch *arch, const char *nam return ops; } =20 -static int mips__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { if (!arch->initialized) { arch->associate_instruction_ops =3D mips__associate_ins_ops; arch->initialized =3D true; arch->objdump.comment_char =3D '#'; - arch->e_machine =3D EM_MIPS; - arch->e_flags =3D 0; } =20 return 0; diff --git a/tools/perf/arch/powerpc/annotate/instructions.c b/tools/perf/u= til/annotate-arch/annotate-powerpc.c similarity index 76% rename from tools/perf/arch/powerpc/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-powerpc.c index d1be55425e35..593c138c8104 100644 --- a/tools/perf/arch/powerpc/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-powerpc.c @@ -1,5 +1,97 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include +#include +#include "../annotate-data.h" +#include "../debug.h" +#include "../disasm.h" + +#define PPC_OP(op) (((op) >> 26) & 0x3F) +#define PPC_21_30(R) (((R) >> 1) & 0x3ff) +#define PPC_22_30(R) (((R) >> 1) & 0x1ff) + +#define MINUS_EXT_XO_FORM 234 +#define SUB_EXT_XO_FORM 232 +#define ADD_ZERO_EXT_XO_FORM 202 +#define SUB_ZERO_EXT_XO_FORM 200 + +static int arithmetic__scnprintf(const struct ins *ins, char *bf, size_t s= ize, + struct ins_operands *ops, int max_ins_name) +{ + return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, + ops->raw); +} + +/* + * Sets the fields: multi_regs and "mem_ref". + * "mem_ref" is set for ops->source which is later used to + * fill the objdump->memory_ref-char field. This ops is currently + * used by powerpc and since binary instruction code is used to + * extract opcode, regs and offset, no other parsing is needed here. + * + * Dont set multi regs for 4 cases since it has only one operand + * for source: + * - Add to Minus One Extended XO-form ( Ex: addme, addmeo ) + * - Subtract From Minus One Extended XO-form ( Ex: subfme ) + * - Add to Zero Extended XO-form ( Ex: addze, addzeo ) + * - Subtract From Zero Extended XO-form ( Ex: subfze ) + */ +static int arithmetic__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, + struct map_symbol *ms __maybe_unused, struct disasm_line *dl) +{ + int opcode =3D PPC_OP(dl->raw.raw_insn); + + ops->source.mem_ref =3D false; + if (opcode =3D=3D 31) { + if ((opcode !=3D MINUS_EXT_XO_FORM) && (opcode !=3D SUB_EXT_XO_FORM) && + (opcode !=3D ADD_ZERO_EXT_XO_FORM) && (opcode !=3D SUB_ZERO_EXT_XO_F= ORM)) + ops->source.multi_regs =3D true; + } + + ops->target.mem_ref =3D false; + ops->target.multi_regs =3D false; + + return 0; +} + +static const struct ins_ops arithmetic_ops =3D { + .parse =3D arithmetic__parse, + .scnprintf =3D arithmetic__scnprintf, +}; + +static int load_store__scnprintf(const struct ins *ins, char *bf, size_t s= ize, + struct ins_operands *ops, int max_ins_name) +{ + return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, + ops->raw); +} + +/* + * Sets the fields: multi_regs and "mem_ref". + * "mem_ref" is set for ops->source which is later used to + * fill the objdump->memory_ref-char field. This ops is currently + * used by powerpc and since binary instruction code is used to + * extract opcode, regs and offset, no other parsing is needed here + */ +static int load_store__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, + struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unu= sed) +{ + ops->source.mem_ref =3D true; + ops->source.multi_regs =3D false; + /* opcode 31 is of X form */ + if (PPC_OP(dl->raw.raw_insn) =3D=3D 31) + ops->source.multi_regs =3D true; + + ops->target.mem_ref =3D false; + ops->target.multi_regs =3D false; + + return 0; +} + +static const struct ins_ops load_store_ops =3D { + .parse =3D load_store__parse, + .scnprintf =3D load_store__scnprintf, +}; =20 static const struct ins_ops *powerpc__associate_instruction_ops(struct arc= h *arch, const char *name) { @@ -49,10 +141,6 @@ static const struct ins_ops *powerpc__associate_instruc= tion_ops(struct arch *arc return ops; } =20 -#define PPC_OP(op) (((op) >> 26) & 0x3F) -#define PPC_21_30(R) (((R) >> 1) & 0x3ff) -#define PPC_22_30(R) (((R) >> 1) & 0x1ff) - struct insn_offset { const char *name; int value; @@ -189,7 +277,7 @@ static int cmp_offset(const void *a, const void *b) return (val1->value - val2->value); } =20 -static const struct ins_ops *check_ppc_insn(struct disasm_line *dl) +const struct ins_ops *check_ppc_insn(struct disasm_line *dl) { int raw_insn =3D dl->raw.raw_insn; int opcode =3D PPC_OP(raw_insn); @@ -302,15 +390,16 @@ static void update_insn_state_powerpc(struct type_sta= te *state, } #endif /* HAVE_LIBDW_SUPPORT */ =20 -static int powerpc__annotate_init(struct arch *arch, char *cpuid __maybe_u= nused) +int powerpc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { if (!arch->initialized) { arch->initialized =3D true; arch->associate_instruction_ops =3D powerpc__associate_instruction_ops; arch->objdump.comment_char =3D '#'; annotate_opts.show_asm_raw =3D true; - arch->e_machine =3D EM_PPC; - arch->e_flags =3D 0; +#ifdef HAVE_LIBDW_SUPPORT + arch->update_insn_state =3D update_insn_state_powerpc; +#endif } =20 return 0; diff --git a/tools/perf/arch/riscv64/annotate/instructions.c b/tools/perf/u= til/annotate-arch/annotate-riscv64.c similarity index 91% rename from tools/perf/arch/riscv64/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-riscv64.c index a34798864fab..15526824037a 100644 --- a/tools/perf/arch/riscv64/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-riscv64.c @@ -1,4 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include "../disasm.h" =20 static const struct ins_ops *riscv64__associate_ins_ops(struct arch *arch, const = char *name) @@ -21,15 +24,12 @@ const struct ins_ops *riscv64__associate_ins_ops(struct= arch *arch, const char * return ops; } =20 -static int riscv64__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { if (!arch->initialized) { arch->associate_instruction_ops =3D riscv64__associate_ins_ops; arch->initialized =3D true; arch->objdump.comment_char =3D '#'; - arch->e_machine =3D EM_RISCV; - arch->e_flags =3D 0; } =20 return 0; diff --git a/tools/perf/arch/s390/annotate/instructions.c b/tools/perf/util= /annotate-arch/annotate-s390.c similarity index 91% rename from tools/perf/arch/s390/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-s390.c index 38f7e918ebf8..c1d06caa5f77 100644 --- a/tools/perf/arch/s390/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-s390.c @@ -1,5 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include +#include "../debug.h" +#include "../disasm.h" +#include "../map.h" +#include "../maps.h" +#include "../symbol.h" +#include "../annotate.h" +#include "../annotate-data.h" =20 static int s390_call__parse(const struct arch *arch, struct ins_operands *= ops, struct map_symbol *ms, @@ -46,7 +54,7 @@ static int s390_call__parse(const struct arch *arch, stru= ct ins_operands *ops, return 0; } =20 -static const struct ins_ops s390_call_ops =3D { +const struct ins_ops s390_call_ops =3D { .parse =3D s390_call__parse, .scnprintf =3D call__scnprintf, }; @@ -156,7 +164,7 @@ static int s390__cpuid_parse(struct arch *arch, char *c= puid) return -1; } =20 -static int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unus= ed) +int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { int err =3D 0; =20 @@ -167,8 +175,7 @@ static int s390__annotate_init(struct arch *arch, char = *cpuid __maybe_unused) if (s390__cpuid_parse(arch, cpuid)) err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; } - arch->e_machine =3D EM_S390; - arch->e_flags =3D 0; + arch->objdump.comment_char =3D '#'; } =20 return err; diff --git a/tools/perf/arch/sparc/annotate/instructions.c b/tools/perf/uti= l/annotate-arch/annotate-sparc.c similarity index 96% rename from tools/perf/arch/sparc/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-sparc.c index a08d8734c883..66a0174376dd 100644 --- a/tools/perf/arch/sparc/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-sparc.c @@ -1,4 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include "../../util/disasm.h" =20 static int is_branch_cond(const char *cond) { @@ -157,14 +160,12 @@ static const struct ins_ops *sparc__associate_instruc= tion_ops(struct arch *arch, return ops; } =20 -static int sparc__annotate_init(struct arch *arch, char *cpuid __maybe_unu= sed) +int sparc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) { if (!arch->initialized) { arch->initialized =3D true; arch->associate_instruction_ops =3D sparc__associate_instruction_ops; arch->objdump.comment_char =3D '#'; - arch->e_machine =3D EM_SPARC; - arch->e_flags =3D 0; } =20 return 0; diff --git a/tools/perf/arch/x86/annotate/instructions.c b/tools/perf/util/= annotate-arch/annotate-x86.c similarity index 97% rename from tools/perf/arch/x86/annotate/instructions.c rename to tools/perf/util/annotate-arch/annotate-x86.c index ffca3029388b..0c7957fe60da 100644 --- a/tools/perf/arch/x86/annotate/instructions.c +++ b/tools/perf/util/annotate-arch/annotate-x86.c @@ -1,4 +1,16 @@ // SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include "../annotate-data.h" +#include "../debug.h" +#include "../disasm.h" +#include "../dso.h" +#include "../map.h" +#include "../string2.h" // strstarts +#include "../symbol.h" + /* * x86 instruction nmemonic table to parse disasm lines for annotate. * This table is searched twice - one for exact match and another for @@ -191,37 +203,6 @@ static int x86__cpuid_parse(struct arch *arch, char *c= puid) return -1; } =20 -static int x86__annotate_init(struct arch *arch, char *cpuid) -{ - int err =3D 0; - - if (arch->initialized) - return 0; - - if (cpuid) { - if (x86__cpuid_parse(arch, cpuid)) - err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; - } - -#ifndef NDEBUG - { - static bool sorted_check; - - if (!sorted_check) { - for (size_t i =3D 0; i < arch->nr_instructions - 1; i++) { - assert(strcmp(arch->instructions[i].name, - arch->instructions[i + 1].name) <=3D 0); - } - sorted_check =3D true; - } - } -#endif - arch->e_machine =3D EM_X86_64; - arch->e_flags =3D 0; - arch->initialized =3D true; - return err; -} - #ifdef HAVE_LIBDW_SUPPORT static void update_insn_state_x86(struct type_state *state, struct data_loc_info *dloc, Dwarf_Die *cu_die, @@ -795,3 +776,45 @@ static void update_insn_state_x86(struct type_state *s= tate, /* Case 4. memory to memory transfers (not handled for now) */ } #endif + +int x86__annotate_init(struct arch *arch, char *cpuid) +{ + int err =3D 0; + + if (arch->initialized) + return 0; + + if (cpuid) { + if (x86__cpuid_parse(arch, cpuid)) + err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; + } + + arch->instructions =3D x86__instructions; + arch->nr_instructions =3D ARRAY_SIZE(x86__instructions); +#ifndef NDEBUG + { + static bool sorted_check; + + if (!sorted_check) { + for (size_t i =3D 0; i < arch->nr_instructions - 1; i++) { + assert(strcmp(arch->instructions[i].name, + arch->instructions[i + 1].name) <=3D 0); + } + sorted_check =3D true; + } + } +#endif + arch->sorted_instructions =3D true; + arch->objdump.comment_char =3D '#'; + arch->objdump.register_char =3D '%'; + arch->objdump.memory_ref_char =3D '('; + arch->objdump.imm_char =3D '$'; + arch->insn_suffix =3D "bwlq"; + arch->e_machine =3D EM_X86_64; + arch->e_flags =3D 0; + arch->initialized =3D true; +#ifdef HAVE_LIBDW_SUPPORT + arch->update_insn_state =3D update_insn_state_x86; +#endif + return err; +} diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index bc6cc7a60e3c..c732b015f2e8 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -33,20 +33,15 @@ static regex_t file_lineno; =20 /* These can be referred from the arch-dependent code */ -static const struct ins_ops call_ops; -static const struct ins_ops dec_ops; -static const struct ins_ops jump_ops; -static const struct ins_ops mov_ops; -static const struct ins_ops nop_ops; -static const struct ins_ops lock_ops; -static const struct ins_ops ret_ops; -static const struct ins_ops load_store_ops; -static const struct ins_ops arithmetic_ops; - -static int jump__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name); -static int call__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name); +const struct ins_ops call_ops; +const struct ins_ops dec_ops; +const struct ins_ops jump_ops; +const struct ins_ops mov_ops; +const struct ins_ops nop_ops; +const struct ins_ops lock_ops; +const struct ins_ops ret_ops; +const struct ins_ops load_store_ops; +const struct ins_ops arithmetic_ops; =20 static void ins__sort(struct arch *arch); static int disasm_line__parse(char *line, const char **namep, char **rawp); @@ -86,7 +81,7 @@ static int arch__grow_instructions(struct arch *arch) goto out_update_instructions; } =20 -static int arch__associate_ins_ops(struct arch *arch, const char *name, co= nst struct ins_ops *ops) +int arch__associate_ins_ops(struct arch *arch, const char *name, const str= uct ins_ops *ops) { struct ins *ins; =20 @@ -106,90 +101,66 @@ static int arch__associate_ins_ops(struct arch *arch,= const char *name, const st return 0; } =20 -#include "arch/arc/annotate/instructions.c" -#include "arch/arm/annotate/instructions.c" -#include "arch/arm64/annotate/instructions.c" -#include "arch/csky/annotate/instructions.c" -#include "arch/loongarch/annotate/instructions.c" -#include "arch/mips/annotate/instructions.c" -#include "arch/x86/annotate/instructions.c" -#include "arch/powerpc/annotate/instructions.c" -#include "arch/riscv64/annotate/instructions.c" -#include "arch/s390/annotate/instructions.c" -#include "arch/sparc/annotate/instructions.c" - static struct arch architectures[] =3D { { .name =3D "arc", .init =3D arc__annotate_init, + .e_machine =3D EM_ARC, }, { .name =3D "arm", .init =3D arm__annotate_init, + .e_machine =3D EM_ARM, }, { .name =3D "arm64", .init =3D arm64__annotate_init, + .e_machine =3D EM_AARCH64, }, { .name =3D "csky", .init =3D csky__annotate_init, + .e_machine =3D EM_CSKY, +#if defined(__CSKYABIV2__) + .e_flags =3D EF_CSKY_ABIV2, +#else + .e_flags =3D EF_CSKY_ABIV1, +#endif }, { .name =3D "mips", .init =3D mips__annotate_init, - .objdump =3D { - .comment_char =3D '#', - }, + .e_machine =3D EM_MIPS, }, { .name =3D "x86", .init =3D x86__annotate_init, - .instructions =3D x86__instructions, - .nr_instructions =3D ARRAY_SIZE(x86__instructions), - .sorted_instructions =3D true, - .insn_suffix =3D "bwlq", - .objdump =3D { - .comment_char =3D '#', - .register_char =3D '%', - .memory_ref_char =3D '(', - .imm_char =3D '$', - }, -#ifdef HAVE_LIBDW_SUPPORT - .update_insn_state =3D update_insn_state_x86, -#endif + .e_machine =3D EM_X86_64, // TODO: EM_386 too. }, { .name =3D "powerpc", .init =3D powerpc__annotate_init, -#ifdef HAVE_LIBDW_SUPPORT - .update_insn_state =3D update_insn_state_powerpc, -#endif + .e_machine =3D EM_PPC, // TODO: EM_PPC64 too. }, { .name =3D "riscv64", .init =3D riscv64__annotate_init, + .e_machine =3D EM_RISCV, }, { .name =3D "s390", .init =3D s390__annotate_init, - .objdump =3D { - .comment_char =3D '#', - }, + .e_machine =3D EM_S390, }, { .name =3D "sparc", .init =3D sparc__annotate_init, - .objdump =3D { - .comment_char =3D '#', - }, + .e_machine =3D EM_SPARC, }, { .name =3D "loongarch", .init =3D loongarch__annotate_init, - .objdump =3D { - .comment_char =3D '#', - }, + .e_machine =3D EM_LOONGARCH, }, }; =20 @@ -248,14 +219,14 @@ static void ins_ops__delete(struct ins_operands *ops) zfree(&ops->target.name); } =20 -static int ins__raw_scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name) +int ins__raw_scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, ops->raw); } =20 -static int ins__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name) +int ins__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name) { if (ins->ops->scnprintf) return ins->ops->scnprintf(ins, bf, size, ops, max_ins_name); @@ -326,8 +297,8 @@ static int call__parse(const struct arch *arch, struct = ins_operands *ops, struct goto find_target; } =20 -static int call__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name) +int call__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name) { if (ops->target.sym) return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, ops->targ= et.sym->name); @@ -341,7 +312,7 @@ static int call__scnprintf(const struct ins *ins, char = *bf, size_t size, return scnprintf(bf, size, "%-*s *%" PRIx64, max_ins_name, ins->name, ops= ->target.addr); } =20 -static const struct ins_ops call_ops =3D { +const struct ins_ops call_ops =3D { .parse =3D call__parse, .scnprintf =3D call__scnprintf, }; @@ -453,8 +424,8 @@ static int jump__parse(const struct arch *arch, struct = ins_operands *ops, struct return 0; } =20 -static int jump__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name) +int jump__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name) { const char *c; =20 @@ -494,7 +465,7 @@ static void jump__delete(struct ins_operands *ops __may= be_unused) */ } =20 -static const struct ins_ops jump_ops =3D { +const struct ins_ops jump_ops =3D { .free =3D jump__delete, .parse =3D jump__parse, .scnprintf =3D jump__scnprintf, @@ -586,7 +557,7 @@ static void lock__delete(struct ins_operands *ops) zfree(&ops->target.name); } =20 -static const struct ins_ops lock_ops =3D { +const struct ins_ops lock_ops =3D { .free =3D lock__delete, .parse =3D lock__parse, .scnprintf =3D lock__scnprintf, @@ -687,103 +658,19 @@ static int mov__parse(const struct arch *arch, struc= t ins_operands *ops, return -1; } =20 -static int mov__scnprintf(const struct ins *ins, char *bf, size_t size, - struct ins_operands *ops, int max_ins_name) +int mov__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name) { return scnprintf(bf, size, "%-*s %s,%s", max_ins_name, ins->name, ops->source.name ?: ops->source.raw, ops->target.name ?: ops->target.raw); } =20 -static const struct ins_ops mov_ops =3D { +const struct ins_ops mov_ops =3D { .parse =3D mov__parse, .scnprintf =3D mov__scnprintf, }; =20 -#define PPC_22_30(R) (((R) >> 1) & 0x1ff) -#define MINUS_EXT_XO_FORM 234 -#define SUB_EXT_XO_FORM 232 -#define ADD_ZERO_EXT_XO_FORM 202 -#define SUB_ZERO_EXT_XO_FORM 200 - -static int arithmetic__scnprintf(const struct ins *ins, char *bf, size_t s= ize, - struct ins_operands *ops, int max_ins_name) -{ - return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, - ops->raw); -} - -/* - * Sets the fields: multi_regs and "mem_ref". - * "mem_ref" is set for ops->source which is later used to - * fill the objdump->memory_ref-char field. This ops is currently - * used by powerpc and since binary instruction code is used to - * extract opcode, regs and offset, no other parsing is needed here. - * - * Dont set multi regs for 4 cases since it has only one operand - * for source: - * - Add to Minus One Extended XO-form ( Ex: addme, addmeo ) - * - Subtract From Minus One Extended XO-form ( Ex: subfme ) - * - Add to Zero Extended XO-form ( Ex: addze, addzeo ) - * - Subtract From Zero Extended XO-form ( Ex: subfze ) - */ -static int arithmetic__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, - struct map_symbol *ms __maybe_unused, struct disasm_line *dl) -{ - int opcode =3D PPC_OP(dl->raw.raw_insn); - - ops->source.mem_ref =3D false; - if (opcode =3D=3D 31) { - if ((opcode !=3D MINUS_EXT_XO_FORM) && (opcode !=3D SUB_EXT_XO_FORM) \ - && (opcode !=3D ADD_ZERO_EXT_XO_FORM) && (opcode !=3D SUB_ZERO_EXT_XO_= FORM)) - ops->source.multi_regs =3D true; - } - - ops->target.mem_ref =3D false; - ops->target.multi_regs =3D false; - - return 0; -} - -static const struct ins_ops arithmetic_ops =3D { - .parse =3D arithmetic__parse, - .scnprintf =3D arithmetic__scnprintf, -}; - -static int load_store__scnprintf(const struct ins *ins, char *bf, size_t s= ize, - struct ins_operands *ops, int max_ins_name) -{ - return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, - ops->raw); -} - -/* - * Sets the fields: multi_regs and "mem_ref". - * "mem_ref" is set for ops->source which is later used to - * fill the objdump->memory_ref-char field. This ops is currently - * used by powerpc and since binary instruction code is used to - * extract opcode, regs and offset, no other parsing is needed here - */ -static int load_store__parse(const struct arch *arch __maybe_unused, struc= t ins_operands *ops, - struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unu= sed) -{ - ops->source.mem_ref =3D true; - ops->source.multi_regs =3D false; - /* opcode 31 is of X form */ - if (PPC_OP(dl->raw.raw_insn) =3D=3D 31) - ops->source.multi_regs =3D true; - - ops->target.mem_ref =3D false; - ops->target.multi_regs =3D false; - - return 0; -} - -static const struct ins_ops load_store_ops =3D { - .parse =3D load_store__parse, - .scnprintf =3D load_store__scnprintf, -}; - static int dec__parse(const struct arch *arch __maybe_unused, struct ins_o= perands *ops, struct map_symbol *ms __maybe_unused, struct disasm_line *dl __maybe_unused) @@ -820,7 +707,7 @@ static int dec__scnprintf(const struct ins *ins, char *= bf, size_t size, ops->target.name ?: ops->target.raw); } =20 -static const struct ins_ops dec_ops =3D { +const struct ins_ops dec_ops =3D { .parse =3D dec__parse, .scnprintf =3D dec__scnprintf, }; @@ -831,11 +718,11 @@ static int nop__scnprintf(const struct ins *ins __may= be_unused, char *bf, size_t return scnprintf(bf, size, "%-*s", max_ins_name, "nop"); } =20 -static const struct ins_ops nop_ops =3D { +const struct ins_ops nop_ops =3D { .scnprintf =3D nop__scnprintf, }; =20 -static const struct ins_ops ret_ops =3D { +const struct ins_ops ret_ops =3D { .scnprintf =3D ins__raw_scnprintf, }; =20 diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index db7f1ee3d8e7..83503c5075f9 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -109,6 +109,28 @@ const struct arch *arch__find(const char *name); bool arch__is_x86(const struct arch *arch); bool arch__is_powerpc(const struct arch *arch); =20 +extern const struct ins_ops call_ops; +extern const struct ins_ops dec_ops; +extern const struct ins_ops jump_ops; +extern const struct ins_ops mov_ops; +extern const struct ins_ops nop_ops; +extern const struct ins_ops lock_ops; +extern const struct ins_ops ret_ops; + +int arch__associate_ins_ops(struct arch *arch, const char *name, const str= uct ins_ops *ops); + +int arc__annotate_init(struct arch *arch, char *cpuid); +int arm__annotate_init(struct arch *arch, char *cpuid); +int arm64__annotate_init(struct arch *arch, char *cpuid); +int csky__annotate_init(struct arch *arch, char *cpuid); +int loongarch__annotate_init(struct arch *arch, char *cpuid); +int mips__annotate_init(struct arch *arch, char *cpuid); +int powerpc__annotate_init(struct arch *arch, char *cpuid); +int riscv64__annotate_init(struct arch *arch, char *cpuid); +int s390__annotate_init(struct arch *arch, char *cpuid); +int sparc__annotate_init(struct arch *arch, char *cpuid); +int x86__annotate_init(struct arch *arch, char *cpuid); + const struct ins_ops *ins__find(const struct arch *arch, const char *name,= struct disasm_line *dl); =20 bool ins__is_call(const struct ins *ins); @@ -117,12 +139,28 @@ bool ins__is_fused(const struct arch *arch, const cha= r *ins1, const char *ins2); bool ins__is_ret(const struct ins *ins); bool ins__is_lock(const struct ins *ins); =20 +extern const struct ins_ops s390_call_ops; +extern const struct ins_ops loongarch_call_ops; +extern const struct ins_ops loongarch_jump_ops; +const struct ins_ops *check_ppc_insn(struct disasm_line *dl); + struct disasm_line *disasm_line__new(struct annotate_args *args); void disasm_line__free(struct disasm_line *dl); =20 int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw, int max_ins_name); =20 +int ins__raw_scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name); +int ins__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name); +int call__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name); +int jump__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name); +int mov__scnprintf(const struct ins *ins, char *bf, size_t size, + struct ins_operands *ops, int max_ins_name); + int symbol__disassemble(struct symbol *sym, struct annotate_args *args); =20 char *expand_tabs(char *line, char **storage, size_t *storage_len); --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 21:24:55 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE9EE48167F for ; Thu, 22 Jan 2026 07:31:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067114; cv=none; b=WP2L4gJVcZCrm1ycl2d7Qd0AjgNh1noMNFXRJiG8spsBv4O2KYQ4mvRoovWMa9PkJllLf6dYB0n0DzApyWCZKYOrlfDXV+ZzkvqgJpoRS+oPcCS5kZ07iCSe/arThkXohE9n9GoZQaJnaiF4eEls5mQWEjeKE9kEhMbzm5N2nRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067114; c=relaxed/simple; bh=p/53skaYkxw3FbY6a+zG/VnxhoQiWrk9vg0CARtxbUo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=PGNn9HKl352ok2tWL/fZu09aBQ8+0e6gOjTiyl4/6sCm4YSzq800Sol24X6wQVwB8+w5wz7j8dTVH3r9amYMaUtTxPR9YHzEFtE+shsMl1PQiIgFFmsyJ+hA7y1H0WUXDiAYpdHnlrnD09id0tGAJswkCQczKMGzHkHTt36zV78= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SwAVxdMy; arc=none smtp.client-ip=74.125.82.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SwAVxdMy" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-122008d48e5so1365802c88.1 for ; Wed, 21 Jan 2026 23:31:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067105; x=1769671905; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=RuAcUlfLOH+Nmb5IOvdzZq6066CfyPFp8FPVv/E64Q8=; b=SwAVxdMyCSAc9RqvV05wFwSmWg0RGGbatx8oKkUF9aq0s2kDjuqTupnCriZf+oBMA9 sfjeuDYPoZmRUKNfINrs9uLOfLL2EYqXb45EuWQgzVUnFRebln8PO8bsre4SKFTYMQ0a /DekiWPmQv/TvsyLEkvLErZF86Uj4fUjqnYxDUXaffcg48zELxlnrUXqZxQvba/O/4x7 lTO9PS92hUeXrjXlvBpoq/3fLsoz03oyr95iTALhvbCYFS6EL2wdYsPbCgdgJndW/lJw S2I3khfXdWw4HOpF1XT1BSIOlFEl38jk0hGkot/kUb0RGhdlqakqwSXDvkyt0MMwqT87 wDfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067105; x=1769671905; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RuAcUlfLOH+Nmb5IOvdzZq6066CfyPFp8FPVv/E64Q8=; b=oDHM+AEyskd7rDttlDnrLebcX792toY6XZ0CxOgO5sEEewXKF0+HCXndS0jH49+la3 SxSn2VWLrCKGNRnlH2crjFsxhqdlf5lKmSTmtpcR0mu6TYLJ08JCEQGT2fxZnbvcgd1G lNvHjjefSm/eyNWPPMhx3b+wArfg7s7sOmYEARngad1P0IU5n0yzUmZ6a1X9RFvmMq1X l4wZ+JFHeFt+AIAP2xLl6PbzcX5PlVRC03l0pLuUNbJnlq2I1nB1knCOhYxSD3ACfBjI 3R6VBAWaU3U4aBNzuHAmidQz7KOknZ29iXFFG7anQvbLARjHSMWQJWckcWqh/BOlK1nF XfyQ== X-Forwarded-Encrypted: i=1; AJvYcCUnX2X8nVfZDJtdD2T4PoC8vFyC+rC0922lHR0ZWKyCsx8onKS2DQLG+dz+AB5nFqU7pXQp8TxVtb3fa+g=@vger.kernel.org X-Gm-Message-State: AOJu0YwNPahVaCFNnxC4ZHOz41HFz1F2nTOxP6FJWjKkcUSBbI/ymf8N L+0xvEMc/HEIMqmCwJ1KaedS9GPqlmkJm7bxJNIaNjcwaTkSW1pEktO1bEAU9HNMYNgdDVYyJZ0 zi16TAmCmog== X-Received: from dlbep12.prod.google.com ([2002:a05:7022:108c:b0:11e:64d:cd3b]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:eacf:b0:11a:fec5:d005 with SMTP id a92af1059eb24-1246a95600emr5252743c88.10.1769067104935; Wed, 21 Jan 2026 23:31:44 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:24 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-9-irogers@google.com> Subject: [PATCH v1 08/11] perf disasm: Refactor ins__is_call/jump to avoid exposing arch ins_ops From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add booleans indicating whether and ins_ops are call or jump and return it. This avoids exposing loongarch and s390 ins_ops for the sake of matching. Signed-off-by: Ian Rogers --- tools/perf/util/annotate-arch/annotate-loongarch.c | 6 ++++-- tools/perf/util/annotate-arch/annotate-s390.c | 3 ++- tools/perf/util/disasm.c | 6 ++++-- tools/perf/util/disasm.h | 5 ++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/annotate-arch/annotate-loongarch.c b/tools/per= f/util/annotate-arch/annotate-loongarch.c index 4bd651b63652..b95ae5d6657f 100644 --- a/tools/perf/util/annotate-arch/annotate-loongarch.c +++ b/tools/perf/util/annotate-arch/annotate-loongarch.c @@ -55,9 +55,10 @@ static int loongarch_call__parse(const struct arch *arch= , struct ins_operands *o return 0; } =20 -const struct ins_ops loongarch_call_ops =3D { +static const struct ins_ops loongarch_call_ops =3D { .parse =3D loongarch_call__parse, .scnprintf =3D call__scnprintf, + .is_call =3D true, }; =20 static int loongarch_jump__parse(const struct arch *arch, struct ins_opera= nds *ops, @@ -104,9 +105,10 @@ static int loongarch_jump__parse(const struct arch *ar= ch, struct ins_operands *o return 0; } =20 -const struct ins_ops loongarch_jump_ops =3D { +static const struct ins_ops loongarch_jump_ops =3D { .parse =3D loongarch_jump__parse, .scnprintf =3D jump__scnprintf, + .is_jump =3D true, }; =20 static diff --git a/tools/perf/util/annotate-arch/annotate-s390.c b/tools/perf/uti= l/annotate-arch/annotate-s390.c index c1d06caa5f77..6d1a1da277e2 100644 --- a/tools/perf/util/annotate-arch/annotate-s390.c +++ b/tools/perf/util/annotate-arch/annotate-s390.c @@ -54,9 +54,10 @@ static int s390_call__parse(const struct arch *arch, str= uct ins_operands *ops, return 0; } =20 -const struct ins_ops s390_call_ops =3D { +static const struct ins_ops s390_call_ops =3D { .parse =3D s390_call__parse, .scnprintf =3D call__scnprintf, + .is_call =3D true, }; =20 static int s390_mov__parse(const struct arch *arch __maybe_unused, diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index c732b015f2e8..bc5323ecb5da 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -315,11 +315,12 @@ int call__scnprintf(const struct ins *ins, char *bf, = size_t size, const struct ins_ops call_ops =3D { .parse =3D call__parse, .scnprintf =3D call__scnprintf, + .is_call =3D true, }; =20 bool ins__is_call(const struct ins *ins) { - return ins->ops =3D=3D &call_ops || ins->ops =3D=3D &s390_call_ops || ins= ->ops =3D=3D &loongarch_call_ops; + return ins->ops && ins->ops->is_call; } =20 /* @@ -469,11 +470,12 @@ const struct ins_ops jump_ops =3D { .free =3D jump__delete, .parse =3D jump__parse, .scnprintf =3D jump__scnprintf, + .is_jump =3D true, }; =20 bool ins__is_jump(const struct ins *ins) { - return ins->ops =3D=3D &jump_ops || ins->ops =3D=3D &loongarch_jump_ops; + return ins->ops && ins->ops->is_jump; } =20 static int comment__symbol(char *raw, char *comment, u64 *addrp, char **na= mep) diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index 83503c5075f9..b6a2a30fdf27 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -93,6 +93,8 @@ struct ins_ops { struct disasm_line *dl); int (*scnprintf)(const struct ins *ins, char *bf, size_t size, struct ins_operands *ops, int max_ins_name); + bool is_jump; + bool is_call; }; =20 struct annotate_args { @@ -139,9 +141,6 @@ bool ins__is_fused(const struct arch *arch, const char = *ins1, const char *ins2); bool ins__is_ret(const struct ins *ins); bool ins__is_lock(const struct ins *ins); =20 -extern const struct ins_ops s390_call_ops; -extern const struct ins_ops loongarch_call_ops; -extern const struct ins_ops loongarch_jump_ops; const struct ins_ops *check_ppc_insn(struct disasm_line *dl); =20 struct disasm_line *disasm_line__new(struct annotate_args *args); --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 21:24:55 2026 Received: from mail-dy1-f202.google.com (mail-dy1-f202.google.com [74.125.82.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A076D481AA8 for ; Thu, 22 Jan 2026 07:31:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067115; cv=none; b=Qk4yt8AMR4Pns2DtTGl5oQTHEXr7Mwwmrm+aIolD0v5WJRN1X/s/lHDMORjL5JROIxHK3+RWQ6wajwVXA0z/y8q6Rv+aRXwWRVwx4doIJufqmugC9HKgi95Oxk72cNwKESMLkweSsWz1UhAhFhoER7r56D7pyKbLeX/RRa2XXYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067115; c=relaxed/simple; bh=TUqeF98l0qdNQ/Fsz65hPZj73WjRw64r79/KQUgVa4s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=qJ3AK9DaKwQunieVay100eORH2rIIxrWLnI21MiJHUq8J3/vUQhR7mtiLk39dNRHhaT7rf1BkEoOX01xcJHadxG5qt0WFIrNGCmJ/zOQNOCF62+c1KeN+dnOQPNtIhSPiSsYRo4+PWZksYah/m4SfCSS+DNlyQ3KNNpFVMFbijY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=I/n8lgmV; arc=none smtp.client-ip=74.125.82.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="I/n8lgmV" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b71c5826fbso704222eec.1 for ; Wed, 21 Jan 2026 23:31:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067107; x=1769671907; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=PuBIk7tpioVz4MoymkEw/EeeS4pL/7FQwHPBgMFfTyI=; b=I/n8lgmVTXTJRbzMLR0PQYU7q4gjWxwSIrzEXl3U/UGQ4CW7P9GUcdZzTBk1Oe6WWW RVBYLtP/UBTfXmYFICc/XexLsQp6w/MVMnrsXa+Z8V/GxRpR7OBAI7MhkznKkdZk4UI0 YnJ3rpOtqlKgRfsO8fjmO/5bWph3y2kjHF/FrDW5x/G/CT95CL06dMMSiQLjyBdyXSUr XPSoxQrgun8TM3ZjD4rUXJQzoLEn2P2bLUywupKeiYvT6bHvL7PEs6zCT/yqhya3J+Qm grk8FyYXDP/PQEVJdHQ4dO/h+UgtWdyWcE7IqM+fjwYW3JlWrX5GABfNqiq6PfRb2gv+ bBeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067107; x=1769671907; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PuBIk7tpioVz4MoymkEw/EeeS4pL/7FQwHPBgMFfTyI=; b=Va4xTzsNOMEvylygASlv38Y8mFEHzi7Q5pCh4E8mjYOfm/jDigwkBkF+3hY63lOHa1 zL4XFIeqEv79G88O4si/H/hG6QqEM9kTManVAg4YiHxuohCUvsMurF2c6Lhkj74WENc4 hdWBTO9H8huaa5GFCOcjQ9MQybUHped+q1R/QZLqZf/Uxs5+slYVU1hELk6Nc601IR7B KmjiYb7OJRX6TA1/ZlX3ZnSmxaKjvwFDb5j+7NibYT3pt4Nyi/vHJiOe0acE+R5gv/gF dCL2xjHYsP6ArjXut8BZGVk6ZRFt2doCCVtzUsHk97R8VyDacLUsAwxMHd5xdF81AOkW dApg== X-Forwarded-Encrypted: i=1; AJvYcCVIyTdjWIUochh4hGiOoIQYy0hKpF+junjoGRlgcfIsAPXKa4t1EFYpdSaAQnsDIEtvnsbIvtLBjVFikTE=@vger.kernel.org X-Gm-Message-State: AOJu0YwhdIFKWUcBi57f6L826wNYMzwjzgp92x+KVbEOvcqAuhuD+5Wj sqZRylZfh9VnRA3THrBcL2YK7GmEM2+ueKgccSlTIEI8oin6Er5nAs3/1RyupclTjfmqygm7eOV 7OrR4N/aUEw== X-Received: from dycnm24.prod.google.com ([2002:a05:7300:d198:b0:2b0:6a03:e2bb]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:100d:b0:2b7:140c:c700 with SMTP id 5a478bee46e88-2b7140cc765mr2519966eec.20.1769067106894; Wed, 21 Jan 2026 23:31:46 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:25 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-10-irogers@google.com> Subject: [PATCH v1 09/11] perf map_symbol: Switch from holding maps to holding thread From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" maps may belong to >1 thread. In contexts like symbolization information from the thread may be useful, such as the ELF machine. As the maps can be gained from the thread switch from holding maps in struct map_symbol to holding the thread. Holding the maps in addr_location is also redundant, switch this to using thread__maps. Signed-off-by: Ian Rogers --- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/ui/browsers/hists.c | 3 ++- tools/perf/util/addr_location.c | 4 ---- tools/perf/util/addr_location.h | 1 - .../util/annotate-arch/annotate-loongarch.c | 5 +++-- tools/perf/util/annotate-arch/annotate-s390.c | 3 ++- tools/perf/util/callchain.c | 12 +++++++----- tools/perf/util/capstone.c | 6 ++++-- tools/perf/util/db-export.c | 1 - tools/perf/util/disasm.c | 7 ++++--- tools/perf/util/event.c | 2 -- tools/perf/util/hist.c | 18 +++++++++--------- tools/perf/util/machine.c | 13 +++++++------ tools/perf/util/map_symbol.c | 5 +++-- tools/perf/util/map_symbol.h | 3 ++- tools/perf/util/sort.c | 2 +- tools/perf/util/unwind-libdw.c | 2 +- tools/perf/util/unwind-libunwind-local.c | 2 +- 18 files changed, 47 insertions(+), 44 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 3df61cd46652..91ded9c271ee 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -601,7 +601,7 @@ static bool annotate_browser__callq(struct annotate_bro= wser *browser, return true; } =20 - target_ms.maps =3D ms->maps; + target_ms.thread =3D ms->thread; target_ms.map =3D ms->map; target_ms.sym =3D dl->ops.target.sym; annotation__unlock(notes); diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 08fecbe28a52..cfa6386e6e1d 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -3189,7 +3189,8 @@ static int evsel__hists_browse(struct evsel *evsel, i= nt nr_events, const char *h case 'k': if (browser->selection !=3D NULL) hists_browser__zoom_map(browser, - maps__machine(browser->selection->maps)->vmlinux_map); + maps__machine(thread__maps(browser->selection->thread) + )->vmlinux_map); continue; case 'V': verbose =3D (verbose + 1) % 4; diff --git a/tools/perf/util/addr_location.c b/tools/perf/util/addr_locatio= n.c index 81a0b79c5e10..57e8217a00f9 100644 --- a/tools/perf/util/addr_location.c +++ b/tools/perf/util/addr_location.c @@ -7,7 +7,6 @@ void addr_location__init(struct addr_location *al) { al->thread =3D NULL; - al->maps =3D NULL; al->map =3D NULL; al->sym =3D NULL; al->srcline =3D NULL; @@ -30,16 +29,13 @@ void addr_location__exit(struct addr_location *al) { map__zput(al->map); thread__zput(al->thread); - maps__zput(al->maps); } =20 void addr_location__copy(struct addr_location *dst, struct addr_location *= src) { thread__put(dst->thread); - maps__put(dst->maps); map__put(dst->map); *dst =3D *src; dst->thread =3D thread__get(src->thread); - dst->maps =3D maps__get(src->maps); dst->map =3D map__get(src->map); } diff --git a/tools/perf/util/addr_location.h b/tools/perf/util/addr_locatio= n.h index 64b551025216..fdc4d3f3a68b 100644 --- a/tools/perf/util/addr_location.h +++ b/tools/perf/util/addr_location.h @@ -11,7 +11,6 @@ struct symbol; =20 struct addr_location { struct thread *thread; - struct maps *maps; struct map *map; struct symbol *sym; const char *srcline; diff --git a/tools/perf/util/annotate-arch/annotate-loongarch.c b/tools/per= f/util/annotate-arch/annotate-loongarch.c index b95ae5d6657f..a23744eafd6a 100644 --- a/tools/perf/util/annotate-arch/annotate-loongarch.c +++ b/tools/perf/util/annotate-arch/annotate-loongarch.c @@ -11,6 +11,7 @@ #include "../map.h" #include "../maps.h" #include "../symbol.h" +#include "../thread.h" =20 static int loongarch_call__parse(const struct arch *arch, struct ins_opera= nds *ops, struct map_symbol *ms, @@ -48,7 +49,7 @@ static int loongarch_call__parse(const struct arch *arch,= struct ins_operands *o =20 target.addr =3D map__objdump_2mem(map, ops->target.addr); =20 - if (maps__find_ams(ms->maps, &target) =3D=3D 0 && + if (maps__find_ams(thread__maps(ms->thread), &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 @@ -91,7 +92,7 @@ static int loongarch_jump__parse(const struct arch *arch,= struct ins_operands *o =20 ops->target.outside =3D target.addr < start || target.addr > end; =20 - if (maps__find_ams(ms->maps, &target) =3D=3D 0 && + if (maps__find_ams(thread__maps(ms->thread), &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 diff --git a/tools/perf/util/annotate-arch/annotate-s390.c b/tools/perf/uti= l/annotate-arch/annotate-s390.c index 6d1a1da277e2..cb112c1ba090 100644 --- a/tools/perf/util/annotate-arch/annotate-s390.c +++ b/tools/perf/util/annotate-arch/annotate-s390.c @@ -6,6 +6,7 @@ #include "../map.h" #include "../maps.h" #include "../symbol.h" +#include "../thread.h" #include "../annotate.h" #include "../annotate-data.h" =20 @@ -47,7 +48,7 @@ static int s390_call__parse(const struct arch *arch, stru= ct ins_operands *ops, return -1; target.addr =3D map__objdump_2mem(map, ops->target.addr); =20 - if (maps__find_ams(ms->maps, &target) =3D=3D 0 && + if (maps__find_ams(thread__maps(ms->thread), &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 428e5350d7a2..515bb8b5da01 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -31,6 +31,7 @@ #include "callchain.h" #include "branch.h" #include "symbol.h" +#include "thread.h" #include "util.h" #include "../perf.h" =20 @@ -1042,7 +1043,7 @@ merge_chain_branch(struct callchain_cursor *cursor, =20 list_for_each_entry_safe(list, next_list, &src->val, list) { struct map_symbol ms =3D { - .maps =3D maps__get(list->ms.maps), + .thread =3D thread__get(list->ms.thread), .map =3D map__get(list->ms.map), }; callchain_cursor_append(cursor, list->ip, &ms, false, NULL, 0, 0, 0, lis= t->srcline); @@ -1147,10 +1148,11 @@ int hist_entry__append_callchain(struct hist_entry = *he, struct perf_sample *samp int fill_callchain_info(struct addr_location *al, struct callchain_cursor_= node *node, bool hide_unresolved) { - struct machine *machine =3D node->ms.maps ? maps__machine(node->ms.maps) = : NULL; + struct machine *machine =3D NULL; + + if (node->ms.thread) + machine =3D maps__machine(thread__maps(node->ms.thread)); =20 - maps__put(al->maps); - al->maps =3D maps__get(node->ms.maps); map__put(al->map); al->map =3D map__get(node->ms.map); al->sym =3D node->ms.sym; @@ -1163,7 +1165,7 @@ int fill_callchain_info(struct addr_location *al, str= uct callchain_cursor_node * if (al->map =3D=3D NULL) goto out; } - if (maps__equal(al->maps, machine__kernel_maps(machine))) { + if (maps__equal(thread__maps(al->thread), machine__kernel_maps(machine)))= { if (machine__is_host(machine)) { al->cpumode =3D PERF_RECORD_MISC_KERNEL; al->level =3D 'k'; diff --git a/tools/perf/util/capstone.c b/tools/perf/util/capstone.c index ce06cfd253ef..9216916f848f 100644 --- a/tools/perf/util/capstone.c +++ b/tools/perf/util/capstone.c @@ -268,7 +268,8 @@ int symbol__disassemble_capstone(const char *filename _= _maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(args->ms->maps), &handle, is_64bit, disas= sembler_style) < 0) + if (capstone_init(maps__machine(thread__maps(args->ms->thread)), &handle,= is_64bit, + disassembler_style) < 0) goto err; =20 needs_cs_close =3D true; @@ -382,7 +383,8 @@ int symbol__disassemble_capstone_powerpc(const char *fi= lename __maybe_unused, !strcmp(args->options->disassembler_style, "att")) disassembler_style =3D true; =20 - if (capstone_init(maps__machine(args->ms->maps), &handle, is_64bit, disas= sembler_style) < 0) + if (capstone_init(maps__machine(thread__maps(args->ms->thread)), &handle,= is_64bit, + disassembler_style) < 0) goto err; =20 needs_cs_close =3D true; diff --git a/tools/perf/util/db-export.c b/tools/perf/util/db-export.c index 8f52e8cefcf3..ae9a9065aab7 100644 --- a/tools/perf/util/db-export.c +++ b/tools/perf/util/db-export.c @@ -254,7 +254,6 @@ static struct call_path *call_path_from_sample(struct d= b_export *dbe, addr_location__init(&al); al.sym =3D node->ms.sym; al.map =3D map__get(node->ms.map); - al.maps =3D maps__get(thread__maps(thread)); al.addr =3D node->ip; al.thread =3D thread__get(thread); =20 diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index bc5323ecb5da..c537c12ff7cd 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -28,6 +28,7 @@ #include "namespaces.h" #include "srcline.h" #include "symbol.h" +#include "thread.h" #include "util.h" =20 static regex_t file_lineno; @@ -277,7 +278,7 @@ static int call__parse(const struct arch *arch, struct = ins_operands *ops, struct .addr =3D map__objdump_2mem(map, ops->target.addr), }; =20 - if (maps__find_ams(ms->maps, &target) =3D=3D 0 && + if (maps__find_ams(thread__maps(ms->thread), &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 @@ -411,7 +412,7 @@ static int jump__parse(const struct arch *arch, struct = ins_operands *ops, struct * Actual navigation will come next, with further understanding of how * the symbol searching and disassembly should be done. */ - if (maps__find_ams(ms->maps, &target) =3D=3D 0 && + if (maps__find_ams(thread__maps(ms->thread), &target) =3D=3D 0 && map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.ad= dr)) =3D=3D ops->target.addr) ops->target.sym =3D target.ms.sym; =20 @@ -1074,7 +1075,7 @@ static int symbol__parse_objdump_line(struct symbol *= sym, .ms =3D { .map =3D map, }, }; =20 - if (!maps__find_ams(args->ms->maps, &target) && + if (!maps__find_ams(thread__maps(args->ms->thread), &target) && target.ms.sym->start =3D=3D target.al_addr) dl->ops.target.sym =3D target.ms.sym; } diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 4c92cc1a952c..aa3f8a3a4438 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -646,7 +646,6 @@ struct map *thread__find_map(struct thread *thread, u8 = cpumode, u64 addr, struct machine *machine =3D maps__machine(maps); bool load_map =3D false; =20 - maps__zput(al->maps); map__zput(al->map); thread__zput(al->thread); al->thread =3D thread__get(thread); @@ -684,7 +683,6 @@ struct map *thread__find_map(struct thread *thread, u8 = cpumode, u64 addr, =20 return NULL; } - al->maps =3D maps__get(maps); al->map =3D maps__find(maps, al->addr); if (al->map !=3D NULL) { /* diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index ef4b569f7df4..7ffaa3d9851b 100644 --- a/tools/perf/util/hist.c +++ b/tools/perf/util/hist.c @@ -251,7 +251,7 @@ void hists__calc_col_len(struct hists *hists, struct hi= st_entry *h) =20 if (h->cgroup) { const char *cgrp_name =3D "unknown"; - struct cgroup *cgrp =3D cgroup__find(maps__machine(h->ms.maps)->env, + struct cgroup *cgrp =3D cgroup__find(maps__machine(thread__maps(h->ms.th= read))->env, h->cgroup); if (cgrp !=3D NULL) cgrp_name =3D cgrp->name; @@ -536,7 +536,7 @@ static int hist_entry__init(struct hist_entry *he, memset(&he->stat, 0, sizeof(he->stat)); } =20 - he->ms.maps =3D maps__get(he->ms.maps); + he->ms.thread =3D thread__get(he->ms.thread); he->ms.map =3D map__get(he->ms.map); =20 if (he->branch_info) { @@ -552,9 +552,9 @@ static int hist_entry__init(struct hist_entry *he, memcpy(he->branch_info, template->branch_info, sizeof(*he->branch_info)); =20 - he->branch_info->from.ms.maps =3D maps__get(he->branch_info->from.ms.map= s); + he->branch_info->from.ms.thread =3D thread__get(he->branch_info->from.ms= .thread); he->branch_info->from.ms.map =3D map__get(he->branch_info->from.ms.map); - he->branch_info->to.ms.maps =3D maps__get(he->branch_info->to.ms.maps); + he->branch_info->to.ms.thread =3D thread__get(he->branch_info->to.ms.thr= ead); he->branch_info->to.ms.map =3D map__get(he->branch_info->to.ms.map); } =20 @@ -810,7 +810,7 @@ __hists__add_entry(struct hists *hists, }, .cgroup =3D sample->cgroup, .ms =3D { - .maps =3D al->maps, + .thread =3D al->thread, .map =3D al->map, .sym =3D al->sym, }, @@ -890,7 +890,7 @@ struct hist_entry *hists__add_entry_block(struct hists = *hists, .block_info =3D block_info, .hists =3D hists, .ms =3D { - .maps =3D al->maps, + .thread =3D al->thread, .map =3D al->map, .sym =3D al->sym, }, @@ -1020,8 +1020,8 @@ iter_next_branch_entry(struct hist_entry_iter *iter, = struct addr_location *al) if (iter->curr >=3D iter->total) return 0; =20 - maps__put(al->maps); - al->maps =3D maps__get(bi[i].to.ms.maps); + thread__put(al->thread); + al->thread =3D thread__get(bi[i].to.ms.thread); map__put(al->map); al->map =3D map__get(bi[i].to.ms.map); al->sym =3D bi[i].to.ms.sym; @@ -1232,7 +1232,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter= *iter, .comm =3D thread__comm(al->thread), .ip =3D al->addr, .ms =3D { - .maps =3D al->maps, + .thread =3D al->thread, .map =3D al->map, .sym =3D al->sym, }, diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 30d606fbf040..5b0f5a48ffd4 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -2016,7 +2016,7 @@ static void ip__resolve_ams(struct thread *thread, ams->addr =3D ip; ams->al_addr =3D al.addr; ams->al_level =3D al.level; - ams->ms.maps =3D maps__get(al.maps); + ams->ms.thread =3D thread__get(al.thread); ams->ms.sym =3D al.sym; ams->ms.map =3D map__get(al.map); ams->phys_addr =3D 0; @@ -2037,7 +2037,7 @@ static void ip__resolve_data(struct thread *thread, ams->addr =3D addr; ams->al_addr =3D al.addr; ams->al_level =3D al.level; - ams->ms.maps =3D maps__get(al.maps); + ams->ms.thread =3D thread__get(al.thread); ams->ms.sym =3D al.sym; ams->ms.map =3D map__get(al.map); ams->phys_addr =3D phys_addr; @@ -2120,7 +2120,7 @@ static int append_inlines(struct callchain_cursor *cu= rsor, struct map_symbol *ms } =20 ilist_ms =3D (struct map_symbol) { - .maps =3D maps__get(ms->maps), + .thread =3D thread__get(ms->thread), .map =3D map__get(map), }; list_for_each_entry(ilist, &inline_node->val, list) { @@ -2220,7 +2220,7 @@ static int add_callchain_ip(struct thread *thread, iter_cycles =3D iter->cycles; } =20 - ms.maps =3D maps__get(al.maps); + ms.thread =3D thread__get(al.thread); ms.map =3D map__get(al.map); ms.sym =3D al.sym; =20 @@ -2383,7 +2383,7 @@ static void save_lbr_cursor_node(struct thread *threa= d, map_symbol__exit(&lbr_stitch->prev_lbr_cursor[idx].ms); memcpy(&lbr_stitch->prev_lbr_cursor[idx], cursor->curr, sizeof(struct callchain_cursor_node)); - lbr_stitch->prev_lbr_cursor[idx].ms.maps =3D maps__get(cursor->curr->ms.m= aps); + lbr_stitch->prev_lbr_cursor[idx].ms.thread =3D thread__get(cursor->curr->= ms.thread); lbr_stitch->prev_lbr_cursor[idx].ms.map =3D map__get(cursor->curr->ms.map= ); =20 lbr_stitch->prev_lbr_cursor[idx].valid =3D true; @@ -2596,7 +2596,8 @@ static bool has_stitched_lbr(struct thread *thread, memcpy(&stitch_node->cursor, &lbr_stitch->prev_lbr_cursor[i], sizeof(struct callchain_cursor_node)); =20 - stitch_node->cursor.ms.maps =3D maps__get(lbr_stitch->prev_lbr_cursor[i]= .ms.maps); + stitch_node->cursor.ms.thread =3D + thread__get(lbr_stitch->prev_lbr_cursor[i].ms.thread); stitch_node->cursor.ms.map =3D map__get(lbr_stitch->prev_lbr_cursor[i].m= s.map); =20 if (callee) diff --git a/tools/perf/util/map_symbol.c b/tools/perf/util/map_symbol.c index 6ad2960bc289..11bc0a7f704c 100644 --- a/tools/perf/util/map_symbol.c +++ b/tools/perf/util/map_symbol.c @@ -2,10 +2,11 @@ #include "map_symbol.h" #include "maps.h" #include "map.h" +#include "thread.h" =20 void map_symbol__exit(struct map_symbol *ms) { - maps__zput(ms->maps); + thread__zput(ms->thread); map__zput(ms->map); } =20 @@ -16,7 +17,7 @@ void addr_map_symbol__exit(struct addr_map_symbol *ams) =20 void map_symbol__copy(struct map_symbol *dst, struct map_symbol *src) { - dst->maps =3D maps__get(src->maps); + dst->thread =3D thread__get(src->thread); dst->map =3D map__get(src->map); dst->sym =3D src->sym; } diff --git a/tools/perf/util/map_symbol.h b/tools/perf/util/map_symbol.h index e370bb32ed47..7437e319f4a3 100644 --- a/tools/perf/util/map_symbol.h +++ b/tools/perf/util/map_symbol.h @@ -4,12 +4,13 @@ =20 #include =20 +struct thread; struct maps; struct map; struct symbol; =20 struct map_symbol { - struct maps *maps; + struct thread *thread; struct map *map; struct symbol *sym; }; diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index f963d61ac166..01a9d73ae348 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -1016,7 +1016,7 @@ static int hist_entry__cgroup_snprintf(struct hist_en= try *he, const char *cgrp_name =3D "N/A"; =20 if (he->cgroup) { - struct cgroup *cgrp =3D cgroup__find(maps__machine(he->ms.maps)->env, + struct cgroup *cgrp =3D cgroup__find(maps__machine(thread__maps(he->ms.t= hread))->env, he->cgroup); if (cgrp !=3D NULL) cgrp_name =3D cgrp->name; diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c index c1646ef5f971..9cb0960ef905 100644 --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c @@ -161,7 +161,7 @@ static int entry(u64 ip, struct unwind_info *ui) } =20 e->ip =3D ip; - e->ms.maps =3D maps__get(al.maps); + e->ms.thread =3D thread__get(al.thread); e->ms.map =3D map__get(al.map); e->ms.sym =3D al.sym; =20 diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unw= ind-libunwind-local.c index a24b45106acd..ecf0c01fe51f 100644 --- a/tools/perf/util/unwind-libunwind-local.c +++ b/tools/perf/util/unwind-libunwind-local.c @@ -666,7 +666,7 @@ static int entry(u64 ip, struct thread *thread, e.ms.sym =3D thread__find_symbol(thread, PERF_RECORD_MISC_USER, ip, &al); e.ip =3D ip; e.ms.map =3D al.map; - e.ms.maps =3D al.maps; + e.ms.thread =3D thread__get(al.thread); =20 pr_debug("unwind: %s:ip =3D 0x%" PRIx64 " (0x%" PRIx64 ")\n", al.sym ? al.sym->name : "''", --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 21:24:55 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D96C5481232 for ; Thu, 22 Jan 2026 07:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067122; cv=none; b=rr9euwo/OSnttXnVUX3n6cumm0EKC+60TSIw0fropFOjplyH+AXvFN7UJ2ZalkYmgbwKnQQgkGJNW13wP1z9gk0LCTvR6zKUaZkDQwaqB899ASnnPprIk06sAcSrLWRpdn9Fjp2XJfmAYwd6SEFRbZMP9GPdVqu+cLWTtAc5A0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067122; c=relaxed/simple; bh=v+aTeeAV8nhOFL8+eVICd0d4UiUDga/acNumVc4sLTk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=LHs08itAejzXBGsPPyKF7bxBGT8nNW13MIgA6N6jr1FcWJq+kHyh0KBfx7iqVKzJxGs0xtmDM+A0FgUSTnRcm6sz0GfKYGoUdaJVbGUpfxP8+1FOnbJY/sUNZOPw1C8I+ey9Mm0IVfrpbOmnfctIXnctFQVuZJuRaActs9TN44o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EKOiXkFP; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EKOiXkFP" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b72a9a9715so1390501eec.1 for ; Wed, 21 Jan 2026 23:31:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067109; x=1769671909; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=uRR5J/0mXEgLBS6l/XCegg4cpSLNBAVJGyQiUAqW/FE=; b=EKOiXkFP9/b6MR/uUVtcIfsvdGw3CJmdsJjODxYASK64OF9Hqn+MwlPBYLv2RROu0K rA3aaGPra4D6AyXtlqOvPMc9jcUQR8ZMjih2MH8JZZoFlX+j4ogY9EYrA0znIxIrQVAW sb1yjn+rkPhO79OINRnickki/OcFg2k+Cd8wLEMkBO+8meLEMZBN+LRjrHLDIirPQGVV 8CbETMfyoHe1g+DtQVZkcGoksPDSS9URmkRIaEiEJLtdOS3ut4gBUaKKlRSLJ/swmbtF PiCtWu7TmfI660o7/JtQHXa7JFjgdTfnyNjN02Cb3FrGfQhc1jnWR1DOYB8DhaE6dSo7 t9HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067109; x=1769671909; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uRR5J/0mXEgLBS6l/XCegg4cpSLNBAVJGyQiUAqW/FE=; b=i/76KqNHaTYdQZ9WZ6abUpCyfmuFq55KoAGzSoGfMVQnNJpPPGl52yxPlvp+aEjY0V wpIN1g4PXrM51qYsIhprDN8We7ni8/eqxlm+0wiP+8Ct11N9aDKuIPHDdYvTdF6Lj70w fNPjeJvEVUYTE3Zx0IO41K9BeoVm7cPCOaMh3ODIiUOQ7epL7Phlom0torGIm0Ke31rD roHt7QRUf1bvwbPlulJiC8ypzUHX7qu0GcdgGEHY8t5OVBOOdnDd/l5GO8vl4HzIqb/m UfOZqsKHVJIOvFMe594uXF4nUaCYGF3ShZULRHYnBDmMkAubZlDXuIx01LbobCI2dKcW h12w== X-Forwarded-Encrypted: i=1; AJvYcCXiVPkjwRCMnZhKdLrebONf4ylKibfkgPQEp16WZJhc9ps5JuJZwvvH4umjGYR1NJoaZzjhVIa493SWcoc=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1mIn14QSfI5lGZYYcLeD4Ph3Ic0ECPpttLb3uhYoMkHeHFYXE qYQHHX7Eqh+7GR8YFpCRtNAOG8Yl4eqV153ZObEzR82ZkBA2+6PGNIXGDSP7UYx75Xq5RRfYaWx rel/uRdH8Ng== X-Received: from dyke40.prod.google.com ([2002:a05:7300:4728:b0:2a2:4eb1:3771]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:6508:b0:2b6:aeb8:3d8c with SMTP id 5a478bee46e88-2b6b503bcb5mr15638769eec.32.1769067108802; Wed, 21 Jan 2026 23:31:48 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:26 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-11-irogers@google.com> Subject: [PATCH v1 10/11] perf disasm: Refactor arch__find and initialization of arch structs From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch arch__find to using an ELF machine number rather than a string. Rather than an array of fixed size arch structs turn the init functions into new functions indexed by the ELF machine they correspond to. This allows data to be stored with a struct arch with the container_of trick, so the priv variable can be removed. Switch to using the thread to find the arch rather than the evsel as the evsel only has limited notions of the running thread upon which disassembly is performed. Factor out the e_machine and e_flags into their own struct to make them easier to pass around. Signed-off-by: Ian Rogers --- tools/perf/ui/browsers/annotate.c | 2 +- tools/perf/util/annotate-arch/annotate-arc.c | 14 +- tools/perf/util/annotate-arch/annotate-arm.c | 37 +++-- .../perf/util/annotate-arch/annotate-arm64.c | 39 +++-- tools/perf/util/annotate-arch/annotate-csky.c | 14 +- .../util/annotate-arch/annotate-loongarch.c | 19 ++- tools/perf/util/annotate-arch/annotate-mips.c | 19 ++- .../util/annotate-arch/annotate-powerpc.c | 22 +-- .../util/annotate-arch/annotate-riscv64.c | 19 ++- tools/perf/util/annotate-arch/annotate-s390.c | 29 ++-- .../perf/util/annotate-arch/annotate-sparc.c | 17 +- tools/perf/util/annotate-arch/annotate-x86.c | 24 +-- tools/perf/util/annotate.c | 46 +++--- tools/perf/util/annotate.h | 2 +- tools/perf/util/disasm.c | 153 ++++++++---------- tools/perf/util/disasm.h | 59 +++---- 16 files changed, 278 insertions(+), 237 deletions(-) diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/ann= otate.c index 91ded9c271ee..ea17e6d29a7e 100644 --- a/tools/perf/ui/browsers/annotate.c +++ b/tools/perf/ui/browsers/annotate.c @@ -1198,7 +1198,7 @@ int __hist_entry__tui_annotate(struct hist_entry *he,= struct map_symbol *ms, ui__warning("Annotation has no source code."); } } else { - err =3D evsel__get_arch(evsel, &browser.arch); + err =3D thread__get_arch(ms->thread, &browser.arch); if (err) { annotate_browser__symbol_annotate_error(&browser, err); return -1; diff --git a/tools/perf/util/annotate-arch/annotate-arc.c b/tools/perf/util= /annotate-arch/annotate-arc.c index d7ca08ca5600..170103e383a4 100644 --- a/tools/perf/util/annotate-arch/annotate-arc.c +++ b/tools/perf/util/annotate-arch/annotate-arc.c @@ -1,10 +1,18 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include "../disasm.h" =20 -int arc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_arc(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - arch->initialized =3D true; + struct arch *arch =3D zalloc(sizeof(*arch)); + + if (!arch) + return NULL; + + arch->name =3D "arc"; + arch->id =3D *id; arch->objdump.comment_char =3D ';'; - return 0; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-arm.c b/tools/perf/util= /annotate-arch/annotate-arm.c index 08c49067c3c9..25086f5fce23 100644 --- a/tools/perf/util/annotate-arch/annotate-arm.c +++ b/tools/perf/util/annotate-arch/annotate-arm.c @@ -7,14 +7,15 @@ #include "../annotate.h" #include "../disasm.h" =20 -struct arm_annotate { - regex_t call_insn, - jump_insn; +struct arch_arm { + struct arch arch; + regex_t call_insn; + regex_t jump_insn; }; =20 static const struct ins_ops *arm__associate_instruction_ops(struct arch *a= rch, const char *name) { - struct arm_annotate *arm =3D arch->priv; + struct arch_arm *arm =3D container_of(arch, struct arch_arm, arch); const struct ins_ops *ops; regmatch_t match[2]; =20 @@ -29,37 +30,39 @@ static const struct ins_ops *arm__associate_instruction= _ops(struct arch *arch, c return ops; } =20 -int arm__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_arm(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - struct arm_annotate *arm; int err; + struct arch_arm *arm =3D zalloc(sizeof(*arm)); + struct arch *arch; =20 - if (arch->initialized) - return 0; - - arm =3D zalloc(sizeof(*arm)); if (!arm) - return ENOMEM; + return NULL; + + arch =3D &arm->arch; + arch->name =3D "arm"; + arch->id =3D *id; + arch->objdump.comment_char =3D ';'; + arch->objdump.skip_functions_char =3D '+'; + arch->associate_instruction_ops =3D arm__associate_instruction_ops; =20 #define ARM_CONDS "(cc|cs|eq|ge|gt|hi|le|ls|lt|mi|ne|pl|vc|vs)" err =3D regcomp(&arm->call_insn, "^blx?" ARM_CONDS "?$", REG_EXTENDED); if (err) goto out_free_arm; + err =3D regcomp(&arm->jump_insn, "^bx?" ARM_CONDS "?$", REG_EXTENDED); if (err) goto out_free_call; #undef ARM_CONDS =20 - arch->initialized =3D true; - arch->priv =3D arm; - arch->associate_instruction_ops =3D arm__associate_instruction_ops; - arch->objdump.comment_char =3D ';'; - arch->objdump.skip_functions_char =3D '+'; return 0; =20 out_free_call: regfree(&arm->call_insn); out_free_arm: free(arm); - return SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP; + errno =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP; + return NULL; } diff --git a/tools/perf/util/annotate-arch/annotate-arm64.c b/tools/perf/ut= il/annotate-arch/annotate-arm64.c index d2ea32984b0d..da45c7d05757 100644 --- a/tools/perf/util/annotate-arch/annotate-arm64.c +++ b/tools/perf/util/annotate-arch/annotate-arm64.c @@ -8,9 +8,10 @@ #include "../annotate.h" #include "../disasm.h" =20 -struct arm64_annotate { - regex_t call_insn, - jump_insn; +struct arch_arm64 { + struct arch arch; + regex_t call_insn; + regex_t jump_insn; }; =20 static int arm64_mov__parse(const struct arch *arch __maybe_unused, @@ -70,7 +71,7 @@ static const struct ins_ops arm64_mov_ops =3D { =20 static const struct ins_ops *arm64__associate_instruction_ops(struct arch = *arch, const char *name) { - struct arm64_annotate *arm =3D arch->priv; + struct arch_arm64 *arm =3D container_of(arch, struct arch_arm64, arch); const struct ins_ops *ops; regmatch_t match[2]; =20 @@ -87,38 +88,44 @@ static const struct ins_ops *arm64__associate_instructi= on_ops(struct arch *arch, return ops; } =20 -int arm64__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_arm64(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - struct arm64_annotate *arm; int err; + struct arch_arm64 *arm =3D zalloc(sizeof(*arm)); + struct arch *arch; =20 - if (arch->initialized) - return 0; + if (!arm) + return NULL; + + arch =3D &arm->arch; + arch->name =3D "arm64"; + arch->id =3D *id; + arch->objdump.comment_char =3D '/'; + arch->objdump.skip_functions_char =3D '+'; + arch->associate_instruction_ops =3D arm64__associate_instruction_ops; =20 arm =3D zalloc(sizeof(*arm)); if (!arm) - return ENOMEM; + return NULL; =20 /* bl, blr */ err =3D regcomp(&arm->call_insn, "^blr?$", REG_EXTENDED); if (err) goto out_free_arm; + /* b, b.cond, br, cbz/cbnz, tbz/tbnz */ err =3D regcomp(&arm->jump_insn, "^[ct]?br?\\.?(cc|cs|eq|ge|gt|hi|hs|le|l= o|ls|lt|mi|ne|pl|vc|vs)?n?z?$", REG_EXTENDED); if (err) goto out_free_call; =20 - arch->initialized =3D true; - arch->priv =3D arm; - arch->associate_instruction_ops =3D arm64__associate_instruction_ops; - arch->objdump.comment_char =3D '/'; - arch->objdump.skip_functions_char =3D '+'; - return 0; + return arch; =20 out_free_call: regfree(&arm->call_insn); out_free_arm: free(arm); - return SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP; + errno =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP; + return NULL; } diff --git a/tools/perf/util/annotate-arch/annotate-csky.c b/tools/perf/uti= l/annotate-arch/annotate-csky.c index 0b0b09b068ec..d2b18e4ea2c9 100644 --- a/tools/perf/util/annotate-arch/annotate-csky.c +++ b/tools/perf/util/annotate-arch/annotate-csky.c @@ -2,6 +2,7 @@ // Copyright (C) 2019 Hangzhou C-SKY Microsystems co.,ltd. #include #include +#include #include "../disasm.h" =20 static const struct ins_ops *csky__associate_ins_ops(struct arch *arch, @@ -39,10 +40,17 @@ static const struct ins_ops *csky__associate_ins_ops(st= ruct arch *arch, return ops; } =20 -int csky__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_csky(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - arch->initialized =3D true; + struct arch *arch =3D zalloc(sizeof(*arch)); + + if (!arch) + return NULL; + + arch->name =3D "csky"; + arch->id =3D *id; arch->objdump.comment_char =3D '/'; arch->associate_instruction_ops =3D csky__associate_ins_ops; - return 0; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-loongarch.c b/tools/per= f/util/annotate-arch/annotate-loongarch.c index a23744eafd6a..2027e3b816f4 100644 --- a/tools/perf/util/annotate-arch/annotate-loongarch.c +++ b/tools/perf/util/annotate-arch/annotate-loongarch.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "../disasm.h" #include "../map.h" #include "../maps.h" @@ -137,13 +138,17 @@ const struct ins_ops *loongarch__associate_ins_ops(st= ruct arch *arch, const char return ops; } =20 -int loongarch__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_loongarch(const struct e_machine_and_e_flags = *id, + const char *cpuid __maybe_unused) { - if (!arch->initialized) { - arch->associate_instruction_ops =3D loongarch__associate_ins_ops; - arch->initialized =3D true; - arch->objdump.comment_char =3D '#'; - } + struct arch *arch =3D zalloc(sizeof(*arch)); =20 - return 0; + if (!arch) + return NULL; + + arch->name =3D "loongarch"; + arch->id =3D *id; + arch->associate_instruction_ops =3D loongarch__associate_ins_ops; + arch->objdump.comment_char =3D '#'; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-mips.c b/tools/perf/uti= l/annotate-arch/annotate-mips.c index f14b34ed77d3..e8d1c6c7e9f3 100644 --- a/tools/perf/util/annotate-arch/annotate-mips.c +++ b/tools/perf/util/annotate-arch/annotate-mips.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include "../disasm.h" =20 static @@ -36,13 +37,17 @@ const struct ins_ops *mips__associate_ins_ops(struct ar= ch *arch, const char *nam return ops; } =20 -int mips__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_mips(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - if (!arch->initialized) { - arch->associate_instruction_ops =3D mips__associate_ins_ops; - arch->initialized =3D true; - arch->objdump.comment_char =3D '#'; - } + struct arch *arch =3D zalloc(sizeof(*arch)); =20 - return 0; + if (!arch) + return NULL; + + arch->name =3D "mips"; + arch->id =3D *id; + arch->objdump.comment_char =3D '#'; + arch->associate_instruction_ops =3D mips__associate_ins_ops; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-powerpc.c b/tools/perf/= util/annotate-arch/annotate-powerpc.c index 593c138c8104..004e6137aa03 100644 --- a/tools/perf/util/annotate-arch/annotate-powerpc.c +++ b/tools/perf/util/annotate-arch/annotate-powerpc.c @@ -390,17 +390,21 @@ static void update_insn_state_powerpc(struct type_sta= te *state, } #endif /* HAVE_LIBDW_SUPPORT */ =20 -int powerpc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_powerpc(const struct e_machine_and_e_flags *i= d, + const char *cpuid __maybe_unused) { - if (!arch->initialized) { - arch->initialized =3D true; - arch->associate_instruction_ops =3D powerpc__associate_instruction_ops; - arch->objdump.comment_char =3D '#'; - annotate_opts.show_asm_raw =3D true; + struct arch *arch =3D zalloc(sizeof(*arch)); + + if (!arch) + return NULL; + + arch->name =3D "powerpc"; + arch->id =3D *id; + arch->objdump.comment_char =3D '#'; + annotate_opts.show_asm_raw =3D true; + arch->associate_instruction_ops =3D powerpc__associate_instruction_ops; #ifdef HAVE_LIBDW_SUPPORT - arch->update_insn_state =3D update_insn_state_powerpc; + arch->update_insn_state =3D update_insn_state_powerpc; #endif - } - return 0; } diff --git a/tools/perf/util/annotate-arch/annotate-riscv64.c b/tools/perf/= util/annotate-arch/annotate-riscv64.c index 15526824037a..29a988fca8c9 100644 --- a/tools/perf/util/annotate-arch/annotate-riscv64.c +++ b/tools/perf/util/annotate-arch/annotate-riscv64.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include "../disasm.h" =20 static @@ -24,13 +25,17 @@ const struct ins_ops *riscv64__associate_ins_ops(struct= arch *arch, const char * return ops; } =20 -int riscv64__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_riscv64(const struct e_machine_and_e_flags *i= d, + const char *cpuid __maybe_unused) { - if (!arch->initialized) { - arch->associate_instruction_ops =3D riscv64__associate_ins_ops; - arch->initialized =3D true; - arch->objdump.comment_char =3D '#'; - } + struct arch *arch =3D zalloc(sizeof(*arch)); =20 - return 0; + if (!arch) + return NULL; + + arch->name =3D "riscv"; + arch->id =3D *id; + arch->objdump.comment_char =3D '#'; + arch->associate_instruction_ops =3D riscv64__associate_ins_ops; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-s390.c b/tools/perf/uti= l/annotate-arch/annotate-s390.c index cb112c1ba090..094b2e125363 100644 --- a/tools/perf/util/annotate-arch/annotate-s390.c +++ b/tools/perf/util/annotate-arch/annotate-s390.c @@ -145,7 +145,7 @@ static const struct ins_ops *s390__associate_ins_ops(st= ruct arch *arch, const ch return ops; } =20 -static int s390__cpuid_parse(struct arch *arch, char *cpuid) +static int s390__cpuid_parse(struct arch *arch, const char *cpuid) { unsigned int family; char model[16], model_c[16], cpumf_v[16], cpumf_a[16]; @@ -166,19 +166,22 @@ static int s390__cpuid_parse(struct arch *arch, char = *cpuid) return -1; } =20 -int s390__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_s390(const struct e_machine_and_e_flags *id, = const char *cpuid) { - int err =3D 0; - - if (!arch->initialized) { - arch->initialized =3D true; - arch->associate_instruction_ops =3D s390__associate_ins_ops; - if (cpuid) { - if (s390__cpuid_parse(arch, cpuid)) - err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; + struct arch *arch =3D zalloc(sizeof(*arch)); + + if (!arch) + return NULL; + + arch->name =3D "s390"; + arch->id =3D *id; + arch->associate_instruction_ops =3D s390__associate_ins_ops; + if (cpuid) { + if (s390__cpuid_parse(arch, cpuid)) { + errno =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; + return NULL; } - arch->objdump.comment_char =3D '#'; } - - return err; + arch->objdump.comment_char =3D '#'; + return arch; } diff --git a/tools/perf/util/annotate-arch/annotate-sparc.c b/tools/perf/ut= il/annotate-arch/annotate-sparc.c index 66a0174376dd..fe7a37966261 100644 --- a/tools/perf/util/annotate-arch/annotate-sparc.c +++ b/tools/perf/util/annotate-arch/annotate-sparc.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include "../../util/disasm.h" =20 static int is_branch_cond(const char *cond) @@ -160,13 +161,17 @@ static const struct ins_ops *sparc__associate_instruc= tion_ops(struct arch *arch, return ops; } =20 -int sparc__annotate_init(struct arch *arch, char *cpuid __maybe_unused) +const struct arch *arch__new_sparc(const struct e_machine_and_e_flags *id, + const char *cpuid __maybe_unused) { - if (!arch->initialized) { - arch->initialized =3D true; - arch->associate_instruction_ops =3D sparc__associate_instruction_ops; - arch->objdump.comment_char =3D '#'; - } + struct arch *arch =3D zalloc(sizeof(*arch)); + + if (!arch) + return NULL; =20 + arch->name =3D "sparc"; + arch->id =3D *id; + arch->associate_instruction_ops =3D sparc__associate_instruction_ops; + arch->objdump.comment_char =3D '#'; return 0; } diff --git a/tools/perf/util/annotate-arch/annotate-x86.c b/tools/perf/util= /annotate-arch/annotate-x86.c index 0c7957fe60da..eb9a649ca656 100644 --- a/tools/perf/util/annotate-arch/annotate-x86.c +++ b/tools/perf/util/annotate-arch/annotate-x86.c @@ -182,7 +182,7 @@ static bool intel__ins_is_fused(const struct arch *arch= , const char *ins1, return false; } =20 -static int x86__cpuid_parse(struct arch *arch, char *cpuid) +static int x86__cpuid_parse(struct arch *arch, const char *cpuid) { unsigned int family, model, stepping; int ret; @@ -777,18 +777,21 @@ static void update_insn_state_x86(struct type_state *= state, } #endif =20 -int x86__annotate_init(struct arch *arch, char *cpuid) +const struct arch *arch__new_x86(const struct e_machine_and_e_flags *id, c= onst char *cpuid) { - int err =3D 0; + struct arch *arch =3D zalloc(sizeof(*arch)); =20 - if (arch->initialized) - return 0; + if (!arch) + return NULL; =20 + arch->name =3D "x86"; + arch->id =3D *id; if (cpuid) { - if (x86__cpuid_parse(arch, cpuid)) - err =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; + if (x86__cpuid_parse(arch, cpuid)) { + errno =3D SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING; + return NULL; + } } - arch->instructions =3D x86__instructions; arch->nr_instructions =3D ARRAY_SIZE(x86__instructions); #ifndef NDEBUG @@ -810,11 +813,8 @@ int x86__annotate_init(struct arch *arch, char *cpuid) arch->objdump.memory_ref_char =3D '('; arch->objdump.imm_char =3D '$'; arch->insn_suffix =3D "bwlq"; - arch->e_machine =3D EM_X86_64; - arch->e_flags =3D 0; - arch->initialized =3D true; #ifdef HAVE_LIBDW_SUPPORT arch->update_insn_state =3D update_insn_state_x86; #endif - return err; + return arch; } diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 79702072568b..c16c6dfaa959 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -980,32 +980,27 @@ void symbol__calc_percent(struct symbol *sym, struct = evsel *evsel) annotation__calc_percent(notes, evsel, symbol__size(sym)); } =20 -int evsel__get_arch(struct evsel *evsel, const struct arch **parch) +int thread__get_arch(struct thread *thread, const struct arch **parch) { - struct perf_env *env =3D evsel__env(evsel); - const char *arch_name =3D perf_env__arch(env); const struct arch *arch; - int err; + struct machine *machine; + uint16_t e_machine; =20 - if (!arch_name) { + if (!thread) { *parch =3D NULL; - return errno; + return -1; } =20 - *parch =3D arch =3D arch__find(arch_name); + machine =3D maps__machine(thread__maps(thread)); + e_machine =3D thread__e_machine(thread, machine); + arch =3D arch__find(e_machine, machine->env ? machine->env->cpuid : NULL); if (arch =3D=3D NULL) { - pr_err("%s: unsupported arch %s\n", __func__, arch_name); - return ENOTSUP; + pr_err("%s: unsupported arch %d\n", __func__, e_machine); + return errno; } + if (parch) + *parch =3D arch; =20 - if (arch->init) { - err =3D arch->init((struct arch *)arch, env ? env->cpuid : NULL); - if (err) { - pr_err("%s: failed to initialize %s arch priv area\n", - __func__, arch->name); - return err; - } - } return 0; } =20 @@ -1020,7 +1015,7 @@ int symbol__annotate(struct map_symbol *ms, struct ev= sel *evsel, const struct arch *arch =3D NULL; int err, nr; =20 - err =3D evsel__get_arch(evsel, &arch); + err =3D thread__get_arch(ms->thread, &arch); if (err) return err; =20 @@ -1268,7 +1263,7 @@ int hist_entry__annotate_printf(struct hist_entry *he= , struct evsel *evsel) =20 apd.addr_fmt_width =3D annotated_source__addr_fmt_width(¬es->src->sour= ce, notes->src->start); - evsel__get_arch(evsel, &apd.arch); + thread__get_arch(ms->thread, &apd.arch); apd.dbg =3D dso__debuginfo(dso); =20 list_for_each_entry(pos, ¬es->src->source, node) { @@ -1373,7 +1368,7 @@ static int symbol__annotate_fprintf2(struct symbol *s= ym, FILE *fp, struct annotation_line *al; =20 if (annotate_opts.code_with_type) { - evsel__get_arch(apd->evsel, &apd->arch); + thread__get_arch(apd->he->ms.thread, &apd->arch); apd->dbg =3D dso__debuginfo(map__dso(apd->he->ms.map)); } =20 @@ -2495,7 +2490,7 @@ static int extract_reg_offset(const struct arch *arch= , const char *str, if (regname =3D=3D NULL) return -1; =20 - op_loc->reg1 =3D get_dwarf_regnum(regname, arch->e_machine, arch->e_flags= ); + op_loc->reg1 =3D get_dwarf_regnum(regname, arch->id.e_machine, arch->id.e= _flags); free(regname); =20 /* Get the second register */ @@ -2508,7 +2503,7 @@ static int extract_reg_offset(const struct arch *arch= , const char *str, if (regname =3D=3D NULL) return -1; =20 - op_loc->reg2 =3D get_dwarf_regnum(regname, arch->e_machine, arch->e_flag= s); + op_loc->reg2 =3D get_dwarf_regnum(regname, arch->id.e_machine, arch->id.= e_flags); free(regname); } return 0; @@ -2607,8 +2602,11 @@ int annotate_get_insn_location(const struct arch *ar= ch, struct disasm_line *dl, if (s =3D=3D NULL) return -1; =20 - if (*s =3D=3D arch->objdump.register_char) - op_loc->reg1 =3D get_dwarf_regnum(s, arch->e_machine, arch->e_flags); + if (*s =3D=3D arch->objdump.register_char) { + op_loc->reg1 =3D get_dwarf_regnum(s, + arch->id.e_machine, + arch->id.e_flags); + } else if (*s =3D=3D arch->objdump.imm_char) { op_loc->offset =3D strtol(s + 1, &p, 0); if (p && p !=3D s + 1) diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h index 58eaf4b2fa65..696e36dbf013 100644 --- a/tools/perf/util/annotate.h +++ b/tools/perf/util/annotate.h @@ -586,5 +586,5 @@ int annotation_br_cntr_entry(char **str, int br_cntr_nr= , u64 *br_cntr, int num_aggr, struct evsel *evsel); int annotation_br_cntr_abbr_list(char **str, struct evsel *evsel, bool hea= der); =20 -int evsel__get_arch(struct evsel *evsel, const struct arch **parch); +int thread__get_arch(struct thread *thread, const struct arch **parch); #endif /* __PERF_ANNOTATE_H */ diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index c537c12ff7cd..e9f3155f3173 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -102,112 +102,101 @@ int arch__associate_ins_ops(struct arch *arch, cons= t char *name, const struct in return 0; } =20 -static struct arch architectures[] =3D { - { - .name =3D "arc", - .init =3D arc__annotate_init, - .e_machine =3D EM_ARC, - }, - { - .name =3D "arm", - .init =3D arm__annotate_init, - .e_machine =3D EM_ARM, - }, - { - .name =3D "arm64", - .init =3D arm64__annotate_init, - .e_machine =3D EM_AARCH64, - }, - { - .name =3D "csky", - .init =3D csky__annotate_init, - .e_machine =3D EM_CSKY, -#if defined(__CSKYABIV2__) - .e_flags =3D EF_CSKY_ABIV2, -#else - .e_flags =3D EF_CSKY_ABIV1, -#endif - }, - { - .name =3D "mips", - .init =3D mips__annotate_init, - .e_machine =3D EM_MIPS, - }, - { - .name =3D "x86", - .init =3D x86__annotate_init, - .e_machine =3D EM_X86_64, // TODO: EM_386 too. - }, - { - .name =3D "powerpc", - .init =3D powerpc__annotate_init, - .e_machine =3D EM_PPC, // TODO: EM_PPC64 too. - }, - { - .name =3D "riscv64", - .init =3D riscv64__annotate_init, - .e_machine =3D EM_RISCV, - }, - { - .name =3D "s390", - .init =3D s390__annotate_init, - .e_machine =3D EM_S390, - }, - { - .name =3D "sparc", - .init =3D sparc__annotate_init, - .e_machine =3D EM_SPARC, - }, - { - .name =3D "loongarch", - .init =3D loongarch__annotate_init, - .e_machine =3D EM_LOONGARCH, - }, -}; +static int e_machine_and_eflags__cmp(const struct e_machine_and_e_flags *v= al1, + const struct e_machine_and_e_flags *val2) +{ + if (val1->e_machine =3D=3D val2->e_machine) { + if (val1->e_machine !=3D EM_CSKY) + return 0; + if ((val1->e_flags & EF_CSKY_ABIMASK) < (val2->e_flags & EF_CSKY_ABIMASK= )) + return -1; + return (val1->e_flags & EF_CSKY_ABIMASK) > (val2->e_flags & EF_CSKY_ABIM= ASK); + } + return val1->e_machine < val2->e_machine ? -1 : 1; +} =20 -static int arch__key_cmp(const void *name, const void *archp) +static int arch__key_cmp(const void *key, const void *archp) { - const struct arch *arch =3D archp; + const struct arch *const *arch =3D archp; =20 - return strcmp(name, arch->name); + return e_machine_and_eflags__cmp(key, &(*arch)->id); } =20 static int arch__cmp(const void *a, const void *b) { - const struct arch *aa =3D a; - const struct arch *ab =3D b; + const struct arch *const *aa =3D a; + const struct arch *const *ab =3D b; =20 - return strcmp(aa->name, ab->name); + return e_machine_and_eflags__cmp(&(*aa)->id, &(*ab)->id); } =20 -static void arch__sort(void) +const struct arch *arch__find(uint16_t e_machine, const char *cpuid) { - const int nmemb =3D ARRAY_SIZE(architectures); + static const struct arch *(*const arch_new_fn[])(const struct e_machine_a= nd_e_flags *id, + const char *cpuid) =3D { + [EM_386] =3D arch__new_x86, + [EM_ARC] =3D arch__new_arc, + [EM_ARM] =3D arch__new_arm, + [EM_AARCH64] =3D arch__new_arm64, + [EM_CSKY] =3D arch__new_csky, + [EM_LOONGARCH] =3D arch__new_loongarch, + [EM_MIPS] =3D arch__new_mips, + [EM_PPC64] =3D arch__new_powerpc, + [EM_PPC] =3D arch__new_powerpc, + [EM_RISCV] =3D arch__new_riscv64, + [EM_S390] =3D arch__new_s390, + [EM_SPARC] =3D arch__new_sparc, + [EM_SPARCV9] =3D arch__new_sparc, + [EM_X86_64] =3D arch__new_x86, + }; + static const struct arch **archs; + static size_t num_archs; + struct e_machine_and_e_flags key =3D { + .e_machine =3D e_machine, + // TODO: e_flags should really come from the same source as e_machine. + .e_flags =3D EF_HOST, + }; + const struct arch *result =3D NULL, **tmp; =20 - qsort(architectures, nmemb, sizeof(struct arch), arch__cmp); -} + if (num_archs > 0) { + tmp =3D bsearch(&key, archs, num_archs, sizeof(*archs), arch__key_cmp); + if (tmp) + result =3D *tmp; + } =20 -const struct arch *arch__find(const char *name) -{ - const int nmemb =3D ARRAY_SIZE(architectures); - static bool sorted; + if (result) + return result; =20 - if (!sorted) { - arch__sort(); - sorted =3D true; + if (e_machine >=3D ARRAY_SIZE(arch_new_fn) || arch_new_fn[e_machine] =3D= =3D NULL) { + errno =3D ENOTSUP; + return NULL; } =20 - return bsearch(name, architectures, nmemb, sizeof(struct arch), arch__key= _cmp); + tmp =3D reallocarray(archs, num_archs + 1, sizeof(*archs)); + if (!tmp) + return NULL; + + result =3D arch_new_fn[e_machine](&key, cpuid); + if (!result) { + pr_err("%s: failed to initialize %s (%u) arch priv area\n", + __func__, result->name, e_machine); + free(tmp); + return NULL; + } + archs =3D tmp; + archs[num_archs++] =3D result; + qsort(archs, num_archs, sizeof(*archs), arch__cmp); + return result; } =20 bool arch__is_x86(const struct arch *arch) { - return arch->e_machine =3D=3D EM_386 || arch->e_machine =3D=3D EM_X86_64; + return arch->id.e_machine =3D=3D EM_386 || arch->id.e_machine =3D=3D EM_X= 86_64; } =20 bool arch__is_powerpc(const struct arch *arch) { - return arch->e_machine =3D=3D EM_PPC || arch->e_machine =3D=3D EM_PPC64; + return arch->id.e_machine =3D=3D EM_PPC || arch->id.e_machine =3D=3D EM_P= PC64; } =20 static void ins_ops__delete(struct ins_operands *ops) diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index b6a2a30fdf27..2793d48aa04e 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -17,21 +17,23 @@ struct data_loc_info; struct type_state; struct disasm_line; =20 +struct e_machine_and_e_flags { + uint16_t e_machine; + uint32_t e_flags; +}; + struct arch { - const char *name; + /** @id: ELF machine and flags associated with arch. */ + struct e_machine_and_e_flags id; + /** @name: name such as "x86" or "powerpc". */ + const char *name; const struct ins *instructions; - size_t nr_instructions; - size_t nr_instructions_allocated; - const struct ins_ops *(*associate_instruction_ops)(struct arch *arch, co= nst char *name); - bool sorted_instructions; - bool initialized; - const char *insn_suffix; - void *priv; - unsigned int model; - unsigned int family; - int (*init)(struct arch *arch, char *cpuid); - bool (*ins_is_fused)(const struct arch *arch, const char *ins1, - const char *ins2); + size_t nr_instructions; + size_t nr_instructions_allocated; + bool sorted_instructions; + const char *insn_suffix; + unsigned int model; + unsigned int family; struct { char comment_char; char skip_functions_char; @@ -39,15 +41,14 @@ struct arch { char memory_ref_char; char imm_char; } objdump; + bool (*ins_is_fused)(const struct arch *arch, const char *ins1, + const char *ins2); + const struct ins_ops *(*associate_instruction_ops)(struct arch *arch, co= nst char *name); #ifdef HAVE_LIBDW_SUPPORT void (*update_insn_state)(struct type_state *state, struct data_loc_info *dloc, Dwarf_Die *cu_die, struct disasm_line *dl); #endif - /** @e_machine: ELF machine associated with arch. */ - unsigned int e_machine; - /** @e_flags: Optional ELF flags associated with arch. */ - unsigned int e_flags; }; =20 struct ins { @@ -107,7 +108,7 @@ struct annotate_args { char *fileloc; }; =20 -const struct arch *arch__find(const char *name); +const struct arch *arch__find(uint16_t e_machine, const char *cpuid); bool arch__is_x86(const struct arch *arch); bool arch__is_powerpc(const struct arch *arch); =20 @@ -121,17 +122,17 @@ extern const struct ins_ops ret_ops; =20 int arch__associate_ins_ops(struct arch *arch, const char *name, const str= uct ins_ops *ops); =20 -int arc__annotate_init(struct arch *arch, char *cpuid); -int arm__annotate_init(struct arch *arch, char *cpuid); -int arm64__annotate_init(struct arch *arch, char *cpuid); -int csky__annotate_init(struct arch *arch, char *cpuid); -int loongarch__annotate_init(struct arch *arch, char *cpuid); -int mips__annotate_init(struct arch *arch, char *cpuid); -int powerpc__annotate_init(struct arch *arch, char *cpuid); -int riscv64__annotate_init(struct arch *arch, char *cpuid); -int s390__annotate_init(struct arch *arch, char *cpuid); -int sparc__annotate_init(struct arch *arch, char *cpuid); -int x86__annotate_init(struct arch *arch, char *cpuid); +const struct arch *arch__new_arc(const struct e_machine_and_e_flags *id, c= onst char *cpuid); +const struct arch *arch__new_arm(const struct e_machine_and_e_flags *id, c= onst char *cpuid); +const struct arch *arch__new_arm64(const struct e_machine_and_e_flags *id,= const char *cpuid); +const struct arch *arch__new_csky(const struct e_machine_and_e_flags *id, = const char *cpuid); +const struct arch *arch__new_loongarch(const struct e_machine_and_e_flags = *id, const char *cpuid); +const struct arch *arch__new_mips(const struct e_machine_and_e_flags *id, = const char *cpuid); +const struct arch *arch__new_powerpc(const struct e_machine_and_e_flags *i= d, const char *cpuid); +const struct arch *arch__new_riscv64(const struct e_machine_and_e_flags *i= d, const char *cpuid); +const struct arch *arch__new_s390(const struct e_machine_and_e_flags *id, = const char *cpuid); +const struct arch *arch__new_sparc(const struct e_machine_and_e_flags *id,= const char *cpuid); +const struct arch *arch__new_x86(const struct e_machine_and_e_flags *id, c= onst char *cpuid); =20 const struct ins_ops *ins__find(const struct arch *arch, const char *name,= struct disasm_line *dl); =20 --=20 2.52.0.457.g6b5491de43-goog From nobody Sat Feb 7 21:24:55 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4AD048166A for ; Thu, 22 Jan 2026 07:31:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067120; cv=none; b=LSRlNSSumHF8A6/Gl/8WU8pZzk8oo8VGFd3k1TmyDp/fikgL4ezdNgYXAl1A8ZjlKue7MyjIRLHl2a+7Aw0clxWhMk8BLefOE33kZcUpt8Awz04RUaPoG3AtuiOcQYn5s+vjuErhn78diidnA9/r0p/0xqxFtZZt1dsa9fViUP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769067120; c=relaxed/simple; bh=DNIcWZ9QKgcap8GIm+HHaS7sytvjKF8lN4kZaGLyU7M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=BrK457f4N2SxlWbOYRp7DyVnbEf8cxQpcjwWxx13w40i6xdYxDp5w5mDktsaAT4z5vU9a+5t4x06ahi8KwKPjyp00XY3fr4c0jXdgrwKjdZmUYf/k7ziaamuRd5bNJFOIzEMrXcAwb8WZRPjq36JonPH0r3nWhJDTOmtXLVHces= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=eBP2E3Lh; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eBP2E3Lh" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b70bd4a2ccso3470489eec.1 for ; Wed, 21 Jan 2026 23:31:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769067111; x=1769671911; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=6zuXMW9ePaQZdk+//RX5ln7bDZ0bQbPZ3cyiYbZ9aMU=; b=eBP2E3LhxPuLiiomYidfhRD5YnCikVSMXJDNq6u0DW0jTf0Hj55j3eVI0w2pLzUdEP x30GY4kf5rhzrRPAGGTXsa1N0BkolrdePWtdH/xJ88P/jigSUCAcXPTTCTeDsONfOIgq gn+Bv5htAmVL4SH7lbiT3wAWzeQNs/IddrdAE4siOBXQ4fAEutZQsOyYBNgu5saGn8SO w7kqVIyspOuE2Ya/45DGqzMA/hxd985wxXBBMM6jKDka/cIp/BdtP3ZZ/qBB6rbamCN6 uis34HZUiHUY5X847R0H2pAAIwRtZekgmvQBntQw8WSm6XZ8OOSICGWvQoxb6bTzdL0Z ug5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769067111; x=1769671911; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6zuXMW9ePaQZdk+//RX5ln7bDZ0bQbPZ3cyiYbZ9aMU=; b=Dbj8xkNAfXQIsJ5wgD7t3ohbE9g4jxq4HlaQlQ+Gyqe/oZ3MGXxZbjQ3a0nQmsfukV oc04a80qY83wZH/+Z/MVadQ7ejCaVOO+sy0gxA0et0LtOA79SQ8HOnXaxSqbudOA7Nn3 TPAtAp3yNV7jdqc0idQskkzhG9IwXnxGCTJvpTPVyegCpJNOR7OGBZ6mzkgaG1DFreQq yjd9Hje0fIqO3bWnsZdvESRdhjPOJAbe6XW0a+SAc6C7UU6LnjwoSpawY/yOlAF4X9Bl /YgOphrknpHOQj3JFmZdq/NKaN0ulr8QcoxiADBozCSq7v491zdyAC5bhsGfxTTkHLvm bsQQ== X-Forwarded-Encrypted: i=1; AJvYcCVXBdTwssvkA0jVD3EzY16WXafEyd0K017pFXxJqofxKcJmwfGfilkJh+xPahdl1vC4xzMSr242Muu/z98=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9aRvc7y8jEeW7QNdY9zDOoxnbKeF43Zqc8bP2VtX0SyYanqSR bFBg/jIqw7rCYReV4H0vP1ykxsjX3UU6iS3BaZzuduHNZhwXx8lS7T5x3Z1C7+jPdaj7UfoLCnc nTi/VTp35wg== X-Received: from dycoz10.prod.google.com ([2002:a05:7301:fc8a:b0:2b7:2358:5b16]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:4350:b0:2b7:f7f:6ad with SMTP id 5a478bee46e88-2b70f7f09f8mr3795608eec.26.1769067110372; Wed, 21 Jan 2026 23:31:50 -0800 (PST) Date: Wed, 21 Jan 2026 23:31:27 -0800 In-Reply-To: <20260122073127.375139-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260122073127.375139-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122073127.375139-12-irogers@google.com> Subject: [PATCH v1 11/11] perf disasm: Minor layout tweaks for struct arch From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , John Garry , Will Deacon , Leo Yan , Guo Ren , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Zecheng Li , Tianyou Li , Thomas Falcon , Julia Lawall , Suchit Karunakaran , Athira Rajeev , Aditya Bodkhe , Howard Chu , "=?UTF-8?q?Krzysztof=20=C5=81opatowski?=" , "Dr. David Alan Gilbert" , Shimin Guo , Sergei Trofimovich , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-riscv@lists.infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pack some holes to bring down the overall struct size from 96 to 88 bytes. Signed-off-by: Ian Rogers --- tools/perf/util/disasm.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/disasm.h b/tools/perf/util/disasm.h index 2793d48aa04e..6a1905f9d4fc 100644 --- a/tools/perf/util/disasm.h +++ b/tools/perf/util/disasm.h @@ -18,22 +18,22 @@ struct type_state; struct disasm_line; =20 struct e_machine_and_e_flags { - uint16_t e_machine; uint32_t e_flags; + uint16_t e_machine; }; =20 struct arch { - /** @id: ELF machine and flags associated with arch. */ - struct e_machine_and_e_flags id; /** @name: name such as "x86" or "powerpc". */ const char *name; const struct ins *instructions; size_t nr_instructions; size_t nr_instructions_allocated; - bool sorted_instructions; const char *insn_suffix; unsigned int model; unsigned int family; + /** @id: ELF machine and flags associated with arch. */ + struct e_machine_and_e_flags id; + bool sorted_instructions; struct { char comment_char; char skip_functions_char; --=20 2.52.0.457.g6b5491de43-goog