[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gpsd-dev] Updated docs on NTP segment management
From: |
Harlan Stenn |
Subject: |
Re: [gpsd-dev] Updated docs on NTP segment management |
Date: |
Sat, 07 Mar 2015 16:25:00 -0800 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
Yes, I saw that, thanks.
And I notice NTP still supports systems that do not have gettimeofday().
As NTF brings Ntimed into the fold and that codebase moves from a
pre-release version of leaf-client code to something that includes time
distribution and refclock support, the interface and portability issues
should sort themselves out.
H
On 3/7/15 2:57 PM, Eric S. Raymond wrote:
> Gary E. Miller <address@hidden>:
>> I spot some doubles still on my hit list, so more clutter yet to go.
>
> I wa AFK during this exchange. But Gary is right - writing the small shim
> needed
> ta make clock_gettime() available even on the Mac and systems without full
> POSIX-2008 is trivial, and with a little autoconf hackery it's easy to hide
> the
> seam from any system that doesn't have it natively.
>
> /*
> * Simulate ANSI/POSIX conformance on platforms that don't have it
> *
> * This file is Copyright (c) 2010 by the GPSD project
> * BSD terms apply: see the file COPYING in the distribution root for details.
> */
> #include <time.h>
> #include <sys/time.h>
>
> #include "compiler.h"
>
> #ifdef __MACH__
> #include <mach/clock.h>
> #include <mach/mach.h>
> #endif
>
> #ifndef HAVE_CLOCK_GETTIME
> int clock_gettime(clockid_t clk_id UNUSED, struct timespec *tp)
> {
> #ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
> clock_serv_t cclock;
> mach_timespec_t mts;
> host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
> clock_get_time(cclock, &mts);
> mach_port_deallocate(mach_task_self(), cclock);
> ts.tv_sec = mts.tv_sec;
> ts.tv_nsec = mts.tv_nsec;
> #else
> struct timeval tv;
> if (gettimeofday(&tv, NULL) < 0)
> return -1;
> tp->ts_sec = tv.tv_sec;
> tp->ts_nsec = tv.tv_usec * 1000;
> /* paranoid programming */
> if (1000000 <= (tv)->tv_usec) {
> (tv)->tv_usec -= 1000000;
> (tv)->tv_sec++;
> } else if (0 > (tv)->tv_usec) {
> (tv)->tv_usec += 1000000;
> (tv)->tv_sec--;
> }
> return 0;
> #endif /* __MACH__ */
> }
> #endif /* HAVE_CLOCK_GETTIME */
>
> /* end */
>
> That's really all there is to it. Worst case is the host quietly does
> millisecond resolution in ns.
>
> A related point of interest: now that Bionic has implemented getsid(), this
> is pretty much the *only* API porting issue we have across our entire
> platform range. I believe POSIX-2001 confirmance is now effectively
> universal
> on Unixes and - by report - on recent Windows as well.
>
> This is a reality the NTP project has not caught up with, and should. What it
> does (and I've been reading the code recently) is good portability practice
> for about 10 to 12 years ago.
>
> Toolchains are really much more standardized today, and the
> possibilities for reducing code complexity are major.
>
--
Harlan Stenn <address@hidden>
http://networktimefoundation.org - be a member!
- Re: [gpsd-dev] Updated docs on NTP segment management, (continued)
Re: [gpsd-dev] Updated docs on NTP segment management, Harlan Stenn, 2015/03/07
- Re: [gpsd-dev] Updated docs on NTP segment management, Gary E. Miller, 2015/03/07
- Re: [gpsd-dev] Updated docs on NTP segment management, Harlan Stenn, 2015/03/07
- Re: [gpsd-dev] Updated docs on NTP segment management, Gary E. Miller, 2015/03/07
- Re: [gpsd-dev] Updated docs on NTP segment management, Harlan Stenn, 2015/03/07
- Re: [gpsd-dev] Updated docs on NTP segment management, Gary E. Miller, 2015/03/07
- Re: [gpsd-dev] Updated docs on NTP segment management, Eric S. Raymond, 2015/03/07
- Re: [gpsd-dev] Updated docs on NTP segment management,
Harlan Stenn <=