2019-05-29 22:18:02 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-09-01 03:40:31 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017, Intel Corporation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Manage metrics and groups of metrics from JSON files */
|
|
|
|
|
|
|
|
#include "metricgroup.h"
|
2019-08-30 02:56:40 +08:00
|
|
|
#include "debug.h"
|
2017-09-01 03:40:31 +08:00
|
|
|
#include "evlist.h"
|
2019-08-21 21:54:14 +08:00
|
|
|
#include "evsel.h"
|
2017-09-01 03:40:31 +08:00
|
|
|
#include "strbuf.h"
|
|
|
|
#include "pmu.h"
|
2021-09-03 10:52:39 +08:00
|
|
|
#include "pmu-hybrid.h"
|
2017-09-01 03:40:31 +08:00
|
|
|
#include "expr.h"
|
|
|
|
#include "rblist.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "strlist.h"
|
|
|
|
#include <assert.h>
|
2019-06-26 08:13:51 +08:00
|
|
|
#include <linux/ctype.h>
|
2021-10-16 01:21:20 +08:00
|
|
|
#include <linux/list_sort.h>
|
2019-08-30 02:56:40 +08:00
|
|
|
#include <linux/string.h>
|
2019-07-04 23:06:20 +08:00
|
|
|
#include <linux/zalloc.h>
|
2019-08-21 21:54:14 +08:00
|
|
|
#include <subcmd/parse-options.h>
|
perf metricgroup: Support metric constraint
Some metric groups have metric constraints. A metric group can be
scheduled as a group only when some constraints are applied. For
example, Page_Walks_Utilization has a metric constraint,
"NO_NMI_WATCHDOG".
When NMI watchdog is disabled, the metric group can be scheduled as a
group. Otherwise, splitting the metric group into standalone metrics.
Add a new function, metricgroup__has_constraint(), to check whether all
constraints are applied. If not, splitting the metric group into
standalone metrics.
Currently, only one constraint, "NO_NMI_WATCHDOG", is checked. Print a
warning for the metric group with the constraint, when NMI WATCHDOG is
enabled.
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Link: http://lore.kernel.org/lkml/1582581564-184429-5-git-send-email-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-02-25 05:59:23 +08:00
|
|
|
#include <api/fs/fs.h>
|
|
|
|
#include "util.h"
|
2020-07-20 02:13:16 +08:00
|
|
|
#include <asm/bug.h>
|
2020-09-24 20:44:53 +08:00
|
|
|
#include "cgroup.h"
|
2017-09-01 03:40:31 +08:00
|
|
|
|
|
|
|
struct metric_event *metricgroup__lookup(struct rblist *metric_events,
|
2019-07-21 19:23:51 +08:00
|
|
|
struct evsel *evsel,
|
2017-09-01 03:40:31 +08:00
|
|
|
bool create)
|
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
struct metric_event me = {
|
|
|
|
.evsel = evsel
|
|
|
|
};
|
perf script: Allow computing 'perf stat' style metrics
Add support for computing 'perf stat' style metrics in 'perf script'.
When using leader sampling we can get metrics for each sampling period
by computing formulas over the values of the different group members.
This allows things like fine grained IPC tracking through sampling, much
more fine grained than with 'perf stat'.
The metric is still averaged over the sampling period, it is not just
for the sampling point.
This patch adds a new metric output field for 'perf script' that uses
the existing 'perf stat' metrics infrastructure to compute any metrics
supported by 'perf stat'.
For example to sample IPC:
$ perf record -e '{ref-cycles,cycles,instructions}:S' -a sleep 1
$ perf script -F metric,ip,sym,time,cpu,comm
...
alsa-sink-ALC32 [000] 42815.856074: 7fd65937d6cc [unknown]
alsa-sink-ALC32 [000] 42815.856074: 7fd65937d6cc [unknown]
alsa-sink-ALC32 [000] 42815.856074: 7fd65937d6cc [unknown]
alsa-sink-ALC32 [000] 42815.856074: metric: 0.13 insn per cycle
swapper [000] 42815.857961: ffffffff81655df0 __schedule
swapper [000] 42815.857961: ffffffff81655df0 __schedule
swapper [000] 42815.857961: ffffffff81655df0 __schedule
swapper [000] 42815.857961: metric: 0.23 insn per cycle
qemu-system-x86 [000] 42815.858130: ffffffff8165ad0e _raw_spin_unlock_irqrestore
qemu-system-x86 [000] 42815.858130: ffffffff8165ad0e _raw_spin_unlock_irqrestore
qemu-system-x86 [000] 42815.858130: ffffffff8165ad0e _raw_spin_unlock_irqrestore
qemu-system-x86 [000] 42815.858130: metric: 0.46 insn per cycle
:4972 [000] 42815.858312: ffffffffa080e5f2 vmx_vcpu_run
:4972 [000] 42815.858312: ffffffffa080e5f2 vmx_vcpu_run
:4972 [000] 42815.858312: ffffffffa080e5f2 vmx_vcpu_run
:4972 [000] 42815.858312: metric: 0.45 insn per cycle
TopDown:
This requires disabling SMT if you have it enabled, because SMT would
require sampling per core, which is not supported.
$ perf record -e '{ref-cycles,topdown-fetch-bubbles,\
topdown-recovery-bubbles,\
topdown-slots-retired,topdown-total-slots,\
topdown-slots-issued}:S' -a sleep 1
$ perf script --header -I -F cpu,ip,sym,event,metric,period
...
[000] 121108 ref-cycles: ffffffff8165222e copy_user_enhanced_fast_string
[000] 190350 topdown-fetch-bubbles: ffffffff8165222e copy_user_enhanced_fast_string
[000] 2055 topdown-recovery-bubbles: ffffffff8165222e copy_user_enhanced_fast_string
[000] 148729 topdown-slots-retired: ffffffff8165222e copy_user_enhanced_fast_string
[000] 144324 topdown-total-slots: ffffffff8165222e copy_user_enhanced_fast_string
[000] 160852 topdown-slots-issued: ffffffff8165222e copy_user_enhanced_fast_string
[000] metric: 33.0% frontend bound
[000] metric: 3.5% bad speculation
[000] metric: 25.8% retiring
[000] metric: 37.7% backend bound
[000] 112112 ref-cycles: ffffffff8165aec8 _raw_spin_lock_irqsave
[000] 357222 topdown-fetch-bubbles: ffffffff8165aec8 _raw_spin_lock_irqsave
[000] 3325 topdown-recovery-bubbles: ffffffff8165aec8 _raw_spin_lock_irqsave
[000] 323553 topdown-slots-retired: ffffffff8165aec8 _raw_spin_lock_irqsave
[000] 270507 topdown-total-slots: ffffffff8165aec8 _raw_spin_lock_irqsave
[000] 341226 topdown-slots-issued: ffffffff8165aec8 _raw_spin_lock_irqsave
[000] metric: 33.0% frontend bound
[000] metric: 2.9% bad speculation
[000] metric: 29.9% retiring
[000] metric: 34.2% backend bound
...
v2:
Use evsel->priv for new fields
Port to new base line, support fp output.
Handle stats in ->stats, not ->priv
Minor cleanups
Extra explanation about the use of the term 'averaging', from Andi in the
thread in the Link: tag below:
<quote Andi>
The current samples contains the sum of event counts for a sampling period.
EventA-1 EventA-2 EventA-3 EventA-4
EventB-1 EventB-2 EventC-3
gap with no events overflow
|-----------------------------------------------------------------|
period-start period-end
^ ^
| |
previous sample current sample
So EventA = 4 and EventB = 3 at the sample point
I generate a metric, let's say EventA / EventB. It applies to the whole period.
But the metric is over a longer time which does not have the same behavior. For
example the gap above doesn't have any events, while they are clustered at the
beginning and end of the sample period.
But we're summing everything together. The metric doesn't know that the gap is
different than the busy period.
That's what I'm trying to express with averaging.
</quote>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20171117214300.32746-4-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2017-11-18 05:43:00 +08:00
|
|
|
|
|
|
|
if (!metric_events)
|
|
|
|
return NULL;
|
|
|
|
|
2017-09-01 03:40:31 +08:00
|
|
|
nd = rblist__find(metric_events, &me);
|
|
|
|
if (nd)
|
|
|
|
return container_of(nd, struct metric_event, nd);
|
|
|
|
if (create) {
|
|
|
|
rblist__add_node(metric_events, &me);
|
|
|
|
nd = rblist__find(metric_events, &me);
|
|
|
|
if (nd)
|
|
|
|
return container_of(nd, struct metric_event, nd);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int metric_event_cmp(struct rb_node *rb_node, const void *entry)
|
|
|
|
{
|
|
|
|
struct metric_event *a = container_of(rb_node,
|
|
|
|
struct metric_event,
|
|
|
|
nd);
|
|
|
|
const struct metric_event *b = entry;
|
|
|
|
|
|
|
|
if (a->evsel == b->evsel)
|
|
|
|
return 0;
|
|
|
|
if ((char *)a->evsel < (char *)b->evsel)
|
|
|
|
return -1;
|
|
|
|
return +1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct rb_node *metric_event_new(struct rblist *rblist __maybe_unused,
|
|
|
|
const void *entry)
|
|
|
|
{
|
|
|
|
struct metric_event *me = malloc(sizeof(struct metric_event));
|
|
|
|
|
|
|
|
if (!me)
|
|
|
|
return NULL;
|
|
|
|
memcpy(me, entry, sizeof(struct metric_event));
|
|
|
|
me->evsel = ((struct metric_event *)entry)->evsel;
|
|
|
|
INIT_LIST_HEAD(&me->head);
|
|
|
|
return &me->nd;
|
|
|
|
}
|
|
|
|
|
2020-06-03 05:47:38 +08:00
|
|
|
static void metric_event_delete(struct rblist *rblist __maybe_unused,
|
|
|
|
struct rb_node *rb_node)
|
|
|
|
{
|
|
|
|
struct metric_event *me = container_of(rb_node, struct metric_event, nd);
|
|
|
|
struct metric_expr *expr, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(expr, tmp, &me->head, nd) {
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
free((char *)expr->metric_name);
|
2020-07-20 02:13:10 +08:00
|
|
|
free(expr->metric_refs);
|
2020-09-15 11:18:10 +08:00
|
|
|
free(expr->metric_events);
|
2020-06-03 05:47:38 +08:00
|
|
|
free(expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(me);
|
|
|
|
}
|
|
|
|
|
2017-09-01 03:40:31 +08:00
|
|
|
static void metricgroup__rblist_init(struct rblist *metric_events)
|
|
|
|
{
|
|
|
|
rblist__init(metric_events);
|
|
|
|
metric_events->node_cmp = metric_event_cmp;
|
|
|
|
metric_events->node_new = metric_event_new;
|
2020-06-03 05:47:38 +08:00
|
|
|
metric_events->node_delete = metric_event_delete;
|
|
|
|
}
|
|
|
|
|
|
|
|
void metricgroup__rblist_exit(struct rblist *metric_events)
|
|
|
|
{
|
|
|
|
rblist__exit(metric_events);
|
2017-09-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
|
2020-07-20 02:13:09 +08:00
|
|
|
/*
|
|
|
|
* A node in the list of referenced metrics. metric_expr
|
|
|
|
* is held as a convenience to avoid a search through the
|
|
|
|
* metric list.
|
|
|
|
*/
|
|
|
|
struct metric_ref_node {
|
|
|
|
const char *metric_name;
|
|
|
|
const char *metric_expr;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
2021-10-16 01:21:22 +08:00
|
|
|
/**
|
|
|
|
* The metric under construction. The data held here will be placed in a
|
|
|
|
* metric_expr.
|
|
|
|
*/
|
2020-07-20 02:13:19 +08:00
|
|
|
struct metric {
|
2017-09-01 03:40:31 +08:00
|
|
|
struct list_head nd;
|
2021-10-16 01:21:22 +08:00
|
|
|
/**
|
|
|
|
* The expression parse context importantly holding the IDs contained
|
|
|
|
* within the expression.
|
|
|
|
*/
|
2021-09-23 15:46:04 +08:00
|
|
|
struct expr_parse_ctx *pctx;
|
2021-10-16 01:21:22 +08:00
|
|
|
/** The name of the metric such as "IPC". */
|
2017-09-01 03:40:31 +08:00
|
|
|
const char *metric_name;
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
/** Modifier on the metric such as "u" or NULL for none. */
|
|
|
|
const char *modifier;
|
2021-10-16 01:21:22 +08:00
|
|
|
/** The expression to parse, for example, "instructions/cycles". */
|
2017-09-01 03:40:31 +08:00
|
|
|
const char *metric_expr;
|
2021-10-16 01:21:22 +08:00
|
|
|
/**
|
|
|
|
* The "ScaleUnit" that scales and adds a unit to the metric during
|
|
|
|
* output.
|
|
|
|
*/
|
perf metricgroup: Scale the metric result
Some metrics define the scale unit, such as
{
"BriefDescription": "Intel Optane DC persistent memory read latency (ns). Derived from unc_m_pmm_rpq_occupancy.all",
"Counter": "0,1,2,3",
"EventCode": "0xE0",
"EventName": "UNC_M_PMM_READ_LATENCY",
"MetricExpr": "UNC_M_PMM_RPQ_OCCUPANCY.ALL / UNC_M_PMM_RPQ_INSERTS / UNC_M_CLOCKTICKS",
"MetricName": "UNC_M_PMM_READ_LATENCY",
"PerPkg": "1",
"ScaleUnit": "6000000000ns",
"UMask": "0x1",
"Unit": "iMC"
},
For above example, the ratio should be,
ratio = (UNC_M_PMM_RPQ_OCCUPANCY.ALL / UNC_M_PMM_RPQ_INSERTS / UNC_M_CLOCKTICKS) * 6000000000
But in current code, the ratio is not scaled ( * 6000000000)
With this patch, the ratio is scaled and the unit (ns) is printed.
For example,
# 219.4 ns UNC_M_PMM_READ_LATENCY
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20190828055932.8269-4-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-28 13:59:31 +08:00
|
|
|
const char *metric_unit;
|
2021-10-16 01:21:23 +08:00
|
|
|
/** Optional null terminated array of referenced metrics. */
|
|
|
|
struct metric_ref *metric_refs;
|
2021-10-16 01:21:22 +08:00
|
|
|
/**
|
|
|
|
* Is there a constraint on the group of events? In which case the
|
|
|
|
* events won't be grouped.
|
|
|
|
*/
|
2020-05-21 02:20:07 +08:00
|
|
|
bool has_constraint;
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
/**
|
|
|
|
* Parsed events for the metric. Optional as events may be taken from a
|
|
|
|
* different metric whose group contains all the IDs necessary for this
|
|
|
|
* one.
|
|
|
|
*/
|
|
|
|
struct evlist *evlist;
|
2017-09-01 03:40:31 +08:00
|
|
|
};
|
|
|
|
|
2021-10-16 01:21:18 +08:00
|
|
|
static void metricgroup___watchdog_constraint_hint(const char *name, bool foot)
|
|
|
|
{
|
|
|
|
static bool violate_nmi_constraint;
|
|
|
|
|
|
|
|
if (!foot) {
|
|
|
|
pr_warning("Splitting metric group %s into standalone metrics.\n", name);
|
|
|
|
violate_nmi_constraint = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!violate_nmi_constraint)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pr_warning("Try disabling the NMI watchdog to comply NO_NMI_WATCHDOG metric constraint:\n"
|
|
|
|
" echo 0 > /proc/sys/kernel/nmi_watchdog\n"
|
|
|
|
" perf stat ...\n"
|
|
|
|
" echo 1 > /proc/sys/kernel/nmi_watchdog\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool metricgroup__has_constraint(const struct pmu_event *pe)
|
|
|
|
{
|
|
|
|
if (!pe->metric_constraint)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!strcmp(pe->metric_constraint, "NO_NMI_WATCHDOG") &&
|
|
|
|
sysctl__nmi_watchdog_enabled()) {
|
|
|
|
metricgroup___watchdog_constraint_hint(pe->metric_name, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct metric *metric__new(const struct pmu_event *pe,
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
const char *modifier,
|
2021-10-16 01:21:18 +08:00
|
|
|
bool metric_no_group,
|
|
|
|
int runtime)
|
|
|
|
{
|
|
|
|
struct metric *m;
|
|
|
|
|
|
|
|
m = zalloc(sizeof(*m));
|
|
|
|
if (!m)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
m->pctx = expr__ctx_new();
|
|
|
|
if (!m->pctx) {
|
|
|
|
free(m);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
m->metric_name = pe->metric_name;
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
m->modifier = modifier ? strdup(modifier) : NULL;
|
|
|
|
if (modifier && !m->modifier) {
|
|
|
|
expr__ctx_free(m->pctx);
|
2021-12-09 01:11:13 +08:00
|
|
|
free(m);
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2021-10-16 01:21:18 +08:00
|
|
|
m->metric_expr = pe->metric_expr;
|
|
|
|
m->metric_unit = pe->unit;
|
|
|
|
m->pctx->runtime = runtime;
|
|
|
|
m->has_constraint = metric_no_group || metricgroup__has_constraint(pe);
|
2021-10-16 01:21:23 +08:00
|
|
|
m->metric_refs = NULL;
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
m->evlist = NULL;
|
2021-10-16 01:21:18 +08:00
|
|
|
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void metric__free(struct metric *m)
|
|
|
|
{
|
2021-10-16 01:21:23 +08:00
|
|
|
free(m->metric_refs);
|
2021-10-16 01:21:18 +08:00
|
|
|
expr__ctx_free(m->pctx);
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
free((char *)m->modifier);
|
2021-11-07 17:00:02 +08:00
|
|
|
evlist__delete(m->evlist);
|
2021-10-16 01:21:18 +08:00
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
static bool contains_metric_id(struct evsel **metric_events, int num_events,
|
|
|
|
const char *metric_id)
|
2020-09-18 04:18:07 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_events; i++) {
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
if (!strcmp(evsel__metric_id(metric_events[i]), metric_id))
|
2020-09-18 04:18:07 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
perf metricgroup: Remove duped metric group events
A metric group contains multiple metrics. These metrics may use the same
events. If metrics use separate events then it leads to more
multiplexing and overall metric counts fail to sum to 100%.
Modify how metrics are associated with events so that if the events in
an earlier group satisfy the current metric, the same events are used.
A record of used events is kept and at the end of processing unnecessary
events are eliminated.
Before:
$ perf stat -a -M TopDownL1 sleep 1
Performance counter stats for 'system wide':
920,211,343 uops_issued.any # 0.5 Backend_Bound (16.56%)
1,977,733,128 idq_uops_not_delivered.core (16.56%)
51,668,510 int_misc.recovery_cycles (16.56%)
732,305,692 uops_retired.retire_slots (16.56%)
1,497,621,849 cycles (16.56%)
721,098,274 uops_issued.any # 0.1 Bad_Speculation (16.79%)
1,332,681,791 cycles (16.79%)
552,475,482 uops_retired.retire_slots (16.79%)
47,708,340 int_misc.recovery_cycles (16.79%)
1,383,713,292 cycles
# 0.4 Frontend_Bound (16.76%)
2,013,757,701 idq_uops_not_delivered.core (16.76%)
1,373,363,790 cycles
# 0.1 Retiring (33.54%)
577,302,589 uops_retired.retire_slots (33.54%)
392,766,987 inst_retired.any # 0.3 IPC (50.24%)
1,351,873,350 cpu_clk_unhalted.thread (50.24%)
1,332,510,318 cycles
# 5330041272.0 SLOTS (49.90%)
1.006336145 seconds time elapsed
After:
$ perf stat -a -M TopDownL1 sleep 1
Performance counter stats for 'system wide':
765,949,145 uops_issued.any # 0.1 Bad_Speculation
# 0.5 Backend_Bound (50.09%)
1,883,830,591 idq_uops_not_delivered.core # 0.3 Frontend_Bound (50.09%)
48,237,080 int_misc.recovery_cycles (50.09%)
581,798,385 uops_retired.retire_slots # 0.1 Retiring (50.09%)
1,361,628,527 cycles
# 5446514108.0 SLOTS (50.09%)
391,415,714 inst_retired.any # 0.3 IPC (49.91%)
1,336,486,781 cpu_clk_unhalted.thread (49.91%)
1.005469298 seconds time elapsed
Note: Bad_Speculation + Backend_Bound + Frontend_Bound + Retiring = 100%
after, where as before it is 110%. After there are 2 groups, whereas
before there are 6. After the cycles event appears once, before it
appeared 5 times.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrii Nakryiko <andriin@fb.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org
Link: http://lore.kernel.org/lkml/20200520182011.32236-6-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-21 02:20:09 +08:00
|
|
|
/**
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
* setup_metric_events - Find a group of events in metric_evlist that correspond
|
|
|
|
* to the IDs from a parsed metric expression.
|
|
|
|
* @ids: the metric IDs to match.
|
|
|
|
* @metric_evlist: the list of perf events.
|
|
|
|
* @out_metric_events: holds the created metric events array.
|
perf metricgroup: Remove duped metric group events
A metric group contains multiple metrics. These metrics may use the same
events. If metrics use separate events then it leads to more
multiplexing and overall metric counts fail to sum to 100%.
Modify how metrics are associated with events so that if the events in
an earlier group satisfy the current metric, the same events are used.
A record of used events is kept and at the end of processing unnecessary
events are eliminated.
Before:
$ perf stat -a -M TopDownL1 sleep 1
Performance counter stats for 'system wide':
920,211,343 uops_issued.any # 0.5 Backend_Bound (16.56%)
1,977,733,128 idq_uops_not_delivered.core (16.56%)
51,668,510 int_misc.recovery_cycles (16.56%)
732,305,692 uops_retired.retire_slots (16.56%)
1,497,621,849 cycles (16.56%)
721,098,274 uops_issued.any # 0.1 Bad_Speculation (16.79%)
1,332,681,791 cycles (16.79%)
552,475,482 uops_retired.retire_slots (16.79%)
47,708,340 int_misc.recovery_cycles (16.79%)
1,383,713,292 cycles
# 0.4 Frontend_Bound (16.76%)
2,013,757,701 idq_uops_not_delivered.core (16.76%)
1,373,363,790 cycles
# 0.1 Retiring (33.54%)
577,302,589 uops_retired.retire_slots (33.54%)
392,766,987 inst_retired.any # 0.3 IPC (50.24%)
1,351,873,350 cpu_clk_unhalted.thread (50.24%)
1,332,510,318 cycles
# 5330041272.0 SLOTS (49.90%)
1.006336145 seconds time elapsed
After:
$ perf stat -a -M TopDownL1 sleep 1
Performance counter stats for 'system wide':
765,949,145 uops_issued.any # 0.1 Bad_Speculation
# 0.5 Backend_Bound (50.09%)
1,883,830,591 idq_uops_not_delivered.core # 0.3 Frontend_Bound (50.09%)
48,237,080 int_misc.recovery_cycles (50.09%)
581,798,385 uops_retired.retire_slots # 0.1 Retiring (50.09%)
1,361,628,527 cycles
# 5446514108.0 SLOTS (50.09%)
391,415,714 inst_retired.any # 0.3 IPC (49.91%)
1,336,486,781 cpu_clk_unhalted.thread (49.91%)
1.005469298 seconds time elapsed
Note: Bad_Speculation + Backend_Bound + Frontend_Bound + Retiring = 100%
after, where as before it is 110%. After there are 2 groups, whereas
before there are 6. After the cycles event appears once, before it
appeared 5 times.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrii Nakryiko <andriin@fb.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org
Link: http://lore.kernel.org/lkml/20200520182011.32236-6-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-21 02:20:09 +08:00
|
|
|
*/
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
static int setup_metric_events(struct hashmap *ids,
|
|
|
|
struct evlist *metric_evlist,
|
|
|
|
struct evsel ***out_metric_events)
|
2017-09-01 03:40:31 +08:00
|
|
|
{
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
struct evsel **metric_events;
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
const char *metric_id;
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
struct evsel *ev;
|
|
|
|
size_t ids_size, matched_events, i;
|
perf metricgroup: Remove duped metric group events
A metric group contains multiple metrics. These metrics may use the same
events. If metrics use separate events then it leads to more
multiplexing and overall metric counts fail to sum to 100%.
Modify how metrics are associated with events so that if the events in
an earlier group satisfy the current metric, the same events are used.
A record of used events is kept and at the end of processing unnecessary
events are eliminated.
Before:
$ perf stat -a -M TopDownL1 sleep 1
Performance counter stats for 'system wide':
920,211,343 uops_issued.any # 0.5 Backend_Bound (16.56%)
1,977,733,128 idq_uops_not_delivered.core (16.56%)
51,668,510 int_misc.recovery_cycles (16.56%)
732,305,692 uops_retired.retire_slots (16.56%)
1,497,621,849 cycles (16.56%)
721,098,274 uops_issued.any # 0.1 Bad_Speculation (16.79%)
1,332,681,791 cycles (16.79%)
552,475,482 uops_retired.retire_slots (16.79%)
47,708,340 int_misc.recovery_cycles (16.79%)
1,383,713,292 cycles
# 0.4 Frontend_Bound (16.76%)
2,013,757,701 idq_uops_not_delivered.core (16.76%)
1,373,363,790 cycles
# 0.1 Retiring (33.54%)
577,302,589 uops_retired.retire_slots (33.54%)
392,766,987 inst_retired.any # 0.3 IPC (50.24%)
1,351,873,350 cpu_clk_unhalted.thread (50.24%)
1,332,510,318 cycles
# 5330041272.0 SLOTS (49.90%)
1.006336145 seconds time elapsed
After:
$ perf stat -a -M TopDownL1 sleep 1
Performance counter stats for 'system wide':
765,949,145 uops_issued.any # 0.1 Bad_Speculation
# 0.5 Backend_Bound (50.09%)
1,883,830,591 idq_uops_not_delivered.core # 0.3 Frontend_Bound (50.09%)
48,237,080 int_misc.recovery_cycles (50.09%)
581,798,385 uops_retired.retire_slots # 0.1 Retiring (50.09%)
1,361,628,527 cycles
# 5446514108.0 SLOTS (50.09%)
391,415,714 inst_retired.any # 0.3 IPC (49.91%)
1,336,486,781 cpu_clk_unhalted.thread (49.91%)
1.005469298 seconds time elapsed
Note: Bad_Speculation + Backend_Bound + Frontend_Bound + Retiring = 100%
after, where as before it is 110%. After there are 2 groups, whereas
before there are 6. After the cycles event appears once, before it
appeared 5 times.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrii Nakryiko <andriin@fb.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org
Link: http://lore.kernel.org/lkml/20200520182011.32236-6-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-05-21 02:20:09 +08:00
|
|
|
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
*out_metric_events = NULL;
|
|
|
|
ids_size = hashmap__size(ids);
|
2021-09-23 15:46:12 +08:00
|
|
|
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
metric_events = calloc(sizeof(void *), ids_size + 1);
|
|
|
|
if (!metric_events)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
matched_events = 0;
|
|
|
|
evlist__for_each_entry(metric_evlist, ev) {
|
|
|
|
struct expr_id_data *val_ptr;
|
2021-09-23 15:46:12 +08:00
|
|
|
|
2020-09-18 04:18:07 +08:00
|
|
|
/*
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
* Check for duplicate events with the same name. For
|
|
|
|
* example, uncore_imc/cas_count_read/ will turn into 6
|
|
|
|
* events per socket on skylakex. Only the first such
|
|
|
|
* event is placed in metric_events.
|
2020-09-18 04:18:07 +08:00
|
|
|
*/
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
metric_id = evsel__metric_id(ev);
|
|
|
|
if (contains_metric_id(metric_events, matched_events, metric_id))
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* Does this event belong to the parse context? For
|
|
|
|
* combined or shared groups, this metric may not care
|
|
|
|
* about this event.
|
|
|
|
*/
|
|
|
|
if (hashmap__find(ids, metric_id, (void **)&val_ptr)) {
|
2021-09-23 15:46:12 +08:00
|
|
|
metric_events[matched_events++] = ev;
|
2019-08-28 13:59:32 +08:00
|
|
|
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
if (matched_events >= ids_size)
|
|
|
|
break;
|
|
|
|
}
|
2019-08-28 13:59:32 +08:00
|
|
|
}
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
if (matched_events < ids_size) {
|
|
|
|
free(metric_events);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ids_size; i++) {
|
perf metricgroup: Fix printing event names of metric group with multiple events incase of overlapping events
Commit f01642e4912b ("perf metricgroup: Support multiple events for
metricgroup") introduced support for multiple events in a metric group.
But with the current upstream, metric events names are not printed
properly incase we try to run multiple metric groups with overlapping
event.
With current upstream version, incase of overlapping metric events issue
is, we always start our comparision logic from start. So, the events
which already matched with some metric group also take part in
comparision logic. Because of that when we have overlapping events, we
end up matching current metric group event with already matched one.
For example, in skylake machine we have metric event CoreIPC and
Instructions. Both of them need 'inst_retired.any' event value. As
events in Instructions is subset of events in CoreIPC, they endup in
pointing to same 'inst_retired.any' value.
In skylake platform:
command:# ./perf stat -M CoreIPC,Instructions -C 0 sleep 1
Performance counter stats for 'CPU(s) 0':
1,254,992,790 inst_retired.any # 1254992790.0
Instructions
# 1.3 CoreIPC
977,172,805 cycles
1,254,992,756 inst_retired.any
1.000802596 seconds time elapsed
command:# sudo ./perf stat -M UPI,IPC sleep 1
Performance counter stats for 'sleep 1':
948,650 uops_retired.retire_slots
866,182 inst_retired.any # 0.7 IPC
866,182 inst_retired.any
1,175,671 cpu_clk_unhalted.thread
Patch fixes the issue by adding a new bool pointer 'evlist_used' to keep
track of events which already matched with some group by setting it
true. So, we skip all used events in list when we start comparision
logic. Patch also make some changes in comparision logic, incase we get
a match miss, we discard the whole match and start again with first
event id in metric event.
With this patch:
In skylake platform:
command:# ./perf stat -M CoreIPC,Instructions -C 0 sleep 1
Performance counter stats for 'CPU(s) 0':
3,348,415 inst_retired.any # 0.3 CoreIPC
11,779,026 cycles
3,348,381 inst_retired.any # 3348381.0
Instructions
1.001649056 seconds time elapsed
command:# ./perf stat -M UPI,IPC sleep 1
Performance counter stats for 'sleep 1':
1,023,148 uops_retired.retire_slots # 1.1 UPI
924,976 inst_retired.any
924,976 inst_retired.any # 0.6 IPC
1,489,414 cpu_clk_unhalted.thread
1.003064672 seconds time elapsed
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Anju T Sudhakar <anju@linux.vnet.ibm.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Link: http://lore.kernel.org/lkml/20200221101121.28920-1-kjain@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-02-21 18:11:21 +08:00
|
|
|
ev = metric_events[i];
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
ev->collect_stat = true;
|
|
|
|
|
2020-09-18 04:18:07 +08:00
|
|
|
/*
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
* The metric leader points to the identically named
|
|
|
|
* event in metric_events.
|
2020-09-18 04:18:07 +08:00
|
|
|
*/
|
|
|
|
ev->metric_leader = ev;
|
|
|
|
/*
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
* Mark two events with identical names in the same
|
|
|
|
* group (or globally) as being in use as uncore events
|
|
|
|
* may be duplicated for each pmu. Set the metric leader
|
|
|
|
* of such events to be the event that appears in
|
|
|
|
* metric_events.
|
2020-09-18 04:18:07 +08:00
|
|
|
*/
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
metric_id = evsel__metric_id(ev);
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
evlist__for_each_entry_continue(metric_evlist, ev) {
|
2022-01-15 14:28:52 +08:00
|
|
|
if (!strcmp(evsel__metric_id(ev), metric_id))
|
2020-09-18 04:18:07 +08:00
|
|
|
ev->metric_leader = metric_events[i];
|
|
|
|
}
|
2019-08-28 13:59:32 +08:00
|
|
|
}
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
*out_metric_events = metric_events;
|
|
|
|
return 0;
|
2017-09-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool match_metric(const char *n, const char *list)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
char *m;
|
|
|
|
|
|
|
|
if (!list)
|
|
|
|
return false;
|
|
|
|
if (!strcmp(list, "all"))
|
|
|
|
return true;
|
|
|
|
if (!n)
|
|
|
|
return !strcasecmp(list, "No_group");
|
|
|
|
len = strlen(list);
|
|
|
|
m = strcasestr(n, list);
|
|
|
|
if (!m)
|
|
|
|
return false;
|
|
|
|
if ((m == n || m[-1] == ';' || m[-1] == ' ') &&
|
|
|
|
(m[len] == 0 || m[len] == ';'))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-16 01:21:15 +08:00
|
|
|
static bool match_pe_metric(const struct pmu_event *pe, const char *metric)
|
2020-12-04 19:10:15 +08:00
|
|
|
{
|
|
|
|
return match_metric(pe->metric_group, metric) ||
|
|
|
|
match_metric(pe->metric_name, metric);
|
|
|
|
}
|
|
|
|
|
2017-09-01 03:40:32 +08:00
|
|
|
struct mep {
|
|
|
|
struct rb_node nd;
|
|
|
|
const char *name;
|
|
|
|
struct strlist *metrics;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int mep_cmp(struct rb_node *rb_node, const void *entry)
|
|
|
|
{
|
|
|
|
struct mep *a = container_of(rb_node, struct mep, nd);
|
|
|
|
struct mep *b = (struct mep *)entry;
|
|
|
|
|
|
|
|
return strcmp(a->name, b->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct rb_node *mep_new(struct rblist *rl __maybe_unused,
|
|
|
|
const void *entry)
|
|
|
|
{
|
|
|
|
struct mep *me = malloc(sizeof(struct mep));
|
|
|
|
|
|
|
|
if (!me)
|
|
|
|
return NULL;
|
|
|
|
memcpy(me, entry, sizeof(struct mep));
|
|
|
|
me->name = strdup(me->name);
|
|
|
|
if (!me->name)
|
|
|
|
goto out_me;
|
|
|
|
me->metrics = strlist__new(NULL, NULL);
|
|
|
|
if (!me->metrics)
|
|
|
|
goto out_name;
|
|
|
|
return &me->nd;
|
|
|
|
out_name:
|
2019-07-04 23:06:20 +08:00
|
|
|
zfree(&me->name);
|
2017-09-01 03:40:32 +08:00
|
|
|
out_me:
|
|
|
|
free(me);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mep *mep_lookup(struct rblist *groups, const char *name)
|
|
|
|
{
|
|
|
|
struct rb_node *nd;
|
|
|
|
struct mep me = {
|
|
|
|
.name = name
|
|
|
|
};
|
|
|
|
nd = rblist__find(groups, &me);
|
|
|
|
if (nd)
|
|
|
|
return container_of(nd, struct mep, nd);
|
|
|
|
rblist__add_node(groups, &me);
|
|
|
|
nd = rblist__find(groups, &me);
|
|
|
|
if (nd)
|
|
|
|
return container_of(nd, struct mep, nd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mep_delete(struct rblist *rl __maybe_unused,
|
|
|
|
struct rb_node *nd)
|
|
|
|
{
|
|
|
|
struct mep *me = container_of(nd, struct mep, nd);
|
|
|
|
|
|
|
|
strlist__delete(me->metrics);
|
2019-07-04 23:06:20 +08:00
|
|
|
zfree(&me->name);
|
2017-09-01 03:40:32 +08:00
|
|
|
free(me);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void metricgroup__print_strlist(struct strlist *metrics, bool raw)
|
|
|
|
{
|
|
|
|
struct str_node *sn;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
strlist__for_each_entry (sn, metrics) {
|
|
|
|
if (raw)
|
|
|
|
printf("%s%s", n > 0 ? " " : "", sn->s);
|
|
|
|
else
|
|
|
|
printf(" %s\n", sn->s);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
if (raw)
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
2021-10-16 01:21:15 +08:00
|
|
|
static int metricgroup__print_pmu_event(const struct pmu_event *pe,
|
2020-12-04 19:10:13 +08:00
|
|
|
bool metricgroups, char *filter,
|
|
|
|
bool raw, bool details,
|
|
|
|
struct rblist *groups,
|
|
|
|
struct strlist *metriclist)
|
|
|
|
{
|
|
|
|
const char *g;
|
|
|
|
char *omg, *mg;
|
|
|
|
|
|
|
|
g = pe->metric_group;
|
|
|
|
if (!g && pe->metric_name) {
|
|
|
|
if (pe->name)
|
|
|
|
return 0;
|
|
|
|
g = "No_group";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mg = strdup(g);
|
|
|
|
|
|
|
|
if (!mg)
|
|
|
|
return -ENOMEM;
|
|
|
|
omg = mg;
|
|
|
|
while ((g = strsep(&mg, ";")) != NULL) {
|
|
|
|
struct mep *me;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
g = skip_spaces(g);
|
|
|
|
if (*g == 0)
|
|
|
|
g = "No_group";
|
|
|
|
if (filter && !strstr(g, filter))
|
|
|
|
continue;
|
|
|
|
if (raw)
|
|
|
|
s = (char *)pe->metric_name;
|
|
|
|
else {
|
|
|
|
if (asprintf(&s, "%s\n%*s%s]",
|
|
|
|
pe->metric_name, 8, "[", pe->desc) < 0)
|
|
|
|
return -1;
|
|
|
|
if (details) {
|
|
|
|
if (asprintf(&s, "%s\n%*s%s]",
|
|
|
|
s, 8, "[", pe->metric_expr) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!s)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!metricgroups) {
|
|
|
|
strlist__add(metriclist, s);
|
|
|
|
} else {
|
|
|
|
me = mep_lookup(groups, g);
|
|
|
|
if (!me)
|
|
|
|
continue;
|
|
|
|
strlist__add(me->metrics, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!raw)
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
free(omg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-04 19:10:14 +08:00
|
|
|
struct metricgroup_print_sys_idata {
|
|
|
|
struct strlist *metriclist;
|
|
|
|
char *filter;
|
|
|
|
struct rblist *groups;
|
|
|
|
bool metricgroups;
|
|
|
|
bool raw;
|
|
|
|
bool details;
|
|
|
|
};
|
|
|
|
|
2021-10-16 01:21:15 +08:00
|
|
|
typedef int (*metricgroup_sys_event_iter_fn)(const struct pmu_event *pe, void *);
|
2020-12-04 19:10:14 +08:00
|
|
|
|
|
|
|
struct metricgroup_iter_data {
|
|
|
|
metricgroup_sys_event_iter_fn fn;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
2021-10-16 01:21:15 +08:00
|
|
|
static int metricgroup__sys_event_iter(const struct pmu_event *pe, void *data)
|
2020-12-04 19:10:14 +08:00
|
|
|
{
|
|
|
|
struct metricgroup_iter_data *d = data;
|
|
|
|
struct perf_pmu *pmu = NULL;
|
|
|
|
|
|
|
|
if (!pe->metric_expr || !pe->compat)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while ((pmu = perf_pmu__scan(pmu))) {
|
|
|
|
|
|
|
|
if (!pmu->id || strcmp(pmu->id, pe->compat))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return d->fn(pe, d->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-16 01:21:15 +08:00
|
|
|
static int metricgroup__print_sys_event_iter(const struct pmu_event *pe, void *data)
|
2020-12-04 19:10:14 +08:00
|
|
|
{
|
|
|
|
struct metricgroup_print_sys_idata *d = data;
|
|
|
|
|
|
|
|
return metricgroup__print_pmu_event(pe, d->metricgroups, d->filter, d->raw,
|
|
|
|
d->details, d->groups, d->metriclist);
|
|
|
|
}
|
|
|
|
|
2017-09-01 03:40:32 +08:00
|
|
|
void metricgroup__print(bool metrics, bool metricgroups, char *filter,
|
2021-09-03 10:52:39 +08:00
|
|
|
bool raw, bool details, const char *pmu_name)
|
2017-09-01 03:40:32 +08:00
|
|
|
{
|
2021-10-16 01:21:13 +08:00
|
|
|
const struct pmu_events_map *map = pmu_events_map__find();
|
2021-10-16 01:21:15 +08:00
|
|
|
const struct pmu_event *pe;
|
2017-09-01 03:40:32 +08:00
|
|
|
int i;
|
|
|
|
struct rblist groups;
|
|
|
|
struct rb_node *node, *next;
|
|
|
|
struct strlist *metriclist = NULL;
|
|
|
|
|
|
|
|
if (!metricgroups) {
|
|
|
|
metriclist = strlist__new(NULL, NULL);
|
|
|
|
if (!metriclist)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rblist__init(&groups);
|
|
|
|
groups.node_new = mep_new;
|
|
|
|
groups.node_cmp = mep_cmp;
|
|
|
|
groups.node_delete = mep_delete;
|
2020-12-04 19:10:14 +08:00
|
|
|
for (i = 0; map; i++) {
|
2017-09-01 03:40:32 +08:00
|
|
|
pe = &map->table[i];
|
|
|
|
|
|
|
|
if (!pe->name && !pe->metric_group && !pe->metric_name)
|
|
|
|
break;
|
|
|
|
if (!pe->metric_expr)
|
|
|
|
continue;
|
2021-09-03 10:52:39 +08:00
|
|
|
if (pmu_name && perf_pmu__is_hybrid(pe->pmu) &&
|
|
|
|
strcmp(pmu_name, pe->pmu)) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-12-04 19:10:13 +08:00
|
|
|
if (metricgroup__print_pmu_event(pe, metricgroups, filter,
|
|
|
|
raw, details, &groups,
|
|
|
|
metriclist) < 0)
|
|
|
|
return;
|
2017-09-01 03:40:32 +08:00
|
|
|
}
|
|
|
|
|
2020-12-04 19:10:14 +08:00
|
|
|
{
|
|
|
|
struct metricgroup_iter_data data = {
|
|
|
|
.fn = metricgroup__print_sys_event_iter,
|
|
|
|
.data = (void *) &(struct metricgroup_print_sys_idata){
|
|
|
|
.metriclist = metriclist,
|
|
|
|
.metricgroups = metricgroups,
|
|
|
|
.filter = filter,
|
|
|
|
.raw = raw,
|
|
|
|
.details = details,
|
|
|
|
.groups = &groups,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
pmu_for_each_sys_event(metricgroup__sys_event_iter, &data);
|
|
|
|
}
|
|
|
|
|
2020-09-09 13:58:48 +08:00
|
|
|
if (!filter || !rblist__empty(&groups)) {
|
|
|
|
if (metricgroups && !raw)
|
|
|
|
printf("\nMetric Groups:\n\n");
|
|
|
|
else if (metrics && !raw)
|
|
|
|
printf("\nMetrics:\n\n");
|
|
|
|
}
|
2017-09-01 03:40:32 +08:00
|
|
|
|
2018-12-07 03:18:16 +08:00
|
|
|
for (node = rb_first_cached(&groups.entries); node; node = next) {
|
2017-09-01 03:40:32 +08:00
|
|
|
struct mep *me = container_of(node, struct mep, nd);
|
|
|
|
|
|
|
|
if (metricgroups)
|
2019-06-29 06:07:36 +08:00
|
|
|
printf("%s%s%s", me->name, metrics && !raw ? ":" : "", raw ? " " : "\n");
|
2017-09-01 03:40:32 +08:00
|
|
|
if (metrics)
|
|
|
|
metricgroup__print_strlist(me->metrics, raw);
|
|
|
|
next = rb_next(node);
|
|
|
|
rblist__remove_node(&groups, node);
|
|
|
|
}
|
|
|
|
if (!metricgroups)
|
|
|
|
metricgroup__print_strlist(metriclist, raw);
|
|
|
|
strlist__delete(metriclist);
|
|
|
|
}
|
|
|
|
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
static const char *code_characters = ",-=@";
|
|
|
|
|
|
|
|
static int encode_metric_id(struct strbuf *sb, const char *x)
|
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
for (; *x; x++) {
|
|
|
|
c = strchr(code_characters, *x);
|
|
|
|
if (c) {
|
|
|
|
ret = strbuf_addch(sb, '!');
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ret = strbuf_addch(sb, '0' + (c - code_characters));
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
ret = strbuf_addch(sb, *x);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int decode_metric_id(struct strbuf *sb, const char *x)
|
|
|
|
{
|
|
|
|
const char *orig = x;
|
|
|
|
size_t i;
|
|
|
|
char c;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
for (; *x; x++) {
|
|
|
|
c = *x;
|
|
|
|
if (*x == '!') {
|
|
|
|
x++;
|
|
|
|
i = *x - '0';
|
|
|
|
if (i > strlen(code_characters)) {
|
|
|
|
pr_err("Bad metric-id encoding in: '%s'", orig);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
c = code_characters[i];
|
|
|
|
}
|
|
|
|
ret = strbuf_addch(sb, c);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
static int decode_all_metric_ids(struct evlist *perf_evlist, const char *modifier)
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
{
|
|
|
|
struct evsel *ev;
|
|
|
|
struct strbuf sb = STRBUF_INIT;
|
|
|
|
char *cur;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
evlist__for_each_entry(perf_evlist, ev) {
|
|
|
|
if (!ev->metric_id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = strbuf_setlen(&sb, 0);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ret = decode_metric_id(&sb, ev->metric_id);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
free((char *)ev->metric_id);
|
|
|
|
ev->metric_id = strdup(sb.buf);
|
|
|
|
if (!ev->metric_id) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the name is just the parsed event, use the metric-id to
|
|
|
|
* give a more friendly display version.
|
|
|
|
*/
|
|
|
|
if (strstr(ev->name, "metric-id=")) {
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
bool has_slash = false;
|
|
|
|
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
free(ev->name);
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
for (cur = strchr(sb.buf, '@') ; cur; cur = strchr(++cur, '@')) {
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
*cur = '/';
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
has_slash = true;
|
|
|
|
}
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
if (modifier) {
|
|
|
|
if (!has_slash && !strchr(sb.buf, ':')) {
|
|
|
|
ret = strbuf_addch(&sb, ':');
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = strbuf_addstr(&sb, modifier);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
ev->name = strdup(sb.buf);
|
|
|
|
if (!ev->name) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strbuf_release(&sb);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int metricgroup__build_event_string(struct strbuf *events,
|
|
|
|
const struct expr_parse_ctx *ctx,
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
const char *modifier,
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
bool has_constraint)
|
2020-02-25 05:59:21 +08:00
|
|
|
{
|
2020-05-16 06:17:32 +08:00
|
|
|
struct hashmap_entry *cur;
|
2020-05-21 02:20:05 +08:00
|
|
|
size_t bkt;
|
|
|
|
bool no_group = true, has_duration = false;
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
#define RETURN_IF_NON_ZERO(x) do { if (x) return x; } while (0)
|
2020-02-25 05:59:21 +08:00
|
|
|
|
2021-09-23 15:46:04 +08:00
|
|
|
hashmap__for_each_entry(ctx->ids, cur, bkt) {
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
const char *sep, *rsep, *id = cur->key;
|
|
|
|
|
|
|
|
pr_debug("found event %s\n", id);
|
2020-02-25 05:59:21 +08:00
|
|
|
/*
|
|
|
|
* Duration time maps to a software event and can make
|
|
|
|
* groups not count. Always use it outside a
|
|
|
|
* group.
|
|
|
|
*/
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
if (!strcmp(id, "duration_time")) {
|
2020-05-21 02:20:05 +08:00
|
|
|
has_duration = true;
|
2020-02-25 05:59:21 +08:00
|
|
|
continue;
|
|
|
|
}
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
/* Separate events with commas and open the group if necessary. */
|
|
|
|
if (no_group) {
|
|
|
|
if (!has_constraint) {
|
|
|
|
ret = strbuf_addch(events, '{');
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
}
|
perf metricgroup: Support metric constraint
Some metric groups have metric constraints. A metric group can be
scheduled as a group only when some constraints are applied. For
example, Page_Walks_Utilization has a metric constraint,
"NO_NMI_WATCHDOG".
When NMI watchdog is disabled, the metric group can be scheduled as a
group. Otherwise, splitting the metric group into standalone metrics.
Add a new function, metricgroup__has_constraint(), to check whether all
constraints are applied. If not, splitting the metric group into
standalone metrics.
Currently, only one constraint, "NO_NMI_WATCHDOG", is checked. Print a
warning for the metric group with the constraint, when NMI WATCHDOG is
enabled.
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Link: http://lore.kernel.org/lkml/1582581564-184429-5-git-send-email-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-02-25 05:59:23 +08:00
|
|
|
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
no_group = false;
|
|
|
|
} else {
|
|
|
|
ret = strbuf_addch(events, ',');
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Encode the ID as an event string. Add a qualifier for
|
|
|
|
* metric_id that is the original name except with characters
|
|
|
|
* that parse-events can't parse replaced. For example,
|
|
|
|
* 'msr@tsc@' gets added as msr/tsc,metric-id=msr!3tsc!3/
|
|
|
|
*/
|
|
|
|
sep = strchr(id, '@');
|
|
|
|
if (sep != NULL) {
|
|
|
|
ret = strbuf_add(events, id, sep - id);
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
ret = strbuf_addch(events, '/');
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
rsep = strrchr(sep, '@');
|
|
|
|
ret = strbuf_add(events, sep + 1, rsep - sep - 1);
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
ret = strbuf_addstr(events, ",metric-id=");
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
sep = rsep;
|
|
|
|
} else {
|
|
|
|
sep = strchr(id, ':');
|
|
|
|
if (sep != NULL) {
|
|
|
|
ret = strbuf_add(events, id, sep - id);
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
} else {
|
|
|
|
ret = strbuf_addstr(events, id);
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
}
|
|
|
|
ret = strbuf_addstr(events, "/metric-id=");
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
}
|
|
|
|
ret = encode_metric_id(events, id);
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
ret = strbuf_addstr(events, "/");
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
|
|
|
|
if (sep != NULL) {
|
|
|
|
ret = strbuf_addstr(events, sep + 1);
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
}
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
if (modifier) {
|
|
|
|
ret = strbuf_addstr(events, modifier);
|
|
|
|
RETURN_IF_NON_ZERO(ret);
|
|
|
|
}
|
2020-05-21 02:20:11 +08:00
|
|
|
}
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
if (has_duration) {
|
|
|
|
if (no_group) {
|
|
|
|
/* Strange case of a metric of just duration_time. */
|
|
|
|
ret = strbuf_addf(events, "duration_time");
|
|
|
|
} else if (!has_constraint)
|
|
|
|
ret = strbuf_addf(events, "}:W,duration_time");
|
|
|
|
else
|
|
|
|
ret = strbuf_addf(events, ",duration_time");
|
|
|
|
} else if (!no_group && !has_constraint)
|
|
|
|
ret = strbuf_addf(events, "}:W");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
#undef RETURN_IF_NON_ZERO
|
perf metricgroup: Support metric constraint
Some metric groups have metric constraints. A metric group can be
scheduled as a group only when some constraints are applied. For
example, Page_Walks_Utilization has a metric constraint,
"NO_NMI_WATCHDOG".
When NMI watchdog is disabled, the metric group can be scheduled as a
group. Otherwise, splitting the metric group into standalone metrics.
Add a new function, metricgroup__has_constraint(), to check whether all
constraints are applied. If not, splitting the metric group into
standalone metrics.
Currently, only one constraint, "NO_NMI_WATCHDOG", is checked. Print a
warning for the metric group with the constraint, when NMI WATCHDOG is
enabled.
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Link: http://lore.kernel.org/lkml/1582581564-184429-5-git-send-email-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-02-25 05:59:23 +08:00
|
|
|
}
|
|
|
|
|
2021-10-16 01:21:15 +08:00
|
|
|
int __weak arch_get_runtimeparam(const struct pmu_event *pe __maybe_unused)
|
perf metricgroups: Enhance JSON/metric infrastructure to handle "?"
Patch enhances current metric infrastructure to handle "?" in the metric
expression. The "?" can be use for parameters whose value not known
while creating metric events and which can be replace later at runtime
to the proper value. It also add flexibility to create multiple events
out of single metric event added in JSON file.
Patch adds function 'arch_get_runtimeparam' which is a arch specific
function, returns the count of metric events need to be created. By
default it return 1.
This infrastructure needed for hv_24x7 socket/chip level events.
"hv_24x7" chip level events needs specific chip-id to which the data is
requested. Function 'arch_get_runtimeparam' implemented in header.c
which extract number of sockets from sysfs file "sockets" under
"/sys/devices/hv_24x7/interface/".
With this patch basically we are trying to create as many metric events
as define by runtime_param.
For that one loop is added in function 'metricgroup__add_metric', which
create multiple events at run time depend on return value of
'arch_get_runtimeparam' and merge that event in 'group_list'.
To achieve that we are actually passing this parameter value as part of
`expr__find_other` function and changing "?" present in metric
expression with this value.
As in our JSON file, there gonna be single metric event, and out of
which we are creating multiple events.
To understand which data count belongs to which parameter value,
we also printing param value in generic_metric function.
For example,
command:# ./perf stat -M PowerBUS_Frequency -C 0 -I 1000
1.000101867 9,356,933 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0
1.000101867 9,366,134 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1
2.000314878 9,365,868 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0
2.000314878 9,366,092 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1
So, here _0 and _1 after PowerBUS_Frequency specify parameter value.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Anju T Sudhakar <anju@linux.vnet.ibm.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Mamatha Inamdar <mamatha4@linux.vnet.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@ozlabs.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lore.kernel.org/lkml/20200401203340.31402-5-kjain@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-04-02 04:33:37 +08:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-10-16 01:21:20 +08:00
|
|
|
/*
|
|
|
|
* A singly linked list on the stack of the names of metrics being
|
|
|
|
* processed. Used to identify recursion.
|
|
|
|
*/
|
|
|
|
struct visited_metric {
|
|
|
|
const char *name;
|
|
|
|
const struct visited_metric *parent;
|
|
|
|
};
|
|
|
|
|
2020-12-04 19:10:15 +08:00
|
|
|
struct metricgroup_add_iter_data {
|
|
|
|
struct list_head *metric_list;
|
2021-10-16 01:21:17 +08:00
|
|
|
const char *metric_name;
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
const char *modifier;
|
2020-12-04 19:10:15 +08:00
|
|
|
int *ret;
|
|
|
|
bool *has_match;
|
|
|
|
bool metric_no_group;
|
2021-10-16 01:21:20 +08:00
|
|
|
struct metric *root_metric;
|
|
|
|
const struct visited_metric *visited;
|
|
|
|
const struct pmu_events_map *map;
|
2020-12-04 19:10:15 +08:00
|
|
|
};
|
|
|
|
|
2021-10-16 01:21:20 +08:00
|
|
|
static int add_metric(struct list_head *metric_list,
|
|
|
|
const struct pmu_event *pe,
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
const char *modifier,
|
2021-10-16 01:21:20 +08:00
|
|
|
bool metric_no_group,
|
|
|
|
struct metric *root_metric,
|
|
|
|
const struct visited_metric *visited,
|
|
|
|
const struct pmu_events_map *map);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* resolve_metric - Locate metrics within the root metric and recursively add
|
|
|
|
* references to them.
|
|
|
|
* @metric_list: The list the metric is added to.
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
* @modifier: if non-null event modifiers like "u".
|
2021-10-16 01:21:20 +08:00
|
|
|
* @metric_no_group: Should events written to events be grouped "{}" or
|
|
|
|
* global. Grouping is the default but due to multiplexing the
|
|
|
|
* user may override.
|
|
|
|
* @root_metric: Metrics may reference other metrics to form a tree. In this
|
|
|
|
* case the root_metric holds all the IDs and a list of referenced
|
|
|
|
* metrics. When adding a root this argument is NULL.
|
|
|
|
* @visited: A singly linked list of metric names being added that is used to
|
|
|
|
* detect recursion.
|
|
|
|
* @map: The map that is searched for metrics, most commonly the table for the
|
|
|
|
* architecture perf is running upon.
|
|
|
|
*/
|
|
|
|
static int resolve_metric(struct list_head *metric_list,
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
const char *modifier,
|
2021-10-16 01:21:20 +08:00
|
|
|
bool metric_no_group,
|
|
|
|
struct metric *root_metric,
|
|
|
|
const struct visited_metric *visited,
|
|
|
|
const struct pmu_events_map *map)
|
|
|
|
{
|
|
|
|
struct hashmap_entry *cur;
|
|
|
|
size_t bkt;
|
|
|
|
struct to_resolve {
|
|
|
|
/* The metric to resolve. */
|
|
|
|
const struct pmu_event *pe;
|
|
|
|
/*
|
|
|
|
* The key in the IDs map, this may differ from in case,
|
|
|
|
* etc. from pe->metric_name.
|
|
|
|
*/
|
|
|
|
const char *key;
|
|
|
|
} *pending = NULL;
|
|
|
|
int i, ret = 0, pending_cnt = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate all the parsed IDs and if there's a matching metric and it to
|
|
|
|
* the pending array.
|
|
|
|
*/
|
|
|
|
hashmap__for_each_entry(root_metric->pctx->ids, cur, bkt) {
|
|
|
|
const struct pmu_event *pe;
|
|
|
|
|
|
|
|
pe = metricgroup__find_metric(cur->key, map);
|
|
|
|
if (pe) {
|
|
|
|
pending = realloc(pending,
|
|
|
|
(pending_cnt + 1) * sizeof(struct to_resolve));
|
|
|
|
if (!pending)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pending[pending_cnt].pe = pe;
|
|
|
|
pending[pending_cnt].key = cur->key;
|
|
|
|
pending_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the metric IDs from the context. */
|
|
|
|
for (i = 0; i < pending_cnt; i++)
|
|
|
|
expr__del_id(root_metric->pctx, pending[i].key);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Recursively add all the metrics, IDs are added to the root metric's
|
|
|
|
* context.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < pending_cnt; i++) {
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
ret = add_metric(metric_list, pending[i].pe, modifier, metric_no_group,
|
2021-10-16 01:21:20 +08:00
|
|
|
root_metric, visited, map);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pending);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-16 01:21:17 +08:00
|
|
|
/**
|
|
|
|
* __add_metric - Add a metric to metric_list.
|
|
|
|
* @metric_list: The list the metric is added to.
|
|
|
|
* @pe: The pmu_event containing the metric to be added.
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
* @modifier: if non-null event modifiers like "u".
|
2021-10-16 01:21:17 +08:00
|
|
|
* @metric_no_group: Should events written to events be grouped "{}" or
|
|
|
|
* global. Grouping is the default but due to multiplexing the
|
|
|
|
* user may override.
|
|
|
|
* @runtime: A special argument for the parser only known at runtime.
|
2021-10-16 01:21:20 +08:00
|
|
|
* @root_metric: Metrics may reference other metrics to form a tree. In this
|
|
|
|
* case the root_metric holds all the IDs and a list of referenced
|
|
|
|
* metrics. When adding a root this argument is NULL.
|
|
|
|
* @visited: A singly linked list of metric names being added that is used to
|
|
|
|
* detect recursion.
|
|
|
|
* @map: The map that is searched for metrics, most commonly the table for the
|
|
|
|
* architecture perf is running upon.
|
2021-10-16 01:21:17 +08:00
|
|
|
*/
|
2020-07-20 02:13:20 +08:00
|
|
|
static int __add_metric(struct list_head *metric_list,
|
2021-10-16 01:21:15 +08:00
|
|
|
const struct pmu_event *pe,
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
const char *modifier,
|
2020-07-20 02:13:08 +08:00
|
|
|
bool metric_no_group,
|
2020-07-20 02:13:09 +08:00
|
|
|
int runtime,
|
2021-10-16 01:21:20 +08:00
|
|
|
struct metric *root_metric,
|
|
|
|
const struct visited_metric *visited,
|
|
|
|
const struct pmu_events_map *map)
|
2020-04-02 04:33:36 +08:00
|
|
|
{
|
2021-10-16 01:21:20 +08:00
|
|
|
const struct visited_metric *vm;
|
|
|
|
int ret;
|
|
|
|
bool is_root = !root_metric;
|
|
|
|
struct visited_metric visited_node = {
|
|
|
|
.name = pe->metric_name,
|
|
|
|
.parent = visited,
|
|
|
|
};
|
|
|
|
|
|
|
|
for (vm = visited; vm; vm = vm->parent) {
|
|
|
|
if (!strcmp(pe->metric_name, vm->name)) {
|
|
|
|
pr_err("failed: recursion detected for %s\n", pe->metric_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2020-04-02 04:33:36 +08:00
|
|
|
|
2021-10-16 01:21:20 +08:00
|
|
|
if (is_root) {
|
2020-07-20 02:13:09 +08:00
|
|
|
/*
|
2021-10-16 01:21:20 +08:00
|
|
|
* This metric is the root of a tree and may reference other
|
|
|
|
* metrics that are added recursively.
|
2020-07-20 02:13:09 +08:00
|
|
|
*/
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
root_metric = metric__new(pe, modifier, metric_no_group, runtime);
|
2021-10-16 01:21:20 +08:00
|
|
|
if (!root_metric)
|
2020-07-20 02:13:09 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
} else {
|
2021-10-16 01:21:23 +08:00
|
|
|
int cnt = 0;
|
|
|
|
|
2020-07-20 02:13:09 +08:00
|
|
|
/*
|
2021-10-16 01:21:19 +08:00
|
|
|
* This metric was referenced in a metric higher in the
|
|
|
|
* tree. Check if the same metric is already resolved in the
|
|
|
|
* metric_refs list.
|
2020-07-20 02:13:09 +08:00
|
|
|
*/
|
2021-10-16 01:21:23 +08:00
|
|
|
if (root_metric->metric_refs) {
|
|
|
|
for (; root_metric->metric_refs[cnt].metric_name; cnt++) {
|
|
|
|
if (!strcmp(pe->metric_name,
|
|
|
|
root_metric->metric_refs[cnt].metric_name))
|
|
|
|
return 0;
|
|
|
|
}
|
2021-10-16 01:21:19 +08:00
|
|
|
}
|
|
|
|
|
2021-10-16 01:21:23 +08:00
|
|
|
/* Create reference. Need space for the entry and the terminator. */
|
|
|
|
root_metric->metric_refs = realloc(root_metric->metric_refs,
|
|
|
|
(cnt + 2) * sizeof(struct metric_ref));
|
|
|
|
if (!root_metric->metric_refs)
|
2020-07-20 02:13:09 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Intentionally passing just const char pointers,
|
|
|
|
* from 'pe' object, so they never go away. We don't
|
|
|
|
* need to change them, so there's no need to create
|
|
|
|
* our own copy.
|
|
|
|
*/
|
2021-10-16 01:21:23 +08:00
|
|
|
root_metric->metric_refs[cnt].metric_name = pe->metric_name;
|
|
|
|
root_metric->metric_refs[cnt].metric_expr = pe->metric_expr;
|
2020-04-02 04:33:36 +08:00
|
|
|
|
2021-10-16 01:21:23 +08:00
|
|
|
/* Null terminate array. */
|
|
|
|
root_metric->metric_refs[cnt+1].metric_name = NULL;
|
|
|
|
root_metric->metric_refs[cnt+1].metric_expr = NULL;
|
2020-07-20 02:13:09 +08:00
|
|
|
}
|
2020-05-16 06:17:32 +08:00
|
|
|
|
2020-07-20 02:13:09 +08:00
|
|
|
/*
|
|
|
|
* For both the parent and referenced metrics, we parse
|
2021-10-16 01:21:20 +08:00
|
|
|
* all the metric's IDs and add it to the root context.
|
2020-07-20 02:13:09 +08:00
|
|
|
*/
|
2021-10-16 01:21:20 +08:00
|
|
|
if (expr__find_ids(pe->metric_expr, NULL, root_metric->pctx) < 0) {
|
|
|
|
/* Broken metric. */
|
|
|
|
ret = -EINVAL;
|
|
|
|
} else {
|
|
|
|
/* Resolve referenced metrics. */
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
ret = resolve_metric(metric_list, modifier, metric_no_group, root_metric,
|
2021-10-16 01:21:20 +08:00
|
|
|
&visited_node, map);
|
2020-05-16 06:17:32 +08:00
|
|
|
}
|
|
|
|
|
2021-10-16 01:21:20 +08:00
|
|
|
if (ret) {
|
|
|
|
if (is_root)
|
|
|
|
metric__free(root_metric);
|
2020-05-21 02:20:08 +08:00
|
|
|
|
2021-10-16 01:21:20 +08:00
|
|
|
} else if (is_root)
|
|
|
|
list_add(&root_metric->nd, metric_list);
|
2020-04-02 04:33:36 +08:00
|
|
|
|
2021-10-16 01:21:20 +08:00
|
|
|
return ret;
|
2020-04-02 04:33:36 +08:00
|
|
|
}
|
|
|
|
|
2020-12-04 19:10:15 +08:00
|
|
|
#define map_for_each_event(__pe, __idx, __map) \
|
|
|
|
if (__map) \
|
|
|
|
for (__idx = 0, __pe = &__map->table[__idx]; \
|
|
|
|
__pe->name || __pe->metric_group || __pe->metric_name; \
|
|
|
|
__pe = &__map->table[++__idx])
|
2020-07-20 02:13:06 +08:00
|
|
|
|
|
|
|
#define map_for_each_metric(__pe, __idx, __map, __metric) \
|
|
|
|
map_for_each_event(__pe, __idx, __map) \
|
|
|
|
if (__pe->metric_expr && \
|
|
|
|
(match_metric(__pe->metric_group, __metric) || \
|
|
|
|
match_metric(__pe->metric_name, __metric)))
|
|
|
|
|
2021-10-16 01:21:15 +08:00
|
|
|
const struct pmu_event *metricgroup__find_metric(const char *metric,
|
|
|
|
const struct pmu_events_map *map)
|
2020-07-20 02:13:09 +08:00
|
|
|
{
|
2021-10-16 01:21:15 +08:00
|
|
|
const struct pmu_event *pe;
|
2020-07-20 02:13:09 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
map_for_each_event(pe, i, map) {
|
|
|
|
if (match_metric(pe->metric_name, metric))
|
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-20 02:13:20 +08:00
|
|
|
static int add_metric(struct list_head *metric_list,
|
2021-10-16 01:21:15 +08:00
|
|
|
const struct pmu_event *pe,
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
const char *modifier,
|
2020-07-20 02:13:09 +08:00
|
|
|
bool metric_no_group,
|
2021-10-16 01:21:20 +08:00
|
|
|
struct metric *root_metric,
|
|
|
|
const struct visited_metric *visited,
|
|
|
|
const struct pmu_events_map *map)
|
2020-07-20 02:13:09 +08:00
|
|
|
{
|
2020-07-20 02:13:07 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name);
|
|
|
|
|
|
|
|
if (!strstr(pe->metric_expr, "?")) {
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
ret = __add_metric(metric_list, pe, modifier, metric_no_group, 0,
|
2021-10-16 01:21:20 +08:00
|
|
|
root_metric, visited, map);
|
2020-07-20 02:13:07 +08:00
|
|
|
} else {
|
|
|
|
int j, count;
|
|
|
|
|
2020-09-07 14:41:32 +08:00
|
|
|
count = arch_get_runtimeparam(pe);
|
2020-07-20 02:13:07 +08:00
|
|
|
|
|
|
|
/* This loop is added to create multiple
|
|
|
|
* events depend on count value and add
|
2020-07-20 02:13:20 +08:00
|
|
|
* those events to metric_list.
|
2020-07-20 02:13:07 +08:00
|
|
|
*/
|
|
|
|
|
2021-10-16 01:21:20 +08:00
|
|
|
for (j = 0; j < count && !ret; j++)
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
ret = __add_metric(metric_list, pe, modifier, metric_no_group, j,
|
2021-10-16 01:21:20 +08:00
|
|
|
root_metric, visited, map);
|
2020-07-20 02:13:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-16 01:21:15 +08:00
|
|
|
static int metricgroup__add_metric_sys_event_iter(const struct pmu_event *pe,
|
2020-12-04 19:10:15 +08:00
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct metricgroup_add_iter_data *d = data;
|
|
|
|
int ret;
|
|
|
|
|
2021-10-16 01:21:17 +08:00
|
|
|
if (!match_pe_metric(pe, d->metric_name))
|
2020-12-04 19:10:15 +08:00
|
|
|
return 0;
|
|
|
|
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
ret = add_metric(d->metric_list, pe, d->modifier, d->metric_no_group,
|
2021-10-16 01:21:20 +08:00
|
|
|
d->root_metric, d->visited, d->map);
|
2020-12-04 19:10:15 +08:00
|
|
|
if (ret)
|
2021-06-10 22:33:00 +08:00
|
|
|
goto out;
|
2020-12-04 19:10:15 +08:00
|
|
|
|
|
|
|
*(d->has_match) = true;
|
|
|
|
|
2021-06-10 22:33:00 +08:00
|
|
|
out:
|
|
|
|
*(d->ret) = ret;
|
|
|
|
return ret;
|
2020-12-04 19:10:15 +08:00
|
|
|
}
|
|
|
|
|
perf metric: Reduce multiplexing with duration_time
It is common to use the same counters with and without duration_time.
The ID sharing code treats duration_time as if it were a hardware event
placed in the same group. This causes unnecessary multiplexing such as
in the following example where l3_cache_access isn't shared:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,117,007 l3_cache_miss # 199.5 MB/s l3_rd_bw
# 43.6 % l3_hits
# 56.4 % l3_miss (50.00%)
5,526,447 l3_cache_access (50.00%)
5,392,435 l3_cache_access # 5389191.2 access/s l3_access_rate (50.00%)
1,000,601,901 ns duration_time
1.000601901 seconds time elapsed
Fix this by placing duration_time in all groups unless metric
sharing has been disabled on the command line:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,597,972 l3_cache_miss # 230.3 MB/s l3_rd_bw
# 48.0 % l3_hits
# 52.0 % l3_miss
6,914,459 l3_cache_access # 6909935.9 access/s l3_access_rate
1,000,654,579 ns duration_time
1.000654579 seconds time elapsed
$ perf stat --metric-no-merge -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,501,834 l3_cache_miss # 53.5 % l3_miss (24.99%)
6,548,173 l3_cache_access (24.99%)
3,417,622 l3_cache_miss # 45.7 % l3_hits (25.04%)
6,294,062 l3_cache_access (25.04%)
5,923,238 l3_cache_access # 5919688.1 access/s l3_access_rate (24.99%)
1,000,599,683 ns duration_time
3,607,486 l3_cache_miss # 230.9 MB/s l3_rd_bw (49.97%)
1.000599683 seconds time elapsed
v2. Doesn't count duration_time in the metric_list_cmp function that
sorts larger metrics first. Without this a metric with duration_time
and an event is sorted the same as a metric with two events,
possibly not allowing the first metric to share with the second.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20211124015226.3317994-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-11-24 09:52:26 +08:00
|
|
|
/**
|
|
|
|
* metric_list_cmp - list_sort comparator that sorts metrics with more events to
|
|
|
|
* the front. duration_time is excluded from the count.
|
|
|
|
*/
|
2021-10-16 01:21:20 +08:00
|
|
|
static int metric_list_cmp(void *priv __maybe_unused, const struct list_head *l,
|
|
|
|
const struct list_head *r)
|
|
|
|
{
|
|
|
|
const struct metric *left = container_of(l, struct metric, nd);
|
|
|
|
const struct metric *right = container_of(r, struct metric, nd);
|
perf metric: Reduce multiplexing with duration_time
It is common to use the same counters with and without duration_time.
The ID sharing code treats duration_time as if it were a hardware event
placed in the same group. This causes unnecessary multiplexing such as
in the following example where l3_cache_access isn't shared:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,117,007 l3_cache_miss # 199.5 MB/s l3_rd_bw
# 43.6 % l3_hits
# 56.4 % l3_miss (50.00%)
5,526,447 l3_cache_access (50.00%)
5,392,435 l3_cache_access # 5389191.2 access/s l3_access_rate (50.00%)
1,000,601,901 ns duration_time
1.000601901 seconds time elapsed
Fix this by placing duration_time in all groups unless metric
sharing has been disabled on the command line:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,597,972 l3_cache_miss # 230.3 MB/s l3_rd_bw
# 48.0 % l3_hits
# 52.0 % l3_miss
6,914,459 l3_cache_access # 6909935.9 access/s l3_access_rate
1,000,654,579 ns duration_time
1.000654579 seconds time elapsed
$ perf stat --metric-no-merge -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,501,834 l3_cache_miss # 53.5 % l3_miss (24.99%)
6,548,173 l3_cache_access (24.99%)
3,417,622 l3_cache_miss # 45.7 % l3_hits (25.04%)
6,294,062 l3_cache_access (25.04%)
5,923,238 l3_cache_access # 5919688.1 access/s l3_access_rate (24.99%)
1,000,599,683 ns duration_time
3,607,486 l3_cache_miss # 230.9 MB/s l3_rd_bw (49.97%)
1.000599683 seconds time elapsed
v2. Doesn't count duration_time in the metric_list_cmp function that
sorts larger metrics first. Without this a metric with duration_time
and an event is sorted the same as a metric with two events,
possibly not allowing the first metric to share with the second.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20211124015226.3317994-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-11-24 09:52:26 +08:00
|
|
|
struct expr_id_data *data;
|
|
|
|
int left_count, right_count;
|
|
|
|
|
|
|
|
left_count = hashmap__size(left->pctx->ids);
|
|
|
|
if (!expr__get_id(left->pctx, "duration_time", &data))
|
|
|
|
left_count--;
|
|
|
|
|
|
|
|
right_count = hashmap__size(right->pctx->ids);
|
|
|
|
if (!expr__get_id(right->pctx, "duration_time", &data))
|
|
|
|
right_count--;
|
2021-10-16 01:21:20 +08:00
|
|
|
|
perf metric: Reduce multiplexing with duration_time
It is common to use the same counters with and without duration_time.
The ID sharing code treats duration_time as if it were a hardware event
placed in the same group. This causes unnecessary multiplexing such as
in the following example where l3_cache_access isn't shared:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,117,007 l3_cache_miss # 199.5 MB/s l3_rd_bw
# 43.6 % l3_hits
# 56.4 % l3_miss (50.00%)
5,526,447 l3_cache_access (50.00%)
5,392,435 l3_cache_access # 5389191.2 access/s l3_access_rate (50.00%)
1,000,601,901 ns duration_time
1.000601901 seconds time elapsed
Fix this by placing duration_time in all groups unless metric
sharing has been disabled on the command line:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,597,972 l3_cache_miss # 230.3 MB/s l3_rd_bw
# 48.0 % l3_hits
# 52.0 % l3_miss
6,914,459 l3_cache_access # 6909935.9 access/s l3_access_rate
1,000,654,579 ns duration_time
1.000654579 seconds time elapsed
$ perf stat --metric-no-merge -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,501,834 l3_cache_miss # 53.5 % l3_miss (24.99%)
6,548,173 l3_cache_access (24.99%)
3,417,622 l3_cache_miss # 45.7 % l3_hits (25.04%)
6,294,062 l3_cache_access (25.04%)
5,923,238 l3_cache_access # 5919688.1 access/s l3_access_rate (24.99%)
1,000,599,683 ns duration_time
3,607,486 l3_cache_miss # 230.9 MB/s l3_rd_bw (49.97%)
1.000599683 seconds time elapsed
v2. Doesn't count duration_time in the metric_list_cmp function that
sorts larger metrics first. Without this a metric with duration_time
and an event is sorted the same as a metric with two events,
possibly not allowing the first metric to share with the second.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20211124015226.3317994-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-11-24 09:52:26 +08:00
|
|
|
return right_count - left_count;
|
2021-10-16 01:21:20 +08:00
|
|
|
}
|
|
|
|
|
2021-10-16 01:21:17 +08:00
|
|
|
/**
|
|
|
|
* metricgroup__add_metric - Find and add a metric, or a metric group.
|
|
|
|
* @metric_name: The name of the metric or metric group. For example, "IPC"
|
|
|
|
* could be the name of a metric and "TopDownL1" the name of a
|
|
|
|
* metric group.
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
* @modifier: if non-null event modifiers like "u".
|
2021-10-16 01:21:17 +08:00
|
|
|
* @metric_no_group: Should events written to events be grouped "{}" or
|
|
|
|
* global. Grouping is the default but due to multiplexing the
|
|
|
|
* user may override.
|
|
|
|
* @metric_list: The list that the metric or metric group are added to.
|
|
|
|
* @map: The map that is searched for metrics, most commonly the table for the
|
|
|
|
* architecture perf is running upon.
|
|
|
|
*/
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
static int metricgroup__add_metric(const char *metric_name, const char *modifier,
|
|
|
|
bool metric_no_group,
|
2020-07-20 02:13:20 +08:00
|
|
|
struct list_head *metric_list,
|
2021-10-16 01:21:13 +08:00
|
|
|
const struct pmu_events_map *map)
|
2017-09-01 03:40:31 +08:00
|
|
|
{
|
2021-10-16 01:21:15 +08:00
|
|
|
const struct pmu_event *pe;
|
2020-07-20 02:13:13 +08:00
|
|
|
LIST_HEAD(list);
|
2020-05-21 02:20:06 +08:00
|
|
|
int i, ret;
|
|
|
|
bool has_match = false;
|
2017-09-01 03:40:31 +08:00
|
|
|
|
2021-10-16 01:21:17 +08:00
|
|
|
/*
|
|
|
|
* Iterate over all metrics seeing if metric matches either the name or
|
|
|
|
* group. When it does add the metric to the list.
|
|
|
|
*/
|
|
|
|
map_for_each_metric(pe, i, map, metric_name) {
|
2020-07-20 02:13:06 +08:00
|
|
|
has_match = true;
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
ret = add_metric(&list, pe, modifier, metric_no_group,
|
2021-10-16 01:21:20 +08:00
|
|
|
/*root_metric=*/NULL,
|
|
|
|
/*visited_metrics=*/NULL, map);
|
2020-07-20 02:13:07 +08:00
|
|
|
if (ret)
|
2020-09-15 11:18:16 +08:00
|
|
|
goto out;
|
2017-09-01 03:40:31 +08:00
|
|
|
}
|
2020-07-20 02:13:06 +08:00
|
|
|
|
2020-12-04 19:10:15 +08:00
|
|
|
{
|
|
|
|
struct metricgroup_iter_data data = {
|
|
|
|
.fn = metricgroup__add_metric_sys_event_iter,
|
|
|
|
.data = (void *) &(struct metricgroup_add_iter_data) {
|
|
|
|
.metric_list = &list,
|
2021-10-16 01:21:17 +08:00
|
|
|
.metric_name = metric_name,
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
.modifier = modifier,
|
2020-12-04 19:10:15 +08:00
|
|
|
.metric_no_group = metric_no_group,
|
|
|
|
.has_match = &has_match,
|
|
|
|
.ret = &ret,
|
2021-10-16 01:21:20 +08:00
|
|
|
.map = map,
|
2020-12-04 19:10:15 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
pmu_for_each_sys_event(metricgroup__sys_event_iter, &data);
|
|
|
|
}
|
2020-07-20 02:13:06 +08:00
|
|
|
/* End of pmu events. */
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
if (!has_match)
|
2020-09-15 11:18:16 +08:00
|
|
|
ret = -EINVAL;
|
2020-07-20 02:13:13 +08:00
|
|
|
|
2020-09-15 11:18:16 +08:00
|
|
|
out:
|
|
|
|
/*
|
|
|
|
* add to metric_list so that they can be released
|
|
|
|
* even if it's failed
|
|
|
|
*/
|
2020-07-20 02:13:20 +08:00
|
|
|
list_splice(&list, metric_list);
|
2020-09-15 11:18:16 +08:00
|
|
|
return ret;
|
2017-09-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
|
2021-10-16 01:21:17 +08:00
|
|
|
/**
|
|
|
|
* metricgroup__add_metric_list - Find and add metrics, or metric groups,
|
|
|
|
* specified in a list.
|
|
|
|
* @list: the list of metrics or metric groups. For example, "IPC,CPI,TopDownL1"
|
|
|
|
* would match the IPC and CPI metrics, and TopDownL1 would match all
|
|
|
|
* the metrics in the TopDownL1 group.
|
|
|
|
* @metric_no_group: Should events written to events be grouped "{}" or
|
|
|
|
* global. Grouping is the default but due to multiplexing the
|
|
|
|
* user may override.
|
|
|
|
* @metric_list: The list that metrics are added to.
|
|
|
|
* @map: The map that is searched for metrics, most commonly the table for the
|
|
|
|
* architecture perf is running upon.
|
|
|
|
*/
|
2020-05-21 02:20:10 +08:00
|
|
|
static int metricgroup__add_metric_list(const char *list, bool metric_no_group,
|
2020-07-20 02:13:20 +08:00
|
|
|
struct list_head *metric_list,
|
2021-10-16 01:21:13 +08:00
|
|
|
const struct pmu_events_map *map)
|
2017-09-01 03:40:31 +08:00
|
|
|
{
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
char *list_itr, *list_copy, *metric_name, *modifier;
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
int ret, count = 0;
|
2017-09-01 03:40:31 +08:00
|
|
|
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
list_copy = strdup(list);
|
|
|
|
if (!list_copy)
|
2017-09-01 03:40:31 +08:00
|
|
|
return -ENOMEM;
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
list_itr = list_copy;
|
2017-09-15 04:57:35 +08:00
|
|
|
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
while ((metric_name = strsep(&list_itr, ",")) != NULL) {
|
|
|
|
modifier = strchr(metric_name, ':');
|
|
|
|
if (modifier)
|
|
|
|
*modifier++ = '\0';
|
|
|
|
|
|
|
|
ret = metricgroup__add_metric(metric_name, modifier,
|
|
|
|
metric_no_group, metric_list,
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
map);
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
if (ret == -EINVAL)
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
pr_err("Cannot find metric or group `%s'\n", metric_name);
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
|
|
|
|
if (ret)
|
2017-09-01 03:40:31 +08:00
|
|
|
break;
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
|
|
|
|
count++;
|
2017-09-01 03:40:31 +08:00
|
|
|
}
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
free(list_copy);
|
perf metricgroup: Support metric constraint
Some metric groups have metric constraints. A metric group can be
scheduled as a group only when some constraints are applied. For
example, Page_Walks_Utilization has a metric constraint,
"NO_NMI_WATCHDOG".
When NMI watchdog is disabled, the metric group can be scheduled as a
group. Otherwise, splitting the metric group into standalone metrics.
Add a new function, metricgroup__has_constraint(), to check whether all
constraints are applied. If not, splitting the metric group into
standalone metrics.
Currently, only one constraint, "NO_NMI_WATCHDOG", is checked. Print a
warning for the metric group with the constraint, when NMI WATCHDOG is
enabled.
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Link: http://lore.kernel.org/lkml/1582581564-184429-5-git-send-email-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-02-25 05:59:23 +08:00
|
|
|
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
if (!ret) {
|
|
|
|
/*
|
|
|
|
* Warn about nmi_watchdog if any parsed metrics had the
|
|
|
|
* NO_NMI_WATCHDOG constraint.
|
|
|
|
*/
|
perf metricgroup: Support metric constraint
Some metric groups have metric constraints. A metric group can be
scheduled as a group only when some constraints are applied. For
example, Page_Walks_Utilization has a metric constraint,
"NO_NMI_WATCHDOG".
When NMI watchdog is disabled, the metric group can be scheduled as a
group. Otherwise, splitting the metric group into standalone metrics.
Add a new function, metricgroup__has_constraint(), to check whether all
constraints are applied. If not, splitting the metric group into
standalone metrics.
Currently, only one constraint, "NO_NMI_WATCHDOG", is checked. Print a
warning for the metric group with the constraint, when NMI WATCHDOG is
enabled.
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Link: http://lore.kernel.org/lkml/1582581564-184429-5-git-send-email-kan.liang@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-02-25 05:59:23 +08:00
|
|
|
metricgroup___watchdog_constraint_hint(NULL, true);
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
/* No metrics. */
|
|
|
|
if (count == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-09-01 03:40:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-07-20 02:13:20 +08:00
|
|
|
static void metricgroup__free_metrics(struct list_head *metric_list)
|
2017-09-01 03:40:31 +08:00
|
|
|
{
|
2020-07-20 02:13:19 +08:00
|
|
|
struct metric *m, *tmp;
|
2017-09-01 03:40:31 +08:00
|
|
|
|
2020-07-20 02:13:20 +08:00
|
|
|
list_for_each_entry_safe (m, tmp, metric_list, nd) {
|
2020-07-20 02:13:19 +08:00
|
|
|
list_del_init(&m->nd);
|
2021-10-16 01:21:18 +08:00
|
|
|
metric__free(m);
|
2017-09-01 03:40:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
/**
|
|
|
|
* build_combined_expr_ctx - Make an expr_parse_ctx with all has_constraint
|
|
|
|
* metric IDs, as the IDs are held in a set,
|
|
|
|
* duplicates will be removed.
|
|
|
|
* @metric_list: List to take metrics from.
|
|
|
|
* @combined: Out argument for result.
|
|
|
|
*/
|
|
|
|
static int build_combined_expr_ctx(const struct list_head *metric_list,
|
|
|
|
struct expr_parse_ctx **combined)
|
|
|
|
{
|
|
|
|
struct hashmap_entry *cur;
|
|
|
|
size_t bkt;
|
|
|
|
struct metric *m;
|
|
|
|
char *dup;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
*combined = expr__ctx_new();
|
|
|
|
if (!*combined)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
list_for_each_entry(m, metric_list, nd) {
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
if (m->has_constraint && !m->modifier) {
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
hashmap__for_each_entry(m->pctx->ids, cur, bkt) {
|
|
|
|
dup = strdup(cur->key);
|
|
|
|
if (!dup) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
ret = expr__add_id(*combined, dup);
|
|
|
|
if (ret)
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
err_out:
|
|
|
|
expr__ctx_free(*combined);
|
|
|
|
*combined = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* parse_ids - Build the event string for the ids and parse them creating an
|
|
|
|
* evlist. The encoded metric_ids are decoded.
|
perf metric: Reduce multiplexing with duration_time
It is common to use the same counters with and without duration_time.
The ID sharing code treats duration_time as if it were a hardware event
placed in the same group. This causes unnecessary multiplexing such as
in the following example where l3_cache_access isn't shared:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,117,007 l3_cache_miss # 199.5 MB/s l3_rd_bw
# 43.6 % l3_hits
# 56.4 % l3_miss (50.00%)
5,526,447 l3_cache_access (50.00%)
5,392,435 l3_cache_access # 5389191.2 access/s l3_access_rate (50.00%)
1,000,601,901 ns duration_time
1.000601901 seconds time elapsed
Fix this by placing duration_time in all groups unless metric
sharing has been disabled on the command line:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,597,972 l3_cache_miss # 230.3 MB/s l3_rd_bw
# 48.0 % l3_hits
# 52.0 % l3_miss
6,914,459 l3_cache_access # 6909935.9 access/s l3_access_rate
1,000,654,579 ns duration_time
1.000654579 seconds time elapsed
$ perf stat --metric-no-merge -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,501,834 l3_cache_miss # 53.5 % l3_miss (24.99%)
6,548,173 l3_cache_access (24.99%)
3,417,622 l3_cache_miss # 45.7 % l3_hits (25.04%)
6,294,062 l3_cache_access (25.04%)
5,923,238 l3_cache_access # 5919688.1 access/s l3_access_rate (24.99%)
1,000,599,683 ns duration_time
3,607,486 l3_cache_miss # 230.9 MB/s l3_rd_bw (49.97%)
1.000599683 seconds time elapsed
v2. Doesn't count duration_time in the metric_list_cmp function that
sorts larger metrics first. Without this a metric with duration_time
and an event is sorted the same as a metric with two events,
possibly not allowing the first metric to share with the second.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20211124015226.3317994-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-11-24 09:52:26 +08:00
|
|
|
* @metric_no_merge: is metric sharing explicitly disabled.
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
* @fake_pmu: used when testing metrics not supported by the current CPU.
|
|
|
|
* @ids: the event identifiers parsed from a metric.
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
* @modifier: any modifiers added to the events.
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
* @has_constraint: false if events should be placed in a weak group.
|
|
|
|
* @out_evlist: the created list of events.
|
|
|
|
*/
|
perf metric: Reduce multiplexing with duration_time
It is common to use the same counters with and without duration_time.
The ID sharing code treats duration_time as if it were a hardware event
placed in the same group. This causes unnecessary multiplexing such as
in the following example where l3_cache_access isn't shared:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,117,007 l3_cache_miss # 199.5 MB/s l3_rd_bw
# 43.6 % l3_hits
# 56.4 % l3_miss (50.00%)
5,526,447 l3_cache_access (50.00%)
5,392,435 l3_cache_access # 5389191.2 access/s l3_access_rate (50.00%)
1,000,601,901 ns duration_time
1.000601901 seconds time elapsed
Fix this by placing duration_time in all groups unless metric
sharing has been disabled on the command line:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,597,972 l3_cache_miss # 230.3 MB/s l3_rd_bw
# 48.0 % l3_hits
# 52.0 % l3_miss
6,914,459 l3_cache_access # 6909935.9 access/s l3_access_rate
1,000,654,579 ns duration_time
1.000654579 seconds time elapsed
$ perf stat --metric-no-merge -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,501,834 l3_cache_miss # 53.5 % l3_miss (24.99%)
6,548,173 l3_cache_access (24.99%)
3,417,622 l3_cache_miss # 45.7 % l3_hits (25.04%)
6,294,062 l3_cache_access (25.04%)
5,923,238 l3_cache_access # 5919688.1 access/s l3_access_rate (24.99%)
1,000,599,683 ns duration_time
3,607,486 l3_cache_miss # 230.9 MB/s l3_rd_bw (49.97%)
1.000599683 seconds time elapsed
v2. Doesn't count duration_time in the metric_list_cmp function that
sorts larger metrics first. Without this a metric with duration_time
and an event is sorted the same as a metric with two events,
possibly not allowing the first metric to share with the second.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20211124015226.3317994-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-11-24 09:52:26 +08:00
|
|
|
static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
|
|
|
|
struct expr_parse_ctx *ids, const char *modifier,
|
|
|
|
bool has_constraint, struct evlist **out_evlist)
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
{
|
|
|
|
struct parse_events_error parse_error;
|
|
|
|
struct evlist *parsed_evlist;
|
|
|
|
struct strbuf events = STRBUF_INIT;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
*out_evlist = NULL;
|
perf metric: Reduce multiplexing with duration_time
It is common to use the same counters with and without duration_time.
The ID sharing code treats duration_time as if it were a hardware event
placed in the same group. This causes unnecessary multiplexing such as
in the following example where l3_cache_access isn't shared:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,117,007 l3_cache_miss # 199.5 MB/s l3_rd_bw
# 43.6 % l3_hits
# 56.4 % l3_miss (50.00%)
5,526,447 l3_cache_access (50.00%)
5,392,435 l3_cache_access # 5389191.2 access/s l3_access_rate (50.00%)
1,000,601,901 ns duration_time
1.000601901 seconds time elapsed
Fix this by placing duration_time in all groups unless metric
sharing has been disabled on the command line:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,597,972 l3_cache_miss # 230.3 MB/s l3_rd_bw
# 48.0 % l3_hits
# 52.0 % l3_miss
6,914,459 l3_cache_access # 6909935.9 access/s l3_access_rate
1,000,654,579 ns duration_time
1.000654579 seconds time elapsed
$ perf stat --metric-no-merge -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,501,834 l3_cache_miss # 53.5 % l3_miss (24.99%)
6,548,173 l3_cache_access (24.99%)
3,417,622 l3_cache_miss # 45.7 % l3_hits (25.04%)
6,294,062 l3_cache_access (25.04%)
5,923,238 l3_cache_access # 5919688.1 access/s l3_access_rate (24.99%)
1,000,599,683 ns duration_time
3,607,486 l3_cache_miss # 230.9 MB/s l3_rd_bw (49.97%)
1.000599683 seconds time elapsed
v2. Doesn't count duration_time in the metric_list_cmp function that
sorts larger metrics first. Without this a metric with duration_time
and an event is sorted the same as a metric with two events,
possibly not allowing the first metric to share with the second.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20211124015226.3317994-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-11-24 09:52:26 +08:00
|
|
|
if (!metric_no_merge || hashmap__size(ids->ids) == 0) {
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
char *tmp;
|
|
|
|
/*
|
perf metric: Reduce multiplexing with duration_time
It is common to use the same counters with and without duration_time.
The ID sharing code treats duration_time as if it were a hardware event
placed in the same group. This causes unnecessary multiplexing such as
in the following example where l3_cache_access isn't shared:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,117,007 l3_cache_miss # 199.5 MB/s l3_rd_bw
# 43.6 % l3_hits
# 56.4 % l3_miss (50.00%)
5,526,447 l3_cache_access (50.00%)
5,392,435 l3_cache_access # 5389191.2 access/s l3_access_rate (50.00%)
1,000,601,901 ns duration_time
1.000601901 seconds time elapsed
Fix this by placing duration_time in all groups unless metric
sharing has been disabled on the command line:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,597,972 l3_cache_miss # 230.3 MB/s l3_rd_bw
# 48.0 % l3_hits
# 52.0 % l3_miss
6,914,459 l3_cache_access # 6909935.9 access/s l3_access_rate
1,000,654,579 ns duration_time
1.000654579 seconds time elapsed
$ perf stat --metric-no-merge -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,501,834 l3_cache_miss # 53.5 % l3_miss (24.99%)
6,548,173 l3_cache_access (24.99%)
3,417,622 l3_cache_miss # 45.7 % l3_hits (25.04%)
6,294,062 l3_cache_access (25.04%)
5,923,238 l3_cache_access # 5919688.1 access/s l3_access_rate (24.99%)
1,000,599,683 ns duration_time
3,607,486 l3_cache_miss # 230.9 MB/s l3_rd_bw (49.97%)
1.000599683 seconds time elapsed
v2. Doesn't count duration_time in the metric_list_cmp function that
sorts larger metrics first. Without this a metric with duration_time
and an event is sorted the same as a metric with two events,
possibly not allowing the first metric to share with the second.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20211124015226.3317994-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-11-24 09:52:26 +08:00
|
|
|
* We may fail to share events between metrics because
|
|
|
|
* duration_time isn't present in one metric. For example, a
|
|
|
|
* ratio of cache misses doesn't need duration_time but the same
|
|
|
|
* events may be used for a misses per second. Events without
|
|
|
|
* sharing implies multiplexing, that is best avoided, so place
|
|
|
|
* duration_time in every group.
|
|
|
|
*
|
|
|
|
* Also, there may be no ids/events in the expression parsing
|
|
|
|
* context because of constant evaluation, e.g.:
|
|
|
|
* event1 if #smt_on else 0
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
* Add a duration_time event to avoid a parse error on an empty
|
|
|
|
* string.
|
|
|
|
*/
|
|
|
|
tmp = strdup("duration_time");
|
|
|
|
if (!tmp)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ids__insert(ids->ids, tmp);
|
|
|
|
}
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
ret = metricgroup__build_event_string(&events, ids, modifier,
|
|
|
|
has_constraint);
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
parsed_evlist = evlist__new();
|
|
|
|
if (!parsed_evlist) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
pr_debug("Parsing metric events '%s'\n", events.buf);
|
2021-11-07 17:00:01 +08:00
|
|
|
parse_events_error__init(&parse_error);
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
ret = __parse_events(parsed_evlist, events.buf, &parse_error, fake_pmu);
|
|
|
|
if (ret) {
|
2021-11-07 17:00:00 +08:00
|
|
|
parse_events_error__print(&parse_error, events.buf);
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
goto err_out;
|
|
|
|
}
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
ret = decode_all_metric_ids(parsed_evlist, modifier);
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
if (ret)
|
|
|
|
goto err_out;
|
|
|
|
|
|
|
|
*out_evlist = parsed_evlist;
|
|
|
|
parsed_evlist = NULL;
|
|
|
|
err_out:
|
2021-11-07 17:00:01 +08:00
|
|
|
parse_events_error__exit(&parse_error);
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
evlist__delete(parsed_evlist);
|
|
|
|
strbuf_release(&events);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-03 05:47:33 +08:00
|
|
|
static int parse_groups(struct evlist *perf_evlist, const char *str,
|
|
|
|
bool metric_no_group,
|
|
|
|
bool metric_no_merge,
|
2020-06-09 23:50:42 +08:00
|
|
|
struct perf_pmu *fake_pmu,
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
struct rblist *metric_events_list,
|
2021-10-16 01:21:13 +08:00
|
|
|
const struct pmu_events_map *map)
|
2017-09-01 03:40:31 +08:00
|
|
|
{
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
struct evlist *combined_evlist = NULL;
|
2020-07-20 02:13:20 +08:00
|
|
|
LIST_HEAD(metric_list);
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
struct metric *m;
|
2017-09-01 03:40:31 +08:00
|
|
|
int ret;
|
|
|
|
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
if (metric_events_list->nr_entries == 0)
|
|
|
|
metricgroup__rblist_init(metric_events_list);
|
2020-05-21 02:20:10 +08:00
|
|
|
ret = metricgroup__add_metric_list(str, metric_no_group,
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
&metric_list, map);
|
2017-09-01 03:40:31 +08:00
|
|
|
if (ret)
|
2020-09-15 11:18:09 +08:00
|
|
|
goto out;
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
|
|
|
|
/* Sort metrics from largest to smallest. */
|
|
|
|
list_sort(NULL, &metric_list, metric_list_cmp);
|
|
|
|
|
|
|
|
if (!metric_no_merge) {
|
|
|
|
struct expr_parse_ctx *combined = NULL;
|
|
|
|
|
|
|
|
ret = build_combined_expr_ctx(&metric_list, &combined);
|
|
|
|
|
|
|
|
if (!ret && combined && hashmap__size(combined->ids)) {
|
perf metric: Reduce multiplexing with duration_time
It is common to use the same counters with and without duration_time.
The ID sharing code treats duration_time as if it were a hardware event
placed in the same group. This causes unnecessary multiplexing such as
in the following example where l3_cache_access isn't shared:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,117,007 l3_cache_miss # 199.5 MB/s l3_rd_bw
# 43.6 % l3_hits
# 56.4 % l3_miss (50.00%)
5,526,447 l3_cache_access (50.00%)
5,392,435 l3_cache_access # 5389191.2 access/s l3_access_rate (50.00%)
1,000,601,901 ns duration_time
1.000601901 seconds time elapsed
Fix this by placing duration_time in all groups unless metric
sharing has been disabled on the command line:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,597,972 l3_cache_miss # 230.3 MB/s l3_rd_bw
# 48.0 % l3_hits
# 52.0 % l3_miss
6,914,459 l3_cache_access # 6909935.9 access/s l3_access_rate
1,000,654,579 ns duration_time
1.000654579 seconds time elapsed
$ perf stat --metric-no-merge -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,501,834 l3_cache_miss # 53.5 % l3_miss (24.99%)
6,548,173 l3_cache_access (24.99%)
3,417,622 l3_cache_miss # 45.7 % l3_hits (25.04%)
6,294,062 l3_cache_access (25.04%)
5,923,238 l3_cache_access # 5919688.1 access/s l3_access_rate (24.99%)
1,000,599,683 ns duration_time
3,607,486 l3_cache_miss # 230.9 MB/s l3_rd_bw (49.97%)
1.000599683 seconds time elapsed
v2. Doesn't count duration_time in the metric_list_cmp function that
sorts larger metrics first. Without this a metric with duration_time
and an event is sorted the same as a metric with two events,
possibly not allowing the first metric to share with the second.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20211124015226.3317994-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-11-24 09:52:26 +08:00
|
|
|
ret = parse_ids(metric_no_merge, fake_pmu, combined,
|
|
|
|
/*modifier=*/NULL,
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
/*has_constraint=*/true,
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
&combined_evlist);
|
|
|
|
}
|
|
|
|
if (combined)
|
|
|
|
expr__ctx_free(combined);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_entry(m, &metric_list, nd) {
|
|
|
|
struct metric_event *me;
|
|
|
|
struct evsel **metric_events;
|
|
|
|
struct evlist *metric_evlist = NULL;
|
|
|
|
struct metric *n;
|
|
|
|
struct metric_expr *expr;
|
|
|
|
|
|
|
|
if (combined_evlist && m->has_constraint) {
|
|
|
|
metric_evlist = combined_evlist;
|
|
|
|
} else if (!metric_no_merge) {
|
|
|
|
/*
|
|
|
|
* See if the IDs for this metric are a subset of an
|
|
|
|
* earlier metric.
|
|
|
|
*/
|
|
|
|
list_for_each_entry(n, &metric_list, nd) {
|
|
|
|
if (m == n)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (n->evlist == NULL)
|
|
|
|
continue;
|
|
|
|
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
if ((!m->modifier && n->modifier) ||
|
|
|
|
(m->modifier && !n->modifier) ||
|
|
|
|
(m->modifier && n->modifier &&
|
|
|
|
strcmp(m->modifier, n->modifier)))
|
|
|
|
continue;
|
|
|
|
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
if (expr__subset_of_ids(n->pctx, m->pctx)) {
|
|
|
|
pr_debug("Events in '%s' fully contained within '%s'\n",
|
|
|
|
m->metric_name, n->metric_name);
|
|
|
|
metric_evlist = n->evlist;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!metric_evlist) {
|
perf metric: Reduce multiplexing with duration_time
It is common to use the same counters with and without duration_time.
The ID sharing code treats duration_time as if it were a hardware event
placed in the same group. This causes unnecessary multiplexing such as
in the following example where l3_cache_access isn't shared:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,117,007 l3_cache_miss # 199.5 MB/s l3_rd_bw
# 43.6 % l3_hits
# 56.4 % l3_miss (50.00%)
5,526,447 l3_cache_access (50.00%)
5,392,435 l3_cache_access # 5389191.2 access/s l3_access_rate (50.00%)
1,000,601,901 ns duration_time
1.000601901 seconds time elapsed
Fix this by placing duration_time in all groups unless metric
sharing has been disabled on the command line:
$ perf stat -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,597,972 l3_cache_miss # 230.3 MB/s l3_rd_bw
# 48.0 % l3_hits
# 52.0 % l3_miss
6,914,459 l3_cache_access # 6909935.9 access/s l3_access_rate
1,000,654,579 ns duration_time
1.000654579 seconds time elapsed
$ perf stat --metric-no-merge -M l3 -a sleep 1
Performance counter stats for 'system wide':
3,501,834 l3_cache_miss # 53.5 % l3_miss (24.99%)
6,548,173 l3_cache_access (24.99%)
3,417,622 l3_cache_miss # 45.7 % l3_hits (25.04%)
6,294,062 l3_cache_access (25.04%)
5,923,238 l3_cache_access # 5919688.1 access/s l3_access_rate (24.99%)
1,000,599,683 ns duration_time
3,607,486 l3_cache_miss # 230.9 MB/s l3_rd_bw (49.97%)
1.000599683 seconds time elapsed
v2. Doesn't count duration_time in the metric_list_cmp function that
sorts larger metrics first. Without this a metric with duration_time
and an event is sorted the same as a metric with two events,
possibly not allowing the first metric to share with the second.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20211124015226.3317994-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-11-24 09:52:26 +08:00
|
|
|
ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier,
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
m->has_constraint, &m->evlist);
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
metric_evlist = m->evlist;
|
|
|
|
}
|
|
|
|
ret = setup_metric_events(m->pctx->ids, metric_evlist, &metric_events);
|
|
|
|
if (ret) {
|
|
|
|
pr_debug("Cannot resolve IDs for %s: %s\n",
|
|
|
|
m->metric_name, m->metric_expr);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
me = metricgroup__lookup(metric_events_list, metric_events[0], true);
|
|
|
|
|
|
|
|
expr = malloc(sizeof(struct metric_expr));
|
|
|
|
if (!expr) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
free(metric_events);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
expr->metric_refs = m->metric_refs;
|
|
|
|
m->metric_refs = NULL;
|
|
|
|
expr->metric_expr = m->metric_expr;
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
if (m->modifier) {
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (asprintf(&tmp, "%s:%s", m->metric_name, m->modifier) < 0)
|
|
|
|
expr->metric_name = NULL;
|
|
|
|
else
|
|
|
|
expr->metric_name = tmp;
|
|
|
|
} else
|
|
|
|
expr->metric_name = strdup(m->metric_name);
|
|
|
|
|
|
|
|
if (!expr->metric_name) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
free(metric_events);
|
|
|
|
goto out;
|
|
|
|
}
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
expr->metric_unit = m->metric_unit;
|
|
|
|
expr->metric_events = metric_events;
|
|
|
|
expr->runtime = m->pctx->runtime;
|
|
|
|
list_add(&expr->nd, &me->head);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-07 17:00:02 +08:00
|
|
|
if (combined_evlist) {
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
evlist__splice_list_tail(perf_evlist, &combined_evlist->core.entries);
|
2021-11-07 17:00:02 +08:00
|
|
|
evlist__delete(combined_evlist);
|
|
|
|
}
|
perf metrics: Modify setup and deduplication
Previously find_evsel_group was trying to share events while
mark-sweeping to eliminate unused events, this was complicated and had
issues around uncore events and grouped sharing.
This was further complicated by the event string being created while
metrics and metric groups were being added, with the string affecting
the evlist order.
This change moves deduplication before event parsing. Ungrouped events
are placed in a single combined set. Groups are checked to see if an
earlier (larger) group can support their events.
As the deduplication and sharing detection is done on metric IDs before
parsing, wildcard expansion problems with uncore events are avoided.
Overall the code is simpler while working better.
An example of failing to deduplicate can be seen with a list of metrics
like the following, where in the after case multiplexing has been
avoided:
Before:
$ perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
959,620,872 uops_issued.any # 0.06 Bad_Speculation (50.03%)
2,163,072,261 cycles
# 0.09 Retiring (50.03%)
735,827,436 uops_retired.retire_slots (50.03%)
74,676,484 int_misc.recovery_cycles (50.03%)
987,062,794 uops_issued.any # 0.50 Backend_Bound (49.97%)
2,203,734,187 cycles
# 0.35 Frontend_Bound (49.97%)
3,085,016,091 idq_uops_not_delivered.core (49.97%)
758,599,232 uops_retired.retire_slots (49.97%)
75,807,526 int_misc.recovery_cycles (49.97%)
2.002103760 seconds time elapsed
After:
$ sudo perf stat -M Bad_Speculation,Backend_Bound,Frontend_Bound,Retiring -a sleep 2
Performance counter stats for 'system wide':
769,694,676 uops_issued.any # 0.08 Bad_Speculation
# 0.41 Backend_Bound
1,087,548,633 cycles
# 0.38 Frontend_Bound
# 0.14 Retiring
1,642,085,777 idq_uops_not_delivered.core
603,112,590 uops_retired.retire_slots
43,787,854 int_misc.recovery_cycles
2.003844383 seconds time elapsed
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-19-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:29 +08:00
|
|
|
|
|
|
|
list_for_each_entry(m, &metric_list, nd) {
|
|
|
|
if (m->evlist)
|
|
|
|
evlist__splice_list_tail(perf_evlist, &m->evlist->core.entries);
|
2017-09-01 03:40:31 +08:00
|
|
|
}
|
perf metric: Encode and use metric-id as qualifier
For a metric like IPC a group of events like {instructions,cycles}:W
would be formed.
If the events names were changed in parsing then the metric expression
parser would fail to find them.
This change makes the event encoding be something like:
{instructions/metric-id=instructions/, cycles/metric-id=cycles/}
and then uses the evsel's stable metric-id value to locate the events.
This fixes the case that an event is restricted to user because of the
paranoia setting:
$ echo 2 > /proc/sys/kernel/perf_event_paranoid
$ perf stat -M IPC /bin/true
Performance counter stats for '/bin/true':
150,298 inst_retired.any:u # 0.77 IPC
187,095 cpu_clk_unhalted.thread:u
0.002042731 seconds time elapsed
0.000000000 seconds user
0.002377000 seconds sys
Adding the metric-id as a qualifier has a complication in that
qualifiers will become embedded in qualifiers.
For example, msr/tsc/ could become msr/tsc,metric-id=msr/tsc// which
will fail parse-events.
To solve this problem the metric is encoded and decoded for the
metric-id with !<num> standing in for an encoded value.
Previously ! wasn't parsed.
With this msr/tsc/ becomes msr/tsc,metric-id=msr!3tsc!3/
The metric expression parser is changed so that @ isn't changed to /,
instead this is done when the ID is encoded for parse events.
metricgroup__add_metric_non_group() and metricgroup__add_metric_weak_group()
need to inject the metric-id qualifier, so to avoid repetition they are
merged into a single metricgroup__build_event_string with error codes
more rigorously checked.
stat-shadow's prepare_metric() uses the metric-id to match the metricgroup
code.
As "metric-id=..." is added to all events, it is adding during testing
with the fake PMU.
This complicates pmu_str_check code as PE_PMU_EVENT_FAKE won't match as
part of a configuration.
The testing fake PMU case is fixed so that if a known qualifier with an
! is parsed then it isn't reported as a fake PMU.
This is sufficient to pass all testing but it and the original mechanism
are somewhat brittle.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-17-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:27 +08:00
|
|
|
|
2017-09-01 03:40:31 +08:00
|
|
|
out:
|
2020-07-20 02:13:20 +08:00
|
|
|
metricgroup__free_metrics(&metric_list);
|
2017-09-01 03:40:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2018-06-26 15:17:01 +08:00
|
|
|
|
2020-06-03 05:47:33 +08:00
|
|
|
int metricgroup__parse_groups(const struct option *opt,
|
|
|
|
const char *str,
|
|
|
|
bool metric_no_group,
|
|
|
|
bool metric_no_merge,
|
|
|
|
struct rblist *metric_events)
|
|
|
|
{
|
|
|
|
struct evlist *perf_evlist = *(struct evlist **)opt->value;
|
2021-10-16 01:21:13 +08:00
|
|
|
const struct pmu_events_map *map = pmu_events_map__find();
|
2020-06-03 05:47:33 +08:00
|
|
|
|
|
|
|
return parse_groups(perf_evlist, str, metric_no_group,
|
2020-06-09 23:57:47 +08:00
|
|
|
metric_no_merge, NULL, metric_events, map);
|
2020-06-03 05:47:33 +08:00
|
|
|
}
|
|
|
|
|
2020-06-03 05:47:36 +08:00
|
|
|
int metricgroup__parse_groups_test(struct evlist *evlist,
|
2021-10-16 01:21:13 +08:00
|
|
|
const struct pmu_events_map *map,
|
2020-06-03 05:47:36 +08:00
|
|
|
const char *str,
|
|
|
|
bool metric_no_group,
|
|
|
|
bool metric_no_merge,
|
|
|
|
struct rblist *metric_events)
|
|
|
|
{
|
|
|
|
return parse_groups(evlist, str, metric_no_group,
|
|
|
|
metric_no_merge, &perf_pmu__fake, metric_events, map);
|
|
|
|
}
|
|
|
|
|
2018-06-26 15:17:01 +08:00
|
|
|
bool metricgroup__has_metric(const char *metric)
|
|
|
|
{
|
2021-10-16 01:21:13 +08:00
|
|
|
const struct pmu_events_map *map = pmu_events_map__find();
|
2021-10-16 01:21:15 +08:00
|
|
|
const struct pmu_event *pe;
|
2018-06-26 15:17:01 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!map)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
pe = &map->table[i];
|
|
|
|
|
|
|
|
if (!pe->name && !pe->metric_group && !pe->metric_name)
|
|
|
|
break;
|
|
|
|
if (!pe->metric_expr)
|
|
|
|
continue;
|
|
|
|
if (match_metric(pe->metric_name, metric))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2020-09-24 20:44:53 +08:00
|
|
|
|
|
|
|
int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
|
|
|
|
struct rblist *new_metric_events,
|
|
|
|
struct rblist *old_metric_events)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < rblist__nr_entries(old_metric_events); i++) {
|
|
|
|
struct rb_node *nd;
|
|
|
|
struct metric_event *old_me, *new_me;
|
|
|
|
struct metric_expr *old_expr, *new_expr;
|
|
|
|
struct evsel *evsel;
|
|
|
|
size_t alloc_size;
|
|
|
|
int idx, nr;
|
|
|
|
|
|
|
|
nd = rblist__entry(old_metric_events, i);
|
|
|
|
old_me = container_of(nd, struct metric_event, nd);
|
|
|
|
|
2021-07-06 23:16:59 +08:00
|
|
|
evsel = evlist__find_evsel(evlist, old_me->evsel->core.idx);
|
2020-09-24 20:44:53 +08:00
|
|
|
if (!evsel)
|
|
|
|
return -EINVAL;
|
|
|
|
new_me = metricgroup__lookup(new_metric_events, evsel, true);
|
|
|
|
if (!new_me)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pr_debug("copying metric event for cgroup '%s': %s (idx=%d)\n",
|
2021-07-06 23:16:59 +08:00
|
|
|
cgrp ? cgrp->name : "root", evsel->name, evsel->core.idx);
|
2020-09-24 20:44:53 +08:00
|
|
|
|
|
|
|
list_for_each_entry(old_expr, &old_me->head, nd) {
|
|
|
|
new_expr = malloc(sizeof(*new_expr));
|
|
|
|
if (!new_expr)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
new_expr->metric_expr = old_expr->metric_expr;
|
perf metric: Allow modifiers on metrics
By allowing modifiers on metrics we can, for example, gather the
same metric for kernel and user mode. On a SkylakeX with
TopDownL1 this gives:
$ perf stat -M TopDownL1:u,TopDownL1:k -a sleep 2
Performance counter stats for 'system wide':
849,855,577 uops_issued.any:k # 0.06 Bad_Speculation:k
# 0.51 Backend_Bound:k (16.71%)
1,995,257,996 cycles:k
# 7981031984.00 SLOTS:k
# 0.35 Frontend_Bound:k
# 0.08 Retiring:k (16.71%)
2,791,940,753 idq_uops_not_delivered.core:k (16.71%)
641,961,928 uops_retired.retire_slots:k (16.71%)
72,239,337 int_misc.recovery_cycles:k (16.71%)
2,294,413,647 uops_issued.any:u # 0.04 Bad_Speculation:u
# 0.39 Backend_Bound:u (16.78%)
1,333,248,940 cycles:u
# 5332995760.00 SLOTS:u
# 0.16 Frontend_Bound:u
# 0.40 Retiring:u (16.78%)
858,517,081 idq_uops_not_delivered.core:u (16.78%)
2,153,789,582 uops_retired.retire_slots:u (16.78%)
19,373,627 int_misc.recovery_cycles:u (16.78%)
31,503,661 cpu_clk_unhalted.one_thread_active:k # 0.18 CoreIPC_SMT:k (16.73%)
315,454,104 inst_retired.any:k # 315454104.00 Instructions:k (16.73%)
42,533,729 cpu_clk_unhalted.ref_xclk:k (16.73%)
2,043,119,037 cpu_clk_unhalted.thread:k (16.73%)
28,843,803 cpu_clk_unhalted.one_thread_active:u # 1.55 CoreIPC_SMT:u (16.60%)
2,153,353,869 inst_retired.any:u # 2153353869.00 Instructions:u (16.60%)
28,844,743 cpu_clk_unhalted.ref_xclk:u (16.60%)
1,387,544,378 cpu_clk_unhalted.thread:u (16.60%)
308,031,603 inst_retired.any:k # 0.15 CoreIPC:k (33.19%)
2,036,774,753 cycles:k (33.19%)
1,994,344,281 inst_retired.any:u # 1.59 CoreIPC:u (33.18%)
1,251,538,227 cycles:u (33.18%)
2.000342948 seconds time elapsed
Modifiers are naively copy and pasted on to events, this can yield errors like:
$ perf stat -M Kernel_Utilization:k -a sleep 2
event syntax error: '..d.thread:k/kk,cpu_clk_unhalted.thread/metric-id=cpu_clk_unhalted.thread/k..'
\___ Bad modifier
Usage: perf stat [<options>] [<command>]
-M, --metrics <metric/metric group list>
monitor specified metrics or metric groups (separated by ,)
When modifiers are present with constraints, from --metric-no-group or
the NMI watchdog, they are no longer placed in the same set - which may
miss deduplicating events.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Antonov <alexander.antonov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andrew Kilroy <andrew.kilroy@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Changbin Du <changbin.du@intel.com>
Cc: Denys Zagorui <dzagorui@cisco.com>
Cc: Fabian Hemmer <copy@copy.sh>
Cc: Felix Fietkau <nbd@nbd.name>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>
Cc: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nicholas Fraser <nfraser@codeweavers.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>
Cc: ShihCheng Tu <mrtoastcheng@gmail.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Sumanth Korikkar <sumanthk@linux.ibm.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Wan Jiabing <wanjiabing@vivo.com>
Cc: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20211015172132.1162559-22-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-10-16 01:21:32 +08:00
|
|
|
new_expr->metric_name = strdup(old_expr->metric_name);
|
|
|
|
if (!new_expr->metric_name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2020-09-24 20:44:53 +08:00
|
|
|
new_expr->metric_unit = old_expr->metric_unit;
|
|
|
|
new_expr->runtime = old_expr->runtime;
|
|
|
|
|
|
|
|
if (old_expr->metric_refs) {
|
|
|
|
/* calculate number of metric_events */
|
|
|
|
for (nr = 0; old_expr->metric_refs[nr].metric_name; nr++)
|
|
|
|
continue;
|
|
|
|
alloc_size = sizeof(*new_expr->metric_refs);
|
|
|
|
new_expr->metric_refs = calloc(nr + 1, alloc_size);
|
|
|
|
if (!new_expr->metric_refs) {
|
|
|
|
free(new_expr);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(new_expr->metric_refs, old_expr->metric_refs,
|
|
|
|
nr * alloc_size);
|
|
|
|
} else {
|
|
|
|
new_expr->metric_refs = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate number of metric_events */
|
|
|
|
for (nr = 0; old_expr->metric_events[nr]; nr++)
|
|
|
|
continue;
|
|
|
|
alloc_size = sizeof(*new_expr->metric_events);
|
|
|
|
new_expr->metric_events = calloc(nr + 1, alloc_size);
|
|
|
|
if (!new_expr->metric_events) {
|
|
|
|
free(new_expr->metric_refs);
|
|
|
|
free(new_expr);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy evsel in the same position */
|
|
|
|
for (idx = 0; idx < nr; idx++) {
|
|
|
|
evsel = old_expr->metric_events[idx];
|
2021-07-06 23:16:59 +08:00
|
|
|
evsel = evlist__find_evsel(evlist, evsel->core.idx);
|
2020-09-24 20:44:53 +08:00
|
|
|
if (evsel == NULL) {
|
|
|
|
free(new_expr->metric_events);
|
|
|
|
free(new_expr->metric_refs);
|
|
|
|
free(new_expr);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
new_expr->metric_events[idx] = evsel;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add(&new_expr->nd, &new_me->head);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|