Skip to contentSkip to conversation

powerpc/perf: Use stack siar instead of mfspr

PATCH Superseded Kajol Jain 4 participants 16 messages Aug 13, 2021 – Aug 17, 2021 PowerPC

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Kajol Jain

author
#0 lore raw

PATCH v2 1/2 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 v2 2/2 powerpc/perf: Return regs->nip as instruction pointer value when SIAR is 0

Incase of random sampling, there can be scenarios where SIAR is not latching sample address and results in 0 value. Since current code directly returning the siar value, we could see multiple instruction pointer values as 0 in perf report.
Patch resolves this issue by adding a ternary condition to return regs->nip incase SIAR is 0.

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 1b464aad29c4..aeecaaf6810f 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 siar + perf_ip_adjust(regs);
+		return siar ? siar + perf_ip_adjust(regs) : regs->nip;
 	else if (use_siar)
 		return 0;		// no valid instruction pointer
 	else
Signature · 1 line
2.26.2
author
#12 lore raw
In reply to Kajol Jain
Quoted 6 lines · Kajol Jain

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")

Please ignore this patch-set as I mentioned wrong version number. I will resend this patch-set again with correct version. Sorry for the confusion.

Thanks,
Kajol Jain

Quoted 18 lines
---
 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
#13 lore raw

Le 13/08/2021 à 10:29, kajoljain a écrit :

Quoted 12 lines · Kajol Jain
Quoted 6 lines

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")

Please ignore this patch-set as I mentioned wrong version number. I will resend this patch-set again with correct version. Sorry for the confusion.

I fear you are creating even more confusion by sending a v1 after sending a v2 ...

Christophe

#2 lore raw

Re: [PATCH v2 2/2] powerpc/perf: Return regs->nip as instruction pointer value when SIAR is 0

In reply to Kajol Jain

Le 13/08/2021 à 10:24, Kajol Jain a écrit :

Quoted 19 lines

Incase of random sampling, there can be scenarios where SIAR is not latching sample address and results in 0 value. Since current code directly returning the siar value, we could see multiple instruction pointer values as 0 in perf report.
Patch resolves this issue by adding a ternary condition to return regs->nip incase SIAR is 0.

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 +0 -0
index 1b464aad29c4..aeecaaf6810f 100644

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

Quoted 5 lines
arch/powerpc/perf/core-book3s.c +1 -1
@@ -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 siar + perf_ip_adjust(regs);
+		return siar ? siar + perf_ip_adjust(regs) : regs->nip;

Why bother about returning SIAR at all if regs->nip is ok ? Why not just return regs->nip all the time ?

Quoted 4 lines
arch/powerpc/perf/core-book3s.c +0 -0
  	else if (use_siar)
  		return 0;		// no valid instruction pointer
  	else
#4 lore raw

Re: [PATCH v2 2/2] powerpc/perf: Return regs->nip as instruction pointer value when SIAR is 0

In reply to Kajol Jain

Le 13/08/2021 à 10:24, Kajol Jain a écrit :

Quoted 6 lines

Incase of random sampling, there can be scenarios where SIAR is not latching sample address and results in 0 value. Since current code directly returning the siar value, we could see multiple instruction pointer values as 0 in perf report.
Patch resolves this issue by adding a ternary condition to return regs->nip incase SIAR is 0.

Your description seems rather similar to https://github.com/linuxppc/linux/commit/2ca13a4cc56c920a6c9fc8ee45d02bccacd7f46c

Does it mean that the problem occurs on more than the power10 DD1 ?

In that case, can the solution be common instead of doing something for power10 DD1 and something for others ?

Quoted 22 lines
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 1b464aad29c4..aeecaaf6810f 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 siar + perf_ip_adjust(regs);
+		return siar ? siar + perf_ip_adjust(regs) : regs->nip;
  	else if (use_siar)
  		return 0;		// no valid instruction pointer
  	else
#3 lore raw

