Lines Matching +full:cpu +full:- +full:core
1 // SPDX-License-Identifier: GPL-2.0-only
3 * builtin-stat.c
6 * overview about any workload, CPU or specific PID.
16 1708.761321 task-clock # 11.037 CPUs utilized
17 41,190 context-switches # 0.024 M/sec
18 6,735 CPU-migrations # 0.004 M/sec
19 17,318 page-faults # 0.010 M/sec
21 3,856,436,920 stalled-cycles-frontend # 74.09% frontend cycles idle
22 1,600,790,871 stalled-cycles-backend # 30.75% backend cycles idle
26 6,388,934 branch-misses # 1.32% of all branches
31 * Copyright (C) 2008-2011, Red Hat Inc, Ingo Molnar <mingo@redhat.com>
45 #include <subcmd/parse-options.h>
46 #include "util/parse-events.h"
65 #include "util/synthetic-events.h"
67 #include "util/time-utils.h"
74 #include "util/intel-tpebs.h"
105 #define FREEZE_ON_SMI_PATH "bus/event_source/devices/cpu/freeze_on_smi"
123 static volatile sig_atomic_t child_pid = -1;
129 static int big_num_opt = -1;
163 bool node, socket, die, cluster, cache, core, thread, no_aggr; member
171 if (opt_mode->node) in opt_aggr_mode_to_aggr_mode()
173 if (opt_mode->socket) in opt_aggr_mode_to_aggr_mode()
175 if (opt_mode->die) in opt_aggr_mode_to_aggr_mode()
177 if (opt_mode->cluster) in opt_aggr_mode_to_aggr_mode()
179 if (opt_mode->cache) in opt_aggr_mode_to_aggr_mode()
181 if (opt_mode->core) in opt_aggr_mode_to_aggr_mode()
183 if (opt_mode->thread) in opt_aggr_mode_to_aggr_mode()
185 if (opt_mode->no_aggr) in opt_aggr_mode_to_aggr_mode()
200 if (perf_cpu_map__equal(leader->core.cpus, evsel->core.cpus)) in evlist__check_cpu_maps()
217 cpu_map__snprint(leader->core.cpus, buf, sizeof(buf)); in evlist__check_cpu_maps()
218 pr_warning(" %s: %s\n", leader->name, buf); in evlist__check_cpu_maps()
219 cpu_map__snprint(evsel->core.cpus, buf, sizeof(buf)); in evlist__check_cpu_maps()
220 pr_warning(" %s: %s\n", evsel->name, buf); in evlist__check_cpu_maps()
230 r->tv_sec = a->tv_sec - b->tv_sec; in diff_timespec()
231 if (a->tv_nsec < b->tv_nsec) { in diff_timespec()
232 r->tv_nsec = a->tv_nsec + NSEC_PER_SEC - b->tv_nsec; in diff_timespec()
233 r->tv_sec--; in diff_timespec()
235 r->tv_nsec = a->tv_nsec - b->tv_nsec ; in diff_timespec()
250 if (perf_data__write(&perf_stat.data, event, event->header.size) < 0) { in process_synthesized_event()
252 return -1; in process_synthesized_event()
255 perf_stat.bytes_written += event->header.size; in process_synthesized_event()
269 #define SID(e, x, y) xyarray__entry(e->core.sample_id, x, y)
275 struct perf_cpu cpu = perf_cpu_map__cpu(evsel__cpus(counter), cpu_map_idx); in evsel__write_stat_event() local
277 return perf_event__synthesize_stat(NULL, cpu, thread, sid->id, count, in evsel__write_stat_event()
293 perf_counts(counter->counts, cpu_map_idx, thread); in read_single_counter()
297 if (counter->prev_raw_counts) in read_single_counter()
298 old_count = perf_counts(counter->prev_raw_counts, cpu_map_idx, thread); in read_single_counter()
305 count->val = val; in read_single_counter()
307 count->run = old_count->run + 1; in read_single_counter()
308 count->ena = old_count->ena + 1; in read_single_counter()
310 count->run++; in read_single_counter()
311 count->ena++; in read_single_counter()
320 * do not aggregate counts across CPUs in system-wide mode
324 int nthreads = perf_thread_map__nr(evsel_list->core.threads); in read_counter_cpu()
327 if (!counter->supported) in read_counter_cpu()
328 return -ENOENT; in read_counter_cpu()
333 count = perf_counts(counter->counts, cpu_map_idx, thread); in read_counter_cpu()
337 * (via evsel__read_counter()) and sets their count->loaded. in read_counter_cpu()
339 if (!perf_counts__is_loaded(counter->counts, cpu_map_idx, thread) && in read_counter_cpu()
341 counter->counts->scaled = -1; in read_counter_cpu()
342 perf_counts(counter->counts, cpu_map_idx, thread)->ena = 0; in read_counter_cpu()
343 perf_counts(counter->counts, cpu_map_idx, thread)->run = 0; in read_counter_cpu()
344 return -1; in read_counter_cpu()
347 perf_counts__set_loaded(counter->counts, cpu_map_idx, thread, false); in read_counter_cpu()
352 return -1; in read_counter_cpu()
361 cpu_map_idx).cpu, in read_counter_cpu()
362 count->val, count->ena, count->run); in read_counter_cpu()
380 return -1; in read_counters_with_affinity()
393 if (!counter->err) in read_counters_with_affinity()
394 counter->err = read_counter_cpu(counter, evlist_cpu_itr.cpu_map_idx); in read_counters_with_affinity()
428 perf_cpu_map__for_each_idx(idx, counter->core.cpus) { in read_tool_counters()
429 if (!counter->err) in read_tool_counters()
430 counter->err = read_counter_cpu(counter, idx); in read_tool_counters()
448 // Read non-BPF and non-tool counters next. in read_counters()
463 if (counter->err) in process_counters()
464 pr_debug("failed to read counter %s\n", counter->name); in process_counters()
465 if (counter->err == 0 && perf_stat_process_counter(&stat_config, counter)) in process_counters()
466 pr_warning("failed to process counter %s\n", counter->name); in process_counters()
467 counter->err = 0; in process_counters()
500 if (interval_count && !(--(*times))) in handle_interval()
532 * If we don't have tracee (attaching to task or cpu), counters may in disable_counters()
554 workload_exec_errno = info->si_value.sival_int; in workload_exec_failed_signal()
559 return STAT_RECORD || counter->core.attr.read_format & PERF_FORMAT_ID; in evsel__should_store_id()
571 for (i = 0; i < threads->nr; i++) { in is_target_alive()
575 threads->map[i].pid); in is_target_alive()
616 tts -= time_diff.tv_sec * MSEC_PER_SEC + in compute_tts()
644 child_exited = !is_target_alive(&target, evsel_list->core.threads) ? 1 : 0; in dispatch_events()
673 assert(!counter->supported); in stat_handle_error()
690 counter->supported = true; in stat_handle_error()
694 evsel_list->core.threads && evsel_list->core.threads->err_thread != -1) { in stat_handle_error()
696 * For global --per-thread case, skip current in stat_handle_error()
699 if (!thread_map__remove(evsel_list->core.threads, in stat_handle_error()
700 evsel_list->core.threads->err_thread)) { in stat_handle_error()
701 evsel_list->core.threads->err_thread = -1; in stat_handle_error()
702 counter->supported = true; in stat_handle_error()
720 struct perf_event_attr *attr = &evsel->core.attr; in create_perf_stat_counter()
724 attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | in create_perf_stat_counter()
732 if (leader->core.nr_members > 1) in create_perf_stat_counter()
733 attr->read_format |= PERF_FORMAT_ID|PERF_FORMAT_GROUP; in create_perf_stat_counter()
735 attr->inherit = !config->no_inherit && list_empty(&evsel->bpf_counter_list); in create_perf_stat_counter()
741 attr->sample_period = 0; in create_perf_stat_counter()
743 if (config->identifier) in create_perf_stat_counter()
744 attr->sample_type = PERF_SAMPLE_IDENTIFIER; in create_perf_stat_counter()
746 if (config->all_user) { in create_perf_stat_counter()
747 attr->exclude_kernel = 1; in create_perf_stat_counter()
748 attr->exclude_user = 0; in create_perf_stat_counter()
751 if (config->all_kernel) { in create_perf_stat_counter()
752 attr->exclude_kernel = 0; in create_perf_stat_counter()
753 attr->exclude_user = 1; in create_perf_stat_counter()
762 attr->disabled = 1; in create_perf_stat_counter()
765 attr->enable_on_exec = 1; in create_perf_stat_counter()
769 evsel->core.threads); in create_perf_stat_counter()
778 (rusage->ru_utime.tv_usec * us_to_ns + rusage->ru_utime.tv_sec * s_to_ns)); in update_rusage_stats()
780 (rusage->ru_stime.tv_usec * us_to_ns + rusage->ru_stime.tv_sec * s_to_ns)); in update_rusage_stats()
803 return -1; in __run_perf_stat()
805 child_pid = evsel_list->workload.pid; in __run_perf_stat()
808 if (!cpu_map__is_dummy(evsel_list->core.user_requested_cpus)) { in __run_perf_stat()
810 err = -1; in __run_perf_stat()
817 counter->reset_group = false; in __run_perf_stat()
819 err = -1; in __run_perf_stat()
838 if (counter->reset_group || !counter->supported) in __run_perf_stat()
858 counter->weak_group) { in __run_perf_stat()
860 assert(counter->reset_group); in __run_perf_stat()
861 counter->supported = true; in __run_perf_stat()
881 if (!counter->reset_group && counter->supported) in __run_perf_stat()
884 perf_evsel__close_cpu(&counter->core, evlist_cpu_itr.cpu_map_idx); in __run_perf_stat()
890 if (!counter->reset_group) in __run_perf_stat()
910 if (!counter->supported) { in __run_perf_stat()
911 perf_evsel__free_fd(&counter->core); in __run_perf_stat()
916 l = strlen(counter->unit); in __run_perf_stat()
922 err = -1; in __run_perf_stat()
933 if (child_pid != -1) in __run_perf_stat()
935 err = -1; in __run_perf_stat()
941 counter->filter, evsel__name(counter), errno, in __run_perf_stat()
943 return -1; in __run_perf_stat()
971 err = -1; in __run_perf_stat()
984 err = -1; in __run_perf_stat()
997 if (child_pid != -1) { in __run_perf_stat()
1006 err = -1; in __run_perf_stat()
1017 err = 0 - (128 + WTERMSIG(status)); in __run_perf_stat()
1031 stat_config.walltime_run[run_idx] = t1 - t0; in __run_perf_stat()
1037 update_stats(stat_config.walltime_nsecs_stats, t1 - t0); in __run_perf_stat()
1043 update_stats(stat_config.walltime_nsecs_stats, t1 - t0); in __run_perf_stat()
1074 * Returns -1 for fatal errors which signifies to not continue
1077 * Returns < -1 error codes when stat record is used. These
1118 static volatile sig_atomic_t signr = -1;
1122 if ((child_pid == -1) || stat_config.interval) in skip_signal()
1132 child_pid = -1; in skip_signal()
1149 if (child_pid != -1) in sig_atexit()
1154 if (signr == -1) in sig_atexit()
1185 return -ENOMEM; in append_metric_groups()
1191 return -ENOMEM; in append_metric_groups()
1200 struct perf_stat_config *config = opt->value; in parse_control_option()
1202 return evlist__parse_control(str, &config->ctl_fd, &config->ctl_fd_ack, &config->ctl_fd_close); in parse_control_option()
1209 pr_err("--cgroup and --for-each-cgroup cannot be used together\n"); in parse_stat_cgroups()
1210 return -1; in parse_stat_cgroups()
1221 struct evlist *evlist = *(struct evlist **)opt->value; in parse_cputype()
1223 if (!list_empty(&evlist->core.entries)) { in parse_cputype()
1225 return -1; in parse_cputype()
1230 fprintf(stderr, "--cputype %s is not supported!\n", str); in parse_cputype()
1231 return -1; in parse_cputype()
1233 parse_events_option_args.pmu_filter = pmu->name; in parse_cputype()
1243 struct opt_aggr_mode *opt_aggr_mode = (struct opt_aggr_mode *)opt->value; in parse_cache_level()
1244 u32 *aggr_level = (u32 *)opt->data; in parse_cache_level()
1262 pr_err("Cache level must be of form L[1-%d], or l[1-%d]\n", in parse_cache_level()
1265 return -EINVAL; in parse_cache_level()
1270 pr_err("Cache level must be of form L[1-%d], or l[1-%d]\n", in parse_cache_level()
1273 return -EINVAL; in parse_cache_level()
1279 return -EINVAL; in parse_cache_level()
1282 opt_aggr_mode->cache = true; in parse_cache_level()
1289 * /sys/devices/system/cpu/cpuX/cache/indexY/shared_cpu_list
1290 * Cache instance ID is the first CPU reported in the shared_cpu_list file.
1292 static int cpu__get_cache_id_from_map(struct perf_cpu cpu, char *map) in cpu__get_cache_id_from_map() argument
1298 * If the map contains no CPU, consider the current CPU to in cpu__get_cache_id_from_map()
1299 * be the first online CPU in the cache domain else use the in cpu__get_cache_id_from_map()
1300 * first online CPU of the cache domain as the ID. in cpu__get_cache_id_from_map()
1302 id = perf_cpu_map__min(cpu_map).cpu; in cpu__get_cache_id_from_map()
1303 if (id == -1) in cpu__get_cache_id_from_map()
1304 id = cpu.cpu; in cpu__get_cache_id_from_map()
1313 * cpu__get_cache_id - Returns 0 if successful in populating the
1315 * /sys/devices/system/cpu/cpuX/cache/indexY/level where as cache instance ID
1316 * is the first CPU reported by
1317 * /sys/devices/system/cpu/cpuX/cache/indexY/shared_cpu_list
1319 static int cpu__get_cache_details(struct perf_cpu cpu, struct perf_cache *cache) in cpu__get_cache_details() argument
1326 cache->cache_lvl = (cache_level > MAX_CACHE_LVL) ? 0 : cache_level; in cpu__get_cache_details()
1327 cache->cache = -1; in cpu__get_cache_details()
1329 ret = build_caches_for_cpu(cpu.cpu, caches, &caches_cnt); in cpu__get_cache_details()
1343 return -1; in cpu__get_cache_details()
1357 cache->cache_lvl = caches[max_level_index].level; in cpu__get_cache_details()
1358 cache->cache = cpu__get_cache_id_from_map(cpu, caches[max_level_index].map); in cpu__get_cache_details()
1367 cache->cache_lvl = cache_level; in cpu__get_cache_details()
1368 cache->cache = cpu__get_cache_id_from_map(cpu, caches[i].map); in cpu__get_cache_details()
1385 * aggr_cpu_id__cache - Create an aggr_cpu_id with cache instache ID, cache
1387 * die and socket for cpu. The function signature is compatible with
1390 static struct aggr_cpu_id aggr_cpu_id__cache(struct perf_cpu cpu, void *data) in aggr_cpu_id__cache() argument
1396 id = aggr_cpu_id__die(cpu, data); in aggr_cpu_id__cache()
1400 ret = cpu__get_cache_details(cpu, &cache); in aggr_cpu_id__cache()
1410 [AGGR_CORE] = "core",
1423 struct perf_cpu cpu) in perf_stat__get_socket() argument
1425 return aggr_cpu_id__socket(cpu, /*data=*/NULL); in perf_stat__get_socket()
1429 struct perf_cpu cpu) in perf_stat__get_die() argument
1431 return aggr_cpu_id__die(cpu, /*data=*/NULL); in perf_stat__get_die()
1435 struct perf_cpu cpu) in perf_stat__get_cache_id() argument
1437 return aggr_cpu_id__cache(cpu, /*data=*/NULL); in perf_stat__get_cache_id()
1441 struct perf_cpu cpu) in perf_stat__get_cluster() argument
1443 return aggr_cpu_id__cluster(cpu, /*data=*/NULL); in perf_stat__get_cluster()
1447 struct perf_cpu cpu) in perf_stat__get_core() argument
1449 return aggr_cpu_id__core(cpu, /*data=*/NULL); in perf_stat__get_core()
1453 struct perf_cpu cpu) in perf_stat__get_node() argument
1455 return aggr_cpu_id__node(cpu, /*data=*/NULL); in perf_stat__get_node()
1459 struct perf_cpu cpu) in perf_stat__get_global() argument
1461 return aggr_cpu_id__global(cpu, /*data=*/NULL); in perf_stat__get_global()
1465 struct perf_cpu cpu) in perf_stat__get_cpu() argument
1467 return aggr_cpu_id__cpu(cpu, /*data=*/NULL); in perf_stat__get_cpu()
1471 aggr_get_id_t get_id, struct perf_cpu cpu) in perf_stat__get_aggr() argument
1475 /* per-process mode - should use global aggr mode */ in perf_stat__get_aggr()
1476 if (cpu.cpu == -1 || cpu.cpu >= config->cpus_aggr_map->nr) in perf_stat__get_aggr()
1477 return get_id(config, cpu); in perf_stat__get_aggr()
1479 if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu.cpu])) in perf_stat__get_aggr()
1480 config->cpus_aggr_map->map[cpu.cpu] = get_id(config, cpu); in perf_stat__get_aggr()
1482 id = config->cpus_aggr_map->map[cpu.cpu]; in perf_stat__get_aggr()
1487 struct perf_cpu cpu) in perf_stat__get_socket_cached() argument
1489 return perf_stat__get_aggr(config, perf_stat__get_socket, cpu); in perf_stat__get_socket_cached()
1493 struct perf_cpu cpu) in perf_stat__get_die_cached() argument
1495 return perf_stat__get_aggr(config, perf_stat__get_die, cpu); in perf_stat__get_die_cached()
1499 struct perf_cpu cpu) in perf_stat__get_cluster_cached() argument
1501 return perf_stat__get_aggr(config, perf_stat__get_cluster, cpu); in perf_stat__get_cluster_cached()
1505 struct perf_cpu cpu) in perf_stat__get_cache_id_cached() argument
1507 return perf_stat__get_aggr(config, perf_stat__get_cache_id, cpu); in perf_stat__get_cache_id_cached()
1511 struct perf_cpu cpu) in perf_stat__get_core_cached() argument
1513 return perf_stat__get_aggr(config, perf_stat__get_core, cpu); in perf_stat__get_core_cached()
1517 struct perf_cpu cpu) in perf_stat__get_node_cached() argument
1519 return perf_stat__get_aggr(config, perf_stat__get_node, cpu); in perf_stat__get_node_cached()
1523 struct perf_cpu cpu) in perf_stat__get_global_cached() argument
1525 return perf_stat__get_aggr(config, perf_stat__get_global, cpu); in perf_stat__get_global_cached()
1529 struct perf_cpu cpu) in perf_stat__get_cpu_cached() argument
1531 return perf_stat__get_aggr(config, perf_stat__get_cpu, cpu); in perf_stat__get_cpu_cached()
1595 stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.user_requested_cpus, in perf_stat_init_aggr_mode()
1599 return -1; in perf_stat_init_aggr_mode()
1605 nr = perf_thread_map__nr(evsel_list->core.threads); in perf_stat_init_aggr_mode()
1608 return -ENOMEM; in perf_stat_init_aggr_mode()
1614 stat_config.aggr_map->map[s] = id; in perf_stat_init_aggr_mode()
1620 * The evsel_list->cpus is the base we operate on, in perf_stat_init_aggr_mode()
1621 * taking the highest cpu number to be the size of in perf_stat_init_aggr_mode()
1624 nr = perf_cpu_map__max(evsel_list->core.all_cpus).cpu + 1; in perf_stat_init_aggr_mode()
1626 return stat_config.cpus_aggr_map ? 0 : -ENOMEM; in perf_stat_init_aggr_mode()
1642 static struct aggr_cpu_id perf_env__get_socket_aggr_by_cpu(struct perf_cpu cpu, void *data) in perf_env__get_socket_aggr_by_cpu() argument
1647 if (cpu.cpu != -1) in perf_env__get_socket_aggr_by_cpu()
1648 id.socket = env->cpu[cpu.cpu].socket_id; in perf_env__get_socket_aggr_by_cpu()
1653 static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(struct perf_cpu cpu, void *data) in perf_env__get_die_aggr_by_cpu() argument
1658 if (cpu.cpu != -1) { in perf_env__get_die_aggr_by_cpu()
1664 id.socket = env->cpu[cpu.cpu].socket_id; in perf_env__get_die_aggr_by_cpu()
1665 id.die = env->cpu[cpu.cpu].die_id; in perf_env__get_die_aggr_by_cpu()
1671 static void perf_env__get_cache_id_for_cpu(struct perf_cpu cpu, struct perf_env *env, in perf_env__get_cache_id_for_cpu() argument
1675 int caches_cnt = env->caches_cnt; in perf_env__get_cache_id_for_cpu()
1676 struct cpu_cache_level *caches = env->caches; in perf_env__get_cache_id_for_cpu()
1678 id->cache_lvl = (cache_level > MAX_CACHE_LVL) ? 0 : cache_level; in perf_env__get_cache_id_for_cpu()
1679 id->cache = -1; in perf_env__get_cache_id_for_cpu()
1684 for (i = caches_cnt - 1; i > -1; --i) { in perf_env__get_cache_id_for_cpu()
1690 * the cpu in the map. Since building the map is expensive, do in perf_env__get_cache_id_for_cpu()
1697 map_contains_cpu = perf_cpu_map__idx(cpu_map, cpu); in perf_env__get_cache_id_for_cpu()
1700 if (map_contains_cpu != -1) { in perf_env__get_cache_id_for_cpu()
1701 id->cache_lvl = caches[i].level; in perf_env__get_cache_id_for_cpu()
1702 id->cache = cpu__get_cache_id_from_map(cpu, caches[i].map); in perf_env__get_cache_id_for_cpu()
1708 static struct aggr_cpu_id perf_env__get_cache_aggr_by_cpu(struct perf_cpu cpu, in perf_env__get_cache_aggr_by_cpu() argument
1714 if (cpu.cpu != -1) { in perf_env__get_cache_aggr_by_cpu()
1717 id.socket = env->cpu[cpu.cpu].socket_id; in perf_env__get_cache_aggr_by_cpu()
1718 id.die = env->cpu[cpu.cpu].die_id; in perf_env__get_cache_aggr_by_cpu()
1719 perf_env__get_cache_id_for_cpu(cpu, env, cache_level, &id); in perf_env__get_cache_aggr_by_cpu()
1725 static struct aggr_cpu_id perf_env__get_cluster_aggr_by_cpu(struct perf_cpu cpu, in perf_env__get_cluster_aggr_by_cpu() argument
1731 if (cpu.cpu != -1) { in perf_env__get_cluster_aggr_by_cpu()
1732 id.socket = env->cpu[cpu.cpu].socket_id; in perf_env__get_cluster_aggr_by_cpu()
1733 id.die = env->cpu[cpu.cpu].die_id; in perf_env__get_cluster_aggr_by_cpu()
1734 id.cluster = env->cpu[cpu.cpu].cluster_id; in perf_env__get_cluster_aggr_by_cpu()
1740 static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(struct perf_cpu cpu, void *data) in perf_env__get_core_aggr_by_cpu() argument
1745 if (cpu.cpu != -1) { in perf_env__get_core_aggr_by_cpu()
1748 * global id. So we set socket, die id, cluster id and core id. in perf_env__get_core_aggr_by_cpu()
1750 id.socket = env->cpu[cpu.cpu].socket_id; in perf_env__get_core_aggr_by_cpu()
1751 id.die = env->cpu[cpu.cpu].die_id; in perf_env__get_core_aggr_by_cpu()
1752 id.cluster = env->cpu[cpu.cpu].cluster_id; in perf_env__get_core_aggr_by_cpu()
1753 id.core = env->cpu[cpu.cpu].core_id; in perf_env__get_core_aggr_by_cpu()
1759 static struct aggr_cpu_id perf_env__get_cpu_aggr_by_cpu(struct perf_cpu cpu, void *data) in perf_env__get_cpu_aggr_by_cpu() argument
1764 if (cpu.cpu != -1) { in perf_env__get_cpu_aggr_by_cpu()
1768 * socket, die id and core id in perf_env__get_cpu_aggr_by_cpu()
1770 id.socket = env->cpu[cpu.cpu].socket_id; in perf_env__get_cpu_aggr_by_cpu()
1771 id.die = env->cpu[cpu.cpu].die_id; in perf_env__get_cpu_aggr_by_cpu()
1772 id.core = env->cpu[cpu.cpu].core_id; in perf_env__get_cpu_aggr_by_cpu()
1773 id.cpu = cpu; in perf_env__get_cpu_aggr_by_cpu()
1779 static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(struct perf_cpu cpu, void *data) in perf_env__get_node_aggr_by_cpu() argument
1783 id.node = perf_env__numa_node(data, cpu); in perf_env__get_node_aggr_by_cpu()
1787 static struct aggr_cpu_id perf_env__get_global_aggr_by_cpu(struct perf_cpu cpu __maybe_unused, in perf_env__get_global_aggr_by_cpu()
1792 /* it always aggregates to the cpu 0 */ in perf_env__get_global_aggr_by_cpu()
1793 id.cpu = (struct perf_cpu){ .cpu = 0 }; in perf_env__get_global_aggr_by_cpu()
1798 struct perf_cpu cpu) in perf_stat__get_socket_file() argument
1800 return perf_env__get_socket_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); in perf_stat__get_socket_file()
1803 struct perf_cpu cpu) in perf_stat__get_die_file() argument
1805 return perf_env__get_die_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); in perf_stat__get_die_file()
1809 struct perf_cpu cpu) in perf_stat__get_cluster_file() argument
1811 return perf_env__get_cluster_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); in perf_stat__get_cluster_file()
1815 struct perf_cpu cpu) in perf_stat__get_cache_file() argument
1817 return perf_env__get_cache_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); in perf_stat__get_cache_file()
1821 struct perf_cpu cpu) in perf_stat__get_core_file() argument
1823 return perf_env__get_core_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); in perf_stat__get_core_file()
1827 struct perf_cpu cpu) in perf_stat__get_cpu_file() argument
1829 return perf_env__get_cpu_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); in perf_stat__get_cpu_file()
1833 struct perf_cpu cpu) in perf_stat__get_node_file() argument
1835 return perf_env__get_node_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); in perf_stat__get_node_file()
1839 struct perf_cpu cpu) in perf_stat__get_global_file() argument
1841 return perf_env__get_global_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); in perf_stat__get_global_file()
1900 struct perf_env *env = perf_session__env(st->session); in perf_stat_init_aggr_mode_file()
1905 int nr = perf_thread_map__nr(evsel_list->core.threads); in perf_stat_init_aggr_mode_file()
1909 return -ENOMEM; in perf_stat_init_aggr_mode_file()
1915 stat_config.aggr_map->map[s] = id; in perf_stat_init_aggr_mode_file()
1923 stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.user_requested_cpus, in perf_stat_init_aggr_mode_file()
1927 return -1; in perf_stat_init_aggr_mode_file()
1938 const struct evsel *lhs = container_of(lhs_core, struct evsel, core); in default_evlist_evsel_cmp()
1940 const struct evsel *rhs = container_of(rhs_core, struct evsel, core); in default_evlist_evsel_cmp()
1944 return lhs_core->idx - rhs_core->idx; in default_evlist_evsel_cmp()
1948 if (lhs->default_metricgroup != rhs->default_metricgroup) in default_evlist_evsel_cmp()
1949 return lhs->default_metricgroup ? -1 : 1; in default_evlist_evsel_cmp()
1951 if (lhs->default_show_events != rhs->default_show_events) in default_evlist_evsel_cmp()
1952 return lhs->default_show_events ? -1 : 1; in default_evlist_evsel_cmp()
1955 if (lhs->pmu != rhs->pmu) in default_evlist_evsel_cmp()
1956 return lhs->pmu->type - rhs->pmu->type; in default_evlist_evsel_cmp()
1964 * if -d/--detailed, -d -d or -d -d -d is used:
1975 return -ENOMEM; in add_default_events()
1984 /* Handle -T as -M transaction. Once platform specific metrics in add_default_events()
1991 ret = -1; in add_default_events()
2009 ret = -1; in add_default_events()
2016 ret = -1; in add_default_events()
2024 ret = -1; in add_default_events()
2051 ret = -1; in add_default_events()
2055 pr_err("Invalid top-down metrics level. The max level is %u.\n", max_level); in add_default_events()
2056 ret = -1; in add_default_events()
2064 "Please print the result regularly, e.g. -I1000\n"); in add_default_events()
2075 ret = -1; in add_default_events()
2083 if (!evlist->core.nr_entries && !evsel_list->core.nr_entries) { in add_default_events()
2104 ret = -ENOMEM; in add_default_events()
2115 ret = -1; in add_default_events()
2120 evsel->default_metricgroup = true; in add_default_events()
2122 evlist__splice_list_tail(evlist, &metric_evlist->core.entries); in add_default_events()
2124 &evlist->metric_events, in add_default_events()
2125 &metric_evlist->metric_events); in add_default_events()
2128 list_sort(/*priv=*/NULL, &evlist->core.entries, default_evlist_evsel_cmp); in add_default_events()
2135 * Make at least one event non-skippable so fatal errors are visible. in add_default_events()
2136 * 'cycles' always used to be default and non-skippable, so use that. in add_default_events()
2139 evsel->skippable = true; in add_default_events()
2143 evlist__splice_list_tail(evsel_list, &evlist->core.entries); in add_default_events()
2145 &evsel_list->metric_events, in add_default_events()
2146 &evlist->metric_events); in add_default_events()
2161 perf_header__set_feat(&session->header, feat); in init_features()
2163 perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT); in init_features()
2164 perf_header__clear_feat(&session->header, HEADER_BUILD_ID); in init_features()
2165 perf_header__clear_feat(&session->header, HEADER_TRACING_DATA); in init_features()
2166 perf_header__clear_feat(&session->header, HEADER_BRANCH_STACK); in init_features()
2167 perf_header__clear_feat(&session->header, HEADER_AUXTRACE); in init_features()
2181 data->path = output_name; in __cmd_record()
2184 pr_err("Cannot use -r option with perf stat record.\n"); in __cmd_record()
2185 return -1; in __cmd_record()
2196 session->evlist = evsel_list; in __cmd_record()
2206 struct perf_record_stat_round *stat_round = &event->stat_round; in process_stat_round_event()
2209 const char **argv = env->cmdline_argv; in process_stat_round_event()
2210 int argc = env->nr_cmdline; in process_stat_round_event()
2214 if (stat_round->type == PERF_STAT_ROUND_TYPE__FINAL) in process_stat_round_event()
2215 update_stats(stat_config.walltime_nsecs_stats, stat_round->time); in process_stat_round_event()
2217 if (stat_config.interval && stat_round->time) { in process_stat_round_event()
2218 tsh.tv_sec = stat_round->time / NSEC_PER_SEC; in process_stat_round_event()
2219 tsh.tv_nsec = stat_round->time % NSEC_PER_SEC; in process_stat_round_event()
2234 perf_event__read_stat_config(&stat_config, &event->stat_config); in process_stat_config_event()
2236 if (perf_cpu_map__is_empty(st->cpus)) { in process_stat_config_event()
2237 if (st->aggr_mode != AGGR_UNSET) in process_stat_config_event()
2239 } else if (st->aggr_mode != AGGR_UNSET) { in process_stat_config_event()
2240 stat_config.aggr_mode = st->aggr_mode; in process_stat_config_event()
2249 int nr_aggr = stat_config.aggr_map->nr; in process_stat_config_event()
2251 if (evlist__alloc_aggr_stats(session->evlist, nr_aggr) < 0) { in process_stat_config_event()
2253 return -1; in process_stat_config_event()
2261 if (!st->cpus || !st->threads) in set_maps()
2264 if (WARN_ONCE(st->maps_allocated, "stats double allocation\n")) in set_maps()
2265 return -EINVAL; in set_maps()
2267 perf_evlist__set_maps(&evsel_list->core, st->cpus, st->threads); in set_maps()
2270 return -ENOMEM; in set_maps()
2272 st->maps_allocated = true; in set_maps()
2283 if (st->threads) { in process_thread_map_event()
2288 st->threads = thread_map__new_event(&event->thread_map); in process_thread_map_event()
2289 if (!st->threads) in process_thread_map_event()
2290 return -ENOMEM; in process_thread_map_event()
2303 if (st->cpus) { in process_cpu_map_event()
2304 pr_warning("Extra cpu map event, ignoring.\n"); in process_cpu_map_event()
2308 cpus = cpu_map__new_data(&event->cpu_map.data); in process_cpu_map_event()
2310 return -ENOMEM; in process_cpu_map_event()
2312 st->cpus = cpus; in process_cpu_map_event()
2331 OPT_SET_UINT(0, "per-socket", &perf_stat.aggr_mode, in __cmd_report()
2333 OPT_SET_UINT(0, "per-die", &perf_stat.aggr_mode, in __cmd_report()
2335 OPT_SET_UINT(0, "per-cluster", &perf_stat.aggr_mode, in __cmd_report()
2337 OPT_CALLBACK_OPTARG(0, "per-cache", &perf_stat.aggr_mode, &perf_stat.aggr_level, in __cmd_report()
2341 OPT_SET_UINT(0, "per-core", &perf_stat.aggr_mode, in __cmd_report()
2342 "aggregate counts per physical processor core", AGGR_CORE), in __cmd_report()
2343 OPT_SET_UINT(0, "per-node", &perf_stat.aggr_mode, in __cmd_report()
2345 OPT_SET_UINT('A', "no-aggr", &perf_stat.aggr_mode, in __cmd_report()
2346 "disable CPU count aggregation", AGGR_NONE), in __cmd_report()
2356 input_name = "-"; in __cmd_report()
2380 evsel_list = session->evlist; in __cmd_report()
2393 * Make system wide (-a) the default target if in setup_system_wide()
2397 * - there's no workload specified in setup_system_wide()
2398 * - there is workload specified but all requested in setup_system_wide()
2410 if (!counter->core.requires_cpu && in setup_system_wide()
2416 if (evsel_list->core.nr_entries) in setup_system_wide()
2425 enum tpebs_mode *mode = opt->value; in parse_tpebs_mode()
2443 return -1; in parse_tpebs_mode()
2458 OPT_BOOLEAN('i', "no-inherit", &stat_config.no_inherit, in cmd_stat()
2465 OPT_STRING('b', "bpf-prog", &target.bpf_str, "bpf-prog-id", in cmd_stat()
2467 OPT_BOOLEAN(0, "bpf-counters", &target.use_bpf, in cmd_stat()
2469 OPT_STRING(0, "bpf-attr-map", &target.attr_map, "attr-map-path", in cmd_stat()
2472 OPT_BOOLEAN('a', "all-cpus", &target.system_wide, in cmd_stat()
2473 "system-wide collection from all CPUs"), in cmd_stat()
2475 "Use --no-scale to disable counter scaling for multiplexing"), in cmd_stat()
2481 "display details about each run (only with -r option)"), in cmd_stat()
2483 "null run - dont start any counters"), in cmd_stat()
2485 "detailed run - start a lot of events"), in cmd_stat()
2488 OPT_CALLBACK_NOOPT('B', "big-num", NULL, NULL, in cmd_stat()
2491 OPT_STRING('C', "cpu", &target.cpu_list, "cpu", in cmd_stat()
2492 "list of cpus to monitor in system-wide"), in cmd_stat()
2493 OPT_BOOLEAN('A', "no-aggr", &opt_mode.no_aggr, in cmd_stat()
2495 OPT_BOOLEAN(0, "no-merge", &opt_mode.no_aggr, in cmd_stat()
2496 "disable aggregation the same as -A or -no-aggr"), in cmd_stat()
2497 OPT_BOOLEAN(0, "hybrid-merge", &stat_config.hybrid_merge, in cmd_stat()
2499 OPT_STRING('x', "field-separator", &stat_config.csv_sep, "separator", in cmd_stat()
2501 OPT_BOOLEAN('j', "json-output", &stat_config.json_output, in cmd_stat()
2505 OPT_STRING(0, "for-each-cgroup", &stat_config.cgroup_list, "name", in cmd_stat()
2509 OPT_INTEGER(0, "log-fd", &output_fd, in cmd_stat()
2515 OPT_UINTEGER('I', "interval-print", &stat_config.interval, in cmd_stat()
2518 OPT_INTEGER(0, "interval-count", &stat_config.times, in cmd_stat()
2520 OPT_BOOLEAN(0, "interval-clear", &stat_config.interval_clear, in cmd_stat()
2524 OPT_BOOLEAN(0, "per-socket", &opt_mode.socket, in cmd_stat()
2526 OPT_BOOLEAN(0, "per-die", &opt_mode.die, "aggregate counts per processor die"), in cmd_stat()
2527 OPT_BOOLEAN(0, "per-cluster", &opt_mode.cluster, in cmd_stat()
2529 OPT_CALLBACK_OPTARG(0, "per-cache", &opt_mode, &stat_config.aggr_level, in cmd_stat()
2532 OPT_BOOLEAN(0, "per-core", &opt_mode.core, in cmd_stat()
2533 "aggregate counts per physical processor core"), in cmd_stat()
2534 OPT_BOOLEAN(0, "per-thread", &opt_mode.thread, "aggregate counts per thread"), in cmd_stat()
2535 OPT_BOOLEAN(0, "per-node", &opt_mode.node, "aggregate counts per numa node"), in cmd_stat()
2537 "ms to wait before starting measurement after program start (-1: start with events disabled)"), in cmd_stat()
2538 OPT_CALLBACK_NOOPT(0, "metric-only", &stat_config.metric_only, NULL, in cmd_stat()
2540 OPT_BOOLEAN(0, "metric-no-group", &stat_config.metric_no_group, in cmd_stat()
2542 OPT_BOOLEAN(0, "metric-no-merge", &stat_config.metric_no_merge, in cmd_stat()
2544 OPT_BOOLEAN(0, "metric-no-threshold", &stat_config.metric_no_threshold, in cmd_stat()
2547 "measure top-down statistics"), in cmd_stat()
2549 OPT_BOOLEAN(0, "record-tpebs", &tpebs_recording, in cmd_stat()
2551 OPT_CALLBACK(0, "tpebs-mode", &tpebs_mode, "tpebs-mode", in cmd_stat()
2555 OPT_UINTEGER(0, "td-level", &stat_config.topdown_level, in cmd_stat()
2556 "Set the metrics level for the top-down statistics (0: max level)"), in cmd_stat()
2557 OPT_BOOLEAN(0, "smi-cost", &smi_cost, in cmd_stat()
2562 OPT_BOOLEAN_FLAG(0, "all-kernel", &stat_config.all_kernel, in cmd_stat()
2565 OPT_BOOLEAN_FLAG(0, "all-user", &stat_config.all_user, in cmd_stat()
2568 OPT_BOOLEAN(0, "percore-show-thread", &stat_config.percore_show_thread, in cmd_stat()
2571 "threads of same physical core"), in cmd_stat()
2574 OPT_BOOLEAN(0, "no-csv-summary", &stat_config.no_csv_summary, in cmd_stat()
2578 OPT_CALLBACK(0, "cputype", &evsel_list, "hybrid cpu type", in cmd_stat()
2579 "Only enable events on applying cpu with this type " in cmd_stat()
2580 "for hybrid platform (e.g. core or atom)", in cmd_stat()
2583 OPT_CALLBACK(0, "pfm-events", &evsel_list, "event", in cmd_stat()
2587 OPT_CALLBACK(0, "control", &stat_config, "fd:ctl-fd[,ack-fd] or fifo:ctl-fifo[,ack-fifo]", in cmd_stat()
2588 …"Listen on ctl-fd descriptor for command to control measurement ('enable': enable events, 'disable… in cmd_stat()
2589 "\t\t\t Optionally send control command completion ('ack\\n') to ack-fd descriptor.\n" in cmd_stat()
2590 "\t\t\t Alternatively, ctl-fifo / ack-fifo will be opened and used as ctl-fd / ack-fd.", in cmd_stat()
2601 int status = -EINVAL, run_idx, err; in cmd_stat()
2613 return -ENOMEM; in cmd_stat()
2617 /* String-parsing callback-based options would segfault when negated */ in cmd_stat()
2638 return -1; in cmd_stat()
2646 * For record command the -o is already taken care of. in cmd_stat()
2648 if (!STAT_RECORD && output_name && strcmp(output_name, "-")) in cmd_stat()
2652 fprintf(stderr, "cannot use both --output and --log-fd\n"); in cmd_stat()
2654 parse_options_usage(NULL, stat_options, "log-fd", 0); in cmd_stat()
2659 fprintf(stderr, "--metric-only is not supported with --per-thread\n"); in cmd_stat()
2664 fprintf(stderr, "--metric-only is not supported with -r\n"); in cmd_stat()
2670 * Current CSV and metric-only JSON output doesn't display the in cmd_stat()
2677 fprintf(stderr, "--table is only supported with -r\n"); in cmd_stat()
2684 fprintf(stderr, "argument to --log-fd must be a > 0\n"); in cmd_stat()
2685 parse_options_usage(stat_usage, stat_options, "log-fd", 0); in cmd_stat()
2696 return -1; in cmd_stat()
2707 return -errno; in cmd_stat()
2712 fprintf(stderr, "--interval-clear does not work with output\n"); in cmd_stat()
2714 parse_options_usage(NULL, stat_options, "log-fd", 0); in cmd_stat()
2715 parse_options_usage(NULL, stat_options, "interval-clear", 0); in cmd_stat()
2716 return -1; in cmd_stat()
2722 * let the spreadsheet do the pretty-printing in cmd_stat()
2725 /* User explicitly passed -B? */ in cmd_stat()
2727 fprintf(stderr, "-B option not supported with -x\n"); in cmd_stat()
2733 } else if (big_num_opt == 0) /* User passed --no-big-num */ in cmd_stat()
2764 pr_err("failed to setup -r option"); in cmd_stat()
2772 fprintf(stderr, "The --per-thread option is only " in cmd_stat()
2773 "available when monitoring via -p -t -a " in cmd_stat()
2774 "options or only --per-thread.\n"); in cmd_stat()
2782 * no_aggr, cgroup are for system-wide only in cmd_stat()
2783 * --per-thread is aggregated per thread, we dont mix it with cpu mode in cmd_stat()
2789 fprintf(stderr, "both cgroup and no-aggregation " in cmd_stat()
2790 "modes only available in system-wide mode\n"); in cmd_stat()
2795 parse_options_usage(NULL, stat_options, "for-each-cgroup", 0); in cmd_stat()
2819 status = -ENOMEM; in cmd_stat()
2826 * knowing the target is system-wide. in cmd_stat()
2850 pr_err("--cgroup and --for-each-cgroup cannot be used together\n"); in cmd_stat()
2852 parse_options_usage(NULL, stat_options, "for-each-cgroup", 0); in cmd_stat()
2858 "for-each-cgroup", 0); in cmd_stat()
2864 (evsel_list->core.nr_entries / nr_cgroups) > BPERF_CGROUP__MAX_EVENTS) { in cmd_stat()
2866 evsel_list->core.nr_entries / nr_cgroups, BPERF_CGROUP__MAX_EVENTS); in cmd_stat()
2874 * Setup BPF counters to require CPUs as any(-1) isn't in cmd_stat()
2880 if ((counter->bpf_counter || target.use_bpf) && !target__has_cpu(&target)) in cmd_stat()
2881 counter->core.requires_cpu = true; in cmd_stat()
2904 thread_map__read_comms(evsel_list->core.threads); in cmd_stat()
2913 pr_err("interval-count option should be used together with " in cmd_stat()
2914 "interval-print.\n"); in cmd_stat()
2915 parse_options_usage(stat_usage, stat_options, "interval-count", 0); in cmd_stat()
2931 pr_err("timeout option is not supported with interval-print.\n"); in cmd_stat()
2949 * by attr->sample_type != 0, and we can't run it on in cmd_stat()
2955 * We dont want to block the signals - that would cause in cmd_stat()
2956 * child tasks to inherit that and Ctrl-C would not work. in cmd_stat()
2957 * What we want is for Ctrl-C to work in the exec()-ed in cmd_stat()
2970 /* Enable ignoring missing threads when -p option is defined. */ in cmd_stat()
2971 evlist__first(evsel_list)->ignore_missing_thread = target.pid; in cmd_stat()
2991 if (!forever && status != -1 && (!interval || stat_config.summary)) { in cmd_stat()
3010 * tools remain -acme in cmd_stat()
3016 &perf_stat.session->machines.host); in cmd_stat()
3023 if (WRITE_STAT_ROUND_EVENT(stat_config.walltime_nsecs_stats->max, FINAL)) in cmd_stat()
3028 perf_stat.session->header.data_size += perf_stat.bytes_written; in cmd_stat()