LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Best method for sending messages to user space?
@ 2008-10-21 17:54 Timur Tabi
  2008-10-21 18:14 ` Dan Williams
  0 siblings, 1 reply; 6+ messages in thread
From: Timur Tabi @ 2008-10-21 17:54 UTC (permalink / raw)
  To: linux-kernel, Kumar Gala

I have a driver that provides services for a hypervisor that my company is
creating.  The hypervisor can send notifications to the driver via interrupts.
I want to send a message to user space whenever the driver receives one of the
interrupts.  The messages don't have any payload.

Should I be creating kobjects and using kobject_uevent(..., KOBJ_CHANGE) to send
these messages?  I want to take advantage of the standard (hotplug?) user-space
interface for this sort of thing, so that I don't need to have a custom-written
daemon running that waits on blocking ioctl calls.

-- 
Timur Tabi
Linux kernel developer at Freescale

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Best method for sending messages to user space?
  2008-10-21 17:54 Best method for sending messages to user space? Timur Tabi
@ 2008-10-21 18:14 ` Dan Williams
  2008-10-21 19:43   ` Timur Tabi
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Williams @ 2008-10-21 18:14 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linux-kernel, Kumar Gala

On Tue, Oct 21, 2008 at 10:54 AM, Timur Tabi <timur@freescale.com> wrote:
> I have a driver that provides services for a hypervisor that my company is
> creating.  The hypervisor can send notifications to the driver via interrupts.
> I want to send a message to user space whenever the driver receives one of the
> interrupts.  The messages don't have any payload.
>
> Should I be creating kobjects and using kobject_uevent(..., KOBJ_CHANGE) to send
> these messages?  I want to take advantage of the standard (hotplug?) user-space
> interface for this sort of thing, so that I don't need to have a custom-written
> daemon running that waits on blocking ioctl calls.
>

I really like the sysfs_notify() approach that Neil Brown has put
together for delivering md-raid events.  Now with 2.6.28 you will be
able do this from an atomic context with sysfs_notify_dirent() [1].

--
Dan

[1] http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=f1282c84

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Best method for sending messages to user space?
  2008-10-21 18:14 ` Dan Williams
@ 2008-10-21 19:43   ` Timur Tabi
  2008-10-21 20:16     ` Dan Williams
  0 siblings, 1 reply; 6+ messages in thread
From: Timur Tabi @ 2008-10-21 19:43 UTC (permalink / raw)
  To: Dan Williams; +Cc: linux-kernel, Kumar Gala

Dan Williams wrote:

> I really like the sysfs_notify() approach that Neil Brown has put
> together for delivering md-raid events.

Is there any documentation for sysfs_notify?  It doesn't appear to do anything
whenever I call it.

>  Now with 2.6.28 you will be
> able do this from an atomic context with sysfs_notify_dirent() [1].

That sounds like something I could use.

Kumar, can you update the repository I'm using to include sysfs_notify_dirent()?

-- 
Timur Tabi
Linux kernel developer at Freescale

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Best method for sending messages to user space?
  2008-10-21 19:43   ` Timur Tabi
@ 2008-10-21 20:16     ` Dan Williams
  2008-10-21 20:23       ` Timur Tabi
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Williams @ 2008-10-21 20:16 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linux-kernel, Kumar Gala

On Tue, Oct 21, 2008 at 12:43 PM, Timur Tabi <timur@freescale.com> wrote:
> Dan Williams wrote:
>
>> I really like the sysfs_notify() approach that Neil Brown has put
>> together for delivering md-raid events.
>
> Is there any documentation for sysfs_notify?  It doesn't appear to do anything
> whenever I call it.
>

It simply allows you to write an event loop in userspace using a sysfs
attribute file descriptor.  Pseudo-example:

fd = open("/sys/block/md0/md/array_state");
do {
	read(buf, fd, len);
	act_on_message(buf);
	select(...); /* wait for next sysfs_notify event */
	lseek(fd, 0, SEEK_SET); /* seek back so we can read the new state */
} while (1);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Best method for sending messages to user space?
  2008-10-21 20:16     ` Dan Williams
@ 2008-10-21 20:23       ` Timur Tabi
  2008-10-21 20:42         ` Dan Williams
  0 siblings, 1 reply; 6+ messages in thread
From: Timur Tabi @ 2008-10-21 20:23 UTC (permalink / raw)
  To: Dan Williams; +Cc: linux-kernel, Kumar Gala

Dan Williams wrote:

> fd = open("/sys/block/md0/md/array_state");
> do {
> 	read(buf, fd, len);
> 	act_on_message(buf);
> 	select(...); /* wait for next sysfs_notify event */
> 	lseek(fd, 0, SEEK_SET); /* seek back so we can read the new state */
> } while (1);

I meant from the kernel side.  I added a call to sysfs_notify(), and I didn't
see any sysfs entries being created, so I presume I need to set up sysfs before
I call sysfs_notify(), but I can't figure out what that setup is.

-- 
Timur Tabi
Linux kernel developer at Freescale

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Best method for sending messages to user space?
  2008-10-21 20:23       ` Timur Tabi
@ 2008-10-21 20:42         ` Dan Williams
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Williams @ 2008-10-21 20:42 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linux-kernel, Kumar Gala

On Tue, Oct 21, 2008 at 1:23 PM, Timur Tabi <timur@freescale.com> wrote:
> Dan Williams wrote:
>
>> fd = open("/sys/block/md0/md/array_state");
>> do {
>>       read(buf, fd, len);
>>       act_on_message(buf);
>>       select(...); /* wait for next sysfs_notify event */
>>       lseek(fd, 0, SEEK_SET); /* seek back so we can read the new state */
>> } while (1);
>
> I meant from the kernel side.  I added a call to sysfs_notify(), and I didn't
> see any sysfs entries being created, so I presume I need to set up sysfs before
> I call sysfs_notify(), but I can't figure out what that setup is.
>

sysfs_notify() will not create any files it only operates on
pre-existing attributes created via kobject_{init_and_}add().  See:
http://lxr.linux.no/linux+v2.6.27/drivers/md/md.c#L3473
http://lxr.linux.no/linux+v2.6.27/drivers/md/md.c#L3761

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-10-21 20:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-21 17:54 Best method for sending messages to user space? Timur Tabi
2008-10-21 18:14 ` Dan Williams
2008-10-21 19:43   ` Timur Tabi
2008-10-21 20:16     ` Dan Williams
2008-10-21 20:23       ` Timur Tabi
2008-10-21 20:42         ` Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).