-
-
Notifications
You must be signed in to change notification settings - Fork 32k
GH-112354: Initial implementation of warm up on exits and trace-stitching #114142
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
Changes from 1 commit
1975b4c
9fb97f7
f9aa235
1288258
7c6267a
55c48e8
8b3c2e0
92a3b61
e3def48
87e544b
2172d68
4448793
c70f12f
d73fe0a
5c8f0bd
140486b
3362c93
63fe653
b0991a7
625bce2
e191fd7
941a14c
cfd3285
1025495
171dad7
e6ca3fe
308b2a7
518143e
9d8cab8
bf07dad
19b6b84
c959e8f
f393ba5
bd66b01
fe75484
3d0110c
de93130
77a6740
0a61d29
b3e306d
8f3aa33
7c84967
8ee6710
f37d7fc
1f8967d
8e4c601
4eb2cfc
ebe804f
c38d4e8
830eb4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2314,6 +2314,7 @@ dummy_func( | |
} | ||
|
||
inst(JUMP_BACKWARD, (unused/1 --)) { | ||
TIER_ONE_ONLY | ||
CHECK_EVAL_BREAKER(); | ||
assert(oparg <= INSTR_OFFSET()); | ||
JUMPBY(-oparg); | ||
|
@@ -4087,25 +4088,26 @@ dummy_func( | |
assert(current_executor->trace[0].opcode != _COLD_EXIT); | ||
_PyExitData *exit = ¤t_executor->exits[oparg]; | ||
exit->hotness++; | ||
assert(exit->executor->trace[0].opcode == _COLD_EXIT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you assert here that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the future, |
||
PyCodeObject *code = _PyFrame_GetCode(frame); | ||
_Py_CODEUNIT *target = _PyCode_CODE(code) + exit->target; | ||
if (exit->hotness < 0) { | ||
next_instr = exit->target + _PyCode_CODE(_PyFrame_GetCode(frame)); | ||
next_instr = target; | ||
Py_DECREF(current_executor); | ||
current_executor = NULL; | ||
DISPATCH(); | ||
} | ||
PyCodeObject *code = _PyFrame_GetCode(frame); | ||
_Py_CODEUNIT *target = _PyCode_CODE(code) + exit->target; | ||
_PyExecutorObject *executor; | ||
if (target->op.code == ENTER_EXECUTOR) { | ||
executor = code->co_executors->executors[target->op.arg]; | ||
Py_INCREF(executor); | ||
} else { | ||
int optimized = _PyOptimizer_Optimize(frame, target, stack_pointer, &executor); | ||
if (optimized <= 0) { | ||
exit->hotness = -10000; /* Choose a better number */ | ||
Py_DECREF(current_executor); | ||
current_executor = NULL; | ||
next_instr = target; | ||
exit->hotness = -10000; /* Choose a better number */ | ||
ERROR_IF(optimized < 0, error); | ||
DISPATCH(); | ||
} | ||
|
@@ -4119,7 +4121,6 @@ dummy_func( | |
op(_START_EXECUTOR, (executor/4 --)) { | ||
TIER_TWO_ONLY | ||
Py_DECREF(current_executor); | ||
Py_INCREF(executor); | ||
current_executor = (_PyExecutorObject*)executor; | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
#include "opcode.h" | ||
#include "pycore_interp.h" | ||
#include "pycore_bitutils.h" // _Py_popcount32() | ||
#include "pycore_object.h" // _PyObject_GC_UNTRACK() | ||
#include "pycore_opcode_metadata.h" // _PyOpcode_OpName[] | ||
#include "pycore_opcode_utils.h" // MAX_REAL_OPCODE | ||
#include "pycore_optimizer.h" // _Py_uop_analyze_and_optimize() | ||
|
@@ -230,8 +231,9 @@ static PyMethodDef executor_methods[] = { | |
|
||
static void | ||
uop_dealloc(_PyExecutorObject *self) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Nit/off-topic: I just realized that these functions would now be better off being named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or better, |
||
_PyObject_GC_UNTRACK(self); | ||
_Py_ExecutorClear(self); | ||
PyObject_Free(self); | ||
PyObject_GC_Del(self); | ||
} | ||
|
||
const char * | ||
|
@@ -282,15 +284,69 @@ PySequenceMethods uop_as_sequence = { | |
.sq_item = (ssizeargfunc)uop_item, | ||
}; | ||
|
||
static void | ||
unlink_executor(_PyExecutorObject *executor) | ||
{ | ||
if (!executor->vm_data.linked) { | ||
return; | ||
} | ||
_PyExecutorLinkListNode *links = &executor->vm_data.links; | ||
_PyExecutorObject *next = links->next; | ||
_PyExecutorObject *prev = links->previous; | ||
if (next != NULL) { | ||
next->vm_data.links.previous = prev; | ||
} | ||
if (prev != NULL) { | ||
prev->vm_data.links.next = next; | ||
} | ||
else { | ||
// prev == NULL implies that executor is the list head | ||
PyInterpreterState *interp = PyInterpreterState_Get(); | ||
assert(interp->executor_list_head == executor); | ||
interp->executor_list_head = next; | ||
} | ||
executor->vm_data.linked = false; | ||
} | ||
|
||
/* This must be called by executors during dealloc */ | ||
void | ||
_Py_ExecutorClear(_PyExecutorObject *executor) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you expect to be calling this from outside this file? There currently don't seem to be callers in other files. (Maybe there would be once we merge the JIT code?) |
||
{ | ||
executor->vm_data.valid = 0; | ||
unlink_executor(executor); | ||
for (uint32_t i = 0; i < executor->exit_count; i++) { | ||
Py_CLEAR(executor->exits[i].executor); | ||
} | ||
} | ||
|
||
static int | ||
executor_clear(PyObject *o) | ||
{ | ||
_Py_ExecutorClear((_PyExecutorObject *)o); | ||
return 0; | ||
} | ||
|
||
static int | ||
executor_traverse(PyObject *o, visitproc visit, void *arg) | ||
{ | ||
_PyExecutorObject *executor = (_PyExecutorObject *)o; | ||
for (uint32_t i = 0; i < executor->exit_count; i++) { | ||
Py_VISIT(executor->exits[i].executor); | ||
} | ||
return 0; | ||
} | ||
|
||
PyTypeObject _PyUOpExecutor_Type = { | ||
PyVarObject_HEAD_INIT(&PyType_Type, 0) | ||
.tp_name = "uop_executor", | ||
.tp_basicsize = offsetof(_PyExecutorObject, exits), | ||
.tp_itemsize = 1, | ||
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION, | ||
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_HAVE_GC, | ||
.tp_dealloc = (destructor)uop_dealloc, | ||
.tp_as_sequence = &uop_as_sequence, | ||
.tp_methods = executor_methods, | ||
.tp_traverse = executor_traverse, | ||
.tp_clear = executor_clear, | ||
}; | ||
|
||
/* TO DO -- Generate these tables */ | ||
|
@@ -316,6 +372,7 @@ BRANCH_TO_GUARD[4][2] = { | |
|
||
#define TRACE_STACK_SIZE 5 | ||
|
||
|
||
#define CONFIDENCE_RANGE 1000 | ||
#define CONFIDENCE_CUTOFF 333 | ||
|
||
|
@@ -751,7 +808,7 @@ static _PyExecutorObject * | |
allocate_executor(int exit_count, int length) | ||
{ | ||
int size = exit_count*sizeof(_PyExitData) + length*sizeof(_PyUOpInstruction); | ||
_PyExecutorObject *res = PyObject_NewVar(_PyExecutorObject, &_PyUOpExecutor_Type, size); | ||
_PyExecutorObject *res = PyObject_GC_NewVar(_PyExecutorObject, &_PyUOpExecutor_Type, size); | ||
if (res == NULL) { | ||
return NULL; | ||
} | ||
|
@@ -852,6 +909,7 @@ make_executor_from_uops(_PyUOpInstruction *buffer, _PyBloomFilter *dependencies) | |
} | ||
} | ||
#endif | ||
_PyObject_GC_TRACK(executor); | ||
return executor; | ||
} | ||
|
||
|
@@ -919,19 +977,22 @@ PyUnstable_Optimizer_NewUOpOptimizer(void) | |
|
||
static void | ||
counter_dealloc(_PyExecutorObject *self) { | ||
PyObject *opt = (PyObject *)self->trace[0].operand; | ||
/* The optimizer is the operand of the first uop. */ | ||
gvanrossum marked this conversation as resolved.
Show resolved
Hide resolved
markshannon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PyObject *opt = (PyObject *)self->trace[1].operand; | ||
Py_DECREF(opt); | ||
uop_dealloc(self); | ||
} | ||
|
||
PyTypeObject _PyCounterExecutor_Type = { | ||
markshannon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PyVarObject_HEAD_INIT(&PyType_Type, 0) | ||
.tp_name = "counting_executor", | ||
.tp_basicsize = offsetof(_PyExecutorObject, trace), | ||
.tp_itemsize = sizeof(_PyUOpInstruction), | ||
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION, | ||
.tp_basicsize = offsetof(_PyExecutorObject, exits), | ||
.tp_itemsize = 1, | ||
markshannon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_HAVE_GC, | ||
.tp_dealloc = (destructor)counter_dealloc, | ||
.tp_methods = executor_methods, | ||
.tp_traverse = executor_traverse, | ||
.tp_clear = executor_clear, | ||
}; | ||
|
||
static int | ||
|
@@ -1120,29 +1181,6 @@ link_executor(_PyExecutorObject *executor) | |
assert(interp->executor_list_head->vm_data.links.previous == NULL); | ||
} | ||
|
||
static void | ||
unlink_executor(_PyExecutorObject *executor) | ||
{ | ||
if (!executor->vm_data.linked) { | ||
return; | ||
} | ||
_PyExecutorLinkListNode *links = &executor->vm_data.links; | ||
_PyExecutorObject *next = links->next; | ||
_PyExecutorObject *prev = links->previous; | ||
if (next != NULL) { | ||
next->vm_data.links.previous = prev; | ||
} | ||
if (prev != NULL) { | ||
prev->vm_data.links.next = next; | ||
} | ||
else { | ||
// prev == NULL implies that executor is the list head | ||
PyInterpreterState *interp = PyInterpreterState_Get(); | ||
assert(interp->executor_list_head == executor); | ||
interp->executor_list_head = next; | ||
} | ||
executor->vm_data.linked = false; | ||
} | ||
|
||
/* This must be called by optimizers before using the executor */ | ||
void | ||
|
@@ -1155,16 +1193,6 @@ _Py_ExecutorInit(_PyExecutorObject *executor, _PyBloomFilter *dependency_set) | |
link_executor(executor); | ||
} | ||
|
||
/* This must be called by executors during dealloc */ | ||
void | ||
_Py_ExecutorClear(_PyExecutorObject *executor) | ||
{ | ||
unlink_executor(executor); | ||
for (uint32_t i = 0; i < executor->exit_count; i++) { | ||
Py_DECREF(executor->exits[i].executor); | ||
} | ||
} | ||
|
||
void | ||
_Py_Executor_DependsOn(_PyExecutorObject *executor, void *obj) | ||
{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.