opnsense-src/sys
Mitchell Horne 5adb91c729 pmc: better distinguish pmu-events allocation path
Background:

The pm_ev field of struct pmc_op_pmcallocate and struct pmc
traditionally contains the index of the chosen event, corresponding to
the __PMC_EVENTS array in pmc_events.h. This is a static list of events,
maintained by FreeBSD.

In the usual case, libpmc translates the user supplied event name
(string) into the pm_ev index, which is passed as an argument to the
allocation syscall. On the kernel side, the allocation method for the
relevant hwpmc class translates the given index into the event code that
will be written to an event selection register.

In 2018, a new source of performance event definitions was introduced:
the pmu-events json files, which are maintained by the Linux kernel. The
result was better coverage for newer Intel processors with a reduced
maintenance burden for libpmc/hwpmc. Intel and AMD CPUs were
unconditionally switched to allocate events from pmu-events instead of
the traditional scheme (959826ca1b, 81eb4dcf9e).

Under the pmu-events scheme, the pm_ev field contains an index
corresponding to the selected event from the pmu-events table, something
which the kernel has no knowledge of. The configuration for the
performance counting registers is instead passed via class-dependent
fields (struct pmc_md_op_pmcallocate).

In 2021 I changed the allocation logic so that it would attempt to
pull from the pmu-events table first, and fall-back to the traditional
method (dfb4fb4116). Later, pmu-events support for arm64 and power8
CPUs was added (28dd6730a5 and b48a2770d4).

The problem that remains is that the pm_ev field is overloaded, without
a definitive way to determine whether the event allocation came from the
pmu-events table or FreeBSD's statically-defined PMC events. This
resulted in a recent fix, 21f7397a61.

Change:

To disambiguate these two supported but separate use-cases, add a new
flag, PMC_F_EV_PMU, to be set as part of the allocation, indicating that
the event index came from pmu-events.

This is useful in two ways:
 1. On the kernel side, we can validate the syscall arguments better.
    Some classes support only the traditional event scheme (e.g.
    hwpmc_armv7), while others support only the pmu-events method (e.g.
    hwpmc_core for Intel). We can now check for this. The hwpmc_arm64
    class supports both methods, so the new flag supersedes the existing
    MD flag, PM_MD_EVENT_RAW.

 2. The flag will be tracked in struct pmc for the duration of its
    lifetime, meaning it is communicated back to userspace. This allows
    libpmc to perform the reverse index-to-event-name translation
    without speculating about the meaning of the index value.

Adding the flag is a backwards-incompatible ABI change. We recently
bumped the major version of the hwpmc module, so this breakage is
acceptable.

Reviewed by:	jkoshy
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40753

