]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1205] Add ntpd --usepcc and --pccfreq options on Windows
authorDave Hart <hart@ntp.org>
Fri, 12 Jun 2009 17:53:01 +0000 (17:53 +0000)
committerDave Hart <hart@ntp.org>
Fri, 12 Jun 2009 17:53:01 +0000 (17:53 +0000)
bk: 4a3295fdtHaLadtYCSqGE4LQ8OS50A

ChangeLog
ntpd/ntpd-opts.c
ntpd/ntpd-opts.h
ntpd/ntpd.c
ntpd/ntpdbase-opts.def
ports/winnt/ntpd/nt_clockstuff.c

index e8a4ade80c93acb37257c925ad90f0203a46ce0e..eb9ae919cf8780d839e320647d8e154207b70a78 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* [Bug 1205] Add ntpd --usepcc and --pccfreq options on Windows
 (4.2.5p181) 2009/06/06 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 1206] Required compiler changes for Windows
 * [Bug 1084] PPSAPI for ntpd on Windows with DLL backends
index c479fb9c2ed2995d481e2336878ae44b2ff0bfee..d8c10c8bdda4d90ead6d407d38c7140595c9614e 100644 (file)
@@ -1,7 +1,7 @@
 /*  
  *  EDIT THIS FILE WITH CAUTION  (ntpd-opts.c)
  *  
- *  It has been AutoGen-ed  Saturday June  6, 2009 at 07:38:41 AM EDT
+ *  It has been AutoGen-ed  Thursday June 11, 2009 at 11:04:39 PM UTC
  *  From the definitions    ntpd-opts.def
  *  and the template file   options
  *
@@ -389,6 +389,43 @@ tSCC    zSlew_NAME[]               = "SLEW";
 tSCC    zSlew_Name[]               = "slew";
 #define SLEW_FLAGS       (OPTST_DISABLED)
 
+/*
+ *  Usepcc option description:
+ */
+#ifdef SYS_WINNT
+tSCC    zUsepccText[] =
+        "Use CPU cycle counter (Windows only)";
+tSCC    zUsepcc_NAME[]             = "USEPCC";
+tSCC    zUsepcc_Name[]             = "usepcc";
+#define USEPCC_FLAGS       (OPTST_DISABLED)
+
+#else   /* disable Usepcc */
+#define VALUE_OPT_USEPCC NO_EQUIVALENT
+#define USEPCC_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
+#define zUsepccText       NULL
+#define zUsepcc_NAME      NULL
+#define zUsepcc_Name      NULL
+#endif  /* SYS_WINNT */
+
+/*
+ *  Pccfreq option description:
+ */
+#ifdef SYS_WINNT
+tSCC    zPccfreqText[] =
+        "Force CPU cycle counter use (Windows only)";
+tSCC    zPccfreq_NAME[]            = "PCCFREQ";
+tSCC    zPccfreq_Name[]            = "pccfreq";
+#define PCCFREQ_FLAGS       (OPTST_DISABLED \
+        | OPTST_SET_ARGTYPE(OPARG_TYPE_STRING))
+
+#else   /* disable Pccfreq */
+#define VALUE_OPT_PCCFREQ NO_EQUIVALENT
+#define PCCFREQ_FLAGS       (OPTST_OMITTED | OPTST_NO_INIT)
+#define zPccfreqText       NULL
+#define zPccfreq_NAME      NULL
+#define zPccfreq_Name      NULL
+#endif  /* SYS_WINNT */
+
 /*
  *  Help/More_Help/Version option descriptions:
  */
@@ -800,6 +837,30 @@ static tOptDesc optDesc[ OPTION_CT ] = {
      /* desc, NAME, name */ zSlewText, zSlew_NAME, zSlew_Name,
      /* disablement strs */ NULL, NULL },
 
