static void accept_new(int accept_fd) { int from, to, feid, teid; while (1) { from = net_accept(cos_spd_id(), accept_fd); assert(from != accept_fd); if (-EAGAIN == from) { return; } else if (from < 0) { BUG(); return; } feid = evt_get(); assert(feid > 0); if (0 < net_accept_data(cos_spd_id(), from, feid)) BUG(); teid = evt_get(); assert(teid > 0); to = tsplit(cos_spd_id(), td_root, "", 0, TOR_RW, teid); if (to < 0) { printc("torrent split returned %d", to); BUG(); } mapping_add(from, to, feid, teid); } }
static void accept_new(int accept_fd) { int from, to, feid, teid; while (1) { feid = evt_get(); assert(feid > 0); from = from_tsplit(cos_spd_id(), accept_fd, "", 0, TOR_RW, feid); assert(from != accept_fd); if (-EAGAIN == from) { evt_put(feid); return; } else if (from < 0) { printc("from torrent returned %d\n", from); BUG(); return; } teid = evt_get(); assert(teid > 0); to = tsplit(cos_spd_id(), td_root, "", 0, TOR_RW, teid); if (to < 0) { printc("torrent split returned %d", to); BUG(); } mapping_add(from, to, feid, teid); } }
void cos_init(void *arg) { int c, accept_fd, ret; long eid; char *init_str = cos_init_args(), *create_str; int lag, nthds, prio; cvect_init_static(&evts); cvect_init_static(&tor_from); cvect_init_static(&tor_to); lock_static_init(&sc_lock); sscanf(init_str, "%d:%d:%d", &lag, &nthds, &prio); printc("lag: %d, nthds:%d, prio:%d\n", lag, nthds, prio); create_str = strstr(init_str, "/"); assert(create_str); eid = evt_get(); ret = c = from_tsplit(cos_spd_id(), td_root, create_str, strlen(create_str), TOR_ALL, eid); if (ret <= td_root) BUG(); accept_fd = c; evt_add(c, eid); /* event loop... */ while (1) { struct tor_conn tc; int t; long evt; memset(&tc, 0, sizeof(struct tor_conn)); evt = evt_wait_all(); t = evt_torrent(evt); if (t > 0) { tc.feid = evt; tc.from = t; if (t == accept_fd) { tc.to = 0; accept_new(accept_fd); } else { tc.to = tor_get_to(t, &tc.teid); assert(tc.to > 0); from_data_new(&tc); } } else { t *= -1; tc.teid = evt; tc.to = t; tc.from = tor_get_from(t, &tc.feid); assert(tc.from > 0); to_data_new(&tc); } cos_mpd_update(); } }
void cos_init(void *arg) { int c, accept_fd, ret; long eid; cvect_init_static(&evts); cvect_init_static(&tor_from); cvect_init_static(&tor_to); eid = evt_get(); c = net_create_tcp_connection(cos_spd_id(), cos_get_thd_id(), eid); if (c < 0) BUG(); ret = net_bind(cos_spd_id(), c, 0, 200); if (ret < 0) BUG(); ret = net_listen(cos_spd_id(), c, 255); if (ret < 0) BUG(); accept_fd = c; evt_add(c, eid); while (1) { struct tor_conn tc; int t; long evt; memset(&tc, 0, sizeof(struct tor_conn)); printc("waiting...\n"); evt = evt_grp_wait(cos_spd_id()); t = evt_torrent(evt); if (t > 0) { tc.feid = evt; tc.from = t; if (t == accept_fd) { tc.to = 0; printc("accepting event.\n"); accept_new(accept_fd); } else { tc.to = tor_get_to(t); assert(tc.to > 0); printc("data from net.\n"); from_data_new(&tc); } } else { t *= -1; tc.teid = evt; tc.to = t; tc.from = tor_get_from(t); assert(tc.from > 0); printc("data from torrent.\n"); to_data_new(&tc); } cos_mpd_update(); } }
void cos_init(void *arg) { int c, accept_fd, ret; long eid; char *init_str = cos_init_args(); char __create_str[128]; static volatile int first = 1, off = 0; int port; u64_t start, end; if (cos_get_thd_id() == pid_thd) { pid_process(); } union sched_param sp; if (first) { first = 0; sp.c.type = SCHEDP_PRIO; sp.c.value = 10; pid_thd = sched_create_thd(cos_spd_id(), sp.v, 0, 0); init(init_str); return; } printc("Thread %d, port %d\n", cos_get_thd_id(), __port+off); port = off++; port += __port; eid = evt_get(); if (snprintf(__create_str, 128, create_str, port) < 0) BUG(); ret = c = from_tsplit(cos_spd_id(), td_root, __create_str, strlen(__create_str), TOR_ALL, eid); if (ret <= td_root) BUG(); accept_fd = c; printc("accept_fd %d (eid %d)\n", accept_fd, eid); evt_add(c, eid); /* event loop... */ while (1) { int t; long evt; evt = evt_wait_all(); t = evt_torrent(evt); printc("an interrupt comes in (thd %d, evt %d t %d)\n", cos_get_thd_id(), evt, t); accept_new(accept_fd); break; } }
static void accept_new(int accept_fd) { int eid; eid = evt_get(); assert(eid > 0); pid_torrent = from_tsplit(cos_spd_id(), accept_fd, "", 0, TOR_RW, eid); assert(pid_torrent!= accept_fd); printc("accept_new: eid %d pid_torrent %d (accept_fd %d)\n", eid, pid_torrent, accept_fd); if (-EAGAIN == pid_torrent) { evt_free(cos_spd_id(), eid); return; } else if (pid_torrent < 0) { printc("pwrite to id_torrent %d\n", pid_torrent); BUG(); return; } mapping_add(pid_torrent, 0, eid, 0); }
int main(int argc, char *argv[]) { FILE *f; //int start = 0, fc = 0, fo = 0, opt, i; long long int res = 0, done = 0; int first_param; first_param = param(argc, argv); if (argc - first_param < 1) { help(argv[0]); } createPidsFilter(relevant_pids); if (strcmp(argv[first_param], "-")) { f = fopen(argv[first_param], "r"); } else { f = stdin; } if (f == NULL) { perror("Cannot open input file"); return -1; } while (!done) { struct event *e; switch (trace_type) { case FTRACE: res = ftrace_parse(f); break; case OFTRACE: res = oftrace_parse(f); break; case JTRACE: res = jtrace_read(f); break; case L4TRACE: res = l4trace_parse(f); break; case TRCUTILS: res = trace_read(f, 0); break; case XTRACE: res = trace_read(f, 1); break; default: fprintf(stderr, "Unknown trace type: this shouldn't have happened...\n"); exit(-1); } while (e = evt_get()) { filterEvent(e); trc_write(e); free(e); } done = feof(f) || (res < 0); } // endAllTask(time); destroyPidsFilter(); return 0; }