From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Sat, 25 Oct 2025 23:56:37 +0000 (+0100) Subject: Change the backoffs to fix nqueens X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf1753940c927faa99be64fe6a89920bfd5ca670;p=thirdparty%2FPython%2Fcpython.git Change the backoffs to fix nqueens --- diff --git a/Include/internal/pycore_backoff.h b/Include/internal/pycore_backoff.h index f92dfd278a1e..86ae7885fd1c 100644 --- a/Include/internal/pycore_backoff.h +++ b/Include/internal/pycore_backoff.h @@ -99,8 +99,13 @@ backoff_counter_triggers(_Py_BackoffCounter counter) // Must be larger than ADAPTIVE_COOLDOWN_VALUE, otherwise when JIT code is // invalidated we may construct a new trace before the bytecode has properly // re-specialized: -#define JUMP_BACKWARD_INITIAL_VALUE 4095 -#define JUMP_BACKWARD_INITIAL_BACKOFF 12 +// Note: this should be a prime number-1. This increases the likelihood of +// finding a "good" loop iteration to trace. +// For example, 4095 does not work for the nqueens benchmark on pyperformanc +// as we always end up tracing the loop iteration's +// exhaustion iteration. Which aborts our current tracer. +#define JUMP_BACKWARD_INITIAL_VALUE 4000 +#define JUMP_BACKWARD_INITIAL_BACKOFF 14 static inline _Py_BackoffCounter initial_jump_backoff_counter(void) { @@ -112,7 +117,7 @@ initial_jump_backoff_counter(void) * Must be larger than ADAPTIVE_COOLDOWN_VALUE, * otherwise when a side exit warms up we may construct * a new trace before the Tier 1 code has properly re-specialized. */ -#define SIDE_EXIT_INITIAL_VALUE 4095 +#define SIDE_EXIT_INITIAL_VALUE 4000 #define SIDE_EXIT_INITIAL_BACKOFF 12 static inline _Py_BackoffCounter diff --git a/Python/optimizer.c b/Python/optimizer.c index d39156a41afd..995ddee86058 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -628,16 +628,19 @@ _PyJit_translate_single_bytecode_to_trace( // Strange control-flow, unsupported opcode, etc. if (tstate->interp->jit_state.dynamic_jump_taken) { + DPRINTF(2, "Unsupported: dynamic jump taken\n"); goto unsupported; } // This happens when a recursive call happens that we can't trace. Such as Python -> C -> Python calls // If we haven't guarded the IP, then it's untraceable. if (frame != tstate->interp->jit_state.prev_instr_frame && !needs_guard_ip) { + DPRINTF(2, "Unsupported: unguardable jump taken\n"); goto unsupported; } if (oparg > 0xFFFF) { + DPRINTF(2, "Unsupported: oparg too large\n"); goto unsupported; } @@ -647,10 +650,12 @@ _PyJit_translate_single_bytecode_to_trace( } if (opcode == WITH_EXCEPT_START || opcode == RERAISE || opcode == CLEANUP_THROW || opcode == PUSH_EXC_INFO) { + DPRINTF(2, "Unsupported: strange control-flow\n"); goto unsupported; } if (frame->owner >= FRAME_OWNED_BY_INTERPRETER) { + DPRINTF(2, "Unsupported: frame owned by interpreter\n"); unsupported: { // Rewind to previous instruction and replace with _EXIT_TRACE.