20250725-wc_linuxkm_relax_long_loop: improvements from peer review: fix, clarify, and extend comments, improve indentation, and snip out a stray redundant preprocessor definition.

This commit is contained in:
Daniel Pouzzner
2025-07-26 08:27:43 -05:00
parent 77dccc0c32
commit b0f6829614
2 changed files with 17 additions and 10 deletions

View File

@@ -360,7 +360,7 @@
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
/* for signal_pending() */ /* for signal_pending() */
#include <linux/sched/signal.h> #include <linux/sched/signal.h>
/* for sched_clock_cpu() */ /* for local_clock() */
#include <linux/sched/clock.h> #include <linux/sched/clock.h>
#endif #endif
#include <linux/random.h> #include <linux/random.h>
@@ -545,7 +545,6 @@
#elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) #elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS)
#error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unsupported architecture. #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 */ #endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */
_Pragma("GCC diagnostic pop"); _Pragma("GCC diagnostic pop");

View File

@@ -219,7 +219,7 @@ int wc_linuxkm_check_for_intr_signals(void) {
if (sigismember(&current->pending.signal, intr_signals[i])) { if (sigismember(&current->pending.signal, intr_signals[i])) {
#ifdef WOLFSSL_LINUXKM_VERBOSE_DEBUG #ifdef WOLFSSL_LINUXKM_VERBOSE_DEBUG
pr_err("INFO: wc_linuxkm_check_for_intr_signals returning " 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 #endif
return INTERRUPTED_E; return INTERRUPTED_E;
} }
@@ -234,15 +234,23 @@ void wc_linuxkm_relax_long_loop(void) {
#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(); 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 now = local_clock();
u64 current_last_arrival = current->sched_info.last_arrival; u64 current_last_arrival = current->sched_info.last_arrival;
s64 delta = (s64)(now - current_last_arrival); s64 delta = (s64)(now - current_last_arrival);
if (delta > WC_LINUXKM_MAX_NS_WITHOUT_YIELD) { if (delta > WC_LINUXKM_MAX_NS_WITHOUT_YIELD) {
cond_resched(); 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 * doesn't even update .last_arrival. we could force update by
* sleeping, but there's no need. we've been nice enough by just * 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