smt_pause, smt_nano_pause - busy wait idle function
#include <synch.h> void smt_pause(void); void smt_nano_pause(hrtime_t nsec);
The smt_pause() and smt_nano_pause() functions are recommended for use in busy wait loops to lessen the impact the loop has on the rest of the system. For example, on CMT systems they enable other hardware strands sharing the core to go faster during the busy wait.
The smt_pause() function delays for a short implementation-dependent period before returning to the caller, consuming as few processor resources as possible.
The smt_nano_pause() function also delays while conserving processor resources but takes the nsec argument to specify the elapsed time of the pause in nanoseconds. The elapsed time will be at least the number of nanoseconds specified and may be greater. The calling thread remains scheduled on the current CPU from an operating system point of view. If the pause duration is expected to be longer than the minimum duration of calls that block such as nanosleep(3C) or poll(2), then overall thread utilization may be improved by using those calls instead.
The smt_nano_pause() function has no effect on the action or blockage of any signal, and will continue pausing after returning from a signal handler.
The usage of smt_pause() function is as follows:
volatile int *wait; while (*wait == 1) smt_pause();
The smt_nano_pause() function might be used in an exponential backoff algorithm:
volatile int *wait; hrtime_t backoff = 20; while (*wait == 1) { if (backoff > 10000000) /* 0.01 seconds */ poll(0, 0, backoff / 1000000); else smt_nano_pause(backoff); backoff *= 2; }
See attributes(5) for descriptions of the following attributes:
|