The name NSEC2SEC implies converting nanoseconds to seconds, but the value
used for the macro converts seconds to nanoseconds. NSEC_PER_SEC is the
accurate name for this macro. Move macro to common location in util.h.

Signed-off-by: Rahul Rameshbabu <rrameshb...@nvidia.com>
---

Notes:
    Changes since RFC:
    
      * Refactored macro to live in util.h.
        + Noticed that float usage in phc_ctl.c does not need an explicit cast

 phc_ctl.c      |  8 +++-----
 port.c         | 14 +++++++-------
 port_private.h |  3 +--
 servo.c        |  3 +--
 tc.c           |  6 +++---
 util.h         |  2 ++
 6 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 92e597c..db89f01 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -48,8 +48,6 @@
 #include "util.h"
 #include "version.h"
 
-#define NSEC2SEC 1000000000.0
-
 /* trap the alarm signal so that pause() will wake up on receipt */
 static void handle_alarm(int s)
 {
@@ -68,7 +66,7 @@ static void double_to_timespec(double d, struct timespec *ts)
         * value by our fractional component. This results in a correct
         * timespec from the double representing seconds.
         */
-       ts->tv_nsec = (long)(NSEC2SEC * fraction);
+       ts->tv_nsec = (long)(NSEC_PER_SEC * fraction);
 }
 
 static int install_handler(int signum, void(*handler)(int))
@@ -230,7 +228,7 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
                return -2;
        }
 
-       nsecs = (int64_t)(NSEC2SEC * time_arg);
+       nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
        clockadj_init(clkid);
        clockadj_step(clkid, nsecs);
@@ -257,7 +255,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
        }
 
        /* parse the double ppb argument */
-       r = get_ranged_double(cmdv[0], &ppb, -NSEC2SEC, NSEC2SEC);
+       r = get_ranged_double(cmdv[0], &ppb, -NSEC_PER_SEC, NSEC_PER_SEC);
        switch (r) {
        case PARSED_OK:
                break;
diff --git a/port.c b/port.c
index d551bef..b75f850 100644
--- a/port.c
+++ b/port.c
@@ -138,17 +138,17 @@ static int msg_current(struct ptp_message *m, struct 
timespec now)
 {
        int64_t t1, t2, tmo;
 
-       t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-       t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+       t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+       t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
        if (m->header.logMessageInterval <= -31) {
                tmo = 0;
        } else if (m->header.logMessageInterval >= 31) {
                tmo = INT64_MAX;
        } else if (m->header.logMessageInterval < 0) {
-               tmo = 4LL * NSEC2SEC / (1 << -m->header.logMessageInterval);
+               tmo = 4LL * NSEC_PER_SEC / (1 << -m->header.logMessageInterval);
        } else {
-               tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC2SEC;
+               tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC_PER_SEC;
        }
 
        return t2 - t1 < tmo;
@@ -340,10 +340,10 @@ static void fc_prune(struct foreign_clock *fc)
 
 static int delay_req_current(struct ptp_message *m, struct timespec now)
 {
-       int64_t t1, t2, tmo = 5 * NSEC2SEC;
+       int64_t t1, t2, tmo = 5 * NSEC_PER_SEC;
 
-       t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-       t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+       t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+       t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
        return t2 - t1 < tmo;
 }
diff --git a/port_private.h b/port_private.h
index 3b02d2f..d922a3d 100644
--- a/port_private.h
+++ b/port_private.h
@@ -28,8 +28,7 @@
 #include "msg.h"
 #include "power_profile.h"
 #include "tmv.h"
-
-#define NSEC2SEC 1000000000LL
+#include "util.h"
 
 enum syfu_state {
        SF_EMPTY,
diff --git a/servo.c b/servo.c
index daaa41c..a68c04a 100644
--- a/servo.c
+++ b/servo.c
@@ -26,11 +26,10 @@
 #include "pi.h"
 #include "refclock_sock.h"
 #include "servo_private.h"
+#include "util.h"
 
 #include "print.h"
 
-#define NSEC_PER_SEC 1000000000
-
 struct servo *servo_create(struct config *cfg, enum servo_type type,
                           double fadj, int max_ppb, int sw_ts)
 {
diff --git a/tc.c b/tc.c
index 1847041..7d1394c 100644
--- a/tc.c
+++ b/tc.c
@@ -256,9 +256,9 @@ static int tc_current(struct ptp_message *m, struct 
timespec now)
 {
        int64_t t1, t2, tmo;
 
-       tmo = 1LL * NSEC2SEC;
-       t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-       t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+       tmo = 1LL * NSEC_PER_SEC;
+       t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+       t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
        return t2 - t1 < tmo;
 }
diff --git a/util.h b/util.h
index 2bbde71..1cbd9b6 100644
--- a/util.h
+++ b/util.h
@@ -33,6 +33,8 @@
 #define MAX_PRINT_BYTES 16
 #define BIN_BUF_SIZE (MAX_PRINT_BYTES * 3 + 1)
 
+#define NSEC_PER_SEC 1000000000LL
+
 /**
  * Table of human readable strings, one for each port state.
  */
-- 
2.40.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to