perf intel-pt: Split VM-Entry and VM-Exit branches
authorAdrian Hunter <adrian.hunter@intel.com>
Thu, 18 Feb 2021 09:58:00 +0000 (11:58 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 18 Feb 2021 19:15:38 +0000 (16:15 -0300)
Events record a single cpumode so the tools cannot handle a branch from
the host machine to a virtual machine, or vice versa. Split it in two so
that each branch can have a different cpumode.

  E.g. host ip -> guest ip

  becomes: host ip -> 0
      0 -> guest ip

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Andi Kleen <ak@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20210218095801.19576-11-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/intel-pt.c

index cafb394..f6e28ac 100644 (file)
@@ -2171,7 +2171,27 @@ static int intel_pt_sample(struct intel_pt_queue *ptq)
        }
 
        if (pt->sample_branches) {
-               err = intel_pt_synth_branch_sample(ptq);
+               if (state->from_nr != state->to_nr &&
+                   state->from_ip && state->to_ip) {
+                       struct intel_pt_state *st = (struct intel_pt_state *)state;
+                       u64 to_ip = st->to_ip;
+                       u64 from_ip = st->from_ip;
+
+                       /*
+                        * perf cannot handle having different machines for ip
+                        * and addr, so create 2 branches.
+                        */
+                       st->to_ip = 0;
+                       err = intel_pt_synth_branch_sample(ptq);
+                       if (err)
+                               return err;
+                       st->from_ip = 0;
+                       st->to_ip = to_ip;
+                       err = intel_pt_synth_branch_sample(ptq);
+                       st->from_ip = from_ip;
+               } else {
+                       err = intel_pt_synth_branch_sample(ptq);
+               }
                if (err)
                        return err;
        }