Live migration optimization for Thunderx platform
v5 cover Live migration optimization for Thunderx platform
From: Vijaya Kumar K <[email protected]>
The CPU MIDR_EL1 register is exposed to userspace for arm64 with the below patch.
https://lkml.org/lkml/2016/7/8/467
Thunderx platform requires explicit prefetch instruction to provide prefetch hint. Using MIDR_EL1 information, provided by above kernel patch, prefetch is executed if the platform is Thunderx.
The results of live migration time improvement is provided in commit message of patch 3.
Note: Check for size of while prefetching beyond page is not added. Making this check is counter productive on performance of live migration.
v4 => v5:
- Compile util/aarch64-cpuid.c when CONFIG_LINUX enabled
- Added stubs include/qemu/aarch64-cpuid.h if __aarch64__ and CONFIG_LINUX are not enabled.
v3 => v4:
- Dropped allocation of memory for buf in
qemu_read_aarch64_midr_el1()
- Moved MIDR reg definitions to header file
- Dropped arm64 and thunder specific code from generic function.
v2 => v3:
- Rebased on top of richard's patches.
- Consider cache line size and line number to prefetch
- Passed optional parameters to __builtin_prefetch
v1 => v2:
- Rename util/cpuinfo.c as util/aarch64-cpuid.c
- Introduced header file include/qemu/aarch64-cpuid.h
- Place all arch specific code under define __aarch64__ and CONFIG_LINUX.
- Used builtin_prefetch() to add prefetch instruction.
- Moved arch specific changes out of generic code
- Dropped prefetching 5th cache line.
Vijaya Kumar K (3):
cutils: Set __builtin_prefetch optional parameters
utils: Add helper to read arm MIDR_EL1 register
utils: Add prefetch for Thunderx platform
include/qemu/aarch64-cpuid.h | 38 ++++++++++++++++++++++++++++++++ util/Makefile.objs | 1 + util/aarch64-cpuid.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ util/bufferiszero.c | 43 +++++++++++++++++++++++++++++++----- 4 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 include/qemu/aarch64-cpuid.h create mode 100644 util/aarch64-cpuid.c
Signature · 1 line
1.9.1
PATCH v5 1/3 cutils: Set __builtin_prefetch optional parameters
From: Vijaya Kumar K <[email protected]>
Optional parameters of __builtin_prefetch() which specifies rw and locality to 0's. For checking buffer is zero, set rw as read and temporal locality to 0.
On arm64, __builtin_prefetch(addr) generates 'prfm pldl1keep'
where __builtin_prefetch(addr, 0, 0) generates 'prfm pldl1strm' instruction which is optimal for this use case
--- util/bufferiszero.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
util/bufferiszero.c +5 -5
@@ -49,7 +49,7 @@ buffer_zero_int(const void *buf, size_t len)const uint64_t *e = (uint64_t *)(((uintptr_t )buf + len) &-8 );for (; p +8 <= e; p +=8 ) { -__builtin_prefetch (p +8 ); +__builtin_prefetch (p +8 ,0 ,0 );if (t) {return false; }
@@ -86,7 +86,7 @@ buffer_zero_sse2(const void *buf, size_t len)/* Loop over 16-byte aligned blocks of 64. */ while (likely (p <= e)) { -__builtin_prefetch (p); +__builtin_prefetch (p,0 ,0 ); t =_mm_cmpeq_epi8 (t, zero);if (unlikely (_mm_movemask_epi8 (t) !=0xFFFF )) {return false;
@@ -127,7 +127,7 @@ buffer_zero_sse4(const void *buf, size_t len)/* Loop over 16-byte aligned blocks of 64. */ while (likely (p <= e)) { -__builtin_prefetch (p); +__builtin_prefetch (p,0 ,0 );if (unlikely (!_mm_testz_si128 (t, t))) {return false; }
@@ -162,7 +162,7 @@ buffer_zero_avx2(const void *buf, size_t len)if (likely (p <= e)) {/* Loop over 32-byte aligned blocks of 128. */ do { - __builtin_prefetch(p); + __builtin_prefetch(p, 0, 0); if (unlikely(!_mm256_testz_si256(t, t))) { return false; }
@@ -303,7 +303,7 @@ bool buffer_is_zero(const void *buf, size_t len) }/* Fetch the beginning of the buffer while we select the accelerator. */ -__builtin_prefetch (buf); +__builtin_prefetch (buf,0 ,0 );/* Use an optimized zero check if possible. Note that this also includes a check for an unrolled loop over 64-bit integers. */
Signature · 1 line
1.9.1
PATCH v5 2/3 utils: Add helper to read arm MIDR_EL1 register
In reply to [email protected]From: Vijaya Kumar K <[email protected]>
Add helper API to read MIDR_EL1 registers to fetch cpu identification information. This helps in adding errata's and architecture specific features.
This is implemented only for arm architecture.
--- include/qemu/aarch64-cpuid.h | 38 ++++++++++++++++++++++++++++++++ util/Makefile.objs | 1 + util/aarch64-cpuid.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+)
include/qemu/aarch64-cpuid.h new file +38 -0
@@ -0,0 +1,38 @@ +#ifndef QEMU_AARCH64_CPUID_H +#define QEMU_AARCH64_CPUID_H + +#if defined(__aarch64__) && defined(CONFIG_LINUX ) +#define MIDR_IMPLEMENTER_SHIFT 24 +#define MIDR_IMPLEMENTER_MASK (0xffULL << MIDR_IMPLEMENTER_SHIFT) +#define MIDR_ARCHITECTURE_SHIFT 16 +#define MIDR_ARCHITECTURE_MASK (0xf << MIDR_ARCHITECTURE_SHIFT) +#define MIDR_PARTNUM_SHIFT 4 +#define MIDR_PARTNUM_MASK (0xfff << MIDR_PARTNUM_SHIFT) + +#define MIDR_CPU_PART (imp, partnum) \ + (((imp) << MIDR_IMPLEMENTER_SHIFT) | \ + (0xf << MIDR_ARCHITECTURE_SHIFT) | \ + ((partnum) << MIDR_PARTNUM_SHIFT)) + +#define ARM_CPU_IMP_CAVIUM 0x43 +#define CAVIUM_CPU_PART_THUNDERX 0x0A1 + +#define MIDR_THUNDERX_PASS2 \ + MIDR_CPU_PART(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX) +#define CPU_MODEL_MASK (MIDR_IMPLEMENTER_MASK | MIDR_ARCHITECTURE_MASK | \ + MIDR_PARTNUM_MASK) + +uint64_t get_aarch64_cpu_id (void ); +bool is_thunderx_pass2_cpu (void ); +#else +static inline uint64_t get_aarch64_cpu_id (void ) +{ +return 0 ; +} + +static inline bool is_thunderx_pass2_cpu (void ) +{ +return false; +} +#endif +#endif
util/Makefile.objs +1 -0
@@ -36,3 +36,4 @@ util-obj-y += log.o util-obj-y += qdist.o util-obj-y += qht.o util-obj-y += range.o +util-obj-$(CONFIG_LINUX) += aarch64-cpuid.o
util/aarch64-cpuid.c new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [Qemu-arm] [PATCH v5 2/3] utils: Add helper to read arm MIDR_EL1 register
Quoted 84 lines · On 7 December 2016 at 17:06, <[email protected]> wrote:
From: Vijaya Kumar K <[email protected]>
Add helper API to read
MIDR_EL1registers to fetch cpu identification information. This helps in adding errata's and architecture specific features.This is implemented only for arm architecture.
Signed-off-by Vijaya Kumar K <[email protected]>--- include/qemu/aarch64-cpuid.h | 38 ++++++++++++++++++++++++++++++++ util/Makefile.objs | 1 + util/aarch64-cpuid.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+)include/qemu/aarch64-cpuid.h new file +38
-0@@ -0,0 +1,38 @@ +#ifndef QEMU_AARCH64_CPUID_H +#define QEMU_AARCH64_CPUID_H + +#if defined(__aarch64__) && defined(CONFIG_LINUX ) +#define MIDR_IMPLEMENTER_SHIFT 24 +#define MIDR_IMPLEMENTER_MASK (0xffULL << MIDR_IMPLEMENTER_SHIFT) +#define MIDR_ARCHITECTURE_SHIFT 16 +#define MIDR_ARCHITECTURE_MASK (0xf << MIDR_ARCHITECTURE_SHIFT) +#define MIDR_PARTNUM_SHIFT 4 +#define MIDR_PARTNUM_MASK (0xfff << MIDR_PARTNUM_SHIFT) + +#define MIDR_CPU_PART (imp, partnum) \ + (((imp) << MIDR_IMPLEMENTER_SHIFT) | \ + (0xf << MIDR_ARCHITECTURE_SHIFT) | \ + ((partnum) << MIDR_PARTNUM_SHIFT)) + +#define ARM_CPU_IMP_CAVIUM 0x43 +#define CAVIUM_CPU_PART_THUNDERX 0x0A1 + +#define MIDR_THUNDERX_PASS2 \ + MIDR_CPU_PART(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX) +#define CPU_MODEL_MASK (MIDR_IMPLEMENTER_MASK | MIDR_ARCHITECTURE_MASK | \ + MIDR_PARTNUM_MASK) + +uint64_t get_aarch64_cpu_id (void ); +bool is_thunderx_pass2_cpu (void ); +#else +static inline uint64_t get_aarch64_cpu_id (void ) +{ +return 0 ; +} + +static inline bool is_thunderx_pass2_cpu (void ) +{ +return false; +} +#endif +#endif util/Makefile.objs +1
-0@@ -36,3 +36,4 @@ util-obj-y += log.o util-obj-y += qdist.o util-obj-y += qht.o util-obj-y += range.o +util-obj-$(CONFIG_LINUX) += aarch64-cpuid.outil/aarch64-cpuid.c new file +10
-0@@ -0,0 +1,52 @@ +/* +* Dealing with arm cpu identification information. +* +* Copyright (C) 2016 Cavium, Inc. +* +* Authors: +* Vijaya Kumar K <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 +* or later. See the COPYING.LIB file in the top-level directory.
util/aarch64-cpuid.c line 20
Quoted 10 lines
util/aarch64-cpuid.c new file +10
-0+*/ + +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "qemu/aarch64-cpuid.h" + +#if defined(__aarch64__) +static uint64_t qemu_read_aarch64_midr_el1 (void ) +{ +const char *file ="/sys/devices/system/cpu/cpu0/regs/identification/midr_el1" ;
If CPU0 happens to be offline (eg hot-unplugged) then this file won't exist, and we'll fail to identify any MIDR value.
The API as designed here also doesn't seem to consider the idea of big.LITTLE systems -- if there are multiple CPUs with different MIDRs, which one should we return here?
Quoted 6 lines
util/aarch64-cpuid.c new file +6
-0+char *buf; +uint64_t midr =0 ; + +if (!g_file_get_contents (file, &buf,0 ,NULL )) { + goto out; + }
util/aarch64-cpuid.c line 36
Quoted 10 lines
util/aarch64-cpuid.c new file +10
-0+ +if (qemu_strtoull (buf,NULL ,0 , &midr) <0 ) { + midr =0 ; + goto out; + } + +out: +g_free (buf); + +return midr;
thanks
-- PMM
Re: [Qemu-arm] [PATCH v5 2/3] utils: Add helper to read arm MIDR_EL1 register
Quoted 90 lines · Peter Maydell
Quoted 89 lines · On 7 December 2016 at 17:06, <[email protected]> wrote:
From: Vijaya Kumar K <[email protected]>
Add helper API to read
MIDR_EL1registers to fetch cpu identification information. This helps in adding errata's and architecture specific features.This is implemented only for arm architecture.
Signed-off-by Vijaya Kumar K <[email protected]>--- include/qemu/aarch64-cpuid.h | 38 ++++++++++++++++++++++++++++++++ util/Makefile.objs | 1 + util/aarch64-cpuid.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+)include/qemu/aarch64-cpuid.h new file +38
-0@@ -0,0 +1,38 @@ +#ifndef QEMU_AARCH64_CPUID_H +#define QEMU_AARCH64_CPUID_H + +#if defined(__aarch64__) && defined(CONFIG_LINUX ) +#define MIDR_IMPLEMENTER_SHIFT 24 +#define MIDR_IMPLEMENTER_MASK (0xffULL << MIDR_IMPLEMENTER_SHIFT) +#define MIDR_ARCHITECTURE_SHIFT 16 +#define MIDR_ARCHITECTURE_MASK (0xf << MIDR_ARCHITECTURE_SHIFT) +#define MIDR_PARTNUM_SHIFT 4 +#define MIDR_PARTNUM_MASK (0xfff << MIDR_PARTNUM_SHIFT) + +#define MIDR_CPU_PART (imp, partnum) \ + (((imp) << MIDR_IMPLEMENTER_SHIFT) | \ + (0xf << MIDR_ARCHITECTURE_SHIFT) | \ + ((partnum) << MIDR_PARTNUM_SHIFT)) + +#define ARM_CPU_IMP_CAVIUM 0x43 +#define CAVIUM_CPU_PART_THUNDERX 0x0A1 + +#define MIDR_THUNDERX_PASS2 \ + MIDR_CPU_PART(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX) +#define CPU_MODEL_MASK (MIDR_IMPLEMENTER_MASK | MIDR_ARCHITECTURE_MASK | \ + MIDR_PARTNUM_MASK) + +uint64_t get_aarch64_cpu_id (void ); +bool is_thunderx_pass2_cpu (void ); +#else +static inline uint64_t get_aarch64_cpu_id (void ) +{ +return 0 ; +} + +static inline bool is_thunderx_pass2_cpu (void ) +{ +return false; +} +#endif +#endif util/Makefile.objs +1
-0@@ -36,3 +36,4 @@ util-obj-y += log.o util-obj-y += qdist.o util-obj-y += qht.o util-obj-y += range.o +util-obj-$(CONFIG_LINUX) += aarch64-cpuid.outil/aarch64-cpuid.c new file +15
-0@@ -0,0 +1,52 @@ +/* +* Dealing with arm cpu identification information. +* +* Copyright (C) 2016 Cavium, Inc. +* +* Authors: +* Vijaya Kumar K <[email protected]> +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 +* or later. See the COPYING.LIB file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "qemu/aarch64-cpuid.h"
Quoted 8 lines
util/aarch64-cpuid.c line 20
Quoted 5 lines
util/aarch64-cpuid.c new file +5
-0+ +#if defined(__aarch64__) +static uint64_t qemu_read_aarch64_midr_el1 (void ) +{ +const char *file ="/sys/devices/system/cpu/cpu0/regs/identification/midr_el1" ;If CPU0 happens to be offline (eg hot-unplugged) then this file won't exist, and we'll fail to identify any MIDR value.
I thought wrongly that cpu0 cannot be hot-plugged on arm64. At-least on our platform, it is not allowed.
One solution I think of is to get current running cpu using sched_getcpu() and fetch midr from that cpu path
OR read /sys/devices/system/cpu/online and find online cpu.
Quoted 4 lines
The API as designed here also doesn't seem to consider the idea of big.LITTLE systems -- if there are multiple CPUs with different MIDRs, which one should we return here?
Yes, this is the limitation here to handle big.LITTLE configuration. It was discussed in initial version of this patch series.
https://lists.gnu.org/archive/html/qemu-devel/2016-05/msg01221.html
(From use case point of view, we require only Implementer ID, which
won't be different for big.LITTLE configuration. I agree that this generic function should work for other use cases as well).
So I will add a comment here.
Quoted 20 lines
Quoted 7 lines
util/aarch64-cpuid.c new file +6
-0+char *buf; +uint64_t midr =0 ; + +if (!g_file_get_contents (file, &buf,0 ,NULL )) { + goto out; + }util/aarch64-cpuid.c line 36
Quoted 10 lines
util/aarch64-cpuid.c new file +10
-0+ +if (qemu_strtoull (buf,NULL ,0 , &midr) <0 ) { + midr =0 ; + goto out; + } + +out: +g_free (buf); + +return midr;thanks
-- PMM
PATCH v5 3/3 utils: Add prefetch for Thunderx platform
In reply to [email protected]From: Vijaya Kumar K <[email protected]>
Thunderx pass2 chip requires explicit prefetch
instruction to give prefetch hint.
To speed up live migration on Thunderx platform, prefetch instruction is added in zero buffer check function.The below results show live migration time improvement with prefetch instruction. VM with 4 VCPUs, 8GB RAM is migrated.
Code for decoding cache size is taken from Richard's patch.
With 1K page size and without prefetch
======================================
Migration status: completed
total time: 13556 milliseconds
downtime: 380 milliseconds
setup: 15 milliseconds
transferred ram: 265557 kbytes
throughput: 160.51 mbps
remaining ram: 0 kbytes
total ram: 8519872 kbytes
duplicate: 8344672 pages
skipped: 0 pages
normal: 190724 pages
normal bytes: 190724 kbytes
dirty sync count: 3
With 1K page size and with prefetch
===================================
Migration status: completed
total time: 8218 milliseconds
downtime: 395 milliseconds
setup: 15 milliseconds
transferred ram: 274484 kbytes
throughput: 273.67 mbps
remaining ram: 0 kbytes
total ram: 8519872 kbytes
duplicate: 8341921 pages
skipped: 0 pages
normal: 199606 pages
normal bytes: 199606 kbytes
dirty sync count: 3
(qemu)
With 4K page size and without prefetch
======================================
Migration status: completed
total time: 11121 milliseconds
downtime: 372 milliseconds
setup: 5 milliseconds
transferred ram: 231777 kbytes
throughput: 170.77 mbps
remaining ram: 0 kbytes
total ram: 8519872 kbytes
duplicate: 2082158 pages
skipped: 0 pages
normal: 53265 pages
normal bytes: 213060 kbytes
dirty sync count: 3
With 4K page size and with prefetch
===================================
Migration status: completed
total time: 5893 milliseconds
downtime: 359 milliseconds
setup: 5 milliseconds
transferred ram: 225795 kbytes
throughput: 313.96 mbps
remaining ram: 0 kbytes
total ram: 8519872 kbytes
duplicate: 2081903 pages
skipped: 0 pages
normal: 51773 pages
normal bytes: 207092 kbytes
dirty sync count: 3
--- util/bufferiszero.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-)
util/bufferiszero.c +35 -2
@@ -25,6 +25,11 @@#include "qemu-common.h" #include "qemu/cutils.h" #include "qemu/bswap.h" +#include "qemu/aarch64-cpuid.h" + +static uint32_t cache_line_size =64 ; +static uint32_t prefetch_line_dist =1 ; +static uint32_t prefetch_distance =8 ;static bool buffer_zero_int (const void *buf,size_t len)
@@ -49,7 +54,7 @@ buffer_zero_int(const void *buf, size_t len)const uint64_t *e = (uint64_t *)(((uintptr_t )buf + len) &-8 );for (; p +8 <= e; p +=8 ) { -__builtin_prefetch (p +8 ,0 ,0 ); +__builtin_prefetch (p + prefetch_distance,0 ,0 );if (t) {return false; }
@@ -293,17 +298,45 @@ bool test_buffer_is_zero_next_accel(void) }#endif +static void __attribute__((constructor))init_cache_size (void ) +{ +#if defined(__aarch64__) +uint64_t t; + +/* Use the DZP block size as a proxy for the cacheline size, +since the later is not available to userspace. This seems +to work in practice for existing implementations. */ + asm("mrs %0, dczid_el0" :"=r" (t)); +if ((1 << ((t &0xf ) +2 )) >=128 ) { + cache_line_size =128 ; + } +#endif + +get_aarch64_cpu_id (); +if (is_thunderx_pass2_cpu ()) { + prefetch_line_dist =3 ; + prefetch_distance = (prefetch_line_dist * cache_line_size) / +sizeof (uint64_t ); + } +} +/* * Checks if a buffer is all zeroes */ bool buffer_is_zero (const void *buf,size_t len) { +int i; +uint32_t prefetch_distance_bytes; +if (unlikely (len ==0 )) {return true; }/* Fetch the beginning of the buffer while we select the accelerator. */ -__builtin_prefetch (buf,0 ,0 ); + prefetch_distance_bytes = prefetch_line_dist * cache_line_size; +for (i =0 ; i < prefetch_distance_bytes && i < len; i += cache_line_size) { +__builtin_prefetch (buf + i,0 ,0 ); + }/* Use an optimized zero check if possible. Note that this also includes a check for an unrolled loop over 64-bit integers. */
Signature · 1 line
1.9.1