Commit graph

367 commits

Author SHA1 Message Date
Jessica Clarke 9f22e0959b libpmc: Allow specifying explicit EVENT_xxH events on armv7 and arm64
This is useful for processors where we don't have an event table; in
those cases we default to a Cortex A8 (armv7) or Cortex A53 (arm64) in
order to attempt to provide something useful, but you're then limited to
the counters in those tables, some of which may also not be implemented
(e.g. LD/ST_RETIRED are no longer implemented in more recent cores,
replaced by LD/ST_SPEC).

Adding the raw EVENT_xxH event lists to each table ensures that you can
always request the exact events you want, regardless of what has been
detected or is known.

Reviewed by:	mhorne
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D33805
2022-02-15 16:10:34 +00:00
Mitchell Horne 99830f702d libpmc: remove mips support
Bye bye!

Reviewed by:	imp, emaste
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34083
2022-01-28 16:35:32 -04:00
Alexander Motin 52d973f52c libpmc: Update some x86 event definitions.
MFC after:	1 month
2021-11-25 11:19:26 -05:00
Mitchell Horne a20c10893e libpmc: add some AMD pmu counter aliases
Make it mostly compatible with what's defined for Intel. Except where
noted, these are defined for all of amdzen(1|2|3).

Reviewed by:	emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32162
2021-09-30 11:15:26 -03:00
Mitchell Horne 937539e0a3 libpmc: fix the 'cycles' event alias on x86
Looking for "tsc-tsc" in the pmu tables will fail every time. Instead,
make this an alias for the static TSC event defined in pmc_events.h.
This fixes 'pmcstat -s cycles' on Intel and AMD.

Reviewed by:	emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32197
2021-09-30 11:15:26 -03:00
Wojciech Macek 319b150003 pmc: intr pmc.soft(3) update
Obtained from:		Semihalf
Sponsored by:		Stormshield
Reviewed by:		mhorne
Differential revision:	https://reviews.freebsd.org/D32055
2021-09-23 06:13:58 +02:00
Mitchell Horne d78896e46f pmc(3): remove Pentium-related man pages and references
Support for Pentium events was removed completely in e92a1350b5.

Don't bump .Dd where we are just removing xrefs.

Reviewed by:	emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31423
2021-08-10 17:19:58 -03:00
Leandro Lupori 95d619a8ea hwpmc: remove static POWER8 definitions
After b48a2770d4, static POWER8 definitions became unnecessary,
as all of them (and much more) are already present in libpmc's
PMU events.

Submitted by:		Leonardo Bianconi <leonardo.bianconi@eldorado.org.br> (initial version)
Reviewed by:		kbowling, mhorne
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D31334
2021-07-29 14:52:00 -03:00
Leandro Lupori b48a2770d4 powerpc64: add Power8 and Power9 PMCs
Add support to allocate Power8 and 9 PMCs.

Submitted by:		Leonardo Bianconi <leonardo.bianconi@eldorado.org.br>
Reviewed by:		mhorne
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D31109
2021-07-26 10:27:23 -03:00
Mitchell Horne 27ea55fc65 libpmc/hwpmc: fix issues with arm64 pmu-events support
Due to a mis-merge, the changes committed to libpmc never called
pmu_parse_event(), or set pm->pm_ev. However, this field shouldn't be
used to carry the actual pmc event code anyway, as it is expected to
contain the index into the pmu event array (otherwise, it breaks event
name lookup in pmclog_get_event()). Add a new MD field,
pm_md.pm_md_config, to pass the raw event code to arm64_allocate_pmc().

Additionally, the change made to pmc_md_op_pmcallocate was incorrect, as
this is a union, not a struct. Restore the proper padding size.

Reviewed by:	luporl, ray, andrew
Fixes:		28dd6730a5 ("libpmc: enable pmu_utils on arm64")
Fixes:		8cc3815f02 ("hwpmc_arm64: accept raw event codes...")
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31221
2021-07-21 20:18:00 -03:00
Gordon Bergling 0b12932525 pmc(3): mandoc clean ups
- new sentence, new line
- tab in filled text
- unusual Xr order
- skipping paragraph macro: Pp before Ss

Reviewed by:	bcr
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31143
2021-07-12 06:28:03 +02:00
Greg V 8c2dd68caa libpmc: Import AMD Zen 3 PMU events
Reviewed by:	mav, mhorne
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D30965
2021-06-30 18:21:23 -03:00
Mitchell Horne 28dd6730a5 libpmc: enable pmu_utils on arm64
This allows supported libpmc to query/select from the pmu-events table,
which may have a more complete set of events than what we define
manually. A future update to these definitions should greatly improve
this support. The alias table is empty for now, until this future import
is complete.

Add the Foundation's copyright for recent work on this file.

Reviewed by:	ray (slightly earlier version)
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30603
2021-06-30 16:47:18 -03:00
Mitchell Horne 0024f1aa77 libpmc: make libpmc_pmu_utils.c more amenable to porting
The current version has every function stubbed out for !x86. Only two
functions (pmu_alias_get() and pmc_pmu_pmcallocate() are really platform
dependent, so reduce the width of the ifdefs and remove some of the
stubs.

Reviewed by:	ray
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30532
2021-05-31 17:39:05 -03:00
Mitchell Horne 507d68984a libpmc: limit pmu-events to 64-bit powerpc
Although currently unused, there are only pmu event definitions for
POWER8 and POWER9. There is no sense in building these on 32-bit
platforms.

Sponsored by:	The FreeBSD Foundation
2021-05-31 17:39:05 -03:00
Mitchell Horne 3864da302a libpmc: use $MACHINE_CPUARCH
This is preferred over $MACHINE_ARCH for these types of checks, although
it makes no difference for amd64 or i386. No functional change intended.

Sponsored by:	The FreeBSD Foundation
2021-05-31 17:39:05 -03:00
Mitchell Horne 689c7e7975 libpmc: always generate libpmc_events.c
The jevents build tool will create an empty table if it doesn't find any
events, so we can remove the extra $MACHINE_CPUARCH checks.

Reviewed by:	gnn, ray, emaste
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30531
2021-05-31 17:39:05 -03:00
Mitchell Horne 0c915023db libpmc: remove pe->alias
It has never been a part of upstream's struct pmu_event. The jevents
utility will not fill this field, so remove it.

Reviewed by:	gnn
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30530
2021-05-31 17:39:05 -03:00
Mitchell Horne ec66cc955b libpmc: eliminate pmc_pmu_stat_mode()
There is a single consumer, the pmc utility, that clearly has knowledge
of which counters it is expecting. Remove this function and have it
use common counter aliases instead.

Reviewed by:	gnn
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30528
2021-05-31 17:39:05 -03:00
Mitchell Horne 0092642f86 libpmc: remove unused 'isfixed' variable
Reviewed by:	gnn, emaste
MFC after:	5 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30529
2021-05-31 17:39:04 -03:00
Mitchell Horne bc1a6a9d69 libpmc: fix "instructions" alias on Intel
The typo prevents the counter from being allocated.

This fixes e.g. pmcstat -s instructions sleep 5

Reviewed by:	mizhka, gnn, ray, emaste
MFC after:	5 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30527
2021-05-31 17:38:19 -03:00
Mitchell Horne dfdc57e8aa libpmc: fall-back to kernel tables if pmu-events fails
On x86, the pmu_events table is the source of truth for finding
supported events. However, events not found there may still be present
in the kernel's static event tables. For example, the pmc.soft(3) events
will never be available from pmu-events.

Update pmc_allocate() to search the legacy event tables if
pmc_pmu_pmcallocate() fails to return a result. This allows both event
sources to be consulted before giving up, thus restoring pmc.soft(3) and
pmc.tsc(3) on x86.

Reviewed by:	emaste
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30216
2021-05-13 16:01:24 -03:00
Mitchell Horne da13ef6aa0 libpmc: remove PMC_MDEP_TABLE logic
This logic was added for handling some of the complicated relationships
between events and x86 CPU models. Since that logic has been mostly
removed from libpmc(3) in favor of pmu-events, this no longer serves
much of a purpose. Mapping CPU types to event tables is already handled
by the switch statement in pmc_init().

Reviewed by:	ray, emaste
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30196
2021-05-13 16:01:19 -03:00
Mitchell Horne 4d8d74a4f5 libpmc: remove unused PMC_MDEP_INIT_INTEL_V2
All uses of this macro were removed in e92a1350b5. Remove
cpu_has_iaf_counters as well.

Reviewed by:	ray, emaste
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30195
2021-05-13 15:56:39 -03:00
Mitchell Horne 50f6c13997 pmc_allocate(3): document the count argument
This was added in b2ca2e50b9, and serves to provide an initial value
to the PMC, eliminating the need for a second syscall via pmc_set(3).

Reviewed by:	gnn, 0mp (manpages)
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D29885
2021-04-21 17:35:03 -03:00
Alan Somers 04e34c0202 libpmc: fix linking with C programs
Revision r334749 Added some C++ code to libpmc.  It didn't change the ABI,
but it did introduce a dependency on libc++.  Nobody noticed because every
program that in the base system that uses libpmc is also C++.

Reported-by:	Dom Dwyer <dom@itsallbroken.com>
Reviewed By:	vangyzen
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D28550
2021-02-15 15:54:18 -07:00
Michal Meloun aa76f0c397 PMC: remove now orphaned PMC for INTEL XScale processors.
Support for XScale architecture has been deleted in FreeBSD 13.
2020-12-25 15:21:53 +01:00
Leandro Lupori 5cebdfc072 libpmc: add support for POWER8/9 PMCs
This change adds support for POWER8/9 performance counters.

Reviewed by:	jhibbits
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D26113
2020-11-05 16:41:28 +00:00
Gordon Bergling 3d265fce43 Fix a few mandoc issues
- skipping paragraph macro: Pp after Sh
- sections out of conventional order: Sh EXAMPLES
- whitespace at end of input line
- normalizing date format
2020-10-09 19:12:44 +00:00
Eric van Gyzen acde2586c9 Fix additional memory leak in process_mapfile
Additional Coverity detected memory leak fix.

Submitted by:	bret_ketchum@dell.com
Reported by:	Coverity
Reviewed by:	cem, emaste
MFC after:	2 weeks
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D26462
2020-09-17 18:24:51 +00:00
Andrew Turner 2a6803de1c Use MACHINE_CPUARCH when checking for arm64
Use MACHINE_CPUARCH with arm64 (aarch64) when we build code that could run
on any 64-bit Arm instruction set. This will simplify checks in downstream
consumers targeting prototype instruction sets.

The only place we check for MACHINE_ARCH == aarch64 is when building the
device tree blobs. As these are targeting current generation ISAs.

Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D26370
2020-09-14 16:12:28 +00:00
Eric van Gyzen 4644463cac libpmc: Fix memory leak in process_mapfile
Coverity detected memory leak fix.

Submitted by:	bret_ketchum@dell.com
Reported by:	Coverity
Reviewed by:	cem
MFC after:	2 weeks
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D26230
2020-08-31 16:07:40 +00:00
Andrew Turner da11e1f9ee Add support for Cortex-A76/Neoverse-N1 to hwpmc
This adds support for the Cortex-A76 and Neoverse-N1 PMU counters to pmc.

While here add more PMCR_IDCODE values and check the implementers code is
correct before setting the PMU type.

Reviewed by:	bz, emaste (looks reasonable to me)
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D25959
2020-08-12 10:17:17 +00:00
Ryan Moeller 24e337bec5 libpmc: Use known pmc_cpuid buffer size
Use the existing PMC_CPUID_LEN to size pmc_cpuid in the kernel and various
buffers for reading it in libpmc.  This avoids some extra syscalls and
malloc/frees.

While in here, use strlcpy to copy a user-provided cpuid string instead of
memcpy, to make sure we terminate the buffer.

Reviewed by:	mav
MFC after:	1 week
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D25679
2020-07-28 02:56:26 +00:00
Alex Richardson a9ea004745 Avoid rebuilding libpmc in every incremental rebuild
Generate libpmc_events.c in a temporary file first and only overwrite it
if the files are actually different.
This avoids compiling and relinking the different variants of libpmc on
every incremental build.

Reviewed By:	jhb
Differential Revision: https://reviews.freebsd.org/D24784
2020-07-15 12:07:47 +00:00
Alexander Motin 1791cad0a9 Add stepping to the kern.hwpmc.cpuid string on x86.
It follows the equivalent Linux change to be able to differentiate
skylakex and cascadelakex, sharing the same model but not stepping.

This fixes skylakex handling broken by r363144.

MFC after:	6 days
2020-07-14 18:11:05 +00:00
Alexander Motin 48daf25193 Update AMD Zen1 and add Zen2 events mapping.
MFC after:	2 weeks
2020-07-13 16:23:02 +00:00
Alexander Motin eab56f7f65 Minor textual fixes.
MFC after:	1 week
2020-07-13 14:25:25 +00:00
Alexander Motin e4e0417440 Map family 0x5F (Denverton) to goldmont.
According to the 325462-071US document, they should be the same.

MFC after:	1 week
2020-04-24 16:05:35 +00:00
Matt Macy 92b14858b4 Update x86 counters
MFC after:	1 week
2020-04-03 22:36:22 +00:00
Emmanuel Vadot 483955de74 libpmc: Always add the full include path for libpmcstat
Previously it was only added for aarch64, amd64 and i386
2020-03-25 02:28:47 +00:00
Emmanuel Vadot ee55186dfd pmc: Add include path for libpmcstat as it is an internallib
Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D24173
2020-03-25 01:32:16 +00:00
Konstantin Belousov 53071ed1c9 pmc: Add Hygon Dhyana support.
To make the PMC tool pmcstat working properly on Hygon platform, add
support for Hygon Dhyana family 18h by using the PMC initialization
code path of AMD family 17h.

Submitted by:	Pu Wen <puwen@hygon.cn>
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D23562
2020-02-07 22:28:04 +00:00
Conrad Meyer f824ea0c26 libpmc: jevents: Go ahead and use snprintf(3)
Reported by:	Coverity
CID:		1391362
2020-01-29 04:33:45 +00:00
Conrad Meyer 3ea691c261 libpmc: jevents: Partial style(9) pass
Sort headers, move includes up to the top of the file, function return types on
their own line; no functional change.
2020-01-29 04:31:26 +00:00
Kyle Evans 4b50c45172 Revert r353140: Re-add ALLOW_MIPS_SHARED_TEXTREL, sprinkle it around
arichardson has an actual fix for the same issue that this was working
around; given that we don't build with llvm today, go ahead and revert the
workaround in advance.
2020-01-14 17:50:13 +00:00
Simon J. Gerraty b114e8fcd7 Tweaks for DIRDEPS_BUILD
libmagic only depend on mkmagic if not DIRDEPS_BUILD

libpmc fix -I for libpmcstat

local.dirdeps.mk be even more careful about adding gnu/lib/csu to DIRDEPS

Reviewed by:	bdrewery
Differential Revision:	https://reviews.freebsd.org/D22872
2019-12-19 02:40:04 +00:00
Ed Maste aab65fc55e libpmc: add MIT SPDX tag to header file
The jevents tool includes a copy of the jsmn json parser which is MIT
licensed.  Upstream the MIT license appears in the jsmn.c source and a
standalone LICENSE file, but the latter is not included in the copy
contained in libpmc and the jsmn.h header carried no license information.
Add an SPDX tag to clarify the situation.
2019-12-12 20:55:43 +00:00
Ed Maste 75d286742d libpmc: convert s390 events data to proper json 2019-12-12 19:37:10 +00:00
Ed Maste 3a3deb00a5 libpmc: convert powerpc event files to proper json 2019-12-12 19:33:16 +00:00
Ed Maste 8b238f4126 libpmc: sort some amdfam17h entries to make valid json 2019-12-12 19:23:38 +00:00
Ed Maste e641f557bd libpmc: remove undesired prefix from two s390 counters
Two counters included a prefix 'Counter:###\tName:XXX' in their
descriptions that appears to be a leftover from some conversion
process.  Remove them.

Found because a json validator tripped over the tab in the description.
2019-12-12 14:52:37 +00:00
Ed Maste c039e9596f libpmc: build json event support also on arm64 2019-12-12 00:14:01 +00:00
Ed Maste 1760167c2b libpmc: convert arm64 data files to proper json
jevents includes a very permissive json parser that accepts invalid
json, of which there are many examples in libpmc (typically extra or
missing commas).  Convert the arm64 files to proper json so other tools
can parse them.

Sponsored by:	The FreeBSD Foundation
2019-12-11 22:09:22 +00:00
Simon J. Gerraty 312809fe7f Update dirdeps.mk and gendirdeps.mk
The env space consumed by exporting all libc's .meta files
left little room for command line,
so unexport when done.

Update dirdeps.mk to latest and add
dirdeps-targets.mk to simplify/update targets/Makefile

Makefile changes to go with Makefile.depend changes in D22494

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22495
2019-12-11 17:38:15 +00:00
Simon J. Gerraty 2c9a9dfc18 Update Makefile.depend files
Update a bunch of Makefile.depend files as
a result of adding Makefile.depend.options files

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22494
2019-12-11 17:37:53 +00:00
Emmanuel Vadot f3dbece807 libpmc: Forgot regex.h
Reported by:	ci
MFC after:	1 week
X-MFC-With:	r354549
2019-11-08 17:27:20 +00:00
Emmanuel Vadot a0ac5706af libpmc: Match on the cpuid with a regex
The CPUID is, or can be, a regex to be matched.
Use regex from libc instead of strcmp

Tested-by:	gallatin
MFC after:	1 week
2019-11-08 16:56:48 +00:00
Ed Maste 6a2a926d5f libpmc: jevents: handle empty descriptoin
PR:		241258
Reported by:	sigsys @ gmail.com
Obtained from:	github.com/andikleen/pmu-tools commit bb3c77ed61
MFC after:	3 days
2019-11-04 22:52:02 +00:00
Dimitry Andric 8b3bc70a2b Merge ^/head r352764 through r353315. 2019-10-08 18:17:02 +00:00
Kyle Evans 036d2e814b Re-add ALLOW_MIPS_SHARED_TEXTREL, sprinkle it around
Diff partially stolen from CheriBSD; these bits need -Wl,-z,notext in order
to build in an LLVM world. They are needed for all flavors/sizes of MIPS.
This will eventually get fixed in LLVM, but it's unclear when.

Reported by:	arichardson, emaste
Differential Revision:	https://reviews.freebsd.org/D21696
2019-10-06 04:19:49 +00:00
Dimitry Andric 0f80acb965 Merge ^/head r352436 through r352536. 2019-09-19 19:26:12 +00:00
Ruslan Bukin 230754ccca Add support for BERI statcounters.
BERI stands for Bluespec Extensible RISC Implementation, based on MIPS.

BERI has not implemented standard MIPS perfomance monitoring counters,
instead it provides statistical counters.

BERI statcounters have a several limitations:
- They can't be written
- They don't support start/stop operation
- None of hardware interrupt is provided on a counter overflow.

So make it separate to hwpmc_mips module and support process/system
counting mode only.

Sponsored by:	DARPA, AFRL
2019-09-18 16:13:50 +00:00
Dimitry Andric 2c3f47a727 Another round of attempting to squelch -Wdeprecated-declarations, which
has become very trigger-happy with libc++ 9.0.0.

It does not help that gcc's implementation of this warning is even more
trigger-happy, in the sense that it already warns on the declaration
itself, not when you are using it.  This is very annoying with our use
of -Wsystem-headers.  That should really be disabled for gcc.
2019-09-17 06:07:08 +00:00
Emmanuel Vadot 4c1a82cea5 pkgbase: Create a FreeBSD-utilities package and make it the default one
The default package use to be FreeBSD-runtime but it should only contain
binaries and libs enough to boot to single user and repair the system, it
is also very handy to have a package that can be tranform to a small mfsroot.
So create a new package named FreeBSD-utilities and make it the default one.
Also move a few binaries and lib into this package when it make sense.
Reviewed by:	bapt, gjb
Differential Revision:	https://reviews.freebsd.org/D21506
2019-09-05 14:15:47 +00:00
Matt Macy 86b5e013ed pmc: restore "unhalted-cycles" alias
Reported by:	mav@
2019-08-15 21:51:11 +00:00
Enji Cooper b3d01a2ad7 Fix warnings with lib/libpmc
* Use `MIN` instead of similar hand rolled macro.
* Sort headers.
* Use `errno.h` instead of `sys/errno.h`.
* Wrap the argument to sizeof in parentheses for clarity.
* Remove `__BSD_VISIBLE` and `_XOPEN_SOURCE` #defines to mute warnings about
  incompatible snprintf definitions.

This fixes a number of warnings I've been seeing lately in my builds.

Sort makefile variables per style.Makefile(9) (`CFLAGS`/`CWARNFLAG.gcc`) and
bump `WARNS` to 3.

MFC after:	2 weeks
Reviewed by:	jtl
Approved by:	jtl (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D19851
2019-04-14 00:06:49 +00:00
Matt Macy 334fd3dabc Fix deterministic builds by sorting input to fts in jevents
Reported by: emaste@
2019-02-05 00:31:25 +00:00
Matt Macy dacc43df34 Add aditional counter descriptions to AMD 0x17
Submitted by:	Somalapuram Amaranath
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D17401
2018-11-04 06:24:27 +00:00
Alex Richardson 2fa224b17d Fix get_maxfds() in jevents
If RLIM_INFINITY == -1ULL (such as on macOS) the min() call will result
in a value of less than 1 being returned. This causes nftw() to fail
with EINVAL.

While touching this file also fix includes to work on Linux/macOS and don't
declare snprintf since it may have different attributes in the system
headers there.

Reviewed By:	mmacy
Approved By:	brooks (mentor)
Differential Revision: https://reviews.freebsd.org/D17682
2018-10-29 21:08:34 +00:00
Matt Macy 0204d85a62 hwpmc: set default rate if event description lacks one / filter rate against misuse
Not all event descriptions have a sample rate (such as inst_retired.any)
this will restore the legacy behavior of using 65536 in that case. It also
prevents accidental API misuse that could lead to panic.

PR:	230985
Reported by:	markj
Reviewed by:	markj
Approved by:	re (gjb)
Sponsored by:	Limelight Networks
Differential Revision:	https://reviews.freebsd.org/D16958
2018-09-14 01:30:05 +00:00
Matt Macy 3b9156971f re-enable pmcstat, pmccontrol, and pmcannotate for gcc4 builds
I had disabled building of the aforementioned targets due to warnings breaking
tinderbox. This silences the warning and restores them to the build.

Reported by:	jhibbits
Reviewed by:	jhibbits
Approved by:	re (gjb)
2018-09-14 01:11:10 +00:00
Matt Macy 81eb4dcf9e Add library and kernel support for AMD Family 17h counters
NB: lacks default sample rate for most counters
2018-08-14 05:18:43 +00:00
Matt Macy 455d10cc4c pmc amd17h: fix inputs to jevents 2018-08-13 23:46:44 +00:00
Matt Macy 6044931335 Add PMC support for AMD Family CPUs 2018-08-13 22:34:57 +00:00
Warner Losh c81b12e0d7 Revert r336773: it removed too much.
r336773 removed all things xscale. However, some things xscale are
really armv5. Revert that entirely. A more modest removal will follow.

Noticed by: andrew@
2018-07-27 21:25:01 +00:00
Warner Losh 626930c2fd Remove xscale support
The OLD XSCALE stuff hasn't been useful in a while. The original
committer (cognet@) was the only one that had boards for it. He's
blessed this removal. Newer XSCALE (GUMSTIX) is for hardware that's
quite old. After discussion on arm@, it was clear there was no support
for keeping it.

Differential Review: https://reviews.freebsd.org/D16313
2018-07-27 18:33:09 +00:00
Bryan Drewery b6b193e9d8 Put in temporary hacks for jevents.
- Handle 'make clean'
- Don't try building it locally, just fail instead.

jevents should really be merged into lib/libpmc/Makefile.
2018-06-15 19:19:36 +00:00
Ryan Libby 2ef5e36473 pmc gcc fixups
Fix the build of lib/libpmc and usr.sbin/pmc for gcc on amd64.

Reviewed by:    mmacy
Sponsored by:   Dell EMC Isilon
Differential Revision:  https://reviews.freebsd.org/D15723
2018-06-11 16:09:54 +00:00
Matt Macy a72a9036d3 libpmc: add missed (uintmax_t) casts 2018-06-07 03:19:21 +00:00
Matt Macy f992dd4b5c pmc: convert native to jsonl and track TSC value of samples
- add '-j' options to filter to enable converting native pmc
  log format to json lines format to enable the use of scripts
  and external tooling

% pmc filter -j pmc.log pmc.jsonl

- Record the tsc value in sampling interrupts as opposed to
  recording nanotime when the sample is copied to a global log
  in hardclock - potentially many milliseconds later.

- At initialize record the tsc_freq and the time of day to give
  us an offset for translating the tsc values in callchain records
2018-06-07 02:03:22 +00:00
Matt Macy 1b000b505b libpmc: simplify lookup by idx 2018-06-07 00:55:17 +00:00
Matt Macy b2ca2e50b9 hwpmc: add summary command and further metadata extensions
metadata changes:
- log pmc sample rate with pmcallocate
- log proc flags with thread / process logging
  to identify user vs kernel threads

fixes:
- use log cpuid to translate event id to event name

Implement rudimentary summary command to track sample
counts by thread and process name within a pmc log.

% make -j4 buildkernel >& /dev/null &
% sudo pmcstat -S unhalted_core_cycles -S llc-misses -O foo sleep 15
% pmc summary foo
cpu_clk_unhalted.thread_p_any:
        idle: 138108207162
        clang-6.0: 105336158004
        sh: 72340108510
        make: 8642012963
        kernel: 7754011631
longest_lat_cache.miss:
        clang-6.0: 87502625
        sh: 40901227
        make: 5500165
        kernel: 3300099
        awk: 2000060

%  pmc summary -f ~/foo
idx: 278 name: cpu_clk_unhalted.thread_p_any rate: 2000003
idle: 69054
clang-6.0: 52668
sh: 36170
make: 4321
kernel: 3877
hwpmc: proc(7445): 3319
awk: 1289
xargs: 357
rand_harvestq: 181
mtree: 102
intr: 53
zfskern: 31
usb: 7
pagedaemon: 4
ntpd: 3
syslogd: 1
acpi_thermal: 1
logger: 1
syncer: 1
snmptrapd: 1
sleep: 1
idx: 17 name: longest_lat_cache.miss rate: 100003
clang-6.0: 875
sh: 409
make: 55
kernel: 33
awk: 20
hwpmc: proc(7445): 14
xargs: 9
idle: 8
intr: 3
zfskern: 2
2018-06-06 02:48:09 +00:00
Matt Macy ebfaf69cc0 hwpmc: log name->pid, name->tid mappings
By logging all threads and processes 'pmc filter'
can now filter on process or thread name, relieving
the user of the burden of determining which tid or
pid was which when the sample was taken.

% pmc filter -T if_io_tqg -P nginx pmc.log pmc-iflib.log

% pmc filter -x -T idle pmc.log pmc-noidle.log
2018-06-05 04:26:40 +00:00
Matt Macy 12193215c2 libpmc: improve arg checking 2018-06-04 21:17:46 +00:00
Matt Macy ee62e0b419 libpmc / stat: use westmere supported counter 2018-06-04 21:17:42 +00:00
Matt Macy ce6fc9d779 update pmc_pmu_idx_get_by_event signature for !x86 2018-06-04 05:04:40 +00:00
Matt Macy bfb46e2ba8 pmc: add filter command
pmc filter allows the user to select event types, threads, and processes from
a sample.

% pmcstat -S unhalted_core_cycles -S llc-misses -S -S  resource_stalls.any -O pmc.log
% pmc filter -e llc-misses pmc.log pmc-llc-misses.log
% pmc filter -e unhalted_core_cycles -t 100339  pmc.log pmc-core-cycles.log
etc...
% pmcstat -R pmc-core-cycles.log -G pmc-core-cycles.stacks
2018-06-04 04:59:48 +00:00
Matt Macy 07d80fd8dc hwpmc: ABI fixes
- increase pmc cpuid field from 8 to 12 bits
- add cpuid version string to initialize entry in the log
  so that filter can identify which counter index an
  event name maps to
- GC unused config flags
- make fixed counter assignment more robust as well as the
  changes needed to be properly identified for filter
2018-06-04 02:05:48 +00:00
Matt Macy fbf962e6bb libpmc: allow substring for list and add function for printing event details 2018-06-01 00:45:53 +00:00
Matt Macy cfb0dfa3c2 libpmc: Intel doesn't require runtime counter table init 2018-06-01 00:45:48 +00:00
Matt Macy 96cbd26a24 libpmc/pmu: update aliases table 2018-06-01 00:45:43 +00:00
Matt Macy e92a1350b5 hwpmc: remove unused pre-table driven bits for intel
Intel now provides comprehensive tables for all performance counters
and the various valid configuration permutations as text .json files.
Libpmc has been converted to use these and hwpmc_core has been greatly
simplified by moving to passthrough of the table values.

The one gotcha is that said tables don't support pentium pro and and pentium
IV. There's very few users of hwpmc on _amd64_ kernels on new hardware. It is
unlikely that anyone is doing low level optimization on 15 year old Intel
hardware. Nonetheless, if someone feels strongly enough to populate the
corresponding tables for p4 and ppro I will reinstate the files in to the
build.

Code for the K8 counters and !x86 architectures remains unchanged.
2018-05-31 22:41:07 +00:00
Matt Macy 7d1c2b74a0 libpmc/pmu: enable for i386 as well 2018-05-31 22:26:55 +00:00
Matt Macy 785dd70da8 libpmc: add pmu support for uncore events 2018-05-31 22:26:50 +00:00
Matt Macy 8ffdc5df52 libpmc: squelch valgrind warnings 2018-05-30 04:12:51 +00:00
Matt Macy 8b20f97570 libpmc: bring pmu_util closer in line with style(9) 2018-05-30 03:40:02 +00:00
Matt Macy 8bed125da7 libpmc: silence scan-build warnings 2018-05-29 21:02:13 +00:00
Eric van Gyzen 4f9b4ac4c2 pmc_annotate: adhere to the API
If the 'mode' parameter was invalid, pmc_annotate() would
return EINVAL instead of setting errno and returning -1.

Sponsored by:	Dell EMC
2018-05-29 20:30:46 +00:00
Matt Macy 1a32aa0ff7 libpmc: don't return -1 on success in pmc_allocate 2018-05-29 20:09:35 +00:00