Lines Matching refs:pmu

115 static int pmu_aliases_parse(struct perf_pmu *pmu);
158 static void perf_pmu_format__load(struct perf_pmu *pmu, struct perf_pmu_format *format) in perf_pmu_format__load() argument
166 if (!perf_pmu__pathname_scnprintf(path, sizeof(path), pmu->name, "format")) in perf_pmu_format__load()
184 int perf_pmu__format_parse(struct perf_pmu *pmu, int dirfd, bool eager_load) in perf_pmu__format_parse() argument
201 format = perf_pmu__new_format(&pmu->format, name); in perf_pmu__format_parse()
234 static int pmu_format(struct perf_pmu *pmu, int dirfd, const char *name) in pmu_format() argument
243 if (perf_pmu__format_parse(pmu, fd, /*eager_load=*/false)) in pmu_format()
286 static int perf_pmu__parse_scale(struct perf_pmu *pmu, struct perf_pmu_alias *alias) in perf_pmu__parse_scale() argument
298 scnprintf(path + len, sizeof(path) - len, "%s/events/%s.scale", pmu->name, alias->name); in perf_pmu__parse_scale()
322 static int perf_pmu__parse_unit(struct perf_pmu *pmu, struct perf_pmu_alias *alias) in perf_pmu__parse_unit() argument
333 scnprintf(path + len, sizeof(path) - len, "%s/events/%s.unit", pmu->name, alias->name); in perf_pmu__parse_unit()
358 perf_pmu__parse_per_pkg(struct perf_pmu *pmu, struct perf_pmu_alias *alias) in perf_pmu__parse_per_pkg() argument
367 scnprintf(path + len, sizeof(path) - len, "%s/events/%s.per-pkg", pmu->name, alias->name); in perf_pmu__parse_per_pkg()
379 static int perf_pmu__parse_snapshot(struct perf_pmu *pmu, struct perf_pmu_alias *alias) in perf_pmu__parse_snapshot() argument
388 scnprintf(path + len, sizeof(path) - len, "%s/events/%s.snapshot", pmu->name, alias->name); in perf_pmu__parse_snapshot()
411 static void perf_pmu__del_aliases(struct perf_pmu *pmu) in perf_pmu__del_aliases() argument
415 list_for_each_entry_safe(alias, tmp, &pmu->aliases, list) { in perf_pmu__del_aliases()
421 static struct perf_pmu_alias *perf_pmu__find_alias(struct perf_pmu *pmu, in perf_pmu__find_alias() argument
427 if (load && !pmu->sysfs_aliases_loaded) in perf_pmu__find_alias()
428 pmu_aliases_parse(pmu); in perf_pmu__find_alias()
430 list_for_each_entry(alias, &pmu->aliases, list) { in perf_pmu__find_alias()
455 static void read_alias_info(struct perf_pmu *pmu, struct perf_pmu_alias *alias) in read_alias_info() argument
463 perf_pmu__parse_unit(pmu, alias); in read_alias_info()
464 perf_pmu__parse_scale(pmu, alias); in read_alias_info()
465 perf_pmu__parse_per_pkg(pmu, alias); in read_alias_info()
466 perf_pmu__parse_snapshot(pmu, alias); in read_alias_info()
470 struct perf_pmu *pmu; member
481 read_alias_info(data->pmu, data->alias); in update_alias()
500 static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name, in perf_pmu__new_alias() argument
509 if (perf_pmu__find_alias(pmu, name, /*load=*/ false)) { in perf_pmu__new_alias()
520 pmu_name = pe->pmu; in perf_pmu__new_alias()
557 .pmu = pmu, in perf_pmu__new_alias()
562 if (pmu->events_table) { in perf_pmu__new_alias()
563 if (pmu_events_table__find_event(pmu->events_table, pmu, name, in perf_pmu__new_alias()
565 pmu->loaded_json_aliases++; in perf_pmu__new_alias()
570 pmu->sysfs_aliases++; in perf_pmu__new_alias()
572 pmu->loaded_json_aliases++; in perf_pmu__new_alias()
573 list_add_tail(&alias->list, &pmu->aliases); in perf_pmu__new_alias()
598 static int pmu_aliases_parse(struct perf_pmu *pmu) in pmu_aliases_parse() argument
609 scnprintf(path + len, sizeof(path) - len, "%s/events", pmu->name); in pmu_aliases_parse()
613 pmu->sysfs_aliases_loaded = true; in pmu_aliases_parse()
647 if (perf_pmu__new_alias(pmu, name, /*desc=*/ NULL, in pmu_aliases_parse()
655 pmu->sysfs_aliases_loaded = true; in pmu_aliases_parse()
697 struct perf_pmu pmu = {.name = pmu_name}; in pmu_cpumask() local
702 file = perf_pmu__open_file_at(&pmu, dirfd, *template); in pmu_cpumask()
758 char *perf_pmu__getcpuid(struct perf_pmu *pmu) in perf_pmu__getcpuid() argument
767 cpuid = get_cpuid_str(pmu); in perf_pmu__getcpuid()
881 struct perf_pmu *pmu = vdata; in pmu_add_cpu_aliases_map_callback() local
883 perf_pmu__new_alias(pmu, pe->name, pe->desc, pe->event, /*val_fd=*/ NULL, pe); in pmu_add_cpu_aliases_map_callback()
891 void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, const struct pmu_events_table *table) in pmu_add_cpu_aliases_table() argument
893 pmu_events_table__for_each_event(table, pmu, pmu_add_cpu_aliases_map_callback, pmu); in pmu_add_cpu_aliases_table()
896 static void pmu_add_cpu_aliases(struct perf_pmu *pmu) in pmu_add_cpu_aliases() argument
898 if (!pmu->events_table) in pmu_add_cpu_aliases()
901 if (pmu->cpu_aliases_added) in pmu_add_cpu_aliases()
904 pmu_add_cpu_aliases_table(pmu, pmu->events_table); in pmu_add_cpu_aliases()
905 pmu->cpu_aliases_added = true; in pmu_add_cpu_aliases()
912 struct perf_pmu *pmu = vdata; in pmu_add_sys_aliases_iter_fn() local
914 if (!pe->compat || !pe->pmu) in pmu_add_sys_aliases_iter_fn()
917 if (!strcmp(pmu->id, pe->compat) && in pmu_add_sys_aliases_iter_fn()
918 pmu_uncore_alias_match(pe->pmu, pmu->name)) { in pmu_add_sys_aliases_iter_fn()
919 perf_pmu__new_alias(pmu, in pmu_add_sys_aliases_iter_fn()
930 void pmu_add_sys_aliases(struct perf_pmu *pmu) in pmu_add_sys_aliases() argument
932 if (!pmu->id) in pmu_add_sys_aliases()
935 pmu_for_each_sys_event(pmu_add_sys_aliases_iter_fn, pmu); in pmu_add_sys_aliases()
939 perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused) in perf_pmu__get_default_config()
956 static int pmu_max_precise(int dirfd, struct perf_pmu *pmu) in pmu_max_precise() argument
960 perf_pmu__scan_file_at(pmu, dirfd, "caps/max_precise", "%d", &max_precise); in pmu_max_precise()
966 struct perf_pmu *pmu; in perf_pmu__lookup() local
971 pmu = zalloc(sizeof(*pmu)); in perf_pmu__lookup()
972 if (!pmu) in perf_pmu__lookup()
975 pmu->name = strdup(name); in perf_pmu__lookup()
976 if (!pmu->name) in perf_pmu__lookup()
983 if (perf_pmu__scan_file_at(pmu, dirfd, "type", "%u", &type) != 1) in perf_pmu__lookup()
986 INIT_LIST_HEAD(&pmu->format); in perf_pmu__lookup()
987 INIT_LIST_HEAD(&pmu->aliases); in perf_pmu__lookup()
988 INIT_LIST_HEAD(&pmu->caps); in perf_pmu__lookup()
995 if (pmu_format(pmu, dirfd, name)) { in perf_pmu__lookup()
996 free(pmu); in perf_pmu__lookup()
999 pmu->is_core = is_pmu_core(name); in perf_pmu__lookup()
1000 pmu->cpus = pmu_cpumask(dirfd, name, pmu->is_core); in perf_pmu__lookup()
1004 pmu->alias_name = strdup(alias_name); in perf_pmu__lookup()
1005 if (!pmu->alias_name) in perf_pmu__lookup()
1009 pmu->type = type; in perf_pmu__lookup()
1010 pmu->is_uncore = pmu_is_uncore(dirfd, name); in perf_pmu__lookup()
1011 if (pmu->is_uncore) in perf_pmu__lookup()
1012 pmu->id = pmu_id(name); in perf_pmu__lookup()
1013 pmu->max_precise = pmu_max_precise(dirfd, pmu); in perf_pmu__lookup()
1014 pmu->events_table = perf_pmu__find_events_table(pmu); in perf_pmu__lookup()
1015 pmu_add_sys_aliases(pmu); in perf_pmu__lookup()
1016 list_add_tail(&pmu->list, pmus); in perf_pmu__lookup()
1018 pmu->default_config = perf_pmu__get_default_config(pmu); in perf_pmu__lookup()
1020 return pmu; in perf_pmu__lookup()
1022 zfree(&pmu->name); in perf_pmu__lookup()
1023 free(pmu); in perf_pmu__lookup()
1030 struct perf_pmu *pmu = zalloc(sizeof(*pmu)); in perf_pmu__create_placeholder_core_pmu() local
1032 if (!pmu) in perf_pmu__create_placeholder_core_pmu()
1035 pmu->name = strdup("cpu"); in perf_pmu__create_placeholder_core_pmu()
1036 if (!pmu->name) { in perf_pmu__create_placeholder_core_pmu()
1037 free(pmu); in perf_pmu__create_placeholder_core_pmu()
1041 pmu->is_core = true; in perf_pmu__create_placeholder_core_pmu()
1042 pmu->type = PERF_TYPE_RAW; in perf_pmu__create_placeholder_core_pmu()
1043 pmu->cpus = cpu_map__online(); in perf_pmu__create_placeholder_core_pmu()
1045 INIT_LIST_HEAD(&pmu->format); in perf_pmu__create_placeholder_core_pmu()
1046 INIT_LIST_HEAD(&pmu->aliases); in perf_pmu__create_placeholder_core_pmu()
1047 INIT_LIST_HEAD(&pmu->caps); in perf_pmu__create_placeholder_core_pmu()
1048 list_add_tail(&pmu->list, core_pmus); in perf_pmu__create_placeholder_core_pmu()
1049 return pmu; in perf_pmu__create_placeholder_core_pmu()
1052 void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu) in perf_pmu__warn_invalid_formats() argument
1056 if (pmu->formats_checked) in perf_pmu__warn_invalid_formats()
1059 pmu->formats_checked = true; in perf_pmu__warn_invalid_formats()
1062 if (pmu == &perf_pmu__fake) in perf_pmu__warn_invalid_formats()
1065 list_for_each_entry(format, &pmu->format, list) { in perf_pmu__warn_invalid_formats()
1066 perf_pmu_format__load(pmu, format); in perf_pmu__warn_invalid_formats()
1070 pmu->name, format->name, format->value); in perf_pmu__warn_invalid_formats()
1078 struct perf_pmu *pmu = evsel__find_pmu(evsel); in evsel__is_aux_event() local
1080 return pmu && pmu->auxtrace; in evsel__is_aux_event()
1092 void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel, in evsel__set_config_if_unset() argument
1101 bits = perf_pmu__format_bits(pmu, config_name); in evsel__set_config_if_unset()
1124 __u64 perf_pmu__format_bits(struct perf_pmu *pmu, const char *name) in perf_pmu__format_bits() argument
1126 struct perf_pmu_format *format = pmu_find_format(&pmu->format, name); in perf_pmu__format_bits()
1139 int perf_pmu__format_type(struct perf_pmu *pmu, const char *name) in perf_pmu__format_type() argument
1141 struct perf_pmu_format *format = pmu_find_format(&pmu->format, name); in perf_pmu__format_type()
1146 perf_pmu_format__load(pmu, format); in perf_pmu__format_type()
1237 static int pmu_config_term(struct perf_pmu *pmu, in pmu_config_term() argument
1261 format = pmu_find_format(&pmu->format, term->config); in pmu_config_term()
1263 char *pmu_term = pmu_formats_string(&pmu->format); in pmu_config_term()
1269 term->config, pmu->name) < 0) in pmu_config_term()
1283 perf_pmu_format__load(pmu, format); in pmu_config_term()
1360 int perf_pmu__config_terms(struct perf_pmu *pmu, in perf_pmu__config_terms() argument
1368 if (pmu_config_term(pmu, attr, term, head_terms, zero, err)) in perf_pmu__config_terms()
1380 int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, in perf_pmu__config() argument
1384 bool zero = !!pmu->default_config; in perf_pmu__config()
1386 return perf_pmu__config_terms(pmu, attr, head_terms, zero, err); in perf_pmu__config()
1389 static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu, in pmu_find_alias() argument
1401 if (pmu_find_format(&pmu->format, term->config)) in pmu_find_alias()
1413 alias = perf_pmu__find_alias(pmu, name, /*load=*/ true); in pmu_find_alias()
1414 if (alias || pmu->cpu_aliases_added) in pmu_find_alias()
1418 if (pmu->events_table && in pmu_find_alias()
1419 pmu_events_table__find_event(pmu->events_table, pmu, name, in pmu_find_alias()
1421 pmu) == 0) { in pmu_find_alias()
1422 alias = perf_pmu__find_alias(pmu, name, /*load=*/ false); in pmu_find_alias()
1428 static int check_info_data(struct perf_pmu *pmu, in check_info_data() argument
1434 read_alias_info(pmu, alias); in check_info_data()
1475 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, in perf_pmu__check_alias() argument
1493 alias = pmu_find_alias(pmu, term); in perf_pmu__check_alias()
1504 ret = check_info_data(pmu, alias, info, err, term->err_term); in perf_pmu__check_alias()
1545 int perf_pmu__find_event(struct perf_pmu *pmu, const char *event, void *state, pmu_event_callback c… in perf_pmu__find_event() argument
1554 return perf_pmu__for_each_event(pmu, /*skip_duplicate_pmus=*/ false, in perf_pmu__find_event()
1569 bool perf_pmu__has_format(const struct perf_pmu *pmu, const char *name) in perf_pmu__has_format() argument
1573 list_for_each_entry(format, &pmu->format, list) { in perf_pmu__has_format()
1585 bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu) in perf_pmu__supports_legacy_cache() argument
1587 return pmu->is_core; in perf_pmu__supports_legacy_cache()
1590 bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu) in perf_pmu__auto_merge_stats() argument
1592 return !pmu->is_core || perf_pmus__num_core_pmus() == 1; in perf_pmu__auto_merge_stats()
1595 bool perf_pmu__have_event(struct perf_pmu *pmu, const char *name) in perf_pmu__have_event() argument
1597 if (perf_pmu__find_alias(pmu, name, /*load=*/ true) != NULL) in perf_pmu__have_event()
1599 if (pmu->cpu_aliases_added || !pmu->events_table) in perf_pmu__have_event()
1601 return pmu_events_table__find_event(pmu->events_table, pmu, name, NULL, NULL) == 0; in perf_pmu__have_event()
1604 size_t perf_pmu__num_events(struct perf_pmu *pmu) in perf_pmu__num_events() argument
1608 if (!pmu->sysfs_aliases_loaded) in perf_pmu__num_events()
1609 pmu_aliases_parse(pmu); in perf_pmu__num_events()
1611 nr = pmu->sysfs_aliases; in perf_pmu__num_events()
1613 if (pmu->cpu_aliases_added) in perf_pmu__num_events()
1614 nr += pmu->loaded_json_aliases; in perf_pmu__num_events()
1615 else if (pmu->events_table) in perf_pmu__num_events()
1616 nr += pmu_events_table__num_events(pmu->events_table, pmu) - pmu->loaded_json_aliases; in perf_pmu__num_events()
1618 return pmu->selectable ? nr + 1 : nr; in perf_pmu__num_events()
1628 static char *format_alias(char *buf, int len, const struct perf_pmu *pmu, in format_alias() argument
1633 ? pmu_name_len_no_suffix(pmu->name, /*num=*/NULL) in format_alias()
1634 : (int)strlen(pmu->name); in format_alias()
1635 int used = snprintf(buf, len, "%.*s/%s", pmu_name_len, pmu->name, alias->name); in format_alias()
1657 int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus, in perf_pmu__for_each_event() argument
1663 .pmu = pmu, in perf_pmu__for_each_event()
1669 pmu_add_cpu_aliases(pmu); in perf_pmu__for_each_event()
1670 list_for_each_entry(event, &pmu->aliases, list) { in perf_pmu__for_each_event()
1673 info.pmu_name = event->pmu_name ?: pmu->name; in perf_pmu__for_each_event()
1679 info.name = format_alias(buf, sizeof(buf), pmu, event, in perf_pmu__for_each_event()
1681 if (pmu->is_core) { in perf_pmu__for_each_event()
1707 if (pmu->selectable) { in perf_pmu__for_each_event()
1709 snprintf(buf, sizeof(buf), "%s//", pmu->name); in perf_pmu__for_each_event()
1716 info.pmu_name = pmu->name; in perf_pmu__for_each_event()
1725 bool pmu__name_match(const struct perf_pmu *pmu, const char *pmu_name) in pmu__name_match() argument
1727 return !strcmp(pmu->name, pmu_name) || in pmu__name_match()
1728 (pmu->is_uncore && pmu_uncore_alias_match(pmu_name, pmu->name)) || in pmu__name_match()
1733 (pmu->is_core && !strcmp(pmu_name, "default_core")); in pmu__name_match()
1736 bool perf_pmu__is_software(const struct perf_pmu *pmu) in perf_pmu__is_software() argument
1738 if (pmu->is_core || pmu->is_uncore || pmu->auxtrace) in perf_pmu__is_software()
1740 switch (pmu->type) { in perf_pmu__is_software()
1749 return !strcmp(pmu->name, "kprobe") || !strcmp(pmu->name, "uprobe"); in perf_pmu__is_software()
1752 FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name) in perf_pmu__open_file() argument
1756 if (!perf_pmu__pathname_scnprintf(path, sizeof(path), pmu->name, name) || in perf_pmu__open_file()
1763 FILE *perf_pmu__open_file_at(struct perf_pmu *pmu, int dirfd, const char *name) in perf_pmu__open_file_at() argument
1767 fd = perf_pmu__pathname_fd(dirfd, pmu->name, name, O_RDONLY); in perf_pmu__open_file_at()
1774 int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, in perf_pmu__scan_file() argument
1782 file = perf_pmu__open_file(pmu, name); in perf_pmu__scan_file()
1791 int perf_pmu__scan_file_at(struct perf_pmu *pmu, int dirfd, const char *name, in perf_pmu__scan_file_at() argument
1799 file = perf_pmu__open_file_at(pmu, dirfd, name); in perf_pmu__scan_file_at()
1808 bool perf_pmu__file_exists(struct perf_pmu *pmu, const char *name) in perf_pmu__file_exists() argument
1812 if (!perf_pmu__pathname_scnprintf(path, sizeof(path), pmu->name, name)) in perf_pmu__file_exists()
1842 static void perf_pmu__del_caps(struct perf_pmu *pmu) in perf_pmu__del_caps() argument
1846 list_for_each_entry_safe(caps, tmp, &pmu->caps, list) { in perf_pmu__del_caps()
1859 int perf_pmu__caps_parse(struct perf_pmu *pmu) in perf_pmu__caps_parse() argument
1867 if (pmu->caps_initialized) in perf_pmu__caps_parse()
1868 return pmu->nr_caps; in perf_pmu__caps_parse()
1870 pmu->nr_caps = 0; in perf_pmu__caps_parse()
1872 if (!perf_pmu__pathname_scnprintf(caps_path, sizeof(caps_path), pmu->name, "caps")) in perf_pmu__caps_parse()
1876 pmu->caps_initialized = true; in perf_pmu__caps_parse()
1905 (perf_pmu__new_caps(&pmu->caps, name, value) < 0)) { in perf_pmu__caps_parse()
1910 pmu->nr_caps++; in perf_pmu__caps_parse()
1916 pmu->caps_initialized = true; in perf_pmu__caps_parse()
1917 return pmu->nr_caps; in perf_pmu__caps_parse()
1920 static void perf_pmu__compute_config_masks(struct perf_pmu *pmu) in perf_pmu__compute_config_masks() argument
1924 if (pmu->config_masks_computed) in perf_pmu__compute_config_masks()
1927 list_for_each_entry(format, &pmu->format, list) { in perf_pmu__compute_config_masks()
1934 pmu->config_masks_present = true; in perf_pmu__compute_config_masks()
1935 mask = &pmu->config_masks[format->value]; in perf_pmu__compute_config_masks()
1940 pmu->config_masks_computed = true; in perf_pmu__compute_config_masks()
1943 void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, in perf_pmu__warn_invalid_config() argument
1950 perf_pmu__compute_config_masks(pmu); in perf_pmu__warn_invalid_config()
1955 if (!pmu->config_masks_present) in perf_pmu__warn_invalid_config()
1958 bits = config & ~pmu->config_masks[config_num]; in perf_pmu__warn_invalid_config()
2038 void perf_pmu__delete(struct perf_pmu *pmu) in perf_pmu__delete() argument
2040 perf_pmu__del_formats(&pmu->format); in perf_pmu__delete()
2041 perf_pmu__del_aliases(pmu); in perf_pmu__delete()
2042 perf_pmu__del_caps(pmu); in perf_pmu__delete()
2044 perf_cpu_map__put(pmu->cpus); in perf_pmu__delete()
2046 zfree(&pmu->default_config); in perf_pmu__delete()
2047 zfree(&pmu->name); in perf_pmu__delete()
2048 zfree(&pmu->alias_name); in perf_pmu__delete()
2049 zfree(&pmu->id); in perf_pmu__delete()
2050 free(pmu); in perf_pmu__delete()
2055 struct perf_pmu *pmu = NULL; in pmu__find_core_pmu() local
2057 while ((pmu = perf_pmus__scan_core(pmu))) { in pmu__find_core_pmu()
2062 if (RC_CHK_ACCESS(pmu->cpus)->nr != cpu__max_cpu().cpu) in pmu__find_core_pmu()
2065 return pmu; in pmu__find_core_pmu()