int tread(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(!tor_is_usrdef(td) || t->data); if (!(t->flags & TOR_READ)) ERR_THROW(-EACCES, done); buf = cbuf2buf(cbid, sz); if (!buf) goto done; channel = (struct channel_info*)t->data; ret = cringbuf_consume(&channel->rb, buf, sz); done: UNLOCK(); return ret; }
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 main(void) { int fd; void *a; char c, buf[PRINT_CHUNK_SZ]; fd = open(PROC_FILE, O_RDWR); if (fd < 0) { perror("open"); exit(-1); } trans_ioctl_set_channel(fd, 0); a = mmap(NULL, MAP_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == a) { perror("mmap"); exit(-1); } cringbuf_init(&sharedbuf, a, MAP_SIZE); while (1) { int amnt; /* wait for an event... */ read(fd, &c, 1); do { amnt = cringbuf_consume(&sharedbuf, buf, PRINT_CHUNK_SZ); write(1 , buf, amnt); /* write to stdout */ } while (amnt); } if (munmap(a, MAP_SIZE) < 0) { perror("munmap"); exit(-1); } /* if (write(fd, name, strlen(name)) < 0) { */ /* perror("read"); */ /* exit(-1); */ /* } */ return 0; }