phc2sys: don't synchronize clock to itself.
When ptp4l is using multiple interfaces sharing the same clock, phc2sys in the automatic mode should not try to synchronize them to each other. Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com> Reported-by: Stefan Lange <s.lange@gateware.de>master
parent
8deb52a849
commit
ac92a71161
16
phc2sys.c
16
phc2sys.c
|
@ -72,6 +72,7 @@
|
||||||
struct clock {
|
struct clock {
|
||||||
LIST_ENTRY(clock) list;
|
LIST_ENTRY(clock) list;
|
||||||
clockid_t clkid;
|
clockid_t clkid;
|
||||||
|
int phc_index;
|
||||||
int sysoff_supported;
|
int sysoff_supported;
|
||||||
int is_utc;
|
int is_utc;
|
||||||
int dest_only;
|
int dest_only;
|
||||||
|
@ -127,7 +128,7 @@ static int clock_handle_leap(struct node *node, struct clock *clock,
|
||||||
static int run_pmc_get_utc_offset(struct node *node, int timeout);
|
static int run_pmc_get_utc_offset(struct node *node, int timeout);
|
||||||
static void run_pmc_events(struct node *node);
|
static void run_pmc_events(struct node *node);
|
||||||
|
|
||||||
static clockid_t clock_open(char *device)
|
static clockid_t clock_open(char *device, int *phc_index)
|
||||||
{
|
{
|
||||||
struct sk_ts_info ts_info;
|
struct sk_ts_info ts_info;
|
||||||
char phc_device[16];
|
char phc_device[16];
|
||||||
|
@ -157,6 +158,7 @@ static clockid_t clock_open(char *device)
|
||||||
clkid = phc_open(phc_device);
|
clkid = phc_open(phc_device);
|
||||||
if (clkid == CLOCK_INVALID)
|
if (clkid == CLOCK_INVALID)
|
||||||
fprintf(stderr, "cannot open %s: %m\n", device);
|
fprintf(stderr, "cannot open %s: %m\n", device);
|
||||||
|
*phc_index = ts_info.phc_index;
|
||||||
return clkid;
|
return clkid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,11 +166,11 @@ static struct clock *clock_add(struct node *node, char *device)
|
||||||
{
|
{
|
||||||
struct clock *c;
|
struct clock *c;
|
||||||
clockid_t clkid = CLOCK_INVALID;
|
clockid_t clkid = CLOCK_INVALID;
|
||||||
int max_ppb;
|
int max_ppb, phc_index = -1;
|
||||||
double ppb;
|
double ppb;
|
||||||
|
|
||||||
if (device) {
|
if (device) {
|
||||||
clkid = clock_open(device);
|
clkid = clock_open(device, &phc_index);
|
||||||
if (clkid == CLOCK_INVALID)
|
if (clkid == CLOCK_INVALID)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -179,6 +181,7 @@ static struct clock *clock_add(struct node *node, char *device)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
c->clkid = clkid;
|
c->clkid = clkid;
|
||||||
|
c->phc_index = phc_index;
|
||||||
c->servo_state = SERVO_UNLOCKED;
|
c->servo_state = SERVO_UNLOCKED;
|
||||||
c->device = strdup(device);
|
c->device = strdup(device);
|
||||||
|
|
||||||
|
@ -638,6 +641,13 @@ static int do_loop(struct node *node, int subscriptions)
|
||||||
if (!update_needed(clock))
|
if (!update_needed(clock))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* don't try to synchronize the clock to itself */
|
||||||
|
if (clock->clkid == node->master->clkid ||
|
||||||
|
(clock->phc_index >= 0 &&
|
||||||
|
clock->phc_index == node->master->phc_index) ||
|
||||||
|
!strcmp(clock->device, node->master->device))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (clock->clkid == CLOCK_REALTIME &&
|
if (clock->clkid == CLOCK_REALTIME &&
|
||||||
node->master->sysoff_supported) {
|
node->master->sysoff_supported) {
|
||||||
/* use sysoff */
|
/* use sysoff */
|
||||||
|
|
Loading…
Reference in New Issue