From 3976d1031417e4090edbc734f08420e533282209 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 10 Jul 2024 10:40:22 -0400 Subject: [PATCH 1/3] gh-121583: Remove dependency from pystats.h to internal header file --- Include/cpython/pystats.h | 10 +++++----- Python/specialize.c | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Include/cpython/pystats.h b/Include/cpython/pystats.h index 38480a4f6cd78f..72a3f7f5e46569 100644 --- a/Include/cpython/pystats.h +++ b/Include/cpython/pystats.h @@ -19,12 +19,12 @@ // Define _PY_INTERPRETER macro to increment interpreter_increfs and // interpreter_decrefs. Otherwise, increment increfs and decrefs. -#include "pycore_uop_ids.h" - #ifndef Py_CPYTHON_PYSTATS_H # error "this header file must not be included directly" #endif +#define PYSTATS_MAX_UOP_ID 512 + #define SPECIALIZATION_FAILURE_KINDS 36 /* Stats for determining who is calling PyEval_EvalFrame */ @@ -100,7 +100,7 @@ typedef struct _gc_stats { typedef struct _uop_stats { uint64_t execution_count; uint64_t miss; - uint64_t pair_count[MAX_UOP_ID + 1]; + uint64_t pair_count[PYSTATS_MAX_UOP_ID + 1]; } UOpStats; #define _Py_UOP_HIST_SIZE 32 @@ -118,7 +118,7 @@ typedef struct _optimization_stats { uint64_t recursive_call; uint64_t low_confidence; uint64_t executors_invalidated; - UOpStats opcode[MAX_UOP_ID+1]; + UOpStats opcode[PYSTATS_MAX_UOP_ID+1]; uint64_t unsupported_opcode[256]; uint64_t trace_length_hist[_Py_UOP_HIST_SIZE]; uint64_t trace_run_length_hist[_Py_UOP_HIST_SIZE]; @@ -128,7 +128,7 @@ typedef struct _optimization_stats { uint64_t optimizer_failure_reason_no_memory; uint64_t remove_globals_builtins_changed; uint64_t remove_globals_incorrect_keys; - uint64_t error_in_opcode[MAX_UOP_ID+1]; + uint64_t error_in_opcode[PYSTATS_MAX_UOP_ID+1]; } OptimizationStats; typedef struct _rare_event_stats { diff --git a/Python/specialize.c b/Python/specialize.c index 497feca06e4c7f..3af0deabb9b40a 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -29,6 +29,10 @@ GCStats _py_gc_stats[NUM_GENERATIONS] = { 0 }; static PyStats _Py_stats_struct = { .gc_stats = _py_gc_stats }; PyStats *_Py_stats = NULL; +#if PYSTATS_MAX_UOP_ID < MAX_UOP_ID +#error "Not enough space allocated for pystats. Increase PYSTATS_MAX_UOP_ID to at least MAX_UOP_ID" +#endif + #define ADD_STAT_TO_DICT(res, field) \ do { \ PyObject *val = PyLong_FromUnsignedLongLong(stats->field); \ From 376ba224ed39fa0d39eae087f72a09ef8d252d2b Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 10 Jul 2024 11:32:59 -0400 Subject: [PATCH 2/3] Update Include/cpython/pystats.h Co-authored-by: Peter Bierma --- Include/cpython/pystats.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/cpython/pystats.h b/Include/cpython/pystats.h index 72a3f7f5e46569..594ef60246162a 100644 --- a/Include/cpython/pystats.h +++ b/Include/cpython/pystats.h @@ -128,7 +128,7 @@ typedef struct _optimization_stats { uint64_t optimizer_failure_reason_no_memory; uint64_t remove_globals_builtins_changed; uint64_t remove_globals_incorrect_keys; - uint64_t error_in_opcode[PYSTATS_MAX_UOP_ID+1]; + uint64_t error_in_opcode[PYSTATS_MAX_UOP_ID + 1]; } OptimizationStats; typedef struct _rare_event_stats { From e48b8ca834e0865b227260fa1ec3cee6bf42db45 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 10 Jul 2024 11:33:04 -0400 Subject: [PATCH 3/3] Update Include/cpython/pystats.h Co-authored-by: Peter Bierma --- Include/cpython/pystats.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/cpython/pystats.h b/Include/cpython/pystats.h index 594ef60246162a..c4480758f48514 100644 --- a/Include/cpython/pystats.h +++ b/Include/cpython/pystats.h @@ -118,7 +118,7 @@ typedef struct _optimization_stats { uint64_t recursive_call; uint64_t low_confidence; uint64_t executors_invalidated; - UOpStats opcode[PYSTATS_MAX_UOP_ID+1]; + UOpStats opcode[PYSTATS_MAX_UOP_ID + 1]; uint64_t unsupported_opcode[256]; uint64_t trace_length_hist[_Py_UOP_HIST_SIZE]; uint64_t trace_run_length_hist[_Py_UOP_HIST_SIZE];