diff --git a/src/components/implementation/chanmgr/simple/chanmgr.c b/src/components/implementation/chanmgr/simple/chanmgr.c index cae8b24008..3fb38c22ad 100644 --- a/src/components/implementation/chanmgr/simple/chanmgr.c +++ b/src/components/implementation/chanmgr/simple/chanmgr.c @@ -94,6 +94,7 @@ chanmgr_mem_resources(chan_id_t id, cbuf_t *cb_id, void **mem) chinfo = ss_channel_get(id); if (!chinfo) return -1; + *mem = chinfo->mem; *cb_id = chinfo->buf_id; return 0; diff --git a/src/components/implementation/tests/chan_hi/chan1.c b/src/components/implementation/tests/chan_hi/chan1.c index b1713428a1..7ee774366b 100644 --- a/src/components/implementation/tests/chan_hi/chan1.c +++ b/src/components/implementation/tests/chan_hi/chan1.c @@ -8,12 +8,40 @@ struct chan_rcv r; #define COMM_AMNT (2^10 * 16) +/* + * the Receiver and sender tests could run at different times, + * causing the numbers to blow up! + * + * Another issue is, when the high priority thread here is printing, + * the test on the low prio side is not done yet! + * + * So, this routine syncs up between chan_hi and chan_lo wherever required! + * Because this (chan_hi) is high priority thread, send first and wait on rcv! + * The chan_lo would receive first and then send, that should immediately switch over to here! + */ +void +rendezvous(void) +{ + ps_tsc_t rcv = 0, snd = 0; + snd = ps_tsc(); + if (chan_send(&s, &snd, 0)) { + printc("chan_send error\n"); + assert(0); + } + + if (chan_recv(&r, &rcv, 0)) { + printc("chan_recv error\n"); + assert(0); + } +} + void receiver(void) { int i; ps_tsc_t tot = 0; + rendezvous(); for (i = 0; i < COMM_AMNT; i++) { ps_tsc_t now, snd; @@ -32,7 +60,7 @@ void ipc(void) { int i; - ps_tsc_t rcv = 0, prev_rcv, snd = 0, tmp; + ps_tsc_t rcv = 0, prev_rcv = 0, snd = 0, tmp; ps_tsc_t rcvcost = 0, sendcost = 0, rtt = 0, l2h = 0; for (i = 0; i < COMM_AMNT; i++) { @@ -50,12 +78,13 @@ ipc(void) l2h += rcv - tmp; rcvcost += rcv - snd; - rtt += rcv - prev_rcv; + if (prev_rcv != 0) rtt += rcv - prev_rcv; if (chan_send(&s, &rcv, 0)) { printc("chan_send error\n"); assert(0); } } + //Sync up here before printing. Chan_lo is *very likely* not done with its measurements yet! printc("Thread with high priority (4):\n\trcv %lld\n\tsend %lld\n\trtt %lld\n\tlow->high %lld\n", rcvcost/COMM_AMNT, sendcost/COMM_AMNT, rtt/COMM_AMNT, l2h/COMM_AMNT); @@ -74,6 +103,8 @@ main(void) void cos_init(void) { + memset(&s, 0, sizeof(struct chan_snd)); + memset(&r, 0, sizeof(struct chan_rcv)); printc("Component chan hi initializing:\n\tCreate channel 1\n"); if (chan_snd_init_with(&s, 1, sizeof(u64_t), 128, CHAN_DEFAULT)) { printc("Chan test 1 (%ld): Could not initialize send.\n", cos_compid()); @@ -85,7 +116,7 @@ cos_init(void) BUG(); } - printc("\tCreate channel 2\n"); + printc("\tPriority 4 for self!\n"); if (sched_thd_param_set(cos_thdid(), sched_param_pack(SCHEDP_PRIO, 4))) { printc("sched_thd_param_set failed.\n"); assert(0); diff --git a/src/components/implementation/tests/chan_lo/chan2.c b/src/components/implementation/tests/chan_lo/chan2.c index 0ba44977cb..48e0c99685 100644 --- a/src/components/implementation/tests/chan_lo/chan2.c +++ b/src/components/implementation/tests/chan_lo/chan2.c @@ -8,11 +8,32 @@ struct chan_rcv r; #define COMM_AMNT (2^10 * 16) +/* + * Sync up chan_hi and chan_lo for benchmarks! + * Because this is chan_lo, recv first, and when it wakes up from rcv, send which immediately should yield to chan_hi + */ +void +rendezvous(void) +{ + ps_tsc_t rcv = 0, snd = 0; + if (chan_recv(&r, &rcv, 0)) { + printc("chan_recv error\n"); + assert(0); + } + + snd = ps_tsc(); + if (chan_send(&s, &snd, 0)) { + printc("chan_send error\n"); + assert(0); + } +} + void sender(void) { int i; + rendezvous(); for (i = 0; i < COMM_AMNT; i++) { ps_tsc_t tsc = ps_tsc(); @@ -52,6 +73,7 @@ ipc(void) assert(0); } } + /* Sync up with chan_hi here..*/ printc("Thread with low priority (5):\n\trcv %lld\n\tsend %lld\n\trtt %lld\n\thigh->low %lld\n", rcvcost/COMM_AMNT, sendcost/COMM_AMNT, rtt/COMM_AMNT, h2l/COMM_AMNT); @@ -60,6 +82,7 @@ ipc(void) int main(void) { + printc("Component chan lo: executing main.\n"); sender(); ipc(); @@ -69,18 +92,22 @@ main(void) void cos_init(void) { + memset(&s, 0, sizeof(struct chan_snd)); + memset(&r, 0, sizeof(struct chan_rcv)); + printc("Component chan lo initializing:\n\tJoin channel 2\n"); if (chan_snd_init_with(&s, 2, sizeof(u64_t), 128, CHAN_DEFAULT)) { printc("Chan test 2 (%ld): Could not initialize send.\n", cos_compid()); BUG(); } + printc("\tJoin channel 1\n"); if (chan_rcv_init_with(&r, 1, sizeof(u64_t), 128, CHAN_DEFAULT)) { printc("Chan test 2 (%ld): Could not initialize recv.\n", cos_compid()); BUG(); } + printc("\tPriority 5 for self!\n"); if (sched_thd_param_set(cos_thdid(), sched_param_pack(SCHEDP_PRIO, 5))) { printc("sched_thd_param_set failed.\n"); BUG(); } - } diff --git a/src/components/lib/chan/chan.c b/src/components/lib/chan/chan.c index 2d7ffbd057..ef8b6520c6 100644 --- a/src/components/lib/chan/chan.c +++ b/src/components/lib/chan/chan.c @@ -36,8 +36,8 @@ static int __chan_gather_resources(struct __chan_meta *m, chan_id_t id, unsigned int item_sz, unsigned int nslots, chan_flags_t flags) { cbuf_t cb; - void *mem; - sched_blkpt_id_t full, empty; + void *mem = NULL; + sched_blkpt_id_t full = 0, empty = 0; int ret; if ((ret = chanmgr_mem_resources(id, &cb, &mem))) return ret; diff --git a/src/components/lib/chan/chan_private.h b/src/components/lib/chan/chan_private.h index fb74371c45..fc562aeea4 100644 --- a/src/components/lib/chan/chan_private.h +++ b/src/components/lib/chan/chan_private.h @@ -76,13 +76,14 @@ __chan_init_with(struct __chan_meta *meta, sched_blkpt_id_t full, sched_blkpt_id struct __chan_mem *m = mem; /* Certainly don't "initialize" if channel has been produced into! */ - if (m->producer != 0) return; + if (m->producer != 0) goto done; crt_blkpt_init_w_id(&m->empty, empty); crt_blkpt_init_w_id(&m->full, full); m->producer = m->consumer = 0; +done: meta->mem = m; return; diff --git a/src/components/lib/sl/sl_sched.c b/src/components/lib/sl/sl_sched.c index fe297c1be9..9815410179 100644 --- a/src/components/lib/sl/sl_sched.c +++ b/src/components/lib/sl/sl_sched.c @@ -507,6 +507,7 @@ sl_thd_param_set(struct sl_thd *t, sched_param_t sp) sched_param_get(sp, &type, &value); + sl_cs_enter(); switch (type) { case SCHEDP_WINDOW: { @@ -523,6 +524,7 @@ sl_thd_param_set(struct sl_thd *t, sched_param_t sp) } sl_mod_thd_param_set(sl_mod_thd_policy_get(t), type, value); + sl_cs_exit(); } void