Skip to content

Commit e43ae98

Browse files
author
rstade
committed
added cycles to port statistics
1 parent d6f30c4 commit e43ae98

File tree

5 files changed

+43
-24
lines changed

5 files changed

+43
-24
lines changed

framework/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "e2d2"
3-
version = "0.3.6"
3+
version = "0.4.0"
44
authors = ["Aurojit Panda <[email protected]>", "rainer <[email protected]>"]
55
build = "build.rs"
66

framework/src/interface/packet.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ impl<T: EndOffset, M: Sized + Send> Packet<T, M> {
253253

254254
/// clone has same mbuf as the original
255255
pub fn clone(&mut self) -> Packet<T, M> {
256-
// unsafe { packet_from_mbuf(self.mbuf, self.offset) };
257256
reference_mbuf(self.mbuf);
258257

259258
Packet::<T, M> {
@@ -266,6 +265,19 @@ impl<T: EndOffset, M: Sized + Send> Packet<T, M> {
266265
}
267266
}
268267

268+
/// same as clone, but without increment of mbuf ref count
269+
pub fn clone_without_ref_counting(&mut self) -> Packet<T, M> {
270+
Packet::<T, M> {
271+
mbuf: self.mbuf,
272+
_phantom_m: PhantomData,
273+
offset: self.offset,
274+
pre_pre_header: self.pre_pre_header,
275+
pre_header: self.pre_header,
276+
header: self.header,
277+
}
278+
}
279+
280+
269281
/// copy gets us a new mbuf
270282
pub unsafe fn copy(&self) -> Packet<T, M> {
271283
// unsafe { packet_from_mbuf(self.mbuf, self.offset) };

framework/src/interface/port/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use allocators::*;
66
use common::*;
77
use interface::{PacketRx, PacketTx};
88
use native::zcsi::MBuf;
9-
use std::sync::atomic::{AtomicUsize, Ordering};
9+
use std::sync::atomic::{AtomicUsize, AtomicU64, Ordering};
1010

1111
mod phy_port;
1212
mod virt_port;
@@ -17,6 +17,7 @@ pub struct PortStats {
1717
pub stats: AtomicUsize,
1818
pub q_len: AtomicUsize,
1919
pub max_q_len: AtomicUsize,
20+
pub cycles: AtomicU64,
2021
}
2122

2223
impl PortStats {
@@ -25,11 +26,13 @@ impl PortStats {
2526
stats: AtomicUsize::new(0),
2627
q_len: AtomicUsize::new(0),
2728
max_q_len: AtomicUsize::new(0),
29+
cycles: AtomicU64::new(0),
2830
})
2931
}
3032

3133
pub fn get_q_len(&self) -> usize { self.q_len.load(Ordering::Relaxed) }
3234
pub fn get_max_q_len(&self) -> usize { self.max_q_len.load(Ordering::Relaxed) }
35+
pub fn cycles(&self) -> u64 { self.cycles.load(Ordering::Relaxed) }
3336

3437
pub fn set_q_len(&self, len: usize) -> usize {
3538
let q_max= self.get_max_q_len();

framework/src/interface/port/phy_port.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::ptr;
1515
use std::ptr::Unique;
1616
use std::sync::atomic::Ordering;
1717
use 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!(

framework/src/operators/merge_batch_auto.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ impl<T: Batch> MergeBatchAuto<T> {
7777
impl<T: Batch> Batch for MergeBatchAuto<T> {
7878
#[inline]
7979
fn queued(&self) -> usize {
80-
/* let mut result = 0;
81-
for b in &self.state {
82-
if *b>0 {
83-
result = *b;
84-
break;
85-
}
86-
}
87-
result
88-
*/
8980
self.queue_size
9081
}
9182
}

0 commit comments

Comments
 (0)