Skip to content

Commit

Permalink
Add libpfm
Browse files Browse the repository at this point in the history
  • Loading branch information
blue42u committed Aug 10, 2024
1 parent 96969db commit 7e0f3c6
Show file tree
Hide file tree
Showing 10 changed files with 463 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ci_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,14 @@
"libpciaccess-dev"
]
},
"libpfm": {
"_comment": "Wrap only supports Linux",
"build_on": {
"windows": false,
"msys2": false,
"darwin": false
}
},
"libpsl": {
"_comment": "with build all, it selects icu as a dependency which breaks the tests.",
"alpine_packages": [
Expand Down
8 changes: 8 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,14 @@
"2.3.1-1"
]
},
"libpfm": {
"dependency_names": [
"libpfm"
],
"versions": [
"4.13.0-1"
]
},
"libpng": {
"dependency_names": [
"libpng"
Expand Down
9 changes: 9 additions & 0 deletions subprojects/libpfm.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[wrap-file]
directory = libpfm-4.13.0
source_url = https://sourceforge.net/projects/perfmon2/files/libpfm4/libpfm-4.13.0.tar.gz/download
source_filename = libpfm-4.13.0.tar.gz
source_hash = d18b97764c755528c1051d376e33545d0eb60c6ebf85680436813fa5b04cc3d1
patch_directory = libpfm

[provide]
libpfm = libpfm_dep
19 changes: 19 additions & 0 deletions subprojects/packagefiles/libpfm/examples/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
_deps = [m_dep, libpfm_dep]
if host_machine.system() == 'linux'
_deps += [threads_dep, rt_dep]
elif host_machine.system() == 'windows'
_deps += [cc.find_library('gnurx', required: false)]
endif

executable(
'showevtinfo',
'showevtinfo.c',
c_args: ['-D_GNU_SOURCE'],
dependencies: _deps,
)
executable(
'check_events',
'check_events.c',
c_args: ['-D_GNU_SOURCE'],
dependencies: _deps,
)
7 changes: 7 additions & 0 deletions subprojects/packagefiles/libpfm/include/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
inc = include_directories('.')
install_headers(
'perfmon/pfmlib.h',
'perfmon/perf_event.h',
'perfmon/pfmlib_perf_event.h',
subdir: 'perfmon',
)
217 changes: 217 additions & 0 deletions subprojects/packagefiles/libpfm/lib/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
_srcs = files('pfmlib_common.c')

if host_machine.system() == 'linux'
_srcs += files(
'pfmlib_perf_event.c',
'pfmlib_perf_event_pmu.c',
'pfmlib_perf_event_raw.c',
)
endif

_args = ['-D_REENTRANT']

if host_machine.cpu_family() == 'ia64'
_args += ['-DCONFIG_PFMLIB_ARCH_IA64']

elif host_machine.cpu_family() in ['x86', 'x86_64']
if host_machine.system() == 'linux'
_srcs += files(
'pfmlib_amd64_perf_event.c',
'pfmlib_intel_netburst_perf_event.c',
'pfmlib_intel_snbep_unc_perf_event.c',
'pfmlib_intel_x86_perf_event.c',
)
endif

_srcs += files(
'pfmlib_amd64.c',
'pfmlib_amd64_fam10h.c',
'pfmlib_amd64_fam11h.c',
'pfmlib_amd64_fam12h.c',
'pfmlib_amd64_fam14h.c',
'pfmlib_amd64_fam15h.c',
'pfmlib_amd64_fam16h.c',
'pfmlib_amd64_fam17h.c',
'pfmlib_amd64_fam19h.c',
'pfmlib_amd64_fam19h_l3.c',
'pfmlib_amd64_k7.c',
'pfmlib_amd64_k8.c',
'pfmlib_amd64_rapl.c',
'pfmlib_intel_atom.c',
'pfmlib_intel_bdw.c',
'pfmlib_intel_bdx_unc_cbo.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_bdx_unc_sbo.c',
'pfmlib_intel_bdx_unc_ubo.c',
'pfmlib_intel_core.c',
'pfmlib_intel_glm.c',
'pfmlib_intel_hsw.c',
'pfmlib_intel_hswep_unc_cbo.c',
'pfmlib_intel_hswep_unc_ha.c',
'pfmlib_intel_hswep_unc_imc.c',
'pfmlib_intel_hswep_unc_irp.c',
'pfmlib_intel_hswep_unc_pcu.c',
'pfmlib_intel_hswep_unc_qpi.c',
'pfmlib_intel_hswep_unc_r2pcie.c',
'pfmlib_intel_hswep_unc_r3qpi.c',
'pfmlib_intel_hswep_unc_sbo.c',
'pfmlib_intel_hswep_unc_ubo.c',
'pfmlib_intel_icl.c',
'pfmlib_intel_ivb.c',
'pfmlib_intel_ivb_unc.c',
'pfmlib_intel_ivbep_unc_cbo.c',
'pfmlib_intel_ivbep_unc_ha.c',
'pfmlib_intel_ivbep_unc_imc.c',
'pfmlib_intel_ivbep_unc_irp.c',
'pfmlib_intel_ivbep_unc_pcu.c',
'pfmlib_intel_ivbep_unc_qpi.c',
'pfmlib_intel_ivbep_unc_r2pcie.c',
'pfmlib_intel_ivbep_unc_r3qpi.c',
'pfmlib_intel_ivbep_unc_ubo.c',
'pfmlib_intel_knc.c',
'pfmlib_intel_knl.c',
'pfmlib_intel_knl_unc_cha.c',
'pfmlib_intel_knl_unc_edc.c',
'pfmlib_intel_knl_unc_imc.c',
'pfmlib_intel_knl_unc_m2pcie.c',
'pfmlib_intel_netburst.c',
'pfmlib_intel_nhm.c',
'pfmlib_intel_nhm_unc.c',
'pfmlib_intel_rapl.c',
'pfmlib_intel_skl.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_slm.c',
'pfmlib_intel_snb.c',
'pfmlib_intel_snb_unc.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_r2pcie.c',
'pfmlib_intel_snbep_unc_r3qpi.c',
'pfmlib_intel_snbep_unc_ubo.c',
'pfmlib_intel_spr.c',
'pfmlib_intel_tmt.c',
'pfmlib_intel_wsm.c',
'pfmlib_intel_x86.c',
'pfmlib_intel_x86_arch.c',
)
_args += ['-DCONFIG_PFMLIB_ARCH_X86']

if host_machine.cpu_family() == 'x86'
_srcs += files('pfmlib_intel_coreduo.c', 'pfmlib_intel_p6.c')
_args += ['-DCONFIG_PFMLIB_ARCH_I386']
elif host_machine.cpu_family() == 'x86_64'
_args += ['-DCONFIG_PFMLIB_ARCH_X86_64']
endif

elif host_machine.cpu_family() in ['ppc', 'ppc64']
if host_machine.system() == 'linux'
_srcs += files('pfmlib_powerpc_perf_event.c')
endif

_srcs += files(
'pfmlib_power10.c',
'pfmlib_power4.c',
'pfmlib_power5.c',
'pfmlib_power6.c',
'pfmlib_power7.c',
'pfmlib_power8.c',
'pfmlib_power9.c',
'pfmlib_powerpc.c',
'pfmlib_powerpc_nest.c',
'pfmlib_ppc970.c',
'pfmlib_torrent.c',
)
_args += ['-DCONFIG_PFMLIB_ARCH_POWERPC']

elif host_machine.cpu_family() == 's390x'
if host_machine.system() == 'linux'
_srcs += files('pfmlib_s390x_perf_event.c')
endif

_srcs += files('pfmlib_s390x_cpumf.c')
_args += ['-DCONFIG_PFMLIB_ARCH_S390X']

elif host_machine.cpu_family() in ['sparc', 'sparc64']
if host_machine.system() == 'linux'
_srcs += files('pfmlib_sparc_perf_event.c')
endif

_srcs += files(
'pfmlib_sparc.c',
'pfmlib_sparc_niagara.c',
'pfmlib_sparc_ultra12.c',
'pfmlib_sparc_ultra3.c',
'pfmlib_sparc_ultra4.c',
)
_args += ['-DCONFIG_PFMLIB_ARCH_SPARC']

elif host_machine.cpu_family() == 'arm'
if host_machine.system() != 'linux'
error('ARM is not supported except on Linux')
endif

_srcs += files(
'pfmlib_arm.c',
'pfmlib_arm_armv6.c',
'pfmlib_arm_armv7_pmuv1.c',
'pfmlib_arm_armv8.c',
'pfmlib_arm_armv9.c',
'pfmlib_arm_perf_event.c',
'pfmlib_kunpeng_unc_perf_event.c',
'pfmlib_tx2_unc_perf_event.c',
)
_args += ['-DCONFIG_PFMLIB_ARCH_ARM']

elif host_machine.cpu_family() == 'aarch64'
if host_machine.system() != 'linux'
error('ARM is not supported except on Linux')
endif

_srcs += files(
'pfmlib_arm.c',
'pfmlib_arm_armv8.c',
'pfmlib_arm_armv9.c',
'pfmlib_arm_perf_event.c',
'pfmlib_kunpeng_unc_perf_event.c',
'pfmlib_tx2_unc_perf_event.c',
)
_args += ['-DCONFIG_PFMLIB_ARCH_ARM64']

elif host_machine.cpu_family() in ['mips', 'mips64']
if host_machine.system() == 'linux'
_srcs += files('pfmlib_mips_perf_event.c')
endif

_srcs += files('pfmlib_mips.c', 'pfmlib_mips_74k.c')
_args += ['-DCONFIG_PFMLIB_ARCH_MIPS']
endif

libpfm_lib = library(
'pfm',
_srcs,
c_args: _args,
gnu_symbol_visibility: 'hidden',
include_directories: inc,
pic: true,
install: true,
)
libpfm_dep = declare_dependency(link_with: libpfm_lib, include_directories: inc)
meson.override_dependency('libpfm', libpfm_dep)
51 changes: 51 additions & 0 deletions subprojects/packagefiles/libpfm/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
project('libpfm', 'c', version: '4.13.0', meson_version: '>=1.0.0')

cc = meson.get_compiler('c')

if not host_machine.system() == 'linux'
error('Due to upstream bugs, this libpfm wrap does not support building for any platform other than Linux')
endif

if not cc.has_header('unistd.h')
error('libpfm does not support building without POSIX headers')
endif
if host_machine.system() == 'linux' and not cc.has_header('sys/prctl.h')
error('libpfm does not support building for Linux without Linux headers')
endif

m_dep = cc.find_library('m', required: false)
rt_dep = cc.find_library('rt', required: false)
threads_dep = dependency('threads')
curses_dep = dependency('curses', required: false, disabler: true)

add_project_arguments(
cc.get_supported_arguments('-Wno-unused-parameter'),
language: 'c',
)

if get_option('buildtype').contains('debug')
add_project_arguments('-DCONFIG_PFMLIB_DEBUG', language: 'c')
endif

if host_machine.system() == 'linux'
add_project_arguments('-DCONFIG_PFMLIB_OS_LINUX', language: 'c')
elif host_machine.system() == 'windows'
add_project_arguments('-DPFMLIB_WINDOWS', language: 'c')
endif

# Define __WORDSIZE on platforms that don't always #define it, like Musl libc.
# This isn't completely accurate but is close enough for practical purposes.
if not cc.compiles('#include <unistd.h>\nstatic int x = __WORDSIZE;')
add_project_arguments(
'-D__WORDSIZE=@0@'.format(cc.sizeof('void*') * 8),
language: 'c',
)
endif

subdir('include')
subdir('lib')
subdir('tests')
subdir('examples')
if host_machine.system() == 'linux'
subdir('perf_examples')
endif
Loading

0 comments on commit 7e0f3c6

Please sign in to comment.