8000 bpo-44338: Port LOAD_GLOBAL to PEP 659 adaptive interpreter by markshannon · Pull Request #26638 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44338: Port LOAD_GLOBAL to PEP 659 adaptive interpreter #26638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 14, 2021
Merged
Prev Previous commit
Next Next commit
Add more stats.
  • Loading branch information
markshannon committed Jun 10, 2021
commit b970dfc98accb760c13ef48095c7f5348f834e7b
10 changes: 8 additions & 2 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,18 @@ int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNI
#if SPECIALIZATION_STATS

typedef struct _specialization_stats {
uint64_t specialization_success;
uint64_t specialization_failure;
uint64_t loadattr_specialization_success;
uint64_t loadattr_specialization_failure;
uint64_t loadattr_hit;
uint64_t loadattr_deferred;
uint64_t loadattr_miss;
uint64_t loadattr_deopt;
uint64_t loadglobal_specialization_success;
uint64_t loadglobal_specialization_failure;
uint64_t loadglobal_hit;
uint64_t loadglobal_deferred;
uint64_t loadglobal_miss;
uint64_t loadglobal_deopt;
} SpecializationStats;

extern SpecializationStats _specialization_stats;
Expand Down
5 changes: 5 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -3033,6 +3033,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
DISPATCH();
}
else {
STAT_INC(loadglobal_deferred);
cache->adaptive.counter--;
oparg = cache->adaptive.original_oparg;
JUMP_TO_INSTRUCTION(LOAD_GLOBAL);
Expand All @@ -3050,6 +3051,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
PyObject *res = ep->me_value;
DEOPT_IF(res == NULL, LOAD_ATTR);
record_cache_hit(cache0);
STAT_INC(loadglobal_hit);
Py_INCREF(res);
PUSH(res);
DISPATCH();
Expand All @@ -3069,6 +3071,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
PyObject *res = ep->me_value;
DEOPT_IF(res == NULL, LOAD_ATTR);
record_cache_hit(cache0);
STAT_INC(loadglobal_hit);
Py_INCREF(res);
PUSH(res);
DISPATCH();
Expand Down Expand Up @@ -4478,9 +4481,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)

LOAD_GLOBAL_miss:
{
STAT_INC(loadglobal_miss);
_PyAdaptiveEntry *cache = &GET_CACHE()->adaptive;
record_cache_miss(cache);
if (too_many_cache_misses(cache)) {
STAT_INC(loadglobal_deopt);
next_instr[-1] = _Py_MAKECODEUNIT(LOAD_GLOBAL_ADAPTIVE, _Py_OPARG(next_instr[-1]));
cache_backoff(cache);
}
Expand Down
16 changes: 12 additions & 4 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ SpecializationStats _specialization_stats = { 0 };
void
_Py_PrintSpecializationStats(void)
{
PRINT_STAT(specialization_success);
PRINT_STAT(specialization_failure);
PRINT_STAT(loadattr_specialization_success);
PRINT_STAT(loadattr_specialization_failure);
PRINT_STAT(loadattr_hit);
PRINT_STAT(loadattr_deferred);
PRINT_STAT(loadattr_miss);
PRINT_STAT(loadattr_deopt);
PRINT_STAT(loadglobal_specialization_success);
PRINT_STAT(loadglobal_specialization_failure);
PRINT_STAT(loadglobal_hit);
PRINT_STAT(loadglobal_deferred);
PRINT_STAT(loadglobal_miss);
PRINT_STAT(loadglobal_deopt);
}

#endif
Expand Down Expand Up @@ -359,12 +365,12 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, Sp
}

fail:
STAT_INC(specialization_failure);
STAT_INC(loadattr_specialization_failure);
assert(!PyErr_Occurred());
cache_backoff(cache0);
return 0;
success:
STAT_INC(specialization_success);
STAT_INC(loadattr_specialization_success);
assert(!PyErr_Occurred());
cache0->counter = saturating_start();
return 0;
Expand Down Expand Up @@ -427,10 +433,12 @@ _Py_Specialize_LoadGlobal(
*instr = _Py_MAKECODEUNIT(LOAD_GLOBAL_BUILTIN, _Py_OPARG(*instr));
goto success;
fail:
STAT_INC(loadglobal_specialization_failure);
assert(!PyErr_Occurred());
cache_backoff(cache0);
return 0;
success:
STAT_INC(loadglobal_specialization_success);
assert(!PyErr_Occurred());
cache0->counter = saturating_start();
return 0;
Expand Down
0