v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
yield-processor.h
Go to the documentation of this file.
1
// Copyright 2021 the V8 project 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 V8_BASE_PLATFORM_YIELD_PROCESSOR_H_
6
#define V8_BASE_PLATFORM_YIELD_PROCESSOR_H_
7
8
// The YIELD_PROCESSOR macro wraps an architecture specific-instruction that
9
// informs the processor we're in a busy wait, so it can handle the branch more
10
// intelligently and e.g. reduce power to our core or give more resources to the
11
// other hyper-thread on this core. See the following for context:
12
// https://software.intel.com/en-us/articles/benefitting-power-and-performance-sleep-loops
13
14
#if defined(THREAD_SANITIZER)
15
#include "
src/base/platform/platform.h
"
16
// TSAN intercepts atomic accesses and uses locking. Since YIELD_PROCESSOR is
17
// used in spinlock loops in conjunction with atomic accesses, such spinlock
18
// loops can exhibit starvation in TSAN. To work around the problem, have
19
// YIELD_PROCESSOR sleep the process for 1ms.
20
#define YIELD_PROCESSOR base::OS::Sleep(base::TimeDelta::FromMilliseconds(1))
21
22
#else
// !THREAD_SANITIZER
23
24
#if defined(V8_CC_MSVC)
25
// MSVC does not support inline assembly via __asm__ and provides compiler
26
// intrinsics instead. Check if there is a usable intrinsic.
27
//
28
// intrin.h is an expensive header, so only include it if we're on a host
29
// architecture that has a usable intrinsic.
30
#if defined(V8_HOST_ARCH_IA32) || defined(V8_HOST_ARCH_X64)
31
#include <intrin.h>
32
#define YIELD_PROCESSOR _mm_pause()
33
#elif defined(V8_HOST_ARCH_ARM64) || \
34
(defined(V8_HOST_ARCH_ARM) && __ARM_ARCH >= 6)
35
#include <intrin.h>
36
#define YIELD_PROCESSOR __yield()
37
#endif
// V8_HOST_ARCH
38
39
#else
// !V8_CC_MSVC
40
41
#if defined(V8_HOST_ARCH_IA32) || defined(V8_HOST_ARCH_X64)
42
#define YIELD_PROCESSOR __asm__ __volatile__("pause")
43
#elif defined(V8_HOST_ARCH_ARM64) || \
44
(defined(V8_HOST_ARCH_ARM) && __ARM_ARCH >= 6)
45
#define YIELD_PROCESSOR __asm__ __volatile__("yield")
46
#elif defined(V8_HOST_ARCH_MIPS64EL) && __mips_isa_rev >= 2
47
// Don't bother doing using .word here since r2 is the lowest supported mips64
48
// that Chromium supports.
49
#define YIELD_PROCESSOR __asm__ __volatile__("pause")
50
#elif defined(V8_HOST_ARCH_PPC64)
51
#define YIELD_PROCESSOR __asm__ __volatile__("or 31,31,31")
52
#endif
// V8_HOST_ARCH
53
54
#endif
// V8_CC_MSVC
55
56
#endif
// THREAD_SANITIZER
57
58
#ifndef YIELD_PROCESSOR
59
#define YIELD_PROCESSOR ((void)0)
60
#endif
61
62
#endif
// V8_BASE_PLATFORM_YIELD_PROCESSOR_H_
platform.h
src
base
platform
yield-processor.h
Generated on Sun Apr 6 2025 21:08:50 for v8 by
1.12.0