Skip to content

Commit e511c4c

Browse files
authored
Stackless issue python#281: Refactor tasklet profiling and tracing
Per tasklet profiling and tracing state information is now stored in the tasklet itself. This increases the size of tasklet objects a bit, but saves a lot of code.
1 parent daf6f4a commit e511c4c

10 files changed

Lines changed: 239 additions & 452 deletions

File tree

‎Include/cpython/slp_structs.h‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,6 @@ typedef struct _tasklet_flags {
101101
unsigned int pending_irq: SLP_TASKLET_FLAGS_BITS_pending_irq;
102102
} PyTaskletFlagStruc;
103103

104-
/* a partial copy of PyThreadState. Used to preserve
105-
the state of a hard switched tasklet */
106-
typedef struct _tasklet_tstate {
107-
int tracing;
108-
Py_tracefunc c_profilefunc;
109-
Py_tracefunc c_tracefunc;
110-
PyObject *c_profileobj;
111-
PyObject *c_traceobj;
112-
} PyTaskletTStateStruc;
113-
114104
typedef struct _tasklet {
115105
PyObject_HEAD
116106
struct _tasklet *next;
@@ -133,9 +123,20 @@ typedef struct _tasklet {
133123
int recursion_depth;
134124
PyObject *def_globals;
135125
PyObject *tsk_weakreflist;
136-
/* If the tasklet is current: NULL. (The context of a current tasklet is always in ts->tasklet.)
126+
/* If the tasklet is current: NULL. (The context of a current tasklet is
127+
* always in ts->context.)
137128
* If the tasklet is not current: the context for the tasklet */
138129
PyObject *context;
130+
131+
/* If the tasklet is current: NULL. (The profile and tracing state of a
132+
* current tasklet is stored in the thread state.)
133+
* If the tasklet is not current: the profile and tracing state for the tasklet.
134+
*/
135+
Py_tracefunc profilefunc;
136+
Py_tracefunc tracefunc;
137+
PyObject *profileobj;
138+
PyObject *traceobj;
139+
int tracing;
139140
} PyTaskletObject;
140141

141142

‎Include/internal/pycore_stackless.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,6 @@ PyAPI_FUNC(PyObject *) PyEval_EvalFrameEx_slp(struct _frame *, int, PyObject *);
380380
/* eval_frame with stack overflow, triggered there with a macro */
381381
PyObject * slp_eval_frame_newstack(struct _frame *f, int throwflag, PyObject *retval);
382382

383-
/* other eval_frame functions from module/scheduling.c */
384-
PyObject * slp_restore_tracing(PyCFrameObject *cf, int exc, PyObject *retval);
385383
/* other eval_frame functions from Objects/typeobject.c */
386384
PyObject * slp_tp_init_callback(PyCFrameObject *cf, int exc, PyObject *retval);
387385
/* functions related to pickling */
@@ -754,7 +752,6 @@ int slp_prepare_slots(PyTypeObject*);
754752
Py_tracefunc slp_get_sys_profile_func(void);
755753
Py_tracefunc slp_get_sys_trace_func(void);
756754
int slp_encode_ctrace_functions(Py_tracefunc c_tracefunc, Py_tracefunc c_profilefunc);
757-
PyTaskletTStateStruc * slp_get_saved_tstate(PyTaskletObject *task);
758755

759756
/*
760757
* Channel related prototypes

‎Lib/stackless.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _tasklet_get_unpicklable_state(tasklet):
9292

9393
flags = pickle_flags(PICKLEFLAGS_PICKLE_CONTEXT, PICKLEFLAGS_PICKLE_CONTEXT)
9494
try:
95-
return {'context': tasklet.__reduce__()[2][8]}
95+
return {'context': tasklet.__reduce__()[2][12]}
9696
finally:
9797
pickle_flags(flags, PICKLEFLAGS_PICKLE_CONTEXT)
9898

‎Stackless/changelog.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ What's New in Stackless 3.X.X?
99

1010
*Release date: 20XX-XX-XX*
1111

12+
- https://github.com/stackless-dev/stackless/issues/281
13+
Per tasklet profiling and tracing state information is now stored in the
14+
tasklet itself. This increases the size of tasklet objects a bit, but saves a
15+
lot of code.
16+
1217
- https://github.com/stackless-dev/stackless/issues/284
1318
Stackless supports pickling functions. But previous versions of Stackless
1419
only pickled the following attributes of a function-object: '__code__',

0 commit comments

Comments
 (0)