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.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Rahul
  • 1,607
  • 3
  • 23
  • 41
  • 1
    The `poll()` function call is different from [hardware polling](http://en.wikipedia.org/wiki/Polling_%28computer_science%29). 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. – artless noise May 25 '13 at 20:01

1 Answers1

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.

CL.
  • 173,858
  • 17
  • 217
  • 259
  • 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 ? – Rahul May 24 '13 at 10:40
  • Multicast has nothing to do with the interface at any single endpoint. – CL. May 24 '13 at 10:56
  • 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 ? – Rahul May 24 '13 at 12:42
  • This is explained in [Why and How to Use Netlink Socket](http://www.linuxjournal.com/article/7356). – CL. May 24 '13 at 12:52
  • 1
    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. – Rahul May 24 '13 at 13:43
  • 1
    A call to `poll` just waits. What this article means with "polling" is to check the status regularly. – CL. May 24 '13 at 14:22