1 #include <linux/list.h>
2 #include <linux/compiler.h>
13 #include "parse-events.h"
16 #include "pmu-events/pmu-events.h"
19 struct perf_pmu_format {
22 DECLARE_BITMAP(bits, PERF_PMU_FORMAT_BITS);
23 struct list_head list;
26 #define EVENT_SOURCE_DEVICE_PATH "/bus/event_source/devices/"
28 int perf_pmu_parse(struct list_head *list, char *name);
29 extern FILE *perf_pmu_in;
31 static LIST_HEAD(pmus);
34 * Parse & process all the sysfs attributes located under
35 * the directory specified in 'dir' parameter.
37 int perf_pmu__format_parse(char *dir, struct list_head *head)
39 struct dirent *evt_ent;
43 format_dir = opendir(dir);
47 while (!ret && (evt_ent = readdir(format_dir))) {
49 char *name = evt_ent->d_name;
52 if (!strcmp(name, ".") || !strcmp(name, ".."))
55 snprintf(path, PATH_MAX, "%s/%s", dir, name);
58 file = fopen(path, "r");
63 ret = perf_pmu_parse(head, name);
72 * Reading/parsing the default pmu format definition, which should be
74 * /sys/bus/event_source/devices/<dev>/format as sysfs group attributes.
76 static int pmu_format(const char *name, struct list_head *format)
80 const char *sysfs = sysfs__mountpoint();
85 snprintf(path, PATH_MAX,
86 "%s" EVENT_SOURCE_DEVICE_PATH "%s/format", sysfs, name);
88 if (stat(path, &st) < 0)
89 return 0; /* no error if format does not exist */
91 if (perf_pmu__format_parse(path, format))
97 static int convert_scale(const char *scale, char **end, double *sval)
103 * save current locale
105 lc = setlocale(LC_NUMERIC, NULL);
108 * The lc string may be allocated in static storage,
109 * so get a dynamic copy to make it survive setlocale
119 * force to C locale to ensure kernel
120 * scale string is converted correctly.
121 * kernel uses default C locale.
123 setlocale(LC_NUMERIC, "C");
125 *sval = strtod(scale, end);
129 setlocale(LC_NUMERIC, lc);
134 static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *name)
142 snprintf(path, PATH_MAX, "%s/%s.scale", dir, name);
144 fd = open(path, O_RDONLY);
148 if (fstat(fd, &st) < 0)
151 sret = read(fd, scale, sizeof(scale)-1);
155 if (scale[sret - 1] == '\n')
156 scale[sret - 1] = '\0';
160 ret = convert_scale(scale, NULL, &alias->scale);
166 static int perf_pmu__parse_unit(struct perf_pmu_alias *alias, char *dir, char *name)
172 snprintf(path, PATH_MAX, "%s/%s.unit", dir, name);
174 fd = open(path, O_RDONLY);
178 sret = read(fd, alias->unit, UNIT_MAX_LEN);
184 if (alias->unit[sret - 1] == '\n')
185 alias->unit[sret - 1] = '\0';
187 alias->unit[sret] = '\0';
192 alias->unit[0] = '\0';
197 perf_pmu__parse_per_pkg(struct perf_pmu_alias *alias, char *dir, char *name)
202 snprintf(path, PATH_MAX, "%s/%s.per-pkg", dir, name);
204 fd = open(path, O_RDONLY);
210 alias->per_pkg = true;
214 static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias,
215 char *dir, char *name)
220 snprintf(path, PATH_MAX, "%s/%s.snapshot", dir, name);
222 fd = open(path, O_RDONLY);
226 alias->snapshot = true;
231 static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
232 char *desc, char *val,
233 char *long_desc, char *topic,
234 char *unit, char *perpkg)
236 struct perf_pmu_alias *alias;
240 alias = malloc(sizeof(*alias));
244 INIT_LIST_HEAD(&alias->terms);
246 alias->unit[0] = '\0';
247 alias->per_pkg = false;
248 alias->snapshot = false;
250 ret = parse_events_terms(&alias->terms, val);
252 pr_err("Cannot parse alias %s: %d\n", val, ret);
257 alias->name = strdup(name);
260 * load unit name and scale if available
262 perf_pmu__parse_unit(alias, dir, name);
263 perf_pmu__parse_scale(alias, dir, name);
264 perf_pmu__parse_per_pkg(alias, dir, name);
265 perf_pmu__parse_snapshot(alias, dir, name);
268 alias->desc = desc ? strdup(desc) : NULL;
269 alias->long_desc = long_desc ? strdup(long_desc) :
270 desc ? strdup(desc) : NULL;
271 alias->topic = topic ? strdup(topic) : NULL;
273 if (convert_scale(unit, &unit, &alias->scale) < 0)
275 snprintf(alias->unit, sizeof(alias->unit), "%s", unit);
277 alias->per_pkg = perpkg && sscanf(perpkg, "%d", &num) == 1 && num == 1;
278 list_add_tail(&alias->list, list);
283 static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file)
288 ret = fread(buf, 1, sizeof(buf), file);
294 return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL,
298 static inline bool pmu_alias_info_file(char *name)
303 if (len > 5 && !strcmp(name + len - 5, ".unit"))
305 if (len > 6 && !strcmp(name + len - 6, ".scale"))
307 if (len > 8 && !strcmp(name + len - 8, ".per-pkg"))
309 if (len > 9 && !strcmp(name + len - 9, ".snapshot"))
316 * Process all the sysfs attributes located under the directory
317 * specified in 'dir' parameter.
319 static int pmu_aliases_parse(char *dir, struct list_head *head)
321 struct dirent *evt_ent;
324 event_dir = opendir(dir);
328 while ((evt_ent = readdir(event_dir))) {
330 char *name = evt_ent->d_name;
333 if (!strcmp(name, ".") || !strcmp(name, ".."))
337 * skip info files parsed in perf_pmu__new_alias()
339 if (pmu_alias_info_file(name))
342 snprintf(path, PATH_MAX, "%s/%s", dir, name);
344 file = fopen(path, "r");
346 pr_debug("Cannot open %s\n", path);
350 if (perf_pmu__new_alias(head, dir, name, file) < 0)
351 pr_debug("Cannot set up %s\n", name);
360 * Reading the pmu event aliases definition, which should be located at:
361 * /sys/bus/event_source/devices/<dev>/events as sysfs group attributes.
363 static int pmu_aliases(const char *name, struct list_head *head)
367 const char *sysfs = sysfs__mountpoint();
372 snprintf(path, PATH_MAX,
373 "%s/bus/event_source/devices/%s/events", sysfs, name);
375 if (stat(path, &st) < 0)
376 return 0; /* no error if 'events' does not exist */
378 if (pmu_aliases_parse(path, head))
384 static int pmu_alias_terms(struct perf_pmu_alias *alias,
385 struct list_head *terms)
387 struct parse_events_term *term, *cloned;
391 list_for_each_entry(term, &alias->terms, list) {
392 ret = parse_events_term__clone(&cloned, term);
394 parse_events_terms__purge(&list);
397 list_add_tail(&cloned->list, &list);
399 list_splice(&list, terms);
404 * Reading/parsing the default pmu type value, which should be
406 * /sys/bus/event_source/devices/<dev>/type as sysfs attribute.
408 static int pmu_type(const char *name, __u32 *type)
414 const char *sysfs = sysfs__mountpoint();
419 snprintf(path, PATH_MAX,
420 "%s" EVENT_SOURCE_DEVICE_PATH "%s/type", sysfs, name);
422 if (stat(path, &st) < 0)
425 file = fopen(path, "r");
429 if (1 != fscanf(file, "%u", type))
436 /* Add all pmus in sysfs to pmu list: */
437 static void pmu_read_sysfs(void)
442 const char *sysfs = sysfs__mountpoint();
447 snprintf(path, PATH_MAX,
448 "%s" EVENT_SOURCE_DEVICE_PATH, sysfs);
454 while ((dent = readdir(dir))) {
455 if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
457 /* add to static LIST_HEAD(pmus): */
458 perf_pmu__find(dent->d_name);
464 static struct cpu_map *pmu_cpumask(const char *name)
469 struct cpu_map *cpus;
470 const char *sysfs = sysfs__mountpoint();
471 const char *templates[] = {
472 "%s/bus/event_source/devices/%s/cpumask",
473 "%s/bus/event_source/devices/%s/cpus",
476 const char **template;
481 for (template = templates; *template; template++) {
482 snprintf(path, PATH_MAX, *template, sysfs, name);
483 if (stat(path, &st) == 0)
490 file = fopen(path, "r");
494 cpus = cpu_map__read(file);
500 * Return the CPU id as a raw string.
502 * Each architecture should provide a more precise id string that
503 * can be use to match the architecture's "mapfile".
505 char * __weak get_cpuid_str(void)
511 * From the pmu_events_map, find the table of PMU events that corresponds
512 * to the current running CPU. Then, add all PMU events from that table
515 static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
518 struct pmu_events_map *map;
519 struct pmu_event *pe;
523 cpuid = getenv("PERF_CPUID");
525 cpuid = strdup(cpuid);
527 cpuid = get_cpuid_str();
532 pr_debug("Using CPUID %s\n", cpuid);
538 map = &pmu_events_map[i++];
542 if (!strcmp(map->cpuid, cpuid))
547 * Found a matching PMU events table. Create aliases
553 pe = &map->table[i++];
557 pname = pe->pmu ? pe->pmu : "cpu";
558 if (strncmp(pname, name, strlen(pname)))
561 /* need type casts to override 'const' */
562 __perf_pmu__new_alias(head, NULL, (char *)pe->name,
563 (char *)pe->desc, (char *)pe->event,
564 (char *)pe->long_desc, (char *)pe->topic,
565 (char *)pe->unit, (char *)pe->perpkg);
572 struct perf_event_attr * __weak
573 perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused)
578 static struct perf_pmu *pmu_lookup(const char *name)
580 struct perf_pmu *pmu;
586 * The pmu data we store & need consists of the pmu
587 * type value and format definitions. Load both right
590 if (pmu_format(name, &format))
594 * Check the type first to avoid unnecessary work.
596 if (pmu_type(name, &type))
599 if (pmu_aliases(name, &aliases))
602 pmu_add_cpu_aliases(&aliases, name);
603 pmu = zalloc(sizeof(*pmu));
607 pmu->cpus = pmu_cpumask(name);
609 INIT_LIST_HEAD(&pmu->format);
610 INIT_LIST_HEAD(&pmu->aliases);
611 list_splice(&format, &pmu->format);
612 list_splice(&aliases, &pmu->aliases);
613 pmu->name = strdup(name);
615 list_add_tail(&pmu->list, &pmus);
617 pmu->default_config = perf_pmu__get_default_config(pmu);
622 static struct perf_pmu *pmu_find(const char *name)
624 struct perf_pmu *pmu;
626 list_for_each_entry(pmu, &pmus, list)
627 if (!strcmp(pmu->name, name))
633 struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu)
636 * pmu iterator: If pmu is NULL, we start at the begin,
637 * otherwise return the next pmu. Returns NULL on end.
641 pmu = list_prepare_entry(pmu, &pmus, list);
643 list_for_each_entry_continue(pmu, &pmus, list)
648 struct perf_pmu *perf_pmu__find(const char *name)
650 struct perf_pmu *pmu;
653 * Once PMU is loaded it stays in the list,
654 * so we keep us from multiple reading/parsing
655 * the pmu format definitions.
657 pmu = pmu_find(name);
661 return pmu_lookup(name);
664 static struct perf_pmu_format *
665 pmu_find_format(struct list_head *formats, const char *name)
667 struct perf_pmu_format *format;
669 list_for_each_entry(format, formats, list)
670 if (!strcmp(format->name, name))
676 __u64 perf_pmu__format_bits(struct list_head *formats, const char *name)
678 struct perf_pmu_format *format = pmu_find_format(formats, name);
685 for_each_set_bit(fbit, format->bits, PERF_PMU_FORMAT_BITS)
686 bits |= 1ULL << fbit;
692 * Sets value based on the format definition (format parameter)
693 * and unformated value (value parameter).
695 static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
698 unsigned long fbit, vbit;
700 for (fbit = 0, vbit = 0; fbit < PERF_PMU_FORMAT_BITS; fbit++) {
702 if (!test_bit(fbit, format))
705 if (value & (1llu << vbit++))
706 *v |= (1llu << fbit);
708 *v &= ~(1llu << fbit);
712 static __u64 pmu_format_max_value(const unsigned long *format)
717 for_each_set_bit(fbit, format, PERF_PMU_FORMAT_BITS)
724 * Term is a string term, and might be a param-term. Try to look up it's value
725 * in the remaining terms.
726 * - We have a term like "base-or-format-term=param-term",
727 * - We need to find the value supplied for "param-term" (with param-term named
728 * in a config string) later on in the term list.
730 static int pmu_resolve_param_term(struct parse_events_term *term,
731 struct list_head *head_terms,
734 struct parse_events_term *t;
736 list_for_each_entry(t, head_terms, list) {
737 if (t->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
738 if (!strcmp(t->config, term->config)) {
747 printf("Required parameter '%s' not specified\n", term->config);
752 static char *pmu_formats_string(struct list_head *formats)
754 struct perf_pmu_format *format;
756 struct strbuf buf = STRBUF_INIT;
762 /* sysfs exported terms */
763 list_for_each_entry(format, formats, list)
764 if (strbuf_addf(&buf, i++ ? ",%s" : "%s", format->name) < 0)
767 str = strbuf_detach(&buf, NULL);
769 strbuf_release(&buf);
775 * Setup one of config[12] attr members based on the
776 * user input data - term parameter.
778 static int pmu_config_term(struct list_head *formats,
779 struct perf_event_attr *attr,
780 struct parse_events_term *term,
781 struct list_head *head_terms,
782 bool zero, struct parse_events_error *err)
784 struct perf_pmu_format *format;
789 * If this is a parameter we've already used for parameterized-eval,
790 * skip it in normal eval.
796 * Hardcoded terms should be already in, so nothing
797 * to be done for them.
799 if (parse_events__is_hardcoded_term(term))
802 format = pmu_find_format(formats, term->config);
805 printf("Invalid event/parameter '%s'\n", term->config);
807 char *pmu_term = pmu_formats_string(formats);
809 err->idx = term->err_term;
810 err->str = strdup("unknown term");
811 err->help = parse_events_formats_error_string(pmu_term);
817 switch (format->value) {
818 case PERF_PMU_FORMAT_VALUE_CONFIG:
821 case PERF_PMU_FORMAT_VALUE_CONFIG1:
824 case PERF_PMU_FORMAT_VALUE_CONFIG2:
832 * Either directly use a numeric term, or try to translate string terms
833 * using event parameters.
835 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM)
837 else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) {
838 if (strcmp(term->val.str, "?")) {
840 pr_info("Invalid sysfs entry %s=%s\n",
841 term->config, term->val.str);
844 err->idx = term->err_val;
845 err->str = strdup("expected numeric value");
850 if (pmu_resolve_param_term(term, head_terms, &val))
855 max_val = pmu_format_max_value(format->bits);
858 err->idx = term->err_val;
859 if (asprintf(&err->str,
860 "value too big for format, maximum is %llu",
861 (unsigned long long)max_val) < 0)
862 err->str = strdup("value too big for format");
866 * Assume we don't care if !err, in which case the value will be
867 * silently truncated.
871 pmu_format_value(format->bits, val, vp, zero);
875 int perf_pmu__config_terms(struct list_head *formats,
876 struct perf_event_attr *attr,
877 struct list_head *head_terms,
878 bool zero, struct parse_events_error *err)
880 struct parse_events_term *term;
882 list_for_each_entry(term, head_terms, list) {
883 if (pmu_config_term(formats, attr, term, head_terms,
892 * Configures event's 'attr' parameter based on the:
893 * 1) users input - specified in terms parameter
894 * 2) pmu format definitions - specified by pmu parameter
896 int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
897 struct list_head *head_terms,
898 struct parse_events_error *err)
900 bool zero = !!pmu->default_config;
902 attr->type = pmu->type;
903 return perf_pmu__config_terms(&pmu->format, attr, head_terms,
907 static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu,
908 struct parse_events_term *term)
910 struct perf_pmu_alias *alias;
913 if (parse_events__is_hardcoded_term(term))
916 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
917 if (term->val.num != 1)
919 if (pmu_find_format(&pmu->format, term->config))
922 } else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) {
923 if (strcasecmp(term->config, "event"))
925 name = term->val.str;
930 list_for_each_entry(alias, &pmu->aliases, list) {
931 if (!strcasecmp(alias->name, name))
938 static int check_info_data(struct perf_pmu_alias *alias,
939 struct perf_pmu_info *info)
942 * Only one term in event definition can
943 * define unit, scale and snapshot, fail
944 * if there's more than one.
946 if ((info->unit && alias->unit) ||
947 (info->scale && alias->scale) ||
948 (info->snapshot && alias->snapshot))
952 info->unit = alias->unit;
955 info->scale = alias->scale;
958 info->snapshot = alias->snapshot;
964 * Find alias in the terms list and replace it with the terms
965 * defined for the alias
967 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
968 struct perf_pmu_info *info)
970 struct parse_events_term *term, *h;
971 struct perf_pmu_alias *alias;
974 info->per_pkg = false;
977 * Mark unit and scale as not set
978 * (different from default values, see below)
982 info->snapshot = false;
984 list_for_each_entry_safe(term, h, head_terms, list) {
985 alias = pmu_find_alias(pmu, term);
988 ret = pmu_alias_terms(alias, &term->list);
992 ret = check_info_data(alias, info);
997 info->per_pkg = true;
999 list_del(&term->list);
1004 * if no unit or scale foundin aliases, then
1005 * set defaults as for evsel
1006 * unit cannot left to NULL
1008 if (info->unit == NULL)
1011 if (info->scale == 0.0)
1017 int perf_pmu__new_format(struct list_head *list, char *name,
1018 int config, unsigned long *bits)
1020 struct perf_pmu_format *format;
1022 format = zalloc(sizeof(*format));
1026 format->name = strdup(name);
1027 format->value = config;
1028 memcpy(format->bits, bits, sizeof(format->bits));
1030 list_add_tail(&format->list, list);
1034 void perf_pmu__set_format(unsigned long *bits, long from, long to)
1041 memset(bits, 0, BITS_TO_BYTES(PERF_PMU_FORMAT_BITS));
1042 for (b = from; b <= to; b++)
1046 static int sub_non_neg(int a, int b)
1053 static char *format_alias(char *buf, int len, struct perf_pmu *pmu,
1054 struct perf_pmu_alias *alias)
1056 struct parse_events_term *term;
1057 int used = snprintf(buf, len, "%s/%s", pmu->name, alias->name);
1059 list_for_each_entry(term, &alias->terms, list) {
1060 if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR)
1061 used += snprintf(buf + used, sub_non_neg(len, used),
1062 ",%s=%s", term->config,
1066 if (sub_non_neg(len, used) > 0) {
1070 if (sub_non_neg(len, used) > 0) {
1074 buf[len - 1] = '\0';
1079 static char *format_alias_or(char *buf, int len, struct perf_pmu *pmu,
1080 struct perf_pmu_alias *alias)
1082 snprintf(buf, len, "%s OR %s/%s/", alias->name, pmu->name, alias->name);
1092 static int cmp_sevent(const void *a, const void *b)
1094 const struct sevent *as = a;
1095 const struct sevent *bs = b;
1097 /* Put extra events last */
1098 if (!!as->desc != !!bs->desc)
1099 return !!as->desc - !!bs->desc;
1100 if (as->topic && bs->topic) {
1101 int n = strcmp(as->topic, bs->topic);
1106 return strcmp(as->name, bs->name);
1109 static void wordwrap(char *s, int start, int max, int corr)
1115 int wlen = strcspn(s, " \t");
1117 if (column + wlen >= max && column > start) {
1118 printf("\n%*s", start, "");
1119 column = start + corr;
1121 n = printf("%s%.*s", column > start ? " " : "", wlen, s);
1131 void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
1134 struct perf_pmu *pmu;
1135 struct perf_pmu_alias *alias;
1139 struct sevent *aliases;
1141 int columns = pager_get_columns();
1146 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1147 list_for_each_entry(alias, &pmu->aliases, list)
1149 if (pmu->selectable)
1152 aliases = zalloc(sizeof(struct sevent) * len);
1157 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1158 list_for_each_entry(alias, &pmu->aliases, list) {
1159 char *name = alias->desc ? alias->name :
1160 format_alias(buf, sizeof(buf), pmu, alias);
1161 bool is_cpu = !strcmp(pmu->name, "cpu");
1163 if (event_glob != NULL &&
1164 !(strglobmatch_nocase(name, event_glob) ||
1165 (!is_cpu && strglobmatch_nocase(alias->name,
1168 strglobmatch_nocase(alias->topic, event_glob))))
1171 if (is_cpu && !name_only && !alias->desc)
1172 name = format_alias_or(buf, sizeof(buf), pmu, alias);
1174 aliases[j].name = name;
1175 if (is_cpu && !name_only && !alias->desc)
1176 aliases[j].name = format_alias_or(buf,
1179 aliases[j].name = strdup(aliases[j].name);
1180 if (!aliases[j].name)
1183 aliases[j].desc = long_desc ? alias->long_desc :
1185 aliases[j].topic = alias->topic;
1188 if (pmu->selectable &&
1189 (event_glob == NULL || strglobmatch(pmu->name, event_glob))) {
1191 if (asprintf(&s, "%s//", pmu->name) < 0)
1193 aliases[j].name = s;
1198 qsort(aliases, len, sizeof(struct sevent), cmp_sevent);
1199 for (j = 0; j < len; j++) {
1200 /* Skip duplicates */
1201 if (j > 0 && !strcmp(aliases[j].name, aliases[j - 1].name))
1204 printf("%s ", aliases[j].name);
1207 if (aliases[j].desc && !quiet_flag) {
1210 if (aliases[j].topic && (!topic ||
1211 strcmp(topic, aliases[j].topic))) {
1212 printf("%s%s:\n", topic ? "\n" : "",
1214 topic = aliases[j].topic;
1216 printf(" %-50s\n", aliases[j].name);
1217 printf("%*s", 8, "[");
1218 wordwrap(aliases[j].desc, 8, columns, 0);
1221 printf(" %-50s [Kernel PMU event]\n", aliases[j].name);
1224 if (printed && pager_in_use())
1227 for (j = 0; j < len; j++)
1228 zfree(&aliases[j].name);
1233 printf("FATAL: not enough memory to print PMU events\n");
1238 bool pmu_have_event(const char *pname, const char *name)
1240 struct perf_pmu *pmu;
1241 struct perf_pmu_alias *alias;
1244 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1245 if (strcmp(pname, pmu->name))
1247 list_for_each_entry(alias, &pmu->aliases, list)
1248 if (!strcmp(alias->name, name))
1254 static FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name)
1257 char path[PATH_MAX];
1260 sysfs = sysfs__mountpoint();
1264 snprintf(path, PATH_MAX,
1265 "%s" EVENT_SOURCE_DEVICE_PATH "%s/%s", sysfs, pmu->name, name);
1267 if (stat(path, &st) < 0)
1270 return fopen(path, "r");
1273 int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
1280 va_start(args, fmt);
1281 file = perf_pmu__open_file(pmu, name);
1283 ret = vfscanf(file, fmt, args);