Commit Graph

367 Commits

Author SHA1 Message Date
Warner Losh
364c014d9b cross-tools: fts has different types for cmp routine
fts has different types for its compare rotuine. Other systems, not
4.4BSD based, have a non-const version. Before we tested against
__GLIBC__, but now we test against __linux__ because that's Linux's API
and musl doesn't define __GLIBC__.

In addition, link against libftl on this platform since musl doesn't
include ftl routines in libc, but rather in libftl.

Co-authored-by:		Val Packett <val@packett.cool>
Sponsored by:		Netflix
Pull Request:		https://github.com/freebsd/freebsd-src/pull/1066
Reviewed by:		val_packett.cool
Differential Revision:	https://reviews.freebsd.org/D45349
2024-05-26 11:38:30 -06:00
Brooks Davis
6729e8a40b libpmc: remove tautological assert
gcc13 whines about this assert than an unsigned integer is >= 0.

Reviewed by:	luporl
Fixes:		b48a2770d4 powerpc64: add Power8 and Power9 PMCs
Differential Revision:	https://reviews.freebsd.org/D45232
2024-05-23 17:27:37 +01:00
Alexander Motin
278d695094 libpmc: Import AMD Zen 4 PMU events
MFC after:	1 week
2024-04-20 11:54:04 -04:00
Jessica Clarke
d8c84215d7 jevents: Fix bootstrapping on macOS with Clang 16 / Apple Clang 15
macOS, like Linux, does not include an outer const qualifier for its
fts_open callback arguments, so -Wincompatible-function-pointer-types
also picks this up and breaks the build now Clang 16 makes it an error
by default. Extend the existing Linux support to fix this.

MFC after:	1 week
2024-03-16 01:50:20 +00:00
Alex Richardson
60e845ceef jevents: fix bootstrapping on Linux with Clang 16
The glibc fts_open() callback type does not have the second const
qualifier and it appears that Clang 16 errors by default for mismatched
function pointer types. Add an ifdef to handle this case.

Reviewed By:	imp, emaste
Differential Revision: https://reviews.freebsd.org/D43000
2023-12-11 21:14:56 -08:00
Warner Losh
a2f733abcf lib: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:23:59 -07:00
Stephen J. Kiernan
e5b786625f dirdeps: Add missing dependency files
Some leaf directories were missing Makefile.depend files or needed
architecture-specific Makefile.depend.* files.
2023-10-29 17:08:29 -04:00
Mitchell Horne
b293497146 pmc.amd(3): rename from pmc.k8(3)
This is the first step in recognizing that the K8 microarchitecture
represents a small and aged subset of AMD CPUs supported by this class.
Future changes will update the code and documentation details to better
reflect this.

Keep the old filename as an alias.

Reviewed by:	jkoshy
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41279
2023-10-18 15:05:45 -03:00
Mitchell Horne
82d6d46d0d pmc: remove last bits of AMD K7 CPU support
This includes event definitions from sys/pmc_events.h, definitions from
sys/pmc.h, and the man pages.

Reviewed by:	jkoshy
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D41275
2023-10-18 15:05:45 -03:00
Mitchell Horne
c190fb35f3 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
2023-09-03 13:27:21 -07:00
Mitchell Horne
45dcc17e2f libpmc: make pmc_pmu_pmcallocate() machine-independent
Have it call the platform-dependent version. For better layering, move
the reset logic inside the new function. This is mainly to facilitate an
upcoming change.

Reviewed by:	jkoshy
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40752
2023-09-03 13:27:05 -07:00
Warner Losh
fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh
2a63c3be15 Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:29 -06:00
Warner Losh
42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Warner Losh
b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Mitchell Horne
398fb4a592 pmclog(3): Drop .Ud
This API is stable and should not be advertised as "currently under
development".

MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2023-07-10 14:30:03 -03:00
Mitchell Horne
ba84e87055 pmc: clean up remaining Pentium man page references
These have been removed.

