#include "common.h"
#include "clock.h"
#include "lib/cq.h"
#include "lib/misc.h"
#include "lib/walloc.h"
#include "if/gnet_property.h"
#include "if/gnet_property_priv.h"
#include "lib/stats.h"
#include "lib/tm.h"
#include "lib/override.h"
Data Structures | |
struct | used_val |
Defines | |
#define | REUSE_DELAY 10800 /**< 3 hours */ |
3 hours | |
#define | ENOUGH_DATA 30 /**< Update skew when we have enough data */ |
Update skew when we have enough data. | |
#define | MIN_DATA 15 /**< Minimum amount of points for update */ |
Minimum amount of points for update. | |
#define | MAX_SDEV 60.0 /**< Maximum dispersion we tolerate */ |
Maximum dispersion we tolerate. | |
#define | CLEAN_STEPS 3 /**< Amount of steps to remove off-track data */ |
Amount of steps to remove off-track data. | |
Functions | |
RCSID ("$Id:clock.c, v 1.16 2005/08/31 21:37:28 rmanfredi Exp $") | |
void | val_free (struct used_val *v) |
Dispose of the value from the `used' table. | |
void | val_destroy (cqueue_t *unused_cq, gpointer obj) |
Called from callout queue when it's time to destroy the record. | |
used_val * | val_create (const host_addr_t addr, gint precision) |
Create a value for the `used' table. | |
void | val_reused (struct used_val *v, gint precision) |
Accepted an update due to a lower precision entry, reschedule the expiration timeout. | |
void | clock_init (void) |
Called at startup time to initialize local structures. | |
void | used_free_kv (gpointer unused_key, gpointer val, gpointer unused_x) |
void | clock_close (void) |
Called at shutdown time to cleanup local structures. | |
void | clock_adjust (void) |
Adjust clock skew when we have enough datapoints. | |
void | clock_update (time_t update, gint precision, const host_addr_t addr) |
Update clock information, with given precision in seconds. | |
time_t | clock_loc2gmt (time_t stamp) |
Given a local timestamp, use our skew to correct it to GMT. | |
time_t | clock_gmt2loc (time_t stamp) |
Given a GMT timestamp, convert it to a local stamp using our skew. | |
Variables | |
GHashTable * | used |
Records the IP address used. | |
gpointer | datapoints = NULL |
This container holds the data points (clock offset between the real UTC time and our local clock time) collected. |
|
Amount of steps to remove off-track data.
|
|
Update skew when we have enough data.
|
|
Maximum dispersion we tolerate.
|
|
Minimum amount of points for update.
|
|
3 hours
|
|
Adjust clock skew when we have enough datapoints.
|
|
Called at shutdown time to cleanup local structures.
|
|
Given a GMT timestamp, convert it to a local stamp using our skew.
|
|
Called at startup time to initialize local structures.
|
|
Given a local timestamp, use our skew to correct it to GMT.
|
|
Update clock information, with given precision in seconds. The `ip' is used to avoid using the same source more than once per REUSE_DELAY seconds. |
|
|
|
|
|
Create a value for the `used' table.
|
|
Called from callout queue when it's time to destroy the record.
|
|
Dispose of the value from the `used' table.
|
|
Accepted an update due to a lower precision entry, reschedule the expiration timeout.
|
|
This container holds the data points (clock offset between the real UTC time and our local clock time) collected. For each update, there are two data points entered: u+d and u-d, where u is the update point and d is the precision of the value. When we have "enough" data points, we compute the average and the standard deviation, then we remove all the points lying outside the range [average - sigma, average + sigma]. We then recompute the average and use that to update our clock skew. Since we can't update the system clock, we define a skew and the relation between the real, the local time and the skew is: real_time = local_time + clock_skew The routine clock_loc2gmt() is used to compute the real time based on the local time, given the currently determined skew. The skewing of the local time is only used when the host is not running NTP. Otherwise, we compute the skew just for the fun of it. |
|
Records the IP address used.
|