Path: blob/master/tools/perf/arch/powerpc/util/header.c
29274 views
// SPDX-License-Identifier: GPL-2.01#include <sys/types.h>2#include <errno.h>3#include <unistd.h>4#include <stdio.h>5#include <stdlib.h>6#include <string.h>7#include <linux/stringify.h>8#include "header.h"9#include "utils_header.h"10#include "metricgroup.h"11#include <api/fs/fs.h>12#include <sys/auxv.h>1314static bool is_compat_mode(void)15{16unsigned long base_platform = getauxval(AT_BASE_PLATFORM);17unsigned long platform = getauxval(AT_PLATFORM);1819if (!strcmp((char *)platform, (char *)base_platform))20return false;2122return true;23}2425int26get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)27{28unsigned long pvr;29int nb;3031pvr = mfspr(SPRN_PVR);3233nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr));3435/* look for end marker to ensure the entire data fit */36if (strchr(buffer, '$')) {37buffer[nb-1] = '\0';38return 0;39}40return ENOBUFS;41}4243char *44get_cpuid_str(struct perf_cpu cpu __maybe_unused)45{46char *bufp;47unsigned long pvr;4849/*50* IBM Power System supports compatible mode. That is51* Nth generation platform can support previous generation52* OS in a mode called compatibile mode. For ex. LPAR can be53* booted in a Power9 mode when the system is a Power10.54*55* In the compatible mode, care must be taken when generating56* PVR value. When read, PVR will be of the AT_BASE_PLATFORM57* To support generic events, return 0x00ffffff as pvr when58* booted in compat mode. Based on this pvr value, json will59* pick events from pmu-events/arch/powerpc/compat60*/61if (!is_compat_mode())62pvr = mfspr(SPRN_PVR);63else64pvr = 0x00ffffff;6566if (asprintf(&bufp, "0x%.8lx", pvr) < 0)67bufp = NULL;6869return bufp;70}7172int arch_get_runtimeparam(const struct pmu_metric *pm)73{74int count;75char path[PATH_MAX] = "/devices/hv_24x7/interface/";7677strcat(path, pm->aggr_mode == PerChip ? "sockets" : "coresperchip");78return sysfs__read_int(path, &count) < 0 ? 1 : count;79}808182