CSTUB_FN(int, tmerge)(struct usr_inv_cap *uc, spdid_t spdid, td_t td, td_t td_into, char *param, int len) { int ret; long fault = 0; struct __sg_tmerge_data *d; cbuf_t cb; int sz = len + sizeof(struct __sg_tmerge_data); assert(param && len > 0); assert(param[len-1] == '\0'); d = cbuf_alloc_ext(sz, &cb, CBUF_TMEM); if (!d) return -1; d->td = td; d->td_into = td_into; d->len[0] = 0; d->len[1] = len; memcpy(&d->data[0], param, len); cbuf_send(cb); CSTUB_INVOKE(ret, fault, uc, 3, spdid, cb, sz); cbuf_free(cb); return ret; }
CSTUB_FN(int, twmeta)(struct usr_inv_cap *uc, spdid_t spdid, td_t td, const char *key, unsigned int klen, const char *val, unsigned int vlen) { int ret; long fault = 0; cbuf_t cb; int sz = sizeof(struct __sg_twmeta_data) + klen + vlen + 1; struct __sg_twmeta_data *d; assert(key && val && klen > 0 && vlen > 0); assert(key[klen] == '\0' && val[vlen] == '\0' && sz <= PAGE_SIZE); d = cbuf_alloc_ext(sz, &cb, CBUF_TMEM); if (!d) assert(0); //return -1; d->td = td; d->klen = klen; d->vlen = vlen; memcpy(&d->data[0], key, klen + 1); memcpy(&d->data[klen + 1], val, vlen + 1); cbuf_send(cb); CSTUB_INVOKE(ret, fault, uc, 3, spdid, cb, sz); cbuf_free(cb); return ret; }
CSTUB_FN(int, trmeta)(struct usr_inv_cap *uc, spdid_t spdid, td_t td, const char *key, unsigned int klen, char *retval, unsigned int max_rval_len) { int ret; long fault = 0; cbuf_t cb; int sz = sizeof(struct __sg_trmeta_data) + klen + max_rval_len + 1; struct __sg_trmeta_data *d; assert(key && retval && klen > 0 && max_rval_len > 0); assert(key[klen] == '\0' && sz <= PAGE_SIZE); d = cbuf_alloc_ext(sz, &cb, CBUF_TMEM); if (!d) return -1; d->td = td; d->klen = klen; d->retval_len = max_rval_len; memcpy(&d->data[0], key, klen + 1); cbuf_send(cb); CSTUB_INVOKE(ret, fault, uc, 3, spdid, cb, sz); if (ret >= 0) { if ((unsigned int)ret > max_rval_len) { // as ret >= 0, cast it to unsigned int to omit compiler warning cbuf_free(cb); return -EIO; } memcpy(retval, &d->data[klen + 1], ret + 1); } cbuf_free(cb); return ret; }
CSTUB_FN(td_t, tsplit)(struct usr_inv_cap *uc, spdid_t spdid, td_t tid, char * param, int len, tor_flags_t tflags, long evtid) { long fault = 0; td_t ret; struct __sg_tsplit_data *d; cbuf_t cb; int sz = len + sizeof(struct __sg_tsplit_data); assert(param && len >= 0); assert(param[len] == '\0'); d = cbuf_alloc_ext(sz, &cb, CBUF_TMEM); if (!d) return -6; d->tid = tid; d->tflags = tflags; d->evtid = evtid; d->len[0] = 0; d->len[1] = len; memcpy(&d->data[0], param, len + 1); cbuf_send(cb); CSTUB_INVOKE(ret, fault, uc, 3, spdid, cb, sz); cbuf_free(cb); return ret; }
cbuf_t unit_cbufp_alloc(int sz) { cbuf_t cbuf; char *addr; addr = cbuf_alloc(sz, &cbuf); assert(addr); assert(cbuf); addr[0] = '_'; cbuf_send(cbuf); return cbuf; }
cbuf_t call_cbuf_pingpong(cbuf_t cb, unsigned long sz) { char *b; b = (char *)cbuf2buf(cb, sz); assert(b && b[0] == '$'); cbuf_free(cb); global_addr[0] = '&'; cbuf_send(global_id); return global_id; }
cbuf_t call_cbuf_alloc(unsigned long sz) { cbuf_t cbuf; char *addr; addr = cbuf_alloc(sz, &cbuf); assert(addr && cbuf); addr[0] = '$'; cbuf_send(cbuf); cbuf_send_free(cbuf); return cbuf; }
void cos_init(void *arg) { td_t t1, serv; long evt; char *params1 = "foo", *params2 = "", *d; int period, num, ret, sz, i, j; u64_t start = 0, end = 0, re_cbuf; cbuf_t cb1; union sched_param sp; static int first = 1; if (first) { first = 0; sp.c.type = SCHEDP_PRIO; sp.c.value = 9; if (sched_create_thd(cos_spd_id(), sp.v, 0, 0) == 0) BUG(); return ; } evt = evt_split(cos_spd_id(), 0, 0); assert(evt > 0); serv = tsplit(cos_spd_id(), td_root, params1, strlen(params1), TOR_RW, evt); if (serv < 1) { printc("UNIT TEST FAILED: split1 failed %d\n", serv); } evt_wait(cos_spd_id(), evt); printc("client split successfully\n"); sz = 4096; j = 1000*ITER; rdtscll(start); for (i=1; i<=j; i++) { if (i == j) rdtscll(end); d = cbuf_alloc(sz, &cb1); if (!d) goto done; cbuf_send(cb1); rdtscll(end); ((u64_t *)d)[0] = end; ret = twritep(cos_spd_id(), serv, cb1, sz); cbuf_free(cb1); } printc("Client snd %d times %llu\n", j-1, (end-start)/(j-1)); /* * insert evt_grp_wait(...) into the code below where it makes * sense to. Simulate if the code were executing in separate * threads. */ parse_args(&period, &num); periodic_wake_create(cos_spd_id(), period); re_cbuf = 0; for (i=1; i<=ITER; i++) { for (j=0; j<num; j++) { rdtscll(start); d = cbuf_alloc(i*sz, &cb1); if (!d) goto done; cbuf_send_free(cb1); rdtscll(end); re_cbuf = re_cbuf+(end-start); rdtscll(end); ((u64_t *)d)[0] = end; ret = twritep(cos_spd_id(), serv, cb1, i*sz); } periodic_wake_wait(cos_spd_id()); } printc("Client: Period %d Num %d Cbuf %llu\n", period, num, re_cbuf/(num*ITER)); done: trelease(cos_spd_id(), serv); printc("client UNIT TEST PASSED: split->release\n"); printc("client UNIT TEST ALL PASSED\n"); return; }