[LinuxPPS] More on problem with the PPS Device.

Rodolfo Giometti giometti at enneenne.com
Sun Jun 29 11:21:11 CEST 2008


On Sat, Jun 28, 2008 at 04:10:08PM -0600, clemens at dwf.com wrote:

> As it stands it does not run with the current patch and 2.6.24.4, and dies
> with the message
> 
> 	Can't open fd2 (/dev/pps1)
> 
> So, it opens /dev/ttyS0, does the set of the line discipline, but then cant
> (immediately) open /dev/pps1.
> 
> My solution was to put a 
> 
> 	sleep(5)
> 
> between the open of the line distribution and the open of /dev/pps1
> and this works.  My assumption is that something that Rodolfo is
> doing in the kernel to create /dev/pps1 is NOT being done immediately
> but is rather being put on a kernel queue, and being done later.  With
> the 5second delay, we outwait it.
> 
> With the 5 second delay inserted, there is a 5sec delay, and then the
> program starts returning timestamps.
> 
> Rodolfo's suggestion was that it might be a udev problem and suggested
> that I try to build /dev/pps1 by hand.  OK, removed the sleep, and
> replaced it with
> 
> 	system("mknod /dev/pps1 c 254 1");
> 
> if udev is still running, and the code has the above line in it, I see the
> error message
> 
> 	mknod: `/dev/pps1': File exists
> 
> and I start receiving timestamps.
> 
> If I kill udev, and run the test program, then it runs, giving timestamps,
> WITHOUT giving any error message.

Good! :)

This means that it's a udev related problem.

> If I run it AGAIN then I get the 'File exists' error message, and /dev/pps1
> still exists after the process terminates.  It would seem to me that when
> the process ends that /dev/pps1 would go away, but mabe thats something
> that udev does... Strange.

No, this is not strange at all. It's correct. Here the explanation: a
kernel device is created and deleted __inside__ the kernel only.

Here the events sequence __inside__ the kernel:

1) When the userland does open("/dev/ttyS0", ...) the device 4,64 is
opened.

2) When the userland does ioctl(fd, TIOCSETD, &ldisc) the line
discipline for device 4,64 is changed to N_PPS and a new device 254,1
is created.

3) when the userland closes "/dev/ttyS0" the line discipline is
automagically turned to N_TTY and the device 254,1 is removed from the
kernel.

When all these stuff happen __inside__ the kernel the userland see
nothing, but __if udev is running__ it catches the kernel events and
build/remove the special __file__ char 254,1. This means that if you
disable udev you have to build __and__ remove your PPS special
__files__ by hand.

Don't confuse drivers (which live __only__ inside the kernel) with
special files in /dev/ (which are simply files). See
http://lwn.net/Kernel/LDD2/ch03.lwn at "Major and Minor Numbers"
paragraph.

In this scenario the 5 seconds delay it's the time between:

1) the kernel sends to the userland the event "char device 254,1
created", and

2) udev catches the events and create the relative pps1 __file__ into
/dev/.

Hope I was clear.

Ciao,

Rodolfo

-- 

GNU/Linux Solutions                  e-mail: giometti at enneenne.com
Linux Device Driver                          giometti at linux.it
Embedded Systems                     phone:  +39 349 2432127
UNIX programming                     skype:  rodolfo.giometti



More information about the LinuxPPS mailing list