Skip to content

Commit 1137319

Browse files
committed
ff_traffic support rx_dropped and tx_dropped.
1 parent ca9922c commit 1137319

File tree

5 files changed

+56
-27
lines changed

5 files changed

+56
-27
lines changed

lib/ff_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ int ff_gettimeofday(struct timeval *tv, struct timezone *tz);
150150
int ff_dup(int oldfd);
151151
int ff_dup2(int oldfd, int newfd);
152152

153-
int ff_pthread_create(pthread_t * thread, const pthread_attr_t * attr,
153+
int ff_pthread_create(pthread_t * thread, const pthread_attr_t * attr,
154154
void * (* start_routine) (void *), void * arg);
155155
int ff_pthread_join(pthread_t thread, void **retval);
156156

@@ -164,7 +164,7 @@ extern int ff_getmaxfd(void);
164164

165165
/*
166166
* Get traffic for QoS or other via API.
167-
* The size of buffer must >= siezof(struct ff_traffic_args), now is 32 bytes.
167+
* The size of buffer must >= siezof(struct ff_traffic_args), now is 48 bytes.
168168
*/
169169
void ff_get_traffic(void *buffer);
170170

lib/ff_dpdk_if.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,14 +1479,17 @@ process_packets(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **bufs,
14791479
}
14801480

14811481
if (ret == FF_DISPATCH_ERROR || ret >= nb_queues) {
1482+
//ff_traffic.rx_dropped += rtem->nb_segs; /* Not counted as packet drop */
14821483
rte_pktmbuf_free(rtem);
14831484
continue;
14841485
}
14851486

14861487
if (ret != queue_id) {
14871488
ret = rte_ring_enqueue(dispatch_ring[port_id][ret], rtem);
1488-
if (ret < 0)
1489+
if (ret < 0) {
1490+
ff_traffic.rx_dropped += rtem->nb_segs;
14891491
rte_pktmbuf_free(rtem);
1492+
}
14901493

14911494
continue;
14921495
}
@@ -1516,8 +1519,10 @@ process_packets(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **bufs,
15161519
if(mbuf_clone) {
15171520
int ret = rte_ring_enqueue(dispatch_ring[port_id][j],
15181521
mbuf_clone);
1519-
if (ret < 0)
1522+
if (ret < 0) {
1523+
ff_traffic.rx_dropped += mbuf_clone->nb_segs;
15201524
rte_pktmbuf_free(mbuf_clone);
1525+
}
15211526
}
15221527
}
15231528
}
@@ -1820,9 +1825,9 @@ send_burst(struct lcore_conf *qconf, uint16_t n, uint8_t port)
18201825
}
18211826

