This just moves code around to have related functions together and forward
declaration at the beginning of the file. No code changes.

Signed-off-by: Jiri Benc <jb...@redhat.com>
---
 phc2sys.c |  208 ++++++++++++++++++++++++++++++-------------------------------
 1 files changed, 103 insertions(+), 105 deletions(-)

diff --git a/phc2sys.c b/phc2sys.c
index 6c86b4d9f028..34f5f94ccb91 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -60,7 +60,41 @@
 #define PHC_PPS_OFFSET_LIMIT 10000000
 #define PMC_UPDATE_INTERVAL (60 * NS_PER_SEC)
 
-struct clock;
+struct clock {
+       LIST_ENTRY(clock) list;
+       clockid_t clkid;
+       int sysoff_supported;
+       int is_utc;
+       struct servo *servo;
+       enum servo_state servo_state;
+       const char *source_label;
+       struct stats *offset_stats;
+       struct stats *freq_stats;
+       struct stats *delay_stats;
+       struct clockcheck *sanity_check;
+};
+
+struct node {
+       unsigned int stats_max_count;
+       int sanity_freq_limit;
+       enum servo_type servo_type;
+       int phc_readings;
+       double phc_interval;
+       int sync_offset;
+       int forced_sync_offset;
+       int leap;
+       int leap_set;
+       int kernel_leap;
+       struct pmc *pmc;
+       int pmc_ds_requested;
+       uint64_t pmc_last_update;
+       LIST_HEAD(clock_head, clock) clocks;
+       struct clock *master;
+};
+
+static int update_sync_offset(struct node *node);
+static int clock_handle_leap(struct node *node, struct clock *clock,
+                            int64_t offset, uint64_t ts, int do_leap);
 
 static clockid_t clock_open(char *device)
 {
@@ -95,6 +129,74 @@ static clockid_t clock_open(char *device)
        return clkid;
 }
 
