|
|
Subscribe / Log in / New account

Some upcoming sysfs enhancements

A glance at Greg Kroah-Hartman's state of the driver core and sysfs message shows that a number of changes are queued up for future kernel cycles. A couple of those add new features to sysfs, and seem worth a mention.

Attribute files in sysfs serve as a channel for sharing information between the kernel and user space. As more of the information interface moves to sysfs, an increasing number of user-space programs will be making use of sysfs attributes. Often, these programs will want to respond when the value of a sysfs attribute changes. In current kernels, however, there is no easy way for an application to know when an attribute has changed; the only option is to repeatedly re-read the file and check for new values.

The current -mm kernels include a patch by Neil Brown which makes it possible to create pollable attributes. With such attributes, user space need only open the attribute of interest pass it to poll() with the POLLERR and POLLPRI events selected. When poll() returns, the file can be reopened and reread to obtain the new value.

Internally, the patch adds a wait queue head to every kobject on the system; that queue is inserted into a poll table in response to a poll() call. The sysfs code has no way of knowing, however, when the value of any given sysfs attribute has changed, so the subsystem implementing a pollable attribute must make explicit calls to:

    void sysfs_notify(struct kobject *kobj, char *dir, char *attr);

Here, kobj and attr describe the attribute whose value has been changed. The dir argument need only be supplied when the given kobject has a special subdirectory (and the attribute is in that directory). This call will cause any polling process to wake up and see that a new value is available.

With the current code, there is no way to mark attributes which can be polled. Any process which calls poll() on an attribute which does not support polling will end up waiting rather longer than the developer intended.

While sysfs attributes are normally low-bandwidth items - holding generally a single value - the relayfs subsystem (added in 2.6.14) is meant to be a high-bandwidth pipe from the kernel to user space. Relayfs is often used for debugging tasks, such as relaying large amounts of kernel trace data for later analysis. User space gets at that data stream by opening a channel file created in the special-purpose relayfs filesystem.

As it turns out, relayfs contains a fairly nice internal abstraction for its file operations, making it possible to create entries for relay channels in other filesystems. Paul Mundt recently put together a patch taking advantage of this feature to allow kernel code to create relayfs channels in sysfs. The reaction to this capability was positive; indeed, it was seen as a better interface to the relay code than relayfs itself. So Paul's patches have grown into a full reworking of the relay interface, with the separate relayfs filesystem going away entirely.

Most of the interfaces remain unchanged; in particular, almost the entire kernel API (as described in the documentation file) remains as it was before. But now there is a pair of new functions:

    int sysfs_create_relay_file(struct kobject *kobj, 
                                struct relay_attribute *attr);
    void sysfs_remove_relay_file(struct kobject *kobj, 
                                 struct relay_attribute *attr);

A simple call to sysfs_create_relay_file() will add a relay channel attribute to the given kobject. The relay_attribute structure must be filled in with information about the actual channel. On the user-space side, the only change is that the application must look in a different place to find the relay channel. All of the supported operations (mmap() in particular) work as before.

Barring last-minute objections, both of these patches seem likely to be merged for 2.6.17.

Index entries for this article
KernelRelayfs
KernelSysfs


(Log in to post comments)

Some upcoming sysfs enhancements

Posted Mar 9, 2006 5:11 UTC (Thu) by kirkengaard (guest, #15022) [Link]

One is tempted to suggest that the head-bashing that is happening over stable API in 2.6, with the good ideas about sysfs, relayfs, and other kernel-to-userspace representations may make a good 2.7 issue, to have a major rework of the good ideas without the "keep it stable" kluges. Eventually it'll hit critical mass; if that's it, then I look forward to 2.8 in terms of userspace system diagnostic capabilities.

Of course, I could be altogether worng. :)

Some upcoming sysfs enhancements

Posted Mar 9, 2006 10:10 UTC (Thu) by nix (subscriber, #2304) [Link]

Certainly I can't see many apps using sysfs if it keeps changing at this rate. There've been major changes (to the behaviour / layout, not just the contents) in virtially every kernel release to date.

One problem is that the sysfs tree is big enough (and pins enough memory) that piling lots of compatibility stuff in there is not an option :(

Some upcoming sysfs enhancements

Posted Mar 9, 2006 14:52 UTC (Thu) by bronson (guest, #4806) [Link]

Oh my god! The number of ioctls is getting way out of hand and the calls are totally inconsistent! It's a mess! I know, let's put most of the information in /proc. What could be simpler than just opening a file?

(4 years later)

Oh my god! The number of files in /proc is way out of hand and who knows what each file is supposed to contain?? It keeps changing. It's a mess! Hey I know, let's make another filesystem, like proc, but only one value per file. That will clean things right up.

(4 years later)

Oh my god! The number of files in /sys is way out of hand. I know *what* the file is supposed to contain but I have no idea where it is! It keeps moving. It's a mess! Hey, I know. Erm... Userspace compatibility library?

Some upcoming sysfs enhancements

Posted Apr 20, 2006 11:21 UTC (Thu) by mic.f (guest, #30242) [Link]

What's the point in designing an API that changes every month ? This is simply useless..but kernel hackers feel so comfortable with this "perfect approach" to kernel development and they continue to reply on criticism with "use distros kernels" but how the fuck I am supposed to write a sysfs-capable app if redhat, debian, suse and every other linux distro have unaligned versions ?

IMO the reality is: developers are happy with the idea that they can change everything everytime in every place of the code BUT people and external developers and the COMMUNITY needs some sort of plan in doing this...Why larger projects do have roadmaps and the linux kernel cant ? Seems like it's because "hey im a kernel hax0r im cool lemme mess around in the code when that exciting speed enanching patch comes in or whatever new thing im happy to put in is ready, i dont care if it will break here and there"

MAYBE "ioctl -> proc -> sysfs -> NEXT_BIG_THING" could have been avoided with DESIGN DECISIONS and some planning and some middle term thinking of new kernel features..

If this is impossible to think by kernel developers, maybe a simple 6-months stable releases cycle (like gnome & co) should align distros and the community on the same kernels.. at least for some months
With a larger time frame on which a kernel is the current kernel it is supposed a lot of distros will end in picking up the same kernel thus reducing fragmentation and starting to make those "APIs" more real and useful.

Some upcoming sysfs enhancements

Posted Jun 1, 2006 17:55 UTC (Thu) by wilck (guest, #29844) [Link]

I full-heartedly agree.

Some upcoming sysfs enhancements

Posted Mar 9, 2006 21:31 UTC (Thu) by iabervon (subscriber, #722) [Link]

Having 2.7/2.8 wouldn't be a considered a sufficiently good excuse to break userspace like that. Version number is more about whether the internal function is similar; if you enable the right options, your Linux 1.2.13 programs should still work.

Now, it's possible that the "stable API" discussion will lead to having the kernel source include libraries linked from userspace programs and run in usermode. At that point, a lot of code can be moved out of the kernel executable and supervisor mode while not having a stable API between it and devices (it would provide a stable API to programs, of course, but compatibility stuff is relatively easy there), and a bunch of stuff currently distributed separately could be moved into the kernel tree (alsalib, e.g.). If this happens, maybe the version number should change from 2.6.x to 3.x, because it's a kind of major organizational change, and it would be good to acknowledge that the development methodology is really different from the 2.n period.

Shouldn't sysfs be single-value-per-fiel only ?

Posted Mar 9, 2006 12:24 UTC (Thu) by xav (guest, #18536) [Link]

Now I don't really understand .. I thought the philosophy of sysfs was
one-value-per-file (as underlined by Greg KH in its message). How can
relayfs be compatible with that ?


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