All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V7 0/8] perf: Expand perf_branch_entry
@ 2022-08-24  4:48 ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Branch Record Buffer Extension (BRBE) implementation on arm64 captures more
branch type classification which cannot be accommodated in the current perf
branch record format via perf_branch_entry.type element (4 bit field). Also
it captures privilege information which does not have a corresponding slot
in perf_branch_entry. This series expands struct perf_branch_entry, to meet
both these requirements without breaking the existing user space ABI for
perf tools.

All architecture specific branch types added via perf_branch_entry.new_type
field in [PATCH 3/4] will be used in BRBE implementation on arm64 platform
later on with the following map.

#ifdef CONFIG_ARM64
#define PERF_BR_FIQ		PERF_BR_NEW_ARCH_1
#define PERF_BR_DEBUG_HALT	PERF_BR_NEW_ARCH_2
#define PERF_BR_DEBUG_EXIT	PERF_BR_NEW_ARCH_3
#define PERF_BR_DEBUG_INST	PERF_BR_NEW_ARCH_4
#define PERF_BR_DEBUG_DATA	PERF_BR_NEW_ARCH_5
#endif

This series applies on v6.20-rc2

perf API

The series being applied

- Clean : tools/perf/check-headers.sh
- Clean : diff -u tools/include/uapi/linux/perf_event.h include/uapi/linux/perf_event.h

References

- BRBE captured branch record information

https://developer.arm.com/documentation/ddi0601/2021-12/AArch64-Registers/BRBINF-n--EL1--Branch-Record-Buffer-Information-Register--n-?lang=en

- BRBE based perf branch stack implementation on arm64 platform

https://lore.kernel.org/all/1642998653-21377-1-git-send-email-anshuman.khandual@arm.com/

Changes in V7:

- Collected earlier 'Reviewed-by:' tags from James Clark
- Rebased on v6.0-rc2

Changes in V6:

https://lore.kernel.org/linux-arm-kernel/20220610035101.424112-1-anshuman.khandual@arm.com/

- Process PERF_BR_EXTEND_ABI in perf tools and fetch from perf_branch_entry.new_type
- Modified the commit message for [PATCH 1/8]

Changes in V5:

https://lore.kernel.org/linux-arm-kernel/20220404045046.634522-1-anshuman.khandual@arm.com/

- Dropped patches [PATCH 1/10] and [PATCH 6/10] related to PERF_BR_[RET|IRQ] - merged
  via the commit cedd3614e5d9c809 ("perf: Add irq and exception return branch types")

- Rebased series on v5.18-rc1

Changes in V4:

https://lore.kernel.org/all/20220315053516.431515-1-anshuman.khandual@arm.com/

- Modified the struct branch_flags as required
- Dropped CONFIG_ARM64 from perf header file to avoid build problem
- Renamed PERF_BR_NEW_<BRANCH_TYPE> as PERF_BR_ARM64_<BRANCH_TYPE>

Changes in V3:

https://lore.kernel.org/all/20220314055857.125421-1-anshuman.khandual@arm.com/

- Fixed small typo s/privillege/privilege in include/uapi/linux/perf_event.h
- Added PRIV_SHIFT in __p_branch_sample_type()
- Added arm64 platform override of the new arch specific branch types
- Renamed s/PERF_BR_XXX/PERF_BR_PRIV_XXX/ for privilege level branch types
- Added PERF_BR_PRIV_UNKNOWN as the starting value
- Expanded perf_branch_entry.priv into a 3 bits field 

Changes in V2:

https://lore.kernel.org/all/20220309033642.144769-1-anshuman.khandual@arm.com/

Cc: Robin Murphy <robin.murphy@arm.com> 
Cc: Suzuki Poulose <suzuki.poulose@arm.com>
Cc: James Clark <james.clark@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

Anshuman Khandual (8):
  perf: Add system error and not in transaction branch types
  perf: Extend branch type classification
  perf: Capture branch privilege information
  perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
  perf/tools: Add system error and not in transaction branch types
  perf/tools: Extend branch type classification
  perf/tools: Add branch privilege information request flag
  perf/tools: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform

 arch/x86/events/intel/lbr.c               |  2 +-
 include/uapi/linux/perf_event.h           | 36 +++++++++++-
 tools/include/uapi/linux/perf_event.h     | 36 +++++++++++-
 tools/perf/Documentation/perf-record.txt  |  1 +
 tools/perf/builtin-script.c               |  2 +-
 tools/perf/util/branch.c                  | 69 ++++++++++++++++++++++-
 tools/perf/util/branch.h                  |  7 ++-
 tools/perf/util/parse-branch-options.c    |  1 +
 tools/perf/util/perf_event_attr_fprintf.c |  2 +-
 tools/perf/util/session.c                 |  2 +-
 10 files changed, 149 insertions(+), 9 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 40+ messages in thread

* [PATCH V7 0/8] perf: Expand perf_branch_entry
@ 2022-08-24  4:48 ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Branch Record Buffer Extension (BRBE) implementation on arm64 captures more
branch type classification which cannot be accommodated in the current perf
branch record format via perf_branch_entry.type element (4 bit field). Also
it captures privilege information which does not have a corresponding slot
in perf_branch_entry. This series expands struct perf_branch_entry, to meet
both these requirements without breaking the existing user space ABI for
perf tools.

All architecture specific branch types added via perf_branch_entry.new_type
field in [PATCH 3/4] will be used in BRBE implementation on arm64 platform
later on with the following map.

#ifdef CONFIG_ARM64
#define PERF_BR_FIQ		PERF_BR_NEW_ARCH_1
#define PERF_BR_DEBUG_HALT	PERF_BR_NEW_ARCH_2
#define PERF_BR_DEBUG_EXIT	PERF_BR_NEW_ARCH_3
#define PERF_BR_DEBUG_INST	PERF_BR_NEW_ARCH_4
#define PERF_BR_DEBUG_DATA	PERF_BR_NEW_ARCH_5
#endif

This series applies on v6.20-rc2

perf API

The series being applied

- Clean : tools/perf/check-headers.sh
- Clean : diff -u tools/include/uapi/linux/perf_event.h include/uapi/linux/perf_event.h

References

- BRBE captured branch record information

https://developer.arm.com/documentation/ddi0601/2021-12/AArch64-Registers/BRBINF-n--EL1--Branch-Record-Buffer-Information-Register--n-?lang=en

- BRBE based perf branch stack implementation on arm64 platform

https://lore.kernel.org/all/1642998653-21377-1-git-send-email-anshuman.khandual@arm.com/

Changes in V7:

- Collected earlier 'Reviewed-by:' tags from James Clark
- Rebased on v6.0-rc2

Changes in V6:

https://lore.kernel.org/linux-arm-kernel/20220610035101.424112-1-anshuman.khandual@arm.com/

- Process PERF_BR_EXTEND_ABI in perf tools and fetch from perf_branch_entry.new_type
- Modified the commit message for [PATCH 1/8]

Changes in V5:

https://lore.kernel.org/linux-arm-kernel/20220404045046.634522-1-anshuman.khandual@arm.com/

- Dropped patches [PATCH 1/10] and [PATCH 6/10] related to PERF_BR_[RET|IRQ] - merged
  via the commit cedd3614e5d9c809 ("perf: Add irq and exception return branch types")

- Rebased series on v5.18-rc1

Changes in V4:

https://lore.kernel.org/all/20220315053516.431515-1-anshuman.khandual@arm.com/

- Modified the struct branch_flags as required
- Dropped CONFIG_ARM64 from perf header file to avoid build problem
- Renamed PERF_BR_NEW_<BRANCH_TYPE> as PERF_BR_ARM64_<BRANCH_TYPE>

Changes in V3:

https://lore.kernel.org/all/20220314055857.125421-1-anshuman.khandual@arm.com/

- Fixed small typo s/privillege/privilege in include/uapi/linux/perf_event.h
- Added PRIV_SHIFT in __p_branch_sample_type()
- Added arm64 platform override of the new arch specific branch types
- Renamed s/PERF_BR_XXX/PERF_BR_PRIV_XXX/ for privilege level branch types
- Added PERF_BR_PRIV_UNKNOWN as the starting value
- Expanded perf_branch_entry.priv into a 3 bits field 

Changes in V2:

https://lore.kernel.org/all/20220309033642.144769-1-anshuman.khandual@arm.com/

Cc: Robin Murphy <robin.murphy@arm.com> 
Cc: Suzuki Poulose <suzuki.poulose@arm.com>
Cc: James Clark <james.clark@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org

Anshuman Khandual (8):
  perf: Add system error and not in transaction branch types
  perf: Extend branch type classification
  perf: Capture branch privilege information
  perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
  perf/tools: Add system error and not in transaction branch types
  perf/tools: Extend branch type classification
  perf/tools: Add branch privilege information request flag
  perf/tools: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform

 arch/x86/events/intel/lbr.c               |  2 +-
 include/uapi/linux/perf_event.h           | 36 +++++++++++-
 tools/include/uapi/linux/perf_event.h     | 36 +++++++++++-
 tools/perf/Documentation/perf-record.txt  |  1 +
 tools/perf/builtin-script.c               |  2 +-
 tools/perf/util/branch.c                  | 69 ++++++++++++++++++++++-
 tools/perf/util/branch.h                  |  7 ++-
 tools/perf/util/parse-branch-options.c    |  1 +
 tools/perf/util/perf_event_attr_fprintf.c |  2 +-
 tools/perf/util/session.c                 |  2 +-
 10 files changed, 149 insertions(+), 9 deletions(-)

-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [PATCH V7 1/8] perf: Add system error and not in transaction branch types
  2022-08-24  4:48 ` Anshuman Khandual
@ 2022-08-24  4:48   ` Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

This expands generic branch type classification by adding two more entries
there in i.e system error and not in transaction. This also updates the x86
implementation to process X86_BR_NO_TX records as appropriate. This changes
branch types reported to user space on x86 platform but it should not be a
problem. The possible scenarios and impacts are enumerated here.

--------------------------------------------------------------------------
| kernel | perf tool |                     Impact                        |
--------------------------------------------------------------------------
|   old  |    old    |  Works as before                                  |
--------------------------------------------------------------------------
|   old  |    new    |  PERF_BR_UNKNOWN is processed                     |
--------------------------------------------------------------------------
|   new  |    old    |  PERF_BR_NO_TX is blocked via old PERF_BR_MAX     |
--------------------------------------------------------------------------
|   new  |    new    |  PERF_BR_NO_TX is recognized                      |
--------------------------------------------------------------------------

When PERF_BR_NO_TX is blocked via old PERF_BR_MAX (new kernel with old perf
tool) the user space might throw up an warning complaining about an
unrecognized branch types being reported, but it's expected. PERF_BR_SERROR
& PERF_BR_NO_TX branch types will be used for BRBE implementation on arm64
platform.

PERF_BR_NO_TX complements 'abort' and 'in_tx' elements in perf_branch_entry
which represent other transaction states for a given branch record. Because
this completes the transaction state classification.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/events/intel/lbr.c     | 2 +-
 include/uapi/linux/perf_event.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
index 4f70fb6c2c1e..30441dd4cf89 100644
--- a/arch/x86/events/intel/lbr.c
+++ b/arch/x86/events/intel/lbr.c
@@ -1334,7 +1334,7 @@ static int branch_map[X86_BR_TYPE_MAP_MAX] = {
 	PERF_BR_IND_CALL,	/* X86_BR_IND_CALL */
 	PERF_BR_UNKNOWN,	/* X86_BR_ABORT */
 	PERF_BR_UNKNOWN,	/* X86_BR_IN_TX */
-	PERF_BR_UNKNOWN,	/* X86_BR_NO_TX */
+	PERF_BR_NO_TX,		/* X86_BR_NO_TX */
 	PERF_BR_CALL,		/* X86_BR_ZERO_CALL */
 	PERF_BR_UNKNOWN,	/* X86_BR_CALL_STACK */
 	PERF_BR_IND,		/* X86_BR_IND_JMP */
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 03b370062741..84e245d37ad4 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -253,6 +253,8 @@ enum {
 	PERF_BR_COND_RET	= 10,	/* conditional function return */
 	PERF_BR_ERET		= 11,	/* exception return */
 	PERF_BR_IRQ		= 12,	/* irq */
+	PERF_BR_SERROR		= 13,	/* system error */
+	PERF_BR_NO_TX		= 14,	/* not in transaction */
 	PERF_BR_MAX,
 };
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 1/8] perf: Add system error and not in transaction branch types
@ 2022-08-24  4:48   ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

This expands generic branch type classification by adding two more entries
there in i.e system error and not in transaction. This also updates the x86
implementation to process X86_BR_NO_TX records as appropriate. This changes
branch types reported to user space on x86 platform but it should not be a
problem. The possible scenarios and impacts are enumerated here.

--------------------------------------------------------------------------
| kernel | perf tool |                     Impact                        |
--------------------------------------------------------------------------
|   old  |    old    |  Works as before                                  |
--------------------------------------------------------------------------
|   old  |    new    |  PERF_BR_UNKNOWN is processed                     |
--------------------------------------------------------------------------
|   new  |    old    |  PERF_BR_NO_TX is blocked via old PERF_BR_MAX     |
--------------------------------------------------------------------------
|   new  |    new    |  PERF_BR_NO_TX is recognized                      |
--------------------------------------------------------------------------

When PERF_BR_NO_TX is blocked via old PERF_BR_MAX (new kernel with old perf
tool) the user space might throw up an warning complaining about an
unrecognized branch types being reported, but it's expected. PERF_BR_SERROR
& PERF_BR_NO_TX branch types will be used for BRBE implementation on arm64
platform.

PERF_BR_NO_TX complements 'abort' and 'in_tx' elements in perf_branch_entry
which represent other transaction states for a given branch record. Because
this completes the transaction state classification.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 arch/x86/events/intel/lbr.c     | 2 +-
 include/uapi/linux/perf_event.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c
index 4f70fb6c2c1e..30441dd4cf89 100644
--- a/arch/x86/events/intel/lbr.c
+++ b/arch/x86/events/intel/lbr.c
@@ -1334,7 +1334,7 @@ static int branch_map[X86_BR_TYPE_MAP_MAX] = {
 	PERF_BR_IND_CALL,	/* X86_BR_IND_CALL */
 	PERF_BR_UNKNOWN,	/* X86_BR_ABORT */
 	PERF_BR_UNKNOWN,	/* X86_BR_IN_TX */
-	PERF_BR_UNKNOWN,	/* X86_BR_NO_TX */
+	PERF_BR_NO_TX,		/* X86_BR_NO_TX */
 	PERF_BR_CALL,		/* X86_BR_ZERO_CALL */
 	PERF_BR_UNKNOWN,	/* X86_BR_CALL_STACK */
 	PERF_BR_IND,		/* X86_BR_IND_JMP */
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 03b370062741..84e245d37ad4 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -253,6 +253,8 @@ enum {
 	PERF_BR_COND_RET	= 10,	/* conditional function return */
 	PERF_BR_ERET		= 11,	/* exception return */
 	PERF_BR_IRQ		= 12,	/* irq */
+	PERF_BR_SERROR		= 13,	/* system error */
+	PERF_BR_NO_TX		= 14,	/* not in transaction */
 	PERF_BR_MAX,
 };
 
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 2/8] perf: Extend branch type classification
  2022-08-24  4:48 ` Anshuman Khandual
@ 2022-08-24  4:48   ` Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

branch_entry.type now has ran out of space to accommodate more branch types
classification. This will prevent perf branch stack implementation on arm64
(via BRBE) to capture all available branch types. Extending this bit field
i.e branch_entry.type [4 bits] is not an option as it will break user space
ABI both for little and big endian perf tools.

Extend branch classification with a new field branch_entry.new_type via a
new branch type PERF_BR_EXTEND_ABI in branch_entry.type. Perf tools which
could decode PERF_BR_EXTEND_ABI, will then parse branch_entry.new_type as
well.

branch_entry.new_type is a 4 bit field which can hold upto 16 branch types.
The first three branch types will hold various generic page faults followed
by five architecture specific branch types, which can be overridden by the
platform for specific use cases. These architecture specific branch types
gets overridden on arm64 platform for BRBE implementation.

New generic branch types

- PERF_BR_NEW_FAULT_ALGN
- PERF_BR_NEW_FAULT_DATA
- PERF_BR_NEW_FAULT_INST

New arch specific branch types

- PERF_BR_NEW_ARCH_1
- PERF_BR_NEW_ARCH_2
- PERF_BR_NEW_ARCH_3
- PERF_BR_NEW_ARCH_4
- PERF_BR_NEW_ARCH_5

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 include/uapi/linux/perf_event.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 84e245d37ad4..5fa1d5a467da 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -255,9 +255,22 @@ enum {
 	PERF_BR_IRQ		= 12,	/* irq */
 	PERF_BR_SERROR		= 13,	/* system error */
 	PERF_BR_NO_TX		= 14,	/* not in transaction */
+	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
 	PERF_BR_MAX,
 };
 
