stable: revert multi-core, restore working single-core optimizations
Keep P0-P4 optimizations: - Fragment mempool (frag_alloc/frag_free) - WS frame alloca() dynamic stack - Fragment read_offset (eliminate memmove) - nclose busy-poll (replace cond_timedwait) - Remove dead ng_tcp_out() Revert experimental multi-core changes (moved to feature/multi-core): - Worker arrays, TLS context switching - RX hash distribution, TX multi-ring collection Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+40
-69
@@ -179,33 +179,28 @@ int main(int argc, char *argv[])
|
||||
ng_init_port(mbuf_pool);
|
||||
rte_eth_macaddr_get(gDpdkPortId, (struct rte_ether_addr *)gSrcMac);
|
||||
|
||||
/* ── Init per-worker ring buffers ── */
|
||||
int num_workers = ng_get_num_workers();
|
||||
for (int w = 1; w <= num_workers; w++)
|
||||
/* ── Init ring buffers ── */
|
||||
struct inout_ring *ring = ringInstance();
|
||||
if (ring->in == NULL)
|
||||
{
|
||||
struct inout_ring *r = ringInstanceFor(w);
|
||||
char name_in[32], name_out[32];
|
||||
snprintf(name_in, sizeof(name_in), "in_ring_w%d", w);
|
||||
snprintf(name_out, sizeof(name_out), "out_ring_w%d", w);
|
||||
r->in = rte_ring_create(name_in, RING_SIZE, rte_socket_id(),
|
||||
RING_F_SP_ENQ | RING_F_SC_DEQ);
|
||||
r->out = rte_ring_create(name_out, RING_SIZE, rte_socket_id(),
|
||||
RING_F_SP_ENQ | RING_F_SC_DEQ);
|
||||
ring->in = rte_ring_create("in_ring", RING_SIZE,
|
||||
rte_socket_id(),
|
||||
RING_F_SP_ENQ | RING_F_SC_DEQ);
|
||||
}
|
||||
if (ring->out == NULL)
|
||||
{
|
||||
ring->out = rte_ring_create("out_ring", RING_SIZE,
|
||||
rte_socket_id(),
|
||||
RING_F_SP_ENQ | RING_F_SC_DEQ);
|
||||
}
|
||||
|
||||
/* ── Launch pkt_process workers on lcores 1..N ── */
|
||||
static struct worker_args wargs[MAX_WORKERS + 1];
|
||||
/* ── Launch pkt_process on secondary lcore ── */
|
||||
unsigned lcore_id = rte_lcore_id();
|
||||
for (int w = 1; w <= num_workers; w++)
|
||||
{
|
||||
lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
|
||||
wargs[w].mbuf_pool = mbuf_pool;
|
||||
wargs[w].worker_id = w;
|
||||
printf("[MAIN] Launching worker %d on lcore %u\n", w, lcore_id);
|
||||
rte_eal_remote_launch(pkt_process, &wargs[w], lcore_id);
|
||||
}
|
||||
lcore_id = rte_get_next_lcore(lcore_id, 1, 0);
|
||||
printf("[MAIN] Launching pkt_process on lcore %u\n", lcore_id);
|
||||
rte_eal_remote_launch(pkt_process, mbuf_pool, lcore_id);
|
||||
|
||||
/* Give workers time to start */
|
||||
/* Give pkt_process time to start */
|
||||
rte_delay_ms(200);
|
||||
|
||||
/* ══════════════════════════════════════════════════════════
|
||||
@@ -251,41 +246,25 @@ int main(int argc, char *argv[])
|
||||
int running = 1;
|
||||
while (running)
|
||||
{
|
||||
/* ── DPDK RX (distribute by flow hash to workers) ── */
|
||||
/* ── DPDK RX ── */
|
||||
struct rte_mbuf *rx[BURST_SIZE];
|
||||
unsigned num_recvd = rte_eth_rx_burst(gDpdkPortId, 0, rx, BURST_SIZE);
|
||||
if (num_recvd > 0)
|
||||
{
|
||||
struct rte_mbuf *rx[BURST_SIZE];
|
||||
unsigned num_recvd = rte_eth_rx_burst(gDpdkPortId, 0, rx, BURST_SIZE);
|
||||
for (unsigned i = 0; i < num_recvd; i++)
|
||||
{
|
||||
struct rte_ether_hdr *ehdr = rte_pktmbuf_mtod(rx[i], struct rte_ether_hdr *);
|
||||
int wid = 1; /* default to worker 1 for non-IP */
|
||||
if (ehdr->ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_IPV4))
|
||||
{
|
||||
struct rte_ipv4_hdr *iph = rte_pktmbuf_mtod_offset(rx[i],
|
||||
struct rte_ipv4_hdr *, sizeof(struct rte_ether_hdr));
|
||||
if (iph->next_proto_id == IPPROTO_TCP)
|
||||
{
|
||||
struct rte_tcp_hdr *th = (struct rte_tcp_hdr *)((uint8_t *)iph +
|
||||
((iph->version_ihl & 0x0F) << 2));
|
||||
wid = ng_compute_worker(iph->src_addr, iph->dst_addr,
|
||||
th->src_port, th->dst_port);
|
||||
}
|
||||
}
|
||||
rte_ring_sp_enqueue(ringInstanceFor(wid)->in, rx[i]);
|
||||
}
|
||||
rte_ring_sp_enqueue_burst(ring->in, (void **)rx,
|
||||
num_recvd, NULL);
|
||||
}
|
||||
|
||||
/* ── DPDK TX (collect from all workers) ── */
|
||||
for (int w = 1; w <= num_workers; w++)
|
||||
/* ── DPDK TX ── */
|
||||
struct rte_mbuf *tx[BURST_SIZE];
|
||||
unsigned nb_tx = rte_ring_sc_dequeue_burst(ring->out,
|
||||
(void **)tx, BURST_SIZE, NULL);
|
||||
if (nb_tx > 0)
|
||||
{
|
||||
struct rte_mbuf *tx[BURST_SIZE];
|
||||
unsigned nb_tx = rte_ring_sc_dequeue_burst(ringInstanceFor(w)->out,
|
||||
(void **)tx, BURST_SIZE, NULL);
|
||||
if (nb_tx > 0)
|
||||
rte_eth_tx_burst(gDpdkPortId, 0, tx, nb_tx);
|
||||
for (unsigned i = 0; i < nb_tx; i++)
|
||||
{
|
||||
rte_eth_tx_burst(gDpdkPortId, 0, tx, nb_tx);
|
||||
for (unsigned i = 0; i < nb_tx; i++)
|
||||
rte_pktmbuf_free(tx[i]);
|
||||
rte_pktmbuf_free(tx[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,27 +348,19 @@ int main(int argc, char *argv[])
|
||||
|
||||
nclose(sockfd);
|
||||
|
||||
/* Service TX until FIN and pending ACKs are sent (all workers) */
|
||||
/* Service TX until FIN and pending ACKs are sent */
|
||||
for (int flush = 0; flush < 500; flush++) {
|
||||
int any = 0;
|
||||
for (int w = 1; w <= num_workers; w++) {
|
||||
struct rte_mbuf *txf[BURST_SIZE];
|
||||
unsigned nb = rte_ring_sc_dequeue_burst(ringInstanceFor(w)->out, (void **)txf, BURST_SIZE, NULL);
|
||||
if (nb > 0) {
|
||||
rte_eth_tx_burst(gDpdkPortId, 0, txf, nb);
|
||||
for (unsigned i = 0; i < nb; i++) rte_pktmbuf_free(txf[i]);
|
||||
any = 1;
|
||||
}
|
||||
struct rte_mbuf *txf[BURST_SIZE];
|
||||
unsigned nb = rte_ring_sc_dequeue_burst(ring->out, (void **)txf, BURST_SIZE, NULL);
|
||||
if (nb > 0) {
|
||||
rte_eth_tx_burst(gDpdkPortId, 0, txf, nb);
|
||||
for (unsigned i = 0; i < nb; i++) rte_pktmbuf_free(txf[i]);
|
||||
}
|
||||
/* RX for any remaining packets */
|
||||
/* Also do one more RX to catch any final packets */
|
||||
struct rte_mbuf *rxf[BURST_SIZE];
|
||||
unsigned nr = rte_eth_rx_burst(gDpdkPortId, 0, rxf, BURST_SIZE);
|
||||
if (nr > 0) {
|
||||
for (unsigned i = 0; i < nr; i++)
|
||||
rte_ring_sp_enqueue(ringInstanceFor(1)->in, rxf[i]);
|
||||
any = 1;
|
||||
}
|
||||
if (!any) rte_delay_us(200);
|
||||
if (nr > 0) rte_ring_sp_enqueue_burst(ring->in, (void **)rxf, nr, NULL);
|
||||
if (nb == 0 && nr == 0) rte_delay_us(200);
|
||||
}
|
||||
|
||||
rte_eal_mp_wait_lcore();
|
||||
|
||||
Reference in New Issue
Block a user