Soft Patch Panel
 help / color / mirror / Atom feed
* [spp] [PATCH 0/3] Update docs of implementation of SPP secondaries
@ 2019-07-03  2:24 yasufum.o
  2019-07-03  2:24 ` [spp] [PATCH 1/3] docs: update implementation of spp_vf yasufum.o
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: yasufum.o @ 2019-07-03  2:24 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

For refactoring of SPP worker processes in previous patches, source
code examples in implementation section should also be updated.
This series of patches is for updating the examples and revising
descriptions for topics.

Yasufumi Ogawa (3):
  docs: update implementation of spp_vf
  docs: update implementation of spp_mirror
  docs: update implementation of spp_pcap

 docs/guides/api_ref/proc_independ.rst  |  11 +-
 docs/guides/design/impl/spp_mirror.rst |  85 ++---
 docs/guides/design/impl/spp_pcap.rst   | 156 +++------
 docs/guides/design/impl/spp_vf.rst     | 438 ++++++++-----------------
 4 files changed, 212 insertions(+), 478 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [spp] [PATCH 1/3] docs: update implementation of spp_vf
  2019-07-03  2:24 [spp] [PATCH 0/3] Update docs of implementation of SPP secondaries yasufum.o
@ 2019-07-03  2:24 ` yasufum.o
  2019-07-03  2:25 ` [spp] [PATCH 2/3] docs: update implementation of spp_mirror yasufum.o
  2019-07-03  2:25 ` [spp] [PATCH 3/3] docs: update implementation of spp_pcap yasufum.o
  2 siblings, 0 replies; 4+ messages in thread
From: yasufum.o @ 2019-07-03  2:24 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This update is to update description and examples of spp_vf because
of previous updates for.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 docs/guides/api_ref/proc_independ.rst |  11 +-
 docs/guides/design/impl/spp_vf.rst    | 438 ++++++++------------------
 2 files changed, 140 insertions(+), 309 deletions(-)

diff --git a/docs/guides/api_ref/proc_independ.rst b/docs/guides/api_ref/proc_independ.rst
index c6180fa..8d4b830 100644
--- a/docs/guides/api_ref/proc_independ.rst
+++ b/docs/guides/api_ref/proc_independ.rst
@@ -100,7 +100,7 @@ logical cores if hyper threading is enabled.
     +-------+-----------------------+
 
 
-.. _table_spp_ctl_cpu_layout:
+.. _table_spp_ctl_cpu_layout_params:
 
 .. table:: Response params of getting CPU layout.
 
@@ -144,11 +144,14 @@ Response
             "core_id": 0,
             "lcores": [0, 1]
           },
-          ...
           {
             "core_id": 2,
             "lcores": [4, 5]
           }
+          {
+            "core_id": 3,
+            "lcores": [6, 7]
+          }
         ],
         "socket_id": 0
       }
@@ -167,7 +170,7 @@ Response
 An array of CPU usage of each of SPP processes. This usage consists of
 two params, master lcore and lcore set including master and slaves.
 
-.. _table_spp_ctl_cpu_layout_codes:
+.. _table_spp_ctl_cpu_usage_codes:
 
 .. table:: Response code of CPU layout.
 
@@ -179,7 +182,7 @@ two params, master lcore and lcore set including master and slaves.
     +-------+-----------------------+
 
 
-.. _table_spp_ctl_cpu_layout:
+.. _table_spp_ctl_cpu_usage_params:
 
 .. table:: Response params of getting CPU layout.
 
diff --git a/docs/guides/design/impl/spp_vf.rst b/docs/guides/design/impl/spp_vf.rst
index 76e4a4c..ed5dc27 100644
--- a/docs/guides/design/impl/spp_vf.rst
+++ b/docs/guides/design/impl/spp_vf.rst
@@ -6,21 +6,34 @@
 spp_vf
 ======
 
-The following sections provide some explanation of the code.
+This section describes implementation of key features of ``spp_vf``.
 
-Initializing
-------------
+``spp_vf`` consists of master thread and several worker threads,
+``forwarder``, ``classifier`` or ``merger``, as slaves.
+For classifying packets, ``spp_vf`` has a worker thread named ``classifier``
+and a table for registering MAC address entries.
 
-A manager thread of ``spp_vf`` initialize eal by ``rte_eal_init()``.
-Then each of component threads are launched by
-``rte_eal_remote_launch()``.
 
+Initialization
+--------------
+
+In master thread, data of classifier and VLAN features are initialized
+after ``rte_eal_init()`` is called.
+Port capability is a set of data for describing VLAN features.
+Then, each of worker threads are launched with ``rte_eal_remote_launch()``
+on assigned lcores..
 
 .. code-block:: c
 
     /* spp_vf.c */
