clib_error_t * ssvm_config (vlib_main_t * vm, unformat_input_t * input) { u8 * name; int is_master = 1; int i, rv; ssvm_eth_main_t * em = &ssvm_eth_main; while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT) { if (unformat (input, "base-va %llx", &em->next_base_va)) ; else if (unformat (input, "segment-size %lld", &em->segment_size)) em->segment_size = 1ULL << (max_log2 (em->segment_size)); else if (unformat (input, "nbuffers %lld", &em->nbuffers)) ; else if (unformat (input, "queue-elts %lld", &em->queue_elts)) ; else if (unformat (input, "slave")) is_master = 0; else if (unformat (input, "%s", &name)) { vec_add1 (em->names, name); printf("AYXX: adding %s\n", name); } else break; } /* No configured instances, we're done... */ if (vec_len (em->names) == 0) return 0; for (i = 0; i < vec_len (em->names); i++) { rv = ssvm_eth_create (em, em->names[i], is_master); if (rv < 0) return clib_error_return (0, "ssvm_eth_create '%s' failed, error %d", em->names[i], rv); } return 0; }
/* Convert size to bin. */ always_inline uword size_to_bin (uword size) { uword bin; ASSERT (size > 0); if (size <= HEAP_SMALL_BINS) { bin = size - 1; if (size == 0) bin = 0; } else { bin = HEAP_SMALL_BINS + max_log2 (size) - (HEAP_LOG2_SMALL_BINS + 1); if (bin >= HEAP_N_BINS) bin = HEAP_N_BINS - 1; } return bin; }
static int ct_init_local_session (app_worker_t * client_wrk, app_worker_t * server_wrk, ct_connection_t * ct, session_t * ls, session_t * ll) { u32 round_rx_fifo_sz, round_tx_fifo_sz, sm_index, seg_size; segment_manager_props_t *props; application_t *server; segment_manager_t *sm; u32 margin = 16 << 10; fifo_segment_t *seg; u64 segment_handle; int seg_index, rv; server = application_get (server_wrk->app_index); props = application_segment_manager_properties (server); round_rx_fifo_sz = 1 << max_log2 (props->rx_fifo_size); round_tx_fifo_sz = 1 << max_log2 (props->tx_fifo_size); seg_size = round_rx_fifo_sz + round_tx_fifo_sz + margin; sm = app_worker_get_listen_segment_manager (server_wrk, ll); seg_index = segment_manager_add_segment (sm, seg_size); if (seg_index < 0) { clib_warning ("failed to add new cut-through segment"); return seg_index; } seg = segment_manager_get_segment_w_lock (sm, seg_index); rv = segment_manager_try_alloc_fifos (seg, props->rx_fifo_size, props->tx_fifo_size, &ls->rx_fifo, &ls->tx_fifo); if (rv) { clib_warning ("failed to add fifos in cut-through segment"); segment_manager_segment_reader_unlock (sm); goto failed; } sm_index = segment_manager_index (sm); ls->rx_fifo->master_session_index = ls->session_index; ls->tx_fifo->master_session_index = ls->session_index; ls->rx_fifo->segment_manager = sm_index; ls->tx_fifo->segment_manager = sm_index; ls->rx_fifo->segment_index = seg_index; ls->tx_fifo->segment_index = seg_index; segment_handle = segment_manager_segment_handle (sm, seg); if ((rv = app_worker_add_segment_notify (server_wrk, segment_handle))) { clib_warning ("failed to notify server of new segment"); segment_manager_segment_reader_unlock (sm); goto failed; } segment_manager_segment_reader_unlock (sm); ct->segment_handle = segment_handle; return 0; failed: segment_manager_del_segment (sm, seg); return rv; }