2
votes

Any suggestions for a function like udelay in linux/delay.h that can be used in user-space?

From userspace, I'd like to generate events every 10s of mircoseconds. Accuracy isn't super important, but I'd like to get it as close as possible. Things like usleep don't work because the context switching overhead. Right now I have a busy-waiting loop that uses clock_gettime with the CLOCK_MONOTONIC clock that constantly compares current time to the time before starting the loop and returning once the number of microseconds passed has elapsed. It works much better than using usleep, but can I get any better without writing kernel code (or switching to a real-time linux)? Thanks.

1
Linux kernel implements some delay and sleep functions for kernel threads, and any delay or sleep implementation of less than 10 us is realized by the busy looping. So even the kernel docs suggest the busy waiting for delays less than 10us, how could the user-space find better methods. - foool

1 Answers

1
votes

select(2) with a timeout and no FDs should be a decent alternative. Just remember to initialize the timeout each time before calling.