Commit 873d6133 authored by Alessandro Rubini's avatar Alessandro Rubini

Merge branch 'config-hot-fix-and-more'

parents 6a547b67 4b2c69d7
......@@ -162,9 +162,18 @@ config MAX_VLANS_PER_PORT
microcontroller-class architectures. Hosted builds
feature a bigger default, because they have no size constraints.
# I want a number, to be used without ifdef
config VLAN_ARRAY_SIZE
int
default 0 if !VLAN
default 1 if !HAS_MULTIPLE_VLAN
default MAX_VLANS_PER_PORT
config DISABLE_OPTIMIZATION
bool "Disable -O2, to ease running a debugger"
config OPTIMIZATION
int
default 0 if DISABLE_OPTIMIZATION
default 2
......@@ -47,7 +47,8 @@ all: $(TARGET).o
# CFLAGS to use. Both this Makefile (later) and app-makefile may grow CFLAGS
CFLAGS = $(USER_CFLAGS)
CFLAGS += -Wall -Wstrict-prototypes -Wmissing-prototypes
CFLAGS += -O2 -ggdb -Iinclude -fno-common
CFLAGS += -O$(CONFIG_OPTIMIZATION)
CFLAGS += -ggdb -Iinclude -fno-common
CFLAGS += -DPPSI_VERSION=\"$(VERSION)\"
# to avoid ifdef as much as possible, I use the kernel trick for OBJ variables
......
#
# Automatically generated make config: don't edit
#
CONFIG_ARCH_UNIX=y
# CONFIG_ARCH_BARE_I386 is not set
# CONFIG_ARCH_BARE_X86_64 is not set
# CONFIG_ARCH_WRPC is not set
# CONFIG_ARCH_WRS is not set
# CONFIG_ARCH_SIMULATOR is not set
CONFIG_ARCH="unix"
#
# PTP Protocol Options
#
CONFIG_E2E=y
# CONFIG_P2P is not set
CONFIG_EXT_NONE=y
CONFIG_EXTENSION=""
CONFIG_CROSS_COMPILE=""
CONFIG_ARCH_CFLAGS=""
CONFIG_ARCH_LDFLAGS=""
CONFIG_HAS_VLAN=y
CONFIG_HAS_MULTIPLE_VLAN=y
CONFIG_VLAN=y
CONFIG_MAX_VLANS_PER_PORT=32
CONFIG_VLAN_ARRAY_SIZE=32
CONFIG_DISABLE_OPTIMIZATION=y
CONFIG_OPTIMIZATION=0
......@@ -101,10 +101,10 @@ typedef struct PortAdress { /* page 13 (33) */
Octet *adressField;
} PortAdress;
typedef struct ClockQuality { /* page 14 (34) */
UInteger8 clockClass;
Enumeration8 clockAccuracy;
UInteger16 offsetScaledLogVariance;
typedef struct ClockQuality { /* page 14 (34) -- int because of lib/config.c */
int clockClass;
int clockAccuracy;
int offsetScaledLogVariance;
} ClockQuality;
struct TLV { /* page 14 (34) -- never used */
......
......@@ -24,10 +24,10 @@ struct pp_runtime_opts {
Integer16 ap, ai;
Integer16 s;
Integer8 announce_intvl;
Integer8 sync_intvl;
UInteger8 prio1;
UInteger8 prio2;
UInteger8 domain_number;
int sync_intvl;
int prio1;
int prio2;
int domain_number;
void *arch_opts;
};
......@@ -114,7 +114,7 @@ enum { /* The two sockets. They are called "net path" for historical reasons */
struct pp_instance_cfg {
char port_name[16];
char iface_name[16];
int ext; /* 0: none, 1: whiterabbit */ /* FIXME extension enumeration */
int ext; /* 0: none, 1: whiterabbit */
};
/*
......@@ -126,8 +126,8 @@ struct pp_instance {
void *arch_data; /* if arch needs it */
void *ext_data; /* if protocol ext needs it */
unsigned long d_flags; /* diagnostics, ppi-specific flags */
unsigned char flags, /* protocol flags (see below) */
role, /* same as in config file */
unsigned char flags; /* protocol flags (see below) */
int role, /* same as in config file */
proto; /* same as in config file */
/* Pointer to global instance owning this pp_instance*/
......@@ -170,8 +170,6 @@ struct pp_instance {
unsigned long timeouts[__PP_TO_ARRAY_SIZE];
UInteger16 recv_sync_sequence_id;
Integer8 log_min_delay_req_interval;
UInteger16 sent_seq[__PP_NR_MESSAGES_TYPES]; /* last sent this type */
MsgHeader received_ptp_header;
......
......@@ -9,7 +9,7 @@
#include <ppsi/ppsi.h>
#include "common-fun.h"
/* Unpack header from in buffer to msg_tmp_header field */
/* Unpack header from in buffer to receieved_ptp_header field */
int msg_unpack_header(struct pp_instance *ppi, void *buf, int plen)
{
MsgHeader *hdr = &ppi->received_ptp_header;
......@@ -159,7 +159,7 @@ static int msg_pack_announce(struct pp_instance *ppi)
return PP_ANNOUNCE_LENGTH;
}
/* Unpack Announce message from in buffer of ppi to msgtmp. Announce */
/* Unpack Announce message from in buffer of ppi to internal structure */
void msg_unpack_announce(void *buf, MsgAnnounce *ann)
{
ann->originTimestamp.secondsField.msb =
......@@ -251,7 +251,7 @@ void msg_pack_pdelay_resp_follow_up(struct pp_instance *ppi,
*(UInteger16 *) (buf + 52) = htons(hdr->sourcePortIdentity.portNumber);
}
/* Unpack FollowUp message from in buffer of ppi to msgtmp.follow */
/* Unpack FollowUp message from in buffer of ppi to internal structure */
void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup)
{
flwup->preciseOriginTimestamp.secondsField.msb =
......@@ -262,7 +262,7 @@ void msg_unpack_follow_up(void *buf, MsgFollowUp *flwup)
htonl(*(UInteger32 *) (buf + 40));
}
/* Unpack PDelay Resp FollowUp message from in buffer of ppi to msgtmp.follow */
/* Unpack PDelayRespFollowUp message from in buffer of ppi to internal struct */
void msg_unpack_pdelay_resp_follow_up(void *buf,
MsgPDelayRespFollowUp * pdelay_resp_flwup)
{
......@@ -413,7 +413,7 @@ static void msg_pack_delay_resp(struct pp_instance *ppi,
htons(hdr->sourcePortIdentity.portNumber);
}
/* Unpack delayReq message from in buffer of ppi to msgtmp.req */
/* Unpack delayReq message from in buffer of ppi to internal structure */
void msg_unpack_delay_req(void *buf, MsgDelayReq *delay_req)
{
delay_req->originTimestamp.secondsField.msb =
......@@ -424,7 +424,7 @@ void msg_unpack_delay_req(void *buf, MsgDelayReq *delay_req)
htonl(*(UInteger32 *) (buf + 40));
}
/* Unpack PDelayReq message from in buffer of ppi to msgtmp.req */
/* Unpack PDelayReq message from in buffer of ppi to internal structure */
void msg_unpack_pdelay_req(void *buf, MsgPDelayReq * pdelay_req)
{
pdelay_req->originTimestamp.secondsField.msb =
......@@ -435,7 +435,7 @@ void msg_unpack_pdelay_req(void *buf, MsgPDelayReq * pdelay_req)
htonl(*(UInteger32 *) (buf + 40));
}
/* Unpack delayResp message from IN buffer of ppi to msgtmp.presp */
/* Unpack delayResp message from IN buffer of ppi to internal structure */
void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp)
{
resp->receiveTimestamp.secondsField.msb =
......@@ -450,7 +450,7 @@ void msg_unpack_delay_resp(void *buf, MsgDelayResp *resp)
htons(*(UInteger16 *) (buf + 52));
}
/* Unpack PDelayResp message from IN buffer of ppi to msgtmp.presp */
/* Unpack PDelayResp message from IN buffer of ppi to internal structure */
void msg_unpack_pdelay_resp(void *buf, MsgPDelayResp * presp)
{
presp->requestReceiptTimestamp.secondsField.msb =
......
......@@ -81,9 +81,9 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (e)
goto out;
ppi->log_min_delay_req_interval =
DSPOR(ppi)->logMinDelayReqInterval =
hdr->logMessageInterval;
pp_timeout_init(ppi); /* new value for logMin */
} else {
pp_diag(ppi, frames, 2, "pp_slave : "
"Delay Resp doesn't match Delay Req\n");
......
......@@ -6,23 +6,29 @@
*/
#include <ppsi/ppsi.h>
enum rand_type {
RAND_NONE, /* Not randomized */
RAND_70_130, /* Should be 70% to 130% of 1 << value */
RAND_0_200, /* Should be 0% to 200% of 1 << value */
};
struct timeout_config {
char *name;
int isrand;
int which_rand;
int value;
};
/* most timeouts have a static configuration. Save it here */
static struct timeout_config to_configs[__PP_TO_ARRAY_SIZE] = {
[PP_TO_REQUEST] = {"REQUEST", 1,},
[PP_TO_SYNC_SEND] = {"SYNC_SEND", 1,},
[PP_TO_ANN_RECEIPT] = {"ANN_RECEIPT", 0,},
[PP_TO_ANN_SEND] = {"ANN_SEND", 1,},
[PP_TO_FAULTY] = {"FAULTY", 0, 4000},
[PP_TO_REQUEST] = {"REQUEST", RAND_0_200,},
[PP_TO_SYNC_SEND] = {"SYNC_SEND", RAND_70_130,},
[PP_TO_ANN_RECEIPT] = {"ANN_RECEIPT", RAND_NONE,},
[PP_TO_ANN_SEND] = {"ANN_SEND", RAND_70_130,},
[PP_TO_FAULTY] = {"FAULTY", RAND_NONE, 4000},
/* extension timeouts are explicitly set to a value */
};
/* Init fills the timeout values; they are not changed after program startup */
/* Init fills the timeout values */
void pp_timeout_init(struct pp_instance *ppi)
{
struct DSPort *port = ppi->portDS;
......@@ -36,24 +42,13 @@ void pp_timeout_init(struct pp_instance *ppi)
to_configs[PP_TO_ANN_SEND].value = port->logAnnounceInterval;
}
static void pp_timeout_log(struct pp_instance *ppi, int index)
{
pp_diag(ppi, time, 1, "timeout expired: %s\n",
to_configs[index].name);
}
void __pp_timeout_set(struct pp_instance *ppi, int index, int millisec)
{
ppi->timeouts[index] = ppi->t_ops->calc_timeout(ppi, millisec);
pp_diag(ppi, time, 3, "new timeout for %s: %i\n",
to_configs[index].name, millisec);
}
/*
* Randomize a timeout. We are required to fit between 70% and 130%
* of the value for 90% of the time, at least. But making it "almost
* exact" is bad in a big network. So randomize between 80% and 120%:
* constant part is 80% and variable is 40%.
*/
void pp_timeout_set(struct pp_instance *ppi, int index)
{
......@@ -62,11 +57,6 @@ void pp_timeout_set(struct pp_instance *ppi, int index)
int millisec;
int logval = to_configs[index].value;
if (!to_configs[index].isrand){
__pp_timeout_set(ppi, index, logval); /* not a logval */
return;
}
if (!seed) {
uint32_t *p;
/* use the least 32 bits of the mac address as seed */
......@@ -84,9 +74,28 @@ void pp_timeout_set(struct pp_instance *ppi, int index)
rval <<= 10;
rval ^= (unsigned int) (seed / 65536) % 1024;
millisec = (1 << logval) * 400; /* This is 40% of the nominal value */
millisec = (millisec * 2) + rval % millisec;
/*
* logval is signed. Let's imagine it's no less than -4.
* Here below, 0 gets to 16 * 25 = 400ms, 40% of the nominal value
*/
millisec = (1 << (logval + 4)) * 25;
switch(to_configs[index].which_rand) {
case RAND_70_130:
/*
* We are required to fit between 70% and 130%
* of the value for 90% of the time, at least.
* So randomize between 80% and 120%: constant
* part is 80% and variable is 40%.
*/
millisec = (millisec * 2) + rval % millisec;
break;
case RAND_0_200:
millisec = rval % (millisec * 5);
break;
case RAND_NONE:
millisec = logval; /* not a log, just a constant */
}
__pp_timeout_set(ppi, index, millisec);
}
......@@ -109,7 +118,8 @@ int pp_timeout(struct pp_instance *ppi, int index)
ppi->timeouts[index]);
if (ret)
pp_timeout_log(ppi, index);
pp_diag(ppi, time, 1, "timeout expired: %s\n",
to_configs[index].name);
return ret;
}
......
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