perf vdso: Use function to add missing maps lock
authorIan Rogers <irogers@google.com>
Thu, 7 Dec 2023 01:16:46 +0000 (17:16 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 20 Dec 2023 17:49:11 +0000 (14:49 -0300)
Switch machine__thread_dso_type() from loop macro maps__for_each_entry()
to maps__for_each_map() function that takes a callback. The function
holds the maps lock, which should be held during iteration.

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

index ae3eee69b659c849ee4eb6ff88330d24d29852e5..df8963796187dc69515114aff048a7a757299a7d 100644 (file)
@@ -140,23 +140,34 @@ static struct dso *__machine__addnew_vdso(struct machine *machine, const char *s
        return dso;
 }
 
+struct machine__thread_dso_type_maps_cb_args {
+       struct machine *machine;
+       enum dso_type dso_type;
+};
+
+static int machine__thread_dso_type_maps_cb(struct map *map, void *data)
+{
+       struct machine__thread_dso_type_maps_cb_args *args = data;
+       struct dso *dso = map__dso(map);
+
+       if (!dso || dso->long_name[0] != '/')
+               return 0;
+
+       args->dso_type = dso__type(dso, args->machine);
+       return (args->dso_type != DSO__TYPE_UNKNOWN) ? 1 : 0;
+}
+
 static enum dso_type machine__thread_dso_type(struct machine *machine,
                                              struct thread *thread)
 {
-       enum dso_type dso_type = DSO__TYPE_UNKNOWN;
-       struct map_rb_node *rb_node;
-
-       maps__for_each_entry(thread__maps(thread), rb_node) {
-               struct dso *dso = map__dso(rb_node->map);
+       struct machine__thread_dso_type_maps_cb_args args = {
+               .machine = machine,
+               .dso_type = DSO__TYPE_UNKNOWN,
+       };
 
-               if (!dso || dso->long_name[0] != '/')
-                       continue;
-               dso_type = dso__type(dso, machine);
-               if (dso_type != DSO__TYPE_UNKNOWN)
-                       break;
-       }
+       maps__for_each_map(thread__maps(thread), machine__thread_dso_type_maps_cb, &args);
 
-       return dso_type;
+       return args.dso_type;
 }
 
 #if BITS_PER_LONG == 64