+enum {
+	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
+	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
+	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
+	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
+	PERF_BR_NEW_MAX,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1375,7 +1388,8 @@ struct perf_branch_entry {
 		abort:1,    /* transaction abort */
 		cycles:16,  /* cycle count to last branch */
 		type:4,     /* branch type */
-		reserved:40;
+		new_type:4, /* additional branch type */
+		reserved:36;
 };
 
 union perf_sample_weight {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 2/8] perf: Extend branch type classification
@ 2022-08-24  4:48   ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

branch_entry.type now has ran out of space to accommodate more branch types
classification. This will prevent perf branch stack implementation on arm64
(via BRBE) to capture all available branch types. Extending this bit field
i.e branch_entry.type [4 bits] is not an option as it will break user space
ABI both for little and big endian perf tools.

Extend branch classification with a new field branch_entry.new_type via a
new branch type PERF_BR_EXTEND_ABI in branch_entry.type. Perf tools which
could decode PERF_BR_EXTEND_ABI, will then parse branch_entry.new_type as
well.

branch_entry.new_type is a 4 bit field which can hold upto 16 branch types.
The first three branch types will hold various generic page faults followed
by five architecture specific branch types, which can be overridden by the
platform for specific use cases. These architecture specific branch types
gets overridden on arm64 platform for BRBE implementation.

New generic branch types

- PERF_BR_NEW_FAULT_ALGN
- PERF_BR_NEW_FAULT_DATA
- PERF_BR_NEW_FAULT_INST

New arch specific branch types

- PERF_BR_NEW_ARCH_1
- PERF_BR_NEW_ARCH_2
- PERF_BR_NEW_ARCH_3
- PERF_BR_NEW_ARCH_4
- PERF_BR_NEW_ARCH_5

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 include/uapi/linux/perf_event.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 84e245d37ad4..5fa1d5a467da 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -255,9 +255,22 @@ enum {
 	PERF_BR_IRQ		= 12,	/* irq */
 	PERF_BR_SERROR		= 13,	/* system error */
 	PERF_BR_NO_TX		= 14,	/* not in transaction */
+	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
 	PERF_BR_MAX,
 };
 
+enum {
+	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
+	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
+	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
+	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
+	PERF_BR_NEW_MAX,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1375,7 +1388,8 @@ struct perf_branch_entry {
 		abort:1,    /* transaction abort */
 		cycles:16,  /* cycle count to last branch */
 		type:4,     /* branch type */
-		reserved:40;
+		new_type:4, /* additional branch type */
+		reserved:36;
 };
 
 union perf_sample_weight {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 3/8] perf: Capture branch privilege information
  2022-08-24  4:48 ` Anshuman Khandual
@ 2022-08-24  4:48   ` Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Platforms like arm64 could capture privilege level information for all the
branch records. Hence this adds a new element in the struct branch_entry to
record the privilege level information, which could be requested through a
new event.attr.branch_sample_type based flag PERF_SAMPLE_BRANCH_PRIV_SAVE.
This flag helps user choose whether privilege information is captured.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 include/uapi/linux/perf_event.h | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 5fa1d5a467da..19e4b69d7297 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -204,6 +204,8 @@ enum perf_branch_sample_type_shift {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT	= 17, /* save low level index of raw branch records */
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT	= 18, /* save privilege mode */
+
 	PERF_SAMPLE_BRANCH_MAX_SHIFT		/* non-ABI */
 };
 
@@ -233,6 +235,8 @@ enum perf_branch_sample_type {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX	= 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE	= 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
+
 	PERF_SAMPLE_BRANCH_MAX		= 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
 };
 
@@ -271,6 +275,13 @@ enum {
 	PERF_BR_NEW_MAX,
 };
 
+enum {
+	PERF_BR_PRIV_UNKNOWN	= 0,
+	PERF_BR_PRIV_USER	= 1,
+	PERF_BR_PRIV_KERNEL	= 2,
+	PERF_BR_PRIV_HV		= 3,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1389,7 +1400,8 @@ struct perf_branch_entry {
 		cycles:16,  /* cycle count to last branch */
 		type:4,     /* branch type */
 		new_type:4, /* additional branch type */
-		reserved:36;
+		priv:3,     /* privilege level */
+		reserved:33;
 };
 
 union perf_sample_weight {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 3/8] perf: Capture branch privilege information
@ 2022-08-24  4:48   ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Platforms like arm64 could capture privilege level information for all the
branch records. Hence this adds a new element in the struct branch_entry to
record the privilege level information, which could be requested through a
new event.attr.branch_sample_type based flag PERF_SAMPLE_BRANCH_PRIV_SAVE.
This flag helps user choose whether privilege information is captured.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 include/uapi/linux/perf_event.h | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 5fa1d5a467da..19e4b69d7297 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -204,6 +204,8 @@ enum perf_branch_sample_type_shift {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT	= 17, /* save low level index of raw branch records */
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT	= 18, /* save privilege mode */
+
 	PERF_SAMPLE_BRANCH_MAX_SHIFT		/* non-ABI */
 };
 
@@ -233,6 +235,8 @@ enum perf_branch_sample_type {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX	= 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE	= 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
+
 	PERF_SAMPLE_BRANCH_MAX		= 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
 };
 
@@ -271,6 +275,13 @@ enum {
 	PERF_BR_NEW_MAX,
 };
 
+enum {
+	PERF_BR_PRIV_UNKNOWN	= 0,
+	PERF_BR_PRIV_USER	= 1,
+	PERF_BR_PRIV_KERNEL	= 2,
+	PERF_BR_PRIV_HV		= 3,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1389,7 +1400,8 @@ struct perf_branch_entry {
 		cycles:16,  /* cycle count to last branch */
 		type:4,     /* branch type */
 		new_type:4, /* additional branch type */
-		reserved:36;
+		priv:3,     /* privilege level */
+		reserved:33;
 };
 
 union perf_sample_weight {
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 4/8] perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
  2022-08-24  4:48 ` Anshuman Khandual
@ 2022-08-24  4:48   ` Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

BRBE captured branch types will overflow perf_branch_entry.type and generic
branch types in perf_branch_entry.new_type. So override each available arch
specific branch type in the following manner to comprehensively process all
reported branch types in BRBE.

PERF_BR_ARM64_FIQ            PERF_BR_NEW_ARCH_1
PERF_BR_ARM64_DEBUG_HALT     PERF_BR_NEW_ARCH_2
PERF_BR_ARM64_DEBUG_EXIT     PERF_BR_NEW_ARCH_3
PERF_BR_ARM64_DEBUG_INST     PERF_BR_NEW_ARCH_4
PERF_BR_ARM64_DEBUG_DATA     PERF_BR_NEW_ARCH_5

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 include/uapi/linux/perf_event.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 19e4b69d7297..e8c4a9716756 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -282,6 +282,12 @@ enum {
 	PERF_BR_PRIV_HV		= 3,
 };
 
+#define PERF_BR_ARM64_FIQ		PERF_BR_NEW_ARCH_1
+#define PERF_BR_ARM64_DEBUG_HALT	PERF_BR_NEW_ARCH_2
+#define PERF_BR_ARM64_DEBUG_EXIT	PERF_BR_NEW_ARCH_3
+#define PERF_BR_ARM64_DEBUG_INST	PERF_BR_NEW_ARCH_4
+#define PERF_BR_ARM64_DEBUG_DATA	PERF_BR_NEW_ARCH_5
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 4/8] perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
@ 2022-08-24  4:48   ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

BRBE captured branch types will overflow perf_branch_entry.type and generic
branch types in perf_branch_entry.new_type. So override each available arch
specific branch type in the following manner to comprehensively process all
reported branch types in BRBE.

PERF_BR_ARM64_FIQ            PERF_BR_NEW_ARCH_1
PERF_BR_ARM64_DEBUG_HALT     PERF_BR_NEW_ARCH_2
PERF_BR_ARM64_DEBUG_EXIT     PERF_BR_NEW_ARCH_3
PERF_BR_ARM64_DEBUG_INST     PERF_BR_NEW_ARCH_4
PERF_BR_ARM64_DEBUG_DATA     PERF_BR_NEW_ARCH_5

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 include/uapi/linux/perf_event.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 19e4b69d7297..e8c4a9716756 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -282,6 +282,12 @@ enum {
 	PERF_BR_PRIV_HV		= 3,
 };
 
+#define PERF_BR_ARM64_FIQ		PERF_BR_NEW_ARCH_1
+#define PERF_BR_ARM64_DEBUG_HALT	PERF_BR_NEW_ARCH_2
+#define PERF_BR_ARM64_DEBUG_EXIT	PERF_BR_NEW_ARCH_3
+#define PERF_BR_ARM64_DEBUG_INST	PERF_BR_NEW_ARCH_4
+#define PERF_BR_ARM64_DEBUG_DATA	PERF_BR_NEW_ARCH_5
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 5/8] perf/tools: Add system error and not in transaction branch types
  2022-08-24  4:48 ` Anshuman Khandual
@ 2022-08-24  4:48   ` Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

This updates the perf tool with generic branch type classification with two
new branch types i.e system error (PERF_BR_SERROR) and not in transaction
(PERF_BR_NO_TX) which got updated earlier in the kernel. This also updates
corresponding branch type strings in branch_type_name().

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 tools/include/uapi/linux/perf_event.h | 2 ++
 tools/perf/util/branch.c              | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index 581ed4bdc062..146c137ff0c1 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -253,6 +253,8 @@ enum {
 	PERF_BR_COND_RET	= 10,	/* conditional function return */
 	PERF_BR_ERET		= 11,	/* exception return */
 	PERF_BR_IRQ		= 12,	/* irq */
+	PERF_BR_SERROR		= 13,	/* system error */
+	PERF_BR_NO_TX		= 14,	/* not in transaction */
 	PERF_BR_MAX,
 };
 
diff --git a/tools/perf/util/branch.c b/tools/perf/util/branch.c
index a9a909db8cc7..abc673347bee 100644
--- a/tools/perf/util/branch.c
+++ b/tools/perf/util/branch.c
@@ -51,7 +51,9 @@ const char *branch_type_name(int type)
 		"COND_CALL",
 		"COND_RET",
 		"ERET",
-		"IRQ"
+		"IRQ",
+		"SERROR",
+		"NO_TX"
 	};
 
 	if (type >= 0 && type < PERF_BR_MAX)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 5/8] perf/tools: Add system error and not in transaction branch types
@ 2022-08-24  4:48   ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

This updates the perf tool with generic branch type classification with two
new branch types i.e system error (PERF_BR_SERROR) and not in transaction
(PERF_BR_NO_TX) which got updated earlier in the kernel. This also updates
corresponding branch type strings in branch_type_name().

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 tools/include/uapi/linux/perf_event.h | 2 ++
 tools/perf/util/branch.c              | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index 581ed4bdc062..146c137ff0c1 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -253,6 +253,8 @@ enum {
 	PERF_BR_COND_RET	= 10,	/* conditional function return */
 	PERF_BR_ERET		= 11,	/* exception return */
 	PERF_BR_IRQ		= 12,	/* irq */
+	PERF_BR_SERROR		= 13,	/* system error */
+	PERF_BR_NO_TX		= 14,	/* not in transaction */
 	PERF_BR_MAX,
 };
 
diff --git a/tools/perf/util/branch.c b/tools/perf/util/branch.c
index a9a909db8cc7..abc673347bee 100644
--- a/tools/perf/util/branch.c
+++ b/tools/perf/util/branch.c
@@ -51,7 +51,9 @@ const char *branch_type_name(int type)
 		"COND_CALL",
 		"COND_RET",
 		"ERET",
-		"IRQ"
+		"IRQ",
+		"SERROR",
+		"NO_TX"
 	};
 
 	if (type >= 0 && type < PERF_BR_MAX)
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 6/8] perf/tools: Extend branch type classification
  2022-08-24  4:48 ` Anshuman Khandual
@ 2022-08-24  4:48   ` Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

This updates the perf tool with generic branch type classification with new
ABI extender place holder i.e PERF_BR_EXTEND_ABI, the new 4 bit branch type
field i.e perf_branch_entry.new_type, new generic page fault related branch
types and some arch specific branch types as added earlier in the kernel.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 tools/include/uapi/linux/perf_event.h | 16 ++++++++-
 tools/perf/builtin-script.c           |  2 +-
 tools/perf/util/branch.c              | 52 ++++++++++++++++++++++++++-
 tools/perf/util/branch.h              |  6 +++-
 tools/perf/util/session.c             |  2 +-
 5 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index 146c137ff0c1..0f7c7ce29899 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -255,9 +255,22 @@ enum {
 	PERF_BR_IRQ		= 12,	/* irq */
 	PERF_BR_SERROR		= 13,	/* system error */
 	PERF_BR_NO_TX		= 14,	/* not in transaction */
+	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
 	PERF_BR_MAX,
 };
 
+enum {
+	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
+	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
+	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
+	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
+	PERF_BR_NEW_MAX,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1375,7 +1388,8 @@ struct perf_branch_entry {
 		abort:1,    /* transaction abort */
 		cycles:16,  /* cycle count to last branch */
 		type:4,     /* branch type */
-		reserved:40;
+		new_type:4, /* additional branch type */
+		reserved:36;
 };
 
 union perf_sample_weight {
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 13580a9c50b8..585171479876 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -877,7 +877,7 @@ static int print_bstack_flags(FILE *fp, struct branch_entry *br)
 		       br->flags.in_tx ? 'X' : '-',
 		       br->flags.abort ? 'A' : '-',
 		       br->flags.cycles,
-		       br->flags.type ? branch_type_name(br->flags.type) : "-");
+		       get_branch_type(br));
 }
 
 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 abc673347bee..6d962b0a4532 100644
--- a/tools/perf/util/branch.c
+++ b/tools/perf/util/branch.c
@@ -21,7 +21,10 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
 	if (flags->type == PERF_BR_UNKNOWN || from == 0)
 		return;
 
-	st->counts[flags->type]++;
+	if (flags->type == PERF_BR_EXTEND_ABI)
+		st->new_counts[flags->new_type]++;
+	else
+		st->counts[flags->type]++;
 
 	if (flags->type == PERF_BR_COND) {
 		if (to > from)
@@ -36,6 +39,25 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
 		st->cross_4k++;
 }
 
+const char *branch_new_type_name(int new_type)
+{
+	const char *branch_new_names[PERF_BR_NEW_MAX] = {
+		"FAULT_ALGN",
+		"FAULT_DATA",
+		"FAULT_INST",
+		"ARCH_1",
+		"ARCH_2",
+		"ARCH_3",
+		"ARCH_4",
+		"ARCH_5"
+	};
+
+	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
+		return branch_new_names[new_type];
+
+	return NULL;
+}
+
 const char *branch_type_name(int type)
 {
 	const char *branch_names[PERF_BR_MAX] = {
@@ -62,6 +84,17 @@ const char *branch_type_name(int type)
 	return NULL;
 }
 
+const char *get_branch_type(struct branch_entry *e)
+{
+	if (e->flags.type == PERF_BR_UNKNOWN)
+		return "";
+
+	if (e->flags.type == PERF_BR_EXTEND_ABI)
+		return branch_new_type_name(e->flags.new_type);
+
+	return branch_type_name(e->flags.type);
+}
+
 void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
 {
 	u64 total = 0;
@@ -108,6 +141,15 @@ void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
 				100.0 *
 				(double)st->counts[i] / (double)total);
 	}
+
+	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
+		if (st->new_counts[i] > 0)
+			fprintf(fp, "\n%8s: %5.1f%%",
+				branch_new_type_name(i),
+				100.0 *
+				(double)st->new_counts[i] / (double)total);
+	}
+
 }
 
 static int count_str_scnprintf(int idx, const char *str, char *bf, int size)
@@ -123,6 +165,9 @@ int branch_type_str(struct branch_type_stat *st, char *bf, int size)
 	for (i = 0; i < PERF_BR_MAX; i++)
 		total += st->counts[i];
 
+	for (i = 0; i < PERF_BR_NEW_MAX; i++)
+		total += st->new_counts[i];
+
 	if (total == 0)
 		return 0;
 
@@ -140,6 +185,11 @@ int branch_type_str(struct branch_type_stat *st, char *bf, int size)
 			printed += count_str_scnprintf(j++, branch_type_name(i), bf + printed, size - printed);
 	}
 
+	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
+		if (st->new_counts[i] > 0)
+			printed += count_str_scnprintf(j++, branch_new_type_name(i), bf + printed, size - printed);
+	}
+
 	if (st->cross_4k > 0)
 		printed += count_str_scnprintf(j++, "CROSS_4K", bf + printed, size - printed);
 
diff --git a/tools/perf/util/branch.h b/tools/perf/util/branch.h
index 17b2ccc61094..8d251b35428a 100644
--- a/tools/perf/util/branch.h
+++ b/tools/perf/util/branch.h
@@ -24,7 +24,8 @@ struct branch_flags {
 			u64 abort:1;
 			u64 cycles:16;
 			u64 type:4;
-			u64 reserved:40;
+			u64 new_type:4;
+			u64 reserved:36;
 		};
 	};
 };
@@ -72,6 +73,7 @@ static inline struct branch_entry *perf_sample__branch_entries(struct perf_sampl
 struct branch_type_stat {
 	bool	branch_to;
 	u64	counts[PERF_BR_MAX];
+	u64	new_counts[PERF_BR_NEW_MAX];
 	u64	cond_fwd;
 	u64	cond_bwd;
 	u64	cross_4k;
@@ -82,6 +84,8 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
 		       u64 from, u64 to);
 
 const char *branch_type_name(int type);
+const char *branch_new_type_name(int new_type);
+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);
 
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 192c9274f7ad..47d5a50e616a 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1180,7 +1180,7 @@ static void branch_stack__printf(struct perf_sample *sample, bool callstack)
 				e->flags.abort ? "A" : " ",
 				e->flags.in_tx ? "T" : " ",
 				(unsigned)e->flags.reserved,