Fixes:	d78896e46f ("pmc(3): remove Pentium-related man pages...")
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2023-06-24 16:30:00 -03:00
John Baldwin
8144db85fe libpmc: Define a PMCLOG_SKIP32 helper macro to skip over a 32-bit field.
This replaces a set but unused noop variable with a more explicit
macro.

Reviewed by:	jkoshy, mhorne
Differential Revision:	https://reviews.freebsd.org/D40651
2023-06-20 12:31:43 -07:00
Mitchell Horne
3977781b98 pmc: clarify and strengthen statements about API/ABI
- Make it clear that applications are not only encouraged to use the
  pmc(3) library, but use of the hwpmc(4) interface directly is a
  use-case we do not support
- Move the COMPATIBILITY section above PROGRAMMING API in hwpmc(4)
- Drop statements about the driver and library being "under development"

Reviewed by:	jkoshy, emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40543
2023-06-16 13:44:54 -03:00
Jessica Clarke
21f7397a61 libpmc: Handle PMCALLOCATE log with PMC code on PMU event system
On an arm64 system that reports as a Cortex A72 r0p3, running

  pmcstat -P CPU_CYCLES command

works, but

  pmcstat -P cpu-cycles command

does not. This is because the former uses the PMU event from the JSON
source, resulting in pl_event in the log event being a small index
(here, 5) into the generated events table, whilst the latter does not
match any of the JSON events and falls back on PMC's own tables, mapping
it to the PMC event 0x14111, i.e. PMC_EV_ARMV8_EVENT_11H. Then, when
libpmc gets the PMCALLOCATE event, it tries to use the event as an index
into the JSON-derived table, but doing so only makes sense for the
former, whilst for the latter it will go way out of bounds and either
read junk (which may trigger the != NULL assertion) or segfault. As far
as I can tell we don't have anything lying around to tell us which of
the two cases we're in, but we can exploit the fact that the first
0x1000 PMC event codes are reserved, and that none of our PMU events
tables reach that number of entries yet.

PR:		268857
Reviewed by:	mhorne
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D39592
2023-06-07 15:24:29 +01:00
Mitchell Horne
be75e57854 libpmc: expand PMC_OP* defines
When performing the syscall, specify the full name of the desired
operation. This improves grep-ability.

No functional change.

Reviewed by:	jkoshy
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D40334
2023-06-01 15:20:13 -03:00
Jessica Clarke
94426d21bf pmc: Rework PROCEXEC event to support PIEs
Currently the PROCEXEC event only reports a single address, entryaddr,
which is the entry point of the interpreter in the typical dynamic case,
and used solely to calculate the base address of the interpreter. For
PDEs this is fine, since the base address is known from the program
headers, but for PIEs the base address varies at run time based on where
the kernel chooses to load it, and so pmcstat has no way of knowing the
real address ranges for the executable. This was less of an issue in the
past since PIEs were rare, but now they're on by default on 64-bit
architectures it's more of a problem.

To solve this, pass through what was picked for et_dyn_addr by the
kernel, and use that as the offset for the executable's start address
just as is done for everything in the kernel. Since we're changing this
interface, sanitise the way we determine the interpreter's base address
by passing it through directly rather than indirectly via the entry
point and having to subtract off whatever the ELF header's e_entry is
(and anything that wants the entry point in future can still add that
back on as needed; this merely changes the interface to directly provide
the underlying variables involved).

This will be followed up by a bump to the pmc major version.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D39595
2023-05-31 00:20:36 +01:00
Jessica Clarke
8e63e787ab pmc: Initialise and check the pm_flags field for CONFIGURELOG
Whilst the former is not breaking, the latter is, and so this will be
followed by a bump to the pmc major version. This will allow the flags
to actually be usable in future, as otherwise we cannot distinguish
uninitialised stack junk from a deliberately-initialised value.

Reviewed by:	jhb, mhorne
Differential Revision:	https://reviews.freebsd.org/D40049
2023-05-31 00:15:24 +01:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Simon J. Gerraty
d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Joseph Koshy
f401d82ef7
pmc: Keep a list sorted.
Approved by:	gnn (mentor)
Differential Revision: https://reviews.freebsd.org/D39439
2023-04-05 20:09:28 +01:00
John Baldwin
c6b3f47fed libpmc: Use LIB_CXX instead of explicit LDADD to link a C++ library.
This uses the C++ compiler as the linker instead of the C compiler
letting the compiler driver pick the right libraries.  This is a no-op
on main and stable/13 but matters for stable/12 where the current
logic breaks for external GCC since it tries to use a non-existent
libstdc++.

Reviewed by:	emaste
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39197
2023-03-23 09:31:58 -07:00
Pau Amma
5faf9f4dff Refresh CPU types and classes from sys/sys/pmc.h.
While here, fix a few nits.

Inspired by reviewing D35342.

Sources for trademark info
- https://www.arm.com/company/policies/trademarks (no Arm8, curiously)
- https://www.ibm.com/legal/copytrade?mhsrc=ibmsearch_a&mhq=trademark

Reviewed by:	carlavilla, luporl, mhorne
Approved by:	carlavilla (mentor), mhorne (src)
Differential Revision: https://reviews.freebsd.org/D35344
2023-01-18 21:50:49 +01:00
Ed Maste
e92d692345 libpmc: remove unused auto_ptr warning suppression
libpmc used -Wno-deprecated-declarations to silence warnings about usage
of deprecated std::auto_ptr, but there is (now) now use of auto_ptr in
libpmc.

Reviewed by:	mhorne
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D37576
2022-12-02 18:52:30 -05:00
Jessica Clarke
91a84eb5ba pmc.sandybridge(3): Fix a few EVENT_ vs Event inconsistencies
Every event other than these four is listed as Event X, Umask Y; fix
these to conform to that style.
2022-10-11 00:50:58 +01:00
Toomas Soome
1f5679569d libpmc: pmc_init() should avoid overflowing pmc_class_table
Use calloc().

Walk the class list we get from kernel, so we will not add something
the kernel does not know about.

Avoid picking headers from /usr/include.

Differential Revision:	https://reviews.freebsd.org/D36401
2022-09-05 15:23:20 +03:00
Gordon Bergling
f0d4c2afd6 pmc(3): Correct some typos in event descriptions
- s/occured/occurred/
- s/the the/the/

MFC after:	3 days
2022-09-04 12:52:38 +02:00
Aleksandr Rybalko
cedbdaf0e5 Add pmc.dmc-620(3) man page.
Reviewed by:	pauamma
Sponsored By:	Ampere Computing
Differential Revision:	https://reviews.freebsd.org/D32669
2022-07-26 11:17:50 +03:00
Aleksandr Rybalko
da4e1e319c Add the Arm CoreLink CMN-600 Coherent Mesh Network Controller PMU driver man page.
Add the Arm CoreLink CMN-600 Coherent Mesh Network Controller PMU driver man page.

Reviewed by:	pauamma_gundo.com
Sponsored By: ARM
Differential Revision: https://reviews.freebsd.org/D32335
2022-07-10 12:26:55 +03:00
Mitchell Horne
6f50b73ee5 libpmc: add armv8 pmu-event aliases
These are all "standard microarchitectural events", which in theory are
supported by every ARMv8 processor. In practice, it depends on the
pmu-event definitions being complete and accurate, which they are not
for every processor. Still, these aliases should be functional on the
majority of systems.

PR:		254532
Reported by:	emaste
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35550
2022-07-06 14:32:21 -03:00
Mitchell Horne
9d97138e2d libpmc: import updated pmu-events for arm64
Thanks to the recently updated import of the jevents utility by mav@, we
can now compile the latest version of these event definitions. This
should support a wider set of common ARMv8 processors, for example, the
Cortex-A72 in the Raspberry Pi 4.

