Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove JULIA_ENABLE_THREADS feature flag #32685

Merged
merged 3 commits into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove JULIA_ENABLE_THREADS feature flag
This flag was essentially not documented, not CI'ed, and broken (it hangs in `jl_task_get_next at /home/mbauman/julia/src/partr.c:475`). Let's strip it out!
  • Loading branch information
mbauman committed Jul 25, 2019
commit e377d9fba3b831b9dc043adec4ed6821336782a5
2 changes: 1 addition & 1 deletion Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ endif

# Threads
ifneq ($(JULIA_THREADS), 0)
JCPPFLAGS += -DJULIA_ENABLE_THREADING -DJULIA_NUM_THREADS=$(JULIA_THREADS)
JCPPFLAGS += -DJULIA_NUM_THREADS=$(JULIA_THREADS)
endif

# Intel VTune Amplifier
Expand Down
3 changes: 0 additions & 3 deletions contrib/julia-config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ function cflags(doframework)
include = shell_escape(includeDir())
print(flags, " -I", include)
end
if threadingOn()
print(flags, " -DJULIA_ENABLE_THREADING=1")
end
if Sys.isunix()
print(flags, " -fPIC")
end
Expand Down
1 change: 0 additions & 1 deletion doc/src/manual/embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ We start by opening Visual Studio and creating a new Console Application project
header file, add the following lines at the end:

```c
#define JULIA_ENABLE_THREADING
#include <julia.h>
```

Expand Down
20 changes: 0 additions & 20 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ NOINLINE uintptr_t gc_get_stack_ptr(void)

#define should_timeout() 0

#ifdef JULIA_ENABLE_THREADING
static void jl_gc_wait_for_the_world(void)
{
if (jl_n_threads > 1)
Expand All @@ -207,11 +206,6 @@ static void jl_gc_wait_for_the_world(void)
}
}
}
#else
static inline void jl_gc_wait_for_the_world(void)
{
}
#endif

// malloc wrappers, aligned allocation