+  {  /* entry idx, value */ 29, VALUE_OPT_USEPCC,
+     /* equiv idx, value */ 29, VALUE_OPT_USEPCC,
+     /* equivalenced to  */ NO_EQUIVALENT,
+     /* min, max, act ct */ 0, 1, 0,
+     /* opt state flags  */ USEPCC_FLAGS, 0,
+     /* last opt argumnt */ { NULL },
+     /* arg list/cookie  */ NULL,
+     /* must/cannot opts */ NULL, NULL,
+     /* option proc      */ NULL,
+     /* desc, NAME, name */ zUsepccText, zUsepcc_NAME, zUsepcc_Name,
+     /* disablement strs */ NULL, NULL },
+
+  {  /* entry idx, value */ 30, VALUE_OPT_PCCFREQ,
+     /* equiv idx, value */ 30, VALUE_OPT_PCCFREQ,
+     /* equivalenced to  */ NO_EQUIVALENT,
+     /* min, max, act ct */ 0, 1, 0,
+     /* opt state flags  */ PCCFREQ_FLAGS, 0,
+     /* last opt argumnt */ { NULL },
+     /* arg list/cookie  */ NULL,
+     /* must/cannot opts */ NULL, NULL,
+     /* option proc      */ NULL,
+     /* desc, NAME, name */ zPccfreqText, zPccfreq_NAME, zPccfreq_Name,
+     /* disablement strs */ NULL, NULL },
+
 #ifdef NO_OPTIONAL_OPT_ARGS
 #  define VERSION_OPT_FLAGS     OPTST_IMM | OPTST_NO_INIT
 #else
@@ -899,7 +960,7 @@ tOptions ntpdOptions = {
       NO_EQUIVALENT /* index of '-#' option */,
       NO_EQUIVALENT /* index of default opt */
     },
-    32 /* full option count */, 29 /* user option count */
+    34 /* full option count */, 31 /* user option count */
 };
 
 /*
index 3d72caab710a1651d91badb32e22f7edf8e0c5b6..92346131619c5d3a442ff3df6cdce9fa4b77c07c 100644 (file)
@@ -1,7 +1,7 @@
 /*  
  *  EDIT THIS FILE WITH CAUTION  (ntpd-opts.h)
  *  
- *  It has been AutoGen-ed  Saturday June  6, 2009 at 07:38:40 AM EDT
+ *  It has been AutoGen-ed  Thursday June 11, 2009 at 11:04:34 PM UTC
  *  From the definitions    ntpd-opts.def
  *  and the template file   options
  *
@@ -81,12 +81,14 @@ typedef enum {
         INDEX_OPT_VAR              = 26,
         INDEX_OPT_DVAR             = 27,
         INDEX_OPT_SLEW             = 28,
-        INDEX_OPT_VERSION          = 29,
-        INDEX_OPT_HELP             = 30,
-        INDEX_OPT_MORE_HELP        = 31
+        INDEX_OPT_USEPCC           = 29,
+        INDEX_OPT_PCCFREQ          = 30,
+        INDEX_OPT_VERSION          = 31,
+        INDEX_OPT_HELP             = 32,
+        INDEX_OPT_MORE_HELP        = 33
 } teOptIndex;
 
-#define OPTION_CT    32
+#define OPTION_CT    34
 #define NTPD_VERSION       "4.2.5p181"
 #define NTPD_FULL_VERSION  "ntpd - NTP daemon program - Ver. 4.2.5p181"
 
@@ -231,6 +233,14 @@ typedef enum {
 #  warning undefining SLEW due to option name conflict
 #  undef   SLEW
 # endif
+# ifdef    USEPCC
+#  warning undefining USEPCC due to option name conflict
+#  undef   USEPCC
+# endif
+# ifdef    PCCFREQ
+#  warning undefining PCCFREQ due to option name conflict
+#  undef   PCCFREQ
+# endif
 #else  /* NO_OPTION_NAME_WARNINGS */
 # undef IPV4
 # undef IPV6
