Commit graph

28 commits

Author SHA1 Message Date
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
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 b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06: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 53d0b9e438 pmc: Provide full path to modules from kernel linker
This unifies the user object and kernel module paths in libpmcstat,
allows modules loaded from non-standard locations (e.g. from a user's
home directory when testing) to be found and, since buffer is what all
the warnings here use (they were never updated when buffer_modules were
added to pick based on where the file was found) has the side-effect of
ensuring the messages are correct.

This includes obsoleting the now-superfluous -k option in pmcstat.

This change breaks the hwpmc ABI and will be followed by a bump to the
pmc major version.

Reviewed by:	jhb, jkoshy, mhorne
Differential Revision:	https://reviews.freebsd.org/D40048
2023-05-31 00:15:34 +01:00
John Baldwin a6db407f15 libpmcstat: Fix a few ARM-specific issues with function symbols.
- Refine the checks for ARM mapping symbols and apply them on arm64 as
  well as 32-bit arm.  In particular, mapping symbols can have
  additional characters and are not strictly limited to just "$a" but
  can append additional characters (e.g. "$a.1").  Add "$x" to the
  list of mapping symbol prefixes.

- Clear the LSB of function symbol addresses.  Thumb function
  addresses set the LSB to enable Thumb mode.  However, the actual
  function starts at the aligned address with LSB clear.  Not clearing
  the LSB can cause pmcannotate to pass misaligned addresses to
  objdump when extracting disassembly.

Reviewed by:	andrew
Obtained from:	CheriBSD
Sponsored by:	University of Cambridge, Google, Inc.
Differential Revision:	https://reviews.freebsd.org/D34416
2022-03-10 15:39:53 -08:00
Andrew Gallatin 517a7adb11 Make hwpmc work for userspace binaries again
hwpmc has been utterly broken for userspace binaries, and has been
labeling all samples from userspace binaries as dubious frames. The
issues are that:

-The check for ph.p_offset & (-ph.p_align) == 0 was mostly bogus. The
 intent was to ignore all executable segments other than the first,
 which when using BFD appeared in the first page, but with current LLD
 a read-only data segment appears before the executable segment,
 pushing the latter into the second page or later. This meant no
 executable segment was ever found, and thus pi_vaddr remained
 0. Instead of relying on BFD's layout, track whether we've seen an
 executable segment explicitly with a local bool.

-Shared libraries were not parsing the segments to calculate pi_vaddr,
 resulting in it always being 0. Again, when using BFD, the executable
 segment started at the first page, and so pi_vaddr was genuinely
 meant to be 0, but not with LLD's current layout. This meant that
 pmcstat_image_link's offset calculation gave the base address of the
 segment in memory, rather than the base address of the whole library
 in memory, and so when adding that to pi_start/pi_end to get the
 range of the executable sections in memory it double-counted the
 offset of the first executable segment within the library. Thus we
 need to do the exact same parsing for ET_DYN as we do for ET_EXEC,
 which is simpler to write as special-casing ET_REL to not look for
 segments. Note that, whilst PT_INTERP isn't needed for shared
 libraries, it will be for PIEs, which pmcstat still fails to handle
 due to not knowing the base address of the PIE; we get the base
 address for libraries by MAP_IN events, and for rtld by virtue of the
 process's entry address being rtld's, but have no equivalent for the
 executable.

Fixes courtesy of jrtc27@.

Reviewed by: jrtc27, jhb (earlier version)
Differential Revision: https://reviews.freebsd.org/D33055
Sponsored by: Netflix
2021-12-15 08:38:36 -05:00
Leandro Lupori 926da0492a pmcstat: fix PPC kernel symbol resolution
PowerPC kernel is of DYN type and it has a base address where it is
initially loaded, before being relocated. As the start address passed to
pmcstat_image_link() is where the kernel was relocated to, but the symbols
always use the original base address, we need to subtract it to get the
correct offset.