-				e->flags.type ? branch_type_name(e->flags.type) : "");
+				get_branch_type(e));
 		} else {
 			if (i == 0) {
 				printf("..... %2"PRIu64": %016" PRIx64 "\n"
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 6/8] perf/tools: Extend branch type classification
@ 2022-08-24  4:48   ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

This updates the perf tool with generic branch type classification with new
ABI extender place holder i.e PERF_BR_EXTEND_ABI, the new 4 bit branch type
field i.e perf_branch_entry.new_type, new generic page fault related branch
types and some arch specific branch types as added earlier in the kernel.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 tools/include/uapi/linux/perf_event.h | 16 ++++++++-
 tools/perf/builtin-script.c           |  2 +-
 tools/perf/util/branch.c              | 52 ++++++++++++++++++++++++++-
 tools/perf/util/branch.h              |  6 +++-
 tools/perf/util/session.c             |  2 +-
 5 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index 146c137ff0c1..0f7c7ce29899 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -255,9 +255,22 @@ enum {
 	PERF_BR_IRQ		= 12,	/* irq */
 	PERF_BR_SERROR		= 13,	/* system error */
 	PERF_BR_NO_TX		= 14,	/* not in transaction */
+	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
 	PERF_BR_MAX,
 };
 
+enum {
+	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
+	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
+	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
+	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
+	PERF_BR_NEW_MAX,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1375,7 +1388,8 @@ struct perf_branch_entry {
 		abort:1,    /* transaction abort */
 		cycles:16,  /* cycle count to last branch */
 		type:4,     /* branch type */
-		reserved:40;
+		new_type:4, /* additional branch type */
+		reserved:36;
 };
 
 union perf_sample_weight {
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 13580a9c50b8..585171479876 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -877,7 +877,7 @@ static int print_bstack_flags(FILE *fp, struct branch_entry *br)
 		       br->flags.in_tx ? 'X' : '-',
 		       br->flags.abort ? 'A' : '-',
 		       br->flags.cycles,
-		       br->flags.type ? branch_type_name(br->flags.type) : "-");
+		       get_branch_type(br));
 }
 
 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 abc673347bee..6d962b0a4532 100644
--- a/tools/perf/util/branch.c
+++ b/tools/perf/util/branch.c
@@ -21,7 +21,10 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
 	if (flags->type == PERF_BR_UNKNOWN || from == 0)
 		return;
 
-	st->counts[flags->type]++;
+	if (flags->type == PERF_BR_EXTEND_ABI)
+		st->new_counts[flags->new_type]++;
+	else
+		st->counts[flags->type]++;
 
 	if (flags->type == PERF_BR_COND) {
 		if (to > from)
@@ -36,6 +39,25 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
 		st->cross_4k++;
 }
 
+const char *branch_new_type_name(int new_type)
+{
+	const char *branch_new_names[PERF_BR_NEW_MAX] = {
+		"FAULT_ALGN",
+		"FAULT_DATA",
+		"FAULT_INST",
+		"ARCH_1",
+		"ARCH_2",
+		"ARCH_3",
+		"ARCH_4",
+		"ARCH_5"
+	};
+
+	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
+		return branch_new_names[new_type];
+
+	return NULL;
+}
+
 const char *branch_type_name(int type)
 {
 	const char *branch_names[PERF_BR_MAX] = {
@@ -62,6 +84,17 @@ const char *branch_type_name(int type)
 	return NULL;
 }
 
+const char *get_branch_type(struct branch_entry *e)
+{
+	if (e->flags.type == PERF_BR_UNKNOWN)
+		return "";
+
+	if (e->flags.type == PERF_BR_EXTEND_ABI)
+		return branch_new_type_name(e->flags.new_type);
+
+	return branch_type_name(e->flags.type);
+}
+
 void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
 {
 	u64 total = 0;
@@ -108,6 +141,15 @@ void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
 				100.0 *
 				(double)st->counts[i] / (double)total);
 	}
+
+	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
+		if (st->new_counts[i] > 0)
+			fprintf(fp, "\n%8s: %5.1f%%",
+				branch_new_type_name(i),
+				100.0 *
+				(double)st->new_counts[i] / (double)total);
+	}
+
 }
 
 static int count_str_scnprintf(int idx, const char *str, char *bf, int size)
@@ -123,6 +165,9 @@ int branch_type_str(struct branch_type_stat *st, char *bf, int size)
 	for (i = 0; i < PERF_BR_MAX; i++)
 		total += st->counts[i];
 
+	for (i = 0; i < PERF_BR_NEW_MAX; i++)
+		total += st->new_counts[i];
+
 	if (total == 0)
 		return 0;
 
@@ -140,6 +185,11 @@ int branch_type_str(struct branch_type_stat *st, char *bf, int size)
 			printed += count_str_scnprintf(j++, branch_type_name(i), bf + printed, size - printed);
 	}
 
+	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
+		if (st->new_counts[i] > 0)
+			printed += count_str_scnprintf(j++, branch_new_type_name(i), bf + printed, size - printed);
+	}
+
 	if (st->cross_4k > 0)
 		printed += count_str_scnprintf(j++, "CROSS_4K", bf + printed, size - printed);
 
diff --git a/tools/perf/util/branch.h b/tools/perf/util/branch.h
index 17b2ccc61094..8d251b35428a 100644
--- a/tools/perf/util/branch.h
+++ b/tools/perf/util/branch.h
@@ -24,7 +24,8 @@ struct branch_flags {
 			u64 abort:1;
 			u64 cycles:16;
 			u64 type:4;
-			u64 reserved:40;
+			u64 new_type:4;
+			u64 reserved:36;
 		};
 	};
 };
@@ -72,6 +73,7 @@ static inline struct branch_entry *perf_sample__branch_entries(struct perf_sampl
 struct branch_type_stat {
 	bool	branch_to;
 	u64	counts[PERF_BR_MAX];
+	u64	new_counts[PERF_BR_NEW_MAX];
 	u64	cond_fwd;
 	u64	cond_bwd;
 	u64	cross_4k;
@@ -82,6 +84,8 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
 		       u64 from, u64 to);
 
 const char *branch_type_name(int type);
+const char *branch_new_type_name(int new_type);
+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);
 
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 192c9274f7ad..47d5a50e616a 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1180,7 +1180,7 @@ static void branch_stack__printf(struct perf_sample *sample, bool callstack)
 				e->flags.abort ? "A" : " ",
 				e->flags.in_tx ? "T" : " ",
 				(unsigned)e->flags.reserved,
-				e->flags.type ? branch_type_name(e->flags.type) : "");
+				get_branch_type(e));
 		} else {
 			if (i == 0) {
 				printf("..... %2"PRIu64": %016" PRIx64 "\n"
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 7/8] perf/tools: Add branch privilege information request flag
  2022-08-24  4:48 ` Anshuman Khandual
@ 2022-08-24  4:48   ` Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

This updates the perf tools with branch privilege information request flag
i.e PERF_SAMPLE_BRANCH_PRIV_SAVE that has been added earlier in the kernel.
This also updates 'perf record' documentation, branch_modes[], and generic
branch privilege level enumeration as added earlier in the kernel.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 tools/include/uapi/linux/perf_event.h     | 14 +++++++++++++-
 tools/perf/Documentation/perf-record.txt  |  1 +
 tools/perf/util/branch.h                  |  3 ++-
 tools/perf/util/parse-branch-options.c    |  1 +
 tools/perf/util/perf_event_attr_fprintf.c |  2 +-
 5 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index 0f7c7ce29899..51168e22f4d8 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -204,6 +204,8 @@ enum perf_branch_sample_type_shift {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT	= 17, /* save low level index of raw branch records */
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT	= 18, /* save privilege mode */
+
 	PERF_SAMPLE_BRANCH_MAX_SHIFT		/* non-ABI */
 };
 
@@ -233,6 +235,8 @@ enum perf_branch_sample_type {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX	= 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE	= 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
+
 	PERF_SAMPLE_BRANCH_MAX		= 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
 };
 
@@ -271,6 +275,13 @@ enum {
 	PERF_BR_NEW_MAX,
 };
 
+enum {
+	PERF_BR_PRIV_UNKNOWN	= 0,
+	PERF_BR_PRIV_USER	= 1,
+	PERF_BR_PRIV_KERNEL	= 2,
+	PERF_BR_PRIV_HV		= 3,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1389,7 +1400,8 @@ struct perf_branch_entry {
 		cycles:16,  /* cycle count to last branch */
 		type:4,     /* branch type */
 		new_type:4, /* additional branch type */
-		reserved:36;
+		priv:3,     /* privilege level */
+		reserved:33;
 };
 
 union perf_sample_weight {
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 099817ef5150..4d4a9f6e5147 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -397,6 +397,7 @@ following filters are defined:
 	- abort_tx: only when the target is a hardware transaction abort
 	- cond: conditional branches
 	- save_type: save branch type during sampling in case binary is not available later
+	- priv: save privilege state during sampling in case binary is not available later
 
 +
 The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
diff --git a/tools/perf/util/branch.h b/tools/perf/util/branch.h
index 8d251b35428a..f838b23db180 100644
--- a/tools/perf/util/branch.h
+++ b/tools/perf/util/branch.h
@@ -25,7 +25,8 @@ struct branch_flags {
 			u64 cycles:16;
 			u64 type:4;
 			u64 new_type:4;
-			u64 reserved:36;
+			u64 priv:3;
+			u64 reserved:33;
 		};
 	};
 };
diff --git a/tools/perf/util/parse-branch-options.c b/tools/perf/util/parse-branch-options.c
index bb4aa88c50a8..00588b9db474 100644
--- a/tools/perf/util/parse-branch-options.c
+++ b/tools/perf/util/parse-branch-options.c
@@ -32,6 +32,7 @@ static const struct branch_mode branch_modes[] = {
 	BRANCH_OPT("call", PERF_SAMPLE_BRANCH_CALL),
 	BRANCH_OPT("save_type", PERF_SAMPLE_BRANCH_TYPE_SAVE),
 	BRANCH_OPT("stack", PERF_SAMPLE_BRANCH_CALL_STACK),
+	BRANCH_OPT("priv", PERF_SAMPLE_BRANCH_PRIV_SAVE),
 	BRANCH_END
 };
 
diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c
index 98af3fa4ea35..4b0db27b7199 100644
--- a/tools/perf/util/perf_event_attr_fprintf.c
+++ b/tools/perf/util/perf_event_attr_fprintf.c
@@ -52,7 +52,7 @@ static void __p_branch_sample_type(char *buf, size_t size, u64 value)
 		bit_name(ABORT_TX), bit_name(IN_TX), bit_name(NO_TX),
 		bit_name(COND), bit_name(CALL_STACK), bit_name(IND_JUMP),
 		bit_name(CALL), bit_name(NO_FLAGS), bit_name(NO_CYCLES),
-		bit_name(TYPE_SAVE), bit_name(HW_INDEX),
+		bit_name(TYPE_SAVE), bit_name(HW_INDEX), bit_name(PRIV_SAVE),
 		{ .name = NULL, }
 	};
 #undef bit_name
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 7/8] perf/tools: Add branch privilege information request flag
@ 2022-08-24  4:48   ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

This updates the perf tools with branch privilege information request flag
i.e PERF_SAMPLE_BRANCH_PRIV_SAVE that has been added earlier in the kernel.
This also updates 'perf record' documentation, branch_modes[], and generic
branch privilege level enumeration as added earlier in the kernel.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 tools/include/uapi/linux/perf_event.h     | 14 +++++++++++++-
 tools/perf/Documentation/perf-record.txt  |  1 +
 tools/perf/util/branch.h                  |  3 ++-
 tools/perf/util/parse-branch-options.c    |  1 +
 tools/perf/util/perf_event_attr_fprintf.c |  2 +-
 5 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index 0f7c7ce29899..51168e22f4d8 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -204,6 +204,8 @@ enum perf_branch_sample_type_shift {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT	= 17, /* save low level index of raw branch records */
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT	= 18, /* save privilege mode */
+
 	PERF_SAMPLE_BRANCH_MAX_SHIFT		/* non-ABI */
 };
 
@@ -233,6 +235,8 @@ enum perf_branch_sample_type {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX	= 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE	= 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
+
 	PERF_SAMPLE_BRANCH_MAX		= 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
 };
 
@@ -271,6 +275,13 @@ enum {
 	PERF_BR_NEW_MAX,
 };
 
+enum {
+	PERF_BR_PRIV_UNKNOWN	= 0,
+	PERF_BR_PRIV_USER	= 1,
+	PERF_BR_PRIV_KERNEL	= 2,
+	PERF_BR_PRIV_HV		= 3,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1389,7 +1400,8 @@ struct perf_branch_entry {
 		cycles:16,  /* cycle count to last branch */
 		type:4,     /* branch type */
 		new_type:4, /* additional branch type */
-		reserved:36;
+		priv:3,     /* privilege level */
+		reserved:33;
 };
 
 union perf_sample_weight {
diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 099817ef5150..4d4a9f6e5147 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -397,6 +397,7 @@ following filters are defined:
 	- abort_tx: only when the target is a hardware transaction abort
 	- cond: conditional branches
 	- save_type: save branch type during sampling in case binary is not available later
+	- priv: save privilege state during sampling in case binary is not available later
 
 +
 The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
diff --git a/tools/perf/util/branch.h b/tools/perf/util/branch.h
index 8d251b35428a..f838b23db180 100644
--- a/tools/perf/util/branch.h
+++ b/tools/perf/util/branch.h
@@ -25,7 +25,8 @@ struct branch_flags {
 			u64 cycles:16;
 			u64 type:4;
 			u64 new_type:4;
-			u64 reserved:36;
+			u64 priv:3;
+			u64 reserved:33;
 		};
 	};
 };
diff --git a/tools/perf/util/parse-branch-options.c b/tools/perf/util/parse-branch-options.c
index bb4aa88c50a8..00588b9db474 100644
--- a/tools/perf/util/parse-branch-options.c
+++ b/tools/perf/util/parse-branch-options.c
@@ -32,6 +32,7 @@ static const struct branch_mode branch_modes[] = {
 	BRANCH_OPT("call", PERF_SAMPLE_BRANCH_CALL),
 	BRANCH_OPT("save_type", PERF_SAMPLE_BRANCH_TYPE_SAVE),
 	BRANCH_OPT("stack", PERF_SAMPLE_BRANCH_CALL_STACK),
+	BRANCH_OPT("priv", PERF_SAMPLE_BRANCH_PRIV_SAVE),
 	BRANCH_END
 };
 
diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c
index 98af3fa4ea35..4b0db27b7199 100644
--- a/tools/perf/util/perf_event_attr_fprintf.c
+++ b/tools/perf/util/perf_event_attr_fprintf.c
@@ -52,7 +52,7 @@ static void __p_branch_sample_type(char *buf, size_t size, u64 value)
 		bit_name(ABORT_TX), bit_name(IN_TX), bit_name(NO_TX),
 		bit_name(COND), bit_name(CALL_STACK), bit_name(IND_JUMP),
 		bit_name(CALL), bit_name(NO_FLAGS), bit_name(NO_CYCLES),
-		bit_name(TYPE_SAVE), bit_name(HW_INDEX),
+		bit_name(TYPE_SAVE), bit_name(HW_INDEX), bit_name(PRIV_SAVE),
 		{ .name = NULL, }
 	};
 #undef bit_name
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 8/8] perf/tools: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
  2022-08-24  4:48 ` Anshuman Khandual
@ 2022-08-24  4:48   ` Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

This updates the perf tool with arch specific branch type classification
used for BRBE on arm64 platform as added in the kernel earlier.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 tools/include/uapi/linux/perf_event.h |  6 ++++++
 tools/perf/util/branch.c              | 13 +++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index 51168e22f4d8..c2230c5aa1c7 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -282,6 +282,12 @@ enum {
 	PERF_BR_PRIV_HV		= 3,
 };
 
+#define PERF_BR_ARM64_FIQ		PERF_BR_NEW_ARCH_1
+#define PERF_BR_ARM64_DEBUG_HALT	PERF_BR_NEW_ARCH_2
+#define PERF_BR_ARM64_DEBUG_EXIT	PERF_BR_NEW_ARCH_3
+#define PERF_BR_ARM64_DEBUG_INST	PERF_BR_NEW_ARCH_4
+#define PERF_BR_ARM64_DEBUG_DATA	PERF_BR_NEW_ARCH_5
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
diff --git a/tools/perf/util/branch.c b/tools/perf/util/branch.c
index 6d962b0a4532..d40776c44b06 100644
--- a/tools/perf/util/branch.c
+++ b/tools/perf/util/branch.c
@@ -45,11 +45,24 @@ const char *branch_new_type_name(int new_type)
 		"FAULT_ALGN",
 		"FAULT_DATA",
 		"FAULT_INST",
+/*
+ * TODO: This switch should happen on 'session->header.env.arch'
+ * instead, because an arm64 platform perf recording could be
+ * opened for analysis on other platforms as well.
+ */
+#ifdef __aarch64__
+		"ARM64_FIQ",
+		"ARM64_DEBUG_HALT",
+		"ARM64_DEBUG_EXIT",
+		"ARM64_DEBUG_INST",
+		"ARM64_DEBUG_DATA"
+#else
 		"ARCH_1",
 		"ARCH_2",
 		"ARCH_3",
 		"ARCH_4",
 		"ARCH_5"
+#endif
 	};
 
 	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [PATCH V7 8/8] perf/tools: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
@ 2022-08-24  4:48   ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-24  4:48 UTC (permalink / raw)
  To: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, acme, mark.rutland
  Cc: Anshuman Khandual, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

This updates the perf tool with arch specific branch type classification
used for BRBE on arm64 platform as added in the kernel earlier.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
 tools/include/uapi/linux/perf_event.h |  6 ++++++
 tools/perf/util/branch.c              | 13 +++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
index 51168e22f4d8..c2230c5aa1c7 100644
--- a/tools/include/uapi/linux/perf_event.h
+++ b/tools/include/uapi/linux/perf_event.h
@@ -282,6 +282,12 @@ enum {
 	PERF_BR_PRIV_HV		= 3,
 };
 
+#define PERF_BR_ARM64_FIQ		PERF_BR_NEW_ARCH_1
+#define PERF_BR_ARM64_DEBUG_HALT	PERF_BR_NEW_ARCH_2
+#define PERF_BR_ARM64_DEBUG_EXIT	PERF_BR_NEW_ARCH_3
+#define PERF_BR_ARM64_DEBUG_INST	PERF_BR_NEW_ARCH_4
+#define PERF_BR_ARM64_DEBUG_DATA	PERF_BR_NEW_ARCH_5
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
diff --git a/tools/perf/util/branch.c b/tools/perf/util/branch.c
index 6d962b0a4532..d40776c44b06 100644
--- a/tools/perf/util/branch.c
+++ b/tools/perf/util/branch.c
@@ -45,11 +45,24 @@ const char *branch_new_type_name(int new_type)
 		"FAULT_ALGN",
 		"FAULT_DATA",
 		"FAULT_INST",
+/*
+ * TODO: This switch should happen on 'session->header.env.arch'
+ * instead, because an arm64 platform perf recording could be
+ * opened for analysis on other platforms as well.
+ */
+#ifdef __aarch64__
+		"ARM64_FIQ",
+		"ARM64_DEBUG_HALT",
+		"ARM64_DEBUG_EXIT",
+		"ARM64_DEBUG_INST",
+		"ARM64_DEBUG_DATA"
+#else
 		"ARCH_1",
 		"ARCH_2",
 		"ARCH_3",
 		"ARCH_4",
 		"ARCH_5"
