File: sourcestats.h

package info (click to toggle)
chrony 1.14-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,480 kB
  • ctags: 2,091
  • sloc: ansic: 15,266; sh: 194; makefile: 113
file content (143 lines) | stat: -rw-r--r-- 5,083 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
  $Header: /cvs/src/chrony/sourcestats.h,v 1.11 1999/04/19 20:27:29 richard Exp $

  =======================================================================

  chronyd/chronyc - Programs for keeping computer clocks accurate.

  Copyright (C) 1997-1999 Richard P. Curnow
  All rights reserved.

  For conditions of use, refer to the file LICENCE.

  =======================================================================

  Header file for module that deals with the measurements and statistics of
  each of the sources. */

#ifndef GOT_SOURCESTATS_H
#define GOT_SOURCESTATS_H

#include "sysincl.h"

#include "reports.h"

typedef struct SST_Stats_Record *SST_Stats;

/* Init and fini functions */
extern void SST_Initialise(void);
extern void SST_Finalise(void);

/* This function creates a new instance of the statistics handler */
extern SST_Stats SST_CreateInstance(unsigned long refid);

/* This function deletes an instance of the statistics handler. */
extern void SST_DeleteInstance(SST_Stats inst);

/* This function accumulates a single sample into the statistics handler

   sample_time is the epoch at which the sample is to be considered to
   have been made.

   offset is the offset of the local clock relative to the source in
   seconds.  Positive indicates that the local clock if FAST (contrary
   to the NTP parts of the software)

   root_distance is the Lambda+Delta/2 term in RFC1305, but excluding
   the extra dispersion due to the residual standard deviation after
   we have done the regression fit.

   stratum is the stratum of the source from which the sample came.
  */

extern void SST_AccumulateSample(SST_Stats inst, struct timeval *sample_time, double offset, double peer_delay, double peer_dispersion, double root_delay, double root_dispersion, int stratum);

/* This function runs the linear regression operation on the data.  It
   finds the set of most recent samples that give the tightest
   confidence interval for the frequency, and truncates the register
   down to that number of samples. */
extern void SST_DoNewRegression(SST_Stats inst);

/* This function does a simple regression on what is in the register,
   without trying to optimise the error bounds on the frequency by
   deleting old samples */
extern void SST_DoUpdateRegression(SST_Stats inst);

/* Return the assumed worst case range of values that this source's
   frequency lies within.  Frequency is defined as the amount of time
   the local clock gains relative to the source per unit local clock
   time. */
extern void SST_GetFrequencyRange(SST_Stats inst, double *lo, double *hi);

/* Get data needed for selection */
extern void
SST_GetSelectionData(SST_Stats inst, struct timeval *now,
                     int *stratum,
                     double *best_offset, double *best_root_delay,
                     double *best_root_dispersion,
                     double *variance,
                     int *average_ok);

/* Get data needed when setting up tracking on this source */
extern void
SST_GetTrackingData(SST_Stats inst, struct timeval *now,
                    double *average_offset, double *offset_sd,
                    double *accrued_dispersion,
                    double *frequency, double *skew);

/* Get parameters for using this source as the reference */
extern void
SST_GetReferenceData(SST_Stats inst, struct timeval *now, 
                     int *stratum, double *offset,
                     double *root_delay, double *root_dispersion,
                     double *frequency, double *skew);



/* This routine is called when the local machine clock parameters are
   changed.  It adjusts all existing samples that we are holding for
   each peer so that it looks like they were made under the new clock
   regime rather than the old one.

   when = cooked local time when the change occurs

   dfreq = delta frequency. positive means the clock has been adjusted
   because it was previously gaining time relative to the external
   reference(s).

   doffset = offset slewed onto local clock.  positive => local clock
   has been made fast by that amount.

*/

extern void SST_SlewSamples(SST_Stats inst, struct timeval *when, double dfreq, double doffset);


/* Predict the offset of the local clock relative to a given source at
   a given local cooked time. Positive indicates local clock is FAST
   relative to reference. */
extern double SST_PredictOffset(SST_Stats inst, struct timeval *when);

/* Find the minimum round trip delay in the register */
extern double SST_MinRoundTripDelay(SST_Stats inst);

extern void SST_SaveToFile(SST_Stats inst, FILE *out);

extern int SST_LoadFromFile(SST_Stats inst, FILE *in);

extern void SST_DoSourceReport(SST_Stats inst, RPT_SourceReport *report, struct timeval *now);

extern void SST_DoSourcestatsReport(SST_Stats inst, RPT_SourcestatsReport *report);

typedef enum {
  SST_Skew_Decrease,
  SST_Skew_Nochange,
  SST_Skew_Increase
} SST_Skew_Direction;

extern SST_Skew_Direction SST_LastSkewChange(SST_Stats inst);

extern void SST_CycleLogFile(void);

#endif /* GOT_SOURCESTATS_H */