1 // SPDX-License-Identifier: GPL-2.0
8 #include <linux/stringify.h>
10 #include "utils_header.h"
11 #include "metricgroup.h"
12 #include <api/fs/fs.h>
15 static bool is_compat_mode(void)
17 unsigned long base_platform = getauxval(AT_BASE_PLATFORM);
18 unsigned long platform = getauxval(AT_PLATFORM);
20 if (!strcmp((char *)platform, (char *)base_platform))
27 get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
32 pvr = mfspr(SPRN_PVR);
34 nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr));
36 /* look for end marker to ensure the entire data fit */
37 if (strchr(buffer, '$')) {
45 get_cpuid_str(struct perf_cpu cpu __maybe_unused)
51 * IBM Power System supports compatible mode. That is
52 * Nth generation platform can support previous generation
53 * OS in a mode called compatibile mode. For ex. LPAR can be
54 * booted in a Power9 mode when the system is a Power10.
56 * In the compatible mode, care must be taken when generating
57 * PVR value. When read, PVR will be of the AT_BASE_PLATFORM
58 * To support generic events, return 0x00ffffff as pvr when
59 * booted in compat mode. Based on this pvr value, json will
60 * pick events from pmu-events/arch/powerpc/compat
62 if (!is_compat_mode())
63 pvr = mfspr(SPRN_PVR);
67 if (asprintf(&bufp, "0x%.8lx", pvr) < 0)
73 int arch_get_runtimeparam(const struct pmu_metric *pm)
76 char path[PATH_MAX] = "/devices/hv_24x7/interface/";
78 strcat(path, pm->aggr_mode == PerChip ? "sockets" : "coresperchip");
79 return sysfs__read_int(path, &count) < 0 ? 1 : count;