Novell Home

Programmatically Checking Time Synchronization

Novell Cool Solutions: Feature
By Siddharth Jagtiani

Digg This - Slashdot This

Posted: 23 Sep 2003
 

Update: Siddarth has added new information to this article.

If you've ever wanted to check for time synchronization events easily and automatically, you may have wondered if you should look at the CLOCK_SYNCHRONIZATION_IS_ACTIVE and CLOCK_IS_NEARLY_IN_SYNC flags. The simple answer to the question is "Yes, you should wait for CLOCK_IS_NEARLY_IN_SYNC to SET." For most cases, this will do. Here the scoop:

Flags

CLOCK_SYNCHRONIZATION_IS_ACTIVE - When XNTPD/Timesync load, we SET this flag. This means, "the time synchronization service is active, you only need to wait a while until time can actually synchronize".

CLOCK_IS_NETWORK_SYNCHRONIZED - Check the value for this flag to know if time is syncrhonized to its time source.

CLOCK_IS_NEARLY_IN_SYNC - Only XNTPD (NTPv3 Daemon on NetWare 6.5) uses this flag. This flag is SET when time is as close as 500 ms to its time source. Hence most applications which are ok with this accuracy can use this flag instead of waiting for CLOCK_IS_NETWORK_SYNCHRONIZED. Or applications can initialize and do initial work until they get CLOCK_IS_SYNCHRONIZED OR CLOCK_IS_NETWORK_SYNCHRONIZED as SET.

Improving Synchronization Performance

Here's the advanced portion of the explanation. How do we get time to synchronize faster and get CLOCK_IS_NEARLY_IN_SYNC to SET within 10 seconds of XNTPD load. Answer is simple: either

  • Call "XNTPD" with "-S" option.
  • Or
  • Edit the ntp.conf file and put "stepclock" keyword in a new line of the configuration file.

The second method (conf file), helps you to avoid the "-S" in the command line. So it's more like a persistent configuration.

If you want time to synchronize fast, you should first use the "stepclock" keyword in your conf file and then load xntpd. After that, wait for only CLOCK_IS_NEARLY_IN_SYNC flag to SET. This will tell you that time has syncrhonized and is as close as 500 ms of the time source. Then when your application reaches a high precision state where 500ms is not enough but you instead need 10 ms, then you should should wait for CLOCK_SYNCHRONIZATION_IS_ACTIVE.

Additional Information

I want to update this cool tip with some more information.

Example

#include <synclock.h>
Synchronized_Clock_T clock ;
int syncStatus ;
 
GetSyncClockFields(SYNCCLOCK_ALL_DEFINED_BITS, &clock);
syncStatus = clock.statusFlags &
     (CLOCK_SYNCHRONIZATION_IS_ACTIVE |
     CLOCK_IS_SYNCHRONIZED |
     CLOCK_IS_NETWORK_SYNCHRONIZED |
     CLOCK_IS_NEARLY_IN_SYNC) ;
if (syncStatus & CLOCK_SYNCHRONIZATION_IS_ACTIVE)
{
     if ( (syncStatus & CLOCK_IS_SYNCHRONIZED) || 
	  (syncStatus & CLOCK_IS_NETWORK_SYNCHRONIZED))
            printf("Time synchronization is loaded and synchronized") ;
    else if (syncStatus & CLOCK_IS_NEARLY_IN_SYNC)
             printf("Time synchronization is loaded and nearly synchronized" ) ;
    else
             printf("Time synchronization is loaded and NOT synchronized" ) ;
 }
else
{
      printf("Time synchronization is NOT loaded" ) ; 
}

NEW Info

// NetWare 5.x and 6.0, 6.5
#defineCLOCK_IS_SYNCHRONIZED0X00000001L
#defineCLOCK_IS_NETWORK_SYNCHRONIZED0x00000002L
#defineCLOCK_SYNCHRONIZATION_IS_ACTIVE0x00000004L
#defineCLOCK_EXTERNAL_SYNC_ACTIVE0x00000008L
#defineCLOCK_STATUS_EXTRN_SYNC_TYPE0x0000F000L
#defineCLOCK_STATUS_SERVER_TYPE0x00000F00L
// NetWare 6.5 Only
#define CLOCK_IS_NEARLY_IN_SYNC0x00000010L


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell