Skip to content

Commit 401b6da

Browse files
Revert make_backoff_counter
1 parent ec27072 commit 401b6da

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

Include/internal/pycore_backoff.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@ extern "C" {
3535
#define BACKOFF_MASK 7
3636
#define MAX_BACKOFF 6
3737
#define UNREACHABLE_BACKOFF 7
38+
#define MAX_VALUE 0x1FFF
3839

3940
#define MAKE_VALUE_AND_BACKOFF(value, backoff) \
4041
((value << BACKOFF_BITS) | backoff)
4142

42-
#define MAKE_BACKOFF_COUNTER(value, backoff) \
43-
((_Py_BackoffCounter){ \
44-
.value_and_backoff = MAKE_VALUE_AND_BACKOFF(value, backoff) \
45-
})
46-
4743
// We only use values x and backoffs b such that
4844
// x + 1 is near to 2**(2*b+1) and x + 1 is prime.
4945
static uint16_t value_and_backoff_next[] = {
@@ -58,6 +54,16 @@ static uint16_t value_and_backoff_next[] = {
5854
MAKE_VALUE_AND_BACKOFF(8190, 6),
5955
};
6056

57+
static inline _Py_BackoffCounter
58+
make_backoff_counter(uint16_t value, uint16_t backoff)
59+
{
60+
assert(backoff <= UNREACHABLE_BACKOFF);
61+
assert(value <= MAX_VALUE);
62+
return ((_Py_BackoffCounter){
63+
.value_and_backoff = MAKE_VALUE_AND_BACKOFF(value, backoff)
64+
});
65+
}
66+
6167
static inline _Py_BackoffCounter
6268
restart_backoff_counter(_Py_BackoffCounter counter)
6369
{
@@ -113,7 +119,7 @@ trigger_backoff_counter(void)
113119
static inline _Py_BackoffCounter
114120
initial_jump_backoff_counter(void)
115121
{
116-
return MAKE_BACKOFF_COUNTER(JUMP_BACKWARD_INITIAL_VALUE,
122+
return make_backoff_counter(JUMP_BACKWARD_INITIAL_VALUE,
117123
JUMP_BACKWARD_INITIAL_BACKOFF);
118124
}
119125

@@ -127,15 +133,15 @@ initial_jump_backoff_counter(void)
127133
static inline _Py_BackoffCounter
128134
initial_temperature_backoff_counter(void)
129135
{
130-
return MAKE_BACKOFF_COUNTER(SIDE_EXIT_INITIAL_VALUE,
136+
return make_backoff_counter(SIDE_EXIT_INITIAL_VALUE,
131137
SIDE_EXIT_INITIAL_BACKOFF);
132138
}
133139

134140
/* Unreachable backoff counter. */
135141
static inline _Py_BackoffCounter
136142
initial_unreachable_backoff_counter(void)
137143
{
138-
return MAKE_BACKOFF_COUNTER(0, UNREACHABLE_BACKOFF);
144+
return make_backoff_counter(0, UNREACHABLE_BACKOFF);
139145
}
140146

141147
#ifdef __cplusplus

Include/internal/pycore_code.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,13 @@ write_location_entry_start(uint8_t *ptr, int code, int length)
468468

469469
static inline _Py_BackoffCounter
470470
adaptive_counter_warmup(void) {
471-
return MAKE_BACKOFF_COUNTER(ADAPTIVE_WARMUP_VALUE,
471+
return make_backoff_counter(ADAPTIVE_WARMUP_VALUE,
472472
ADAPTIVE_WARMUP_BACKOFF);
473473
}
474474

475475
static inline _Py_BackoffCounter
476476
adaptive_counter_cooldown(void) {
477-
return MAKE_BACKOFF_COUNTER(ADAPTIVE_COOLDOWN_VALUE,
477+
return make_backoff_counter(ADAPTIVE_COOLDOWN_VALUE,
478478
ADAPTIVE_COOLDOWN_BACKOFF);
479479
}
480480

Python/ceval_macros.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ GETITEM(PyObject *v, Py_ssize_t i) {
315315
* which is always an integral type. */
316316
// Force re-specialization when tracing a side exit to get good side exits.
317317
#define ADAPTIVE_COUNTER_TRIGGERS(COUNTER) \
318-
backoff_counter_triggers(MAKE_BACKOFF_COUNTER(0, (COUNTER)))
318+
backoff_counter_triggers(make_backoff_counter(0, (COUNTER)))
319319

320320
#define ADVANCE_ADAPTIVE_COUNTER(COUNTER) \
321321
do { \

0 commit comments

Comments
 (0)