+
     int ret_dpdk = rte_eal_init(argc, argv);
 
+    int ret_classifier_mac_init = spp_classifier_mac_init();
+
+    init_forwarder();
+    sppwk_port_capability_init();
+
     /* Start worker threads of classifier and forwarder */
     unsigned int lcore_id = 0;
     RTE_LCORE_FOREACH_SLAVE(lcore_id) {
@@ -28,260 +41,118 @@ Then each of component threads are launched by
     }
 
 
-Main function of slave thread
------------------------------
+Slave Main
+----------
 
-``slave_main()`` is called from ``rte_eal_remote_launch()``.
-It call ``spp_classifier_mac_do()`` or ``spp_forward()`` depending
-on the component command setting.
-``spp_classifier_mac_do()`` provides function for classifier,
-and ``spp_forward()`` provides forwarder and merger.
+Main function of worker thread is defined as ``slave_main()`` which is called
+from ``rte_eal_remote_launch()``.
+Behavior of worker thread is decided in while loop in this function.
+If lcore status is not ``SPPWK_LCORE_RUNNING``, worker thread does nothing.
+On the other hand, it does packet forwarding with or without classifying.
+It classifies incoming packets if component type is ``SPPWK_TYPE_CLS``,
+or simply forwards packets.
 
 .. code-block:: c
 
     /* spp_vf.c */
