libports: Ported libpfm4 to Genode.

This commit is contained in:
Michael Mueller
2022-12-08 11:20:24 +01:00
parent 84a5e1ac0a
commit fb91e40f0c
12 changed files with 1508 additions and 1 deletions

View File

@@ -0,0 +1 @@
INC_DIR += $(call select_from_ports,libpfm4)/include

View File

@@ -0,0 +1,204 @@
LIBPFM4_DIR := $(call select_from_ports,libpfm4)/src/lib/libpfm4
CC_OPT += -D_REENTRANT -fvisibility=hidden
SRC_CC = $(LIBPFM4_DIR)/lib/pfmlib_common.c
# build libpfm only for x86_64 for now
CONFIG_PFMLIB_ARCH_X86_64=y
CONFIG_PFMLIB_ARCH_X86=y
CONFIG_PFMLIB_SHARED?=n
CONFIG_PFMLIB_DEBUG?=y
CONFIG_PFMLIB_NOPYTHON?=y
#
# list all library support modules
#
ifeq ($(CONFIG_PFMLIB_ARCH_IA64),y)
INCARCH = $(INC_IA64)
#SRCS += pfmlib_gen_ia64.c pfmlib_itanium.c pfmlib_itanium2.c pfmlib_montecito.c
CFLAGS += -DCONFIG_PFMLIB_ARCH_IA64
endif
ifeq ($(CONFIG_PFMLIB_ARCH_X86),y)
ifeq ($(SYS),Linux)
SRCS += pfmlib_intel_x86_perf_event.c pfmlib_amd64_perf_event.c \
pfmlib_intel_netburst_perf_event.c \
pfmlib_intel_snbep_unc_perf_event.c
endif
INCARCH = $(INC_X86)
SRCS += pfmlib_amd64.c pfmlib_intel_core.c pfmlib_intel_x86.c \
pfmlib_intel_x86_arch.c pfmlib_intel_atom.c \
pfmlib_intel_nhm_unc.c pfmlib_intel_nhm.c \
pfmlib_intel_wsm.c \
pfmlib_intel_snb.c pfmlib_intel_snb_unc.c \
pfmlib_intel_ivb.c pfmlib_intel_ivb_unc.c \
pfmlib_intel_hsw.c \
pfmlib_intel_bdw.c \
pfmlib_intel_skl.c \
pfmlib_intel_icl.c \
pfmlib_intel_spr.c \
pfmlib_intel_rapl.c \
pfmlib_intel_snbep_unc.c \
pfmlib_intel_snbep_unc_cbo.c \
pfmlib_intel_snbep_unc_ha.c \
pfmlib_intel_snbep_unc_imc.c \
pfmlib_intel_snbep_unc_pcu.c \
pfmlib_intel_snbep_unc_qpi.c \
pfmlib_intel_snbep_unc_ubo.c \
pfmlib_intel_snbep_unc_r2pcie.c \
pfmlib_intel_snbep_unc_r3qpi.c \
pfmlib_intel_ivbep_unc_cbo.c \
pfmlib_intel_ivbep_unc_ha.c \
pfmlib_intel_ivbep_unc_imc.c \
pfmlib_intel_ivbep_unc_pcu.c \
pfmlib_intel_ivbep_unc_qpi.c \
pfmlib_intel_ivbep_unc_ubo.c \
pfmlib_intel_ivbep_unc_r2pcie.c \
pfmlib_intel_ivbep_unc_r3qpi.c \
pfmlib_intel_ivbep_unc_irp.c \
pfmlib_intel_hswep_unc_cbo.c \
pfmlib_intel_hswep_unc_ha.c \
pfmlib_intel_hswep_unc_imc.c \
pfmlib_intel_hswep_unc_pcu.c \
pfmlib_intel_hswep_unc_qpi.c \
pfmlib_intel_hswep_unc_ubo.c \
pfmlib_intel_hswep_unc_r2pcie.c \
pfmlib_intel_hswep_unc_r3qpi.c \
pfmlib_intel_hswep_unc_irp.c \
pfmlib_intel_hswep_unc_sbo.c \
pfmlib_intel_bdx_unc_cbo.c \
pfmlib_intel_bdx_unc_ubo.c \
pfmlib_intel_bdx_unc_sbo.c \
pfmlib_intel_bdx_unc_ha.c \
pfmlib_intel_bdx_unc_imc.c \
pfmlib_intel_bdx_unc_irp.c \
pfmlib_intel_bdx_unc_pcu.c \
pfmlib_intel_bdx_unc_qpi.c \
pfmlib_intel_bdx_unc_r2pcie.c \
pfmlib_intel_bdx_unc_r3qpi.c \
pfmlib_intel_skx_unc_cha.c \
pfmlib_intel_skx_unc_iio.c \
pfmlib_intel_skx_unc_imc.c \
pfmlib_intel_skx_unc_irp.c \
pfmlib_intel_skx_unc_m2m.c \
pfmlib_intel_skx_unc_m3upi.c \
pfmlib_intel_skx_unc_pcu.c \
pfmlib_intel_skx_unc_ubo.c \
pfmlib_intel_skx_unc_upi.c \
pfmlib_intel_knc.c \
pfmlib_intel_slm.c \
pfmlib_intel_tmt.c \
pfmlib_intel_knl.c \
pfmlib_intel_knl_unc_imc.c \
pfmlib_intel_knl_unc_edc.c \
pfmlib_intel_knl_unc_cha.c \
pfmlib_intel_knl_unc_m2pcie.c \
pfmlib_intel_glm.c \
pfmlib_intel_netburst.c \
pfmlib_amd64_k7.c pfmlib_amd64_k8.c pfmlib_amd64_fam10h.c \
pfmlib_amd64_fam11h.c pfmlib_amd64_fam12h.c \
pfmlib_amd64_fam14h.c pfmlib_amd64_fam15h.c \
pfmlib_amd64_fam17h.c pfmlib_amd64_fam16h.c \
pfmlib_amd64_fam19h.c pfmlib_amd64_rapl.c \
pfmlib_amd64_fam19h_l3.c
CFLAGS += -DCONFIG_PFMLIB_ARCH_X86
ifeq ($(CONFIG_PFMLIB_ARCH_I386),y)
SRCS += pfmlib_intel_coreduo.c pfmlib_intel_p6.c
CFLAGS += -DCONFIG_PFMLIB_ARCH_I386
endif
ifeq ($(CONFIG_PFMLIB_ARCH_X86_64),y)
CFLAGS += -DCONFIG_PFMLIB_ARCH_X86_64
endif
endif
ifeq ($(CONFIG_PFMLIB_ARCH_POWERPC),y)
ifeq ($(SYS),Linux)
SRCS += pfmlib_powerpc_perf_event.c
endif
INCARCH = $(INC_POWERPC)
SRCS += pfmlib_powerpc.c pfmlib_power4.c pfmlib_ppc970.c pfmlib_power5.c \
pfmlib_power6.c pfmlib_power7.c pfmlib_torrent.c pfmlib_power8.c \
pfmlib_power9.c pfmlib_powerpc_nest.c pfmlib_power10.c
CFLAGS += -DCONFIG_PFMLIB_ARCH_POWERPC
endif
ifeq ($(CONFIG_PFMLIB_ARCH_S390X),y)
ifeq ($(SYS),Linux)
SRCS += pfmlib_s390x_perf_event.c
endif
INCARCH = $(INC_S390X)
SRCS += pfmlib_s390x_cpumf.c
CFLAGS += -DCONFIG_PFMLIB_ARCH_S390X
endif
ifeq ($(CONFIG_PFMLIB_ARCH_SPARC),y)
ifeq ($(SYS),Linux)
SRCS += pfmlib_sparc_perf_event.c
endif
INCARCH = $(INC_SPARC)
SRCS += pfmlib_sparc.c pfmlib_sparc_ultra12.c pfmlib_sparc_ultra3.c pfmlib_sparc_ultra4.c pfmlib_sparc_niagara.c
CFLAGS += -DCONFIG_PFMLIB_ARCH_SPARC
endif
ifeq ($(CONFIG_PFMLIB_ARCH_ARM),y)
ifeq ($(SYS),Linux)
SRCS += pfmlib_arm_perf_event.c
endif
INCARCH = $(INC_ARM)
SRCS += pfmlib_arm.c pfmlib_arm_armv7_pmuv1.c pfmlib_arm_armv6.c pfmlib_arm_armv8.c pfmlib_tx2_unc_perf_event.c pfmlib_kunpeng_unc_perf_event.c
CFLAGS += -DCONFIG_PFMLIB_ARCH_ARM
endif
ifeq ($(CONFIG_PFMLIB_ARCH_ARM64),y)
ifeq ($(SYS),Linux)
SRCS += pfmlib_arm_perf_event.c
endif
INCARCH = $(INC_ARM64)
SRCS += pfmlib_arm.c pfmlib_arm_armv8.c pfmlib_tx2_unc_perf_event.c pfmlib_kunpeng_unc_perf_event.c
CFLAGS += -DCONFIG_PFMLIB_ARCH_ARM64
endif
ifeq ($(CONFIG_PFMLIB_ARCH_MIPS),y)
ifeq ($(SYS),Linux)
SRCS += pfmlib_mips_perf_event.c
endif
INCARCH = $(INC_MIPS)
SRCS += pfmlib_mips.c pfmlib_mips_74k.c
CFLAGS += -DCONFIG_PFMLIB_ARCH_MIPS
endif
ifeq ($(CONFIG_PFMLIB_CELL),y)
INCARCH = $(INC_CELL)
#SRCS += pfmlib_cell.c
CFLAGS += -DCONFIG_PFMLIB_CELL
endif
SRC_CC += $(addprefix $(LIBPFM4_DIR)/lib/,$(SRCS))
vpath %.c $(LIBPFM4_DIR)/lib
CC_OPT += $(CFLAGS)
INC_DIR += $(LIBPFM4_DIR)/include $(LIBPFM4_DIR)/lib/events
vpath %.h $(INC_DIR)
LIBS += base libm libc

