Commit 0a8e929e authored by Pietro Fezzardi's avatar Pietro Fezzardi Committed by Alessandro Rubini

use INST() to access instances everywhere

given that INTS() is defined as inline it should not affect
the performance even in time-critical cases.
parent 85e1aa6a
......@@ -24,7 +24,7 @@ static int run_all_state_machines(struct pp_globals *ppg)
int delay_ms = 0, delay_ms_j;
for (j = 0; j < ppg->nlinks; j++) {
struct pp_instance *ppi = &ppg->pp_instances[j];
struct pp_instance *ppi = INST(ppg, j);
delay_ms_j = pp_state_machine(ppi, NULL, 0);
/* delay_ms is the least delay_ms among all instances */
......@@ -46,7 +46,7 @@ void unix_main_loop(struct pp_globals *ppg)
/* Initialize each link's state machine */
for (j = 0; j < ppg->nlinks; j++) {
ppi = &ppg->pp_instances[j];
ppi = INST(ppg, j);
/*
* If we are sending or receiving raw ethernet frames,
......@@ -76,7 +76,7 @@ void unix_main_loop(struct pp_globals *ppg)
if (ppg->ebest_updated) {
for (j = 0; j < ppg->nlinks; j++) {
int new_state;
struct pp_instance *ppi = &ppg->pp_instances[j];
struct pp_instance *ppi = INST(ppg, j);
new_state = bmc(ppi);
if (new_state != ppi->state) {
ppi->state = new_state;
......@@ -104,7 +104,7 @@ void unix_main_loop(struct pp_globals *ppg)
for (j = 0; j < ppg->nlinks; j++) {
int tmp_d;
ppi = &ppg->pp_instances[j];
ppi = INST(ppg, j);
if ((NP(ppi)->ch[PP_NP_GEN].pkt_present) ||
(NP(ppi)->ch[PP_NP_EVT].pkt_present)) {
......
......@@ -72,7 +72,7 @@ int main(int argc, char **argv)
for (i = 0; i < ppg->nlinks; i++) {
ppi = &ppg->pp_instances[i];
ppi = INST(ppg, i);
NP(ppi)->ch[PP_NP_EVT].fd = -1;
NP(ppi)->ch[PP_NP_GEN].fd = -1;
......
......@@ -28,7 +28,7 @@ static int run_all_state_machines(struct pp_globals *ppg)
int delay_ms = 0, delay_ms_j;
for (j = 0; j < ppg->nlinks; j++) {
struct pp_instance *ppi = &ppg->pp_instances[j];
struct pp_instance *ppi = INST(ppg, j);
int old_lu = WR_DSPOR(ppi)->linkUP;
hexp_port_state_t state;
......@@ -82,7 +82,7 @@ void wrs_main_loop(struct pp_globals *ppg)
/* Initialize each link's state machine */
for (j = 0; j < ppg->nlinks; j++) {
ppi = &ppg->pp_instances[j];
ppi = INST(ppg, j);
/*
* If we are sending or receiving raw ethernet frames,
......@@ -114,7 +114,7 @@ void wrs_main_loop(struct pp_globals *ppg)
if (ppg->ebest_updated) {
for (j = 0; j < ppg->nlinks; j++) {
int new_state;
struct pp_instance *ppi = &ppg->pp_instances[j];
struct pp_instance *ppi = INST(ppg, j);
new_state = bmc(ppi);
if (new_state != ppi->state) {
ppi->state = new_state;
......@@ -142,7 +142,7 @@ void wrs_main_loop(struct pp_globals *ppg)
for (j = 0; j < ppg->nlinks; j++) {
int tmp_d;
ppi = &ppg->pp_instances[j];
ppi = INST(ppg, j);
if ((NP(ppi)->ch[PP_NP_GEN].pkt_present) ||
(NP(ppi)->ch[PP_NP_EVT].pkt_present)) {
......
......@@ -132,7 +132,7 @@ int main(int argc, char **argv)
}
for (i = 0; i < ppg->nlinks; i++) {
ppi = &ppg->pp_instances[i];
ppi = INST(ppg, i);
NP(ppi)->ch[PP_NP_EVT].fd = -1;
NP(ppi)->ch[PP_NP_GEN].fd = -1;
......
......@@ -160,7 +160,7 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv)
case 'b':
a = argv[++i];
if (ppg->nlinks == 1)
ppg->pp_instances[0].iface_name = a;
INST(ppg, 0)->iface_name = a;
else {
/* If ppsi.conf exists and more than one link is
* configured, it makes no sense trying to set an iface
......@@ -197,7 +197,7 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv)
= PP_CLASS_SLAVE_ONLY;
/* Apply -g option globally, to each configured link */
for (j = 0; j < ppg->nlinks; j++)
ppg->pp_instances[j].slave_only = 1;
INST(ppg, j)->slave_only = 1;
break;
case 'v':
a = argv[++i];
......@@ -228,7 +228,7 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv)
case 'e':
/* Apply -e option globally, to each configured link */
for (j = 0; j < ppg->nlinks; j++)
ppg->pp_instances[j].ethernet_mode = 1;
INST(ppg, j)->ethernet_mode = 1;
break;
case 'G':
/* gptp_mode not supported: fall through */
......
......@@ -25,7 +25,7 @@ static int f_port(int lineno, union pp_cfg_arg *arg)
/* First look for an existing port with the same name */
for (i = 0; i < current_ppg->nlinks; i++) {
current_ppi = current_ppg->pp_instances + i;
current_ppi = INST(current_ppg, i);
if (!strcmp(arg->s, current_ppi->cfg.port_name))
return 0;
}
......@@ -35,7 +35,7 @@ static int f_port(int lineno, union pp_cfg_arg *arg)
lineno);
return -1;
}
current_ppi = current_ppg->pp_instances + current_ppg->nlinks;
current_ppi = INST(current_ppg, current_ppg->nlinks);
/* FIXME: strncpy (it is missing in bare archs by now) */
strcpy(current_ppi->cfg.port_name, arg->s);
......
......@@ -32,16 +32,16 @@ static int wr_open(struct pp_globals *ppg, struct pp_runtime_opts *rt_opts)
* configuration, just assume there is one ppi instance,
* already configured properly by the arch's main loop */
if (ppg->nlinks == 0) {
ppg->pp_instances[0].ext_data = &wr_data;
INST(ppg, 0)->ext_data = &wr_data;
return 0;
}
for (i = 0; i < ppg->nlinks; i++) {
struct pp_instance *ppi = &ppg->pp_instances[i];
struct pp_instance *ppi = INST(ppg, i);
/* FIXME check if correct: assign to each instance the same
* wr_data. May I move it to pp_globals? */
ppg->pp_instances[i].ext_data = &wr_data;
INST(ppg, i)->ext_data = &wr_data;
if (ppi->cfg.ext == PPSI_EXT_WR) {
switch (ppi->cfg.role) {
......
......@@ -265,8 +265,8 @@ void bmc_update_ebest(struct pp_globals *ppg)
for (i = 1, best = 0; i < ppg->defaultDS->numberPorts; i++) {
ppi_best = &ppg->pp_instances[best];
ppi = &ppg->pp_instances[i];
ppi_best = INST(ppg, best);
ppi = INST(ppg, i);
if ((ppi->frgn_rec_num > 0) &&
(bmc_dataset_cmp(ppi,
......
......@@ -63,7 +63,7 @@ int pp_init_globals(struct pp_globals *ppg, struct pp_runtime_opts *pp_rt_opts)
sizeof(ClockQuality));
if (def->numberPorts == 1)
def->slaveOnly = ppg->pp_instances[0].slave_only;
def->slaveOnly = INST(ppg, 0)->slave_only;
else
def->slaveOnly = 1; /* the for cycle below will set it to 0 if not
* ports are not all slave_only */
......@@ -73,7 +73,7 @@ int pp_init_globals(struct pp_globals *ppg, struct pp_runtime_opts *pp_rt_opts)
def->domainNumber = rt_opts->domain_number;
for (i = 0; i < def->numberPorts; i++) {
struct pp_instance *ppi = &ppg->pp_instances[i];
struct pp_instance *ppi = INST(ppg, i);
if (def->slaveOnly && !ppi->slave_only)
def->slaveOnly = 0;
......
......@@ -428,7 +428,7 @@ static int unix_net_check_packet(struct pp_globals *ppg, int delay_ms)
FD_ZERO(&set);
for (j = 0; j < ppg->nlinks; j++) {
struct pp_instance *ppi = &ppg->pp_instances[j];
struct pp_instance *ppi = INST(ppg, j);
int fd_to_set;
/* Use either fd that is valid, irrespective of ether/udp */
......@@ -454,7 +454,7 @@ static int unix_net_check_packet(struct pp_globals *ppg, int delay_ms)
return 0;
for (j = 0; j < ppg->nlinks; j++) {
struct pp_instance *ppi = &ppg->pp_instances[j];
struct pp_instance *ppi = INST(ppg, j);
int fd = NP(ppi)->ch[PP_NP_GEN].fd;
if (fd >= 0 && FD_ISSET(fd, &set)) {
......
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