2019-05-29 14:18:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-08-31 19:40:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017, Intel Corporation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Manage metrics and groups of metrics from JSON files */
|
|
|
|
|
|
|
|
#include "metricgroup.h"
|
2019-08-29 18:56:40 +00:00
|
|
|
#include "debug.h"
|
2017-08-31 19:40:31 +00:00
|
|
|
#include "evlist.h"
|
2019-08-21 13:54:14 +00:00
|
|
|
#include "evsel.h"
|
2017-08-31 19:40:31 +00:00
|
|
|
#include "strbuf.h"
|
|
|
|
#include "pmu.h"
|
|
|
|
#include "expr.h"
|
|
|
|
#include "rblist.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "strlist.h"
|
|
|
|
#include <assert.h>
|
2019-06-26 00:13:51 +00:00
|
|
|
#include <linux/ctype.h>
|
2019-08-29 18:56:40 +00:00
|
|
|
#include <linux/string.h>
|
2019-07-04 15:06:20 +00:00
|
|
|
#include <linux/zalloc.h>
|
2019-08-21 13:54:14 +00: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-24 21:59:23 +00:00
|
|
|
#include <api/fs/fs.h>
|
|
|
|
#include "util.h"
|
2020-07-19 18:13:16 +00:00
|
|
|
#include <asm/bug.h>
|
2020-09-24 12:44:53 +00:00
|
|
|
#include "cgroup.h"
|
2017-08-31 19:40:31 +00:00
|
|
|
|
|
|
|
struct metric_event *metricgroup__lookup(struct rblist *metric_events,
|
2019-07-21 11:23:51 +00:00
|
|
|
struct evsel *evsel,
|
2017-08-31 19:40:31 +00: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-17 21:43:00 +00:00
|
|
|
|
|
|
|
if (!metric_events)
|
|
|
|
return NULL;
|
|
|
|
|
2017-08-31 19:40:31 +00: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-02 21:47:38 +00: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) {
|
2020-07-19 18:13:10 +00:00
|
|
|
free(expr->metric_refs);
|
2020-09-15 03:18:10 +00:00
|
|
|
free(expr->metric_events);
|
2020-06-02 21:47:38 +00:00
|
|
|
free(expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(me);
|
|
|
|
}
|
|
|
|
|
2017-08-31 19:40:31 +00: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-02 21:47:38 +00:00
|
|
|
metric_events->node_delete = metric_event_delete;
|
|
|
|
}
|
|
|
|
|
|
|
|
void metricgroup__rblist_exit(struct rblist *metric_events)
|
|
|
|
{
|
|
|
|
rblist__exit(metric_events);
|
2017-08-31 19:40:31 +00:00
|
|
|
}
|
|
|
|
|
2020-07-19 18:13:09 +00: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;
|
|
|
|
};
|
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
struct metric {
|
2017-08-31 19:40:31 +00:00
|
|
|
struct list_head nd;
|
2020-05-15 22:17:32 +00:00
|
|
|
struct expr_parse_ctx pctx;
|
2017-08-31 19:40:31 +00:00
|
|
|
const char *metric_name;
|
|
|
|
const char *metric_expr;
|
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 05:59:31 +00:00
|
|
|
const char *metric_unit;
|
2020-07-19 18:13:09 +00:00
|
|
|
struct list_head metric_refs;
|
|
|
|
int metric_refs_cnt;
|
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-01 20:33:37 +00:00
|
|
|
int runtime;
|
2020-05-20 18:20:07 +00:00
|
|
|
bool has_constraint;
|
2017-08-31 19:40:31 +00:00
|
|
|
};
|
|
|
|
|
2020-07-19 18:13:16 +00:00
|
|
|
#define RECURSION_ID_MAX 1000
|
|
|
|
|
|
|
|
struct expr_ids {
|
|
|
|
struct expr_id id[RECURSION_ID_MAX];
|
|
|
|
int cnt;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct expr_id *expr_ids__alloc(struct expr_ids *ids)
|
|
|
|
{
|
|
|
|
if (ids->cnt >= RECURSION_ID_MAX)
|
|
|
|
return NULL;
|
|
|
|
return &ids->id[ids->cnt++];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void expr_ids__exit(struct expr_ids *ids)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ids->cnt; i++)
|
|
|
|
free(ids->id[i].id);
|
|
|
|
}
|
|
|
|
|
2020-09-17 20:18:07 +00:00
|
|
|
static bool contains_event(struct evsel **metric_events, int num_events,
|
|
|
|
const char *event_name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_events; i++) {
|
|
|
|
if (!strcmp(metric_events[i]->name, event_name))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
perf metricgroup: Fix find_evsel_group() event selector
The following command segfaults on my x86 broadwell:
$ ./perf stat -M frontend_bound,retiring,backend_bound,bad_speculation sleep 1
WARNING: grouped events cpus do not match, disabling group:
anon group { raw 0x10e }
anon group { raw 0x10e }
perf: util/evsel.c:1596: get_group_fd: Assertion `!(!leader->core.fd)' failed.
Aborted (core dumped)
The issue shows itself as a use-after-free in evlist__check_cpu_maps(),
whereby the leader of an event selector (evsel) has been deleted (yet we
still attempt to verify for an evsel).
Fundamentally the problem comes from metricgroup__setup_events() ->
find_evsel_group(), and has developed from the previous fix attempt in
commit 9c880c24cb0d ("perf metricgroup: Fix for metrics containing
duration_time").
The problem now is that the logic in checking if an evsel is in the same
group is subtly broken for the "cycles" event. For the "cycles" event,
the pmu_name is NULL; however the logic in find_evsel_group() may set an
event matched against "cycles" as used, when it should not be.
This leads to a condition where an evsel is set, yet its leader is not.
Fix the check for evsel pmu_name by not matching evsels when either has a
NULL pmu_name.
There is still a pre-existing metric issue whereby the ordering of the
metrics may break the 'stat' function, as discussed at:
https://lore.kernel.org/lkml/49c6fccb-b716-1bf0-18a6-cace1cdb66b9@huawei.com/
Fixes: 9c880c24cb0d ("perf metricgroup: Fix for metrics containing duration_time")
Signed-off-by: John Garry <john.garry@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> # On a Thinkpad T450S
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/1623335580-187317-2-git-send-email-john.garry@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-10 14:32:59 +00:00
|
|
|
static bool evsel_same_pmu_or_none(struct evsel *ev1, struct evsel *ev2)
|
perf metricgroup: Fix for metrics containing duration_time
Metrics containing duration_time cause a segfault:
$ perf stat -v -M L1D_Cache_Fill_BW sleep 1
Using CPUID GenuineIntel-6-3D-4
metric expr 64 * l1d.replacement / 1000000000 / duration_time for L1D_Cache_Fill_BW
found event duration_time
found event l1d.replacement
adding {l1d.replacement}:W,duration_time
l1d.replacement -> cpu/umask=0x1,(null)=0x1e8483,event=0x51/
Segmentation fault
$
In commit c2337d67199a1ea1 ("perf metricgroup: Fix metrics using aliases
covering multiple PMUs"), the logic in find_evsel_group() when iter'ing
events was changed to not only select events in same group, but also for
aliased PMUs.
Checking whether events were for aliased PMUs was done by comparing the
event PMU name. This was not safe for duration_time event, which has no
associated PMU (and no PMU name), so fix by checking if the event PMU name
is set also.
Committer testing:
Reproduced the bug, then, on a:
$ grep -m1 ^'model name' /proc/cpuinfo
model name : Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
$
We now get:
$ perf stat -M L1D_Cache_Fill_BW sleep 1
Performance counter stats for 'sleep 1':
4,141 l1d.replacement:u
1,001,285,107 ns duration_time:u
1.001285107 seconds time elapsed
0.000000000 seconds user
0.001119000 seconds sys
$
Detais from -v:
Using CPUID GenuineIntel-6-8E-A
metric expr 64 * l1d.replacement / 1000000000 / duration_time for L1D_Cache_Fill_BW
found event duration_time
found event l1d.replacement
adding {l1d.replacement}:W,duration_time
l1d.replacement -> cpu/(null)=0x1e8483,umask=0x1,event=0x51/
Control descriptor is not initialized
Warning:
kernel.perf_event_paranoid=2, trying to fall back to excluding kernel and hypervisor samples
Warning:
kernel.perf_event_paranoid=2, trying to fall back to excluding kernel and hypervisor samples
l1d.replacement:u: 4592 612201 612201
duration_time:u: 1001478621 1001478621 1001478621
Fixes: c2337d67199a1ea1 ("perf metricgroup: Fix metrics using aliases covering multiple PMUs")
Reported-by: Joakim Zhang <qiangqing.zhang@nxp.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linuxarm@openeuler.org
Link: https://lore.kernel.org/r/1611159518-226883-1-git-send-email-john.garry@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-20 16:18:38 +00:00
|
|
|
{
|
|
|
|
if (!ev1->pmu_name || !ev2->pmu_name)
|
perf metricgroup: Fix find_evsel_group() event selector
The following command segfaults on my x86 broadwell:
$ ./perf stat -M frontend_bound,retiring,backend_bound,bad_speculation sleep 1
WARNING: grouped events cpus do not match, disabling group:
anon group { raw 0x10e }
anon group { raw 0x10e }
perf: util/evsel.c:1596: get_group_fd: Assertion `!(!leader->core.fd)' failed.
Aborted (core dumped)
The issue shows itself as a use-after-free in evlist__check_cpu_maps(),
whereby the leader of an event selector (evsel) has been deleted (yet we
still attempt to verify for an evsel).
Fundamentally the problem comes from metricgroup__setup_events() ->
find_evsel_group(), and has developed from the previous fix attempt in
commit 9c880c24cb0d ("perf metricgroup: Fix for metrics containing
duration_time").
The problem now is that the logic in checking if an evsel is in the same
group is subtly broken for the "cycles" event. For the "cycles" event,
the pmu_name is NULL; however the logic in find_evsel_group() may set an
event matched against "cycles" as used, when it should not be.
This leads to a condition where an evsel is set, yet its leader is not.
Fix the check for evsel pmu_name by not matching evsels when either has a
NULL pmu_name.
There is still a pre-existing metric issue whereby the ordering of the
metrics may break the 'stat' function, as discussed at:
https://lore.kernel.org/lkml/49c6fccb-b716-1bf0-18a6-cace1cdb66b9@huawei.com/
Fixes: 9c880c24cb0d ("perf metricgroup: Fix for metrics containing duration_time")
Signed-off-by: John Garry <john.garry@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> # On a Thinkpad T450S
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/1623335580-187317-2-git-send-email-john.garry@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-10 14:32:59 +00:00
|
|
|
return true;
|
perf metricgroup: Fix for metrics containing duration_time
Metrics containing duration_time cause a segfault:
$ perf stat -v -M L1D_Cache_Fill_BW sleep 1
Using CPUID GenuineIntel-6-3D-4
metric expr 64 * l1d.replacement / 1000000000 / duration_time for L1D_Cache_Fill_BW
found event duration_time
found event l1d.replacement
adding {l1d.replacement}:W,duration_time
l1d.replacement -> cpu/umask=0x1,(null)=0x1e8483,event=0x51/
Segmentation fault
$
In commit c2337d67199a1ea1 ("perf metricgroup: Fix metrics using aliases
covering multiple PMUs"), the logic in find_evsel_group() when iter'ing
events was changed to not only select events in same group, but also for
aliased PMUs.
Checking whether events were for aliased PMUs was done by comparing the
event PMU name. This was not safe for duration_time event, which has no
associated PMU (and no PMU name), so fix by checking if the event PMU name
is set also.
Committer testing:
Reproduced the bug, then, on a:
$ grep -m1 ^'model name' /proc/cpuinfo
model name : Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
$
We now get:
$ perf stat -M L1D_Cache_Fill_BW sleep 1
Performance counter stats for 'sleep 1':
4,141 l1d.replacement:u
1,001,285,107 ns duration_time:u
1.001285107 seconds time elapsed
0.000000000 seconds user
0.001119000 seconds sys
$
Detais from -v:
Using CPUID GenuineIntel-6-8E-A
metric expr 64 * l1d.replacement / 1000000000 / duration_time for L1D_Cache_Fill_BW
found event duration_time
found event l1d.replacement
adding {l1d.replacement}:W,duration_time
l1d.replacement -> cpu/(null)=0x1e8483,umask=0x1,event=0x51/
Control descriptor is not initialized
Warning:
kernel.perf_event_paranoid=2, trying to fall back to excluding kernel and hypervisor samples
Warning:
kernel.perf_event_paranoid=2, trying to fall back to excluding kernel and hypervisor samples
l1d.replacement:u: 4592 612201 612201
duration_time:u: 1001478621 1001478621 1001478621
Fixes: c2337d67199a1ea1 ("perf metricgroup: Fix metrics using aliases covering multiple PMUs")
Reported-by: Joakim Zhang <qiangqing.zhang@nxp.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Jiri Olsa <jolsa@redhat.com>
Acked-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linuxarm@openeuler.org
Link: https://lore.kernel.org/r/1611159518-226883-1-git-send-email-john.garry@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-20 16:18:38 +00:00
|
|
|
|
|
|
|
return !strcmp(ev1->pmu_name, ev2->pmu_name);
|
|
|
|
}
|
|
|
|
|
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-20 18:20:09 +00:00
|
|
|
/**
|
2020-09-10 03:26:31 +00:00
|
|
|
* Find a group of events in perf_evlist that correspond to those from a parsed
|
2020-05-20 18:20:10 +00:00
|
|
|
* metric expression. Note, as find_evsel_group is called in the same order as
|
|
|
|
* perf_evlist was constructed, metric_no_merge doesn't need to test for
|
|
|
|
* underfilling a group.
|
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-20 18:20:09 +00:00
|
|
|
* @perf_evlist: a list of events something like: {metric1 leader, metric1
|
|
|
|
* sibling, metric1 sibling}:W,duration_time,{metric2 leader, metric2 sibling,
|
|
|
|
* metric2 sibling}:W,duration_time
|
|
|
|
* @pctx: the parse context for the metric expression.
|
2020-05-20 18:20:10 +00:00
|
|
|
* @metric_no_merge: don't attempt to share events for the metric with other
|
|
|
|
* metrics.
|
2021-03-23 16:09:15 +00:00
|
|
|
* @has_constraint: is there a constraint on the group of events? In which case
|
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-20 18:20:09 +00:00
|
|
|
* the events won't be grouped.
|
|
|
|
* @metric_events: out argument, null terminated array of evsel's associated
|
|
|
|
* with the metric.
|
|
|
|
* @evlist_used: in/out argument, bitmap tracking which evlist events are used.
|
|
|
|
* @return the first metric event or NULL on failure.
|
|
|
|
*/
|
2019-07-21 11:23:52 +00:00
|
|
|
static struct evsel *find_evsel_group(struct evlist *perf_evlist,
|
2020-05-15 22:17:32 +00:00
|
|
|
struct expr_parse_ctx *pctx,
|
2020-05-20 18:20:10 +00:00
|
|
|
bool metric_no_merge,
|
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-20 18:20:09 +00:00
|
|
|
bool has_constraint,
|
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 10:11:21 +00:00
|
|
|
struct evsel **metric_events,
|
2020-05-20 07:28:08 +00:00
|
|
|
unsigned long *evlist_used)
|
2017-08-31 19:40:31 +00:00
|
|
|
{
|
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-20 18:20:09 +00:00
|
|
|
struct evsel *ev, *current_leader = NULL;
|
2020-07-12 13:26:18 +00:00
|
|
|
struct expr_id_data *val_ptr;
|
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-20 18:20:09 +00:00
|
|
|
int i = 0, matched_events = 0, events_to_match;
|
|
|
|
const int idnum = (int)hashmap__size(&pctx->ids);
|
|
|
|
|
2020-09-17 20:18:07 +00:00
|
|
|
/*
|
|
|
|
* duration_time is always grouped separately, when events are grouped
|
|
|
|
* (ie has_constraint is false) then ignore it in the matching loop and
|
|
|
|
* add it to metric_events at the end.
|
|
|
|
*/
|
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-20 18:20:09 +00:00
|
|
|
if (!has_constraint &&
|
|
|
|
hashmap__find(&pctx->ids, "duration_time", (void **)&val_ptr))
|
|
|
|
events_to_match = idnum - 1;
|
|
|
|
else
|
|
|
|
events_to_match = idnum;
|
2017-08-31 19:40:31 +00:00
|
|
|
|
|
|
|
evlist__for_each_entry (perf_evlist, ev) {
|
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-20 18:20:09 +00:00
|
|
|
/*
|
|
|
|
* Events with a constraint aren't grouped and match the first
|
|
|
|
* events available.
|
|
|
|
*/
|
|
|
|
if (has_constraint && ev->weak_group)
|
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 10:11:21 +00:00
|
|
|
continue;
|
2020-05-20 18:20:10 +00:00
|
|
|
/* Ignore event if already used and merging is disabled. */
|
|
|
|
if (metric_no_merge && test_bit(ev->idx, evlist_used))
|
|
|
|
continue;
|
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-20 18:20:09 +00:00
|
|
|
if (!has_constraint && ev->leader != current_leader) {
|
|
|
|
/*
|
|
|
|
* Start of a new group, discard the whole match and
|
|
|
|
* start again.
|
|
|
|
*/
|
|
|
|
matched_events = 0;
|
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 10:11:21 +00:00
|
|
|
memset(metric_events, 0,
|
|
|
|
sizeof(struct evsel *) * idnum);
|
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-20 18:20:09 +00:00
|
|
|
current_leader = ev->leader;
|
|
|
|
}
|
2020-09-17 20:18:07 +00: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. If events aren't grouped then this also
|
|
|
|
* ensures that the same event in different sibling groups
|
|
|
|
* aren't both added to metric_events.
|
|
|
|
*/
|
|
|
|
if (contains_event(metric_events, matched_events, ev->name))
|
|
|
|
continue;
|
|
|
|
/* Does this event belong to the parse context? */
|
|
|
|
if (hashmap__find(&pctx->ids, ev->name, (void **)&val_ptr))
|
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-20 18:20:09 +00:00
|
|
|
metric_events[matched_events++] = ev;
|
2020-09-17 20:18:07 +00:00
|
|
|
|
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-20 18:20:09 +00:00
|
|
|
if (matched_events == events_to_match)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (events_to_match != idnum) {
|
|
|
|
/* Add the first duration_time. */
|
|
|
|
evlist__for_each_entry(perf_evlist, ev) {
|
|
|
|
if (!strcmp(ev->name, "duration_time")) {
|
|
|
|
metric_events[matched_events++] = ev;
|
|
|
|
break;
|
|
|
|
}
|
2017-08-31 19:40:31 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-28 05:59:32 +00:00
|
|
|
|
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-20 18:20:09 +00:00
|
|
|
if (matched_events != idnum) {
|
2020-09-17 20:18:07 +00:00
|
|
|
/* Not a whole match */
|
2019-08-28 05:59:32 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
metric_events[idnum] = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < idnum; 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 10:11:21 +00:00
|
|
|
ev = metric_events[i];
|
2020-09-17 20:18:07 +00:00
|
|
|
/* Don't free the used events. */
|
2020-05-20 07:28:08 +00:00
|
|
|
set_bit(ev->idx, evlist_used);
|
2020-09-17 20:18:07 +00:00
|
|
|
/*
|
|
|
|
* The metric leader points to the identically named event in
|
|
|
|
* metric_events.
|
|
|
|
*/
|
|
|
|
ev->metric_leader = ev;
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
evlist__for_each_entry_continue(perf_evlist, ev) {
|
|
|
|
/*
|
|
|
|
* If events are grouped then the search can terminate
|
|
|
|
* when then group is left.
|
|
|
|
*/
|
|
|
|
if (!has_constraint &&
|
perf metricgroup: Fix metrics using aliases covering multiple PMUs
Support for metric expressions using aliases which cover multiple PMUs
is broken. Consider the following test metric expression:
"MetricExpr": "UNC_CBO_XSNP_RESPONSE.MISS_XCORE * UNC_CBO_XSNP_RESPONSE.MISS_EVICTION"
When used on my broadwell, "perf stat" gives:
unc_cbo_xsnp_response.miss_eviction -> uncore_cbox_1/umask=0x81,event=0x22/
unc_cbo_xsnp_response.miss_eviction -> uncore_cbox_0/umask=0x81,event=0x22/
unc_cbo_xsnp_response.miss_xcore -> uncore_cbox_1/umask=0x41,event=0x22/
unc_cbo_xsnp_response.miss_xcore -> uncore_cbox_0/umask=0x41,event=0x22/
Control descriptor is not initialized
unc_cbo_xsnp_response.miss_eviction: 3645925 1000850523 1000850523
unc_cbo_xsnp_response.miss_xcore: 106850 1000850523 1000850523
Performance counter stats for 'system wide':
3,645,925 unc_cbo_xsnp_response.miss_eviction # 389567086250.00 test_metric_inc
106,850 unc_cbo_xsnp_response.miss_xcore
1.000883096 seconds time elapsed
Notice that only the results from one PMU are included. Fix the logic of
find_evsel_group() to enable events which apply to multiple PMUs, by
checking if the event pmu_name matches that of the metric event.
With that, "perf stat" now gives:
unc_cbo_xsnp_response.miss_eviction -> uncore_cbox_1/umask=0x81,event=0x22/
unc_cbo_xsnp_response.miss_eviction -> uncore_cbox_0/umask=0x81,event=0x22/
unc_cbo_xsnp_response.miss_xcore -> uncore_cbox_1/umask=0x41,event=0x22/
unc_cbo_xsnp_response.miss_xcore -> uncore_cbox_0/umask=0x41,event=0x22/
Control descriptor is not initialized
unc_cbo_xsnp_response.miss_eviction: 4237983 1000904100 1000904100
unc_cbo_xsnp_response.miss_xcore: 218643 1000904100 1000904100
unc_cbo_xsnp_response.miss_eviction: 4254148 1000902629 1000902629
unc_cbo_xsnp_response.miss_xcore: 213352 1000902629 1000902629
Performance counter stats for 'system wide':
4,237,983 unc_cbo_xsnp_response.miss_eviction # 3668558131345.00 test_metric_inc
218,643 unc_cbo_xsnp_response.miss_xcore
4,254,148 unc_cbo_xsnp_response.miss_eviction
213,352 unc_cbo_xsnp_response.miss_xcore
1.000938151 seconds time elapsed
Signed-off-by: John Garry <john.garry@huawei.com>
Acked-by: Kajol Jain <kjain@linux.ibm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shaokun Zhang <zhangshaokun@hisilicon.com>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linuxarm@huawei.com
Link: http://lore.kernel.org/lkml/1607080216-36968-7-git-send-email-john.garry@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-12-04 11:10:12 +00:00
|
|
|
ev->leader != metric_events[i]->leader &&
|
perf metricgroup: Fix find_evsel_group() event selector
The following command segfaults on my x86 broadwell:
$ ./perf stat -M frontend_bound,retiring,backend_bound,bad_speculation sleep 1
WARNING: grouped events cpus do not match, disabling group:
anon group { raw 0x10e }
anon group { raw 0x10e }
perf: util/evsel.c:1596: get_group_fd: Assertion `!(!leader->core.fd)' failed.
Aborted (core dumped)
The issue shows itself as a use-after-free in evlist__check_cpu_maps(),
whereby the leader of an event selector (evsel) has been deleted (yet we
still attempt to verify for an evsel).
Fundamentally the problem comes from metricgroup__setup_events() ->
find_evsel_group(), and has developed from the previous fix attempt in
commit 9c880c24cb0d ("perf metricgroup: Fix for metrics containing
duration_time").
The problem now is that the logic in checking if an evsel is in the same
group is subtly broken for the "cycles" event. For the "cycles" event,
the pmu_name is NULL; however the logic in find_evsel_group() may set an
event matched against "cycles" as used, when it should not be.
This leads to a condition where an evsel is set, yet its leader is not.
Fix the check for evsel pmu_name by not matching evsels when either has a
NULL pmu_name.
There is still a pre-existing metric issue whereby the ordering of the
metrics may break the 'stat' function, as discussed at:
https://lore.kernel.org/lkml/49c6fccb-b716-1bf0-18a6-cace1cdb66b9@huawei.com/
Fixes: 9c880c24cb0d ("perf metricgroup: Fix for metrics containing duration_time")
Signed-off-by: John Garry <john.garry@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> # On a Thinkpad T450S
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/1623335580-187317-2-git-send-email-john.garry@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-06-10 14:32:59 +00:00
|
|
|
evsel_same_pmu_or_none(ev->leader, metric_events[i]->leader))
|
2020-09-17 20:18:07 +00:00
|
|
|
break;
|
|
|
|
if (!strcmp(metric_events[i]->name, ev->name)) {
|
|
|
|
set_bit(ev->idx, evlist_used);
|
|
|
|
ev->metric_leader = metric_events[i];
|
|
|
|
}
|
|
|
|
}
|
2019-08-28 05:59:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return metric_events[0];
|
2017-08-31 19:40:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int metricgroup__setup_events(struct list_head *groups,
|
2020-05-20 18:20:10 +00:00
|
|
|
bool metric_no_merge,
|
2019-07-21 11:23:52 +00:00
|
|
|
struct evlist *perf_evlist,
|
2017-08-31 19:40:31 +00:00
|
|
|
struct rblist *metric_events_list)
|
|
|
|
{
|
|
|
|
struct metric_event *me;
|
|
|
|
struct metric_expr *expr;
|
|
|
|
int i = 0;
|
|
|
|
int ret = 0;
|
2020-07-19 18:13:19 +00:00
|
|
|
struct metric *m;
|
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-20 18:20:09 +00:00
|
|
|
struct evsel *evsel, *tmp;
|
2020-05-20 07:28:08 +00:00
|
|
|
unsigned long *evlist_used;
|
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 10:11:21 +00:00
|
|
|
|
2020-05-20 07:28:08 +00:00
|
|
|
evlist_used = bitmap_alloc(perf_evlist->core.nr_entries);
|
|
|
|
if (!evlist_used)
|
|
|
|
return -ENOMEM;
|
2017-08-31 19:40:31 +00:00
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
list_for_each_entry (m, groups, nd) {
|
2019-07-21 11:23:51 +00:00
|
|
|
struct evsel **metric_events;
|
2020-07-19 18:13:10 +00:00
|
|
|
struct metric_ref *metric_refs = NULL;
|
2017-08-31 19:40:31 +00:00
|
|
|
|
2020-05-15 22:17:32 +00:00
|
|
|
metric_events = calloc(sizeof(void *),
|
2020-07-19 18:13:19 +00:00
|
|
|
hashmap__size(&m->pctx.ids) + 1);
|
2017-08-31 19:40:31 +00:00
|
|
|
if (!metric_events) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
break;
|
|
|
|
}
|
2020-07-19 18:13:19 +00:00
|
|
|
evsel = find_evsel_group(perf_evlist, &m->pctx,
|
2020-05-20 18:20:10 +00:00
|
|
|
metric_no_merge,
|
2020-07-19 18:13:19 +00:00
|
|
|
m->has_constraint, metric_events,
|
2020-05-20 18:20:10 +00:00
|
|
|
evlist_used);
|
2017-08-31 19:40:31 +00:00
|
|
|
if (!evsel) {
|
|
|
|
pr_debug("Cannot resolve %s: %s\n",
|
2020-07-19 18:13:19 +00:00
|
|
|
m->metric_name, m->metric_expr);
|
2020-05-08 05:36:24 +00:00
|
|
|
free(metric_events);
|
2017-08-31 19:40:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-05-15 22:17:32 +00:00
|
|
|
for (i = 0; metric_events[i]; i++)
|
2017-08-31 19:40:31 +00:00
|
|
|
metric_events[i]->collect_stat = true;
|
|
|
|
me = metricgroup__lookup(metric_events_list, evsel, true);
|
|
|
|
if (!me) {
|
|
|
|
ret = -ENOMEM;
|
2020-05-08 05:36:24 +00:00
|
|
|
free(metric_events);
|
2017-08-31 19:40:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
expr = malloc(sizeof(struct metric_expr));
|
|
|
|
if (!expr) {
|
|
|
|
ret = -ENOMEM;
|
2020-05-08 05:36:24 +00:00
|
|
|
free(metric_events);
|
2017-08-31 19:40:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-07-19 18:13:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Collect and store collected nested expressions
|
|
|
|
* for metric processing.
|
|
|
|
*/
|
2020-07-19 18:13:19 +00:00
|
|
|
if (m->metric_refs_cnt) {
|
2020-07-19 18:13:10 +00:00
|
|
|
struct metric_ref_node *ref;
|
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
metric_refs = zalloc(sizeof(struct metric_ref) * (m->metric_refs_cnt + 1));
|
2020-07-19 18:13:10 +00:00
|
|
|
if (!metric_refs) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
free(metric_events);
|
2020-09-15 03:18:10 +00:00
|
|
|
free(expr);
|
2020-07-19 18:13:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
2020-07-19 18:13:19 +00:00
|
|
|
list_for_each_entry(ref, &m->metric_refs, list) {
|
2020-07-19 18:13:10 +00:00
|
|
|
/*
|
|
|
|
* Intentionally passing just const char pointers,
|
|
|
|
* originally from 'struct pmu_event' object.
|
|
|
|
* We don't need to change them, so there's no
|
|
|
|
* need to create our own copy.
|
|
|
|
*/
|
|
|
|
metric_refs[i].metric_name = ref->metric_name;
|
|
|
|
metric_refs[i].metric_expr = ref->metric_expr;
|
|
|
|
i++;
|
|
|
|
}
|
2021-02-01 07:41:17 +00:00
|
|
|
}
|
2020-07-19 18:13:10 +00:00
|
|
|
|
|
|
|
expr->metric_refs = metric_refs;
|
2020-07-19 18:13:19 +00:00
|
|
|
expr->metric_expr = m->metric_expr;
|
|
|
|
expr->metric_name = m->metric_name;
|
|
|
|
expr->metric_unit = m->metric_unit;
|
2017-08-31 19:40:31 +00:00
|
|
|
expr->metric_events = metric_events;
|
2020-07-19 18:13:19 +00:00
|
|
|
expr->runtime = m->runtime;
|
2017-08-31 19:40:31 +00:00
|
|
|
list_add(&expr->nd, &me->head);
|
|
|
|
}
|
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 10:11:21 +00:00
|
|
|
|
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-20 18:20:09 +00:00
|
|
|
evlist__for_each_entry_safe(perf_evlist, tmp, evsel) {
|
|
|
|
if (!test_bit(evsel->idx, evlist_used)) {
|
|
|
|
evlist__remove(perf_evlist, evsel);
|
|
|
|
evsel__delete(evsel);
|
|
|
|
}
|
|
|
|
}
|
2020-05-20 07:28:08 +00:00
|
|
|
bitmap_free(evlist_used);
|
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 10:11:21 +00:00
|
|
|
|
2017-08-31 19:40:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-12-04 11:10:15 +00:00
|
|
|
static bool match_pe_metric(struct pmu_event *pe, const char *metric)
|
|
|
|
{
|
|
|
|
return match_metric(pe->metric_group, metric) ||
|
|
|
|
match_metric(pe->metric_name, metric);
|
|
|
|
}
|
|
|
|
|
2017-08-31 19:40:32 +00: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 15:06:20 +00:00
|
|
|
zfree(&me->name);
|
2017-08-31 19:40:32 +00: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 15:06:20 +00:00
|
|
|
zfree(&me->name);
|
2017-08-31 19:40:32 +00: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');
|
|
|
|
}
|
|
|
|
|
2020-12-04 11:10:13 +00:00
|
|
|
static int metricgroup__print_pmu_event(struct pmu_event *pe,
|
|
|
|
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 11:10:14 +00:00
|
|
|
struct metricgroup_print_sys_idata {
|
|
|
|
struct strlist *metriclist;
|
|
|
|
char *filter;
|
|
|
|
struct rblist *groups;
|
|
|
|
bool metricgroups;
|
|
|
|
bool raw;
|
|
|
|
bool details;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef int (*metricgroup_sys_event_iter_fn)(struct pmu_event *pe, void *);
|
|
|
|
|
|
|
|
struct metricgroup_iter_data {
|
|
|
|
metricgroup_sys_event_iter_fn fn;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int metricgroup__sys_event_iter(struct pmu_event *pe, void *data)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int metricgroup__print_sys_event_iter(struct pmu_event *pe, void *data)
|
|
|
|
{
|
|
|
|
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-08-31 19:40:32 +00:00
|
|
|
void metricgroup__print(bool metrics, bool metricgroups, char *filter,
|
2019-02-13 12:32:41 +00:00
|
|
|
bool raw, bool details)
|
2017-08-31 19:40:32 +00:00
|
|
|
{
|
2021-04-07 10:32:47 +00:00
|
|
|
struct pmu_events_map *map = pmu_events_map__find();
|
2017-08-31 19:40:32 +00:00
|
|
|
struct pmu_event *pe;
|
|
|
|
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 11:10:14 +00:00
|
|
|
for (i = 0; map; i++) {
|
2017-08-31 19:40:32 +00:00
|
|
|
pe = &map->table[i];
|
|
|
|
|
|
|
|
if (!pe->name && !pe->metric_group && !pe->metric_name)
|
|
|
|
break;
|
|
|
|
if (!pe->metric_expr)
|
|
|
|
continue;
|
2020-12-04 11:10:13 +00:00
|
|
|
if (metricgroup__print_pmu_event(pe, metricgroups, filter,
|
|
|
|
raw, details, &groups,
|
|
|
|
metriclist) < 0)
|
|
|
|
return;
|
2017-08-31 19:40:32 +00:00
|
|
|
}
|
|
|
|
|
2020-12-04 11:10:14 +00: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 05:58:48 +00:00
|
|
|
if (!filter || !rblist__empty(&groups)) {
|
|
|
|
if (metricgroups && !raw)
|
|
|
|
printf("\nMetric Groups:\n\n");
|
|
|
|
else if (metrics && !raw)
|
|
|
|
printf("\nMetrics:\n\n");
|
|
|
|
}
|
2017-08-31 19:40:32 +00:00
|
|
|
|
2018-12-06 19:18:16 +00:00
|
|
|
for (node = rb_first_cached(&groups.entries); node; node = next) {
|
2017-08-31 19:40:32 +00:00
|
|
|
struct mep *me = container_of(node, struct mep, nd);
|
|
|
|
|
|
|
|
if (metricgroups)
|
2019-06-28 22:07:36 +00:00
|
|
|
printf("%s%s%s", me->name, metrics && !raw ? ":" : "", raw ? " " : "\n");
|
2017-08-31 19:40:32 +00: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);
|
|
|
|
}
|
|
|
|
|
2020-02-24 21:59:21 +00:00
|
|
|
static void metricgroup__add_metric_weak_group(struct strbuf *events,
|
2020-05-15 22:17:32 +00:00
|
|
|
struct expr_parse_ctx *ctx)
|
2020-02-24 21:59:21 +00:00
|
|
|
{
|
2020-05-15 22:17:32 +00:00
|
|
|
struct hashmap_entry *cur;
|
2020-05-20 18:20:05 +00:00
|
|
|
size_t bkt;
|
|
|
|
bool no_group = true, has_duration = false;
|
2020-02-24 21:59:21 +00:00
|
|
|
|
2020-05-15 22:17:32 +00:00
|
|
|
hashmap__for_each_entry((&ctx->ids), cur, bkt) {
|
|
|
|
pr_debug("found event %s\n", (const char *)cur->key);
|
2020-02-24 21:59:21 +00:00
|
|
|
/*
|
|
|
|
* Duration time maps to a software event and can make
|
|
|
|
* groups not count. Always use it outside a
|
|
|
|
* group.
|
|
|
|
*/
|
2020-05-15 22:17:32 +00:00
|
|
|
if (!strcmp(cur->key, "duration_time")) {
|
2020-05-20 18:20:05 +00:00
|
|
|
has_duration = true;
|
2020-02-24 21:59:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
strbuf_addf(events, "%s%s",
|
2020-05-20 18:20:05 +00:00
|
|
|
no_group ? "{" : ",",
|
2020-05-15 22:17:32 +00:00
|
|
|
(const char *)cur->key);
|
2020-02-24 21:59:21 +00:00
|
|
|
no_group = false;
|
|
|
|
}
|
2020-05-20 18:20:05 +00:00
|
|
|
if (!no_group) {
|
2020-02-24 21:59:21 +00:00
|
|
|
strbuf_addf(events, "}:W");
|
2020-05-20 18:20:05 +00:00
|
|
|
if (has_duration)
|
|
|
|
strbuf_addf(events, ",duration_time");
|
|
|
|
} else if (has_duration)
|
|
|
|
strbuf_addf(events, "duration_time");
|
2020-02-24 21:59:21 +00:00
|
|
|
}
|
|
|
|
|
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-24 21:59:23 +00:00
|
|
|
static void metricgroup__add_metric_non_group(struct strbuf *events,
|
2020-05-15 22:17:32 +00:00
|
|
|
struct expr_parse_ctx *ctx)
|
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-24 21:59:23 +00:00
|
|
|
{
|
2020-05-15 22:17:32 +00:00
|
|
|
struct hashmap_entry *cur;
|
|
|
|
size_t bkt;
|
2020-05-20 18:20:11 +00:00
|
|
|
bool first = true;
|
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-24 21:59:23 +00:00
|
|
|
|
2020-05-20 18:20:11 +00:00
|
|
|
hashmap__for_each_entry((&ctx->ids), cur, bkt) {
|
|
|
|
if (!first)
|
|
|
|
strbuf_addf(events, ",");
|
|
|
|
strbuf_addf(events, "%s", (const char *)cur->key);
|
|
|
|
first = false;
|
|
|
|
}
|
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-24 21:59:23 +00: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(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;
|
|
|
|
}
|
|
|
|
|
2020-09-07 06:41:32 +00:00
|
|
|
int __weak arch_get_runtimeparam(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-01 20:33:37 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-12-04 11:10:15 +00:00
|
|
|
struct metricgroup_add_iter_data {
|
|
|
|
struct list_head *metric_list;
|
|
|
|
const char *metric;
|
|
|
|
struct expr_ids *ids;
|
|
|
|
int *ret;
|
|
|
|
bool *has_match;
|
|
|
|
bool metric_no_group;
|
|
|
|
};
|
|
|
|
|
2020-07-19 18:13:20 +00:00
|
|
|
static int __add_metric(struct list_head *metric_list,
|
2020-07-19 18:13:08 +00:00
|
|
|
struct pmu_event *pe,
|
|
|
|
bool metric_no_group,
|
2020-07-19 18:13:09 +00:00
|
|
|
int runtime,
|
2020-07-19 18:13:19 +00:00
|
|
|
struct metric **mp,
|
2020-07-19 18:13:16 +00:00
|
|
|
struct expr_id *parent,
|
|
|
|
struct expr_ids *ids)
|
2020-04-01 20:33:36 +00:00
|
|
|
{
|
2020-07-19 18:13:09 +00:00
|
|
|
struct metric_ref_node *ref;
|
2020-07-19 18:13:19 +00:00
|
|
|
struct metric *m;
|
2020-04-01 20:33:36 +00:00
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
if (*mp == NULL) {
|
2020-07-19 18:13:09 +00:00
|
|
|
/*
|
|
|
|
* We got in here for the parent group,
|
|
|
|
* allocate it and put it on the list.
|
|
|
|
*/
|
2020-07-19 18:13:19 +00:00
|
|
|
m = zalloc(sizeof(*m));
|
|
|
|
if (!m)
|
2020-07-19 18:13:09 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
expr__ctx_init(&m->pctx);
|
|
|
|
m->metric_name = pe->metric_name;
|
|
|
|
m->metric_expr = pe->metric_expr;
|
|
|
|
m->metric_unit = pe->unit;
|
|
|
|
m->runtime = runtime;
|
|
|
|
m->has_constraint = metric_no_group || metricgroup__has_constraint(pe);
|
|
|
|
INIT_LIST_HEAD(&m->metric_refs);
|
|
|
|
m->metric_refs_cnt = 0;
|
2020-07-19 18:13:16 +00:00
|
|
|
|
|
|
|
parent = expr_ids__alloc(ids);
|
|
|
|
if (!parent) {
|
2020-07-19 18:13:19 +00:00
|
|
|
free(m);
|
2020-07-19 18:13:16 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent->id = strdup(pe->metric_name);
|
|
|
|
if (!parent->id) {
|
2020-07-19 18:13:19 +00:00
|
|
|
free(m);
|
2020-07-19 18:13:16 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2020-09-15 03:18:17 +00:00
|
|
|
*mp = m;
|
2020-07-19 18:13:09 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We got here for the referenced metric, via the
|
|
|
|
* recursive metricgroup__add_metric call, add
|
|
|
|
* it to the parent group.
|
|
|
|
*/
|
2020-07-19 18:13:19 +00:00
|
|
|
m = *mp;
|
2020-07-19 18:13:09 +00:00
|
|
|
|
|
|
|
ref = malloc(sizeof(*ref));
|
|
|
|
if (!ref)
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
ref->metric_name = pe->metric_name;
|
|
|
|
ref->metric_expr = pe->metric_expr;
|
2020-04-01 20:33:36 +00:00
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
list_add(&ref->list, &m->metric_refs);
|
|
|
|
m->metric_refs_cnt++;
|
2020-07-19 18:13:09 +00:00
|
|
|
}
|
2020-05-15 22:17:32 +00:00
|
|
|
|
2020-07-19 18:13:16 +00:00
|
|
|
/* Force all found IDs in metric to have us as parent ID. */
|
|
|
|
WARN_ON_ONCE(!parent);
|
2020-07-19 18:13:19 +00:00
|
|
|
m->pctx.parent = parent;
|
2020-07-19 18:13:16 +00:00
|
|
|
|
2020-07-19 18:13:09 +00:00
|
|
|
/*
|
|
|
|
* For both the parent and referenced metrics, we parse
|
|
|
|
* all the metric's IDs and add it to the parent context.
|
|
|
|
*/
|
2020-07-19 18:13:19 +00:00
|
|
|
if (expr__find_other(pe->metric_expr, NULL, &m->pctx, runtime) < 0) {
|
2020-09-15 03:18:17 +00:00
|
|
|
if (m->metric_refs_cnt == 0) {
|
|
|
|
expr__ctx_clear(&m->pctx);
|
|
|
|
free(m);
|
|
|
|
*mp = NULL;
|
|
|
|
}
|
2020-05-15 22:17:32 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-07-19 18:13:09 +00:00
|
|
|
/*
|
|
|
|
* We add new group only in the 'parent' call,
|
|
|
|
* so bail out for referenced metric case.
|
|
|
|
*/
|
2020-07-19 18:13:19 +00:00
|
|
|
if (m->metric_refs_cnt)
|
2020-07-19 18:13:09 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-07-19 18:13:20 +00:00
|
|
|
if (list_empty(metric_list))
|
|
|
|
list_add(&m->nd, metric_list);
|
2020-05-20 18:20:08 +00:00
|
|
|
else {
|
|
|
|
struct list_head *pos;
|
|
|
|
|
|
|
|
/* Place the largest groups at the front. */
|
2020-07-19 18:13:20 +00:00
|
|
|
list_for_each_prev(pos, metric_list) {
|
2020-07-19 18:13:19 +00:00
|
|
|
struct metric *old = list_entry(pos, struct metric, nd);
|
2020-05-20 18:20:08 +00:00
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
if (hashmap__size(&m->pctx.ids) <=
|
2020-05-20 18:20:08 +00:00
|
|
|
hashmap__size(&old->pctx.ids))
|
|
|
|
break;
|
|
|
|
}
|
2020-07-19 18:13:19 +00:00
|
|
|
list_add(&m->nd, pos);
|
2020-05-20 18:20:08 +00:00
|
|
|
}
|
2020-04-01 20:33:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-04 11:10:15 +00: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-19 18:13:06 +00: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-04-07 10:32:45 +00:00
|
|
|
struct pmu_event *metricgroup__find_metric(const char *metric,
|
|
|
|
struct pmu_events_map *map)
|
2020-07-19 18:13:09 +00:00
|
|
|
{
|
|
|
|
struct pmu_event *pe;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
map_for_each_event(pe, i, map) {
|
|
|
|
if (match_metric(pe->metric_name, metric))
|
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
static int recursion_check(struct metric *m, const char *id, struct expr_id **parent,
|
2020-07-19 18:13:16 +00:00
|
|
|
struct expr_ids *ids)
|
|
|
|
{
|
|
|
|
struct expr_id_data *data;
|
|
|
|
struct expr_id *p;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We get the parent referenced by 'id' argument and
|
|
|
|
* traverse through all the parent object IDs to check
|
|
|
|
* if we already processed 'id', if we did, it's recursion
|
|
|
|
* and we fail.
|
|
|
|
*/
|
2020-07-19 18:13:19 +00:00
|
|
|
ret = expr__get_id(&m->pctx, id, &data);
|
2020-07-19 18:13:16 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-08-26 15:30:55 +00:00
|
|
|
p = expr_id_data__parent(data);
|
2020-07-19 18:13:16 +00:00
|
|
|
|
|
|
|
while (p->parent) {
|
|
|
|
if (!strcmp(p->id, id)) {
|
|
|
|
pr_err("failed: recursion detected for %s\n", id);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
p = p->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are over the limit of static entris, the metric
|
|
|
|
* is too difficult/nested to process, fail as well.
|
|
|
|
*/
|
|
|
|
p = expr_ids__alloc(ids);
|
|
|
|
if (!p) {
|
|
|
|
pr_err("failed: too many nested metrics\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->id = strdup(id);
|
2020-08-26 15:30:55 +00:00
|
|
|
p->parent = expr_id_data__parent(data);
|
2020-07-19 18:13:16 +00:00
|
|
|
*parent = p;
|
|
|
|
|
|
|
|
return p->id ? 0 : -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2020-07-19 18:13:20 +00:00
|
|
|
static int add_metric(struct list_head *metric_list,
|
2020-07-19 18:13:09 +00:00
|
|
|
struct pmu_event *pe,
|
|
|
|
bool metric_no_group,
|
2020-07-19 18:13:19 +00:00
|
|
|
struct metric **mp,
|
2020-07-19 18:13:16 +00:00
|
|
|
struct expr_id *parent,
|
|
|
|
struct expr_ids *ids);
|
2020-07-19 18:13:09 +00:00
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
static int __resolve_metric(struct metric *m,
|
2020-07-19 18:13:09 +00:00
|
|
|
bool metric_no_group,
|
2020-07-19 18:13:20 +00:00
|
|
|
struct list_head *metric_list,
|
2020-07-19 18:13:16 +00:00
|
|
|
struct pmu_events_map *map,
|
|
|
|
struct expr_ids *ids)
|
2020-07-19 18:13:09 +00:00
|
|
|
{
|
|
|
|
struct hashmap_entry *cur;
|
|
|
|
size_t bkt;
|
|
|
|
bool all;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate all the parsed IDs and if there's metric,
|
|
|
|
* add it to the context.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
all = true;
|
2020-07-19 18:13:19 +00:00
|
|
|
hashmap__for_each_entry((&m->pctx.ids), cur, bkt) {
|
2020-07-19 18:13:16 +00:00
|
|
|
struct expr_id *parent;
|
2020-07-19 18:13:09 +00:00
|
|
|
struct pmu_event *pe;
|
|
|
|
|
2021-04-07 10:32:45 +00:00
|
|
|
pe = metricgroup__find_metric(cur->key, map);
|
2020-07-19 18:13:09 +00:00
|
|
|
if (!pe)
|
|
|
|
continue;
|
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
ret = recursion_check(m, cur->key, &parent, ids);
|
2020-07-19 18:13:16 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2020-07-19 18:13:09 +00:00
|
|
|
all = false;
|
|
|
|
/* The metric key itself needs to go out.. */
|
2020-07-19 18:13:19 +00:00
|
|
|
expr__del_id(&m->pctx, cur->key);
|
2020-07-19 18:13:09 +00:00
|
|
|
|
|
|
|
/* ... and it gets resolved to the parent context. */
|
2020-07-19 18:13:20 +00:00
|
|
|
ret = add_metric(metric_list, pe, metric_no_group, &m, parent, ids);
|
2020-07-19 18:13:09 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We added new metric to hashmap, so we need
|
|
|
|
* to break the iteration and start over.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!all);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int resolve_metric(bool metric_no_group,
|
|
|
|
struct list_head *metric_list,
|
2020-07-19 18:13:16 +00:00
|
|
|
struct pmu_events_map *map,
|
|
|
|
struct expr_ids *ids)
|
2020-07-19 18:13:09 +00:00
|
|
|
{
|
2020-07-19 18:13:19 +00:00
|
|
|
struct metric *m;
|
2020-07-19 18:13:09 +00:00
|
|
|
int err;
|
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
list_for_each_entry(m, metric_list, nd) {
|
|
|
|
err = __resolve_metric(m, metric_no_group, metric_list, map, ids);
|
2020-07-19 18:13:09 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-19 18:13:20 +00:00
|
|
|
static int add_metric(struct list_head *metric_list,
|
2020-07-19 18:13:07 +00:00
|
|
|
struct pmu_event *pe,
|
2020-07-19 18:13:09 +00:00
|
|
|
bool metric_no_group,
|
2020-07-19 18:13:19 +00:00
|
|
|
struct metric **m,
|
2020-07-19 18:13:16 +00:00
|
|
|
struct expr_id *parent,
|
|
|
|
struct expr_ids *ids)
|
2020-07-19 18:13:07 +00:00
|
|
|
{
|
2020-07-19 18:13:19 +00:00
|
|
|
struct metric *orig = *m;
|
2020-07-19 18:13:07 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name);
|
|
|
|
|
|
|
|
if (!strstr(pe->metric_expr, "?")) {
|
2020-07-19 18:13:20 +00:00
|
|
|
ret = __add_metric(metric_list, pe, metric_no_group, 1, m, parent, ids);
|
2020-07-19 18:13:07 +00:00
|
|
|
} else {
|
|
|
|
int j, count;
|
|
|
|
|
2020-09-07 06:41:32 +00:00
|
|
|
count = arch_get_runtimeparam(pe);
|
2020-07-19 18:13:07 +00:00
|
|
|
|
|
|
|
/* This loop is added to create multiple
|
|
|
|
* events depend on count value and add
|
2020-07-19 18:13:20 +00:00
|
|
|
* those events to metric_list.
|
2020-07-19 18:13:07 +00:00
|
|
|
*/
|
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
for (j = 0; j < count && !ret; j++, *m = orig)
|
2020-07-19 18:13:20 +00:00
|
|
|
ret = __add_metric(metric_list, pe, metric_no_group, j, m, parent, ids);
|
2020-07-19 18:13:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-12-04 11:10:15 +00:00
|
|
|
static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct metricgroup_add_iter_data *d = data;
|
2021-01-19 10:04:15 +00:00
|
|
|
struct metric *m = NULL;
|
2020-12-04 11:10:15 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!match_pe_metric(pe, d->metric))
|
|
|
|
return 0;
|
|
|
|
|
2021-01-19 10:04:15 +00:00
|
|
|
ret = add_metric(d->metric_list, pe, d->metric_no_group, &m, NULL, d->ids);
|
2020-12-04 11:10:15 +00:00
|
|
|
if (ret)
|
2021-06-10 14:33:00 +00:00
|
|
|
goto out;
|
2020-12-04 11:10:15 +00:00
|
|
|
|
|
|
|
ret = resolve_metric(d->metric_no_group,
|
|
|
|
d->metric_list, NULL, d->ids);
|
|
|
|
if (ret)
|
2021-06-10 14:33:00 +00:00
|
|
|
goto out;
|
2020-12-04 11:10:15 +00:00
|
|
|
|
|
|
|
*(d->has_match) = true;
|
|
|
|
|
2021-06-10 14:33:00 +00:00
|
|
|
out:
|
|
|
|
*(d->ret) = ret;
|
|
|
|
return ret;
|
2020-12-04 11:10:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 18:20:10 +00:00
|
|
|
static int metricgroup__add_metric(const char *metric, bool metric_no_group,
|
|
|
|
struct strbuf *events,
|
2020-07-19 18:13:20 +00:00
|
|
|
struct list_head *metric_list,
|
2020-06-09 15:57:47 +00:00
|
|
|
struct pmu_events_map *map)
|
2017-08-31 19:40:31 +00:00
|
|
|
{
|
2020-07-19 18:13:16 +00:00
|
|
|
struct expr_ids ids = { .cnt = 0, };
|
2017-08-31 19:40:31 +00:00
|
|
|
struct pmu_event *pe;
|
2020-07-19 18:13:19 +00:00
|
|
|
struct metric *m;
|
2020-07-19 18:13:13 +00:00
|
|
|
LIST_HEAD(list);
|
2020-05-20 18:20:06 +00:00
|
|
|
int i, ret;
|
|
|
|
bool has_match = false;
|
2017-08-31 19:40:31 +00:00
|
|
|
|
2020-07-19 18:13:06 +00:00
|
|
|
map_for_each_metric(pe, i, map, metric) {
|
|
|
|
has_match = true;
|
2020-07-19 18:13:19 +00:00
|
|
|
m = NULL;
|
2020-07-19 18:13:09 +00:00
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
ret = add_metric(&list, pe, metric_no_group, &m, NULL, &ids);
|
2020-07-19 18:13:09 +00:00
|
|
|
if (ret)
|
2020-09-15 03:18:16 +00:00
|
|
|
goto out;
|
2020-07-19 18:13:06 +00:00
|
|
|
|
2020-07-19 18:13:09 +00:00
|
|
|
/*
|
|
|
|
* Process any possible referenced metrics
|
|
|
|
* included in the expression.
|
|
|
|
*/
|
|
|
|
ret = resolve_metric(metric_no_group,
|
2020-07-19 18:13:16 +00:00
|
|
|
&list, map, &ids);
|
2020-07-19 18:13:07 +00:00
|
|
|
if (ret)
|
2020-09-15 03:18:16 +00:00
|
|
|
goto out;
|
2017-08-31 19:40:31 +00:00
|
|
|
}
|
2020-07-19 18:13:06 +00:00
|
|
|
|
2020-12-04 11:10:15 +00:00
|
|
|
{
|
|
|
|
struct metricgroup_iter_data data = {
|
|
|
|
.fn = metricgroup__add_metric_sys_event_iter,
|
|
|
|
.data = (void *) &(struct metricgroup_add_iter_data) {
|
|
|
|
.metric_list = &list,
|
|
|
|
.metric = metric,
|
|
|
|
.metric_no_group = metric_no_group,
|
|
|
|
.ids = &ids,
|
|
|
|
.has_match = &has_match,
|
|
|
|
.ret = &ret,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
pmu_for_each_sys_event(metricgroup__sys_event_iter, &data);
|
|
|
|
}
|
2020-07-19 18:13:06 +00:00
|
|
|
/* End of pmu events. */
|
2020-09-15 03:18:16 +00:00
|
|
|
if (!has_match) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2020-07-19 18:13:06 +00:00
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
list_for_each_entry(m, &list, nd) {
|
2020-05-20 18:20:07 +00:00
|
|
|
if (events->len > 0)
|
|
|
|
strbuf_addf(events, ",");
|
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
if (m->has_constraint) {
|
2020-05-20 18:20:07 +00:00
|
|
|
metricgroup__add_metric_non_group(events,
|
2020-07-19 18:13:19 +00:00
|
|
|
&m->pctx);
|
2020-05-20 18:20:07 +00:00
|
|
|
} else {
|
|
|
|
metricgroup__add_metric_weak_group(events,
|
2020-07-19 18:13:19 +00:00
|
|
|
&m->pctx);
|
2020-05-20 18:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-19 18:13:13 +00:00
|
|
|
|
2020-09-15 03:18:16 +00:00
|
|
|
out:
|
|
|
|
/*
|
|
|
|
* add to metric_list so that they can be released
|
|
|
|
* even if it's failed
|
|
|
|
*/
|
2020-07-19 18:13:20 +00:00
|
|
|
list_splice(&list, metric_list);
|
2020-07-19 18:13:16 +00:00
|
|
|
expr_ids__exit(&ids);
|
2020-09-15 03:18:16 +00:00
|
|
|
return ret;
|
2017-08-31 19:40:31 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 18:20:10 +00:00
|
|
|
static int metricgroup__add_metric_list(const char *list, bool metric_no_group,
|
|
|
|
struct strbuf *events,
|
2020-07-19 18:13:20 +00:00
|
|
|
struct list_head *metric_list,
|
2020-06-09 15:57:47 +00:00
|
|
|
struct pmu_events_map *map)
|
2017-08-31 19:40:31 +00:00
|
|
|
{
|
|
|
|
char *llist, *nlist, *p;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
|
|
|
|
nlist = strdup(list);
|
|
|
|
if (!nlist)
|
|
|
|
return -ENOMEM;
|
|
|
|
llist = nlist;
|
2017-09-14 20:57:35 +00:00
|
|
|
|
|
|
|
strbuf_init(events, 100);
|
|
|
|
strbuf_addf(events, "%s", "");
|
|
|
|
|
2017-08-31 19:40:31 +00:00
|
|
|
while ((p = strsep(&llist, ",")) != NULL) {
|
2020-05-20 18:20:10 +00:00
|
|
|
ret = metricgroup__add_metric(p, metric_no_group, events,
|
2020-07-19 18:13:20 +00:00
|
|
|
metric_list, map);
|
2017-08-31 19:40:31 +00:00
|
|
|
if (ret == -EINVAL) {
|
|
|
|
fprintf(stderr, "Cannot find metric or group `%s'\n",
|
|
|
|
p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(nlist);
|
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-24 21:59:23 +00:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
metricgroup___watchdog_constraint_hint(NULL, true);
|
|
|
|
|
2017-08-31 19:40:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
static void metric__free_refs(struct metric *metric)
|
2020-07-19 18:13:09 +00:00
|
|
|
{
|
|
|
|
struct metric_ref_node *ref, *tmp;
|
|
|
|
|
2020-07-19 18:13:19 +00:00
|
|
|
list_for_each_entry_safe(ref, tmp, &metric->metric_refs, list) {
|
2020-07-19 18:13:09 +00:00
|
|
|
list_del(&ref->list);
|
|
|
|
free(ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-19 18:13:20 +00:00
|
|
|
static void metricgroup__free_metrics(struct list_head *metric_list)
|
2017-08-31 19:40:31 +00:00
|
|
|
{
|
2020-07-19 18:13:19 +00:00
|
|
|
struct metric *m, *tmp;
|
2017-08-31 19:40:31 +00:00
|
|
|
|
2020-07-19 18:13:20 +00:00
|
|
|
list_for_each_entry_safe (m, tmp, metric_list, nd) {
|
2020-07-19 18:13:19 +00:00
|
|
|
metric__free_refs(m);
|
|
|
|
expr__ctx_clear(&m->pctx);
|
|
|
|
list_del_init(&m->nd);
|
|
|
|
free(m);
|
2017-08-31 19:40:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-02 21:47:33 +00:00
|
|
|
static int parse_groups(struct evlist *perf_evlist, const char *str,
|
|
|
|
bool metric_no_group,
|
|
|
|
bool metric_no_merge,
|
2020-06-09 15:50:42 +00:00
|
|
|
struct perf_pmu *fake_pmu,
|
2020-06-09 15:57:47 +00:00
|
|
|
struct rblist *metric_events,
|
|
|
|
struct pmu_events_map *map)
|
2017-08-31 19:40:31 +00:00
|
|
|
{
|
|
|
|
struct parse_events_error parse_error;
|
|
|
|
struct strbuf extra_events;
|
2020-07-19 18:13:20 +00:00
|
|
|
LIST_HEAD(metric_list);
|
2017-08-31 19:40:31 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (metric_events->nr_entries == 0)
|
|
|
|
metricgroup__rblist_init(metric_events);
|
2020-05-20 18:20:10 +00:00
|
|
|
ret = metricgroup__add_metric_list(str, metric_no_group,
|
2020-07-19 18:13:20 +00:00
|
|
|
&extra_events, &metric_list, map);
|
2017-08-31 19:40:31 +00:00
|
|
|
if (ret)
|
2020-09-15 03:18:09 +00:00
|
|
|
goto out;
|
2017-08-31 19:40:31 +00:00
|
|
|
pr_debug("adding %s\n", extra_events.buf);
|
perf parse: Report initial event parsing error
Record the first event parsing error and report. Implementing feedback
from Jiri Olsa:
https://lkml.org/lkml/2019/10/28/680
An example error is:
$ tools/perf/perf stat -e c/c/
WARNING: multiple event parsing errors
event syntax error: 'c/c/'
\___ unknown term
valid terms: event,filter_rem,filter_opc0,edge,filter_isoc,filter_tid,filter_loc,filter_nc,inv,umask,filter_opc1,tid_en,thresh,filter_all_op,filter_not_nm,filter_state,filter_nm,config,config1,config2,name,period,percore
Initial error:
event syntax error: 'c/c/'
\___ Cannot find PMU `c'. Missing kernel support?
Run 'perf list' for a list of valid events
Usage: perf stat [<options>] [<command>]
-e, --event <event> event selector. use 'perf list' to list available events
Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Allison Randal <allison@lohutok.net>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Anju T Sudhakar <anju@linux.vnet.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.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>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Link: http://lore.kernel.org/lkml/20191116074652.9960-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-11-16 07:46:52 +00:00
|
|
|
bzero(&parse_error, sizeof(parse_error));
|
2020-06-09 15:50:42 +00:00
|
|
|
ret = __parse_events(perf_evlist, extra_events.buf, &parse_error, fake_pmu);
|
2017-08-31 19:40:31 +00:00
|
|
|
if (ret) {
|
2017-09-13 21:50:06 +00:00
|
|
|
parse_events_print_error(&parse_error, extra_events.buf);
|
2017-08-31 19:40:31 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2020-07-19 18:13:20 +00:00
|
|
|
ret = metricgroup__setup_events(&metric_list, metric_no_merge,
|
2020-05-20 18:20:10 +00:00
|
|
|
perf_evlist, metric_events);
|
2017-08-31 19:40:31 +00:00
|
|
|
out:
|
2020-07-19 18:13:20 +00:00
|
|
|
metricgroup__free_metrics(&metric_list);
|
2020-09-15 03:18:09 +00:00
|
|
|
strbuf_release(&extra_events);
|
2017-08-31 19:40:31 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2018-06-26 07:17:01 +00:00
|
|
|
|
2020-06-02 21:47:33 +00: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-04-07 10:32:47 +00:00
|
|
|
struct pmu_events_map *map = pmu_events_map__find();
|
2020-06-02 21:47:33 +00:00
|
|
|
|
|
|
|
return parse_groups(perf_evlist, str, metric_no_group,
|
2020-06-09 15:57:47 +00:00
|
|
|
metric_no_merge, NULL, metric_events, map);
|
2020-06-02 21:47:33 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 21:47:36 +00:00
|
|
|
int metricgroup__parse_groups_test(struct evlist *evlist,
|
|
|
|
struct pmu_events_map *map,
|
|
|
|
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 07:17:01 +00:00
|
|
|
bool metricgroup__has_metric(const char *metric)
|
|
|
|
{
|
2021-04-07 10:32:47 +00:00
|
|
|
struct pmu_events_map *map = pmu_events_map__find();
|
2018-06-26 07:17:01 +00:00
|
|
|
struct pmu_event *pe;
|
|
|
|
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 12:44:53 +00: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);
|
|
|
|
|
|
|
|
evsel = evlist__find_evsel(evlist, old_me->evsel->idx);
|
|
|
|
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",
|
|
|
|
cgrp ? cgrp->name : "root", evsel->name, evsel->idx);
|
|
|
|
|
|
|
|
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;
|
|
|
|
new_expr->metric_name = old_expr->metric_name;
|
|
|
|
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];
|
|
|
|
evsel = evlist__find_evsel(evlist, evsel->idx);
|
|
|
|
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;
|
|
|
|
}
|