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 alias->str = strdup(val);
280 list_add_tail(&alias->list, list);
285 static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file)
290 ret = fread(buf, 1, sizeof(buf), file);
296 return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL,
300 static inline bool pmu_alias_info_file(char *name)
305 if (len > 5 && !strcmp(name + len - 5, ".unit"))
307 if (len > 6 && !strcmp(name + len - 6, ".scale"))
309 if (len > 8 && !strcmp(name + len - 8, ".per-pkg"))
311 if (len > 9 && !strcmp(name + len - 9, ".snapshot"))
318 * Process all the sysfs attributes located under the directory
319 * specified in 'dir' parameter.
321 static int pmu_aliases_parse(char *dir, struct list_head *head)
323 struct dirent *evt_ent;
326 event_dir = opendir(dir);
330 while ((evt_ent = readdir(event_dir))) {
332 char *name = evt_ent->d_name;
335 if (!strcmp(name, ".") || !strcmp(name, ".."))
339 * skip info files parsed in perf_pmu__new_alias()
341 if (pmu_alias_info_file(name))
344 snprintf(path, PATH_MAX, "%s/%s", dir, name);
346 file = fopen(path, "r");
348 pr_debug("Cannot open %s\n", path);
352 if (perf_pmu__new_alias(head, dir, name, file) < 0)
353 pr_debug("Cannot set up %s\n", name);
362 * Reading the pmu event aliases definition, which should be located at:
363 * /sys/bus/event_source/devices/<dev>/events as sysfs group attributes.
365 static int pmu_aliases(const char *name, struct list_head *head)
369 const char *sysfs = sysfs__mountpoint();
374 snprintf(path, PATH_MAX,
375 "%s/bus/event_source/devices/%s/events", sysfs, name);
377 if (stat(path, &st) < 0)
378 return 0; /* no error if 'events' does not exist */
380 if (pmu_aliases_parse(path, head))
386 static int pmu_alias_terms(struct perf_pmu_alias *alias,
387 struct list_head *terms)
389 struct parse_events_term *term, *cloned;
393 list_for_each_entry(term, &alias->terms, list) {
394 ret = parse_events_term__clone(&cloned, term);
396 parse_events_terms__purge(&list);
399 list_add_tail(&cloned->list, &list);
401 list_splice(&list, terms);
406 * Reading/parsing the default pmu type value, which should be
408 * /sys/bus/event_source/devices/<dev>/type as sysfs attribute.
410 static int pmu_type(const char *name, __u32 *type)
416 const char *sysfs = sysfs__mountpoint();
421 snprintf(path, PATH_MAX,
422 "%s" EVENT_SOURCE_DEVICE_PATH "%s/type", sysfs, name);
424 if (stat(path, &st) < 0)
427 file = fopen(path, "r");
431 if (1 != fscanf(file, "%u", type))
438 /* Add all pmus in sysfs to pmu list: */
439 static void pmu_read_sysfs(void)
444 const char *sysfs = sysfs__mountpoint();
449 snprintf(path, PATH_MAX,
450 "%s" EVENT_SOURCE_DEVICE_PATH, sysfs);
456 while ((dent = readdir(dir))) {
457 if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
459 /* add to static LIST_HEAD(pmus): */
460 perf_pmu__find(dent->d_name);
466 static struct cpu_map *pmu_cpumask(const char *name)
471 struct cpu_map *cpus;
472 const char *sysfs = sysfs__mountpoint();
473 const char *templates[] = {
474 "%s/bus/event_source/devices/%s/cpumask",
475 "%s/bus/event_source/devices/%s/cpus",
478 const char **template;
483 for (template = templates; *template; template++) {
484 snprintf(path, PATH_MAX, *template, sysfs, name);
485 if (stat(path, &st) == 0)
492 file = fopen(path, "r");
496 cpus = cpu_map__read(file);
502 * Return the CPU id as a raw string.
504 * Each architecture should provide a more precise id string that
505 * can be use to match the architecture's "mapfile".
507 char * __weak get_cpuid_str(void)
513 * From the pmu_events_map, find the table of PMU events that corresponds
514 * to the current running CPU. Then, add all PMU events from that table
517 static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
520 struct pmu_events_map *map;
521 struct pmu_event *pe;
525 cpuid = getenv("PERF_CPUID");
527 cpuid = strdup(cpuid);
529 cpuid = get_cpuid_str();
534 pr_debug("Using CPUID %s\n", cpuid);
540 map = &pmu_events_map[i++];
544 if (!strcmp(map->cpuid, cpuid))
549 * Found a matching PMU events table. Create aliases
555 pe = &map->table[i++];
559 pname = pe->pmu ? pe->pmu : "cpu";
560 if (strncmp(pname, name, strlen(pname)))
563 /* need type casts to override 'const' */
564 __perf_pmu__new_alias(head, NULL, (char *)pe->name,
565 (char *)pe->desc, (char *)pe->event,
566 (char *)pe->long_desc, (char *)pe->topic,
567 (char *)pe->unit, (char *)pe->perpkg);
574 struct perf_event_attr * __weak
575 perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused)
580 static struct perf_pmu *pmu_lookup(const char *name)
582 struct perf_pmu *pmu;
588 * The pmu data we store & need consists of the pmu
589 * type value and format definitions. Load both right
592 if (pmu_format(name, &format))
596 * Check the type first to avoid unnecessary work.
598 if (pmu_type(name, &type))
601 if (pmu_aliases(name, &aliases))
604 pmu_add_cpu_aliases(&aliases, name);
605 pmu = zalloc(sizeof(*pmu));
609 pmu->cpus = pmu_cpumask(name);
611 INIT_LIST_HEAD(&pmu->format);
612 INIT_LIST_HEAD(&pmu->aliases);
613 list_splice(&format, &pmu->format);
614 list_splice(&aliases, &pmu->aliases);
615 pmu->name = strdup(name);
617 list_add_tail(&pmu->list, &pmus);
619 pmu->default_config = perf_pmu__get_default_config(pmu);
624 static struct perf_pmu *pmu_find(const char *name)
626 struct perf_pmu *pmu;
628 list_for_each_entry(pmu, &pmus, list)
629 if (!strcmp(pmu->name, name))
635 struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu)
638 * pmu iterator: If pmu is NULL, we start at the begin,
639 * otherwise return the next pmu. Returns NULL on end.
643 pmu = list_prepare_entry(pmu, &pmus, list);
645 list_for_each_entry_continue(pmu, &pmus, list)
650 struct perf_pmu *perf_pmu__find(const char *name)
652 struct perf_pmu *pmu;
655 * Once PMU is loaded it stays in the list,
656 * so we keep us from multiple reading/parsing
657 * the pmu format definitions.
659 pmu = pmu_find(name);
663 return pmu_lookup(name);
666 static struct perf_pmu_format *
667 pmu_find_format(struct list_head *formats, const char *name)
669 struct perf_pmu_format *format;
671 list_for_each_entry(format, formats, list)
672 if (!strcmp(format->name, name))
678 __u64 perf_pmu__format_bits(struct list_head *formats, const char *name)
680 struct perf_pmu_format *format = pmu_find_format(formats, name);
687 for_each_set_bit(fbit, format->bits, PERF_PMU_FORMAT_BITS)
688 bits |= 1ULL << fbit;
694 * Sets value based on the format definition (format parameter)
695 * and unformated value (value parameter).
697 static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
700 unsigned long fbit, vbit;
702 for (fbit = 0, vbit = 0; fbit < PERF_PMU_FORMAT_BITS; fbit++) {
704 if (!test_bit(fbit, format))
707 if (value & (1llu << vbit++))
708 *v |= (1llu << fbit);
710 *v &= ~(1llu << fbit);
714 static __u64 pmu_format_max_value(const unsigned long *format)
719 for_each_set_bit(fbit, format, PERF_PMU_FORMAT_BITS)
726 * Term is a string term, and might be a param-term. Try to look up it's value
727 * in the remaining terms.
728 * - We have a term like "base-or-format-term=param-term",
729 * - We need to find the value supplied for "param-term" (with param-term named
730 * in a config string) later on in the term list.
732 static int pmu_resolve_param_term(struct parse_events_term *term,
733 struct list_head *head_terms,
736 struct parse_events_term *t;
738 list_for_each_entry(t, head_terms, list) {
739 if (t->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
740 if (!strcmp(t->config, term->config)) {
749 printf("Required parameter '%s' not specified\n", term->config);
754 static char *pmu_formats_string(struct list_head *formats)
756 struct perf_pmu_format *format;
758 struct strbuf buf = STRBUF_INIT;
764 /* sysfs exported terms */
765 list_for_each_entry(format, formats, list)
766 if (strbuf_addf(&buf, i++ ? ",%s" : "%s", format->name) < 0)
769 str = strbuf_detach(&buf, NULL);
771 strbuf_release(&buf);
777 * Setup one of config[12] attr members based on the
778 * user input data - term parameter.
780 static int pmu_config_term(struct list_head *formats,
781 struct perf_event_attr *attr,
782 struct parse_events_term *term,
783 struct list_head *head_terms,
784 bool zero, struct parse_events_error *err)
786 struct perf_pmu_format *format;
791 * If this is a parameter we've already used for parameterized-eval,
792 * skip it in normal eval.
798 * Hardcoded terms should be already in, so nothing
799 * to be done for them.
801 if (parse_events__is_hardcoded_term(term))
804 format = pmu_find_format(formats, term->config);
807 printf("Invalid event/parameter '%s'\n", term->config);
809 char *pmu_term = pmu_formats_string(formats);
811 err->idx = term->err_term;
812 err->str = strdup("unknown term");
813 err->help = parse_events_formats_error_string(pmu_term);
819 switch (format->value) {
820 case PERF_PMU_FORMAT_VALUE_CONFIG:
823 case PERF_PMU_FORMAT_VALUE_CONFIG1:
826 case PERF_PMU_FORMAT_VALUE_CONFIG2:
834 * Either directly use a numeric term, or try to translate string terms
835 * using event parameters.
837 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM)
839 else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) {
840 if (strcmp(term->val.str, "?")) {
842 pr_info("Invalid sysfs entry %s=%s\n",
843 term->config, term->val.str);
846 err->idx = term->err_val;
847 err->str = strdup("expected numeric value");
852 if (pmu_resolve_param_term(term, head_terms, &val))
857 max_val = pmu_format_max_value(format->bits);
860 err->idx = term->err_val;
861 if (asprintf(&err->str,
862 "value too big for format, maximum is %llu",
863 (unsigned long long)max_val) < 0)
864 err->str = strdup("value too big for format");
868 * Assume we don't care if !err, in which case the value will be
869 * silently truncated.
873 pmu_format_value(format->bits, val, vp, zero);
877 int perf_pmu__config_terms(struct list_head *formats,
878 struct perf_event_attr *attr,
879 struct list_head *head_terms,
880 bool zero, struct parse_events_error *err)
882 struct parse_events_term *term;
884 list_for_each_entry(term, head_terms, list) {
885 if (pmu_config_term(formats, attr, term, head_terms,
894 * Configures event's 'attr' parameter based on the:
895 * 1) users input - specified in terms parameter
896 * 2) pmu format definitions - specified by pmu parameter
898 int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
899 struct list_head *head_terms,
900 struct parse_events_error *err)
902 bool zero = !!pmu->default_config;
904 attr->type = pmu->type;
905 return perf_pmu__config_terms(&pmu->format, attr, head_terms,
909 static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu,
910 struct parse_events_term *term)
912 struct perf_pmu_alias *alias;
915 if (parse_events__is_hardcoded_term(term))
918 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
919 if (term->val.num != 1)
921 if (pmu_find_format(&pmu->format, term->config))
924 } else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) {
925 if (strcasecmp(term->config, "event"))
927 name = term->val.str;
932 list_for_each_entry(alias, &pmu->aliases, list) {
933 if (!strcasecmp(alias->name, name))
940 static int check_info_data(struct perf_pmu_alias *alias,
941 struct perf_pmu_info *info)
944 * Only one term in event definition can
945 * define unit, scale and snapshot, fail
946 * if there's more than one.
948 if ((info->unit && alias->unit[0]) ||
949 (info->scale && alias->scale) ||
950 (info->snapshot && alias->snapshot))
954 info->unit = alias->unit;
957 info->scale = alias->scale;
960 info->snapshot = alias->snapshot;
966 * Find alias in the terms list and replace it with the terms
967 * defined for the alias
969 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
970 struct perf_pmu_info *info)
972 struct parse_events_term *term, *h;
973 struct perf_pmu_alias *alias;
976 info->per_pkg = false;
979 * Mark unit and scale as not set
980 * (different from default values, see below)
984 info->snapshot = false;
986 list_for_each_entry_safe(term, h, head_terms, list) {
987 alias = pmu_find_alias(pmu, term);
990 ret = pmu_alias_terms(alias, &term->list);
994 ret = check_info_data(alias, info);
999 info->per_pkg = true;
1001 list_del(&term->list);
1006 * if no unit or scale foundin aliases, then
1007 * set defaults as for evsel
1008 * unit cannot left to NULL
1010 if (info->unit == NULL)
1013 if (info->scale == 0.0)
1019 int perf_pmu__new_format(struct list_head *list, char *name,
1020 int config, unsigned long *bits)
1022 struct perf_pmu_format *format;
1024 format = zalloc(sizeof(*format));
1028 format->name = strdup(name);
1029 format->value = config;
1030 memcpy(format->bits, bits, sizeof(format->bits));
1032 list_add_tail(&format->list, list);
1036 void perf_pmu__set_format(unsigned long *bits, long from, long to)
1043 memset(bits, 0, BITS_TO_BYTES(PERF_PMU_FORMAT_BITS));
1044 for (b = from; b <= to; b++)
1048 static int sub_non_neg(int a, int b)
1055 static char *format_alias(char *buf, int len, struct perf_pmu *pmu,
1056 struct perf_pmu_alias *alias)
1058 struct parse_events_term *term;
1059 int used = snprintf(buf, len, "%s/%s", pmu->name, alias->name);
1061 list_for_each_entry(term, &alias->terms, list) {
1062 if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR)
1063 used += snprintf(buf + used, sub_non_neg(len, used),
1064 ",%s=%s", term->config,
1068 if (sub_non_neg(len, used) > 0) {
1072 if (sub_non_neg(len, used) > 0) {
1076 buf[len - 1] = '\0';
1081 static char *format_alias_or(char *buf, int len, struct perf_pmu *pmu,
1082 struct perf_pmu_alias *alias)
1084 snprintf(buf, len, "%s OR %s/%s/", alias->name, pmu->name, alias->name);
1096 static int cmp_sevent(const void *a, const void *b)
1098 const struct sevent *as = a;
1099 const struct sevent *bs = b;
1101 /* Put extra events last */
1102 if (!!as->desc != !!bs->desc)
1103 return !!as->desc - !!bs->desc;
1104 if (as->topic && bs->topic) {
1105 int n = strcmp(as->topic, bs->topic);
1110 return strcmp(as->name, bs->name);
1113 static void wordwrap(char *s, int start, int max, int corr)
1119 int wlen = strcspn(s, " \t");
1121 if (column + wlen >= max && column > start) {
1122 printf("\n%*s", start, "");
1123 column = start + corr;
1125 n = printf("%s%.*s", column > start ? " " : "", wlen, s);
1135 void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
1138 struct perf_pmu *pmu;
1139 struct perf_pmu_alias *alias;
1143 struct sevent *aliases;
1145 int columns = pager_get_columns();
1150 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1151 list_for_each_entry(alias, &pmu->aliases, list)
1153 if (pmu->selectable)
1156 aliases = zalloc(sizeof(struct sevent) * len);
1161 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1162 list_for_each_entry(alias, &pmu->aliases, list) {
1163 char *name = alias->desc ? alias->name :
1164 format_alias(buf, sizeof(buf), pmu, alias);
1165 bool is_cpu = !strcmp(pmu->name, "cpu");
1167 if (event_glob != NULL &&
1168 !(strglobmatch_nocase(name, event_glob) ||
1169 (!is_cpu && strglobmatch_nocase(alias->name,
1172 strglobmatch_nocase(alias->topic, event_glob))))
1175 if (is_cpu && !name_only && !alias->desc)
1176 name = format_alias_or(buf, sizeof(buf), pmu, alias);
1178 aliases[j].name = name;
1179 if (is_cpu && !name_only && !alias->desc)
1180 aliases[j].name = format_alias_or(buf,
1183 aliases[j].name = strdup(aliases[j].name);
1184 if (!aliases[j].name)
1187 aliases[j].desc = long_desc ? alias->long_desc :
1189 aliases[j].topic = alias->topic;
1190 aliases[j].str = alias->str;
1191 aliases[j].pmu = pmu->name;
1194 if (pmu->selectable &&
1195 (event_glob == NULL || strglobmatch(pmu->name, event_glob))) {
1197 if (asprintf(&s, "%s//", pmu->name) < 0)
1199 aliases[j].name = s;
1204 qsort(aliases, len, sizeof(struct sevent), cmp_sevent);
1205 for (j = 0; j < len; j++) {
1206 /* Skip duplicates */
1207 if (j > 0 && !strcmp(aliases[j].name, aliases[j - 1].name))
1210 printf("%s ", aliases[j].name);
1213 if (aliases[j].desc && !quiet_flag) {
1216 if (aliases[j].topic && (!topic ||
1217 strcmp(topic, aliases[j].topic))) {
1218 printf("%s%s:\n", topic ? "\n" : "",
1220 topic = aliases[j].topic;
1222 printf(" %-50s\n", aliases[j].name);
1223 printf("%*s", 8, "[");
1224 wordwrap(aliases[j].desc, 8, columns, 0);
1227 printf("%*s%s/%s/\n", 8, "", aliases[j].pmu, aliases[j].str);
1229 printf(" %-50s [Kernel PMU event]\n", aliases[j].name);
1232 if (printed && pager_in_use())
1235 for (j = 0; j < len; j++)
1236 zfree(&aliases[j].name);
1241 printf("FATAL: not enough memory to print PMU events\n");
1246 bool pmu_have_event(const char *pname, const char *name)
1248 struct perf_pmu *pmu;
1249 struct perf_pmu_alias *alias;
1252 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1253 if (strcmp(pname, pmu->name))
1255 list_for_each_entry(alias, &pmu->aliases, list)
1256 if (!strcmp(alias->name, name))
1262 static FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name)
1265 char path[PATH_MAX];
1268 sysfs = sysfs__mountpoint();
1272 snprintf(path, PATH_MAX,
1273 "%s" EVENT_SOURCE_DEVICE_PATH "%s/%s", sysfs, pmu->name, name);
1275 if (stat(path, &st) < 0)
1278 return fopen(path, "r");
1281 int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
1288 va_start(args, fmt);
1289 file = perf_pmu__open_file(pmu, name);
1291 ret = vfscanf(file, fmt, args);