History log of /freebsd-current/usr.sbin/pmcstat/pmcstat.c
Revision Date Author Comments
# 4d65a7c6 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.sbin: 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


# c362fe93 27-Sep-2023 Mitchell Horne <mhorne@FreeBSD.org>

pmcstat: fix duplicate event allocation on CPU 0

Commit b6e28991bf3a modified the allocation path for system scope PMCs
so that the event was allocated early for CPU 0. The reason is so that
the PMC's capabilities could be checked, to determine if pmcstat should
allocate the event on every CPU, or just on one CPU in each NUMA domain.
In the current scheme, there is no way to determine this information
without performing the PMC allocation.

This broke the established use-case of log analysis, and so
0aa150775179a was committed to fix the assertion. The result was what
appeared to be functional, but in normal counter measurement pmcstat was
silently allocating two counters for CPU 0.

This cuts the total number of counters that can be allocated from a CPU
in half. Additionally, depending on the particular hardware/event, we
might not be able to allocate the same event twice on a single CPU.

The simplest solution is to release the early-allocated PMC once we have
obtained its capabilities, and reallocate it later on. This restores the
event list logic to behave as it has for many years, and partially
reverts commit b6e28991bf3a.

Reported by: alc, kevans
Reviewed by: jkoshy, ray
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D41978


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# aee3611f 07-Jun-2023 John Baldwin <jhb@FreeBSD.org>

pmcstat: Tweak typo fix.

Reviewed by: imp


# b8b97d31 01-Jun-2023 Elyes Haouas <ehaouas@noos.fr>

pmcstat: Fix typos

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/653


# 53d0b9e4 30-May-2023 Jessica Clarke <jrtc27@FreeBSD.org>

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


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

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


# bf661593 05-May-2023 Mitchell Horne <mhorne@FreeBSD.org>

pmcstat: augment an error message

It also applies to the -t argument.

Reviewed by: jkoshy
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D39907


# ca2edebb 02-Mar-2023 Elyes Haouas <ehaouas@noos.fr>

pmcstat: Remove useless return at the end of void function

Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/656


# 0aa15077 03-Jul-2022 Andrew Gallatin <gallatin@FreeBSD.org>

pmcstat: fix log analysis

pmcstat has been broken for analyzing logs since D35342 / b6e28991bf3aadb.

This is because the pmc for the first CPU is not added when reading logs
because unlike its clones, its event id is not invalid. That causes us
to fail the assertion at lib/libpmcstat/libpmcstat_logging.c:293
when encountering samples from cpu0.

Fix this by removing the check that the PMC is invalid

Reviewed by: tsoome
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D35709


# b6e28991 15-Feb-2022 Aleksandr Rybalko <ray@freebsd.org>

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


# 0939f965 28-Aug-2021 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

Update a sysctl name to nbuffers_pcpu in hwpmc.4 and pmcstat.c

This change was missed in r333509 (e6b475e0af).

Differential Revision: https://reviews.freebsd.org/D31704
Reviewed by: mjg


# c4473add 21-Apr-2021 Mitchell Horne <mhorne@FreeBSD.org>

pmcstat: fix the usage message for -t

A slight mix-up of the flags means this case isn't triggered when it
should be. Now, `pmcstat -s event -t 1234` will print the correct
error message.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation


# edcf9e59 21-Apr-2021 Mitchell Horne <mhorne@FreeBSD.org>

pmcstat: set initial counter value to zero

For an infrequent event, pmcstat may report (u_long)-1 for CPUs where
the counter was never incremented. Just set this to zero, instead.

ev->ev_count is passed as the 'count' argument to pmc_allocate(3), but
this wasn't always the case.

Reviewed by: gnn
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29887


# d3231fbd 04-Nov-2020 Mateusz Piotrowski <0mp@FreeBSD.org>

pmcstat: Fix a typo in the usage message

