Skip to content

Commit 61e8f1d

Browse files
authored
Move jl_task_t to julia_threads.h (#57117)
This is a subset of PR #56477 . I hope that it will be easier to get this merged first, as it just moves things around, afterwards we can update #56477 and it will be considerably smaller, and will thus hopefully break less often (and in less bad ways) over time. (I can perform the required update of that PR, too). See also PR #57116 which contains another independent part of that PR.
1 parent 7f99e95 commit 61e8f1d

File tree

2 files changed

+78
-77
lines changed

2 files changed

+78
-77
lines changed

src/julia.h

+8-77
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,20 @@ typedef struct _jl_tls_states_t *jl_ptls_t;
7272
#endif
7373
#include "gc-interface.h"
7474
#include "julia_atomics.h"
75-
#include "julia_threads.h"
7675
#include "julia_assert.h"
7776

77+
// the common fields are hidden before the pointer, but the following macro is
78+
// used to indicate which types below are subtypes of jl_value_t
79+
#define JL_DATA_TYPE
80+
typedef struct _jl_value_t jl_value_t;
81+
#include "julia_threads.h"
82+
7883
#ifdef __cplusplus
7984
extern "C" {
8085
#endif
8186

8287
// core data types ------------------------------------------------------------
8388

84-
// the common fields are hidden before the pointer, but the following macro is
85-
// used to indicate which types below are subtypes of jl_value_t
86-
#define JL_DATA_TYPE
87-
88-
typedef struct _jl_value_t jl_value_t;
89-
9089
struct _jl_taggedvalue_bits {
9190
uintptr_t gc:2;
9291
uintptr_t in_image:1;
@@ -484,9 +483,6 @@ typedef struct _jl_abi_override_t {
484483
jl_method_instance_t *def;
485484
} jl_abi_override_t;
486485

487-
// all values are callable as Functions
488-
typedef jl_value_t jl_function_t;
489-
490486
typedef struct {
491487
JL_DATA_TYPE
492488
jl_sym_t *name;
@@ -2262,12 +2258,8 @@ JL_DLLEXPORT void jl_sigatomic_end(void);
22622258

22632259
// tasks and exceptions -------------------------------------------------------
22642260

2265-
typedef struct _jl_timing_block_t jl_timing_block_t;
2266-
typedef struct _jl_timing_event_t jl_timing_event_t;
2267-
typedef struct _jl_excstack_t jl_excstack_t;
2268-
22692261
// info describing an exception handler
2270-
typedef struct _jl_handler_t {
2262+
struct _jl_handler_t {
22712263
jl_jmp_buf eh_ctx;
22722264
jl_gcframe_t *gcstack;
22732265
jl_value_t *scope;
@@ -2277,68 +2269,7 @@ typedef struct _jl_handler_t {
22772269
sig_atomic_t defer_signal;
22782270
jl_timing_block_t *timing_stack;
22792271
size_t world_age;
2280-
} jl_handler_t;
2281-
2282-
#define JL_RNG_SIZE 5 // xoshiro 4 + splitmix 1
2283-
2284-
typedef struct _jl_task_t {
2285-
JL_DATA_TYPE
2286-
jl_value_t *next; // invasive linked list for scheduler
2287-
jl_value_t *queue; // invasive linked list for scheduler
2288-
jl_value_t *tls;
2289-
jl_value_t *donenotify;
2290-
jl_value_t *result;
2291-
jl_value_t *scope;
2292-
jl_function_t *start;
2293-
_Atomic(uint8_t) _state;
2294-
uint8_t sticky; // record whether this Task can be migrated to a new thread
2295-
uint16_t priority;
2296-
_Atomic(uint8_t) _isexception; // set if `result` is an exception to throw or that we exited with
2297-
uint8_t pad0[3];
2298-
// === 64 bytes (cache line)
2299-
uint64_t rngState[JL_RNG_SIZE];
2300-
// flag indicating whether or not to record timing metrics for this task
2301-
uint8_t metrics_enabled;
2302-
uint8_t pad1[3];
2303-
// timestamp this task first entered the run queue
2304-
_Atomic(uint64_t) first_enqueued_at;
2305-
// timestamp this task was most recently scheduled to run
2306-
_Atomic(uint64_t) last_started_running_at;
2307-
// time this task has spent running; updated when it yields or finishes.
2308-
_Atomic(uint64_t) running_time_ns;
2309-
// === 64 bytes (cache line)
2310-
// timestamp this task finished (i.e. entered state DONE or FAILED).
2311-
_Atomic(uint64_t) finished_at;
2312-
2313-
// hidden state:
2314-
2315-
// id of owning thread - does not need to be defined until the task runs
2316-
_Atomic(int16_t) tid;
2317-
// threadpool id
2318-
int8_t threadpoolid;
2319-
// Reentrancy bits
2320-
// Bit 0: 1 if we are currently running inference/codegen
2321-
// Bit 1-2: 0-3 counter of how many times we've reentered inference
2322-
// Bit 3: 1 if we are writing the image and inference is illegal
2323-
uint8_t reentrant_timing;
2324-
// 2 bytes of padding on 32-bit, 6 bytes on 64-bit
2325-
// uint16_t padding2_32;
2326-
// uint48_t padding2_64;
2327-
// saved gc stack top for context switches
2328-
jl_gcframe_t *gcstack;
2329-
size_t world_age;
2330-
// quick lookup for current ptls
2331-
jl_ptls_t ptls; // == jl_all_tls_states[tid]
2332-
#ifdef USE_TRACY
2333-
const char *name;
2334-
#endif
2335-
// saved exception stack
2336-
jl_excstack_t *excstack;
2337-
// current exception handler
2338-
jl_handler_t *eh;
2339-
// saved thread state
2340-
jl_ucontext_t ctx; // pointer into stkbuf, if suspended
2341-
} jl_task_t;
2272+
};
23422273

23432274
#define JL_TASK_STATE_RUNNABLE 0
23442275
#define JL_TASK_STATE_DONE 1

src/julia_threads.h

+70
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,76 @@ typedef struct _jl_tls_states_t {
218218
#endif
219219
} jl_tls_states_t;
220220

221+
#define JL_RNG_SIZE 5 // xoshiro 4 + splitmix 1
222+
223+
// all values are callable as Functions
224+
typedef jl_value_t jl_function_t;
225+
226+
typedef struct _jl_timing_block_t jl_timing_block_t;
227+
typedef struct _jl_timing_event_t jl_timing_event_t;
228+
typedef struct _jl_excstack_t jl_excstack_t;
229+
230+
typedef struct _jl_handler_t jl_handler_t;
231+
232+
typedef struct _jl_task_t {
233+
JL_DATA_TYPE
234+
jl_value_t *next; // invasive linked list for scheduler
235+
jl_value_t *queue; // invasive linked list for scheduler
236+
jl_value_t *tls;
237+
jl_value_t *donenotify;
238+
jl_value_t *result;
239+
jl_value_t *scope;
240+
jl_function_t *start;
241+
_Atomic(uint8_t) _state;
242+
uint8_t sticky; // record whether this Task can be migrated to a new thread
243+
uint16_t priority;
244+
_Atomic(uint8_t) _isexception; // set if `result` is an exception to throw or that we exited with
245+
uint8_t pad0[3];
246+
// === 64 bytes (cache line)
247+
uint64_t rngState[JL_RNG_SIZE];
248+
// flag indicating whether or not to record timing metrics for this task
249+
uint8_t metrics_enabled;
250+
uint8_t pad1[3];
251+
// timestamp this task first entered the run queue
252+
_Atomic(uint64_t) first_enqueued_at;
253+
// timestamp this task was most recently scheduled to run
254+
_Atomic(uint64_t) last_started_running_at;
255+
// time this task has spent running; updated when it yields or finishes.
256+
_Atomic(uint64_t) running_time_ns;
257+
// === 64 bytes (cache line)
258+
// timestamp this task finished (i.e. entered state DONE or FAILED).
259+
_Atomic(uint64_t) finished_at;
260+
261+
// hidden state:
262+
263+
// id of owning thread - does not need to be defined until the task runs
264+
_Atomic(int16_t) tid;
265+
// threadpool id
266+
int8_t threadpoolid;
267+
// Reentrancy bits
268+
// Bit 0: 1 if we are currently running inference/codegen
269+
// Bit 1-2: 0-3 counter of how many times we've reentered inference
270+
// Bit 3: 1 if we are writing the image and inference is illegal
271+
uint8_t reentrant_timing;
272+
// 2 bytes of padding on 32-bit, 6 bytes on 64-bit
273+
// uint16_t padding2_32;
274+
// uint48_t padding2_64;
275+
// saved gc stack top for context switches
276+
jl_gcframe_t *gcstack;
277+
size_t world_age;
278+
// quick lookup for current ptls
279+
jl_ptls_t ptls; // == jl_all_tls_states[tid]
280+
#ifdef USE_TRACY
281+
const char *name;
282+
#endif
283+
// saved exception stack
284+
jl_excstack_t *excstack;
285+
// current exception handler
286+
jl_handler_t *eh;
287+
// saved thread state
288+
jl_ucontext_t ctx; // pointer into stkbuf, if suspended
289+
} jl_task_t;
290+
221291
JL_DLLEXPORT void *jl_get_ptls_states(void);
222292

223293
// Update codegen version in `ccall.cpp` after changing either `pause` or `wake`

0 commit comments

Comments
 (0)