Re: [PATCH v2 2/2] powerpc/perf: Return regs->nip as instruction pointer value when SIAR is 0

In reply to Christophe Leroy
Quoted 15 lines · Christophe Leroy

Le 13/08/2021 à 10:24, Kajol Jain a écrit :

Quoted 14 lines

Incase of random sampling, there can be scenarios where SIAR is not latching sample address and results in 0 value. Since current code directly returning the siar value, we could see multiple instruction pointer values as 0 in perf report.
Patch resolves this issue by adding a ternary condition to return regs->nip incase SIAR is 0.

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(-)
Quoted 12 lines

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

Quoted 10 lines
arch/powerpc/perf/core-book3s.c +1 -1
index 1b464aad29c4..aeecaaf6810f 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 siar + perf_ip_adjust(regs);
+		return siar ? siar + perf_ip_adjust(regs) : regs->nip;

Why bother about returning SIAR at all if regs->nip is ok ? Why not just return regs->nip all the time ?

Same answer as last time :)

https://lore.kernel.org/linuxppc-dev/[email protected]/

ie. SIAR can point into interrupts-off code, whereas regs->nip will point to where we re-enabled interrupts.

cheers

#14 lore raw
In reply to Christophe Leroy
Quoted 6 lines · Christophe Leroy

Le 13/08/2021 à 10:29, kajoljain a écrit :

