* Re: SYSFS: need a noncaching read
2007-09-12 10:01 ` Greg KH
@ 2007-09-11 19:19 ` Nick Piggin
2007-09-12 17:57 ` Neil Brown
2007-09-12 11:13 ` Heiko Schocher
2007-09-17 5:22 ` Tejun Heo
2 siblings, 1 reply; 11+ messages in thread
From: Nick Piggin @ 2007-09-11 19:19 UTC (permalink / raw)
To: Greg KH; +Cc: linuxppc-dev, Heiko Schocher, linux-kernel, Detlev Zundel
On Wednesday 12 September 2007 20:01, Greg KH wrote:
> On Wed, Sep 12, 2007 at 07:32:07AM +0200, Robert Schwebel wrote:
> > On Tue, Sep 11, 2007 at 11:43:17AM +0200, Heiko Schocher wrote:
> > > I have developed a device driver and use the sysFS to export some
> > > registers to userspace.
> >
> > Uuuh, uggly. Don't do that. Device drivers are there to abstract things,
> > not to play around with registers from userspace.
> >
> > > I opened the sysFS File for one register and did some reads from this
> > > File, but I alwas becoming the same value from the register, whats not
> > > OK, because they are changing. So I found out that the sysFS caches
> > > the reads ... :-(
> >
> > Yes, it does. What you can do is close()ing the file handle between
> > accesses, which makes it work but is slow.
>
> Do an lseek back to 0 and then re-read, you will get called in your
> driver again.
Can you do a pread with offset 0 to avoid the two syscalls? (which some
people seem to be concerned about)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: SYSFS: need a noncaching read
2007-09-11 19:19 ` Nick Piggin
@ 2007-09-12 17:57 ` Neil Brown
0 siblings, 0 replies; 11+ messages in thread
From: Neil Brown @ 2007-09-12 17:57 UTC (permalink / raw)
To: Nick Piggin
Cc: Detlev Zundel, Greg KH, linux-kernel, linuxppc-dev,
Heiko Schocher
On Wednesday September 12, nickpiggin@yahoo.com.au wrote:
> On Wednesday 12 September 2007 20:01, Greg KH wrote:
> > On Wed, Sep 12, 2007 at 07:32:07AM +0200, Robert Schwebel wrote:
> > > On Tue, Sep 11, 2007 at 11:43:17AM +0200, Heiko Schocher wrote:
> > > > I have developed a device driver and use the sysFS to export some
> > > > registers to userspace.
> > >
> > > Uuuh, uggly. Don't do that. Device drivers are there to abstract things,
> > > not to play around with registers from userspace.
> > >
> > > > I opened the sysFS File for one register and did some reads from this
> > > > File, but I alwas becoming the same value from the register, whats not
> > > > OK, because they are changing. So I found out that the sysFS caches
> > > > the reads ... :-(
> > >
> > > Yes, it does. What you can do is close()ing the file handle between
> > > accesses, which makes it work but is slow.
> >
> > Do an lseek back to 0 and then re-read, you will get called in your
> > driver again.
>
> Can you do a pread with offset 0 to avoid the two syscalls? (which some
> people seem to be concerned about)
No.
Looking in fs/sysfs/file.c, we notice the field "needs_read_fill" in
struct sysfs_buffer.
sysfs_read_file will only call fill_read_buffer (which calls the
->show routine) if this is 1;
It is cleared by fill_read_buffer and set to 1:
- at open
- by fill_write_buffer (i.e. if you write to the file descriptor)
- by sysfs_poll when an event was detected.
So currently you cannot simply open a sysfs file an read multiple
times.
One option would be to call fill_read_buffer if *ppos == 0.
I cannot see that being a problem in practice, but maybe there is a
reason why it wasn't done that way.
Another option might be to call fill_read_buffer also if
buffer->event != atomic_read(&attr_sd->s_event)
and require drivers to call sysfs_notify when they make a change that
should be noticed. But I doubt that is really important.
NeilBrown
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: SYSFS: need a noncaching read
2007-09-12 10:01 ` Greg KH
2007-09-11 19:19 ` Nick Piggin
@ 2007-09-12 11:13 ` Heiko Schocher
2007-09-12 11:39 ` Greg KH
2007-09-17 5:22 ` Tejun Heo
2 siblings, 1 reply; 11+ messages in thread
From: Heiko Schocher @ 2007-09-12 11:13 UTC (permalink / raw)
To: Greg KH; +Cc: linuxppc-dev, linux-kernel, Detlev Zundel
Hello Greg
Am Mittwoch, den 12.09.2007, 03:01 -0700 schrieb Greg KH:
> On Wed, Sep 12, 2007 at 07:32:07AM +0200, Robert Schwebel wrote:
> > On Tue, Sep 11, 2007 at 11:43:17AM +0200, Heiko Schocher wrote:
> > > I have developed a device driver and use the sysFS to export some
> > > registers to userspace.
> >
> > Uuuh, uggly. Don't do that. Device drivers are there to abstract things,
> > not to play around with registers from userspace.
> >
> > > I opened the sysFS File for one register and did some reads from this
> > > File, but I alwas becoming the same value from the register, whats not
> > > OK, because they are changing. So I found out that the sysFS caches
> > > the reads ... :-(
> >
> > Yes, it does. What you can do is close()ing the file handle between
> > accesses, which makes it work but is slow.
>
> Do an lseek back to 0 and then re-read, you will get called in your
> driver again.
No thats not true. I thought this too, but if I make a:
seek (fd, 0L, SEEK_SET);
in Userspace, there is no retrigger in the sysFS, my driver is *not*
called again. So I made a own sysfs_seek function, which does retrigger
the driver ...
Is this really wanted in the sysFS, that there is no way to retrigger a
read?
thanks
Heiko
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: SYSFS: need a noncaching read
2007-09-12 11:13 ` Heiko Schocher
@ 2007-09-12 11:39 ` Greg KH
2007-09-12 11:59 ` Heiko Schocher
0 siblings, 1 reply; 11+ messages in thread
From: Greg KH @ 2007-09-12 11:39 UTC (permalink / raw)
To: Heiko Schocher; +Cc: linuxppc-dev, linux-kernel, Detlev Zundel
On Wed, Sep 12, 2007 at 01:13:32PM +0200, Heiko Schocher wrote:
> Hello Greg
>
> Am Mittwoch, den 12.09.2007, 03:01 -0700 schrieb Greg KH:
> > On Wed, Sep 12, 2007 at 07:32:07AM +0200, Robert Schwebel wrote:
> > > On Tue, Sep 11, 2007 at 11:43:17AM +0200, Heiko Schocher wrote:
> > > > I have developed a device driver and use the sysFS to export some
> > > > registers to userspace.
> > >
> > > Uuuh, uggly. Don't do that. Device drivers are there to abstract things,
> > > not to play around with registers from userspace.
> > >
> > > > I opened the sysFS File for one register and did some reads from this
> > > > File, but I alwas becoming the same value from the register, whats not
> > > > OK, because they are changing. So I found out that the sysFS caches
> > > > the reads ... :-(
> > >
> > > Yes, it does. What you can do is close()ing the file handle between
> > > accesses, which makes it work but is slow.
> >
> > Do an lseek back to 0 and then re-read, you will get called in your
> > driver again.
>
> No thats not true. I thought this too, but if I make a:
>
> seek (fd, 0L, SEEK_SET);
>
> in Userspace, there is no retrigger in the sysFS, my driver is *not*
> called again. So I made a own sysfs_seek function, which does retrigger
> the driver ...
Hm, are you sure? Otherwise the poll() stuff would not work at all.
> Is this really wanted in the sysFS, that there is no way to retrigger a
> read?
Yes, use the sysfs poll/select stuff to do that.
And "sysfs" has no upper-case letters :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: SYSFS: need a noncaching read
2007-09-12 11:39 ` Greg KH
@ 2007-09-12 11:59 ` Heiko Schocher
0 siblings, 0 replies; 11+ messages in thread
From: Heiko Schocher @ 2007-09-12 11:59 UTC (permalink / raw)
To: Greg KH; +Cc: linuxppc-dev, linux-kernel, Detlev Zundel
Hello Greg,
Am Mittwoch, den 12.09.2007, 04:39 -0700 schrieb Greg KH:
> > > Do an lseek back to 0 and then re-read, you will get called in your
> > > driver again.
> >
> > No thats not true. I thought this too, but if I make a:
> >
> > seek (fd, 0L, SEEK_SET);
> >
> > in Userspace, there is no retrigger in the sysFS, my driver is *not*
> > called again. So I made a own sysfs_seek function, which does retrigger
> > the driver ...
>
> Hm, are you sure? Otherwise the poll() stuff would not work at all.
Yes.
Sysfs uses generic_file_llseek (). And in sysfs_read_file ()
buffer->needs_read_fill must be 1, to reread from the driver.
generic_file_llseek () doesnt change this variable.
Best regards
Heiko
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: SYSFS: need a noncaching read
2007-09-12 10:01 ` Greg KH
2007-09-11 19:19 ` Nick Piggin
2007-09-12 11:13 ` Heiko Schocher
@ 2007-09-17 5:22 ` Tejun Heo
2 siblings, 0 replies; 11+ messages in thread
From: Tejun Heo @ 2007-09-17 5:22 UTC (permalink / raw)
To: Greg KH; +Cc: linuxppc-dev, Heiko Schocher, linux-kernel, Detlev Zundel
Greg KH wrote:
> On Wed, Sep 12, 2007 at 07:32:07AM +0200, Robert Schwebel wrote:
>> On Tue, Sep 11, 2007 at 11:43:17AM +0200, Heiko Schocher wrote:
>>> I have developed a device driver and use the sysFS to export some
>>> registers to userspace.
>> Uuuh, uggly. Don't do that. Device drivers are there to abstract things,
>> not to play around with registers from userspace.
>>
>>> I opened the sysFS File for one register and did some reads from this
>>> File, but I alwas becoming the same value from the register, whats not
>>> OK, because they are changing. So I found out that the sysFS caches
>>> the reads ... :-(
>> Yes, it does. What you can do is close()ing the file handle between
>> accesses, which makes it work but is slow.
>
> Do an lseek back to 0 and then re-read, you will get called in your
> driver again.
There should be an intervening sysfs_notify() call from kernel side to
make sysfs re-populate its cache on read again. sysfs bin files buffer
the result but don't cache the result but this again doesn't really fit
the usage case.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 11+ messages in thread