From nobody Mon Feb 9 23:43:44 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08BA6130AD6; Thu, 4 Apr 2024 17:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712253441; cv=none; b=Ff8m0yiJ+7CNnqGWgtnMTovTZuZS1FXzJ3r/lB2cYmkpiqsrYH4JI30QnMv7jq0VL7sjg/TeZLnVytdL/rHozvJFqt4gkyh19e1LInCeVi8L0z0RdQU61IIYzAI/H8KSBFfpJzrpubF7qLsJwgWdCaDBgf358we6TrgNaPNqUBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712253441; c=relaxed/simple; bh=fv8+KGbOGn0vJth3f19KOjYOJnNdxCaQN7X8NxsFZaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uhNgdpUPcMWQwURiXe3WoaxV0Qeyi/0fRAkI8NT174KwFhuU7qmKueji1dOQupaRWXy0nxywFn7+cP8IzjaMAXQfN7Yu7tYFrMvIBfYCHMROmyRoQwE3UZsFCV50L8kHnHtXTqvCcNKiSCw+Caf2rWJk7RustEs4znziqnA7Uo4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T/ErhSB9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T/ErhSB9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89856C433C7; Thu, 4 Apr 2024 17:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712253440; bh=fv8+KGbOGn0vJth3f19KOjYOJnNdxCaQN7X8NxsFZaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T/ErhSB9/JWesnoJaud1PgLIOFJdTGdy6nla3lvbvaEdlivSQQzR5e1WlKjpMkm6j 6Ll6ojkBFCp/vOHhg7NLro1t8xwJCxYtndcOtGzDGabrzR193eG5ZwdGZiNwZhfNKT sQIVzaNlUUe6RtlqHogKOp6bxVCCtMbomvSVFaqsqbYEyPuj7iA21A2WaZXKBi6Ab1 F5nbA0tKhQKVeGIhspnDsLooivXyR0thTR6ZEUY20ee7yHZLuKKqp8gwl32dcmC+tE VurtgaKsvTAxheDuJGcifvyOqUJZxO0OyFOmxdoJVyYhfzVb2BxfqWKp0ul5TYsThP BNmlw0shmU0LQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers , Kan Liang Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org Subject: [PATCH 4/9] perf annotate: Check annotation lines more efficiently Date: Thu, 4 Apr 2024 10:57:11 -0700 Message-ID: <20240404175716.1225482-5-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog In-Reply-To: <20240404175716.1225482-1-namhyung@kernel.org> References: <20240404175716.1225482-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In some places, it checks annotated (disasm) lines for each byte. But as it already has a list of disasm lines, it'd be better to traverse the list entries instead of checking every offset with linear search (by annotated_source__get_line() helper). Signed-off-by: Namhyung Kim --- tools/perf/util/annotate.c | 56 ++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 2409d7424c71..d98fc248ba5b 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -383,12 +383,19 @@ struct annotation_line *annotated_source__get_line(st= ruct annotated_source *src, =20 static unsigned annotation__count_insn(struct annotation *notes, u64 start= , u64 end) { + struct annotation_line *al; unsigned n_insn =3D 0; - u64 offset; =20 - for (offset =3D start; offset <=3D end; offset++) { - if (annotated_source__get_line(notes->src, offset)) - n_insn++; + al =3D annotated_source__get_line(notes->src, start); + if (al =3D=3D NULL) + return 0; + + list_for_each_entry_from(al, ¬es->src->source, node) { + if (al->offset =3D=3D -1) + continue; + if ((u64)al->offset > end) + break; + n_insn++; } return n_insn; } @@ -405,10 +412,10 @@ static void annotation__count_and_fill(struct annotat= ion *notes, u64 start, u64 { unsigned n_insn; unsigned int cover_insn =3D 0; - u64 offset; =20 n_insn =3D annotation__count_insn(notes, start, end); if (n_insn && ch->num && ch->cycles) { + struct annotation_line *al; struct annotated_branch *branch; float ipc =3D n_insn / ((double)ch->cycles / (double)ch->num); =20 @@ -416,11 +423,16 @@ static void annotation__count_and_fill(struct annotat= ion *notes, u64 start, u64 if (ch->reset >=3D 0x7fff) return; =20 - for (offset =3D start; offset <=3D end; offset++) { - struct annotation_line *al; + al =3D annotated_source__get_line(notes->src, start); + if (al =3D=3D NULL) + return; =20 - al =3D annotated_source__get_line(notes->src, offset); - if (al && al->cycles && al->cycles->ipc =3D=3D 0.0) { + list_for_each_entry_from(al, ¬es->src->source, node) { + if (al->offset =3D=3D -1) + continue; + if ((u64)al->offset > end) + break; + if (al->cycles && al->cycles->ipc =3D=3D 0.0) { al->cycles->ipc =3D ipc; cover_insn++; } @@ -1268,13 +1280,16 @@ void symbol__annotate_decay_histogram(struct symbol= *sym, int evidx) { struct annotation *notes =3D symbol__annotation(sym); struct sym_hist *h =3D annotation__histogram(notes, evidx); - int len =3D symbol__size(sym), offset; + struct annotation_line *al; =20 h->nr_samples =3D 0; - for (offset =3D 0; offset < len; ++offset) { + list_for_each_entry(al, ¬es->src->source, node) { struct sym_hist_entry *entry; =20 - entry =3D annotated_source__hist_entry(notes->src, evidx, offset); + if (al->offset =3D=3D -1) + continue; + + entry =3D annotated_source__hist_entry(notes->src, evidx, al->offset); if (entry =3D=3D NULL) continue; =20 @@ -1334,33 +1349,32 @@ bool disasm_line__is_valid_local_jump(struct disasm= _line *dl, struct symbol *sym static void annotation__mark_jump_targets(struct annotation *notes, struct symbol *sym) { - u64 offset, size =3D symbol__size(sym); + struct annotation_line *al; =20 /* PLT symbols contain external offsets */ if (strstr(sym->name, "@plt")) return; =20 - for (offset =3D 0; offset < size; ++offset) { - struct annotation_line *al; + list_for_each_entry(al, ¬es->src->source, node) { struct disasm_line *dl; + struct annotation_line *target; =20 - al =3D annotated_source__get_line(notes->src, offset); dl =3D disasm_line(al); =20 if (!disasm_line__is_valid_local_jump(dl, sym)) continue; =20 - al =3D notes->src->offsets[dl->ops.target.offset]; - + target =3D annotated_source__get_line(notes->src, + dl->ops.target.offset); /* * FIXME: Oops, no jump target? Buggy disassembler? Or do we * have to adjust to the previous offset? */ - if (al =3D=3D NULL) + if (target =3D=3D NULL) continue; =20 - if (++al->jump_sources > notes->max_jump_sources) - notes->max_jump_sources =3D al->jump_sources; + if (++target->jump_sources > notes->max_jump_sources) + notes->max_jump_sources =3D target->jump_sources; } } =20 --=20 2.44.0.478.gd926399ef9-goog