header.c (1019B)
1// SPDX-License-Identifier: GPL-2.0 2#include <sys/types.h> 3#include <errno.h> 4#include <unistd.h> 5#include <stdio.h> 6#include <stdlib.h> 7#include <string.h> 8#include <linux/stringify.h> 9#include "header.h" 10#include "utils_header.h" 11#include "metricgroup.h" 12#include <api/fs/fs.h> 13 14int 15get_cpuid(char *buffer, size_t sz) 16{ 17 unsigned long pvr; 18 int nb; 19 20 pvr = mfspr(SPRN_PVR); 21 22 nb = scnprintf(buffer, sz, "%lu,%lu$", PVR_VER(pvr), PVR_REV(pvr)); 23 24 /* look for end marker to ensure the entire data fit */ 25 if (strchr(buffer, '$')) { 26 buffer[nb-1] = '\0'; 27 return 0; 28 } 29 return ENOBUFS; 30} 31 32char * 33get_cpuid_str(struct perf_pmu *pmu __maybe_unused) 34{ 35 char *bufp; 36 37 if (asprintf(&bufp, "%.8lx", mfspr(SPRN_PVR)) < 0) 38 bufp = NULL; 39 40 return bufp; 41} 42 43int arch_get_runtimeparam(const struct pmu_event *pe) 44{ 45 int count; 46 char path[PATH_MAX] = "/devices/hv_24x7/interface/"; 47 48 atoi(pe->aggr_mode) == PerChip ? strcat(path, "sockets") : strcat(path, "coresperchip"); 49 return sysfs__read_int(path, &count) < 0 ? 1 : count; 50}