Tachyon (current)  Current Main Branch
Data Structures | Macros | Typedefs | Functions | Variables
threads.h File Reference

Tachyon cross-platform thread creation and management, atomic operations, and CPU feature query APIs. More...

Go to the source code of this file.

Data Structures

struct  rt_cpu_caps_struct
 
struct  atomic_int_struct
 atomic int structure with padding to prevent false sharing More...
 
struct  barrier_struct
 barrier sync object with padding to prevent false sharing More...
 
struct  rt_run_barrier_struct
 run-barrier sync object with padding to prevent false sharing More...
 
struct  rt_tasktile_struct
 Task tile struct for stack, iterator, and scheduler routines; 'start' is inclusive, 'end' is exclusive. More...
 
struct  rt_tilestack_t
 stack of work tiles, for error handling More...
 
struct  rt_shared_iterator_struct
 iterator used for dynamic load balancing More...
 
struct  rt_threadpool_workerdata_struct
 thread-specific handle data for workers More...
 
struct  rt_threadpool_struct
 persistent thread pool More...
 
struct  rt_threadlaunch_struct
 Routines to generate a pool of threads which then grind through a dynamically load balanced work queue implemented as a shared iterator. More...
 

Macros

#define CPU_SMTDEPTH_UNKNOWN   0
 Unknown SMT depth. More...
 
#define CPU_UNKNOWN   0x00000001
 Unknown CPU type. More...
 
#define CPU_HT   0x00000010
 x86 Hyperthreading detected More...
 
#define CPU_HYPERVISOR   0x00000020
 VM/Hypervisor environment. More...
 
#define CPU_SSE2   0x00000100
 SSE2 SIMD avail. More...
 
#define CPU_SSE4_1   0x00000200
 SSE4.1 SIMD avail. More...
 
#define CPU_F16C   0x00000400
 F16C insns avail. More...
 
#define CPU_FMA   0x00000800
 FMA insns avail. More...
 
#define CPU_AVX   0x00001000
 AVX SIMD avail. More...
 
#define CPU_AVX2   0x00002000
 AVX2 SIMD avail. More...
 
#define CPU_AVX512F   0x00010000
 AVX-512F SIMD avail. More...
 
#define CPU_AVX512CD   0x00020000
 AVX-512CD SIMD avail. More...
 
#define CPU_AVX512ER   0x00040000
 AVX-512ER SIMD avail. More...
 
#define CPU_AVX512PF   0x00080000
 AVX-512PF SIMD avail. More...
 
#define CPU_KNL
 Intel KNL. More...
 
#define CPU_ARM64_CPUID   0x00000010
 ARM64 CPUID. More...
 
#define CPU_ARM64_CRC32   0x00000020
 CRC32 insns avail. More...
 
#define CPU_ARM64_FP   0x00000080
 FP insns avail. More...
 
#define CPU_ARM64_HPFP   0x00000080
 High-prec FP insns avail. More...
 
#define CPU_ARM64_AES   0x00000100
 AES insns avail. More...
 
#define CPU_ARM64_ATOMICS   0x00000200
 Atomic insns avail. More...
 
#define CPU_ARM64_ASIMD   0x00000400
 Advanced SIMD avail. More...
 
#define CPU_ARM64_ASIMDDP   0x00000800
 Advanced SIMD DP avail. More...
 
#define CPU_ARM64_ASIMDHP   0x00001000
 Advanced SIMD HP avail. More...
 
#define CPU_ARM64_ASIMDRDM   0x00002000
 Advanced SIMD RDM avail. More...
 
#define CPU_ARM64_ASIMDFHM   0x00004000
 Advanced SIMD FHM avail. More...
 
#define CPU_ARM64_SVE   0x00008000
 Scalable Vector Extns avail. More...
 
#define CPU_ARM64_SHA512   0x00010000
 SHA-512 insns avail. More...
 
#define CPU_ARM64_SHA1   0x00020000
 SHA-1 insns avail. More...
 
#define CPU_ARM64_SHA2   0x00040000
 SHA-2 insns avail. More...
 
#define CPU_ARM64_SHA3   0x00080000
 SHA-3 insns avail. More...
 
#define RT_TILESTACK_EMPTY   -1
 
#define RT_SCHED_DONE   -1
 Shared iterators intended for trivial CPU/GPU load balancing with no exception handling capability (all work units must complete with no errors, or else the whole thing is canceled). More...
 
#define RT_SCHED_CONTINUE   0
 some work remains in the queue More...
 
#define RT_THREADPOOL_DEVLIST_CPUSONLY   NULL
 shortcut macro to tell the create routine we only want CPU cores More...
 
#define RT_THREADPOOL_DEVID_CPU   -1
 symbolic constant macro to test if we have a GPU or not More...
 

Typedefs

typedef struct rt_cpu_caps_struct rt_cpu_caps_t
 
typedef int rt_thread_t
 
typedef int rt_mutex_t
 
typedef int rt_cond_t
 
typedef int rt_rwlock_t
 
typedef struct atomic_int_struct rt_atomic_int_t
 atomic int structure with padding to prevent false sharing More...
 
typedef struct barrier_struct rt_barrier_t
 barrier sync object with padding to prevent false sharing More...
 
typedef struct rt_run_barrier_struct rt_run_barrier_t
 run-barrier sync object with padding to prevent false sharing More...
 
typedef struct rt_tasktile_struct rt_tasktile_t
 Task tile struct for stack, iterator, and scheduler routines; 'start' is inclusive, 'end' is exclusive. More...
 
typedef struct rt_shared_iterator_struct rt_shared_iterator_t
 iterator used for dynamic load balancing More...
 
