diff mbox series

[v4,05/12] ARM: vfp: Record VFP bounces as perf emulation faults

Message ID 20230320131845.3138015-6-ardb@kernel.org (mailing list archive)
State New, archived
Headers show
Series ARM: vfp: Switch to C API to en/disable softirqs | expand

Commit Message

Ard Biesheuvel March 20, 2023, 1:18 p.m. UTC
VFP 'bouncing' occurs when the VFP unit cannot complete the execution of
a VFP instruction, either because it is not implemented at all, or
because the values of the arguments are out of range for the hardware
implementation, and the software needs to step in to complete the
operation.

To give some insight in how much certain programs rely on this bouncing,
record the emulation of a VFP instruction in perf's emulation-faults
counter.

This can be used like so

  perf stat -e emulation-faults ./testfloat -all2

and the output will be something like

 Performance counter stats for './testfloat -all2':

           259,277      emulation-faults:u

       6.846432176 seconds time elapsed

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm/vfp/vfpmodule.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Linus Walleij March 21, 2023, 2:33 p.m. UTC | #1
On Mon, Mar 20, 2023 at 2:19 PM Ard Biesheuvel <ardb@kernel.org> wrote:

> VFP 'bouncing' occurs when the VFP unit cannot complete the execution of
> a VFP instruction, either because it is not implemented at all, or
> because the values of the arguments are out of range for the hardware
> implementation, and the software needs to step in to complete the
> operation.
>
> To give some insight in how much certain programs rely on this bouncing,
> record the emulation of a VFP instruction in perf's emulation-faults
> counter.
>
> This can be used like so
>
>   perf stat -e emulation-faults ./testfloat -all2
>
> and the output will be something like
>
>  Performance counter stats for './testfloat -all2':
>
>            259,277      emulation-faults:u
>
>        6.846432176 seconds time elapsed
>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

Oh that's really useful.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c
index 4c7473d2f89a040f..039c8dab990699e2 100644
--- a/arch/arm/vfp/vfpmodule.c
+++ b/arch/arm/vfp/vfpmodule.c
@@ -18,6 +18,7 @@ 
 #include <linux/uaccess.h>
 #include <linux/user.h>
 #include <linux/export.h>
+#include <linux/perf_event.h>
 
 #include <asm/cp15.h>
 #include <asm/cputype.h>
@@ -313,6 +314,7 @@  static u32 vfp_emulate_instruction(u32 inst, u32 fpscr, struct pt_regs *regs)
 		 * emulate it.
 		 */
 	}
+	perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, regs->ARM_pc);
 	return exceptions & ~VFP_NAN_FLAG;
 }