Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2185850rda; Tue, 24 Oct 2023 15:27:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlbq8ojoq02jgYiOEO2vUmdbGbZ3+n33Pta6g1KLVesGvUGNqfyXqlK5v8eiWs5Cz5Pa1u X-Received: by 2002:a05:6a21:3e05:b0:16b:c62d:876 with SMTP id bk5-20020a056a213e0500b0016bc62d0876mr3785615pzc.23.1698186419994; Tue, 24 Oct 2023 15:26:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698186419; cv=none; d=google.com; s=arc-20160816; b=oDa1GI9iY4G1ElxAodkX0XyHUULV92d2fQZ78o2fC3lbJOfZWE5NHq6ZMrXSeCrBoa SbGUOOzQHajBVwTyYtBlDdlNq6BtOCxjp5Tgd5RptrQTHdLllk17pDCFczKz6GVwS/tx NY8/3NJAANeiu0Fc/NZrC9jflTNH6zzJfsIkc3KdesaDqkcEWlF/c9xH/yvKLAPMnk2t racR2jpN+rwRTu+HoZKjpWE5m2wo9PdD0017bqPuLx4xpEoxKhauC7iGqhp4SIM4+QGJ +aNssiuMaQN7+j/nFqHZVi8sjcHD+w606CA2ddTakY2XIagByg7lLmO6SzCdDwosCX4Z 6n+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=nzIlX+P2Xnb51CqannJImstzqGSg/CO4GFxV9EhldOc=; fh=NAro5oTsDEB2Or99ABwb774QJkwQSkr6EoLVqn/Yde0=; b=aBzFi+4V2s2rZOxldwkKTp9zCjf7zhcNwDKhb6PaVBsbwpQ5xm7i5fJYmyNgKFA3lv A01ES9100ROQZpHq8ysf3QB6nT1rHqixKlRusC2j3Q8SmV9OL4cF2bLCQKrMFK5wMCPO SL/75FqqREGw60KlTdIw2SDj9RkgGGE3bavPpM1X9ZZDa8l5tmN5S1SuwlYhMQ3exxDK 6O4tFY3Z4lM7OxzG4GEIGHl8OxHOzEdE5fsTeo+oyY1OWDFiOXNEBinodaQAuOWiL17V tRMumrel+bOoRnFYY1m+weDFA+3w5JXedzk5Smt3OrVvn/c39CSnhxXoxjqd/USomd9e j6UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XtlLXByk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id w21-20020a637b15000000b005b8dde7e12dsi2837216pgc.98.2023.10.24.15.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 15:26:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XtlLXByk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4DD7680A9B24; Tue, 24 Oct 2023 15:26:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344564AbjJXW0t (ORCPT + 99 others); Tue, 24 Oct 2023 18:26:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344585AbjJXW0L (ORCPT ); Tue, 24 Oct 2023 18:26:11 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F7002D76 for ; Tue, 24 Oct 2023 15:25:35 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7cf717bacso67706637b3.1 for ; Tue, 24 Oct 2023 15:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698186334; x=1698791134; 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=nzIlX+P2Xnb51CqannJImstzqGSg/CO4GFxV9EhldOc=; b=XtlLXBykJVKWfk5yCU+rQn2Ll3gCSIsu1hHyuLDQqWdexiEcx0cDqPhM0Z1y+cxDP8 FCTxk5T2UFFxH52Wv8sLC5OtK45tol1MiXEuh4hecOSn95JZ1b/wpyGgr2hSBg+6t6/a e1Rt7+mLp+K7PMssJ8Aczt3mAMc6qWvofhfNCpjdXmb6WxHdsd6nhaTDZ+vgmB6dSMyn v3sLqdx7GtzSUtYarXbyZnXzkOBcdM8la3spVgZqMSNMd8U5mPz9F6iM40I33lw6c/AR X9nYb0oNOr+D5GIxoYY4NXtY/y96qK75aXcLWf/rArqs7r8cNUAYbzmJIl8c82kNCYyv LlDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698186334; x=1698791134; 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=nzIlX+P2Xnb51CqannJImstzqGSg/CO4GFxV9EhldOc=; b=ZK07sLGO7o95JJxVoIIeZhIjV9/x6TIah4EofUTnBKfzfcF2Shg7QsqZlYj5Zjo0gO zaAdkL49vPKfY6mu1r+1aiLyaIXk/DfjZQmvqilpAlJfLyETXGPLXreA2dAmHaW7j2sB VnSmRGOuIZP8Sl0jojxPmjJAsWT3BKITpcspHW5AoDK9wG+3u6OnZI0NeV6bP91IUY00 1PyUdcXP4a+S0KvVcR2i/5b7RuWYAGu/GyFUmhlAhTFpeB68f9i6XOi/vUNtA6/+mkM8 VdADaZ8YbXNjjcKjC8Tgs0xyGYmYFG7i1a1WRZO+pdBQCozj91wYzYcCbu7gCfckKYKI xM5g== X-Gm-Message-State: AOJu0YztGFwYLbW8Mo9J582A+pC68rsHnzxra1N+LxwGE/HxLxxV7Pds mIJ5dG5qh40S9GPakfhkrnVBvjeonOFL X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:93d2:18cc:4d63:45ba]) (user=irogers job=sendgmr) by 2002:a0d:ca8b:0:b0:589:a855:7af with SMTP id m133-20020a0dca8b000000b00589a85507afmr268615ywd.7.1698186333865; Tue, 24 Oct 2023 15:25:33 -0700 (PDT) Date: Tue, 24 Oct 2023 15:23:39 -0700 In-Reply-To: <20231024222353.3024098-1-irogers@google.com> Message-Id: <20231024222353.3024098-37-irogers@google.com> Mime-Version: 1.0 References: <20231024222353.3024098-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Subject: [PATCH v3 36/50] perf maps: Reduce scope of map_rb_node and maps internals 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 , Leo Yan , Song Liu , Sandipan Das , James Clark , Anshuman Khandual , Miguel Ojeda , Liam Howlett , Yang Jihong , Athira Rajeev , Kajol Jain , K Prateek Nayak , Sean Christopherson , Yanteng Si , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Masami Hiramatsu , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 24 Oct 2023 15:26:57 -0700 (PDT) Avoid exposing the implementation of maps so that the internals can be refactored. Signed-off-by: Ian Rogers --- tools/perf/util/maps.c | 90 ++++++++++++++++++++++++++---------------- tools/perf/util/maps.h | 23 ----------- 2 files changed, 55 insertions(+), 58 deletions(-) diff --git a/tools/perf/util/maps.c b/tools/perf/util/maps.c index 38d56709bd5e..01c15d0b300a 100644 --- a/tools/perf/util/maps.c +++ b/tools/perf/util/maps.c @@ -10,6 +10,11 @@ #include "ui/ui.h" #include "unwind.h" +struct map_rb_node { + struct rb_node rb_node; + struct map *map; +}; + #define maps__for_each_entry(maps, map) \ for (map = maps__first(maps); map; map = map_rb_node__next(map)) @@ -17,6 +22,56 @@ for (map = maps__first(maps), next = map_rb_node__next(map); map; \ map = next, next = map_rb_node__next(map)) +static struct rb_root *maps__entries(struct maps *maps) +{ + return &RC_CHK_ACCESS(maps)->entries; +} + +static struct rw_semaphore *maps__lock(struct maps *maps) +{ + return &RC_CHK_ACCESS(maps)->lock; +} + +static struct map **maps__maps_by_name(struct maps *maps) +{ + return RC_CHK_ACCESS(maps)->maps_by_name; +} + +static struct map_rb_node *maps__first(struct maps *maps) +{ + struct rb_node *first = rb_first(maps__entries(maps)); + + if (first) + return rb_entry(first, struct map_rb_node, rb_node); + return NULL; +} + +static struct map_rb_node *map_rb_node__next(struct map_rb_node *node) +{ + struct rb_node *next; + + if (!node) + return NULL; + + next = rb_next(&node->rb_node); + + if (!next) + return NULL; + + return rb_entry(next, struct map_rb_node, rb_node); +} + +static struct map_rb_node *maps__find_node(struct maps *maps, struct map *map) +{ + struct map_rb_node *rb_node; + + maps__for_each_entry(maps, rb_node) { + if (rb_node->RC_CHK_ACCESS(map) == RC_CHK_ACCESS(map)) + return rb_node; + } + return NULL; +} + static void maps__init(struct maps *maps, struct machine *machine) { refcount_set(maps__refcnt(maps), 1); @@ -484,17 +539,6 @@ int maps__copy_from(struct maps *maps, struct maps *parent) return err; } -struct map_rb_node *maps__find_node(struct maps *maps, struct map *map) -{ - struct map_rb_node *rb_node; - - maps__for_each_entry(maps, rb_node) { - if (rb_node->RC_CHK_ACCESS(map) == RC_CHK_ACCESS(map)) - return rb_node; - } - return NULL; -} - struct map *maps__find(struct maps *maps, u64 ip) { struct rb_node *p; @@ -520,30 +564,6 @@ struct map *maps__find(struct maps *maps, u64 ip) return m ? m->map : NULL; } -struct map_rb_node *maps__first(struct maps *maps) -{ - struct rb_node *first = rb_first(maps__entries(maps)); - - if (first) - return rb_entry(first, struct map_rb_node, rb_node); - return NULL; -} - -struct map_rb_node *map_rb_node__next(struct map_rb_node *node) -{ - struct rb_node *next; - - if (!node) - return NULL; - - next = rb_next(&node->rb_node); - - if (!next) - return NULL; - - return rb_entry(next, struct map_rb_node, rb_node); -} - static int map__strcmp(const void *a, const void *b) { const struct map *map_a = *(const struct map **)a; diff --git a/tools/perf/util/maps.h b/tools/perf/util/maps.h index 84b42c8456e8..d836d04c9402 100644 --- a/tools/perf/util/maps.h +++ b/tools/perf/util/maps.h @@ -15,11 +15,6 @@ struct machine; struct map; struct maps; -struct map_rb_node { - struct rb_node rb_node; - struct map *map; -}; - struct map_list_node { struct list_head node; struct map *map; @@ -30,9 +25,6 @@ static inline struct map_list_node *map_list_node__new(void) return malloc(sizeof(struct map_list_node)); } -struct map_rb_node *maps__first(struct maps *maps); -struct map_rb_node *map_rb_node__next(struct map_rb_node *node); -struct map_rb_node *maps__find_node(struct maps *maps, struct map *map); struct map *maps__find(struct maps *maps, u64 addr); DECLARE_RC_STRUCT(maps) { @@ -78,26 +70,11 @@ int maps__for_each_map(struct maps *maps, int (*cb)(struct map *map, void *data) /* Iterate over map removing an entry if cb returns true. */ void maps__remove_maps(struct maps *maps, bool (*cb)(struct map *map, void *data), void *data); -static inline struct rb_root *maps__entries(struct maps *maps) -{ - return &RC_CHK_ACCESS(maps)->entries; -} - static inline struct machine *maps__machine(struct maps *maps) { return RC_CHK_ACCESS(maps)->machine; } -static inline struct rw_semaphore *maps__lock(struct maps *maps) -{ - return &RC_CHK_ACCESS(maps)->lock; -} - -static inline struct map **maps__maps_by_name(struct maps *maps) -{ - return RC_CHK_ACCESS(maps)->maps_by_name; -} - static inline unsigned int maps__nr_maps(const struct maps *maps) { return RC_CHK_ACCESS(maps)->nr_maps; -- 2.42.0.758.gaed0368e0e-goog