-    RTE_LOG(INFO, APP, "Core[%d] Start.\n", lcore_id);
-    set_core_status(lcore_id, SPP_CORE_IDLE);
 
     while ((status = spp_get_core_status(lcore_id)) !=
-            SPP_CORE_STOP_REQUEST) {
-            if (status != SPP_CORE_FORWARD)
-                    continue;
-
-            if (spp_check_core_index(lcore_id)) {
-                    /* Setting with the flush command trigger. */
-                    info->ref_index = (info->upd_index+1) %
-                            SPP_INFO_AREA_MAX;
-                    core = get_core_info(lcore_id);
-            }
-
-            for (cnt = 0; cnt < core->num; cnt++) {
-                    if (spp_get_component_type(lcore_id) ==
-                                    SPP_COMPONENT_CLASSIFIER_MAC) {
-                            /* Classifier loops inside the function. */
-                            ret = spp_classifier_mac_do(core->id[cnt]);
-                            break;
-                    }
-
-                    /*
-                     * Forward / Merge returns at once.
-                     * It is for processing multiple components.
-                     */
-                    ret = spp_forward(core->id[cnt]);
-                    if (unlikely(ret != 0))
-                            break;
-            }
-            if (unlikely(ret != 0)) {
-                    RTE_LOG(ERR, APP,
-                            "Core[%d] Component Error. (id = %d)\n",
-                            lcore_id, core->id[cnt]);
+        SPPWK_LCORE_REQ_STOP) {
+    	if (status != SPPWK_LCORE_RUNNING)
+    	    continue;
+
+        // skipping lines ...
+
+        /* It is for processing multiple components. */
+        for (cnt = 0; cnt < core->num; cnt++) {
+        /* Component classification to call a function. */
+        if (spp_get_component_type(core->id[cnt]) ==
+            SPPWK_TYPE_CLS) {
+           	/* Component type for classifier. */
+           	ret = spp_classifier_mac_do(core->id[cnt]);
+           	if (unlikely(ret != 0))
+            break;
+        } else {
+            /* Component type for forward or merge. */
+                ret = forward_packets(core->id[cnt]);
+                if (unlikely(ret != 0))
                     break;
             }
-    }
-
-    set_core_status(lcore_id, SPP_CORE_STOP);
-    RTE_LOG(INFO, APP, "Core[%d] End.\n", lcore_id);
-
-Data structure of classifier table
-----------------------------------
-
-``spp_classifier_mac_do()`` lookup following data defined in
-``classifier_mac.c``,
-when it process the packets.
-Configuration of classifier is stored in the structure of
-``classified_data``, ``classifier_mac_info`` and
-``classifier_mac_mng_info``.
-The ``classified_data`` has member variables for expressing the port
-to be classified, ``classifier_mac_info`` has member variables
-for determining the direction of packets such as hash tables.
-Classifier manages two ``classifier_mac_info``, one is for updating by
-commands, the other is for looking up to process packets.
-Then the ``classifier_mac_mng_info`` has
-two(``NUM_CLASSIFIER_MAC_INFO``) ``classifier_mac_info``
-and index number for updating or reference.
-
-.. code-block:: c
+        }
 
-    /* classifier_mac.c */
-    /* classified data (destination port, target packets, etc) */
-    struct classified_data {
-            /* interface type (see "enum port_type") */
-            enum port_type  iface_type;
 
-            /* index of ports handled by classifier */
-            int             iface_no;
+Data structure of classifier
+----------------------------
 
-            /* id for interface generated by spp_vf */
-            int             iface_no_global;
+Classifier has a set of attributes for classification as
+struct ``mac_classifier``, which consists of a table of MAC addresses,
+number of classifying ports, indices of ports
+and default index of port.
+Clasifier table is implemented as hash of struct ``rte_hash``.
 
-            /* port id generated by DPDK */
-            uint16_t        port;
+.. code-block:: c
 
-            /* the number of packets in pkts[] */
-            uint16_t        num_pkt;
+    /* shared/secondary/spp_worker_th/vf_deps.h */
 
-            /* packet array to be classified */
-            struct rte_mbuf *pkts[MAX_PKT_BURST];
+    /* Classifier for MAC addresses. */
+    struct mac_classifier {
+        struct rte_hash *cls_tbl;  /* Hash table for MAC classification. */
+        int nof_cls_ports;  /* Num of ports classified validly. */
+        int cls_ports[RTE_MAX_ETHPORTS];  /* Ports for classification. */
+        int default_cls_idx;  /* Default index for classification. */
     };
 
-    /* classifier information */
-    struct classifier_mac_info {
-            /* component name */
-            char name[SPP_NAME_STR_LEN];
-
-            /* hash table keeps classifier_table */
-            struct rte_hash *classifier_table;
-
-            /* number of valid classification */
-            int num_active_classified;
-
-            /* index of valid classification */
-            int active_classifieds[RTE_MAX_ETHPORTS];
+Classifier itself is defined as a struct ``cls_comp_info``.
+There are several attributes in this struct including ``mac_classifier``
+or ``cls_port_info`` or so.
+``cls_port_info`` is for defining a set of attributes of ports, such as
+interface type, device ID or packet data.
 
-            /* index of default classification */
-            int default_classified;
-
-            /* number of transmission ports */
-            int n_classified_data_tx;
-
-            /* receive port handled by classifier */
-            struct classified_data classified_data_rx;
+.. code-block:: c
 
-            /* transmission ports handled by classifier */
-            struct classified_data classified_data_tx[RTE_MAX_ETHPORTS];
+    /* shared/secondary/spp_worker_th/vf_deps.h */
+
+    /* classifier component information */
+    struct cls_comp_info {
+        char name[STR_LEN_NAME];  /* component name */
+        int mac_addr_entry;  /* mac address entry flag */
+        struct mac_classifier *mac_clfs[NOF_VLAN];  /* classifiers per VLAN. */
+        int nof_tx_ports;  /* Number of TX ports info entries. */
+        /* Classifier has one RX port and several TX ports. */
+        struct cls_port_info rx_port_i;  /* RX port info classified. */
+        struct cls_port_info tx_ports_i[RTE_MAX_ETHPORTS];  /* TX info. */
     };
 
-    /* classifier management information */
-    struct classifier_mac_mng_info {
-            /* classifier information */
-            struct classifier_mac_info info[NUM_CLASSIFIER_MAC_INFO];
-
-            /* Reference index number for classifier information */
-            volatile int ref_index;
-
-            /* Update index number for classifier information */
-            volatile int upd_index;
+    /* Attirbutes of port for classification. */
+    struct cls_port_info {
+        enum port_type iface_type;
+        int iface_no;   /* Index of ports handled by classifier. */
+        int iface_no_global;  /* ID for interface generated by spp_vf */
+        uint16_t ethdev_port_id;  /* Ethdev port ID. */
+        uint16_t nof_pkts;  /* Number of packets in pkts[]. */
+        struct rte_mbuf *pkts[MAX_PKT_BURST];  /* packets to be classified. */
     };
 
 
-Packet processing in classifier
--------------------------------
+Classifying the packet
+----------------------
 
-In ``spp_classifier_mac_do()``, it receives packets from rx port and
-send them to destinations with ``classify_packet()``.
-``classifier_info`` is an argument of ``classify_packet()`` and is used
-to decide the destinations.
+If component type is ``SPPWK_TYPE_CLS``, worker thread behaves as a classifier,
+so component calls ``spp_classifier_mac_do()``. In this function, packets
+from RX port are received with ``sppwk_eth_vlan_rx_burst()`` which is derived
+from ``rte_eth_rx_burst()`` for adding or deleting VLAN tags.
+Received packets are classified with ``classify_packet()``.
 
 .. code-block:: c
 
     /* classifier_mac.c */
-        while (likely(spp_get_core_status(lcore_id) == SPP_CORE_FORWARD) &&
-                        likely(spp_check_core_index(lcore_id) == 0)) {
-                /* change index of update side */
-                change_update_index(classifier_mng_info, id);
-
-                /* decide classifier information of the current cycle */
-                classifier_info = classifier_mng_info->info +
-                                classifier_mng_info->ref_index;
-                classified_data_rx = &classifier_info->classified_data_rx;
-                classified_data_tx = classifier_info->classified_data_tx;
-
-                /* drain tx packets, if buffer is not filled for interval */
-                cur_tsc = rte_rdtsc();
-                if (unlikely(cur_tsc - prev_tsc > drain_tsc)) {
-                        for (i = 0; i < classifier_info->n_classified_data_tx;
-                                        i++) {
-                                if (likely(classified_data_tx[i].num_pkt == 0))
-                                        continue;
-
-                                RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC,
-                                                "transmit packets (drain). "
-                                                "index=%d, "
-                                                "num_pkt=%hu, "
-                                                "interval=%lu\n",
-                                                i,
-                                                classified_data_tx[i].num_pkt,
-                                                cur_tsc - prev_tsc);
-                                transmit_packet(&classified_data_tx[i]);
-                        }
-                        prev_tsc = cur_tsc;
-                }
-
-                if (classified_data_rx->iface_type == UNDEF)
-                        continue;
-
-                /* retrieve packets */
-                n_rx = rte_eth_rx_burst(classified_data_rx->port, 0,
-                                rx_pkts, MAX_PKT_BURST);
-                if (unlikely(n_rx == 0))
-                        continue;
-
-    #ifdef SPP_RINGLATENCYSTATS_ENABLE
-                    if (classified_data_rx->iface_type == RING)
-                            spp_ringlatencystats_calculate_latency(
-                                            classified_data_rx->iface_no,
-                                            rx_pkts, n_rx);
-    #endif
-
-                /* classify and transmit (filled) */
-                classify_packet(rx_pkts, n_rx, classifier_info,
-                                classified_data_tx);
-        }
-
-Classifying the packets
------------------------
 
-``classify_packet()`` uses hash function of DPDK to determine
-destination.
-Hash has MAC address as Key, it retrieves destination information
-from destination MAC address in the packet.
+    n_rx = sppwk_eth_vlan_rx_burst(clsd_data_rx->ethdev_port_id, 0,
+        rx_pkts, MAX_PKT_BURST);
 
-.. code-block:: c
+    // skipping lines ...
 
-    for (i = 0; i < n_rx; i++) {
-            eth = rte_pktmbuf_mtod(rx_pkts[i], struct ether_hdr *);
-
-            /* find in table (by destination mac address)*/
-            ret = rte_hash_lookup_data(classifier_info->classifier_table,
-                            (const void *)&eth->d_addr, &lookup_data);
-            if (ret < 0) {
-                    /* L2 multicast(include broadcast) ? */
-                    if (unlikely(is_multicast_ether_addr(&eth->d_addr))) {
-                            RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC,
-                                            "multicast mac address.\n");
-                            handle_l2multicast_packet(rx_pkts[i],
-                                            classifier_info,
-                                            classified_data);
-                            continue;
-                    }
-
-                    /* if no default, drop packet */
-                    if (unlikely(classifier_info->default_classified ==
-                                    -1)) {
-                            ether_format_addr(mac_addr_str,
-                                            sizeof(mac_addr_str),
-                                            &eth->d_addr);
-                            RTE_LOG(ERR, SPP_CLASSIFIER_MAC,
-                                            "unknown mac address. "
-                                            "ret=%d, mac_addr=%s\n",
-                                            ret, mac_addr_str);
-                            rte_pktmbuf_free(rx_pkts[i]);
-                            continue;
-                    }
-
-                    /* to default classified */
-                    RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC,
-                                    "to default classified.\n");
-                    lookup_data = (void *)(long)classifier_info->
-                                    default_classified;
-            }
-
-            /*
-             * set mbuf pointer to tx buffer
-             * and transmit packet, if buffer is filled
-             */
-            push_packet(rx_pkts[i], classified_data + (long)lookup_data);
-    }
+    classify_packet(rx_pkts, n_rx, cmp_info, clsd_data_tx);
 
 
 Packet processing in forwarder and merger
@@ -325,78 +196,34 @@ packets.
     };
 
 