+#endif
 	};
 
 	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 0/8] perf: Expand perf_branch_entry
  2022-08-24  4:48 ` Anshuman Khandual
@ 2022-08-25 10:22   ` Peter Zijlstra
  -1 siblings, 0 replies; 40+ messages in thread
From: Peter Zijlstra @ 2022-08-25 10:22 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-kernel, linux-perf-users, alexander.shishkin, jolsa, acme,
	mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

On Wed, Aug 24, 2022 at 10:18:14AM +0530, Anshuman Khandual wrote:
> Anshuman Khandual (8):
>   perf: Add system error and not in transaction branch types
>   perf: Extend branch type classification
>   perf: Capture branch privilege information
>   perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform

I picked up these first 4 and rebased them on top of the recent AMD LBR
patches.

They live in:

  git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git perf/core

for robot exposure. If all goes well they'll land in -tip.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 0/8] perf: Expand perf_branch_entry
@ 2022-08-25 10:22   ` Peter Zijlstra
  0 siblings, 0 replies; 40+ messages in thread
From: Peter Zijlstra @ 2022-08-25 10:22 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-kernel, linux-perf-users, alexander.shishkin, jolsa, acme,
	mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

On Wed, Aug 24, 2022 at 10:18:14AM +0530, Anshuman Khandual wrote:
> Anshuman Khandual (8):
>   perf: Add system error and not in transaction branch types
>   perf: Extend branch type classification
>   perf: Capture branch privilege information
>   perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform

I picked up these first 4 and rebased them on top of the recent AMD LBR
patches.

They live in:

  git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git perf/core

for robot exposure. If all goes well they'll land in -tip.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [tip: perf/core] perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
  2022-08-24  4:48   ` Anshuman Khandual
  (?)
@ 2022-08-26 22:15   ` tip-bot2 for Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: tip-bot2 for Anshuman Khandual @ 2022-08-26 22:15 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Anshuman Khandual, Peter Zijlstra (Intel),
	James Clark, x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     3051ee34ccb5a821bc46ef06639ff275e9c810b7
Gitweb:        https://git.kernel.org/tip/3051ee34ccb5a821bc46ef06639ff275e9c810b7
Author:        Anshuman Khandual <anshuman.khandual@arm.com>
AuthorDate:    Wed, 24 Aug 2022 10:18:18 +05:30
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Sat, 27 Aug 2022 00:05:47 +02:00

perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform

BRBE captured branch types will overflow perf_branch_entry.type and generic
branch types in perf_branch_entry.new_type. So override each available arch
specific branch type in the following manner to comprehensively process all
reported branch types in BRBE.

PERF_BR_ARM64_FIQ            PERF_BR_NEW_ARCH_1
PERF_BR_ARM64_DEBUG_HALT     PERF_BR_NEW_ARCH_2
PERF_BR_ARM64_DEBUG_EXIT     PERF_BR_NEW_ARCH_3
PERF_BR_ARM64_DEBUG_INST     PERF_BR_NEW_ARCH_4
PERF_BR_ARM64_DEBUG_DATA     PERF_BR_NEW_ARCH_5

Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: James Clark <james.clark@arm.com>
Link: https://lkml.kernel.org/r/20220824044822.70230-5-anshuman.khandual@arm.com
---
 include/uapi/linux/perf_event.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 1a258d4..dca1658 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -293,6 +293,12 @@ enum {
 	PERF_BR_PRIV_HV		= 3,
 };
 
+#define PERF_BR_ARM64_FIQ		PERF_BR_NEW_ARCH_1
+#define PERF_BR_ARM64_DEBUG_HALT	PERF_BR_NEW_ARCH_2
+#define PERF_BR_ARM64_DEBUG_EXIT	PERF_BR_NEW_ARCH_3
+#define PERF_BR_ARM64_DEBUG_INST	PERF_BR_NEW_ARCH_4
+#define PERF_BR_ARM64_DEBUG_DATA	PERF_BR_NEW_ARCH_5
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [tip: perf/core] perf: Capture branch privilege information
  2022-08-24  4:48   ` Anshuman Khandual
  (?)
@ 2022-08-26 22:15   ` tip-bot2 for Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: tip-bot2 for Anshuman Khandual @ 2022-08-26 22:15 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Anshuman Khandual, Peter Zijlstra (Intel),
	James Clark, x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     7203d4a5c19fc13c5229c4c1a08a5f9222207230
Gitweb:        https://git.kernel.org/tip/7203d4a5c19fc13c5229c4c1a08a5f9222207230
Author:        Anshuman Khandual <anshuman.khandual@arm.com>
AuthorDate:    Wed, 24 Aug 2022 10:18:17 +05:30
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Sat, 27 Aug 2022 00:05:47 +02:00

perf: Capture branch privilege information

Platforms like arm64 could capture privilege level information for all the
branch records. Hence this adds a new element in the struct branch_entry to
record the privilege level information, which could be requested through a
new event.attr.branch_sample_type based flag PERF_SAMPLE_BRANCH_PRIV_SAVE.
This flag helps user choose whether privilege information is captured.

Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: James Clark <james.clark@arm.com>
Link: https://lkml.kernel.org/r/20220824044822.70230-4-anshuman.khandual@arm.com
---
 include/uapi/linux/perf_event.h | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index fed60e6..1a258d4 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -204,6 +204,8 @@ enum perf_branch_sample_type_shift {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT	= 17, /* save low level index of raw branch records */
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT	= 18, /* save privilege mode */
+
 	PERF_SAMPLE_BRANCH_MAX_SHIFT		/* non-ABI */
 };
 
@@ -233,6 +235,8 @@ enum perf_branch_sample_type {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX	= 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE	= 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
+
 	PERF_SAMPLE_BRANCH_MAX		= 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
 };
 
@@ -282,6 +286,13 @@ enum {
 	PERF_BR_NEW_MAX,
 };
 
+enum {
+	PERF_BR_PRIV_UNKNOWN	= 0,
+	PERF_BR_PRIV_USER	= 1,
+	PERF_BR_PRIV_KERNEL	= 2,
+	PERF_BR_PRIV_HV		= 3,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1402,7 +1413,8 @@ struct perf_branch_entry {
 		type:4,     /* branch type */
 		spec:2,     /* branch speculation info */
 		new_type:4, /* additional branch type */
-		reserved:34;
+		priv:3,     /* privilege level */
+		reserved:31;
 };
 
 union perf_sample_weight {

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [tip: perf/core] perf: Extend branch type classification
  2022-08-24  4:48   ` Anshuman Khandual
  (?)
@ 2022-08-26 22:15   ` tip-bot2 for Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: tip-bot2 for Anshuman Khandual @ 2022-08-26 22:15 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Anshuman Khandual, Peter Zijlstra (Intel),
	James Clark, x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     082252a6ee5d35fddcc44ce4bc1a176496749d98
Gitweb:        https://git.kernel.org/tip/082252a6ee5d35fddcc44ce4bc1a176496749d98
Author:        Anshuman Khandual <anshuman.khandual@arm.com>
AuthorDate:    Wed, 24 Aug 2022 10:18:16 +05:30
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Sat, 27 Aug 2022 00:05:46 +02:00

perf: Extend branch type classification

branch_entry.type now has ran out of space to accommodate more branch types
classification. This will prevent perf branch stack implementation on arm64
(via BRBE) to capture all available branch types. Extending this bit field
i.e branch_entry.type [4 bits] is not an option as it will break user space
ABI both for little and big endian perf tools.

Extend branch classification with a new field branch_entry.new_type via a
new branch type PERF_BR_EXTEND_ABI in branch_entry.type. Perf tools which
could decode PERF_BR_EXTEND_ABI, will then parse branch_entry.new_type as
well.

branch_entry.new_type is a 4 bit field which can hold upto 16 branch types.
The first three branch types will hold various generic page faults followed
by five architecture specific branch types, which can be overridden by the
platform for specific use cases. These architecture specific branch types
gets overridden on arm64 platform for BRBE implementation.

New generic branch types

- PERF_BR_NEW_FAULT_ALGN
- PERF_BR_NEW_FAULT_DATA
- PERF_BR_NEW_FAULT_INST

New arch specific branch types

- PERF_BR_NEW_ARCH_1
- PERF_BR_NEW_ARCH_2
- PERF_BR_NEW_ARCH_3
- PERF_BR_NEW_ARCH_4
- PERF_BR_NEW_ARCH_5

Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: James Clark <james.clark@arm.com>
Link: https://lkml.kernel.org/r/20220824044822.70230-3-anshuman.khandual@arm.com
---
 include/uapi/linux/perf_event.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index a79cc0e..fed60e6 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -255,6 +255,7 @@ enum {
 	PERF_BR_IRQ		= 12,	/* irq */
 	PERF_BR_SERROR		= 13,	/* system error */
 	PERF_BR_NO_TX		= 14,	/* not in transaction */
+	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
 	PERF_BR_MAX,
 };
 
@@ -269,6 +270,18 @@ enum {
 	PERF_BR_SPEC_MAX,
 };
 
+enum {
+	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
+	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
+	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
+	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
+	PERF_BR_NEW_MAX,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1388,7 +1401,8 @@ struct perf_branch_entry {
 		cycles:16,  /* cycle count to last branch */
 		type:4,     /* branch type */
 		spec:2,     /* branch speculation info */
-		reserved:38;
+		new_type:4, /* additional branch type */
+		reserved:34;
 };
 
 union perf_sample_weight {

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [tip: perf/core] perf: Add system error and not in transaction branch types
  2022-08-24  4:48   ` Anshuman Khandual
  (?)
@ 2022-08-26 22:15   ` tip-bot2 for Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: tip-bot2 for Anshuman Khandual @ 2022-08-26 22:15 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     6bc72375dd930fb7a8b71f6e5ced02b3b7cfdca1
Gitweb:        https://git.kernel.org/tip/6bc72375dd930fb7a8b71f6e5ced02b3b7cfdca1
Author:        Anshuman Khandual <anshuman.khandual@arm.com>
AuthorDate:    Wed, 24 Aug 2022 10:18:15 +05:30
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Sat, 27 Aug 2022 00:05:46 +02:00

perf: Add system error and not in transaction branch types

This expands generic branch type classification by adding two more entries
there in i.e system error and not in transaction. This also updates the x86
implementation to process X86_BR_NO_TX records as appropriate. This changes
branch types reported to user space on x86 platform but it should not be a
problem. The possible scenarios and impacts are enumerated here.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220824044822.70230-2-anshuman.khandual@arm.com
---
 arch/x86/events/utils.c         | 2 +-
 include/uapi/linux/perf_event.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/events/utils.c b/arch/x86/events/utils.c
index e013243..5f5617a 100644
--- a/arch/x86/events/utils.c
+++ b/arch/x86/events/utils.c
@@ -225,7 +225,7 @@ static int branch_map[X86_BR_TYPE_MAP_MAX] = {
 	PERF_BR_IND_CALL,	/* X86_BR_IND_CALL */
 	PERF_BR_UNKNOWN,	/* X86_BR_ABORT */
 	PERF_BR_UNKNOWN,	/* X86_BR_IN_TX */
-	PERF_BR_UNKNOWN,	/* X86_BR_NO_TX */
+	PERF_BR_NO_TX,		/* X86_BR_NO_TX */
 	PERF_BR_CALL,		/* X86_BR_ZERO_CALL */
 	PERF_BR_UNKNOWN,	/* X86_BR_CALL_STACK */
 	PERF_BR_IND,		/* X86_BR_IND_JMP */
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 30a4723..a79cc0e 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -253,6 +253,8 @@ enum {
 	PERF_BR_COND_RET	= 10,	/* conditional function return */
 	PERF_BR_ERET		= 11,	/* exception return */
 	PERF_BR_IRQ		= 12,	/* irq */
+	PERF_BR_SERROR		= 13,	/* system error */
+	PERF_BR_NO_TX		= 14,	/* not in transaction */
 	PERF_BR_MAX,
 };
 

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 0/8] perf: Expand perf_branch_entry
  2022-08-25 10:22   ` Peter Zijlstra
@ 2022-08-29  4:12     ` Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-29  4:12 UTC (permalink / raw)
  To: Peter Zijlstra, Arnaldo Carvalho de Melo
  Cc: linux-kernel, linux-perf-users, alexander.shishkin, jolsa, acme,
	mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

On 8/25/22 15:52, Peter Zijlstra wrote:
> On Wed, Aug 24, 2022 at 10:18:14AM +0530, Anshuman Khandual wrote:
>> Anshuman Khandual (8):
>>   perf: Add system error and not in transaction branch types
>>   perf: Extend branch type classification
>>   perf: Capture branch privilege information
>>   perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
> 
> I picked up these first 4 and rebased them on top of the recent AMD LBR
> patches.
> 
> They live in:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git perf/core
> 
> for robot exposure. If all goes well they'll land in -tip.

Thanks Peter, I guess now Arnaldo could also pick up the tools patches well.

- Anshuman

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 0/8] perf: Expand perf_branch_entry
@ 2022-08-29  4:12     ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-08-29  4:12 UTC (permalink / raw)
  To: Peter Zijlstra, Arnaldo Carvalho de Melo
  Cc: linux-kernel, linux-perf-users, alexander.shishkin, jolsa, acme,
	mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

On 8/25/22 15:52, Peter Zijlstra wrote:
> On Wed, Aug 24, 2022 at 10:18:14AM +0530, Anshuman Khandual wrote:
>> Anshuman Khandual (8):
>>   perf: Add system error and not in transaction branch types
>>   perf: Extend branch type classification
>>   perf: Capture branch privilege information
>>   perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
> 
> I picked up these first 4 and rebased them on top of the recent AMD LBR
> patches.
> 
> They live in:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git perf/core
> 
> for robot exposure. If all goes well they'll land in -tip.

Thanks Peter, I guess now Arnaldo could also pick up the tools patches well.

- Anshuman

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [tip: perf/core] perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform
  2022-08-24  4:48   ` Anshuman Khandual
  (?)
  (?)
@ 2022-08-29  7:49   ` tip-bot2 for Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: tip-bot2 for Anshuman Khandual @ 2022-08-29  7:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Anshuman Khandual, Peter Zijlstra (Intel),
	James Clark, x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     f4054e522531038354bea5c924f286fdd8ae77b5
Gitweb:        https://git.kernel.org/tip/f4054e522531038354bea5c924f286fdd8ae77b5
Author:        Anshuman Khandual <anshuman.khandual@arm.com>
AuthorDate:    Wed, 24 Aug 2022 10:18:18 +05:30
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 29 Aug 2022 09:42:42 +02:00

perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform

BRBE captured branch types will overflow perf_branch_entry.type and generic
branch types in perf_branch_entry.new_type. So override each available arch
specific branch type in the following manner to comprehensively process all
reported branch types in BRBE.

  PERF_BR_ARM64_FIQ            PERF_BR_NEW_ARCH_1
  PERF_BR_ARM64_DEBUG_HALT     PERF_BR_NEW_ARCH_2
  PERF_BR_ARM64_DEBUG_EXIT     PERF_BR_NEW_ARCH_3
  PERF_BR_ARM64_DEBUG_INST     PERF_BR_NEW_ARCH_4
  PERF_BR_ARM64_DEBUG_DATA     PERF_BR_NEW_ARCH_5

Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: James Clark <james.clark@arm.com>
Link: https://lkml.kernel.org/r/20220824044822.70230-5-anshuman.khandual@arm.com
---
 include/uapi/linux/perf_event.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 1a258d4..dca1658 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -293,6 +293,12 @@ enum {
 	PERF_BR_PRIV_HV		= 3,
 };
 
+#define PERF_BR_ARM64_FIQ		PERF_BR_NEW_ARCH_1
+#define PERF_BR_ARM64_DEBUG_HALT	PERF_BR_NEW_ARCH_2
+#define PERF_BR_ARM64_DEBUG_EXIT	PERF_BR_NEW_ARCH_3
+#define PERF_BR_ARM64_DEBUG_INST	PERF_BR_NEW_ARCH_4
+#define PERF_BR_ARM64_DEBUG_DATA	PERF_BR_NEW_ARCH_5
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [tip: perf/core] perf: Capture branch privilege information
  2022-08-24  4:48   ` Anshuman Khandual
  (?)
  (?)
@ 2022-08-29  7:50   ` tip-bot2 for Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: tip-bot2 for Anshuman Khandual @ 2022-08-29  7:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Anshuman Khandual, Peter Zijlstra (Intel),
	James Clark, x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     5402d25aa5710d240040f73fb13d7d5c303ef071
Gitweb:        https://git.kernel.org/tip/5402d25aa5710d240040f73fb13d7d5c303ef071
Author:        Anshuman Khandual <anshuman.khandual@arm.com>
AuthorDate:    Wed, 24 Aug 2022 10:18:17 +05:30
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 29 Aug 2022 09:42:42 +02:00

perf: Capture branch privilege information

Platforms like arm64 could capture privilege level information for all the
branch records. Hence this adds a new element in the struct branch_entry to
record the privilege level information, which could be requested through a
new event.attr.branch_sample_type based flag PERF_SAMPLE_BRANCH_PRIV_SAVE.
This flag helps user choose whether privilege information is captured.

Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: James Clark <james.clark@arm.com>
Link: https://lkml.kernel.org/r/20220824044822.70230-4-anshuman.khandual@arm.com
---
 include/uapi/linux/perf_event.h | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index fed60e6..1a258d4 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -204,6 +204,8 @@ enum perf_branch_sample_type_shift {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT	= 17, /* save low level index of raw branch records */
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT	= 18, /* save privilege mode */
+
 	PERF_SAMPLE_BRANCH_MAX_SHIFT		/* non-ABI */
 };
 
@@ -233,6 +235,8 @@ enum perf_branch_sample_type {
 
 	PERF_SAMPLE_BRANCH_HW_INDEX	= 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
 
+	PERF_SAMPLE_BRANCH_PRIV_SAVE	= 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
+
 	PERF_SAMPLE_BRANCH_MAX		= 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
 };
 
@@ -282,6 +286,13 @@ enum {
 	PERF_BR_NEW_MAX,
 };
 
+enum {
+	PERF_BR_PRIV_UNKNOWN	= 0,
+	PERF_BR_PRIV_USER	= 1,
+	PERF_BR_PRIV_KERNEL	= 2,
+	PERF_BR_PRIV_HV		= 3,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1402,7 +1413,8 @@ struct perf_branch_entry {
 		type:4,     /* branch type */
 		spec:2,     /* branch speculation info */
 		new_type:4, /* additional branch type */
-		reserved:34;
+		priv:3,     /* privilege level */
+		reserved:31;
 };
 
 union perf_sample_weight {

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [tip: perf/core] perf: Extend branch type classification
  2022-08-24  4:48   ` Anshuman Khandual
  (?)
  (?)
