inline thread_p remote_pop() { if (remote_can_split()) { STAT_COUNT(THREAD_SPLIT); thread_p t = my_ready_threads.front(); size_t sz = t->size(); assert(sz > 1); return t->split(sz / 2); } else { assert(remote_has()); return my_ready_threads.pop_front(); } }
/*----------------------------------------------------------------------------*/ int psio_send_pkts(struct mtcp_thread_context *ctxt, int nif) { struct psio_private_context *ppc; mtcp_manager_t mtcp; int ret, prev_cnt; ppc = (struct psio_private_context *)ctxt->io_private_context; mtcp = ctxt->mtcp_manager; #if 0 /* if tx if not available, pass */ if (!NID_ISSET(nif, ppc->tx_avail)) { NID_SET(nif, ppc->event.tx_nids); return -1; } #endif while ((prev_cnt = ppc->w_chunk_buf[nif].cnt) > 0) { ret = psio_flush_pkts(ctxt, nif); if (ret <= 0) { if (ret < 0) TRACE_ERROR("ps_send_chunk_buf failed to send.\n"); NID_SET(nif, ppc->event.tx_nids); NID_CLR(nif, ppc->tx_avail); break; } else if (ret < prev_cnt) { NID_CLR(nif, ppc->tx_avail); NID_SET(nif, ppc->event.tx_nids); STAT_COUNT(mtcp->runstat.rounds_tx); break; } else { STAT_COUNT(mtcp->runstat.rounds_tx); } } return 0; }
/*----------------------------------------------------------------------------*/ static int psio_flush_pkts(struct mtcp_thread_context *ctx, int nif) { struct ps_chunk_buf *c_buf; mtcp_manager_t mtcp; struct psio_private_context *ppc; int send_cnt, to_send_cnt = 0; int start_idx, i; ppc = (struct psio_private_context *)ctx->io_private_context; c_buf = &ppc->w_chunk_buf[nif]; mtcp = ctx->mtcp_manager; /* if chunk (for writing) is not there... then return */ if (!c_buf) return -1; to_send_cnt = c_buf->cnt; if (to_send_cnt > 0) { STAT_COUNT(mtcp->runstat.rounds_tx_try); start_idx = c_buf->next_to_send; send_cnt = ps_send_chunk_buf(&ppc->handle, c_buf); for (i = 0; i < send_cnt; i++) { #ifdef NETSTAT mtcp->nstat.tx_bytes[nif] += c_buf->info[start_idx].len + 24; #endif #if PKTDUMP DumpPacket(mtcp, c_buf->buf + c_buf->info[start_idx].offset, c_buf->info[start_idx].len, "OUT", nif); #endif start_idx = (start_idx + 1) % ENTRY_CNT; } if (send_cnt < 0) { TRACE_ERROR("ps_send_chunk_buf failed. " "ret: %d, error: %s\n", send_cnt, strerror(errno)); #ifdef NETSTAT } else { mtcp->nstat.tx_packets[nif] += send_cnt; #endif } return send_cnt; } return 0; }
/*----------------------------------------------------------------------------*/ int32_t psio_select(struct mtcp_thread_context *ctxt) { struct psio_private_context *ppc; mtcp_manager_t mtcp; struct timeval cur_ts; int i, ret; ppc = (struct psio_private_context *) ctxt->io_private_context; mtcp = ctxt->mtcp_manager; gettimeofday(&cur_ts, NULL); if (!ppc->rx_avail || ppc->event.tx_nids) { for (i = 0; i < CONFIG.eths_num; i++) { if (ppc->w_chunk_buf[i].cnt > 0) NID_SET(i, ppc->event.tx_nids); if (mtcp->n_sender[i]->control_list_cnt > 0 || mtcp->n_sender[i]->send_list_cnt > 0 || mtcp->n_sender[i]->ack_list_cnt > 0) { if (cur_ts.tv_sec > ppc->last_tx_set[i].tv_sec || cur_ts.tv_usec > ppc->last_tx_set[i].tv_usec) { NID_SET(i, ppc->event.tx_nids); ppc->last_tx_set[i] = cur_ts; } } } TRACE_SELECT("BEFORE: rx_avail: %d, tx_avail: %d, event.rx_nids: %0x, event.tx_nids: %0x\n", ppc->rx_avail, ppc->tx_avail, ppc->event.rx_nids, ppc->event.tx_nids); mtcp->is_sleeping = TRUE; ret = ps_select(&ppc->handle, &ppc->event); mtcp->is_sleeping = FALSE; #if TIME_STAT gettimeofday(&select_ts, NULL); UpdateStatCounter(&mtcp->rtstat.select, TimeDiffUs(&select_ts, &xmit_ts)); #endif if (ret < 0) { if (errno != EAGAIN && errno != EINTR) { perror("ps_select"); exit(EXIT_FAILURE); } if (errno == EINTR) { STAT_COUNT(mtcp->runstat.rounds_select_intr); } } else { TRACE_SELECT("ps_select(): event.rx_nids: %0x, event.tx_nids: %0x\n", ppc->event.rx_nids, ppc->event.tx_nids); if (ppc->event.rx_nids != 0) { STAT_COUNT(mtcp->runstat.rounds_select_rx); } if (ppc->event.tx_nids != 0) { for (i = 0; i < CONFIG.eths_num; i++) { if (NID_ISSET(i, ppc->event.tx_nids)) { NID_SET(i, ppc->tx_avail); } } STAT_COUNT(mtcp->runstat.rounds_select_tx); } } TRACE_SELECT("AFTER: rx_avail: %d, tx_avail: %d, event.rx_nids: %d, event.tx_nids: %d\n", ppc->rx_avail, ppc->tx_avail, ppc->event.rx_nids, ppc->event.tx_nids); STAT_COUNT(mtcp->runstat.rounds_select); } /* reset psio parameters */ ppc->event.timeout = PS_SELECT_TIMEOUT; NID_ZERO(ppc->event.rx_nids); NID_ZERO(ppc->event.tx_nids); NID_ZERO(ppc->rx_avail); //NID_ZERO(ppc->tx_avail); return 0; }
int Lsuper_local_code_optimization (L_Func * fn, int renaming_done) { int i, j, opti_applied = 0 , global_dead_total; L_Cb *cb; L_normalize_ops (fn); STAT_INIT ("Lsuper_local_code_optimization", fn); L_partial_dead_code_removal (fn); L_do_flow_analysis (fn, LIVE_VARIABLE); #if 0 printf("Beginning new run of Lsuperscalar.\n"); #endif for (i = 0; i < REPEAT_LOCAL_OPTI; i++) { int global_dead; #if 0 printf("Beginning iteration %d of Lsuperscalar loop.\n", i); #endif for (cb = fn->first_cb; cb != NULL; cb = cb->next_cb) { /* check for empty cb */ if (!cb->first_op) continue; /* REH 9/95 - Don't perform local optimizations within */ /* region boundary cb's */ if (L_EXTRACT_BIT_VAL (cb->flags, L_CB_BOUNDARY)) continue; for (j = 0; j < REPEAT_LOCAL_OPTI; j++) { int change, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c17, c18, c19, use_sync_arcs = 0; c1 = c2 = c3 = c4 = c5 = c6 = c7 = c8 = c9 = c10 = c11 = c12 = c13 = c14 = c15 = c17 = c18 = c19 = 0; if (Lsuper_do_const_prop) { c1 = L_local_constant_propagation (cb, 0); STAT_COUNT ("L_local_constant_propagation", c1, cb); } if (Lsuper_do_rev_copy_prop && !renaming_done) { c2 = L_local_rev_copy_propagation (cb); STAT_COUNT ("L_local_rev_copy_propagation", c2, cb); } if (Lsuper_do_copy_prop) { c3 = L_local_copy_propagation (cb); STAT_COUNT ("L_local_copy_propagation", c3, cb); } if (Lsuper_do_mem_copy_prop) { c4 = L_local_memory_copy_propagation (cb); STAT_COUNT ("L_local_memory_copy_propagation_total", c4, cb); } if (Lsuper_do_common_sub) { c5 = L_local_common_subexpression (cb, 0); STAT_COUNT ("L_local_common_subexpression_total", c5, cb); } if (Lopti_ignore_sync_arcs_for_red_elim) { use_sync_arcs = L_use_sync_arcs; L_use_sync_arcs = 0; } if (Lsuper_do_red_load) { c6 = L_local_redundant_load (cb); STAT_COUNT ("L_local_redundant_load", c6, cb); } if (Lsuper_do_red_store) { c7 = L_local_redundant_store (cb); STAT_COUNT ("L_local_redundant_store", c7, cb); } if (Lopti_ignore_sync_arcs_for_red_elim) { L_use_sync_arcs = use_sync_arcs; } if (Lsuper_do_const_comb) { c8 = L_local_constant_combining (cb); STAT_COUNT ("L_local_constant_combining_total", c8, cb); } if (Lsuper_do_const_fold) { c9 = L_local_constant_folding (cb); STAT_COUNT ("L_local_constant_folding_total", c9, cb); } if (Lsuper_do_str_red) { c10 = L_local_strength_reduction (cb); STAT_COUNT ("L_local_strength_reduction_total", c10, cb); } if (Lsuper_do_br_fold) { c11 = L_local_branch_folding (cb); STAT_COUNT ("L_local_branch_folding", c11, cb); /* control structure modified so redo flow analysis */ if (c11 != 0) L_do_flow_analysis (fn, LIVE_VARIABLE); STAT_COUNT ("L_local_branch_folding_total", c11, cb); } if (Lsuper_do_dead_code) { c12 = L_local_dead_code_removal (cb); STAT_COUNT ("L_local_dead_code_removal_total", c12, cb); } if (Lsuper_do_code_motion) { c13 = L_local_code_motion (cb); STAT_COUNT ("L_local_code_motion_total", c13, cb); } if (Lsuper_do_op_fold) { c14 = L_local_operation_folding (cb); STAT_COUNT ("L_local_operation_folding_total", c14, cb); } if (Lsuper_do_op_cancel) { c17 = L_local_operation_cancellation (cb); STAT_COUNT ("L_local_operation_cancellation_total", c17, cb); } if (Lsuper_do_remove_sign_ext) { c18 = L_local_remove_sign_extension (cb); STAT_COUNT ("L_local_remove_sign_extension", c18, cb); } if (Lsuper_do_reduce_logic) { c19 = L_local_logic_reduction (cb); STAT_COUNT ("L_local_logic_reduction_total", c19, cb); } change = c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 + c9 + c10 + c11 + c12 + c13 + c14 + c15 + c17 + c18 + c19; opti_applied += change; if (!change) break; } } global_dead_total = L_partial_dead_code_removal (fn); if (Lsuper_do_dead_code) { L_do_flow_analysis (fn, LIVE_VARIABLE); for (cb = fn->first_cb; cb; cb = cb->next_cb) { L_local_pred_dead_code_removal (cb); global_dead = L_global_dead_code_removal (cb); global_dead_total += global_dead; STAT_COUNT ("L_global_dead_code_removal", global_dead, cb); } } if (!global_dead_total) break; } if (opti_applied) L_invalidate_dataflow (); return opti_applied; }
int L_global_memflow_optimization (L_Func * fn) { int opti_applied; L_Cb *cb; L_Oper *op; int c1; int load_op, store_op, jsr_op; if (Lopti_do_memflow_opti == 0) return (0); /* Don't do these optis if the number of loads/stores/jsrs is excessive since it is a memory hog */ load_op = 0; store_op = 0; jsr_op = 0; for (cb = fn->first_cb; cb != NULL; cb = cb->next_cb) { for (op = cb->first_op; op != NULL; op = op->next_op) { if (L_general_load_opcode (op)) load_op++; if (L_general_store_opcode (op)) store_op++; if (L_general_subroutine_call_opcode (op)) jsr_op++; } } if (load_op > Lopti_memflow_bypass_load) return (0); if (store_op > Lopti_memflow_bypass_store) return (0); if (jsr_op > Lopti_memflow_bypass_jsr) return (0); if ((load_op + store_op + jsr_op) > Lopti_memflow_bypass_total) return (0); if (Lopti_debug_memflow) fprintf (stderr, "Doing memflow\n"); L_do_flow_analysis (fn, MEM_REACHING_DEFINITION); opti_applied = 0; c1 = 0; /* Call Various Opti's on each oper */ for (cb = fn->first_cb; cb != NULL; cb = cb->next_cb) { if (L_EXTRACT_BIT_VAL (cb->flags, L_CB_BOUNDARY)) continue; for (op = cb->first_op; op != NULL; op = op->next_op) { /* Opti routines */ if (Lopti_do_memflow_multistore_load) { c1 += L_global_memflow_multistore_load (fn, cb, op); } L_global_memflow_multiloadstore_load (fn, cb, op); } } if (Lopti_do_memflow_multistore_load) { Lopti_cnt_memflow_multistore_load = c1; STAT_COUNT ("L_memflow_multistore_load", c1, NULL); } if (c1) opti_applied = 1; return (opti_applied); }
//! Replaces the default "new" operator with ours void* operator new (size_t size) { STAT_COUNT(THREAD_ALLOC); return ::operator new(size); }
ColorIt<ColorPredicate,CellIterator>::ColorIt(const BoardCell& iCell, const BaseBoard* iBoard) : /*_level(0),*/ _it(iCell, iBoard) { STAT_COUNT(ColorIt::CopyCtor); //_stack.reserve(iBoard->cellCount()); _mask.testAndSet(iCell.x(), iCell.y()); }
GenericIt<Type>::GenericIt(const BoardCell& iCell, const BaseBoard* iBoard) : _state(), _current(iCell), _board(iBoard) { STAT_COUNT(GenericIt::CopyCtor); ASSERT(_board || _state == TRANSFORMATIONS_LEN, "Null inner board"); }
/*----------------------------------------------------------------------------*/ int FlushWriteBuffer(struct mtcp_thread_context* ctx, int ifidx) { int ret = 0; struct ps_chunk* w_chunk = ctx->w_chunk; mtcp_manager_t mtcp = ctx->mtcp_manager; int i; int drop = 0; assert(ctx != NULL); assert(w_chunk != NULL); if (w_chunk[ifidx].cnt > 0) { STAT_COUNT(mtcp->runstat.rounds_tx_try); ret = ps_send_chunk(ctx->handle, &w_chunk[ifidx]); drop = ctx->w_chunk[ifidx].cnt - ret; if (ret < 0) { TRACE_ERROR("ps_send_chunk failed to send chunks, %d:%d\n", ifidx, w_chunk[ifidx].cnt); return ret; } else { #ifdef NETSTAT mtcp->nstat.tx_packets[ifidx] += ret; #endif /* NETSTAT */ for (i = 0; i < ret; i++) { #ifdef PKTDUMP DumpPacket(mtcp, w_chunk[ifidx].buf + w_chunk[ifidx].info[i].offset, w_chunk[ifidx].info[i].len, "OUT", ifidx); #endif /* PKTDUMP */ #ifdef NETSTAT mtcp->nstat.tx_bytes[ifidx] += w_chunk[ifidx].info[i].len + 24; #endif /* NETSTAT */ } #ifdef NETSTAT if (ret != w_chunk[ifidx].cnt) { mtcp->nstat.tx_drops[ifidx] += (w_chunk[ifidx].cnt - ret); } #endif /* NETSTAT */ if (ret == 0) { return ret; } } #ifdef PKTDUMP thread_printf(mtcp, mtcp->log_fp, "sent chunks, ret: %d (tries: %d)\n", ret, w_chunk[ifidx].cnt); thread_printf(mtcp, mtcp->log_fp, "======================================" "======================================================" "====================\n\n"); #endif /* PKTDUMP */ if (drop > 0) { ctx->w_chunk[ifidx].cnt = drop; for (i = 0; i < drop; i++) { ctx->w_chunk[ifidx].info[i].len = ctx->w_chunk[ifidx].info[ret + i].len; ctx->w_chunk[ifidx].info[i].offset = ctx->w_chunk[ifidx].info[ret + i].offset; } ctx->w_off[ifidx] = ctx->w_chunk[ifidx].info[drop - 1].offset + (ctx->w_chunk[ifidx].info[drop - 1].len + 63) / 64 * 64; ctx->w_cur_idx[ifidx] += ret; } else { ctx->w_chunk[ifidx].cnt = 0; ctx->w_off[ifidx] = 0; ctx->w_cur_idx[ifidx] = 0; } } return ret; }