Description
For a thread calling this function, onload_thread_set_spin()
sets the per-thread spinning actions, it is
not per-stack and not per-socket.
Definition
int onload_thread_set_spin(enum onload_spin_type type, unsigned spin)
Formal Parameters
-
type
- Which operation to change the spin status of. The
type
must be one of the following:enum onload_spin_type { ONLOAD_SPIN_ALL, /* enable or disable all spin options */ ONLOAD_SPIN_UDP_RECV, ONLOAD_SPIN_UDP_SEND, ONLOAD_SPIN_TCP_RECV, ONLOAD_SPIN_TCP_SEND, ONLOAD_SPIN_TCP_ACCEPT, ONLOAD_SPIN_PIPE_RECV, ONLOAD_SPIN_PIPE_SEND, ONLOAD_SPIN_SELECT, ONLOAD_SPIN_POLL, ONLOAD_SPIN_PKT_WAIT, ONLOAD_SPIN_EPOLL_WAIT, ONLOAD_SPIN_STACK_LOCK, ONLOAD_SPIN_SOCK_LOCK, ONLOAD_SPIN_SO_BUSY_POLL, ONLOAD_SPIN_TCP_CONNECT, ONLOAD_SPIN_MIMIC_EF_POLL, /* thread spin configuration which mimics * spin settings in EF_POLL_USEC. Note * that this has no effect on the * usec-setting part of EF_POLL_USEC. * This needs to be set separately */ ONLOAD_SPIN_MAX /* special value to mark largest valid input */ };
-
spin
- A boolean which indicates whether the operation should spin or not.
Return Value
0 on success
-EINVAL if unsupported type is specified.
Notes
Spin time (for all threads) is set using the per-process EF_SPIN_USEC parameter.
Examples
The onload_thread_set_spin
API can be used to control spinning on a per-thread or per-API basis. The existing spin-related configuration options set the default behavior for threads, and the onload_thread_set_spin
API overrides the default for the thread calling this function.
- Disable All Sorts of Spinning
-
onload_thread_set_spin(ONLOAD_SPIN_ALL, 0);
- Enable All Sorts of Spinning
-
onload_thread_set_spin(ONLOAD_SPIN_ALL, 1);
- Enable Spinning only for Certain Threads
-
- Set the spin timeout by setting EF_SPIN_USEC, and disable spinning
by default by setting EF_POLL_USEC
=0
. - In each thread that should spin, invoke
onload_thread_set_spin()
.
- Set the spin timeout by setting EF_SPIN_USEC, and disable spinning
by default by setting EF_POLL_USEC
- Disable Spinning only in Certain Threads
-
- Enable spinning by setting
EF_POLL_USEC
=<timeout>
. - In each thread that should not spin, invoke
onload_thread_set_spin()
.
Important: If a thread is set to NOT spin and then blocks this might invoke an interrupt for the whole stack. Interrupts occurring on moderately busy threads can cause unintended and undesirable consequences. - Enable spinning by setting
EF_POLL_USEC
- Enable Spinning for UDP Traffic, but not TCP Traffic
-
- Set the spin timeout by setting EF_SPIN_USEC, and disable spinning
by default by setting EF_POLL_USEC
=0
. - In each thread that should spin (UDP only), do:
onload_thread_set_spin(ONLOAD_SPIN_UDP_RECV, 1) onload_thread_set_spin(ONLOAD_SPIN_UDP_SEND, 1)
- Set the spin timeout by setting EF_SPIN_USEC, and disable spinning
by default by setting EF_POLL_USEC
- Enable Spinning for TCP Traffic, but not UDP Traffic
-
- Set the spin timeout by setting EF_SPIN_USEC, and disable spinning
by default by setting EF_POLL_USEC
=0
. - In each thread that should spin (TCP only), do:
onload_thread_set_spin(ONLOAD_SPIN_TCP_RECV, 1) onload_thread_set_spin(ONLOAD_SPIN_TCP_SEND, 1) onload_thread_set_spin(ONLOAD_SPIN_TCP_ACCEPT, 1)
- Set the spin timeout by setting EF_SPIN_USEC, and disable spinning
by default by setting EF_POLL_USEC
Spinning and Sockets
When a thread calls onload_thread_set_spin()
it sets the spinning actions applied when the thread accesses any socket - irrespective of whether the socket is created by this thread.
If a socket is created by thread-A and is accessed by thread-B, calling onload_thread_set_spin(
ONLOAD_SPIN_ALL, 1)
only from thread-B will enable spinning for thread-B, but not for thread-A. In the same scenario, if onload_thread_set_spin(
ONLOAD_SPIN_ALL, 1)
is called only from thread-A, then spinning is enabled only for thread-A, but not for thread-B.
The onload_thread_set_spin()
function sets the per-thread spinning action.