Commit 2dc1b909 authored by Adam Wujek's avatar Adam Wujek 💬

Merge branch jcb-bmc-optimization

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parents 73ebe33f 06f1986c
......@@ -15,5 +15,15 @@
# define ntohl htonl
#endif
/* Code optimization for WRPC architecture */
#ifndef CODEOPT_BMCA
#define CODEOPT_BMCA 1 /* Code optimization for BMCA. Can be overwritten in the makefile*/
#endif
#define CODEOPT_ONE_PORT() (1 && CODEOPT_BMCA==1) /* Code optimization when only one port is used. */
#define CODEOPT_ROLE_MASTER_SLAVE_ONLY() (1 && CODEOPT_BMCA==1) /* Code optimization when only one port is used. */
#define abs(x) ((x >= 0) ? x : -x)
#endif /* __ARCH_H__ */
......@@ -92,7 +92,7 @@ int pp_leave_current_state(struct pp_instance *ppi)
pp_hooks.state_change(ppi);
/* if the next or old state is non standard PTP reset all timeouts */
if ((ppi->state > PPS_SLAVE) || (ppi->next_state > PPS_SLAVE))
if ((ppi->state > PPS_LAST_STATE) || (ppi->next_state > PPS_LAST_STATE))
pp_timeout_setall(ppi);
ppi->state = ppi->next_state;
......
......@@ -63,7 +63,11 @@
#define PP_SERVO_HOLDOVER 2
#define PP_SERVO_UNLOCKED 3
#define PP_NR_FOREIGN_RECORDS 5
#ifdef CONFIG_ARCH_WRPC
#define PP_NR_FOREIGN_RECORDS 1 /* Does not follow the standard : Clause 9.3.2.4.5 */
#else
#define PP_NR_FOREIGN_RECORDS 5 /* Clause 9.3.2.4.5 : Minimum size capacity is 5 */
#endif
#define PP_FOREIGN_MASTER_TIME_WINDOW 4
#define PP_FOREIGN_MASTER_THRESHOLD 2
#define PP_DEFAULT_TTL 1
......
......@@ -80,6 +80,26 @@ extern void __pp_diag(struct pp_instance *ppi, enum pp_diag_things th,
#define pp_diag_allow(ppi_, th_, level_) \
(PP_HAS_DIAG && __PP_DIAG_ALLOW(ppi_, pp_dt_ ## th_, level_))
/*
* Set of useful macros to store temporary diag messages
* 'buff' parameter can be a global or local char pointer.
* Local variables use less code to access them (measure done with lm32 compiler)
*/
#define pp_diag_set_msg(buff,msg) \
({ \
if (PP_HAS_DIAG) \
buff=msg; \
PP_HAS_DIAG; /* return 1 if done, 0 if not done */ \
})
#define pp_diag_clear_msg(buff) pp_diag_set_msg(buff,0)
#define pp_diag_get_msg(buff) buff
#define pp_diag_is_msg_set(buff) \
(PP_HAS_DIAG && (buff!=0))
/*
* And this is the parser of the string. Internally it obeys VERB_LOG_MESGS
* to set the value to 0xfffffff0 to be compatible with previous usage.
......
......@@ -268,6 +268,7 @@ enum pp_std_states {
PPS_PASSIVE,
PPS_UNCALIBRATED,
PPS_SLAVE,
PPS_LAST_STATE=PPS_SLAVE
};
enum pp_std_messages {
......
......@@ -67,19 +67,19 @@ struct pp_frgn_master {
/* how many announce messages from this port where received in the
* interval */
UInteger16 foreignMasterAnnounceMessages[PP_FOREIGN_MASTER_TIME_WINDOW];
/* on which port we received the frame */
PortIdentity receivePortIdentity;
/* BMC related information */
UInteger16 sequenceId;
PortIdentity sourcePortIdentity;
Octet flagField[2];
UInteger16 stepsRemoved;
Integer16 currentUtcOffset;
UInteger8 grandmasterPriority1;
/* on which port we received the frame */
PortIdentity receivePortIdentity;
PortIdentity sourcePortIdentity;
ClockQuality grandmasterClockQuality;
UInteger8 grandmasterPriority2;
ClockIdentity grandmasterIdentity;
UInteger16 stepsRemoved;
UInteger8 grandmasterPriority1;
UInteger8 grandmasterPriority2;
Enumeration8 timeSource;
Octet flagField[2];
unsigned long ext_specific; /* used by extension */
};
......
......@@ -33,6 +33,32 @@
# define CONFIG_HAS_WRPC_FAULTS 0
#endif
/* Default values for code optimization. Can be redefined for each targets in arch/arch.h*/
#ifndef CODEOPT_BMCA
#define CODEOPT_BMCA 0 /* Code optimization for BMCA. If set to 0, remove all code optimizations */
#endif
#ifndef CODEOPT_ONE_PORT
#define CODEOPT_ONE_PORT() (0 && CODEOPT_BMCA==1) /* Code optimization when only one port is used. */
#endif
#ifndef CODEOPT_ONE_FMASTER
#define CODEOPT_ONE_FMASTER() ((PP_NR_FOREIGN_RECORDS==1) && CODEOPT_BMCA==1) /* Code optimization when only one foreign master. */
#endif
#ifndef CODEOPT_ROLE_MASTER_SLAVE_ONLY
#define CODEOPT_ROLE_MASTER_SLAVE_ONLY() ( 0 && CODEOPT_BMCA==1) /* Code optimization when role auto not allowed. */
#endif
#ifdef CONFIG_ARCH_WRPC
#define ARCH_IS_WRPC (1)
#else
#define ARCH_IS_WRPC (0)
#endif
#ifdef CONFIG_ARCH_WRS
#define ARCH_IS_WRS (1)
#else
#define ARCH_IS_WRS (0)
#endif
/* We can't include pp-printf.h when building freestading, so have it here */
extern int pp_printf(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
......@@ -370,25 +396,13 @@ extern void bmc_s1(struct pp_instance *ppi,
struct pp_frgn_master *frgn_master);
extern void bmc_p1(struct pp_instance *ppi);
extern void bmc_p2(struct pp_instance *ppi);
extern void bmc_setup_local_frgn_master(struct pp_instance *ppi,
struct pp_frgn_master *frgn_master);
extern int bmc_idcmp(struct ClockIdentity *a, struct ClockIdentity *b);
extern int bmc_pidcmp(struct PortIdentity *a, struct PortIdentity *b);
extern int bmc(struct pp_instance *ppi);
extern int bmc_gm_cmp(struct pp_instance *ppi,
struct pp_frgn_master *a,
struct pp_frgn_master *b);
extern int bmc_topology_cmp(struct pp_instance *ppi,
struct pp_frgn_master *a,
struct pp_frgn_master *b);
extern int bmc_dataset_cmp(struct pp_instance *ppi,
struct pp_frgn_master *a,
struct pp_frgn_master *b);
extern void bmc_store_frgn_master(struct pp_instance *ppi,
struct pp_frgn_master *frgn_master, void *buf, int len);
extern void bmc_add_frgn_master(struct pp_instance *ppi, void *buf,
int len);
extern int bmc_check_frgn_master(struct pp_instance *ppi);
/* msg.c */
extern void msg_init_header(struct pp_instance *ppi, void *buf);
......
......@@ -161,6 +161,7 @@ static int wr_handle_resp(struct pp_instance *ppi)
static void wr_s1(struct pp_instance *ppi, struct pp_frgn_master *frgn_master)
{
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
WR_DSPOR(ppi)->parentIsWRnode =
((frgn_master->ext_specific & WR_NODE_MODE) != NON_WR);
......@@ -200,15 +201,16 @@ static int wr_handle_announce(struct pp_instance *ppi)
{
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
if ((ppi->state == WRS_PRESENT) ||
(ppi->state == WRS_S_LOCK) ||
(ppi->state == WRS_LOCKED) ||
(ppi->state == WRS_CALIBRATION) ||
(ppi->state == WRS_CALIBRATED) ||
(ppi->state == WRS_RESP_CALIB_REQ) ||
(ppi->state == WRS_WR_LINK_ON)) {
/* reset announce timeout when in the WR slave states */
pp_timeout_set(ppi, PP_TO_ANN_RECEIPT);
switch (ppi->state) {
case WRS_PRESENT:
case WRS_S_LOCK :
case WRS_LOCKED :
case WRS_CALIBRATION :
case WRS_CALIBRATED :
case WRS_RESP_CALIB_REQ :
case WRS_WR_LINK_ON :
/* reset announce timeout when in the WR slave states */
pp_timeout_set(ppi, PP_TO_ANN_RECEIPT);
}
/* handshake is started in slave mode */
......@@ -295,15 +297,17 @@ static int wr_state_decision(struct pp_instance *ppi, int next_state)
* if in one of the WR states stay in them,
* they will eventually go back to the normal states
*/
if ((ppi->state == WRS_PRESENT) ||
(ppi->state == WRS_M_LOCK) ||
(ppi->state == WRS_S_LOCK) ||
(ppi->state == WRS_LOCKED) ||
(ppi->state == WRS_CALIBRATION) ||
(ppi->state == WRS_CALIBRATED) ||
(ppi->state == WRS_RESP_CALIB_REQ) ||
(ppi->state == WRS_WR_LINK_ON))
return ppi->state;
switch (ppi->state ) {
case WRS_PRESENT :
case WRS_M_LOCK :
case WRS_S_LOCK :
case WRS_LOCKED :
case WRS_CALIBRATION :
case WRS_CALIBRATED :
case WRS_RESP_CALIB_REQ :
case WRS_WR_LINK_ON :
return ppi->state;
}
/* else do the normal statemachine */
return next_state;
......@@ -315,15 +319,17 @@ static void wr_state_change(struct pp_instance *ppi)
pp_diag(ppi, ext, 2, "hook: %s\n", __func__);
if ((ppi->next_state == WRS_PRESENT) ||
(ppi->next_state == WRS_M_LOCK) ||
(ppi->next_state == WRS_S_LOCK) ||
(ppi->next_state == WRS_LOCKED) ||
(ppi->next_state == WRS_CALIBRATION) ||
(ppi->next_state == WRS_CALIBRATED) ||
(ppi->next_state == WRS_RESP_CALIB_REQ) ||
(ppi->next_state == WRS_WR_LINK_ON))
return;
switch (ppi->next_state) {
case WRS_PRESENT :
case WRS_M_LOCK :
case WRS_S_LOCK :
case WRS_LOCKED :
case WRS_CALIBRATION :
case WRS_CALIBRATED :
case WRS_RESP_CALIB_REQ :
case WRS_WR_LINK_ON :
return;
}
/* if we are leaving the WR locked states reset the WR process */
if ((ppi->next_state != ppi->state) &&
......
......@@ -43,5 +43,8 @@ int wr_s_lock(struct pp_instance *ppi, void *buf, int len)
ppi->next_delay = 0;
}
/* Calibration can take time so we restart the BMC timer to avoid aged foreign master removed. */
pp_timeout_set(ppi, PP_TO_BMC);
return 0;
}
......@@ -3,12 +3,6 @@
#include "wr-api.h"
#include <libwr/shmem.h>
#ifdef CONFIG_ARCH_WRS
#define ARCH_IS_WRS 1
#else
#define ARCH_IS_WRS 0
#endif
#ifdef CONFIG_WRPC_FAULTS
#define HAS_FAULTS 1
#else
......
This diff is collapsed.
This diff is collapsed.
......@@ -8,13 +8,6 @@
#include <ppsi/ppsi.h>
#include "common-fun.h"
#include "../lib/network_types.h"
#include "../proto-ext-whiterabbit/wr-api.h" /* FIXME: phase_to_cf_units */
#ifdef CONFIG_ARCH_WRS
#define ARCH_IS_WRS 1
#else
#define ARCH_IS_WRS 0
#endif
void *msg_copy_header(MsgHeader *dest, MsgHeader *src)
{
......@@ -98,7 +91,7 @@ int st_com_check_announce_receive_timeout(struct pp_instance *ppi)
pp_timeout_set(ppi, PP_TO_ANN_RECEIPT);
if (DSDEF(ppi)->clockQuality.clockClass != PP_CLASS_SLAVE_ONLY
&& (ppi->role != PPSI_ROLE_SLAVE)) {
if (DSDEF(ppi)->numberPorts > 1) {
if (!CODEOPT_ONE_PORT() && DSDEF(ppi)->numberPorts > 1) {
for (i = 0; i < ppg->defaultDS->numberPorts; i++) {
if ((INST(ppg, i)->state == PPS_UNCALIBRATED) ||
(INST(ppg, i)->state == PPS_SLAVE))
......
......@@ -53,7 +53,7 @@ int pp_initializing(struct pp_instance *ppi, void *buf, int len)
goto failure;
/* only fill in the data set when initializing */
if (DSDEF(ppi)->numberPorts > 1) {
if (!CODEOPT_ONE_PORT() && DSDEF(ppi)->numberPorts > 1) {
for (i = 0; i < ppg->defaultDS->numberPorts; i++) {
if ((INST(ppg, i)->state != PPS_INITIALIZING) && (INST(ppg, i)->link_up == TRUE))
initds = 0;
......@@ -65,7 +65,7 @@ int pp_initializing(struct pp_instance *ppi, void *buf, int len)
*/
if (initds)
{
if (DSDEF(ppi)->numberPorts > 1) {
if (!CODEOPT_ONE_PORT() && DSDEF(ppi)->numberPorts > 1) {
/* Clock identity comes from mac address with 0xff:0xfe intermixed */
mac = ppi->ch[PP_NP_GEN].addr;
/* calculate MAC of Port 0 */
......@@ -84,14 +84,9 @@ int pp_initializing(struct pp_instance *ppi, void *buf, int len)
mac_port1[i] = ((unsigned char*)ppi->ch[PP_NP_GEN].addr)[i];
}
DSDEF(ppi)->clockIdentity.id[0] = mac_port1[0];
DSDEF(ppi)->clockIdentity.id[1] = mac_port1[1];
DSDEF(ppi)->clockIdentity.id[2] = mac_port1[2];
memcpy( DSDEF(ppi)->clockIdentity.id, mac_port1, PP_CLOCK_IDENTITY_LENGTH);
DSDEF(ppi)->clockIdentity.id[3] = 0xff;
DSDEF(ppi)->clockIdentity.id[4] = 0xfe;
DSDEF(ppi)->clockIdentity.id[5] = mac_port1[3];
DSDEF(ppi)->clockIdentity.id[6] = mac_port1[4];
DSDEF(ppi)->clockIdentity.id[7] = mac_port1[5];
init_parent_ds(ppi);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment