yield_processor.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_YIELD_PROCESSOR_H_
  5. #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_YIELD_PROCESSOR_H_
  6. #include "build/build_config.h"
  7. // The PA_YIELD_PROCESSOR macro wraps an architecture specific-instruction that
  8. // informs the processor we're in a busy wait, so it can handle the branch more
  9. // intelligently and e.g. reduce power to our core or give more resources to the
  10. // other hyper-thread on this core. See the following for context:
  11. // https://software.intel.com/en-us/articles/benefitting-power-and-performance-sleep-loops
  12. #if BUILDFLAG(IS_NACL)
  13. // Inline assembly not allowed.
  14. #define PA_YIELD_PROCESSOR ((void)0)
  15. #else
  16. #if defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_X86)
  17. #define PA_YIELD_PROCESSOR __asm__ __volatile__("pause")
  18. #elif (defined(ARCH_CPU_ARMEL) && __ARM_ARCH >= 6) || defined(ARCH_CPU_ARM64)
  19. #define PA_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 PA_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 PA_YIELD_PROCESSOR __asm__ __volatile__("pause")
  29. #elif defined(ARCH_CPU_PPC64_FAMILY)
  30. #define PA_YIELD_PROCESSOR __asm__ __volatile__("or 31,31,31")
  31. #elif defined(ARCH_CPU_S390_FAMILY)
  32. // just do nothing
  33. #define PA_YIELD_PROCESSOR ((void)0)
  34. #endif // ARCH
  35. #ifndef PA_YIELD_PROCESSOR
  36. #define PA_YIELD_PROCESSOR ((void)0)
  37. #endif
  38. #endif // BUILDFLAG(IS_NACL)
  39. #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_YIELD_PROCESSOR_H_