Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3428317rdh; Mon, 27 Nov 2023 14:11:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuyEsufB/EKhiwctMcK73NkZ2pBzt3iQaLUIVN5lbL6xOLZulpt2pz3BPKn2dTpZe4zZKh X-Received: by 2002:a05:6a21:338e:b0:18c:8fef:22d3 with SMTP id yy14-20020a056a21338e00b0018c8fef22d3mr5921102pzb.34.1701123118714; Mon, 27 Nov 2023 14:11:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701123118; cv=none; d=google.com; s=arc-20160816; b=pUp1OyVDpAlX6oV4c14LRzbRmM7QuYDWzYXbbjklyQtrbHnOApomDgIPUBMhREg0NQ opQESLmb39k09D2fDjpG0BUxlPQYxWAHrvu53Zv+BJr8/EIh9kUHcXaChELRrCrN9BrX zhXPZwgXj6eJToFyCY2RUCzkpVGIbfQtTKB+EL6mrIwPSD4Q74zBFVOHtDUTLSCKq9v4 +fje4usPZH1P+QepIUqU/jNV0uU6w8kzdqx05APrxN14/+9OmTBfaXDclQWZPLf7b0jt OGdXX5SwKb4M7UIrCyLH8r45cOMftHCcY8O87kAVB56HF0RFNFsbkebLvVtxA0wnEeEW QQGg== 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=jKzr4H8qcCWkzlhhc5mjc/fFOHye0m+UsUUrI2SedSA=; fh=Io7x3OacpefNRRNKoYAzVE0aWTDwD7FRzyCdD1e3AN4=; b=ma/f35j/dWZONPhElIJbZjs7Sczeyi3nSv3YKjt3eGU2Pyh1PWupA8GyspTiDP9DUP ieXxt8GMED6nTtTDGI2JlTMXm31hBexBOy3kbA0+/yhI3U7zWhrRqJEgegYF/XTeOCIi oRJGl4bmrF2Fac79kNWMP/blpCjKGv1AVcEwVIWftjA6k0p4JmzStc8xyLrpubDnzH4v AHTOE0cJ3sUqjiB3SKZpZAeGM1zJw/BPgtfzCOcqFLpQmfGEq4YeOW2hKWpv0n84bfBa RKLSh3ye4eRdc45UOcDcB2aoIQcBwV6Ok1BaZNccPq8AfisI+PJOf48ahwr8JDVA+nVm zI5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HtMZ9Zvg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id y194-20020a62cecb000000b006cd8878e98csi3848593pfg.51.2023.11.27.14.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 14:11:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HtMZ9Zvg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 310D880689EE; Mon, 27 Nov 2023 14:11:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233832AbjK0WLj (ORCPT + 99 others); Mon, 27 Nov 2023 17:11:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233816AbjK0WKu (ORCPT ); Mon, 27 Nov 2023 17:10:50 -0500 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 B5E2A2698 for ; Mon, 27 Nov 2023 14:10:17 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5cdc42ce40fso47466297b3.2 for ; Mon, 27 Nov 2023 14:10:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701123017; x=1701727817; 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=jKzr4H8qcCWkzlhhc5mjc/fFOHye0m+UsUUrI2SedSA=; b=HtMZ9Zvgj5ZtK5nQb4syb6X+0JZdUGOwgIzsY+sCZ1WxNSPpPwsApBt9NqmLb1e/aO CEiqc8oDdKctNCYZ77cT9ofL4vl7cMntVok3wrFX0Ak1UJbZFqGqJLP2FF+7mDXw8yqX CYP+yThPsFQeE6L5/BRZyDgrKoM2bC+6hKrQYsmSvo05WcRw5ko70cVV/FFIsjOU6svv k07yV1EVhcs2Ma7Nxlgo4KtjjIfUKl4TFsUoByCRX6WUwrrG9gZr1zoxiQ4jACOsqUYb GgyRvCsOwf8Z69zbjp4ryYCnZREHaqeojUszYwH1Czbl/cGbnxvI1iqOmQy/ZfS1zb/5 5vbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701123017; x=1701727817; 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=jKzr4H8qcCWkzlhhc5mjc/fFOHye0m+UsUUrI2SedSA=; b=tkdWvdEZHCbUv3/+4Z4zc0b5VSgJeglJ5MXgHu1rCBNXaEbXG6u4HdJxIzxSmzhPcq HLEQIIU0S49HSmyRvxfJfSalFSkC47S7pSW9KC3T+lBKTHCYLBHOm2whh+J1rtK9yiyC 2GfsAYqVsPcvem7Sz4pIwBVEqfWud3ioYhKApVV7cGRC2VhSyI4fsKvyJnkhUlOF63ZY Vqh7ezcOuvYdX+Hv1IPtaPa5tE1IcddvWWwzXizByfVUEE/eCl8+Ovlw+sRwbJ1mwvhv AwFXSCQX0S5pPQSXCGfJIPwlOCTqBW4hPqTqHtTdnbpXM/fb+dG5lwvzQ7wKSl/AXGM6 k4Ig== X-Gm-Message-State: AOJu0YwpfRwkZshXc3nWcqsbQsshyGMlek/zDWJUgDtsMAhu7+QZikw8 eR4rRG9lHLeBB8o6vX/l2wQYcEBzNqqF X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:829:6e77:9093:f39b]) (user=irogers job=sendgmr) by 2002:a05:690c:480d:b0:5ce:a88:8436 with SMTP id hc13-20020a05690c480d00b005ce0a888436mr379574ywb.10.1701123016797; Mon, 27 Nov 2023 14:10:16 -0800 (PST) Date: Mon, 27 Nov 2023 14:08:35 -0800 In-Reply-To: <20231127220902.1315692-1-irogers@google.com> Message-Id: <20231127220902.1315692-24-irogers@google.com> Mime-Version: 1.0 References: <20231127220902.1315692-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v5 23/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 , 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 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,T_SCC_BODY_TEXT_LINE, 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]); Mon, 27 Nov 2023 14:11:55 -0800 (PST) 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.43.0.rc1.413.gea7ed67945-goog