perf hist: Add 'kvm_info' field in histograms entry
authorLeo Yan <leo.yan@linaro.org>
Wed, 15 Mar 2023 14:51:05 +0000 (22:51 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 15 Mar 2023 19:47:20 +0000 (16:47 -0300)
__hists__add_entry() creates a temporary entry and compare it with
existed histograms entries, if any existed entry equals to the
temporary entry it skips to allocation to avoid duplication.

The problem for support KVM event in histograms is it doesn't contain
any info to identify KVM event and can be used for comparison entries.

This patch adds 'kvm_info' field in the histograms entry which contains
the KVM event's key, this identifier will be used for comparison
histograms entries in later change.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230315145112.186603-2-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-annotate.c
tools/perf/builtin-c2c.c
tools/perf/builtin-diff.c
tools/perf/tests/hists_link.c
tools/perf/util/hist.c
tools/perf/util/hist.h
tools/perf/util/kvm-stat.h
tools/perf/util/sort.h

index 90458ca6933fd6543620c657408f599ac046378e..4750fac7bf932659f652bcd31a9af2917de3e61d 100644 (file)
@@ -252,7 +252,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample,
        if (ann->has_br_stack && has_annotation(ann))
                return process_branch_callback(evsel, sample, al, ann, machine);
 
-       he = hists__add_entry(hists, al, NULL, NULL, NULL, sample, true);
+       he = hists__add_entry(hists, al, NULL, NULL, NULL, NULL, sample, true);
        if (he == NULL)
                return -ENOMEM;
 
index 56974eae06380b2e12d3b47363240952c06dbdf9..d3181fee4d3da17e94fcef0c053fed6757972671 100644 (file)
@@ -315,7 +315,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
        c2c_decode_stats(&stats, mi);
 
        he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops,
-                                 &al, NULL, NULL, mi,
+                                 &al, NULL, NULL, mi, NULL,
                                  sample, true);
        if (he == NULL)
                goto free_mi;
@@ -349,7 +349,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
                        goto free_mi;
 
                he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops,
-                                         &al, NULL, NULL, mi,
+                                         &al, NULL, NULL, mi, NULL,
                                          sample, true);
                if (he == NULL)
                        goto free_mi;
index ed07cc6cca56ccbd651c43bed022dcc3ada06380..22b526766e144b76b31c69f72b4c34884806d3ad 100644 (file)
@@ -423,7 +423,7 @@ static int diff__process_sample_event(struct perf_tool *tool,
        switch (compute) {
        case COMPUTE_CYCLES:
                if (!hists__add_entry_ops(hists, &block_hist_ops, &al, NULL,
-                                         NULL, NULL, sample, true)) {
+                                         NULL, NULL, NULL, sample, true)) {
                        pr_warning("problem incrementing symbol period, "
                                   "skipping event\n");
                        goto out_put;
@@ -442,7 +442,7 @@ static int diff__process_sample_event(struct perf_tool *tool,
                break;
 
        default:
-               if (!hists__add_entry(hists, &al, NULL, NULL, NULL, sample,
+               if (!hists__add_entry(hists, &al, NULL, NULL, NULL, NULL, sample,
                                      true)) {
                        pr_warning("problem incrementing symbol period, "
                                   "skipping event\n");
index 14b2ff808b5e68965bf7acacf872383fc9fff26d..e7e4ee57ce0414fb9e1cef870a9eeaa21d36d81d 100644 (file)
@@ -87,7 +87,7 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine)
                                goto out;
 
                        he = hists__add_entry(hists, &al, NULL,
-                                               NULL, NULL, &sample, true);
+                                             NULL, NULL, NULL, &sample, true);
                        if (he == NULL) {
                                addr_location__put(&al);
                                goto out;
@@ -106,7 +106,7 @@ static int add_hist_entries(struct evlist *evlist, struct machine *machine)
                                goto out;
 
                        he = hists__add_entry(hists, &al, NULL,
-                                               NULL, NULL, &sample, true);
+                                             NULL, NULL, NULL, &sample, true);
                        if (he == NULL) {
                                addr_location__put(&al);
                                goto out;
index b6e4b4edde43b447577c5a30cf9e198e570e47de..3670136a0074692290610ca601a22aa7808a4028 100644 (file)
@@ -4,6 +4,7 @@
 #include "dso.h"
 #include "build-id.h"
 #include "hist.h"
+#include "kvm-stat.h"
 #include "map.h"
 #include "map_symbol.h"
 #include "branch.h"
@@ -698,6 +699,7 @@ __hists__add_entry(struct hists *hists,
                   struct symbol *sym_parent,
                   struct branch_info *bi,
                   struct mem_info *mi,
+                  struct kvm_info *ki,
                   struct block_info *block_info,
                   struct perf_sample *sample,
                   bool sample_self,
@@ -733,6 +735,7 @@ __hists__add_entry(struct hists *hists,
                .hists  = hists,
                .branch_info = bi,
                .mem_info = mi,
+               .kvm_info = ki,
                .block_info = block_info,
                .transaction = sample->transaction,
                .raw_data = sample->raw_data,
@@ -756,10 +759,11 @@ struct hist_entry *hists__add_entry(struct hists *hists,
                                    struct symbol *sym_parent,
                                    struct branch_info *bi,
                                    struct mem_info *mi,
+                                   struct kvm_info *ki,
                                    struct perf_sample *sample,
                                    bool sample_self)
 {
-       return __hists__add_entry(hists, al, sym_parent, bi, mi, NULL,
+       return __hists__add_entry(hists, al, sym_parent, bi, mi, ki, NULL,
                                  sample, sample_self, NULL);
 }
 
@@ -769,10 +773,11 @@ struct hist_entry *hists__add_entry_ops(struct hists *hists,
                                        struct symbol *sym_parent,
                                        struct branch_info *bi,
                                        struct mem_info *mi,
+                                       struct kvm_info *ki,
                                        struct perf_sample *sample,
                                        bool sample_self)
 {
-       return __hists__add_entry(hists, al, sym_parent, bi, mi, NULL,
+       return __hists__add_entry(hists, al, sym_parent, bi, mi, ki, NULL,
                                  sample, sample_self, ops);
 }
 
@@ -846,7 +851,7 @@ iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al
         */
        sample->period = cost;
 
-       he = hists__add_entry(hists, al, iter->parent, NULL, mi,
+       he = hists__add_entry(hists, al, iter->parent, NULL, mi, NULL,
                              sample, true);
        if (!he)
                return -ENOMEM;
@@ -949,7 +954,7 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a
        sample->period = 1;
        sample->weight = bi->flags.cycles ? bi->flags.cycles : 1;
 
-       he = hists__add_entry(hists, al, iter->parent, &bi[i], NULL,
+       he = hists__add_entry(hists, al, iter->parent, &bi[i], NULL, NULL,
                              sample, true);
        if (he == NULL)
                return -ENOMEM;
@@ -987,7 +992,7 @@ iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location
        struct hist_entry *he;
 
        he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL,
-                             sample, true);
+                             NULL, sample, true);
        if (he == NULL)
                return -ENOMEM;
 
@@ -1047,7 +1052,7 @@ iter_add_single_cumulative_entry(struct hist_entry_iter *iter,
        struct hist_entry *he;
        int err = 0;
 
-       he = hists__add_entry(hists, al, iter->parent, NULL, NULL,
+       he = hists__add_entry(hists, al, iter->parent, NULL, NULL, NULL,
                              sample, true);
        if (he == NULL)
                return -ENOMEM;
@@ -1148,7 +1153,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter,
        }
 
        he = hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL,
-                             sample, false);
+                             NULL, sample, false);
        if (he == NULL)
                return -ENOMEM;
 
index d93a4e510dc776f30d444c7fa121427e6c92a2d9..86a6779542792c593315ef5c8c0161e9bbacf7e6 100644 (file)
@@ -14,6 +14,7 @@ struct hist_entry_ops;
 struct addr_location;
 struct map_symbol;
 struct mem_info;
+struct kvm_info;
 struct branch_info;
 struct branch_stack;
 struct block_info;
@@ -150,6 +151,7 @@ struct hist_entry *hists__add_entry(struct hists *hists,
                                    struct symbol *parent,
                                    struct branch_info *bi,
                                    struct mem_info *mi,
+                                   struct kvm_info *ki,
                                    struct perf_sample *sample,
                                    bool sample_self);
 
@@ -159,6 +161,7 @@ struct hist_entry *hists__add_entry_ops(struct hists *hists,
                                        struct symbol *sym_parent,
                                        struct branch_info *bi,
                                        struct mem_info *mi,
+                                       struct kvm_info *ki,
                                        struct perf_sample *sample,
                                        bool sample_self);
 
index 3b2eab91a9bea742b57fcc4775567b3f8eb8ea85..0cf704333c4ce5a134ca7358ea0fdd799aa73289 100644 (file)
@@ -23,6 +23,10 @@ struct event_key {
        struct exit_reasons_table *exit_reasons;
 };
 
+struct kvm_info {
+       char name[KVM_EVENT_NAME_LEN];
+};
+
 struct kvm_event_stats {
        u64 time;
        struct stats stats;
index d79a100e5999a51dd81edd2004bc11f6c0aafdac..22f437c3476f47fe227e49a88dfced96217946b3 100644 (file)
@@ -144,6 +144,7 @@ struct hist_entry {
        struct hists            *hists;
        struct mem_info         *mem_info;
        struct block_info       *block_info;
+       struct kvm_info         *kvm_info;
        void                    *raw_data;
        u32                     raw_size;
        int                     num_res;