···20172017 &options[nr_options], dso);20182018 nr_options += add_map_opt(browser, &actions[nr_options],20192019 &options[nr_options],20202020- browser->selection->map);20202020+ browser->selection ?20212021+ browser->selection->map : NULL);20212022 nr_options += add_socket_opt(browser, &actions[nr_options],20222023 &options[nr_options],20232024 socked_id);···20282027 &actions[nr_options],20292028 &options[nr_options],20302029 thread, NULL);20302030+ /*20312031+ * Note that browser->selection != NULL20322032+ * when browser->he_selection is not NULL,20332033+ * so we don't need to check browser->selection20342034+ * before fetching browser->selection->sym like what20352035+ * we do before fetching browser->selection->map.20362036+ *20372037+ * See hist_browser__show_entry.20382038+ */20312039 nr_options += add_script_opt(browser,20322040 &actions[nr_options],20332041 &options[nr_options],
+76-62
tools/perf/util/evlist.c
···125125 free(evlist);126126}127127128128+static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,129129+ struct perf_evsel *evsel)130130+{131131+ /*132132+ * We already have cpus for evsel (via PMU sysfs) so133133+ * keep it, if there's no target cpu list defined.134134+ */135135+ if (!evsel->own_cpus || evlist->has_user_cpus) {136136+ cpu_map__put(evsel->cpus);137137+ evsel->cpus = cpu_map__get(evlist->cpus);138138+ } else if (evsel->cpus != evsel->own_cpus) {139139+ cpu_map__put(evsel->cpus);140140+ evsel->cpus = cpu_map__get(evsel->own_cpus);141141+ }142142+143143+ thread_map__put(evsel->threads);144144+ evsel->threads = thread_map__get(evlist->threads);145145+}146146+147147+static void perf_evlist__propagate_maps(struct perf_evlist *evlist)148148+{149149+ struct perf_evsel *evsel;150150+151151+ evlist__for_each(evlist, evsel)152152+ __perf_evlist__propagate_maps(evlist, evsel);153153+}154154+128155void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)129156{130157 entry->evlist = evlist;···161134162135 if (!evlist->nr_entries++)163136 perf_evlist__set_id_pos(evlist);137137+138138+ __perf_evlist__propagate_maps(evlist, entry);164139}165140166141void perf_evlist__splice_list_tail(struct perf_evlist *evlist,167167- struct list_head *list,168168- int nr_entries)142142+ struct list_head *list)169143{170170- bool set_id_pos = !evlist->nr_entries;144144+ struct perf_evsel *evsel, *temp;171145172172- list_splice_tail(list, &evlist->entries);173173- evlist->nr_entries += nr_entries;174174- if (set_id_pos)175175- perf_evlist__set_id_pos(evlist);146146+ __evlist__for_each_safe(list, temp, evsel) {147147+ list_del_init(&evsel->node);148148+ perf_evlist__add(evlist, evsel);149149+ }176150}177151178152void __perf_evlist__set_leader(struct list_head *list)···239211 list_add_tail(&evsel->node, &head);240212 }241213242242- perf_evlist__splice_list_tail(evlist, &head, nr_attrs);214214+ perf_evlist__splice_list_tail(evlist, &head);243215244216 return 0;245217···11321104 return perf_evlist__mmap_ex(evlist, pages, overwrite, 0, false);11331105}1134110611351135-static int perf_evlist__propagate_maps(struct perf_evlist *evlist,11361136- bool has_user_cpus)11371137-{11381138- struct perf_evsel *evsel;11391139-11401140- evlist__for_each(evlist, evsel) {11411141- /*11421142- * We already have cpus for evsel (via PMU sysfs) so11431143- * keep it, if there's no target cpu list defined.11441144- */11451145- if (evsel->cpus && has_user_cpus)11461146- cpu_map__put(evsel->cpus);11471147-11481148- if (!evsel->cpus || has_user_cpus)11491149- evsel->cpus = cpu_map__get(evlist->cpus);11501150-11511151- evsel->threads = thread_map__get(evlist->threads);11521152-11531153- if ((evlist->cpus && !evsel->cpus) ||11541154- (evlist->threads && !evsel->threads))11551155- return -ENOMEM;11561156- }11571157-11581158- return 0;11591159-}11601160-11611107int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)11621108{11631163- evlist->threads = thread_map__new_str(target->pid, target->tid,11641164- target->uid);11091109+ struct cpu_map *cpus;11101110+ struct thread_map *threads;1165111111661166- if (evlist->threads == NULL)11121112+ threads = thread_map__new_str(target->pid, target->tid, target->uid);11131113+11141114+ if (!threads)11671115 return -1;1168111611691117 if (target__uses_dummy_map(target))11701170- evlist->cpus = cpu_map__dummy_new();11181118+ cpus = cpu_map__dummy_new();11711119 else11721172- evlist->cpus = cpu_map__new(target->cpu_list);11201120+ cpus = cpu_map__new(target->cpu_list);1173112111741174- if (evlist->cpus == NULL)11221122+ if (!cpus)11751123 goto out_delete_threads;1176112411771177- return perf_evlist__propagate_maps(evlist, !!target->cpu_list);11251125+ evlist->has_user_cpus = !!target->cpu_list;11261126+11271127+ perf_evlist__set_maps(evlist, cpus, threads);11281128+11291129+ return 0;1178113011791131out_delete_threads:11801180- thread_map__put(evlist->threads);11811181- evlist->threads = NULL;11321132+ thread_map__put(threads);11821133 return -1;11831134}1184113511851185-int perf_evlist__set_maps(struct perf_evlist *evlist,11861186- struct cpu_map *cpus,11871187- struct thread_map *threads)11361136+void perf_evlist__set_maps(struct perf_evlist *evlist, struct cpu_map *cpus,11371137+ struct thread_map *threads)11881138{11891189- if (evlist->cpus)11391139+ /*11401140+ * Allow for the possibility that one or another of the maps isn't being11411141+ * changed i.e. don't put it. Note we are assuming the maps that are11421142+ * being applied are brand new and evlist is taking ownership of the11431143+ * original reference count of 1. If that is not the case it is up to11441144+ * the caller to increase the reference count.11451145+ */11461146+ if (cpus != evlist->cpus) {11901147 cpu_map__put(evlist->cpus);11481148+ evlist->cpus = cpus;11491149+ }1191115011921192- evlist->cpus = cpus;11931193-11941194- if (evlist->threads)11511151+ if (threads != evlist->threads) {11951152 thread_map__put(evlist->threads);11531153+ evlist->threads = threads;11541154+ }1196115511971197- evlist->threads = threads;11981198-11991199- return perf_evlist__propagate_maps(evlist, false);11561156+ perf_evlist__propagate_maps(evlist);12001157}1201115812021159int perf_evlist__apply_filters(struct perf_evlist *evlist, struct perf_evsel **err_evsel)···1401138814021389static int perf_evlist__create_syswide_maps(struct perf_evlist *evlist)14031390{13911391+ struct cpu_map *cpus;13921392+ struct thread_map *threads;14041393 int err = -ENOMEM;1405139414061395 /*···14141399 * error, and we may not want to do that fallback to a14151400 * default cpu identity map :-\14161401 */14171417- evlist->cpus = cpu_map__new(NULL);14181418- if (evlist->cpus == NULL)14021402+ cpus = cpu_map__new(NULL);14031403+ if (!cpus)14191404 goto out;1420140514211421- evlist->threads = thread_map__new_dummy();14221422- if (evlist->threads == NULL)14231423- goto out_free_cpus;14061406+ threads = thread_map__new_dummy();14071407+ if (!threads)14081408+ goto out_put;1424140914251425- err = 0;14101410+ perf_evlist__set_maps(evlist, cpus, threads);14261411out:14271412 return err;14281428-out_free_cpus:14291429- cpu_map__put(evlist->cpus);14301430- evlist->cpus = NULL;14131413+out_put:14141414+ cpu_map__put(cpus);14311415 goto out;14321416}14331417