diff --git a/linuxkm/linuxkm_wc_port.h b/linuxkm/linuxkm_wc_port.h index 3e6035980..78dbdb84d 100644 --- a/linuxkm/linuxkm_wc_port.h +++ b/linuxkm/linuxkm_wc_port.h @@ -360,7 +360,7 @@ #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) /* for signal_pending() */ #include - /* for sched_clock_cpu() */ + /* for local_clock() */ #include #endif #include @@ -545,7 +545,6 @@ #elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) #error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unsupported architecture. - #define RESTORE_VECTOR_REGISTERS() WC_RELAX_LONG_LOOP(); #endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */ _Pragma("GCC diagnostic pop"); diff --git a/linuxkm/module_hooks.c b/linuxkm/module_hooks.c index 18a8887a7..e0674868a 100644 --- a/linuxkm/module_hooks.c +++ b/linuxkm/module_hooks.c @@ -219,7 +219,7 @@ int wc_linuxkm_check_for_intr_signals(void) { if (sigismember(¤t->pending.signal, intr_signals[i])) { #ifdef WOLFSSL_LINUXKM_VERBOSE_DEBUG pr_err("INFO: wc_linuxkm_check_for_intr_signals returning " - "-EINTR on signal %d\n", intr_signals[i]); + "INTERRUPTED_E on signal %d\n", intr_signals[i]); #endif return INTERRUPTED_E; } @@ -229,25 +229,33 @@ int wc_linuxkm_check_for_intr_signals(void) { } void wc_linuxkm_relax_long_loop(void) { -#if WC_LINUXKM_MAX_NS_WITHOUT_YIELD >= 0 + #if WC_LINUXKM_MAX_NS_WITHOUT_YIELD >= 0 if (preempt_count() == 0) { -#if (WC_LINUXKM_MAX_NS_WITHOUT_YIELD == 0) || !defined(CONFIG_SCHED_INFO) + #if (WC_LINUXKM_MAX_NS_WITHOUT_YIELD == 0) || !defined(CONFIG_SCHED_INFO) cond_resched(); -#else + #else + /* note that local_clock() wraps a local_clock_noinstr() in a + * preempt_disable_notrace(), which sounds expensive but isn't -- + * preempt_disable_notrace() is actually just a nonlocking integer + * increment of current_thread_info()->preempt.count, protected only by + * various compiler optimizer barriers. + */ u64 now = local_clock(); u64 current_last_arrival = current->sched_info.last_arrival; s64 delta = (s64)(now - current_last_arrival); if (delta > WC_LINUXKM_MAX_NS_WITHOUT_YIELD) { cond_resched(); - /* note, if nothing else is runnable, cond_resched() is a no-op and + /* if nothing else is runnable, cond_resched() is a no-op and * doesn't even update .last_arrival. we could force update by * sleeping, but there's no need. we've been nice enough by just - * cond_resched()ing. + * cond_resched()ing, and it's actually preferable to call + * cond_resched() frequently once computation has looped + * continuously for longer than WC_LINUXKM_MAX_NS_WITHOUT_YIELD. */ } -#endif + #endif } -#endif + #endif } #if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)