Files
Bibo Mao 492ac37fa3 perf kvm: Add kvm-stat for loongarch64
Add support for 'perf kvm stat' on loongarch64 platform, now only kvm
exit event is supported.

Here is example output about "perf kvm --host stat report" command

   Event name   Samples   Sample%     Time (ns)   Time%   Mean Time (ns)
    Mem Store     83969    51.00%     625697070   8.00%             7451
     Mem Read     37641    22.00%     112485730   1.00%             2988
    Interrupt     15542     9.00%      20620190   0.00%             1326
        IOCSR     15207     9.00%      94296190   1.00%             6200
    Hypercall      4873     2.00%      12265280   0.00%             2516
         Idle      3713     2.00%    6322055860  87.00%          1702681
          FPU      1819     1.00%       2750300   0.00%             1511
   Inst Fetch       502     0.00%       1341740   0.00%             2672
   Mem Modify       324     0.00%        602240   0.00%             1858
       CPUCFG        55     0.00%         77610   0.00%             1411
          CSR        12     0.00%         19690   0.00%             1640
         LASX         3     0.00%          4870   0.00%             1623
          LSX         2     0.00%          2100   0.00%             1050

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2024-07-10 16:50:27 +08:00

97 lines
1.7 KiB
C

// SPDX-License-Identifier: GPL-2.0-only
/*
* Implementation of get_cpuid().
*
* Author: Nikita Shubin <n.shubin@yadro.com>
* Bibo Mao <maobibo@loongson.cn>
* Huacai Chen <chenhuacai@loongson.cn>
*/
#include <stdio.h>
#include <stdlib.h>
#include <api/fs/fs.h>
#include <errno.h>
#include "util/debug.h"
#include "util/header.h"
/*
* Output example from /proc/cpuinfo
* CPU Family : Loongson-64bit
* Model Name : Loongson-3C5000
* CPU Revision : 0x10
* FPU Revision : 0x01
*/
#define CPUINFO_MODEL "Model Name"
#define CPUINFO "/proc/cpuinfo"
static char *_get_field(const char *line)
{
char *line2, *nl;
line2 = strrchr(line, ' ');
if (!line2)
return NULL;
line2++;
nl = strrchr(line, '\n');
if (!nl)
return NULL;
return strndup(line2, nl - line2);
}
static char *_get_cpuid(void)
{
unsigned long line_sz;
char *line, *model, *cpuid;
FILE *file;
file = fopen(CPUINFO, "r");
if (file == NULL)
return NULL;
line = model = cpuid = NULL;
while (getline(&line, &line_sz, file) != -1) {
if (strncmp(line, CPUINFO_MODEL, strlen(CPUINFO_MODEL)))
continue;
model = _get_field(line);
if (!model)
goto out_free;
break;
}
if (model && (asprintf(&cpuid, "%s", model) < 0))
cpuid = NULL;
out_free:
fclose(file);
free(model);
return cpuid;
}
int get_cpuid(char *buffer, size_t sz)
{
int ret = 0;
char *cpuid = _get_cpuid();
if (!cpuid)
return EINVAL;
if (sz < strlen(cpuid)) {
ret = ENOBUFS;
goto out_free;
}
scnprintf(buffer, sz, "%s", cpuid);
out_free:
free(cpuid);
return ret;
}
char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
{
return _get_cpuid();
}