From nobody Sun Feb 8 21:47:06 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 5D1DC3EBF16 for ; Thu, 22 Jan 2026 16:54:29 +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=1769100877; cv=none; b=TkcHYG6eti2eD4Y5XxlpN6nAbuzTlgFGGd27E8Etzw6UtWVDcVtaHzCbHMBNKrfylceoXLrbjt6HDgGTzqrtx/GUOnWsAdmMbKHFDpEJsG7otcIJ+m41ZXHwdDnsMRCNWeed3l/wy0SLUIpuMgzl2Lr6/kksguxQ3b7RYnGkwHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769100877; c=relaxed/simple; bh=KR5+2EshErmuRybWcBELHd/O8khmGf6P5Bg86ngz38E=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=ZDHuzG/K3ARx8M7yMu0lDm+9cLPmQnSoGHDWcBa286Ig78OA24wU7vXmcTiN2/SaAMtpjjgGohVHcaoccyOd/gaeMTX5/2+1Fb4o9lsPPP/9aQsOsJPVSovi5rzo/wzBbVzgyyG/RQDA3rn8FFGS/V3+/d48idpoeXtI/LwPS+Q= 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=vLLLvjm2; 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="vLLLvjm2" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-2b704019c98so1266762eec.0 for ; Thu, 22 Jan 2026 08:54:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769100866; x=1769705666; 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=LJvCENf9OUao4NjSk9nvAVIfxbnn+tkq0I5XRhSJkfA=; b=vLLLvjm2OTcAI8h0rOuRT1Dk7RwqfSamkn1ITs0RE6z8oyaeGNbdME4rI5a/KhTYlI /ZKkfQZUZA7fYz0a2JUdDrxSKuabpKH31nOuOIsvcTFpEDb2ANUNWieatwgHrSNzpIJb 0zTcMF2Rgm8KY3EIEmCH0VjTiZu7odMHvQ4bb2WeCCUFWx7MN39J5/o3TFQeng1Qbx0c 9kSBoWQxetCOHq5DaORjay2tTw91r6lQNLtNl/tRMW6eUhTwMSXSrdUCqjM/7ZmxP1YS sDc0K8CE8K6aeAtW3FrD6nfd6kO8izLFwf/oXfceN9PDI+m6LNTwF9drVjW4I5+zmIDm By2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769100866; x=1769705666; 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=LJvCENf9OUao4NjSk9nvAVIfxbnn+tkq0I5XRhSJkfA=; b=VlJPpBPfC6YXPa1Lis6jxWSrf+pNVls5+hn44ktbv4L+8FDljv7ELT/8UrfmzRzGyb BaqgfqZ//9sBj0yJv/LQEuT4Pz4Q5ahD/+09qk+Zl09BZfIgDVfMIcrze5i2VthT8elm vtEdrpAvrHia6iMf6Yv+V7ZF2rdD/QKKRz4btFRNfeLTD/JtsDABaXcsVP/soB9/dYMy qRhT6MBmlEwbvAaZfwYtWp4v6q44nYh46YXqM8T62fUdBYy3zTK30/iePC1tmTlk6YEo CMw8cKpKIWzm4RcrUnUQTqKhz0G1UejjITKIOz+SrUYXB2MGuUzYjb5FL3c3cGStK1bb etTw== X-Forwarded-Encrypted: i=1; AJvYcCUraAlKz8z1coTrEsi/+sicHOhmMmcZ6j+HjFZr+1v8iZpr2hcsFdJzxGZubKSqQkbtOL6mc8qlFGPs5pA=@vger.kernel.org X-Gm-Message-State: AOJu0YwlSQpHb/JeJVm61Y6V8NKsMOpcNRdYlSx+mlmEnm/OUdpdokn7 awiRNS2Nka83XwtzlB5hMjJcTkVR4Z2pcjENTmipwgVMdSpSDyKJSyKXyN0N9tCAeRvVKtZp0aJ 3MfP4hHPSmg== X-Received: from dycna11.prod.google.com ([2002:a05:7300:ea8b:b0:2b0:5418:353f]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:693c:3005:b0:2b7:13f5:43ac with SMTP id 5a478bee46e88-2b713f54696mr3598450eec.15.1769100865487; Thu, 22 Jan 2026 08:54:25 -0800 (PST) Date: Thu, 22 Jan 2026 08:54:01 -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-7-irogers@google.com> Subject: [PATCH v2 06/12] 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 9bc9b1de98db..2793697ce75c 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