summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorDino Viehland <dinoviehland@meta.com>2024-04-30 18:38:05 (GMT)
committerGitHub <noreply@github.com>2024-04-30 18:38:05 (GMT)
commit4a1cf66c5c0afa36d7a51d5f9d3874cda10df79c (patch)
tree3a37a8d9e9758ba71ad558a051324c20e140c777 /Python
parent1f16b4ce569f222af74fcbb7b2ef98eee2398d20 (diff)
downloadcpython-4a1cf66c5c0afa36d7a51d5f9d3874cda10df79c.zip
cpython-4a1cf66c5c0afa36d7a51d5f9d3874cda10df79c.tar.gz
cpython-4a1cf66c5c0afa36d7a51d5f9d3874cda10df79c.tar.bz2
gh-117657: Fix small issues with instrumentation and TSAN (#118064)
Small TSAN fixups for instrumentation
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c4
-rw-r--r--Python/ceval.c2
-rw-r--r--Python/ceval_macros.h2
-rw-r--r--Python/generated_cases.c.h2
-rw-r--r--Python/instrumentation.c9
5 files changed, 11 insertions, 8 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index eee8b32..5bb7e12 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -20,7 +20,7 @@
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "pycore_opcode_metadata.h" // uop names
#include "pycore_opcode_utils.h" // MAKE_FUNCTION_*
-#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_PTR_ACQUIRE
+#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_*
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_range.h" // _PyRangeIterObject
@@ -163,7 +163,7 @@ dummy_func(
if ((oparg & RESUME_OPARG_LOCATION_MASK) < RESUME_AFTER_YIELD_FROM) {
CHECK_EVAL_BREAKER();
}
- this_instr->op.code = RESUME_CHECK;
+ FT_ATOMIC_STORE_UINT8_RELAXED(this_instr->op.code, RESUME_CHECK);
}
}
diff --git a/Python/ceval.c b/Python/ceval.c
index d130c73..8b23bc6 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -20,7 +20,7 @@
#include "pycore_opcode_metadata.h" // EXTRA_CASES
#include "pycore_optimizer.h" // _PyUOpExecutor_Type
#include "pycore_opcode_utils.h" // MAKE_FUNCTION_*
-#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_PTR_ACQUIRE
+#include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_*
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_range.h" // _PyRangeIterObject
diff --git a/Python/ceval_macros.h b/Python/ceval_macros.h
index 1a8554a..c88a07c 100644
--- a/Python/ceval_macros.h
+++ b/Python/ceval_macros.h
@@ -162,7 +162,7 @@ GETITEM(PyObject *v, Py_ssize_t i) {
/* The integer overflow is checked by an assertion below. */
#define INSTR_OFFSET() ((int)(next_instr - _PyCode_CODE(_PyFrame_GetCode(frame))))
#define NEXTOPARG() do { \
- _Py_CODEUNIT word = *next_instr; \
+ _Py_CODEUNIT word = {.cache = FT_ATOMIC_LOAD_UINT16_RELAXED(*(uint16_t*)next_instr)}; \
opcode = word.op.code; \
oparg = word.op.arg; \
} while (0)
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 7c1cc14..a5bb293 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -4955,7 +4955,7 @@
if ((oparg & RESUME_OPARG_LOCATION_MASK) < RESUME_AFTER_YIELD_FROM) {
CHECK_EVAL_BREAKER();
}
- this_instr->op.code = RESUME_CHECK;
+ FT_ATOMIC_STORE_UINT8_RELAXED(this_instr->op.code, RESUME_CHECK);
}
DISPATCH();
}
diff --git a/Python/instrumentation.c b/Python/instrumentation.c
index 328a3b1..ce97c3a 100644
--- a/Python/instrumentation.c
+++ b/Python/instrumentation.c
@@ -626,9 +626,10 @@ de_instrument(PyCodeObject *code, int i, int event)
return;
}
CHECK(_PyOpcode_Deopt[deinstrumented] == deinstrumented);
- *opcode_ptr = deinstrumented;
+ FT_ATOMIC_STORE_UINT8_RELAXED(*opcode_ptr, deinstrumented);
if (_PyOpcode_Caches[deinstrumented]) {
- instr[1].counter = adaptive_counter_warmup();
+ FT_ATOMIC_STORE_UINT16_RELAXED(instr[1].counter.as_counter,
+ adaptive_counter_warmup().as_counter);
}
}
@@ -703,8 +704,10 @@ instrument(PyCodeObject *code, int i)
int deopt = _PyOpcode_Deopt[opcode];
int instrumented = INSTRUMENTED_OPCODES[deopt];
assert(instrumented);
- *opcode_ptr = instrumented;
+ FT_ATOMIC_STORE_UINT8_RELAXED(*opcode_ptr, instrumented);
if (_PyOpcode_Caches[deopt]) {
+ FT_ATOMIC_STORE_UINT16_RELAXED(instr[1].counter.as_counter,
+ adaptive_counter_warmup().as_counter);
instr[1].counter = adaptive_counter_warmup();
}
}