Skip to content

Commit 00c6d3d

Browse files
author
wxue1
committed
Cacheline demote to improve performance
Once code is emitted to JIT buffer, hint the hardware to demote the corresponding cache lines to more distant level so other CPUs can access them more quickly. This gets nearly 1% performance gain on our workload. Signed-off-by: Xue,Wang <[email protected]> Signed-off-by: Tao,Su <[email protected]> Signed-off-by: Hu,chen <[email protected]>
1 parent 360e6f8 commit 00c6d3d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,22 @@ static zend_jit_trace_info *zend_jit_get_current_trace_info(void);
144144
static uint32_t zend_jit_trace_find_exit_point(const void* addr);
145145
#endif
146146

147+
#if ZEND_JIT_TARGET_X86
148+
# if defined(__GNUC__) && defined(__linux__)
149+
#include <immintrin.h>
150+
#pragma GCC target("cldemote")
151+
static inline void shared_cacheline_demote(void *start, size_t size) {
152+
void *cache_line_base;
153+
cache_line_base = (void *)(((uintptr_t)start) & ~0x3F);
154+
do {
155+
_cldemote(cache_line_base);
156+
// next cacheline start address, 64 is the cacheline size
157+
cache_line_base += 64;
158+
} while (cache_line_base < start + size);
159+
}
160+
# endif
161+
#endif
162+
147163
static int zend_jit_assign_to_variable(dasm_State **Dst,
148164
const zend_op *opline,
149165
zend_jit_addr var_use_addr,
@@ -973,6 +989,14 @@ static void *dasm_link_and_encode(dasm_State **dasm_state,
973989

974990
/* flush the hardware I-cache */
975991
JIT_CACHE_FLUSH(entry, entry + size);
992+
/* hint to the hardware to push out the cache line that contains the linear address */
993+
#if ZEND_JIT_TARGET_X86
994+
# if defined(__GNUC__) && defined(__linux__)
995+
if (JIT_G(trigger) == ZEND_JIT_ON_HOT_TRACE) {
996+
shared_cacheline_demote(entry, size);
997+
}
998+
# endif
999+
#endif
9761000

9771001
if (trace_num) {
9781002
zend_jit_trace_add_code(entry, dasm_getpclabel(dasm_state, 1));

0 commit comments

Comments
 (0)