pmu.c (355b60296143a090039211c5f0e1463f84aab65a) pmu.c (eab35953e67b48c763fbb0e0ffc64dd3152361ea)
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/list.h>
3#include <linux/compiler.h>
4#include <linux/string.h>
5#include <linux/zalloc.h>
6#include <subcmd/pager.h>
7#include <sys/types.h>
8#include <errno.h>

--- 292 unchanged lines hidden (view full) ---

301 perf_pmu_free_alias(newalias);
302 return true;
303 }
304 }
305 return false;
306}
307
308static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/list.h>
3#include <linux/compiler.h>
4#include <linux/string.h>
5#include <linux/zalloc.h>
6#include <subcmd/pager.h>
7#include <sys/types.h>
8#include <errno.h>

--- 292 unchanged lines hidden (view full) ---

301 perf_pmu_free_alias(newalias);
302 return true;
303 }
304 }
305 return false;
306}
307
308static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
309 char *desc, char *val,
310 char *long_desc, char *topic,
311 char *unit, char *perpkg,
312 char *metric_expr,
313 char *metric_name,
314 char *deprecated)
309 char *desc, char *val, struct pmu_event *pe)
315{
316 struct parse_events_term *term;
317 struct perf_pmu_alias *alias;
318 int ret;
319 int num;
320 char newval[256];
310{
311 struct parse_events_term *term;
312 struct perf_pmu_alias *alias;
313 int ret;
314 int num;
315 char newval[256];
316 char *long_desc = NULL, *topic = NULL, *unit = NULL, *perpkg = NULL,
317 *metric_expr = NULL, *metric_name = NULL, *deprecated = NULL;
321
318
319 if (pe) {
320 long_desc = (char *)pe->long_desc;
321 topic = (char *)pe->topic;
322 unit = (char *)pe->unit;
323 perpkg = (char *)pe->perpkg;
324 metric_expr = (char *)pe->metric_expr;
325 metric_name = (char *)pe->metric_name;
326 deprecated = (char *)pe->deprecated;
327 }
328
322 alias = malloc(sizeof(*alias));
323 if (!alias)
324 return -ENOMEM;
325
326 INIT_LIST_HEAD(&alias->terms);
327 alias->scale = 1.0;
328 alias->unit[0] = '\0';
329 alias->per_pkg = false;

--- 71 unchanged lines hidden (view full) ---

401 if (ret == 0)
402 return -EINVAL;
403
404 buf[ret] = 0;
405
406 /* Remove trailing newline from sysfs file */
407 strim(buf);
408
329 alias = malloc(sizeof(*alias));
330 if (!alias)
331 return -ENOMEM;
332
333 INIT_LIST_HEAD(&alias->terms);
334 alias->scale = 1.0;
335 alias->unit[0] = '\0';
336 alias->per_pkg = false;

--- 71 unchanged lines hidden (view full) ---

408 if (ret == 0)
409 return -EINVAL;
410
411 buf[ret] = 0;
412
413 /* Remove trailing newline from sysfs file */
414 strim(buf);
415
409 return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL,
410 NULL, NULL, NULL, NULL);
416 return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL);
411}
412
413static inline bool pmu_alias_info_file(char *name)
414{
415 size_t len;
416
417 len = strlen(name);
418 if (len > 5 && !strcmp(name + len - 5, ".unit"))

--- 293 unchanged lines hidden (view full) ---

712
713 if (!strcmp_cpuid_str(map->cpuid, cpuid))
714 break;
715 }
716 free(cpuid);
717 return map;
718}
719
417}
418
419static inline bool pmu_alias_info_file(char *name)
420{
421 size_t len;
422
423 len = strlen(name);
424 if (len > 5 && !strcmp(name + len - 5, ".unit"))

--- 293 unchanged lines hidden (view full) ---

718
719 if (!strcmp_cpuid_str(map->cpuid, cpuid))
720 break;
721 }
722 free(cpuid);
723 return map;
724}
725
726struct pmu_events_map *__weak pmu_events_map__find(void)
727{
728 return perf_pmu__find_map(NULL);
729}
730
720bool pmu_uncore_alias_match(const char *pmu_name, const char *name)
721{
722 char *tmp = NULL, *tok, *str;
723 bool res;
724
725 str = strdup(pmu_name);
726 if (!str)
727 return false;

--- 60 unchanged lines hidden (view full) ---

788
789 if (strcmp(pname, name))
790 continue;
791
792new_alias:
793 /* need type casts to override 'const' */
794 __perf_pmu__new_alias(head, NULL, (char *)pe->name,
795 (char *)pe->desc, (char *)pe->event,
731bool pmu_uncore_alias_match(const char *pmu_name, const char *name)
732{
733 char *tmp = NULL, *tok, *str;
734 bool res;
735
736 str = strdup(pmu_name);
737 if (!str)
738 return false;

--- 60 unchanged lines hidden (view full) ---

799
800 if (strcmp(pname, name))
801 continue;
802
803new_alias:
804 /* need type casts to override 'const' */
805 __perf_pmu__new_alias(head, NULL, (char *)pe->name,
806 (char *)pe->desc, (char *)pe->event,
796 (char *)pe->long_desc, (char *)pe->topic,
797 (char *)pe->unit, (char *)pe->perpkg,
798 (char *)pe->metric_expr,
799 (char *)pe->metric_name,
800 (char *)pe->deprecated);
807 pe);
801 }
802}
803
804static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu)
805{
806 struct pmu_events_map *map;
807
808 map = perf_pmu__find_map(pmu);

--- 50 unchanged lines hidden (view full) ---

859 return 0;
860
861 if (!strcmp(pmu->id, pe->compat) &&
862 pmu_uncore_alias_match(pe->pmu, pmu->name)) {
863 __perf_pmu__new_alias(idata->head, NULL,
864 (char *)pe->name,
865 (char *)pe->desc,
866 (char *)pe->event,
808 }
809}
810
811static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu)
812{
813 struct pmu_events_map *map;
814
815 map = perf_pmu__find_map(pmu);

--- 50 unchanged lines hidden (view full) ---

866 return 0;
867
868 if (!strcmp(pmu->id, pe->compat) &&
869 pmu_uncore_alias_match(pe->pmu, pmu->name)) {
870 __perf_pmu__new_alias(idata->head, NULL,
871 (char *)pe->name,
872 (char *)pe->desc,
873 (char *)pe->event,
867 (char *)pe->long_desc,
868 (char *)pe->topic,
869 (char *)pe->unit,
870 (char *)pe->perpkg,
871 (char *)pe->metric_expr,
872 (char *)pe->metric_name,
873 (char *)pe->deprecated);
874 pe);
874 }
875
876 return 0;
877}
878
879static void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu)
880{
881 struct pmu_sys_event_iter_data idata = {

--- 182 unchanged lines hidden (view full) ---

1064 if (!format)
1065 return -1;
1066
1067 return format->value;
1068}
1069
1070/*
1071 * Sets value based on the format definition (format parameter)
875 }
876
877 return 0;
878}
879
880static void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu)
881{
882 struct pmu_sys_event_iter_data idata = {

--- 182 unchanged lines hidden (view full) ---

1065 if (!format)
1066 return -1;
1067
1068 return format->value;
1069}
1070
1071/*
1072 * Sets value based on the format definition (format parameter)
1072 * and unformated value (value parameter).
1073 * and unformatted value (value parameter).
1073 */
1074static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
1075 bool zero)
1076{
1077 unsigned long fbit, vbit;
1078
1079 for (fbit = 0, vbit = 0; fbit < PERF_PMU_FORMAT_BITS; fbit++) {
1080

--- 322 unchanged lines hidden (view full) ---

1403 info->metric_expr = alias->metric_expr;
1404 info->metric_name = alias->metric_name;
1405
1406 list_del_init(&term->list);
1407 parse_events_term__delete(term);
1408 }
1409
1410 /*
1074 */
1075static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
1076 bool zero)
1077{
1078 unsigned long fbit, vbit;
1079
1080 for (fbit = 0, vbit = 0; fbit < PERF_PMU_FORMAT_BITS; fbit++) {
1081

--- 322 unchanged lines hidden (view full) ---

1404 info->metric_expr = alias->metric_expr;
1405 info->metric_name = alias->metric_name;
1406
1407 list_del_init(&term->list);
1408 parse_events_term__delete(term);
1409 }
1410
1411 /*
1411 * if no unit or scale foundin aliases, then
1412 * if no unit or scale found in aliases, then
1412 * set defaults as for evsel
1413 * unit cannot left to NULL
1414 */
1415 if (info->unit == NULL)
1416 info->unit = "";
1417
1418 if (info->scale == 0.0)
1419 info->scale = 1.0;

--- 428 unchanged lines hidden ---
1413 * set defaults as for evsel
1414 * unit cannot left to NULL
1415 */
1416 if (info->unit == NULL)
1417 info->unit = "";
1418
1419 if (info->scale == 0.0)
1420 info->scale = 1.0;

--- 428 unchanged lines hidden ---