Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,6 @@
perf-util-y += header.o
perf-util-y += machine.o
perf-util-y += pmu.o
perf-util-y += auxtrace.o
@@ -0,0 +1,125 @@
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/bitops.h>
#include <linux/log2.h>
#include <linux/zalloc.h>
#include "../../util/evlist.h"
#include "../../util/auxtrace.h"
#include "../../util/evsel.h"
#include "../../util/record.h"
#define PERF_EVENT_CPUM_SF 0xB0000 /* Event: Basic-sampling */
#define PERF_EVENT_CPUM_SF_DIAG 0xBD000 /* Event: Combined-sampling */
#define DEFAULT_AUX_PAGES 128
#define DEFAULT_FREQ 4000
static void cpumsf_free(struct auxtrace_record *itr)
{
free(itr);
}
static size_t cpumsf_info_priv_size(struct auxtrace_record *itr __maybe_unused,
struct evlist *evlist __maybe_unused)
{
return 0;
}
static int
cpumsf_info_fill(struct auxtrace_record *itr __maybe_unused,
struct perf_session *session __maybe_unused,
struct perf_record_auxtrace_info *auxtrace_info __maybe_unused,
size_t priv_size __maybe_unused)
{
auxtrace_info->type = PERF_AUXTRACE_S390_CPUMSF;
return 0;
}
static unsigned long
cpumsf_reference(struct auxtrace_record *itr __maybe_unused)
{
return 0;
}
static int
cpumsf_recording_options(struct auxtrace_record *ar __maybe_unused,
struct evlist *evlist __maybe_unused,
struct record_opts *opts)
{
unsigned int factor = 1;
unsigned int pages;
opts->full_auxtrace = true;
/*
* The AUX buffer size should be set properly to avoid
* overflow of samples if it is not set explicitly.
* DEFAULT_AUX_PAGES is an proper size when sampling frequency
* is DEFAULT_FREQ. It is expected to hold about 1/2 second
* of sampling data. The size used for AUX buffer will scale
* according to the specified frequency and DEFAULT_FREQ.
*/
if (!opts->auxtrace_mmap_pages) {
if (opts->user_freq != UINT_MAX)
factor = (opts->user_freq + DEFAULT_FREQ
- 1) / DEFAULT_FREQ;
pages = DEFAULT_AUX_PAGES * factor;
opts->auxtrace_mmap_pages = roundup_pow_of_two(pages);
}
return 0;
}
static int
cpumsf_parse_snapshot_options(struct auxtrace_record *itr __maybe_unused,
struct record_opts *opts __maybe_unused,
const char *str __maybe_unused)
{
return 0;
}
/*
* auxtrace_record__init is called when perf record
* check if the event really need auxtrace
*/
struct auxtrace_record *auxtrace_record__init(struct evlist *evlist,
int *err)
{
struct auxtrace_record *aux;
struct evsel *pos;
int diagnose = 0;
*err = 0;
if (evlist->core.nr_entries == 0)
return NULL;
evlist__for_each_entry(evlist, pos) {
if (pos->core.attr.config == PERF_EVENT_CPUM_SF_DIAG) {
diagnose = 1;
pos->needs_auxtrace_mmap = true;
break;
}
}
if (!diagnose)
return NULL;
/* sampling in diagnose mode. alloc aux buffer */
aux = zalloc(sizeof(*aux));
if (aux == NULL) {
*err = -ENOMEM;
return NULL;
}
aux->parse_snapshot_options = cpumsf_parse_snapshot_options;
aux->recording_options = cpumsf_recording_options;
aux->info_priv_size = cpumsf_info_priv_size;
aux->info_fill = cpumsf_info_fill;
aux->free = cpumsf_free;
aux->reference = cpumsf_reference;
return aux;
}
@@ -0,0 +1,147 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Implementation of get_cpuid().
*
* Copyright IBM Corp. 2014, 2018
* Author(s): Alexander Yarygin <yarygin@linux.vnet.ibm.com>
* Thomas Richter <tmricht@linux.vnet.ibm.com>
*/
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <linux/ctype.h>
#include <linux/kernel.h>
#include <linux/zalloc.h>
#include "../../util/header.h"
#define SYSINFO_MANU "Manufacturer:"
#define SYSINFO_TYPE "Type:"
#define SYSINFO_MODEL "Model:"
#define SRVLVL_CPUMF "CPU-MF:"
#define SRVLVL_VERSION "version="
#define SRVLVL_AUTHORIZATION "authorization="
#define SYSINFO "/proc/sysinfo"
#define SRVLVL "/proc/service_levels"
int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
{
char *cp, *line = NULL, *line2;
char type[8], model[33], version[8], manufacturer[32], authorization[8];
int tpsize = 0, mdsize = 0, vssize = 0, mfsize = 0, atsize = 0;
int read;
unsigned long line_sz;
size_t nbytes;
FILE *sysinfo;
/*
* Scan /proc/sysinfo line by line and read out values for
* Manufacturer:, Type: and Model:, for example:
* Manufacturer: IBM
* Type: 2964
* Model: 702 N96
* The first word is the Model Capacity and the second word is
* Model (can be omitted). Both words have a maximum size of 16
* bytes.
*/
memset(manufacturer, 0, sizeof(manufacturer));
memset(type, 0, sizeof(type));
memset(model, 0, sizeof(model));
memset(version, 0, sizeof(version));
memset(authorization, 0, sizeof(authorization));
sysinfo = fopen(SYSINFO, "r");
if (sysinfo == NULL)
return errno;
while ((read = getline(&line, &line_sz, sysinfo)) != -1) {
if (!strncmp(line, SYSINFO_MANU, strlen(SYSINFO_MANU))) {
line2 = line + strlen(SYSINFO_MANU);
while ((cp = strtok_r(line2, "\n ", &line2))) {
mfsize += scnprintf(manufacturer + mfsize,
sizeof(manufacturer) - mfsize, "%s", cp);
}
}
if (!strncmp(line, SYSINFO_TYPE, strlen(SYSINFO_TYPE))) {
line2 = line + strlen(SYSINFO_TYPE);
while ((cp = strtok_r(line2, "\n ", &line2))) {
tpsize += scnprintf(type + tpsize,
sizeof(type) - tpsize, "%s", cp);
}
}
if (!strncmp(line, SYSINFO_MODEL, strlen(SYSINFO_MODEL))) {
line2 = line + strlen(SYSINFO_MODEL);
while ((cp = strtok_r(line2, "\n ", &line2))) {
mdsize += scnprintf(model + mdsize, sizeof(model) - mdsize,
"%s%s", model[0] ? "," : "", cp);
}
break;
}
}
fclose(sysinfo);
/* Missing manufacturer, type or model information should not happen */
if (!manufacturer[0] || !type[0] || !model[0])
return EINVAL;
/*
* Scan /proc/service_levels and return the CPU-MF counter facility
* version number and authorization level.
* Optional, does not exist on z/VM guests.
*/
sysinfo = fopen(SRVLVL, "r");
if (sysinfo == NULL)
goto skip_sysinfo;
while ((read = getline(&line, &line_sz, sysinfo)) != -1) {
if (strncmp(line, SRVLVL_CPUMF, strlen(SRVLVL_CPUMF)))
continue;
line2 = line + strlen(SRVLVL_CPUMF);
while ((cp = strtok_r(line2, "\n ", &line2))) {
if (!strncmp(cp, SRVLVL_VERSION,
strlen(SRVLVL_VERSION))) {
char *sep = strchr(cp, '=');
vssize += scnprintf(version + vssize,
sizeof(version) - vssize, "%s", sep + 1);
}
if (!strncmp(cp, SRVLVL_AUTHORIZATION,
strlen(SRVLVL_AUTHORIZATION))) {
char *sep = strchr(cp, '=');
atsize += scnprintf(authorization + atsize,
sizeof(authorization) - atsize, "%s", sep + 1);
}
}
}
fclose(sysinfo);
skip_sysinfo:
free(line);
if (version[0] && authorization[0] )
nbytes = snprintf(buffer, sz, "%s,%s,%s,%s,%s",
manufacturer, type, model, version,
authorization);
else
nbytes = snprintf(buffer, sz, "%s,%s,%s", manufacturer, type,
model);
return (nbytes >= sz) ? ENOBUFS : 0;
}
char *get_cpuid_str(struct perf_cpu cpu)
{
char *buf = malloc(128);
if (buf && get_cpuid(buf, 128, cpu))
zfree(&buf);
return buf;
}
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: GPL-2.0
#include <inttypes.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <internal/lib.h> // page_size
#include "machine.h"
#include "api/fs/fs.h"
#include "debug.h"
#include "symbol.h"
int arch__fix_module_text_start(u64 *start, u64 *size, const char *name)
{
u64 m_start = *start;
char path[PATH_MAX];
snprintf(path, PATH_MAX, "module/%.*s/sections/.text",
(int)strlen(name) - 2, name + 1);
if (sysfs__read_ull(path, (unsigned long long *)start) < 0) {
pr_debug2("Using module %s start:%#lx\n", path, m_start);
*start = m_start;
} else {
/* Successful read of the modules segment text start address.
* Calculate difference between module start address
* in memory and module text segment start address.
* For example module load address is 0x3ff8011b000
* (from /proc/modules) and module text segment start
* address is 0x3ff8011b870 (from file above).
*
* Adjust the module size and subtract the GOT table
* size located at the beginning of the module.
*/
*size -= (*start - m_start);
}
return 0;
}
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright IBM Corp. 2023
* Author(s): Thomas Richter <tmricht@linux.ibm.com>
*/
#include <string.h>
#include "../../../util/pmu.h"
#define S390_PMUPAI_CRYPTO "pai_crypto"
#define S390_PMUPAI_EXT "pai_ext"
#define S390_PMUCPUM_CF "cpum_cf"
void perf_pmu__arch_init(struct perf_pmu *pmu)
{
if (!strcmp(pmu->name, S390_PMUPAI_CRYPTO) ||
!strcmp(pmu->name, S390_PMUPAI_EXT) ||
!strcmp(pmu->name, S390_PMUCPUM_CF))
pmu->selectable = true;
}