From nobody Wed Dec 17 12:44:25 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16D15C4167B for ; Mon, 27 Nov 2023 22:14:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233672AbjK0WOo (ORCPT ); Mon, 27 Nov 2023 17:14:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234321AbjK0WN5 (ORCPT ); Mon, 27 Nov 2023 17:13:57 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 845A91FFB for ; Mon, 27 Nov 2023 14:10:58 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5ca26c07848so72300347b3.0 for ; Mon, 27 Nov 2023 14:10:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701123057; x=1701727857; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=QTYELVsMNSn9FzIG0KWWztNJ9JaJROGY0ifNjwNzxkc=; b=OfIBrK9gvv5MIog5jC+fCfi8oF/oZgRWZYxBWfk3eYW/92FpEbAnV2MZ4lxFxqTZVa p2Mj9mcYMr8s9KG02w7Ef0FmKYSE2Ho1xMgONbzULGi26IUWLkVcdL0r5CO9TAma0pz0 NJ03nt4mDuOxEThCmpm3n0mkngCHnE4i97750KGCQ0EuKbeMkLvv8FhgoAYYmFqaLzbc NiilJZtVdrEbwdzpDJQ9B99tVCRHLVGXCz7L2wry5VdLLum94h0p911U+qRopg7Bh2ZX 9++JPRD+O3CFqjth6z5PLMcLba+TTu1C//DmV+L5r6jKDA6msdWls1GMOMWhSCoOCL9k tP9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701123057; x=1701727857; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QTYELVsMNSn9FzIG0KWWztNJ9JaJROGY0ifNjwNzxkc=; b=uhKlpUDevYG2w+OMbdc6S/tBPfNxjp0BtAKOyk4jKOmcbwJZFi/s1bpGiKGXyvQgxy PrSbX6Uue3NaBRSd9MgGRMQFlI65hy3BvX/tlQHML4j618QxlDH/Wtx5oV/hup8aZa1a 7+UjtwZ11GgTcdK/ZjmBoNipl7rb2keYX0nmjCqJZdWukjdJY2/ehfPLn/XxfYBUMCIa eHsL1JpLC7Ke7MUU1CIO0y26ZBE5yW8n5PuYBSfI5aM4dJ5eKeR+A+5ivhe4UnDvrvTe fL3dygXdZpqf+1iBNSb37BppvbXw4L23t7nxF8mpYZTkQNKgJPSuFq7y0Tkf1FKQB/M7 lMmQ== X-Gm-Message-State: AOJu0YxgA64Br+3oxUQVsMTIJ1knOw2r968jmoLQXzoLkpjcpX9wbzjW aBY5u7a1v1lxSJ7uU93pDdOHiOOjYddh X-Google-Smtp-Source: AGHT+IG/qehtXDc1gu/EpczI5diE+ulI2sPLVQvSR3BdLHdFV5zrNknSj+W/wmEN6OUUEdNqdz1i5pdYQwq8 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:829:6e77:9093:f39b]) (user=irogers job=sendgmr) by 2002:a05:690c:2e10:b0:5cd:c47d:d89f with SMTP id et16-20020a05690c2e1000b005cdc47dd89fmr394425ywb.5.1701123057642; Mon, 27 Nov 2023 14:10:57 -0800 (PST) Date: Mon, 27 Nov 2023 14:08:53 -0800 In-Reply-To: <20231127220902.1315692-1-irogers@google.com> Message-Id: <20231127220902.1315692-42-irogers@google.com> Mime-Version: 1.0 References: <20231127220902.1315692-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v5 41/50] perf dso: Move dso functions out of dsos From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move dso and dso_id functions to dso.c to match the struct declarations. Signed-off-by: Ian Rogers --- tools/perf/util/dso.c | 61 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/dso.h | 4 +++ tools/perf/util/dsos.c | 61 ------------------------------------------ 3 files changed, 65 insertions(+), 61 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 1f629b6fb7cf..1b0990507a42 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1268,6 +1268,67 @@ static void dso__set_long_name_id(struct dso *dso, c= onst char *name, struct dso_ __dsos__findnew_link_by_longname_id(root, dso, NULL, id); } =20 +static int __dso_id__cmp(struct dso_id *a, struct dso_id *b) +{ + if (a->maj > b->maj) return -1; + if (a->maj < b->maj) return 1; + + if (a->min > b->min) return -1; + if (a->min < b->min) return 1; + + if (a->ino > b->ino) return -1; + if (a->ino < b->ino) return 1; + + /* + * Synthesized MMAP events have zero ino_generation, avoid comparing + * them with MMAP events with actual ino_generation. + * + * I found it harmful because the mismatch resulted in a new + * dso that did not have a build ID whereas the original dso did have a + * build ID. The build ID was essential because the object was not found + * otherwise. - Adrian + */ + if (a->ino_generation && b->ino_generation) { + if (a->ino_generation > b->ino_generation) return -1; + if (a->ino_generation < b->ino_generation) return 1; + } + + return 0; +} + +bool dso_id__empty(struct dso_id *id) +{ + if (!id) + return true; + + return !id->maj && !id->min && !id->ino && !id->ino_generation; +} + +void dso__inject_id(struct dso *dso, struct dso_id *id) +{ + dso->id.maj =3D id->maj; + dso->id.min =3D id->min; + dso->id.ino =3D id->ino; + dso->id.ino_generation =3D id->ino_generation; +} + +int dso_id__cmp(struct dso_id *a, struct dso_id *b) +{ + /* + * The second is always dso->id, so zeroes if not set, assume passing + * NULL for a means a zeroed id + */ + if (dso_id__empty(a) || dso_id__empty(b)) + return 0; + + return __dso_id__cmp(a, b); +} + +int dso__cmp_id(struct dso *a, struct dso *b) +{ + return __dso_id__cmp(&a->id, &b->id); +} + void dso__set_long_name(struct dso *dso, const char *name, bool name_alloc= ated) { dso__set_long_name_id(dso, name, NULL, name_allocated); diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 8b45dbdae776..1b247eeaa81e 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -235,6 +235,9 @@ static inline void dso__set_loaded(struct dso *dso) dso->loaded =3D true; } =20 +int dso_id__cmp(struct dso_id *a, struct dso_id *b); +bool dso_id__empty(struct dso_id *id); + struct dso *dso__new_id(const char *name, struct dso_id *id); struct dso *dso__new(const char *name); void dso__delete(struct dso *dso); @@ -242,6 +245,7 @@ void dso__delete(struct dso *dso); int dso__cmp_id(struct dso *a, struct dso *b); void dso__set_short_name(struct dso *dso, const char *name, bool name_allo= cated); void dso__set_long_name(struct dso *dso, const char *name, bool name_alloc= ated); +void dso__inject_id(struct dso *dso, struct dso_id *id); =20 int dso__name_len(const struct dso *dso); =20 diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index d43f64939b12..f816927a21ff 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -41,67 +41,6 @@ void dsos__exit(struct dsos *dsos) exit_rwsem(&dsos->lock); } =20 -static int __dso_id__cmp(struct dso_id *a, struct dso_id *b) -{ - if (a->maj > b->maj) return -1; - if (a->maj < b->maj) return 1; - - if (a->min > b->min) return -1; - if (a->min < b->min) return 1; - - if (a->ino > b->ino) return -1; - if (a->ino < b->ino) return 1; - - /* - * Synthesized MMAP events have zero ino_generation, avoid comparing - * them with MMAP events with actual ino_generation. - * - * I found it harmful because the mismatch resulted in a new - * dso that did not have a build ID whereas the original dso did have a - * build ID. The build ID was essential because the object was not found - * otherwise. - Adrian - */ - if (a->ino_generation && b->ino_generation) { - if (a->ino_generation > b->ino_generation) return -1; - if (a->ino_generation < b->ino_generation) return 1; - } - - return 0; -} - -static bool dso_id__empty(struct dso_id *id) -{ - if (!id) - return true; - - return !id->maj && !id->min && !id->ino && !id->ino_generation; -} - -static void dso__inject_id(struct dso *dso, struct dso_id *id) -{ - dso->id.maj =3D id->maj; - dso->id.min =3D id->min; - dso->id.ino =3D id->ino; - dso->id.ino_generation =3D id->ino_generation; -} - -static int dso_id__cmp(struct dso_id *a, struct dso_id *b) -{ - /* - * The second is always dso->id, so zeroes if not set, assume passing - * NULL for a means a zeroed id - */ - if (dso_id__empty(a) || dso_id__empty(b)) - return 0; - - return __dso_id__cmp(a, b); -} - -int dso__cmp_id(struct dso *a, struct dso *b) -{ - return __dso_id__cmp(&a->id, &b->id); -} - bool __dsos__read_build_ids(struct dsos *dsos, bool with_hits) { struct list_head *head =3D &dsos->head; --=20 2.43.0.rc1.413.gea7ed67945-goog