View File

@@ -0,0 +1 @@
b0ec09148c2be9f4a96203a3d2de4ebed6ce2da0

View File

@@ -0,0 +1,13 @@
LICENSE := PD
DOWNLOADS := libpfm4.git
VERSION := git
URL(libpfm4) := https://github.com/wcohen/libpfm4.git
REV(libpfm4) := 8aaaf1747e96031a47ed6bd9337ff61a21f8cc64
DIR(libpfm4) := src/lib/libpfm4
DIRS += include
DIRS += include/perfmon
DIR_CONTENT(include) += src/lib/libpfm4/include/perfmon
DIR_CONTENT(include/perfmon) += src/lib/libpfm4/include/perfmon/*.h

View File

@@ -0,0 +1 @@
libpfm4

View File

@@ -0,0 +1,17 @@
MIRROR_FROM_REP_DIR := lib/mk/libpfm4.mk lib/import/import-libpfm4.mk
content: src/lib/libpfm4 COPYING $(MIRROR_FROM_REP_DIR)
PORT_DIR := $(call port_dir,$(REP_DIR)/ports/libpfm4)
src/lib/libpfm4:
mkdir -p $@
cp -r $(PORT_DIR)/src/lib/libpfm4/* $@
rm -rf $@/.git
echo "LIBS = libpfm4" > $@/target.mk
$(MIRROR_FROM_REP_DIR):
$(mirror_from_rep_dir)
LICENSE:
echo "libpfm license, see src/lib/libpfm4/COPYING" > $@

View File

@@ -0,0 +1,3 @@
base
libm
libc

View File

@@ -0,0 +1,68 @@
set build_components {
core init timer app/libpfm_test
}
source ${genode_dir}/repos/base/run/platform_drv.inc
append_platform_drv_build_components
build $build_components
create_boot_directory
set config {
<config>
<parent-provides>
<service name="LOG"/>
<service name="LOG"/>
<service name="PD"/>
<service name="CPU"/>
<service name="ROM"/>
<service name="RAM"/>
<service name="IRQ"/>
<service name="IO_MEM"/>
<service name="IO_PORT"/>
<service name="CAP"/>
<service name="RM"/>
<service name="SIGNAL"/>
<service name="TOPO"/>
</parent-provides>
<default-route>
<any-service><parent/><any-child/></any-service>
</default-route>
<default caps="200"/>
<start name="timer">
<resource name="RAM" quantum="1M"/>
<provides><service name="Timer"/></provides>
<route>
<any-service><parent/><any-child/></any-service>
</route>
</start>
}
append config {
<start name="libpfm_test">
<resource name="RAM" quantum="10M"/>
<config>
<vfs> <dir name="dev"> <log/> <inline name="rtc">2022-07-20 14:30</inline> </dir> </vfs>
<libc stdout="/dev/log" stderr="/dev/log" rtc="/dev/rtc"/>
</config>
<route>
<service name="Timer"><child name="timer"/></service>
<any-service><parent/><any-child/></any-service>
</route>
</start>
</config>
}
install_config $config
set boot_modules {
core init timer vfs.lib.so ld.lib.so posix.lib.so libc.lib.so libm.lib.so stdcxx.lib.so libpfm_test
}
append_platform_drv_boot_modules
build_boot_image $boot_modules
append qemu_args "-nographic "
run_genode_until forever

View File

@@ -0,0 +1,174 @@
/*
* check_events.c - show event encoding
*
* Copyright (c) 2009 Google, Inc
* Contributed by Stephane Eranian <eranian@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* This file is part of libpfm, a performance monitoring support library for
* applications on Linux.
*/
#include <sys/types.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <perfmon/err.h>
#include <perfmon/pfmlib.h>
int pmu_is_present(pfm_pmu_t p)
{
pfm_pmu_info_t pinfo;
int ret;
memset(&pinfo, 0, sizeof(pinfo));
ret = pfm_get_pmu_info(p, &pinfo);
return ret == PFM_SUCCESS ? pinfo.is_present : 0;
}
int main(int argc, const char **argv)
{
pfm_pmu_info_t pinfo;
pfm_pmu_encode_arg_t e;
const char *arg[3];
const char **p;
char *fqstr;
pfm_event_info_t info;
int j, ret;
pfm_pmu_t i;
int total_supported_events = 0;
int total_available_events = 0;
unsigned long low, high, msr;
msr = 0xc0010200;
asm volatile("rdmsr"
: "=a"(low), "=d"(high)
: "c"(msr)); /*
* Initialize pfm library (required before we can use it)
*/
ret = pfm_initialize();
if (ret != PFM_SUCCESS)
errx(1, "cannot initialize library: %s\n", pfm_strerror(ret));
memset(&pinfo, 0, sizeof(pinfo));
memset(&info, 0, sizeof(info));
printf("Supported PMU models:\n");
for (i = PFM_PMU_NONE; i < PFM_PMU_MAX; i++)
{
ret = pfm_get_pmu_info(i, &pinfo);
if (ret != PFM_SUCCESS)
continue;
printf("\t[%d, %s, \"%s\"]\n", i, pinfo.name, pinfo.desc);
}
printf("Detected PMU models:\n");
for (i = PFM_PMU_NONE; i < PFM_PMU_MAX; i++)
{
ret = pfm_get_pmu_info(i, &pinfo);
if (ret != PFM_SUCCESS)
continue;
if (pinfo.is_present)
{
printf("\t[%d, %s, \"%s\"]\n", i, pinfo.name, pinfo.desc);
total_supported_events += pinfo.nevents;
}
total_available_events += pinfo.nevents;
}
printf("Total events: %d available, %d supported\n", total_available_events, total_supported_events);
/*
* be nice to user!
*/
if (argc < 2 && pmu_is_present(PFM_PMU_PERF_EVENT))
{
arg[0] = "PERF_COUNT_HW_CPU_CYCLES";
arg[1] = "PERF_COUNT_HW_INSTRUCTIONS";
arg[2] = NULL;
p = arg;
}
else
{
p = argv + 1;
}
if (!*p)
errx(1, "you must pass at least one event");
memset(&e, 0, sizeof(e));
while (*p)
{
/*
* extract raw event encoding
*
* For perf_event encoding, use
* #include <perfmon/pfmlib_perf_event.h>
* and the function:
* pfm_get_perf_event_encoding()
*/
fqstr = NULL;
e.fstr = &fqstr;
ret = pfm_get_os_event_encoding(*p, PFM_PLM0 | PFM_PLM3, PFM_OS_NONE, &e);
if (ret != PFM_SUCCESS)
{
/*
* codes is too small for this event
* free and let the library resize
*/
if (ret == PFM_ERR_TOOSMALL)
{
free(e.codes);
e.codes = NULL;
e.count = 0;
free(fqstr);
continue;
}
if (ret == PFM_ERR_NOTFOUND && strstr(*p, "::"))
errx(1, "%s: try setting LIBPFM_ENCODE_INACTIVE=1", pfm_strerror(ret));
errx(1, "cannot encode event %s: %s", *p, pfm_strerror(ret));
}
ret = pfm_get_event_info(e.idx, PFM_OS_NONE, &info);
if (ret != PFM_SUCCESS)
errx(1, "cannot get event info: %s", pfm_strerror(ret));
ret = pfm_get_pmu_info(info.pmu, &pinfo);
if (ret != PFM_SUCCESS)
errx(1, "cannot get PMU info: %s", pfm_strerror(ret));
printf("Requested Event: %s\n", *p);
printf("Actual Event: %s\n", fqstr);
printf("PMU : %s\n", pinfo.desc);
printf("IDX : %d\n", e.idx);
printf("Codes :");
for (j = 0; j < e.count; j++)
printf(" 0x%" PRIx64, e.codes[j]);
putchar('\n');
free(fqstr);
p++;
}
if (e.codes)
free(e.codes);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,5 @@
TARGET = libpfm_test
SRC_CC = check_events.c
LIBS += base posix libm libc stdcxx libpfm4
CC_OPT += -Wno-error -Wno-permissive -fpermissive

View File

@@ -1,4 +1,4 @@
TARGET = thread_test
SRC_CC = thread_test.cc
LIBS += base stdcxx
LIBS += base libc stdcxx
CXXFLAGS += -Wno-error