-Forward and merge the packets
------------------------------
-
-``spp_forward()`` defined in ``spp_forward.c`` is a main function
-for both forwarder and merger.
-``spp_forward()`` simply passes packet received from rx port to
-tx port of the pair.
-
-.. code-block:: c
-
-    /* spp_forward.c */
-            for (cnt = 0; cnt < num; cnt++) {
-                    rx = &path->ports[cnt].rx;
-                    tx = &path->ports[cnt].tx;
-
-                    /* Receive packets */
-                    nb_rx = rte_eth_rx_burst(
-                            rx->dpdk_port, 0, bufs, MAX_PKT_BURST);
-                    if (unlikely(nb_rx == 0))
-                            continue;
-
-    #ifdef SPP_RINGLATENCYSTATS_ENABLE
-                    if (rx->iface_type == RING)
-                            spp_ringlatencystats_calculate_latency(
-                                            rx->iface_no,
-                                            bufs, nb_rx);
-
-                    if (tx->iface_type == RING)
-                            spp_ringlatencystats_add_time_stamp(
-                                            tx->iface_no,
-                                            bufs, nb_rx);
-    #endif /* SPP_RINGLATENCYSTATS_ENABLE */
-
-                    /* Send packets */
-                    if (tx->dpdk_port >= 0)
-                            nb_tx = rte_eth_tx_burst(
-                                    tx->dpdk_port, 0, bufs, nb_rx);
-
-                    /* Discard remained packets to release mbuf */
-                    if (unlikely(nb_tx < nb_rx)) {
-                            for (buf = nb_tx; buf < nb_rx; buf++)
-                                    rte_pktmbuf_free(bufs[buf]);
-                    }
-            }
-
-
 L2 Multicast Support
 --------------------
 
-SPP_VF also supports multicast for resolving ARP requests.
+``spp_vf`` supports multicast for resolving ARP requests.
 It is implemented as ``handle_l2multicast_packet()`` and called from
 ``classify_packet()`` for incoming multicast packets.
 
 .. code-block:: c
 
-  /* classify_packet() in classifier_mac.c */
-               /* L2 multicast(include broadcast) ? */
-               if (unlikely(is_multicast_ether_addr(&eth->d_addr))) {
-                       RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC,
-                                       "multicast mac address.\n");
-                       handle_l2multicast_packet(rx_pkts[i],
-                                       classifier_info,
-                                       classified_data);
-                       continue;
-               }
+    /* classify_packet() in classifier_mac.c */
+
+    /* L2 multicast(include broadcast) ? */
+    if (unlikely(is_multicast_ether_addr(&eth->d_addr))) {
+            RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC,
+                            "multicast mac address.\n");
+            handle_l2multicast_packet(rx_pkts[i],
+                            classifier_info,
+                            classified_data);
+            continue;
+    }
 
-For distributing multicast packet, it is cloned with
-``rte_mbuf_refcnt_update()``.
+Packets are cloned with ``rte_mbuf_refcnt_update()`` for distributing
+multicast packets.
 
 .. code-block:: c
 
     /* classifier_mac.c */
+
     /* handle L2 multicast(include broadcast) packet */
     static inline void
     handle_l2multicast_packet(struct rte_mbuf *pkt,
@@ -422,10 +249,11 @@ For distributing multicast packet, it is cloned with
             }
     }
 
+
 Two phase update for forwarding
 -------------------------------
 
-Updating netowrk configuration in ``spp_vf`` is done in a short period of
+Update of netowrk configuration in ``spp_vf`` is done in a short period of
 time, but not so short considering the time scale of packet forwarding.
 It might forward packets before the updating is completed possibly.
 To avoid such kind of situation, ``spp_vf`` has two phase update mechanism.
@@ -433,25 +261,25 @@ Status info is referred from forwarding process after the update is completed.
 
 .. code-block:: c
 
