From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 AEE3D7994B for ; Mon, 4 Mar 2024 18:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709577354; cv=none; b=JyALeEZwr4OmsXkT60ljQqO6rEZujYsLQIr4OQTembNZVxnlsds4XyFTnsSzdNoUU1vlYxUtWLI55uePQpIdV06f55d7UpPjVbZo9/QsttQ+BARZVjK6G2esNQ5mVEik8rQUxNIACVEkQyZVRGwczI5qWEdg0799Ey2oNWeE3So= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709577354; c=relaxed/simple; bh=QrSmy13/9Ha6STFBsJdzjqHoQ22optSdm5UqcwkqLK4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=DLudqd93LsW3JYKlfJ5kNZa70dRSiFN8bpc067Ya5i79qt2GgVNkKVd/H+UDwbf01rqC+xDHvp8N5LgycgNYhRt8PbOiGMok+I4dHJvWjIkmkrsmxTcge2rQiTSSCsxFfE47wrRSrbadLneF6uNa4i+DOttcgskgt69PtWQqmp8= 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=vZIkWC8g; arc=none smtp.client-ip=209.85.128.202 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vZIkWC8g" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60987370f06so35236107b3.1 for ; Mon, 04 Mar 2024 10:35:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709577352; x=1710182152; 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=mIv3NxAA/SUyMYNLyp+4H26Q3ru/ng/h+58kwWeCpLc=; b=vZIkWC8gBTdvTYabqzl7tirhBV/vukPasqGRRtptCRJMK8hmqjtuWnstsworT7leU8 TlJNuuO4Qoll06CondpzYLU+JlPYc3Bz7X+femGRTpNhc0T6P90CFzmTD7QZi3dIIpac nsPSTKQgKt2ZdGbASPNIZG96ROEk+r3jDc5SXj1tvHev12UkXnlOqv4Gwo5lO0qju0aL ZZSNekS4IocGMVPLrE73oKLzQ8ilOy4+7Ji9pLc4wMSIbQLjtbPgbDJY9ZVBaZs1Lh1Y SX7EnHKzZyRpneYrATmLo2+piaKHCN9pvBYR2EYmmpIPfyYv72WvYdC5ZW4/Vbaopz6O CgOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709577352; x=1710182152; 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=mIv3NxAA/SUyMYNLyp+4H26Q3ru/ng/h+58kwWeCpLc=; b=ggJatdcYn7mEs7q7R50dL7pRQUfnkikTN3P094AyfW1nJ94/E/z9SF3azcUToXRgG1 egfXaeoslajYfBNSKu4OSbJBICTSrvtkJ1CkYucAiyl43ew401koKe7mpMany8UZo0HI kXtJk2YeHCbM73vM0KkXwVxU6QIgKz/zF3FdjZ/zlvC8uPCID80j14x3Tnh8EBQsiuJS KsjznNTFQplmigL1+Q8XFYh0Px1xxSV/L4GiW+27CB/gYyDCk3lOUDekyLXsmkq4bBI6 IJ/1Ns2nw4hFxPk11kFTyr+Z7tKG42Hd7Bmv+FgKqMFlKu9FgX0m2WzGGKWkQkuJJgpM clZQ== X-Forwarded-Encrypted: i=1; AJvYcCV0pHjubiuRFBVL5b1rgpBsGCpohFHsxYwsSSSC0G9z+DSibHaSlJOsY+A4FQLd1dlFuTLz/XB/NWabFg84WQoj+CwOmnH2T2V5rg7s X-Gm-Message-State: AOJu0YxyELJ5EygnGQoHlKdl38gmyO3g1XhplbXHXvbaya9ap9+HYarJ UmJ+wqPBcRv3BtdwMculwKL/2VxEzteMv8sXpt1mIlrNbTxNF/7vn+/pmLHBKMEjYDVdZ3y9f5o IF46y6w== X-Google-Smtp-Source: AGHT+IHhIyitjE0gDji0P58ykUnYzRPqwSWjvyku+79XD48BXD1lRyrDQoD+gLHjbqE0JKOnix0e0qHz8yHk X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:38b7:9cbf:f246:dafb]) (user=irogers job=sendgmr) by 2002:a05:6902:154e:b0:dc7:3189:4e75 with SMTP id r14-20020a056902154e00b00dc731894e75mr337563ybu.3.1709577351690; Mon, 04 Mar 2024 10:35:51 -0800 (PST) Date: Mon, 4 Mar 2024 10:35:16 -0800 In-Reply-To: <20240304183525.3222581-1-irogers@google.com> Message-Id: <20240304183525.3222581-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: <20240304183525.3222581-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 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 , German Gomez , Sun Haiyong , Changbin Du , Masami Hiramatsu , zhaimingbing , Paran Lee , Li Dong , linux-perf-users@vger.kernel.org, linux-kernel@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 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.44.0.278.ge034bb2e1d-goog