8000 bpo-45527: Don't count cache hits, just misses. by markshannon · Pull Request #29092 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45527: Don't count cache hits, just misses. #29092

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 5 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Do not record cache hits.
  • Loading branch information
markshannon committed Oct 20, 2021
commit 8406bc7ab81f7d64a049ef83d836c9936c493186
17 changes: 10 additions & 7 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ saturating_zero(void)
return 255;
}


/* Starting value for saturating counter.
* Technically this should be 1, but that is likely to
* cause a bit of thrashing when we optimize then get an immediate miss.
Expand All @@ -275,22 +276,24 @@ saturating_zero(void)
static inline uint8_t
saturating_start(void)
{
return saturating_zero()<<3;
return 32;
}

static inline void
record_cache_hit(_PyAdaptiveEntry *entry) {
entry->counter = saturating_increment(entry->counter);
}
// static inline void
// record_cache_hit(_PyAdaptiveEntry *entry) {
// entry->counter = saturating_increment(entry->counter);
// }

#define record_cache_hit(e) ((void)0)

static inline void
record_cache_miss(_PyAdaptiveEntry *entry) {
entry->counter = saturating_decrement(entry->counter);
entry->counter--;
}

static inline int
too_many_cache_misses(_PyAdaptiveEntry *entry) {
return entry->counter == saturating_zero();
return entry->counter == 0;
}

#define ADAPTIVE_CACHE_BACKOFF 64
Expand Down
16 changes: 9 additions & 7 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1452,11 +1452,13 @@ eval_frame_handle_pending(PyThreadState *tstate)

#define UPDATE_PREV_INSTR_OPARG(instr, oparg) ((uint8_t*)(instr))[-1] = (oparg)

static inline void
record_hit_inline(_Py_CODEUNIT *next_instr, int oparg)
{
UPDATE_PREV_INSTR_OPARG(next_instr, saturating_increment(oparg));
}
// static inline void
// record_hit_inline(_Py_CODEUNIT *next_instr, int oparg)
// {
// UPDATE_PREV_INSTR_OPARG(next_instr, saturating_increment(oparg));
// }

#define record_hit_inline(n, o) ((void)0)

#define GLOBALS() frame->f_globals
#define BUILTINS() frame->f_builtins
Expand Down Expand Up @@ -5115,10 +5117,10 @@ opname ## _miss: \
opname ## _miss: \
{ \
STAT_INC(opname, miss); \
uint8_t oparg = saturating_decrement(_Py_OPARG(next_instr[-1])); \
uint8_t oparg = _Py_OPARG(next_instr[-1])-1; \
UPDATE_PREV_INSTR_OPARG(next_instr, oparg); \
assert(_Py_OPARG(next_instr[-1]) == oparg); \
if (oparg == saturating_zero()) /* too many cache misses */ { \
if (oparg == 0) /* too many cache misses */ { \
oparg = ADAPTIVE_CACHE_BACKOFF; \
next_instr[-1] = _Py_MAKECODEUNIT(opname ## _ADAPTIVE, oparg); \
STAT_INC(opname, deopt); \
Expand Down
0