[v3,1/2] perf script: Show branch speculation info

Message ID 87c48949f5a442dda6d4dc75d4a4303973eb04b2.1675057032.git.sandipan.das@amd.com
State New
Headers
Series tools perf: Add branch speculation info |

Commit Message

Sandipan Das Jan. 30, 2023, 5:59 a.m. UTC
  Show the branch speculation info if provided by the branch recording
hardware feature. This can be useful for optimizing code further.

The speculation info is appended to the end of the list of fields so any
existing tools that use "/" as a delimiter for access fields via an index
remain unaffected. Also show "-" instead of "N/A" when speculation info
is unavailable because "/" is used as the field separator.

E.g.

  $ perf record -j any,u,save_type ./test_branch
  $ perf script --fields brstacksym

Before:

  [...]
  check_match+0x60/strcmp+0x0/P/-/-/0/CALL
  do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL
  [...]

After:

  [...]
  check_match+0x60/strcmp+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
  do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
  [...]

Signed-off-by: Sandipan Das <sandipan.das@amd.com>
---
 tools/perf/builtin-script.c |  5 +++--
 tools/perf/util/branch.c    | 15 +++++++++++++++
 tools/perf/util/branch.h    |  2 ++
 tools/perf/util/evsel.c     | 15 ++++++++++++---
 4 files changed, 32 insertions(+), 5 deletions(-)
  

Comments

Sandipan Das Jan. 30, 2023, 10:34 a.m. UTC | #1
On 1/30/2023 11:29 AM, Sandipan Das wrote:
> Show the branch speculation info if provided by the branch recording
> hardware feature. This can be useful for optimizing code further.
> 
> The speculation info is appended to the end of the list of fields so any
> existing tools that use "/" as a delimiter for access fields via an index
> remain unaffected. Also show "-" instead of "N/A" when speculation info
> is unavailable because "/" is used as the field separator.
> 
> E.g.
> 
>   $ perf record -j any,u,save_type ./test_branch
>   $ perf script --fields brstacksym
> 
> Before:
> 
>   [...]
>   check_match+0x60/strcmp+0x0/P/-/-/0/CALL
>   do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL
>   [...]
> 
> After:
> 
>   [...]
>   check_match+0x60/strcmp+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
>   do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
>   [...]
> 
> Signed-off-by: Sandipan Das <sandipan.das@amd.com>
> ---
>  tools/perf/builtin-script.c |  5 +++--
>  tools/perf/util/branch.c    | 15 +++++++++++++++
>  tools/perf/util/branch.h    |  2 ++
>  tools/perf/util/evsel.c     | 15 ++++++++++++---
>  4 files changed, 32 insertions(+), 5 deletions(-)
> 

Sorry but I realized later that this change breaks the builtin branch test.
The additional change below fixes that.

diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh
index 59195eb80052..1c49d8293003 100755
--- a/tools/perf/tests/shell/test_brstack.sh
+++ b/tools/perf/tests/shell/test_brstack.sh
@@ -30,14 +30,14 @@ test_user_branches() {
        #       brstack_foo+0x14/brstack_bar+0x40/P/-/-/0/CALL

        set -x
-       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL$"        $TMPDIR/perf.script
-       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL$"      $TMPDIR/perf.script
-       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL$"    $TMPDIR/perf.script
-       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL$"    $TMPDIR/perf.script
-       grep -E -m1 "^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET$"               $TMPDIR/perf.script
-       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET$"     $TMPDIR/perf.script
-       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND$"  $TMPDIR/perf.script
-       grep -E -m1 "^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND$"            $TMPDIR/perf.script
+       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL/.*$"     $TMPDIR/perf.script
+       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$"   $TMPDIR/perf.script
+       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL/.*$" $TMPDIR/perf.script
+       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$" $TMPDIR/perf.script
+       grep -E -m1 "^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET/.*$"            $TMPDIR/perf.script
+       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET/.*$"  $TMPDIR/perf.script
+       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND/.*$"       $TMPDIR/perf.script
+       grep -E -m1 "^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND/.*$"         $TMPDIR/perf.script
        set +x

        # some branch types are still not being tested:
@@ -57,7 +57,7 @@ test_filter() {

        # fail if we find any branch type that doesn't match any of the expected ones
        # also consider UNKNOWN branch types (-)
-       if grep -E -vm1 "^[^ ]*/($expect|-|( *))$" $TMPDIR/perf.script; then
+       if grep -E -vm1 "^[^ ]*/($expect|-|( *))/.*$" $TMPDIR/perf.script; then
                return 1
        fi
 }


- Sandipan
  
Arnaldo Carvalho de Melo Jan. 30, 2023, 8:09 p.m. UTC | #2
Em Mon, Jan 30, 2023 at 04:04:58PM +0530, Sandipan Das escreveu:
> On 1/30/2023 11:29 AM, Sandipan Das wrote:
> > Show the branch speculation info if provided by the branch recording
> > hardware feature. This can be useful for optimizing code further.
> > 
> > The speculation info is appended to the end of the list of fields so any
> > existing tools that use "/" as a delimiter for access fields via an index
> > remain unaffected. Also show "-" instead of "N/A" when speculation info
> > is unavailable because "/" is used as the field separator.
> > 
> > E.g.
> > 
> >   $ perf record -j any,u,save_type ./test_branch
> >   $ perf script --fields brstacksym
> > 
> > Before:
> > 
> >   [...]
> >   check_match+0x60/strcmp+0x0/P/-/-/0/CALL
> >   do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL
> >   [...]
> > 
> > After:
> > 
> >   [...]
> >   check_match+0x60/strcmp+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
> >   do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
> >   [...]
> > 
> > Signed-off-by: Sandipan Das <sandipan.das@amd.com>
> > ---
> >  tools/perf/builtin-script.c |  5 +++--
> >  tools/perf/util/branch.c    | 15 +++++++++++++++
> >  tools/perf/util/branch.h    |  2 ++
> >  tools/perf/util/evsel.c     | 15 ++++++++++++---
> >  4 files changed, 32 insertions(+), 5 deletions(-)
> > 
> 
> Sorry but I realized later that this change breaks the builtin branch test.
> The additional change below fixes that.

Please wait a bit for people to be able to review the other patches and
then submit a v2 series.

- Arnaldo
 
> diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh
> index 59195eb80052..1c49d8293003 100755
> --- a/tools/perf/tests/shell/test_brstack.sh
> +++ b/tools/perf/tests/shell/test_brstack.sh
> @@ -30,14 +30,14 @@ test_user_branches() {
>         #       brstack_foo+0x14/brstack_bar+0x40/P/-/-/0/CALL
> 
>         set -x
> -       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL$"        $TMPDIR/perf.script
> -       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL$"      $TMPDIR/perf.script
> -       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL$"    $TMPDIR/perf.script
> -       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL$"    $TMPDIR/perf.script
> -       grep -E -m1 "^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET$"               $TMPDIR/perf.script
> -       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET$"     $TMPDIR/perf.script
> -       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND$"  $TMPDIR/perf.script
> -       grep -E -m1 "^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND$"            $TMPDIR/perf.script
> +       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL/.*$"     $TMPDIR/perf.script
> +       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$"   $TMPDIR/perf.script
> +       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL/.*$" $TMPDIR/perf.script
> +       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$" $TMPDIR/perf.script
> +       grep -E -m1 "^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET/.*$"            $TMPDIR/perf.script
> +       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET/.*$"  $TMPDIR/perf.script
> +       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND/.*$"       $TMPDIR/perf.script
> +       grep -E -m1 "^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND/.*$"         $TMPDIR/perf.script
>         set +x
> 
>         # some branch types are still not being tested:
> @@ -57,7 +57,7 @@ test_filter() {
> 
>         # fail if we find any branch type that doesn't match any of the expected ones
>         # also consider UNKNOWN branch types (-)
> -       if grep -E -vm1 "^[^ ]*/($expect|-|( *))$" $TMPDIR/perf.script; then
> +       if grep -E -vm1 "^[^ ]*/($expect|-|( *))/.*$" $TMPDIR/perf.script; then
>                 return 1
>         fi
>  }
> 
> 
> - Sandipan
  
Arnaldo Carvalho de Melo Feb. 2, 2023, 1:13 a.m. UTC | #3
Em Mon, Jan 30, 2023 at 05:09:10PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, Jan 30, 2023 at 04:04:58PM +0530, Sandipan Das escreveu:
> > On 1/30/2023 11:29 AM, Sandipan Das wrote:
> > > Show the branch speculation info if provided by the branch recording
> > > hardware feature. This can be useful for optimizing code further.
> > > 
> > > The speculation info is appended to the end of the list of fields so any
> > > existing tools that use "/" as a delimiter for access fields via an index
> > > remain unaffected. Also show "-" instead of "N/A" when speculation info
> > > is unavailable because "/" is used as the field separator.
> > > 
> > > E.g.
> > > 
> > >   $ perf record -j any,u,save_type ./test_branch
> > >   $ perf script --fields brstacksym
> > > 
> > > Before:
> > > 
> > >   [...]
> > >   check_match+0x60/strcmp+0x0/P/-/-/0/CALL
> > >   do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL
> > >   [...]
> > > 
> > > After:
> > > 
> > >   [...]
> > >   check_match+0x60/strcmp+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
> > >   do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
> > >   [...]
> > > 
> > > Signed-off-by: Sandipan Das <sandipan.das@amd.com>
> > > ---
> > >  tools/perf/builtin-script.c |  5 +++--
> > >  tools/perf/util/branch.c    | 15 +++++++++++++++
> > >  tools/perf/util/branch.h    |  2 ++
> > >  tools/perf/util/evsel.c     | 15 ++++++++++++---
> > >  4 files changed, 32 insertions(+), 5 deletions(-)
> > > 
> > 
> > Sorry but I realized later that this change breaks the builtin branch test.
> > The additional change below fixes that.
> 
> Please wait a bit for people to be able to review the other patches and
> then submit a v2 series.

So I applied it manually, no need to send v2.

- Arnaldo
 
> - Arnaldo
>  
> > diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh
> > index 59195eb80052..1c49d8293003 100755
> > --- a/tools/perf/tests/shell/test_brstack.sh
> > +++ b/tools/perf/tests/shell/test_brstack.sh
> > @@ -30,14 +30,14 @@ test_user_branches() {
> >         #       brstack_foo+0x14/brstack_bar+0x40/P/-/-/0/CALL
> > 
> >         set -x
> > -       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL$"        $TMPDIR/perf.script
> > -       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL$"      $TMPDIR/perf.script
> > -       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL$"    $TMPDIR/perf.script
> > -       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL$"    $TMPDIR/perf.script
> > -       grep -E -m1 "^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET$"               $TMPDIR/perf.script
> > -       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET$"     $TMPDIR/perf.script
> > -       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND$"  $TMPDIR/perf.script
> > -       grep -E -m1 "^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND$"            $TMPDIR/perf.script
> > +       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL/.*$"     $TMPDIR/perf.script
> > +       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$"   $TMPDIR/perf.script
> > +       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL/.*$" $TMPDIR/perf.script
> > +       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL/.*$" $TMPDIR/perf.script
> > +       grep -E -m1 "^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET/.*$"            $TMPDIR/perf.script
> > +       grep -E -m1 "^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET/.*$"  $TMPDIR/perf.script
> > +       grep -E -m1 "^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND/.*$"       $TMPDIR/perf.script
> > +       grep -E -m1 "^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND/.*$"         $TMPDIR/perf.script
> >         set +x
> > 
> >         # some branch types are still not being tested:
> > @@ -57,7 +57,7 @@ test_filter() {
> > 
> >         # fail if we find any branch type that doesn't match any of the expected ones
> >         # also consider UNKNOWN branch types (-)
> > -       if grep -E -vm1 "^[^ ]*/($expect|-|( *))$" $TMPDIR/perf.script; then
> > +       if grep -E -vm1 "^[^ ]*/($expect|-|( *))/.*$" $TMPDIR/perf.script; then
> >                 return 1
> >         fi
> >  }
> > 
> > 
> > - Sandipan
> 
> -- 
> 
> - Arnaldo
  
Arnaldo Carvalho de Melo Feb. 2, 2023, 2:34 a.m. UTC | #4
Em Wed, Feb 01, 2023 at 10:13:03PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, Jan 30, 2023 at 05:09:10PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Mon, Jan 30, 2023 at 04:04:58PM +0530, Sandipan Das escreveu:
> > > On 1/30/2023 11:29 AM, Sandipan Das wrote:
> > > > Show the branch speculation info if provided by the branch recording
> > > > hardware feature. This can be useful for optimizing code further.
> > > > 
> > > > The speculation info is appended to the end of the list of fields so any
> > > > existing tools that use "/" as a delimiter for access fields via an index
> > > > remain unaffected. Also show "-" instead of "N/A" when speculation info
> > > > is unavailable because "/" is used as the field separator.
> > > > 
> > > > E.g.
> > > > 
> > > >   $ perf record -j any,u,save_type ./test_branch
> > > >   $ perf script --fields brstacksym
> > > > 
> > > > Before:
> > > > 
> > > >   [...]
> > > >   check_match+0x60/strcmp+0x0/P/-/-/0/CALL
> > > >   do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL
> > > >   [...]
> > > > 
> > > > After:
> > > > 
> > > >   [...]
> > > >   check_match+0x60/strcmp+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
> > > >   do_lookup_x+0x3c5/check_match+0x0/P/-/-/0/CALL/NON_SPEC_CORRECT_PATH
> > > >   [...]
> > > > 
> > > > Signed-off-by: Sandipan Das <sandipan.das@amd.com>
> > > > ---
> > > >  tools/perf/builtin-script.c |  5 +++--
> > > >  tools/perf/util/branch.c    | 15 +++++++++++++++
> > > >  tools/perf/util/branch.h    |  2 ++
> > > >  tools/perf/util/evsel.c     | 15 ++++++++++++---
> > > >  4 files changed, 32 insertions(+), 5 deletions(-)
> > > > 
> > > 
> > > Sorry but I realized later that this change breaks the builtin branch test.
> > > The additional change below fixes that.
> > 
> > Please wait a bit for people to be able to review the other patches and
> > then submit a v2 series.
> 
> So I applied it manually, no need to send v2.

Please send v2 after figuring out why 'perf test "Sample parsing"'
fails,

I removed both patches for now.

- Arnaldo
  
Arnaldo Carvalho de Melo Feb. 2, 2023, 2:37 a.m. UTC | #5
Em Wed, Feb 01, 2023 at 11:34:46PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, Feb 01, 2023 at 10:13:03PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Mon, Jan 30, 2023 at 05:09:10PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Em Mon, Jan 30, 2023 at 04:04:58PM +0530, Sandipan Das escreveu:
> > > > Sorry but I realized later that this change breaks the builtin branch test.
> > > > The additional change below fixes that.
> > > 
> > > Please wait a bit for people to be able to review the other patches and
> > > then submit a v2 series.
> > 
> > So I applied it manually, no need to send v2.
> 
> Please send v2 after figuring out why 'perf test "Sample parsing"'
> fails,
> 
> I removed both patches for now.

Triple checking:

[acme@quaco perf]$ git log --oneline -1
24a617c84f0da540 (HEAD -> perf/core) perf session: Show branch speculation info in raw dump
[acme@quaco perf]$ perf -v
perf version 6.2.rc5.g24a617c84f0d
[acme@quaco perf]$ perf test "Sample testing"
[acme@quaco perf]$ perf test "Sample parsing"
 27: Sample parsing                                                  : FAILED!
 80: x86 Sample parsing                                              : Ok
[acme@quaco perf]$ git reset --hard HEAD~
HEAD is now at 1fad7c0ae6516706 perf script: Show branch speculation info

[acme@quaco perf]$ git log --oneline -1
1fad7c0ae6516706 (HEAD -> perf/core) perf script: Show branch speculation info
[acme@quaco perf]$ perf -v
perf version 6.2.rc5.g1fad7c0ae651
[acme@quaco perf]$ perf test 27
 27: Sample parsing                                                  : FAILED!
[acme@quaco perf]$ git reset --hard HEAD~
HEAD is now at d4a6f399c89520ba perf bench syscall: Add execve syscall benchmark
[acme@quaco perf]$

[acme@quaco perf]$ git log --oneline -1
d4a6f399c89520ba (HEAD -> perf/core, five/perf/core) perf bench syscall: Add execve syscall benchmark
[acme@quaco perf]$ perf -v
perf version 6.2.rc5.gd4a6f399c895
[acme@quaco perf]$ perf test 27
 27: Sample parsing                                                  : Ok
[acme@quaco perf]$

- Arnaldo
  

Patch

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 69394ac0a20d..782319e8fe6a 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -880,12 +880,13 @@  mispred_str(struct branch_entry *br)
 
 static int print_bstack_flags(FILE *fp, struct branch_entry *br)
 {
-	return fprintf(fp, "/%c/%c/%c/%d/%s ",
+	return fprintf(fp, "/%c/%c/%c/%d/%s/%s ",
 		       mispred_str(br),
 		       br->flags.in_tx ? 'X' : '-',
 		       br->flags.abort ? 'A' : '-',
 		       br->flags.cycles,
-		       get_branch_type(br));
+		       get_branch_type(br),
+		       br->flags.spec ? branch_spec_desc(br->flags.spec) : "-");
 }
 
 static int perf_sample__fprintf_brstack(struct perf_sample *sample,
diff --git a/tools/perf/util/branch.c b/tools/perf/util/branch.c
index 6d38238481d3..378f16a24751 100644
--- a/tools/perf/util/branch.c
+++ b/tools/perf/util/branch.c
@@ -212,3 +212,18 @@  int branch_type_str(struct branch_type_stat *st, char *bf, int size)
 
 	return printed;
 }
+
+const char *branch_spec_desc(int spec)
+{
+	const char *branch_spec_outcomes[PERF_BR_SPEC_MAX] = {
+		"N/A",
+		"SPEC_WRONG_PATH",
+		"NON_SPEC_CORRECT_PATH",
+		"SPEC_CORRECT_PATH",
+	};
+
+	if (spec >= 0 && spec < PERF_BR_SPEC_MAX)
+		return branch_spec_outcomes[spec];
+
+	return NULL;
+}
diff --git a/tools/perf/util/branch.h b/tools/perf/util/branch.h
index 3ed792db1125..e41bfffe2217 100644
--- a/tools/perf/util/branch.h
+++ b/tools/perf/util/branch.h
@@ -89,4 +89,6 @@  const char *get_branch_type(struct branch_entry *e);
 void branch_type_stat_display(FILE *fp, struct branch_type_stat *st);
 int branch_type_str(struct branch_type_stat *st, char *bf, int bfsize);
 
+const char *branch_spec_desc(int spec);
+
 #endif /* _PERF_BRANCH_H */
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 8550638587e5..019e53db03b3 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -2319,7 +2319,10 @@  u64 evsel__bitfield_swap_branch_flags(u64 value)
 	 * 		abort:1		//transaction abort
 	 * 		cycles:16	//cycle count to last branch
 	 * 		type:4		//branch type
-	 * 		reserved:40
+	 * 		spec:2		//branch speculation info
+	 * 		new_type:4	//additional branch type
+	 * 		priv:3		//privilege level
+	 * 		reserved:31
 	 * 	}
 	 * }
 	 *
@@ -2335,7 +2338,10 @@  u64 evsel__bitfield_swap_branch_flags(u64 value)
 		new_val |= bitfield_swap(value, 3, 1);
 		new_val |= bitfield_swap(value, 4, 16);
 		new_val |= bitfield_swap(value, 20, 4);
-		new_val |= bitfield_swap(value, 24, 40);
+		new_val |= bitfield_swap(value, 24, 2);
+		new_val |= bitfield_swap(value, 26, 4);
+		new_val |= bitfield_swap(value, 30, 3);
+		new_val |= bitfield_swap(value, 33, 31);
 	} else {
 		new_val = bitfield_swap(value, 63, 1);
 		new_val |= bitfield_swap(value, 62, 1);
@@ -2343,7 +2349,10 @@  u64 evsel__bitfield_swap_branch_flags(u64 value)
 		new_val |= bitfield_swap(value, 60, 1);
 		new_val |= bitfield_swap(value, 44, 16);
 		new_val |= bitfield_swap(value, 40, 4);
-		new_val |= bitfield_swap(value, 0, 40);
+		new_val |= bitfield_swap(value, 38, 2);
+		new_val |= bitfield_swap(value, 34, 4);
+		new_val |= bitfield_swap(value, 31, 3);
+		new_val |= bitfield_swap(value, 0, 31);
 	}
 
 	return new_val;