Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp567308lqp; Thu, 21 Mar 2024 09:04:34 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXdZgjx1I6txd16pqcpWd3tIK+QlU+o6eHAFuzRhiwmwQbq8Yq1ZqmZG5hu8e23qiARaQ6IyDtxpbLL5izDcMCB1H8Bp+DN03jzB5hs/g== X-Google-Smtp-Source: AGHT+IFnslYl++/U5CjweYWHUY4N/tzCYObh0p/FUuM+uPQzZ163omXdg4IhYiUDj1anAstnUEzX X-Received: by 2002:a67:bc12:0:b0:476:a7e4:4647 with SMTP id t18-20020a67bc12000000b00476a7e44647mr2022918vsn.35.1711037074020; Thu, 21 Mar 2024 09:04:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711037074; cv=pass; d=google.com; s=arc-20160816; b=pPjXS3NRtHxNRT46AVzmrlPl0t/Zv2cmwnzSIY8mYhpHv1XDL8Ey4L0tZ36oYfRtzl yx4RVXODZzjfn4M4j+zB6uBJLO+7L096NbGdtpSl0q64mWwL86s0Fw9nvNJhMcinct9B 8QwXBRIP4P/PT0nZtXeVDFSrEknDfiPM4Gq826yGRElrsEglz8GRxpcXb3DnRZMP0gcJ +re7mbSuTH1nLPVZOEUZru1yf9DvAC23uVftTb23AeExXrzO2Gfwq0ALIn+a4Kt4cj0t aD//Lt5f5RSZ3wHlVyEcr/OtilxtAAj/Qh+AnOl3qM5QH+Pl01vqSiVJTPyKUOdMgsaQ Efgg== ARC-Message-Signature: i=2; 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=G9mbEbN1xeqzONkxcGNMMjxISnrWiZEkSSQzXGtcTD4=; fh=BGaO1kfvvEHFGdOBCHi7luiYQl2fZdbuMt/4qsbdKjY=; b=My8QhhgQLwFaqsymexVxu3I0ElXGmyFzq2lwan/epApH7hSbOE/7SZa4HcdqO66K7h pqPUhfHTdeSG0hRnW23YOEwMIP9fYswVgTyv8x2ypFwaSdnX5Ly5n9D7a62+JzJmvurs E24kgREWFp5gJG2rfAPeNxDwiY9P7z5+fcDy/yqZ3qZ0RN8wNKmpiEdxnIFTNuixEJcv KIv7Nu6VYYYRvcOsMhiIdDXT+gJOwNJ6D7L2aIwLfb/aG1zGXCAYrEHAeVtHqAZtuRI2 b610BDaB9tD0tLwmDh8SssOWthvfqban9EYW+DlV4BbA3m65tfZf62Qtp2R0tukwH1lj a2iQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Mdb7spP3; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-110300-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110300-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 j8-20020a056102334800b0047669edd0f4si17599vse.548.2024.03.21.09.04.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:04:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110300-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=Mdb7spP3; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-110300-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110300-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 92E061C2186D for ; Thu, 21 Mar 2024 16:04:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9276112CD8F; Thu, 21 Mar 2024 16:03:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Mdb7spP3" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 A0A6712BF23 for ; Thu, 21 Mar 2024 16:03:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037001; cv=none; b=EnIsenZJnO4SUSgamAaKKBSKtW5f3XJNBBMlAQykbP3lURQpQUeAsPBAl2+Zi/nafJVXawMohBNXHAeieUNsD5//LcCLLZ+yGrJa4XDQMfeL/j7MteWjbuzfhPALY+/WTnu1Ltxl2g2XBWh3MMP3tV0Z9iIEuzCGfPS7AmY20Ek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711037001; c=relaxed/simple; bh=9LrrlqsVcKRB6YFnDGI9TYjo4HpRppL0r92IM1Tgoh4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=SaWWpXPPj+99gKBe4PPgW5PqvYKQI+sDZlcpLwwaoRCZ46FU70Cn2UXtiobKpUREsMFdAnh4SdzPp+BeXU5S3EfCWxWDN+zc2Xp4QXdGctO9WA5cl+t13Z6vuEZTTB9EA9rA5lDljI+en9acdP0B5QbfCWZWEE5gW92MxlTr808= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Mdb7spP3; arc=none smtp.client-ip=209.85.219.201 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-f201.google.com with SMTP id 3f1490d57ef6-dd944567b6cso1494676276.2 for ; Thu, 21 Mar 2024 09:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711036999; x=1711641799; 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=G9mbEbN1xeqzONkxcGNMMjxISnrWiZEkSSQzXGtcTD4=; b=Mdb7spP32sGQEDm0u4BJmuQ50CiiR95D5hOAsmq/iCi7OoJ9z/PgZ1jrDduIWvcnEq LzRn2L+Ebl0pEsVYiDeKbRBAr2fXSgS6JKwEya501VjjDNbHnnR7akVowIJ4FwMGjFXK hbKiaDwC1/iMznYYWQFGYFmD72sF8Qx8Kbd170XdHHt6pfssaud2oDGlimZ2+wWlPhua 8s0D2DLmJTNwQZcU3YuHc97CU1Y6AJcaKfw0OYcMh1odkbIx5pOf8gw1wPqnk40ttePL AGH22U7ixF7dpWifcrknw6ylwxXI3oMzaz3jClY3C+msJJ6SP4hhzobQ+kWMcj4acE5U pwqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711036999; x=1711641799; 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=G9mbEbN1xeqzONkxcGNMMjxISnrWiZEkSSQzXGtcTD4=; b=lyzEaiE0AF3i7YYgb92FOsbPDGY7oc58rmbMIra95bCLQ2GItmghM4ai4R0e3NSHou Fo/NZavk/65mvtflfivbiBXDp2H3UhpwT0666WY904drCt1uEUiVkKG4LofVw83rqsw6 m+8fkoaKjGZnJhRV8d45ufA3KlafP0FSikdIaNjkz1LPL3sJcJg1bjDd9Kl2+HsEYyon 5oReu8BmzXTayoRcuGjL6+BF7/WfbYfDe9fWLFKhmSvGYVFm2Gr+Hj/2LMXkPr9SGKzE EIQ+J8VyEtvq1Cmdc14sSIoYpC+zihC5WSmqyIPRAHkUfXU9SknOtebwi7x+Gqby9QKk hUZw== X-Forwarded-Encrypted: i=1; AJvYcCVNeWvQ3ZprNIorjjgnCK1EbuM5ATgky03QUmEXPBDn0YtXeb54cI8lKLowlXJY2zwqeBhUdnHhQQa7vQM1PXn9g9lybD/QpKNVpAno X-Gm-Message-State: AOJu0Yw28sT9Ng5IfKTYsOfzxQmjcjKIRJpgNJRypMLCLsKACnIAfDdu OIehG07CkYKiAuVNIa7EVPX3UFdviApU+844Tch0WAbouL4+sxBtOrTQZiuFVKIyBZGPq9t/Cdm khm8dwQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7f3:cf74:42c4:c0a]) (user=irogers job=sendgmr) by 2002:a05:6902:218c:b0:dcc:4785:b51e with SMTP id dl12-20020a056902218c00b00dcc4785b51emr969569ybb.12.1711036998640; Thu, 21 Mar 2024 09:03:18 -0700 (PDT) Date: Thu, 21 Mar 2024 09:02:52 -0700 In-Reply-To: <20240321160300.1635121-1-irogers@google.com> Message-Id: <20240321160300.1635121-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240321160300.1635121-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.396.g6e790dbe36-goog Subject: [PATCH v2 05/13] perf dso: Move dso functions out of dsos From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Athira Rajeev , Colin Ian King , "=?UTF-8?q?Ahelenia=20Ziemia=C5=84ska?=" , Leo Yan , Song Liu , Miguel Ojeda , Liam Howlett , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Kan Liang , Yanteng Si , Ravi Bangoria , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , elfring@users.sourceforge.net, Andi Kleen , Markus Elfring , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org 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 6e2a7198b382..ad562743d769 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 3d4faad8d5dc..2c295438226d 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -238,6 +238,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); @@ -245,6 +248,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.44.0.396.g6e790dbe36-goog