linux/tools/perf/util/evlist-hybrid.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-only
   2#include <errno.h>
   3#include <inttypes.h>
   4#include "cpumap.h"
   5#include "evlist.h"
   6#include "evsel.h"
   7#include "../perf.h"
   8#include "util/pmu-hybrid.h"
   9#include "util/evlist-hybrid.h"
  10#include "debug.h"
  11#include <unistd.h>
  12#include <stdlib.h>
  13#include <linux/err.h>
  14#include <linux/string.h>
  15#include <perf/evlist.h>
  16#include <perf/evsel.h>
  17#include <perf/cpumap.h>
  18
  19int evlist__add_default_hybrid(struct evlist *evlist, bool precise)
  20{
  21        struct evsel *evsel;
  22        struct perf_pmu *pmu;
  23        __u64 config;
  24        struct perf_cpu_map *cpus;
  25
  26        perf_pmu__for_each_hybrid_pmu(pmu) {
  27                config = PERF_COUNT_HW_CPU_CYCLES |
  28                         ((__u64)pmu->type << PERF_PMU_TYPE_SHIFT);
  29                evsel = evsel__new_cycles(precise, PERF_TYPE_HARDWARE,
  30                                          config);
  31                if (!evsel)
  32                        return -ENOMEM;
  33
  34                cpus = perf_cpu_map__get(pmu->cpus);
  35                evsel->core.cpus = cpus;
  36                evsel->core.own_cpus = perf_cpu_map__get(cpus);
  37                evsel->pmu_name = strdup(pmu->name);
  38                evlist__add(evlist, evsel);
  39        }
  40
  41        return 0;
  42}
  43
  44static bool group_hybrid_conflict(struct evsel *leader)
  45{
  46        struct evsel *pos, *prev = NULL;
  47
  48        for_each_group_evsel(pos, leader) {
  49                if (!evsel__is_hybrid(pos))
  50                        continue;
  51
  52                if (prev && strcmp(prev->pmu_name, pos->pmu_name))
  53                        return true;
  54
  55                prev = pos;
  56        }
  57
  58        return false;
  59}
  60
  61void evlist__warn_hybrid_group(struct evlist *evlist)
  62{
  63        struct evsel *evsel;
  64
  65        evlist__for_each_entry(evlist, evsel) {
  66                if (evsel__is_group_leader(evsel) &&
  67                    evsel->core.nr_members > 1 &&
  68                    group_hybrid_conflict(evsel)) {
  69                        pr_warning("WARNING: events in group from "
  70                                   "different hybrid PMUs!\n");
  71                        return;
  72                }
  73        }
  74}
  75
  76bool evlist__has_hybrid(struct evlist *evlist)
  77{
  78        struct evsel *evsel;
  79
  80        evlist__for_each_entry(evlist, evsel) {
  81                if (evsel->pmu_name &&
  82                    perf_pmu__is_hybrid(evsel->pmu_name)) {
  83                        return true;
  84                }
  85        }
  86
  87        return false;
  88}
  89