Skip to content

Commit 631bb23

Browse files
captain5050acmel
authored andcommitted
perf maps: Reduce scope of map_rb_node and maps internals
Avoid exposing the implementation of maps so that the internals can be refactored. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Changbin Du <changbin.du@huawei.com> Cc: Colin Ian King <colin.i.king@gmail.com> Cc: Dmitrii Dolgov <9erthalion6@gmail.com> Cc: German Gomez <german.gomez@arm.com> Cc: Guilherme Amadio <amadio@gentoo.org> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: K Prateek Nayak <kprateek.nayak@amd.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Li Dong <lidong@vivo.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Miguel Ojeda <ojeda@kernel.org> Cc: Ming Wang <wangming01@loongson.cn> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Nick Terrell <terrelln@fb.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Sean Christopherson <seanjc@google.com> Cc: Steinar H. Gunderson <sesse@google.com> Cc: Vincent Whitchurch <vincent.whitchurch@axis.com> Cc: Wenyu Liu <liuwenyu7@huawei.com> Cc: Yang Jihong <yangjihong1@huawei.com> Link: https://lore.kernel.org/r/20231207011722.1220634-22-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 7585800 commit 631bb23

2 files changed

Lines changed: 55 additions & 58 deletions

File tree

tools/perf/util/maps.c

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,68 @@
1010
#include "ui/ui.h"
1111
#include "unwind.h"
1212

13+
struct map_rb_node {
14+
struct rb_node rb_node;
15+
struct map *map;
16+
};
17+
1318
#define maps__for_each_entry(maps, map) \
1419
for (map = maps__first(maps); map; map = map_rb_node__next(map))
1520

1621
#define maps__for_each_entry_safe(maps, map, next) \
1722
for (map = maps__first(maps), next = map_rb_node__next(map); map; \
1823
map = next, next = map_rb_node__next(map))
1924

25+
static struct rb_root *maps__entries(struct maps *maps)
26+
{
27+
return &RC_CHK_ACCESS(maps)->entries;
28+
}
29+
30+
static struct rw_semaphore *maps__lock(struct maps *maps)
31+
{
32+
return &RC_CHK_ACCESS(maps)->lock;
33+
}
34+
35+
static struct map **maps__maps_by_name(struct maps *maps)
36+
{
37+
return RC_CHK_ACCESS(maps)->maps_by_name;
38+
}
39+
40+
static struct map_rb_node *maps__first(struct maps *maps)
41+
{
42+
struct rb_node *first = rb_first(maps__entries(maps));
43+
44+
if (first)
45+
return rb_entry(first, struct map_rb_node, rb_node);
46+
return NULL;
47+
}
48+
49+
static struct map_rb_node *map_rb_node__next(struct map_rb_node *node)
50+
{
51+
struct rb_node *next;
52+
53+
if (!node)
54+
return NULL;
55+
56+
next = rb_next(&node->rb_node);
57+
58+
if (!next)
59+
return NULL;
60+
61+
return rb_entry(next, struct map_rb_node, rb_node);
62+
}
63+
64+
static struct map_rb_node *maps__find_node(struct maps *maps, struct map *map)
65+
{
66+
struct map_rb_node *rb_node;
67+
68+
maps__for_each_entry(maps, rb_node) {
69+
if (rb_node->RC_CHK_ACCESS(map) == RC_CHK_ACCESS(map))
70+
return rb_node;
71+
}
72+
return NULL;
73+
}
74+
2075
static void maps__init(struct maps *maps, struct machine *machine)
2176
{
2277
refcount_set(maps__refcnt(maps), 1);
@@ -485,17 +540,6 @@ int maps__copy_from(struct maps *maps, struct maps *parent)
485540
return err;
486541
}
487542

488-
struct map_rb_node *maps__find_node(struct maps *maps, struct map *map)
489-
{
490-
struct map_rb_node *rb_node;
491-
492-
maps__for_each_entry(maps, rb_node) {
493-
if (rb_node->RC_CHK_ACCESS(map) == RC_CHK_ACCESS(map))
494-
return rb_node;
495-
}
496-
return NULL;
497-
}
498-
499543
struct map *maps__find(struct maps *maps, u64 ip)
500544
{
501545
struct rb_node *p;
@@ -521,30 +565,6 @@ struct map *maps__find(struct maps *maps, u64 ip)
521565
return m ? m->map : NULL;
522566
}
523567

524-
struct map_rb_node *maps__first(struct maps *maps)
525-
{
526-
struct rb_node *first = rb_first(maps__entries(maps));
527-
528-
if (first)
529-
return rb_entry(first, struct map_rb_node, rb_node);
530-
return NULL;
531-
}
532-
533-
struct map_rb_node *map_rb_node__next(struct map_rb_node *node)
534-
{
535-
struct rb_node *next;
536-
537-
if (!node)
538-
return NULL;
539-
540-
next = rb_next(&node->rb_node);
541-
542-
if (!next)
543-
return NULL;
544-
545-
return rb_entry(next, struct map_rb_node, rb_node);
546-
}
547-
548568
static int map__strcmp(const void *a, const void *b)
549569
{
550570
const struct map *map_a = *(const struct map **)a;

tools/perf/util/maps.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ struct machine;
1515
struct map;
1616
struct maps;
1717

18-
struct map_rb_node {
19-
struct rb_node rb_node;
20-
struct map *map;
21-
};
22-
2318
struct map_list_node {
2419
struct list_head node;
2520
struct map *map;
@@ -30,9 +25,6 @@ static inline struct map_list_node *map_list_node__new(void)
3025
return malloc(sizeof(struct map_list_node));
3126
}
3227

33-
struct map_rb_node *maps__first(struct maps *maps);
34-
struct map_rb_node *map_rb_node__next(struct map_rb_node *node);
35-
struct map_rb_node *maps__find_node(struct maps *maps, struct map *map);
3628
struct map *maps__find(struct maps *maps, u64 addr);
3729

3830
DECLARE_RC_STRUCT(maps) {
@@ -78,26 +70,11 @@ int maps__for_each_map(struct maps *maps, int (*cb)(struct map *map, void *data)
7870
/* Iterate over map removing an entry if cb returns true. */
7971
void maps__remove_maps(struct maps *maps, bool (*cb)(struct map *map, void *data), void *data);
8072

81-
static inline struct rb_root *maps__entries(struct maps *maps)
82-
{
83-
return &RC_CHK_ACCESS(maps)->entries;
84-
}
85-
8673
static inline struct machine *maps__machine(struct maps *maps)
8774
{
8875
return RC_CHK_ACCESS(maps)->machine;
8976
}
9077

91-
static inline struct rw_semaphore *maps__lock(struct maps *maps)
92-
{
93-
return &RC_CHK_ACCESS(maps)->lock;
94-
}
95-
96-
static inline struct map **maps__maps_by_name(struct maps *maps)
97-
{
98-
return RC_CHK_ACCESS(maps)->maps_by_name;
99-
}
100-
10178
static inline unsigned int maps__nr_maps(const struct maps *maps)
10279
{
10380
return RC_CHK_ACCESS(maps)->nr_maps;

0 commit comments

Comments
 (0)