typedef struct rt_threadpool_workerdata_struct rt_threadpool_workerdata_t
 thread-specific handle data for workers More...
 
typedef struct rt_threadpool_struct rt_threadpool_t
 persistent thread pool More...
 
typedef struct rt_threadlaunch_struct rt_threadlaunch_t
 Routines to generate a pool of threads which then grind through a dynamically load balanced work queue implemented as a shared iterator. More...
 

Functions

int rt_thread_numphysprocessors (void)
 number of physical processors available More...
 
int rt_thread_numprocessors (void)
 number of processors available, subject to user override More...
 
int rt_cpu_capability_flags (rt_cpu_caps_t *cpucaps)
 CPU optional instruction set capability flags. More...
 
int rt_cpu_smt_depth (void)
 CPU logical processors (SMT depth / aka hyperthreading) More...
 
int * rt_cpu_affinitylist (int *cpuaffinitycount)
 query CPU affinity of the calling process (if allowed by host system) More...
 
int rt_thread_set_self_cpuaffinity (int cpu)
 set the CPU affinity of the current thread (if allowed by host system) More...
 
int rt_thread_setconcurrency (int)
 set the concurrency level and scheduling scope for threads More...
 
int rt_thread_create (rt_thread_t *, void *fctn(void *), void *)
 create a new child thread More...
 
int rt_thread_join (rt_thread_t, void **)
 join (wait for completion of, and merge with) a thread More...
 
int rt_mutex_init (rt_mutex_t *)
 initialize a mutex More...
 
int rt_mutex_lock (rt_mutex_t *)
 lock a mutex More...
 
int rt_mutex_trylock (rt_mutex_t *)
 try to lock a mutex More...
 
int rt_mutex_spin_lock (rt_mutex_t *)
 lock a mutex by spinning only More...
 
int rt_mutex_unlock (rt_mutex_t *)
 unlock a mutex More...
 
int rt_mutex_destroy (rt_mutex_t *)
 destroy a mutex More...
 
int rt_cond_init (rt_cond_t *)
 initialize a condition variable More...
 
int rt_cond_destroy (rt_cond_t *)
 destroy a condition variable More...
 
int rt_cond_wait (rt_cond_t *, rt_mutex_t *)
 wait on a condition variable More...
 
int rt_cond_signal (rt_cond_t *)
 signal a condition variable, waking at least one thread More...
 
int rt_cond_broadcast (rt_cond_t *)
 signal a condition variable, waking all threads More...
 
int rt_atomic_int_init (rt_atomic_int_t *atomp, int val)
 initialize an atomic int variable More...
 
int rt_atomic_int_destroy (rt_atomic_int_t *atomp)
 destroy an atomic int variable More...
 
int rt_atomic_int_set (rt_atomic_int_t *atomp, int val)
 set an atomic int variable More...
 
int rt_atomic_int_get (rt_atomic_int_t *atomp)
 get an atomic int variable More...
 
int rt_atomic_int_fetch_and_add (rt_atomic_int_t *atomp, int inc)
 fetch an atomic int and add inc to it, returning original value More...
 
int rt_atomic_int_add_and_fetch (rt_atomic_int_t *atomp, int inc)
 fetch an atomic int and add inc to it, returning new value More...
 
int rt_rwlock_init (rt_rwlock_t *)
 initialize a reader/writer lock More...
 
int rt_rwlock_readlock (rt_rwlock_t *)
 set reader lock More...
 
int rt_rwlock_writelock (rt_rwlock_t *)
 set writer lock More...
 
int rt_rwlock_unlock (rt_rwlock_t *)
 unlock reader/writer lock More...
 
rt_barrier_trt_thread_barrier_init (int n_clients)
 initialize counting barrier primitive More...
 
int rt_thread_barrier_init_proc_shared (rt_barrier_t *, int n_clients)
 When rendering in the CAVE we use a special synchronization mode so that shared memory mutexes and condition variables will work correctly when accessed from multiple processes. More...
 
void rt_thread_barrier_destroy (rt_barrier_t *barrier)
 destroy counting barrier primitive More...
 
int rt_thread_barrier (rt_barrier_t *barrier, int increment)
 synchronize on counting barrier primitive More...
 
int rt_thread_run_barrier_init (rt_run_barrier_t *barrier, int n_clients)
 initialize thread pool barrier More...
 
void rt_thread_run_barrier_destroy (rt_run_barrier_t *barrier)
 destroy thread pool barrier More...
 
int rt_thread_run_barrier_poll (rt_run_barrier_t *barrier)
 non-blocking poll to see if peers are already at the barrier More...
 
int rt_tilestack_init (rt_tilestack_t *s, int size)
 initialize task tile stack (to empty) More...
 
void rt_tilestack_destroy (rt_tilestack_t *)
 destroy task tile stack More...
 
int rt_tilestack_compact (rt_tilestack_t *)
 shrink memory buffers associated with task tile stack if possible More...
 
int rt_tilestack_push (rt_tilestack_t *, const rt_tasktile_t *)
 push a task tile onto the stack More...
 
int rt_tilestack_pop (rt_tilestack_t *, rt_tasktile_t *)
 pop a task tile off of the stack More...
 
int rt_tilestack_popall (rt_tilestack_t *)
 pop all of the task tiles off of the stack More...
 
int rt_tilestack_empty (rt_tilestack_t *)
 query if the task tile stack is empty or not More...
 
int rt_shared_iterator_init (rt_shared_iterator_t *it)
 initialize a shared iterator More...
 
int rt_shared_iterator_destroy (rt_shared_iterator_t *it)
 destroy a shared iterator More...
 
int rt_shared_iterator_set (rt_shared_iterator_t *it, rt_tasktile_t *tile)
 Set shared iterator state to half-open interval defined by tile. More...
 
int rt_shared_iterator_next_tile (rt_shared_iterator_t *it, int reqsize, rt_tasktile_t *tile)
 iterate the shared iterator with a requested tile size, returns the tile received, and a return code of -1 if no iterations left or a fatal error has occured during processing, canceling all worker threads. More...
 
int rt_shared_iterator_setfatalerror (rt_shared_iterator_t *it)
 worker thread calls this to indicate a fatal error More...
 
int rt_shared_iterator_getfatalerror (rt_shared_iterator_t *it)
 master thread calls this to query for fatal errors More...
 
rt_threadpool_trt_threadpool_create (int workercount, int *devlist)
 create a thread pool with a specified number of worker threads More...
 
int rt_threadpool_launch (rt_threadpool_t *thrpool, void *fctn(void *), void *parms, int blocking)
 launch threads onto a new function, with associated parms More...
 
int rt_threadpool_wait (rt_threadpool_t *thrpool)
 wait for all worker threads to complete their work More...
 
int rt_threadpool_destroy (rt_threadpool_t *thrpool)
 join all worker threads and free resources More...
 
int rt_threadpool_get_workercount (rt_threadpool_t *thrpool)
 query number of worker threads in the pool More...
 
int rt_threadpool_worker_getid (void *voiddata, int *threadid, int *threadcount)
 worker thread can call this to get its ID and number of peers More...
 
int rt_threadpool_worker_getdevid (void *voiddata, int *devid)
 worker thread can call this to get its CPU/GPU device ID More...
 
int rt_threadpool_worker_setdevspeed (void *voiddata, float speed)
 Worker thread calls this to set relative speed of this device as determined by the SM/core count and clock rate Note: this should only be called once, during the worker's device initialization process. More...
 
int rt_threadpool_worker_getdevspeed (void *voiddata, float *speed)
 Worker thread calls this to get relative speed of this device as determined by the SM/core count and clock rate. More...
 
int rt_threadpool_worker_devscaletile (void *voiddata, int *tilesize)
 worker thread calls this to scale max tile size by worker speed as determined by the SM/core count and clock rate More...
 
int rt_threadpool_worker_getdata (void *voiddata, void **clientdata)
 worker thread can call this to get its client data pointer More...
 
int rt_threadpool_sched_dynamic (rt_threadpool_t *thrpool, rt_tasktile_t *tile)
 Set dynamic scheduler state to half-open interval defined by tile. More...
 
int rt_threadpool_next_tile (void *thrpool, int reqsize, rt_tasktile_t *tile)
 worker thread calls this to get its next work unit iterate the shared iterator, returns -1 if no iterations left More...
 
int rt_threadpool_tile_failed (void *thrpool, rt_tasktile_t *tile)
 worker thread calls this when it fails computing a tile after it has already taken it from the scheduler More...
 
int rt_threadpool_setfatalerror (void *thrparms)
 worker thread calls this to indicate that an unrecoverable error occured More...
 
int rt_threadpool_getfatalerror (void *thrparms)
 master thread calls this to query for fatal errors More...
 
int rt_threadlaunch (int numprocs, void *clientdata, void *fctn(void *), rt_tasktile_t *tile)
 launch up to numprocs threads using shared iterator as a load balancer More...
 
int rt_threadlaunch_getid (void *thrparms, int *threadid, int *threadcount)
 worker thread can call this to get its ID and number of peers More...
 
int rt_threadlaunch_getdata (void *thrparms, void **clientdata)
 worker thread can call this to get its client data pointer More...
 
int rt_threadlaunch_next_tile (void *voidparms, int reqsize, rt_tasktile_t *tile)
 worker thread calls this to get its next work unit iterate the shared iterator, returns -1 if no iterations left More...
 
int rt_threadlaunch_setfatalerror (void *thrparms)
 worker thread calls this to indicate that an unrecoverable error occured More...
 

Variables

void *(*)(void *) rt_thread_run_barrier (rt_run_barrier_t *barrier, void *fctn(void *), void *parms, void **rsltparms)
 sleeping barrier synchronization for thread pool More...
 

Detailed Description

Tachyon cross-platform thread creation and management, atomic operations, and CPU feature query APIs.

Definition in file threads.h.

Macro Definition Documentation

◆ CPU_ARM64_AES

#define CPU_ARM64_AES   0x00000100

AES insns avail.

Definition at line 75 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_ASIMD

#define CPU_ARM64_ASIMD   0x00000400

Advanced SIMD avail.

Definition at line 77 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_ASIMDDP

#define CPU_ARM64_ASIMDDP   0x00000800

Advanced SIMD DP avail.

Definition at line 78 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_ASIMDFHM

#define CPU_ARM64_ASIMDFHM   0x00004000

Advanced SIMD FHM avail.

Definition at line 81 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_ASIMDHP

#define CPU_ARM64_ASIMDHP   0x00001000

Advanced SIMD HP avail.

Definition at line 79 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_ASIMDRDM

#define CPU_ARM64_ASIMDRDM   0x00002000

Advanced SIMD RDM avail.

Definition at line 80 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_ATOMICS

#define CPU_ARM64_ATOMICS   0x00000200

Atomic insns avail.

Definition at line 76 of file threads.h.

◆ CPU_ARM64_CPUID

#define CPU_ARM64_CPUID   0x00000010

ARM64 CPUID.

Definition at line 71 of file threads.h.

◆ CPU_ARM64_CRC32

#define CPU_ARM64_CRC32   0x00000020

CRC32 insns avail.

Definition at line 72 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_FP

#define CPU_ARM64_FP   0x00000080

FP insns avail.

