From e67f2e89877988130101c8b4f9adcfe3148679d4 Mon Sep 17 00:00:00 2001 From: Kiran Pamnany Date: Tue, 3 Nov 2015 10:37:47 +0530 Subject: [PATCH] Threads: use new libuv thread calls Removed the pthread calls for thread creation and affinity setting and replaced them with libuv thread calls (from PR #31). --- .../md5 | 1 - .../sha512 | 1 - .../md5 | 1 + .../sha512 | 1 + deps/libuv.version | 2 +- src/threading.c | 53 ++++++------------- src/threading.h | 5 -- 7 files changed, 18 insertions(+), 46 deletions(-) delete mode 100644 deps/checksums/libuv-28f5f06b5ff6f010d666ec26552e0badaca5cdcd.tar.gz/md5 delete mode 100644 deps/checksums/libuv-28f5f06b5ff6f010d666ec26552e0badaca5cdcd.tar.gz/sha512 create mode 100644 deps/checksums/libuv-bfeafcf23c5fd85aa22eff4fc44fd7febbfd9b44.tar.gz/md5 create mode 100644 deps/checksums/libuv-bfeafcf23c5fd85aa22eff4fc44fd7febbfd9b44.tar.gz/sha512 diff --git a/deps/checksums/libuv-28f5f06b5ff6f010d666ec26552e0badaca5cdcd.tar.gz/md5 b/deps/checksums/libuv-28f5f06b5ff6f010d666ec26552e0badaca5cdcd.tar.gz/md5 deleted file mode 100644 index 4edee6e62e585..0000000000000 --- a/deps/checksums/libuv-28f5f06b5ff6f010d666ec26552e0badaca5cdcd.tar.gz/md5 +++ /dev/null @@ -1 +0,0 @@ -429c128e55147c8b43d6555fe406869b diff --git a/deps/checksums/libuv-28f5f06b5ff6f010d666ec26552e0badaca5cdcd.tar.gz/sha512 b/deps/checksums/libuv-28f5f06b5ff6f010d666ec26552e0badaca5cdcd.tar.gz/sha512 deleted file mode 100644 index 00006bb78791c..0000000000000 --- a/deps/checksums/libuv-28f5f06b5ff6f010d666ec26552e0badaca5cdcd.tar.gz/sha512 +++ /dev/null @@ -1 +0,0 @@ -c80390c970cebded5a444cabce95e80314f10c56aa59a37c67f9221ba69d1ebe8ece2d524abb71d83aa7d239e92149171bc2f7428f4efe9a7e259ab2b019b871 diff --git a/deps/checksums/libuv-bfeafcf23c5fd85aa22eff4fc44fd7febbfd9b44.tar.gz/md5 b/deps/checksums/libuv-bfeafcf23c5fd85aa22eff4fc44fd7febbfd9b44.tar.gz/md5 new file mode 100644 index 0000000000000..dfc9a1893856b --- /dev/null +++ b/deps/checksums/libuv-bfeafcf23c5fd85aa22eff4fc44fd7febbfd9b44.tar.gz/md5 @@ -0,0 +1 @@ +069718374ef9743add058379547ec7e4 diff --git a/deps/checksums/libuv-bfeafcf23c5fd85aa22eff4fc44fd7febbfd9b44.tar.gz/sha512 b/deps/checksums/libuv-bfeafcf23c5fd85aa22eff4fc44fd7febbfd9b44.tar.gz/sha512 new file mode 100644 index 0000000000000..8ac2fb08a7907 --- /dev/null +++ b/deps/checksums/libuv-bfeafcf23c5fd85aa22eff4fc44fd7febbfd9b44.tar.gz/sha512 @@ -0,0 +1 @@ +a8d170e6997b65ef3fe11679df7524c8271601f6e4d1c81edaa94c42110bf1b4b89ec98551226ece4435df672e89d924f9c375ccbd7921c1745f31a86c64cdc8 diff --git a/deps/libuv.version b/deps/libuv.version index 07dde31f2ac4d..b1acce0963c2a 100644 --- a/deps/libuv.version +++ b/deps/libuv.version @@ -1,2 +1,2 @@ LIBUV_BRANCH=julia-uv0.11.26 -LIBUV_SHA1=28f5f06b5ff6f010d666ec26552e0badaca5cdcd +LIBUV_SHA1=bfeafcf23c5fd85aa22eff4fc44fd7febbfd9b44 diff --git a/src/threading.c b/src/threading.c index 94a5a0fe9e80d..47c8d7d1717bb 100644 --- a/src/threading.c +++ b/src/threading.c @@ -99,39 +99,6 @@ uint64_t *user_ticks; uint64_t *join_ticks; #endif -// create a thread and affinitize it if proc_num is specified -int ti_threadcreate(uv_thread_t *thread_id, int proc_num, - void (*thread_fun)(void *), void *thread_arg) -{ -#ifdef _OS_LINUX_ - pthread_attr_t attr; - pthread_attr_init(&attr); - - cpu_set_t cset; - if (proc_num >= 0) { - CPU_ZERO(&cset); - CPU_SET(proc_num, &cset); - pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &cset); - } - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - return pthread_create(thread_id, &attr, thread_fun, thread_arg); -#else - return uv_thread_create(thread_id, thread_fun, thread_arg); -#endif -} - -// set thread affinity -void ti_threadsetaffinity(uint64_t thread_id, int proc_num) -{ -#ifdef _OS_LINUX_ - cpu_set_t cset; - - CPU_ZERO(&cset); - CPU_SET(proc_num, &cset); - pthread_setaffinity_np(thread_id, sizeof(cpu_set_t), &cset); -#endif -} - // thread function: used by all except the main thread void ti_threadfun(void *arg) { @@ -240,9 +207,9 @@ void jl_init_threading(void) void jl_start_threads(void) { - char *cp; + char *cp, mask[UV_CPU_SETSIZE]; int i, exclusive; - uv_thread_t ptid; + uv_thread_t uvtid; ti_threadarg_t **targs; // do we have exclusive use of the machine? default is no @@ -254,8 +221,12 @@ void jl_start_threads(void) // exclusive use: affinitize threads, master thread on proc 0, rest // according to a 'compact' policy // non-exclusive: no affinity settings; let the kernel move threads about - if (exclusive) - ti_threadsetaffinity(uv_thread_self(), 0); + if (exclusive) { + memset(mask, 0, UV_CPU_SETSIZE); + mask[0] = 1; + uvtid = (uv_thread_t)uv_thread_self(); + uv_thread_setaffinity(&uvtid, mask, NULL, UV_CPU_SETSIZE); + } // create threads targs = malloc((jl_n_threads - 1) * sizeof (ti_threadarg_t *)); @@ -263,7 +234,13 @@ void jl_start_threads(void) targs[i] = (ti_threadarg_t *)malloc(sizeof (ti_threadarg_t)); targs[i]->state = TI_THREAD_INIT; targs[i]->tid = i + 1; - ti_threadcreate(&ptid, exclusive ? i+1 : -1, ti_threadfun, targs[i]); + uv_thread_create(&uvtid, ti_threadfun, targs[i]); + if (exclusive) { + memset(mask, 0, UV_CPU_SETSIZE); + mask[i+1] = 1; + uv_thread_setaffinity(&uvtid, mask, NULL, UV_CPU_SETSIZE); + } + uv_thread_detach(&uvtid); } // set up the world thread group diff --git a/src/threading.h b/src/threading.h index c719b0b11392c..8b1b803bab636 100644 --- a/src/threading.h +++ b/src/threading.h @@ -57,11 +57,6 @@ typedef struct { } ti_threadwork_t; -// basic functions for thread creation -int ti_threadcreate(uv_thread_t *thread_id, int proc_num, - void (*thread_fun)(void *), void *thread_arg); -void ti_threadsetaffinity(uint64_t thread_id, int proc_num); - // thread function void ti_threadfun(void *arg);