LWN.net Logo

Advertisement

E-Commerce & credit card processing - the Open Source way!

Advertise here

I want some of them callbacks!

I want some of them callbacks!

Posted Oct 31, 2002 11:01 UTC (Thu) by zooko (subscriber, #2589)
Parent article: sys_epoll - making poll fast

I don't understand why the callbacks aren't propagated to userland. All of my code which uses select() or poll() style interfaces immediately invokes callbacks based on which fds have changed, so if my code ran on top of epoll(), then the sequence of events would look like this:

  • the socket activity would cause callbacks
  • which would be intercepted by the epoll() system
  • which would update the data structure and then return from epoll_wait(),
  • where my userland code would crawl the data structure and invoke callbacks for each changed thing,
  • where higher-level application code would then receive the callbacks.

Doesn't this seem unnecessarily complicated, not to mention less efficient? Is it too tricky to have the kernel change to user context and invoke a function pointer that I have given it?

Regards,

Zooko


(Log in to post comments)

I want some of them callbacks!

Posted Oct 31, 2002 13:24 UTC (Thu) by IkeTo (subscriber, #2122) [Link]

Hmm... that seems to be as difficult to use as signals. The function that you want to use is never in the list of async signal-safe functions, and you application will always have race condition using signals unless your application uses the call in a very limited way: your main application must do basically nothing, and your application must block basically every signal (and wait for signals using sigwait() or sigsuspend()). That means... you'll have to create system calls similar to those to deal with signals, and then to setup a huge size set for suspending file descriptor callbacks. Not to mention that pushing some code to the user is not something that a kernel developers would like to do unless absolutely needed. Doesn't seem to be exactly exciting for this type of optimization which is constant-time anyway.

I want some of them callbacks!

Posted Oct 31, 2002 20:56 UTC (Thu) by zooko (subscriber, #2589) [Link]

I think there is an interesting disconnect between the low-level hackers and the higher level network/application level hackers here. A lot of the interesting projects that I know of (not to mention the ones that I lead myself: Mnet), use select()/poll() interfaces exactly as I've described above -- as nothing more than a way to get at the callbacks which they then immediately de-multiplex back into callbacks. The projects I'm thinking of here are things like Twisted, and E (although the current E implementation doesn't use kernel calls, as it is in Java...).

Regards,

Zooko

I want some of them callbacks!

Posted Nov 2, 2002 21:15 UTC (Sat) by bronson (subscriber, #4806) [Link]

Maybe IkeTo gave too comprehensive an answer...

Is it too tricky to have the kernel change to user context and invoke a function pointer that I have given it?

Yes.

Whenever the kernel calls user code directly, non-obvious and non-trivial race conditions result. It's a very difficult problem. Much easier to just have the system call return, and then the user can deal with the callbacks however she/he wants.

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds