examples/l2fwd-event: add option to configure port pairs
[dpdk.git] / doc / guides / sample_app_ug / l2_forward_event.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2010-2014 Intel Corporation.
3
4 .. _l2_fwd_event_app:
5
6 L2 Forwarding Eventdev Sample Application
7 =========================================
8
9 The L2 Forwarding eventdev sample application is a simple example of packet
10 processing using the Data Plane Development Kit (DPDK) to demonstrate usage of
11 poll and event mode packet I/O mechanism.
12
13 Overview
14 --------
15
16 The L2 Forwarding eventdev sample application, performs L2 forwarding for each
17 packet that is received on an RX_PORT. The destination port is the adjacent port
18 from the enabled portmask, that is, if the first four ports are enabled (portmask=0x0f),
19 ports 1 and 2 forward into each other, and ports 3 and 4 forward into each other.
20 Also, if MAC addresses updating is enabled, the MAC addresses are affected as follows:
21
22 *   The source MAC address is replaced by the TX_PORT MAC address
23
24 *   The destination MAC address is replaced by  02:00:00:00:00:TX_PORT_ID
25
26 Application receives packets from RX_PORT using below mentioned methods:
27
28 *   Poll mode
29
30 *   Eventdev mode (default)
31
32 This application can be used to benchmark performance using a traffic-generator,
33 as shown in the :numref:`figure_l2fwd_event_benchmark_setup`.
34
35 .. _figure_l2fwd_event_benchmark_setup:
36
37 .. figure:: img/l2_fwd_benchmark_setup.*
38
39    Performance Benchmark Setup (Basic Environment)
40
41 Compiling the Application
42 -------------------------
43
44 To compile the sample application see :doc:`compiling`.
45
46 The application is located in the ``l2fwd-event`` sub-directory.
47
48 Running the Application
49 -----------------------
50
51 The application requires a number of command line options:
52
53 .. code-block:: console
54
55     ./build/l2fwd-event [EAL options] -- -p PORTMASK [-q NQ] --[no-]mac-updating --mode=MODE --eventq-sched=SCHED_MODE
56
57 where,
58
59 *   p PORTMASK: A hexadecimal bitmask of the ports to configure
60
61 *   q NQ: A number of queues (=ports) per lcore (default is 1)
62
63 *   --[no-]mac-updating: Enable or disable MAC addresses updating (enabled by default).
64
65 *   --mode=MODE: Packet transfer mode for I/O, poll or eventdev. Eventdev by default.
66
67 *   --eventq-sched=SCHED_MODE: Event queue schedule mode, Ordered, Atomic or Parallel. Atomic by default.
68
69 *   --config: Configure forwarding port pair mapping. Alternate port pairs by default.
70
71 Sample usage commands are given below to run the application into different mode:
72
73 Poll mode with 4 lcores, 16 ports and 8 RX queues per lcore and MAC address updating enabled,
74 issue the command:
75
76 .. code-block:: console
77
78     ./build/l2fwd-event -l 0-3 -n 4 -- -q 8 -p ffff --mode=poll
79
80 Eventdev mode with 4 lcores, 16 ports , sched method ordered and MAC address updating enabled,
81 issue the command:
82
83 .. code-block:: console
84
85     ./build/l2fwd-event -l 0-3 -n 4 -- -p ffff --eventq-sched=ordered
86
87 or
88
89 .. code-block:: console
90
91     ./build/l2fwd-event -l 0-3 -n 4 -- -q 8 -p ffff --mode=eventdev --eventq-sched=ordered
92
93 Refer to the *DPDK Getting Started Guide* for general information on running
94 applications and the Environment Abstraction Layer (EAL) options.
95
96 To run application with S/W scheduler, it uses following DPDK services:
97
98 *   Software scheduler
99 *   Rx adapter service function
100 *   Tx adapter service function
101
102 Application needs service cores to run above mentioned services. Service cores
103 must be provided as EAL parameters along with the --vdev=event_sw0 to enable S/W
104 scheduler. Following is the sample command:
105
106 .. code-block:: console
107
108     ./build/l2fwd-event -l 0-7 -s 0-3 -n 4 --vdev event_sw0 -- -q 8 -p ffff --mode=eventdev --eventq-sched=ordered
109
110 Explanation
111 -----------
112
113 The following sections provide some explanation of the code.
114
115 .. _l2_fwd_event_app_cmd_arguments:
116
117 Command Line Arguments
118 ~~~~~~~~~~~~~~~~~~~~~~
119
120 The L2 Forwarding eventdev sample application takes specific parameters,
121 in addition to Environment Abstraction Layer (EAL) arguments.
122 The preferred way to parse parameters is to use the getopt() function,
123 since it is part of a well-defined and portable library.
124
125 The parsing of arguments is done in the **l2fwd_parse_args()** function for non
126 eventdev parameters and in **parse_eventdev_args()** for eventdev parameters.
127 The method of argument parsing is not described here. Refer to the
128 *glibc getopt(3)* man page for details.
129
130 EAL arguments are parsed first, then application-specific arguments.
131 This is done at the beginning of the main() function and eventdev parameters
132 are parsed in eventdev_resource_setup() function during eventdev setup:
133
134 .. code-block:: c
135
136     /* init EAL */
137
138     ret = rte_eal_init(argc, argv);
139     if (ret < 0)
140         rte_panic("Invalid EAL arguments\n");
141
142     argc -= ret;
143     argv += ret;
144
145     /* parse application arguments (after the EAL ones) */
146
147     ret = l2fwd_parse_args(argc, argv);
148     if (ret < 0)
149         rte_panic("Invalid L2FWD arguments\n");
150     .
151     .
152     .
153
154     /* Parse eventdev command line options */
155     ret = parse_eventdev_args(argc, argv);
156     if (ret < 0)
157         return ret;
158
159
160
161
162 .. _l2_fwd_event_app_mbuf_init:
163
164 Mbuf Pool Initialization
165 ~~~~~~~~~~~~~~~~~~~~~~~~
166
167 Once the arguments are parsed, the mbuf pool is created.
168 The mbuf pool contains a set of mbuf objects that will be used by the driver
169 and the application to store network packet data:
170
171 .. code-block:: c
172
173     /* create the mbuf pool */
174
175     l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF,
176                                                  MEMPOOL_CACHE_SIZE, 0,
177                                                  RTE_MBUF_DEFAULT_BUF_SIZE,
178                                                  rte_socket_id());
179     if (l2fwd_pktmbuf_pool == NULL)
180         rte_panic("Cannot init mbuf pool\n");
181
182 The rte_mempool is a generic structure used to handle pools of objects.
183 In this case, it is necessary to create a pool that will be used by the driver.
184 The number of allocated pkt mbufs is NB_MBUF, with a data room size of
185 RTE_MBUF_DEFAULT_BUF_SIZE each.
186 A per-lcore cache of 32 mbufs is kept.
187 The memory is allocated in NUMA socket 0,
188 but it is possible to extend this code to allocate one mbuf pool per socket.
189
190 The rte_pktmbuf_pool_create() function uses the default mbuf pool and mbuf
191 initializers, respectively rte_pktmbuf_pool_init() and rte_pktmbuf_init().
192 An advanced application may want to use the mempool API to create the
193 mbuf pool with more control.
194
195 .. _l2_fwd_event_app_drv_init:
196
197 Driver Initialization
198 ~~~~~~~~~~~~~~~~~~~~~
199
200 The main part of the code in the main() function relates to the initialization
201 of the driver. To fully understand this code, it is recommended to study the
202 chapters that related to the Poll Mode and Event mode Driver in the
203 *DPDK Programmer's Guide* - Rel 1.4 EAR and the *DPDK API Reference*.
204
205 .. code-block:: c
206
207     if (rte_pci_probe() < 0)
208         rte_panic("Cannot probe PCI\n");
209
210     /* reset l2fwd_dst_ports */
211
212     for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++)
213         l2fwd_dst_ports[portid] = 0;
214
215     last_port = 0;
216
217     /*
218      * Each logical core is assigned a dedicated TX queue on each port.
219      */
220
221     RTE_ETH_FOREACH_DEV(portid) {
222         /* skip ports that are not enabled */
223
224         if ((l2fwd_enabled_port_mask & (1 << portid)) == 0)
225            continue;
226
227         if (nb_ports_in_mask % 2) {
228             l2fwd_dst_ports[portid] = last_port;
229             l2fwd_dst_ports[last_port] = portid;
230         }
231         else
232            last_port = portid;
233
234         nb_ports_in_mask++;
235
236         rte_eth_dev_info_get((uint8_t) portid, &dev_info);
237     }
238
239 Observe that:
240
241 *   rte_pci_probe() parses the devices on the PCI bus and initializes recognized
242     devices.
243
244 The next step is to configure the RX and TX queues. For each port, there is only
245 one RX queue (only one lcore is able to poll a given port). The number of TX
246 queues depends on the number of available lcores. The rte_eth_dev_configure()
247 function is used to configure the number of queues for a port:
248
249 .. code-block:: c
250
251     ret = rte_eth_dev_configure((uint8_t)portid, 1, 1, &port_conf);
252     if (ret < 0)
253         rte_panic("Cannot configure device: err=%d, port=%u\n",
254                   ret, portid);
255
256 .. _l2_fwd_event_app_rx_init:
257
258 RX Queue Initialization
259 ~~~~~~~~~~~~~~~~~~~~~~~
260
261 The application uses one lcore to poll one or several ports, depending on the -q
262 option, which specifies the number of queues per lcore.
263
264 For example, if the user specifies -q 4, the application is able to poll four
265 ports with one lcore. If there are 16 ports on the target (and if the portmask
266 argument is -p ffff ), the application will need four lcores to poll all the
267 ports.
268
269 .. code-block:: c
270
271     ret = rte_eth_rx_queue_setup((uint8_t) portid, 0, nb_rxd, SOCKET0,
272                                  &rx_conf, l2fwd_pktmbuf_pool);
273     if (ret < 0)
274
275         rte_panic("rte_eth_rx_queue_setup: err=%d, port=%u\n",
276                   ret, portid);
277
278 The list of queues that must be polled for a given lcore is stored in a private
279 structure called struct lcore_queue_conf.
280
281 .. code-block:: c
282
283     struct lcore_queue_conf {
284         unsigned n_rx_port;
285         unsigned rx_port_list[MAX_RX_QUEUE_PER_LCORE];
286         struct mbuf_table tx_mbufs[L2FWD_MAX_PORTS];
287     } rte_cache_aligned;
288
289     struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE];
290
291 The values n_rx_port and rx_port_list[] are used in the main packet processing
292 loop (see :ref:`l2_fwd_event_app_rx_tx_packets`).
293
294 .. _l2_fwd_event_app_tx_init:
295
296 TX Queue Initialization
297 ~~~~~~~~~~~~~~~~~~~~~~~
298
299 Each lcore should be able to transmit on any port. For every port, a single TX
300 queue is initialized.
301
302 .. code-block:: c
303
304     /* init one TX queue on each port */
305
306     fflush(stdout);
307
308     ret = rte_eth_tx_queue_setup((uint8_t) portid, 0, nb_txd,
309                                  rte_eth_dev_socket_id(portid), &tx_conf);
310     if (ret < 0)
311         rte_panic("rte_eth_tx_queue_setup:err=%d, port=%u\n",
312                   ret, (unsigned) portid);
313
314 To configure eventdev support, application setups following components:
315
316 *   Event dev
317 *   Event queue
318 *   Event Port
319 *   Rx/Tx adapters
320 *   Ethernet ports
321
322 .. _l2_fwd_event_app_event_dev_init:
323
324 Event device Initialization
325 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
326 Application can use either H/W or S/W based event device scheduler
327 implementation and supports single instance of event device. It configures event
328 device as per below configuration
329
330 .. code-block:: c
331
332    struct rte_event_dev_config event_d_conf = {
333         .nb_event_queues = ethdev_count, /* Dedicated to each Ethernet port */
334         .nb_event_ports = num_workers, /* Dedicated to each lcore */
335         .nb_events_limit  = 4096,
336         .nb_event_queue_flows = 1024,
337         .nb_event_port_dequeue_depth = 128,
338         .nb_event_port_enqueue_depth = 128
339    };
340
341    ret = rte_event_dev_configure(event_d_id, &event_d_conf);
342    if (ret < 0)
343         rte_panic("Error in configuring event device\n");
344
345 In case of S/W scheduler, application runs eventdev scheduler service on service
346 core. Application retrieves service id and finds the best possible service core to
347 run S/W scheduler.
348
349 .. code-block:: c
350
351         rte_event_dev_info_get(evt_rsrc->event_d_id, &evdev_info);
352         if (evdev_info.event_dev_cap  & RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED) {
353                 ret = rte_event_dev_service_id_get(evt_rsrc->event_d_id,
354                                 &service_id);
355                 if (ret != -ESRCH && ret != 0)
356                         rte_panic("Error in starting eventdev service\n");
357                 l2fwd_event_service_enable(service_id);
358         }
359
360 .. _l2_fwd_app_event_queue_init:
361
362 Event queue Initialization
363 ~~~~~~~~~~~~~~~~~~~~~~~~~~
364 Each Ethernet device is assigned a dedicated event queue which will be linked
365 to all available event ports i.e. each lcore can dequeue packets from any of the
366 Ethernet ports.
367
368 .. code-block:: c
369
370    struct rte_event_queue_conf event_q_conf = {
371         .nb_atomic_flows = 1024,
372         .nb_atomic_order_sequences = 1024,
373         .event_queue_cfg = 0,
374         .schedule_type = RTE_SCHED_TYPE_ATOMIC,
375         .priority = RTE_EVENT_DEV_PRIORITY_HIGHEST
376    };
377
378    /* User requested sched mode */
379    event_q_conf.schedule_type = eventq_sched_mode;
380    for (event_q_id = 0; event_q_id < ethdev_count; event_q_id++) {
381         ret = rte_event_queue_setup(event_d_id, event_q_id,
382                                             &event_q_conf);
383         if (ret < 0)
384               rte_panic("Error in configuring event queue\n");
385    }
386
387 In case of S/W scheduler, an extra event queue is created which will be used for
388 Tx adapter service function for enqueue operation.
389
390 .. _l2_fwd_app_event_port_init:
391
392 Event port Initialization
393 ~~~~~~~~~~~~~~~~~~~~~~~~~
394 Each worker thread is assigned a dedicated event port for enq/deq operations
395 to/from an event device. All event ports are linked with all available event
396 queues.
397
398 .. code-block:: c
399
400    struct rte_event_port_conf event_p_conf = {
401         .dequeue_depth = 32,
402         .enqueue_depth = 32,
403         .new_event_threshold = 4096
404    };
405
406    for (event_p_id = 0; event_p_id < num_workers; event_p_id++) {
407         ret = rte_event_port_setup(event_d_id, event_p_id,
408                                    &event_p_conf);
409         if (ret < 0)
410               rte_panic("Error in configuring event port %d\n", event_p_id);
411
412         ret = rte_event_port_link(event_d_id, event_p_id, NULL,
413                                   NULL, 0);
414         if (ret < 0)
415               rte_panic("Error in linking event port %d to queue\n",
416                         event_p_id);
417    }
418
419 In case of S/W scheduler, an extra event port is created by DPDK library which
420 is retrieved  by the application and same will be used by Tx adapter service.
421
422 .. code-block:: c
423
424         ret = rte_event_eth_tx_adapter_event_port_get(tx_adptr_id, &tx_port_id);
425         if (ret)
426                 rte_panic("Failed to get Tx adapter port id: %d\n", ret);
427
428         ret = rte_event_port_link(event_d_id, tx_port_id,
429                                   &evt_rsrc.evq.event_q_id[
430                                         evt_rsrc.evq.nb_queues - 1],
431                                   NULL, 1);
432         if (ret != 1)
433                 rte_panic("Unable to link Tx adapter port to Tx queue:err=%d\n",
434                           ret);
435
436 .. _l2_fwd_event_app_adapter_init:
437
438 Rx/Tx adapter Initialization
439 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
440 Each Ethernet port is assigned a dedicated Rx/Tx adapter for H/W scheduler. Each
441 Ethernet port's Rx queues are connected to its respective event queue at
442 priority 0 via Rx adapter configuration and Ethernet port's tx queues are
443 connected via Tx adapter.
444
445 .. code-block:: c
446
447         RTE_ETH_FOREACH_DEV(port_id) {
448                 if ((rsrc->enabled_port_mask & (1 << port_id)) == 0)
449                         continue;
450                 ret = rte_event_eth_rx_adapter_create(adapter_id, event_d_id,
451                                                 &evt_rsrc->def_p_conf);
452                 if (ret)
453                         rte_panic("Failed to create rx adapter[%d]\n",
454                                   adapter_id);
455
456                 /* Configure user requested sched type*/
457                 eth_q_conf.ev.sched_type = rsrc->sched_type;
458                 eth_q_conf.ev.queue_id = evt_rsrc->evq.event_q_id[q_id];
459                 ret = rte_event_eth_rx_adapter_queue_add(adapter_id, port_id,
460                                                          -1, &eth_q_conf);
461                 if (ret)
462                         rte_panic("Failed to add queues to Rx adapter\n");
463
464                 ret = rte_event_eth_rx_adapter_start(adapter_id);
465                 if (ret)
466                         rte_panic("Rx adapter[%d] start Failed\n", adapter_id);
467
468                 evt_rsrc->rx_adptr.rx_adptr[adapter_id] = adapter_id;
469                 adapter_id++;
470                 if (q_id < evt_rsrc->evq.nb_queues)
471                         q_id++;
472         }
473
474         adapter_id = 0;
475         RTE_ETH_FOREACH_DEV(port_id) {
476                 if ((rsrc->enabled_port_mask & (1 << port_id)) == 0)
477                         continue;
478                 ret = rte_event_eth_tx_adapter_create(adapter_id, event_d_id,
479                                                 &evt_rsrc->def_p_conf);
480                 if (ret)
481                         rte_panic("Failed to create tx adapter[%d]\n",
482                                   adapter_id);
483
484                 ret = rte_event_eth_tx_adapter_queue_add(adapter_id, port_id,
485                                                          -1);
486                 if (ret)
487                         rte_panic("Failed to add queues to Tx adapter\n");
488
489                 ret = rte_event_eth_tx_adapter_start(adapter_id);
490                 if (ret)
491                         rte_panic("Tx adapter[%d] start Failed\n", adapter_id);
492
493                 evt_rsrc->tx_adptr.tx_adptr[adapter_id] = adapter_id;
494                 adapter_id++;
495         }
496
497 For S/W scheduler instead of dedicated adapters, common Rx/Tx adapters are
498 configured which will be shared among all the Ethernet ports. Also DPDK library
499 need service cores to run internal services for Rx/Tx adapters. Application gets
500 service id for Rx/Tx adapters and after successful setup it runs the services
501 on dedicated service cores.
502
503 .. code-block:: c
504
505         for (i = 0; i < evt_rsrc->rx_adptr.nb_rx_adptr; i++) {
506                 ret = rte_event_eth_rx_adapter_caps_get(evt_rsrc->event_d_id,
507                                 evt_rsrc->rx_adptr.rx_adptr[i], &caps);
508                 if (ret < 0)
509                         rte_panic("Failed to get Rx adapter[%d] caps\n",
510                                   evt_rsrc->rx_adptr.rx_adptr[i]);
511                 ret = rte_event_eth_rx_adapter_service_id_get(
512                                                 evt_rsrc->event_d_id,
513                                                 &service_id);
514                 if (ret != -ESRCH && ret != 0)
515                         rte_panic("Error in starting Rx adapter[%d] service\n",
516                                   evt_rsrc->rx_adptr.rx_adptr[i]);
517                 l2fwd_event_service_enable(service_id);
518         }
519
520         for (i = 0; i < evt_rsrc->tx_adptr.nb_tx_adptr; i++) {
521                 ret = rte_event_eth_tx_adapter_caps_get(evt_rsrc->event_d_id,
522                                 evt_rsrc->tx_adptr.tx_adptr[i], &caps);
523                 if (ret < 0)
524                         rte_panic("Failed to get Rx adapter[%d] caps\n",
525                                   evt_rsrc->tx_adptr.tx_adptr[i]);
526                 ret = rte_event_eth_tx_adapter_service_id_get(
527                                 evt_rsrc->event_d_id,
528                                 &service_id);
529                 if (ret != -ESRCH && ret != 0)
530                         rte_panic("Error in starting Rx adapter[%d] service\n",
531                                   evt_rsrc->tx_adptr.tx_adptr[i]);
532                 l2fwd_event_service_enable(service_id);
533         }
534
535 .. _l2_fwd_event_app_rx_tx_packets:
536
537 Receive, Process and Transmit Packets
538 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
539
540 In the **l2fwd_main_loop()** function, the main task is to read ingress packets from
541 the RX queues. This is done using the following code:
542
543 .. code-block:: c
544
545     /*
546      * Read packet from RX queues
547      */
548
549     for (i = 0; i < qconf->n_rx_port; i++) {
550         portid = qconf->rx_port_list[i];
551         nb_rx = rte_eth_rx_burst((uint8_t) portid, 0,  pkts_burst,
552                                  MAX_PKT_BURST);
553
554         for (j = 0; j < nb_rx; j++) {
555             m = pkts_burst[j];
556             rte_prefetch0(rte_pktmbuf_mtod(m, void *));
557             l2fwd_simple_forward(m, portid);
558         }
559     }
560
561 Packets are read in a burst of size MAX_PKT_BURST. The rte_eth_rx_burst()
562 function writes the mbuf pointers in a local table and returns the number of
563 available mbufs in the table.
564
565 Then, each mbuf in the table is processed by the l2fwd_simple_forward()
566 function. The processing is very simple: process the TX port from the RX port,
567 then replace the source and destination MAC addresses if MAC addresses updating
568 is enabled.
569
570 During the initialization process, a static array of destination ports
571 (l2fwd_dst_ports[]) is filled such that for each source port, a destination port
572 is assigned that is either the next or previous enabled port from the portmask.
573 If number of ports are odd in portmask then packet from last port will be
574 forwarded to first port i.e. if portmask=0x07, then forwarding will take place
575 like p0--->p1, p1--->p2, p2--->p0.
576
577 Also to optimize enqueue operation, l2fwd_simple_forward() stores incoming mbufs
578 up to MAX_PKT_BURST. Once it reaches up to limit, all packets are transmitted to
579 destination ports.
580
581 .. code-block:: c
582
583    static void
584    l2fwd_simple_forward(struct rte_mbuf *m, uint32_t portid)
585    {
586        uint32_t dst_port;
587        int32_t sent;
588        struct rte_eth_dev_tx_buffer *buffer;
589
590        dst_port = l2fwd_dst_ports[portid];
591
592        if (mac_updating)
593            l2fwd_mac_updating(m, dst_port);
594
595        buffer = tx_buffer[dst_port];
596        sent = rte_eth_tx_buffer(dst_port, 0, buffer, m);
597        if (sent)
598        port_statistics[dst_port].tx += sent;
599    }
600
601 For this test application, the processing is exactly the same for all packets
602 arriving on the same RX port. Therefore, it would have been possible to call
603 the rte_eth_tx_buffer() function directly from the main loop to send all the
604 received packets on the same TX port, using the burst-oriented send function,
605 which is more efficient.
606
607 However, in real-life applications (such as, L3 routing),
608 packet N is not necessarily forwarded on the same port as packet N-1.
609 The application is implemented to illustrate that, so the same approach can be
610 reused in a more complex application.
611
612 To ensure that no packets remain in the tables, each lcore does a draining of TX
613 queue in its main loop. This technique introduces some latency when there are
614 not many packets to send, however it improves performance:
615
616 .. code-block:: c
617
618         cur_tsc = rte_rdtsc();
619
620         /*
621         * TX burst queue drain
622         */
623         diff_tsc = cur_tsc - prev_tsc;
624         if (unlikely(diff_tsc > drain_tsc)) {
625                 for (i = 0; i < qconf->n_rx_port; i++) {
626                         portid = l2fwd_dst_ports[qconf->rx_port_list[i]];
627                         buffer = tx_buffer[portid];
628                         sent = rte_eth_tx_buffer_flush(portid, 0,
629                                                        buffer);
630                         if (sent)
631                                 port_statistics[portid].tx += sent;
632                 }
633
634                 /* if timer is enabled */
635                 if (timer_period > 0) {
636                         /* advance the timer */
637                         timer_tsc += diff_tsc;
638
639                         /* if timer has reached its timeout */
640                         if (unlikely(timer_tsc >= timer_period)) {
641                                 /* do this only on master core */
642                                 if (lcore_id == rte_get_master_lcore()) {
643                                         print_stats();
644                                         /* reset the timer */
645                                         timer_tsc = 0;
646                                 }
647                         }
648                 }
649
650                 prev_tsc = cur_tsc;
651         }
652
653 In the **l2fwd_event_loop()** function, the main task is to read ingress
654 packets from the event ports. This is done using the following code:
655
656 .. code-block:: c
657
658         /* Read packet from eventdev */
659         nb_rx = rte_event_dequeue_burst(event_d_id, event_p_id,
660                                         events, deq_len, 0);
661         if (nb_rx == 0) {
662                 rte_pause();
663                 continue;
664         }
665
666         for (i = 0; i < nb_rx; i++) {
667                 mbuf[i] = events[i].mbuf;
668                 rte_prefetch0(rte_pktmbuf_mtod(mbuf[i], void *));
669         }
670
671
672 Before reading packets, deq_len is fetched to ensure correct allowed deq length
673 by the eventdev.
674 The rte_event_dequeue_burst() function writes the mbuf pointers in a local table
675 and returns the number of available mbufs in the table.
676
677 Then, each mbuf in the table is processed by the l2fwd_eventdev_forward()
678 function. The processing is very simple: process the TX port from the RX port,
679 then replace the source and destination MAC addresses if MAC addresses updating
680 is enabled.
681
682 During the initialization process, a static array of destination ports
683 (l2fwd_dst_ports[]) is filled such that for each source port, a destination port
684 is assigned that is either the next or previous enabled port from the portmask.
685 If number of ports are odd in portmask then packet from last port will be
686 forwarded to first port i.e. if portmask=0x07, then forwarding will take place
687 like p0--->p1, p1--->p2, p2--->p0.
688
689 l2fwd_eventdev_forward() does not stores incoming mbufs. Packet will forwarded
690 be to destination ports via Tx adapter or generic event dev enqueue API
691 depending H/W or S/W scheduler is used.
692
693 .. code-block:: c
694
695         nb_tx = rte_event_eth_tx_adapter_enqueue(event_d_id, port_id, ev,
696                                                  nb_rx);
697         while (nb_tx < nb_rx && !rsrc->force_quit)
698                 nb_tx += rte_event_eth_tx_adapter_enqueue(
699                                 event_d_id, port_id,
700                                 ev + nb_tx, nb_rx - nb_tx);