Reviewed by: emaste
Approved by: emaste
Differential Revision: https://reviews.freebsd.org/D26082


# 94e9ef85 05-Aug-2020 Mateusz Guzik <mjg@FreeBSD.org>

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


# b2ca2e50 05-Jun-2018 Matt Macy <mmacy@FreeBSD.org>

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


# 5de96e33 03-Jun-2018 Matt Macy <mmacy@FreeBSD.org>

hwpmc: support sampling both kernel and user stacks when interrupted in kernel

This adds the -U options to pmcstat which will attribute in-kernel samples
back to the user stack that invoked the system call. It is not the default,
because when looking at kernel profiles it is generally more desirable to
merge all instances of a given system call together.

Although heavily revised, this change is directly derived from D7350 by
Jonathan T. Looney.

Obtained from: jtl
Sponsored by: Juniper Networks, Limelight Networks


# fbf962e6 31-May-2018 Matt Macy <mmacy@FreeBSD.org>

libpmc: allow substring for list and add function for printing event details


# ae266f9f 27-May-2018 Matt Macy <mmacy@FreeBSD.org>

pmcstat: suppress uninitialized warning of event


# 959826ca 26-May-2018 Matt Macy <mmacy@FreeBSD.org>

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.


# 5506ceb8 26-May-2018 Matt Macy <mmacy@FreeBSD.org>

Revert r334242 "pmc(3)/hwpmc(4): update supported Intel processors to rely fully on the"
because of squash commit messages


# 49281356 26-May-2018 Matt Macy <mmacy@FreeBSD.org>

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


# e22ee9b2 25-May-2018 Sean Bruno <sbruno@FreeBSD.org>

pmcstat(8)
- Document per thread filtering.

Submitted by: kbowling
Sponsored by: Limelight Networks
Differential Revision: https://reviews.freebsd.org/D15549


# 0a87e3ff 24-May-2018 Matt Macy <mmacy@FreeBSD.org>

pmcstat: add usage strings for -L and -I


# 357405d9 23-May-2018 Matt Macy <mmacy@FreeBSD.org>

pmcstat: don't compare signed and unsigned


# e98bbcf9 23-May-2018 Matt Macy <mmacy@FreeBSD.org>

libpmcstat: compile in events based on json description


# 0b5dc7f6 23-May-2018 Matt Macy <mmacy@FreeBSD.org>

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


# 821a352a 21-May-2018 Matt Macy <mmacy@FreeBSD.org>

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


# cb43ed28 17-Jan-2018 Fabien Thomas <fabient@FreeBSD.org>

Only call flush in pipe mode.
It fixes a crash with a socket in top mode.

Ex:
# pmcstat -R 127.0.0.1:8080 -T -w1
then
# pmcstat -n1 -Sclock.prof -Slock.failed -O 127.0.0.1:8080

MFC after: 1 week
Sponsored by: Stormshield


# 1de7b4b8 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

various: general adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.


# d27927f7 24-Oct-2017 Ruslan Bukin <br@FreeBSD.org>

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


# 3ad36a25 07-Oct-2016 Stephen J. Kiernan <stevek@FreeBSD.org>

Just remove freeing memory in pmcstat_cleanup, since we only clean up
when we are exiting anyway.

Add NULL checks for all malloc and strdup returns.

Reviewed by: gnn
Approved by: sjg (mentor)
Obtained from: Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D8002


# 465dadb5 18-Nov-2015 Jonathan T. Looney <jtl@FreeBSD.org>

Support a wider history counter in pmcstat(8) gmon output

pmcstat(8) contains an option to output sampling data in a gmon format
compatible with gprof(1). Currently, it uses the default histcounter,
which is an (unsigned short). With large sets of sampling data, it
is possible to overflow the maximum value provided by an (unsigned
short).

This change adds the -e argument to pmcstat. If -e and -g are both
specified, pmcstat will use a histcounter type of uint64_t.

