[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Receiving Network Packets with Mirage/kFreeBSD
Hello there, For your information, I have just added support for receiving network packets to the kFreeBSD backend of mirage-platform: https://github.com/pgj/mirage-kfreebsd/commit/c10b740218fd0af10e7b8e424d4cdde191edb251 Note that there is also a basic/netif test added to mirage-test/regress to try this out and see it in action. I would like to call for your reviews and comments. To narrate on the design choices I made, here is a brief summary on how the current implementation looks like at the moment. - After loading the built kernel module and starting up the evaluation of the Netif.create function, Mirage asks for a list of available Ethernet interfaces from the FreeBSD kernel and then assigns an lwt thread to each of them by "plugging". - Plugged interfaces are stored in a linked list and have their ng_ether(4) hook (called from ether_input()) activated and pointed to netif_ether_input(). At the same time, there is a shared ring buffer created for each of them in Mirage then passed to the C function responsible for administering the list of plugged interfaces, caml_plug_vif(). - Shared ring buffers are created as Io_pages by allocating page-aligned, contiguous, multi-page memory areas via FreeBSD's contigmalloc(9). These are directly accessible in Mirage as character arrays. - Each shared ring buffer is currently of size 33 pages, and operates with 2048-byte slots. The buffers start with a header that maintains all the required meta information, like next position, available items, size of stored items. - Each packet arriving on any of the plugged interfaces is placed to the next available slot of the corresponding shared ring buffer with m_copydata(). - In parallel with this in Mirage, the rx_poll function is run in loop that polls for available packets in the shared ring buffer. - When rx_poll finds unprocessed packets then it runs the user-specified function on them, e.g. print the size of the packet in basic/netif. It is implemented by passing a view on the Io_page, i.e. without copying. After the user function has finished, the packet is removed from the ring. - When no packets are available on the polled interface, rx_poll sleeps for a millisecond. - Mirage is stopped when the kernel module is unloaded, which also involves unplugging the interfaces. Let me add that shared rings do not do locking at the moment, but if you are happy with the design I could proceed with implementing it. (However, I am not completely sure how to share locks between OCaml and C.)
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |