11use anyhow:: Context ;
2- use dpdk:: arrayvec:: { self , ArrayVec } ;
2+ use dpdk:: arrayvec:: ArrayVec ;
33use dpdk:: eal:: { self , Eal , LCoreId , Port , TxQ } ;
44use dpdk:: tx_buffer:: TxBuffer ;
55use log:: { info, warn} ;
66use smoltcp:: wire:: { EthernetAddress , EthernetFrame } ;
77use structopt:: StructOpt ;
88
99use dpdk:: eal:: EalGlobalApi ;
10- use std:: cell:: Cell ;
1110use std:: env;
1211
1312mod utils;
@@ -187,21 +186,18 @@ fn forward_loop(eal: &Eal, lcore: LCoreId, fwds: Vec<ForwardDesc>) {
187186 let mut prev_tsc = 0 ;
188187 let drain_tsc = ( eal. get_tsc_hz ( ) + US_PER_S - 1 ) / US_PER_S * BURST_TX_DRAIN_US ;
189188
190- let sent = Cell :: new ( 0 ) ;
191- let dropped = Cell :: new ( 0 ) ;
189+ let mut _sent = 0 ;
190+ let mut _dropped = 0 ;
192191 let mut _recv = 0 ;
193- let handle_tx_res =
194- |( sent_cnt, dropped_pkts) : ( usize , Option < arrayvec:: Drain < ' _ , _ , MAX_PKT_BURST > > ) | {
195- sent. set ( sent. get ( ) + sent_cnt) ;
196- dropped. set ( dropped. get ( ) + dropped_pkts. map_or ( 0 , |d| d. len ( ) ) ) ;
197- } ;
198192
199193 loop {
200194 let cur_tsc = eal. get_tsc_cycles ( ) ;
201195 let diff_tsc = cur_tsc - prev_tsc;
202196 if diff_tsc > drain_tsc {
203197 for ( dst, tx_buf) in itertools:: izip!( & mut dsts, & mut tx_bufs) {
204- handle_tx_res ( tx_buf. flush ( dst) ) ;
198+ let ( cur_sent, cur_dropped_iter) = tx_buf. flush ( dst) ;
199+ _sent += cur_sent;
200+ _dropped += cur_dropped_iter. map_or ( 0 , |d| d. len ( ) ) ;
205201 }
206202 prev_tsc = cur_tsc;
207203 }
@@ -223,7 +219,9 @@ fn forward_loop(eal: &Eal, lcore: LCoreId, fwds: Vec<ForwardDesc>) {
223219 // flush, but in the current implementation we can't do it
224220 // because we have common prev_tsc for all fwds handled by
225221 // this lcore.
226- handle_tx_res ( tx_buf. tx ( dst, pkt) ) ;
222+ let ( cur_sent, cur_dropped_iter) = tx_buf. tx ( dst, pkt) ;
223+ _sent += cur_sent;
224+ _dropped += cur_dropped_iter. map_or ( 0 , |d| d. len ( ) ) ;
227225 }
228226 }
229227 }
0 commit comments