Skip to content

Commit

Permalink
revert benchmark stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
neonene committed Aug 20, 2024
1 parent 6e62c38 commit 89754d7
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static inline PyThreadState*
_PyThreadState_GET(void)
{
#if defined(HAVE_THREAD_LOCAL) && !defined(Py_BUILD_CORE_MODULE)
return (PyThreadState*)_Py_atomic_load_ptr_relaxed(&_PyRuntime.tstate_current);
return _Py_tss_tstate;
#else
return _PyThreadState_GetCurrent();
#endif
Expand Down
1 change: 0 additions & 1 deletion Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ typedef struct pyruntimestate {
struct _pythread_runtime_state threads;
struct _signals_runtime_state signals;

PyThreadState *tstate_current;
/* Used for the thread state bound to the current thread. */
Py_tss_t autoTSSkey;

Expand Down
51 changes: 0 additions & 51 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5226,57 +5226,6 @@ get_module_by_def(PyTypeObject *type, PyModuleDef *def)
return res;
}

// copied from the above
Py_NO_INLINE static PyObject *
get_module_by_def_NoInline(PyTypeObject *type, PyModuleDef *def)
{
assert(PyType_Check(type));

if (!_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE)) {
// type_ready_mro() ensures that no heap type is
// contained in a static type MRO.
return NULL;
}
else {
PyHeapTypeObject *ht = (PyHeapTypeObject*)type;
PyObject *module = ht->ht_module;
if (module && _PyModule_GetDef(module) == def) {
return module;
}
}

PyObject *res = NULL;
BEGIN_TYPE_LOCK();

PyObject *mro = lookup_tp_mro(type);
// The type must be ready
assert(mro != NULL);
assert(PyTuple_Check(mro));
// mro_invoke() ensures that the type MRO cannot be empty.
assert(PyTuple_GET_SIZE(mro) >= 1);
// Also, the first item in the MRO is the type itself, which
// we already checked above. We skip it in the loop.
assert(PyTuple_GET_ITEM(mro, 0) == (PyObject *)type);

Py_ssize_t n = PyTuple_GET_SIZE(mro);
for (Py_ssize_t i = 1; i < n; i++) {
PyObject *super = PyTuple_GET_ITEM(mro, i);
if(!_PyType_HasFeature((PyTypeObject *)super, Py_TPFLAGS_HEAPTYPE)) {
// Static types in the MRO need to be skipped
continue;
}

PyHeapTypeObject *ht = (PyHeapTypeObject*)super;
PyObject *module = ht->ht_module;
if (module && _PyModule_GetDef(module) == def) {
res = module;
break;
}
}
END_TYPE_LOCK();
return res;
}

PyObject *
PyType_GetModuleByDef(PyTypeObject *type, PyModuleDef *def)
{
Expand Down
3 changes: 0 additions & 3 deletions PCbuild/pyproject.props
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@
<AdditionalOptions Condition="$(MSVCHasBrokenARM64SignExtension) == 'true' and $(Platform) == 'ARM64'">-d2ssa-patterns-all- %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="$(GenerateSourceDependencies) == 'true'">/sourceDependencies "$(IntDir.Trim(`\`))" %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<ClCompile Condition="!$(RootNamespace.Contains(`test`)) and $(RootNamespace) != '_freeze_module'">
<AdditionalOptions>/Ob3 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<ClCompile Condition="$(Configuration) == 'Debug'">
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<Optimization>Disabled</Optimization>
Expand Down
18 changes: 5 additions & 13 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,23 @@ current_fast_get(void)
#endif
}

static inline PyThreadState *
current_fast_get2(void)
{
return (PyThreadState*)_Py_atomic_load_ptr_relaxed(&_PyRuntime.tstate_current);
}

static inline void
current_fast_set(_PyRuntimeState *Py_UNUSED(runtime), PyThreadState *tstate)
{
assert(tstate != NULL);
#ifdef HAVE_THREAD_LOCAL
_Py_tss_tstate = tstate;
_Py_atomic_store_ptr_relaxed(&_PyRuntime.tstate_current, tstate);
#else
// XXX Fall back to the PyThread_tss_*() API.
# error "no supported thread-local variable storage classifier"
#endif
}

static inline void
current_fast_clear(_PyRuntimeState *runtime)
current_fast_clear(_PyRuntimeState *Py_UNUSED(runtime))
{
#ifdef HAVE_THREAD_LOCAL
_Py_tss_tstate = NULL;
_Py_atomic_store_ptr_relaxed(&runtime->tstate_current, NULL);
#else
// XXX Fall back to the PyThread_tss_*() API.
# error "no supported thread-local variable storage classifier"
Expand All @@ -118,7 +110,7 @@ current_fast_clear(_PyRuntimeState *runtime)
PyThreadState *
_PyThreadState_GetCurrent(void)
{
return current_fast_get2();
return current_fast_get();
}


Expand Down Expand Up @@ -1339,7 +1331,7 @@ _PyInterpreterState_RequireIDRef(PyInterpreterState *interp, int required)
PyInterpreterState*
PyInterpreterState_Get(void)
{
PyThreadState *tstate = current_fast_get2();
PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate);
PyInterpreterState *interp = tstate->interp;
if (interp == NULL) {
Expand Down Expand Up @@ -2420,14 +2412,14 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
PyThreadState *
PyThreadState_GetUnchecked(void)
{
return current_fast_get2();
return current_fast_get();
}


PyThreadState *
PyThreadState_Get(void)
{
PyThreadState *tstate = current_fast_get2();
PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate);
return tstate;
}
Expand Down

0 comments on commit 89754d7

Please sign in to comment.