Differential Revision: https://reviews.freebsd.org/D4151
Reviewed by: jhb, bjk
Approved by: gnn (mentor)
MFC after: 1 month
Sponsored by: Juniper Networks


# e64ba55d 16-Nov-2015 Jonathan T. Looney <jtl@FreeBSD.org>

Change the driver stats to what they really are: unsigned values.

When pmcstat exits after some samples were dropped, give the user an
idea of how many were lost. (Granted, these are global numbers, but
they may still help quantify the scope of the loss.)

Differential Revision: https://reviews.freebsd.org/D4123
Approved by: gnn (mentor)
MFC after: 1 month
Sponsored by: Juniper Networks


# 7816cb4a 01-Sep-2015 John Baldwin <jhb@FreeBSD.org>

Fix an off by one error in r283613: Like regular ffs(), CPU_FFS() returns
1 for CPU 0, etc. so the return value must be decremented to obtain the
first valid CPU ID.

Submitted by: fabient
MFC after: 1 week


# ef16b9ab 27-May-2015 John Baldwin <jhb@FreeBSD.org>

Use the cpuset API more consistently:
- Fetch the root set from cpuset_getaffinity() instead of assuming all CPUs
from 0 to hw.ncpu are the root set.
- Use CPU_SETSIZE and CPU_FFS.
- The original notion of halted CPUs the manpage and code refers to is gone.
Use the term "available" instead.

Differential Revision: https://reviews.freebsd.org/D2491
Reviewed by: emaste
MFC after: 1 week


# 38fd3834 08-May-2015 John Baldwin <jhb@FreeBSD.org>

Use the kern.bootfile sysctl to set the default kernel path rather than
hardcoding /boot/kernel. This allows pmcstat(8) to work without -k when
using nextboot -k or 'boot foo' at the loader to boot alternate kernels.

Differential Revision: https://reviews.freebsd.org/D2425
Reviewed by: adrian, emaste, gnn
MFC after: 2 weeks
Sponsored by: Norse Corp, Inc.


# 10813ab3 28-Mar-2015 Eric van Gyzen <vangyzen@FreeBSD.org>

pmcstat.8: fix -a flag description; improve -m flag to match

The -a flag reads a file saved by -O, not -o.

The -m flag requires the -R flag. Copy that paragraph from -a.

Reviewed by: adrian
Approved by: kib (mentor)
MFC after: 1 week
Sponsored by: Dell Inc


# 72fe532c 15-May-2014 George V. Neville-Neil <gnn@FreeBSD.org>

Add a command line argument (-l) to end event collection after some
number of seconds. The number of seconds may be a fraction.

Submitted by: Julien Charbon <jcharbon@versign.com>
MFC after: 2 weeks
Relnotes: yes


# 5ae1451d 29-Apr-2014 Scott Long <scottl@FreeBSD.org>

Fix formatting of the -a option in usage() to be consistent.

Obtained from: Netflix, Inc.
MFC after: 3 days


# 85ec49f3 23-Feb-2014 Adrian Chadd <adrian@FreeBSD.org>

Add a new option - 'a <file>' - which spits out annotated callgraphs.

'-m <file>' spits out the given stream into <file> (eg, /dev/stdout).
However, it only resolves the first symbol; it doesn't parse the entire
callgraph. If it fails to lookup then it doesn't print anything.

'-a' instead does a symbol and file:line lookup for each address in each
callgraph and will happily print the address itself with no lookup
information if it couldn't look things up.

This makes it much easier to pull out individual records from a
pmc data file and look at the callgraph information without having to
hand-decode the addresses.

Sponsored by: Netflix, Inc.


# bf70bece 19-Oct-2012 Ed Schouten <ed@FreeBSD.org>

More -Wmissing-variable-declarations fixes.

