Discussion:
[Linuxptp-devel] [PATCH 1/2] port: Change port_dispatch() into a void function.
Richard Cochran
2017-02-05 17:35:30 UTC
Permalink
This global function used to return an error code, but now it always
returns zero. This patch converts the function signature to return void
and simplifies the main clock loop by removing the useless test.

Signed-off-by: Richard Cochran <***@gmail.com>
---
clock.c | 6 +++---
port.c | 9 ++++-----
port.h | 4 +---
3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/clock.c b/clock.c
index a6a1a1a..f027305 100644
--- a/clock.c
+++ b/clock.c
@@ -1463,7 +1463,7 @@ struct PortIdentity clock_parent_identity(struct clock *c)

int clock_poll(struct clock *c)
{
- int cnt, err, i, sde = 0;
+ int cnt, i, sde = 0;
enum fsm_event event;
struct pollfd *cur;
struct port *p;
@@ -1490,14 +1490,14 @@ int clock_poll(struct clock *c)
cur++;
LIST_FOREACH(p, &c->ports, list) {
/* Let the ports handle their events. */
- for (i = err = 0; i < N_POLLFD && !err; i++) {
+ for (i = 0; i < N_POLLFD; i++) {
if (cur[i].revents & (POLLIN|POLLPRI)) {
event = port_event(p, i);
if (EV_STATE_DECISION_EVENT == event)
sde = 1;
if (EV_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES == event)
sde = 1;
- err = port_dispatch(p, event, 0);
+ port_dispatch(p, event, 0);
/* Clear any fault after a little while. */
if (PS_FAULTY == port_state(p)) {
clock_fault_timeout(p, 1);
diff --git a/port.c b/port.c
index 5f1646b..0f99b1b 100644
--- a/port.c
+++ b/port.c
@@ -2143,7 +2143,7 @@ static void port_p2p_transition(struct port *p, enum port_state next)
};
}

-int port_dispatch(struct port *p, enum fsm_event event, int mdiff)
+void port_dispatch(struct port *p, enum fsm_event event, int mdiff)
{
enum port_state next;

@@ -2180,7 +2180,7 @@ int port_dispatch(struct port *p, enum fsm_event event, int mdiff)
}

if (next == p->state)
- return 0;
+ return;

port_show_transition(p, next, event);

@@ -2196,12 +2196,11 @@ int port_dispatch(struct port *p, enum fsm_event event, int mdiff)
if (p->jbod && next == PS_UNCALIBRATED) {
if (clock_switch_phc(p->clock, p->phc_index)) {
p->last_fault_type = FT_SWITCH_PHC;
- return port_dispatch(p, EV_FAULT_DETECTED, 0);
+ port_dispatch(p, EV_FAULT_DETECTED, 0);
+ return;
}
clock_sync_interval(p->clock, p->log_sync_interval);
}
-
- return 0;
}

enum fsm_event port_event(struct port *p, int fd_index)
diff --git a/port.h b/port.h
index d2e0865..b00bc64 100644
--- a/port.h
+++ b/port.h
@@ -69,10 +69,8 @@ struct foreign_clock *port_compute_best(struct port *port);
* @param port A pointer previously obtained via port_open().
* @param event One of the @a fsm_event codes.
* @param mdiff Whether a new master has been selected.
- * @return Zero if the port's file descriptor array is still valid,
- * and non-zero if it has become invalid.
*/
-int port_dispatch(struct port *p, enum fsm_event event, int mdiff);
+void port_dispatch(struct port *p, enum fsm_event event, int mdiff);

/**
* Generates state machine events based on activity on a port's file
--
2.1.4
Richard Cochran
2017-02-05 17:35:31 UTC
Permalink
Having one fewer port may affect the result of the BMCA. This patch
changes the main loop so that a link down event also causes a state
decision event.

Signed-off-by: Richard Cochran <***@gmail.com>
Reported-by: Henry Jesuiter <***@alcnetworx.de>
---
clock.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/clock.c b/clock.c
index f027305..6ec3e72 100644
--- a/clock.c
+++ b/clock.c
@@ -96,6 +96,7 @@ struct clock {
int pollfd_valid;
int nports; /* does not include the UDS port */
int last_port_number;
+ int sde;
struct hash *index2port;
int free_running;
int freq_est_interval;
@@ -341,6 +342,11 @@ static void clock_link_status(void *ctx, int index, int linkup)
port_dispatch(p, EV_FAULT_CLEARED, 0);
} else {
port_dispatch(p, EV_FAULT_DETECTED, 0);
+ /*
+ * A port going down can affect the BMCA result.
+ * Force a state decision event.
+ */
+ c->sde = 1;
}
}

@@ -1463,7 +1469,7 @@ struct PortIdentity clock_parent_identity(struct clock *c)

int clock_poll(struct clock *c)
{
- int cnt, i, sde = 0;
+ int cnt, i;
enum fsm_event event;
struct pollfd *cur;
struct port *p;
@@ -1494,9 +1500,9 @@ int clock_poll(struct clock *c)
if (cur[i].revents & (POLLIN|POLLPRI)) {
event = port_event(p, i);
if (EV_STATE_DECISION_EVENT == event)
- sde = 1;
+ c->sde = 1;
if (EV_ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES == event)
- sde = 1;
+ c->sde = 1;
port_dispatch(p, event, 0);
/* Clear any fault after a little while. */
if (PS_FAULTY == port_state(p)) {
@@ -1525,13 +1531,14 @@ int clock_poll(struct clock *c)
if (cur[i].revents & (POLLIN|POLLPRI)) {
event = port_event(c->uds_port, i);
if (EV_STATE_DECISION_EVENT == event)
- sde = 1;
+ c->sde = 1;
}
}

- if (sde)
+ if (c->sde) {
handle_state_decision_event(c);
-
+ c->sde = 0;
+ }
clock_prune_subscriptions(c);
return 0;
}
--
2.1.4
Loading...