From: Stewart Smith <hidden> Date: 2014-07-04 01:24:08
The POWER8 processor has a Micro Partition Prefetch Engine, which is
a fancy way of saying "has way to store and load contents of L2 or
L2+MRU way of L3 cache". We initiate the storing of the log (list of
addresses) using the logmpp instruction and start restore by writing
to a SPR.
The logmpp instruction takes parameters in a single 64bit register:
- starting address of the table to store log of L2/L2+L3 cache contents
- 32kb for L2
- 128kb for L2+L3
- Aligned relative to maximum size of the table (32kb or 128kb)
- Log control (no-op, L2 only, L2 and L3, abort logout)
We should abort any ongoing logging before initiating one.
To initiate restore, we write to the MPPR SPR. The format of what to write
to the SPR is similar to the logmpp instruction parameter:
- starting address of the table to read from (same alignment requirements)
- table size (no data, until end of table)
- prefetch rate (from fastest possible to slower. about every 8, 16, 24 or
32 cycles)
The idea behind loading and storing the contents of L2/L3 cache is to
reduce memory latency in a system that is frequently swapping vcores on
a physical CPU.
The best case scenario for doing this is when some vcores are doing very
cache heavy workloads. The worst case is when they have about 0 cache hits,
so we just generate needless memory operations.
This implementation just does L2 store/load. In my benchmarks this proves
to be useful.
Benchmark 1:
- 16 core POWER8
- 3x Ubuntu 14.04LTS guests (LE) with 8 VCPUs each
- No split core/SMT
- two guests running sysbench memory test.
sysbench --test=memory --num-threads=8 run
- one guest running apache bench (of default HTML page)
ab -n 490000 -c 400 http://localhost/
This benchmark aims to measure performance of real world application (apache)
where other guests are cache hot with their own workloads. The sysbench memory
benchmark does pointer sized writes to a (small) memory buffer in a loop.
In this benchmark with this patch I can see an improvement both in requests
per second (~5%) and in mean and median response times (again, about 5%).
The spread of minimum and maximum response times were largely unchanged.
benchmark 2:
- Same VM config as benchmark 1
- all three guests running sysbench memory benchmark
This benchmark aims to see if there is a positive or negative affect to this
cache heavy benchmark. Although due to the nature of the benchmark (stores) we
may not see a difference in performance, but rather hopefully an improvement
in consistency of performance (when vcore switched in, don't have to wait
many times for cachelines to be pulled in)
The results of this benchmark are improvements in consistency of performance
rather than performance itself. With this patch, the few outliers in duration
go away and we get more consistent performance in each guest.
benchmark 3:
- same 3 guests and CPU configuration as benchmark 1 and 2.
- two idle guests
- 1 guest running STREAM benchmark
This scenario also saw performance improvement with this patch. On Copy and
Scale workloads from STREAM, I got 5-6% improvement with this patch. For
Add and triad, it was around 10% (or more).
benchmark 4:
- same 3 guests as previous benchmarks
- two guests running sysbench --memory, distinctly different cache heavy
workload
- one guest running STREAM benchmark.
Similar improvements to benchmark 3.
benchmark 5:
- 1 guest, 8 VCPUs, Ubuntu 14.04
- Host configured with split core (SMT8, subcores-per-core=4)
- STREAM benchmark
In this benchmark, we see a 10-20% performance improvement across the board
of STREAM benchmark results with this patch.
Based on preliminary investigation and microbenchmarks
by Prerna Saxena [off-list ref]
Signed-off-by: Stewart Smith <redacted>
---
arch/powerpc/include/asm/kvm_host.h | 1 +
arch/powerpc/include/asm/ppc-opcode.h | 10 +++++++
arch/powerpc/include/asm/reg.h | 1 +
arch/powerpc/kvm/book3s_hv.c | 53 ++++++++++++++++++++++++++++++++-
4 files changed, 64 insertions(+), 1 deletion(-)
@@ -1528,6 +1528,7 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc)inti,need_vpa_update;intsrcu_idx;structkvm_vcpu*vcpus_to_update[threads_per_core];+phys_addr_tphy_addr,tmp;/* don't start if any threads have a signal pending */need_vpa_update=0;
@@ -1590,9 +1591,51 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc)srcu_idx=srcu_read_lock(&vc->kvm->srcu);+/* If we have a saved list of L2/L3, restore it */+if(cpu_has_feature(CPU_FTR_ARCH_207S)&&vc->mppe){+phy_addr=virt_to_phys((void*)vc->mppe);+#if defined(CONFIG_PPC_4K_PAGES)+phy_addr=(phy_addr+8*4096)&~(8*4096);+#endif+tmp=phy_addr&PPC_MPPE_ADDRESS_MASK;+tmp=tmp|PPC_MPPE_WHOLE_TABLE;++/* For sanity, abort any 'save' requests in progress */+asmvolatile(PPC_LOGMPP(R1)::"r"(tmp));++/* Inititate a cache-load request */+mtspr(SPRN_MPPR,tmp);+}++/* Allocate memory before switching out of guest so we don't+trashL2/L3withmemoryallocationstuff*/+if(cpu_has_feature(CPU_FTR_ARCH_207S)&&!vc->mppe){+#if defined(CONFIG_PPC_64K_PAGES)+vc->mppe=__get_free_pages(GFP_KERNEL|__GFP_ZERO,0);+#elif defined(CONFIG_PPC_4K_PAGES)+vc->mppe=__get_free_pages(GFP_KERNEL|__GFP_ZERO,4);+#endif+}+__kvmppc_vcore_entry();spin_lock(&vc->lock);++if(cpu_has_feature(CPU_FTR_ARCH_207S)&&vc->mppe){+phy_addr=(phys_addr_t)virt_to_phys((void*)vc->mppe);+#if defined(CONFIG_PPC_4K_PAGES)+phy_addr=(phy_addr+8*4096)&~(8*4096);+#endif+tmp=PPC_MPPE_ADDRESS_MASK&phy_addr;+tmp=tmp|PPC_MPPE_LOG_L2;++/* Abort any existing 'fetch' operations for this core */+mtspr(SPRN_MPPR,tmp&0x0fffffffffffffff);++/* Finally, issue logmpp to save cache contents for L2 */+asmvolatile(PPC_LOGMPP(R1)::"r"(tmp));+}+/* disable sending of IPIs on virtual external irqs */list_for_each_entry(vcpu,&vc->runnable_threads,arch.run_list)vcpu->cpu=-1;
From: Stewart Smith <hidden> Date: 2014-07-08 05:07:11
The POWER8 processor has a Micro Partition Prefetch Engine, which is
a fancy way of saying "has way to store and load contents of L2 or
L2+MRU way of L3 cache". We initiate the storing of the log (list of
addresses) using the logmpp instruction and start restore by writing
to a SPR.
The logmpp instruction takes parameters in a single 64bit register:
- starting address of the table to store log of L2/L2+L3 cache contents
- 32kb for L2
- 128kb for L2+L3
- Aligned relative to maximum size of the table (32kb or 128kb)
- Log control (no-op, L2 only, L2 and L3, abort logout)
We should abort any ongoing logging before initiating one.
To initiate restore, we write to the MPPR SPR. The format of what to write
to the SPR is similar to the logmpp instruction parameter:
- starting address of the table to read from (same alignment requirements)
- table size (no data, until end of table)
- prefetch rate (from fastest possible to slower. about every 8, 16, 24 or
32 cycles)
The idea behind loading and storing the contents of L2/L3 cache is to
reduce memory latency in a system that is frequently swapping vcores on
a physical CPU.
The best case scenario for doing this is when some vcores are doing very
cache heavy workloads. The worst case is when they have about 0 cache hits,
so we just generate needless memory operations.
This implementation just does L2 store/load. In my benchmarks this proves
to be useful.
Benchmark 1:
- 16 core POWER8
- 3x Ubuntu 14.04LTS guests (LE) with 8 VCPUs each
- No split core/SMT
- two guests running sysbench memory test.
sysbench --test=memory --num-threads=8 run
- one guest running apache bench (of default HTML page)
ab -n 490000 -c 400 http://localhost/
This benchmark aims to measure performance of real world application (apache)
where other guests are cache hot with their own workloads. The sysbench memory
benchmark does pointer sized writes to a (small) memory buffer in a loop.
In this benchmark with this patch I can see an improvement both in requests
per second (~5%) and in mean and median response times (again, about 5%).
The spread of minimum and maximum response times were largely unchanged.
benchmark 2:
- Same VM config as benchmark 1
- all three guests running sysbench memory benchmark
This benchmark aims to see if there is a positive or negative affect to this
cache heavy benchmark. Although due to the nature of the benchmark (stores) we
may not see a difference in performance, but rather hopefully an improvement
in consistency of performance (when vcore switched in, don't have to wait
many times for cachelines to be pulled in)
The results of this benchmark are improvements in consistency of performance
rather than performance itself. With this patch, the few outliers in duration
go away and we get more consistent performance in each guest.
benchmark 3:
- same 3 guests and CPU configuration as benchmark 1 and 2.
- two idle guests
- 1 guest running STREAM benchmark
This scenario also saw performance improvement with this patch. On Copy and
Scale workloads from STREAM, I got 5-6% improvement with this patch. For
Add and triad, it was around 10% (or more).
benchmark 4:
- same 3 guests as previous benchmarks
- two guests running sysbench --memory, distinctly different cache heavy
workload
- one guest running STREAM benchmark.
Similar improvements to benchmark 3.
benchmark 5:
- 1 guest, 8 VCPUs, Ubuntu 14.04
- Host configured with split core (SMT8, subcores-per-core=4)
- STREAM benchmark
In this benchmark, we see a 10-20% performance improvement across the board
of STREAM benchmark results with this patch.
Based on preliminary investigation and microbenchmarks
by Prerna Saxena [off-list ref]
Signed-off-by: Stewart Smith <redacted>
--
changes since v1:
- s/mppe/mpp_buffer/
- add MPP_BUFFER_ORDER define.
---
arch/powerpc/include/asm/kvm_host.h | 1 +
arch/powerpc/include/asm/ppc-opcode.h | 10 ++++++
arch/powerpc/include/asm/reg.h | 1 +
arch/powerpc/kvm/book3s_hv.c | 54 ++++++++++++++++++++++++++++++++-
4 files changed, 65 insertions(+), 1 deletion(-)
@@ -67,6 +67,13 @@/* Used as a "null" value for timebase values */#define TB_NIL (~(u64)0)+#if defined(CONFIG_PPC_64K_PAGES)+#define MPP_BUFFER_ORDER 0+#elif defined(CONFIG_PPC_4K_PAGES)+#define MPP_BUFFER_ORDER 4+#endif++staticvoidkvmppc_end_cede(structkvm_vcpu*vcpu);staticintkvmppc_hv_setup_htab_rma(structkvm_vcpu*vcpu);
@@ -1528,6 +1535,7 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc)inti,need_vpa_update;intsrcu_idx;structkvm_vcpu*vcpus_to_update[threads_per_core];+phys_addr_tphy_addr,tmp;/* don't start if any threads have a signal pending */need_vpa_update=0;
@@ -1590,9 +1598,48 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc)srcu_idx=srcu_read_lock(&vc->kvm->srcu);+/* If we have a saved list of L2/L3, restore it */+if(cpu_has_feature(CPU_FTR_ARCH_207S)&&vc->mpp_buffer){+phy_addr=virt_to_phys((void*)vc->mpp_buffer);+#if defined(CONFIG_PPC_4K_PAGES)+phy_addr=(phy_addr+8*4096)&~(8*4096);+#endif+tmp=phy_addr&PPC_MPPE_ADDRESS_MASK;+tmp=tmp|PPC_MPPE_WHOLE_TABLE;++/* For sanity, abort any 'save' requests in progress */+asmvolatile(PPC_LOGMPP(R1)::"r"(tmp));++/* Inititate a cache-load request */+mtspr(SPRN_MPPR,tmp);+}++/* Allocate memory before switching out of guest so we don't+trashL2/L3withmemoryallocationstuff*/+if(cpu_has_feature(CPU_FTR_ARCH_207S)&&!vc->mpp_buffer){+vc->mpp_buffer=__get_free_pages(GFP_KERNEL|__GFP_ZERO,+MPP_BUFFER_ORDER);+}+__kvmppc_vcore_entry();spin_lock(&vc->lock);++if(cpu_has_feature(CPU_FTR_ARCH_207S)&&vc->mpp_buffer){+phy_addr=(phys_addr_t)virt_to_phys((void*)vc->mpp_buffer);+#if defined(CONFIG_PPC_4K_PAGES)+phy_addr=(phy_addr+8*4096)&~(8*4096);+#endif+tmp=PPC_MPPE_ADDRESS_MASK&phy_addr;+tmp=tmp|PPC_MPPE_LOG_L2;++/* Abort any existing 'fetch' operations for this core */+mtspr(SPRN_MPPR,tmp&0x0fffffffffffffff);++/* Finally, issue logmpp to save cache contents for L2 */+asmvolatile(PPC_LOGMPP(R1)::"r"(tmp));+}+/* disable sending of IPIs on virtual external irqs */list_for_each_entry(vcpu,&vc->runnable_threads,arch.run_list)vcpu->cpu=-1;
From: Alexander Graf <hidden> Date: 2014-07-08 10:41:17
On 08.07.14 07:06, Stewart Smith wrote:
quoted hunk
The POWER8 processor has a Micro Partition Prefetch Engine, which is
a fancy way of saying "has way to store and load contents of L2 or
L2+MRU way of L3 cache". We initiate the storing of the log (list of
addresses) using the logmpp instruction and start restore by writing
to a SPR.
The logmpp instruction takes parameters in a single 64bit register:
- starting address of the table to store log of L2/L2+L3 cache contents
- 32kb for L2
- 128kb for L2+L3
- Aligned relative to maximum size of the table (32kb or 128kb)
- Log control (no-op, L2 only, L2 and L3, abort logout)
We should abort any ongoing logging before initiating one.
To initiate restore, we write to the MPPR SPR. The format of what to write
to the SPR is similar to the logmpp instruction parameter:
- starting address of the table to read from (same alignment requirements)
- table size (no data, until end of table)
- prefetch rate (from fastest possible to slower. about every 8, 16, 24 or
32 cycles)
The idea behind loading and storing the contents of L2/L3 cache is to
reduce memory latency in a system that is frequently swapping vcores on
a physical CPU.
The best case scenario for doing this is when some vcores are doing very
cache heavy workloads. The worst case is when they have about 0 cache hits,
so we just generate needless memory operations.
This implementation just does L2 store/load. In my benchmarks this proves
to be useful.
Benchmark 1:
- 16 core POWER8
- 3x Ubuntu 14.04LTS guests (LE) with 8 VCPUs each
- No split core/SMT
- two guests running sysbench memory test.
sysbench --test=memory --num-threads=8 run
- one guest running apache bench (of default HTML page)
ab -n 490000 -c 400 http://localhost/
This benchmark aims to measure performance of real world application (apache)
where other guests are cache hot with their own workloads. The sysbench memory
benchmark does pointer sized writes to a (small) memory buffer in a loop.
In this benchmark with this patch I can see an improvement both in requests
per second (~5%) and in mean and median response times (again, about 5%).
The spread of minimum and maximum response times were largely unchanged.
benchmark 2:
- Same VM config as benchmark 1
- all three guests running sysbench memory benchmark
This benchmark aims to see if there is a positive or negative affect to this
cache heavy benchmark. Although due to the nature of the benchmark (stores) we
may not see a difference in performance, but rather hopefully an improvement
in consistency of performance (when vcore switched in, don't have to wait
many times for cachelines to be pulled in)
The results of this benchmark are improvements in consistency of performance
rather than performance itself. With this patch, the few outliers in duration
go away and we get more consistent performance in each guest.
benchmark 3:
- same 3 guests and CPU configuration as benchmark 1 and 2.
- two idle guests
- 1 guest running STREAM benchmark
This scenario also saw performance improvement with this patch. On Copy and
Scale workloads from STREAM, I got 5-6% improvement with this patch. For
Add and triad, it was around 10% (or more).
benchmark 4:
- same 3 guests as previous benchmarks
- two guests running sysbench --memory, distinctly different cache heavy
workload
- one guest running STREAM benchmark.
Similar improvements to benchmark 3.
benchmark 5:
- 1 guest, 8 VCPUs, Ubuntu 14.04
- Host configured with split core (SMT8, subcores-per-core=4)
- STREAM benchmark
In this benchmark, we see a 10-20% performance improvement across the board
of STREAM benchmark results with this patch.
Based on preliminary investigation and microbenchmarks
by Prerna Saxena [off-list ref]
Signed-off-by: Stewart Smith <redacted>
--
changes since v1:
- s/mppe/mpp_buffer/
- add MPP_BUFFER_ORDER define.
---
arch/powerpc/include/asm/kvm_host.h | 1 +
arch/powerpc/include/asm/ppc-opcode.h | 10 ++++++
arch/powerpc/include/asm/reg.h | 1 +
arch/powerpc/kvm/book3s_hv.c | 54 ++++++++++++++++++++++++++++++++-
4 files changed, 65 insertions(+), 1 deletion(-)
@@ -67,6 +67,13 @@/* Used as a "null" value for timebase values */#define TB_NIL (~(u64)0)+#if defined(CONFIG_PPC_64K_PAGES)+#define MPP_BUFFER_ORDER 0+#elif defined(CONFIG_PPC_4K_PAGES)+#define MPP_BUFFER_ORDER 4+#endif++staticvoidkvmppc_end_cede(structkvm_vcpu*vcpu);staticintkvmppc_hv_setup_htab_rma(structkvm_vcpu*vcpu);
In fact, this whole block up here could be a function, no?
+
+ /* Allocate memory before switching out of guest so we don't
+ trash L2/L3 with memory allocation stuff */
+ if (cpu_has_feature(CPU_FTR_ARCH_207S) && !vc->mpp_buffer) {
+ vc->mpp_buffer = __get_free_pages(GFP_KERNEL|__GFP_ZERO,
+ MPP_BUFFER_ORDER);
get_order(64 * 1024)?
Also, why allocate it here and not on vcore creation?
+
+ /* Finally, issue logmpp to save cache contents for L2 */
+ asm volatile(PPC_LOGMPP(R1) : : "r" (tmp));
+ }
This too should be a separate function.
Alex
quoted hunk
+
/* disable sending of IPIs on virtual external irqs */
list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list)
vcpu->cpu = -1;
@@ -2329,8 +2376,13 @@ static void kvmppc_free_vcores(struct kvm *kvm) { long int i;- for (i = 0; i < KVM_MAX_VCORES; ++i)+ for (i = 0; i < KVM_MAX_VCORES; ++i) {+ if (kvm->arch.vcores[i] && kvm->arch.vcores[i]->mpp_buffer) {+ free_pages(kvm->arch.vcores[i]->mpp_buffer,+ MPP_BUFFER_ORDER);+ } kfree(kvm->arch.vcores[i]);+ } kvm->arch.online_vcores = 0; }
From: Stewart Smith <hidden> Date: 2014-07-08 22:59:49
Hi!
Thanks for review, much appreciated!
Alexander Graf [off-list ref] writes:
On 08.07.14 07:06, Stewart Smith wrote:
quoted
@@ -1528,6 +1535,7 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) int i, need_vpa_update; int srcu_idx; struct kvm_vcpu *vcpus_to_update[threads_per_core];+ phys_addr_t phy_addr, tmp;
Please put the variable declarations into the if () branch so that the
compiler can catch potential leaks :)
ack. will fix.
quoted
@@ -1590,9 +1598,48 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) srcu_idx = srcu_read_lock(&vc->kvm->srcu);+ /* If we have a saved list of L2/L3, restore it */+ if (cpu_has_feature(CPU_FTR_ARCH_207S) && vc->mpp_buffer) {+ phy_addr = virt_to_phys((void *)vc->mpp_buffer);+#if defined(CONFIG_PPC_4K_PAGES)+ phy_addr = (phy_addr + 8*4096) & ~(8*4096);
get_free_pages() is automatically aligned to the order, no?
That's what Paul reckoned too, and then we've attempted to find anywhere
that documents that behaviour. Happen to be able to point to docs/source
that say this is part of API?
In fact, this whole block up here could be a function, no?
It could, perfectly happy for it to be one. Will fix.
quoted
+
+ /* Allocate memory before switching out of guest so we don't
+ trash L2/L3 with memory allocation stuff */
+ if (cpu_has_feature(CPU_FTR_ARCH_207S) && !vc->mpp_buffer) {
+ vc->mpp_buffer = __get_free_pages(GFP_KERNEL|__GFP_ZERO,
+ MPP_BUFFER_ORDER);
get_order(64 * 1024)?
Also, why allocate it here and not on vcore creation?
There's also the possibility of saving/restorting part of the L3 cache
as well, and I was envisioning a future patch to this which checks a
flag in vcore (maybe exposed via sysfs or whatever mechanism is
applicable) if it should save/restore L2 or L2/L3, so thus it makes a
bit more sense allocating it there rather than elsewhere.
There's also no real reason to fail to create a vcore if we can't
allocate a buffer for L2/L3 cache contents - retrying later is perfectly
harmless.
Yeah, sorry about that.... I'll hide it in a function at least, and do
something a bit better there... IIRC this magic came from the initial
work that proved the hardware functionality, so I'll go back and re-read
some hardware documentation to see where exactly this came from...
quoted
+
+ /* Finally, issue logmpp to save cache contents for L2 */
+ asm volatile(PPC_LOGMPP(R1) : : "r" (tmp));
+ }
From: Alexander Graf <hidden> Date: 2014-07-10 11:05:51
On 09.07.14 00:59, Stewart Smith wrote:
Hi!
Thanks for review, much appreciated!
Alexander Graf [off-list ref] writes:
quoted
On 08.07.14 07:06, Stewart Smith wrote:
quoted
@@ -1528,6 +1535,7 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) int i, need_vpa_update; int srcu_idx; struct kvm_vcpu *vcpus_to_update[threads_per_core];+ phys_addr_t phy_addr, tmp;
Please put the variable declarations into the if () branch so that the
compiler can catch potential leaks :)
ack. will fix.
quoted
quoted
@@ -1590,9 +1598,48 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) srcu_idx = srcu_read_lock(&vc->kvm->srcu);+ /* If we have a saved list of L2/L3, restore it */+ if (cpu_has_feature(CPU_FTR_ARCH_207S) && vc->mpp_buffer) {+ phy_addr = virt_to_phys((void *)vc->mpp_buffer);+#if defined(CONFIG_PPC_4K_PAGES)+ phy_addr = (phy_addr + 8*4096) & ~(8*4096);
get_free_pages() is automatically aligned to the order, no?
That's what Paul reckoned too, and then we've attempted to find anywhere
that documents that behaviour. Happen to be able to point to docs/source
that say this is part of API?
Phew - it's probably buried somewhere. I could only find this document
saying that we always get order-aligned allocations:
http://www.thehackademy.net/madchat/ebooks/Mem_virtuelle/linux-mm/zonealloc.html
Mel, do you happen to have any pointer to something that explicitly (or
even properly implicitly) says that get_free_pages() returns
order-aligned memory?
In fact, this whole block up here could be a function, no?
It could, perfectly happy for it to be one. Will fix.
quoted
quoted
+
+ /* Allocate memory before switching out of guest so we don't
+ trash L2/L3 with memory allocation stuff */
+ if (cpu_has_feature(CPU_FTR_ARCH_207S) && !vc->mpp_buffer) {
+ vc->mpp_buffer = __get_free_pages(GFP_KERNEL|__GFP_ZERO,
+ MPP_BUFFER_ORDER);
get_order(64 * 1024)?
Also, why allocate it here and not on vcore creation?
There's also the possibility of saving/restorting part of the L3 cache
as well, and I was envisioning a future patch to this which checks a
flag in vcore (maybe exposed via sysfs or whatever mechanism is
applicable) if it should save/restore L2 or L2/L3, so thus it makes a
bit more sense allocating it there rather than elsewhere.
There's also no real reason to fail to create a vcore if we can't
allocate a buffer for L2/L3 cache contents - retrying later is perfectly
harmless.
If we failed during core creation just don't save/restore L2 cache
contents at all. I really prefer to have allocation and dealloction all
at init time - and such low order allocations will most likely succeed.
Let's leave the L3 cache bits for later when we know whether it actually
has an impact. I personally doubt it :).
Alex
On Thu, Jul 10, 2014 at 01:05:47PM +0200, Alexander Graf wrote:
On 09.07.14 00:59, Stewart Smith wrote:
quoted
Hi!
Thanks for review, much appreciated!
Alexander Graf [off-list ref] writes:
quoted
On 08.07.14 07:06, Stewart Smith wrote:
quoted
@@ -1528,6 +1535,7 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) int i, need_vpa_update; int srcu_idx; struct kvm_vcpu *vcpus_to_update[threads_per_core];+ phys_addr_t phy_addr, tmp;
Please put the variable declarations into the if () branch so that the
compiler can catch potential leaks :)
ack. will fix.
quoted
quoted
@@ -1590,9 +1598,48 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) srcu_idx = srcu_read_lock(&vc->kvm->srcu);+ /* If we have a saved list of L2/L3, restore it */+ if (cpu_has_feature(CPU_FTR_ARCH_207S) && vc->mpp_buffer) {+ phy_addr = virt_to_phys((void *)vc->mpp_buffer);+#if defined(CONFIG_PPC_4K_PAGES)+ phy_addr = (phy_addr + 8*4096) & ~(8*4096);
get_free_pages() is automatically aligned to the order, no?
That's what Paul reckoned too, and then we've attempted to find anywhere
that documents that behaviour. Happen to be able to point to docs/source
that say this is part of API?
Phew - it's probably buried somewhere. I could only find this
document saying that we always get order-aligned allocations:
http://www.thehackademy.net/madchat/ebooks/Mem_virtuelle/linux-mm/zonealloc.html
Mel, do you happen to have any pointer to something that explicitly
(or even properly implicitly) says that get_free_pages() returns
order-aligned memory?
I did not read the whole thread so I lack context and will just answer
this part.
There is no guarantee that pages are returned in PFN order for multiple
requests to the page allocator. This is the relevant comment in
rmqueue_bulk
/*
* Split buddy pages returned by expand() are received here
* in physical page order. The page is added to the callers and
* list and the list head then moves forward. From the callers
* perspective, the linked list is ordered by page number in
* some conditions. This is useful for IO devices that can
* merge IO requests if the physical pages are ordered
* properly.
*/
It will probably be true early in the lifetime of the system but the milage
will vary on systems with a lot of uptime. If you depend on this behaviour
for correctness then you will have a bad day.
High-order page requests to the page allocator are guaranteed to be in physical
order. However, this does not apply to vmalloc() where allocations are
only guaranteed to be virtually contiguous.
--
Mel Gorman
SUSE Labs
From: Alexander Graf <hidden> Date: 2014-07-10 13:17:19
On 10.07.14 15:07, Mel Gorman wrote:
On Thu, Jul 10, 2014 at 01:05:47PM +0200, Alexander Graf wrote:
quoted
On 09.07.14 00:59, Stewart Smith wrote:
quoted
Hi!
Thanks for review, much appreciated!
Alexander Graf [off-list ref] writes:
quoted
On 08.07.14 07:06, Stewart Smith wrote:
quoted
@@ -1528,6 +1535,7 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) int i, need_vpa_update; int srcu_idx; struct kvm_vcpu *vcpus_to_update[threads_per_core];+ phys_addr_t phy_addr, tmp;
Please put the variable declarations into the if () branch so that the
compiler can catch potential leaks :)
ack. will fix.
quoted
quoted
@@ -1590,9 +1598,48 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) srcu_idx = srcu_read_lock(&vc->kvm->srcu);+ /* If we have a saved list of L2/L3, restore it */+ if (cpu_has_feature(CPU_FTR_ARCH_207S) && vc->mpp_buffer) {+ phy_addr = virt_to_phys((void *)vc->mpp_buffer);+#if defined(CONFIG_PPC_4K_PAGES)+ phy_addr = (phy_addr + 8*4096) & ~(8*4096);
get_free_pages() is automatically aligned to the order, no?
That's what Paul reckoned too, and then we've attempted to find anywhere
that documents that behaviour. Happen to be able to point to docs/source
that say this is part of API?
Phew - it's probably buried somewhere. I could only find this
document saying that we always get order-aligned allocations:
http://www.thehackademy.net/madchat/ebooks/Mem_virtuelle/linux-mm/zonealloc.html
Mel, do you happen to have any pointer to something that explicitly
(or even properly implicitly) says that get_free_pages() returns
order-aligned memory?
I did not read the whole thread so I lack context and will just answer
this part.
There is no guarantee that pages are returned in PFN order for multiple
requests to the page allocator. This is the relevant comment in
rmqueue_bulk
/*
* Split buddy pages returned by expand() are received here
* in physical page order. The page is added to the callers and
* list and the list head then moves forward. From the callers
* perspective, the linked list is ordered by page number in
* some conditions. This is useful for IO devices that can
* merge IO requests if the physical pages are ordered
* properly.
*/
It will probably be true early in the lifetime of the system but the milage
will vary on systems with a lot of uptime. If you depend on this behaviour
for correctness then you will have a bad day.
High-order page requests to the page allocator are guaranteed to be in physical
order. However, this does not apply to vmalloc() where allocations are
only guaranteed to be virtually contiguous.
Hrm, ok to be very concrete:
Does __get_free_pages(..., 4); on a 4k page size system give me a 64k
aligned pointer? :)
Alex
On Thu, Jul 10, 2014 at 03:17:16PM +0200, Alexander Graf wrote:
On 10.07.14 15:07, Mel Gorman wrote:
quoted
On Thu, Jul 10, 2014 at 01:05:47PM +0200, Alexander Graf wrote:
quoted
On 09.07.14 00:59, Stewart Smith wrote:
quoted
Hi!
Thanks for review, much appreciated!
Alexander Graf [off-list ref] writes:
quoted
On 08.07.14 07:06, Stewart Smith wrote:
quoted
@@ -1528,6 +1535,7 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) int i, need_vpa_update; int srcu_idx; struct kvm_vcpu *vcpus_to_update[threads_per_core];+ phys_addr_t phy_addr, tmp;
Please put the variable declarations into the if () branch so that the
compiler can catch potential leaks :)
ack. will fix.
quoted
quoted
@@ -1590,9 +1598,48 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) srcu_idx = srcu_read_lock(&vc->kvm->srcu);+ /* If we have a saved list of L2/L3, restore it */+ if (cpu_has_feature(CPU_FTR_ARCH_207S) && vc->mpp_buffer) {+ phy_addr = virt_to_phys((void *)vc->mpp_buffer);+#if defined(CONFIG_PPC_4K_PAGES)+ phy_addr = (phy_addr + 8*4096) & ~(8*4096);
get_free_pages() is automatically aligned to the order, no?
That's what Paul reckoned too, and then we've attempted to find anywhere
that documents that behaviour. Happen to be able to point to docs/source
that say this is part of API?
Phew - it's probably buried somewhere. I could only find this
document saying that we always get order-aligned allocations:
http://www.thehackademy.net/madchat/ebooks/Mem_virtuelle/linux-mm/zonealloc.html
Mel, do you happen to have any pointer to something that explicitly
(or even properly implicitly) says that get_free_pages() returns
order-aligned memory?
I did not read the whole thread so I lack context and will just answer
this part.
There is no guarantee that pages are returned in PFN order for multiple
requests to the page allocator. This is the relevant comment in
rmqueue_bulk
/*
* Split buddy pages returned by expand() are received here
* in physical page order. The page is added to the callers and
* list and the list head then moves forward. From the callers
* perspective, the linked list is ordered by page number in
* some conditions. This is useful for IO devices that can
* merge IO requests if the physical pages are ordered
* properly.
*/
It will probably be true early in the lifetime of the system but the milage
will vary on systems with a lot of uptime. If you depend on this behaviour
for correctness then you will have a bad day.
High-order page requests to the page allocator are guaranteed to be in physical
order. However, this does not apply to vmalloc() where allocations are
only guaranteed to be virtually contiguous.
Hrm, ok to be very concrete:
Does __get_free_pages(..., 4); on a 4k page size system give me a
64k aligned pointer? :)
From: Alexander Graf <hidden> Date: 2014-07-10 13:31:05
On 10.07.14 15:30, Mel Gorman wrote:
On Thu, Jul 10, 2014 at 03:17:16PM +0200, Alexander Graf wrote:
quoted
On 10.07.14 15:07, Mel Gorman wrote:
quoted
On Thu, Jul 10, 2014 at 01:05:47PM +0200, Alexander Graf wrote:
quoted
On 09.07.14 00:59, Stewart Smith wrote:
quoted
Hi!
Thanks for review, much appreciated!
Alexander Graf [off-list ref] writes:
quoted
On 08.07.14 07:06, Stewart Smith wrote:
quoted
@@ -1528,6 +1535,7 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) int i, need_vpa_update; int srcu_idx; struct kvm_vcpu *vcpus_to_update[threads_per_core];+ phys_addr_t phy_addr, tmp;
Please put the variable declarations into the if () branch so that the
compiler can catch potential leaks :)
ack. will fix.
quoted
quoted
@@ -1590,9 +1598,48 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) srcu_idx = srcu_read_lock(&vc->kvm->srcu);+ /* If we have a saved list of L2/L3, restore it */+ if (cpu_has_feature(CPU_FTR_ARCH_207S) && vc->mpp_buffer) {+ phy_addr = virt_to_phys((void *)vc->mpp_buffer);+#if defined(CONFIG_PPC_4K_PAGES)+ phy_addr = (phy_addr + 8*4096) & ~(8*4096);
get_free_pages() is automatically aligned to the order, no?
That's what Paul reckoned too, and then we've attempted to find anywhere
that documents that behaviour. Happen to be able to point to docs/source
that say this is part of API?
Phew - it's probably buried somewhere. I could only find this
document saying that we always get order-aligned allocations:
http://www.thehackademy.net/madchat/ebooks/Mem_virtuelle/linux-mm/zonealloc.html
Mel, do you happen to have any pointer to something that explicitly
(or even properly implicitly) says that get_free_pages() returns
order-aligned memory?
I did not read the whole thread so I lack context and will just answer
this part.
There is no guarantee that pages are returned in PFN order for multiple
requests to the page allocator. This is the relevant comment in
rmqueue_bulk
/*
* Split buddy pages returned by expand() are received here
* in physical page order. The page is added to the callers and
* list and the list head then moves forward. From the callers
* perspective, the linked list is ordered by page number in
* some conditions. This is useful for IO devices that can
* merge IO requests if the physical pages are ordered
* properly.
*/
It will probably be true early in the lifetime of the system but the milage
will vary on systems with a lot of uptime. If you depend on this behaviour
for correctness then you will have a bad day.
High-order page requests to the page allocator are guaranteed to be in physical
order. However, this does not apply to vmalloc() where allocations are
only guaranteed to be virtually contiguous.
Hrm, ok to be very concrete:
Does __get_free_pages(..., 4); on a 4k page size system give me a
64k aligned pointer? :)
From: Stewart Smith <hidden> Date: 2014-07-17 03:20:12
The POWER8 processor has a Micro Partition Prefetch Engine, which is
a fancy way of saying "has way to store and load contents of L2 or
L2+MRU way of L3 cache". We initiate the storing of the log (list of
addresses) using the logmpp instruction and start restore by writing
to a SPR.
The logmpp instruction takes parameters in a single 64bit register:
- starting address of the table to store log of L2/L2+L3 cache contents
- 32kb for L2
- 128kb for L2+L3
- Aligned relative to maximum size of the table (32kb or 128kb)
- Log control (no-op, L2 only, L2 and L3, abort logout)
We should abort any ongoing logging before initiating one.
To initiate restore, we write to the MPPR SPR. The format of what to write
to the SPR is similar to the logmpp instruction parameter:
- starting address of the table to read from (same alignment requirements)
- table size (no data, until end of table)
- prefetch rate (from fastest possible to slower. about every 8, 16, 24 or
32 cycles)
The idea behind loading and storing the contents of L2/L3 cache is to
reduce memory latency in a system that is frequently swapping vcores on
a physical CPU.
The best case scenario for doing this is when some vcores are doing very
cache heavy workloads. The worst case is when they have about 0 cache hits,
so we just generate needless memory operations.
This implementation just does L2 store/load. In my benchmarks this proves
to be useful.
Benchmark 1:
- 16 core POWER8
- 3x Ubuntu 14.04LTS guests (LE) with 8 VCPUs each
- No split core/SMT
- two guests running sysbench memory test.
sysbench --test=memory --num-threads=8 run
- one guest running apache bench (of default HTML page)
ab -n 490000 -c 400 http://localhost/
This benchmark aims to measure performance of real world application (apache)
where other guests are cache hot with their own workloads. The sysbench memory
benchmark does pointer sized writes to a (small) memory buffer in a loop.
In this benchmark with this patch I can see an improvement both in requests
per second (~5%) and in mean and median response times (again, about 5%).
The spread of minimum and maximum response times were largely unchanged.
benchmark 2:
- Same VM config as benchmark 1
- all three guests running sysbench memory benchmark
This benchmark aims to see if there is a positive or negative affect to this
cache heavy benchmark. Although due to the nature of the benchmark (stores) we
may not see a difference in performance, but rather hopefully an improvement
in consistency of performance (when vcore switched in, don't have to wait
many times for cachelines to be pulled in)
The results of this benchmark are improvements in consistency of performance
rather than performance itself. With this patch, the few outliers in duration
go away and we get more consistent performance in each guest.
benchmark 3:
- same 3 guests and CPU configuration as benchmark 1 and 2.
- two idle guests
- 1 guest running STREAM benchmark
This scenario also saw performance improvement with this patch. On Copy and
Scale workloads from STREAM, I got 5-6% improvement with this patch. For
Add and triad, it was around 10% (or more).
benchmark 4:
- same 3 guests as previous benchmarks
- two guests running sysbench --memory, distinctly different cache heavy
workload
- one guest running STREAM benchmark.
Similar improvements to benchmark 3.
benchmark 5:
- 1 guest, 8 VCPUs, Ubuntu 14.04
- Host configured with split core (SMT8, subcores-per-core=4)
- STREAM benchmark
In this benchmark, we see a 10-20% performance improvement across the board
of STREAM benchmark results with this patch.
Based on preliminary investigation and microbenchmarks
by Prerna Saxena [off-list ref]
Signed-off-by: Stewart Smith <redacted>
--
changes since v2:
- based on feedback from Alexander Graf:
- move save and restore of cache to separate functions
- move allocation of mpp_buffer to vcore creation
- get_free_pages() does actually allocate pages aligned to order
(Mel Gorman confirms)
- make SPR and logmpp parameters a bit less magic, especially around abort
changes since v1:
- s/mppe/mpp_buffer/
- add MPP_BUFFER_ORDER define.
---
arch/powerpc/include/asm/kvm_host.h | 2 +
arch/powerpc/include/asm/ppc-opcode.h | 17 +++++++
arch/powerpc/include/asm/reg.h | 1 +
arch/powerpc/kvm/book3s_hv.c | 89 +++++++++++++++++++++++++++++----
4 files changed, 98 insertions(+), 11 deletions(-)
@@ -275,6 +276,20 @@#define __PPC_EH(eh) 0#endif+/* POWER8 Micro Partition Prefetch (MPP) parameters */+/* Address mask is common for LOGMPP instruction and MPPR SPR */+#define PPC_MPPE_ADDRESS_MASK 0xffffffffc000++/* Bits 60 and 61 of MPP SPR should be set to one of the following */+/* Aborting the fetch is indeed setting 00 in the table size bits */+#define PPC_MPPR_FETCH_ABORT (0x0ULL << 60)+#define PPC_MPPR_FETCH_WHOLE_TABLE (0x2ULL << 60)++/* Bits 54 and 55 of register for LOGMPP instruction should be set to: */+#define PPC_LOGMPP_LOG_L2 (0x02ULL << 54)+#define PPC_LOGMPP_LOG_L2L3 (0x01ULL << 54)+#define PPC_LOGMPP_LOG_ABORT (0x03ULL << 54)+/* Deal with instructions that older assemblers aren't aware of */#define PPC_DCBAL(a, b) stringify_in_c(.long PPC_INST_DCBAL | \__PPC_RA(a)|__PPC_RB(b))
@@ -67,6 +67,13 @@/* Used as a "null" value for timebase values */#define TB_NIL (~(u64)0)+#if defined(CONFIG_PPC_64K_PAGES)+#define MPP_BUFFER_ORDER 0+#elif defined(CONFIG_PPC_4K_PAGES)+#define MPP_BUFFER_ORDER 4+#endif++staticvoidkvmppc_end_cede(structkvm_vcpu*vcpu);staticintkvmppc_hv_setup_htab_rma(structkvm_vcpu*vcpu);
@@ -1516,6 +1540,37 @@ static int on_primary_thread(void)return1;}+staticvoidppc_start_saving_l2_cache(structkvmppc_vcore*vc)+{+phys_addr_tphy_addr,tmp;++phy_addr=(phys_addr_t)virt_to_phys((void*)vc->mpp_buffer);++tmp=phy_addr&PPC_MPPE_ADDRESS_MASK;++mtspr(SPRN_MPPR,tmp|PPC_MPPR_FETCH_ABORT);++asmvolatile(PPC_LOGMPP(R1)::"r"(tmp|PPC_LOGMPP_LOG_L2));++vc->mpp_buffer_is_valid=true;+}++staticvoidppc_start_restoring_l2_cache(conststructkvmppc_vcore*vc)+{+phys_addr_tphy_addr,tmp;++phy_addr=virt_to_phys((void*)vc->mpp_buffer);++tmp=phy_addr&PPC_MPPE_ADDRESS_MASK;++/* We must abort any in-progress save operations to ensure+*thetableisvalidsothatprefetchengineknowswhento+*stopprefetching.*/+asmvolatile(PPC_LOGMPP(R1)::"r"(tmp|PPC_LOGMPP_LOG_ABORT));++mtspr(SPRN_MPPR,tmp|PPC_MPPR_FETCH_WHOLE_TABLE);+}+/**Runasetofguestthreadsonaphysicalcore.*Calledwithvc->lockheld.
@@ -1590,9 +1645,16 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc)srcu_idx=srcu_read_lock(&vc->kvm->srcu);+if(vc->mpp_buffer_is_valid)+ppc_start_restoring_l2_cache(vc);+__kvmppc_vcore_entry();spin_lock(&vc->lock);++if(vc->mpp_buffer)+ppc_start_saving_l2_cache(vc);+/* disable sending of IPIs on virtual external irqs */list_for_each_entry(vcpu,&vc->runnable_threads,arch.run_list)vcpu->cpu=-1;
From: Alexander Graf <hidden> Date: 2014-07-17 07:55:18
On 17.07.14 05:19, Stewart Smith wrote:
The POWER8 processor has a Micro Partition Prefetch Engine, which is
a fancy way of saying "has way to store and load contents of L2 or
L2+MRU way of L3 cache". We initiate the storing of the log (list of
addresses) using the logmpp instruction and start restore by writing
to a SPR.
The logmpp instruction takes parameters in a single 64bit register:
- starting address of the table to store log of L2/L2+L3 cache contents
- 32kb for L2
- 128kb for L2+L3
- Aligned relative to maximum size of the table (32kb or 128kb)
- Log control (no-op, L2 only, L2 and L3, abort logout)
We should abort any ongoing logging before initiating one.
To initiate restore, we write to the MPPR SPR. The format of what to write
to the SPR is similar to the logmpp instruction parameter:
- starting address of the table to read from (same alignment requirements)
- table size (no data, until end of table)
- prefetch rate (from fastest possible to slower. about every 8, 16, 24 or
32 cycles)
The idea behind loading and storing the contents of L2/L3 cache is to
reduce memory latency in a system that is frequently swapping vcores on
a physical CPU.
The best case scenario for doing this is when some vcores are doing very
cache heavy workloads. The worst case is when they have about 0 cache hits,
so we just generate needless memory operations.
This implementation just does L2 store/load. In my benchmarks this proves
to be useful.
Benchmark 1:
- 16 core POWER8
- 3x Ubuntu 14.04LTS guests (LE) with 8 VCPUs each
- No split core/SMT
- two guests running sysbench memory test.
sysbench --test=memory --num-threads=8 run
- one guest running apache bench (of default HTML page)
ab -n 490000 -c 400 http://localhost/
This benchmark aims to measure performance of real world application (apache)
where other guests are cache hot with their own workloads. The sysbench memory
benchmark does pointer sized writes to a (small) memory buffer in a loop.
In this benchmark with this patch I can see an improvement both in requests
per second (~5%) and in mean and median response times (again, about 5%).
The spread of minimum and maximum response times were largely unchanged.
benchmark 2:
- Same VM config as benchmark 1
- all three guests running sysbench memory benchmark
This benchmark aims to see if there is a positive or negative affect to this
cache heavy benchmark. Although due to the nature of the benchmark (stores) we
may not see a difference in performance, but rather hopefully an improvement
in consistency of performance (when vcore switched in, don't have to wait
many times for cachelines to be pulled in)
The results of this benchmark are improvements in consistency of performance
rather than performance itself. With this patch, the few outliers in duration
go away and we get more consistent performance in each guest.
benchmark 3:
- same 3 guests and CPU configuration as benchmark 1 and 2.
- two idle guests
- 1 guest running STREAM benchmark
This scenario also saw performance improvement with this patch. On Copy and
Scale workloads from STREAM, I got 5-6% improvement with this patch. For
Add and triad, it was around 10% (or more).
benchmark 4:
- same 3 guests as previous benchmarks
- two guests running sysbench --memory, distinctly different cache heavy
workload
- one guest running STREAM benchmark.
Similar improvements to benchmark 3.
benchmark 5:
- 1 guest, 8 VCPUs, Ubuntu 14.04
- Host configured with split core (SMT8, subcores-per-core=4)
- STREAM benchmark
In this benchmark, we see a 10-20% performance improvement across the board
of STREAM benchmark results with this patch.
Based on preliminary investigation and microbenchmarks
by Prerna Saxena [off-list ref]
Signed-off-by: Stewart Smith <redacted>
A lot nicer :)
quoted hunk
--
changes since v2:
- based on feedback from Alexander Graf:
- move save and restore of cache to separate functions
- move allocation of mpp_buffer to vcore creation
- get_free_pages() does actually allocate pages aligned to order
(Mel Gorman confirms)
- make SPR and logmpp parameters a bit less magic, especially around abort
changes since v1:
- s/mppe/mpp_buffer/
- add MPP_BUFFER_ORDER define.
---
arch/powerpc/include/asm/kvm_host.h | 2 +
arch/powerpc/include/asm/ppc-opcode.h | 17 +++++++
arch/powerpc/include/asm/reg.h | 1 +
arch/powerpc/kvm/book3s_hv.c | 89 +++++++++++++++++++++++++++++----
4 files changed, 98 insertions(+), 11 deletions(-)
@@ -275,6 +276,20 @@#define __PPC_EH(eh) 0#endif+/* POWER8 Micro Partition Prefetch (MPP) parameters */+/* Address mask is common for LOGMPP instruction and MPPR SPR */+#define PPC_MPPE_ADDRESS_MASK 0xffffffffc000++/* Bits 60 and 61 of MPP SPR should be set to one of the following */+/* Aborting the fetch is indeed setting 00 in the table size bits */+#define PPC_MPPR_FETCH_ABORT (0x0ULL << 60)+#define PPC_MPPR_FETCH_WHOLE_TABLE (0x2ULL << 60)++/* Bits 54 and 55 of register for LOGMPP instruction should be set to: */+#define PPC_LOGMPP_LOG_L2 (0x02ULL << 54)+#define PPC_LOGMPP_LOG_L2L3 (0x01ULL << 54)+#define PPC_LOGMPP_LOG_ABORT (0x03ULL << 54)+/* Deal with instructions that older assemblers aren't aware of */#define PPC_DCBAL(a, b) stringify_in_c(.long PPC_INST_DCBAL | \__PPC_RA(a)|__PPC_RB(b))
@@ -67,6 +67,13 @@/* Used as a "null" value for timebase values */#define TB_NIL (~(u64)0)+#if defined(CONFIG_PPC_64K_PAGES)+#define MPP_BUFFER_ORDER 0+#elif defined(CONFIG_PPC_4K_PAGES)+#define MPP_BUFFER_ORDER 4+#endif++staticvoidkvmppc_end_cede(structkvm_vcpu*vcpu);staticintkvmppc_hv_setup_htab_rma(structkvm_vcpu*vcpu);
Can you move this asm() into a static inline function in generic code
somewhere?
+
+ vc->mpp_buffer_is_valid = true;
Where does this ever get unset? And what point does this variable make?
Can't you just check on if (vc->mpp_buffer)?
Also, a single whitespace line between every instruction you do looks
weird ;). When you have the feeling that the code flow is weird enough
that you need empty lines between every real line, there's probably
something wrong in the code flow :).
Alex
quoted hunk
+}
+
+static void ppc_start_restoring_l2_cache(const struct kvmppc_vcore *vc)
+{
+ phys_addr_t phy_addr, tmp;
+
+ phy_addr = virt_to_phys((void *)vc->mpp_buffer);
+
+ tmp = phy_addr & PPC_MPPE_ADDRESS_MASK;
+
+ /* We must abort any in-progress save operations to ensure
+ * the table is valid so that prefetch engine knows when to
+ * stop prefetching. */
+ asm volatile(PPC_LOGMPP(R1) : : "r" (tmp | PPC_LOGMPP_LOG_ABORT));
+
+ mtspr(SPRN_MPPR, tmp | PPC_MPPR_FETCH_WHOLE_TABLE);
+}
+
/*
* Run a set of guest threads on a physical core.
* Called with vc->lock held.
@@ -1590,9 +1645,16 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) srcu_idx = srcu_read_lock(&vc->kvm->srcu);+ if (vc->mpp_buffer_is_valid)+ ppc_start_restoring_l2_cache(vc);+ __kvmppc_vcore_entry(); spin_lock(&vc->lock);++ if (vc->mpp_buffer)+ ppc_start_saving_l2_cache(vc);+ /* disable sending of IPIs on virtual external irqs */ list_for_each_entry(vcpu, &vc->runnable_threads, arch.run_list) vcpu->cpu = -1;
@@ -2329,8 +2391,13 @@ static void kvmppc_free_vcores(struct kvm *kvm) { long int i;- for (i = 0; i < KVM_MAX_VCORES; ++i)+ for (i = 0; i < KVM_MAX_VCORES; ++i) {+ if (kvm->arch.vcores[i] && kvm->arch.vcores[i]->mpp_buffer) {+ free_pages(kvm->arch.vcores[i]->mpp_buffer,+ MPP_BUFFER_ORDER);+ } kfree(kvm->arch.vcores[i]);+ } kvm->arch.online_vcores = 0; }
From: Paul Mackerras <hidden> Date: 2014-07-17 23:52:20
On Thu, Jul 17, 2014 at 01:19:57PM +1000, Stewart Smith wrote:
The POWER8 processor has a Micro Partition Prefetch Engine, which is
a fancy way of saying "has way to store and load contents of L2 or
L2+MRU way of L3 cache". We initiate the storing of the log (list of
addresses) using the logmpp instruction and start restore by writing
to a SPR.
The logmpp instruction takes parameters in a single 64bit register:
- starting address of the table to store log of L2/L2+L3 cache contents
- 32kb for L2
- 128kb for L2+L3
- Aligned relative to maximum size of the table (32kb or 128kb)
- Log control (no-op, L2 only, L2 and L3, abort logout)
We should abort any ongoing logging before initiating one.
Do we ever want to wait for ongoing logging to finish?
[snip]
Is there a particular reason why you need to pull this code out into a
separate function? If so, it would be a little nicer if you did that
in a separate patch, to make it easier to see that the code motion
changes nothing.
quoted hunk
@@ -1590,9 +1645,16 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) srcu_idx = srcu_read_lock(&vc->kvm->srcu);+ if (vc->mpp_buffer_is_valid)+ ppc_start_restoring_l2_cache(vc);+ __kvmppc_vcore_entry(); spin_lock(&vc->lock);++ if (vc->mpp_buffer)+ ppc_start_saving_l2_cache(vc);
I wonder if we would get better performance improvements if we kicked
this off earlier, for instance before we save all the FP/VSX state and
switch the MMU? I guess that could be a subsequent patch.
Paul.
From: Stewart Smith <hidden> Date: 2014-07-18 04:10:23
Paul Mackerras [off-list ref] writes:
On Thu, Jul 17, 2014 at 01:19:57PM +1000, Stewart Smith wrote:
quoted
The POWER8 processor has a Micro Partition Prefetch Engine, which is
a fancy way of saying "has way to store and load contents of L2 or
L2+MRU way of L3 cache". We initiate the storing of the log (list of
addresses) using the logmpp instruction and start restore by writing
to a SPR.
The logmpp instruction takes parameters in a single 64bit register:
- starting address of the table to store log of L2/L2+L3 cache contents
- 32kb for L2
- 128kb for L2+L3
- Aligned relative to maximum size of the table (32kb or 128kb)
- Log control (no-op, L2 only, L2 and L3, abort logout)
We should abort any ongoing logging before initiating one.
Do we ever want to wait for ongoing logging to finish?
*Probably* not... but as far as I can see the hardware doesn't expose a
way to find out if there is any ongoing logging or a way to be notified
when it's done.
Is there a particular reason why you need to pull this code out into a
separate function? If so, it would be a little nicer if you did that
in a separate patch, to make it easier to see that the code motion
changes nothing.
ack, done.
quoted
@@ -1590,9 +1645,16 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc) srcu_idx = srcu_read_lock(&vc->kvm->srcu);+ if (vc->mpp_buffer_is_valid)+ ppc_start_restoring_l2_cache(vc);+ __kvmppc_vcore_entry(); spin_lock(&vc->lock);++ if (vc->mpp_buffer)+ ppc_start_saving_l2_cache(vc);
I wonder if we would get better performance improvements if we kicked
this off earlier, for instance before we save all the FP/VSX state and
switch the MMU? I guess that could be a subsequent patch.
Possibly, yes. Maybe something to look at in future patch, along with if
also doing the L3 save/restore is a benefit.
get_free_pages returns an unsigned long and free_pages accepts an
unsigned long, so I was just avoiding the cast. Is the style in this
case to do void* rather than unsigned long and cast it everywhere?
In v4 of patch I've gone to void* anyway.
Can you move this asm() into a static inline function in generic code
somewhere?
okay. It seems the best place may be powerpc/include/asm/cache.h -
simply because it deals with cache things. I'm open to better
suggestions :)
quoted
+
+ vc->mpp_buffer_is_valid = true;
Where does this ever get unset? And what point does this variable make?
Can't you just check on if (vc->mpp_buffer)?
The problem with having moved the memory allocation for mpp_buffer to
vcore setup is that we'll have vc->mpp_buffer != NULL but have some
random contents in it, so when we first start executing the vcore, we
shouldn't initiate prefetching (hence mpp_buffer_is_valid).
If we point the prefetch engine to random memory contents, we get the
most amazing array of incomprehensible illegal accesses :)
The aborting of saving the L2 contents before starting the reading back
in makes the hardware ensure the content of that buffer is finished
correctly.
The hardware docs don't describe the exact format of what it puts in the
buffer, just that there's an 'end of table' bit set in the last entry.
Also, a single whitespace line between every instruction you do looks
weird ;). When you have the feeling that the code flow is weird enough
that you need empty lines between every real line, there's probably
something wrong in the code flow :).
ok, looks a bit better with logmpp as func rather than asm block.
From: Stewart Smith <hidden> Date: 2014-07-18 04:18:57
changes since v3:
- use kvmppc namespace
- MPP_BUFFER_ORDER of 3 not 4, as we only need 32k and it's already 32k aligned
- split out kvmppc_vcore_create in separate patch
- give a variable a better name: s/tmp/mpp_addr/
- logmpp becomes static inline function
Stewart Smith (2):
Split out struct kvmppc_vcore creation to separate function
Use the POWER8 Micro Partition Prefetch Engine in KVM HV on POWER8
arch/powerpc/include/asm/cache.h | 7 +++
arch/powerpc/include/asm/kvm_host.h | 2 +
arch/powerpc/include/asm/ppc-opcode.h | 17 +++++++
arch/powerpc/include/asm/reg.h | 1 +
arch/powerpc/kvm/book3s_hv.c | 88 ++++++++++++++++++++++++++++-----
5 files changed, 104 insertions(+), 11 deletions(-)
--
1.7.10.4
From: Stewart Smith <hidden> Date: 2014-07-18 04:18:57
The POWER8 processor has a Micro Partition Prefetch Engine, which is
a fancy way of saying "has way to store and load contents of L2 or
L2+MRU way of L3 cache". We initiate the storing of the log (list of
addresses) using the logmpp instruction and start restore by writing
to a SPR.
The logmpp instruction takes parameters in a single 64bit register:
- starting address of the table to store log of L2/L2+L3 cache contents
- 32kb for L2
- 128kb for L2+L3
- Aligned relative to maximum size of the table (32kb or 128kb)
- Log control (no-op, L2 only, L2 and L3, abort logout)
We should abort any ongoing logging before initiating one.
To initiate restore, we write to the MPPR SPR. The format of what to write
to the SPR is similar to the logmpp instruction parameter:
- starting address of the table to read from (same alignment requirements)
- table size (no data, until end of table)
- prefetch rate (from fastest possible to slower. about every 8, 16, 24 or
32 cycles)
The idea behind loading and storing the contents of L2/L3 cache is to
reduce memory latency in a system that is frequently swapping vcores on
a physical CPU.
The best case scenario for doing this is when some vcores are doing very
cache heavy workloads. The worst case is when they have about 0 cache hits,
so we just generate needless memory operations.
This implementation just does L2 store/load. In my benchmarks this proves
to be useful.
Benchmark 1:
- 16 core POWER8
- 3x Ubuntu 14.04LTS guests (LE) with 8 VCPUs each
- No split core/SMT
- two guests running sysbench memory test.
sysbench --test=memory --num-threads=8 run
- one guest running apache bench (of default HTML page)
ab -n 490000 -c 400 http://localhost/
This benchmark aims to measure performance of real world application (apache)
where other guests are cache hot with their own workloads. The sysbench memory
benchmark does pointer sized writes to a (small) memory buffer in a loop.
In this benchmark with this patch I can see an improvement both in requests
per second (~5%) and in mean and median response times (again, about 5%).
The spread of minimum and maximum response times were largely unchanged.
benchmark 2:
- Same VM config as benchmark 1
- all three guests running sysbench memory benchmark
This benchmark aims to see if there is a positive or negative affect to this
cache heavy benchmark. Although due to the nature of the benchmark (stores) we
may not see a difference in performance, but rather hopefully an improvement
in consistency of performance (when vcore switched in, don't have to wait
many times for cachelines to be pulled in)
The results of this benchmark are improvements in consistency of performance
rather than performance itself. With this patch, the few outliers in duration
go away and we get more consistent performance in each guest.
benchmark 3:
- same 3 guests and CPU configuration as benchmark 1 and 2.
- two idle guests
- 1 guest running STREAM benchmark
This scenario also saw performance improvement with this patch. On Copy and
Scale workloads from STREAM, I got 5-6% improvement with this patch. For
Add and triad, it was around 10% (or more).
benchmark 4:
- same 3 guests as previous benchmarks
- two guests running sysbench --memory, distinctly different cache heavy
workload
- one guest running STREAM benchmark.
Similar improvements to benchmark 3.
benchmark 5:
- 1 guest, 8 VCPUs, Ubuntu 14.04
- Host configured with split core (SMT8, subcores-per-core=4)
- STREAM benchmark
In this benchmark, we see a 10-20% performance improvement across the board
of STREAM benchmark results with this patch.
Based on preliminary investigation and microbenchmarks
by Prerna Saxena [off-list ref]
Signed-off-by: Stewart Smith <redacted>
--
changes since v3:
- use kvmppc namespace
- MPP_BUFFER_ORDER of 3 not 4, as we only need 32k and it's already 32k aligned
- split out kvmppc_vcore_create in separate patch
- give a variable a better name: s/tmp/mpp_addr/
- logmpp becomes static inline function
changes since v2:
- based on feedback from Alexander Graf:
- move save and restore of cache to separate functions
- move allocation of mpp_buffer to vcore creation
- get_free_pages() does actually allocate pages aligned to order
(Mel Gorman confirms)
- make SPR and logmpp parameters a bit less magic, especially around abort
changes since v1:
- s/mppe/mpp_buffer/
- add MPP_BUFFER_ORDER define.
---
arch/powerpc/include/asm/cache.h | 7 ++++
arch/powerpc/include/asm/kvm_host.h | 2 ++
arch/powerpc/include/asm/ppc-opcode.h | 17 ++++++++++
arch/powerpc/include/asm/reg.h | 1 +
arch/powerpc/kvm/book3s_hv.c | 57 ++++++++++++++++++++++++++++++++-
5 files changed, 83 insertions(+), 1 deletion(-)
@@ -275,6 +276,20 @@#define __PPC_EH(eh) 0#endif+/* POWER8 Micro Partition Prefetch (MPP) parameters */+/* Address mask is common for LOGMPP instruction and MPPR SPR */+#define PPC_MPPE_ADDRESS_MASK 0xffffffffc000++/* Bits 60 and 61 of MPP SPR should be set to one of the following */+/* Aborting the fetch is indeed setting 00 in the table size bits */+#define PPC_MPPR_FETCH_ABORT (0x0ULL << 60)+#define PPC_MPPR_FETCH_WHOLE_TABLE (0x2ULL << 60)++/* Bits 54 and 55 of register for LOGMPP instruction should be set to: */+#define PPC_LOGMPP_LOG_L2 (0x02ULL << 54)+#define PPC_LOGMPP_LOG_L2L3 (0x01ULL << 54)+#define PPC_LOGMPP_LOG_ABORT (0x03ULL << 54)+/* Deal with instructions that older assemblers aren't aware of */#define PPC_DCBAL(a, b) stringify_in_c(.long PPC_INST_DCBAL | \__PPC_RA(a)|__PPC_RB(b))
@@ -67,6 +68,13 @@/* Used as a "null" value for timebase values */#define TB_NIL (~(u64)0)+#if defined(CONFIG_PPC_64K_PAGES)+#define MPP_BUFFER_ORDER 0+#elif defined(CONFIG_PPC_4K_PAGES)+#define MPP_BUFFER_ORDER 3+#endif++staticvoidkvmppc_end_cede(structkvm_vcpu*vcpu);staticintkvmppc_hv_setup_htab_rma(structkvm_vcpu*vcpu);
@@ -1511,6 +1526,33 @@ static int on_primary_thread(void)return1;}+staticvoidkvmppc_start_saving_l2_cache(structkvmppc_vcore*vc)+{+phys_addr_tphy_addr,mpp_addr;++phy_addr=(phys_addr_t)virt_to_phys(vc->mpp_buffer);+mpp_addr=phy_addr&PPC_MPPE_ADDRESS_MASK;++mtspr(SPRN_MPPR,mpp_addr|PPC_MPPR_FETCH_ABORT);+logmpp(mpp_addr|PPC_LOGMPP_LOG_L2);++vc->mpp_buffer_is_valid=true;+}++staticvoidkvmppc_start_restoring_l2_cache(conststructkvmppc_vcore*vc)+{+phys_addr_tphy_addr,mpp_addr;++phy_addr=virt_to_phys(vc->mpp_buffer);+mpp_addr=phy_addr&PPC_MPPE_ADDRESS_MASK;++/* We must abort any in-progress save operations to ensure+*thetableisvalidsothatprefetchengineknowswhento+*stopprefetching.*/+logmpp(mpp_addr|PPC_LOGMPP_LOG_ABORT);+mtspr(SPRN_MPPR,mpp_addr|PPC_MPPR_FETCH_WHOLE_TABLE);+}+/**Runasetofguestthreadsonaphysicalcore.*Calledwithvc->lockheld.
@@ -1588,9 +1630,16 @@ static void kvmppc_run_core(struct kvmppc_vcore *vc)srcu_idx=srcu_read_lock(&vc->kvm->srcu);+if(vc->mpp_buffer_is_valid)+kvmppc_start_restoring_l2_cache(vc);+__kvmppc_vcore_entry();spin_lock(&vc->lock);++if(vc->mpp_buffer)+kvmppc_start_saving_l2_cache(vc);+/* disable sending of IPIs on virtual external irqs */list_for_each_entry(vcpu,&vc->runnable_threads,arch.run_list)vcpu->cpu=-1;
From: Stewart Smith <hidden> Date: 2014-07-18 04:18:58
No code changes, just split it out to a function so that with the addition
of micro partition prefetch buffer allocation (in subsequent patch) looks
neater and doesn't require excessive indentation.
Signed-off-by: Stewart Smith <redacted>
---
arch/powerpc/kvm/book3s_hv.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
From: Paul Mackerras <hidden> Date: 2014-07-18 07:48:12
On Fri, Jul 18, 2014 at 02:18:43PM +1000, Stewart Smith wrote:
The POWER8 processor has a Micro Partition Prefetch Engine, which is
a fancy way of saying "has way to store and load contents of L2 or
L2+MRU way of L3 cache". We initiate the storing of the log (list of
addresses) using the logmpp instruction and start restore by writing
to a SPR.
The logmpp instruction takes parameters in a single 64bit register:
- starting address of the table to store log of L2/L2+L3 cache contents
- 32kb for L2
- 128kb for L2+L3
- Aligned relative to maximum size of the table (32kb or 128kb)
- Log control (no-op, L2 only, L2 and L3, abort logout)
We should abort any ongoing logging before initiating one.
To initiate restore, we write to the MPPR SPR. The format of what to write
to the SPR is similar to the logmpp instruction parameter:
- starting address of the table to read from (same alignment requirements)
- table size (no data, until end of table)
- prefetch rate (from fastest possible to slower. about every 8, 16, 24 or
32 cycles)
The idea behind loading and storing the contents of L2/L3 cache is to
reduce memory latency in a system that is frequently swapping vcores on
a physical CPU.
The best case scenario for doing this is when some vcores are doing very
cache heavy workloads. The worst case is when they have about 0 cache hits,
so we just generate needless memory operations.
This implementation just does L2 store/load. In my benchmarks this proves
to be useful.
Benchmark 1:
- 16 core POWER8
- 3x Ubuntu 14.04LTS guests (LE) with 8 VCPUs each
- No split core/SMT
- two guests running sysbench memory test.
sysbench --test=memory --num-threads=8 run
- one guest running apache bench (of default HTML page)
ab -n 490000 -c 400 http://localhost/
This benchmark aims to measure performance of real world application (apache)
where other guests are cache hot with their own workloads. The sysbench memory
benchmark does pointer sized writes to a (small) memory buffer in a loop.
In this benchmark with this patch I can see an improvement both in requests
per second (~5%) and in mean and median response times (again, about 5%).
The spread of minimum and maximum response times were largely unchanged.
benchmark 2:
- Same VM config as benchmark 1
- all three guests running sysbench memory benchmark
This benchmark aims to see if there is a positive or negative affect to this
cache heavy benchmark. Although due to the nature of the benchmark (stores) we
may not see a difference in performance, but rather hopefully an improvement
in consistency of performance (when vcore switched in, don't have to wait
many times for cachelines to be pulled in)
The results of this benchmark are improvements in consistency of performance
rather than performance itself. With this patch, the few outliers in duration
go away and we get more consistent performance in each guest.
benchmark 3:
- same 3 guests and CPU configuration as benchmark 1 and 2.
- two idle guests
- 1 guest running STREAM benchmark
This scenario also saw performance improvement with this patch. On Copy and
Scale workloads from STREAM, I got 5-6% improvement with this patch. For
Add and triad, it was around 10% (or more).
benchmark 4:
- same 3 guests as previous benchmarks
- two guests running sysbench --memory, distinctly different cache heavy
workload
- one guest running STREAM benchmark.
Similar improvements to benchmark 3.
benchmark 5:
- 1 guest, 8 VCPUs, Ubuntu 14.04
- Host configured with split core (SMT8, subcores-per-core=4)
- STREAM benchmark
In this benchmark, we see a 10-20% performance improvement across the board
of STREAM benchmark results with this patch.
Based on preliminary investigation and microbenchmarks
by Prerna Saxena [off-list ref]
Signed-off-by: Stewart Smith <redacted>
From: Paul Mackerras <hidden> Date: 2014-07-18 07:48:12
On Fri, Jul 18, 2014 at 02:18:42PM +1000, Stewart Smith wrote:
No code changes, just split it out to a function so that with the addition
of micro partition prefetch buffer allocation (in subsequent patch) looks
neater and doesn't require excessive indentation.
Signed-off-by: Stewart Smith <redacted>
get_free_pages returns an unsigned long and free_pages accepts an
unsigned long, so I was just avoiding the cast. Is the style in this
case to do void* rather than unsigned long and cast it everywhere?
In v4 of patch I've gone to void* anyway.
It's probably just a matter of personal taste, but I personally prefer
to keep pointers to memory locations in pointers.
Can you move this asm() into a static inline function in generic code
somewhere?
okay. It seems the best place may be powerpc/include/asm/cache.h -
simply because it deals with cache things. I'm open to better
suggestions :)
quoted
quoted
+
+ vc->mpp_buffer_is_valid = true;
Where does this ever get unset? And what point does this variable make?
Can't you just check on if (vc->mpp_buffer)?
The problem with having moved the memory allocation for mpp_buffer to
vcore setup is that we'll have vc->mpp_buffer != NULL but have some
random contents in it, so when we first start executing the vcore, we
shouldn't initiate prefetching (hence mpp_buffer_is_valid).
If we point the prefetch engine to random memory contents, we get the
most amazing array of incomprehensible illegal accesses :)
I see :). That makes a lot of sense indeed. Maybe rename the variable to
mpp_content_is_valid to indicate that we are not looking at a valid
buffer, but valid content?
Alex
From: Alexander Graf <hidden> Date: 2014-07-28 12:34:41
On 18.07.14 06:18, Stewart Smith wrote:
changes since v3:
- use kvmppc namespace
- MPP_BUFFER_ORDER of 3 not 4, as we only need 32k and it's already 32k aligned
- split out kvmppc_vcore_create in separate patch
- give a variable a better name: s/tmp/mpp_addr/
- logmpp becomes static inline function
Stewart Smith (2):
Split out struct kvmppc_vcore creation to separate function
Use the POWER8 Micro Partition Prefetch Engine in KVM HV on POWER8
I only realized just now that I've commented on v3 :). Sorry. I guess
the name isn't really important enough for a respin. If you come up with
a really nice one, I'd be happy to apply another patch that renames it.
Thanks, applied all to kvm-ppc-queue.
Alex