1 /* Parse event JSON files */
4 * Copyright (c) 2014, Intel Corporation
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/param.h>
35 #include <sys/resource.h> /* getrlimit */
37 #include <sys/time.h> /* getrlimit */
60 nftw_ordered(const char *path, int (*fn)(const char *, const struct stat *, int,
61 struct FTW *), int nfds, int ftwflags);
67 eprintf(int level, int var, const char *fmt, ...)
78 ret = vfprintf(stderr, fmt, args);
85 __attribute__((weak)) char *
92 addfield(char *map, char **dst, const char *sep, const char *a, jsmntok_t *bt)
94 unsigned int len = strlen(a) + 1 + strlen(sep);
95 int olen = *dst ? strlen(*dst) : 0;
96 int blen = bt ? json_len(bt) : 0;
99 out = realloc(*dst, len + olen + blen);
101 /* Don't add field in this case */
112 strncat(*dst, map + bt->start, blen);
125 char *e = s + strlen(s);
127 /* Remove trailing dots that look ugly in perf list */
129 while (e >= s && isspace(*e))
131 if (e >= s && *e == '.')
135 /* Add escapes for '\' so they are proper C strings. */
144 /* Count the number of '\' in string */
145 for (p = s; *p; p++) {
154 /* allocate space for a new string */
155 fixed = (char *) malloc(len + 1);
159 /* copy over the characters */
161 for (p = s; *p; p++) {
173 static struct msrmap {
177 { "0x3F6", "ldlat=" },
178 { "0x1A6", "offcore_rsp=" },
179 { "0x1A7", "offcore_rsp=" },
180 { "0x3F7", "frontend=" },
184 static struct field {
188 { "UMask", "umask=" },
189 { "CounterMask", "cmask=" },
190 { "Invert", "inv=" },
191 { "AnyThread", "any=" },
192 { "EdgeDetect", "edge=" },
193 { "SampleAfterValue", "period=" },
194 { "FCMask", "fc_mask=" },
195 { "PortMask", "ch_mask=" },
196 { "L3ThreadMask", "l3_thread_mask=" },
197 { "L3SliceMask", "l3_slice_mask=" },
202 cut_comma(char *map, jsmntok_t *newval)
206 /* Cut off everything after comma */
207 for (i = newval->start; i < newval->end; i++) {
214 match_field(char *map, jsmntok_t *field, int nz, char **event, jsmntok_t *val)
217 jsmntok_t newval = *val;
219 for (f = fields; f->field; f++)
220 if (json_streq(map, field, f->field) && nz) {
221 cut_comma(map, &newval);
222 addfield(map, event, ",", f->kernel, &newval);
228 static struct msrmap *
229 lookup_msr(char *map, jsmntok_t *val)
231 jsmntok_t newval = *val;
235 cut_comma(map, &newval);
236 for (i = 0; msrmap[i].num; i++)
237 if (json_streq(map, &newval, msrmap[i].num))
241 pr_err("%s: Unknown MSR in event file %.*s\n", prog,
242 json_len(val), map + val->start);
251 { "CBO", "uncore_cbox" },
252 { "QPI LL", "uncore_qpi" },
253 { "SBO", "uncore_sbox" },
254 { "iMPH-U", "uncore_arb" },
259 field_to_perf(struct map *table, char *map, jsmntok_t *val)
263 for (i = 0; table[i].json; i++) {
264 if (json_streq(map, val, table[i].json))
265 return table[i].perf;
270 #define EXPECT(e, t, m) do { if (!(e)) { \
271 jsmntok_t *loc = (t); \
272 if (!(t)->start && (t) > tokens) \
274 pr_err("%s:%d: " m ", got %s\n", fn, \
275 json_line(map, loc), \
289 /* tp is free'd in process_one_file() */
290 i = asprintf(&tp, "%s", topic);
292 pr_info("%s: asprintf() error %s\n", prog);
296 for (i = 0; i < (int) strlen(tp); i++) {
311 add_topic(const char *bname)
314 topic = strdup(bname);
316 pr_info("%s: strdup() error %s for file %s\n", prog,
317 strerror(errno), bname);
323 struct perf_entry_data {
328 static int close_table;
331 print_events_table_prefix(FILE *fp, const char *tblname)
333 fprintf(fp, "static struct pmu_event %s[] = {\n", tblname);
338 print_events_table_entry(void *data, char *name, const char *event, char *desc,
339 char *long_desc, char *pmu, char *unit, char *perpkg, char *metric_expr,
340 char *metric_name, char *metric_group)
342 struct perf_entry_data *pd = data;
343 FILE *outfp = pd->outfp;
344 char *etopic = pd->topic;
347 * TODO: Remove formatting chars after debugging to reduce
350 fprintf(outfp, "{\n");
353 fprintf(outfp, "\t.name = \"%s\",\n", name);
355 fprintf(outfp, "\t.event = \"%s\",\n", event);
356 fprintf(outfp, "\t.desc = \"%s\",\n", desc);
357 fprintf(outfp, "\t.topic = \"%s\",\n", etopic);
358 if (long_desc && long_desc[0])
359 fprintf(outfp, "\t.long_desc = \"%s\",\n", long_desc);
361 fprintf(outfp, "\t.pmu = \"%s\",\n", pmu);
363 fprintf(outfp, "\t.unit = \"%s\",\n", unit);
365 fprintf(outfp, "\t.perpkg = \"%s\",\n", perpkg);
367 fprintf(outfp, "\t.metric_expr = \"%s\",\n", metric_expr);
369 fprintf(outfp, "\t.metric_name = \"%s\",\n", metric_name);
371 fprintf(outfp, "\t.metric_group = \"%s\",\n", metric_group);
372 fprintf(outfp, "},\n");
377 struct event_struct {
378 struct list_head list;
391 #define ADD_EVENT_FIELD(field) do { if (field) { \
392 es->field = strdup(field); \
397 #define FREE_EVENT_FIELD(field) free(es->field)
399 #define TRY_FIXUP_FIELD(field) do { if (es->field && !*field) {\
400 *field = strdup(es->field); \
405 #define FOR_ALL_EVENT_STRUCT_FIELDS(op) do { \
418 static LIST_HEAD(arch_std_events);
421 free_arch_std_events(void)
423 struct event_struct *es, *next;
425 list_for_each_entry_safe(es, next, &arch_std_events, list) {
426 FOR_ALL_EVENT_STRUCT_FIELDS(FREE_EVENT_FIELD);
433 save_arch_std_events(void *data __unused, char *name, const char *event,
434 char *desc, char *long_desc, char *pmu, char *unit, char *perpkg,
435 char *metric_expr, char *metric_name, char *metric_group)
437 struct event_struct *es;
439 es = malloc(sizeof(*es));
442 memset(es, 0, sizeof(*es));
443 FOR_ALL_EVENT_STRUCT_FIELDS(ADD_EVENT_FIELD);
444 list_add_tail(&es->list, &arch_std_events);
447 FOR_ALL_EVENT_STRUCT_FIELDS(FREE_EVENT_FIELD);
453 print_events_table_suffix(FILE *outfp)
455 fprintf(outfp, "{\n");
457 fprintf(outfp, "\t.name = 0,\n");
458 fprintf(outfp, "\t.event = 0,\n");
459 fprintf(outfp, "\t.desc = 0,\n");
461 fprintf(outfp, "},\n");
462 fprintf(outfp, "};\n");
466 static struct fixed {
470 { "inst_retired.any", "event=0xc0" },
471 { "inst_retired.any_p", "event=0xc0" },
472 { "cpu_clk_unhalted.ref", "event=0x0,umask=0x03" },
473 { "cpu_clk_unhalted.thread", "event=0x3c" },
474 { "cpu_clk_unhalted.thread_any", "event=0x3c,any=1" },
479 * Handle different fixed counter encodings between JSON and perf.
482 real_event(const char *name, char *event)
489 for (i = 0; fixed[i].name; i++)
490 if (!strcasecmp(name, fixed[i].name))
491 return fixed[i].event;
496 try_fixup(const char *fn, char *arch_std, char **event, char **desc,
497 char **name, char **long_desc, char **pmu, char **filter __unused,
498 char **perpkg, char **unit, char **metric_expr, char **metric_name,
499 char **metric_group, unsigned long long eventcode)
501 /* try to find matching event from arch standard values */
502 struct event_struct *es;
504 list_for_each_entry(es, &arch_std_events, list) {
505 if (!strcmp(arch_std, es->name)) {
506 if (!eventcode && es->event) {
507 /* allow EventCode to be overridden */
511 FOR_ALL_EVENT_STRUCT_FIELDS(TRY_FIXUP_FIELD);
516 pr_err("%s: could not find matching %s for %s\n",
521 /* Call func with each event in the json file */
523 json_events(const char *fn,
524 int (*func)(void *data, char *name, const char *event, char *desc,
526 char *pmu, char *unit, char *perpkg,
528 char *metric_name, char *metric_group),
533 jsmntok_t *tokens, *tok;
541 tokens = parse_json(fn, &map, &size, &len);
544 EXPECT(tokens->type == JSMN_ARRAY, tokens, "expected top level array");
546 for (i = 0; i < tokens->size; i++) {
547 char *event = NULL, *desc = NULL, *name = NULL;
548 char *long_desc = NULL;
549 char *extra_desc = NULL;
554 char *metric_expr = NULL;
555 char *metric_name = NULL;
556 char *metric_group = NULL;
557 char *arch_std = NULL;
558 unsigned long long eventcode = 0;
559 struct msrmap *msr = NULL;
560 jsmntok_t *msrval = NULL;
561 jsmntok_t *precise = NULL;
562 jsmntok_t *obj = tok++;
564 EXPECT(obj->type == JSMN_OBJECT, obj, "expected object");
565 for (j = 0; j < obj->size; j += 2) {
566 jsmntok_t *field, *val;
571 EXPECT(field->type == JSMN_STRING, tok + j,
572 "Expected field name");
574 EXPECT(val->type == JSMN_STRING, tok + j + 1,
575 "Expected string value");
577 nz = !json_streq(map, val, "0");
578 if (match_field(map, field, nz, &event, val)) {
580 } else if (json_streq(map, field, "EventCode")) {
582 addfield(map, &code, "", "", val);
583 eventcode |= strtoul(code, NULL, 0);
585 } else if (json_streq(map, field, "ExtSel")) {
587 addfield(map, &code, "", "", val);
588 eventcode |= strtoul(code, NULL, 0) << 21;
590 } else if (json_streq(map, field, "EventName")) {
591 addfield(map, &name, "", "", val);
592 } else if (json_streq(map, field, "BriefDescription")) {
593 addfield(map, &desc, "", "", val);
595 } else if (json_streq(map, field,
596 "PublicDescription")) {
597 addfield(map, &long_desc, "", "", val);
599 } else if (json_streq(map, field, "PEBS") && nz) {
601 } else if (json_streq(map, field, "MSRIndex") && nz) {
602 msr = lookup_msr(map, val);
603 } else if (json_streq(map, field, "MSRValue")) {
605 } else if (json_streq(map, field, "Errata") &&
606 !json_streq(map, val, "null")) {
607 addfield(map, &extra_desc, ". ",
608 " Spec update: ", val);
609 } else if (json_streq(map, field, "Data_LA") && nz) {
610 addfield(map, &extra_desc, ". ",
611 " Supports address when precise",
613 } else if (json_streq(map, field, "Unit")) {
616 ppmu = field_to_perf(unit_to_pmu, map, val);
621 pmu = strdup("uncore_");
622 addfield(map, &pmu, "", "", val);
623 for (s = pmu; *s; s++)
626 addfield(map, &desc, ". ", "Unit: ", NULL);
627 addfield(map, &desc, "", pmu, NULL);
628 addfield(map, &desc, "", " ", NULL);
629 } else if (json_streq(map, field, "Filter")) {
630 addfield(map, &filter, "", "", val);
631 } else if (json_streq(map, field, "ScaleUnit")) {
632 addfield(map, &unit, "", "", val);
633 } else if (json_streq(map, field, "PerPkg")) {
634 addfield(map, &perpkg, "", "", val);
635 } else if (json_streq(map, field, "MetricName")) {
636 addfield(map, &metric_name, "", "", val);
637 } else if (json_streq(map, field, "MetricGroup")) {
638 addfield(map, &metric_group, "", "", val);
639 } else if (json_streq(map, field, "MetricExpr")) {
640 addfield(map, &metric_expr, "", "", val);
641 for (s = metric_expr; *s; s++)
643 } else if (json_streq(map, field, "ArchStdEvent")) {
644 addfield(map, &arch_std, "", "", val);
645 for (s = arch_std; *s; s++)
648 /* ignore unknown fields */
650 if (precise && desc && !strstr(desc, "(Precise Event)")) {
651 if (json_streq(map, precise, "2"))
652 addfield(map, &extra_desc, " ",
653 "(Must be precise)", NULL);
655 addfield(map, &extra_desc, " ",
656 "(Precise event)", NULL);
658 snprintf(buf, sizeof(buf), "event=%#llx", eventcode);
659 addfield(map, &event, ",", buf, NULL);
660 if (desc && extra_desc)
661 addfield(map, &desc, " ", extra_desc, NULL);
662 if (long_desc && extra_desc)
663 addfield(map, &long_desc, " ", extra_desc, NULL);
665 addfield(map, &event, ",", filter, NULL);
667 addfield(map, &event, ",", msr->pname, msrval);
673 * An arch standard event is referenced, so try to
674 * fixup any unassigned values.
676 err = try_fixup(fn, arch_std, &event, &desc, &name,
677 &long_desc, &pmu, &filter, &perpkg,
678 &unit, &metric_expr, &metric_name,
679 &metric_group, eventcode);
683 err = func(data, name, real_event(name, event), desc, long_desc,
684 pmu, unit, perpkg, metric_expr, metric_name, metric_group);
704 EXPECT(tok - tokens == len, tok, "unexpected objects at end");
707 free_json(map, size, tokens);
712 file_name_to_table_name(const char *fname)
721 * Ensure tablename starts with alphabetic character.
722 * Derive rest of table name from basename of the JSON file,
723 * replacing hyphens and stripping out .json suffix.
725 n = asprintf(&tblname, "pme_%s", fname);
727 pr_info("%s: asprintf() error %s for file %s\n", prog,
728 strerror(errno), fname);
732 for (i = 0; i < strlen(tblname); i++) {
735 if (c == '-' || c == '/')
740 } else if (!isalnum(c) && c != '_') {
741 char *tmp = strdup(fname);
742 pr_err("%s: Invalid character '%c' in file name %s\n",
743 prog, c, basename(tmp));
755 print_mapping_table_prefix(FILE *outfp)
757 fprintf(outfp, "struct pmu_events_map pmu_events_map[] = {\n");
761 print_mapping_table_suffix(FILE *outfp)
764 * Print the terminating, NULL entry.
766 fprintf(outfp, "{\n");
767 fprintf(outfp, "\t.cpuid = 0,\n");
768 fprintf(outfp, "\t.version = 0,\n");
769 fprintf(outfp, "\t.type = 0,\n");
770 fprintf(outfp, "\t.table = 0,\n");
771 fprintf(outfp, "},\n");
773 /* and finally, the closing curly bracket for the struct */
774 fprintf(outfp, "};\n");
778 process_mapfile(FILE *outfp, char *fpath)
787 pr_info("%s: Processing mapfile %s\n", prog, fpath);
793 mapfp = fopen(fpath, "r");
795 pr_info("%s: Error %s opening %s\n", prog, strerror(errno),
801 print_mapping_table_prefix(outfp);
803 /* Skip first line (header) */
804 p = fgets(line, n, mapfp);
810 char *cpuid, *version, *type, *fname;
813 p = fgets(line, n, mapfp);
817 if (line[0] == '#' || line[0] == '\n')
820 if (line[strlen(line)-1] != '\n') {
821 /* TODO Deal with lines longer than 16K */
822 pr_info("%s: Mapfile %s: line %d too long, aborting\n",
823 prog, fpath, line_num);
828 line[strlen(line)-1] = '\0';
830 cpuid = fixregex(strtok_r(p, ",", &save));
831 version = strtok_r(NULL, ",", &save);
832 fname = strtok_r(NULL, ",", &save);
833 type = strtok_r(NULL, ",", &save);
835 tblname = file_name_to_table_name(fname);
836 fprintf(outfp, "{\n");
837 fprintf(outfp, "\t.cpuid = \"%s\",\n", cpuid);
838 fprintf(outfp, "\t.version = \"%s\",\n", version);
839 fprintf(outfp, "\t.type = \"%s\",\n", type);
842 * CHECK: We can't use the type (eg "core") field in the
843 * table name. For us to do that, we need to somehow tweak
844 * the other caller of file_name_to_table(), process_json()
845 * to determine the type. process_json() file has no way
846 * of knowing these are "core" events unless file name has
847 * core in it. If filename has core in it, we can safely
848 * ignore the type field here also.
850 fprintf(outfp, "\t.table = %s\n", tblname);
851 fprintf(outfp, "},\n");
855 print_mapping_table_suffix(outfp);
862 * If we fail to locate/process JSON and map files, create a NULL mapping
863 * table. This would at least allow perf to build even if we can't find/use
867 create_empty_mapping(const char *output_file)
871 pr_info("%s: Creating empty pmu_events_map[] table\n", prog);
873 /* Truncate file to clear any partial writes to it */
874 outfp = fopen(output_file, "w");
880 fprintf(outfp, "#include \"pmu-events/pmu-events.h\"\n");
881 print_mapping_table_prefix(outfp);
882 print_mapping_table_suffix(outfp);
891 if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
892 if (rlim.rlim_max == RLIM_INFINITY)
894 return MIN(rlim.rlim_max / 2, 512);
901 * nftw() doesn't let us pass an argument to the processing function,
902 * so use a global variables.
904 static FILE *eventsfp;
905 static char *mapfile;
908 is_leaf_dir(const char *fpath)
918 while ((dir = readdir(d)) != NULL) {
919 if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."))
922 if (dir->d_type == DT_DIR) {
925 } else if (dir->d_type == DT_UNKNOWN) {
929 snprintf(path, sizeof(path), "%s/%s", fpath,
934 if (S_ISDIR(st.st_mode)) {
947 is_json_file(const char *name)
951 if (strlen(name) < 5)
954 suffix = name + strlen(name) - 5;
956 if (strncmp(suffix, ".json", 5) == 0)
962 preprocess_arch_std_files(const char *fpath, const struct stat *sb,
963 int typeflag, struct FTW *ftwbuf)
965 int level = ftwbuf->level;
966 int is_file = typeflag == FTW_F;
968 if (level == 1 && is_file && is_json_file(fpath))
969 return json_events(fpath, save_arch_std_events, (void *)(uintptr_t)sb);
975 process_one_file(const char *fpath, const struct stat *sb, int typeflag,
980 int is_dir = typeflag == FTW_D;
981 int is_file = typeflag == FTW_F;
982 int level = ftwbuf->level;
985 if (level == 2 && is_dir) {
987 * For level 2 directory, bname will include parent name,
988 * like vendor/platform. So search back from platform dir
991 bname = fpath + ftwbuf->base - 2;
999 bname = fpath + ftwbuf->base;
1001 pr_debug("%s %d %7jd %-20s %s\n",
1002 is_file ? "f" : is_dir ? "d" : "x",
1003 level, sb->st_size, bname, fpath);
1005 /* base dir or too deep */
1006 if (level == 0 || level > 3)
1010 /* model directory, reset topic */
1011 if ((level == 1 && is_dir && is_leaf_dir(fpath)) ||
1012 (level == 2 && is_dir)) {
1014 print_events_table_suffix(eventsfp);
1017 * Drop file name suffix. Replace hyphens with underscores.
1018 * Fail if file name contains any alphanum characters besides
1021 tblname = file_name_to_table_name(bname);
1023 pr_info("%s: Error determining table name for %s\n", prog,
1028 print_events_table_prefix(eventsfp, tblname);
1033 * Save the mapfile name for now. We will process mapfile
1034 * after processing all JSON files (so we can write out the
1035 * mapping table after all PMU events tables).
1038 if (level == 1 && is_file) {
1039 if (!strcmp(bname, "mapfile.csv")) {
1040 mapfile = strdup(fpath);
1044 pr_info("%s: Ignoring file %s\n", prog, fpath);
1049 * If the file name does not have a .json extension,
1050 * ignore it. It could be a readme.txt for instance.
1053 if (!is_json_file(bname)) {
1054 pr_info("%s: Ignoring file without .json suffix %s\n", prog,
1060 if (level > 1 && add_topic(bname))
1064 * Assume all other files are JSON files.
1066 * If mapfile refers to 'power7_core.json', we create a table
1067 * named 'power7_core'. Any inconsistencies between the mapfile
1068 * and directory tree could result in build failure due to table
1069 * names not being found.
1071 * Atleast for now, be strict with processing JSON file names.
1072 * i.e. if JSON file name cannot be mapped to C-style table name,
1076 struct perf_entry_data data = {
1077 .topic = get_topic(),
1081 err = json_events(fpath, print_events_table_entry, &data);
1090 * Starting in directory 'start_dirname', find the "mapfile.csv" and
1091 * the set of JSON files for the architecture 'arch'.
1093 * From each JSON file, create a C-style "PMU events table" from the
1094 * JSON file (see struct pmu_event).
1096 * From the mapfile, create a mapping between the CPU revisions and
1097 * PMU event tables (see struct pmu_events_map).
1099 * Write out the PMU events tables and the mapping table to pmu-event.c.
1102 main(int argc, char *argv[])
1106 char ldirname[PATH_MAX];
1109 const char *output_file;
1110 const char *start_dirname;
1113 prog = basename(argv[0]);
1115 pr_err("Usage: %s <arch> <starting_dir> <output_file>\n", prog);
1120 start_dirname = argv[2];
1121 output_file = argv[3];
1124 verbose = atoi(argv[4]);
1126 eventsfp = fopen(output_file, "w");
1128 pr_err("%s Unable to create required file %s (%s)\n",
1129 prog, output_file, strerror(errno));
1133 snprintf(ldirname, sizeof(ldirname), "%s/%s", start_dirname, arch);
1135 /* If architecture does not have any event lists, bail out */
1136 if (stat(ldirname, &stbuf) < 0) {
1137 pr_info("%s: Arch %s has no PMU event lists\n", prog, arch);
1141 /* Include pmu-events.h first */
1142 fprintf(eventsfp, "#include \"pmu-events/pmu-events.h\"\n");
1145 * The mapfile allows multiple CPUids to point to the same JSON file,
1146 * so, not sure if there is a need for symlinks within the pmu-events
1149 * For now, treat symlinks of JSON files as regular files and create
1150 * separate tables for each symlink (presumably, each symlink refers
1151 * to specific version of the CPU).
1154 maxfds = get_maxfds();
1156 rc = nftw_ordered(ldirname, preprocess_arch_std_files, maxfds, 0);
1157 if (rc && verbose) {
1158 pr_info("%s: Error preprocessing arch standard files %s: %s\n",
1159 prog, ldirname, strerror(errno));
1161 } else if (rc < 0) {
1162 /* Make build fail */
1163 free_arch_std_events();
1169 rc = nftw_ordered(ldirname, process_one_file, maxfds, 0);
1170 if (rc && verbose) {
1171 pr_info("%s: Error walking file tree %s\n", prog, ldirname);
1173 } else if (rc < 0) {
1174 /* Make build fail */
1175 free_arch_std_events();
1182 print_events_table_suffix(eventsfp);
1185 pr_info("%s: No CPU->JSON mapping?\n", prog);
1189 if (process_mapfile(eventsfp, mapfile)) {
1190 pr_info("%s: Error processing mapfile %s\n", prog, mapfile);
1191 /* Make build fail */
1199 create_empty_mapping(output_file);
1200 free_arch_std_events();
1205 fts_compare(const FTSENT * const *a, const FTSENT * const *b)
1207 return (strcmp((*a)->fts_name, (*b)->fts_name));
1211 nftw_ordered(const char *path, int (*fn)(const char *, const struct stat *, int,
1212 struct FTW *), int nfds, int ftwflags)
1214 char * const paths[2] = { (char *)path, NULL };
1218 int error = 0, ftsflags, fnflag, postorder, sverrno;
1220 /* XXX - nfds is currently unused */
1226 ftsflags = FTS_COMFOLLOW;
1227 if (!(ftwflags & FTW_CHDIR))
1228 ftsflags |= FTS_NOCHDIR;
1229 if (ftwflags & FTW_MOUNT)
1230 ftsflags |= FTS_XDEV;
1231 if (ftwflags & FTW_PHYS)
1232 ftsflags |= FTS_PHYSICAL;
1234 ftsflags |= FTS_LOGICAL;
1235 postorder = (ftwflags & FTW_DEPTH) != 0;
1236 ftsp = fts_open(paths, ftsflags, fts_compare);
1239 while ((cur = fts_read(ftsp)) != NULL) {
1240 switch (cur->fts_info) {
1274 ftw.base = cur->fts_pathlen - cur->fts_namelen;
1275 ftw.level = cur->fts_level;
1276 error = fn(cur->fts_path, cur->fts_statp, fnflag, &ftw);
1282 if (fts_close(ftsp) != 0 && error == 0)