@@ -15,7 +15,7 @@ use std::ptr;
1515use std:: ptr:: Unique ;
1616use std:: sync:: atomic:: Ordering ;
1717use std:: sync:: Arc ;
18- use utils:: FiveTupleV4 ;
18+ use utils:: { FiveTupleV4 , rdtsc_unsafe } ;
1919
2020/// A DPDK based PMD port. Send and receive should not be called directly on this structure but on the port queue
2121/// structure instead.
@@ -114,12 +114,13 @@ impl fmt::Display for PortQueue {
114114 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
115115 write ! (
116116 f,
117- "port: {} ({}) rxq: {} txq: {}, max_rxq_len: {}" ,
117+ "port: {} ({}) rxq: {} txq: {}, max_rxq_len: {}, recv_cycles: {} " ,
118118 self . port. mac_address( ) ,
119119 self . port_id,
120120 self . rxq,
121121 self . txq,
122122 self . stats_rx. get_max_q_len( ) ,
123+ self . stats_rx. cycles( ) ,
123124 )
124125 }
125126}
@@ -147,6 +148,7 @@ impl PortQueue {
147148
148149 #[ inline]
149150 fn recv_queue ( & self , pkts : & mut [ * mut MBuf ] , to_recv : u16 ) -> errors:: Result < ( u32 , i32 ) > {
151+ let start= rdtsc_unsafe ( ) ;
150152 unsafe {
151153 let ( recv, q_count) = if self . port . is_kni ( ) {
152154 //debug!("calling rte_kni_rx_burst for {}.{}", self.port, self.rxq);
@@ -160,6 +162,10 @@ impl PortQueue {
160162 let update = self . stats_rx . stats . load ( Ordering :: Relaxed ) + recv as usize ;
161163 self . stats_rx . stats . store ( update, Ordering :: Relaxed ) ;
162164 self . stats_rx . set_q_len ( q_count as usize ) ;
165+ if recv > 0 ||q_count > 0 {
166+ let update = self . stats_rx . cycles . load ( Ordering :: Relaxed ) + ( rdtsc_unsafe ( ) - start) ;
167+ self . stats_rx . cycles . store ( update, Ordering :: Relaxed ) ;
168+ }
163169 Ok ( ( recv, q_count) )
164170 }
165171 }
@@ -298,11 +304,6 @@ impl PmdPort {
298304 }
299305 }
300306
301- /// Current port ID.
302- // #[inline]
303- // pub fn name(&self) -> i32 {
304- // self.port
305- // }
306307 /// Get stats for an RX/TX queue pair.
307308 pub fn stats ( & self , queue : i32 ) -> ( usize , usize , usize ) {
308309 let idx = queue as usize ;
@@ -313,6 +314,18 @@ impl PmdPort {
313314 )
314315 }
315316
317+ /// Get stats for an RX/TX queue pair.
318+ fn stats_4 ( & self , queue : i32 ) -> ( usize , usize , usize , u64 ) {
319+ let idx = queue as usize ;
320+ (
321+ self . stats_rx [ idx] . stats . load ( Ordering :: Relaxed ) ,
322+ self . stats_tx [ idx] . stats . load ( Ordering :: Relaxed ) ,
323+ self . stats_rx [ idx] . get_max_q_len ( ) ,
324+ self . stats_rx [ idx] . cycles ( ) ,
325+ )
326+ }
327+
328+
316329 pub fn map_rx_flow_2_queue ( & self , rxq : u16 , flow : FiveTupleV4 , flow_mask : FiveTupleV4 ) -> Option < & RteFlow > {
317330 unsafe {
318331 let mut error = RteFlowError {
@@ -353,17 +366,17 @@ impl PmdPort {
353366
354367 pub fn print_soft_statistics ( & self ) {
355368 println ! (
356- "{0:>3} | {1: >20} | {2: >20} | {3: >20} | {4: >20} | {5: >20} | {6: >20} | {7: >20}" ,
357- "q" , "ipackets" , "opackets" , "ibytes" , "obytes" , "ierrors" , "oerrors" , "queue_len"
369+ "{0:>3} | {1: >20} | {2: >20} | {3: >20} | {4: >20} | {5: >20} | {6: >20} | {7: >20} | {8: >20} " ,
370+ "q" , "ipackets" , "opackets" , "ibytes" , "obytes" , "ierrors" , "oerrors" , "queue_len" , "rx_cycles"
358371 ) ;
359372 let ( mut sin_p, mut sout_p) = ( 0usize , 0usize ) ;
360373 for q in 0 ..self . rxqs ( ) {
361- let ( in_p, out_p, rx_max_q_len) = self . stats ( q) ;
374+ let ( in_p, out_p, rx_max_q_len, cycles ) = self . stats_4 ( q) ;
362375 sin_p += in_p;
363376 sout_p += out_p;
364377 println ! (
365- "{0:>3} | {1: >20} | {2: >20} | {3: >20} | {4: >20} | {5: >20} | {6: >20} | {7: >20}" ,
366- q, in_p, out_p, 0 , 0 , 0 , 0 , rx_max_q_len
378+ "{0:>3} | {1: >20} | {2: >20} | {3: >20} | {4: >20} | {5: >20} | {6: >20} | {7: >20} | {8: >20} " ,
379+ q, in_p, out_p, 0 , 0 , 0 , 0 , rx_max_q_len, cycles
367380 ) ;
368381 }
369382 println ! (
0 commit comments