Expand Down Expand Up @@ -1095,9 +1089,7 @@ JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset,
// to workaround a llvm bug.
// Ref https://llvm.org/bugs/show_bug.cgi?id=27190
jl_gc_pool_t *p = (jl_gc_pool_t*)((char*)ptls + pool_offset);
#ifdef JULIA_ENABLE_THREADING
assert(ptls->gc_state == 0);
#endif
#ifdef MEMDEBUG
return jl_gc_big_alloc(ptls, osize);
#endif
Expand Down Expand Up @@ -1451,12 +1443,6 @@ JL_DLLEXPORT void jl_gc_queue_root(jl_value_t *ptr)
{
jl_ptls_t ptls = jl_get_ptls_states();
jl_taggedvalue_t *o = jl_astaggedvalue(ptr);
#ifndef JULIA_ENABLE_THREADING
// Disable this assert since it can happen with multithreading (same
// with the ones in gc_queue_binding) when two threads are writing
// to the same object.
assert(o->bits.gc == GC_OLD_MARKED);
#endif
// The modification of the `gc_bits` is not atomic but it
// should be safe here since GC is not allowed to run here and we only
// write GC_OLD to the GC bits outside GC. This could cause
Expand All @@ -1470,10 +1456,6 @@ void gc_queue_binding(jl_binding_t *bnd)
{
jl_ptls_t ptls = jl_get_ptls_states();
jl_taggedvalue_t *buf = jl_astaggedvalue(bnd);
#ifndef JULIA_ENABLE_THREADING
// Will fail for multithreading. See `jl_gc_queue_root`
assert(buf->bits.gc == GC_OLD_MARKED);
#endif
buf->bits.gc = GC_MARKED;
arraylist_push(&ptls->heap.rem_bindings, bnd);
}
Expand Down Expand Up @@ -2495,9 +2477,7 @@ static void mark_roots(jl_gc_mark_cache_t *gc_cache, jl_gc_mark_sp_t *sp)
gc_mark_queue_obj(gc_cache, sp, jl_main_module);

// tasks
#ifdef JULIA_ENABLE_THREADING
jl_gc_mark_enqueued_tasks(gc_cache, sp);
#endif

// invisible builtin values
if (jl_an_empty_vec_any != NULL)
Expand Down
24 changes: 9 additions & 15 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,19 @@ void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
#ifdef _OS_WINDOWS_
(void)ismaster;
// https://en.wikipedia.org/wiki/Win32_Thread_Information_Block
#ifdef _P64
# ifdef _P64
*stack_hi = (void**)__readgsqword(0x08); // Stack Base / Bottom of stack (high address)
*stack_lo = (void**)__readgsqword(0x10); // Stack Limit / Ceiling of stack (low address)
#else
# else // !_P64
*stack_hi = (void**)__readfsdword(0x04); // Stack Base / Bottom of stack (high address)
*stack_lo = (void**)__readfsdword(0x08); // Stack Limit / Ceiling of stack (low address)
#endif
#else
# ifdef JULIA_ENABLE_THREADING
# endif // _P64
#else // !_OS_WINDOWS_
// Only use pthread_*_np functions to get stack address for non-master
// threads since it seems to return bogus values for master thread on Linux
// and possibly OSX.
if (!ismaster) {
# if defined(_OS_LINUX_)
# if defined(_OS_LINUX_)
pthread_attr_t attr;
pthread_getattr_np(pthread_self(), &attr);
void *stackaddr;
Expand All @@ -92,7 +91,7 @@ void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
*stack_lo = (void*)stackaddr;
*stack_hi = (void*)((char*)stackaddr + stacksize);
return;
# elif defined(_OS_DARWIN_)
# elif defined(_OS_DARWIN_)
extern void *pthread_get_stackaddr_np(pthread_t thread);
extern size_t pthread_get_stacksize_np(pthread_t thread);
pthread_t thread = pthread_self();
Expand All @@ -101,7 +100,7 @@ void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
*stack_lo = (char*)stackaddr;
*stack_hi = (void*)((char*)stackaddr + stacksize);
return;
# elif defined(_OS_FREEBSD_)
# elif defined(_OS_FREEBSD_)
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_get_np(pthread_self(), &attr);
Expand All @@ -112,13 +111,10 @@ void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
*stack_lo = (char*)stackaddr;
*stack_hi = (void*)((char*)stackaddr + stacksize);
return;
# else
# warning "Getting precise stack size for thread is not supported."
# endif
}
# else
(void)ismaster;
# warning "Getting precise stack size for thread is not supported."
# endif
}
struct rlimit rl;
getrlimit(RLIMIT_STACK, &rl);
size_t stack_size = rl.rlim_cur;
Expand Down Expand Up @@ -651,10 +647,8 @@ static void jl_set_io_wait(int v)
void _julia_init(JL_IMAGE_SEARCH rel)
{
jl_init_timing();
#ifdef JULIA_ENABLE_THREADING
// Make sure we finalize the tls callback before starting any threads.
jl_get_ptls_states_getter();
#endif
jl_ptls_t ptls = jl_get_ptls_states();
(void)ptls; assert(ptls); // make sure early that we have initialized ptls
jl_safepoint_init();
Expand Down
9 changes: 2 additions & 7 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1515,12 +1515,11 @@ typedef enum {
JL_IMAGE_JULIA_HOME = 1,
//JL_IMAGE_LIBJULIA = 2,
} JL_IMAGE_SEARCH;
#ifdef JULIA_ENABLE_THREADING
// this helps turn threading compilation mismatches into linker errors
#define julia_init julia_init__threading
#define jl_init jl_init__threading
#define jl_init_with_image jl_init_with_image__threading
#endif

JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel);
JL_DLLEXPORT void jl_init(void);
JL_DLLEXPORT void jl_init_with_image(const char *julia_bindir,
Expand Down Expand Up @@ -1656,9 +1655,7 @@ typedef struct _jl_handler_t {
jl_gcframe_t *gcstack;
struct _jl_handler_t *prev;
int8_t gc_state;
#ifdef JULIA_ENABLE_THREADING
size_t locks_len;
#endif
sig_atomic_t defer_signal;
int finalizers_inhibited;
jl_timing_block_t *timing_stack;
Expand Down Expand Up @@ -1700,10 +1697,8 @@ typedef struct _jl_task_t {
int16_t tid;
/* for the multiqueue */
int16_t prio;
#ifdef JULIA_ENABLE_THREADING
// This is statically initialized when the task is not holding any locks
arraylist_t locks;
#endif
jl_timing_block_t *timing_stack;
} jl_task_t;

Expand Down Expand Up @@ -2019,7 +2014,7 @@ typedef struct {
extern JL_DLLEXPORT jl_cgparams_t jl_default_cgparams;
extern JL_DLLEXPORT int jl_default_debug_info_kind;

#if defined(JULIA_ENABLE_THREADING) && !defined(_OS_DARWIN_) && !defined(_OS_WINDOWS_)
#if !defined(_OS_DARWIN_) && !defined(_OS_WINDOWS_)
#define JULIA_DEFINE_FAST_TLS() \
JL_DLLEXPORT JL_CONST_FUNC jl_ptls_t jl_get_ptls_states_static(void) \
{ \
Expand Down
4 changes: 2 additions & 2 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ void jl_safepoint_defer_sigint(void);
int jl_safepoint_consume_sigint(void);
void jl_wake_libuv(void);

#if defined(JULIA_ENABLE_THREADING) && !defined(__clang_analyzer__)
#if !defined(__clang_analyzer__)
jl_get_ptls_states_func jl_get_ptls_states_getter(void);
static inline void jl_set_gc_and_wait(void)
{
Expand Down Expand Up @@ -853,7 +853,7 @@ extern jl_mutex_t safepoint_lock;

// -- gc.c -- //

#if defined(__APPLE__) && defined(JULIA_ENABLE_THREADING)
#if defined(__APPLE__)
void jl_mach_gc_end(void);
#endif

Expand Down
14 changes: 0 additions & 14 deletions src/julia_threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
// Nonetheless, we define JL_THREAD and use it to give advanced notice to
// maintainers of what eventual threading support will change.

// JULIA_ENABLE_THREADING is switched on in Make.inc if JULIA_THREADS is
// set (in Make.user)

// Options for task switching algorithm (in order of preference):
// JL_HAVE_ASM -- mostly setjmp
// JL_HAVE_UNW_CONTEXT -- hybrid of libunwind for start, setjmp for resume
Expand Down Expand Up @@ -260,16 +257,6 @@ void jl_sigint_safepoint(jl_ptls_t tls) JL_NOTSAFEPOINT;
(void)safepoint_load; \
} while (0)
#endif
#ifndef JULIA_ENABLE_THREADING
#define jl_gc_state(ptls) ((int8_t)0)
STATIC_INLINE int8_t jl_gc_state_set(jl_ptls_t ptls, int8_t state,
int8_t old_state)
{
(void)ptls;
(void)state;
return old_state;
}
#else // ifndef JULIA_ENABLE_THREADING
// Make sure jl_gc_state() is always a rvalue
#define jl_gc_state(ptls) ((int8_t)ptls->gc_state)
STATIC_INLINE int8_t jl_gc_state_set(jl_ptls_t ptls, int8_t state,
Expand All @@ -282,7 +269,6 @@ STATIC_INLINE int8_t jl_gc_state_set(jl_ptls_t ptls, int8_t state,
jl_gc_safepoint_(ptls);
return old_state;
}
#endif // ifndef JULIA_ENABLE_THREADING
STATIC_INLINE int8_t jl_gc_state_save_and_set(jl_ptls_t ptls,
int8_t state)
{
Expand Down
22 changes: 2 additions & 20 deletions src/llvm-ptls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/MDBuilder.h>

#if defined(JULIA_ENABLE_THREADING)
# include <llvm/IR/InlineAsm.h>
# include <llvm/Transforms/Utils/BasicBlockUtils.h>
#endif
#include <llvm/IR/InlineAsm.h>
#include <llvm/Transforms/Utils/BasicBlockUtils.h>

#include "julia.h"
#include "julia_internal.h"
Expand Down Expand Up @@ -61,21 +59,16 @@ struct LowerPTLS: public ModulePass {
Type *T_int8;
Type *T_size;
PointerType *T_pint8;
#ifdef JULIA_ENABLE_THREADING
GlobalVariable *ptls_slot{nullptr};
GlobalVariable *ptls_offset{nullptr};
void set_ptls_attrs(CallInst *ptlsStates) const;
Instruction *emit_ptls_tp(Value *offset, Instruction *insertBefore) const;
template<typename T> T *add_comdat(T *G) const;
GlobalVariable *create_aliased_global(Type *T, StringRef name) const;
#else
GlobalVariable *static_tls;
#endif
void fix_ptls_use(CallInst *ptlsStates);
bool runOnModule(Module &M) override;
};

#ifdef JULIA_ENABLE_THREADING
void LowerPTLS::set_ptls_attrs(CallInst *ptlsStates) const
{
ptlsStates->addAttribute(AttributeList::FunctionIndex, Attribute::ReadNone);
Expand Down Expand Up @@ -182,7 +175,6 @@ inline T *LowerPTLS::add_comdat(T *G) const
#endif
return G;
}
#endif

void LowerPTLS::fix_ptls_use(CallInst *ptlsStates)
{
Expand All @@ -191,7 +183,6 @@ void LowerPTLS::fix_ptls_use(CallInst *ptlsStates)
return;
}

#ifdef JULIA_ENABLE_THREADING
if (imaging_mode) {
if (jl_tls_elf_support) {
// if (offset != 0)
Expand Down Expand Up @@ -245,10 +236,6 @@ void LowerPTLS::fix_ptls_use(CallInst *ptlsStates)
ptlsStates->setCalledFunction(ptlsStates->getFunctionType(), ConstantExpr::getIntToPtr(val, T_ptls_getter));
set_ptls_attrs(ptlsStates);
}
#else
ptlsStates->replaceAllUsesWith(static_tls);
ptlsStates->eraseFromParent();
#endif
}

bool LowerPTLS::runOnModule(Module &_M)
Expand All @@ -268,15 +255,10 @@ bool LowerPTLS::runOnModule(Module &_M)
T_int8 = Type::getInt8Ty(*ctx);
T_size = sizeof(size_t) == 8 ? Type::getInt64Ty(*ctx) : Type::getInt32Ty(*ctx);
T_pint8 = T_int8->getPointerTo();
#ifdef JULIA_ENABLE_THREADING
if (imaging_mode) {
ptls_slot = create_aliased_global(T_ptls_getter, "jl_get_ptls_states_slot");
ptls_offset = create_aliased_global(T_size, "jl_tls_offset");
}
#else
static_tls = new GlobalVariable(*M, T_ppjlvalue, false, GlobalVariable::ExternalLinkage,
NULL, "jl_tls_states");
#endif

for (auto it = ptls_getter->user_begin(); it != ptls_getter->user_end();) {
auto call = cast<CallInst>(*it);
Expand Down
30 changes: 0 additions & 30 deletions src/locks.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ static inline void jl_mutex_lock_nogc(jl_mutex_t *lock) JL_NOTSAFEPOINT
#endif
}

#ifdef JULIA_ENABLE_THREADING
static inline void jl_lock_frame_push(jl_mutex_t *lock)
{
jl_ptls_t ptls = jl_get_ptls_states();
Expand All @@ -75,15 +74,6 @@ static inline void jl_lock_frame_pop(void)
ptls->current_task->locks.len--;
}
}
#else
static inline void jl_lock_frame_push(jl_mutex_t *lock)
{
(void)lock;
}
static inline void jl_lock_frame_pop(void)
{
}
#endif // ifndef JULIA_ENABLE_THREADING

#define JL_SIGATOMIC_BEGIN() do { \
jl_get_ptls_states()->defer_signal++; \
Expand Down Expand Up @@ -181,31 +171,11 @@ static inline void jl_mutex_init(jl_mutex_t *lock) JL_NOTSAFEPOINT
lock->count = 0;
}

#ifdef JULIA_ENABLE_THREADING
#define JL_MUTEX_INIT(m) jl_mutex_init(m)
#define JL_LOCK(m) jl_mutex_lock(m)
#define JL_UNLOCK(m) jl_mutex_unlock(m)
#define JL_LOCK_NOGC(m) jl_mutex_lock_nogc(m)
#define JL_UNLOCK_NOGC(m) jl_mutex_unlock_nogc(m)
#else // JULIA_ENABLE_THREADING
static inline void jl_mutex_check_type(jl_mutex_t *m) JL_NOTSAFEPOINT
{
(void)m;
}
#define JL_MUTEX_INIT(m) jl_mutex_check_type(m)
#define JL_LOCK(m) do { \
JL_SIGATOMIC_BEGIN(); \
jl_gc_enable_finalizers(jl_get_ptls_states(), 0); \
jl_mutex_check_type(m); \
} while (0)
#define JL_UNLOCK(m) do { \
jl_gc_enable_finalizers(jl_get_ptls_states(), 1); \
jl_mutex_check_type(m); \
JL_SIGATOMIC_END(); \
} while (0)
#define JL_LOCK_NOGC(m) jl_mutex_check_type(m)
#define JL_UNLOCK_NOGC(m) jl_mutex_check_type(m)
#endif // JULIA_ENABLE_THREADING

#ifdef __cplusplus
}
Expand Down
Loading