18221827
ret = rte_eth_tx_burst(port, queueid, m_table, n);
1823-
ff_traffic.tx_packets += ret;
18241828
uint16_t i;
18251829
for (i = 0; i < ret; i++) {
1830+
ff_traffic.tx_packets += m_table[i]->nb_segs; // use ret or rets' nb_segs?
18261831
ff_traffic.tx_bytes += rte_pktmbuf_pkt_len(m_table[i]);
18271832
#ifdef FF_USE_PAGE_ARRAY
18281833
if (qconf->tx_mbufs[port].bsd_m_table[i])
@@ -1831,6 +1836,7 @@ send_burst(struct lcore_conf *qconf, uint16_t n, uint8_t port)
18311836
}
18321837
if (unlikely(ret < n)) {
18331838
do {
1839+
ff_traffic.tx_dropped += m_table[ret]->nb_segs;
18341840
rte_pktmbuf_free(m_table[ret]);
18351841
#ifdef FF_USE_PAGE_ARRAY
18361842
if ( qconf->tx_mbufs[port].bsd_m_table[ret] )
@@ -1882,6 +1888,7 @@ ff_dpdk_if_send(struct ff_dpdk_if_context *ctx, void *m,
18821888
struct rte_mempool *mbuf_pool = pktmbuf_pool[lcore_conf.socket_id];
18831889
struct rte_mbuf *head = rte_pktmbuf_alloc(mbuf_pool);
18841890
if (head == NULL) {
1891+
ff_traffic.tx_dropped++;
18851892
ff_mbuf_free(m);
18861893
return -1;
18871894
}
@@ -1895,6 +1902,7 @@ ff_dpdk_if_send(struct ff_dpdk_if_context *ctx, void *m,
18951902
if (cur == NULL) {
18961903
cur = rte_pktmbuf_alloc(mbuf_pool);
18971904
if (cur == NULL) {
1905+
ff_traffic.tx_dropped += head->nb_segs + 1;
18981906
rte_pktmbuf_free(head);
18991907
ff_mbuf_free(m);
19001908
return -1;
@@ -1911,6 +1919,7 @@ ff_dpdk_if_send(struct ff_dpdk_if_context *ctx, void *m,
19111919
int len = total > RTE_MBUF_DEFAULT_DATAROOM ? RTE_MBUF_DEFAULT_DATAROOM : total;
19121920
int ret = ff_mbuf_copydata(m, data, off, len);
19131921
if (ret < 0) {
1922+
ff_traffic.tx_dropped += head->nb_segs;
19141923
rte_pktmbuf_free(head);
19151924
ff_mbuf_free(m);
19161925
return -1;
@@ -2003,6 +2012,7 @@ ff_dpdk_raw_packet_send(void *data, int total, uint16_t port_id)
20032012
struct rte_mempool *mbuf_pool = pktmbuf_pool[lcore_conf.socket_id];
20042013
struct rte_mbuf *head = rte_pktmbuf_alloc(mbuf_pool);
20052014
if (head == NULL) {
2015+
ff_traffic.tx_dropped++;
20062016
return -1;
20072017
}
20082018

@@ -2015,6 +2025,7 @@ ff_dpdk_raw_packet_send(void *data, int total, uint16_t port_id)
20152025
if (cur == NULL) {
20162026
cur = rte_pktmbuf_alloc(mbuf_pool);
20172027
if (cur == NULL) {
2028+
ff_traffic.tx_dropped += head->nb_segs + 1;
20182029
rte_pktmbuf_free(head);
20192030
return -1;
20202031
}

lib/ff_dpdk_kni.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct kni_interface_stats {
8383
/* number of pkts received from NIC, and sent to KNI */
8484
uint64_t rx_packets;
8585

86-
/* number of pkts received from NIC, but failed to send to KNI */
86+
/* number of pkts received from NIC, but failed to send to KNI or kni_ring */
8787
uint64_t rx_dropped;
8888

8989
/* number of pkts received from KNI, and sent to NIC */
@@ -665,6 +665,7 @@ ff_kni_enqueue(enum FilterReturn filter, uint16_t port_id, struct rte_mbuf *pkt)
665665
return 0;
666666

667667
error:
668+
kni_stat[port_id]->rx_dropped++;
668669
rte_pktmbuf_free(pkt);
669670

670671
return -1;

lib/ff_msg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ struct ff_traffic_args {
105105
uint64_t rx_bytes;
106106
uint64_t tx_packets;
107107
uint64_t tx_bytes;
108+
uint64_t rx_dropped; /* number of pkts received from NIC, but failed to send to dispatch_ring */
109+
uint64_t tx_dropped; /* number of pkts failed to send to rte_mbuf or NIC. Not accurate, for reference only. */
108110
};
109111

110112
enum FF_KNICTL_CMD {

tools/traffic/traffic.c

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ int main(int argc, char **argv)
5252
int ch, delay = 1, n = 0;
5353
int single = 0;
5454
unsigned int i, j;
55-
struct ff_traffic_args traffic = {0, 0, 0, 0}, otr;
55+
struct ff_traffic_args traffic = {0, 0, 0, 0, 0, 0}, otr;
5656
struct ff_traffic_args ptraffic[RTE_MAX_LCORE], potr[RTE_MAX_LCORE];
5757
int proc_id = 0, max_proc_id = -1;
58-
uint64_t rxp, rxb, txp, txb;
59-
uint64_t prxp, prxb, ptxp, ptxb;
58+
uint64_t rxp, rxb, txp, txb, rxd, txd;
59+
uint64_t prxp, prxb, ptxp, ptxb, prxd, ptxd;
6060
int title_line = 40;
6161

6262
ff_ipc_init();
@@ -106,8 +106,9 @@ int main(int argc, char **argv)
106106
return -1;
107107
}
108108

109-
printf("%lu,%lu,%lu,%lu\n", traffic.rx_packets, traffic.rx_bytes,
110-
traffic.tx_packets, traffic.tx_bytes);
109+
printf("%lu,%lu,%lu,%lu,%lu,%lu\n", traffic.rx_packets, traffic.rx_bytes,
110+
traffic.tx_packets, traffic.tx_bytes,
111+
traffic.rx_dropped, traffic.tx_dropped);
111112
} else {
112113
for (j = proc_id; j <= max_proc_id; j++) {
113114
ff_set_proc_id(j);
@@ -117,19 +118,21 @@ int main(int argc, char **argv)
117118
return -1;
118119
}
119120

120-
printf("%9d,%20lu,%20lu,%20lu,%20lu,\n",
121+
printf("%9d,%20lu,%20lu,%20lu,%20lu,%20lu,%20lu,\n",
121122
j, ptraffic[j].rx_packets, ptraffic[j].rx_bytes,
122-
ptraffic[j].tx_packets, ptraffic[j].tx_bytes);
123+
ptraffic[j].tx_packets, ptraffic[j].tx_bytes,
124+
traffic.rx_dropped, traffic.tx_dropped);
123125

124126
ADD_S(rx_packets);
125127
ADD_S(rx_bytes);
126128
ADD_S(tx_packets);
127129
ADD_S(tx_bytes);
128130
}
129131

130-
printf("%9s,%20lu,%20lu,%20lu,%20lu,\n",
132+
printf("%9s,%20lu,%20lu,%20lu,%20lu,%20lu,%20lu\n",
131133
"total", traffic.rx_packets, traffic.rx_bytes,
132-
traffic.tx_packets, traffic.tx_bytes);
134+
traffic.tx_packets, traffic.tx_bytes,
135+
traffic.rx_dropped, traffic.tx_dropped);
133136
}
134137
ff_ipc_exit();
135138
return 0;
@@ -145,36 +148,43 @@ int main(int argc, char **argv)
145148

146149
if (i % title_line == 0) {
147150
printf("|--------------------|--------------------|");
148-
printf("--------------------|--------------------|\n");
149-
printf("|%20s|%20s|%20s|%20s|\n", "rx packets", "rx bytes",
150-
"tx packets", "tx bytes");
151+
printf("--------------------|--------------------|"
152+
"--------------------|--------------------|\n");
153+
printf("|%20s|%20s|%20s|%20s|%20s|%20s|\n", "rx packets", "rx bytes",
154+
"tx packets", "tx bytes", "rx_dropped", "tx_dropped");
151155
printf("|--------------------|--------------------|");
152-
printf("--------------------|--------------------|\n");
156+
printf("--------------------|--------------------|"
157+
"--------------------|--------------------|\n");
153158
}
154159

155160
if (i) {
156161
rxp = DIFF(rx_packets);
157162
rxb = DIFF(rx_bytes);
158163
txp = DIFF(tx_packets);
159164
txb = DIFF(tx_bytes);
165+
rxd = DIFF(rx_dropped);
166+
txd = DIFF(tx_dropped);
160167

161-
printf("|%20lu|%20lu|%20lu|%20lu|\n", rxp, rxb, txp, txb);
168+
printf("|%20lu|%20lu|%20lu|%20lu|%20lu|%20lu|\n",
169+
rxp, rxb, txp, txb, rxd, txd);
162170
}
163171
} else {
164172
/*
165173
* get and show traffic from proc_id to max_proc_id.
166174
*/
167175
if (i % (title_line / (max_proc_id - proc_id + 2)) == 0) {
168176
printf("|---------|--------------------|--------------------|"
177+
"--------------------|--------------------|"
169178
"--------------------|--------------------|\n");
170-
printf("|%9s|%20s|%20s|%20s|%20s|\n",
179+
printf("|%9s|%20s|%20s|%20s|%20s|%20s|%20s|\n",
171180
"proc_id", "rx packets", "rx bytes",
172-
"tx packets", "tx bytes");
181+
"tx packets", "tx bytes", "rx_dropped", "tx_dropped");
173182
printf("|---------|--------------------|--------------------|"
183+
"--------------------|--------------------|"
174184
"--------------------|--------------------|\n");
175185
}
176186

177-
rxp = rxb = txp = txb = 0;
187+
rxp = rxb = txp = txb = rxd = txd = 0;
178188
for (j = proc_id; j <= max_proc_id; j++) {
179189
potr[j] = ptraffic[j];
180190

@@ -190,18 +200,23 @@ int main(int argc, char **argv)
190200
prxb = DIFF_P(rx_bytes);
191201
ptxp = DIFF_P(tx_packets);
192202
ptxb = DIFF_P(tx_bytes);
193-
printf("|%9d|%20lu|%20lu|%20lu|%20lu|\n",
194-
j, prxp, prxb, ptxp, ptxb);
203+
prxd = DIFF_P(rx_dropped);
204+
ptxd = DIFF_P(tx_dropped);
205+
printf("|%9d|%20lu|%20lu|%20lu|%20lu|%20lu|%20lu|\n",
206+
j, prxp, prxb, ptxp, ptxb, prxd, ptxd);
195207

196208
rxp += prxp;
197209
rxb += prxb;
198210
txp += ptxp;
199211
txb += ptxb;
212+
rxd += prxd;
213+
txd += ptxd;
200214

201215
if (j == max_proc_id) {
202-
printf("|%9s|%20lu|%20lu|%20lu|%20lu|\n",
203-
"total", rxp, rxb, txp, txb);
216+
printf("|%9s|%20lu|%20lu|%20lu|%20lu|%20lu|%20lu|\n",
217+
"total", rxp, rxb, txp, txb, rxd, txd);
204218
printf("| | |"
219+
" | |"
205220
" | |"
206221
" |\n");
207222
}

0 commit comments

Comments
 (0)