Reviewed by:	jhibbits
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D26114
2020-11-05 16:47:23 +00:00
Mateusz Guzik 94e9ef85c5 pmcstat: implement showing offsets into symbols in top mode
The -I option (and hotkey) is reused for this. Skipping symbol resolution is
moved to the new -A option (and hotkey).

While arguably this violates POLA I think it's a change for the better.
ALso note the -I option was added in head.

Differential Revision:	https://reviews.freebsd.org/D21658
2020-08-05 19:05:49 +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
Ryan Moeller 797711a84f libpmcstat: Try /boot/modules if module not found
Modules from ports/pkg are commonly installed to /boot/modules rather than to
the same directory the kernel resides in.  Look there if a module is not found
next to the kernel.

Submitted by:	mmacy
Reported by:	Nick Principe <nap@iXsystems.com>
Approved by:	mmacy (mentor)
MFC after:	2 weeks
Sponsored by:	iXsystems, Inc.
2020-03-12 23:04:40 +00:00
Matt Macy 959826ca1b pmc(3)/hwpmc(4): update supported Intel processors to rely fully on the
vendor provided pmu-events tables and sundry cleanups.

The vendor pmu-events tables provide counter descriptions, default
sample rates, event, umask, and flag values for all the counter
configuration permutations. Using this gives us:

- much simpler kernel code for the MD component
- helpful long and short event descriptions
- simpler user code
- sample rates that won't overload the system

Update man page with newer sample types and remove unused sample type.
2018-05-26 19:29:19 +00:00
Matt Macy 5506ceb87f Revert r334242 "pmc(3)/hwpmc(4): update supported Intel processors to rely fully on the"
because of squash commit messages
2018-05-26 19:26:19 +00:00
Matt Macy 4928135658 pmc(3)/hwpmc(4): update supported Intel processors to rely fully on the
vendor provided pmu-events tables and sundry cleanups.

The vendor pmu-events tables provide counter descriptions, default
sample rates, event, umask, and flag values for all the counter
configuration permutations. Using this gives us:

- much simpler kernel code for the MD component
- helpful long and short event descriptions
- simpler user code
- sample rates that won't overload the system

Update man page with newer sample types and remove unused sample type.

Squashed commit of the following:

commit 4459d43eff815bec08ccc5533dbe5de846f03128
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Sat May 26 00:06:31 2018 -0700

    libpmc: fix pmu function signatures for non amd64

commit a2cb8bbc586c65d41f9b291430a2261ec67b59fe
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 22:38:11 2018 -0700

    pmcstat: fix indentation of usage

commit f686954b15ff56a833ac80404898977cb80a265b
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 22:19:49 2018 -0700

    pmclog(3): add callchain and pmcallocatedyn, remove pcsample

commit 73e13a0d2e9498c81c150d14d022050cee7511bb
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 22:19:00 2018 -0700

    pmclog.h: GC pcsample field

commit 3e93ffd65da641fa657539dad3c48e281f8b5798
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 22:05:57 2018 -0700

    hwpmc: make Intel core CPUs use external event tables

commit 634f5fae1e1644ac324003136c66cd9c619d1c93
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 22:00:06 2018 -0700

    pmclog: update log record types, bump PMC_MAJOR
    - explicitly make log record types a multiple of 8 bytes
    - hook in pmu event types for pmc_allocate records
    - remove references to no longer PCSAMPLE record

commit 83d84fcd2d65bdf6ddcb2e155a22f0cfa2a9c225
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 21:52:10 2018 -0700

    libpmc: add support for having vendor table driven pmc_allocate

commit 9e6ad63c40c2fce8404847ace5078ca6cb33a736
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 19:11:33 2018 -0700

    hwpmc_core: add accessors for EVSEL & UMASK, make IAP_UMASK useful to user

commit 859dceb93daa6419a48c794db99b6758e5b041c9
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 19:09:45 2018 -0700

    pmcstat: update usage and man page as well as make -L consistent with pmccontrol

commit 79c7d8597e28c2eb13f5f9113e65ec2792ca57b1
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 18:07:03 2018 -0700

    pmu_util: add support for all current intel event keywords

