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 C2DFA7994C for ; Mon, 4 Mar 2024 18:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709577354; cv=none; b=DmdsskhvulPXEaaKFWeT6qxvfdwF0lHLO5YOdjX5Bg9Fw3eE0iwc04SkEuHMtyPx1+/sIUUyslFVMpzJ2y7KBzx3B0nd87oF8l0Q5gjXlLr//mcPOyBSgIAFr9zvh+lddi3drx+dKb6Bzqg2wlYMOdZiNUEVd8T9S5YgmngJHaw= 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.219.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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dcc05887ee9so6494419276.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=g1l2PniQUsLQFUqShc7U0T2n9Fl+1wC7ADSfdimRM2CE7R2qptad1mgPc0wV+nbG6M 7t3iM08qms3pp9XNc68Pi3B4TwA6HU0/JAMT/wXi4kyxpQhraNv5ZfBxnS2oROWl0mJj rjcJMzuONdMrZnyFYJbUMW0zDMUAJ6PNyqtcyqpZ4lYqIgsot93veA88AmyLOS0GyW3H SBF6wdeTxNvYr339nEh5dYh15mVElHlf4aUXqh/O2QOS8jUMHX63GumMjf7uBRtZLRrn pRr4r+nHslgeRZiLKddDSMj8z6Tfifjy8Fra7OxuvESyWktbYQdG+q+QmnGjKPin5VfT XqQQ== X-Forwarded-Encrypted: i=1; AJvYcCWYrJKgHJl/nbvF6Ovq0oOZAXWoNJDrRd9s7uInTWcy3nHnr6saWPWCal30oPfJAU8YSvx44QGGnB2abLEznBvUlDzDx7TJdOBzTybvnN+ASg== X-Gm-Message-State: AOJu0YzQUlkFScoYIXw1ILTZvuPdP1bi+DYw7XNsf3cYon6wg4qXmVbD jHPXbHAEU0sXjOlZ8jBqEvHXf8WwgZ/p7aJgbYBqeqwE2q4ULBgo4cKzaaR2iOWcFjkyxPnbLs4 05WFeAA== 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-perf-users@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