int window_control(int peer_id, int count) { int index = get_upload_index_by_id(peer_id); int window_size_change = 0; if(index == -1) return -1; if(cc_policies[index] == slow_start) { cwnds[index] += count; max_cwnds[index] = MAX(cwnds[index], max_cwnds[index]); window_size_change = 1; } else if (cc_policies[index] == congestion_avoidance) { if(cwnds[index] <= max_cwnds[index]/2) { /* current wnd reachs half of max, linear increase */ ack_counts[index] += count; if(ack_counts[index] >= cwnds[index]) { ack_counts[index] -= cwnds[index]; cwnds[index]++; window_size_change = 1; } } else { cwnds[index] += count; window_size_change = 1; } } if(window_size_change) log_window(peer_id, cwnds[index], milli_time()); return 1; }
void window_timeout(int peer_id) { int index = get_upload_index_by_id(peer_id); if(index == -1) return; printf("window timout\n"); cc_policies[index] = congestion_avoidance; cwnds[index] = INITIAL_WINDOW; log_window(peer_id, cwnds[index], milli_time()); }
void init_cwnd(int peer_id) { int index = get_upload_index_by_id(peer_id); if(index == -1) return; cc_policies[index] = slow_start; cwnds[index] = INITIAL_WINDOW; ack_counts[index] = 0; max_cwnds[index] = 1; log_window(peer_id, cwnds[index], milli_time()); }
int main(int argc, char **argv) { int varmax, size, repetitions; int array[VARLIMIT]; int reps, v0; MR_ROBDD_type *f; millisec clock0, clock1, clock2, clock3; float runtime, overhead, rate; int test_nodes, overhead_nodes; if (argc < 3) { usage(argv[0]); return 20; } if ((varmax=atoi(argv[2]))<1 || varmax>=VARLIMIT) { usage(argv[0]); printf("\n varmax must be between 1 <= varmax < %d\n", VARLIMIT); return 20; } if ((size=atoi(argv[1]))<0 || size>=varmax) { usage(argv[0]); printf("\n size must be between 0 <= size < varmax\n"); return 20; } repetitions=(argc>3 ? atoi(argv[3]) : 1); if (repetitions <= 0) repetitions = 1; opcount = 0; clock0 = milli_time(); for (reps=repetitions; reps>0; --reps) { for (v0=0; v0<varmax; ++v0) { init_array(size, v0, array); f = MR_ROBDD_testing_iff_conj_array(v0, size, array); inner_loop(varmax, f); while (next_array(size, varmax, v0, array)) { f = MR_ROBDD_testing_iff_conj_array(v0, size, array); inner_loop(varmax, f); } } } clock1 = milli_time(); test_nodes = MR_ROBDD_nodes_in_use(); MR_ROBDD_initRep(); clock2 = milli_time(); for (reps=repetitions; reps>0; --reps) { for (v0=0; v0<varmax; ++v0) { init_array(size, v0, array); f = MR_ROBDD_testing_iff_conj_array(v0, size, array); dont_inner_loop(varmax, f); while (next_array(size, varmax, v0, array)) { f = MR_ROBDD_testing_iff_conj_array(v0, size, array); dont_inner_loop(varmax, f); } } } clock3 = milli_time(); overhead_nodes = MR_ROBDD_nodes_in_use(); runtime = (float)(clock1-clock0)/1000; overhead = (float)(clock3-clock2)/1000; rate = ((float)opcount)/(runtime-overhead); printf("%s %d %d %d: %.3f - %.3f = %.3f secs, %d ops, %d nodes, %.1f ops/sec\n", argv[0], size, varmax, repetitions, runtime, overhead, (runtime-overhead), opcount, test_nodes-overhead_nodes, rate); return 0; }