Definition at line 73 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_HPFP

#define CPU_ARM64_HPFP   0x00000080

High-prec FP insns avail.

Definition at line 74 of file threads.h.

◆ CPU_ARM64_SHA1

#define CPU_ARM64_SHA1   0x00020000

SHA-1 insns avail.

Definition at line 84 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_SHA2

#define CPU_ARM64_SHA2   0x00040000

SHA-2 insns avail.

Definition at line 85 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_SHA3

#define CPU_ARM64_SHA3   0x00080000

SHA-3 insns avail.

Definition at line 86 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_SHA512

#define CPU_ARM64_SHA512   0x00010000

SHA-512 insns avail.

Definition at line 83 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_ARM64_SVE

#define CPU_ARM64_SVE   0x00008000

Scalable Vector Extns avail.

Definition at line 82 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_AVX

#define CPU_AVX   0x00001000

AVX SIMD avail.

Definition at line 61 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_AVX2

#define CPU_AVX2   0x00002000

AVX2 SIMD avail.

Definition at line 62 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_AVX512CD

#define CPU_AVX512CD   0x00020000

AVX-512CD SIMD avail.

Definition at line 64 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_AVX512ER

#define CPU_AVX512ER   0x00040000

AVX-512ER SIMD avail.

Definition at line 65 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_AVX512F

#define CPU_AVX512F   0x00010000

AVX-512F SIMD avail.

Definition at line 63 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_AVX512PF

#define CPU_AVX512PF   0x00080000

AVX-512PF SIMD avail.

Definition at line 66 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_F16C

#define CPU_F16C   0x00000400

F16C insns avail.

Definition at line 59 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_FMA

#define CPU_FMA   0x00000800

FMA insns avail.

Definition at line 60 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_HT

#define CPU_HT   0x00000010

x86 Hyperthreading detected

Definition at line 55 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_HYPERVISOR

#define CPU_HYPERVISOR   0x00000020

VM/Hypervisor environment.

Definition at line 56 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_KNL

#define CPU_KNL
Value:
CPU_AVX512ER | CPU_AVX512PF)
#define CPU_AVX512CD
AVX-512CD SIMD avail.
Definition: threads.h:64
#define CPU_AVX512F
AVX-512F SIMD avail.
Definition: threads.h:63
#define CPU_AVX512PF
AVX-512PF SIMD avail.
Definition: threads.h:66

Intel KNL.

Definition at line 67 of file threads.h.

Referenced by rendercheck().

◆ CPU_SMTDEPTH_UNKNOWN

#define CPU_SMTDEPTH_UNKNOWN   0

Unknown SMT depth.

Definition at line 51 of file threads.h.

Referenced by rt_cpu_capability_flags(), and rt_cpu_smt_depth().

◆ CPU_SSE2

#define CPU_SSE2   0x00000100

SSE2 SIMD avail.

Definition at line 57 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_SSE4_1

#define CPU_SSE4_1   0x00000200

SSE4.1 SIMD avail.

Definition at line 58 of file threads.h.

Referenced by rendercheck(), and rt_cpu_capability_flags().

◆ CPU_UNKNOWN

#define CPU_UNKNOWN   0x00000001

Unknown CPU type.

Definition at line 52 of file threads.h.

Referenced by rt_cpu_capability_flags().

◆ RT_SCHED_CONTINUE

#define RT_SCHED_CONTINUE   0

some work remains in the queue

Definition at line 437 of file threads.h.

Referenced by rt_shared_iterator_next_tile(), and rt_threadpool_next_tile().

◆ RT_SCHED_DONE

#define RT_SCHED_DONE   -1

Shared iterators intended for trivial CPU/GPU load balancing with no exception handling capability (all work units must complete with no errors, or else the whole thing is canceled).

no work left to process

Definition at line 436 of file threads.h.

Referenced by rt_shared_iterator_next_tile(), and rt_threadpool_next_tile().

◆ RT_THREADPOOL_DEVID_CPU

#define RT_THREADPOOL_DEVID_CPU   -1

symbolic constant macro to test if we have a GPU or not

Definition at line 480 of file threads.h.

◆ RT_THREADPOOL_DEVLIST_CPUSONLY

#define RT_THREADPOOL_DEVLIST_CPUSONLY   NULL

shortcut macro to tell the create routine we only want CPU cores

Definition at line 477 of file threads.h.

◆ RT_TILESTACK_EMPTY

#define RT_TILESTACK_EMPTY   -1

Definition at line 396 of file threads.h.

Referenced by rt_threadpool_next_tile(), and rt_tilestack_pop().

Typedef Documentation

◆ rt_atomic_int_t

atomic int structure with padding to prevent false sharing

◆ rt_barrier_t

typedef struct barrier_struct rt_barrier_t

barrier sync object with padding to prevent false sharing

◆ rt_cond_t

typedef int rt_cond_t

Definition at line 167 of file threads.h.

◆ rt_cpu_caps_t

◆ rt_mutex_t

typedef int rt_mutex_t

Definition at line 166 of file threads.h.

◆ rt_run_barrier_t

run-barrier sync object with padding to prevent false sharing

◆ rt_rwlock_t

typedef int rt_rwlock_t

Definition at line 168 of file threads.h.

◆ rt_shared_iterator_t

iterator used for dynamic load balancing

◆ rt_tasktile_t

Task tile struct for stack, iterator, and scheduler routines; 'start' is inclusive, 'end' is exclusive.

This yields a half-open interval that corresponds to a typical 'for' loop.

◆ rt_thread_t

typedef int rt_thread_t

Definition at line 165 of file threads.h.

◆ rt_threadlaunch_t

Routines to generate a pool of threads which then grind through a dynamically load balanced work queue implemented as a shared iterator.

