Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6936284rdb; Tue, 2 Jan 2024 21:12:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEexpFfJXl14HekTWiBymwqDMTF9KXBbiz+y2u/K+r7meLzzvMNSRIvvq9dnRjjT1IcvUHk X-Received: by 2002:a05:622a:407:b0:427:88c0:14e7 with SMTP id n7-20020a05622a040700b0042788c014e7mr17655160qtx.8.1704258733419; Tue, 02 Jan 2024 21:12:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704258733; cv=none; d=google.com; s=arc-20160816; b=T5YVUc/KPdBO4+cTmhIV4jIz3Ow3jr4O8BzfA45s66NW4E+TkSULO7vToEIBfJLvaD qBXqcgGn/FDsHFYYuyo2MYnBcEEpYMi1AR1zJHdkMlsmFELnoYBl+igafvVm4zyJkR/B Z9k5nXbzw8jhcnHxe3rINlusgTQr+ZicAV0WCH43F0ESSoDrBUM/t+/mmN4Wcovs6fdN duR+nA4Wa0P4datuFsofT1SHQ66Y29N+xehvve6QKHFCUEJdB9LctV73OJcRKw4XujGc UPbus0hzzoK4r7ay5dz0emJyL2WL2RIT9ERlrjoIQIHmc4y+FW8oeBISaV1UXH64amkg RS+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=QnywQA305odd9sKHPypg2d0PzGxKOKU5IEe0duYYqhE=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=xX5OvlDrSn9BxKg40iwGOLc2LL0VpZuJq8wMmZnT+60lYsfOZU+4ELevUYIStgyW1S yZQWBzXuhdG8hs3POz0iZ1U5hx8ShhkadDxUTn2XXRRfvu8+gR1gQ+AE24gLqZcOlOnx KoZ3RRCQX+yALNe2F/0vtbLyIspqp1XGZTq4yXLpJ4P2pKZHhvNLfd14l+qpCb2zwFKk BLIhME0L7tAevhaVzuBaMB3RdsGbzQkUVwLcXBH17ARg8nD00V27zLYN0pqsu7mttZZX c9O0T/toUJ6U10rV0NVg49rUAruq3TEJZ6Gp85FLuKjee8Hfd7SrGbPNT84T5B/V3ROk xtHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fAby1ci8; spf=pass (google.com: domain of linux-kernel+bounces-15176-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15176-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r10-20020ac85c8a000000b0042826e29067si4486890qta.628.2024.01.02.21.12.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 21:12:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15176-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fAby1ci8; spf=pass (google.com: domain of linux-kernel+bounces-15176-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15176-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 23EED1C22EC6 for ; Wed, 3 Jan 2024 05:12:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0792B1A27E; Wed, 3 Jan 2024 05:07:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fAby1ci8" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 947A019BAF for ; Wed, 3 Jan 2024 05:07:26 +0000 (UTC) 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 Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbdc1d8025cso11167136276.1 for ; Tue, 02 Jan 2024 21:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704258445; x=1704863245; 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=QnywQA305odd9sKHPypg2d0PzGxKOKU5IEe0duYYqhE=; b=fAby1ci8YELtifcOgTQsrwpkWObBWLU4r1puAXyqDfvnShZnHFUnYY006dyVOpo43a QAGkkTII8AfvakOjAMFUHHTzRI9rxwczF4PTCDvUHW2UOD9yD9wW1PdiOoL9gDowX300 O0BxgS+5YNIHSQEpeefRPq5Bh1UcO/PDHgRqjN6WrEphqjSefXMF6ekyx33Rdzkqs2Bo iMaqbLGEg8BnP1tCi3fMTi4+rEaFrI/4lFuD8YazAZMGFGH0LrSBGHnDalgqi5T3VYsN /OGBanJqk6alu32VpkHse9wBsQ7Q78inXexUsVjA/OSFsZIG8zM/xcPlhYkts+7B7wAG OOow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704258445; x=1704863245; 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=QnywQA305odd9sKHPypg2d0PzGxKOKU5IEe0duYYqhE=; b=eVFtHRVpQo6bfGxazFROBKY/BvESqFtmMgSZAe+l/EVqa+QV7vnTSZc03eveXe/Cmd eDs2VQJajuD72Wo69N3POQODTo7amQUo1wYr054dG63WuMWVS6FkAygVHk1IMjn38boZ V+dKAuyzD+HJcoJB4+zupy6wPP5aGIDIYAek22Mdg90mtZLwSFkJdzldwMt4syQw2EhV dXYQmjLpyofLuxOgMzMw7mBhUQdLZfa3Lb5B4jCnIzPUXYu5ROGH+9njie6NAjKNWgSe EVEig1+voMT+eyY1/EdhRRZkSq1V7z9cfkvFYpnlWB11fdjhhj/ES9YF+U7a1y5XEVV3 JJAA== X-Gm-Message-State: AOJu0YwQEIHzcZZCFKosZ8ECvj/TQcm6q9b765ZdUEQH1JB+vPux8KZc HxaSnWMiQsIjcTaAF3I15sFW229wGfkBeLRnqTI= X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e2bd:f1f6:8ea6:8d6c]) (user=irogers job=sendgmr) by 2002:a05:6902:1347:b0:dbc:ed8b:feaa with SMTP id g7-20020a056902134700b00dbced8bfeaamr5165498ybu.10.1704258445701; Tue, 02 Jan 2024 21:07:25 -0800 (PST) Date: Tue, 2 Jan 2024 21:06:27 -0800 In-Reply-To: <20240103050635.391888-1-irogers@google.com> Message-Id: <20240103050635.391888-18-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240103050635.391888-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Subject: [PATCH v7 17/25] 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" 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 22fd5fa806ed..69b9aa256776 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1269,6 +1269,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 2b9cf9177085..7447d7a1942a 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -237,6 +237,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); @@ -244,6 +247,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.472.g3155946c3a-goog