In addition to adding `static' where possible:

- bin/date: Move `retval' into extern.h to make it visible to date.c.
- bin/ed: Move globally used variables into ed.h.
- sbin/camcontrol: Move `verbose' into camcontrol.h and fix shadow warnings.
- usr.bin/calendar: Remove unneeded variables.
- usr.bin/chat: Make `line' local instead of global.
- usr.bin/elfdump: Comment out unneeded function.
- usr.bin/rlogin: Use _Noreturn instead of __dead2.
- usr.bin/tset: Pull `Ospeed' into extern.h.
- usr.sbin/mfiutil: Put global variables in mfiutil.h.
- usr.sbin/pkg: Remove unused `os_corres'.
- usr.sbin/quotaon, usr.sbin/repquota: Remove unused `qfname'.


# 33b12a85 22-Aug-2012 Jim Harris <jimharris@FreeBSD.org>

Add -m option (for printing sampled PCs to a file) to pmcstat usage
message.

Sponsored by: Intel
MFC after: 3 days


# 831b9630 19-Jan-2012 Eitan Adler <eadler@FreeBSD.org>

Fix warning when compiling with gcc46:
error: variable 'current_cpu' set but not used

Approved by: dim, cperciva (mentor, blanket for pre-mentorship already-approved commits)
MFC after: 3 days


# 3df5ecac 30-Dec-2011 Ulrich Spörlein <uqs@FreeBSD.org>

Spelling fixes for usr.sbin/


# 37d6f8a9 14-Nov-2011 David E. O'Brien <obrien@FreeBSD.org>

Improve the chances of matching an outputted string with the line of code.


# 3b6dc18e 13-Nov-2011 Eitan Adler <eadler@FreeBSD.org>

- fix duplicate "a a" in some comments

Submitted by: eadler
Approved by: simon
MFC after: 3 days


# 66ce9936 01-Nov-2011 Fabien Thomas <fabient@FreeBSD.org>

Two bugs fixed:
- Do not close stdout or stderr when redirecting to file.
- Correctly handle error code to detect when no buffer available.

MFC after: 1 month


# dceed24a 18-Oct-2011 Fabien Thomas <fabient@FreeBSD.org>

Add a flush of the current PMC log buffer before displaying the next top.

As the underlying block is 4KB if the PMC throughput is low the measurement
will be reported on the next tick. pmcstat(8) use the modified flush API to
reclaim current buffer before displaying next top.

MFC after: 1 month


# ea056888 07-Aug-2011 Attilio Rao <attilio@FreeBSD.org>

Convert pmcstat about using cpuset_t rather than relying on plain 32 bit
ints. That fixes a first bug where pmcstat wasn't using the old
cpumask_t interface and now also brings the full support for more
than 32 cpus.

While here, make the functions pmcstat_clone_event_descriptor() and
pmcstat_get_cpumask() private to pmcstat.

The problem of assuming cpu dense masks still persists and should be
eventually fixed, as reported by avg.

Tested by: pluknet
Reviewed by: gnn
Approved by: re (kib)


# 44735e89 15-Jul-2011 Andriy Gapon <avg@FreeBSD.org>

pmcstat, pmccontrol: catch up with removal of machdep.hlt_cpus sysctl

Reported by: Pan Tsu <inyaoo@gmail.com>
Reviewed by: attilio
No objections: gnn


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# e7ef1de5 03-Aug-2010 Fabien Thomas <fabient@FreeBSD.org>

- Do not use the runtime mask when logfile is specified.
- Revert the fix on rtld path that is not necessary.

MFC after: 1 week


# ac708fdd 03-Aug-2010 Fabien Thomas <fabient@FreeBSD.org>

Allow file as a top source, it works with socket now.
This will allow top monitoring using socket/ssh tunnelling
of system without local symbols.

client:
pmcstat -R <ip>:<port> -T -r <symbolspath>
monitored device:
pmcstat -Sinstructions -O <ip>:<port>

- Move the file read in the event loop
- Initialize and clean log in all cases
- Preserve global stats value during top refresh
- Fix the rtld/line resolver that ignore '-r' prefix
- Support socket for '-R' (server mode)
- Display the statistics when exiting top mode


# 5c15d3c8 05-Jun-2010 Fabien Thomas <fabient@FreeBSD.org>

Fix warnings found by Coverity.

Found with: Coverity Prevent(tm)
MFC after: 1 month


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 433d44f1 08-Mar-2010 Fabien Thomas <fabient@FreeBSD.org>

MFC r204783:
Bug fixed:
- no display on serial terminal in top mode.
- display alignment for continuation string.
- correct invalid value used for display limit.


# 2aa983e5 05-Mar-2010 Fabien Thomas <fabient@FreeBSD.org>

Bug fixed:
- no display on serial terminal in top mode.
- display alignment for continuation string.
- correct invalid value used for display limit.

MFC after: 3 days


# 2553c385 05-Mar-2010 Fabien Thomas <fabient@FreeBSD.org>

MFC 203790:
- Reorganize code in 'plugin' to share log processing.
- Kcachegrind (calltree) support with assembly/source
code mapping and call count estimator (-F).
- Top mode for calltree and callgraph plugin (-T).


# 0b86b1bb 11-Feb-2010 Fabien Thomas <fabient@FreeBSD.org>

- Reorganize code in 'plugin' to share log processing.
- Kcachegrind (calltree) support with assembly/source
code mapping and call count estimator (-F).
- Top mode for calltree and callgraph plugin (-T).

MFC after: 1 month


# 8cfb4353 22-Dec-2008 Joseph Koshy <jkoshy@FreeBSD.org>

Close the read side of the pipe to self when exiting.


# c0252222 25-Nov-2008 Attilio Rao <attilio@FreeBSD.org>

Add the -m option to pmcstat.
This option prints the list of sampled PCs along with the function name,
the start and end addresses of this where their live within.

Reviewed by: jkoshy
Tested by: gnn
Sponsored by: Nokia


# b8fbd97b 18-Nov-2008 Joseph Koshy <jkoshy@FreeBSD.org>

As a matter of good programming style, stop PMCs before releasing
them.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 5477328d 07-Oct-2008 Joseph Koshy <jkoshy@FreeBSD.org>

- Avoid a spurious error when a command line is specified without
any process scope PMCs.
- Change the -c '*' option to denote non-halted CPUs.


# 67442c6e 19-Sep-2008 Joseph Koshy <jkoshy@FreeBSD.org>

Bring the usage message in sync with the manual page.


# 165b10b0 01-Jul-2008 Joseph Koshy <jkoshy@FreeBSD.org>

Fix a regression: attach process PMCs to the process created when
a command line is specified.


# bcba261a 10-Jan-2008 Jung-uk Kim <jkim@FreeBSD.org>

Fix non-SMP kernel regression introduced in the previous commit.

Reviewed by: jkoshy


# b6010f9e 07-Dec-2007 Joseph Koshy <jkoshy@FreeBSD.org>

Introduce pmcstat(8) changes for summarizing hwpmc(4) callchain records in
in textual form and in gmon.out format.

Update manual page.

Sponsored by: FreeBSD Foundation and Google Inc.


# fbd8b34a 26-Apr-2007 Joseph Koshy <jkoshy@FreeBSD.org>

MFP4: Enhancements to pmcstat(8):

- Allow the "-t" option to take a regular expression naming command
line processes to attach process PMCs to.

- Update the manual page and add an example showing the use of the
new functionality.

- Update the (c) year on the affected source files.


# ee4910b1 22-Apr-2007 Joseph Koshy <jkoshy@FreeBSD.org>

MFP4: Enhancements and bug-fixes to pmcstat(8):

- The '-c' option now takes a comma-separated list of CPU
numbers, or a literal '*' denoting all CPUs in the system.
Subsequent system PMCs are allocated on the CPUs so specified.

Change the default behaviour to allocate system PMCs on all CPUs,
not just CPU 0.

Update the manual page and add an example of how to use the new
functionality.

- Attach PMCs to a (commandline) child process more reliably. This
fixes a long standing bug in counting events incurred by short-lived
processes.


# 00a22dc5 20-Apr-2007 Joseph Koshy <jkoshy@FreeBSD.org>

Correct a sanity check.


# 24bffe06 29-Sep-2006 Ruslan Ermilov <ru@FreeBSD.org>

Line up usage output.


# 302cbb90 01-Apr-2006 Joseph Koshy <jkoshy@FreeBSD.org>

- Teach pmcstat(8) to log over the network; the -O option now
takes a host:port specification.
- Update the manual page and add an example showing how log
over the network using pmcstat(8) and nc(1). Document the
current inability to process logs in cross-platform manner.
- Have pmcstat_open_log() call err(3) directly in case
of an error; this simplifies error handling in its caller.

MFC after: 1 week


# 49874f6e 25-Mar-2006 Joseph Koshy <jkoshy@FreeBSD.org>

MFP4: Support for profiling dynamically loaded objects.

Kernel changes:

Inform hwpmc of executable objects brought into the system by
kldload() and mmap(), and of their removal by kldunload() and
munmap(). A helper function linker_hwpmc_list_objects() has been
added to "sys/kern/kern_linker.c" and is used by hwpmc to retrieve
the list of currently loaded kernel modules.

The unused `MAPPINGCHANGE' event has been deprecated in favour
of separate `MAP_IN' and `MAP_OUT' events; this change reduces
space wastage in the log.

Bump the hwpmc's ABI version to "2.0.00". Teach hwpmc(4) to
handle the map change callbacks.

Change the default per-cpu sample buffer size to hold
32 samples (up from 16).

Increment __FreeBSD_version.

libpmc(3) changes:

Update libpmc(3) to deal with the new events in the log file; bring
the pmclog(3) manual page in sync with the code.

pmcstat(8) changes:

Introduce new options to pmcstat(8): "-r" (root fs path), "-M"
(mapfile name), "-q"/"-v" (verbosity control). Option "-k" now
takes a kernel directory as its argument but will also work with
the older invocation syntax.

Rework string handling in pmcstat(8) to use an opaque type for
interned strings. Clean up ELF parsing code and add support for
tracking dynamic object mappings reported by a v2.0.00 hwpmc(4).

Report statistics at the end of a log conversion run depending
on the requested verbosity level.

Reviewed by: jhb, dds (kernel parts of an earlier patch)
Tested by: gallatin (earlier patch)


# bea6aa93 24-Dec-2005 Joseph Koshy <jkoshy@FreeBSD.org>

- Don't print an errno string when reporting dropped samples.
- Prevent an unsuccessful exec() of a target program from triggering
a false 'dropped samples' message.


# 7fbf3da2 21-Oct-2005 Joseph Koshy <jkoshy@FreeBSD.org>

