Skip to content

Commit bf17539

Browse files
Change the backoffs to fix nqueens
1 parent 1e132f0 commit bf17539

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Include/internal/pycore_backoff.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,13 @@ backoff_counter_triggers(_Py_BackoffCounter counter)
9999
// Must be larger than ADAPTIVE_COOLDOWN_VALUE, otherwise when JIT code is
100100
// invalidated we may construct a new trace before the bytecode has properly
101101
// re-specialized:
102-
#define JUMP_BACKWARD_INITIAL_VALUE 4095
103-
#define JUMP_BACKWARD_INITIAL_BACKOFF 12
102+
// Note: this should be a prime number-1. This increases the likelihood of
103+
// finding a "good" loop iteration to trace.
104+
// For example, 4095 does not work for the nqueens benchmark on pyperformanc
105+
// as we always end up tracing the loop iteration's
106+
// exhaustion iteration. Which aborts our current tracer.
107+
#define JUMP_BACKWARD_INITIAL_VALUE 4000
108+
#define JUMP_BACKWARD_INITIAL_BACKOFF 14
104109
static inline _Py_BackoffCounter
105110
initial_jump_backoff_counter(void)
106111
{
@@ -112,7 +117,7 @@ initial_jump_backoff_counter(void)
112117
* Must be larger than ADAPTIVE_COOLDOWN_VALUE,
113118
* otherwise when a side exit warms up we may construct
114119
* a new trace before the Tier 1 code has properly re-specialized. */
115-
#define SIDE_EXIT_INITIAL_VALUE 4095
120+
#define SIDE_EXIT_INITIAL_VALUE 4000
116121
#define SIDE_EXIT_INITIAL_BACKOFF 12
117122

118123
static inline _Py_BackoffCounter

Python/optimizer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,16 +628,19 @@ _PyJit_translate_single_bytecode_to_trace(
628628

629629
// Strange control-flow, unsupported opcode, etc.
630630
if (tstate->interp->jit_state.dynamic_jump_taken) {
631+
DPRINTF(2, "Unsupported: dynamic jump taken\n");
631632
goto unsupported;
632633
}
633634

634635
// This happens when a recursive call happens that we can't trace. Such as Python -> C -> Python calls
635636
// If we haven't guarded the IP, then it's untraceable.
636637
if (frame != tstate->interp->jit_state.prev_instr_frame && !needs_guard_ip) {
638+
DPRINTF(2, "Unsupported: unguardable jump taken\n");
637639
goto unsupported;
638640
}
639641

640642
if (oparg > 0xFFFF) {
643+
DPRINTF(2, "Unsupported: oparg too large\n");
641644
goto unsupported;
642645
}
643646

@@ -647,10 +650,12 @@ _PyJit_translate_single_bytecode_to_trace(
647650
}
648651

649652
if (opcode == WITH_EXCEPT_START || opcode == RERAISE || opcode == CLEANUP_THROW || opcode == PUSH_EXC_INFO) {
653+
DPRINTF(2, "Unsupported: strange control-flow\n");
650654
goto unsupported;
651655
}
652656

653657
if (frame->owner >= FRAME_OWNED_BY_INTERPRETER) {
658+
DPRINTF(2, "Unsupported: frame owned by interpreter\n");
654659
unsupported:
655660
{
656661
// Rewind to previous instruction and replace with _EXIT_TRACE.

0 commit comments

Comments
 (0)