Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3429866rdh; Mon, 27 Nov 2023 14:15:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPkGIRQrerVBp/z96H+HT8IIpbiliobLoGlIOZ49wdKE8X/uQistQ9LbSAxLO6cD/leajV X-Received: by 2002:a92:cc45:0:b0:35c:789a:ccb4 with SMTP id t5-20020a92cc45000000b0035c789accb4mr11665987ilq.24.1701123303841; Mon, 27 Nov 2023 14:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701123303; cv=none; d=google.com; s=arc-20160816; b=ujoHtzsqAs6WYdiRwaTUwBvU66ouA1xuVp0a/IvEVgYegTqzn0VRZ3XzwVxalVM7lG i+aFoZ14X6kBiVHHS9yIURdTZ+AThHygpxCmJbBRGkcNwjGH0TjiHhUvKMwCXLsl6ciR XQ0d8BGBFiW7icEzc7t4t43EhPVWZKBPJCsB+rpF2EGdFU1cVCrfoKuNSVJ/e0SAgUQt STy848jERfEerknVX+/DP/iU1144JNr+XhfNa6tKTn3pOg60lWo/2fjezy03lQBQb1tp 4PCVsVFA/aXP/0vK7H0Ird92zp6W1/Z7fBczGz6QyasKm2ypQNCwVxzoHXeXdlork5Vs l5+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=QTYELVsMNSn9FzIG0KWWztNJ9JaJROGY0ifNjwNzxkc=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=F7h4ilQi3yGPWKp+1+oRotQ2rMlmFrQ58HFb9xXcIkuaknu9lsrOICMtUI87Eu4Gub O6zpimvN3mipN5u6FKP7FVX1nY9wRMwMVkoV+bmThOsxiDjSx8DwC38/xM+VKPlw3jkz aeiy2IqIMHPYkt6XvChp08A7NCTzxcRIsreVu0HFPqD/oVWDRu2hFMXRz8cRh9YNabWN phPIDWSya/bYkBraQcjuGgFSsxmqAJ15W+nwIZJ8soh+wcJdghHlTU/5hEr1d6Ao6rXN nhtI/WKF/3mKYOXXITxvbpBX338eqJv1l0QzgNAwWExMMUdetHTaFcKhd4J+35/wXV2U n6Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OfIBrK9g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id s23-20020a656917000000b005c24214bfffsi10683044pgq.412.2023.11.27.14.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 14:15:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OfIBrK9g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 1EC2E807385A; Mon, 27 Nov 2023 14:15:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233745AbjK0WOj (ORCPT + 99 others); Mon, 27 Nov 2023 17:14:39 -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-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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 27 Nov 2023 14:15:00 -0800 (PST) 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, const char *name, struct dso_ __dsos__findnew_link_by_longname_id(root, dso, NULL, id); } +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 = id->maj; + dso->id.min = id->min; + dso->id.ino = id->ino; + dso->id.ino_generation = 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_allocated) { 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 = true; } +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_allocated); void dso__set_long_name(struct dso *dso, const char *name, bool name_allocated); +void dso__inject_id(struct dso *dso, struct dso_id *id); int dso__name_len(const struct dso *dso); 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); } -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 = id->maj; - dso->id.min = id->min; - dso->id.ino = id->ino; - dso->id.ino_generation = 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 = &dsos->head; -- 2.43.0.rc1.413.gea7ed67945-goog