commit d8089c7f6a6c8527f38324252b1ffb47004694c6
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 17:45:00 2018 -0700

    add description for new arguments

commit 058336740bab53c62ec88a3a026ea848cf3878c6
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 17:38:15 2018 -0700

    libpmc: move pmu_events table and pmu_utils out of libpmcstat so that they can be used by pmc_allocate

commit 049b66b382e2f833c3f47bc8df9e750cb265709f
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 16:12:41 2018 -0700

    pmcstat: hook pmu_events counter description utility routines in

commit f5e01e7b37a691dc045e1aa16b3ebdd162515de8
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 16:11:59 2018 -0700

    pmu_events: add utility routines for listing counters and their descriptions

commit cba4d4f8907f772279f86f18f915e0d74d33ac56
Author: Matt Macy <mmacy@mattmacy.io>
Date:   Fri May 25 16:09:50 2018 -0700

    pmu-events: expand out skylake regex to simplify string matches
2018-05-26 18:12:50 +00:00
Bryan Drewery 672ea456f9 META_MODE: Fix trying to rebuild jevents due to missing .meta file.
The tool is built separately in buildworld in a subdirectory rather than
how other build-tools are done.  Subdirectory builds in lib/libpmcstat
remain broken since the tool cannot be auto-built from here.
2018-05-25 21:46:53 +00:00
Bryan Drewery efd834d6ce Use proper BTOOLSPATH for build-tools path. 2018-05-25 21:46:49 +00:00
Bryan Drewery 783fe372bf Cleanup style 2018-05-25 21:46:07 +00:00
Matt Macy 773015538c libpmcstat: Don't build pmu tables on !amd64 until the corresponding
util routines have been written and tested. Currently building them
breaks the build on power64

Reported by:	emaste
2018-05-24 21:22:03 +00:00
Matt Macy 4d388c5528 remove All Rights Reserved from new libpmcstat file 2018-05-24 15:04:44 +00:00
Matt Macy f2597cf756 libpmcstat: import aliases table and bug fixes 2018-05-24 06:47:40 +00:00
Matt Macy 341890e07d fix !amd64 signature for pmu_sample_rate_get 2018-05-24 04:38:17 +00:00
Matt Macy e98bbcf9ca libpmcstat: compile in events based on json description 2018-05-24 04:30:06 +00:00
Matt Macy 0b5dc7f64f hwpmc: add thread id field to callchain and context switch records to allow filtering
on thread in post-processing.

To generate stacks for just ${THREADID}:

pmcstat -R ${PREFIX}.pmcstat -L ${THREADID} -z100 -G ${PREFIX}.stacks

Sponsored by:	Limelight Networks
2018-05-23 17:25:00 +00:00
Matt Macy 821a352a77 pmcstat: add option to not decode the leaf function in top mode
-I will allow the user to see the hot instruction in question
as opposed getting the name of the function
2018-05-22 04:45:46 +00:00
Ruslan Bukin 167b8a609d Fix bug: increment the value of pmcstat_npmcs instead of moving pointer
to the next int position.

Bug was introduced in r324959 ("Extract a set of pmcstat functions and
interfaces to the new internal library -- libpmcstat.")

This fixes pmcstat top mode (-T) operation.
Example: pmcstat -n1 -S clock.hard -T

Reported by:	Peter Holm <peter@holm.cc>
Sponsored by:	DARPA, AFRL
2018-01-16 09:31:01 +00:00
Bryan Drewery 3806950135 DIRDEPS_BUILD: Connect new directories.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:04:07 +00:00
Ruslan Bukin d27927f731 Extract a set of pmcstat functions and interfaces to the new internal
library -- libpmcstat.

This includes PMC logging module, symbols lookup functions,
ELF parsing, process management, PMC attachment, etc.

This allows to reuse code while building new hwpmc(4)-based applications.

Also add pmcstat_symbol_search_by_name() function that allows to find
mapped IP range for a given function name.

Reviewed by:	kib
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D12718
2017-10-24 16:28:00 +00:00