No exception handling is possible, just a simple all-or-nothing attept. Useful for simple calculations that take very little time. An array of threads is generated, launched, and joined all with one call.

◆ rt_threadpool_t

persistent thread pool

◆ rt_threadpool_workerdata_t

thread-specific handle data for workers

Function Documentation

◆ rt_atomic_int_add_and_fetch()

int rt_atomic_int_add_and_fetch ( rt_atomic_int_t atomp,
int  inc 
)

fetch an atomic int and add inc to it, returning new value

Definition at line 1180 of file threads.c.

References atomic_int_struct::lock, rt_mutex_lock(), rt_mutex_unlock(), and atomic_int_struct::val.

◆ rt_atomic_int_destroy()

int rt_atomic_int_destroy ( rt_atomic_int_t atomp)

destroy an atomic int variable

Definition at line 1066 of file threads.c.

References atomic_int_struct::lock, and rt_mutex_destroy().

Referenced by destroy_render_threads().

◆ rt_atomic_int_fetch_and_add()

int rt_atomic_int_fetch_and_add ( rt_atomic_int_t atomp,
int  inc 
)

fetch an atomic int and add inc to it, returning original value

Definition at line 1152 of file threads.c.

References atomic_int_struct::lock, rt_mutex_lock(), rt_mutex_unlock(), and atomic_int_struct::val.

Referenced by thread_trace().

◆ rt_atomic_int_get()

int rt_atomic_int_get ( rt_atomic_int_t atomp)

get an atomic int variable

Definition at line 1123 of file threads.c.

References atomic_int_struct::lock, rt_mutex_lock(), rt_mutex_unlock(), and atomic_int_struct::val.

◆ rt_atomic_int_init()

int rt_atomic_int_init ( rt_atomic_int_t atomp,
int  val 
)

initialize an atomic int variable

Definition at line 1043 of file threads.c.

References atomic_int_struct::lock, rt_mutex_init(), and atomic_int_struct::val.

Referenced by create_render_threads().

◆ rt_atomic_int_set()

int rt_atomic_int_set ( rt_atomic_int_t atomp,
int  val 
)

set an atomic int variable

Definition at line 1087 of file threads.c.

References atomic_int_struct::lock, rt_mutex_lock(), rt_mutex_unlock(), and atomic_int_struct::val.

Referenced by renderscene().

◆ rt_cond_broadcast()

int rt_cond_broadcast ( rt_cond_t )

signal a condition variable, waking all threads

Definition at line 1003 of file threads.c.

Referenced by rt_thread_barrier().

◆ rt_cond_destroy()

int rt_cond_destroy ( rt_cond_t )

destroy a condition variable

Definition at line 888 of file threads.c.

Referenced by rt_thread_barrier_destroy(), and rt_thread_run_barrier_destroy().

◆ rt_cond_init()

int rt_cond_init ( rt_cond_t )

initialize a condition variable

Definition at line 852 of file threads.c.

Referenced by rt_rwlock_init(), rt_thread_barrier_init(), and rt_thread_run_barrier_init().

◆ rt_cond_signal()

int rt_cond_signal ( rt_cond_t )

signal a condition variable, waking at least one thread

Definition at line 971 of file threads.c.

Referenced by rt_rwlock_unlock().

◆ rt_cond_wait()

int rt_cond_wait ( rt_cond_t ,
rt_mutex_t  
)

wait on a condition variable

Definition at line 912 of file threads.c.

Referenced by rt_rwlock_readlock(), rt_rwlock_writelock(), and rt_thread_barrier().

◆ rt_cpu_affinitylist()

int* rt_cpu_affinitylist ( int *  cpuaffinitycount)

query CPU affinity of the calling process (if allowed by host system)

Definition at line 483 of file threads.c.

◆ rt_cpu_capability_flags()

int rt_cpu_capability_flags ( rt_cpu_caps_t cpucaps)

◆ rt_cpu_smt_depth()

int rt_cpu_smt_depth ( void  )

CPU logical processors (SMT depth / aka hyperthreading)

Definition at line 466 of file threads.c.

References CPU_SMTDEPTH_UNKNOWN, rt_cpu_capability_flags(), and rt_cpu_caps_struct::smtdepth.

◆ rt_mutex_destroy()

int rt_mutex_destroy ( rt_mutex_t )

◆ rt_mutex_init()

int rt_mutex_init ( rt_mutex_t )

◆ rt_mutex_lock()

int rt_mutex_lock ( rt_mutex_t )

◆ rt_mutex_spin_lock()

int rt_mutex_spin_lock ( rt_mutex_t )

lock a mutex by spinning only

Definition at line 784 of file threads.c.

Referenced by rt_shared_iterator_next_tile(), and rt_shared_iterator_setfatalerror().

◆ rt_mutex_trylock()

int rt_mutex_trylock ( rt_mutex_t )

try to lock a mutex

Definition at line 763 of file threads.c.

◆ rt_mutex_unlock()

int rt_mutex_unlock ( rt_mutex_t )

◆ rt_rwlock_init()

int rt_rwlock_init ( rt_rwlock_t )

initialize a reader/writer lock

Definition at line 1212 of file threads.c.

References rt_cond_init(), and rt_mutex_init().

◆ rt_rwlock_readlock()

int rt_rwlock_readlock ( rt_rwlock_t )

set reader lock

Definition at line 1241 of file threads.c.

References rt_cond_wait(), rt_mutex_lock(), and rt_mutex_unlock().

◆ rt_rwlock_unlock()

int rt_rwlock_unlock ( rt_rwlock_t )

unlock reader/writer lock

Definition at line 1305 of file threads.c.

