Commit 9957d8c8 authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim
Browse files

perf jevents: Add common software event json



Add json for software events so that in perf list the events can have
a description.  Common json exists for the tool PMU but it has no
sysfs equivalent. Modify the map_for_pmu code to return the common map
(rather than an architecture specific one) when a PMU with a common
name is being looked for, this allows the events to be found.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/r/20250725185202.68671-3-irogers@google.com


Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent af470fb5
Loading
Loading
Loading
Loading
+92 −0
Original line number Diff line number Diff line
[
  {
    "Unit": "software",
    "EventName": "cpu-clock",
    "BriefDescription": "Per-CPU high-resolution timer based event",
    "ConfigCode": "0"
  },
  {
    "Unit": "software",
    "EventName": "task-clock",
    "BriefDescription": "Per-task high-resolution timer based event",
    "ConfigCode": "1"
  },
  {
    "Unit": "software",
    "EventName": "faults",
    "BriefDescription": "Number of page faults [This event is an alias of page-faults]",
    "ConfigCode": "2"
  },
  {
    "Unit": "software",
    "EventName": "page-faults",
    "BriefDescription": "Number of page faults [This event is an alias of faults]",
    "ConfigCode": "2"
  },
  {
    "Unit": "software",
    "EventName": "context-switches",
    "BriefDescription": "Number of context switches [This event is an alias of cs]",
    "ConfigCode": "3"
  },
  {
    "Unit": "software",
    "EventName": "cs",
    "BriefDescription": "Number of context switches [This event is an alias of context-switches]",
    "ConfigCode": "3"
  },
  {
    "Unit": "software",
    "EventName": "cpu-migrations",
    "BriefDescription": "Number of times a process has migrated to a new CPU [This event is an alias of migrations]",
    "ConfigCode": "4"
  },
  {
    "Unit": "software",
    "EventName": "migrations",
    "BriefDescription": "Number of times a process has migrated to a new CPU [This event is an alias of cpu-migrations]",
    "ConfigCode": "4"
  },
  {
    "Unit": "software",
    "EventName": "minor-faults",
    "BriefDescription": "Number of minor page faults. Minor faults don't require I/O to handle",
    "ConfigCode": "5"
  },
  {
    "Unit": "software",
    "EventName": "major-faults",
    "BriefDescription": "Number of major page faults. Major faults require I/O to handle",
    "ConfigCode": "6"
  },
  {
    "Unit": "software",
    "EventName": "alignment-faults",
    "BriefDescription": "Number of kernel handled memory alignment faults",
    "ConfigCode": "7"
  },
  {
    "Unit": "software",
    "EventName": "emulation-faults",
    "BriefDescription": "Number of kernel handled unimplemented instruction faults handled through emulation",
    "ConfigCode": "8"
  },
  {
    "Unit": "software",
    "EventName": "dummy",
    "BriefDescription": "A placeholder event that doesn't count anything",
    "ConfigCode": "9"
  },
  {
    "Unit": "software",
    "EventName": "bpf-output",
    "BriefDescription": "An event used by BPF programs to write to the perf ring buffer",
    "ConfigCode": "10"
  },
  {
    "Unit": "software",
    "EventName": "cgroup-switches",
    "BriefDescription": "Number of context switches to a task in a different cgroup",
    "ConfigCode": "11"
  }
]
+158 −108

File changed.

Preview size limit exceeded, changes collapsed.

+14 −1
Original line number Diff line number Diff line
@@ -296,6 +296,7 @@ class JsonEvent:
          'cpu_atom': 'cpu_atom',
          'ali_drw': 'ali_drw',
          'arm_cmn': 'arm_cmn',
          'software': 'software',
          'tool': 'tool',
      }
      return table[unit] if unit in table else f'uncore_{unit.lower()}'
@@ -1159,8 +1160,20 @@ static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu)
{
        struct perf_cpu cpu = {-1};

        if (pmu)
        if (pmu) {
                for (size_t i = 0; i < ARRAY_SIZE(pmu_events__common); i++) {
                        const char *pmu_name = &big_c_string[pmu_events__common[i].pmu_name.offset];

                        if (!strcmp(pmu_name, pmu->name)) {
                                const struct pmu_events_map *map = &pmu_events_map[0];

                                while (strcmp("common", map->arch))
                                        map++;
                                return map;
                        }
                }
                cpu = perf_cpu_map__min(pmu->cpus);
        }
        return map_for_cpu(cpu);
}