Detecting LD/ST instruction
I am working on implementing the 'perf mem' command for Power systems. This would for instance, let us know where in the memory hierarchy (L1, L2, Local RAM etc) the data for a load/store instruction was found (hit).
On Power7, if the mcmcra[DCACHE_MISS] is clear _and_ the instruction is a load/store, then it implies a L1-hit.
Unlike on Power8, the Power7 event vector has no indication if the instruction was load/store.
In the context of a PMU interrupt, is there any way to determine if an instruction is a load/store ?
Sukadev
Quoted 5 lines
I am working on implementing the 'perf mem' command for Power systems. This would for instance, let us know where in the memory hierarchy (L1, L2, Local RAM etc) the data for a load/store instruction was found (hit).
Quoted 8 lines
On Power7, if the mcmcra[DCACHE_MISS] is clear _and_ the instruction is a load/store, then it implies a L1-hit.
Unlike on Power8, the Power7 event vector has no indication if the instruction was load/store.
In the context of a PMU interrupt, is there any way to determine if an instruction is a load/store ?
You could read the instruction from memory and work it out.
We do something similar to this in power_pmu_bhrb_to() where we read the instruction and work out where the branch is going to.
If you do this, please use and/or extend the functions in arch/powerpc/lib/code-patching.c
Mikey
Michael Neuling [[email protected]] wrote:
| > I am working on implementing the 'perf mem' command for Power | > systems. This would for instance, let us know where in the memory | > hierarchy (L1, L2, Local RAM etc) the data for a load/store | > instruction was found (hit). | > | > On Power7, if the mcmcra[DCACHE_MISS] is clear _and_ the | > instruction is a load/store, then it implies a L1-hit. | > | > Unlike on Power8, the Power7 event vector has no indication | > if the instruction was load/store. | > | > In the context of a PMU interrupt, is there any way to determine | > if an instruction is a load/store ? | | You could read the instruction from memory and work it out. | | We do something similar to this in power_pmu_bhrb_to() where we read the | instruction and work out where the branch is going to. | | If you do this, please use and/or extend the functions in | arch/powerpc/lib/code-patching.c
Here is a draft of what I could come up with. With this patch, the number of L1 hits on Power7 matches that on Power8 for one application.
But, wondering if there is a more efficient way to do this - there are over 50 flavors of load and store!
(btw, I will resend my whole patchset after some time-off).
---
Quoted 1 line
From
db90cd382f4c1c0d84a0cfb07c9ffdb05d529456Mon Sep 17 00:00:00 2001
From: Sukadev Bhattiprolu <[email protected]>
Date: Fri, 23 Aug 2013 18:35:02 -0700
Subject: [PATCH 1/1] Try to detect load/store instruction on Power7
--- arch/powerpc/include/asm/code-patching.h | 1 + arch/powerpc/lib/code-patching.c | 97 ++++++++++++++++++++++++++++++ arch/powerpc/perf/power7-pmu.c | 21 +++++++ 3 files changed, 119 insertions(+)
arch/powerpc/include/asm/code-patching.h +1 -0
@@ -34,6 +34,7 @@ int instr_is_branch_to_addr(const unsigned int *instr, unsigned long addr);unsigned long branch_target (const unsigned int *instr);unsigned int translate_branch (const unsigned int *dest,const unsigned int *src); +int instr_is_load_store (const unsigned int *instr);static inline unsigned long ppc_function_entry (void *func) {
arch/powerpc/lib/code-patching.c +97 -0
103 lines not on this page · raw message
arch/powerpc/perf/power7-pmu.c +21 -0
@@ -11,8 +11,10 @@#include <linux/kernel.h> #include <linux/perf_event.h> #include <linux/string.h> +#include <linux/uaccess.h> #include <asm/reg.h> #include <asm/cputable.h> +#include <asm/code-patching.h> /* * Bits in event code for POWER7
@@ -383,13 +385,32 @@ static void power7_get_mem_data_src(union perf_mem_data_src *dsrc, {u64 idx;u64 mmcra = regs->dsisr; +u64 addr; +int ret; +unsigned int instr;if (mmcra &POWER7_MMCRA_DCACHE_MISS ) { idx = mmcra &POWER7_MMCRA_DCACHE_SRC_MASK ; idx >>=POWER7_MMCRA_DCACHE_SRC_SHIFT ; dsrc->val |= dcache_src_map[idx]; +return ; } + + instr =0 ; + addr =perf_instruction_pointer (regs); + +if (is_kernel_addr (addr)) + instr = *(unsigned int *)addr; +else { +pagefault_disable (); + ret =__get_user_inatomic (instr, (unsigned int __user *)addr); +pagefault_enable (); +if (ret) + instr =0 ; + } +if (instr &&instr_is_load_store (&instr)) + dsrc->val |=PLH (LVL ,L1 ); }
Signature · 1 line
1.7.9.5
Quoted 23 lines · Sukadev Bhattiprolu
Michael Neuling [[email protected]] wrote:
| > I am working on implementing the 'perf mem' command for Power | > systems. This would for instance, let us know where in the memory | > hierarchy (L1, L2, Local RAM etc) the data for a load/store | > instruction was found (hit). | > | > On Power7, if the mcmcra[DCACHE_MISS] is clear _and_ the | > instruction is a load/store, then it implies a L1-hit. | > | > Unlike on Power8, the Power7 event vector has no indication | > if the instruction was load/store. | > | > In the context of a PMU interrupt, is there any way to determine | > if an instruction is a load/store ? | | You could read the instruction from memory and work it out. | | We do something similar to this in power_pmu_bhrb_to() where we read the | instruction and work out where the branch is going to. | | If you do this, please use and/or extend the functions in | arch/powerpc/lib/code-patching.c
Quoted 3 lines
Here is a draft of what I could come up with. With this patch, the number of L1 hits on Power7 matches that on Power8 for one application.
Nice, the approach is along the lines of what I was thinking.
Quoted 2 lines
But, wondering if there is a more efficient way to do this - there are over 50 flavors of load and store!
I dunno, there might be. If you look at all the opcodes in binary, there's often a nice little pattern you can use.
Did you catch all the VSX and VMX loads/stores?
<snip>
arch/powerpc/lib/code-patching.c unsigned int translate_branch(const unsigned int *dest, const unsigned int *src) · line 250
Quoted 4 lines
arch/powerpc/lib/code-patching.c +4
-0+if (op ==31 ) { + n =sizeof (x_form_load_store) /sizeof (int ); + +for (i =0 ; i < n; i++) {
Yeah, this might be a bit slow... Are there any instructions with op == 31 that aren't a load/store?
Quoted 8 lines
arch/powerpc/lib/code-patching.c +7
-0+if (x_form_load_store[i] ==load_store_xval (*instr)) +return 1 ; + } + } + +return 0 ; +}