Skip to content

Commit 1435f91

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 1435f91

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

ext/opcache/jit/zend_jit.c

+21
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ 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__)
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+
cache_line_base += 64;
157+
} while (start + size > cache_line_base);
158+
}
159+
# endif
160+
#endif
161+
147162
static int zend_jit_assign_to_variable(dasm_State **Dst,
148163
const zend_op *opline,
149164
zend_jit_addr var_use_addr,
@@ -973,6 +988,12 @@ static void *dasm_link_and_encode(dasm_State **dasm_state,
973988

974989
/* flush the hardware I-cache */
975990
JIT_CACHE_FLUSH(entry, entry + size);
991+
/* hint to the hardware to push out the cache line that contains the linear address */
992+
#if ZEND_JIT_TARGET_X86
993+
# if defined(__GNUC__)
994+
shared_cacheline_demote(entry, size);
995+
# endif
996+
#endif
976997

977998
if (trace_num) {
978999
zend_jit_trace_add_code(entry, dasm_getpclabel(dasm_state, 1));

0 commit comments

Comments
 (0)