-        spp_flush(void)
-        {
-                int ret = SPP_RET_NG;
-                struct cancel_backup_info *backup_info = NULL;
+    int
+    flush_cmd(void)
+    {
+        int ret;
+        int *p_change_comp;
+        struct sppwk_comp_info *p_comp_info;
+        struct cancel_backup_info *backup_info;
 
-                spp_get_mng_data_addr(NULL, NULL, NULL,
-                                        NULL, NULL, NULL, &backup_info);
+        sppwk_get_mng_data(NULL, &p_comp_info, NULL, NULL, &p_change_comp,
+                &backup_info);
 
-                /* Initial setting of each interface. */
-                ret = flush_port();
-                        if (ret < SPP_RET_OK)
-                        return ret;
+        ret = update_port_info();
+        if (ret < SPP_RET_OK)
+            return ret;
 
-                /* Flush of core index. */
-                flush_core();
+        update_lcore_info();
 
-                /* Flush of component */
-                ret = flush_component();
+        ret = update_comp_info(p_comp_info, p_change_comp);
 
-                backup_mng_info(backup_info);
-                return ret;
-        }
+        backup_mng_info(backup_info);
+        return ret;
+    }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [spp] [PATCH 2/3] docs: update implementation of spp_mirror
  2019-07-03  2:24 [spp] [PATCH 0/3] Update docs of implementation of SPP secondaries yasufum.o
  2019-07-03  2:24 ` [spp] [PATCH 1/3] docs: update implementation of spp_vf yasufum.o
@ 2019-07-03  2:25 ` yasufum.o
  2019-07-03  2:25 ` [spp] [PATCH 3/3] docs: update implementation of spp_pcap yasufum.o
  2 siblings, 0 replies; 4+ messages in thread
From: yasufum.o @ 2019-07-03  2:25 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This patch is to update description and examples of spp_mirror.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 docs/guides/design/impl/spp_mirror.rst | 85 ++++++++------------------
 1 file changed, 27 insertions(+), 58 deletions(-)

diff --git a/docs/guides/design/impl/spp_mirror.rst b/docs/guides/design/impl/spp_mirror.rst
index bb4548e..6233de9 100644
--- a/docs/guides/design/impl/spp_mirror.rst
+++ b/docs/guides/design/impl/spp_mirror.rst
@@ -6,81 +6,50 @@
 spp_mirror
 ==========
 
-Initializing
-------------
+This section describes implementation of ``spp_mirror``.
+It consists of master thread and several worker threads for duplicating
+packets.
 
-A main thread of ``spp_mirror`` initialize eal by ``rte_eal_init()``.
-Then each of worker threads is launched from ``rte_eal_remote_launch()``
-by giving a function ``slave_main()`` for forwarding.
-
-.. code-block:: c
-
-    /* spp_mirror.c */
-    int ret_dpdk = rte_eal_init(argc, argv);
-
-    /* Start worker threads of classifier and forwarder */
-    unsigned int lcore_id = 0;
-    RTE_LCORE_FOREACH_SLAVE(lcore_id) {
-            rte_eal_remote_launch(slave_main, NULL, lcore_id);
-    }
 
+Slave Main
+----------
 
-Main function of slave thread
------------------------------
-
-In ``slave_main()``, it calls ``mirror_proc()`` in which packet processing for
-duplicating is defined after finding a core on which running the duplicating.
+Main function of worker thread is defined as ``slave_main()`` in which
+for duplicating packets is ``mirror_proc()`` on each of lcores.
 
 .. code-block:: c
 
-	RTE_LOG(INFO, MIRROR, "Core[%d] Start.\n", lcore_id);
-	set_core_status(lcore_id, SPP_CORE_IDLE);
-
-	while ((status = spp_get_core_status(lcore_id)) !=
-			SPP_CORE_STOP_REQUEST) {
-		if (status != SPP_CORE_FORWARD)
-			continue;
-
-		if (spp_check_core_index(lcore_id)) {
-			/* Setting with the flush command trigger. */
-			info->ref_index = (info->upd_index+1) %
-					SPP_INFO_AREA_MAX;
-			core = get_core_info(lcore_id);
-		}
-
 		for (cnt = 0; cnt < core->num; cnt++) {
-			/*
-			 * mirror returns at once.
-			 * It is for processing multiple components.
-			 */
+
 			ret = mirror_proc(core->id[cnt]);
 			if (unlikely(ret != 0))
 				break;
 		}
-		if (unlikely(ret != 0)) {
-			RTE_LOG(ERR, MIRROR,
-				"Core[%d] Component Error. (id = %d)\n",
-					lcore_id, core->id[cnt]);
-			break;
-		}
-	}
 
-	set_core_status(lcore_id, SPP_CORE_STOP);
-	RTE_LOG(INFO, MIRROR, "Core[%d] End.\n", lcore_id);
 
-Packet mirroring
-----------------
+Mirroring Packets
+-----------------
 
-In ``mirror_proc()``, it receives packets from rx port.
+Worker thread receives and duplicate packets. There are two modes of copying
+packets, ``shallowcopy`` and ``deepcopy``.
+Deep copy is for duplicating whole of packet data, but less performance than
+shallow copy. Shallow copy duplicates only packet header and body is not shared
+among original packet and duplicated packet. So, changing packet data affects
+both of original and copied packet.
 
-.. code-block:: c
+You can configure using which of modes in Makefile. Default mode is
+``shallowcopy``. If you change the mode to ``deepcopy``, comment out this
+line of CFLAGS.
+
+.. code-block:: makefile
 
-        /* Receive packets */
-        nb_rx = spp_eth_rx_burst(rx->dpdk_port, 0, bufs, MAX_PKT_BURST);
+    # Default mode is shallow copy.
+    CFLAGS += -DSPP_MIRROR_SHALLOWCOPY
 
-Each of received packet is copied with ``rte_pktmbuf_clone()`` if you use
-``shallowcopy`` defined as default in Makefile.
-If you use ``deepcopy``, several mbuf objects are allocated for copying.
+This code is a part of ``mirror_proc()``. In this function,
+``rte_pktmbuf_clone()`` is just called if in shallow copy
+mode, or create a new packet with ``rte_pktmbuf_alloc()`` for duplicated
+packet if in deep copy mode.
 
 .. code-block:: c
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [spp] [PATCH 3/3] docs: update implementation of spp_pcap
  2019-07-03  2:24 [spp] [PATCH 0/3] Update docs of implementation of SPP secondaries yasufum.o
  2019-07-03  2:24 ` [spp] [PATCH 1/3] docs: update implementation of spp_vf yasufum.o
  2019-07-03  2:25 ` [spp] [PATCH 2/3] docs: update implementation of spp_mirror yasufum.o
@ 2019-07-03  2:25 ` yasufum.o
  2 siblings, 0 replies; 4+ messages in thread
From: yasufum.o @ 2019-07-03  2:25 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This patch is to update description and examples of spp_pcap.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 docs/guides/design/impl/spp_pcap.rst | 156 ++++++++-------------------
 1 file changed, 45 insertions(+), 111 deletions(-)

diff --git a/docs/guides/design/impl/spp_pcap.rst b/docs/guides/design/impl/spp_pcap.rst
index 8c3f624..1f93d41 100644
--- a/docs/guides/design/impl/spp_pcap.rst
+++ b/docs/guides/design/impl/spp_pcap.rst
@@ -6,139 +6,73 @@
 spp_pcap
 ========
 
-The following sections provide some explanation of the code.
+This section describes implementation of ``spp_pcap``.
 
-Initializing
-------------
 
-A manager thread of ``spp_pcap`` initialize eal by ``rte_eal_init()``.
-Then each of component threads are launched by
-``rte_eal_remote_launch()``.
+Slave Main
+----------
 
+In ``slave_main()``, it calls ``pcap_proc_receive()`` if thread type is
+receiver, or ``pcap_proc_write()`` if the type is writer.
 
 .. code-block:: c
 
     /* spp_pcap.c */
-    int ret_dpdk = rte_eal_init(argc, argv);
 
-    /* Start worker threads of classifier and forwarder */
-    RTE_LCORE_FOREACH_SLAVE(lcore_id) {
-        g_core_info[lcore_id].core[0].num = 1;
-        g_pcap_info[lcore_id].thread_no = thread_no++;
-        rte_eal_remote_launch(slave_main, NULL, lcore_id);
-    }
+    while ((status = spp_get_core_status(lcore_id)) !=
+                    SPP_CORE_STOP_REQUEST) {
 
+            if (pcap_info->type == TYPE_RECIVE)
+                    ret = pcap_proc_receive(lcore_id);
+            else
+                    ret = pcap_proc_write(lcore_id);
+            }
+    }
 
-Main function of slave thread
------------------------------
+Receiving Pakcets
+-----------------
 
-``slave_main()`` is called from ``rte_eal_remote_launch()``.
-It call ``pcap_proc_receive()`` or ``pcap_proc_write()``
-depending on the core assignment.
-``pcap_proc_write();`` provides function for ``receive``,
-and ``pcap_proc_write();`` provides function for ``write``.
+``pcap_proc_receive()`` is for receiving packets with ``rte_eth_rx_burst``
+and sending the packets to the writer thread via ring memory by using
+``rte_ring_enqueue_bulk()``.
 
 .. code-block:: c
 
     /* spp_pcap.c */
-        int ret = SPP_RET_OK;
-        unsigned int lcore_id = rte_lcore_id();
-        enum spp_core_status status = SPP_CORE_STOP;
-        struct pcap_mng_info *pcap_info = &g_pcap_info[lcore_id];
-
-        if (pcap_info->thread_no == 0) {
-                RTE_LOG(INFO, PCAP, "Core[%d] Start recive.\n", lcore_id);
-                pcap_info->type = TYPE_RECIVE;
-        } else {
-                RTE_LOG(INFO, PCAP, "Core[%d] Start write(%d).\n",
-                                        lcore_id, pcap_info->thread_no);
-                pcap_info->type = TYPE_WRITE;
-        }
-        RTE_LOG(INFO, PCAP, "Core[%d] Start.\n", lcore_id);
-        set_core_status(lcore_id, SPP_CORE_IDLE);
-
-        while ((status = spp_get_core_status(lcore_id)) !=
-                        SPP_CORE_STOP_REQUEST) {
-
-                if (pcap_info->type == TYPE_RECIVE)
-                        ret = pcap_proc_receive(lcore_id);
-                else
-                        ret = pcap_proc_write(lcore_id);
-                if (unlikely(ret != SPP_RET_OK)) {
-                        RTE_LOG(ERR, PCAP, "Core[%d] Thread Error.\n",
-                                                                lcore_id);
-                        break;
-                }
-        }
-
-Receive Pakcet
---------------
-
-``pcap_proc_receive()`` is the function to realize
-receiving incoming packets. This function is called in the while loop and
-receive packets. Everytime it receves packet via ``spp_eth_rx_burst()``, then
-it enqueue those packet into the ring using ``rte_ring_enqueue_bulk()``.
-Those packets are trnsfered to ``write`` cores via the ring.
-
-
-.. code-block:: c
 
