static int print_init(void) { static int first = 1; char *addr, *start; unsigned long i, sz; if (!first) return 0; first = 0; sz = cos_trans_cntl(COS_TRANS_MAP_SZ, 0, 0, 0); if (sz > (8*1024*1024)) return -1; addr = start = cos_get_vas_page(); if (!start) return -2; for (i = PAGE_SIZE ; i < sz ; i += PAGE_SIZE) { char *next_addr = cos_get_vas_page(); if ((((unsigned long)next_addr) - (unsigned long)addr) != PAGE_SIZE) return -3; addr = next_addr; } for (i = 0, addr = start ; i < sz ; i += PAGE_SIZE, addr += PAGE_SIZE) { if (cos_trans_cntl(COS_TRANS_MAP, COS_TRANS_SERVICE_PRINT, (unsigned long)addr, i)) return -4; } cringbuf_init(&sharedbuf, start, sz); return 0; }
void read_ltoc(void) { char *addr, *start; unsigned long i, sz; unsigned short int bid; int direction; int channel = COS_TRANS_SERVICE_PONG; char buf[512]; direction = cos_trans_cntl(COS_TRANS_DIRECTION, channel, 0, 0); if (direction < 0) { channels[channel].exists = 0; return; } channels[channel].exists = 1; channels[channel].direction = direction; sz = cos_trans_cntl(COS_TRANS_MAP_SZ, channel, 0, 0); assert(sz <= (4*1024*1024)); /* current 8MB max */ start = valloc_alloc(cos_spd_id(), cos_spd_id(), sz/PAGE_SIZE); assert(start); for (i = 0, addr = start ; i < sz ; i += PAGE_SIZE, addr += PAGE_SIZE) { assert(!cos_trans_cntl(COS_TRANS_MAP, channel, (unsigned long)addr, i)); } cringbuf_init(&channels[channel].rb, start, sz); assert(direction == COS_TRANS_DIR_LTOC); bid = cos_brand_cntl(COS_BRAND_CREATE, 0, 0, cos_spd_id()); assert(bid > 0); assert(!cos_trans_cntl(COS_TRANS_BRAND, channel, bid, 0)); if (sched_add_thd_to_brand(cos_spd_id(), bid, cos_get_thd_id())) BUG(); while (1) { int ret, i; char *p; struct channel_info *info; unsigned long long *t, local_t; // printc("going to wait for input...\n"); if (-1 == (ret = cos_brand_wait(bid))) BUG(); rdtscll(local_t); ret = cringbuf_consume(&channels[channel].rb, buf, 512); p = buf; // while (*p != '\0') { t = p; meas[idx++] = (local_t - *t); assert(local_t > *t); // printc("local t %llu, start %llu, diff %u\n", local_t, *t, meas[idx-1]); *p = '\0'; // p++; // } if (idx == ITER) break; } report(); return; }
int print_str(char *s, unsigned int len) { // if (!COS_IN_ARGREG(s) || !COS_IN_ARGREG(s + len)) { if (1) { static char foo[MAX_LEN]; snprintf(foo, MAX_LEN, "print argument out of bounds: %x", (unsigned int)s); cos_print(foo, 0); return -1; } s[len+1] = '\0'; #ifdef COS_PRINT_SHELL assert(!print_init()); if (sharedbuf.b) { int amnt; amnt = cringbuf_produce(&sharedbuf, s, len); assert(amnt >= 0); cos_trans_cntl(COS_TRANS_TRIGGER, COS_TRANS_SERVICE_PRINT, 0, 0); } #endif #ifdef COS_PRINT_DMESG cos_print(buf_ptr, len); #endif return 0; }
int twrite(spdid_t spdid, td_t td, int cbid, int sz) { int ret = -1; struct channel_info *channel; struct torrent *t; char *buf; if (tor_isnull(td)) return -EINVAL; LOCK(); t = tor_lookup(td); if (!t) ERR_THROW(-EINVAL, done); assert(t->data); if (!(t->flags & TOR_WRITE)) ERR_THROW(-EACCES, done); buf = cbuf2buf(cbid, sz); if (!buf) ERR_THROW(-EINVAL, done); channel = (struct channel_info*)t->data; ret = cringbuf_produce(&channels->rb, buf, sz); cos_trans_cntl(COS_TRANS_TRIGGER, 0, 0, 0); t->offset += ret; done: UNLOCK(); return ret; }
static int channel_init(int channel) { char *addr, *start; unsigned long i, sz; int acap, srv_acap; int direction; direction = cos_trans_cntl(COS_TRANS_DIRECTION, channel, 0, 0); if (direction < 0) { channels[channel].exists = 0; return 0; } channels[channel].exists = 1; channels[channel].direction = direction; sz = cos_trans_cntl(COS_TRANS_MAP_SZ, channel, 0, 0); assert(sz <= (4*1024*1024)); /* current 8MB max */ start = valloc_alloc(cos_spd_id(), cos_spd_id(), sz/PAGE_SIZE); assert(start); for (i = 0, addr = start ; i < sz ; i += PAGE_SIZE, addr += PAGE_SIZE) { assert(!cos_trans_cntl(COS_TRANS_MAP, channel, (unsigned long)addr, i)); } cringbuf_init(&channels[channel].rb, start, sz); if (direction == COS_TRANS_DIR_LTOC) { acap = cos_async_cap_cntl(COS_ACAP_CREATE, cos_spd_id(), cos_spd_id(), cos_get_thd_id() << 16 | cos_get_thd_id()); assert(acap); /* cli acap not used. Linux thread will be triggering the * acap. We set the cli acap owner to the current thread for * access control only.*/ srv_acap = acap & 0xFFFF; cos_trans_cntl(COS_TRANS_ACAP, channel, srv_acap, 0); while (1) { int ret; if (-1 == (ret = cos_ainv_wait(srv_acap))) BUG(); assert(channels[channel].t); evt_trigger(cos_spd_id(), channels[channel].t->evtid); } } return 0; }
static int channel_init(int channel) { char *addr, *start; unsigned long i, sz; unsigned short int bid; int direction; direction = cos_trans_cntl(COS_TRANS_DIRECTION, channel, 0, 0); if (direction < 0) { channels[channel].exists = 0; return 0; } channels[channel].exists = 1; channels[channel].direction = direction; sz = cos_trans_cntl(COS_TRANS_MAP_SZ, channel, 0, 0); assert(sz <= (4*1024*1024)); /* current 8MB max */ start = valloc_alloc(cos_spd_id(), cos_spd_id(), sz/PAGE_SIZE); assert(start); for (i = 0, addr = start ; i < sz ; i += PAGE_SIZE, addr += PAGE_SIZE) { assert(!cos_trans_cntl(COS_TRANS_MAP, channel, (unsigned long)addr, i)); } cringbuf_init(&channels[channel].rb, start, sz); if (direction == COS_TRANS_DIR_LTOC) { bid = cos_brand_cntl(COS_BRAND_CREATE, 0, 0, cos_spd_id()); assert(bid > 0); assert(!cos_trans_cntl(COS_TRANS_BRAND, channel, bid, 0)); if (sched_add_thd_to_brand(cos_spd_id(), bid, cos_get_thd_id())) BUG(); while (1) { int ret; if (-1 == (ret = cos_brand_wait(bid))) BUG(); assert(channels[channel].t); evt_trigger(cos_spd_id(), channels[channel].t->evtid); } } return 0; }