From patchwork Fri Feb 2 06:15:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 195599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp239154dyc; Thu, 1 Feb 2024 22:20:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfrPWxwcNc/SCdiq49+hNLBGb/t/FjC8l0PjAaLr9e5IO7K1La7VbiuZPU01LYIRhEnDZu X-Received: by 2002:a05:6a20:93a7:b0:19c:881d:78e6 with SMTP id x39-20020a056a2093a700b0019c881d78e6mr1181893pzh.42.1706854850343; Thu, 01 Feb 2024 22:20:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706854850; cv=pass; d=google.com; s=arc-20160816; b=gsmBhTU4FHMGCSrs+SGMQXi9zOzzcrqw2wk60yNDJr3qQcBmb1GNuA2OqPUDGANxmj PYDIKV2SoekKi8sxHSODZdg2op9ArOuhQPvwh6fft8B9Cl2l/zmYkHBfhETmGOJN4b3a HoIvKsIX3Z3KvzJiQv6kXg+I4/VhORVfLQ7uCB1rhT2itwosRDpRbCCiADyJQjXQgqR5 9QlRmgABm61P90e3XhoyLO+G3q+kFrXvDSJTtKijN7hZorZQpUNTGk53/nm4GKUNiSPE 1i3+tvQFlPR8pKMqcDktcyh7DMmitN7Kd40FDj9xhun+PLy7wxJ7M/nQgmaGvE7hhJEU zc8w== 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=mottUhS25FsEFHcj0V/KGhVDM/ufFOH0iq7vn6sYGZo=; fh=sqJDmMf/xtVzTXwxC4nj8YzjdIJrVzjjLgBm6YTYKN4=; b=wPnZT2q8NoG0mWaYmeSdWsveNDV79sgg1d6kUxx+mceMRkNKH0omshg72FPAbGaarb n/6Lrf7+cYH8ZL1MySZBRH3a1sOgqL9lhI1Am74kqjyIxXKlaVK/RyS6HtdIsEqUObv/ V7f/CQ7B43ONpTqp+IUhEC/LL8lE/I4aaqt6BorSFlKuy/ULFQLmQZV+dmCk9bMbg5GB W6/fZ5czlguRt21WHAj/ylPmcEAqeApPkBA0zwenoc68vT8np1qT8+nnHu8oaMG+IBvM iNomCbchScGO4jxxiX3I2sKHxqDN2uwI5cT/S9IR4T8Z//a7eeXxlxGPU60XWLcIrbm4 xW/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nyNKy1MV; 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-49256-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49256-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCVNGzHrcK85BYrAKAc9dTgnXaTY48JK65/ePbc7GESfva99x7K5LCAjBMRZgIhbMPaA9CVojBcY1zlhZo/QP9UfnETuyg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id mh1-20020a17090b4ac100b002961cebf1cesi2462988pjb.166.2024.02.01.22.20.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 22:20:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49256-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nyNKy1MV; 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-49256-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49256-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9C5542810A3 for ; Fri, 2 Feb 2024 06:20:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6917447F55; Fri, 2 Feb 2024 06:16:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nyNKy1MV" 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 B79293FB37 for ; Fri, 2 Feb 2024 06:16:26 +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=1706854588; cv=none; b=NOJ7wt7ztIycpOYlfJWKN+ohf3sn45/sWNLKmiWHS9/FyfKx0gCpRhQObyyGbwfeYgCIeNJYrTehZAqqhbgJWaS4PD20nbegodd9SpUZzrfKSyMUTBCMwwQ0SkxHPieCYQJabSFEGQjoPkeKz01cxpdyjzZ10+A277tVtNL22i4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706854588; c=relaxed/simple; bh=6VWn0G9osA8gozSelQTcU7d5xrzfIxfJu3Uomo4VPvE=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=rkyprOUTpwkDnzgtxW33Rwby/BlLcKQVaGZlndSueZXAl07KqwrQh4EfWUHpDqVpi+65n2MSufqOhHs4nL3Jvm9S5cWI0c/2O2jgbK2up7rm1I14fFDFAorCmWGL2wTu8PHUGcD0gwG6yVLHG1MHgIvay7teeTOU3vrmAWWbKQ8= 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=nyNKy1MV; 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 Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5ee22efe5eeso30800897b3.3 for ; Thu, 01 Feb 2024 22:16:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706854586; x=1707459386; 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=mottUhS25FsEFHcj0V/KGhVDM/ufFOH0iq7vn6sYGZo=; b=nyNKy1MVCa74G88wL78AybqbkKBeVGrFmHs3qnuRFw77/A4myTrpMTdXIwSi5UUtDf OlhOiHOJCQKMzwp2Txv1xilT35y1lLG2Y2bFV2+TSYNhcMPK8Cm6EAqynMlsSWgVMWHr ZC6LEXngcE47N7QhPuf0P6/j23yg3oUw+IPyMWXfCmGvwfosj6AQxupQ2ptSslRSiIhz C97tta0qxjQfjEfnlwvF9eNjmNZt7DrypM0gtnM0ZkmB2rzhLf0Kh91rTl2PMa6BpySq lB7H2S4ujCAUq6JLMUiFZhuLMP5qtfHWvZFGISsozj8xj0aHM8IODnGZKvLTy/8hPb+6 SiRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706854586; x=1707459386; 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=mottUhS25FsEFHcj0V/KGhVDM/ufFOH0iq7vn6sYGZo=; b=iTVjeoiRA4uqrj/htienNJF9NpCXU941BHFy+mLq5rWk0ervxc3p5acVBkOpi1wXPv i/e6ZJ/25CmvM9Tci8aMT+U77t2ff6CMZRUesVeoiu+ElvROZDnkmrs2IEPDYCaaCvUF XBukupCdNWImt79ZVDdukrTCNeuUHGpxam6dPXlZLdybnBZYTlHJCeszk8B9vUhEnc6t DNCJMgUJcX1V8TLpIepIJt1c2FOR5KyVzVqy5efnn+BeOCiCKwB7IPrL+2Ow7hurh412 VAYNTDRn2Xc1tt197+C3uT5RzXIoF7MIVeRAdwCN5fAMEZbSTPvES6WUNZnVB0RRVSvb ng/Q== X-Gm-Message-State: AOJu0Yzhi5MzDhGXO3ta506tHL1VcCgweyBLqEKpUOXA+/rG59pLBo2O C/EJXDaONhNt94IzVsBPOMy+whSHlhW+d3rnyTD5yGhl1gCbppJR9SpBdIQqnLkuTogLGb7vPCL KcJT5jg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a85f:db1d:a66b:7f53]) (user=irogers job=sendgmr) by 2002:a05:690c:19:b0:600:2492:f962 with SMTP id bc25-20020a05690c001900b006002492f962mr751446ywb.8.1706854585762; Thu, 01 Feb 2024 22:16:25 -0800 (PST) Date: Thu, 1 Feb 2024 22:15:24 -0800 In-Reply-To: <20240202061532.1939474-1-irogers@google.com> Message-Id: <20240202061532.1939474-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: <20240202061532.1939474-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v8 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 , "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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789767031278241810 X-GMAIL-MSGID: 1789767031278241810 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;