perf maps: Add maps__load_first()
authorIan Rogers <irogers@google.com>
Thu, 7 Dec 2023 01:16:53 +0000 (17:16 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 20 Dec 2023 17:56:10 +0000 (14:56 -0300)
Avoid bpf_lock_contention_read touching the internal maps data structure
by adding a helper function. As access is done directly on the map in
maps, hold the read lock to stop it being removed.

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-20-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/bpf_lock_contention.c
tools/perf/util/maps.c
tools/perf/util/maps.h

index f1716c089c9912f4f9bfca827bde4e509db8d22e..31ff19afc20c1b857a4397185926007dacb75e71 100644 (file)
@@ -318,7 +318,7 @@ int lock_contention_read(struct lock_contention *con)
        }
 
        /* make sure it loads the kernel map */
-       map__load(maps__first(machine->kmaps)->map);
+       maps__load_first(machine->kmaps);
 
        prev_key = NULL;
        while (!bpf_map_get_next_key(fd, prev_key, &key)) {
index 986daa1b049786095fbeadafa88c509c7ec2f1e9..024a6c9f72c402628c0765d9e9c9cca08bdf50f1 100644 (file)
@@ -793,3 +793,16 @@ out:
        }
        return err;
 }
+
+void maps__load_first(struct maps *maps)
+{
+       struct map_rb_node *first;
+
+       down_read(maps__lock(maps));
+
+       first = maps__first(maps);
+       if (first)
+               map__load(first->map);
+
+       up_read(maps__lock(maps));
+}
index e4a49d6ff5cfca5d0b567ea6ffedcf5950f9ad6a..b7ab3ec61b7c95efa1c1f50742a4dfd08e5e5df7 100644 (file)
@@ -142,4 +142,6 @@ void __maps__sort_by_name(struct maps *maps);
 
 void maps__fixup_end(struct maps *maps);
 
+void maps__load_first(struct maps *maps);
+
 #endif // __PERF_MAPS_H