Received: by 2002:a05:7412:b795:b0:e2:908c:2ebd with SMTP id iv21csp559282rdb; Thu, 2 Nov 2023 11:06:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEro+psE/XfdiO11Xs/hd7z/I+5ClpzCIInK5d2BZ4VLPecHdGLio1szF/DGZdCMVKyOQFg X-Received: by 2002:a05:6a00:1410:b0:6ba:bd35:9efd with SMTP id l16-20020a056a00141000b006babd359efdmr17009465pfu.5.1698948397501; Thu, 02 Nov 2023 11:06:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698948397; cv=none; d=google.com; s=arc-20160816; b=Tl+xnFvzwhdM6339xk9TA+Suortu9hvgU9+q5hnUoqD+CT0edhKGxVwBLAbxERzwtf Au3zVqMbBWVZAIx7VGL/20pek+pRMfNKnsqXBVfeVTnYGWuhivRlLoZ3aEQQHyFHNPRv DLe0UwMLP4Oq3oF9+ncn0XMkNTFiWrJnKf7+88FQ2FQjcnCriPrxV7gCBPcSkFUu8pzd SwEBmF8pfz/WhlOhXgqzQscFJeBk0eSVzo8pRFYYCM2la1f3ZwX+L1bKU0Akp/ssGKDo 635WNN29qPbb0BLUPVHqiUt4tPWoWytLV4tlkBKKWVtj+TxxZKw+UkkWpPYNFwIRH8yf kjvA== 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=ETIbyPpooQ3kZGOmPXZ75/2dFjZJwxSdFPAfNzqS1m0=; fh=z1KcSqUpYQ9oC4uLSeIkhAYTnJ2bvP0QbNW2xqV5NqA=; b=VogJt2T7v9To3xdtZrKwX+izmY5GQhqUFahaqDRUdu3unTZz0Y1XfM5Jehq7yFv9TH TM5gw5tvZgtqb2AxvkF773X+vhbio0Jj5LwhNEQgN7ZzeYHDdQd12rSnC7hQkIt5aiAC d8UVp+1N9q1rk9FvHUKBn1DKl/xI024RRkUFFSHFOtfFvkK/WMsuBfHeJ/AW4ve18qbu bKyLdtlv1oMyTxX3b9Y1SsCJj/xhzEMEUFrYf9iSGPvHvMLFmqYHiL61w4l0b2mCCcld mWYgEjA6CHeo/eDgaRdW1ORnZ4g90q4fLIa7FxP1TZX1GNBoU7H3lT5rjc3DY2uKAt1h brug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AoefiHXN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id r7-20020a63e507000000b005b9022ddeb9si60063pgh.501.2023.11.02.11.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:06:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AoefiHXN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 9CEB280657FB; Thu, 2 Nov 2023 11:05:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235666AbjKBSFD (ORCPT + 99 others); Thu, 2 Nov 2023 14:05:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235713AbjKBSEf (ORCPT ); Thu, 2 Nov 2023 14:04:35 -0400 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 66C062118 for ; Thu, 2 Nov 2023 10:59:38 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5afe220cadeso16891987b3.3 for ; Thu, 02 Nov 2023 10:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698947977; x=1699552777; 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=ETIbyPpooQ3kZGOmPXZ75/2dFjZJwxSdFPAfNzqS1m0=; b=AoefiHXNQpIadUOeIEnj+SfguJNnlfQyqXzknOxP6ZsHKxmvrGboUsXIdpVpkXlMZU SidhpH7xHG/i4tnN//ll20gWsETxnk2j8IFF0qv0XkwXtRHB4DCZT3VpgMWA/WkPsHVU JmN7GQD6R8QiD/2KHOvnu5FGhMqF9Q3LHZhDn3Cik8lg3l37tIbSxXdHltc8oBvaHyHb ApG9eJ0PU7j5n6cxQBX2DV56d33mlcZN9S8qzyTuWGfnOGNhUzO6WFao/4afx1qDE6Ja Mcvu8DrKo+3/1QTZTAsTdQaISy1mpVfUiqNFwdaOBZHNpzG3xRU/P2SCcTIBLV2yxZ8A ll1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698947977; x=1699552777; 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=ETIbyPpooQ3kZGOmPXZ75/2dFjZJwxSdFPAfNzqS1m0=; b=RCnqr3rnGBLMYr9AxFyp5AXO9ocJ87ePKOVG6VrTIFVd2EoIZ7qDhQojMwTkzlpy58 mJmK4H/WTzVqwd8PErWGrklqcS8Q1pHo9AMpm3fOed1sqVr7UpY/MSqqW9j6cEK+H01Z +oYCzpSedgeFORWar4GGCq85+qE4xgoGUyGd2nqgqcOm23Pf9+Mt/4Vp05gP+ZaBQQMx qO6EOtegif5B23Kvfs4amB8N0qYTAcBZMS+RgtDjbs/WwbFN9xDqc7xVARfVc55iaj0L YmMT21pzvSQfwbF3sB+h/FIGfzWtZoaOxXM0IBbrMTimxoVOKM7o6LGjNhpHs2G3kT1A QGSw== X-Gm-Message-State: AOJu0YzIWosVibjEDM15P4z/kpCoakvCWDWBKuB08/ZE1pT6g1akg9eI tLGMlu+ICvaf+eCNYoaoe4K5PaskRBU+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bb34:df9c:836c:afca]) (user=irogers job=sendgmr) by 2002:a0d:dd90:0:b0:59b:e97e:f7e2 with SMTP id g138-20020a0ddd90000000b0059be97ef7e2mr7907ywe.4.1698947977308; Thu, 02 Nov 2023 10:59:37 -0700 (PDT) Date: Thu, 2 Nov 2023 10:57:26 -0700 In-Reply-To: <20231102175735.2272696-1-irogers@google.com> Message-Id: <20231102175735.2272696-45-irogers@google.com> Mime-Version: 1.0 References: <20231102175735.2272696-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Subject: [PATCH v4 44/53] 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 02 Nov 2023 11:05:31 -0700 (PDT) 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.42.0.869.gea05f2083d-goog