Skip to content

Commit 50e915b

Browse files
fingolfind-netto
authored andcommitted
Move jl_task_t to julia_threads.h
1 parent b70761f commit 50e915b

File tree

2 files changed

+78
-77
lines changed

2 files changed

+78
-77
lines changed

src/julia.h

Lines changed: 8 additions & 77 deletions
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;
@@ -2263,12 +2259,8 @@ JL_DLLEXPORT void jl_sigatomic_end(void);
22632259

22642260
// tasks and exceptions -------------------------------------------------------
22652261

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

23442275
#define JL_TASK_STATE_RUNNABLE 0
23452276
#define JL_TASK_STATE_DONE 1

src/julia_threads.h

Lines changed: 70 additions & 0 deletions
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)