This brings this folder in sync with Linux commit 62e6eb8d5454.

Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35549
2022-07-06 14:32:21 -03:00
Gordon Bergling
a4adfaf712 pmc(3): Fix a common typo in a description
- s/transistioned/transitioned/

MFC after:	3 days
2022-07-03 13:53:01 +02:00
Bjoern A. Zeeb
dd2fd62184 libpmc: attempt to fix the build
Try to fix the build (blindly) after e3572eb654.
I had missed the missing #ifdef in the review.  Hope that's all it takes.
2022-06-26 23:14:56 +00:00
Aleksandr Rybalko
e3572eb654 Allocate event for DMC-620 and CMN-600 controllers PMU. Add events supported by DMC-620 and CMN-600 controllers PMU.
Allocate event for DMC-620 and CMN-600 controllers PMU.
Add events supported by DMC-620 and CMN-600 controllers PMU.

Reviewed by: bz
Sponsored By: ARM
Sponsored By: Ampere Computing
Differential Revision: https://reviews.freebsd.org/D35609
2022-06-26 21:52:26 +03:00
Aleksandr Rybalko
b6e28991bf System wide and NUMA domain wide counters support. PMC classes for ARM DMC-620 and CMN-600.
Add support for system wide and NUMA domain wide counters support.
Add 3 new PMC classes for ARM DMC-620 and CMN-600 controllers PMU.

Reviewed by:	mhorne
Sponsored By:	ARM
Sponsored By:	Ampere Computing
Differential Revision: https://reviews.freebsd.org/D35342
2022-06-26 08:31:03 +03:00
Alexander Motin
e144cd92bb libpmc: Prefer fixed counters in Intel event aliases.
It is recommended by Intel to use fixed counters when possible to
leave programmable ones for different events.

This fixes `pmc stat`, which tries to count 6 events same time, while
many Intel CPUs have only 4 programmable counters.

MFC after:	1 month
2022-06-02 15:17:13 -04:00
Alexander Motin
037dd0a967 libpmc: Fix INVERT flag mapping for both Intel and AMD.
Looks like somebody's trivial copy/paste bug.

MFC after:	1 month
2022-05-31 00:04:43 -04:00
Alexander Motin
73b7b181e6 libpmc: Disable hardcoding of Intel fixed counters.
Intel json's now have pretty reasonable fixed counters representation
via event=0 and umask.  Hardcoded values create more confusion than fix.

MFC after:	1 month
2022-05-30 20:05:15 -04:00
Alexander Motin
62ff619dcc libpmc: jevents: Sync with the latest Linux kernel.
commit f4df0dbbe62ee8e4405a57b27ccd54393971c773
Date:   Wed May 25 22:04:10 2022 +0800

MFC after:	1 month
2022-05-30 14:10:21 -04:00
Alexander Motin
51f329660f Revert "libpmc: jevents: Partial style(9) pass"
This file is shared with Linux.  Having local style patches does not
help with updating it.

This reverts commit 3ea691c261.
2022-05-30 14:10:21 -04:00
Alexander Motin
18054d0220 libpmc: Another update of x86 event definitions.
MFC after:	1 month
2022-05-26 22:07:42 -04:00
Gordon Bergling
5c4aa62572 pmc(3): Fix a common typo in json descriptions
- s/from from/from/

MFC after:	3 days
2022-03-28 19:32:21 +02:00
John Baldwin
6bb7ba4aa1 arm64 hwpmc: Support restricting counters to user or kernel mode.
Support the "usr" and "os" qualifiers on arm64 events to restrict
event counting to either usermode or the kernel, respectively.  If
neither qualifier is given, events are counted in both.

Reviewed by:	emaste
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D34527
2022-03-11 11:29:45 -08:00