By default, do not synchronize CLOCK_REALTIME. To do it, -r option is
needed. That will only consider CLOCK_REALTIME as the destination. To
consider it also as a possible time source, use -rr.

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

diff --git a/phc2sys.c b/phc2sys.c
index bc5c4dc61073..e184fc9cd637 100644
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -67,6 +67,7 @@ struct clock {
        clockid_t clkid;
        int sysoff_supported;
        int is_utc;
+       int dest_only;
        int state;
        int new_state;
        struct servo *servo;
@@ -323,10 +324,16 @@ static void reconfigure(struct node *node)
                node->master = NULL;
                return;
        }
+       if ((!src_cnt && (!rt || rt->dest_only)) ||
+           (!dst_cnt && !rt)) {
+               pr_info("nothing to synchronize");
+               node->master = NULL;
+               return;
+       }
        if (!src_cnt) {
                src = rt;
                rt->state = PS_SLAVE;
-       } else {
+       } else if (rt) {
                if (rt->state != PS_MASTER) {
                        rt->state = PS_MASTER;
                        clock_reinit(rt);
@@ -884,7 +891,7 @@ static void close_pmc(struct node *node)
        node->pmc = NULL;
 }
 
-static int auto_init_ports(struct node *node)
+static int auto_init_ports(struct node *node, int add_rt)
 {
        struct ptp_message *msg;
        struct port_enumeration_np *pen;
@@ -942,9 +949,14 @@ static int auto_init_ports(struct node *node)
        }
        node->state_changed = 1;
 
-       if (!clock_add(node, "CLOCK_REALTIME")) {
-               res = -1;
-               goto out;
+       if (add_rt) {
+               clock = clock_add(node, "CLOCK_REALTIME");
+               if (!clock) {
+                       res = -1;
+                       goto out;
+               }
+               if (add_rt == 1)
+                       clock->dest_only = 1;
        }
 
        /* get initial offset */
@@ -1042,6 +1054,8 @@ static void usage(char *progname)
                "\n"
                " automatic configuration:\n"
                " -a             turn on autoconfiguration\n"
+               " -r             synchronize system (realtime) clock\n"
+               "                repeat -r to consider it also as a time 
source\n"
                " manual configuration:\n"
                " -c [dev|name]  slave clock (CLOCK_REALTIME)\n"
                " -d [dev]       master PPS device\n"
@@ -1074,7 +1088,7 @@ int main(int argc, char *argv[])
        char *progname;
        char *src_name = NULL, *dst_name = NULL;
        struct clock *src, *dst;
-       int autocfg = 0;
+       int autocfg = 0, rt = 0;
        int c, domain_number = 0, pps_fd = -1;
        int r, wait_sync = 0;
        int print_level = LOG_INFO, use_syslog = 1, verbose = 0;
@@ -1094,11 +1108,14 @@ int main(int argc, char *argv[])
        progname = strrchr(argv[0], '/');
        progname = progname ? 1+progname : argv[0];
        while (EOF != (c = getopt(argc, argv,
-                                 "ac:d:s:E:P:I:S:F:R:N:O:L:i:u:wn:xl:mqvh"))) {
+                                 "arc:d:s:E:P:I:S:F:R:N:O:L:i:u:wn:xl:mqvh"))) 
{
                switch (c) {
                case 'a':
                        autocfg = 1;
                        break;
+               case 'r':
+                       rt++;
+                       break;
                case 'c':
                        dst_name = strdup(optarg);
                        break;
@@ -1228,7 +1245,7 @@ int main(int argc, char *argv[])
        if (autocfg) {
                if (init_pmc(&node, domain_number))
                        return -1;
-               if (auto_init_ports(&node) < 0)
+               if (auto_init_ports(&node, rt) < 0)
                        return -1;
                return do_loop(&node, 1);
        }
-- 
1.7.6.5


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to