Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 374613 - pps-tools: new package to support new kernel time keeping features
Summary: pps-tools: new package to support new kernel time keeping features
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Unspecified (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Gentoo's Team for Core System packages
URL: http://wiki.enneenne.com/index.php/Li...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-09 21:37 UTC by Hal Engel
Modified: 2011-07-12 06:09 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hal Engel 2011-07-09 21:37:16 UTC
There is currently no package/ebuild for the pp-stools package.  This is located here:

git://github.com/ago/pps-tools.git

This includes a number of user land tools related to using hardware reference clocks with Pulse Per Second (PPS) outputs and a header file necessary for ntp to build correctly (IE. with reference clock support) with recent kernels.

If ntp is built with use=parse-clocks on a Linux system without the header file in this package being present ntp will not be built with parse-clock support.  
Linux has had PPS support since 2.6.29 and has recently had kernel consumer support added.  This means that the Linux kernel is now a full featured time keeping kernel.  But it needs to have the timepps.h file from pps-tools installed for programs like ntp to build correctly to use these features.
Comment 1 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2011-07-11 04:32:25 UTC
1. Committed as net-misc/pps-tools
2. net-misc/ntp-4.2.6_p3-r1 contains support for it.
Comment 2 Hal Engel 2011-07-11 23:44:01 UTC
Had a look and everything looks like it should. By the way very fast turn around and I was pleasantly surprised to find this in portage so quickly.  

The ntp ebuild will require pps-tools if use=parse-clocks.  This is correct and was a good catch on your part.  

The inclusion of the pps_tools check in the ntp build made me think it would also be nice if use=parse-clocks forced more of the pps related configuration into place so that users had more of a starting frame work for configuring their clocks.  This would make things easier for users who are new to using PPS devices.  

These include:

1. Before starting ntp with a serial PPS device it is necessary to run 

# ldattach PPS <PPS serial device>

Most systems will use a serial port for the PPS connection so this is the most common setup.  To do this I am using a custom init script that I use instead of /etc/init.d/ntpd named /etc/init.d/ntp-pps that looks like this:

#!/sbin/runscript
depend() {
        after  ntp-client
}

start() {

        ebegin "Starting custom ntpd"

        start-stop-daemon --background --start --exec /usr/sbin/ldattach \
                          --make-pidfile --pidfile /var/run/ldattach.pid \
                          -- --debug PPS ${NTP_PPS_DEVICE}
        eend $? "Failed to start ldattach"

        sleep 1 # give ldattach and udev time to get settled

        /etc/init.d/ntpd start
}

stop() {
        ebegin "Stopping custom ntpd"

        start-stop-daemon --stop --pidfile /var/run/ldattach.pid
        /etc/init.d/ntpd stop
}

________________________________

I didn't want to alter the default ntpd init script so the above may not be the optimal way to do this.  But it does work.

To configure the port in the above script I use /etc/conf.d/ntp-pps and it looks like this:

# /etc/conf.d/ntp-pps

# To pass the device for the PPS ldattach command
# Set this to the serial port you are using for your PPS device
# so that line discipline is setup on the correct port

NTP_PPS_DEVICE="/dev/ttyS1"

_______________________________________________

2. Depending on the clock being used one or more symlinks need to be created so that the clock driver can find it's devices.  Most clocks will require two symlinks, one for the PPS and one for talking to the clock to get year, month, date, hour, minutes and seconds and other information from the clock.

For #2 I use a set of udev rules that look like this:

KERNEL=="ttyS1", RUN+="/bin/setserial -v /dev/%k low_latency", SYMLINK+="oncore.serial.0"

KERNEL=="pps0", OWNER="root", GROUP="uucp", MODE="0660", SYMLINK+="oncore.pps.0", OPTIONS+="last_rule"

The above is for a Motorola Oncore GPS and the udev stuff will be different depending on the clock being used since each clock driver expects different device names. 

____________________________

3. The kernel needs to be correctly configured.

For example the ntp ebuild could check the kernel config to make sure that at a minimum that CONFIG_PPS and CONFIG_PPS_CLIENT_LDISC are set if use=parse-clocks.  Users also need to set CONFIG_NTP_PPS if they want to use the new (starting with 2.6.38) kernel consumer which is a good idea IMO. In addition if users want to hook the PPS up to a parallel port they need to enable CONFIG_PPS_CLIENT_PARPORT.  Issuing a warning if these are not set is probably the correct thing to do.

__________________________________



By the way Gentoo is now it is one of the better Linux platforms for using a local hardware clock for time keeping.  I have been using this stuff on my gentoo machine since kernel 2.6.24 when the kernel had to be patched to get PPS support (actually we also had to patch glibc at one point as well).  Now this is part of the kernel and I can almost setup one of these on a gentoo system in my sleep.  On the other hand I tried to get this working on a Ubuntu machine the other day.   I have yet to get it working and it appears that there is an issue with the kernel even though I have PPS working as the ntp Oncore clock driver fails on a system call.
Comment 3 SpanKY gentoo-dev 2011-07-12 05:43:59 UTC
(1) add a new init.d script that only does the ldattach (call it "foo")
(2) add rc_need=foo to /etc/conf.d/ntpd

for serial devices, there's really no files we can automatically install.  users will need to set these up themselves.

the setserial package already has an /etc/init.d/setserial and /etc/serial.conf file ...
Comment 4 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2011-07-12 06:09:02 UTC
That init.d script is potentially dangerous. You should never call other scripts in init.d from a script. There are cases with parallel boot that it will not work as you expect.

Here's a rough idea of one instead (non-ideal, it should support multiple PPS devices...):
==== /etc/init.d/pps-tools
#!/sbin/runscript
depend() {
  after ntp-client
  before ntpd
}
start() {
  einfo "Attaching to PPS hardware on ${NTP_PPS_DEVICE}"
  start-stop-daemon --background --start --exec /usr/sbin/ldattach \
  --make-pidfile --pidfile /var/run/ldattach.pid \
  -- --debug PPS ${NTP_PPS_DEVICE}
  rc=$?
  eend $rc "Failed to start ldattach"
  [ $rc -eq 0 ] && sleep 1
}
stop() {
  einfo "Detatching PPS hardware on ${NTP_PPS_DEVICE}"
  start-stop-daemon --stop --pidfile /var/run/ldattach.pid
}
==== /etc/conf.d/pps-tools
# To pass the device for the PPS ldattach command
# Set this to the serial port you are using for your PPS device
# so that line discipline is setup on the correct port

NTP_PPS_DEVICE="/dev/ttyS1"
====

Then for init.d/ntpd, add "use pps-tools".

I'll try and see what NTP PPS hardware I can get my hands on to improve this.