Skip to contentSkip to conversation

powerpc/perf: Use stack siar instead of mfspr

PATCH Superseded Kajol Jain 2 participants 5 messages Aug 18, 2021 PowerPC

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Kajol Jain

author
#0 lore raw

PATCH v3 1/3 powerpc/perf: Use stack siar instead of mfspr

Minor optimization in the 'perf_instruction_pointer' function code by making use of stack siar instead of mfspr.

Fixes 75382aa72f06 ("powerpc/perf: Move code to select SIAR or pt_regs

into perf_read_regs")

---
 arch/powerpc/perf/core-book3s.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/perf/core-book3s.c +1 -1
index bb0ee716de91..1b464aad29c4 100644
@@ -2260,7 +2260,7 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs)
 		else
 			return regs->nip;
 	} else if (use_siar && siar_valid(regs))
-		return mfspr(SPRN_SIAR) + perf_ip_adjust(regs);
+		return siar + perf_ip_adjust(regs);
 	else if (use_siar)
 		return 0;		// no valid instruction pointer
 	else
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH v3 2/3 powerpc/perf: Drop the case of returning 0 as instruction pointer

Drop the case of returning 0 as instruction pointer since kernel never executes at 0 and userspace almost never does either.

Fixes e6878835ac47 ("powerpc/perf: Sample only if SIAR-Valid

bit is set in P7+")

---
 arch/powerpc/perf/core-book3s.c | 2 --
 1 file changed, 2 deletions(-)
arch/powerpc/perf/core-book3s.c +0 -2
index 1b464aad29c4..23ec89a59893 100644
@@ -2261,8 +2261,6 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs)
 			return regs->nip;
 	} else if (use_siar && siar_valid(regs))
 		return siar + perf_ip_adjust(regs);
-	else if (use_siar)
-		return 0;		// no valid instruction pointer
 	else
 		return regs->nip;
 }
Signature · 1 line
2.26.2
author
#2 lore raw

PATCH v3 3/3 powerpc/perf: Fix the check for SIAR value

In reply to Kajol Jain

Incase of random sampling, there can be scenarios where Sample Instruction Address Register(SIAR) may not latch to the sampled instruction and could result in the value of 0. In these scenarios it is preferred to return regs->nip. These corner cases are seen in the previous generation (p9) also.

Patch adds the check for SIAR value along with use_siar and siar_valid checks so that the function will return regs->nip incase SIAR is zero.

Patch drops the code under PPMU_P10_DD1 flag check which handles SIAR 0 case only for Power10 DD1.

Fixes 2ca13a4cc56c9 ("powerpc/perf: Use regs->nip when SIAR is zero")

---

Changelog:
- Drop adding new ternary condition to check siar value.
- Remove siar check specific for PPMU_P10_DD1 and add it along with common checks as suggested by Christophe Leroy and Michael Ellermen

 arch/powerpc/perf/core-book3s.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
arch/powerpc/perf/core-book3s.c +1 -6
index 23ec89a59893..55efbba7572b 100644
@@ -2254,12 +2254,7 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs)
 	bool use_siar = regs_use_siar(regs);
 	unsigned long siar = mfspr(SPRN_SIAR);
 
-	if (ppmu && (ppmu->flags & PPMU_P10_DD1)) {
-		if (siar)
-			return siar;
-		else
-			return regs->nip;
-	} else if (use_siar && siar_valid(regs))
+	if (use_siar && siar_valid(regs) && siar)
 		return siar + perf_ip_adjust(regs);
 	else
 		return regs->nip;
Signature · 1 line
2.26.2
#3 lore raw

Re: [PATCH v3 3/3] powerpc/perf: Fix the check for SIAR value

Le 18/08/2021 à 15:19, Kajol Jain a écrit :

Quoted 32 lines

Incase of random sampling, there can be scenarios where Sample Instruction Address Register(SIAR) may not latch to the sampled instruction and could result in the value of 0. In these scenarios it is preferred to return regs->nip. These corner cases are seen in the previous generation (p9) also.

Patch adds the check for SIAR value along with use_siar and siar_valid checks so that the function will return regs->nip incase SIAR is zero.

