static int spdk_nvmf_check_pool(struct rte_mempool *pool, uint32_t count) { if (rte_mempool_count(pool) != count) { SPDK_ERRLOG("rte_mempool_count(%s) == %d, should be %d\n", pool->name, rte_mempool_count(pool), count); return -1; } else { return 0; } }
/* * This function displays the recorded statistics for each port * and for each client. It uses ANSI terminal codes to clear * screen when called. It is called from a single non-master * thread in the server process, when the process is run with more * than one lcore enabled. */ static void stats_display(void) { unsigned i = 0; unsigned j = 0; /* ANSI escape sequences for terminal display. * 27 = ESC, 2J = Clear screen */ const char clr[] = {27, '[', '2', 'J', '\0'}; /* H = Home position for cursor*/ const char topLeft[] = {27, '[', '1', ';', '1', 'H','\0'}; uint64_t overruns = 0; /* Clear screen and move to top left */ printf("%s%s", clr, topLeft); printf("Physical Ports\n"); printf("-----\n"); for (i = 0; i < ports->num_ports; i++) printf("Port %u: '%s'\t", ports->id[i], get_printable_mac_addr(ports->id[i])); printf("\n\n"); printf("\nVport Statistics\n" "============ ============ ============ ============ ============\n" "Interface rx_packets rx_dropped tx_packets tx_dropped \n" "------------ ------------ ------------ ------------ ------------\n"); for (i = 0; i < MAX_VPORTS; i++) { if (i == 0) { printf("vswitchd "); } else if (i <= PORT_MASK) { printf("Client %2u", i); } else if (i <= KNI_MASK) { printf("Port %2u", i & PORT_MASK); } else { printf("KNI Port %2u", i & KNI_MASK); } printf("%13"PRIu64" %13"PRIu64" %13"PRIu64" %13"PRIu64"\n", stats_vport_rx_get(i), stats_vport_rx_drop_get(i), stats_vport_tx_get(i), stats_vport_tx_drop_get(i)); overruns += stats_vport_overrun_get(i); } printf("============ ============ ============ ============ ============\n"); printf("\n Switch rx dropped %d\n", stats_vswitch_rx_drop_get()); printf("\n Switch tx dropped %d\n", stats_vswitch_tx_drop_get()); printf("\n Queue overruns %d\n", overruns); printf("\n Mempool count %9u\n", rte_mempool_count(pktmbuf_pool)); printf("\n"); }
int ipaugenblick_get_socket_tx_space(int sock) { int ring_space = ipaugenblick_socket_tx_space(sock); int free_bufs_count = rte_mempool_count(tx_bufs_pool); int rc = (ring_space > free_bufs_count) ? (free_bufs_count > 0 ? free_bufs_count : 0) : ring_space; int tx_space = rte_atomic32_read(&(local_socket_descriptors[sock & SOCKET_READY_MASK].socket->tx_space))/1448; // printf("sock %d ring space %d free bufs %d tx space %d\n",sock,ring_space,free_bufs_count,tx_space); if(rc > tx_space) rc = tx_space; if(!rc) { rte_atomic16_set(&(local_socket_descriptors[sock & SOCKET_READY_MASK].socket->write_ready_to_app),0); ipaugenblick_notify_empty_tx_buffers(sock); } return rc; }
void send_loop(void) { RTE_LOG(INFO, APP, "send_loop()\n"); char pkt[PKT_SIZE] = {0}; int nreceived; int retval = 0; (void) retval; #ifdef CALC_CHECKSUM unsigned int kk = 0; #endif srand(time(NULL)); //Initializate packet contents int i; for(i = 0; i < PKT_SIZE; i++) pkt[i] = rand()%256; #if ALLOC_METHOD == ALLOC_APP struct rte_mempool * packets_pool = rte_mempool_lookup("ovs_mp_1500_0_262144"); //struct rte_mempool * packets_pool = rte_mempool_lookup("packets"); //Create mempool //struct rte_mempool * packets_pool = rte_mempool_create( // "packets", // NUM_PKTS, // MBUF_SIZE, // CACHE_SIZE, //This is the size of the mempool cache // sizeof(struct rte_pktmbuf_pool_private), // rte_pktmbuf_pool_init, // NULL, // rte_pktmbuf_init, // NULL, // rte_socket_id(), // 0 /*NO_FLAGS*/); if(packets_pool == NULL) { RTE_LOG(INFO, APP, "rte_errno: %s\n", rte_strerror(rte_errno)); rte_exit(EXIT_FAILURE, "Cannot find memory pool\n"); } RTE_LOG(INFO, APP, "There are %d free packets in the pool\n", rte_mempool_count(packets_pool)); #endif #ifdef USE_BURST struct rte_mbuf * packets_array[BURST_SIZE] = {0}; struct rte_mbuf * packets_array_rx[BURST_SIZE] = {0}; int ntosend; int n; (void) n; /* prealloc packets */ do { n = rte_mempool_get_bulk(packets_pool, (void **) packets_array, BURST_SIZE); } while(n != 0 && !stop); ntosend = BURST_SIZE; #else struct rte_mbuf * mbuf; /* prealloc packet */ do { mbuf = rte_pktmbuf_alloc(packets_pool); } while(mbuf == NULL); #endif RTE_LOG(INFO, APP, "Starting sender loop\n"); signal (SIGINT, crtl_c_handler); stop = 0; while(likely(!stop)) { while(pause_); #ifdef USE_BURST #if ALLOC_METHOD == ALLOC_OVS //Try to get BURS_SIZE free slots ntosend = rte_ring_dequeue_burst(alloc_q, (void **) packets_array, BURST_SIZE); #elif ALLOC_METHOD == ALLOC_APP //do //{ // n = rte_mempool_get_bulk(packets_pool, (void **) packets_array, BURST_SIZE); //} while(n != 0 && !stop); //ntosend = BURST_SIZE; #else #error "No implemented" #endif //Copy data to the buffers for(i = 0; i < ntosend; i++) { rte_memcpy(packets_array[i]->buf_addr, pkt, PKT_SIZE); //fill_packet(packets_array[i]->pkt.data); packets_array[i]->next = NULL; packets_array[i]->pkt_len = PKT_SIZE; packets_array[i]->data_len = PKT_SIZE; #ifdef CALC_CHECKSUM for(i = 0; i < ntosend; i++) for(kk = 0; kk < 8; kk++) checksum += ((uint64_t *)packets_array[i]->buf_addr)[kk]; #endif } //Enqueue data (try until all the allocated packets are enqueue) i = 0; while(i < ntosend && !stop) { i += rte_ring_enqueue_burst(tx_ring, (void **) &packets_array[i], ntosend - i); /* also dequeue some packets */ nreceived= rte_ring_dequeue_burst(rx_ring, (void **) packets_array_rx, BURST_SIZE); rx += nreceived; /* update statistics */ } #else // [NO] USE_BURST #if ALLOC_METHOD == ALLOC_OVS //Method 1 //Read a buffer to be used as a buffer for a packet retval = rte_ring_dequeue(alloc_q, (void **)&mbuf); if(retval != 0) { #ifdef CALC_ALLOC_STATS //stats.alloc_fails++; #endif continue; } #elif ALLOC_METHOD == ALLOC_APP //Method 2 //mbuf = rte_pktmbuf_alloc(packets_pool); //if(mbuf == NULL) //{ //#ifdef CALC_ALLOC_STATS // stats.alloc_fails++; //#endif // continue; //} #else #error "ALLOC_METHOD has a non valid value" #endif #if DELAY_CYCLES > 0 //This loop increases mumber of packets per second (don't ask me why) unsigned long long j = 0; for(j = 0; j < DELAY_CYCLES; j++) asm(""); #endif //Copy packet to the correct buffer rte_memcpy(mbuf->buf_addr, pkt, PKT_SIZE); //fill_packet(mbuf->pkt.data); //mbuf->pkt.next = NULL; //mbuf->pkt.pkt_len = PKT_SIZE; //mbuf->pkt.data_len = PKT_SIZE; (void) pkt; mbuf->next = NULL; mbuf->pkt_len = PKT_SIZE; mbuf->data_len = PKT_SIZE; #ifdef CALC_CHECKSUM for(kk = 0; kk < 8; kk++) checksum += ((uint64_t *)mbuf->buf_addr)[kk]; #endif //this method avoids dropping packets: //Simple tries until the packet is inserted in the queue tryagain: retval = rte_ring_enqueue(tx_ring, (void *) mbuf); if(retval == -ENOBUFS && !stop) { #ifdef CALC_TX_TRIES //stats.tx_retries++; #endif goto tryagain; } #ifdef CALC_TX_STATS //stats.tx++; #endif #endif //USE_BURST } #ifdef CALC_CHECKSUM printf("Checksum was %" PRIu64 "\n", checksum); #endif }
void show_mib_stats(void); /* This function only prints statistics, it it not called on data path */ static int print_stats(__attribute__((unused)) void *dummy) { while(1) { app_glue_print_stats(); show_mib_stats(); dpdk_dev_print_stats(); print_user_stats(); syslog(LOG_INFO,"sk_stream_alloc_skb_failed %"PRIu64"\n",sk_stream_alloc_skb_failed); syslog(LOG_INFO,"tcp_memory_allocated=%"PRIu64"\n",tcp_memory_allocated); syslog(LOG_INFO,"jiffies %"PRIu64"\n",jiffies); dump_header_cache(); dump_head_cache(); dump_fclone_cache(); syslog(LOG_INFO,"rx pool free count %d\n",rte_mempool_count(pool_direct[0])); syslog(LOG_INFO,"stack pool free count %d\n",rte_mempool_count(mbufs_mempool)); syslog(LOG_INFO,"write_sockets_queue_len %"PRIu64" read_sockets_queue_len %"PRIu64" command pool %d \n", write_sockets_queue_len,read_sockets_queue_len,free_command_pool ? rte_mempool_count(free_command_pool) : -1); syslog(LOG_INFO,"driver_tx_offload_pkts %"PRIu64" driver_tx_wo_offload_pkts %"PRIu64"\n",driver_tx_offload_pkts,driver_tx_wo_offload_pkts); print_skb_iov_stats(); sleep(1); } return 0; } /* This function allocates rte_mbuf */ void *get_buffer() { return rte_pktmbuf_alloc(mbufs_mempool); } /* this function gets a pointer to data in the newly allocated rte_mbuf */