Lines Matching +full:long +full:- +full:term

1 // SPDX-License-Identifier: GPL-2.0
23 #include "parse-events.h"
55 return -EINVAL; in perf_pmu__format_parse()
59 char *name = evt_ent->d_name; in perf_pmu__format_parse()
67 ret = -EINVAL; in perf_pmu__format_parse()
92 return -1; in pmu_format()
101 return -1; in pmu_format()
123 ret = -ENOMEM; in perf_pmu__convert_scale()
148 int fd, ret = -1; in perf_pmu__parse_scale()
154 if (fd == -1) in perf_pmu__parse_scale()
155 return -1; in perf_pmu__parse_scale()
160 sret = read(fd, scale, sizeof(scale)-1); in perf_pmu__parse_scale()
164 if (scale[sret - 1] == '\n') in perf_pmu__parse_scale()
165 scale[sret - 1] = '\0'; in perf_pmu__parse_scale()
169 ret = perf_pmu__convert_scale(scale, NULL, &alias->scale); in perf_pmu__parse_scale()
184 if (fd == -1) in perf_pmu__parse_unit()
185 return -1; in perf_pmu__parse_unit()
187 sret = read(fd, alias->unit, UNIT_MAX_LEN); in perf_pmu__parse_unit()
193 if (alias->unit[sret - 1] == '\n') in perf_pmu__parse_unit()
194 alias->unit[sret - 1] = '\0'; in perf_pmu__parse_unit()
196 alias->unit[sret] = '\0'; in perf_pmu__parse_unit()
201 alias->unit[0] = '\0'; in perf_pmu__parse_unit()
202 return -1; in perf_pmu__parse_unit()
211 scnprintf(path, PATH_MAX, "%s/%s.per-pkg", dir, name); in perf_pmu__parse_per_pkg()
214 if (fd == -1) in perf_pmu__parse_per_pkg()
215 return -1; in perf_pmu__parse_per_pkg()
219 alias->per_pkg = true; in perf_pmu__parse_per_pkg()
232 if (fd == -1) in perf_pmu__parse_snapshot()
233 return -1; in perf_pmu__parse_snapshot()
235 alias->snapshot = true; in perf_pmu__parse_snapshot()
251 } else /* Nothing new --> keep old string */ in perf_pmu_assign_str()
261 perf_pmu_assign_str(old->name, "desc", &old->desc, &newalias->desc); in perf_pmu_update_alias()
262 perf_pmu_assign_str(old->name, "long_desc", &old->long_desc, in perf_pmu_update_alias()
263 &newalias->long_desc); in perf_pmu_update_alias()
264 perf_pmu_assign_str(old->name, "topic", &old->topic, &newalias->topic); in perf_pmu_update_alias()
265 perf_pmu_assign_str(old->name, "metric_expr", &old->metric_expr, in perf_pmu_update_alias()
266 &newalias->metric_expr); in perf_pmu_update_alias()
267 perf_pmu_assign_str(old->name, "metric_name", &old->metric_name, in perf_pmu_update_alias()
268 &newalias->metric_name); in perf_pmu_update_alias()
269 perf_pmu_assign_str(old->name, "value", &old->str, &newalias->str); in perf_pmu_update_alias()
270 old->scale = newalias->scale; in perf_pmu_update_alias()
271 old->per_pkg = newalias->per_pkg; in perf_pmu_update_alias()
272 old->snapshot = newalias->snapshot; in perf_pmu_update_alias()
273 memcpy(old->unit, newalias->unit, sizeof(old->unit)); in perf_pmu_update_alias()
279 zfree(&newalias->name); in perf_pmu_free_alias()
280 zfree(&newalias->desc); in perf_pmu_free_alias()
281 zfree(&newalias->long_desc); in perf_pmu_free_alias()
282 zfree(&newalias->topic); in perf_pmu_free_alias()
283 zfree(&newalias->str); in perf_pmu_free_alias()
284 zfree(&newalias->metric_expr); in perf_pmu_free_alias()
285 zfree(&newalias->metric_name); in perf_pmu_free_alias()
286 parse_events_terms__purge(&newalias->terms); in perf_pmu_free_alias()
299 if (!strcasecmp(newalias->name, a->name)) { in perf_pmu_merge_alias()
316 struct parse_events_term *term; in __perf_pmu__new_alias() local
324 return -ENOMEM; in __perf_pmu__new_alias()
326 INIT_LIST_HEAD(&alias->terms); in __perf_pmu__new_alias()
327 alias->scale = 1.0; in __perf_pmu__new_alias()
328 alias->unit[0] = '\0'; in __perf_pmu__new_alias()
329 alias->per_pkg = false; in __perf_pmu__new_alias()
330 alias->snapshot = false; in __perf_pmu__new_alias()
331 alias->deprecated = false; in __perf_pmu__new_alias()
333 ret = parse_events_terms(&alias->terms, val); in __perf_pmu__new_alias()
345 * Rebuild string to make alias->str member comparable. in __perf_pmu__new_alias()
349 list_for_each_entry(term, &alias->terms, list) { in __perf_pmu__new_alias()
351 ret += scnprintf(newval + ret, sizeof(newval) - ret, in __perf_pmu__new_alias()
353 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) in __perf_pmu__new_alias()
354 ret += scnprintf(newval + ret, sizeof(newval) - ret, in __perf_pmu__new_alias()
355 "%s=%#x", term->config, term->val.num); in __perf_pmu__new_alias()
356 else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) in __perf_pmu__new_alias()
357 ret += scnprintf(newval + ret, sizeof(newval) - ret, in __perf_pmu__new_alias()
358 "%s=%s", term->config, term->val.str); in __perf_pmu__new_alias()
361 alias->name = strdup(name); in __perf_pmu__new_alias()
372 alias->metric_expr = metric_expr ? strdup(metric_expr) : NULL; in __perf_pmu__new_alias()
373 alias->metric_name = metric_name ? strdup(metric_name): NULL; in __perf_pmu__new_alias()
374 alias->desc = desc ? strdup(desc) : NULL; in __perf_pmu__new_alias()
375 alias->long_desc = long_desc ? strdup(long_desc) : in __perf_pmu__new_alias()
377 alias->topic = topic ? strdup(topic) : NULL; in __perf_pmu__new_alias()
379 if (perf_pmu__convert_scale(unit, &unit, &alias->scale) < 0) in __perf_pmu__new_alias()
380 return -1; in __perf_pmu__new_alias()
381 snprintf(alias->unit, sizeof(alias->unit), "%s", unit); in __perf_pmu__new_alias()
383 alias->per_pkg = perpkg && sscanf(perpkg, "%d", &num) == 1 && num == 1; in __perf_pmu__new_alias()
384 alias->str = strdup(newval); in __perf_pmu__new_alias()
387 alias->deprecated = true; in __perf_pmu__new_alias()
390 list_add_tail(&alias->list, list); in __perf_pmu__new_alias()
402 return -EINVAL; in perf_pmu__new_alias()
418 if (len > 5 && !strcmp(name + len - 5, ".unit")) in pmu_alias_info_file()
420 if (len > 6 && !strcmp(name + len - 6, ".scale")) in pmu_alias_info_file()
422 if (len > 8 && !strcmp(name + len - 8, ".per-pkg")) in pmu_alias_info_file()
424 if (len > 9 && !strcmp(name + len - 9, ".snapshot")) in pmu_alias_info_file()
441 return -EINVAL; in pmu_aliases_parse()
445 char *name = evt_ent->d_name; in pmu_aliases_parse()
484 return -1; in pmu_aliases()
493 return -1; in pmu_aliases()
501 struct parse_events_term *term, *cloned; in pmu_alias_terms() local
505 list_for_each_entry(term, &alias->terms, list) { in pmu_alias_terms()
506 ret = parse_events_term__clone(&cloned, term); in pmu_alias_terms()
515 cloned->weak = true; in pmu_alias_terms()
516 list_add_tail(&cloned->list, &list); in pmu_alias_terms()
535 return -1; in pmu_type()
541 return -1; in pmu_type()
545 return -EINVAL; in pmu_type()
548 ret = -1; in pmu_type()
573 if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, "..")) in pmu_read_sysfs()
576 perf_pmu__find(dent->d_name); in pmu_read_sysfs()
692 if (!map->table) { in perf_pmu__find_map()
697 if (!strcmp_cpuid_str(map->cpuid, cpuid)) in perf_pmu__find_map()
723 * Match more complex aliases where the alias name is a comma-delimited in pmu_uncore_alias_match()
753 const char *name = pmu->name; in pmu_add_cpu_aliases_map()
760 struct pmu_event *pe = &map->table[i++]; in pmu_add_cpu_aliases_map()
761 const char *pname = pe->pmu ? pe->pmu : cpu_name; in pmu_add_cpu_aliases_map()
763 if (!pe->name) { in pmu_add_cpu_aliases_map()
764 if (pe->metric_group || pe->metric_name) in pmu_add_cpu_aliases_map()
778 __perf_pmu__new_alias(head, NULL, (char *)pe->name, in pmu_add_cpu_aliases_map()
779 (char *)pe->desc, (char *)pe->event, in pmu_add_cpu_aliases_map()
780 (char *)pe->long_desc, (char *)pe->topic, in pmu_add_cpu_aliases_map()
781 (char *)pe->unit, (char *)pe->perpkg, in pmu_add_cpu_aliases_map()
782 (char *)pe->metric_expr, in pmu_add_cpu_aliases_map()
783 (char *)pe->metric_name, in pmu_add_cpu_aliases_map()
784 (char *)pe->deprecated); in pmu_add_cpu_aliases_map()
808 int max_precise = -1; in pmu_max_precise()
846 pmu->cpus = pmu_cpumask(name); in pmu_lookup()
847 pmu->name = strdup(name); in pmu_lookup()
848 pmu->type = type; in pmu_lookup()
849 pmu->is_uncore = pmu_is_uncore(name); in pmu_lookup()
850 pmu->max_precise = pmu_max_precise(name); in pmu_lookup()
853 INIT_LIST_HEAD(&pmu->format); in pmu_lookup()
854 INIT_LIST_HEAD(&pmu->aliases); in pmu_lookup()
855 INIT_LIST_HEAD(&pmu->caps); in pmu_lookup()
856 list_splice(&format, &pmu->format); in pmu_lookup()
857 list_splice(&aliases, &pmu->aliases); in pmu_lookup()
858 list_add_tail(&pmu->list, &pmus); in pmu_lookup()
860 pmu->default_config = perf_pmu__get_default_config(pmu); in pmu_lookup()
870 if (!strcmp(pmu->name, name)) in pmu_find()
881 if (pmu->type == type) in perf_pmu__find_by_type()
907 if (pmu->type == evsel->core.attr.type) in evsel__find_pmu()
918 return pmu && pmu->auxtrace; in evsel__is_aux_event()
943 if (!strcmp(format->name, name)) in pmu_find_format()
958 for_each_set_bit(fbit, format->bits, PERF_PMU_FORMAT_BITS) in perf_pmu__format_bits()
969 return -1; in perf_pmu__format_type()
971 return format->value; in perf_pmu__format_type()
978 static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v, in pmu_format_value()
981 unsigned long fbit, vbit; in pmu_format_value()
995 static __u64 pmu_format_max_value(const unsigned long *format) in pmu_format_max_value()
1003 return (1ULL << w) - 1; in pmu_format_max_value()
1004 return -1; in pmu_format_max_value()
1008 * Term is a string term, and might be a param-term. Try to look up it's value
1010 * - We have a term like "base-or-format-term=param-term",
1011 * - We need to find the value supplied for "param-term" (with param-term named
1012 * in a config string) later on in the term list.
1014 static int pmu_resolve_param_term(struct parse_events_term *term, in pmu_resolve_param_term() argument
1021 if (t->type_val == PARSE_EVENTS__TERM_TYPE_NUM && in pmu_resolve_param_term()
1022 t->config && !strcmp(t->config, term->config)) { in pmu_resolve_param_term()
1023 t->used = true; in pmu_resolve_param_term()
1024 *value = t->val.num; in pmu_resolve_param_term()
1030 printf("Required parameter '%s' not specified\n", term->config); in pmu_resolve_param_term()
1032 return -1; in pmu_resolve_param_term()
1047 if (strbuf_addf(&buf, i++ ? ",%s" : "%s", format->name) < 0) in pmu_formats_string()
1059 * user input data - term parameter.
1064 struct parse_events_term *term, in pmu_config_term() argument
1073 * If this is a parameter we've already used for parameterized-eval, in pmu_config_term()
1076 if (term->used) in pmu_config_term()
1083 if (parse_events__is_hardcoded_term(term)) in pmu_config_term()
1086 format = pmu_find_format(formats, term->config); in pmu_config_term()
1093 "unknown term '%s' for pmu '%s'", in pmu_config_term()
1094 term->config, pmu_name) < 0) in pmu_config_term()
1098 parse_events__handle_error(err, term->err_term, in pmu_config_term()
1106 return -EINVAL; in pmu_config_term()
1109 switch (format->value) { in pmu_config_term()
1111 vp = &attr->config; in pmu_config_term()
1114 vp = &attr->config1; in pmu_config_term()
1117 vp = &attr->config2; in pmu_config_term()
1120 return -EINVAL; in pmu_config_term()
1124 * Either directly use a numeric term, or try to translate string terms in pmu_config_term()
1127 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) { in pmu_config_term()
1128 if (term->no_value && in pmu_config_term()
1129 bitmap_weight(format->bits, PERF_PMU_FORMAT_BITS) > 1) { in pmu_config_term()
1131 parse_events__handle_error(err, term->err_val, in pmu_config_term()
1132 strdup("no value assigned for term"), in pmu_config_term()
1135 return -EINVAL; in pmu_config_term()
1138 val = term->val.num; in pmu_config_term()
1139 } else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) { in pmu_config_term()
1140 if (strcmp(term->val.str, "?")) { in pmu_config_term()
1143 term->config, term->val.str); in pmu_config_term()
1146 parse_events__handle_error(err, term->err_val, in pmu_config_term()
1150 return -EINVAL; in pmu_config_term()
1153 if (pmu_resolve_param_term(term, head_terms, &val)) in pmu_config_term()
1154 return -EINVAL; in pmu_config_term()
1156 return -EINVAL; in pmu_config_term()
1158 max_val = pmu_format_max_value(format->bits); in pmu_config_term()
1163 parse_events__handle_error(err, term->err_val, in pmu_config_term()
1166 (unsigned long long)max_val) < 0 in pmu_config_term()
1170 return -EINVAL; in pmu_config_term()
1178 pmu_format_value(format->bits, val, vp, zero); in pmu_config_term()
1187 struct parse_events_term *term; in perf_pmu__config_terms() local
1189 list_for_each_entry(term, head_terms, list) { in perf_pmu__config_terms()
1190 if (pmu_config_term(pmu_name, formats, attr, term, head_terms, in perf_pmu__config_terms()
1192 return -EINVAL; in perf_pmu__config_terms()
1200 * 1) users input - specified in terms parameter
1201 * 2) pmu format definitions - specified by pmu parameter
1207 bool zero = !!pmu->default_config; in perf_pmu__config()
1209 attr->type = pmu->type; in perf_pmu__config()
1210 return perf_pmu__config_terms(pmu->name, &pmu->format, attr, in perf_pmu__config()
1215 struct parse_events_term *term) in pmu_find_alias() argument
1220 if (parse_events__is_hardcoded_term(term)) in pmu_find_alias()
1223 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) { in pmu_find_alias()
1224 if (term->val.num != 1) in pmu_find_alias()
1226 if (pmu_find_format(&pmu->format, term->config)) in pmu_find_alias()
1228 name = term->config; in pmu_find_alias()
1229 } else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) { in pmu_find_alias()
1230 if (strcasecmp(term->config, "event")) in pmu_find_alias()
1232 name = term->val.str; in pmu_find_alias()
1237 list_for_each_entry(alias, &pmu->aliases, list) { in pmu_find_alias()
1238 if (!strcasecmp(alias->name, name)) in pmu_find_alias()
1249 * Only one term in event definition can in check_info_data()
1253 if ((info->unit && alias->unit[0]) || in check_info_data()
1254 (info->scale && alias->scale) || in check_info_data()
1255 (info->snapshot && alias->snapshot)) in check_info_data()
1256 return -EINVAL; in check_info_data()
1258 if (alias->unit[0]) in check_info_data()
1259 info->unit = alias->unit; in check_info_data()
1261 if (alias->scale) in check_info_data()
1262 info->scale = alias->scale; in check_info_data()
1264 if (alias->snapshot) in check_info_data()
1265 info->snapshot = alias->snapshot; in check_info_data()
1277 struct parse_events_term *term, *h; in perf_pmu__check_alias() local
1281 info->per_pkg = false; in perf_pmu__check_alias()
1287 info->unit = NULL; in perf_pmu__check_alias()
1288 info->scale = 0.0; in perf_pmu__check_alias()
1289 info->snapshot = false; in perf_pmu__check_alias()
1290 info->metric_expr = NULL; in perf_pmu__check_alias()
1291 info->metric_name = NULL; in perf_pmu__check_alias()
1293 list_for_each_entry_safe(term, h, head_terms, list) { in perf_pmu__check_alias()
1294 alias = pmu_find_alias(pmu, term); in perf_pmu__check_alias()
1297 ret = pmu_alias_terms(alias, &term->list); in perf_pmu__check_alias()
1305 if (alias->per_pkg) in perf_pmu__check_alias()
1306 info->per_pkg = true; in perf_pmu__check_alias()
1307 info->metric_expr = alias->metric_expr; in perf_pmu__check_alias()
1308 info->metric_name = alias->metric_name; in perf_pmu__check_alias()
1310 list_del_init(&term->list); in perf_pmu__check_alias()
1311 parse_events_term__delete(term); in perf_pmu__check_alias()
1319 if (info->unit == NULL) in perf_pmu__check_alias()
1320 info->unit = ""; in perf_pmu__check_alias()
1322 if (info->scale == 0.0) in perf_pmu__check_alias()
1323 info->scale = 1.0; in perf_pmu__check_alias()
1329 int config, unsigned long *bits) in perf_pmu__new_format()
1335 return -ENOMEM; in perf_pmu__new_format()
1337 format->name = strdup(name); in perf_pmu__new_format()
1338 format->value = config; in perf_pmu__new_format()
1339 memcpy(format->bits, bits, sizeof(format->bits)); in perf_pmu__new_format()
1341 list_add_tail(&format->list, list); in perf_pmu__new_format()
1345 void perf_pmu__set_format(unsigned long *bits, long from, long to) in perf_pmu__set_format()
1347 long b; in perf_pmu__set_format()
1362 list_del(&fmt->list); in perf_pmu__del_formats()
1363 free(fmt->name); in perf_pmu__del_formats()
1372 return a - b; in sub_non_neg()
1378 struct parse_events_term *term; in format_alias() local
1379 int used = snprintf(buf, len, "%s/%s", pmu->name, alias->name); in format_alias()
1381 list_for_each_entry(term, &alias->terms, list) { in format_alias()
1382 if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) in format_alias()
1384 ",%s=%s", term->config, in format_alias()
1385 term->val.str); in format_alias()
1396 buf[len - 1] = '\0'; in format_alias()
1404 snprintf(buf, len, "%s OR %s/%s/", alias->name, pmu->name, alias->name); in format_alias_or()
1425 if (!!as->desc != !!bs->desc) in cmp_sevent()
1426 return !!as->desc - !!bs->desc; in cmp_sevent()
1427 if (as->topic && bs->topic) { in cmp_sevent()
1428 int n = strcmp(as->topic, bs->topic); in cmp_sevent()
1435 if (as->is_cpu != bs->is_cpu) in cmp_sevent()
1436 return bs->is_cpu - as->is_cpu; in cmp_sevent()
1438 return strcmp(as->name, bs->name); in cmp_sevent()
1483 list_for_each_entry(alias, &pmu->aliases, list) in print_pmu_events()
1485 if (pmu->selectable) in print_pmu_events()
1494 list_for_each_entry(alias, &pmu->aliases, list) { in print_pmu_events()
1495 char *name = alias->desc ? alias->name : in print_pmu_events()
1497 bool is_cpu = is_pmu_core(pmu->name); in print_pmu_events()
1499 if (alias->deprecated && !deprecated) in print_pmu_events()
1504 (!is_cpu && strglobmatch_nocase(alias->name, in print_pmu_events()
1506 (alias->topic && in print_pmu_events()
1507 strglobmatch_nocase(alias->topic, event_glob)))) in print_pmu_events()
1510 if (is_cpu && !name_only && !alias->desc) in print_pmu_events()
1514 if (is_cpu && !name_only && !alias->desc) in print_pmu_events()
1522 aliases[j].desc = long_desc ? alias->long_desc : in print_pmu_events()
1523 alias->desc; in print_pmu_events()
1524 aliases[j].topic = alias->topic; in print_pmu_events()
1525 aliases[j].str = alias->str; in print_pmu_events()
1526 aliases[j].pmu = pmu->name; in print_pmu_events()
1527 aliases[j].metric_expr = alias->metric_expr; in print_pmu_events()
1528 aliases[j].metric_name = alias->metric_name; in print_pmu_events()
1532 if (pmu->selectable && in print_pmu_events()
1533 (event_glob == NULL || strglobmatch(pmu->name, event_glob))) { in print_pmu_events()
1535 if (asprintf(&s, "%s//", pmu->name) < 0) in print_pmu_events()
1545 if (j > 0 && !strcmp(aliases[j].name, aliases[j - 1].name)) in print_pmu_events()
1560 printf(" %-50s\n", aliases[j].name); in print_pmu_events()
1573 printf(" %-50s [Kernel PMU event]\n", aliases[j].name); in print_pmu_events()
1597 if (strcmp(pname, pmu->name)) in pmu_have_event()
1599 list_for_each_entry(alias, &pmu->aliases, list) in pmu_have_event()
1600 if (!strcmp(alias->name, name)) in pmu_have_event()
1616 "%s" EVENT_SOURCE_DEVICE_PATH "%s/%s", sysfs, pmu->name, name); in perf_pmu__open_file()
1644 return -ENOMEM; in perf_pmu__new_caps()
1646 caps->name = strdup(name); in perf_pmu__new_caps()
1647 if (!caps->name) in perf_pmu__new_caps()
1649 caps->value = strndup(value, strlen(value) - 1); in perf_pmu__new_caps()
1650 if (!caps->value) in perf_pmu__new_caps()
1652 list_add_tail(&caps->list, list); in perf_pmu__new_caps()
1656 zfree(caps->name); in perf_pmu__new_caps()
1660 return -ENOMEM; in perf_pmu__new_caps()
1678 return -1; in perf_pmu__caps_parse()
1681 "%s" EVENT_SOURCE_DEVICE_PATH "%s/caps", sysfs, pmu->name); in perf_pmu__caps_parse()
1688 return -EINVAL; in perf_pmu__caps_parse()
1692 char *name = evt_ent->d_name; in perf_pmu__caps_parse()
1706 (perf_pmu__new_caps(&pmu->caps, name, value) < 0)) { in perf_pmu__caps_parse()