From b68e846fa236b7b7beeb23a84108fb713272440d Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 27 Aug 2010 19:39:42 -0700 Subject: [PATCH] kernel - Adjust contention handler * Simplify handle_cpu_contention_mask() a little. For vkernels we call pthread_yield(). * Just call cpu_pause() in cpu_spinlock_contested(). Don't do anything fancier, the routine is called as part of the exponential backoff code. --- sys/platform/pc32/i386/machdep.c | 4 +--- sys/platform/pc64/x86_64/machdep.c | 7 ++++++- sys/platform/vkernel/i386/cpu_regs.c | 12 +++--------- sys/platform/vkernel64/x86_64/cpu_regs.c | 11 ++++------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/sys/platform/pc32/i386/machdep.c b/sys/platform/pc32/i386/machdep.c index 3a0c741d30..1ccf9b0779 100644 --- a/sys/platform/pc32/i386/machdep.c +++ b/sys/platform/pc32/i386/machdep.c @@ -954,10 +954,8 @@ handle_cpu_contention_mask(void) mask = cpu_contention_mask; cpu_ccfence(); - if (mask && bsfl(mask) != mycpu->gd_cpuid) { - cpu_pause(); + if (mask && bsfl(mask) != mycpu->gd_cpuid) DELAY(2); - } } /* diff --git a/sys/platform/pc64/x86_64/machdep.c b/sys/platform/pc64/x86_64/machdep.c index 22438fb18e..426462d336 100644 --- a/sys/platform/pc64/x86_64/machdep.c +++ b/sys/platform/pc64/x86_64/machdep.c @@ -975,7 +975,12 @@ cpu_idle(void) void handle_cpu_contention_mask(void) { - cpu_pause(); + cpumask_t mask; + + mask = cpu_contention_mask; + cpu_ccfence(); + if (mask && bsfl(mask) != mycpu->gd_cpuid) + DELAY(2); } /* diff --git a/sys/platform/vkernel/i386/cpu_regs.c b/sys/platform/vkernel/i386/cpu_regs.c index dc98099fe4..442a3d8d36 100644 --- a/sys/platform/vkernel/i386/cpu_regs.c +++ b/sys/platform/vkernel/i386/cpu_regs.c @@ -109,6 +109,7 @@ #include #include #include /* umtx_* functions */ +#include /* pthread_yield */ extern void dblfault_handler (void); @@ -784,11 +785,8 @@ handle_cpu_contention_mask(void) mask = cpu_contention_mask; cpu_ccfence(); - if (mask && bsfl(mask) != mycpu->gd_cpuid) { - cpu_pause(); - usleep(1000); - } - /* usleep(1000); */ + if (mask && bsfl(mask) != mycpu->gd_cpuid) + pthread_yield(); } /* @@ -802,10 +800,6 @@ void cpu_spinlock_contested(void) { cpu_pause(); - /* - crit_enter(); - usleep(1000); - crit_exit();*/ } #endif diff --git a/sys/platform/vkernel64/x86_64/cpu_regs.c b/sys/platform/vkernel64/x86_64/cpu_regs.c index 03e347bab6..fe6a46b562 100644 --- a/sys/platform/vkernel64/x86_64/cpu_regs.c +++ b/sys/platform/vkernel64/x86_64/cpu_regs.c @@ -106,6 +106,7 @@ #include #include #include /* umtx_* functions */ +#include /* pthread_yield() */ extern void dblfault_handler (void); @@ -778,10 +779,8 @@ handle_cpu_contention_mask(void) mask = cpu_contention_mask; cpu_ccfence(); - if (mask && bsfl(mask) != mycpu->gd_cpuid) { - cpu_pause(); - usleep(1000); - } + if (mask && bsfl(mask) != mycpu->gd_cpuid) + pthread_yield(); } /* @@ -794,9 +793,7 @@ handle_cpu_contention_mask(void) void cpu_spinlock_contested(void) { - crit_enter(); - usleep(1000); - crit_exit(); + cpu_pause(); } #endif -- 2.41.0