diff options
author | Zachary Leaf <zachary.leaf@arm.com> | 2022-05-12 02:26:00 -0500 |
---|---|---|
committer | Damjan Marion <dmarion@0xa5.net> | 2022-07-12 15:29:23 +0000 |
commit | 268d7be66b8b48a230e06de645e3a8b7de29d93c (patch) | |
tree | 098d15e0c3f6fa7864c3f581367d8d5bb80495fa /src/plugins/perfmon/cli.c | |
parent | c7d43a5eb19f2acab900274432cfd0e136d6cb44 (diff) |
perfmon: enable perfmon plugin for Arm
This patch enables statistics from the Arm PMUv3 through the perfmon
plugin.
In comparison to using the Linux "perf" tool, it allows obtaining
direct, per node level statistics (rather than per thread). By accessing
the PMU counter registers directly from userspace, we can avoid the
overhead of using a read() system call and get more accurate and fine
grained statistics about the running of individual nodes.
A demo of perfmon on Arm can be found at:
https://asciinema.org/a/egVNN1OF7JEKHYmfl5bpDYxfF
*Important Note*
Perfmon on Arm is dependent on and works only on Linux kernel versions
of v5.17+ as this is when userspace access to Arm perf counters was
included.
On most Arm systems, a maximum of 7 PMU events can be configured at once
- (6x PMU events + 1x CPU_CYCLE counter). If some perf counters are in
use elsewhere by other applications, and there are insufficient counters
remaining to open the bundle, the perf_event_open call will fail
(provided the events are grouped with the group_fd param, which perfmon
currently utilises).
See arm/events.h for a list of PMUv3 events available, although it is
implementation defined whether most events are implemented or not. Only
a small set of 7 events is required to be implemented in Armv8.0, with
some additional events required in later versions. As such, depending on
the implementation, some statistics may not be available. See Arm
Architecture Reference Manual for Armv8-A, D7.10.2 "The PMU event number
space and common events" for more information.
arm/events.c:arm_init() gets information from the sysfs about what
events are implemented on a particular CPU at runtime. Arm's
implementation of the perfmon source callback .bundle_support uses this
information to disable unsupported events in a bundle, or in the case
no events are supported, disable the entire bundle.
Where a particular event in a bundle is not implemented, the statistic
for that event is shown as '-' in the 'show perfmon statistics' cli
output, by disabling the column.
There is additional code in perfmon.c to only open events which are
marked as implemented. Since we're only opening and reading events that
are implemented, some extra logic is required in cli.c to re-align
either perfmon_node_stats_t or perfmon_reading_t with the column
headings configured in each bundle, taking into account disabled
columns.
Userspace access to perf counters is disabled by default, and needs to
be enabled with 'sudo sysctl kernel/perf_user_access=1'.
There is a check built into the Arm event source init function
(arm/events.c:arm_init) to check that userspace reading of perf counters
is enabled in the /proc/sys/kernel/perf_user_access file.
If the above file does not exist, it means the kernel version is
unsupported. Users without a supported kernel will see a warning
message, and no Arm bundles will be registered to use in perfmon.
Enabling/using plugin:
- include the following in startup.conf:
- plugins { plugin perfmon_plugin.so { enable }
- 'show perfmon bundle [verbose]' - show available statistics bundles
- 'perfmon start bundle <bundle-name>' - enable and start logging
- 'perfmon stop' - stop logging
- 'show perfmon statistics' - show output
For a general guide on using and understanding Arm PMUv3 events, see
https://community.arm.com/arm-community-blogs/b/tools-software-ides-blog/posts/arm-neoverse-n1-performance-analysis-methodology
Type: feature
Signed-off-by: Zachary Leaf <zachary.leaf@arm.com>
Tested-by: Jieqiang Wang <jieqiang.wang@arm.com>
Change-Id: I0620fe5b1bbe78842dfb1d0b6a060bb99e777651
Diffstat (limited to 'src/plugins/perfmon/cli.c')
-rw-r--r-- | src/plugins/perfmon/cli.c | 73 |
1 files changed, 66 insertions, 7 deletions
diff --git a/src/plugins/perfmon/cli.c b/src/plugins/perfmon/cli.c index aa5b5636235..0cdc4dba073 100644 --- a/src/plugins/perfmon/cli.c +++ b/src/plugins/perfmon/cli.c @@ -413,18 +413,77 @@ show_perfmon_stats_command_fn (vlib_main_t *vm, unformat_input_t *input, vm, j, b->active_type); table_set_cell_align (t, col, -1, TTAA_RIGHT); table_set_cell_fg_color (t, col, -1, TTAC_CYAN); - clib_memcpy_fast (&ns, tr->node_stats + j, sizeof (ns)); + + if (PREDICT_TRUE (clib_bitmap_is_zero (b->event_disabled))) + clib_memcpy_fast (&ns, tr->node_stats + j, sizeof (ns)); + /* if some events are not implemented, we need to realign these + to display under the correct column headers */ + else + { + perfmon_node_stats_t *tr_ns = tr->node_stats + j; + ns.n_calls = tr_ns->n_calls; + ns.n_packets = tr_ns->n_packets; + /* loop through all events in bundle + manually copy into + the correct place, until we've read all values that are + implemented */ + int num_enabled_events = + b->n_events - + clib_bitmap_count_set_bits (b->event_disabled); + for (int i = 0, k = 0; k < num_enabled_events; i++) + { + if (!clib_bitmap_get (b->event_disabled, i)) + { + ns.value[i] = tr_ns->value[k]; + k++; + } + } + } for (int j = 0; j < n_row; j++) - table_format_cell (t, col, j, "%U", b->format_fn, &ns, j, - b->active_type); + { + if (clib_bitmap_get (b->column_disabled, j)) + table_format_cell (t, col, j, "-"); + else + table_format_cell (t, col, j, "%U", b->format_fn, &ns, j, + b->active_type); + } } } - else + else /* b->type != PERFMON_BUNDLE_TYPE_NODE */ { - for (int j = 0; j < n_row; j++) - table_format_cell (t, i, j, "%U", b->format_fn, r, j, - b->active_type); + if (PREDICT_TRUE (clib_bitmap_is_zero (b->event_disabled))) + { + for (int j = 0; j < n_row; j++) + table_format_cell (t, i, j, "%U", b->format_fn, r, j, + b->active_type); + } + /* similarly for THREAD/SYSTEM bundles, if some events are not + implemented, we need to realign readings under column headings */ + else + { + perfmon_reading_t aligned_r[b->n_events]; + aligned_r->nr = r->nr; + aligned_r->time_enabled = r->time_enabled; + aligned_r->time_running = r->time_running; + int num_enabled_events = + b->n_events - clib_bitmap_count_set_bits (b->event_disabled); + for (int i = 0, k = 0; k < num_enabled_events; i++) + { + if (!clib_bitmap_get (b->event_disabled, i)) + { + aligned_r->value[i] = r->value[k]; + k++; + } + } + for (int j = 0; j < n_row; j++) + { + if (clib_bitmap_get (b->column_disabled, j)) + table_format_cell (t, col, j, "-"); + else + table_format_cell (t, i, j, "%U", b->format_fn, aligned_r, + j, b->active_type); + } + } } col++; } |