How are netlink sockets in the Linux kernel different from polling from userland?
Asked Answered
G

1

4

I have doubt about the functioning of netlink socket in kernel-application interaction context. As I have read that netlink socket is used for event based notification from kernel to application. The benefit of this is Application is not required to poll.

But as in case of netlink socket also, it will also be polling finally to check whether some data has been sent from kernel. So my question is, how this functioning of netlink socket is different from Polling of file decriptor? I refered this but it tells how to use netlink, not the difference between netlink socket and polling.

Gaskins answered 24/5, 2013 at 3:23 Comment(1)
The poll() function call is different from hardware polling. It is quite possible that many read() will return of -1; Contrast edge-triggered versus continually reading an I/O value. What ever you read may not be referring to poll(), the system call.Raddatz
L
2

For applications, the behaviour of netlink sockets and other device files is mostly similar (i.e., calling poll and read).

You would use netlink if you need one of netlink's features (such as multicast) or if your driver becomes easier to implement (the kernel-side API is more similar to a socket and has built-in buffering) because you don't you have to write the file operations yourself.

Lanky answered 24/5, 2013 at 7:13 Comment(6)
how multicast will make any difference? As if kernel sends multicast to applications or those application keep on polling on the device file, ultimately it is same, isn't it ?Gaskins
Multicast has nothing to do with the interface at any single endpoint.Lanky
Actually I want to know what makes netlink socket more preferable than polling. I checked code of UeventObserver.java as well as uevent.c from platform side. there is one while loop in both files, which keep on checking for the event. So how it is good, why kernel developers preferred netlink socket over any other proc or sysfs file system to communicate ?Gaskins
This is explained in Why and How to Use Netlink Socket.Lanky
Thanks for staying with this question :) .. but one more thing, in the same link there is a paragraph it says "Normally, applications periodically need to poll the kernel to get the state changes, although intensive polling is expensive. Netlink solves this problem gracefully by allowing the kernel to initiate sessions too" even though it allows toinitiate the session, ultimately application will end up polling for socket. so in that scenario how we can say with netlink socket we are skipping intense polling.Gaskins
A call to poll just waits. What this article means with "polling" is to check the status regularly.Lanky

© 2022 - 2024 — McMap. All rights reserved.