@ 2022-08-29  7:50   ` tip-bot2 for Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: tip-bot2 for Anshuman Khandual @ 2022-08-29  7:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Anshuman Khandual, Peter Zijlstra (Intel),
	James Clark, x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     b190bc4ac9e6d9763b61654c5a0c085ff77d7a09
Gitweb:        https://git.kernel.org/tip/b190bc4ac9e6d9763b61654c5a0c085ff77d7a09
Author:        Anshuman Khandual <anshuman.khandual@arm.com>
AuthorDate:    Wed, 24 Aug 2022 10:18:16 +05:30
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 29 Aug 2022 09:42:42 +02:00

perf: Extend branch type classification

branch_entry.type now has ran out of space to accommodate more branch types
classification. This will prevent perf branch stack implementation on arm64
(via BRBE) to capture all available branch types. Extending this bit field
i.e branch_entry.type [4 bits] is not an option as it will break user space
ABI both for little and big endian perf tools.

Extend branch classification with a new field branch_entry.new_type via a
new branch type PERF_BR_EXTEND_ABI in branch_entry.type. Perf tools which
could decode PERF_BR_EXTEND_ABI, will then parse branch_entry.new_type as
well.

branch_entry.new_type is a 4 bit field which can hold upto 16 branch types.
The first three branch types will hold various generic page faults followed
by five architecture specific branch types, which can be overridden by the
platform for specific use cases. These architecture specific branch types
gets overridden on arm64 platform for BRBE implementation.

New generic branch types

 - PERF_BR_NEW_FAULT_ALGN
 - PERF_BR_NEW_FAULT_DATA
 - PERF_BR_NEW_FAULT_INST

New arch specific branch types

 - PERF_BR_NEW_ARCH_1
 - PERF_BR_NEW_ARCH_2
 - PERF_BR_NEW_ARCH_3
 - PERF_BR_NEW_ARCH_4
 - PERF_BR_NEW_ARCH_5

Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: James Clark <james.clark@arm.com>
Link: https://lkml.kernel.org/r/20220824044822.70230-3-anshuman.khandual@arm.com
---
 include/uapi/linux/perf_event.h | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index a79cc0e..fed60e6 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -255,6 +255,7 @@ enum {
 	PERF_BR_IRQ		= 12,	/* irq */
 	PERF_BR_SERROR		= 13,	/* system error */
 	PERF_BR_NO_TX		= 14,	/* not in transaction */
+	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
 	PERF_BR_MAX,
 };
 
@@ -269,6 +270,18 @@ enum {
 	PERF_BR_SPEC_MAX,
 };
 
+enum {
+	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
+	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
+	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
+	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
+	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
+	PERF_BR_NEW_MAX,
+};
+
 #define PERF_SAMPLE_BRANCH_PLM_ALL \
 	(PERF_SAMPLE_BRANCH_USER|\
 	 PERF_SAMPLE_BRANCH_KERNEL|\
@@ -1388,7 +1401,8 @@ struct perf_branch_entry {
 		cycles:16,  /* cycle count to last branch */
 		type:4,     /* branch type */
 		spec:2,     /* branch speculation info */
-		reserved:38;
+		new_type:4, /* additional branch type */
+		reserved:34;
 };
 
 union perf_sample_weight {

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* [tip: perf/core] perf: Add system error and not in transaction branch types
  2022-08-24  4:48   ` Anshuman Khandual
  (?)
  (?)
@ 2022-08-29  7:50   ` tip-bot2 for Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: tip-bot2 for Anshuman Khandual @ 2022-08-29  7:50 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Anshuman Khandual, Peter Zijlstra (Intel),
	James Clark, x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     a724ec82966d57e4b5d36341d3e3dc1a3c011564
Gitweb:        https://git.kernel.org/tip/a724ec82966d57e4b5d36341d3e3dc1a3c011564
Author:        Anshuman Khandual <anshuman.khandual@arm.com>
AuthorDate:    Wed, 24 Aug 2022 10:18:15 +05:30
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Mon, 29 Aug 2022 09:42:41 +02:00

perf: Add system error and not in transaction branch types

This expands generic branch type classification by adding two more entries
there in i.e system error and not in transaction. This also updates the x86
implementation to process X86_BR_NO_TX records as appropriate. This changes
branch types reported to user space on x86 platform but it should not be a
problem. The possible scenarios and impacts are enumerated here.

 --------------------------------------------------------------------------
 | kernel | perf tool |                     Impact                        |
 --------------------------------------------------------------------------
 |   old  |    old    |  Works as before                                  |
 --------------------------------------------------------------------------
 |   old  |    new    |  PERF_BR_UNKNOWN is processed                     |
 --------------------------------------------------------------------------
 |   new  |    old    |  PERF_BR_NO_TX is blocked via old PERF_BR_MAX     |
 --------------------------------------------------------------------------
 |   new  |    new    |  PERF_BR_NO_TX is recognized                      |
 --------------------------------------------------------------------------

When PERF_BR_NO_TX is blocked via old PERF_BR_MAX (new kernel with old perf
tool) the user space might throw up an warning complaining about an
unrecognized branch types being reported, but it's expected. PERF_BR_SERROR
& PERF_BR_NO_TX branch types will be used for BRBE implementation on arm64
platform.

PERF_BR_NO_TX complements 'abort' and 'in_tx' elements in perf_branch_entry
which represent other transaction states for a given branch record. Because
this completes the transaction state classification.

Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: James Clark <james.clark@arm.com>
Link: https://lkml.kernel.org/r/20220824044822.70230-2-anshuman.khandual@arm.com
---
 arch/x86/events/utils.c         | 2 +-
 include/uapi/linux/perf_event.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/events/utils.c b/arch/x86/events/utils.c
index e013243..5f5617a 100644
--- a/arch/x86/events/utils.c
+++ b/arch/x86/events/utils.c
@@ -225,7 +225,7 @@ static int branch_map[X86_BR_TYPE_MAP_MAX] = {
 	PERF_BR_IND_CALL,	/* X86_BR_IND_CALL */
 	PERF_BR_UNKNOWN,	/* X86_BR_ABORT */
 	PERF_BR_UNKNOWN,	/* X86_BR_IN_TX */
-	PERF_BR_UNKNOWN,	/* X86_BR_NO_TX */
+	PERF_BR_NO_TX,		/* X86_BR_NO_TX */
 	PERF_BR_CALL,		/* X86_BR_ZERO_CALL */
 	PERF_BR_UNKNOWN,	/* X86_BR_CALL_STACK */
 	PERF_BR_IND,		/* X86_BR_IND_JMP */
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 30a4723..a79cc0e 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -253,6 +253,8 @@ enum {
 	PERF_BR_COND_RET	= 10,	/* conditional function return */
 	PERF_BR_ERET		= 11,	/* exception return */
 	PERF_BR_IRQ		= 12,	/* irq */
+	PERF_BR_SERROR		= 13,	/* system error */
+	PERF_BR_NO_TX		= 14,	/* not in transaction */
 	PERF_BR_MAX,
 };
 

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 6/8] perf/tools: Extend branch type classification
  2022-08-24  4:48   ` Anshuman Khandual
@ 2022-08-30 21:11     ` Arnaldo Carvalho de Melo
  -1 siblings, 0 replies; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-08-30 21:11 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Em Wed, Aug 24, 2022 at 10:18:20AM +0530, Anshuman Khandual escreveu:
> This updates the perf tool with generic branch type classification with new
> ABI extender place holder i.e PERF_BR_EXTEND_ABI, the new 4 bit branch type
> field i.e perf_branch_entry.new_type, new generic page fault related branch
> types and some arch specific branch types as added earlier in the kernel.
> 
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Will Deacon <will@kernel.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-perf-users@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
>  tools/include/uapi/linux/perf_event.h | 16 ++++++++-
>  tools/perf/builtin-script.c           |  2 +-
>  tools/perf/util/branch.c              | 52 ++++++++++++++++++++++++++-
>  tools/perf/util/branch.h              |  6 +++-
>  tools/perf/util/session.c             |  2 +-
>  5 files changed, 73 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
> index 146c137ff0c1..0f7c7ce29899 100644
> --- a/tools/include/uapi/linux/perf_event.h
> +++ b/tools/include/uapi/linux/perf_event.h
> @@ -255,9 +255,22 @@ enum {
>  	PERF_BR_IRQ		= 12,	/* irq */
>  	PERF_BR_SERROR		= 13,	/* system error */
>  	PERF_BR_NO_TX		= 14,	/* not in transaction */
> +	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
>  	PERF_BR_MAX,
>  };
>  
> +enum {
> +	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
> +	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
> +	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
> +	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
> +	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
> +	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
> +	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
> +	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
> +	PERF_BR_NEW_MAX,
> +};
> +
>  #define PERF_SAMPLE_BRANCH_PLM_ALL \
>  	(PERF_SAMPLE_BRANCH_USER|\
>  	 PERF_SAMPLE_BRANCH_KERNEL|\
> @@ -1375,7 +1388,8 @@ struct perf_branch_entry {
>  		abort:1,    /* transaction abort */
>  		cycles:16,  /* cycle count to last branch */
>  		type:4,     /* branch type */
> -		reserved:40;
> +		new_type:4, /* additional branch type */
> +		reserved:36;
>  };
>  
>  union perf_sample_weight {
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 13580a9c50b8..585171479876 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -877,7 +877,7 @@ static int print_bstack_flags(FILE *fp, struct branch_entry *br)
>  		       br->flags.in_tx ? 'X' : '-',
>  		       br->flags.abort ? 'A' : '-',
>  		       br->flags.cycles,
> -		       br->flags.type ? branch_type_name(br->flags.type) : "-");
> +		       get_branch_type(br));
>  }
>  
>  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 abc673347bee..6d962b0a4532 100644
> --- a/tools/perf/util/branch.c
> +++ b/tools/perf/util/branch.c
> @@ -21,7 +21,10 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
>  	if (flags->type == PERF_BR_UNKNOWN || from == 0)
>  		return;
>  
> -	st->counts[flags->type]++;
> +	if (flags->type == PERF_BR_EXTEND_ABI)
> +		st->new_counts[flags->new_type]++;
> +	else
> +		st->counts[flags->type]++;
>  
>  	if (flags->type == PERF_BR_COND) {
>  		if (to > from)
> @@ -36,6 +39,25 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
>  		st->cross_4k++;
>  }
>  
> +const char *branch_new_type_name(int new_type)
> +{
> +	const char *branch_new_names[PERF_BR_NEW_MAX] = {
> +		"FAULT_ALGN",
> +		"FAULT_DATA",
> +		"FAULT_INST",
> +		"ARCH_1",
> +		"ARCH_2",
> +		"ARCH_3",
> +		"ARCH_4",
> +		"ARCH_5"
> +	};
> +
> +	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
> +		return branch_new_names[new_type];
> +
> +	return NULL;
> +}
> +
>  const char *branch_type_name(int type)
>  {
>  	const char *branch_names[PERF_BR_MAX] = {
> @@ -62,6 +84,17 @@ const char *branch_type_name(int type)
>  	return NULL;
>  }
>  
> +const char *get_branch_type(struct branch_entry *e)
> +{
> +	if (e->flags.type == PERF_BR_UNKNOWN)
> +		return "";
> +
> +	if (e->flags.type == PERF_BR_EXTEND_ABI)
> +		return branch_new_type_name(e->flags.new_type);
> +
> +	return branch_type_name(e->flags.type);
> +}
> +
>  void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
>  {
>  	u64 total = 0;
> @@ -108,6 +141,15 @@ void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
>  				100.0 *
>  				(double)st->counts[i] / (double)total);
>  	}
> +
> +	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
> +		if (st->new_counts[i] > 0)
> +			fprintf(fp, "\n%8s: %5.1f%%",
> +				branch_new_type_name(i),
> +				100.0 *
> +				(double)st->new_counts[i] / (double)total);
> +	}
> +

Strange:

  75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
        inlined from 'branch_type_stat_display' at util/branch.c:152:4:
    /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
      100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      101 |    __va_arg_pack ());
          |    ~~~~~~~~~~~~~~~~~


>  }
>  
>  static int count_str_scnprintf(int idx, const char *str, char *bf, int size)
> @@ -123,6 +165,9 @@ int branch_type_str(struct branch_type_stat *st, char *bf, int size)
>  	for (i = 0; i < PERF_BR_MAX; i++)
>  		total += st->counts[i];
>  
> +	for (i = 0; i < PERF_BR_NEW_MAX; i++)
> +		total += st->new_counts[i];
> +
>  	if (total == 0)
>  		return 0;
>  
> @@ -140,6 +185,11 @@ int branch_type_str(struct branch_type_stat *st, char *bf, int size)
>  			printed += count_str_scnprintf(j++, branch_type_name(i), bf + printed, size - printed);
>  	}
>  
> +	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
> +		if (st->new_counts[i] > 0)
> +			printed += count_str_scnprintf(j++, branch_new_type_name(i), bf + printed, size - printed);
> +	}
> +
>  	if (st->cross_4k > 0)
>  		printed += count_str_scnprintf(j++, "CROSS_4K", bf + printed, size - printed);
>  
> diff --git a/tools/perf/util/branch.h b/tools/perf/util/branch.h
> index 17b2ccc61094..8d251b35428a 100644
> --- a/tools/perf/util/branch.h
> +++ b/tools/perf/util/branch.h
> @@ -24,7 +24,8 @@ struct branch_flags {
>  			u64 abort:1;
>  			u64 cycles:16;
>  			u64 type:4;
> -			u64 reserved:40;
> +			u64 new_type:4;
> +			u64 reserved:36;
>  		};
>  	};
>  };
> @@ -72,6 +73,7 @@ static inline struct branch_entry *perf_sample__branch_entries(struct perf_sampl
>  struct branch_type_stat {
>  	bool	branch_to;
>  	u64	counts[PERF_BR_MAX];
> +	u64	new_counts[PERF_BR_NEW_MAX];
>  	u64	cond_fwd;
>  	u64	cond_bwd;
>  	u64	cross_4k;
> @@ -82,6 +84,8 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
>  		       u64 from, u64 to);
>  
>  const char *branch_type_name(int type);
> +const char *branch_new_type_name(int new_type);
> +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);
>  
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index 192c9274f7ad..47d5a50e616a 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -1180,7 +1180,7 @@ static void branch_stack__printf(struct perf_sample *sample, bool callstack)
>  				e->flags.abort ? "A" : " ",
>  				e->flags.in_tx ? "T" : " ",
>  				(unsigned)e->flags.reserved,
> -				e->flags.type ? branch_type_name(e->flags.type) : "");
> +				get_branch_type(e));
>  		} else {
>  			if (i == 0) {
>  				printf("..... %2"PRIu64": %016" PRIx64 "\n"
> -- 
> 2.25.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 6/8] perf/tools: Extend branch type classification
@ 2022-08-30 21:11     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-08-30 21:11 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Em Wed, Aug 24, 2022 at 10:18:20AM +0530, Anshuman Khandual escreveu:
> This updates the perf tool with generic branch type classification with new
> ABI extender place holder i.e PERF_BR_EXTEND_ABI, the new 4 bit branch type
> field i.e perf_branch_entry.new_type, new generic page fault related branch
> types and some arch specific branch types as added earlier in the kernel.
> 
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Will Deacon <will@kernel.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-perf-users@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> ---
>  tools/include/uapi/linux/perf_event.h | 16 ++++++++-
>  tools/perf/builtin-script.c           |  2 +-
>  tools/perf/util/branch.c              | 52 ++++++++++++++++++++++++++-
>  tools/perf/util/branch.h              |  6 +++-
>  tools/perf/util/session.c             |  2 +-
>  5 files changed, 73 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
> index 146c137ff0c1..0f7c7ce29899 100644
> --- a/tools/include/uapi/linux/perf_event.h
> +++ b/tools/include/uapi/linux/perf_event.h
> @@ -255,9 +255,22 @@ enum {
>  	PERF_BR_IRQ		= 12,	/* irq */
>  	PERF_BR_SERROR		= 13,	/* system error */
>  	PERF_BR_NO_TX		= 14,	/* not in transaction */
> +	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
>  	PERF_BR_MAX,
>  };
>  
> +enum {
> +	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
> +	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
> +	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
> +	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
> +	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
> +	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
> +	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
> +	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
> +	PERF_BR_NEW_MAX,
> +};
> +
>  #define PERF_SAMPLE_BRANCH_PLM_ALL \
>  	(PERF_SAMPLE_BRANCH_USER|\
>  	 PERF_SAMPLE_BRANCH_KERNEL|\
> @@ -1375,7 +1388,8 @@ struct perf_branch_entry {
>  		abort:1,    /* transaction abort */
>  		cycles:16,  /* cycle count to last branch */
>  		type:4,     /* branch type */
> -		reserved:40;
> +		new_type:4, /* additional branch type */
> +		reserved:36;
>  };
>  
>  union perf_sample_weight {
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 13580a9c50b8..585171479876 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -877,7 +877,7 @@ static int print_bstack_flags(FILE *fp, struct branch_entry *br)
>  		       br->flags.in_tx ? 'X' : '-',
>  		       br->flags.abort ? 'A' : '-',
>  		       br->flags.cycles,
> -		       br->flags.type ? branch_type_name(br->flags.type) : "-");
> +		       get_branch_type(br));
>  }
>  
>  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 abc673347bee..6d962b0a4532 100644
> --- a/tools/perf/util/branch.c
> +++ b/tools/perf/util/branch.c
> @@ -21,7 +21,10 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
>  	if (flags->type == PERF_BR_UNKNOWN || from == 0)
>  		return;
>  
> -	st->counts[flags->type]++;
> +	if (flags->type == PERF_BR_EXTEND_ABI)
> +		st->new_counts[flags->new_type]++;
> +	else
> +		st->counts[flags->type]++;
>  
>  	if (flags->type == PERF_BR_COND) {
>  		if (to > from)
> @@ -36,6 +39,25 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
>  		st->cross_4k++;
>  }
>  
> +const char *branch_new_type_name(int new_type)
> +{
> +	const char *branch_new_names[PERF_BR_NEW_MAX] = {
> +		"FAULT_ALGN",
> +		"FAULT_DATA",
> +		"FAULT_INST",
> +		"ARCH_1",
> +		"ARCH_2",
> +		"ARCH_3",
> +		"ARCH_4",
> +		"ARCH_5"
> +	};
> +
> +	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
> +		return branch_new_names[new_type];
> +
> +	return NULL;
> +}
> +
>  const char *branch_type_name(int type)
>  {
>  	const char *branch_names[PERF_BR_MAX] = {
> @@ -62,6 +84,17 @@ const char *branch_type_name(int type)
>  	return NULL;
>  }
>  
> +const char *get_branch_type(struct branch_entry *e)
> +{
> +	if (e->flags.type == PERF_BR_UNKNOWN)
> +		return "";
> +
> +	if (e->flags.type == PERF_BR_EXTEND_ABI)
> +		return branch_new_type_name(e->flags.new_type);
> +
> +	return branch_type_name(e->flags.type);
> +}
> +
>  void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
>  {
>  	u64 total = 0;
> @@ -108,6 +141,15 @@ void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
>  				100.0 *
>  				(double)st->counts[i] / (double)total);
>  	}
> +
> +	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
> +		if (st->new_counts[i] > 0)
> +			fprintf(fp, "\n%8s: %5.1f%%",
> +				branch_new_type_name(i),
> +				100.0 *
> +				(double)st->new_counts[i] / (double)total);
> +	}
> +

Strange:

  75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
        inlined from 'branch_type_stat_display' at util/branch.c:152:4:
    /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
      100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
          |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      101 |    __va_arg_pack ());
          |    ~~~~~~~~~~~~~~~~~


>  }
>  
>  static int count_str_scnprintf(int idx, const char *str, char *bf, int size)
> @@ -123,6 +165,9 @@ int branch_type_str(struct branch_type_stat *st, char *bf, int size)
>  	for (i = 0; i < PERF_BR_MAX; i++)
>  		total += st->counts[i];
>  
> +	for (i = 0; i < PERF_BR_NEW_MAX; i++)
> +		total += st->new_counts[i];
> +
>  	if (total == 0)
>  		return 0;
>  
> @@ -140,6 +185,11 @@ int branch_type_str(struct branch_type_stat *st, char *bf, int size)
>  			printed += count_str_scnprintf(j++, branch_type_name(i), bf + printed, size - printed);
>  	}
>  
> +	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
> +		if (st->new_counts[i] > 0)
> +			printed += count_str_scnprintf(j++, branch_new_type_name(i), bf + printed, size - printed);
> +	}
> +
>  	if (st->cross_4k > 0)
>  		printed += count_str_scnprintf(j++, "CROSS_4K", bf + printed, size - printed);
>  
> diff --git a/tools/perf/util/branch.h b/tools/perf/util/branch.h
> index 17b2ccc61094..8d251b35428a 100644
> --- a/tools/perf/util/branch.h
> +++ b/tools/perf/util/branch.h
> @@ -24,7 +24,8 @@ struct branch_flags {
>  			u64 abort:1;
>  			u64 cycles:16;
>  			u64 type:4;
> -			u64 reserved:40;
> +			u64 new_type:4;
> +			u64 reserved:36;
>  		};
>  	};
>  };
> @@ -72,6 +73,7 @@ static inline struct branch_entry *perf_sample__branch_entries(struct perf_sampl
>  struct branch_type_stat {
>  	bool	branch_to;
>  	u64	counts[PERF_BR_MAX];
> +	u64	new_counts[PERF_BR_NEW_MAX];
>  	u64	cond_fwd;
>  	u64	cond_bwd;
>  	u64	cross_4k;
> @@ -82,6 +84,8 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
>  		       u64 from, u64 to);
>  
>  const char *branch_type_name(int type);
> +const char *branch_new_type_name(int new_type);
> +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);
>  
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index 192c9274f7ad..47d5a50e616a 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -1180,7 +1180,7 @@ static void branch_stack__printf(struct perf_sample *sample, bool callstack)
>  				e->flags.abort ? "A" : " ",
>  				e->flags.in_tx ? "T" : " ",
>  				(unsigned)e->flags.reserved,
> -				e->flags.type ? branch_type_name(e->flags.type) : "");
> +				get_branch_type(e));
>  		} else {
>  			if (i == 0) {
>  				printf("..... %2"PRIu64": %016" PRIx64 "\n"
> -- 
> 2.25.1

-- 

- Arnaldo

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 6/8] perf/tools: Extend branch type classification
  2022-08-30 21:11     ` Arnaldo Carvalho de Melo
@ 2022-09-01  5:07       ` Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-09-01  5:07 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel



On 8/31/22 02:41, Arnaldo Carvalho de Melo wrote:
> Em Wed, Aug 24, 2022 at 10:18:20AM +0530, Anshuman Khandual escreveu:
>> This updates the perf tool with generic branch type classification with new
>> ABI extender place holder i.e PERF_BR_EXTEND_ABI, the new 4 bit branch type
>> field i.e perf_branch_entry.new_type, new generic page fault related branch
>> types and some arch specific branch types as added earlier in the kernel.
>>
>> Cc: Peter Zijlstra <peterz@infradead.org>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
>> Cc: Mark Rutland <mark.rutland@arm.com>
>> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
>> Cc: Jiri Olsa <jolsa@redhat.com>
>> Cc: Namhyung Kim <namhyung@kernel.org>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>> Cc: Will Deacon <will@kernel.org>
>> Cc: linux-arm-kernel@lists.infradead.org
>> Cc: linux-perf-users@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>> ---
>>  tools/include/uapi/linux/perf_event.h | 16 ++++++++-
>>  tools/perf/builtin-script.c           |  2 +-
>>  tools/perf/util/branch.c              | 52 ++++++++++++++++++++++++++-
>>  tools/perf/util/branch.h              |  6 +++-
>>  tools/perf/util/session.c             |  2 +-
>>  5 files changed, 73 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
>> index 146c137ff0c1..0f7c7ce29899 100644
>> --- a/tools/include/uapi/linux/perf_event.h
>> +++ b/tools/include/uapi/linux/perf_event.h
>> @@ -255,9 +255,22 @@ enum {
>>  	PERF_BR_IRQ		= 12,	/* irq */
>>  	PERF_BR_SERROR		= 13,	/* system error */
>>  	PERF_BR_NO_TX		= 14,	/* not in transaction */
>> +	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
>>  	PERF_BR_MAX,
>>  };
>>  
>> +enum {
>> +	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
>> +	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
>> +	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
>> +	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
>> +	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
>> +	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
>> +	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
>> +	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
>> +	PERF_BR_NEW_MAX,
>> +};
>> +
>>  #define PERF_SAMPLE_BRANCH_PLM_ALL \
>>  	(PERF_SAMPLE_BRANCH_USER|\
>>  	 PERF_SAMPLE_BRANCH_KERNEL|\
>> @@ -1375,7 +1388,8 @@ struct perf_branch_entry {
>>  		abort:1,    /* transaction abort */
>>  		cycles:16,  /* cycle count to last branch */
>>  		type:4,     /* branch type */
>> -		reserved:40;
>> +		new_type:4, /* additional branch type */
>> +		reserved:36;
>>  };
>>  
>>  union perf_sample_weight {
>> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
>> index 13580a9c50b8..585171479876 100644
>> --- a/tools/perf/builtin-script.c
>> +++ b/tools/perf/builtin-script.c
>> @@ -877,7 +877,7 @@ static int print_bstack_flags(FILE *fp, struct branch_entry *br)
>>  		       br->flags.in_tx ? 'X' : '-',
>>  		       br->flags.abort ? 'A' : '-',
>>  		       br->flags.cycles,
>> -		       br->flags.type ? branch_type_name(br->flags.type) : "-");
>> +		       get_branch_type(br));
>>  }
>>  
>>  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 abc673347bee..6d962b0a4532 100644
>> --- a/tools/perf/util/branch.c
>> +++ b/tools/perf/util/branch.c
>> @@ -21,7 +21,10 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
>>  	if (flags->type == PERF_BR_UNKNOWN || from == 0)
>>  		return;
>>  
>> -	st->counts[flags->type]++;
>> +	if (flags->type == PERF_BR_EXTEND_ABI)
>> +		st->new_counts[flags->new_type]++;
>> +	else
>> +		st->counts[flags->type]++;
>>  
>>  	if (flags->type == PERF_BR_COND) {
>>  		if (to > from)
>> @@ -36,6 +39,25 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
>>  		st->cross_4k++;
>>  }
>>  
>> +const char *branch_new_type_name(int new_type)
>> +{
>> +	const char *branch_new_names[PERF_BR_NEW_MAX] = {
>> +		"FAULT_ALGN",
>> +		"FAULT_DATA",
>> +		"FAULT_INST",
>> +		"ARCH_1",
>> +		"ARCH_2",
>> +		"ARCH_3",
>> +		"ARCH_4",
>> +		"ARCH_5"
>> +	};
>> +
>> +	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
>> +		return branch_new_names[new_type];
>> +
>> +	return NULL;
>> +}
>> +
>>  const char *branch_type_name(int type)
>>  {
>>  	const char *branch_names[PERF_BR_MAX] = {
>> @@ -62,6 +84,17 @@ const char *branch_type_name(int type)
>>  	return NULL;
>>  }
>>  
>> +const char *get_branch_type(struct branch_entry *e)
>> +{
>> +	if (e->flags.type == PERF_BR_UNKNOWN)
>> +		return "";
>> +
>> +	if (e->flags.type == PERF_BR_EXTEND_ABI)
>> +		return branch_new_type_name(e->flags.new_type);
>> +
>> +	return branch_type_name(e->flags.type);
>> +}
>> +
>>  void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
>>  {
>>  	u64 total = 0;
>> @@ -108,6 +141,15 @@ void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
>>  				100.0 *
>>  				(double)st->counts[i] / (double)total);
>>  	}
>> +
>> +	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
>> +		if (st->new_counts[i] > 0)
>> +			fprintf(fp, "\n%8s: %5.1f%%",
>> +				branch_new_type_name(i),
>> +				100.0 *
>> +				(double)st->new_counts[i] / (double)total);
>> +	}
>> +
> Strange:
> 
>   75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
>         inlined from 'branch_type_stat_display' at util/branch.c:152:4:
>     /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
>       100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
>           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>       101 |    __va_arg_pack ());
>           |    ~~~~~~~~~~~~~~~~~
> 

Indeed. But this new code block here looks exact same like the previous and existing one
i.e with branch_new_name() and PERF_BR_NEW_MAX. The complain is that - '%8s' directive
argument is NULL. This warning might just be a false positive [1], because of a compiler
problem on powerpc64el ? But please do let me know if something needs to be changed here
to avoid this warning.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036

- Anshuman

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 6/8] perf/tools: Extend branch type classification
@ 2022-09-01  5:07       ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-09-01  5:07 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel



On 8/31/22 02:41, Arnaldo Carvalho de Melo wrote:
> Em Wed, Aug 24, 2022 at 10:18:20AM +0530, Anshuman Khandual escreveu:
>> This updates the perf tool with generic branch type classification with new
>> ABI extender place holder i.e PERF_BR_EXTEND_ABI, the new 4 bit branch type
>> field i.e perf_branch_entry.new_type, new generic page fault related branch
>> types and some arch specific branch types as added earlier in the kernel.
>>
>> Cc: Peter Zijlstra <peterz@infradead.org>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
>> Cc: Mark Rutland <mark.rutland@arm.com>
>> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
>> Cc: Jiri Olsa <jolsa@redhat.com>
>> Cc: Namhyung Kim <namhyung@kernel.org>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>> Cc: Will Deacon <will@kernel.org>
>> Cc: linux-arm-kernel@lists.infradead.org
>> Cc: linux-perf-users@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
>> ---
>>  tools/include/uapi/linux/perf_event.h | 16 ++++++++-
>>  tools/perf/builtin-script.c           |  2 +-
>>  tools/perf/util/branch.c              | 52 ++++++++++++++++++++++++++-
>>  tools/perf/util/branch.h              |  6 +++-
>>  tools/perf/util/session.c             |  2 +-
>>  5 files changed, 73 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
>> index 146c137ff0c1..0f7c7ce29899 100644
>> --- a/tools/include/uapi/linux/perf_event.h
>> +++ b/tools/include/uapi/linux/perf_event.h
>> @@ -255,9 +255,22 @@ enum {
>>  	PERF_BR_IRQ		= 12,	/* irq */
>>  	PERF_BR_SERROR		= 13,	/* system error */
>>  	PERF_BR_NO_TX		= 14,	/* not in transaction */
>> +	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
>>  	PERF_BR_MAX,
>>  };
>>  
>> +enum {
>> +	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
>> +	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
>> +	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
>> +	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
>> +	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
>> +	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
>> +	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
>> +	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
>> +	PERF_BR_NEW_MAX,
>> +};
>> +
>>  #define PERF_SAMPLE_BRANCH_PLM_ALL \
>>  	(PERF_SAMPLE_BRANCH_USER|\
>>  	 PERF_SAMPLE_BRANCH_KERNEL|\
>> @@ -1375,7 +1388,8 @@ struct perf_branch_entry {
>>  		abort:1,    /* transaction abort */
>>  		cycles:16,  /* cycle count to last branch */
>>  		type:4,     /* branch type */
>> -		reserved:40;
>> +		new_type:4, /* additional branch type */
>> +		reserved:36;
>>  };
>>  
>>  union perf_sample_weight {
>> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
>> index 13580a9c50b8..585171479876 100644
>> --- a/tools/perf/builtin-script.c
>> +++ b/tools/perf/builtin-script.c
>> @@ -877,7 +877,7 @@ static int print_bstack_flags(FILE *fp, struct branch_entry *br)
>>  		       br->flags.in_tx ? 'X' : '-',
>>  		       br->flags.abort ? 'A' : '-',
>>  		       br->flags.cycles,
>> -		       br->flags.type ? branch_type_name(br->flags.type) : "-");
>> +		       get_branch_type(br));
>>  }
>>  
>>  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 abc673347bee..6d962b0a4532 100644
>> --- a/tools/perf/util/branch.c
>> +++ b/tools/perf/util/branch.c
>> @@ -21,7 +21,10 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
>>  	if (flags->type == PERF_BR_UNKNOWN || from == 0)
>>  		return;
>>  
>> -	st->counts[flags->type]++;
>> +	if (flags->type == PERF_BR_EXTEND_ABI)
>> +		st->new_counts[flags->new_type]++;
>> +	else
>> +		st->counts[flags->type]++;
>>  
>>  	if (flags->type == PERF_BR_COND) {
>>  		if (to > from)
>> @@ -36,6 +39,25 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
>>  		st->cross_4k++;
>>  }
>>  
>> +const char *branch_new_type_name(int new_type)
>> +{
>> +	const char *branch_new_names[PERF_BR_NEW_MAX] = {
>> +		"FAULT_ALGN",
>> +		"FAULT_DATA",
>> +		"FAULT_INST",
>> +		"ARCH_1",
>> +		"ARCH_2",
>> +		"ARCH_3",
>> +		"ARCH_4",
>> +		"ARCH_5"
>> +	};
>> +
>> +	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
>> +		return branch_new_names[new_type];
>> +
>> +	return NULL;
>> +}
>> +
>>  const char *branch_type_name(int type)
>>  {
>>  	const char *branch_names[PERF_BR_MAX] = {
>> @@ -62,6 +84,17 @@ const char *branch_type_name(int type)
>>  	return NULL;
>>  }
>>  
>> +const char *get_branch_type(struct branch_entry *e)
>> +{
>> +	if (e->flags.type == PERF_BR_UNKNOWN)
>> +		return "";
>> +
>> +	if (e->flags.type == PERF_BR_EXTEND_ABI)
>> +		return branch_new_type_name(e->flags.new_type);
>> +
>> +	return branch_type_name(e->flags.type);
>> +}
>> +
>>  void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
>>  {
>>  	u64 total = 0;
>> @@ -108,6 +141,15 @@ void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
>>  				100.0 *
>>  				(double)st->counts[i] / (double)total);
>>  	}
>> +
>> +	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
>> +		if (st->new_counts[i] > 0)
>> +			fprintf(fp, "\n%8s: %5.1f%%",
>> +				branch_new_type_name(i),
>> +				100.0 *
>> +				(double)st->new_counts[i] / (double)total);
>> +	}
>> +
> Strange:
> 
>   75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
>         inlined from 'branch_type_stat_display' at util/branch.c:152:4:
>     /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
>       100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
>           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>       101 |    __va_arg_pack ());
>           |    ~~~~~~~~~~~~~~~~~
> 

Indeed. But this new code block here looks exact same like the previous and existing one
i.e with branch_new_name() and PERF_BR_NEW_MAX. The complain is that - '%8s' directive
argument is NULL. This warning might just be a false positive [1], because of a compiler
problem on powerpc64el ? But please do let me know if something needs to be changed here
to avoid this warning.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036

- Anshuman

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 6/8] perf/tools: Extend branch type classification
  2022-09-01  5:07       ` Anshuman Khandual