Quoted 5 lines · Kajol Jain
Quoted 3 lines

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

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Fixes 75382aa72f06 ("powerpc/perf: Move code to select SIAR or pt_regs

into perf_read_regs")

Please ignore this patch-set as I mentioned wrong version number. I will resend this patch-set again with correct version. Sorry for the confusion.

I fear you are creating even more confusion by sending a v1 after sending a v2 ...

Yeah in future just reply to the v2 saying "oops I sent v2 instead of v1" and leave it at that.

cheers

#5 lore raw

Re: [PATCH v2 2/2] powerpc/perf: Return regs->nip as instruction pointer value when SIAR is 0

In reply to Christophe Leroy
Quoted 5 lines · Christophe Leroy

Le 13/08/2021 à 10:24, Kajol Jain a écrit :

Quoted 4 lines

Incase of random sampling, there can be scenarios where SIAR is not latching sample address and results in 0 value. Since current code directly returning the siar value, we could see multiple instruction pointer values as 0 in perf report.

Can you please give more detail on that? What scenarios? On what CPUs?

Quoted 10 lines
Quoted 2 lines

Patch resolves this issue by adding a ternary condition to return regs->nip incase SIAR is 0.

Your description seems rather similar to
https://github.com/linuxppc/linux/commit/2ca13a4cc56c920a6c9fc8ee45d02bccacd7f46c

Does it mean that the problem occurs on more than the power10 DD1 ?

In that case, can the solution be common instead of doing something for power10 DD1 and something for others ?

Agreed.

This change would seem to make that P10 DD1 logic superfluous.

Also we already have a fallback to regs->nip in the else case of the if, so we should just use that rather than adding a ternary condition.

eg.

	if (use_siar && siar_valid(regs) && siar)
		return siar + perf_ip_adjust(regs);
	else if (use_siar)
		return 0;		// no valid instruction pointer
	else
		return regs->nip;

I'm also not sure why we have that return 0 case, I can't think of why we'd ever want to do that rather than using nip. So maybe we should do another patch to drop that case.

cheers

author
#15 lore raw
In reply to Michael Ellerman
Quoted 11 lines · Michael Ellerman
Quoted 10 lines · Christophe Leroy

Le 13/08/2021 à 10:29, kajoljain a écrit :

Quoted 9 lines · Kajol Jain
Quoted 6 lines

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")

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Please ignore this patch-set as I mentioned wrong version number. I will resend this patch-set again with correct version. Sorry for the confusion.

I fear you are creating even more confusion by sending a v1 after sending a v2 ...

Yeah in future just reply to the v2 saying "oops I sent v2 instead of v1" and leave it at that.

Hi Christophe/Michael,
Sure I will take care next time.

Thanks,
Kajol Jain

Quoted 3 lines

cheers

author
#6 lore raw

Re: [PATCH v2 2/2] powerpc/perf: Return regs->nip as instruction pointer value when SIAR is 0

In reply to Michael Ellerman
Quoted 9 lines · Michael Ellerman
Quoted 5 lines · Christophe Leroy

Le 13/08/2021 à 10:24, Kajol Jain a écrit :

Quoted 4 lines

Incase of random sampling, there can be scenarios where SIAR is not latching sample address and results in 0 value. Since current code directly returning the siar value, we could see multiple instruction pointer values as 0 in perf report.

Can you please give more detail on that? What scenarios? On what CPUs?

Hi Michael,
Sure I will update these details in my next patch-set.

Quoted 28 lines
Quoted 10 lines
Quoted 2 lines

Patch resolves this issue by adding a ternary condition to return regs->nip incase SIAR is 0.

Your description seems rather similar to
https://github.com/linuxppc/linux/commit/2ca13a4cc56c920a6c9fc8ee45d02bccacd7f46c

Does it mean that the problem occurs on more than the power10 DD1 ?

In that case, can the solution be common instead of doing something for power10 DD1 and something for others ?

Agreed.

This change would seem to make that P10 DD1 logic superfluous.

Also we already have a fallback to regs->nip in the else case of the if, so we should just use that rather than adding a ternary condition.

eg.

	if (use_siar && siar_valid(regs) && siar)
		return siar + perf_ip_adjust(regs);
	else if (use_siar)
		return 0;		// no valid instruction pointer
	else
		return regs->nip;
Quoted 3 lines

I'm also not sure why we have that return 0 case, I can't think of why we'd ever want to do that rather than using nip. So maybe we should do another patch to drop that case.

Yeah make sense. I will remove return 0 case in my next version.

Thanks,
Kajol Jain

Quoted 3 lines

cheers

author
#11 lore raw

Re: [PATCH v2 2/2] powerpc/perf: Return regs->nip as instruction pointer value when SIAR is 0

In reply to Christophe Leroy
Quoted 10 lines · Christophe Leroy

Le 13/08/2021 à 10:24, Kajol Jain a écrit :

Quoted 6 lines

Incase of random sampling, there can be scenarios where SIAR is not latching sample address and results in 0 value. Since current code directly returning the siar value, we could see multiple instruction pointer values as 0 in perf report.
Patch resolves this issue by adding a ternary condition to return regs->nip incase SIAR is 0.

Quoted 5 lines

Your description seems rather similar to https://github.com/linuxppc/linux/commit/2ca13a4cc56c920a6c9fc8ee45d02bccacd7f46c

Does it mean that the problem occurs on more than the power10 DD1 ?

In that case, can the solution be common instead of doing something for power10 DD1 and something for others ?

Hi Christophe,
Yes its better to have common check. I will make these updates.

Thanks,
Kajol Jain

Quoted 23 lines
Quoted 23 lines
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 +0 -0
index 1b464aad29c4..aeecaaf6810f 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 siar + perf_ip_adjust(regs);
+        return siar ? siar + perf_ip_adjust(regs) : regs->nip; else if (use_siar)
          return 0;        // no valid instruction pointer else

#7 lore raw

Re: [PATCH v2 2/2] powerpc/perf: Return regs->nip as instruction pointer value when SIAR is 0

In reply to kajoljain

Le 16/08/2021 à 08:44, kajoljain a écrit :

Quoted 44 lines · Michael Ellerman
Quoted 9 lines
Quoted 5 lines · Christophe Leroy

Le 13/08/2021 à 10:24, Kajol Jain a écrit :

Quoted 4 lines

Incase of random sampling, there can be scenarios where SIAR is not latching sample address and results in 0 value. Since current code directly returning the siar value, we could see multiple instruction pointer values as 0 in perf report.

Can you please give more detail on that? What scenarios? On what CPUs?

Hi Michael,
Sure I will update these details in my next patch-set.

Quoted 28 lines
Quoted 10 lines
Quoted 2 lines

Patch resolves this issue by adding a ternary condition to return regs->nip incase SIAR is 0.

Your description seems rather similar to
https://github.com/linuxppc/linux/commit/2ca13a4cc56c920a6c9fc8ee45d02bccacd7f46c

Does it mean that the problem occurs on more than the power10 DD1 ?

In that case, can the solution be common instead of doing something for power10 DD1 and something for others ?

Agreed.

This change would seem to make that P10 DD1 logic superfluous.

Also we already have a fallback to regs->nip in the else case of the if, so we should just use that rather than adding a ternary condition.

eg.

	if (use_siar && siar_valid(regs) && siar)
		return siar + perf_ip_adjust(regs);
	else if (use_siar)
		return 0;		// no valid instruction pointer
	else
		return regs->nip;
Quoted 6 lines
Quoted 3 lines

I'm also not sure why we have that return 0 case, I can't think of why we'd ever want to do that rather than using nip. So maybe we should do another patch to drop that case.

Yeah make sense. I will remove return 0 case in my next version.

This was added by commit https://github.com/linuxppc/linux/commit/e6878835ac4794f25385522d29c634b7bbb7cca9

Are we sure it was an error to add it and it can be removed ?

Christophe

#8 lore raw

Re: [PATCH v2 2/2] powerpc/perf: Return regs->nip as instruction pointer value when SIAR is 0

Quoted 52 lines · Christophe Leroy

Le 16/08/2021 à 08:44, kajoljain a écrit :

Quoted 49 lines · Michael Ellerman
Quoted 9 lines
Quoted 5 lines · Christophe Leroy

Le 13/08/2021 à 10:24, Kajol Jain a écrit :

Quoted 4 lines

Incase of random sampling, there can be scenarios where SIAR is not latching sample address and results in 0 value. Since current code directly returning the siar value, we could see multiple instruction pointer values as 0 in perf report.

Can you please give more detail on that? What scenarios? On what CPUs?

Hi Michael,
     Sure I will update these details in my next patch-set.

Quoted 32 lines
Quoted 11 lines
Quoted 2 lines

Patch resolves this issue by adding a ternary condition to return regs->nip incase SIAR is 0.

Your description seems rather similar to
https://github.com/linuxppc/linux/commit/2ca13a4cc56c920a6c9fc8ee45d02bccacd7f46c

Does it mean that the problem occurs on more than the power10 DD1 ?

In that case, can the solution be common instead of doing something for power10 DD1 and something for others ?

Agreed.

This change would seem to make that P10 DD1 logic superfluous.

Also we already have a fallback to regs->nip in the else case of the if, so we should just use that rather than adding a ternary condition.

eg.

    if (use_siar && siar_valid(regs) && siar) return siar + perf_ip_adjust(regs); else if (use_siar)
        return 0;        // no valid instruction pointer else
        return regs->nip;

I'm also not sure why we have that return 0 case, I can't think of why we'd ever want to do that rather than using nip. So maybe we should do another patch to drop that case.

Quoted 6 lines
Quoted 2 lines

Yeah make sense. I will remove return 0 case in my next version.

This was added by commit https://github.com/linuxppc/linux/commit/e6878835ac4794f25385522d29c634b7bbb7cca9

Are we sure it was an error to add it and it can be removed ?

pc having 0 is wrong (kernel does not execute at 0x0 or userspace). yeah we should drop it.

Maddy

Quoted 2 lines

Christophe

author
#9 lore raw

Re: [PATCH v2 2/2] powerpc/perf: Return regs->nip as instruction pointer value when SIAR is 0

Quoted 56 lines · Madhavan Srinivasan
Quoted 54 lines · Christophe Leroy

Le 16/08/2021 à 08:44, kajoljain a écrit :

Quoted 50 lines · Michael Ellerman
Quoted 9 lines
Quoted 5 lines · Christophe Leroy

Le 13/08/2021 à 10:24, Kajol Jain a écrit :

Quoted 4 lines

Incase of random sampling, there can be scenarios where SIAR is not latching sample address and results in 0 value. Since current code directly returning the siar value, we could see multiple instruction pointer values as 0 in perf report.

Can you please give more detail on that? What scenarios? On what CPUs?

Hi Michael,
     Sure I will update these details in my next patch-set.

Quoted 28 lines
Quoted 10 lines
Quoted 2 lines

Patch resolves this issue by adding a ternary condition to return regs->nip incase SIAR is 0.

Your description seems rather similar to
https://github.com/linuxppc/linux/commit/2ca13a4cc56c920a6c9fc8ee45d02bccacd7f46c

Does it mean that the problem occurs on more than the power10 DD1 ?

In that case, can the solution be common instead of doing something for power10 DD1 and something for others ?

Agreed.

This change would seem to make that P10 DD1 logic superfluous.

Also we already have a fallback to regs->nip in the else case of the if, so we should just use that rather than adding a ternary condition.

eg.

    if (use_siar && siar_valid(regs) && siar) return siar + perf_ip_adjust(regs); else if (use_siar)
        return 0;        // no valid instruction pointer else
        return regs->nip;

Quoted 3 lines

I'm also not sure why we have that return 0 case, I can't think of why we'd ever want to do that rather than using nip. So maybe we should do another patch to drop that case.

Yeah make sense. I will remove return 0 case in my next version.

Quoted 6 lines
Quoted 3 lines

This was added by commit https://github.com/linuxppc/linux/commit/e6878835ac4794f25385522d29c634b7bbb7cca9

Are we sure it was an error to add it and it can be removed ?

pc having 0 is wrong (kernel does not execute at 0x0 or userspace). yeah we should drop it.

Hi Madhavan,
Sure I will add another patch to drop return 0 condition.

Thanks,
Kajol jain

Quoted 4 lines

Maddy

Quoted 2 lines

Christophe

#10 lore raw

Re: [PATCH v2 2/2] powerpc/perf: Return regs->nip as instruction pointer value when SIAR is 0

In reply to Christophe Leroy
Quoted 2 lines · Christophe Leroy

Le 16/08/2021 à 08:44, kajoljain a écrit :

Quoted 1 line · Michael Ellerman

...

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

eg.

	if (use_siar && siar_valid(regs) && siar)
		return siar + perf_ip_adjust(regs);
	else if (use_siar)
		return 0;		// no valid instruction pointer
	else
		return regs->nip;

I'm also not sure why we have that return 0 case, I can't think of why we'd ever want to do that rather than using nip. So maybe we should do another patch to drop that case.

Quoted 6 lines
Quoted 1 line

Yeah make sense. I will remove return 0 case in my next version.

This was added by commit
https://github.com/linuxppc/linux/commit/e6878835ac4794f25385522d29c634b7bbb7cca9

Are we sure it was an error to add it and it can be removed ?

I think so.

That commit added siar_valid(), and updated record_and_restart() to only record if siar_valid() returned true.

- record = 1;
+ record = siar_valid(regs);

It then also changed perf_instruction_pointer():

- if (use_siar)
+ if (use_siar && siar_valid(regs))

                   return mfspr(SPRN_SIAR) + perf_ip_adjust(regs);
  +        else if (use_siar)
  +                return 0;                // no valid instruction pointer
           else
                   return regs->nip;

The first change means we would never even call perf_instruction_pointer() if siar_valid() is false, so we could never hit the use_siar && !siar_valid() case.

But even so it's always preferable to use regs->nip than 0, even if nip is somewhat skewed due to interrupts being disabled etc.

cheers