From patchwork Wed Jan 3 05:06:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 184618 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4838145dyb; Tue, 2 Jan 2024 21:12:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvjTy1+Sb73ul6g7w0qgVC/M+wMg0JuuSJuF+kLAzXd6t+kew8Qlue885xa8X+iM6ySnKd X-Received: by 2002:a05:600c:4981:b0:40c:486d:6cb4 with SMTP id h1-20020a05600c498100b0040c486d6cb4mr9884813wmp.83.1704258754419; Tue, 02 Jan 2024 21:12:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704258754; cv=none; d=google.com; s=arc-20160816; b=vrTynRuyslKTJ9BcdxmRhkFu+qagrjy51Kn9piojGgYL7/t2PrP22qjnhIm7lfNZ7B oHke1ZCPMG2OWXZW03S+01qdX1gXGW6MjMsxKDddPGAKJdDC2momx1M58zvJDnABBel7 wkdyf5AGv1kDtkTTdW5YAMKtqyF96NddyZ+w2cy3duTTiYZrPLar7JlvvGtIbL+r6xhw ocshQD9kIn70Xihlk3NitpUQ5e1WJUtb7kJ0x/mLa/OodycfLlseCy2oPGROVgXaMOZA +Wmo75D7JSEGRtxVlIy2nlqeVr3BpwFXYa+nezTLEd5LGGHa30hTQ5eTTTlzXaNJpLIa BYAQ== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15176-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id c9-20020a1709060fc900b00a26b9a288bfsi9846848ejk.370.2024.01.02.21.12.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 21:12:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-15176-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-15176-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 am.mirrors.kernel.org (Postfix) with ESMTPS id BA0961F21496 for ; Wed, 3 Jan 2024 05:12:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C97481A596; Wed, 3 Jan 2024 05:07:31 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787044827604634644 X-GMAIL-MSGID: 1787044827604634644 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;