@ 2022-09-02 17:31         ` Arnaldo Carvalho de Melo
  -1 siblings, 0 replies; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-09-02 17:31 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Em Thu, Sep 01, 2022 at 10:37:24AM +0530, Anshuman Khandual escreveu:
> 
> 
> On 8/31/22 02:41, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Aug 24, 2022 at 10:18:20AM +0530, Anshuman Khandual escreveu:
> >> This updates the perf tool with generic branch type classification with new
> >> ABI extender place holder i.e PERF_BR_EXTEND_ABI, the new 4 bit branch type
> >> field i.e perf_branch_entry.new_type, new generic page fault related branch
> >> types and some arch specific branch types as added earlier in the kernel.
> >>
> >> Cc: Peter Zijlstra <peterz@infradead.org>
> >> Cc: Ingo Molnar <mingo@redhat.com>
> >> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> >> Cc: Mark Rutland <mark.rutland@arm.com>
> >> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> >> Cc: Jiri Olsa <jolsa@redhat.com>
> >> Cc: Namhyung Kim <namhyung@kernel.org>
> >> Cc: Thomas Gleixner <tglx@linutronix.de>
> >> Cc: Will Deacon <will@kernel.org>
> >> Cc: linux-arm-kernel@lists.infradead.org
> >> Cc: linux-perf-users@vger.kernel.org
> >> Cc: linux-kernel@vger.kernel.org
> >> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> >> ---
> >>  tools/include/uapi/linux/perf_event.h | 16 ++++++++-
> >>  tools/perf/builtin-script.c           |  2 +-
> >>  tools/perf/util/branch.c              | 52 ++++++++++++++++++++++++++-
> >>  tools/perf/util/branch.h              |  6 +++-
> >>  tools/perf/util/session.c             |  2 +-
> >>  5 files changed, 73 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
> >> index 146c137ff0c1..0f7c7ce29899 100644
> >> --- a/tools/include/uapi/linux/perf_event.h
> >> +++ b/tools/include/uapi/linux/perf_event.h
> >> @@ -255,9 +255,22 @@ enum {
> >>  	PERF_BR_IRQ		= 12,	/* irq */
> >>  	PERF_BR_SERROR		= 13,	/* system error */
> >>  	PERF_BR_NO_TX		= 14,	/* not in transaction */
> >> +	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
> >>  	PERF_BR_MAX,
> >>  };
> >>  
> >> +enum {
> >> +	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
> >> +	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
> >> +	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
> >> +	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
> >> +	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
> >> +	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
> >> +	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
> >> +	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
> >> +	PERF_BR_NEW_MAX,
> >> +};
> >> +
> >>  #define PERF_SAMPLE_BRANCH_PLM_ALL \
> >>  	(PERF_SAMPLE_BRANCH_USER|\
> >>  	 PERF_SAMPLE_BRANCH_KERNEL|\
> >> @@ -1375,7 +1388,8 @@ struct perf_branch_entry {
> >>  		abort:1,    /* transaction abort */
> >>  		cycles:16,  /* cycle count to last branch */
> >>  		type:4,     /* branch type */
> >> -		reserved:40;
> >> +		new_type:4, /* additional branch type */
> >> +		reserved:36;
> >>  };
> >>  
> >>  union perf_sample_weight {
> >> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> >> index 13580a9c50b8..585171479876 100644
> >> --- a/tools/perf/builtin-script.c
> >> +++ b/tools/perf/builtin-script.c
> >> @@ -877,7 +877,7 @@ static int print_bstack_flags(FILE *fp, struct branch_entry *br)
> >>  		       br->flags.in_tx ? 'X' : '-',
> >>  		       br->flags.abort ? 'A' : '-',
> >>  		       br->flags.cycles,
> >> -		       br->flags.type ? branch_type_name(br->flags.type) : "-");
> >> +		       get_branch_type(br));
> >>  }
> >>  
> >>  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 abc673347bee..6d962b0a4532 100644
> >> --- a/tools/perf/util/branch.c
> >> +++ b/tools/perf/util/branch.c
> >> @@ -21,7 +21,10 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
> >>  	if (flags->type == PERF_BR_UNKNOWN || from == 0)
> >>  		return;
> >>  
> >> -	st->counts[flags->type]++;
> >> +	if (flags->type == PERF_BR_EXTEND_ABI)
> >> +		st->new_counts[flags->new_type]++;
> >> +	else
> >> +		st->counts[flags->type]++;
> >>  
> >>  	if (flags->type == PERF_BR_COND) {
> >>  		if (to > from)
> >> @@ -36,6 +39,25 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
> >>  		st->cross_4k++;
> >>  }
> >>  
> >> +const char *branch_new_type_name(int new_type)
> >> +{
> >> +	const char *branch_new_names[PERF_BR_NEW_MAX] = {
> >> +		"FAULT_ALGN",
> >> +		"FAULT_DATA",
> >> +		"FAULT_INST",
> >> +		"ARCH_1",
> >> +		"ARCH_2",
> >> +		"ARCH_3",
> >> +		"ARCH_4",
> >> +		"ARCH_5"
> >> +	};
> >> +
> >> +	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
> >> +		return branch_new_names[new_type];
> >> +
> >> +	return NULL;
> >> +}
> >> +
> >>  const char *branch_type_name(int type)
> >>  {
> >>  	const char *branch_names[PERF_BR_MAX] = {
> >> @@ -62,6 +84,17 @@ const char *branch_type_name(int type)
> >>  	return NULL;
> >>  }
> >>  
> >> +const char *get_branch_type(struct branch_entry *e)
> >> +{
> >> +	if (e->flags.type == PERF_BR_UNKNOWN)
> >> +		return "";
> >> +
> >> +	if (e->flags.type == PERF_BR_EXTEND_ABI)
> >> +		return branch_new_type_name(e->flags.new_type);
> >> +
> >> +	return branch_type_name(e->flags.type);
> >> +}
> >> +
> >>  void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
> >>  {
> >>  	u64 total = 0;
> >> @@ -108,6 +141,15 @@ void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
> >>  				100.0 *
> >>  				(double)st->counts[i] / (double)total);
> >>  	}
> >> +
> >> +	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
> >> +		if (st->new_counts[i] > 0)
> >> +			fprintf(fp, "\n%8s: %5.1f%%",
> >> +				branch_new_type_name(i),
> >> +				100.0 *
> >> +				(double)st->new_counts[i] / (double)total);
> >> +	}
> >> +
> > Strange:
> > 
> >   75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
> >         inlined from 'branch_type_stat_display' at util/branch.c:152:4:
> >     /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
> >       100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
> >           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >       101 |    __va_arg_pack ());
> >           |    ~~~~~~~~~~~~~~~~~
> > 
> 
> Indeed. But this new code block here looks exact same like the previous and existing one
> i.e with branch_new_name() and PERF_BR_NEW_MAX. The complain is that - '%8s' directive
> argument is NULL. This warning might just be a false positive [1], because of a compiler
> problem on powerpc64el ? But please do let me know if something needs to be changed here
> to avoid this warning.
> 
> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
> 

So, I tried not returning NULL in the functions that are ultimately
called, but that didn't help, so I'll try just disabling that specific
warning for this specific file.

The patch that didn't help is below.

- Arnaldo

commit 07c96060c410db6d10dbbdffb22bb46afebfe2c0
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date:   Wed Aug 31 13:26:22 2022 -0300

    perf branch: Don't return NULL on function that is used in a %s printf format
    
    To address this warning:
    
      In file included from /usr/include/stdio.h:866,
                       from /home/sfr/next/next/tools/perf/util/branch.h:9,
                       from util/branch.c:2:
      In function 'fprintf',
          inlined from 'branch_type_stat_display' at util/branch.c:152:4:
      /usr/include/powerpc64le-linux-gnu/bits/stdio2.h:105:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
        105 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
            |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        106 |                         __va_arg_pack ());
            |                         ~~~~~~~~~~~~~~~~~
      cc1: all warnings being treated as errors
    
    Fixes: 9781e500dcb87eeb ("perf branch: Extend branch type classification")
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

diff --git a/tools/perf/util/branch.c b/tools/perf/util/branch.c
index d40776c44b060b7e..f30366999f01e5e7 100644
--- a/tools/perf/util/branch.c
+++ b/tools/perf/util/branch.c
@@ -68,7 +68,7 @@ const char *branch_new_type_name(int new_type)
 	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
 		return branch_new_names[new_type];
 
-	return NULL;
+	return "<<INVALID>>";
 }
 
 const char *branch_type_name(int type)
@@ -94,7 +94,7 @@ const char *branch_type_name(int type)
 	if (type >= 0 && type < PERF_BR_MAX)
 		return branch_names[type];
 
-	return NULL;
+	return "<<INVALID>>";
 }
 
 const char *get_branch_type(struct branch_entry *e)

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 6/8] perf/tools: Extend branch type classification
@ 2022-09-02 17:31         ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-09-02 17:31 UTC (permalink / raw)
  To: Anshuman Khandual
  Cc: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Em Thu, Sep 01, 2022 at 10:37:24AM +0530, Anshuman Khandual escreveu:
> 
> 
> On 8/31/22 02:41, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Aug 24, 2022 at 10:18:20AM +0530, Anshuman Khandual escreveu:
> >> This updates the perf tool with generic branch type classification with new
> >> ABI extender place holder i.e PERF_BR_EXTEND_ABI, the new 4 bit branch type
> >> field i.e perf_branch_entry.new_type, new generic page fault related branch
> >> types and some arch specific branch types as added earlier in the kernel.
> >>
> >> Cc: Peter Zijlstra <peterz@infradead.org>
> >> Cc: Ingo Molnar <mingo@redhat.com>
> >> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> >> Cc: Mark Rutland <mark.rutland@arm.com>
> >> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> >> Cc: Jiri Olsa <jolsa@redhat.com>
> >> Cc: Namhyung Kim <namhyung@kernel.org>
> >> Cc: Thomas Gleixner <tglx@linutronix.de>
> >> Cc: Will Deacon <will@kernel.org>
> >> Cc: linux-arm-kernel@lists.infradead.org
> >> Cc: linux-perf-users@vger.kernel.org
> >> Cc: linux-kernel@vger.kernel.org
> >> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
> >> ---
> >>  tools/include/uapi/linux/perf_event.h | 16 ++++++++-
> >>  tools/perf/builtin-script.c           |  2 +-
> >>  tools/perf/util/branch.c              | 52 ++++++++++++++++++++++++++-
> >>  tools/perf/util/branch.h              |  6 +++-
> >>  tools/perf/util/session.c             |  2 +-
> >>  5 files changed, 73 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
> >> index 146c137ff0c1..0f7c7ce29899 100644
> >> --- a/tools/include/uapi/linux/perf_event.h
> >> +++ b/tools/include/uapi/linux/perf_event.h
> >> @@ -255,9 +255,22 @@ enum {
> >>  	PERF_BR_IRQ		= 12,	/* irq */
> >>  	PERF_BR_SERROR		= 13,	/* system error */
> >>  	PERF_BR_NO_TX		= 14,	/* not in transaction */
> >> +	PERF_BR_EXTEND_ABI	= 15,	/* extend ABI */
> >>  	PERF_BR_MAX,
> >>  };
> >>  
> >> +enum {
> >> +	PERF_BR_NEW_FAULT_ALGN		= 0,    /* Alignment fault */
> >> +	PERF_BR_NEW_FAULT_DATA		= 1,    /* Data fault */
> >> +	PERF_BR_NEW_FAULT_INST		= 2,    /* Inst fault */
> >> +	PERF_BR_NEW_ARCH_1		= 3,    /* Architecture specific */
> >> +	PERF_BR_NEW_ARCH_2		= 4,    /* Architecture specific */
> >> +	PERF_BR_NEW_ARCH_3		= 5,    /* Architecture specific */
> >> +	PERF_BR_NEW_ARCH_4		= 6,    /* Architecture specific */
> >> +	PERF_BR_NEW_ARCH_5		= 7,    /* Architecture specific */
> >> +	PERF_BR_NEW_MAX,
> >> +};
> >> +
> >>  #define PERF_SAMPLE_BRANCH_PLM_ALL \
> >>  	(PERF_SAMPLE_BRANCH_USER|\
> >>  	 PERF_SAMPLE_BRANCH_KERNEL|\
> >> @@ -1375,7 +1388,8 @@ struct perf_branch_entry {
> >>  		abort:1,    /* transaction abort */
> >>  		cycles:16,  /* cycle count to last branch */
> >>  		type:4,     /* branch type */
> >> -		reserved:40;
> >> +		new_type:4, /* additional branch type */
> >> +		reserved:36;
> >>  };
> >>  
> >>  union perf_sample_weight {
> >> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> >> index 13580a9c50b8..585171479876 100644
> >> --- a/tools/perf/builtin-script.c
> >> +++ b/tools/perf/builtin-script.c
> >> @@ -877,7 +877,7 @@ static int print_bstack_flags(FILE *fp, struct branch_entry *br)
> >>  		       br->flags.in_tx ? 'X' : '-',
> >>  		       br->flags.abort ? 'A' : '-',
> >>  		       br->flags.cycles,
> >> -		       br->flags.type ? branch_type_name(br->flags.type) : "-");
> >> +		       get_branch_type(br));
> >>  }
> >>  
> >>  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 abc673347bee..6d962b0a4532 100644
> >> --- a/tools/perf/util/branch.c
> >> +++ b/tools/perf/util/branch.c
> >> @@ -21,7 +21,10 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
> >>  	if (flags->type == PERF_BR_UNKNOWN || from == 0)
> >>  		return;
> >>  
> >> -	st->counts[flags->type]++;
> >> +	if (flags->type == PERF_BR_EXTEND_ABI)
> >> +		st->new_counts[flags->new_type]++;
> >> +	else
> >> +		st->counts[flags->type]++;
> >>  
> >>  	if (flags->type == PERF_BR_COND) {
> >>  		if (to > from)
> >> @@ -36,6 +39,25 @@ void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
> >>  		st->cross_4k++;
> >>  }
> >>  
> >> +const char *branch_new_type_name(int new_type)
> >> +{
> >> +	const char *branch_new_names[PERF_BR_NEW_MAX] = {
> >> +		"FAULT_ALGN",
> >> +		"FAULT_DATA",
> >> +		"FAULT_INST",
> >> +		"ARCH_1",
> >> +		"ARCH_2",
> >> +		"ARCH_3",
> >> +		"ARCH_4",
> >> +		"ARCH_5"
> >> +	};
> >> +
> >> +	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
> >> +		return branch_new_names[new_type];
> >> +
> >> +	return NULL;
> >> +}
> >> +
> >>  const char *branch_type_name(int type)
> >>  {
> >>  	const char *branch_names[PERF_BR_MAX] = {
> >> @@ -62,6 +84,17 @@ const char *branch_type_name(int type)
> >>  	return NULL;
> >>  }
> >>  
> >> +const char *get_branch_type(struct branch_entry *e)
> >> +{
> >> +	if (e->flags.type == PERF_BR_UNKNOWN)
> >> +		return "";
> >> +
> >> +	if (e->flags.type == PERF_BR_EXTEND_ABI)
> >> +		return branch_new_type_name(e->flags.new_type);
> >> +
> >> +	return branch_type_name(e->flags.type);
> >> +}
> >> +
> >>  void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
> >>  {
> >>  	u64 total = 0;
> >> @@ -108,6 +141,15 @@ void branch_type_stat_display(FILE *fp, struct branch_type_stat *st)
> >>  				100.0 *
> >>  				(double)st->counts[i] / (double)total);
> >>  	}
> >> +
> >> +	for (i = 0; i < PERF_BR_NEW_MAX; i++) {
> >> +		if (st->new_counts[i] > 0)
> >> +			fprintf(fp, "\n%8s: %5.1f%%",
> >> +				branch_new_type_name(i),
> >> +				100.0 *
> >> +				(double)st->new_counts[i] / (double)total);
> >> +	}
> >> +
> > Strange:
> > 
> >   75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
> >         inlined from 'branch_type_stat_display' at util/branch.c:152:4:
> >     /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
> >       100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
> >           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >       101 |    __va_arg_pack ());
> >           |    ~~~~~~~~~~~~~~~~~
> > 
> 
> Indeed. But this new code block here looks exact same like the previous and existing one
> i.e with branch_new_name() and PERF_BR_NEW_MAX. The complain is that - '%8s' directive
> argument is NULL. This warning might just be a false positive [1], because of a compiler
> problem on powerpc64el ? But please do let me know if something needs to be changed here
> to avoid this warning.
> 
> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
> 

So, I tried not returning NULL in the functions that are ultimately
called, but that didn't help, so I'll try just disabling that specific
warning for this specific file.

The patch that didn't help is below.

- Arnaldo

commit 07c96060c410db6d10dbbdffb22bb46afebfe2c0
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date:   Wed Aug 31 13:26:22 2022 -0300

    perf branch: Don't return NULL on function that is used in a %s printf format
    
    To address this warning:
    
      In file included from /usr/include/stdio.h:866,
                       from /home/sfr/next/next/tools/perf/util/branch.h:9,
                       from util/branch.c:2:
      In function 'fprintf',
          inlined from 'branch_type_stat_display' at util/branch.c:152:4:
      /usr/include/powerpc64le-linux-gnu/bits/stdio2.h:105:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
        105 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
            |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        106 |                         __va_arg_pack ());
            |                         ~~~~~~~~~~~~~~~~~
      cc1: all warnings being treated as errors
    
    Fixes: 9781e500dcb87eeb ("perf branch: Extend branch type classification")
    Cc: Anshuman Khandual <anshuman.khandual@arm.com>
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

diff --git a/tools/perf/util/branch.c b/tools/perf/util/branch.c
index d40776c44b060b7e..f30366999f01e5e7 100644
--- a/tools/perf/util/branch.c
+++ b/tools/perf/util/branch.c
@@ -68,7 +68,7 @@ const char *branch_new_type_name(int new_type)
 	if (new_type >= 0 && new_type < PERF_BR_NEW_MAX)
 		return branch_new_names[new_type];
 
-	return NULL;
+	return "<<INVALID>>";
 }
 
 const char *branch_type_name(int type)
@@ -94,7 +94,7 @@ const char *branch_type_name(int type)
 	if (type >= 0 && type < PERF_BR_MAX)
 		return branch_names[type];
 
-	return NULL;
+	return "<<INVALID>>";
 }
 
 const char *get_branch_type(struct branch_entry *e)

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 6/8] perf/tools: Extend branch type classification
  2022-09-02 17:31         ` Arnaldo Carvalho de Melo
