powerpc/e6500: remove the stale TCD_LOCK macro
PATCH 1/3 powerpc/e6500: remove the stale TCD_LOCK macro
Since we moved the "lock" to be the first element of struct tlb_core_data in commit 82d86de25b9c ("powerpc/e6500: Make TLB lock recursive), this macro is not used by any code. Just delete it.
--- arch/powerpc/kernel/asm-offsets.c | 1 - 1 file changed, 1 deletion(-)
arch/powerpc/kernel/asm-offsets.c +0 -1
@@ -213,7 +213,6 @@ int main(void) offsetof(struct tlb_core_data, esel_max));DEFINE (TCD_ESEL_FIRST , offsetof(struct tlb_core_data , esel_first)); -DEFINE (TCD_LOCK , offsetof(struct tlb_core_data , lock));#endif /* CONFIG_PPC_BOOK3E */ #ifdef CONFIG_PPC_STD_MMU_64
Signature · 1 line
2.1.0
PATCH 2/3 powerpc/e6500: hw tablewalk: optimize a bit for tcd lock acquiring codes
It makes no sense to put the instructions for calculating the lock value (cpu number + 1) and the clearing of eq bit of cr1 in lbarx/stbcx loop. And when the lock is acquired by the other thread, the current lock value has no chance to equal with the lock value used by current cpu. So we can skip the comparing for these two lock values in the lbz/bne loop.
--- arch/powerpc/mm/tlb_low_64e.S | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/mm/tlb_low_64e.S +5 -5
@@ -308,11 +308,11 @@ BEGIN_FTR_SECTION /* CPU_FTR_SMT */ * * MAS6:IND should be already set based on MAS4 */ -1: lbarx r15,0,r11 lhz r10,PACAPACAINDEX(r13) - cmpdi r15,0 - cmpdi cr1,r15,1 /* set cr1.eq = 0 for non-recursive */ addi r10,r10,1 + crclr cr1*4+eq /* set cr1.eq = 0 for non-recursive */ +1: lbarx r15,0,r11 + cmpdi r15,0 bne 2f stbcx. r10,0,r11 bne 1b
@@ -320,9 +320,9 @@ BEGIN_FTR_SECTION /* CPU_FTR_SMT */ .subsection 1 2: cmpd cr1,r15,r10 /* recursive lock due to mcheck/crit/etc? */ beq cr1,3b /* unlock will happen if cr1.eq = 0 */ - lbz r15,0(r11) +10: lbz r15,0(r11) cmpdi r15,0 - bne 2b + bne 10b b 1b .previous
Signature · 1 line
2.1.0
PATCH 3/3 powerpc/e6500: hw tablewalk: order the memory access when acquire/release tcd lock
In reply to Kevin HaoI didn't find anything unusual. But I think we do need to order the load/store of esel_next when acquire/release tcd lock. For acquire, add a data dependency to order the loads of lock and esel_next. For release, even there already have a "isync" here, but it doesn't guarantee any memory access order. So we still need "lwsync" for the two stores for lock and esel_next.
--- arch/powerpc/mm/tlb_low_64e.S | 3 +++ 1 file changed, 3 insertions(+)
arch/powerpc/mm/tlb_low_64e.S +3 -0
@@ -334,6 +334,8 @@ BEGIN_FTR_SECTION /* CPU_FTR_SMT */ * with tlbilx before overwriting. */ + andi r15,r15,0 /* add a data dependency to order the loards */ + add r11,r11,r15 /* between the lock and esel_next */ lbz r15,TCD_ESEL_NEXT(r11) rlwinm r10,r15,16,0xff0000 oris r10,r10,MAS0_TLBSEL(1)@h
@@ -447,6 +449,7 @@ BEGIN_FTR_SECTION beq cr1,1f /* no unlock if lock was recursively grabbed */ li r15,0 isync + lwsync stb r15,0(r11) 1: END_FTR_SECTION_IFSET(CPU_FTR_SMT)
Signature · 1 line
2.1.0
Re: [PATCH 2/3] powerpc/e6500: hw tablewalk: optimize a bit for tcd lock acquiring codes
In reply to Kevin HaoQuoted 19 lines · Kevin Hao
It makes no sense to put the instructions for calculating the lock value (cpu number + 1) and the clearing of eq bit of cr1 in lbarx/stbcx loop. And when the lock is acquired by the other thread, the current lock value has no chance to equal with the lock value used by current cpu. So we can skip the comparing for these two lock values in the lbz/bne loop.
Signed-off-by Kevin Hao <[email protected]>--- arch/powerpc/mm/tlb_low_64e.S | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)arch/powerpc/mm/tlb_low_64e.S +0
-0@@ -308,11 +308,11 @@ BEGIN_FTR_SECTION /* CPU_FTR_SMT */ * * MAS6:IND should be already set based on MAS4
arch/powerpc/mm/tlb_low_64e.S BEGIN_FTR_SECTION /* CPU_FTR_SMT */ · line 316
Quoted 10 lines
arch/powerpc/mm/tlb_low_64e.S +3
-3*/ -1: lbarx r15,0,r11 lhz r10,PACAPACAINDEX(r13) - cmpdi r15,0 - cmpdi cr1,r15,1 /* set cr1.eq = 0 for non-recursive */ addi r10,r10,1 + crclr cr1*4+eq /* set cr1.eq = 0 for non-recursive */ +1: lbarx r15,0,r11 + cmpdi r15,0 bne 2f
You're optimizing the contended case at the expense of introducing stalls in the uncontended case. Does it really matter if there are more instructions in the loop? This change just means that you'll spin in the loop for more iterations (if it even does that -- I think the cycles per loop iteration might be the same before and after, due to load latency and pairing) while waiting for the other thread to release the lock.
Do you have any benchmark results for this patch?
-Scott
Re: [PATCH 3/3] powerpc/e6500: hw tablewalk: order the memory access when acquire/release tcd lock
In reply to Kevin HaoQuoted 6 lines · Kevin Hao
I didn't find anything unusual. But I think we do need to order the load/store of
esel_nextwhen acquire/release tcd lock. For acquire, add a data dependency to order the loads of lock andesel_next. For release, even there already have a "isync" here, but it doesn't guarantee any memory access order. So we still need "lwsync" for the two stores for lock andesel_next.
I was going to say that esel_next is just a hint and it doesn't really matter if we occasionally get the wrong value, unless it happens often enough to cause more performance degradation than the lwsync causes. However, with the A-008139 workaround we do need to read the same value from esel_next both times. It might be less costly to save/restore an additional register instead of lwsync, though.
-Scott
Re: [PATCH 2/3] powerpc/e6500: hw tablewalk: optimize a bit for tcd lock acquiring codes
In reply to Scott WoodQuoted 25 lines · Scott Wood
Quoted 24 lines · Kevin Hao
It makes no sense to put the instructions for calculating the lock value (cpu number + 1) and the clearing of eq bit of cr1 in lbarx/stbcx loop. And when the lock is acquired by the other thread, the current lock value has no chance to equal with the lock value used by current cpu. So we can skip the comparing for these two lock values in the lbz/bne loop.
Signed-off-by Kevin Hao <[email protected]>--- arch/powerpc/mm/tlb_low_64e.S | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)arch/powerpc/mm/tlb_low_64e.S +0
-3@@ -308,11 +308,11 @@ BEGIN_FTR_SECTION /* CPU_FTR_SMT */ * * MAS6:IND should be already set based on MAS4 */ -1: lbarx r15,0,r11 lhz r10,PACAPACAINDEX(r13) - cmpdi r15,0 - cmpdi cr1,r15,1 /* set cr1.eq = 0 for non-recursive */
Quoted 8 lines
arch/powerpc/mm/tlb_low_64e.S BEGIN_FTR_SECTION /* CPU_FTR_SMT */ · line 316
Quoted 5 lines
arch/powerpc/mm/tlb_low_64e.S +3
-0addi r10,r10,1 + crclr cr1*4+eq /* set cr1.eq = 0 for non-recursive */ +1: lbarx r15,0,r11 + cmpdi r15,0 bne 2fYou're optimizing the contended case at the expense of introducing stalls in the uncontended case.
Before the patch, the uncontended case code sequence are:
1: lbarx r15,0,r11
lhz r10,PACAPACAINDEX(r13) cmpdi r15,0 cmpdi cr1,r15,1 /* set cr1.eq = 0 for non-recursive */ addi r10,r10,1 bne 2f stbcx. r10,0,r11 bne 1b
After the patch:
lhz r10,PACAPACAINDEX(r13) addi r10,r10,1 crclr cr1*4+eq /* set cr1.eq = 0 for non-recursive */ 1: lbarx r15,0,r11 cmpdi r15,0 bne 2f stbcx. r10,0,r11 bne 1b
As you know, the lbarx is a Presync instruction and stbcx is a Presync and Postsync instruction. Putting the unnecessary instructions in the lbarx/stbcx loop also serialize these instructions execution. The execution latency of lbarx is only 3 cycles and there are still two instructions after it. Considering the out of order execution optimization after this patch, do you really think that new uncontended path will become slower due to this additional stall?
Quoted 2 lines
Does it really matter if there are more instructions
in the loop?
I really think we should minimize the window of lbarx/stbcx, for following two reasons:
- The bigger of this window, the more possible conflicts between the two threads run into this loop simultaneously.
- The reservation used by lbarx may be cleared by another thread due to store to the same reservation granule. The smaller the window of lbarx/stbcx, the less possibility to be affected by this.
Quoted 4 lines
This change just means that you'll spin in the loop for more
iterations (if it even does that -- I think the cycles per loop iteration might be the same before and after, due to load latency and pairing) while waiting for the other thread to release the lock.
Besides the optimization for the contended case, it also make the code more readable with these changes:
- It always seem a bit weird to calculate the lock value for the current cpu in the lbarx/stbcx loop.
- The "cmpdi cr1,r15,1" seems pretty confusion. It doesn't always do what
the comment said (set cr1.eq = 0). In some cases, it does set the crq.eq = 1, such as when running on cpu 1 with lock is acquired by cpu0. All we need to do just clear the cr1.eq unconditionally.
Quoted 2 lines
Do you have any benchmark results for this patch?
I doubt it will get any visible difference. Anyway I will gave it a try.
Thanks,
Kevin
Quoted 3 lines
-Scott
Re: [PATCH 3/3] powerpc/e6500: hw tablewalk: order the memory access when acquire/release tcd lock
In reply to Scott WoodQuoted 8 lines · Scott Wood
Quoted 6 lines · Kevin Hao
I didn't find anything unusual. But I think we do need to order the load/store of
esel_nextwhen acquire/release tcd lock. For acquire, add a data dependency to order the loads of lock andesel_next. For release, even there already have a "isync" here, but it doesn't guarantee any memory access order. So we still need "lwsync" for the two stores for lock andesel_next.
Quoted 6 lines
I was going to say that
esel_nextis just a hint and it doesn't really matter if we occasionally get the wrong value, unless it happens often enough to cause more performance degradation than the lwsync causes. However, with the A-008139 workaround we do need to read the same value fromesel_nextboth times. It might be less costly to save/restore an additional register instead of lwsync, though.
I will try to get some benchmark number to compare which method is a bit better. Do you have any recommended benchmark for a case this is?
Thanks,
Kevin
Quoted 3 lines
-Scott
Re: [PATCH 3/3] powerpc/e6500: hw tablewalk: order the memory access when acquire/release tcd lock
Quoted 18 lines · Kevin Hao
Quoted 8 lines · Scott Wood
Quoted 6 lines · Kevin Hao
I didn't find anything unusual. But I think we do need to order the load/store of
esel_nextwhen acquire/release tcd lock. For acquire, add a data dependency to order the loads of lock andesel_next. For release, even there already have a "isync" here, but it doesn't guarantee any memory access order. So we still need "lwsync" for the two stores for lock andesel_next.Quoted 8 lines
I was going to say that
esel_nextis just a hint and it doesn't really matter
if we occasionally get the wrong value, unless it happens often enough to cause more performance degradation than the lwsync causes. However, with the
A-008139 workaround we do need to read the same value fromesel_nextboth times. It might be less costly to save/restore an additional register instead of lwsync, though.
Quoted 3 lines
I will try to get some benchmark number to compare which method is a bit better.
Do you have any recommended benchmark for a case this is?
lmbench lat_mem_rd with a stride chosen to maximize TLB misses. For the uncontended case, one instance; for the contended case, two instances, one pinned to each thread of a core.
-Scott
Re: [PATCH 2/3] powerpc/e6500: hw tablewalk: optimize a bit for tcd lock acquiring codes
In reply to Kevin HaoQuoted 58 lines · Kevin Hao
Quoted 27 lines · Scott Wood
Quoted 26 lines · Kevin Hao
It makes no sense to put the instructions for calculating the lock value (cpu number + 1) and the clearing of eq bit of cr1 in lbarx/stbcx loop. And when the lock is acquired by the other thread, the current lock value has no chance to equal with the lock value used by current cpu. So we can skip the comparing for these two lock values in the lbz/bne loop.
Signed-off-by Kevin Hao <[email protected]>--- arch/powerpc/mm/tlb_low_64e.S | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)arch/powerpc/mm/tlb_low_64e.S +0
-3@@ -308,11 +308,11 @@ BEGIN_FTR_SECTION /* CPU_FTR_SMT */ * * MAS6:IND should be already set based on MAS4 */ -1: lbarx r15,0,r11 lhz r10,PACAPACAINDEX(r13) - cmpdi r15,0 - cmpdi cr1,r15,1 /* set cr1.eq = 0 for non-recursive */ addi r10,r10,1Quoted 8 lines
arch/powerpc/mm/tlb_low_64e.S BEGIN_FTR_SECTION /* CPU_FTR_SMT */ · line 316
Quoted 4 lines
arch/powerpc/mm/tlb_low_64e.S +3
-0+ crclr cr1*4+eq /* set cr1.eq = 0 for non-recursive */ +1: lbarx r15,0,r11 + cmpdi r15,0 bne 2fYou're optimizing the contended case at the expense of introducing stalls in
the uncontended case.Before the patch, the uncontended case code sequence are:
1: lbarx r15,0,r11 lhz r10,PACAPACAINDEX(r13) cmpdi r15,0 cmpdi cr1,r15,1 /* set cr1.eq = 0 for non-recursive */ addi r10,r10,1 bne 2f stbcx. r10,0,r11 bne 1bAfter the patch:
lhz r10,PACAPACAINDEX(r13) addi r10,r10,1 crclr cr1*4+eq /* set cr1.eq = 0 for non-recursive */ 1: lbarx r15,0,r11 cmpdi r15,0 bne 2f stbcx. r10,0,r11 bne 1b
Quoted 2 lines
As you know, the lbarx is a Presync instruction and stbcx is a Presync and Postsync instruction.
Yes, so don't we want to move instructions after the lbarx if possible, so that the presync condition is achieved sooner?
Quoted 2 lines
Putting the unnecessary instructions in the lbarx/stbcx
loop also serialize these instructions execution.
Again, the common case should be that the loop executes only once. The two cmpdi instructions should pair, the addi should pair with the bne, and the lhz should happen while waiting for the lbarx result. My understanding of how to model this stuff is certainly imperfect/incomplete, so I generally try to confirm by testing, but I think both loops take the same number of cycles per iteration.
Quoted 5 lines
The execution latency of
lbarx is only 3 cycles and there are still two instructions after it. Considering the out of order execution optimization after this patch, do you really think that new uncontended path will become slower due to this additional stall?
The (theoretical) additional time is before the loop, not during it.
Quoted 8 lines
Quoted 2 lines
Does it really matter if there are more instructions
in the loop?I really think we should minimize the window of lbarx/stbcx, for following two
reasons:
- The bigger of this window, the more possible conflicts between the two threads run into this loop simultaneously.
That's more true of the total time the lock is held, not the lbarx/stbcx section.
Quoted 3 lines
- The reservation used by lbarx may be cleared by another thread due to store to the same reservation granule. The smaller the window of lbarx/stbcx, the less possibility to be affected by this.
There's only one other thread that should be touching that reservation granule, and it's the one we're waiting for.
In any case, if there is a difference in loop iteration execution time, it's small.
Quoted 6 lines
Quoted 5 lines
This change just means that you'll spin in the loop for more iterations (if it even does that -- I think the cycles per loop iteration might be the same before and after, due to load latency and pairing) while
waiting for the other thread to release the lock.
Quoted 9 lines
Besides the optimization for the contended case, it also make the code more readable with these changes:
- It always seem a bit weird to calculate the lock value for the current cpu in the lbarx/stbcx loop.
- The "cmpdi cr1,r15,1" seems pretty confusion. It doesn't always do
what
the comment said (set cr1.eq = 0). In some cases, it does set the crq.eq = 1, such as when running on cpu 1 with lock is acquired by cpu0. All we need to do just clear the cr1.eq unconditionally.
We only care about cr1.eq when we break out of the loop, in which case r15 will have been zero. But yes, crclr is better.
Quoted 4 lines
Quoted 2 lines
Do you have any benchmark results for this patch?
I doubt it will get any visible difference. Anyway I will gave it a try.
I tried a couple different benchmarks and didn't find a significant difference, relative to the variability of the results running on the same kernel. A patch that claims to "optimize a bit" as its main purpose ought to show some results. :-)
-Scott
Re: [PATCH 2/3] powerpc/e6500: hw tablewalk: optimize a bit for tcd lock acquiring codes
Quoted 4 lines · Scott Wood
I tried a couple different benchmarks and didn't find a significant difference, relative to the variability of the results running on the same kernel. A patch that claims to "optimize a bit" as its main purpose ought to show some results. :-)
I tried to compare the execution time of these two code sequences with the following test module:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/printk.h>
static void test1(void)
{
int i;
unsigned char lock, c;
unsigned short cpu, s;
for (i = 0; i < 100000; i++) {
lock = 0;
cpu = 1;
asm volatile (
"1: lbarx %0,0,%2\n\
lhz %1,0(%3)\n\
cmpdi %0,0\n\
cmpdi cr1,%1,1\n\
addi %1,%1,1\n\
bne 2f\n\
stbcx. %1,0,%2\n\
bne 1b\n\
2:"
: "=&r" (c), "=&r" (s) : "r" (&lock), "r" (&cpu) : "cr0", "cr1", "memory");
}
}static void test2(void)
{
int i;
unsigned char lock, c;
unsigned short cpu, s;
for (i = 0; i < 100000; i++) {
lock = 0;
cpu = 1;
asm volatile (
" lhz %1,0(%3)\n\
addi %1,%1,1\n\
crclr cr1*4+eq\n\
1: lbarx %0,0,%2\n\
cmpdi %0,0\n\
bne 2f\n\
stbcx. %1,0,%2\n\
bne 1b\n\
2:"
: "=&r" (c), "=&r" (s) : "r" (&lock), "r" (&cpu) : "cr0", "cr1", "memory");
}
}static int test_init(void)
{
unsigned long s, e, tm1, tm2;
__hard_irq_disable();
/* Just for prefetch */
test1();
s = mftb();
test1();
e = mftb();
tm1 = e - s;
/* Just for prefetch */
test2();
s = mftb();
test2();
e = mftb();
tm2 = e - s;
__hard_irq_enable();
pr_err("test1: %ld, test2: %ld, %%%ld\n", tm1, tm2, (tm1 - tm2) * 100 / tm1);
return 0;
}static void test_exit(void)
{
return;
}module_init(test_init);module_exit(test_exit);MODULE_LICENSE("GPL");
The results:
test1: 156568, test2: 151675, %3
test1: 156604, test2: 151670, %3
test1: 156567, test2: 151684, %3
test1: 156567, test2: 151678, %3
test1: 156567, test2: 151688, %3
test1: 156570, test2: 151683, %3
test1: 156565, test2: 151675, %3
test1: 156565, test2: 151673, %3
It seems that there do have a %3 gain in performance by moving the 3 instructions out of lbarx/stbcx loop.
Thanks,
Kevin
Re: [PATCH 3/3] powerpc/e6500: hw tablewalk: order the memory access when acquire/release tcd lock
In reply to Scott WoodQuoted 19 lines · Scott Wood
Quoted 18 lines · Kevin Hao
Quoted 16 lines · Scott Wood
Quoted 6 lines · Kevin Hao
I didn't find anything unusual. But I think we do need to order the load/store of
esel_nextwhen acquire/release tcd lock. For acquire, add a data dependency to order the loads of lock andesel_next. For release, even there already have a "isync" here, but it doesn't guarantee any memory access order. So we still need "lwsync" for the two stores for lock andesel_next.I was going to say that
esel_nextis just a hint and it doesn't really matter
if we occasionally get the wrong value, unless it happens often enough to cause more performance degradation than the lwsync causes. However, with the
A-008139 workaround we do need to read the same value fromesel_nextboth times. It might be less costly to save/restore an additional register instead of lwsync, though.
Quoted 7 lines
Quoted 3 lines
I will try to get some benchmark number to compare which method is a bit better.
Do you have any recommended benchmark for a case this is?lmbench
lat_mem_rdwith a stride chosen to maximize TLB misses. For the uncontended case, one instance; for the contended case, two instances, one pinned to each thread of a core.
I have tried the method to save/restore an additional register for the esel with the following codes:
arch/powerpc/include/asm/exception-64e.h +2 -2
@@ -69,9 +69,9 @@#define EX_TLB_ESR ( 9 * 8)/* Level 0 and 2 only */ #define EX_TLB_SRR0 (10 * 8)#define EX_TLB_SRR1 (11 * 8) +#define EX_TLB_R9 (12 * 8)#ifdef CONFIG_BOOK3E_MMU_TLB_STATS -#define EX_TLB_R8 (12 * 8) -#define EX_TLB_R9 (13 * 8) +#define EX_TLB_R8 (13 * 8)#define EX_TLB_LR (14 * 8)#define EX_TLB_SIZE (15 * 8)#else
arch/powerpc/mm/tlb_low_64e.S +10 -8
@@ -68,11 +68,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV) ld r14,PACAPGD(r13) std r15,EX_TLB_R15(r12) std r10,EX_TLB_CR(r12) + std r9,EX_TLB_R9(r12) TLB_MISS_PROLOG_STATS .endm .macro tlb_epilog_bolted ld r14,EX_TLB_CR(r12) + ld r9,EX_TLB_R9(r12) ld r10,EX_TLB_R10(r12) ld r11,EX_TLB_R11(r12) ld r13,EX_TLB_R13(r12)
@@ -297,6 +299,7 @@ itlb_miss_fault_bolted: * r13 = PACA * r11 = tlb_per_core ptr * r10 = crap (free to use) + * r9 = esel entry */ tlb_miss_common_e6500: crmove cr2*4+2,cr0*4+2 /* cr2.eq != 0 if kernel address */
@@ -334,8 +337,8 @@ BEGIN_FTR_SECTION /* CPU_FTR_SMT */ * with tlbilx before overwriting. */ - lbz r15,TCD_ESEL_NEXT(r11) - rlwinm r10,r15,16,0xff0000 + lbz r9,TCD_ESEL_NEXT(r11) + rlwinm r10,r9,16,0xff0000 oris r10,r10,MAS0_TLBSEL(1)@h mtspr SPRN_MAS0,r10 isync
@@ -429,15 +432,14 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_SMT) mtspr SPRN_MAS2,r15 tlb_miss_huge_done_e6500: - lbz r15,TCD_ESEL_NEXT(r11) lbz r16,TCD_ESEL_MAX(r11) lbz r14,TCD_ESEL_FIRST(r11) - rlwimi r10,r15,16,0x00ff0000 /* insert esel_next into MAS0 */ - addi r15,r15,1 /* increment esel_next */ + rlwimi r10,r9,16,0x00ff0000 /* insert esel_next into MAS0 */ + addi r9,r9,1 /* increment esel_next */ mtspr SPRN_MAS0,r10 - cmpw r15,r16 - iseleq r15,r14,r15 /* if next == last use first */ - stb r15,TCD_ESEL_NEXT(r11) + cmpw r9,r16 + iseleq r9,r14,r9 /* if next == last use first */ + stb r9,TCD_ESEL_NEXT(r11) tlbwe
The following is the benchmark number on a t2080rdb board:
For uncontended case (taskset -c 0 lat_mem_rd 2048 2097152):
origin lwsync r9
2.00000 1.958 1.958 1.958
3.00000 1.958 1.958 1.958
4.00000 1.958 1.958 1.958
6.00000 1.958 1.958 1.958
8.00000 1.958 1.958 1.958
12.00000 6.528 6.528 6.528
16.00000 6.528 6.528 6.528
24.00000 37.862 37.862 37.861
32.00000 37.862 37.862 37.862
48.00000 37.862 37.862 37.862
64.00000 37.862 37.862 37.862
96.00000 37.862 37.863 37.862
128.00000 221.621 232.067 222.927
192.00000 221.874 232.333 222.925
256.00000 221.623 232.066 222.927
384.00000 221.758 232.331 222.927
512.00000 221.621 232.165 222.926
768.00000 221.776 236.870 226.598
1024.00000 264.199 271.351 259.281
1536.00000 370.748 380.910 372.544
2048.00000 392.185 404.696 395.881
For contended case (taskset -c 0 lat_mem_rd 2048 2097152 &
taskset -c 1 lat_mem_rd 2048 2097152 >/dev/null 2>&1): origin lwsync r9
2.00000 3.366 2.944 3.086
3.00000 2.915 3.256 3.095
4.00000 3.043 2.443 2.617
6.00000 2.742 3.367 2.629
8.00000 3.145 3.365 2.443
12.00000 18.267 11.885 13.736
16.00000 15.607 13.312 18.048
24.00000 37.856 37.208 37.855
32.00000 37.856 37.861 37.855
48.00000 37.856 37.861 37.855
64.00000 57.487 37.861 52.505
96.00000 270.445 229.641 143.241
128.00000 284.535 279.907 305.540
192.00000 275.491 298.282 295.592
256.00000 265.155 331.212 259.096
384.00000 276.084 291.023 251.282
512.00000 275.852 335.602 267.074
768.00000 289.682 354.521 312.180
1024.00000 344.968 355.977 343.725
1536.00000 410.961 454.381 412.790
2048.00000 392.984 461.818 397.185
It seems that the using of an additional register do have better performance in both cases.
Thanks,
Kevin
Re: [PATCH 2/3] powerpc/e6500: hw tablewalk: optimize a bit for tcd lock acquiring codes
In reply to Kevin HaoQuoted 16 lines · Kevin Hao
Quoted 6 lines · Scott Wood
I tried a couple different benchmarks and didn't find a significant difference, relative to the variability of the results running on the same
kernel. A patch that claims to "optimize a bit" as its main purpose ought to
show some results. :-)I tried to compare the execution time of these two code sequences with the following test module:
#include <
linux/module.h>
#include <linux/kernel.h>
#include <linux/printk.h>static void test1(void)
Quoted 14 lines
{
int i;
unsigned char lock, c;
unsigned short cpu, s;
for (i = 0; i < 100000; i++) {
lock = 0;
cpu = 1;
asm volatile (
"1: lbarx %0,0,%2\n\
lhz %1,0(%3)\n\
cmpdi %0,0\n\
cmpdi cr1,%1,1\n\This should be either "cmpdi cr1,%0,1" or crclr, not that it made much difference. The test seemed to be rather sensitive to additional instructions inserted at the beginning of the asm statement (especially isync), so the initial instructions before the loop are probably pairing with something outside the asm.
That said, it looks like this patch at least doesn't make things worse, and does convert cmpdi to a more readable crclr, so I guess I'll apply it even though it doesn't show any measurable benefit when testing entire TLB misses (much less actual applications).
I suspect the point where I misunderstood the core manual was where it listed lbarx as having a repeat-rate of 3 cycles. I probably assumed that that was because of the presync, and thus a subsequent unrelated load could execute partially in parallel, but it looks like the repeat rate is specifically talking about how long it is until the execution unit can accept any other instruction.
-Scott
PATCH v2 1/1 powerpc/e6500: hw tablewalk: make sure we invalidate and write to the same tlb entry
In reply to Kevin HaoIn order to workaround Erratum A-008139, we have to invalidate the tlb entry with tlbilx before overwriting. Due to the performance consideration, we don't add any memory barrier when acquire/release the tcd lock. This means the two load instructions for esel_next do have the possibility to return different value. This is definitely not acceptable due to the Erratum A-008139. We have two options to fix this issue:
a) Add memory barrier when acquire/release tcd lock to order the load/store to esel_next.
b) Just make sure to invalidate and write to the same tlb entry and tolerate the race that we may get the wrong value and overwrite the tlb entry just updated by the other thread.
We observe better performance using option b. So reserve an additional register to save the value of the esel_next.
---
v2: Use an additional register for saving the value of esel_next instead of lwsync.
arch/powerpc/include/asm/exception-64e.h | 11 ++++++----- arch/powerpc/mm/tlb_low_64e.S | 26 ++++++++++++++++++-------- 2 files changed, 24 insertions(+), 13 deletions(-)
arch/powerpc/include/asm/exception-64e.h +6 -5
@@ -69,13 +69,14 @@#define EX_TLB_ESR ( 9 * 8)/* Level 0 and 2 only */ #define EX_TLB_SRR0 (10 * 8)#define EX_TLB_SRR1 (11 * 8) +#define EX_TLB_R7 (12 * 8)#ifdef CONFIG_BOOK3E_MMU_TLB_STATS -#define EX_TLB_R8 (12 * 8) -#define EX_TLB_R9 (13 * 8) -#define EX_TLB_LR (14 * 8) -#define EX_TLB_SIZE (15 * 8) +#define EX_TLB_R8 (13 * 8) +#define EX_TLB_R9 (14 * 8) +#define EX_TLB_LR (15 * 8) +#define EX_TLB_SIZE (16 * 8)#else -#define EX_TLB_SIZE (12 * 8) +#define EX_TLB_SIZE (13 * 8)#endif #define START_EXCEPTION (label) \
arch/powerpc/mm/tlb_low_64e.S +18 -8
@@ -68,11 +68,21 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV) ld r14,PACAPGD(r13) std r15,EX_TLB_R15(r12) std r10,EX_TLB_CR(r12) +#ifdef CONFIG_PPC_FSL_BOOK3E +BEGIN_FTR_SECTION + std r7,EX_TLB_R7(r12) +END_FTR_SECTION_IFSET(CPU_FTR_SMT) +#endif TLB_MISS_PROLOG_STATS .endm .macro tlb_epilog_bolted ld r14,EX_TLB_CR(r12) +#ifdef CONFIG_PPC_FSL_BOOK3E +BEGIN_FTR_SECTION + ld r7,EX_TLB_R7(r12) +END_FTR_SECTION_IFSET(CPU_FTR_SMT) +#endif ld r10,EX_TLB_R10(r12) ld r11,EX_TLB_R11(r12) ld r13,EX_TLB_R13(r12)
@@ -297,6 +307,7 @@ itlb_miss_fault_bolted: * r13 = PACA * r11 = tlb_per_core ptr * r10 = crap (free to use) + * r7 = esel_next */ tlb_miss_common_e6500: crmove cr2*4+2,cr0*4+2 /* cr2.eq != 0 if kernel address */
@@ -334,8 +345,8 @@ BEGIN_FTR_SECTION /* CPU_FTR_SMT */ * with tlbilx before overwriting. */ - lbz r15,TCD_ESEL_NEXT(r11) - rlwinm r10,r15,16,0xff0000 + lbz r7,TCD_ESEL_NEXT(r11) + rlwinm r10,r7,16,0xff0000 oris r10,r10,MAS0_TLBSEL(1)@h mtspr SPRN_MAS0,r10 isync
@@ -429,15 +440,14 @@ ALT_FTR_SECTION_END_IFSET(CPU_FTR_SMT) mtspr SPRN_MAS2,r15 tlb_miss_huge_done_e6500: - lbz r15,TCD_ESEL_NEXT(r11) lbz r16,TCD_ESEL_MAX(r11) lbz r14,TCD_ESEL_FIRST(r11) - rlwimi r10,r15,16,0x00ff0000 /* insert esel_next into MAS0 */ - addi r15,r15,1 /* increment esel_next */ + rlwimi r10,r7,16,0x00ff0000 /* insert esel_next into MAS0 */ + addi r7,r7,1 /* increment esel_next */ mtspr SPRN_MAS0,r10 - cmpw r15,r16 - iseleq r15,r14,r15 /* if next == last use first */ - stb r15,TCD_ESEL_NEXT(r11) + cmpw r7,r16 + iseleq r7,r14,r7 /* if next == last use first */ + stb r7,TCD_ESEL_NEXT(r11) tlbwe
Signature · 1 line
2.1.0
Re: [v2] powerpc/e6500: hw tablewalk: make sure we invalidate and write to the same tlb entry
Quoted 13 lines · Kevin Hao
arch/powerpc/mm/tlb_low_64e.S +5
-0@@ -68,11 +68,21 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV) ld r14,PACAPGD(r13) std r15,EX_TLB_R15(r12) std r10,EX_TLB_CR(r12) +#ifdef CONFIG_PPC_FSL_BOOK3E +BEGIN_FTR_SECTION + std r7,EX_TLB_R7(r12) +END_FTR_SECTION_IFSET(CPU_FTR_SMT) +#endif
arch/powerpc/mm/tlb_low_64e.S END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV) · line 85
Quoted 10 lines
arch/powerpc/mm/tlb_low_64e.S +5
-0TLB_MISS_PROLOG_STATS .endm .macro tlb_epilog_bolted ld r14,EX_TLB_CR(r12) +#ifdef CONFIG_PPC_FSL_BOOK3E +BEGIN_FTR_SECTION + ld r7,EX_TLB_R7(r12) +END_FTR_SECTION_IFSET(CPU_FTR_SMT) +#endif
r7 is used outside the CPU_FTR_SMT section of the e6500 TLB handler.
-Scott
Re: [v2] powerpc/e6500: hw tablewalk: make sure we invalidate and write to the same tlb entry
Quoted 17 lines · Scott Wood
Quoted 16 lines · Kevin Hao
arch/powerpc/mm/tlb_low_64e.S +5
-0@@ -68,11 +68,21 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV) ld r14,PACAPGD(r13) std r15,EX_TLB_R15(r12) std r10,EX_TLB_CR(r12) +#ifdef CONFIG_PPC_FSL_BOOK3E +BEGIN_FTR_SECTION + std r7,EX_TLB_R7(r12) +END_FTR_SECTION_IFSET(CPU_FTR_SMT) +#endif TLB_MISS_PROLOG_STATS .endm
Quoted 9 lines
arch/powerpc/mm/tlb_low_64e.S END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV) · line 85
Quoted 7 lines
arch/powerpc/mm/tlb_low_64e.S +5
-0.macro tlb_epilog_bolted ld r14,EX_TLB_CR(r12) +#ifdef CONFIG_PPC_FSL_BOOK3E +BEGIN_FTR_SECTION + ld r7,EX_TLB_R7(r12) +END_FTR_SECTION_IFSET(CPU_FTR_SMT) +#endifr7 is used outside the
CPU_FTR_SMTsection of the e6500 TLB handler.
Sorry for the delay response just back from vacation. I will move the load of TCD_ESEL_NEXT out of CPU_FTR_SMT wrap.
Thanks,
Kevin