net/ice: fix memory leak when releasing VSI
[dpdk.git] / app / test-pipeline / runtime.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stdint.h>
8 #include <inttypes.h>
9 #include <sys/types.h>
10 #include <string.h>
11 #include <sys/queue.h>
12 #include <stdarg.h>
13 #include <errno.h>
14 #include <getopt.h>
15
16 #include <rte_common.h>
17 #include <rte_byteorder.h>
18 #include <rte_log.h>
19 #include <rte_memory.h>
20 #include <rte_memcpy.h>
21 #include <rte_eal.h>
22 #include <rte_per_lcore.h>
23 #include <rte_launch.h>
24 #include <rte_atomic.h>
25 #include <rte_cycles.h>
26 #include <rte_prefetch.h>
27 #include <rte_branch_prediction.h>
28 #include <rte_interrupts.h>
29 #include <rte_pci.h>
30 #include <rte_random.h>
31 #include <rte_debug.h>
32 #include <rte_ether.h>
33 #include <rte_ethdev.h>
34 #include <rte_ring.h>
35 #include <rte_mempool.h>
36 #include <rte_mbuf.h>
37 #include <rte_ip.h>
38 #include <rte_tcp.h>
39 #include <rte_lpm.h>
40 #include <rte_lpm6.h>
41 #include <rte_malloc.h>
42
43 #include "main.h"
44
45 void
46 app_main_loop_rx(void) {
47         uint32_t i;
48         int ret;
49
50         RTE_LOG(INFO, USER1, "Core %u is doing RX\n", rte_lcore_id());
51
52         for (i = 0; ; i = ((i + 1) & (app.n_ports - 1))) {
53                 uint16_t n_mbufs;
54
55                 n_mbufs = rte_eth_rx_burst(
56                         app.ports[i],
57                         0,
58                         app.mbuf_rx.array,
59                         app.burst_size_rx_read);
60
61                 if (n_mbufs == 0)
62                         continue;
63
64                 do {
65                         ret = rte_ring_sp_enqueue_bulk(
66                                 app.rings_rx[i],
67                                 (void **) app.mbuf_rx.array,
68                                 n_mbufs, NULL);
69                 } while (ret == 0);
70         }
71 }
72
73 void
74 app_main_loop_worker(void) {
75         struct app_mbuf_array *worker_mbuf;
76         uint32_t i;
77
78         RTE_LOG(INFO, USER1, "Core %u is doing work (no pipeline)\n",
79                 rte_lcore_id());
80
81         worker_mbuf = rte_malloc_socket(NULL, sizeof(struct app_mbuf_array),
82                         RTE_CACHE_LINE_SIZE, rte_socket_id());
83         if (worker_mbuf == NULL)
84                 rte_panic("Worker thread: cannot allocate buffer space\n");
85
86         for (i = 0; ; i = ((i + 1) & (app.n_ports - 1))) {
87                 int ret;
88
89                 ret = rte_ring_sc_dequeue_bulk(
90                         app.rings_rx[i],
91                         (void **) worker_mbuf->array,
92                         app.burst_size_worker_read,
93                         NULL);
94
95                 if (ret == 0)
96                         continue;
97
98                 do {
99                         ret = rte_ring_sp_enqueue_bulk(
100                                 app.rings_tx[i ^ 1],
101                                 (void **) worker_mbuf->array,
102                                 app.burst_size_worker_write,
103                                 NULL);
104                 } while (ret == 0);
105         }
106 }
107
108 void
109 app_main_loop_tx(void) {
110         uint32_t i;
111
112         RTE_LOG(INFO, USER1, "Core %u is doing TX\n", rte_lcore_id());
113
114         for (i = 0; ; i = ((i + 1) & (app.n_ports - 1))) {
115                 uint16_t n_mbufs, n_pkts;
116                 int ret;
117
118                 n_mbufs = app.mbuf_tx[i].n_mbufs;
119
120                 ret = rte_ring_sc_dequeue_bulk(
121                         app.rings_tx[i],
122                         (void **) &app.mbuf_tx[i].array[n_mbufs],
123                         app.burst_size_tx_read,
124                         NULL);
125
126                 if (ret == 0)
127                         continue;
128
129                 n_mbufs += app.burst_size_tx_read;
130
131                 if (n_mbufs < app.burst_size_tx_write) {
132                         app.mbuf_tx[i].n_mbufs = n_mbufs;
133                         continue;
134                 }
135
136                 n_pkts = rte_eth_tx_burst(
137                         app.ports[i],
138                         0,
139                         app.mbuf_tx[i].array,
140                         n_mbufs);
141
142                 if (n_pkts < n_mbufs) {
143                         uint16_t k;
144
145                         for (k = n_pkts; k < n_mbufs; k++) {
146                                 struct rte_mbuf *pkt_to_free;
147
148                                 pkt_to_free = app.mbuf_tx[i].array[k];
149                                 rte_pktmbuf_free(pkt_to_free);
150                         }
151                 }
152
153                 app.mbuf_tx[i].n_mbufs = 0;
154         }
155 }