From: Dave Hart Date: Fri, 12 Jun 2009 17:53:01 +0000 (+0000) Subject: [Bug 1205] Add ntpd --usepcc and --pccfreq options on Windows X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a18bb0fa1eb4696af90530c5a3a4f31bc9b2dce;p=thirdparty%2Fntp.git [Bug 1205] Add ntpd --usepcc and --pccfreq options on Windows bk: 4a3295fdtHaLadtYCSqGE4LQ8OS50A --- diff --git a/ChangeLog b/ChangeLog index e8a4ade80c..eb9ae919cf 100644 --- 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 * [Bug 1206] Required compiler changes for Windows * [Bug 1084] PPSAPI for ntpd on Windows with DLL backends diff --git a/ntpd/ntpd-opts.c b/ntpd/ntpd-opts.c index c479fb9c2e..d8c10c8bdd 100644 --- a/ntpd/ntpd-opts.c +++ b/ntpd/ntpd-opts.c @@ -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 */ }; /* diff --git a/ntpd/ntpd-opts.h b/ntpd/ntpd-opts.h index 3d72caab71..9234613161 100644 --- a/ntpd/ntpd-opts.h +++ b/ntpd/ntpd-opts.h @@ -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 '?' diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index 1139ef760e..8944846d32 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -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 */ diff --git a/ntpd/ntpdbase-opts.def b/ntpd/ntpdbase-opts.def index b7073b0a50..231c3a4689 100644 --- a/ntpd/ntpdbase-opts.def +++ b/ntpd/ntpdbase-opts.def @@ -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_; +}; diff --git a/ports/winnt/ntpd/nt_clockstuff.c b/ports/winnt/ntpd/nt_clockstuff.c index 3dd0594655..3c2d04b47f 100644 --- a/ports/winnt/ntpd/nt_clockstuff.c +++ b/ports/winnt/ntpd/nt_clockstuff.c @@ -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;