From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Sun, 18 Apr 2021 11:06:38 +0000 (+0100) Subject: clang and clean up some debug messages X-Git-Tag: 1.1-dev~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7a4f63dec75ce672b5e1aa36d332e0f32fe1ea4;p=thirdparty%2Fnqptp.git clang and clean up some debug messages --- diff --git a/nqptp-clock-sources.c b/nqptp-clock-sources.c index 14443a1..6aa3661 100644 --- a/nqptp-clock-sources.c +++ b/nqptp-clock-sources.c @@ -31,8 +31,7 @@ clock_source_private_data clocks_private[MAX_CLOCKS]; -int find_clock_source_record(char *sender_string, - clock_source_private_data *clocks_private_info) { +int find_clock_source_record(char *sender_string, clock_source_private_data *clocks_private_info) { // return the index of the clock in the clock information arrays or -1 int response = -1; int i = 0; @@ -67,7 +66,8 @@ int create_clock_source_record(char *sender_string, if (found == 1) { response = i; memset(&clocks_private_info[i], 0, sizeof(clock_source_private_data)); - strncpy((char *)&clocks_private_info[i].ip, sender_string, FIELD_SIZEOF(clock_source_private_data, ip) - 1); + strncpy((char *)&clocks_private_info[i].ip, sender_string, + FIELD_SIZEOF(clock_source_private_data, ip) - 1); clocks_private_info[i].in_use = 1; clocks_private_info[i].t2 = 0; clocks_private_info[i].current_stage = waiting_for_sync; @@ -80,8 +80,7 @@ int create_clock_source_record(char *sender_string, return response; } -void manage_clock_sources(uint64_t reception_time, - clock_source_private_data *clocks_private_info) { +void manage_clock_sources(uint64_t reception_time, clock_source_private_data *clocks_private_info) { debug(3, "manage_clock_sources"); int i; // do a garbage collect for clock records no longer in use diff --git a/nqptp-clock-sources.h b/nqptp-clock-sources.h index 8a4f18b..ece2aca 100644 --- a/nqptp-clock-sources.h +++ b/nqptp-clock-sources.h @@ -78,16 +78,13 @@ typedef struct { } clock_source_private_data; -int find_clock_source_record(char *sender_string, - clock_source_private_data *clocks_private_info); +int find_clock_source_record(char *sender_string, clock_source_private_data *clocks_private_info); -int create_clock_source_record(char *sender_string, - clock_source_private_data *clocks_private_info); +int create_clock_source_record(char *sender_string, clock_source_private_data *clocks_private_info); void update_clock_self_identifications(clock_source_private_data *clocks_private_info); -void manage_clock_sources(uint64_t reception_time, - clock_source_private_data *clocks_private_info); +void manage_clock_sources(uint64_t reception_time, clock_source_private_data *clocks_private_info); extern clock_source_private_data clocks_private[MAX_CLOCKS]; diff --git a/nqptp-message-handlers.c b/nqptp-message-handlers.c index 447ee17..d55ecd2 100644 --- a/nqptp-message-handlers.c +++ b/nqptp-message-handlers.c @@ -31,7 +31,7 @@ void update_master_old(clock_source_private_data *clock_private_info) { for (i = 0; i < MAX_CLOCKS; i++) { if ((clock_private_info[i].flags & (1 << clock_is_master)) != 0) if (old_master == -1) - old_master = i; // find old master + old_master = i; // find old master clock_private_info[i].flags &= ~(1 << clock_is_master); // turn them all off } @@ -73,15 +73,17 @@ void update_master_old(clock_source_private_data *clock_private_info) { } } if (best_so_far != -1) { - // we found a master clock + // we found a master clock clock_private_info[best_so_far].flags |= (1 << clock_is_master); // master_clock_index = best_so_far; if (old_master != best_so_far) { - update_master_clock_info(clock_private_info[best_so_far].clock_id, clock_private_info[best_so_far].local_time, clock_private_info[best_so_far].local_to_source_time_offset); + update_master_clock_info(clock_private_info[best_so_far].clock_id, + clock_private_info[best_so_far].local_time, + clock_private_info[best_so_far].local_to_source_time_offset); } } else { if (timing_peer_count == 0) - debug(1, "No timing peer list found"); + debug(2, "No timing peer list found"); else debug(1, "No master clock not found!"); } @@ -89,20 +91,17 @@ void update_master_old(clock_source_private_data *clock_private_info) { // check for (i = 0; i < MAX_CLOCKS; i++) { if ((clock_private_info[i].flags & (1 << clock_is_master)) != 0) - debug(2,"leaving with %d as master", i); + debug(2, "leaving with %d as master", i); } - } -void update_master() { - update_master_old(clocks_private); -} +void update_master() { update_master_old(clocks_private); } void handle_control_port_messages(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info) { if (recv_len != -1) { buf[recv_len - 1] = 0; // make sure there's a null in it! - debug(1,"Received a new timing peer list message: \"%s\".", buf); + debug(2, "Received a new timing peer list message: \"%s\".", buf); if (buf[0] == 'T') { char *ip_list = buf + 1; @@ -112,7 +111,8 @@ void handle_control_port_messages(char *buf, ssize_t recv_len, // turn off all is_timing_peer flags int i; for (i = 0; i < MAX_CLOCKS; i++) { - clock_private_info[i].flags &= ~(1 << clock_is_a_timing_peer); // turn off peer flag (but not the master flag!) + clock_private_info[i].flags &= + ~(1 << clock_is_a_timing_peer); // turn off peer flag (but not the master flag!) } while (ip_list != NULL) { @@ -149,8 +149,8 @@ void handle_control_port_messages(char *buf, ssize_t recv_len, } } -void handle_announce(char *buf, ssize_t recv_len, - clock_source_private_data *clock_private_info, uint64_t reception_time) { +void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info, + uint64_t reception_time) { // reject Announce messages from self if (clock_private_info->is_one_of_ours == 0) { // debug_print_buffer(1, buf, (size_t) recv_len); @@ -355,7 +355,8 @@ void handle_sync(char *buf, __attribute__((unused)) ssize_t recv_len, } void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, - clock_source_private_data *clock_private_info, __attribute__((unused)) uint64_t reception_time) { + clock_source_private_data *clock_private_info, + __attribute__((unused)) uint64_t reception_time) { struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf; if ((clock_private_info->current_stage == sync_seen) && @@ -508,21 +509,21 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, } */ - // int64_t estimated_variation = estimated_offset - clock_private_info->previous_estimated_offset; - // debug(1, "clock: %" PRIx64 ", estimated_jitter: %+f ms, divergence: %+f.", - // clock_info->clock_id, + // int64_t estimated_variation = estimated_offset - + // clock_private_info->previous_estimated_offset; debug(1, "clock: %" PRIx64 ", + // estimated_jitter: %+f ms, divergence: %+f.", clock_info->clock_id, // estimated_variation * 0.000001, divergence * 0.000001); clock_private_info->previous_estimated_offset = estimated_offset; - clock_private_info->clock_id = packet_clock_id; clock_private_info->flags |= (1 << clock_is_valid); clock_private_info->local_time = clock_private_info->t2; clock_private_info->local_to_source_time_offset = estimated_offset; if ((clock_private_info->flags & (1 << clock_is_master)) != 0) { - update_master_clock_info(clock_private_info->clock_id, clock_private_info->local_time, clock_private_info->local_to_source_time_offset); + update_master_clock_info(clock_private_info->clock_id, clock_private_info->local_time, + clock_private_info->local_to_source_time_offset); } clock_private_info->next_sample_goes_here++; diff --git a/nqptp-message-handlers.h b/nqptp-message-handlers.h index 0e6700e..1debea5 100644 --- a/nqptp-message-handlers.h +++ b/nqptp-message-handlers.h @@ -23,14 +23,14 @@ #include "nqptp-clock-sources.h" #include "nqptp-shm-structures.h" -void handle_announce(char *buf, ssize_t recv_len, - clock_source_private_data *clock_private_info, uint64_t reception_time); +void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info, + uint64_t reception_time); -void handle_sync(char *buf, ssize_t recv_len, - clock_source_private_data *clock_private_info, uint64_t reception_time); +void handle_sync(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info, + uint64_t reception_time); -void handle_follow_up(char *buf, ssize_t recv_len, - clock_source_private_data *clock_private_info, uint64_t reception_time); +void handle_follow_up(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info, + uint64_t reception_time); void handle_control_port_messages(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info); diff --git a/nqptp-shm-structures.h b/nqptp-shm-structures.h index b5cf7e0..42d4e23 100644 --- a/nqptp-shm-structures.h +++ b/nqptp-shm-structures.h @@ -36,11 +36,11 @@ #include struct shm_structure { - pthread_mutex_t shm_mutex; // for safely accessing the structure - uint16_t version; // deprecated -- check this is equal to NQPTP_SHM_STRUCTURES_VERSION - uint32_t flags; // unused - uint64_t master_clock_id; // the current master clock - uint64_t local_time; // the time when the offset was calculated + pthread_mutex_t shm_mutex; // for safely accessing the structure + uint16_t version; // deprecated -- check this is equal to NQPTP_SHM_STRUCTURES_VERSION + uint32_t flags; // unused + uint64_t master_clock_id; // the current master clock + uint64_t local_time; // the time when the offset was calculated uint64_t local_to_master_time_offset; // add this to the local time to get master clock time }; diff --git a/nqptp.c b/nqptp.c index 98271fc..2fc2556 100644 --- a/nqptp.c +++ b/nqptp.c @@ -71,9 +71,10 @@ int master_clock_index = -1; struct shm_structure *shared_memory = NULL; // this is where public clock info is available int epoll_fd; -void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time, uint64_t local_to_master_offset) { +void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time, + uint64_t local_to_master_offset) { if (shared_memory->master_clock_id != master_clock_id) - debug(1,"Master clock is: %" PRIx64 ", local_to_ptp_time_offset: %" PRIx64 ".", shared_memory->master_clock_id, shared_memory->local_to_master_time_offset); + debug(1, "Master clock is: %" PRIx64".", master_clock_id); int rc = pthread_mutex_lock(&shared_memory->shm_mutex); if (rc != 0) warn("Can't acquire mutex to update master clock!"); @@ -340,14 +341,12 @@ int main(void) { memset(sender_string, 0, sizeof(sender_string)); inet_ntop(connection_ip_family, sender_addr, sender_string, sizeof(sender_string)); // now, find or create a record for this ip - int the_clock = - find_clock_source_record(sender_string, - (clock_source_private_data *)&clocks_private); + int the_clock = find_clock_source_record( + sender_string, (clock_source_private_data *)&clocks_private); // not sure about requiring a Sync before creating it... if ((the_clock == -1) && ((buf[0] & 0xF) == Sync)) { the_clock = create_clock_source_record( - sender_string, - (clock_source_private_data *)&clocks_private); + sender_string, (clock_source_private_data *)&clocks_private); } if (the_clock != -1) { clocks_private[the_clock].time_of_last_use = @@ -355,19 +354,15 @@ int main(void) { switch (buf[0] & 0xF) { case Announce: // needed to reject messages coming from self - update_clock_self_identifications( - (clock_source_private_data *)&clocks_private); - handle_announce(buf, recv_len, - &clocks_private[the_clock], reception_time); + update_clock_self_identifications((clock_source_private_data *)&clocks_private); + handle_announce(buf, recv_len, &clocks_private[the_clock], reception_time); break; case Sync: { // if it's a sync - handle_sync(buf, recv_len, - &clocks_private[the_clock], reception_time); + handle_sync(buf, recv_len, &clocks_private[the_clock], reception_time); } break; case Follow_Up: { - handle_follow_up(buf, recv_len, - &clocks_private[the_clock], reception_time); + handle_follow_up(buf, recv_len, &clocks_private[the_clock], reception_time); } break; default: break; @@ -377,8 +372,7 @@ int main(void) { } } } - manage_clock_sources(reception_time, - (clock_source_private_data *)&clocks_private); + manage_clock_sources(reception_time, (clock_source_private_data *)&clocks_private); } } diff --git a/nqptp.h b/nqptp.h index b3e3dcd..8dbedd8 100644 --- a/nqptp.h +++ b/nqptp.h @@ -21,13 +21,12 @@ #define NQPTP_H // 0 means no debug messages. 3 means lots! -#define DEBUG_LEVEL 0 +#define DEBUG_LEVEL 1 #include "nqptp-shm-structures.h" #define MAX_OPEN_SOCKETS 16 - // When a new timing peer group is created, one of the clocks in the // group becomes the master and its native time becomes the "master time". // This is what is provided to the client. @@ -35,6 +34,7 @@ extern int master_clock_index; extern struct shm_structure *shared_memory; -void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time, uint64_t local_to_master_offset); +void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time, + uint64_t local_to_master_offset); #endif \ No newline at end of file