References rt_cond_signal(), rt_mutex_lock(), and rt_mutex_unlock().

◆ rt_rwlock_writelock()

int rt_rwlock_writelock ( rt_rwlock_t )

set writer lock

Definition at line 1270 of file threads.c.

References rt_cond_wait(), rt_mutex_lock(), and rt_mutex_unlock().

◆ rt_shared_iterator_destroy()

int rt_shared_iterator_destroy ( rt_shared_iterator_t it)

destroy a shared iterator

Definition at line 1710 of file threads.c.

References rt_shared_iterator_struct::mtx, and rt_mutex_destroy().

Referenced by rt_threadlaunch(), and rt_threadpool_destroy().

◆ rt_shared_iterator_getfatalerror()

int rt_shared_iterator_getfatalerror ( rt_shared_iterator_t it)

master thread calls this to query for fatal errors

Definition at line 1785 of file threads.c.

References rt_shared_iterator_struct::fatalerror, rt_shared_iterator_struct::mtx, rt_mutex_lock(), and rt_mutex_unlock().

Referenced by rt_threadlaunch(), and rt_threadpool_getfatalerror().

◆ rt_shared_iterator_init()

int rt_shared_iterator_init ( rt_shared_iterator_t it)

initialize a shared iterator

Definition at line 1700 of file threads.c.

References rt_shared_iterator_struct::mtx, and rt_mutex_init().

Referenced by rt_threadlaunch(), and rt_threadpool_create().

◆ rt_shared_iterator_next_tile()

int rt_shared_iterator_next_tile ( rt_shared_iterator_t it,
int  reqsize,
rt_tasktile_t tile 
)

iterate the shared iterator with a requested tile size, returns the tile received, and a return code of -1 if no iterations left or a fatal error has occured during processing, canceling all worker threads.

iterate the shared iterator with a requested tile size, returns the tile received, and a return code of -1 if no iterations left or a fatal error has occured during processing, canceling all worker threads.

Definition at line 1736 of file threads.c.

References rt_shared_iterator_struct::current, rt_tasktile_struct::end, rt_shared_iterator_struct::end, rt_shared_iterator_struct::fatalerror, rt_shared_iterator_struct::mtx, rt_mutex_spin_lock(), rt_mutex_unlock(), RT_SCHED_CONTINUE, RT_SCHED_DONE, and rt_tasktile_struct::start.

Referenced by rt_threadlaunch_next_tile(), and rt_threadpool_next_tile().

◆ rt_shared_iterator_set()

int rt_shared_iterator_set ( rt_shared_iterator_t it,
rt_tasktile_t tile 
)

Set shared iterator state to half-open interval defined by tile.

Set shared iterator state to half-open interval defined by tile.

Definition at line 1719 of file threads.c.

References rt_shared_iterator_struct::current, rt_tasktile_struct::end, rt_shared_iterator_struct::end, rt_shared_iterator_struct::fatalerror, rt_shared_iterator_struct::mtx, rt_mutex_lock(), rt_mutex_unlock(), rt_tasktile_struct::start, and rt_shared_iterator_struct::start.

Referenced by rt_threadlaunch(), and rt_threadpool_sched_dynamic().

◆ rt_shared_iterator_setfatalerror()

int rt_shared_iterator_setfatalerror ( rt_shared_iterator_t it)

worker thread calls this to indicate a fatal error

Definition at line 1772 of file threads.c.

References rt_shared_iterator_struct::fatalerror, rt_shared_iterator_struct::mtx, rt_mutex_spin_lock(), and rt_mutex_unlock().

Referenced by rt_threadlaunch_setfatalerror(), and rt_threadpool_setfatalerror().

◆ rt_thread_barrier()

int rt_thread_barrier ( rt_barrier_t barrier,
int  increment 
)

◆ rt_thread_barrier_destroy()

void rt_thread_barrier_destroy ( rt_barrier_t barrier)

destroy counting barrier primitive

Definition at line 1416 of file threads.c.

References barrier_struct::lock, rt_cond_destroy(), rt_mutex_destroy(), and barrier_struct::wait_cv.

Referenced by destroy_render_threads().

◆ rt_thread_barrier_init()

rt_barrier_t* rt_thread_barrier_init ( int  n_clients)

◆ rt_thread_barrier_init_proc_shared()

int rt_thread_barrier_init_proc_shared ( rt_barrier_t ,
int  n_clients 
)

When rendering in the CAVE we use a special synchronization mode so that shared memory mutexes and condition variables will work correctly when accessed from multiple processes.

Inter-process synchronization involves the kernel to a greater degree, so these barriers are substantially more costly to use than the ones designed for use within a single-process.

Definition at line 1379 of file threads.c.

References barrier_struct::lock, barrier_struct::n_clients, barrier_struct::n_waiting, barrier_struct::phase, barrier_struct::sum, and barrier_struct::wait_cv.

◆ rt_thread_create()

int rt_thread_create ( rt_thread_t ,
void *  fctnvoid *,
void *   
)

create a new child thread

Definition at line 645 of file threads.c.

Referenced by create_render_threads(), rt_threadlaunch(), and rt_threadpool_create().

◆ rt_thread_join()

int rt_thread_join ( rt_thread_t  ,
void **   
)

join (wait for completion of, and merge with) a thread

Definition at line 688 of file threads.c.

Referenced by destroy_render_threads(), rt_threadlaunch(), and rt_threadpool_destroy().

◆ rt_thread_numphysprocessors()

int rt_thread_numphysprocessors ( void  )

number of physical processors available

number of physical processors available

Definition at line 114 of file threads.c.

Referenced by rt_thread_numprocessors().

◆ rt_thread_numprocessors()

