Lines Matching +full:long +full:- +full:term
1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
111 * struct hwmon_pmu_event_value: Value in hwmon_pmu->events.
129 return pmu && pmu->type >= PERF_PMU_TYPE_HWMON_START && in perf_pmu__is_hwmon()
130 pmu->type <= PERF_PMU_TYPE_HWMON_END; in perf_pmu__is_hwmon()
135 return perf_pmu__is_hwmon(evsel->pmu); in evsel__is_hwmon()
138 static size_t hwmon_pmu__event_hashmap_hash(long key, void *ctx __maybe_unused) in hwmon_pmu__event_hashmap_hash()
143 static bool hwmon_pmu__event_hashmap_equal(long key1, long key2, void *ctx __maybe_unused) in hwmon_pmu__event_hashmap_equal()
180 *number = -1; in parse_hwmon_filename()
189 elem = bsearch(&fn_type, hwmon_type_strs + 1, ARRAY_SIZE(hwmon_type_strs) - 1, in parse_hwmon_filename()
197 *type = elem - &hwmon_type_strs[0]; in parse_hwmon_filename()
203 if (fn_item_len > 6 && !strcmp(&fn_item[fn_item_len - 6], "_alarm")) { in parse_hwmon_filename()
205 strlcpy(fn_type, fn_item, fn_item_len - 5); in parse_hwmon_filename()
209 elem = bsearch(fn_item, hwmon_item_strs + 1, ARRAY_SIZE(hwmon_item_strs) - 1, in parse_hwmon_filename()
216 *item = elem - &hwmon_item_strs[0]; in parse_hwmon_filename()
244 if (pmu->pmu.sysfs_aliases_loaded) in hwmon_pmu__read_events()
248 * Use a dup-ed fd as closedir will close it. Use openat so that the in hwmon_pmu__read_events()
251 dup_fd = openat(pmu->hwmon_dir_fd, ".", O_DIRECTORY); in hwmon_pmu__read_events()
253 if (dup_fd == -1) in hwmon_pmu__read_events()
254 return -ENOMEM; in hwmon_pmu__read_events()
259 return -ENOMEM; in hwmon_pmu__read_events()
270 if (ent->d_type != DT_REG) in hwmon_pmu__read_events()
273 if (!parse_hwmon_filename(ent->d_name, &type, &number, &item, &alarm)) { in hwmon_pmu__read_events()
274 pr_debug3("Not a hwmon file '%s'\n", ent->d_name); in hwmon_pmu__read_events()
279 if (!hashmap__find(&pmu->events, key.type_and_num, &value)) { in hwmon_pmu__read_events()
282 err = -ENOMEM; in hwmon_pmu__read_events()
285 err = hashmap__add(&pmu->events, key.type_and_num, value); in hwmon_pmu__read_events()
288 err = -ENOMEM; in hwmon_pmu__read_events()
292 __set_bit(item, alarm ? value->alarm_items : value->items); in hwmon_pmu__read_events()
295 int fd = openat(pmu->hwmon_dir_fd, ent->d_name, O_RDONLY); in hwmon_pmu__read_events()
303 while (read_len > 0 && buf[read_len - 1] == '\n') in hwmon_pmu__read_events()
304 read_len--; in hwmon_pmu__read_events()
311 pmu->pmu.name, ent->d_name); in hwmon_pmu__read_events()
315 value->label = strdup(buf); in hwmon_pmu__read_events()
316 if (!value->label) { in hwmon_pmu__read_events()
321 snprintf(buf, sizeof(buf), "%s_%s", hwmon_type_strs[type], value->label); in hwmon_pmu__read_events()
323 value->name = strdup(buf); in hwmon_pmu__read_events()
324 if (!value->name) in hwmon_pmu__read_events()
329 if (hashmap__size(&pmu->events) == 0) in hwmon_pmu__read_events()
330 pr_debug2("hwmon_pmu: %s has no events\n", pmu->pmu.name); in hwmon_pmu__read_events()
332 hashmap__for_each_entry_safe((&pmu->events), cur, tmp, bkt) { in hwmon_pmu__read_events()
334 .type_and_num = cur->key, in hwmon_pmu__read_events()
336 struct hwmon_pmu_event_value *value = cur->pvalue; in hwmon_pmu__read_events()
338 if (!test_bit(HWMON_ITEM_INPUT, value->items)) { in hwmon_pmu__read_events()
340 pmu->pmu.name, hwmon_type_strs[key.type], key.num); in hwmon_pmu__read_events()
341 hashmap__delete(&pmu->events, key.type_and_num, &key, &value); in hwmon_pmu__read_events()
342 zfree(&value->label); in hwmon_pmu__read_events()
343 zfree(&value->name); in hwmon_pmu__read_events()
347 pmu->pmu.sysfs_aliases_loaded = true; in hwmon_pmu__read_events()
363 hwm->hwmon_dir_fd = hwmon_dir; in hwmon_pmu__new()
364 hwm->pmu.type = PERF_PMU_TYPE_HWMON_START + strtoul(sysfs_name + 5, NULL, 10); in hwmon_pmu__new()
365 if (hwm->pmu.type > PERF_PMU_TYPE_HWMON_END) { in hwmon_pmu__new()
371 hwm->pmu.name = strdup(buf); in hwmon_pmu__new()
372 if (!hwm->pmu.name) in hwmon_pmu__new()
374 hwm->pmu.alias_name = strdup(sysfs_name); in hwmon_pmu__new()
375 if (!hwm->pmu.alias_name) in hwmon_pmu__new()
377 hwm->pmu.cpus = perf_cpu_map__new("0"); in hwmon_pmu__new()
378 if (!hwm->pmu.cpus) in hwmon_pmu__new()
380 INIT_LIST_HEAD(&hwm->pmu.format); in hwmon_pmu__new()
381 INIT_LIST_HEAD(&hwm->pmu.aliases); in hwmon_pmu__new()
382 INIT_LIST_HEAD(&hwm->pmu.caps); in hwmon_pmu__new()
383 hashmap__init(&hwm->events, hwmon_pmu__event_hashmap_hash, in hwmon_pmu__new()
386 list_add_tail(&hwm->pmu.list, pmus); in hwmon_pmu__new()
387 return &hwm->pmu; in hwmon_pmu__new()
389 free((char *)hwm->pmu.name); in hwmon_pmu__new()
390 free(hwm->pmu.alias_name); in hwmon_pmu__new()
402 hashmap__for_each_entry_safe((&hwm->events), cur, tmp, bkt) { in hwmon_pmu__exit()
403 struct hwmon_pmu_event_value *value = cur->pvalue; in hwmon_pmu__exit()
405 zfree(&value->label); in hwmon_pmu__exit()
406 zfree(&value->name); in hwmon_pmu__exit()
409 hashmap__clear(&hwm->events); in hwmon_pmu__exit()
410 close(hwm->hwmon_dir_fd); in hwmon_pmu__exit()
415 const unsigned long *items, bool is_alarm) in hwmon_pmu__describe_items()
432 fd = openat(hwm->hwmon_dir_fd, buf, O_RDONLY); in hwmon_pmu__describe_items()
436 while (read_len > 0 && buf[read_len - 1] == '\n') in hwmon_pmu__describe_items()
437 read_len--; in hwmon_pmu__describe_items()
440 long long val; in hwmon_pmu__describe_items()
444 len += snprintf(out_buf + len, out_buf_len - len, "%s%s%s=%g%s", in hwmon_pmu__describe_items()
466 hashmap__for_each_entry((&hwm->events), cur, bkt) { in hwmon_pmu__for_each_event()
497 .type_and_num = cur->key, in hwmon_pmu__for_each_event()
499 struct hwmon_pmu_event_value *value = cur->pvalue; in hwmon_pmu__for_each_event()
502 .name = value->name, in hwmon_pmu__for_each_event()
509 .pmu_name = pmu->name, in hwmon_pmu__for_each_event()
524 pmu->name + 6, in hwmon_pmu__for_each_event()
525 value->label ?: info.name); in hwmon_pmu__for_each_event()
527 len += hwmon_pmu__describe_items(hwm, desc_buf + len, sizeof(desc_buf) - len, in hwmon_pmu__for_each_event()
528 key, value->items, /*is_alarm=*/false); in hwmon_pmu__for_each_event()
530 len += hwmon_pmu__describe_items(hwm, desc_buf + len, sizeof(desc_buf) - len, in hwmon_pmu__for_each_event()
531 key, value->alarm_items, /*is_alarm=*/true); in hwmon_pmu__for_each_event()
534 pmu->name, cur->key); in hwmon_pmu__for_each_event()
548 return hashmap__size(&hwm->events); in hwmon_pmu__num_events()
568 if (hashmap_find(&hwm->events, key.type_and_num, /*value=*/NULL)) in hwmon_pmu__have_event()
570 if (key.num != -1) in hwmon_pmu__have_event()
573 hashmap__for_each_entry((&hwm->events), cur, bkt) { in hwmon_pmu__have_event()
574 struct hwmon_pmu_event_value *value = cur->pvalue; in hwmon_pmu__have_event()
576 key.type_and_num = cur->key; in hwmon_pmu__have_event()
577 if (key.type == type && value->name && !strcasecmp(name, value->name)) in hwmon_pmu__have_event()
585 struct parse_events_term *term, in hwmon_pmu__config_term() argument
588 if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER) { in hwmon_pmu__config_term()
592 if (parse_hwmon_filename(term->config, &type, &number, in hwmon_pmu__config_term()
594 if (number == -1) { in hwmon_pmu__config_term()
602 attr->config = 0; in hwmon_pmu__config_term()
603 hashmap__for_each_entry((&hwm->events), cur, bkt) { in hwmon_pmu__config_term()
605 .type_and_num = cur->key, in hwmon_pmu__config_term()
607 struct hwmon_pmu_event_value *value = cur->pvalue; in hwmon_pmu__config_term()
609 if (key.type == type && value->name && in hwmon_pmu__config_term()
610 !strcasecmp(term->config, value->name)) { in hwmon_pmu__config_term()
611 attr->config = key.type_and_num; in hwmon_pmu__config_term()
615 if (attr->config == 0) in hwmon_pmu__config_term()
616 return -EINVAL; in hwmon_pmu__config_term()
624 attr->config = key.type_and_num; in hwmon_pmu__config_term()
632 parse_events_error__handle(err, term->err_val, in hwmon_pmu__config_term()
634 "unexpected hwmon event term (%s) %s", in hwmon_pmu__config_term()
635 parse_events__term_type_str(term->type_term), in hwmon_pmu__config_term()
636 term->config) < 0 in hwmon_pmu__config_term()
637 ? strdup("unexpected hwmon event term") in hwmon_pmu__config_term()
641 return -EINVAL; in hwmon_pmu__config_term()
650 struct parse_events_term *term; in hwmon_pmu__config_terms() local
657 list_for_each_entry(term, &terms->terms, list) { in hwmon_pmu__config_terms()
658 if (hwmon_pmu__config_term(hwm, attr, term, err)) in hwmon_pmu__config_terms()
659 return -EINVAL; in hwmon_pmu__config_terms()
669 struct parse_events_term *term = in hwmon_pmu__check_alias() local
670 list_first_entry(&terms->terms, struct parse_events_term, list); in hwmon_pmu__check_alias()
672 if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER) { in hwmon_pmu__check_alias()
676 if (parse_hwmon_filename(term->config, &type, &number, in hwmon_pmu__check_alias()
678 info->unit = hwmon_units[type]; in hwmon_pmu__check_alias()
681 info->scale = 1; in hwmon_pmu__check_alias()
683 info->scale = 0.001; in hwmon_pmu__check_alias()
690 parse_events_error__handle(err, term->err_val, in hwmon_pmu__check_alias()
692 "unexpected hwmon event term (%s) %s", in hwmon_pmu__check_alias()
693 parse_events__term_type_str(term->type_term), in hwmon_pmu__check_alias()
694 term->config) < 0 in hwmon_pmu__check_alias()
695 ? strdup("unexpected hwmon event term") in hwmon_pmu__check_alias()
699 return -EINVAL; in hwmon_pmu__check_alias()
723 if (class_hwmon_ent->d_type != DT_LNK) in perf_pmus__read_hwmon_pmus()
726 scnprintf(buf, sizeof(buf), "%s/class/hwmon/%s", sysfs, class_hwmon_ent->d_name); in perf_pmus__read_hwmon_pmus()
728 if (hwmon_dir == -1) { in perf_pmus__read_hwmon_pmus()
730 sysfs, class_hwmon_ent->d_name); in perf_pmus__read_hwmon_pmus()
734 if (name_fd == -1) { in perf_pmus__read_hwmon_pmus()
736 sysfs, class_hwmon_ent->d_name); in perf_pmus__read_hwmon_pmus()
742 if (line_len > 0 && line[line_len - 1] == '\n') in perf_pmus__read_hwmon_pmus()
743 line[line_len - 1] = '\0'; in perf_pmus__read_hwmon_pmus()
744 hwmon_pmu__new(pmus, hwmon_dir, class_hwmon_ent->d_name, line); in perf_pmus__read_hwmon_pmus()
752 #define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))
758 struct hwmon_pmu *hwm = container_of(evsel->pmu, struct hwmon_pmu, pmu); in evsel__hwmon_pmu_open()
760 .type_and_num = evsel->core.attr.config, in evsel__hwmon_pmu_open()
773 fd = openat(hwm->hwmon_dir_fd, buf, O_RDONLY); in evsel__hwmon_pmu_open()
776 err = -errno; in evsel__hwmon_pmu_open()
784 threads->err_thread = thread; in evsel__hwmon_pmu_open()
787 while (--thread >= 0) { in evsel__hwmon_pmu_open()
790 FD(evsel, idx, thread) = -1; in evsel__hwmon_pmu_open()
793 } while (--idx >= 0); in evsel__hwmon_pmu_open()
804 if (evsel->prev_raw_counts) in evsel__hwmon_pmu_read()
805 old_count = perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); in evsel__hwmon_pmu_read()
807 count = perf_counts(evsel->counts, cpu_map_idx, thread); in evsel__hwmon_pmu_read()
811 count->lost++; in evsel__hwmon_pmu_read()
812 return -EINVAL; in evsel__hwmon_pmu_read()
816 count->val = old_count->val + strtoll(buf, NULL, 10); in evsel__hwmon_pmu_read()
817 count->run = old_count->run + 1; in evsel__hwmon_pmu_read()
818 count->ena = old_count->ena + 1; in evsel__hwmon_pmu_read()
820 count->val = strtoll(buf, NULL, 10); in evsel__hwmon_pmu_read()
821 count->run++; in evsel__hwmon_pmu_read()
822 count->ena++; in evsel__hwmon_pmu_read()