Warn the user if the kernel driver dropped samples or ran out of event buffers
during a data collection run.


# 4525db8c 05-Sep-2005 Joseph Koshy <jkoshy@FreeBSD.org>

Improve an error message.

MFC after: 3 days


# 38fc5f34 03-Aug-2005 Joseph Koshy <jkoshy@FreeBSD.org>

Correctly print system-wide PMC counts for short-lived command lines.

Reported by: cracauer
MFC after: 3 days


# 9133b639 23-Jul-2005 Joseph Koshy <jkoshy@FreeBSD.org>

Sync usage message with the code and manual page.

Submitted by: maxim


# dc1d9d2e 09-Jul-2005 Joseph Koshy <jkoshy@FreeBSD.org>

Fix a bug that affected on-the-fly gmon.out file generation.

Approved by: re (scottl)


# 15139246 30-Jun-2005 Joseph Koshy <jkoshy@FreeBSD.org>

MFP4:

- pmcstat(8) gprof output mode fixes:

lib/libpmc/pmclog.{c,h}, sys/sys/pmclog.h:
+ Add a 'is_usermode' field to the PMCLOG_PCSAMPLE event
+ Add an 'entryaddr' field to the PMCLOG_PROCEXEC event,
so that pmcstat(8) can determine where the runtime loader
/libexec/ld-elf.so.1 is getting loaded.

