perf record: Support "--cputype" option for hybrid events
PATCH 1/1 perf record: Support "--cputype" option for hybrid events
From: Zhengjun Xing <[email protected]>
perf stat already has the "--cputype" option to enable events only on the specified PMU for the hybrid platform, this commit extends the "--cputype" support to perf record.
Without "--cputype", it reports events for both cpu_core and cpu_atom.
# ./perf record -e cycles -a sleep 1 | ./perf report
# To display the perf.data header info, please use --header/--header-only options. #
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB (null) ]
#
# Total Lost Samples: 0
#
# Samples: 335 of event 'cpu_core/cycles/'
# Event count (approx.): 35855267
#
# Overhead Command Shared Object Symbol
# ........ ............... ................. .........................................
#
10.31% swapper [kernel.kallsyms] [k] poll_idle
9.42% swapper [kernel.kallsyms] [k] menu_select
... ... ... ... ... # Samples: 61 of event 'cpu_atom/cycles/'
# Event count (approx.): 16453825
#
# Overhead Command Shared Object Symbol
# ........ ............. ................. ......................................
#
26.36% snapd [unknown] [.] 0x0000563cc6d03841
7.43% migration/13 [kernel.kallsyms] [k] update_sd_lb_stats.constprop.0
... ... ... ... ...With "--cputype", it reports events only for the specified PMU.
# ./perf record --cputype core -e cycles -a sleep 1 | ./perf report
# To display the perf.data header info, please use --header/--header-only options. #
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB (null) ]
#
# Total Lost Samples: 0
#
# Samples: 221 of event 'cpu_core/cycles/'
# Event count (approx.): 27121818
#
# Overhead Command Shared Object Symbol
# ........ ............... ................. .........................................
#
11.24% swapper [kernel.kallsyms] [k] e1000_irq_enable
7.77% swapper [kernel.kallsyms] [k] mwait_idle_with_hints.constprop.0
... ... ... ... ...--- tools/perf/Documentation/perf-record.txt | 4 ++++ tools/perf/builtin-record.c | 3 +++ tools/perf/builtin-stat.c | 20 -------------------- tools/perf/util/pmu-hybrid.c | 19 +++++++++++++++++++ tools/perf/util/pmu-hybrid.h | 2 ++ 5 files changed, 28 insertions(+), 20 deletions(-)
tools/perf/Documentation/perf-record.txt +4 -0
@@ -402,6 +402,10 @@ Enable weightened sampling. An additional weight is recorded per sample and can displayed with the weight and local_weight sort keys. This currently works for TSX abort events and some memory events in precise mode on modern Intel CPUs. +--cputype:: +Only enable events on applying cpu with this type for hybrid platform(e.g. core or atom). +For non-hybrid events, it should be no effect. + --namespaces:: Record events of type PERF_RECORD_NAMESPACES. This enables 'cgroup_id' sort key.
tools/perf/builtin-record.c +3 -0
@@ -3183,6 +3183,9 @@ static struct option __record_options[] = {OPT_INCR ('v' ,"verbose" , &verbose,"be more verbose (show counter open errors, etc)" ),OPT_BOOLEAN ('q' ,"quiet" , &quiet,"don't print any message" ), +OPT_CALLBACK (0 ,"cputype" , &record.evlist,"hybrid cpu type" , +"Only enable events on applying cpu with this type for hybrid platform (e.g. core or atom)" , + parse_hybrid_type),OPT_BOOLEAN ('s' ,"stat" , &record.opts.inherit_stat,"per thread counts" ), OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample addresses"),
tools/perf/builtin-stat.c +0 -20
@@ -1184,26 +1184,6 @@ static int parse_stat_cgroups(const struct option *opt,return parse_cgroups (opt, str, unset); } -static int parse_hybrid_type (const struct option *opt, -const char *str, -int unset__maybe_unused ) -{ -struct evlist *evlist = *(struct evlist **)opt->value; - -if (!list_empty (&evlist->core.entries)) { -fprintf (stderr,"Must define cputype before events/metrics\n" ); -return -1 ; - } - - evlist->hybrid_pmu_name =perf_pmu__hybrid_type_to_pmu (str); -if (!evlist->hybrid_pmu_name) { -fprintf (stderr,"--cputype %s is not supported!\n" , str); -return -1 ; - } - -return 0 ; -} -static struct option stat_options[] = {OPT_BOOLEAN ('T' ,"transaction" , &transaction_run,"hardware transaction statistics" ),
tools/perf/util/pmu-hybrid.c +19 -0
@@ -13,6 +13,7 @@#include <stdarg.h> #include <locale.h> #include <api/fs/fs.h> +#include "util/evlist.h" #include "fncache.h" #include "pmu-hybrid.h"
@@ -87,3 +88,21 @@ char *perf_pmu__hybrid_type_to_pmu(const char *type)free (pmu_name);return NULL ; } + +int parse_hybrid_type (const struct option *opt,const char *str,int unset__maybe_unused ) +{ +struct evlist *evlist = *(struct evlist **)opt->value; + +if (!list_empty (&evlist->core.entries)) { +fprintf (stderr,"Must define cputype before events/metrics\n" ); +return -1 ; + } + + evlist->hybrid_pmu_name =perf_pmu__hybrid_type_to_pmu (str); +if (!evlist->hybrid_pmu_name) { +fprintf (stderr,"--cputype %s is not supported!\n" , str); +return -1 ; + } + +return 0 ; +}
tools/perf/util/pmu-hybrid.h +2 -0
@@ -5,6 +5,7 @@#include <linux/perf_event.h> #include <linux/compiler.h> #include <linux/list.h> +#include <subcmd/parse-options.h> #include <stdbool.h> #include "pmu.h"
@@ -18,6 +19,7 @@ bool perf_pmu__hybrid_mounted(const char *name);struct perf_pmu *perf_pmu__find_hybrid_pmu (const char *name);bool perf_pmu__is_hybrid (const char *name);char *perf_pmu__hybrid_type_to_pmu (const char *type); +int parse_hybrid_type (const struct option *opt,const char *str,int unset__maybe_unused );static inline int perf_pmu__hybrid_pmu_num (void ) {
Signature · 1 line
2.25.1
Ian Rogers
reviewerQuoted 52 lines · On Wed, Jun 15, 2022 at 8:07 AM <[email protected]> wrote:
From: Zhengjun Xing <[email protected]>
perf stat already has the "--cputype" option to enable events only on the specified PMU for the hybrid platform, this commit extends the "--cputype" support to perf record.
Without "--cputype", it reports events for both
cpu_coreandcpu_atom.# ./perf record -e cycles -a sleep 1 | ./perf report# To display the perf.data header info, please use --header/--header-only options. #
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB (null) ]
#
# Total Lost Samples: 0
#
# Samples: 335 of event 'cpu_core/cycles/'
# Event count (approx.): 35855267
## Overhead Command Shared Object Symbol # ........ ............... ................. ......................................... # 10.31% swapper [kernel.kallsyms] [k] poll_idle 9.42% swapper [kernel.kallsyms] [k] menu_select ... ... ... ... ...# Samples: 61 of event 'cpu_atom/cycles/'
# Event count (approx.): 16453825
## Overhead Command Shared Object Symbol # ........ ............. ................. ...................................... # 26.36% snapd [unknown] [.] 0x0000563cc6d03841 7.43% migration/13 [kernel.kallsyms] [k] update_sd_lb_stats.constprop.0 ... ... ... ... ...With "--cputype", it reports events only for the specified PMU.
# ./perf record --cputype core -e cycles -a sleep 1 | ./perf report# To display the perf.data header info, please use --header/--header-only options. #
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB (null) ]
#
# Total Lost Samples: 0
#
# Samples: 221 of event 'cpu_core/cycles/'
# Event count (approx.): 27121818
#
Quoted 6 lines
# Overhead Command Shared Object Symbol
# ........ ............... ................. .........................................
#
11.24% swapper [kernel.kallsyms] [k] e1000_irq_enable
7.77% swapper [kernel.kallsyms] [k] mwait_idle_with_hints.constprop.0
... ... ... ... ...This is already possible by having the PMU name as part of the event, cpu_atom/cycles/ or cpu_core/cycles/. I don't know why we're adding "hybrid" all over the code base, I wish it would stop. You are asking for an option here for an implied PMU for events that don't specify a PMU. The option should be called --pmutype and consider all PMUs. We should remove the "hybrid" PMU list and make all of the "hybrid" code generic.
Thanks,
Ian
Quoted 127 lines
Signed-off-by Zhengjun Xing <[email protected]>Reviewed-by Kan Liang <[email protected]>--- tools/perf/Documentation/perf-record.txt | 4 ++++ tools/perf/builtin-record.c | 3 +++ tools/perf/builtin-stat.c | 20 -------------------- tools/perf/util/pmu-hybrid.c | 19 +++++++++++++++++++ tools/perf/util/pmu-hybrid.h | 2 ++ 5 files changed, 28 insertions(+), 20 deletions(-)tools/perf/Documentation/perf-record.txt +4
-0@@ -402,6 +402,10 @@ Enable weightened sampling. An additional weight is recorded per sample and can displayed with the weight and local_weight sort keys. This currently works for TSX abort events and some memory events in precise mode on modern Intel CPUs. +--cputype:: +Only enable events on applying cpu with this type for hybrid platform(e.g. core or atom). +For non-hybrid events, it should be no effect. + --namespaces:: Record events of type PERF_RECORD_NAMESPACES. This enables 'cgroup_id' sort key.tools/perf/builtin-record.c +3
-0@@ -3183,6 +3183,9 @@ static struct option __record_options[] = {OPT_INCR ('v' ,"verbose" , &verbose,"be more verbose (show counter open errors, etc)" ),OPT_BOOLEAN ('q' ,"quiet" , &quiet,"don't print any message" ), +OPT_CALLBACK (0 ,"cputype" , &record.evlist,"hybrid cpu type" , +"Only enable events on applying cpu with this type for hybrid platform (e.g. core or atom)" , + parse_hybrid_type),OPT_BOOLEAN ('s' ,"stat" , &record.opts.inherit_stat,"per thread counts" ), OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample addresses"),tools/perf/builtin-stat.c +0
-20@@ -1184,26 +1184,6 @@ static int parse_stat_cgroups(const struct option *opt,return parse_cgroups (opt, str, unset); } -static int parse_hybrid_type (const struct option *opt, -const char *str, -int unset__maybe_unused ) -{ -struct evlist *evlist = *(struct evlist **)opt->value; - -if (!list_empty (&evlist->core.entries)) { -fprintf (stderr,"Must define cputype before events/metrics\n" ); -return -1 ; - } - - evlist->hybrid_pmu_name =perf_pmu__hybrid_type_to_pmu (str); -if (!evlist->hybrid_pmu_name) { -fprintf (stderr,"--cputype %s is not supported!\n" , str); -return -1 ; - } - -return 0 ; -} -static struct option stat_options[] = {OPT_BOOLEAN ('T' ,"transaction" , &transaction_run,"hardware transaction statistics" ),tools/perf/util/pmu-hybrid.c +19
-0@@ -13,6 +13,7 @@#include <stdarg.h> #include <locale.h> #include <api/fs/fs.h> +#include "util/evlist.h" #include "fncache.h" #include "pmu-hybrid.h" @@ -87,3 +88,21 @@ char *perf_pmu__hybrid_type_to_pmu(const char *type)free (pmu_name);return NULL ; } + +int parse_hybrid_type (const struct option *opt,const char *str,int unset__maybe_unused ) +{ +struct evlist *evlist = *(struct evlist **)opt->value; + +if (!list_empty (&evlist->core.entries)) { +fprintf (stderr,"Must define cputype before events/metrics\n" ); +return -1 ; + } + + evlist->hybrid_pmu_name =perf_pmu__hybrid_type_to_pmu (str); +if (!evlist->hybrid_pmu_name) { +fprintf (stderr,"--cputype %s is not supported!\n" , str); +return -1 ; + } + +return 0 ; +}tools/perf/util/pmu-hybrid.h +2
-1@@ -5,6 +5,7 @@#include <linux/perf_event.h> #include <linux/compiler.h> #include <linux/list.h> +#include <subcmd/parse-options.h> #include <stdbool.h> #include "pmu.h" @@ -18,6 +19,7 @@ bool perf_pmu__hybrid_mounted(const char *name);struct perf_pmu *perf_pmu__find_hybrid_pmu (const char *name);bool perf_pmu__is_hybrid (const char *name);char *perf_pmu__hybrid_type_to_pmu (const char *type); +int parse_hybrid_type (const struct option *opt,const char *str,int unset__maybe_unused );static inline int perf_pmu__hybrid_pmu_num (void ) { --2.25.1
Hi Ian,
Quoted 60 lines · Ian Rogers
Quoted 52 lines · On Wed, Jun 15, 2022 at 8:07 AM <[email protected]> wrote:
From: Zhengjun Xing <[email protected]>
perf stat already has the "--cputype" option to enable events only on the specified PMU for the hybrid platform, this commit extends the "--cputype" support to perf record.
Without "--cputype", it reports events for both
cpu_coreandcpu_atom.# ./perf record -e cycles -a sleep 1 | ./perf report# To display the perf.data header info, please use --header/--header-only options. #
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB (null) ]
#
# Total Lost Samples: 0
#
# Samples: 335 of event 'cpu_core/cycles/'
# Event count (approx.): 35855267
## Overhead Command Shared Object Symbol # ........ ............... ................. ......................................... # 10.31% swapper [kernel.kallsyms] [k] poll_idle 9.42% swapper [kernel.kallsyms] [k] menu_select ... ... ... ... ...# Samples: 61 of event 'cpu_atom/cycles/'
# Event count (approx.): 16453825
## Overhead Command Shared Object Symbol # ........ ............. ................. ...................................... # 26.36% snapd [unknown] [.] 0x0000563cc6d03841 7.43% migration/13 [kernel.kallsyms] [k] update_sd_lb_stats.constprop.0 ... ... ... ... ...With "--cputype", it reports events only for the specified PMU.
# ./perf record --cputype core -e cycles -a sleep 1 | ./perf report# To display the perf.data header info, please use --header/--header-only options. #
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB (null) ]
#
# Total Lost Samples: 0
#
# Samples: 221 of event 'cpu_core/cycles/'
# Event count (approx.): 27121818
#Quoted 6 lines
# Overhead Command Shared Object Symbol # ........ ............... ................. ......................................... # 11.24% swapper [kernel.kallsyms] [k] e1000_irq_enable 7.77% swapper [kernel.kallsyms] [k] mwait_idle_with_hints.constprop.0 ... ... ... ... ...
Quoted 8 lines
This is already possible by having the PMU name as part of the event, cpu_atom/cycles/ or cpu_core/cycles/. I don't know why we're adding "hybrid" all over the code base, I wish it would stop. You are asking for an option here for an implied PMU for events that don't specify a PMU. The option should be called --pmutype and consider all PMUs. We should remove the "hybrid" PMU list and make all of the "hybrid" code generic.
I can change the option name from "cputype" to "pmutype". We have planned to clean up the hybrid code, and try to reduce the code with "if perf_pmu__has_hybrid()", this will be done step by step, from this patch, we have begun to do some clean-up, move the hybrid API from the common file to the hybrid-specific files. For the clean-up, Do you have any ideas? Thanks.
Quoted 130 lines
Thanks,
IanQuoted 127 lines
Signed-off-by Zhengjun Xing <[email protected]>Reviewed-by Kan Liang <[email protected]>--- tools/perf/Documentation/perf-record.txt | 4 ++++ tools/perf/builtin-record.c | 3 +++ tools/perf/builtin-stat.c | 20 -------------------- tools/perf/util/pmu-hybrid.c | 19 +++++++++++++++++++ tools/perf/util/pmu-hybrid.h | 2 ++ 5 files changed, 28 insertions(+), 20 deletions(-)tools/perf/Documentation/perf-record.txt +4
-0@@ -402,6 +402,10 @@ Enable weightened sampling. An additional weight is recorded per sample and can displayed with the weight and local_weight sort keys. This currently works for TSX abort events and some memory events in precise mode on modern Intel CPUs. +--cputype:: +Only enable events on applying cpu with this type for hybrid platform(e.g. core or atom). +For non-hybrid events, it should be no effect. + --namespaces:: Record events of type PERF_RECORD_NAMESPACES. This enables 'cgroup_id' sort key.tools/perf/builtin-record.c +3
-0@@ -3183,6 +3183,9 @@ static struct option __record_options[] = {OPT_INCR ('v' ,"verbose" , &verbose,"be more verbose (show counter open errors, etc)" ),OPT_BOOLEAN ('q' ,"quiet" , &quiet,"don't print any message" ), +OPT_CALLBACK (0 ,"cputype" , &record.evlist,"hybrid cpu type" , +"Only enable events on applying cpu with this type for hybrid platform (e.g. core or atom)" , + parse_hybrid_type),OPT_BOOLEAN ('s' ,"stat" , &record.opts.inherit_stat,"per thread counts" ), OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample addresses"),tools/perf/builtin-stat.c +0
-20@@ -1184,26 +1184,6 @@ static int parse_stat_cgroups(const struct option *opt,return parse_cgroups (opt, str, unset); } -static int parse_hybrid_type (const struct option *opt, -const char *str, -int unset__maybe_unused ) -{ -struct evlist *evlist = *(struct evlist **)opt->value; - -if (!list_empty (&evlist->core.entries)) { -fprintf (stderr,"Must define cputype before events/metrics\n" ); -return -1 ; - } - - evlist->hybrid_pmu_name =perf_pmu__hybrid_type_to_pmu (str); -if (!evlist->hybrid_pmu_name) { -fprintf (stderr,"--cputype %s is not supported!\n" , str); -return -1 ; - } - -return 0 ; -} -static struct option stat_options[] = {OPT_BOOLEAN ('T' ,"transaction" , &transaction_run,"hardware transaction statistics" ),tools/perf/util/pmu-hybrid.c +19
-0@@ -13,6 +13,7 @@#include <stdarg.h> #include <locale.h> #include <api/fs/fs.h> +#include "util/evlist.h" #include "fncache.h" #include "pmu-hybrid.h" @@ -87,3 +88,21 @@ char *perf_pmu__hybrid_type_to_pmu(const char *type)free (pmu_name);return NULL ; } + +int parse_hybrid_type (const struct option *opt,const char *str,int unset__maybe_unused ) +{ +struct evlist *evlist = *(struct evlist **)opt->value; + +if (!list_empty (&evlist->core.entries)) { +fprintf (stderr,"Must define cputype before events/metrics\n" ); +return -1 ; + } + + evlist->hybrid_pmu_name =perf_pmu__hybrid_type_to_pmu (str); +if (!evlist->hybrid_pmu_name) { +fprintf (stderr,"--cputype %s is not supported!\n" , str); +return -1 ; + } + +return 0 ; +}tools/perf/util/pmu-hybrid.h +2
-1@@ -5,6 +5,7 @@#include <linux/perf_event.h> #include <linux/compiler.h> #include <linux/list.h> +#include <subcmd/parse-options.h> #include <stdbool.h> #include "pmu.h" @@ -18,6 +19,7 @@ bool perf_pmu__hybrid_mounted(const char *name);struct perf_pmu *perf_pmu__find_hybrid_pmu (const char *name);bool perf_pmu__is_hybrid (const char *name);char *perf_pmu__hybrid_type_to_pmu (const char *type); +int parse_hybrid_type (const struct option *opt,const char *str,int unset__maybe_unused );static inline int perf_pmu__hybrid_pmu_num (void ) { --2.25.1
Signature · 1 line
Zhengjun Xing
Quoted 70 lines · Xing Zhengjun
Hi Ian,
Quoted 67 lines · Ian Rogers
Quoted 52 lines · On Wed, Jun 15, 2022 at 8:07 AM <[email protected]> wrote:
From: Zhengjun Xing <[email protected]>
perf stat already has the "--cputype" option to enable events only on the specified PMU for the hybrid platform, this commit extends the "--cputype" support to perf record.
Without "--cputype", it reports events for both
cpu_coreandcpu_atom.# ./perf record -e cycles -a sleep 1 | ./perf report# To display the perf.data header info, please use
--header/--header-only options.
#
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB (null) ]
#
# Total Lost Samples: 0
#
# Samples: 335 of event 'cpu_core/cycles/'
# Event count (approx.): 35855267
#
# Overhead Command Shared Object Symbol
# ........ ............... ................. ......................................... #
10.31% swapper [kernel.kallsyms] [k]poll_idle
9.42% swapper [kernel.kallsyms] [k]menu_select
... ... ... ... ...# Samples: 61 of event 'cpu_atom/cycles/'
# Event count (approx.): 16453825
#
# Overhead Command Shared Object Symbol
# ........ ............. ................. ...................................... #
26.36% snapd [unknown] [.]0x0000563cc6d038417.43% migration/13 [kernel.kallsyms] [k] update_sd_lb_stats.constprop.0 ... ... ... ... ...With "--cputype", it reports events only for the specified PMU.
# ./perf record --cputype core -e cycles -a sleep 1 | ./perf report# To display the perf.data header info, please use --header/--header-only options.
#
[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB (null) ] #
# Total Lost Samples: 0
#
# Samples: 221 of event 'cpu_core/cycles/'Quoted 8 lines
# Event count (approx.): 27121818
#
# Overhead Command Shared Object Symbol
# ........ ............... ................. ......................................... #
11.24% swapper [kernel.kallsyms] [k]e1000_irq_enable
7.77% swapper [kernel.kallsyms] [k] mwait_idle_with_hints.constprop.0 ... ... ... ... ...This is already possible by having the PMU name as part of the event, cpu_atom/cycles/ or cpu_core/cycles/. I don't know why we're adding "hybrid" all over the code base, I wish it would stop. You are asking for an option here for an implied PMU for events that don't specify a PMU. The option should be called --pmutype and consider all PMUs.
The --pmutype should be redundant because other PMUs have to specify the PMU name with the event. Only the CPU type of PMUs have events which doesn't have a PMU name prefix, e.g., cycles, instructions. So the "--cputype" was introduced for perf stat to avoid the annoying pmu prefix for the CPU type of PMU.
This patch just extends the "--cputype" to perf record to address the request from the community. It reuses the existing function.
Quoted 3 lines
Quoted 3 lines
We
should remove the "hybrid" PMU list and make all of the "hybrid" code generic.
We already start to rework on the "hybrid" code.
We recently rework the perf stat default
https://lore.kernel.org/lkml/[email protected]/
With the help of Ravi, we clean up the hybrid CPU in the perf header.
https://lore.kernel.org/all/[email protected]/
I think Zhengjun will work on the perf record default cleanup shortly.
Then I guess we can further clean up the "--cputype", e.g., removing hybrid_pmu_name from evlist... as next step.
Thanks,
Kan
Quoted 145 lines
Quoted 1 line
I can change the option name from "cputype" to "pmutype". We have planned to clean up the hybrid code, and try to reduce the code with "if
perf_pmu__has_hybrid()", this will be done step by step, from this patch, we have begun to do some clean-up, move the hybrid API from the common file to the hybrid-specific files. For the clean-up, Do you have any ideas? Thanks.Quoted 140 lines
Thanks,
IanQuoted 137 lines
Signed-off-by Zhengjun Xing <[email protected]>Reviewed-by Kan Liang <[email protected]>---
tools/perf/Documentation/perf-record.txt| 4 ++++ tools/perf/builtin-record.c | 3 +++ tools/perf/builtin-stat.c | 20 -------------------- tools/perf/util/pmu-hybrid.c | 19 +++++++++++++++++++ tools/perf/util/pmu-hybrid.h | 2 ++5 files changed, 28 insertions(+), 20 deletions(-)tools/perf/Documentation/perf-record.txt +0
-0@@ -402,6 +402,10 @@ Enable weightened sampling. An additional weightis recorded per sample and can
displayed with the weight andlocal_weightsort keys. This currently works for TSX abort events and some memory events in precise mode on modern Intel CPUs.+--cputype::
+Only enable events on applying cpu with this type for hybrid platform(e.g. core or atom).tools/perf/Documentation/perf-record.txt +2
-0+For non-hybrid events, it should be no effect. +--namespaces::
Record events of type PERF_RECORD_NAMESPACES. This enables 'cgroup_id' sort key.tools/perf/builtin-record.c +3
-0@@ -3183,6 +3183,9 @@ static struct option __record_options[] = { OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"), OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"), + OPT_CALLBACK(0, "cputype", &record.evlist, "hybrid cpu type", + "Only enable events on applying cpu with this type for hybrid platform (e.g. core or atom)", + parse_hybrid_type), OPT_BOOLEAN('s', "stat", &record.opts.inherit_stat, "per thread counts"),
OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample addresses"),tools/perf/builtin-stat.c +0
-20@@ -1184,26 +1184,6 @@ static int parse_stat_cgroups(const structoption *opt, return parse_cgroups(opt, str, unset); } -static int parse_hybrid_type (const struct option *opt, - const char *str, - int unset __maybe_unused) -{ - struct evlist *evlist = *(struct evlist **)opt->value; - - if (!list_empty(&evlist->core.entries)) { - fprintf(stderr, "Must define cputype before events/metrics\n"); - return -1; - } - - evlist->hybrid_pmu_name = perf_pmu__hybrid_type_to_pmu(str); - if (!evlist->hybrid_pmu_name) { - fprintf(stderr, "--cputype %s is not supported!\n", str); - return -1; - } - - return 0; -} -static struct option stat_options[] = {
OPT_BOOLEAN('T', "transaction", &transaction_run, "hardware transaction statistics"),tools/perf/util/pmu-hybrid.c +3
-0@@ -13,6 +13,7 @@ #include <stdarg.h> #include <locale.h> #include <api/fs/fs.h> +#include "util/evlist.h" #include "fncache.h" #include "pmu-hybrid.h"@@ -87,3 +88,21 @@ char *perf_pmu__hybrid_type_to_pmu(const char *type) free(pmu_name); return NULL; } + +int parse_hybrid_type(const struct option *opt, const char *str, intunset
__maybe_unused)tools/perf/util/pmu-hybrid.c +5
-0+{ + struct evlist *evlist = *(struct evlist **)opt->value; + + if (!list_empty(&evlist->core.entries)) { + fprintf(stderr, "Must define cputype beforeevents/metrics\n");
+ return -1;
+ }
+
+evlist->hybrid_pmu_name=perf_pmu__hybrid_type_to_pmu(str); + if (!evlist->hybrid_pmu_name) {
+fprintf(stderr, "--cputype %s is not supported!\n", str);
+ return -1;
+ }tools/perf/util/pmu-hybrid.c +3
-0+ + return 0; +}tools/perf/util/pmu-hybrid.h +2
-0@@ -5,6 +5,7 @@ #include <linux/perf_event.h> #include <linux/compiler.h> #include <linux/list.h> +#include <subcmd/parse-options.h> #include <stdbool.h> #include "pmu.h"@@ -18,6 +19,7 @@ bool perf_pmu__hybrid_mounted(const char *name); struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name); bool perf_pmu__is_hybrid(const char *name); char *perf_pmu__hybrid_type_to_pmu(const char *type); +int parse_hybrid_type (const struct option *opt,const char *str,int unset__maybe_unused ); static inline int perf_pmu__hybrid_pmu_num(void){
Signature · 1 line
2.25.1
Hi Ian,
Quoted 74 lines · Kan
Quoted 70 lines · Xing Zhengjun
Hi Ian,
Quoted 67 lines · Ian Rogers
Quoted 52 lines · On Wed, Jun 15, 2022 at 8:07 AM <[email protected]> wrote:
From: Zhengjun Xing <[email protected]>
perf stat already has the "--cputype" option to enable events only on the specified PMU for the hybrid platform, this commit extends the "--cputype" support to perf record.
Without "--cputype", it reports events for both
cpu_coreandcpu_atom.# ./perf record -e cycles -a sleep 1 | ./perf report# To display the perf.data header info, please use
--header/--header-only options.
#
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB (null) ]
#
# Total Lost Samples: 0
#
# Samples: 335 of event 'cpu_core/cycles/'
# Event count (approx.): 35855267
#
# Overhead Command Shared Object Symbol
# ........ ............... ................. ......................................... #
10.31% swapper [kernel.kallsyms] [k]poll_idle
9.42% swapper [kernel.kallsyms] [k]menu_select
... ... ... ... ...# Samples: 61 of event 'cpu_atom/cycles/'
# Event count (approx.): 16453825
#
# Overhead Command Shared Object Symbol
# ........ ............. ................. ...................................... #
26.36% snapd [unknown] [.]0x0000563cc6d038417.43% migration/13 [kernel.kallsyms] [k] update_sd_lb_stats.constprop.0 ... ... ... ... ...With "--cputype", it reports events only for the specified PMU.
# ./perf record --cputype core -e cycles -a sleep 1 | ./perf report# To display the perf.data header info, please use --header/--header-only options.
#
[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB (null) ] #
# Total Lost Samples: 0
#
# Samples: 221 of event 'cpu_core/cycles/'Quoted 8 lines
# Event count (approx.): 27121818
#
# Overhead Command Shared Object Symbol
# ........ ............... ................. ......................................... #
11.24% swapper [kernel.kallsyms] [k]e1000_irq_enable7.77% swapper [kernel.kallsyms] [k] mwait_idle_with_hints.constprop.0 ... ... ... ... ...This is already possible by having the PMU name as part of the event, cpu_atom/cycles/ or cpu_core/cycles/. I don't know why we're adding "hybrid" all over the code base, I wish it would stop. You are asking for an option here for an implied PMU for events that don't specify a PMU. The option should be called --pmutype and consider all PMUs.
Quoted 5 lines
The --pmutype should be redundant because other PMUs have to specify the PMU name with the event. Only the CPU type of PMUs have events which doesn't have a PMU name prefix, e.g., cycles, instructions. So the "--cputype" was introduced for perf stat to avoid the annoying pmu prefix for the CPU type of PMU.
This patch just extends the "--cputype" to perf record to address the request from the community. It reuses the existing function.
Yes, "--cputype" is better. Ian, what do you think? Thanks.
Quoted 164 lines
Quoted 3 lines
Quoted 3 lines
We
should remove the "hybrid" PMU list and make all of the "hybrid" code generic.We already start to rework on the "hybrid" code.
We recently rework the perf stat default
https://lore.kernel.org/lkml/[email protected]/With the help of Ravi, we clean up the hybrid CPU in the perf header.
https://lore.kernel.org/all/[email protected]/I think Zhengjun will work on the perf record default cleanup shortly.
Then I guess we can further clean up the "--cputype", e.g., removing
hybrid_pmu_namefrom evlist... as next step.Thanks,
KanQuoted 145 lines
Quoted 1 line
I can change the option name from "cputype" to "pmutype". We have planned to clean up the hybrid code, and try to reduce the code with "if
perf_pmu__has_hybrid()", this will be done step by step, from this patch, we have begun to do some clean-up, move the hybrid API from the common file to the hybrid-specific files. For the clean-up, Do you have any ideas? Thanks.Quoted 140 lines
Thanks,
IanQuoted 137 lines
Signed-off-by Zhengjun Xing <[email protected]>Reviewed-by Kan Liang <[email protected]>---
tools/perf/Documentation/perf-record.txt| 4 ++++ tools/perf/builtin-record.c | 3 +++ tools/perf/builtin-stat.c | 20 -------------------- tools/perf/util/pmu-hybrid.c | 19 +++++++++++++++++++ tools/perf/util/pmu-hybrid.h | 2 ++5 files changed, 28 insertions(+), 20 deletions(-)tools/perf/Documentation/perf-record.txt +0
-0@@ -402,6 +402,10 @@ Enable weightened sampling. An additionalweight is recorded per sample and can
displayed with the weight andlocal_weightsort keys. This currently works for TSX abort events and some memory events in precise mode on modern Intel CPUs.+--cputype::
+Only enable events on applying cpu with this type for hybrid platform(e.g. core or atom).tools/perf/Documentation/perf-record.txt +2
-0+For non-hybrid events, it should be no effect. +--namespaces::
Record events of type PERF_RECORD_NAMESPACES. This enables 'cgroup_id' sort key.tools/perf/builtin-record.c +3
-0@@ -3183,6 +3183,9 @@ static struct option __record_options[] = { OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"), OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"), + OPT_CALLBACK(0, "cputype", &record.evlist, "hybrid cpu type", + "Only enable events on applying cpu with this type for hybrid platform (e.g. core or atom)", + parse_hybrid_type), OPT_BOOLEAN('s', "stat", &record.opts.inherit_stat, "per thread counts"),
OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample addresses"),tools/perf/builtin-stat.c +0
-20@@ -1184,26 +1184,6 @@ static int parse_stat_cgroups(const structoption *opt, return parse_cgroups(opt, str, unset); } -static int parse_hybrid_type (const struct option *opt, - const char *str, - int unset __maybe_unused) -{ - struct evlist *evlist = *(struct evlist **)opt->value; - - if (!list_empty(&evlist->core.entries)) { - fprintf(stderr, "Must define cputype before events/metrics\n"); - return -1; - } - - evlist->hybrid_pmu_name = perf_pmu__hybrid_type_to_pmu(str); - if (!evlist->hybrid_pmu_name) { - fprintf(stderr, "--cputype %s is not supported!\n", str); - return -1; - } - - return 0; -} -static struct option stat_options[] = {
OPT_BOOLEAN('T', "transaction", &transaction_run, "hardware transaction statistics"),tools/perf/util/pmu-hybrid.c +3
-0@@ -13,6 +13,7 @@ #include <stdarg.h> #include <locale.h> #include <api/fs/fs.h> +#include "util/evlist.h" #include "fncache.h" #include "pmu-hybrid.h"@@ -87,3 +88,21 @@ char *perf_pmu__hybrid_type_to_pmu(const char *type) free(pmu_name); return NULL; } + +int parse_hybrid_type(const struct option *opt, const char *str,int unset
__maybe_unused)tools/perf/util/pmu-hybrid.c +5
-0+{ + struct evlist *evlist = *(struct evlist **)opt->value; + + if (!list_empty(&evlist->core.entries)) { + fprintf(stderr, "Must define cputype beforeevents/metrics\n");
+ return -1;
+ }
+
+evlist->hybrid_pmu_name=perf_pmu__hybrid_type_to_pmu(str); + if (!evlist->hybrid_pmu_name) {
+fprintf(stderr, "--cputype %s is not supported!\n", str);
+ return -1;
+ }tools/perf/util/pmu-hybrid.c +3
-0+ + return 0; +}tools/perf/util/pmu-hybrid.h +2
-0@@ -5,6 +5,7 @@ #include <linux/perf_event.h> #include <linux/compiler.h> #include <linux/list.h> +#include <subcmd/parse-options.h> #include <stdbool.h> #include "pmu.h"@@ -18,6 +19,7 @@ bool perf_pmu__hybrid_mounted(const char *name); struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name); bool perf_pmu__is_hybrid(const char *name); char *perf_pmu__hybrid_type_to_pmu(const char *type); +int parse_hybrid_type (const struct option *opt,const char *str,int unset__maybe_unused ); static inline int perf_pmu__hybrid_pmu_num(void){
Signature · 1 line
2.25.1
Signature · 1 line
Zhengjun Xing
Hi Ian,
Quoted 77 lines · Xing Zhengjun
Hi Ian,
Quoted 74 lines · Kan
Quoted 70 lines · Xing Zhengjun
Hi Ian,
Quoted 67 lines · Ian Rogers
Quoted 52 lines · On Wed, Jun 15, 2022 at 8:07 AM <[email protected]> wrote:
From: Zhengjun Xing <[email protected]>
perf stat already has the "--cputype" option to enable events only on the specified PMU for the hybrid platform, this commit extends the "--cputype" support to perf record.
Without "--cputype", it reports events for both
cpu_coreandcpu_atom.# ./perf record -e cycles -a sleep 1 | ./perf report# To display the perf.data header info, please use
--header/--header-only options.
#
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.000 MB (null) ]
#
# Total Lost Samples: 0
#
# Samples: 335 of event 'cpu_core/cycles/'
# Event count (approx.): 35855267
#
# Overhead Command Shared Object Symbol
# ........ ............... ................. ......................................... #
10.31% swapper [kernel.kallsyms] [k]poll_idle
9.42% swapper [kernel.kallsyms] [k]menu_select
... ... ... ... ...# Samples: 61 of event 'cpu_atom/cycles/'
# Event count (approx.): 16453825
#
# Overhead Command Shared Object Symbol
# ........ ............. ................. ...................................... #
26.36% snapd [unknown] [.]0x0000563cc6d038417.43% migration/13 [kernel.kallsyms] [k] update_sd_lb_stats.constprop.0 ... ... ... ... ...With "--cputype", it reports events only for the specified PMU.
# ./perf record --cputype core -e cycles -a sleep 1 | ./perf report# To display the perf.data header info, please use --header/--header-only options.
#
[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.000 MB (null) ] #
# Total Lost Samples: 0
#
# Samples: 221 of event 'cpu_core/cycles/'Quoted 8 lines
# Event count (approx.): 27121818
#
# Overhead Command Shared Object Symbol
# ........ ............... ................. ......................................... #
11.24% swapper [kernel.kallsyms] [k]e1000_irq_enable7.77% swapper [kernel.kallsyms] [k] mwait_idle_with_hints.constprop.0 ... ... ... ... ...This is already possible by having the PMU name as part of the event, cpu_atom/cycles/ or cpu_core/cycles/. I don't know why we're adding "hybrid" all over the code base, I wish it would stop. You are asking for an option here for an implied PMU for events that don't specify a PMU. The option should be called --pmutype and consider all PMUs.
Quoted 7 lines
Quoted 5 lines
The --pmutype should be redundant because other PMUs have to specify the PMU name with the event. Only the CPU type of PMUs have events which doesn't have a PMU name prefix, e.g., cycles, instructions. So the "--cputype" was introduced for perf stat to avoid the annoying pmu prefix for the CPU type of PMU.
This patch just extends the "--cputype" to perf record to address the request from the community. It reuses the existing function.
Yes, "--cputype" is better. Ian, what do you think? Thanks.
Ian, Could you help to comment on it? Thanks.
Quoted 167 lines
Quoted 166 lines
Quoted 4 lines
Quoted 4 lines
We
should remove the "hybrid" PMU list and make all of the "hybrid" code generic.We already start to rework on the "hybrid" code.
We recently rework the perf stat default
https://lore.kernel.org/lkml/[email protected]/With the help of Ravi, we clean up the hybrid CPU in the perf header.
https://lore.kernel.org/all/[email protected]/I think Zhengjun will work on the perf record default cleanup shortly.
Then I guess we can further clean up the "--cputype", e.g., removing
hybrid_pmu_namefrom evlist... as next step.Thanks,
KanQuoted 146 lines
Quoted 1 line
I can change the option name from "cputype" to "pmutype". We have planned to clean up the hybrid code, and try to reduce the code with "if
perf_pmu__has_hybrid()", this will be done step by step, from this patch, we have begun to do some clean-up, move the hybrid API from the common file to the hybrid-specific files. For the clean-up, Do you have any ideas? Thanks.Quoted 141 lines
Thanks,
IanQuoted 138 lines
Signed-off-by Zhengjun Xing <[email protected]>Reviewed-by Kan Liang <[email protected]>---
tools/perf/Documentation/perf-record.txt| 4 ++++ tools/perf/builtin-record.c | 3 +++ tools/perf/builtin-stat.c | 20 -------------------- tools/perf/util/pmu-hybrid.c | 19 +++++++++++++++++++ tools/perf/util/pmu-hybrid.h | 2 ++5 files changed, 28 insertions(+), 20 deletions(-)tools/perf/Documentation/perf-record.txt +0
-0@@ -402,6 +402,10 @@ Enable weightened sampling. An additionalweight is recorded per sample and can
displayed with the weight andlocal_weightsort keys. This currently works for TSX abort events and some memory events in precise mode on modern Intel CPUs.+--cputype::
+Only enable events on applying cpu with this type for hybrid platform(e.g. core or atom).tools/perf/Documentation/perf-record.txt +2
-0+For non-hybrid events, it should be no effect. +--namespaces::
Record events of type PERF_RECORD_NAMESPACES. This enables 'cgroup_id' sort key.tools/perf/builtin-record.c +3
-0@@ -3183,6 +3183,9 @@ static struct option __record_options[] = { OPT_INCR('v', "verbose", &verbose, "be more verbose (show counter open errors, etc)"), OPT_BOOLEAN('q', "quiet", &quiet, "don't print any message"), + OPT_CALLBACK(0, "cputype", &record.evlist, "hybrid cpu type", + "Only enable events on applying cpu with this type for hybrid platform (e.g. core or atom)", + parse_hybrid_type), OPT_BOOLEAN('s', "stat", &record.opts.inherit_stat, "per thread counts"),
OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample addresses"),tools/perf/builtin-stat.c +0
-20@@ -1184,26 +1184,6 @@ static int parse_stat_cgroups(const structoption *opt, return parse_cgroups(opt, str, unset); } -static int parse_hybrid_type (const struct option *opt, - const char *str, - int unset __maybe_unused) -{ - struct evlist *evlist = *(struct evlist **)opt->value; - - if (!list_empty(&evlist->core.entries)) { - fprintf(stderr, "Must define cputype before events/metrics\n"); - return -1; - } - - evlist->hybrid_pmu_name = perf_pmu__hybrid_type_to_pmu(str); - if (!evlist->hybrid_pmu_name) { - fprintf(stderr, "--cputype %s is not supported!\n", str); - return -1; - } - - return 0; -} -static struct option stat_options[] = {
OPT_BOOLEAN('T', "transaction", &transaction_run, "hardware transaction statistics"),tools/perf/util/pmu-hybrid.c +1
-0@@ -13,6 +13,7 @@ #include <stdarg.h> #include <locale.h> #include <api/fs/fs.h> +#include "util/evlist.h" #include "fncache.h" #include "pmu-hybrid.h"@@ -87,3 +88,21 @@ char *perf_pmu__hybrid_type_to_pmu(const char *type) free(pmu_name); return NULL;}
tools/perf/util/pmu-hybrid.c +2
-0+ +int parse_hybrid_type(const struct option *opt, const char *str,int unset
__maybe_unused)tools/perf/util/pmu-hybrid.c +5
-0+{ + struct evlist *evlist = *(struct evlist **)opt->value; + + if (!list_empty(&evlist->core.entries)) { + fprintf(stderr, "Must define cputype beforeevents/metrics\n");
+ return -1;
+ }
+
+evlist->hybrid_pmu_name=perf_pmu__hybrid_type_to_pmu(str); + if (!evlist->hybrid_pmu_name) {
+fprintf(stderr, "--cputype %s is not supported!\n", str);
+ return -1;
+ }tools/perf/util/pmu-hybrid.c +3
-0+ + return 0; +}tools/perf/util/pmu-hybrid.h +2
-0@@ -5,6 +5,7 @@ #include <linux/perf_event.h> #include <linux/compiler.h> #include <linux/list.h> +#include <subcmd/parse-options.h> #include <stdbool.h> #include "pmu.h"@@ -18,6 +19,7 @@ bool perf_pmu__hybrid_mounted(const char *name); struct perf_pmu *perf_pmu__find_hybrid_pmu(const char *name); bool perf_pmu__is_hybrid(const char *name); char *perf_pmu__hybrid_type_to_pmu(const char *type); +int parse_hybrid_type (const struct option *opt,const char *str,int unset__maybe_unused ); static inline int perf_pmu__hybrid_pmu_num(void){
Signature · 1 line
2.25.1
Signature · 1 line
Zhengjun Xing