(cherry picked from commit c190fb35f35cc163b61e582a49115680b0d49dcc)
2023-09-11 12:19:58 -07:00
..
amd64 release: update stable/14 following branching from main 2023-08-24 19:07:33 -04:00
arm release: update stable/14 following branching from main 2023-08-24 19:07:33 -04:00
arm64 pmc: better distinguish pmu-events allocation path 2023-09-11 12:19:58 -07:00
bsm timerfd: Move implementation from linux compat to sys/kern 2023-08-24 14:28:56 -06:00
cam cam/scsi_da: Bump deprecation one release. 2023-08-23 22:34:41 -06:00
cddl sys: Remove $FreeBSD$: one-line catalog 2023-08-16 11:55:22 -06:00
compat linux(4): Return ENOTSUP from listxattr instead of EPERM 2023-09-11 14:59:38 +03:00
conf release: update __FreeBSD_version after branching releng/14.0 2023-09-07 20:06:07 -04:00
contrib zfs: merge openzfs/zfs@e96fbdba3 (zfs-2.2-release) into stable/14 2023-09-11 09:24:58 +02:00
crypto ossl: Update the generated assembly files from OpenSSL 3.0. 2023-09-08 13:55:44 -07:00
ddb sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
dev pmc: better distinguish pmu-events allocation path 2023-09-11 12:19:58 -07:00
dts sys: Remove $FreeBSD$: one-line bare tag 2023-08-16 11:55:17 -06:00
fs vfs: copy_file_range() between multiple mountpoints of the same fs type 2023-09-07 09:39:40 +02:00
gdb sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
geom geom_linux_lvm: Check the offset of physical volume header 2023-08-22 17:20:10 +08:00
gnu sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
i386 release: update stable/14 following branching from main 2023-08-24 19:07:33 -04:00
isa sys: Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:54:58 -06:00
kern kthread_add(): do not allow to attach the thread to a dead or dying process 2023-09-09 11:26:33 +03:00
kgssapi sys: Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:54:58 -06:00
libkern sys: Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:54:58 -06:00
modules zfs: merge openzfs/zfs@e96fbdba3 (zfs-2.2-release) into stable/14 2023-09-11 09:24:58 +02:00
net if_vlan: Always default to 802.1q. 2023-09-07 20:28:31 +00:00
net80211 sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
netgraph sys: Remove $FreeBSD$: one-line bare tag 2023-08-16 11:55:17 -06:00
netinet mcast: fix memory leak in imf_purge() 2023-09-07 21:26:07 +02:00
netinet6 sctp: cleanup cdefs.h include 2023-08-18 15:25:34 +02:00
netipsec sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
netlink sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
netpfil pf: Access r->rpool.cur->kif under mutex protection 2023-08-24 13:05:33 +02:00
netsmb sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
nfs sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
nfsclient sys: Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:18 -06:00
nfsserver sys: Remove $FreeBSD$: one-line .h pattern 2023-08-16 11:54:18 -06:00
nlm sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
ofed ofed: mask seq_num identifier to occupy only 3 bytes 2023-08-22 16:09:13 -07:00
opencrypto sys: Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:54:58 -06:00
powerpc release: update stable/14 following branching from main 2023-08-24 19:07:33 -04:00
riscv release: update stable/14 following branching from main 2023-08-24 19:07:33 -04:00
rpc sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
security sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
sys pmc: better distinguish pmu-events allocation path 2023-09-11 12:19:58 -07:00
teken sys: Remove $FreeBSD$: two-line nroff pattern 2023-08-16 11:55:06 -06:00
tests sys: Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:54:58 -06:00
tools sys: Remove $FreeBSD$: two-line lua tag 2023-08-16 11:55:27 -06:00
ufs sys: Remove $FreeBSD$: one-line bare tag 2023-08-16 11:55:17 -06:00
vm add pmap_active_cpus() 2023-08-23 03:02:21 +03:00
x86 x86: Introduce APIC ID limit by default on AMD hardware 2023-09-04 19:08:34 -04:00
xdr sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
xen sys: Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:54:58 -06:00
Makefile sys: Remove $FreeBSD$: one-line sh pattern 2023-08-16 11:54:58 -06:00
README.md sys/README.md: Add a section for documentation 2023-08-03 11:07:41 -03:00

FreeBSD Kernel Source:

This directory contains the source files and build glue that make up the FreeBSD kernel and its modules, including both original and contributed software.

Kernel configuration files are located in the conf/ subdirectory of each architecture. GENERIC is the configuration used in release builds. NOTES contains documentation of all possible entries. LINT is a compile-only configuration used to maximize build coverage and detect regressions.

Documentation:

Source code documentation is maintained in a set of man pages, under section 9. These pages are located in share/man/man9, from the top-level of the src tree. Consult intro(9) for an overview of existing pages.

Some additional high-level documentation of the kernel is maintained in the Architecture Handbook.

Source Roadmap:

Directory Description
amd64 AMD64 (64-bit x86) architecture support
arm 32-bit ARM architecture support
arm64 64-bit ARM (AArch64) architecture support
cam Common Access Method storage subsystem - cam(4) and ctl(4)
cddl CDDL-licensed optional sources such as DTrace
conf kernel build glue
compat Linux compatibility layer, FreeBSD 32-bit compatibility
contrib 3rd-party imported software such as OpenZFS
crypto crypto drivers
ddb interactive kernel debugger - ddb(4)
fs most filesystems, excluding UFS, NFS, and ZFS
dev device drivers and other arch independent code
gdb kernel remote GDB stub - gdb(4)
geom GEOM framework - geom(4)
i386 i386 (32-bit x86) architecture support
kern main part of the kernel
libkern libc-like and other support functions for kernel use
modules kernel module infrastructure
net core networking code
net80211 wireless networking (IEEE 802.11) - net80211(4)
netgraph graph-based networking subsystem - netgraph(4)
netinet IPv4 protocol implementation - inet(4)
netinet6 IPv6 protocol implementation - inet6(4)
netipsec IPsec protocol implementation - ipsec(4)
netpfil packet filters - ipfw(4), pf(4), and ipfilter(4)
opencrypto OpenCrypto framework - crypto(7)
powerpc PowerPC/POWER (32 and 64-bit) architecture support
riscv 64-bit RISC-V architecture support
security security facilities - audit(4) and mac(4)
sys kernel headers
tests kernel unit tests
ufs Unix File System - ffs(7)
vm virtual memory system
x86 code shared by AMD64 and i386 architectures