// do a garbage collect for clock records no longer in use
for (i = 0; i < MAX_CLOCKS; i++) {
// only if its in use and not a timing peer... don't need a mutex to check
- if ((clocks_private_info[i].in_use != 0) && (clocks_shared_info[i].timing_peer == 0)) {
+ if ((clocks_private_info[i].in_use != 0) &&
+ ((clocks_shared_info[i].flags & (1 << clock_is_a_timing_peer)) == 0)) {
int64_t time_since_last_use = reception_time - clocks_private_info[i].time_of_last_use;
// using a sync timeout to determine when to drop the record...
// the following give the sync receipt time in whole seconds
sync_seen,
};
+#define MAX_TIMING_SAMPLES 480
+typedef struct {
+ uint64_t local, local_to_remote_offset;
+} timing_samples;
+
// private information -- not for putting in shared memory -- about each clock source
typedef struct {
uint16_t sequence_number;
uint16_t in_use;
enum stage current_stage;
- uint64_t t2;
+ uint64_t t2, previous_offset, previous_estimated_offset;
// for garbage collection
uint64_t time_of_last_use; // will be taken out of use if not used for a while and not in the
// timing peer group
// for Announce Qualification
uint64_t announce_times[4]; // we'll check qualification and currency using these
int is_one_of_ours; // true if it is one of our own clocks
+ timing_samples samples[MAX_TIMING_SAMPLES];
+ int vacant_samples; // the number of elements in the timing_samples array that are not yet used
+ int next_sample_goes_here; // point to where in the timing samples array the next entries should
+ // go
} clock_source_private_data;
int find_clock_source_record(char *sender_string, clock_source *clocks_shared_info,
// turn off all is_timing_peers
int i;
for (i = 0; i < MAX_CLOCKS; i++)
- clock_info[i].timing_peer = 0;
+ clock_info[i].flags &= ~(1 << clock_is_a_timing_peer); // turn off peer flags
while (ip_list != NULL) {
char *new_ip = strsep(&ip_list, " ");
t = create_clock_source_record(new_ip, clock_info, clock_private_info,
0); // don't use the mutex
- clock_info[t].timing_peer = 1;
+ clock_info[t].flags |= (1 << clock_is_a_timing_peer);
}
rc = pthread_mutex_unlock(&shared_memory->shm_mutex);
warn("Can't release mutex after set_timing_peers!");
for (i = 0; i < MAX_CLOCKS; i++) {
- if (clock_info[i].timing_peer != 0)
+ if ((clock_info[i].flags & (1 << clock_is_a_timing_peer)) != 0)
debug(3, "%s is in the timing peer group.", &clock_info[i].ip);
}
} else {
i++;
}
if (valid_count >= foreign_master_threshold) {
- if (clock_info->qualified == 0) {
+ if ((clock_info->flags & (1 << clock_is_qualified)) == 0) {
uint64_t grandmaster_clock_id = nctohl(&msg->announce.grandmasterIdentity[0]);
uint64_t grandmaster_clock_id_low = nctohl(&msg->announce.grandmasterIdentity[4]);
grandmaster_clock_id = grandmaster_clock_id << 32;
}
if (pthread_mutex_lock(&shared_memory->shm_mutex) != 0)
warn("Can't acquire mutex to set_timing_peers!");
- clock_info->qualified = 1;
+ clock_info->flags |= (1 << clock_is_qualified);
if (pthread_mutex_unlock(&shared_memory->shm_mutex) != 0)
warn("Can't release mutex after set_timing_peers!");
} else {
- if (clock_info->qualified != 0)
+ if ((clock_info->flags & (1 << clock_is_qualified)) !=
+ 0) // if it was qualified, but now isn't
debug(1,
"clock_id %" PRIx64
" on ip: %s \"Announce\" message is not Qualified -- See 9.3.2.5.",
clock_info->clock_id, clock_info->ip);
if (pthread_mutex_lock(&shared_memory->shm_mutex) != 0)
warn("Can't acquire mutex to set_timing_peers!");
- clock_info->qualified = 0;
+ clock_info->flags &= ~(1 << clock_is_qualified);
if (pthread_mutex_unlock(&shared_memory->shm_mutex) != 0)
warn("Can't release mutex after set_timing_peers!");
}
#include <netinet/in.h>
#include <pthread.h>
+// most of this will probably become private when
+// the master clock selection stuff works automatically
+
+typedef enum { clock_is_valid, clock_is_a_timing_peer, clock_is_qualified } clock_flags;
+
typedef struct {
char ip[64]; // 64 is nicely aligned and bigger than INET6_ADDRSTRLEN (46)
uint64_t clock_id;
uint64_t local_time; // the local time when the offset was calculated
uint64_t local_to_source_time_offset; // add this to the local time to get source time
- uint8_t flags; // not used yet
- uint8_t valid; // this entry is valid
- uint8_t timing_peer; // true if this is in the current timing peer group
- uint8_t qualified; // true if it has valid Announce messages
+ uint32_t flags;
} clock_source;
struct shm_structure {
// update/set the clock_id
shared_memory->clocks[the_clock].clock_id = packet_clock_id;
- shared_memory->clocks[the_clock].valid = 1;
+ shared_memory->clocks[the_clock].flags |= (1 << clock_is_valid);
shared_memory->clocks[the_clock].local_time = clocks_private[the_clock].t2;
shared_memory->clocks[the_clock].local_to_source_time_offset = offset;
rc = pthread_mutex_unlock(&shared_memory->shm_mutex);