Commit 77db1c77 authored by Pietro Fezzardi's avatar Pietro Fezzardi Committed by Alessandro Rubini

arch-sim: use new functions to access instances

when possible substitute the access pattern

	ppi = &ppg->pp_instances[n];

with
	ppi = INST(ppg, n);

In the simulator-specific code also pp_sim_get_master() and
pp_sim_get_slave() are used. Finally pp_sim_is_master() and
pp_sim_is_slave() are used to make the conditions easier to
understand
parent 40288459
......@@ -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);
sim_set_global_DS(ppi);
delay_ms_j = pp_state_machine(ppi, NULL, 0);
......@@ -48,7 +48,7 @@ void sim_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);
ppi->is_new_state = 1;
}
......@@ -63,7 +63,7 @@ void sim_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;
......@@ -74,7 +74,7 @@ void sim_main_loop(struct pp_globals *ppg)
}
while (data->n_pending && data->pending->delay_ns <= delay_ns) {
ppi = &ppg->pp_instances[data->pending->which_ppi];
ppi = INST(ppg, data->pending->which_ppi);
sim_fast_forward_ns(ppg, data->pending->delay_ns);
delay_ns -= data->pending->delay_ns;
......
......@@ -79,7 +79,7 @@ static int sim_ppi_init(struct pp_instance *ppi, int which_ppi)
data->rt_opts = &sim_master_rt_opts;
else
data->rt_opts = &__pp_default_rt_opts;
data->other_ppi = &ppi->glbs->pp_instances[- (which_ppi - 1)];
data->other_ppi = INST(ppi->glbs, -(which_ppi - 1));
return 0;
}
......@@ -102,7 +102,7 @@ int main(int argc, char **argv)
/* Alloc data stuctures inside the pp_instances */
for (i = 0; i < ppg->max_links; i++) {
ppi = &ppg->pp_instances[i];
ppi = INST(ppg, i);
ppi->glbs = ppg; // must be done before using sim_set_global_DS
if (sim_ppi_init(ppi, i))
return -1;
......@@ -118,14 +118,14 @@ int main(int argc, char **argv)
* master config later because the initial time for the master is needed
* to set the initial offset for the slave
*/
sim_set_global_DS(&ppg->pp_instances[SIM_MASTER]);
sim_set_global_DS(pp_sim_get_master(ppg));
pp_config_string(ppg, strdup("port SIM_MASTER; iface MASTER;"
"proto udp; role master;"
"sim_duration_sec 3600;" // one hour
"sim_init_master_time 10.0;"));
/* parse commandline for configuration options */
sim_set_global_DS(&ppg->pp_instances[SIM_SLAVE]);
sim_set_global_DS(pp_sim_get_slave(ppg));
if (pp_parse_cmdline(ppg, argc, argv) != 0)
return -1;
/* If no item has been parsed, provide default file or string */
......@@ -136,7 +136,7 @@ int main(int argc, char **argv)
"proto udp; role slave;"));
for (i = 0; i < ppg->nlinks; i++) {
ppi = &ppg->pp_instances[i];
ppi = INST(ppg, i);
sim_set_global_DS(ppi);
ppi->iface_name = ppi->cfg.iface_name;
if (ppi->cfg.proto == PPSI_PROTO_RAW)
......@@ -154,7 +154,7 @@ int main(int argc, char **argv)
}
ppi->t_ops = &DEFAULT_TIME_OPS;
ppi->n_ops = &DEFAULT_NET_OPS;
if (ppi - ppi->glbs->pp_instances == SIM_MASTER)
if (pp_sim_is_master(ppi))
pp_init_globals(ppg, &sim_master_rt_opts);
else
pp_init_globals(ppg, &__pp_default_rt_opts);
......
......@@ -161,7 +161,7 @@ static int sim_net_send(struct pp_instance *ppi, void *pkt, int len,
/* only UDP */
addr.sin_family = AF_INET;
if (ppi - ppi->glbs->pp_instances == SIM_SLAVE)
if (pp_sim_is_slave(ppi))
addr.sin_port = htons(chtype == PP_NP_GEN ?
PP_MASTER_GEN_PORT :
PP_MASTER_EVT_PORT);
......@@ -182,7 +182,7 @@ static int sim_net_send(struct pp_instance *ppi, void *pkt, int len,
/* store pending packets in global structure */
pending.chtype = chtype;
if (ppi - ppi->glbs->pp_instances == SIM_MASTER)
if (pp_sim_is_master(ppi))
pending.which_ppi = SIM_SLAVE;
else
pending.which_ppi = SIM_MASTER;
......@@ -254,7 +254,7 @@ static int sim_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
* messages */
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
if ((ppi - ppi->glbs->pp_instances) == SIM_MASTER)
if (pp_sim_is_master(ppi))
addr.sin_port = htons(chtype == PP_NP_GEN ?
PP_MASTER_GEN_PORT :
PP_MASTER_EVT_PORT);
......@@ -273,7 +273,7 @@ static int sim_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
* itself, based on the clockIdentity. This hack avoids this behaviour,
* changing the clockIdentity of the master.
*/
if (ppi - ppi->glbs->pp_instances == SIM_MASTER)
if (pp_sim_is_master(ppi))
memset(NP(ppi)->ch[chtype].addr, 111, 1);
return 0;
......
......@@ -21,7 +21,7 @@ int sim_fast_forward_ns(struct pp_globals *ppg, int64_t ff_ns)
int i;
for (i = 0; i < ppg->nlinks; i++) {
t_inst = &SIM_PPI_ARCH(ppg->pp_instances + i)->time;
t_inst = &SIM_PPI_ARCH(INST(ppg, i))->time;
t_inst->current_ns += ff_ns +
(t_inst->freq_ppm_servo + t_inst->freq_ppm_real) *
ff_ns / 1000 / 1000 / 1000;
......
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