Skip to content

Commit

Permalink
Getting rid of malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
georgit committed Mar 8, 2017
1 parent 4ccb15a commit 455be7e
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions src/components/implementation/fork_tests/voter/voter.c
Expand Up @@ -18,17 +18,17 @@ struct replica_info {
void *buf_write;
unsigned short int thread_id;
int blocked;
u64_t start; // set each time the replica is woken up. Accurate?
};

struct nmod_comp {
struct replica_info *replicas;
struct replica_info replicas[9];// let's call this max
int nreplicas;
};

struct channel {
struct nmod_comp *snd, *rcv;
int data, have_data; // make these arrays
u64_t start; // set each time the replica is woken up. Accurate?
};

struct map_entry {
Expand Down Expand Up @@ -121,58 +121,27 @@ int nread(spdid_t spdid, replica_type from, int data) {
}
}

int confirm(spdid_t spdid, replica_type type) {
printc("Confirming readiness of spdid %d\n", spdid);

int ret;
int i;

int t = (type == ping) ? 0 : 1;
struct replica_info *replicas = components[t].replicas;

for (i = 0; i < components[t].nreplicas; i++) {
if (replicas[i].spdid == 0) {
printc("creating replica for spdid %d in slot %d\n", spdid, i);
replicas[i].spdid = spdid;
//replicas[i].spdid = quarantine_fork(cos_spd_id(), comp2fork);
//if (replicas[i].spdid == 0) printc("Error: f1 fork failed\n");
replicas[i].buf_read = cbuf_alloc(1024, &replicas[i].read_buffer);
replicas[i].buf_write = cbuf_alloc(1024, &replicas[i].write_buffer);
replicas[i].blocked = 0;
replicas[i].thread_id = cos_get_thd_id();

map[spdid].type = type;
map[spdid].replica = &replicas[i];
map[spdid].component = &components[t];
return 0;
}
else {
printc("replica for spdid %d already exists\n", replicas[i].spdid);
}
}
return 0;
}

void restart_comp(struct replica_info *replica) {
printc("About to fork but actually not implemented yet :(\n");
}

void monitor(void) {
struct nmod_comp *rcv_comp, *component;
struct nmod_comp *rcv_comp;
struct channel *channel;
struct replica_info *rcv_replica;
int i, j;
int found = 0;
u64_t time;

/* Let's do waking up and restarting in a separate loop */
for (i = 0; i < N_COMPS; i++) {
component = &components[i];
for (i = 0; i < N_CHANNELS; i++) {
channel = &channels[i];

for (j = 0; j < component->nreplicas; j++) {
for (j = 0; j < channel->rcv->nreplicas; j++) {
rdtscll(time);
printc("time: %lu\n", time - component->replicas[j].start);
if (time > 500) {
restart_comp(&component->replicas[i]);
printc("time: %lu\n", time - channel->start);
if (time > 500) { // this is waaaaaay too small of a timeout. How many cycles are 10 seconds???
restart_comp(&channel->rcv->replicas[i]);
}
}
}
Expand All @@ -181,6 +150,7 @@ void monitor(void) {
printc("Examing channel %d between nmodcomps with replicas %d and %d \n", i, channels[i].snd->replicas[0].spdid, channels[i].rcv->replicas[0].spdid);

printc("channel data present %d (%d)\n", channels[i].have_data, channels[i].data);
rdtscll(channels[i].start);

if (channels[i].have_data) {
rcv_comp = channels[i].rcv;
Expand All @@ -197,7 +167,6 @@ void monitor(void) {
printc("Looking at replica %d\n", rcv_replica->spdid);

if (rcv_replica->blocked) {
rdtscll(rcv_replica->start);
rcv_replica->blocked = 0;
if (!rcv_replica->thread_id) BUG();
printc("waking up thread %d\n", rcv_replica->thread_id);
Expand All @@ -207,13 +176,44 @@ void monitor(void) {
}
}

int confirm(spdid_t spdid, replica_type type) {
printc("Confirming readiness of spdid %d\n", spdid);

int ret;
int i;

int t = (type == ping) ? 0 : 1;
struct replica_info *replicas = components[t].replicas;

for (i = 0; i < components[t].nreplicas; i++) {
if (replicas[i].spdid == 0) {
printc("creating replica for spdid %d in slot %d\n", spdid, i);
replicas[i].spdid = spdid;
//replicas[i].spdid = quarantine_fork(cos_spd_id(), comp2fork);
//if (replicas[i].spdid == 0) printc("Error: f1 fork failed\n");
replicas[i].buf_read = cbuf_alloc(1024, &replicas[i].read_buffer);
replicas[i].buf_write = cbuf_alloc(1024, &replicas[i].write_buffer);
replicas[i].blocked = 0;
replicas[i].thread_id = cos_get_thd_id();

map[spdid].type = type;
map[spdid].replica = &replicas[i];
map[spdid].component = &components[t];
return 0;
}
else {
printc("replica for spdid %d already exists\n", replicas[i].spdid);
}
}
return 0;
}

void cos_init(void)
{
int i, j;
for (i = 0; i < N_COMPS; i++) {
printc("Setting up nmod component %d\n", i);
components[i].nreplicas = 1; // for now, no fork
components[i].replicas = (struct replica_info*) malloc(sizeof(struct replica_info) * components[i].nreplicas);

for (j = 0; j < components[i].nreplicas; j++) {
components[i].replicas[j].spdid = 0;
Expand Down

0 comments on commit 455be7e

Please sign in to comment.