Patch drops the code under PPMU_P10_DD1 flag check which handles SIAR 0 case only for Power10 DD1.

Fixes 2ca13a4cc56c9 ("powerpc/perf: Use regs->nip when SIAR is zero")

---

Changelog:
- Drop adding new ternary condition to check siar value.
- Remove siar check specific for PPMU_P10_DD1 and add it along with common checks as suggested by Christophe Leroy and Michael Ellermen

  arch/powerpc/perf/core-book3s.c | 7 +------
  1 file changed, 1 insertion(+), 6 deletions(-)
arch/powerpc/perf/core-book3s.c +0 -0
index 23ec89a59893..55efbba7572b 100644

arch/powerpc/perf/core-book3s.c unsigned long perf_instruction_pointer(struct pt_regs *regs) · line 2257

Quoted 10 lines
arch/powerpc/perf/core-book3s.c +1 -6
@@ -2254,12 +2254,7 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs)
  	bool use_siar = regs_use_siar(regs);
  	unsigned long siar = mfspr(SPRN_SIAR);
 
-	if (ppmu && (ppmu->flags & PPMU_P10_DD1)) {
-		if (siar)
-			return siar;
-		else
-			return regs->nip;
-	} else if (use_siar && siar_valid(regs))
+	if (use_siar && siar_valid(regs) && siar)

You can probably now do

+ if (regs_use_siar(regs) && siar_valid(regs) && siar)

and remove use_siar

Quoted 4 lines
arch/powerpc/perf/core-book3s.c +0 -0
  		return siar + perf_ip_adjust(regs);
  	else
  		return regs->nip;
author
#4 lore raw

Re: [PATCH v3 3/3] powerpc/perf: Fix the check for SIAR value

Quoted 47 lines · Christophe Leroy

Le 18/08/2021 à 15:19, Kajol Jain a écrit :

Quoted 32 lines

Incase of random sampling, there can be scenarios where Sample Instruction Address Register(SIAR) may not latch to the sampled instruction and could result in the value of 0. In these scenarios it is preferred to return regs->nip. These corner cases are seen in the previous generation (p9) also.

Patch adds the check for SIAR value along with use_siar and siar_valid checks so that the function will return regs->nip incase SIAR is zero.

Patch drops the code under PPMU_P10_DD1 flag check which handles SIAR 0 case only for Power10 DD1.

Fixes 2ca13a4cc56c9 ("powerpc/perf: Use regs->nip when SIAR is zero")

---

Changelog:
- Drop adding new ternary condition to check siar value.
- Remove siar check specific for PPMU_P10_DD1 and add it along with common checks as suggested by Christophe Leroy and Michael Ellermen

  arch/powerpc/perf/core-book3s.c | 7 +------

  1 file changed, 1 insertion(+), 6 deletions(-)
arch/powerpc/perf/core-book3s.c +0 -0
index 23ec89a59893..55efbba7572b 100644

arch/powerpc/perf/core-book3s.c unsigned long perf_instruction_pointer(struct pt_regs *regs) · line 2257

Quoted 9 lines
arch/powerpc/perf/core-book3s.c +1 -5
@@ -2254,12 +2254,7 @@ unsigned long perf_instruction_pointer(struct pt_regs *regs)
       bool use_siar = regs_use_siar(regs);
       unsigned long siar = mfspr(SPRN_SIAR);
   -    if (ppmu && (ppmu->flags & PPMU_P10_DD1)) {
-        if (siar)
-            return siar;
-        else
-            return regs->nip;
-    } else if (use_siar && siar_valid(regs))
+    if (use_siar && siar_valid(regs) && siar)

You can probably now do

Quoted 3 lines

+    if (regs_use_siar(regs) && siar_valid(regs) && siar)

and remove use_siar

Hi Christophe,
I will update it. Thanks for pointing it.

Thanks,
Kajol Jain

Quoted 5 lines
Quoted 5 lines
arch/powerpc/perf/core-book3s.c +0 -0
           return siar + perf_ip_adjust(regs);

      else
          return regs->nip;