From f1db56fcd77e3479f8bea9047b83b3757a805567 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sun, 8 Jan 2017 23:05:55 +0100 Subject: [PATCH 1/2] Replace sched_yield with usleep(1) on Linux to avoid the massive overhead of the sched_yield call on Linux kernels since its semantics were changed in early 2003 (late 2.5 series) to include reordering of the thread queue. Ref. #900,#923 --- common.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common.h b/common.h index 480174c11..e728b9ef3 100644 --- a/common.h +++ b/common.h @@ -313,6 +313,10 @@ typedef int blasint; #if defined(OS_SUNOS) #define YIELDING thr_yield() #endif + +#if defined(OS_LINUX) +#define YIELDING usleep(1) +#endif #if defined(OS_WINDOWS) #if defined(_MSC_VER) && !defined(__clang__) From fb31c8154d9b7491d2487468783960bb3f10d61d Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Wed, 11 Jan 2017 23:36:04 +0100 Subject: [PATCH 2/2] Replace sched_yield on Linux with nop instruction --- common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.h b/common.h index e728b9ef3..d973e44c8 100644 --- a/common.h +++ b/common.h @@ -315,7 +315,7 @@ typedef int blasint; #endif #if defined(OS_LINUX) -#define YIELDING usleep(1) +#define YIELDING __asm__ __volatile__ ("nop;nop;nop;nop;nop;nop;nop;nop;\n"); #endif #if defined(OS_WINDOWS)