Commit d93b31c7 authored by Alessandro Rubini's avatar Alessandro Rubini

general: move buffers our of pp_instance, and make them smaller

In order to fit all pp_instance items withing WRS shared memory,
we need to make them a little smaller.  Thus, the tx and rx buffers
are now allocated separately.  And, while I am at it, I make them
smaller, because 128 bytes are more than enough for PTP with
extensions (all frames are under 100 bytes). Given we are always
showr of memory in wrpc-sw, this is benefical.

As a side effect, clean up some out-of-memory exit paths, and fix a
use-before-check buglet in arch-unix (no, we never go out of memory,
but the check was wrong).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent ff1c7bb1
......@@ -58,6 +58,8 @@ static int sim_ppi_init(struct pp_instance *ppi, int which_ppi)
{
struct sim_ppi_arch_data *data;
ppi->proto = PP_DEFAULT_PROTO;
ppi->__tx_buffer = malloc(PP_MAX_FRAME_LENGTH);
ppi->__rx_buffer = malloc(PP_MAX_FRAME_LENGTH);
ppi->arch_data = calloc(1, sizeof(struct sim_ppi_arch_data));
ppi->portDS = calloc(1, sizeof(*ppi->portDS));
if ((!ppi->arch_data) || (!ppi->portDS))
......
......@@ -55,15 +55,19 @@ int main(int argc, char **argv)
ppg->max_links = PP_MAX_LINKS;
ppg->arch_data = calloc(1, sizeof(struct unix_arch_data));
ppg->pp_instances = calloc(ppg->max_links, sizeof(struct pp_instance));
if ((!ppg->arch_data) || (!ppg->pp_instances)) {
fprintf(stderr, "ppsi: out of memory\n");
exit(1);
}
/* Before the configuration is parsed, set defaults */
for (i = 0; i < ppg->max_links; i++) {
ppi = INST(ppg, i);
ppi->proto = PP_DEFAULT_PROTO;
ppi->role = PP_DEFAULT_ROLE;
}
if ((!ppg->arch_data) || (!ppg->pp_instances))
exit(__LINE__);
/* Set offset here, so config parsing can override it */
if (adjtimex(&t) >= 0)
timePropertiesDS.currentUtcOffset = t.tai;
......@@ -87,16 +91,19 @@ int main(int argc, char **argv)
ppi->iface_name = ppi->cfg.iface_name;
ppi->port_name = ppi->cfg.port_name;
ppi->portDS = calloc(1, sizeof(*ppi->portDS));
/* The following default names depend on TIME= at build time */
ppi->n_ops = &DEFAULT_NET_OPS;
ppi->t_ops = &DEFAULT_TIME_OPS;
if (!ppi->portDS)
exit(__LINE__);
}
ppi->portDS = calloc(1, sizeof(*ppi->portDS));
ppi->__tx_buffer = malloc(PP_MAX_FRAME_LENGTH);
ppi->__rx_buffer = malloc(PP_MAX_FRAME_LENGTH);
if (!ppi->portDS || !ppi->__tx_buffer || !ppi->__rx_buffer) {
fprintf(stderr, "ppsi: out of memory\n");
exit(1);
}
}
pp_init_globals(ppg, &__pp_default_rt_opts);
seed = time(NULL);
......
......@@ -67,6 +67,8 @@ static int start_tics = 0;
static int last_link_up = 0;
static struct pp_globals ppg_static; /* forward declaration */
static unsigned char __tx_buffer[PP_MAX_FRAME_LENGTH];
static unsigned char __rx_buffer[PP_MAX_FRAME_LENGTH];
/* despite the name, ppi_static is not static: tests/measure_t24p.c uses it */
struct pp_instance ppi_static = {
......@@ -77,6 +79,8 @@ struct pp_instance ppi_static = {
.proto = PP_DEFAULT_PROTO,
.iface_name = "wr1",
.port_name = "wr1",
.__tx_buffer = __tx_buffer,
.__rx_buffer = __rx_buffer,
};
/* We now have a structure with all globals, and multiple ppi inside */
......
......@@ -132,8 +132,10 @@ int main(int argc, char **argv)
ppg->arch_data = calloc(1, sizeof(struct unix_arch_data));
ppg->pp_instances = calloc(ppg->max_links, sizeof(struct pp_instance));
if ((!ppg->arch_data) || (!ppg->pp_instances))
exit(__LINE__);
if ((!ppg->arch_data) || (!ppg->pp_instances)) {
fprintf(stderr, "ppsi: out of memory\n");
exit(1);
}
/* Set offset here, so config parsing can override it */
if (adjtimex(&t) >= 0) {
......@@ -176,12 +178,13 @@ int main(int argc, char **argv)
ppi->iface_name = ppi->cfg.iface_name;
ppi->port_name = ppi->cfg.port_name;
ppi->portDS = calloc(1, sizeof(*ppi->portDS));
if (!ppi->portDS)
exit(__LINE__);
ppi->portDS->ext_dsport = calloc(1, sizeof(struct wr_dsport));
if (!ppi->portDS->ext_dsport)
exit(__LINE__);
if (ppi->portDS)
ppi->portDS->ext_dsport =
calloc(1, sizeof(struct wr_dsport));
if (!ppi->portDS || !ppi->portDS->ext_dsport) {
fprintf(stderr, "ppsi: out of memory\n");
exit(1);
}
wrp = WR_DSPOR(ppi); /* just allocated above */
wrp->ops = &wrs_wr_operations;
......@@ -189,6 +192,14 @@ int main(int argc, char **argv)
ppi->n_ops = &DEFAULT_NET_OPS;
ppi->t_ops = &DEFAULT_TIME_OPS;
ppi->portDS = calloc(1, sizeof(*ppi->portDS));
ppi->__tx_buffer = malloc(PP_MAX_FRAME_LENGTH);
ppi->__rx_buffer = malloc(PP_MAX_FRAME_LENGTH);
if (!ppi->__tx_buffer || !ppi->__rx_buffer) {
fprintf(stderr, "ppsi: out of memory\n");
exit(1);
}
}
pp_init_globals(ppg, &__pp_default_rt_opts);
......
......@@ -79,7 +79,7 @@ enum pp_timeouts {
#define PP_MANAGEMENT_LENGTH 48
#define PP_MINIMUM_LENGTH 44
#define PP_MAX_FRAME_LENGTH 200 /* must fit extension and ethhdr */
#define PP_MAX_FRAME_LENGTH 128 /* must fit extension and ethhdr */
#define PP_DEFAULT_NEXT_DELAY_MS 1000
......
......@@ -151,11 +151,11 @@ struct pp_instance {
struct pp_time_operations *t_ops;
/*
* We host the buffer for this fsm here, tracking both frame
* and payload. send/recv get the frame, pack/unpack the payload
* The buffer for this fsm are allocated. Then we need two
* extra pointer to track separately the frame and payload.
* So send/recv use the frame, pack/unpack use the payload.
*/
unsigned char tx_buffer[PP_MAX_FRAME_LENGTH];
unsigned char rx_buffer[PP_MAX_FRAME_LENGTH];
void *__tx_buffer, *__rx_buffer;
void *tx_frame, *rx_frame, *tx_ptp, *rx_ptp;
/* The net_path used to be allocated separately, but there's no need */
......
......@@ -31,6 +31,8 @@ static DSTimeProperties timePropertiesDS;
static struct pp_servo servo;
static struct pp_globals ppg_static; /* forward declaration */
static unsigned char __tx_buffer[PP_MAX_FRAME_LENGTH];
static unsigned char __rx_buffer[PP_MAX_FRAME_LENGTH];
static struct pp_instance ppi_static = {
.glbs = &ppg_static,
......@@ -40,6 +42,8 @@ static struct pp_instance ppi_static = {
.iface_name = "eth0",
.port_name = "eth0",
.proto = PP_DEFAULT_PROTO,
.__tx_buffer = __tx_buffer,
.__rx_buffer = __rx_buffer,
};
/* We now have a structure with all globals, and multiple ppi inside */
......
......@@ -25,8 +25,8 @@ static void *__align_pointer(void *p)
void pp_prepare_pointers(struct pp_instance *ppi)
{
ppi->tx_ptp = __align_pointer(pp_get_payload(ppi, ppi->tx_buffer));
ppi->rx_ptp = __align_pointer(pp_get_payload(ppi, ppi->rx_buffer));
ppi->tx_ptp = __align_pointer(pp_get_payload(ppi, ppi->__tx_buffer));
ppi->rx_ptp = __align_pointer(pp_get_payload(ppi, ppi->__rx_buffer));
/* Now that ptp payload is aligned, get back the header */
ppi->tx_frame = pp_get_header(ppi, ppi->tx_ptp);
......@@ -34,9 +34,9 @@ void pp_prepare_pointers(struct pp_instance *ppi)
if (0) { /* enable to verify... it works for me though */
pp_printf("%p -> %p %p\n",
ppi->tx_buffer, ppi->tx_frame, ppi->tx_ptp);
ppi->__tx_buffer, ppi->tx_frame, ppi->tx_ptp);
pp_printf("%p -> %p %p\n",
ppi->rx_buffer, ppi->rx_frame, ppi->rx_ptp);
ppi->__rx_buffer, ppi->rx_frame, ppi->rx_ptp);
}
}
......
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