int rt_thread_numprocessors ( void  )

number of processors available, subject to user override

Definition at line 202 of file threads.c.

References rt_thread_numphysprocessors().

Referenced by rt_par_getcpuinfo(), and rt_set_numthreads().

◆ rt_thread_run_barrier_destroy()

void rt_thread_run_barrier_destroy ( rt_run_barrier_t barrier)

destroy thread pool barrier

Definition at line 1478 of file threads.c.

References rt_run_barrier_struct::lock, rt_cond_destroy(), rt_mutex_destroy(), and rt_run_barrier_struct::wait_cv.

Referenced by rt_threadpool_destroy().

◆ rt_thread_run_barrier_init()

int rt_thread_run_barrier_init ( rt_run_barrier_t barrier,
int  n_clients 
)

◆ rt_thread_run_barrier_poll()

int rt_thread_run_barrier_poll ( rt_run_barrier_t barrier)

non-blocking poll to see if peers are already at the barrier

Definition at line 1536 of file threads.c.

References rt_run_barrier_struct::lock, rt_run_barrier_struct::n_clients, rt_run_barrier_struct::n_waiting, rt_mutex_lock(), and rt_mutex_unlock().

Referenced by rt_threadpool_poll().

◆ rt_thread_set_self_cpuaffinity()

int rt_thread_set_self_cpuaffinity ( int  cpu)

set the CPU affinity of the current thread (if allowed by host system)

Definition at line 572 of file threads.c.

Referenced by thread_worker().

◆ rt_thread_setconcurrency()

int rt_thread_setconcurrency ( int  )

set the concurrency level and scheduling scope for threads

Definition at line 618 of file threads.c.

Referenced by rt_set_numthreads().

◆ rt_threadlaunch()

int rt_threadlaunch ( int  numprocs,
void *  clientdata,
void *  fctnvoid *,
rt_tasktile_t tile 
)

◆ rt_threadlaunch_getdata()

int rt_threadlaunch_getdata ( void *  thrparms,
void **  clientdata 
)

worker thread can call this to get its client data pointer

Definition at line 2175 of file threads.c.

References rt_threadlaunch_struct::clientdata.

◆ rt_threadlaunch_getid()

int rt_threadlaunch_getid ( void *  thrparms,
int *  threadid,
int *  threadcount 
)

worker thread can call this to get its ID and number of peers

Definition at line 2162 of file threads.c.

References rt_threadlaunch_struct::threadcount, and rt_threadlaunch_struct::threadid.

◆ rt_threadlaunch_next_tile()

int rt_threadlaunch_next_tile ( void *  voidparms,
int  reqsize,
rt_tasktile_t tile 
)

worker thread calls this to get its next work unit iterate the shared iterator, returns -1 if no iterations left

worker thread calls this to get its next work unit iterate the shared iterator, returns -1 if no iterations left

Definition at line 2185 of file threads.c.

References rt_threadlaunch_struct::iter, and rt_shared_iterator_next_tile().

◆ rt_threadlaunch_setfatalerror()

int rt_threadlaunch_setfatalerror ( void *  thrparms)

worker thread calls this to indicate that an unrecoverable error occured

Definition at line 2193 of file threads.c.

References rt_threadlaunch_struct::iter, and rt_shared_iterator_setfatalerror().

◆ rt_threadpool_create()

rt_threadpool_t* rt_threadpool_create ( int  workercount,
int *  devlist 
)

◆ rt_threadpool_destroy()

int rt_threadpool_destroy ( rt_threadpool_t thrpool)

◆ rt_threadpool_get_workercount()

int rt_threadpool_get_workercount ( rt_threadpool_t thrpool)

query number of worker threads in the pool

query number of worker threads in the pool

Definition at line 1951 of file threads.c.

References rt_threadpool_struct::workercount.

◆ rt_threadpool_getfatalerror()

int rt_threadpool_getfatalerror ( void *  thrparms)

master thread calls this to query for fatal errors

Definition at line 2077 of file threads.c.

References rt_threadpool_workerdata_struct::iter, and rt_shared_iterator_getfatalerror().

◆ rt_threadpool_launch()

int rt_threadpool_launch ( rt_threadpool_t thrpool,
void *  fctnvoid *,
void *  parms,
int  blocking 
)

launch threads onto a new function, with associated parms

Definition at line 1882 of file threads.c.

References rt_threadpool_workerdata_struct::parms, rt_thread_run_barrier, rt_threadpool_struct::runbar, and rt_threadpool_struct::workerdata.

◆ rt_threadpool_next_tile()

int rt_threadpool_next_tile ( void *  voidparms,
int  reqsize,
rt_tasktile_t tile 
)

worker thread calls this to get its next work unit iterate the shared iterator, returns -1 if no iterations left

worker thread calls this to get its next work unit iterate the shared iterator, returns -1 if no iterations left

Definition at line 2042 of file threads.c.

References rt_threadpool_workerdata_struct::errorstack, rt_threadpool_workerdata_struct::iter, RT_SCHED_CONTINUE, RT_SCHED_DONE, rt_shared_iterator_next_tile(), RT_TILESTACK_EMPTY, and rt_tilestack_pop().

◆ rt_threadpool_sched_dynamic()

int rt_threadpool_sched_dynamic ( rt_threadpool_t thrpool,
rt_tasktile_t tile 
)

Set dynamic scheduler state to half-open interval defined by tile.

Set dynamic scheduler state to half-open interval defined by tile.

Definition at line 2034 of file threads.c.

References rt_threadpool_struct::iter, and rt_shared_iterator_set().

◆ rt_threadpool_setfatalerror()

int rt_threadpool_setfatalerror ( void *  thrparms)

