perf tools: Add a 'percore' event qualifier
authorJin Yao <yao.jin@linux.intel.com>
Fri, 12 Apr 2019 13:59:47 +0000 (21:59 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 16 May 2019 17:17:24 +0000 (14:17 -0300)
Add a 'percore' event qualifier, like cpu/event=0,umask=0x3,percore=1/,
that sums up the event counts for both hardware threads in a core.

We can already do this with --per-core, but it's often useful to do
this together with other metrics that are collected per hardware thread.
So we need to support this per-core counting on a event level.

This can be implemented in only the user tool, no kernel support needed.

 v4:
 ---
 1. Add Arnaldo's patch which updates the documentation for
    this new qualifier.
 2. Rebase to latest perf/core branch

 v3:
 ---
 Simplify the code according to Jiri's comments.
 Before:
   "return term->val.percore ? true : false;"
 Now:
   "return term->val.percore;"

 v2:
 ---
 Change the qualifier name from 'coresum' to 'percore' according to
 comments from Jiri and Andi.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Tested-by: Ravi Bangoria <ravi.bangoria@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: Jin Yao <yao.jin@intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1555077590-27664-2-git-send-email-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-list.txt
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/parse-events.c
tools/perf/util/parse-events.h
tools/perf/util/parse-events.l

index 138fb6e94b3c40f70db82a2943bd792a859f118e..18ed1b0fceb33e4f9042ef6ec9ad1445c039e943 100644 (file)
@@ -199,6 +199,18 @@ also be supplied. For example:
 
   perf stat -C 0 -e 'hv_gpci/dtbp_ptitc,phys_processor_idx=0x2/' ...
 
+EVENT QUALIFIERS:
+
+It is also possible to add extra qualifiers to an event:
+
+percore:
+
+Sums up the event counts for all hardware threads in a core, e.g.:
+
+
+  perf stat -e cpu/event=0,umask=0x3,percore=1/
+
+
 EVENT GROUPS
 ------------
 
index a10cf4cde92059b3b667216bc625a5b472f7237a..a6f572a40deb3bb1e3aaa64d03c53a7e0372c46f 100644 (file)
@@ -813,6 +813,8 @@ static void apply_config_terms(struct perf_evsel *evsel,
                        break;
                case PERF_EVSEL__CONFIG_TERM_DRV_CFG:
                        break;
+               case PERF_EVSEL__CONFIG_TERM_PERCORE:
+                       break;
                default:
                        break;
                }
index 6d190cbf1070218e6048cb5a3d2b9bf8e843bb5f..cad54e8ba522d2abf0a7fecbbdcc2a232e448f9f 100644 (file)
@@ -50,6 +50,7 @@ enum term_type {
        PERF_EVSEL__CONFIG_TERM_OVERWRITE,
        PERF_EVSEL__CONFIG_TERM_DRV_CFG,
        PERF_EVSEL__CONFIG_TERM_BRANCH,
+       PERF_EVSEL__CONFIG_TERM_PERCORE,
 };
 
 struct perf_evsel_config_term {
@@ -67,6 +68,7 @@ struct perf_evsel_config_term {
                bool    overwrite;
                char    *branch;
                unsigned long max_events;
+               bool    percore;
        } val;
        bool weak;
 };
@@ -158,6 +160,7 @@ struct perf_evsel {
        struct perf_evsel       **metric_events;
        bool                    collect_stat;
        bool                    weak_group;
+       bool                    percore;
        const char              *pmu_name;
        struct {
                perf_evsel__sb_cb_t     *cb;
index 4432bfe039fd99668447bd2f407f5fd631f16855..cf0b9b81c5aaa7f5e2866896fa39e361d43dae8a 100644 (file)
@@ -950,6 +950,7 @@ static const char *config_term_names[__PARSE_EVENTS__TERM_TYPE_NR] = {
        [PARSE_EVENTS__TERM_TYPE_OVERWRITE]             = "overwrite",
        [PARSE_EVENTS__TERM_TYPE_NOOVERWRITE]           = "no-overwrite",
        [PARSE_EVENTS__TERM_TYPE_DRV_CFG]               = "driver-config",
+       [PARSE_EVENTS__TERM_TYPE_PERCORE]               = "percore",
 };
 
 static bool config_term_shrinked;
@@ -970,6 +971,7 @@ config_term_avail(int term_type, struct parse_events_error *err)
        case PARSE_EVENTS__TERM_TYPE_CONFIG2:
        case PARSE_EVENTS__TERM_TYPE_NAME:
        case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD:
+       case PARSE_EVENTS__TERM_TYPE_PERCORE:
                return true;
        default:
                if (!err)
@@ -1061,6 +1063,14 @@ do {                                                                        \
        case PARSE_EVENTS__TERM_TYPE_MAX_EVENTS:
                CHECK_TYPE_VAL(NUM);
                break;
+       case PARSE_EVENTS__TERM_TYPE_PERCORE:
+               CHECK_TYPE_VAL(NUM);
+               if ((unsigned int)term->val.num > 1) {
+                       err->str = strdup("expected 0 or 1");
+                       err->idx = term->err_val;
+                       return -EINVAL;
+               }
+               break;
        default:
                err->str = strdup("unknown term");
                err->idx = term->err_term;
@@ -1199,6 +1209,10 @@ do {                                                             \
                case PARSE_EVENTS__TERM_TYPE_DRV_CFG:
                        ADD_CONFIG_TERM(DRV_CFG, drv_cfg, term->val.str);
                        break;
+               case PARSE_EVENTS__TERM_TYPE_PERCORE:
+                       ADD_CONFIG_TERM(PERCORE, percore,
+                                       term->val.num ? true : false);
+                       break;
                default:
                        break;
                }
@@ -1260,6 +1274,18 @@ int parse_events_add_tool(struct parse_events_state *parse_state,
        return add_event_tool(list, &parse_state->idx, tool_event);
 }
 
+static bool config_term_percore(struct list_head *config_terms)
+{
+       struct perf_evsel_config_term *term;
+
+       list_for_each_entry(term, config_terms, list) {
+               if (term->type == PERF_EVSEL__CONFIG_TERM_PERCORE)
+                       return term->val.percore;
+       }
+
+       return false;
+}
+
 int parse_events_add_pmu(struct parse_events_state *parse_state,
                         struct list_head *list, char *name,
                         struct list_head *head_config,
@@ -1333,6 +1359,7 @@ int parse_events_add_pmu(struct parse_events_state *parse_state,
                evsel->metric_name = info.metric_name;
                evsel->pmu_name = name;
                evsel->use_uncore_alias = use_uncore_alias;
+               evsel->percore = config_term_percore(&evsel->config_terms);
        }
 
        return evsel ? 0 : -ENOMEM;
index a052cd6ac63e4ed2c1aa843a8cb64dba6831e0f0..f7139e1a2fd30caffc173eefdbf960c8b049d794 100644 (file)
@@ -75,6 +75,7 @@ enum {
        PARSE_EVENTS__TERM_TYPE_NOOVERWRITE,
        PARSE_EVENTS__TERM_TYPE_OVERWRITE,
        PARSE_EVENTS__TERM_TYPE_DRV_CFG,
+       PARSE_EVENTS__TERM_TYPE_PERCORE,
        __PARSE_EVENTS__TERM_TYPE_NR,
 };
 
index c54bfe88626c169e45e9c765d1dff0d53530bcff..ca6098874fe21d98ae45262c9b3986545647dc0f 100644 (file)
@@ -283,6 +283,7 @@ inherit                     { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_INHERIT); }
 no-inherit             { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); }
 overwrite              { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_OVERWRITE); }
 no-overwrite           { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOOVERWRITE); }
+percore                        { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_PERCORE); }
 ,                      { return ','; }
 "/"                    { BEGIN(INITIAL); return '/'; }
 {name_minus}           { return str(yyscanner, PE_NAME); }