Merge branch 'for-6.9/amd-sfh' into for-linus
[sfrench/cifs-2.6.git] / tools / perf / util / maps.c
index 024a6c9f72c402628c0765d9e9c9cca08bdf50f1..0334fc18d9c65897c5e76111d8cb3a6f8a4a53ba 100644 (file)
 #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))
 
        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);
@@ -485,17 +540,6 @@ out_unlock:
        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;
@@ -521,30 +565,6 @@ out:
        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;
@@ -663,6 +683,17 @@ out_unlock:
        return map;
 }
 
+struct map *maps__find_next_entry(struct maps *maps, struct map *map)
+{
+       struct map_rb_node *rb_node = maps__find_node(maps, map);
+       struct map_rb_node *next = map_rb_node__next(rb_node);
+
+       if (next)
+               return next->map;
+
+       return NULL;
+}
+
 void maps__fixup_end(struct maps *maps)
 {
        struct map_rb_node *prev = NULL, *curr;
@@ -670,7 +701,7 @@ void maps__fixup_end(struct maps *maps)
        down_write(maps__lock(maps));
 
        maps__for_each_entry(maps, curr) {
-               if (prev != NULL && !map__end(prev->map))
+               if (prev && (!map__end(prev->map) || map__end(prev->map) > map__start(curr->map)))
                        map__set_end(prev->map, map__start(curr->map));
 
                prev = curr;