Lines Matching +full:num +full:- +full:strings
1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
25 /** Strings that correspond to enum hwmon_type. */
41 /** Strings that correspond to enum hwmon_item. */
111 * union hwmon_pmu_event_key: Key for hwmon_pmu->events as such each key
119 int num :16; member
125 * struct hwmon_pmu_event_value: Value in hwmon_pmu->events.
143 return pmu && pmu->type >= PERF_PMU_TYPE_HWMON_START && in perf_pmu__is_hwmon()
144 pmu->type <= PERF_PMU_TYPE_HWMON_END; in perf_pmu__is_hwmon()
149 return perf_pmu__is_hwmon(evsel->pmu); in evsel__is_hwmon()
194 *number = -1; in parse_hwmon_filename()
203 elem = bsearch(&fn_type, hwmon_type_strs + 1, ARRAY_SIZE(hwmon_type_strs) - 1, in parse_hwmon_filename()
211 *type = elem - &hwmon_type_strs[0]; in parse_hwmon_filename()
217 if (fn_item_len > 6 && !strcmp(&fn_item[fn_item_len - 6], "_alarm")) { in parse_hwmon_filename()
219 strlcpy(fn_type, fn_item, fn_item_len - 5); in parse_hwmon_filename()
223 elem = bsearch(fn_item, hwmon_item_strs + 1, ARRAY_SIZE(hwmon_item_strs) - 1, in parse_hwmon_filename()
230 *item = elem - &hwmon_item_strs[0]; in parse_hwmon_filename()
258 if (pmu->pmu.sysfs_aliases_loaded) in hwmon_pmu__read_events()
262 * Use a dup-ed fd as closedir will close it. Use openat so that the in hwmon_pmu__read_events()
265 dup_fd = openat(pmu->hwmon_dir_fd, ".", O_DIRECTORY); in hwmon_pmu__read_events()
267 if (dup_fd == -1) in hwmon_pmu__read_events()
268 return -ENOMEM; in hwmon_pmu__read_events()
273 return -ENOMEM; in hwmon_pmu__read_events()
284 if (ent->d_type != DT_REG) in hwmon_pmu__read_events()
287 if (!parse_hwmon_filename(ent->d_name, &type, &number, &item, &alarm)) { in hwmon_pmu__read_events()
288 pr_debug3("Not a hwmon file '%s'\n", ent->d_name); in hwmon_pmu__read_events()
291 key.num = number; in hwmon_pmu__read_events()
293 if (!hashmap__find(&pmu->events, key.type_and_num, &value)) { in hwmon_pmu__read_events()
296 err = -ENOMEM; in hwmon_pmu__read_events()
299 err = hashmap__add(&pmu->events, key.type_and_num, value); in hwmon_pmu__read_events()
302 err = -ENOMEM; in hwmon_pmu__read_events()
306 __set_bit(item, alarm ? value->alarm_items : value->items); in hwmon_pmu__read_events()
309 int fd = openat(pmu->hwmon_dir_fd, ent->d_name, O_RDONLY); in hwmon_pmu__read_events()
317 while (read_len > 0 && buf[read_len - 1] == '\n') in hwmon_pmu__read_events()
318 read_len--; in hwmon_pmu__read_events()
325 pmu->pmu.name, ent->d_name); in hwmon_pmu__read_events()
329 value->label = strdup(buf); in hwmon_pmu__read_events()
330 if (!value->label) { in hwmon_pmu__read_events()
335 snprintf(buf, sizeof(buf), "%s_%s", hwmon_type_strs[type], value->label); in hwmon_pmu__read_events()
337 value->name = strdup(buf); in hwmon_pmu__read_events()
338 if (!value->name) in hwmon_pmu__read_events()
343 if (hashmap__size(&pmu->events) == 0) in hwmon_pmu__read_events()
344 pr_debug2("hwmon_pmu: %s has no events\n", pmu->pmu.name); in hwmon_pmu__read_events()
346 hashmap__for_each_entry_safe((&pmu->events), cur, tmp, bkt) { in hwmon_pmu__read_events()
348 .type_and_num = cur->key, in hwmon_pmu__read_events()
350 struct hwmon_pmu_event_value *value = cur->pvalue; in hwmon_pmu__read_events()
352 if (!test_bit(HWMON_ITEM_INPUT, value->items)) { in hwmon_pmu__read_events()
354 pmu->pmu.name, hwmon_type_strs[key.type], key.num); in hwmon_pmu__read_events()
355 hashmap__delete(&pmu->events, key.type_and_num, &key, &value); in hwmon_pmu__read_events()
356 zfree(&value->label); in hwmon_pmu__read_events()
357 zfree(&value->name); in hwmon_pmu__read_events()
361 pmu->pmu.sysfs_aliases_loaded = true; in hwmon_pmu__read_events()
377 hwm->hwmon_dir_fd = hwmon_dir; in hwmon_pmu__new()
378 hwm->pmu.type = PERF_PMU_TYPE_HWMON_START + strtoul(sysfs_name + 5, NULL, 10); in hwmon_pmu__new()
379 if (hwm->pmu.type > PERF_PMU_TYPE_HWMON_END) { in hwmon_pmu__new()
385 hwm->pmu.name = strdup(buf); in hwmon_pmu__new()
386 if (!hwm->pmu.name) in hwmon_pmu__new()
388 hwm->pmu.alias_name = strdup(sysfs_name); in hwmon_pmu__new()
389 if (!hwm->pmu.alias_name) in hwmon_pmu__new()
391 hwm->pmu.cpus = perf_cpu_map__new("0"); in hwmon_pmu__new()
392 if (!hwm->pmu.cpus) in hwmon_pmu__new()
394 INIT_LIST_HEAD(&hwm->pmu.format); in hwmon_pmu__new()
395 INIT_LIST_HEAD(&hwm->pmu.aliases); in hwmon_pmu__new()
396 INIT_LIST_HEAD(&hwm->pmu.caps); in hwmon_pmu__new()
397 hashmap__init(&hwm->events, hwmon_pmu__event_hashmap_hash, in hwmon_pmu__new()
400 list_add_tail(&hwm->pmu.list, pmus); in hwmon_pmu__new()
401 return &hwm->pmu; in hwmon_pmu__new()
403 free((char *)hwm->pmu.name); in hwmon_pmu__new()
404 free(hwm->pmu.alias_name); in hwmon_pmu__new()
416 hashmap__for_each_entry_safe((&hwm->events), cur, tmp, bkt) { in hwmon_pmu__exit()
417 struct hwmon_pmu_event_value *value = cur->pvalue; in hwmon_pmu__exit()
419 zfree(&value->label); in hwmon_pmu__exit()
420 zfree(&value->name); in hwmon_pmu__exit()
423 hashmap__clear(&hwm->events); in hwmon_pmu__exit()
424 close(hwm->hwmon_dir_fd); in hwmon_pmu__exit()
443 key.num, in hwmon_pmu__describe_items()
446 fd = openat(hwm->hwmon_dir_fd, buf, O_RDONLY); in hwmon_pmu__describe_items()
450 while (read_len > 0 && buf[read_len - 1] == '\n') in hwmon_pmu__describe_items()
451 read_len--; in hwmon_pmu__describe_items()
458 len += snprintf(out_buf + len, out_buf_len - len, "%s%s%s=%g%s", in hwmon_pmu__describe_items()
480 hashmap__for_each_entry((&hwm->events), cur, bkt) { in hwmon_pmu__for_each_event()
511 .type_and_num = cur->key, in hwmon_pmu__for_each_event()
513 struct hwmon_pmu_event_value *value = cur->pvalue; in hwmon_pmu__for_each_event()
516 .name = value->name, in hwmon_pmu__for_each_event()
523 .pmu_name = pmu->name, in hwmon_pmu__for_each_event()
530 hwmon_type_strs[key.type], key.num); in hwmon_pmu__for_each_event()
538 pmu->name + 6, in hwmon_pmu__for_each_event()
539 value->label ?: info.name); in hwmon_pmu__for_each_event()
541 len += hwmon_pmu__describe_items(hwm, desc_buf + len, sizeof(desc_buf) - len, in hwmon_pmu__for_each_event()
542 key, value->items, /*is_alarm=*/false); in hwmon_pmu__for_each_event()
544 len += hwmon_pmu__describe_items(hwm, desc_buf + len, sizeof(desc_buf) - len, in hwmon_pmu__for_each_event()
545 key, value->alarm_items, /*is_alarm=*/true); in hwmon_pmu__for_each_event()
548 pmu->name, cur->key); in hwmon_pmu__for_each_event()
562 return hashmap__size(&hwm->events); in hwmon_pmu__num_events()
581 key.num = number; in hwmon_pmu__have_event()
582 if (hashmap_find(&hwm->events, key.type_and_num, /*value=*/NULL)) in hwmon_pmu__have_event()
584 if (key.num != -1) in hwmon_pmu__have_event()
587 hashmap__for_each_entry((&hwm->events), cur, bkt) { in hwmon_pmu__have_event()
588 struct hwmon_pmu_event_value *value = cur->pvalue; in hwmon_pmu__have_event()
590 key.type_and_num = cur->key; in hwmon_pmu__have_event()
591 if (key.type == type && value->name && !strcasecmp(name, value->name)) in hwmon_pmu__have_event()
602 if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER) { in hwmon_pmu__config_term()
606 if (parse_hwmon_filename(term->config, &type, &number, in hwmon_pmu__config_term()
608 if (number == -1) { in hwmon_pmu__config_term()
616 attr->config = 0; in hwmon_pmu__config_term()
617 hashmap__for_each_entry((&hwm->events), cur, bkt) { in hwmon_pmu__config_term()
619 .type_and_num = cur->key, in hwmon_pmu__config_term()
621 struct hwmon_pmu_event_value *value = cur->pvalue; in hwmon_pmu__config_term()
623 if (key.type == type && value->name && in hwmon_pmu__config_term()
624 !strcasecmp(term->config, value->name)) { in hwmon_pmu__config_term()
625 attr->config = key.type_and_num; in hwmon_pmu__config_term()
629 if (attr->config == 0) in hwmon_pmu__config_term()
630 return -EINVAL; in hwmon_pmu__config_term()
637 key.num = number; in hwmon_pmu__config_term()
638 attr->config = key.type_and_num; in hwmon_pmu__config_term()
646 parse_events_error__handle(err, term->err_val, in hwmon_pmu__config_term()
649 parse_events__term_type_str(term->type_term), in hwmon_pmu__config_term()
650 term->config) < 0 in hwmon_pmu__config_term()
655 return -EINVAL; in hwmon_pmu__config_term()
671 list_for_each_entry(term, &terms->terms, list) { in hwmon_pmu__config_terms()
673 return -EINVAL; in hwmon_pmu__config_terms()
684 list_first_entry(&terms->terms, struct parse_events_term, list); in hwmon_pmu__check_alias()
686 if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER) { in hwmon_pmu__check_alias()
690 if (parse_hwmon_filename(term->config, &type, &number, in hwmon_pmu__check_alias()
692 info->unit = hwmon_units[type]; in hwmon_pmu__check_alias()
695 info->scale = 1; in hwmon_pmu__check_alias()
697 info->scale = 0.001; in hwmon_pmu__check_alias()
704 parse_events_error__handle(err, term->err_val, in hwmon_pmu__check_alias()
707 parse_events__term_type_str(term->type_term), in hwmon_pmu__check_alias()
708 term->config) < 0 in hwmon_pmu__check_alias()
713 return -EINVAL; in hwmon_pmu__check_alias()
737 if (class_hwmon_ent->d_type != DT_LNK) in perf_pmus__read_hwmon_pmus()
740 scnprintf(buf, sizeof(buf), "%s/class/hwmon/%s", sysfs, class_hwmon_ent->d_name); in perf_pmus__read_hwmon_pmus()
742 if (hwmon_dir == -1) { in perf_pmus__read_hwmon_pmus()
744 sysfs, class_hwmon_ent->d_name); in perf_pmus__read_hwmon_pmus()
748 if (name_fd == -1) { in perf_pmus__read_hwmon_pmus()
750 sysfs, class_hwmon_ent->d_name); in perf_pmus__read_hwmon_pmus()
756 if (line_len > 0 && line[line_len - 1] == '\n') in perf_pmus__read_hwmon_pmus()
757 line[line_len - 1] = '\0'; in perf_pmus__read_hwmon_pmus()
758 hwmon_pmu__new(pmus, hwmon_dir, class_hwmon_ent->d_name, line); in perf_pmus__read_hwmon_pmus()
766 #define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))
772 struct hwmon_pmu *hwm = container_of(evsel->pmu, struct hwmon_pmu, pmu); in evsel__hwmon_pmu_open()
774 .type_and_num = evsel->core.attr.config, in evsel__hwmon_pmu_open()
785 hwmon_type_strs[key.type], key.num); in evsel__hwmon_pmu_open()
787 fd = openat(hwm->hwmon_dir_fd, buf, O_RDONLY); in evsel__hwmon_pmu_open()
790 err = -errno; in evsel__hwmon_pmu_open()
798 threads->err_thread = thread; in evsel__hwmon_pmu_open()
801 while (--thread >= 0) { in evsel__hwmon_pmu_open()
804 FD(evsel, idx, thread) = -1; in evsel__hwmon_pmu_open()
807 } while (--idx >= 0); in evsel__hwmon_pmu_open()
818 if (evsel->prev_raw_counts) in evsel__hwmon_pmu_read()
819 old_count = perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); in evsel__hwmon_pmu_read()
821 count = perf_counts(evsel->counts, cpu_map_idx, thread); in evsel__hwmon_pmu_read()
825 count->lost++; in evsel__hwmon_pmu_read()
826 return -EINVAL; in evsel__hwmon_pmu_read()
830 count->val = old_count->val + strtoll(buf, NULL, 10); in evsel__hwmon_pmu_read()
831 count->run = old_count->run + 1; in evsel__hwmon_pmu_read()
832 count->ena = old_count->ena + 1; in evsel__hwmon_pmu_read()
834 count->val = strtoll(buf, NULL, 10); in evsel__hwmon_pmu_read()
835 count->run++; in evsel__hwmon_pmu_read()
836 count->ena++; in evsel__hwmon_pmu_read()