brintos

brintos / linux-shallow public Read only

0
0
Text · 1002 B · 6b00efd Raw
51 lines · c
1// SPDX-License-Identifier: GPL-2.02#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 14int15get_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, "0x%.8lx", mfspr(SPRN_PVR)) < 0)38		bufp = NULL;39 40	return bufp;41}42 43int arch_get_runtimeparam(const struct pmu_metric *pm)44{45	int count;46	char path[PATH_MAX] = "/devices/hv_24x7/interface/";47 48	strcat(path, pm->aggr_mode == PerChip ? "sockets" : "coresperchip");49	return sysfs__read_int(path, &count) < 0 ? 1 : count;50}51