Skip to content

Commit

Permalink
fixed some bugs, but chan_evt still not stable yet.
Browse files Browse the repository at this point in the history
  • Loading branch information
phanikishoreg committed Aug 28, 2020
1 parent 868ccb3 commit b173b2a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/components/implementation/chanmgr/simple/chanmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 34 additions & 3 deletions src/components/implementation/tests/chan_hi/chan1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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++) {
Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -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);
Expand Down
29 changes: 28 additions & 1 deletion src/components/implementation/tests/chan_lo/chan2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -60,6 +82,7 @@ ipc(void)
int
main(void)
{
printc("Component chan lo: executing main.\n");
sender();
ipc();

Expand All @@ -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();
}

}
4 changes: 2 additions & 2 deletions src/components/lib/chan/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/components/lib/chan/chan_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/components/lib/sl/sl_sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
{
Expand All @@ -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
Expand Down

1 comment on commit b173b2a

@gparmer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks fine to me!

Please sign in to comment.