Skip to content

Commit

Permalink
Remove JIT type profiling infra
Browse files Browse the repository at this point in the history
Summary:
Doesn't feel great removing this but, we're not using it right now and `s_live_types` is causing problems with 3.12 and native tests. The issue there is 3.12 doesn't send type change events when types are deleted so references to types are in `s_live_types` are out living the types causing use-after-free errors when `s_live_types` is deallocated.

I've deleted all the references I could find but I've left some stubs in `cinder.py` from 3.10 just in case. Once we move to 3.12 these will no longer be present and we can deal with any fall out then.

Reviewed By: alexmalyshev

Differential Revision: D59877256

fbshipit-source-id: 7c76c649d8d8dce99eab8bd6744126db708d1a58
  • Loading branch information
jbower-fb authored and facebook-github-bot committed Jul 19, 2024
1 parent 0c8b47a commit 48359f2
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 67 deletions.
5 changes: 0 additions & 5 deletions Include/cinder/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@ CiAPI_DATA(int8_t) Ci_cinderx_initialized;
/* Hooks for JIT type profiling. */

typedef void(*Ci_TypeCallback)(PyTypeObject *type);
CiAPI_DATA(Ci_TypeCallback) Ci_hook_type_created;
CiAPI_DATA(Ci_TypeCallback) Ci_hook_type_destroyed;
CiAPI_DATA(Ci_TypeCallback) Ci_hook_type_name_modified;

typedef int (*Ci_HookType_JIT_GetProfileNewInterpThread)(void);
CiAPI_DATA(Ci_HookType_JIT_GetProfileNewInterpThread)
Ci_hook_JIT_GetProfileNewInterpThread;

/* Hooks for JIT Shadow frames*/

typedef PyFrameObject *(*Ci_HookType_JIT_GetFrame)(PyThreadState *tstate);
Expand Down
7 changes: 0 additions & 7 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,6 @@ struct _ts {
/* The current top of the shadow frame stack; analogous to the frame member
* up above. */
struct _PyShadowFrame *shadow_frame;

/* TODO(T123968561): Put remaining fields somewhere CinderX-specific. */

/* 0 or 1 to indicate if this thread has interpreter type profiling
* enabled. */
char profile_interp;

};

// Alias for backward compatibility with Python 3.8
Expand Down
7 changes: 0 additions & 7 deletions Include/internal/pycore_interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ struct _ceval_state {
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
struct _gil_runtime_state gil;
#endif

/* TODO(T123968561): Put remaining fields somewhere CinderX-specific. */

/* Global instruction counter used by interpreter type profiling. */
long profile_instr_counter;
/* Configurable period for interpreter type profiling. */
long profile_instr_period;
};

/* fs_codec.encoding is initialized to NULL.
Expand Down
3 changes: 1 addition & 2 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ _Py_ThreadCanHandlePendingCalls(void)
static inline int
_Py_ThreadStateHasTracing(PyThreadState* ts)
{
return ts->c_tracefunc != NULL || ts->c_profilefunc != NULL ||
ts->profile_interp;
return ts->c_tracefunc != NULL || ts->c_profilefunc != NULL;
}

/* Variable and macro for in-line access to current thread
Expand Down
8 changes: 0 additions & 8 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3469,9 +3469,6 @@ type_new_impl(type_new_ctx *ctx)
}

assert(_PyType_CheckConsistency(type));
if (Ci_hook_type_created) {
Ci_hook_type_created(type);
}
return (PyObject *)type;

error:
Expand Down Expand Up @@ -6909,11 +6906,6 @@ PyType_Ready(PyTypeObject *type)
/* All done -- set the ready flag */
type->tp_flags = (type->tp_flags & ~Py_TPFLAGS_READYING) | Py_TPFLAGS_READY;
assert(_PyType_CheckConsistency(type));
if (Ci_hook_type_created && !PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
/* type_new_impl() has more work to do on heap types; only tell the callback
* about static types right here. */
Ci_hook_type_created(type);
}
return 0;
}

Expand Down
4 changes: 0 additions & 4 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,6 @@ _PyEval_InitState(struct _ceval_state *ceval)
_gil_initialize(&ceval->gil);
#endif

// Added for Cinder
ceval->profile_instr_counter = 0;
ceval->profile_instr_period = 0;

return 0;
}

Expand Down
2 changes: 0 additions & 2 deletions Python/cinderhooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ int _PyShadow_PolymorphicCacheEnabled = 1;
int8_t Ci_cinderx_initialized = 0;

/* JIT type profiling. */
Ci_TypeCallback Ci_hook_type_created = NULL;
Ci_TypeCallback Ci_hook_type_destroyed = NULL;
Ci_TypeCallback Ci_hook_type_name_modified = NULL;
Ci_HookType_JIT_GetProfileNewInterpThread Ci_hook_JIT_GetProfileNewInterpThread = NULL;

/* Hooks for JIT Shadow frames*/
Ci_HookType_JIT_GetFrame Ci_hook_JIT_GetFrame = NULL;
Expand Down
32 changes: 0 additions & 32 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,6 @@ new_threadstate(PyInterpreterState *interp, int init)
interp->tstate_head = tstate;
HEAD_UNLOCK(runtime);

tstate->profile_interp = 0;
if (Ci_hook_JIT_GetProfileNewInterpThread != NULL && Ci_hook_JIT_GetProfileNewInterpThread()) {
Ci_ThreadState_SetProfileInterp(tstate, 1);
}

return tstate;
}

Expand Down Expand Up @@ -1333,33 +1328,6 @@ _PyThread_CurrentExceptions(void)
return result;
}

void Ci_ThreadState_SetProfileInterpAll(int enabled) {
PyThreadState *tstate;
_PyRuntimeState *runtime = &_PyRuntime;

HEAD_LOCK(runtime);
for (tstate = _PyThreadState_GET()->interp->tstate_head;
tstate != NULL;
tstate = tstate->next) {
Ci_ThreadState_SetProfileInterp(tstate, enabled);
}
HEAD_UNLOCK(runtime);
}

void
Ci_ThreadState_SetProfileInterp(PyThreadState *tstate, int enabled) {
if (!tstate->profile_interp == !enabled) {
return;
}
tstate->profile_interp = !!enabled;
tstate->cframe->use_tracing = _Py_ThreadStateHasTracing(tstate);
}

void
Ci_RuntimeState_SetProfileInterpPeriod(long period) {
PyThreadState_Get()->interp->ceval.profile_instr_period = period;
}

/* Python "auto thread state" API. */

/* Keep this as a static, as it is not reliable! It can only
Expand Down

0 comments on commit 48359f2

Please sign in to comment.