@ 2022-09-02 17:46           ` Arnaldo Carvalho de Melo
  -1 siblings, 0 replies; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-09-02 17:46 UTC (permalink / raw)
  To: Anshuman Khandual, Stephen Rothwell
  Cc: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Em Fri, Sep 02, 2022 at 02:31:34PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Thu, Sep 01, 2022 at 10:37:24AM +0530, Anshuman Khandual escreveu:
> > On 8/31/22 02:41, Arnaldo Carvalho de Melo wrote:
> > > Strange:
> > > 
> > >   75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
> > >         inlined from 'branch_type_stat_display' at util/branch.c:152:4:
> > >     /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
> > >       100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
> > >           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >       101 |    __va_arg_pack ());
> > >           |    ~~~~~~~~~~~~~~~~~
> > > 
> > 
> > Indeed. But this new code block here looks exact same like the previous and existing one
> > i.e with branch_new_name() and PERF_BR_NEW_MAX. The complain is that - '%8s' directive
> > argument is NULL. This warning might just be a false positive [1], because of a compiler
> > problem on powerpc64el ? But please do let me know if something needs to be changed here
> > to avoid this warning.
> > 
> > [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
> > 
> 
> So, I tried not returning NULL in the functions that are ultimately
> called, but that didn't help, so I'll try just disabling that specific
> warning for this specific file.

Got it building:

    23.68 ubuntu:20.04-x-powerpc64el    : Ok   powerpc64le-linux-gnu-gcc (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0
BUILD_TARBALL_HEAD=b0f700972d9d0c9b8e73f69ccf0e56d74c580d71

With:

From b0f700972d9d0c9b8e73f69ccf0e56d74c580d71 Mon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Fri, 2 Sep 2022 14:35:26 -0300
Subject: [PATCH 1/1] perf build: Avoid false positive with
 -Werror=format-overflow= with gcc 10.3.0 on powerpc

When building with gcc 10.3.0 on powerpc this is happening:

   75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
         inlined from 'branch_type_stat_display' at util/branch.c:152:4:
     /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
       100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       101 |    __va_arg_pack ());
           |    ~~~~~~~~~~~~~~~~~

Looks related to:

  [10/11/12/13 Regression] false positive: directive argument is null [-Werror=format-overflow=]
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036

So lets disable this just for the util/branch.o file.

Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Link: http://lore.kernel.org/lkml/YxI99uLvpgAZjm2r@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/Build | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 8fd6dc8de5210336..20a5524e88a04d44 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -223,6 +223,10 @@ CFLAGS_llvm-utils.o += -DPERF_INCLUDE_DIR="BUILD_STR($(perf_include_dir_SQ))"
 # avoid compiler warnings in 32-bit mode
 CFLAGS_genelf_debug.o  += -Wno-packed
 
+# avoid false positive when building with gcc 10.3.0 on powerpc
+# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
+CFLAGS_branch.o += -Wno-format-overflow
+
 $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-flex.h: util/parse-events.l $(OUTPUT)util/parse-events-bison.c
 	$(call rule_mkdir)
 	$(Q)$(call echo-cmd,flex)$(FLEX) -o $(OUTPUT)util/parse-events-flex.c \
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 6/8] perf/tools: Extend branch type classification
@ 2022-09-02 17:46           ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 40+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-09-02 17:46 UTC (permalink / raw)
  To: Anshuman Khandual, Stephen Rothwell
  Cc: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel

Em Fri, Sep 02, 2022 at 02:31:34PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Thu, Sep 01, 2022 at 10:37:24AM +0530, Anshuman Khandual escreveu:
> > On 8/31/22 02:41, Arnaldo Carvalho de Melo wrote:
> > > Strange:
> > > 
> > >   75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
> > >         inlined from 'branch_type_stat_display' at util/branch.c:152:4:
> > >     /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
> > >       100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
> > >           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >       101 |    __va_arg_pack ());
> > >           |    ~~~~~~~~~~~~~~~~~
> > > 
> > 
> > Indeed. But this new code block here looks exact same like the previous and existing one
> > i.e with branch_new_name() and PERF_BR_NEW_MAX. The complain is that - '%8s' directive
> > argument is NULL. This warning might just be a false positive [1], because of a compiler
> > problem on powerpc64el ? But please do let me know if something needs to be changed here
> > to avoid this warning.
> > 
> > [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
> > 
> 
> So, I tried not returning NULL in the functions that are ultimately
> called, but that didn't help, so I'll try just disabling that specific
> warning for this specific file.

Got it building:

    23.68 ubuntu:20.04-x-powerpc64el    : Ok   powerpc64le-linux-gnu-gcc (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0
BUILD_TARBALL_HEAD=b0f700972d9d0c9b8e73f69ccf0e56d74c580d71

With:

From b0f700972d9d0c9b8e73f69ccf0e56d74c580d71 Mon Sep 17 00:00:00 2001
From: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Fri, 2 Sep 2022 14:35:26 -0300
Subject: [PATCH 1/1] perf build: Avoid false positive with
 -Werror=format-overflow= with gcc 10.3.0 on powerpc

When building with gcc 10.3.0 on powerpc this is happening:

   75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
         inlined from 'branch_type_stat_display' at util/branch.c:152:4:
     /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
       100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       101 |    __va_arg_pack ());
           |    ~~~~~~~~~~~~~~~~~

Looks related to:

  [10/11/12/13 Regression] false positive: directive argument is null [-Werror=format-overflow=]
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036

So lets disable this just for the util/branch.o file.

Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Link: http://lore.kernel.org/lkml/YxI99uLvpgAZjm2r@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/Build | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 8fd6dc8de5210336..20a5524e88a04d44 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -223,6 +223,10 @@ CFLAGS_llvm-utils.o += -DPERF_INCLUDE_DIR="BUILD_STR($(perf_include_dir_SQ))"
 # avoid compiler warnings in 32-bit mode
 CFLAGS_genelf_debug.o  += -Wno-packed
 
+# avoid false positive when building with gcc 10.3.0 on powerpc
+# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
+CFLAGS_branch.o += -Wno-format-overflow
+
 $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-flex.h: util/parse-events.l $(OUTPUT)util/parse-events-bison.c
 	$(call rule_mkdir)
 	$(Q)$(call echo-cmd,flex)$(FLEX) -o $(OUTPUT)util/parse-events-flex.c \
-- 
2.37.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 6/8] perf/tools: Extend branch type classification
  2022-09-02 17:46           ` Arnaldo Carvalho de Melo
@ 2022-09-05  8:00             ` Anshuman Khandual
  -1 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-09-05  8:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Stephen Rothwell
  Cc: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel



On 9/2/22 23:16, Arnaldo Carvalho de Melo wrote:
> Em Fri, Sep 02, 2022 at 02:31:34PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Thu, Sep 01, 2022 at 10:37:24AM +0530, Anshuman Khandual escreveu:
>>> On 8/31/22 02:41, Arnaldo Carvalho de Melo wrote:
>>>> Strange:
>>>>
>>>>   75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
>>>>         inlined from 'branch_type_stat_display' at util/branch.c:152:4:
>>>>     /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
>>>>       100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
>>>>           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>       101 |    __va_arg_pack ());
>>>>           |    ~~~~~~~~~~~~~~~~~
>>>>
>>>
>>> Indeed. But this new code block here looks exact same like the previous and existing one
>>> i.e with branch_new_name() and PERF_BR_NEW_MAX. The complain is that - '%8s' directive
>>> argument is NULL. This warning might just be a false positive [1], because of a compiler
>>> problem on powerpc64el ? But please do let me know if something needs to be changed here
>>> to avoid this warning.
>>>
>>> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
>>>
>>
>> So, I tried not returning NULL in the functions that are ultimately
>> called, but that didn't help, so I'll try just disabling that specific
>> warning for this specific file.
> 
> Got it building:

Thanks Arnaldo, I guess all the tool changes in this series, along with this
build will land in linux-next later for more test coverage.

> 
>     23.68 ubuntu:20.04-x-powerpc64el    : Ok   powerpc64le-linux-gnu-gcc (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0
> BUILD_TARBALL_HEAD=b0f700972d9d0c9b8e73f69ccf0e56d74c580d71
> 
> With:
> 
>>From b0f700972d9d0c9b8e73f69ccf0e56d74c580d71 Mon Sep 17 00:00:00 2001
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
> Date: Fri, 2 Sep 2022 14:35:26 -0300
> Subject: [PATCH 1/1] perf build: Avoid false positive with
>  -Werror=format-overflow= with gcc 10.3.0 on powerpc
> 
> When building with gcc 10.3.0 on powerpc this is happening:
> 
>    75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
>          inlined from 'branch_type_stat_display' at util/branch.c:152:4:
>      /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
>        100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
>            |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>        101 |    __va_arg_pack ());
>            |    ~~~~~~~~~~~~~~~~~
> 
> Looks related to:
> 
>   [10/11/12/13 Regression] false positive: directive argument is null [-Werror=format-overflow=]
>   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
> 
> So lets disable this just for the util/branch.o file.
> 
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: James Clark <james.clark@arm.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Will Deacon <will@kernel.org>
> Link: http://lore.kernel.org/lkml/YxI99uLvpgAZjm2r@kernel.org
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/perf/util/Build | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index 8fd6dc8de5210336..20a5524e88a04d44 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -223,6 +223,10 @@ CFLAGS_llvm-utils.o += -DPERF_INCLUDE_DIR="BUILD_STR($(perf_include_dir_SQ))"
>  # avoid compiler warnings in 32-bit mode
>  CFLAGS_genelf_debug.o  += -Wno-packed
>  
> +# avoid false positive when building with gcc 10.3.0 on powerpc
> +# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
> +CFLAGS_branch.o += -Wno-format-overflow
> +
>  $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-flex.h: util/parse-events.l $(OUTPUT)util/parse-events-bison.c
>  	$(call rule_mkdir)
>  	$(Q)$(call echo-cmd,flex)$(FLEX) -o $(OUTPUT)util/parse-events-flex.c \

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [PATCH V7 6/8] perf/tools: Extend branch type classification
@ 2022-09-05  8:00             ` Anshuman Khandual
  0 siblings, 0 replies; 40+ messages in thread
From: Anshuman Khandual @ 2022-09-05  8:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Stephen Rothwell
  Cc: linux-kernel, linux-perf-users, peterz, alexander.shishkin,
	jolsa, mark.rutland, Robin Murphy, Suzuki Poulose, James Clark,
	Ingo Molnar, Namhyung Kim, Thomas Gleixner, Will Deacon,
	Catalin Marinas, linux-arm-kernel



On 9/2/22 23:16, Arnaldo Carvalho de Melo wrote:
> Em Fri, Sep 02, 2022 at 02:31:34PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Thu, Sep 01, 2022 at 10:37:24AM +0530, Anshuman Khandual escreveu:
>>> On 8/31/22 02:41, Arnaldo Carvalho de Melo wrote:
>>>> Strange:
>>>>
>>>>   75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
>>>>         inlined from 'branch_type_stat_display' at util/branch.c:152:4:
>>>>     /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
>>>>       100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
>>>>           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>       101 |    __va_arg_pack ());
>>>>           |    ~~~~~~~~~~~~~~~~~
>>>>
>>>
>>> Indeed. But this new code block here looks exact same like the previous and existing one
>>> i.e with branch_new_name() and PERF_BR_NEW_MAX. The complain is that - '%8s' directive
>>> argument is NULL. This warning might just be a false positive [1], because of a compiler
>>> problem on powerpc64el ? But please do let me know if something needs to be changed here
>>> to avoid this warning.
>>>
>>> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
>>>
>>
>> So, I tried not returning NULL in the functions that are ultimately
>> called, but that didn't help, so I'll try just disabling that specific
>> warning for this specific file.
> 
> Got it building:

Thanks Arnaldo, I guess all the tool changes in this series, along with this
build will land in linux-next later for more test coverage.

> 
>     23.68 ubuntu:20.04-x-powerpc64el    : Ok   powerpc64le-linux-gnu-gcc (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0
> BUILD_TARBALL_HEAD=b0f700972d9d0c9b8e73f69ccf0e56d74c580d71
> 
> With:
> 
>>From b0f700972d9d0c9b8e73f69ccf0e56d74c580d71 Mon Sep 17 00:00:00 2001
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
> Date: Fri, 2 Sep 2022 14:35:26 -0300
> Subject: [PATCH 1/1] perf build: Avoid false positive with
>  -Werror=format-overflow= with gcc 10.3.0 on powerpc
> 
> When building with gcc 10.3.0 on powerpc this is happening:
> 
>    75     8.89 ubuntu:20.04-x-powerpc64el    : FAIL gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
>          inlined from 'branch_type_stat_display' at util/branch.c:152:4:
>      /usr/powerpc64le-linux-gnu/include/bits/stdio2.h:100:10: error: '%8s' directive argument is null [-Werror=format-overflow=]
>        100 |   return __fprintf_chk (__stream, __USE_FORTIFY_LEVEL - 1, __fmt,
>            |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>        101 |    __va_arg_pack ());
>            |    ~~~~~~~~~~~~~~~~~
> 
> Looks related to:
> 
>   [10/11/12/13 Regression] false positive: directive argument is null [-Werror=format-overflow=]
>   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
> 
> So lets disable this just for the util/branch.o file.
> 
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: James Clark <james.clark@arm.com>
> Cc: Jiri Olsa <jolsa@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Robin Murphy <robin.murphy@arm.com>
> Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Will Deacon <will@kernel.org>
> Link: http://lore.kernel.org/lkml/YxI99uLvpgAZjm2r@kernel.org
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/perf/util/Build | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tools/perf/util/Build b/tools/perf/util/Build
> index 8fd6dc8de5210336..20a5524e88a04d44 100644
> --- a/tools/perf/util/Build
> +++ b/tools/perf/util/Build
> @@ -223,6 +223,10 @@ CFLAGS_llvm-utils.o += -DPERF_INCLUDE_DIR="BUILD_STR($(perf_include_dir_SQ))"
>  # avoid compiler warnings in 32-bit mode
>  CFLAGS_genelf_debug.o  += -Wno-packed
>  
> +# avoid false positive when building with gcc 10.3.0 on powerpc
> +# See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90036
> +CFLAGS_branch.o += -Wno-format-overflow
> +
>  $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-flex.h: util/parse-events.l $(OUTPUT)util/parse-events-bison.c
>  	$(call rule_mkdir)
>  	$(Q)$(call echo-cmd,flex)$(FLEX) -o $(OUTPUT)util/parse-events-flex.c \

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2022-09-05  9:52 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-24  4:48 [PATCH V7 0/8] perf: Expand perf_branch_entry Anshuman Khandual
2022-08-24  4:48 ` Anshuman Khandual
2022-08-24  4:48 ` [PATCH V7 1/8] perf: Add system error and not in transaction branch types Anshuman Khandual
2022-08-24  4:48   ` Anshuman Khandual
2022-08-26 22:15   ` [tip: perf/core] " tip-bot2 for Anshuman Khandual
2022-08-29  7:50   ` tip-bot2 for Anshuman Khandual
2022-08-24  4:48 ` [PATCH V7 2/8] perf: Extend branch type classification Anshuman Khandual
2022-08-24  4:48   ` Anshuman Khandual
2022-08-26 22:15   ` [tip: perf/core] " tip-bot2 for Anshuman Khandual
2022-08-29  7:50   ` tip-bot2 for Anshuman Khandual
2022-08-24  4:48 ` [PATCH V7 3/8] perf: Capture branch privilege information Anshuman Khandual
2022-08-24  4:48   ` Anshuman Khandual
2022-08-26 22:15   ` [tip: perf/core] " tip-bot2 for Anshuman Khandual
2022-08-29  7:50   ` tip-bot2 for Anshuman Khandual
2022-08-24  4:48 ` [PATCH V7 4/8] perf: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform Anshuman Khandual
2022-08-24  4:48   ` Anshuman Khandual
2022-08-26 22:15   ` [tip: perf/core] " tip-bot2 for Anshuman Khandual
2022-08-29  7:49   ` tip-bot2 for Anshuman Khandual
2022-08-24  4:48 ` [PATCH V7 5/8] perf/tools: Add system error and not in transaction branch types Anshuman Khandual
2022-08-24  4:48   ` Anshuman Khandual
2022-08-24  4:48 ` [PATCH V7 6/8] perf/tools: Extend branch type classification Anshuman Khandual
2022-08-24  4:48   ` Anshuman Khandual
2022-08-30 21:11   ` Arnaldo Carvalho de Melo
2022-08-30 21:11     ` Arnaldo Carvalho de Melo
2022-09-01  5:07     ` Anshuman Khandual
2022-09-01  5:07       ` Anshuman Khandual
2022-09-02 17:31       ` Arnaldo Carvalho de Melo
2022-09-02 17:31         ` Arnaldo Carvalho de Melo
2022-09-02 17:46         ` Arnaldo Carvalho de Melo
2022-09-02 17:46           ` Arnaldo Carvalho de Melo
2022-09-05  8:00           ` Anshuman Khandual
2022-09-05  8:00             ` Anshuman Khandual
2022-08-24  4:48 ` [PATCH V7 7/8] perf/tools: Add branch privilege information request flag Anshuman Khandual
2022-08-24  4:48   ` Anshuman Khandual
2022-08-24  4:48 ` [PATCH V7 8/8] perf/tools: Add PERF_BR_NEW_ARCH_[N] map for BRBE on arm64 platform Anshuman Khandual
2022-08-24  4:48   ` Anshuman Khandual
2022-08-25 10:22 ` [PATCH V7 0/8] perf: Expand perf_branch_entry Peter Zijlstra
2022-08-25 10:22   ` Peter Zijlstra
2022-08-29  4:12   ` Anshuman Khandual
2022-08-29  4:12     ` Anshuman Khandual

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.