worker thread calls this to indicate that an unrecoverable error occured

Definition at line 2069 of file threads.c.

References rt_threadpool_workerdata_struct::iter, and rt_shared_iterator_setfatalerror().

◆ rt_threadpool_tile_failed()

int rt_threadpool_tile_failed ( void *  voidparms,
rt_tasktile_t tile 
)

worker thread calls this when it fails computing a tile after it has already taken it from the scheduler

worker thread calls this when it fails computing a tile after it has already taken it from the scheduler

Definition at line 2062 of file threads.c.

References rt_threadpool_workerdata_struct::errorstack, and rt_tilestack_push().

◆ rt_threadpool_wait()

int rt_threadpool_wait ( rt_threadpool_t thrpool)

wait for all worker threads to complete their work

Definition at line 1900 of file threads.c.

References rt_thread_run_barrier, and rt_threadpool_struct::runbar.

◆ rt_threadpool_worker_devscaletile()

int rt_threadpool_worker_devscaletile ( void *  voiddata,
int *  tilesize 
)

worker thread calls this to scale max tile size by worker speed as determined by the SM/core count and clock rate

Definition at line 2008 of file threads.c.

References rt_threadpool_workerdata_struct::devspeed.

◆ rt_threadpool_worker_getdata()

int rt_threadpool_worker_getdata ( void *  voiddata,
void **  clientdata 
)

worker thread can call this to get its client data pointer

Definition at line 2024 of file threads.c.

References rt_threadpool_workerdata_struct::parms.

◆ rt_threadpool_worker_getdevid()

int rt_threadpool_worker_getdevid ( void *  voiddata,
int *  devid 
)

worker thread can call this to get its CPU/GPU device ID

Definition at line 1970 of file threads.c.

References rt_threadpool_workerdata_struct::devid.

◆ rt_threadpool_worker_getdevspeed()

int rt_threadpool_worker_getdevspeed ( void *  voiddata,
float *  speed 
)

Worker thread calls this to get relative speed of this device as determined by the SM/core count and clock rate.

Worker thread calls this to get relative speed of this device as determined by the SM/core count and clock rate.

Definition at line 1996 of file threads.c.

References rt_threadpool_workerdata_struct::devspeed.

◆ rt_threadpool_worker_getid()

int rt_threadpool_worker_getid ( void *  voiddata,
int *  threadid,
int *  threadcount 
)

worker thread can call this to get its ID and number of peers

Definition at line 1957 of file threads.c.

References rt_threadpool_workerdata_struct::threadcount, and rt_threadpool_workerdata_struct::threadid.

◆ rt_threadpool_worker_setdevspeed()

int rt_threadpool_worker_setdevspeed ( void *  voiddata,
float  speed 
)

Worker thread calls this to set relative speed of this device as determined by the SM/core count and clock rate Note: this should only be called once, during the worker's device initialization process.

Worker thread calls this to set relative speed of this device as determined by the SM/core count and clock rate Note: this should only be called once, during the worker's device initialization process.

Definition at line 1985 of file threads.c.

References rt_threadpool_workerdata_struct::devspeed.

◆ rt_tilestack_compact()

int rt_tilestack_compact ( rt_tilestack_t )

shrink memory buffers associated with task tile stack if possible

Definition at line 1584 of file threads.c.

References rt_tilestack_t::mtx, rt_mutex_lock(), rt_mutex_unlock(), rt_tilestack_t::s, rt_tilestack_t::size, and rt_tilestack_t::top.

◆ rt_tilestack_destroy()

void rt_tilestack_destroy ( rt_tilestack_t )

destroy task tile stack

Definition at line 1575 of file threads.c.

References rt_tilestack_t::mtx, rt_mutex_destroy(), and rt_tilestack_t::s.

Referenced by rt_threadpool_destroy().

◆ rt_tilestack_empty()

int rt_tilestack_empty ( rt_tilestack_t )

query if the task tile stack is empty or not

Definition at line 1675 of file threads.c.

References rt_tilestack_t::mtx, rt_mutex_lock(), rt_mutex_unlock(), and rt_tilestack_t::top.

◆ rt_tilestack_init()

int rt_tilestack_init ( rt_tilestack_t s,
int  size 
)

initialize task tile stack (to empty)

Definition at line 1552 of file threads.c.

References rt_tilestack_t::growthrate, rt_tilestack_t::mtx, rt_mutex_init(), rt_tilestack_t::s, rt_tilestack_t::size, and rt_tilestack_t::top.

Referenced by rt_threadpool_create().

◆ rt_tilestack_pop()

int rt_tilestack_pop ( rt_tilestack_t ,
rt_tasktile_t  
)

pop a task tile off of the stack

Definition at line 1637 of file threads.c.

References rt_tilestack_t::mtx, rt_mutex_lock(), rt_mutex_unlock(), RT_TILESTACK_EMPTY, rt_tilestack_t::s, and rt_tilestack_t::top.

Referenced by rt_threadpool_next_tile().

◆ rt_tilestack_popall()

int rt_tilestack_popall ( rt_tilestack_t )

pop all of the task tiles off of the stack

Definition at line 1660 of file threads.c.

References rt_tilestack_t::mtx, rt_mutex_lock(), rt_mutex_unlock(), and rt_tilestack_t::top.

◆ rt_tilestack_push()

int rt_tilestack_push ( rt_tilestack_t ,
const rt_tasktile_t  
)

Variable Documentation

◆ rt_thread_run_barrier

void*(*)(void *) rt_thread_run_barrier(rt_run_barrier_t *barrier, void *fctn(void *), void *parms, void **rsltparms)

sleeping barrier synchronization for thread pool

Definition at line 373 of file threads.h.