sys/kern/kern_exec.c:
+ Use a local struct to group the entry address of the image being
exec()'ed and the process credential changed flag to the exec
handling hook inside hwpmc(4).

usr.sbin/pmcstat/*:
+ Support "-k kernelpath", "-D sampledir".
+ Implement the ELF bits of 'gmon.out' profile generation in a new
file "pmcstat_log.c". Move all log related functions to this
file.
+ Move local definitions and prototypes to "pmcstat.h"

- Other bug fixes:
+ lib/libpmc/pmclog.c: correctly handle EOF in pmclog_read().
+ sys/dev/hwpmc_mod.c: unconditionally log a PROCEXIT event to all
attached PMCs when a process exits.
+ sys/sys/pmc.h: correct a function prototype.
+ Improve usage checks in pmcstat(8).

Approved by: re (blanket hwpmc)


# f263522a 09-Jun-2005 Joseph Koshy <jkoshy@FreeBSD.org>

MFP4:

- Implement sampling modes and logging support in hwpmc(4).

- Separate MI and MD parts of hwpmc(4) and allow sharing of
PMC implementations across different architectures.
Add support for P4 (EMT64) style PMCs to the amd64 code.

- New pmcstat(8) options: -E (exit time counts) -W (counts
every context switch), -R (print log file).

- pmc(3) API changes, improve our ability to keep ABI compatibility
in the future. Add more 'alias' names for commonly used events.

- bug fixes & documentation.


# 39f4e0fc 02-May-2005 Joseph Koshy <jkoshy@FreeBSD.org>

Neaten usage message.


# c5153e19 01-May-2005 Joseph Koshy <jkoshy@FreeBSD.org>

Add convenience APIs pmc_width() and pmc_capabilities() to -lpmc.
Have pmcstat(8) and pmccontrol(8) use these APIs.

Return PMC class-related constants (PMC widths and capabilities)
with the OP GETCPUINFO call leaving OP PMCINFO to return only the
dynamic information associated with a PMC (i.e., whether enabled,
owner pid, reload count etc.).

Allow pmc_read() (i.e., OPS PMCRW) on active self-attached PMCs to
get upto-date values from hardware since we can guarantee that the
hardware is running the correct PMC at the time of the call.

Bug fixes:
- (x86 class processors) Fix a bug that prevented an RDPMC
instruction from being recognized as permitted till after the
attached process had context switched out and back in again after
a pmc_start() call.

Tighten the rules for using RDPMC class instructions: a GETMSR
OP is now allowed only after an OP ATTACH has been done by the
PMC's owner to itself. OP GETMSR is not allowed for PMCs that
track descendants, for PMCs attached to processes other than
their owner processes.

- (P4/HTT processors only) Fix a bug that caused the MI and MD
layers to get out of sync. Add a new MD operation 'get_config()'
as part of this fix.

- Allow multiple system-mode PMCs at the same row-index but on
different CPUs to be allocated.

- Reject allocation of an administratively disabled PMC.

Misc. code cleanups and refactoring. Improve a few comments.


# ebccf1e3 18-Apr-2005 Joseph Koshy <jkoshy@FreeBSD.org>

Bring a working snapshot of hwpmc(4), its associated libraries, userland utilities
and documentation into -CURRENT.

Bump FreeBSD_version.

Reviewed by: alc, jhb (kernel changes)