+static int clock_add(struct node *node, clockid_t clkid)
+{
+       struct clock *c;
+       int max_ppb;
+       double ppb;
+
+       c = calloc(1, sizeof(*c));
+       if (!c) {
+               pr_err("failed to allocate memory for a clock");
+               return -1;
+       }
+       c->clkid = clkid;
+       c->servo_state = SERVO_UNLOCKED;
+
+       if (c->clkid == CLOCK_REALTIME) {
+               c->source_label = "sys";
+               c->is_utc = 1;
+       } else {
+               c->source_label = "phc";
+       }
+
+       if (node->stats_max_count > 0) {
+               c->offset_stats = stats_create();
+               c->freq_stats = stats_create();
+               c->delay_stats = stats_create();
+               if (!c->offset_stats ||
+                   !c->freq_stats ||
+                   !c->delay_stats) {
+                       pr_err("failed to create stats");
+                       return -1;
+               }
+       }
+       if (node->sanity_freq_limit) {
+               c->sanity_check = clockcheck_create(node->sanity_freq_limit);
+               if (!c->sanity_check) {
+                       pr_err("failed to create clock check");
+                       return -1;
+               }
+       }
+
+       clockadj_init(c->clkid);
+       ppb = clockadj_get_freq(c->clkid);
+       /* The reading may silently fail and return 0, reset the frequency to
+          make sure ppb is the actual frequency of the clock. */
+       clockadj_set_freq(c->clkid, ppb);
+       if (c->clkid == CLOCK_REALTIME) {
+               sysclk_set_leap(0);
+               max_ppb = sysclk_max_freq();
+       } else {
+               max_ppb = phc_max_adj(c->clkid);
+               if (!max_ppb) {
+                       pr_err("clock is not adjustable");
+                       return -1;
+               }
+       }
+
+       c->servo = servo_create(node->servo_type, -ppb, max_ppb, 0);
+       servo_sync_interval(c->servo, node->phc_interval);
+
+       if (clkid != CLOCK_REALTIME)
+               c->sysoff_supported = (SYSOFF_SUPPORTED ==
+                                      sysoff_probe(CLOCKID_TO_FD(clkid),
+                                                   node->phc_readings));
+
+       LIST_INSERT_HEAD(&node->clocks, c, list);
+       return 0;
+}
+
 static int read_phc(clockid_t clkid, clockid_t sysclk, int readings,
                    int64_t *offset, uint64_t *ts, int64_t *delay)
 {
@@ -126,42 +228,6 @@ static int read_phc(clockid_t clkid, clockid_t sysclk, int 
readings,
        return 1;
 }
 
-struct clock {
-       LIST_ENTRY(clock) list;
-       clockid_t clkid;
-       int sysoff_supported;
-       int is_utc;
-       struct servo *servo;
-       enum servo_state servo_state;
-       const char *source_label;
-       struct stats *offset_stats;
-       struct stats *freq_stats;
-       struct stats *delay_stats;
-       struct clockcheck *sanity_check;
-};
-
-struct node {
-       unsigned int stats_max_count;
-       int sanity_freq_limit;
-       enum servo_type servo_type;
-       int phc_readings;
-       double phc_interval;
-       int sync_offset;
-       int forced_sync_offset;
-       int leap;
-       int leap_set;
-       int kernel_leap;
-       struct pmc *pmc;
-       int pmc_ds_requested;
-       uint64_t pmc_last_update;
-       LIST_HEAD(clock_head, clock) clocks;
-       struct clock *master;
-};
-
-static int update_sync_offset(struct node *node);
-static int clock_handle_leap(struct node *node, struct clock *clock,
-                            int64_t offset, uint64_t ts, int do_leap);
-
 static int64_t get_sync_offset(struct node *node, struct clock *src)
 {
        int direction = node->forced_sync_offset;
@@ -600,74 +666,6 @@ static int clock_handle_leap(struct node *node, struct 
clock *clock,
        return 0;
 }
 
-static int clock_add(struct node *node, clockid_t clkid)
-{
-       struct clock *c;
-       int max_ppb;
-       double ppb;
-
-       c = calloc(1, sizeof(*c));
-       if (!c) {
-               pr_err("failed to allocate memory for a clock");
-               return -1;
-       }
-       c->clkid = clkid;
-       c->servo_state = SERVO_UNLOCKED;
-
-       if (c->clkid == CLOCK_REALTIME) {
-               c->source_label = "sys";
-               c->is_utc = 1;
-       } else {
-               c->source_label = "phc";
-       }
-
-       if (node->stats_max_count > 0) {
-               c->offset_stats = stats_create();
-               c->freq_stats = stats_create();
-               c->delay_stats = stats_create();
-               if (!c->offset_stats ||
-                   !c->freq_stats ||
-                   !c->delay_stats) {
-                       pr_err("failed to create stats");
-                       return -1;
-               }
-       }
-       if (node->sanity_freq_limit) {
-               c->sanity_check = clockcheck_create(node->sanity_freq_limit);
-               if (!c->sanity_check) {
-                       pr_err("failed to create clock check");
-                       return -1;
-               }
-       }
-
-       clockadj_init(c->clkid);
-       ppb = clockadj_get_freq(c->clkid);
-       /* The reading may silently fail and return 0, reset the frequency to
-          make sure ppb is the actual frequency of the clock. */
-       clockadj_set_freq(c->clkid, ppb);
-       if (c->clkid == CLOCK_REALTIME) {
-               sysclk_set_leap(0);
-               max_ppb = sysclk_max_freq();
-       } else {
-               max_ppb = phc_max_adj(c->clkid);
-               if (!max_ppb) {
-                       pr_err("clock is not adjustable");
-                       return -1;
-               }
-       }
-
-       c->servo = servo_create(node->servo_type, -ppb, max_ppb, 0);
-       servo_sync_interval(c->servo, node->phc_interval);
-
-       if (clkid != CLOCK_REALTIME)
-               c->sysoff_supported = (SYSOFF_SUPPORTED ==
-                                      sysoff_probe(CLOCKID_TO_FD(clkid),
-                                                   node->phc_readings));
-
-       LIST_INSERT_HEAD(&node->clocks, c, list);
-       return 0;
-}
-
 static void usage(char *progname)
 {
        fprintf(stderr,
-- 
1.7.6.5


------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to