]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Add time of accession to bus mastership to the shm. Useful for deciding how long...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 27 May 2021 07:33:58 +0000 (08:33 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 27 May 2021 07:33:58 +0000 (08:33 +0100)
nqptp-shm-structures.h
nqptp.c

index 3e3f0cabac1ec87dee3fef7b580e961e893dcabc..9704644e0c8834c09dd52361b1d83bcc61161efe 100644 (file)
@@ -22,7 +22,7 @@
 
 #define STORAGE_ID "/nqptp"
 #define MAX_CLOCKS 32
-#define NQPTP_SHM_STRUCTURES_VERSION 4
+#define NQPTP_SHM_STRUCTURES_VERSION 5
 #define NQPTP_CONTROL_PORT 9000
 
 // the control port will accept a UDP packet with the first letter being:
@@ -43,6 +43,7 @@ struct shm_structure {
   char master_clock_ip[64];             // where it's coming from
   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
+  uint64_t master_clock_start_time;     // this is when the master clock became master
 };
 
 #endif
diff --git a/nqptp.c b/nqptp.c
index 457514ea8a91dd5e81ee69e4d6cd92100f5a6389..a2e0960c0263f87b36460d48133713674afb3adb 100644 (file)
--- a/nqptp.c
+++ b/nqptp.c
@@ -86,7 +86,10 @@ void update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t
   int rc = pthread_mutex_lock(&shared_memory->shm_mutex);
   if (rc != 0)
     warn("Can't acquire mutex to update master clock!");
-  shared_memory->master_clock_id = master_clock_id;
+  if (shared_memory->master_clock_id != master_clock_id) {
+    shared_memory->master_clock_id = master_clock_id;
+    shared_memory->master_clock_start_time = get_time_now();
+  }
   if (ip != NULL)
     strncpy((char *)&shared_memory->master_clock_ip, ip,
             FIELD_SIZEOF(struct shm_structure, master_clock_ip) - 1);
@@ -136,7 +139,7 @@ int main(int argc, char **argv) {
     if (argv[i][0] == '-') {
       if (strcmp(argv[i] + 1, "V") == 0) {
 #ifdef CONFIG_USE_GIT_VERSION_STRING
-        if (git_version_string[0] != '\0') 
+        if (git_version_string[0] != '\0')
           fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", git_version_string,
                 NQPTP_SHM_STRUCTURES_VERSION);
         else