[ntp:questions] use ntpd, how to know unsync status on linuxsystem

赵颖科 zhaoyingke at sf-auto.com
Mon Aug 16 07:40:15 UTC 2010


>>         I`m using ntpd(ntp4.2.6p1) as client in linux(2.6.26). I have some questions about my user app how to know the ntp client sync status.
>>
>>         1. I use ntp_gettime, is there other way?
>
>That depends on what you want to know about the state of ntpd.  You
>probably should want to know the error bound, in which case it is an
>appropriate method.  If you really want to know whether it is synched,
>you need to use the NTP protocol to either check the stratum (note that
>this may take a long time to go to 16, when the last server stops
>responding, or more detailed state variables.
>
           Thank you, David.
                I just forcus on the return value of ntp_getime, but don`t know the stratum. I think the stratum means the time quality, is right?


>>         2. If there is no server alive, when I start ntp client, why ntptime show :ntp_gettime() returns code 0, but not code 5?
>
>I believe there was a policy decision some time ago never to declare a
>failure to this interface.
>
>>          I trace the  function loop_config in the file ntpd/ntp_loopfilter.c :
>>         I think it should be :
>>                 ntv.maxerror = (u_int32)(MAXDISPERSE * 1e6);
>>                 ntv.esterror = (u_int32)(MAXDISPERSE * 1e6);
>
>I tend to agree.
>>
>>         or not?
>>
>>         3. If ntp server no answer for 1h or shortter time, ntpd can mark unsync stat? how could I config ntpd?
>>
>
>Why is this important to you?  The time should still be very accurate at
>that point.
>

     My project is about receive sample value for the merge unit, by IEC61850-9-2. The merge unit (MU) only show the sample count in one second. eg: 0 -- 3999. So, my PC must get the SOC  and associated with sample value.
     When the ntpd, which run on my PC as client, cann`t receive the reply from ntp server, the SOC got from my PC clock will offset about 10s in 24h. So, I`m  apt to mark the unsync stat for the sample value so qickly.

        this is app map:  ntpd  --->  linux system  ---->  my app <---  MU

    So, I realy want to know the unsync, as fast as I can, by some API. By your answer, I`ll try to check the stratum, and use local server 127...    stratum 16. When remote server no reply received, can ntpd use the local server`s stratum?

        Maybe it help to  change the stratum so qickly as I wash?


     When I waited the help, I try to write a simple sntp client for my project. When I use ntp_adjtime to adjust the offset, I see ntptime show:

ntp_adjtime() returns code 0 (OK)
  modes 0x0 (),
  offset -535.000 us, frequency -500.000 ppm, interval 1 s,
  maximum error 42516 us, estimated error 16 us,
  status 0x1 (PLL),
  time constant 2, precision 1.000 us, tolerance 500 ppm,

next to change :

ntp_adjtime() returns code 0 (OK)
  modes 0x0 (),
  offset 0.000 us, frequency -500.000 ppm, interval 1 s,
  maximum error 454516 us, estimated error 16 us,
  status 0x1 (PLL),
  time constant 2, precision 1.000 us, tolerance 500 ppm,


my function is :

static inline __attribute__((always_inline))
int sntp_adjtime(double offset)
{
    struct timex ntpx;

    ntpx.modes = 0;
    ntp_adjtime(&ntpx);

    if ((ntpx.status&STA_UNSYNC) || (fabs(offset) >= 0.128)){
        ntpx.modes = MOD_STATUS|MOD_MAXERROR|MOD_ESTERROR|ADJ_OFFSET;
        ntpx.status = STA_PLL;
        ntpx.maxerror = MAXDISPERSE;
        ntpx.esterror = MAXDISPERSE;
        ntpx.offset = (uint32_t)(offset*1e6);
        ntp_adjtime(&ntpx);

        printf("sntp adjtime %f\n", offset);
    }


    return 0;
}

    I don`t know the particular about how to use the ntp_adjtime.

    I want to know how the ntpd adjust the local clock, or where can I get the doc about ntpd work logic?








>
>_______________________________________________
>questions mailing list
>questions at lists.ntp.org
>http://lists.ntp.org/listinfo/questions



本电子邮件及附件都属机密文件,并且仅供标明地址的个人或团体使用。
如果本电子邮件与您无关,请删除全部原始信息(包括任何原始信息的备份),并通知发件人。
This email and its attachments may be confidential and are intended solely for the use of the individual to whom it is addressed.
If you are not the intended recipient of this email and its attachments, you must take no action based upon them, nor must you copy or show them to anyone. Please contact the sender if you believe you have received this email in error.



More information about the questions mailing list