* Signal from kernel space to user space @ 2009-12-01 11:07 Mai Daftedar 2009-12-01 13:30 ` Clemens Ladisch 0 siblings, 1 reply; 7+ messages in thread From: Mai Daftedar @ 2009-12-01 11:07 UTC (permalink / raw) To: linux-kernel Hi everyone Im still new to the kernel development world :)and I was wondering what functions I can use in the kernel space for a signal to be sent to the userspace I tryed a number of examples I found after I did some googling that used the API "send_sig_info" however nothing worked :( Any help would be appreciated Can you please CC me in the reply to this mail Thanks Mai ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Signal from kernel space to user space 2009-12-01 11:07 Signal from kernel space to user space Mai Daftedar @ 2009-12-01 13:30 ` Clemens Ladisch 2009-12-01 15:18 ` Mark Hounschell 0 siblings, 1 reply; 7+ messages in thread From: Clemens Ladisch @ 2009-12-01 13:30 UTC (permalink / raw) To: Mai Daftedar; +Cc: linux-kernel Mai Daftedar wrote: > Im still new to the kernel development world :)and I was wondering > what functions I can use in the kernel space for a signal to be sent > to the userspace kill_pid_(info) is to be preferred over send_sig_info because it ensures that the destination process has the same identity (a plain pid number might have wrappend around and be in use by another process). However, why are you using a signal? What information are you trying to send, and why wouldn't eventfd or a plain device thaz becomes readable be a better solution? > I tryed a number of examples I found after I did some googling that > used the API "send_sig_info" however nothing worked :( Because something in that code is wrong. I can't tell you more about the details because my crystal ball is in repair. Best regards, Clemens ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Signal from kernel space to user space 2009-12-01 13:30 ` Clemens Ladisch @ 2009-12-01 15:18 ` Mark Hounschell 2009-12-01 18:05 ` Davide Libenzi 2009-12-02 12:28 ` Clemens Ladisch 0 siblings, 2 replies; 7+ messages in thread From: Mark Hounschell @ 2009-12-01 15:18 UTC (permalink / raw) To: Clemens Ladisch; +Cc: Mai Daftedar, linux-kernel Clemens Ladisch wrote: > Mai Daftedar wrote: >> Im still new to the kernel development world :)and I was wondering >> what functions I can use in the kernel space for a signal to be sent >> to the userspace > I have some interest in this. Might I inject a couple of probably stupid related questions? > kill_pid_(info) is to be preferred over send_sig_info because it ensures > that the destination process has the same identity (a plain pid number > might have wrappend around and be in use by another process). > Does that mean I can't assume my process pid will unique for the life of the process? > However, why are you using a signal? What information are you trying to > send, and why wouldn't eventfd or a plain device thaz becomes readable > be a better solution? > If no "information" is required, which of these are the fastest, say from an interrupt handler? I have a PCI card that handles external interrupts from the outside world and does nothing but report those external interrupts to userland. We use send_sig or wake_up_process depending on whether userland is going to wait for it or not. If there is a better/faster way I would be very interested. Thanks and sorry for butting in Mark ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Signal from kernel space to user space 2009-12-01 15:18 ` Mark Hounschell @ 2009-12-01 18:05 ` Davide Libenzi [not found] ` <2cd4ff050912020309j6e7c0ae9n89c011889b09f3e1@mail.gmail.com> 2009-12-02 12:28 ` Clemens Ladisch 1 sibling, 1 reply; 7+ messages in thread From: Davide Libenzi @ 2009-12-01 18:05 UTC (permalink / raw) To: Mark Hounschell; +Cc: Clemens Ladisch, Mai Daftedar, linux-kernel On Tue, 1 Dec 2009, Mark Hounschell wrote: > If no "information" is required, which of these are the fastest, say from an interrupt handler? > I have a PCI card that handles external interrupts from the outside world and does nothing but > report those external interrupts to userland. We use send_sig or wake_up_process depending > on whether userland is going to wait for it or not. If there is a better/faster way I would be > very interested. eventfd is. eventfd_signal() is also callable from non-sleeping contexts. - Davide ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <2cd4ff050912020309j6e7c0ae9n89c011889b09f3e1@mail.gmail.com>]
* Re: Signal from kernel space to user space [not found] ` <2cd4ff050912020309j6e7c0ae9n89c011889b09f3e1@mail.gmail.com> @ 2009-12-02 11:26 ` Mai Daftedar 0 siblings, 0 replies; 7+ messages in thread From: Mai Daftedar @ 2009-12-02 11:26 UTC (permalink / raw) To: Davide Libenzi; +Cc: Mark Hounschell, Clemens Ladisch, linux-kernel Thanks all for the help, I needed to use signals just as interrupt signal from the kernel space so that when a certain change occurs I'd be notified in the userspace I used send_sig _info and it worked :)..The problem was with the signal number I using a wong one.. Thanks > On Tue, Dec 1, 2009 at 8:05 PM, Davide Libenzi <davidel@xmailserver.org> wrote: >> >> On Tue, 1 Dec 2009, Mark Hounschell wrote: >> >> > If no "information" is required, which of these are the fastest, say from an interrupt handler? >> > I have a PCI card that handles external interrupts from the outside world and does nothing but >> > report those external interrupts to userland. We use send_sig or wake_up_process depending >> > on whether userland is going to wait for it or not. If there is a better/faster way I would be >> > very interested. >> >> eventfd is. eventfd_signal() is also callable from non-sleeping contexts. >> >> >> - Davide >> >> > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Signal from kernel space to user space 2009-12-01 15:18 ` Mark Hounschell 2009-12-01 18:05 ` Davide Libenzi @ 2009-12-02 12:28 ` Clemens Ladisch 2009-12-03 14:36 ` Eric W. Biederman 1 sibling, 1 reply; 7+ messages in thread From: Clemens Ladisch @ 2009-12-02 12:28 UTC (permalink / raw) To: markh; +Cc: Mai Daftedar, linux-kernel Mark Hounschell wrote: > Clemens Ladisch wrote: > > kill_pid_(info) is to be preferred over send_sig_info because it ensures > > that the destination process has the same identity (a plain pid number > > might have wrappend around and be in use by another process). > > Does that mean I can't assume my process pid will unique for the life of the process? The pid _does_ uniquely identify your process. However, after the process has died, it could be used for some new process, and send_sig_info would happily kill the new process. > > However, why are you using a signal? What information are you trying to > > send, and why wouldn't eventfd or a plain device thaz becomes readable > > be a better solution? > > If no "information" is required, which of these are the fastest, say > from an interrupt handler? If there really is no information, doing nothing would be fastest. ;-) If you want to tell userland that some event has happened, the various mechanisms are not much different as far as the kernel is concerned, as long as you don't have many thousands of events per seconds; the biggest problems for event delivery are scheduling the userland process for execution and handling of the event. Signals handlers interrupt any other userland code and therefore are not allowed to do much; therefore, I would strongly prefer to use some file handle that can be waited on with poll(). Furthermore, poll() allows to wait for multiple handles, and does not have the complexities of signal delivery and blocking. I would use signals only if the handler must interrupt any other running code, and if the signal can be handled completely without running into reentrancy problems. It is possible to handle signals with poll() by using signalfd, but when designing a new interface, one could just use eventfd instead. Best regards, Clemens ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Signal from kernel space to user space 2009-12-02 12:28 ` Clemens Ladisch @ 2009-12-03 14:36 ` Eric W. Biederman 0 siblings, 0 replies; 7+ messages in thread From: Eric W. Biederman @ 2009-12-03 14:36 UTC (permalink / raw) To: Clemens Ladisch; +Cc: markh, Mai Daftedar, linux-kernel Clemens Ladisch <clemens@ladisch.de> writes: > Mark Hounschell wrote: >> Clemens Ladisch wrote: >> > kill_pid_(info) is to be preferred over send_sig_info because it ensures >> > that the destination process has the same identity (a plain pid number >> > might have wrappend around and be in use by another process). >> >> Does that mean I can't assume my process pid will unique for the life of the process? > > The pid _does_ uniquely identify your process. However, after the > process has died, it could be used for some new process, and > send_sig_info would happily kill the new process. send_sig_info isn't that bad as it takes a task struct. Plain pid_t's are just broken to use. A pid_t uniquely identifies a process within a pid namespace, not within all of the pid namespaces present on the kernel. >> > However, why are you using a signal? What information are you trying to >> > send, and why wouldn't eventfd or a plain device thaz becomes readable >> > be a better solution? >> >> If no "information" is required, which of these are the fastest, say >> from an interrupt handler? > > If there really is no information, doing nothing would be fastest. ;-) That or simply waking up the task. > If you want to tell userland that some event has happened, the various > mechanisms are not much different as far as the kernel is concerned, > as long as you don't have many thousands of events per seconds; the > biggest problems for event delivery are scheduling the userland process > for execution and handling of the event. > > Signals handlers interrupt any other userland code and therefore are > not allowed to do much; therefore, I would strongly prefer to use > some file handle that can be waited on with poll(). Furthermore, > poll() allows to wait for multiple handles, and does not have the > complexities of signal delivery and blocking. I would use signals only > if the handler must interrupt any other running code, and if the signal > can be handled completely without running into reentrancy problems. Plus signals have all kinds of weird latency and overhead. Outside of core kernel code, or subsystems where they are already used I would be surprised if signals could be done correctly and usefully. pid rollover isn't the only hidden gotcha. Eric ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-12-03 14:37 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-01 11:07 Signal from kernel space to user space Mai Daftedar
2009-12-01 13:30 ` Clemens Ladisch
2009-12-01 15:18 ` Mark Hounschell
2009-12-01 18:05 ` Davide Libenzi
[not found] ` <2cd4ff050912020309j6e7c0ae9n89c011889b09f3e1@mail.gmail.com>
2009-12-02 11:26 ` Mai Daftedar
2009-12-02 12:28 ` Clemens Ladisch
2009-12-03 14:36 ` Eric W. Biederman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox