mirror of
https://github.com/python/cpython.git
synced 2025-07-10 04:45:36 +00:00
gh-116968: Reimplement Tier 2 counters (#117144)
Introduce a unified 16-bit backoff counter type (``_Py_BackoffCounter``), shared between the Tier 1 adaptive specializer and the Tier 2 optimizer. The API used for adaptive specialization counters is changed but the behavior is (supposed to be) identical. The behavior of the Tier 2 counters is changed: - There are no longer dynamic thresholds (we never varied these). - All counters now use the same exponential backoff. - The counter for ``JUMP_BACKWARD`` starts counting down from 16. - The ``temperature`` in side exits starts counting down from 64.
This commit is contained in:
parent
63bbe77d9b
commit
060a96f1a9
19 changed files with 313 additions and 235 deletions
|
@ -262,7 +262,7 @@ GETITEM(PyObject *v, Py_ssize_t i) {
|
|||
STAT_INC(opcode, miss); \
|
||||
STAT_INC((INSTNAME), miss); \
|
||||
/* The counter is always the first cache entry: */ \
|
||||
if (ADAPTIVE_COUNTER_IS_ZERO(next_instr->cache)) { \
|
||||
if (ADAPTIVE_COUNTER_TRIGGERS(next_instr->cache)) { \
|
||||
STAT_INC((INSTNAME), deopt); \
|
||||
} \
|
||||
} while (0)
|
||||
|
@ -290,29 +290,28 @@ GETITEM(PyObject *v, Py_ssize_t i) {
|
|||
dtrace_function_entry(frame); \
|
||||
}
|
||||
|
||||
#define ADAPTIVE_COUNTER_IS_ZERO(COUNTER) \
|
||||
(((COUNTER) >> ADAPTIVE_BACKOFF_BITS) == 0)
|
||||
|
||||
#define ADAPTIVE_COUNTER_IS_MAX(COUNTER) \
|
||||
(((COUNTER) >> ADAPTIVE_BACKOFF_BITS) == ((1 << MAX_BACKOFF_VALUE) - 1))
|
||||
/* This takes a uint16_t instead of a _Py_BackoffCounter,
|
||||
* because it is used directly on the cache entry in generated code,
|
||||
* which is always an integral type. */
|
||||
#define ADAPTIVE_COUNTER_TRIGGERS(COUNTER) \
|
||||
backoff_counter_triggers(forge_backoff_counter((COUNTER)))
|
||||
|
||||
#ifdef Py_GIL_DISABLED
|
||||
#define DECREMENT_ADAPTIVE_COUNTER(COUNTER) \
|
||||
do { \
|
||||
/* gh-115999 tracks progress on addressing this. */ \
|
||||
#define ADVANCE_ADAPTIVE_COUNTER(COUNTER) \
|
||||
do { \
|
||||
/* gh-115999 tracks progress on addressing this. */ \
|
||||
static_assert(0, "The specializing interpreter is not yet thread-safe"); \
|
||||
} while (0);
|
||||
#else
|
||||
#define DECREMENT_ADAPTIVE_COUNTER(COUNTER) \
|
||||
do { \
|
||||
assert(!ADAPTIVE_COUNTER_IS_ZERO((COUNTER))); \
|
||||
(COUNTER) -= (1 << ADAPTIVE_BACKOFF_BITS); \
|
||||
#define ADVANCE_ADAPTIVE_COUNTER(COUNTER) \
|
||||
do { \
|
||||
(COUNTER) = advance_backoff_counter((COUNTER)); \
|
||||
} while (0);
|
||||
#endif
|
||||
|
||||
#define INCREMENT_ADAPTIVE_COUNTER(COUNTER) \
|
||||
do { \
|
||||
(COUNTER) += (1 << ADAPTIVE_BACKOFF_BITS); \
|
||||
#define PAUSE_ADAPTIVE_COUNTER(COUNTER) \
|
||||
do { \
|
||||
(COUNTER) = pause_backoff_counter((COUNTER)); \
|
||||
} while (0);
|
||||
|
||||
#define UNBOUNDLOCAL_ERROR_MSG \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue