diff --git a/libpfm-4.12.0.tar.gz b/libpfm-4.12.0.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..cb99f5830b52bd9ccaa80261ddde003902cbe135 Binary files /dev/null and b/libpfm-4.12.0.tar.gz differ diff --git a/libpfm-kernel518.patch b/libpfm-kernel518.patch new file mode 100644 index 0000000000000000000000000000000000000000..67cc26050553313e93c09938dd8fb9c29f54446f --- /dev/null +++ b/libpfm-kernel518.patch @@ -0,0 +1,266 @@ +commit 8c606bc2f2d186c2797d9f013283c9150f594f93 +Author: Masahiko, Yamada +Date: Tue Sep 20 14:04:31 2022 +0900 + + update perf_event.h to Linux 5.18 + + The perf_events interface for directly accessing PMU registers + from userspace for arm64 has been formally implemented in the + kernel v5.18. + + Update perf_event.h header used to build perf_event based examples. + + Signed-off-by: Masahiko Yamada + +diff --git a/include/perfmon/perf_event.h b/include/perfmon/perf_event.h +index 81e02a2..a3bbb14 100644 +--- a/include/perfmon/perf_event.h ++++ b/include/perfmon/perf_event.h +@@ -143,7 +143,12 @@ enum perf_event_sample_format { + PERF_SAMPLE_TRANSACTION = 1U << 17, + PERF_SAMPLE_REGS_INTR = 1U << 18, + PERF_SAMPLE_PHYS_ADDR = 1U << 19, +- PERF_SAMPLE_MAX = 1U << 19, ++ PERF_SAMPLE_AUX = 1U << 20, ++ PERF_SAMPLE_CGROUP = 1U << 21, ++ PERF_SAMPLE_DATA_PAGE_SIZE = 1U << 22, ++ PERF_SAMPLE_CODE_PAGE_SIZE = 1U << 23, ++ PERF_SAMPLE_WEIGHT_STRUCT = 1U << 24, ++ PERF_SAMPLE_MAX = 1U << 25, + }; + enum { + PERF_TXN_ELISION = (1 << 0), +@@ -180,6 +185,7 @@ enum perf_branch_sample_type_shift { + PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT = 14, + PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT = 15, + PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT = 16, ++ PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT = 17, + + PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */ + }; +@@ -204,6 +210,7 @@ enum perf_branch_sample_type { + PERF_SAMPLE_BRANCH_NO_FLAGS = 1U << PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT, + PERF_SAMPLE_BRANCH_NO_CYCLES = 1U << PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT, + PERF_SAMPLE_BRANCH_TYPE_SAVE = 1U << PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT, ++ PERF_SAMPLE_BRANCH_HW_INDEX = 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT, + + PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT, + }; +@@ -232,6 +239,8 @@ enum perf_event_read_format { + /* add: sample_stack_user */ + #define PERF_ATTR_SIZE_VER4 104 /* add: sample_regs_intr */ + #define PERF_ATTR_SIZE_VER5 112 /* add: aux_watermark */ ++#define PERF_ATTR_SIZE_VER6 120 /* add: aux_sample_size */ ++#define PERF_ATTR_SIZE_VER7 128 /* add: sig_data */ + + + /* +@@ -289,7 +298,16 @@ typedef struct perf_event_attr { + context_switch : 1, + write_backward : 1, + namespaces : 1, +- __reserved_1 : 35; ++ ksymbol : 1, ++ bpf_event : 1, ++ aux_output : 1, ++ cgroup : 1, ++ text_poke : 1, ++ build_id : 1, ++ inherit_thread : 1, ++ remove_on_exec : 1, ++ sigtrap : 1, ++ __reserved_1 : 26; + + union { + uint32_t wakeup_events; +@@ -311,7 +329,11 @@ typedef struct perf_event_attr { + int32_t clockid; + uint64_t sample_regs_intr; + uint32_t aux_watermark; +- uint32_t __reserved_2; ++ uint16_t sample_max_stack; ++ uint16_t __reserved_2; ++ uint32_t aux_sample_size; ++ uint32_t __reserved_3; ++ uint64_t sig_data; + } perf_event_attr_t; + + struct perf_branch_entry { +@@ -340,19 +362,32 @@ struct perf_branch_stack { + struct perf_branch_entry entries[0]; + }; + ++/* ++ * Structure used by below PERF_EVENT_IOC_QUERY_BPF command ++ * to query bpf programs attached to the same perf tracepoint ++ * as the given perf event. ++ */ ++struct perf_event_query_bpf { ++ uint32_t ids_len; ++ uint32_t prog_cnt; ++ uint32_t ids[0]; ++}; ++ + /* + * perf_events ioctl commands, use with event fd + */ +-#define PERF_EVENT_IOC_ENABLE _IO ('$', 0) +-#define PERF_EVENT_IOC_DISABLE _IO ('$', 1) +-#define PERF_EVENT_IOC_REFRESH _IO ('$', 2) +-#define PERF_EVENT_IOC_RESET _IO ('$', 3) +-#define PERF_EVENT_IOC_PERIOD _IOW('$', 4, uint64_t) +-#define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5) +-#define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *) +-#define PERF_EVENT_IOC_ID _IOR('$', 7, uint64_t *) +-#define PERF_EVENT_IOC_SET_BPF _IOW('$', 8, uint32_t) +-#define PERF_EVENT_IOC_PAUSE_OUTPUT _IOW('$', 9, __u32) ++#define PERF_EVENT_IOC_ENABLE _IO ('$', 0) ++#define PERF_EVENT_IOC_DISABLE _IO ('$', 1) ++#define PERF_EVENT_IOC_REFRESH _IO ('$', 2) ++#define PERF_EVENT_IOC_RESET _IO ('$', 3) ++#define PERF_EVENT_IOC_PERIOD _IOW('$', 4, uint64_t) ++#define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5) ++#define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *) ++#define PERF_EVENT_IOC_ID _IOR('$', 7, uint64_t *) ++#define PERF_EVENT_IOC_SET_BPF _IOW('$', 8, uint32_t) ++#define PERF_EVENT_IOC_PAUSE_OUTPUT _IOW('$', 9, __u32) ++#define PERF_EVENT_IOC_QUERY_BPF _IOWR('$', 10, struct perf_event_query_bpf *) ++#define PERF_EVENT_IOC_MODIFY_ATTRIBUTES _IOW('$', 11, struct perf_event_attr *) + + /* + * ioctl() 3rd argument +@@ -381,7 +416,8 @@ struct perf_event_mmap_page { + cap_usr_rdpmc:1, + cap_user_time:1, + cap_user_time_zero:1, +- cap_____res:59; ++ cap_user_time_short:1, ++ cap_____res:58; + } SWIG_NAME(rdmap_cap_s); + } SWIG_NAME(rdmap_cap_u); + uint16_t pmc_width; +@@ -391,7 +427,10 @@ struct perf_event_mmap_page { + + uint64_t time_zero; + uint32_t size; +- uint8_t __reserved[118*8+4]; ++ uint32_t __reserved_1; ++ uint64_t time_cycles; ++ uint64_t time_mask; ++ uint8_t __reserved[116*8]; + + uint64_t data_head; + uint64_t data_tail; +@@ -450,9 +489,38 @@ enum perf_event_type { + PERF_RECORD_SWITCH = 14, + PERF_RECORD_SWITCH_CPU_WIDE = 15, + PERF_RECORD_NAMESPACES = 16, ++ PERF_RECORD_KSYMBOL = 17, ++ PERF_RECORD_BPF_EVENT = 18, ++ PERF_RECORD_CGROUP = 19, ++ PERF_RECORD_TEXT_POKE = 20, ++ PERF_RECORD_AUX_OUTPUT_HW_ID = 21, + PERF_RECORD_MAX + }; + ++enum perf_record_ksymbol_type { ++ PERF_RECORD_KSYMBOL_TYPE_UNKNOWN = 0, ++ PERF_RECORD_KSYMBOL_TYPE_BPF = 1, ++ /* ++ * Out of line code such as kprobe-replaced instructions or optimized ++ * kprobes or ftrace trampolines. ++ */ ++ PERF_RECORD_KSYMBOL_TYPE_OOL = 2, ++ PERF_RECORD_KSYMBOL_TYPE_MAX /* non-ABI */ ++}; ++ ++#define PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER (1 << 0) ++ ++enum perf_bpf_event_type { ++ PERF_BPF_EVENT_UNKNOWN = 0, ++ PERF_BPF_EVENT_PROG_LOAD = 1, ++ PERF_BPF_EVENT_PROG_UNLOAD = 2, ++ PERF_BPF_EVENT_MAX, /* non-ABI */ ++}; ++ ++#define PERF_MAX_STACK_DEPTH 127 ++#define PERF_MAX_CONTEXTS_PER_STACK 8 ++ ++ + enum perf_callchain_context { + PERF_CONTEXT_HV = (uint64_t)-32, + PERF_CONTEXT_KERNEL = (uint64_t)-128, +@@ -465,8 +533,16 @@ enum perf_callchain_context { + PERF_CONTEXT_MAX = (uint64_t)-4095, + }; + +-#define PERF_AUX_FLAG_TRUNCATED 0x01 +-#define PERF_AUX_FLAG_OVERWRITE 0x02 ++#define PERF_AUX_FLAG_TRUNCATED 0x01 ++#define PERF_AUX_FLAG_OVERWRITE 0x02 ++#define PERF_AUX_FLAG_PARTIAL 0x04 ++#define PERF_AUX_FLAG_COLLISION 0x08 ++#define PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK 0xff00 ++ ++/* CoreSight PMU AUX buffer formats */ ++#define PERF_AUX_FLAG_CORESIGHT_FORMAT_CORESIGHT 0x0000 ++#define PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW 0x0100 ++ + + /* + * flags for perf_event_open() +@@ -544,12 +620,17 @@ perf_event_open( + union perf_mem_data_src { + uint64_t val; + struct { +- uint64_t mem_op:5, /* type of opcode */ +- mem_lvl:14, /* memory hierarchy level */ +- mem_snoop:5, /* snoop mode */ +- mem_lock:2, /* lock instr */ +- mem_dtlb:7, /* tlb access */ +- mem_rsvd:31; ++ uint64_t mem_op:5, /* type of opcode */ ++ mem_lvl:14, /* memory hierarchy level */ ++ mem_snoop:5, /* snoop mode */ ++ mem_lock:2, /* lock instr */ ++ mem_dtlb:7, /* tlb access */ ++ mem_lvl_num:4, /* memory hierarchy level number */ ++ mem_remote:1, /* remote */ ++ mem_snoopx:2, /* snoop mode, ext */ ++ mem_blk:3, /* access blocked */ ++ mem_hops:3, /* hop level */ ++ mem_rsvd:18; + }; + }; + +@@ -590,7 +671,8 @@ union perf_mem_data_src { + #define PERF_MEM_SNOOP_SHIFT 19 + + #define PERF_MEM_SNOOPX_FWD 0x01 /* forward */ +-#define PERF_MEM_SNOOPX_SHIFT 37 ++/* 1 free */ ++#define PERF_MEM_SNOOPX_SHIFT 38 + + /* locked instruction */ + #define PERF_MEM_LOCK_NA 0x01 /* not available */ +@@ -607,6 +689,20 @@ union perf_mem_data_src { + #define PERF_MEM_TLB_OS 0x40 /* OS fault handler */ + #define PERF_MEM_TLB_SHIFT 26 + ++/* Access blocked */ ++#define PERF_MEM_BLK_NA 0x01 /* not available */ ++#define PERF_MEM_BLK_DATA 0x02 /* data could not be forwarded */ ++#define PERF_MEM_BLK_ADDR 0x04 /* address conflict */ ++#define PERF_MEM_BLK_SHIFT 40 ++ ++/* hop level */ ++#define PERF_MEM_HOPS_0 0x01 /* remote core, same node */ ++#define PERF_MEM_HOPS_1 0x02 /* remote node, same socket */ ++#define PERF_MEM_HOPS_2 0x03 /* remote socket, same board */ ++#define PERF_MEM_HOPS_3 0x04 /* remote board */ ++/* 5-7 available */ ++#define PERF_MEM_HOPS_SHIFT 43 ++ + #define PERF_MEM_S(a, s) \ + (((u64)PERF_MEM_##a##_##s) << PERF_MEM_##a##_SHIFT) + diff --git a/libpfm-python3-setup.patch b/libpfm-python3-setup.patch new file mode 100644 index 0000000000000000000000000000000000000000..f43187a6ea4f3d3e0055dca233fc24c95a2c4215 --- /dev/null +++ b/libpfm-python3-setup.patch @@ -0,0 +1,10 @@ +diff --git a/python/setup.py b/python/setup.py +index eda8fa5..dff0f27 100755 +--- a/python/setup.py ++++ b/python/setup.py +@@ -1,4 +1,4 @@ +-#!/usr/bin/env python ++#!/usr/bin/env python3 + + from distutils.core import setup, Extension + from distutils.command.install_data import install_data diff --git a/libpfm.spec b/libpfm.spec new file mode 100644 index 0000000000000000000000000000000000000000..4c7654056426e35c3f852f2c4ff07f83de52bf17 --- /dev/null +++ b/libpfm.spec @@ -0,0 +1,140 @@ +%define anolis_release 1 + +# Default to no static libraries +%{!?with_static: %global with_static 1} +%bcond_without python +%if %{with python} +%define python_sitearch %(python3 -c "from distutils.sysconfig import get_python_lib; print (get_python_lib(1))") +%define python_prefix %(python3 -c "import sys; print (sys.prefix)") +%{?filter_setup: +%filter_provides_in %{python3_sitearch}/perfmon/.*\.so$ +%filter_setup +} +%endif + +Name: libpfm +Version: 4.12.0 +Release: %{anolis_release}%{?dist} +Summary: Library to encode performance events for use by perf tool +License: MIT +URL: http://perfmon2.sourceforge.net/ +Source0: http://sourceforge.net/projects/perfmon2/files/libpfm4/%{name}-%{version}.tar.gz +Patch0: libpfm-python3-setup.patch +Patch1: libpfm-kernel518.patch + +BuildRequires: make +BuildRequires: gcc +%if %{with python} +BuildRequires: python3 +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: swig +%endif + +%description +libpfm4 is a library to help encode events for use with operating system +kernels performance monitoring interfaces. The current version provides support +for the perf_events interface available in upstream Linux kernels since v2.6.31. + +%package devel +Summary: Development library to encode performance events for perf_events based tools +Requires: %{name} = %{version}-%{release} + +%description devel +Development library and header files to create performance monitoring +applications for the perf_events interface. + +%if %{with_static} +%package static +Summary: Static library to encode performance events for perf_events based tools +Requires: %{name} = %{version}-%{release} + +%description static +Static version of the libpfm library for performance monitoring +applications for the perf_events interface. +%endif + +%if %{with python} +%package -n python3-libpfm +%{?python_provide:%python_provide python3-libpfm} +Provides: %{name}-python = %{version}-%{release} +Provides: %{name}-python = %{version}-%{release} +Obsoletes: %{name}-python < %{version}-%{release} +Summary: Python bindings for libpfm and perf_event_open system call +Requires: %{name} = %{version}-%{release} + +%description -n python3-libpfm +Python bindings for libpfm4 and perf_event_open system call. +%endif + +%package doc +Summary: Documentation files for %{name} +Requires: %{name} = %{EVR} +BuildArch: noarch + +%description doc +The %{name}-doc package contains documentation files for %{name}. + +%prep +%setup -q +%patch0 -p1 -b .python3 +%patch1 -p1 -b .kernel518 + +%build +%if %{with python} +%global python_config CONFIG_PFMLIB_NOPYTHON=n +%else +%global python_config CONFIG_PFMLIB_NOPYTHON=y +%endif +%make_build %{python_config} \ + OPTIM="%{optflags}" LDFLAGS="%{build_ldflags}" + +%install +rm -rf $RPM_BUILD_ROOT + +%if %{with python} +%global python_config CONFIG_PFMLIB_NOPYTHON=n PYTHON_PREFIX=$RPM_BUILD_ROOT/%{python_prefix} +%else +%global python_config CONFIG_PFMLIB_NOPYTHON=y +%endif + +make \ + PREFIX=$RPM_BUILD_ROOT%{_prefix} \ + LIBDIR=$RPM_BUILD_ROOT%{_libdir} \ + %{python_config} \ + LDCONFIG=/bin/true \ + install + +%if !%{with_static} +rm $RPM_BUILD_ROOT%{_libdir}/lib*.a +%endif + +%generate_compatibility_deps + +%files +%{_libdir}/lib*.so.* +%dir %{abidir} +%{abidir}/_perfmon_int.cpython-310-*-linux-gnu.dump +%{abidir}/libpfm.dump + +%files devel +%{_includedir}/* +%{_mandir}/man3/* +%{_libdir}/lib*.so + +%if %{with_static} +%files static +%{_libdir}/lib*.a +%endif + +%if %{with python} +%files -n python3-libpfm +%{python3_sitearch}/* +%endif + +%files doc +%doc README + +%changelog +* Mon Mar 27 2023 Yuanhong Peng - 4.12.0-1 +- Init from upstream