-        /* spp_pcap.c */
-        /* Receive packets */
-        rx = &g_pcap_option.port_cap;
+    rx = &g_pcap_option.port_cap;
+	nb_rx = rte_eth_rx_burst(rx->ethdev_port_id, 0, bufs, MAX_PCAP_BURST);
 
-        nb_rx = spp_eth_rx_burst(rx->dpdk_port, 0, bufs, MAX_PKT_BURST);
-        if (unlikely(nb_rx == 0))
-                return SPP_RET_OK;
+	/* Forward to ring for writer thread */
+	nb_tx = rte_ring_enqueue_burst(write_ring, (void *)bufs, nb_rx, NULL);
 
-        /* Write ring packets */
 
-        nb_tx = rte_ring_enqueue_bulk(write_ring, (void *)bufs, nb_rx, NULL);
-
-        /* Discard remained packets to release mbuf */
-
-        if (unlikely(nb_tx < nb_rx)) {
-                for (buf = nb_tx; buf < nb_rx; buf++)
-                        rte_pktmbuf_free(bufs[buf]);
-        }
-
-        return SPP_RET_OK;
-
-
-Write Packet
-------------
+Writing Packet
+--------------
 
-In ``pcap_proc_write()``, it dequeue packets from ring.Then it writes to
-storage after data compression using LZ4 libraries. ``compress_file_packet``
-is the function to write packet with LZ4. LZ4 is lossless compression
-algorithm, providing compression speed > 500 MB/s per core, scalable with
-multi-cores CPU. It features an extremely fast decoder, with speed in multiple
-GB/s per core, typically reaching RAM speed limits on multi-core systems.
-Please see details in
+``pcap_proc_write()`` is for capturing packets to a file. The captured file
+is compressed with
 `LZ4
 <https://github.com/lz4/lz4>`_
+which is a lossless compression algorithm and providing compression
+speed > 500 MB/s per core.
 
 .. code-block:: c
 
-        /* Read packets */
-        nb_rx =  rte_ring_dequeue_bulk(read_ring, (void *)bufs, MAX_PKT_BURST,
-                                                                        NULL);
-        if (unlikely(nb_rx == 0))
-                return SPP_RET_OK;
-
-        for (buf = 0; buf < nb_rx; buf++) {
-                mbuf = bufs[buf];
-                rte_prefetch0(rte_pktmbuf_mtod(mbuf, void *));
-                if (compress_file_packet(&g_pcap_info[lcore_id], mbuf)
-                                                        != SPP_RET_OK) {
-                        RTE_LOG(ERR, PCAP, "capture file write error: "
-                                "%d (%s)\n", errno, strerror(errno));
-                        ret = SPP_RET_NG;
-                        info->status = SPP_CAPTURE_IDLE;
-                        compress_file_operation(info, CLOSE_MODE);
-                        break;
-                }
-        }
-        for (buf = nb_rx; buf < nb_rx; buf++)
-                rte_pktmbuf_free(bufs[buf]);
-        return ret;
+    nb_rx =  rte_ring_dequeue_bulk(read_ring, (void *)bufs, MAX_PKT_BURST,
+                                                                    NULL);
+    for (buf = 0; buf < nb_rx; buf++) {
+            mbuf = bufs[buf];
+            rte_prefetch0(rte_pktmbuf_mtod(mbuf, void *));
+            if (compress_file_packet(&g_pcap_info[lcore_id], mbuf)
+                                                    != SPP_RET_OK) {
+                    RTE_LOG(ERR, PCAP, "capture file write error: "
+                            "%d (%s)\n", errno, strerror(errno));
+                    ret = SPP_RET_NG;
+                    info->status = SPP_CAPTURE_IDLE;
+                    compress_file_operation(info, CLOSE_MODE);
+                    break;
+            }
+    }
+    for (buf = nb_rx; buf < nb_rx; buf++)
+            rte_pktmbuf_free(bufs[buf]);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-07-03  2:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-03  2:24 [spp] [PATCH 0/3] Update docs of implementation of SPP secondaries yasufum.o
2019-07-03  2:24 ` [spp] [PATCH 1/3] docs: update implementation of spp_vf yasufum.o
2019-07-03  2:25 ` [spp] [PATCH 2/3] docs: update implementation of spp_mirror yasufum.o
2019-07-03  2:25 ` [spp] [PATCH 3/3] docs: update implementation of spp_pcap yasufum.o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).