From nobody Mon Feb 9 00:53:29 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 7CB9B366819 for ; Thu, 22 Jan 2026 16:54:31 +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=1769100881; cv=none; b=cDy1BCnXYLHF17kToOIBm8/rEihvBU7ZtXDhmw4iqcgkOURl+w+bFwajqdCFB0E2sCso3CODp+e93i7TU7mIr4SPDBPJJoy2OMCGARupW7rZOnWxKC7R98kLnxAUnpuF3qZcChMN52iVLFBsyz7j9P9l2fPlo8afgjHSD7q4daM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100881; c=relaxed/simple; bh=sRclvWe9do8aJB1oNVcjn3sHrsa8VOSwS5xxwOFocf8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=cIAYcdLghXvkLVMqMiUrP+/Pckged6VlCEEr111qEGxoT4gdcD0cilV81B4WNnztSN3QhhN+ub/5QIIIlfL0sOLrXgg+0Dq3YS9LtjTd141oA1AN0S9H0JqnofUI/y2WTyBkZSm6F9qSaRYxYVNIsFRwtDpOk94yY/DS8OyoImY= 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=KchcVmj5; 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="KchcVmj5" Received: by mail-dy1-f202.google.com with SMTP id 5a478bee46e88-2b724ff60e6so982943eec.0 for ; Thu, 22 Jan 2026 08:54:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100868; x=1769705668; 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=mohShwdVVANhhguIax08ioRiqfRGyb+9L7Fn7SVEHWE=; b=KchcVmj5Ms28YNpMprKIkNJ37Ln0M+9RxZ2EUBI4GqU3BUqvaBk9cdJK5tuOwzOTDL Dg6s9O44/G8FrrmbrwIpbInC/Ltf95PpDfvvk9zJaYVecHMX0clD6W2MTVSNU2Slb7K1 vThJ63PUqaEnPv1iN8bLnysmeH5OuxjNv6h3FFF3rGKtiDgLULIn3dtBJnqDNnRd3zzQ TkjF1Le38Z4cW9xwK796KKuKYehWewqFH5wO2dHbfpCY4vwjMTn/foxO06HdvtID9JeK oRU2A84XvASPihEcT6m7AJZYHmP8AuqV4H+tdlUPmY7sF/p35CJjRZuDRPQTtR6IVA9A SIZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100868; x=1769705668; 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=mohShwdVVANhhguIax08ioRiqfRGyb+9L7Fn7SVEHWE=; b=BG+MKIyhzq/lD+G7BpoblbS0EuE/pxccC0jA6H/J/Jrvs7Fu07BkHsTSFejzNTgk1W AcyQ4BVpPAQWNK9JwgFzMho5TY5SMOGcDJxoGfN2bD/T/Kjp6AY80ki+8WD4i6NlUBZZ aBbLgQVJT9aVjneFNvW8d0+ycz7wLa0o+3kdVO5krokXkeXzAcNbbbWCVxlWRLeOCCdP UZqy4ygzQwewWmyiSfMednWYaKYoMAhfFgAc0m8dSl2JlnzRPoQHRqY/bI9t/93yMuj6 xl9bYKyKCrmE7qsNb4EyrqV19BY1nd5rKLu0QhDD3OJ4pIiY2kAGmkjMUOzA2oTyI5F7 qKeA== X-Forwarded-Encrypted: i=1; AJvYcCXBt6G7rT47JUp4CvOw/7oPB009FIxbtSnNSUQ6jJuQf8k1g47AW90QNIc/2vrvh7JDEu6txW3Cxbskq9Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzdVQLqltc7JDsTwB0auuJicZ/tM2GqSTKyko1oJDpnFtqQYiYp jnwT8spRfe1kFcI9yWSTtt8PKE2KRbJYb6bZsMm0+jdpfkFunwB4R+5dz4oQ/v8j6WC3R3aEasv HLt57zf/+YQ== X-Received: from dycoh11.prod.google.com ([2002:a05:7301:da0b:b0:2b7:9eb:9ca9]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7300:8623:b0:2b0:5735:25a1 with SMTP id 5a478bee46e88-2b6fd5d816fmr6237134eec.7.1769100867496; Thu, 22 Jan 2026 08:54:27 -0800 (PST) Date: Thu, 22 Jan 2026 08:54:02 -0800 In-Reply-To: <20260122165407.561888-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: <20260122165407.561888-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260122165407.561888-8-irogers@google.com> Subject: [PATCH v2 07/12] 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 2793697ce75c..b7523256c4ad 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) @@ -1700,7 +1705,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