Context :
Debian 64 bits.
Making a linux-only userspace networking stack that I may release open source.
Everything is ready but one last thing.
The problem :
I know about poll
/select
/epoll
and use them heavily already but they are too complicated for my need and tend to add latency (few nanoseconds -> too much).
The need :
A simple mean to notify from the kernel to an application that packets are to be processed and the reverse with a shared mmap
file operating as a multi-ring buffer. It would obviously not incur a context-switch.
I wrote a custom driver for my NIC (and plan to create others for the big league -> 1-10Gb).
I would like two shared arrays of int
and two shared arrays of char
. I have the multiprocess and non blocking design already working.
A peer (int and char) for the kernel -> app direction; another for app -> kernel.
But how to notify at the very moment mmap
has changed. I read a msync
would do it but it is slow too. That is my problem.
Mutexes lead to dead slow code. Spinlocks tend to waste cpu cycles on overload.
Not talking about a busy while(1)
loop always reading -> cpu cycles waste.
What do you recommend ?
It is my last step.
Thanks
Update:
I think i will have to pay the latency of setting the interrupt mask anyway. So it should ideally be amortized by the number of incoming packets during that required latency. The first few packets after a burst will always be slower i guess since i obviously don't infinite loop.
The worst case would be that packets are sparse to come (hence why seeking saturating link performance at the first place). That worts case will be met at times. But who cares, it is still faster than the stock kernel anyway. Trade-offs trade-offs :)