staticvoid __perf_evlist__propagate_maps(struct perf_evlist *evlist, struct perf_evsel *evsel)
{ if (perf_cpu_map__is_empty(evsel->cpus)) { if (perf_cpu_map__is_empty(evsel->pmu_cpus)) { /* * Assume the unset PMU cpus were for a system-wide * event, like a software or tracepoint.
*/
evsel->pmu_cpus = perf_cpu_map__new_online_cpus();
} if (evlist->has_user_cpus && !evsel->system_wide) { /* * Use the user CPUs unless the evsel is set to be * system wide, such as the dummy event.
*/
evsel->cpus = perf_cpu_map__get(evlist->user_requested_cpus);
} else { /* * System wide and other modes, assume the cpu map * should be set to all PMU CPUs.
*/
evsel->cpus = perf_cpu_map__get(evsel->pmu_cpus);
}
} /* * Avoid "any CPU"(-1) for uncore and PMUs that require a CPU, even if * requested.
*/ if (evsel->requires_cpu && perf_cpu_map__has_any_cpu(evsel->cpus)) {
perf_cpu_map__put(evsel->cpus);
evsel->cpus = perf_cpu_map__get(evsel->pmu_cpus);
}
/* * Globally requested CPUs replace user requested unless the evsel is * set to be system wide.
*/ if (evlist->has_user_cpus && !evsel->system_wide) {
assert(!perf_cpu_map__has_any_cpu(evlist->user_requested_cpus)); if (!perf_cpu_map__equal(evsel->cpus, evlist->user_requested_cpus)) {
perf_cpu_map__put(evsel->cpus);
evsel->cpus = perf_cpu_map__get(evlist->user_requested_cpus);
}
}
/* * Was event requested on all the PMU's CPUs but the user requested is * any CPU (-1)? If so switch to using any CPU (-1) to reduce the number * of events.
*/ if (!evsel->system_wide &&
!evsel->requires_cpu &&
perf_cpu_map__equal(evsel->cpus, evsel->pmu_cpus) &&
perf_cpu_map__has_any_cpu(evlist->user_requested_cpus)) {
perf_cpu_map__put(evsel->cpus);
evsel->cpus = perf_cpu_map__get(evlist->user_requested_cpus);
}
/* Sanity check assert before the evsel is potentially removed. */
assert(!evsel->requires_cpu || !perf_cpu_map__has_any_cpu(evsel->cpus));
/* * Empty cpu lists would eventually get opened as "any" so remove * genuinely empty ones before they're opened in the wrong place.
*/ if (perf_cpu_map__is_empty(evsel->cpus)) { struct perf_evsel *next = perf_evlist__next(evlist, evsel);
void perf_evlist__set_maps(struct perf_evlist *evlist, struct perf_cpu_map *cpus, struct perf_thread_map *threads)
{ /* * Allow for the possibility that one or another of the maps isn't being * changed i.e. don't put it. Note we are assuming the maps that are * being applied are brand new and evlist is taking ownership of the * original reference count of 1. If that is not the case it is up to * the caller to increase the reference count.
*/ if (cpus != evlist->user_requested_cpus) {
perf_cpu_map__put(evlist->user_requested_cpus);
evlist->user_requested_cpus = perf_cpu_map__get(cpus);
}
if (threads != evlist->threads) {
perf_thread_map__put(evlist->threads);
evlist->threads = perf_thread_map__get(threads);
}
perf_evlist__propagate_maps(evlist);
}
int perf_evlist__open(struct perf_evlist *evlist)
{ struct perf_evsel *evsel; int err;
int perf_evlist__id_add_fd(struct perf_evlist *evlist, struct perf_evsel *evsel, int cpu_map_idx, int thread, int fd)
{
u64 read_data[4] = { 0, }; int id_idx = 1; /* The first entry is the counter value */
u64 id; int ret;
if (!SID(evsel, cpu_map_idx, thread)) return -1;
ret = ioctl(fd, PERF_EVENT_IOC_ID, &id); if (!ret) goto add;
if (errno != ENOTTY) return -1;
/* Legacy way to get event id.. All hail to old kernels! */
/* * This way does not work with group format read, so bail * out in that case.
*/ if (perf_evlist__read_format(evlist) & PERF_FORMAT_GROUP) return -1;
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
{ int nr_cpus = perf_cpu_map__nr(evlist->all_cpus); int nr_threads = perf_thread_map__nr(evlist->threads); int nfds = 0; struct perf_evsel *evsel;
map = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap)); if (!map) return NULL;
for (i = 0; i < evlist->nr_mmaps; i++) { struct perf_mmap *prev = i ? &map[i - 1] : NULL;
/* * When the perf_mmap() call is made we grab one refcount, plus * one extra to let perf_mmap__consume() get the last * events after all real references (perf_mmap__get()) are * dropped. * * Each PERF_EVENT_IOC_SET_OUTPUT points to this mmap and * thus does perf_mmap__get() on it.
*/
perf_mmap__init(&map[i], prev, overwrite, NULL);
}
return map;
}
staticvoid perf_evsel__set_sid_idx(struct perf_evsel *evsel, int idx, int cpu, int thread)
{ struct perf_sample_id *sid = SID(evsel, cpu, thread);
staticint
mmap_per_evsel(struct perf_evlist *evlist, struct perf_evlist_mmap_ops *ops, int idx, struct perf_mmap_param *mp, int cpu_idx, int thread, int *_output, int *_output_overwrite, int *nr_mmaps)
{ struct perf_cpu evlist_cpu = perf_cpu_map__cpu(evlist->all_cpus, cpu_idx); struct perf_evsel *evsel; int revent;
/* * The last one will be done at perf_mmap__consume(), so that we * make sure we don't prevent tools from consuming every last event in * the ring buffer. * * I.e. we can get the POLLHUP meaning that the fd doesn't exist * anymore, but the last events for it are still in the ring buffer, * waiting to be consumed. * * Tools can chose to ignore this at their own discretion, but the * evlist layer can't just drop it when filtering events in * perf_evlist__filter_pollfd().
*/
refcount_set(&map->refcnt, 2);
if (ops->idx)
ops->idx(evlist, evsel, mp, idx);
/* Debug message used by test scripts */
pr_debug("idx %d: mmapping fd %d\n", idx, *output); if (ops->mmap(map, mp, *output, evlist_cpu) < 0) return -1;
*nr_mmaps += 1;
if (!idx)
perf_evlist__set_mmap_first(evlist, map, overwrite);
} else { /* Debug message used by test scripts */
pr_debug("idx %d: set output fd %d -> %d\n", idx, fd, *output); if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0) return -1;
staticint perf_evlist__nr_mmaps(struct perf_evlist *evlist)
{ int nr_mmaps;
/* One for each CPU */
nr_mmaps = perf_cpu_map__nr(evlist->all_cpus); if (perf_cpu_map__has_any_cpu_or_is_empty(evlist->all_cpus)) { /* Plus one for each thread */
nr_mmaps += perf_thread_map__nr(evlist->threads); /* Minus the per-thread CPU (-1) */
nr_mmaps -= 1;
}
int perf_evlist__nr_groups(struct perf_evlist *evlist)
{ struct perf_evsel *evsel; int nr_groups = 0;
perf_evlist__for_each_evsel(evlist, evsel) { /* * evsels by default have a nr_members of 1, and they are their * own leader. If the nr_members is >1 then this is an * indication of a group.
*/ if (evsel->leader == evsel && evsel->nr_members > 1)
nr_groups++;
} return nr_groups;
}
void perf_evlist__go_system_wide(struct perf_evlist *evlist, struct perf_evsel *evsel)
{ if (!evsel->system_wide) {
evsel->system_wide = true; if (evlist->needs_map_propagation)
__perf_evlist__propagate_maps(evlist, evsel);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.