1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_YIELD_PROCESSOR_H_ 6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_YIELD_PROCESSOR_H_ 7 8 #include "build/build_config.h" 9 10 // The YIELD_PROCESSOR macro wraps an architecture specific-instruction that 11 // informs the processor we're in a busy wait, so it can handle the branch more 12 // intelligently and e.g. reduce power to our core or give more resources to the 13 // other hyper-thread on this core. See the following for context: 14 // https://software.intel.com/en-us/articles/benefitting-power-and-performance-sleep-loops 15 16 #if defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_X86) 17 #define YIELD_PROCESSOR __asm__ __volatile__("pause") 18 #elif (defined(ARCH_CPU_ARMEL) && __ARM_ARCH >= 6) || defined(ARCH_CPU_ARM64) 19 #define YIELD_PROCESSOR __asm__ __volatile__("yield") 20 #elif defined(ARCH_CPU_MIPSEL) 21 // The MIPS32 docs state that the PAUSE instruction is a no-op on older 22 // architectures (first added in MIPS32r2). To avoid assembler errors when 23 // targeting pre-r2, we must encode the instruction manually. 24 #define YIELD_PROCESSOR __asm__ __volatile__(".word 0x00000140") 25 #elif defined(ARCH_CPU_MIPS64EL) && __mips_isa_rev >= 2 26 // Don't bother doing using .word here since r2 is the lowest supported mips64 27 // that Chromium supports. 28 #define YIELD_PROCESSOR __asm__ __volatile__("pause") 29 #elif defined(ARCH_CPU_PPC64_FAMILY) 30 #define YIELD_PROCESSOR __asm__ __volatile__("or 31,31,31") 31 #elif defined(ARCH_CPU_S390_FAMILY) 32 // just do nothing 33 #define YIELD_PROCESSOR ((void)0) 34 #endif // ARCH 35 36 #ifndef YIELD_PROCESSOR 37 #define YIELD_PROCESSOR ((void)0) 38 #endif 39 40 #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_YIELD_PROCESSOR_H_ 41