@@ -261,6 +271,8 @@ typedef enum {
 # undef VAR
 # undef DVAR
 # undef SLEW
+# undef USEPCC
+# undef PCCFREQ
 #endif  /*  NO_OPTION_NAME_WARNINGS */
 
 /*
@@ -309,6 +321,12 @@ typedef enum {
 #define VALUE_OPT_VAR            26
 #define VALUE_OPT_DVAR           27
 #define VALUE_OPT_SLEW           'x'
+#ifdef SYS_WINNT
+#define VALUE_OPT_USEPCC         29
+#endif /* SYS_WINNT */
+#ifdef SYS_WINNT
+#define VALUE_OPT_PCCFREQ        30
+#endif /* SYS_WINNT */
 
 #define VALUE_OPT_VERSION       INDEX_OPT_VERSION
 #define VALUE_OPT_HELP          '?'
index 1139ef760e5c74fb90d37fa2d0920163ffd9cd92..8944846d328d7eacb6c2e8f291316a701517ee17 100644 (file)
@@ -563,6 +563,8 @@ ntpdmain(
        }
 #endif
 
+       setup_logfile();
+
 #ifdef SYS_WINNT
        /*
         * Initialize the time structures and variables
@@ -570,8 +572,6 @@ ntpdmain(
        init_winnt_time();
 #endif
 
-       setup_logfile();
-
        /*
         * Initialize random generator and public key pair
         */
index b7073b0a502288d624cacaa1e1c2d841cbbbe120..231c3a46898f37285b4aca082c9332992c229825 100644 (file)
@@ -360,3 +360,27 @@ flag = {
        Note: The kernel time discipline is disabled with this option.
        _EndOfDoc_;
 };
+
+flag = {
+    ifdef     = SYS_WINNT;
+    name      = usepcc;
+    descrip   = "Use CPU cycle counter (Windows only)";
+    doc = <<-  _EndOfDoc_
+       Attempt to substitute the CPU counter for QueryPerformanceCounter.
+       The CPU counter and QueryPerformanceCounter are compared, and if
+       they have the same frequency, the CPU counter (RDTSC on x86) is
+       used directly, saving the overhead of a system call.
+       _EndOfDoc_;
+};
+
+flag = {
+    ifdef     = SYS_WINNT;
+    name      = pccfreq;
+    arg-type  = string;
+    descrip   = "Force CPU cycle counter use (Windows only)";
+    doc = <<-  _EndOfDoc_
+       Force substitution the CPU counter for QueryPerformanceCounter.
+       The CPU counter (RDTSC on x86) is used unconditionally with the
+       given frequency (in Hz).
+       _EndOfDoc_;
+};
index 3dd0594655924ca7a3cd20130b10a278f62e108d..3c2d04b47f9c8caa65cf8cc3b8ca378ec343e88d 100644 (file)
@@ -28,6 +28,7 @@
 #include "clockstuff.h"
 #include "ntservice.h"
 #include "ntpd.h"
+#include "../../../ntpd/ntpd-opts.h"
 
 extern double sys_residual;    /* residual from previous adjustment */
 
@@ -245,7 +246,7 @@ perf_ctr(void)
                FT_ULL ft4;
                FT_ULL ft5;
                LONGLONG offset;
-               char *ntpd_pcc_freq_text;
+               const char *ntpd_pcc_freq_text;
 
                /* one-time initialization */
 
@@ -283,10 +284,14 @@ perf_ctr(void)
                 * ntpd port to the sole remaining alternative, Intel
                 * Itanium.
                 */
-               ntpd_pcc_freq_text = getenv("NTPD_PCC_FREQ");
+               if (HAVE_OPT(PCCFREQ))
+                       ntpd_pcc_freq_text = OPT_ARG(PCCFREQ);
+               else
+                       ntpd_pcc_freq_text = getenv("NTPD_PCC_FREQ");
 
-               if (NULL != getenv("NTPD_QPC")
-                   || (NULL == ntpd_pcc_freq_text && NULL == getenv("NTPD_PCC"))) {
+               if (!HAVE_OPT(USEPCC)
+                   && NULL == ntpd_pcc_freq_text
+                   && NULL == getenv("NTPD_PCC")) {
                        use_pcc = 0;
                        QueryPerformanceCounter(&ft1.li);
                        return ft1.ull;