drivers/net: share vdev data to secondary process
authorJianfeng Tan <jianfeng.tan@intel.com>
Tue, 24 Apr 2018 05:51:24 +0000 (05:51 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 24 Apr 2018 10:37:31 +0000 (12:37 +0200)
dpdk-procinfo, as a secondary process, cannot fetch stats for vdev.

This patch enables that by attaching the port from the shared data.
We also fill the eth dev ops, with only some ops works in secondary
process, for example, stats_get().

Note that, we still cannot Rx/Tx packets on the ports which do not
support multi-process.

Reported-by: Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
Reviewed-by: Qi Zhang <qi.z.zhang@intel.com>
doc/guides/rel_notes/release_18_05.rst
drivers/net/af_packet/rte_eth_af_packet.c
drivers/net/bonding/rte_eth_bond_pmd.c
drivers/net/failsafe/failsafe.c
drivers/net/kni/rte_eth_kni.c
drivers/net/null/rte_eth_null.c
drivers/net/octeontx/octeontx_ethdev.c
drivers/net/pcap/rte_eth_pcap.c
drivers/net/softnic/rte_eth_softnic.c
drivers/net/tap/rte_eth_tap.c
drivers/net/vhost/rte_eth_vhost.c

index 5276882b839a683cfd0702c11b35f2fb175a9d53..cd958c138817fb518570f66842a2aefb57a0c74b 100644 (file)
@@ -134,6 +134,12 @@ New Features
 
   Linux uevent is supported as backend of this device event notification framework.
 
+* **Added support for procinfo and pdump on eth vdev.**
+
+  For ethernet virtual devices (like tap, pcap, etc), with this feature, we can get
+  stats/xstats on shared memory from secondary process, and also pdump packets on
+  those virtual devices.
+
 
 API Changes
 -----------
index 110e8a5cc60e8d6868e775c942298e2cbb305144..b394d3cb2926d1f260d6c8cbe2d88b8fa3952084 100644 (file)
@@ -915,9 +915,22 @@ rte_pmd_af_packet_probe(struct rte_vdev_device *dev)
        int ret = 0;
        struct rte_kvargs *kvlist;
        int sockfd = -1;
+       struct rte_eth_dev *eth_dev;
+       const char *name = rte_vdev_device_name(dev);
+
+       RTE_LOG(INFO, PMD, "Initializing pmd_af_packet for %s\n", name);
 
-       RTE_LOG(INFO, PMD, "Initializing pmd_af_packet for %s\n",
-               rte_vdev_device_name(dev));
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+           strlen(rte_vdev_device_args(dev)) == 0) {
+               eth_dev = rte_eth_dev_attach_secondary(name);
+               if (!eth_dev) {
+                       RTE_LOG(ERR, PMD, "Failed to probe %s\n", name);
+                       return -1;
+               }
+               /* TODO: request info from primary to set up Rx and Tx */
+               eth_dev->dev_ops = &ops;
+               return 0;
+       }
 
        kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
        if (kvlist == NULL) {
index 2805c710bc57f0e8b0279a7a5f1d7485ba3839e3..09696ea3f88ca2ac7e80531e051c240e8fede162 100644 (file)
@@ -3021,6 +3021,7 @@ bond_probe(struct rte_vdev_device *dev)
        uint8_t bonding_mode, socket_id/*, agg_mode*/;
        int  arg_count, port_id;
        uint8_t agg_mode;
+       struct rte_eth_dev *eth_dev;
 
        if (!dev)
                return -EINVAL;
@@ -3028,6 +3029,18 @@ bond_probe(struct rte_vdev_device *dev)
        name = rte_vdev_device_name(dev);
        RTE_LOG(INFO, EAL, "Initializing pmd_bond for %s\n", name);
 
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+           strlen(rte_vdev_device_args(dev)) == 0) {
+               eth_dev = rte_eth_dev_attach_secondary(name);
+               if (!eth_dev) {
+                       RTE_LOG(ERR, PMD, "Failed to probe %s\n", name);
+                       return -1;
+               }
+               /* TODO: request info from primary to set up Rx and Tx */
+               eth_dev->dev_ops = &default_dev_ops;
+               return 0;
+       }
+
        kvlist = rte_kvargs_parse(rte_vdev_device_args(dev),
                pmd_bond_init_valid_arguments);
        if (kvlist == NULL)
index fa279cbd6f359e13fcc1c24ff6e75a41df7872b0..dc9b0d08881daf3d23b6b681e13f0bd5cfd30ac8 100644 (file)
@@ -294,10 +294,24 @@ static int
 rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
 {
        const char *name;
+       struct rte_eth_dev *eth_dev;
 
        name = rte_vdev_device_name(vdev);
        INFO("Initializing " FAILSAFE_DRIVER_NAME " for %s",
                        name);
+
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+           strlen(rte_vdev_device_args(vdev)) == 0) {
+               eth_dev = rte_eth_dev_attach_secondary(name);
+               if (!eth_dev) {
+                       RTE_LOG(ERR, PMD, "Failed to probe %s\n", name);
+                       return -1;
+               }
+               /* TODO: request info from primary to set up Rx and Tx */
+               eth_dev->dev_ops = &failsafe_ops;
+               return 0;
+       }
+
        return fs_eth_dev_create(vdev);
 }
 
index b7897b65630f67de34a5d72b008697f38e9e70c8..08fc6a35e0e13c86d1e6c74fadc6aa7c32caceec 100644 (file)
@@ -404,6 +404,18 @@ eth_kni_probe(struct rte_vdev_device *vdev)
        params = rte_vdev_device_args(vdev);
        RTE_LOG(INFO, PMD, "Initializing eth_kni for %s\n", name);
 
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+           strlen(params) == 0) {
+               eth_dev = rte_eth_dev_attach_secondary(name);
+               if (!eth_dev) {
+                       RTE_LOG(ERR, PMD, "Failed to probe %s\n", name);
+                       return -1;
+               }
+               /* TODO: request info from primary to set up Rx and Tx */
+               eth_dev->dev_ops = &eth_kni_ops;
+               return 0;
+       }
+
        ret = eth_kni_kvargs_process(&args, params);
        if (ret < 0)
                return ret;
index 7d89a3259753b4ca2d40c678c1156f93a2438b95..6413a9064245152f621542d83c582945e549e7b8 100644 (file)
@@ -597,6 +597,7 @@ rte_pmd_null_probe(struct rte_vdev_device *dev)
        unsigned packet_size = default_packet_size;
        unsigned packet_copy = default_packet_copy;
        struct rte_kvargs *kvlist = NULL;
+       struct rte_eth_dev *eth_dev;
        int ret;
 
        if (!dev)
@@ -606,6 +607,18 @@ rte_pmd_null_probe(struct rte_vdev_device *dev)
        params = rte_vdev_device_args(dev);
        RTE_LOG(INFO, PMD, "Initializing pmd_null for %s\n", name);
 
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+           strlen(params) == 0) {
+               eth_dev = rte_eth_dev_attach_secondary(name);
+               if (!eth_dev) {
+                       RTE_LOG(ERR, PMD, "Failed to probe %s\n", name);
+                       return -1;
+               }
+               /* TODO: request info from primary to set up Rx and Tx */
+               eth_dev->dev_ops = &ops;
+               return 0;
+       }
+
        if (params != NULL) {
                kvlist = rte_kvargs_parse(params, valid_arguments);
                if (kvlist == NULL)
index ee06cd355466feb4b76d396780d1684c31a8ec21..04120f502ece655c8de4ff24befc430e387e06bb 100644 (file)
@@ -1228,12 +1228,26 @@ octeontx_probe(struct rte_vdev_device *dev)
        struct rte_event_dev_config dev_conf;
        const char *eventdev_name = "event_octeontx";
        struct rte_event_dev_info info;
+       struct rte_eth_dev *eth_dev;
 
        struct octeontx_vdev_init_params init_params = {
                OCTEONTX_VDEV_DEFAULT_MAX_NR_PORT
        };
 
        dev_name = rte_vdev_device_name(dev);
+
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+           strlen(rte_vdev_device_args(dev)) == 0) {
+               eth_dev = rte_eth_dev_attach_secondary(dev_name);
+               if (!eth_dev) {
+                       RTE_LOG(ERR, PMD, "Failed to probe %s\n", dev_name);
+                       return -1;
+               }
+               /* TODO: request info from primary to set up Rx and Tx */
+               eth_dev->dev_ops = &octeontx_dev_ops;
+               return 0;
+       }
+
        res = octeontx_parse_vdev_init_params(&init_params, dev);
        if (res < 0)
                return -EINVAL;
index 8740d527f0b60899a19d66a372b82929e454e79e..570c9e984d32e353591d8947e12528c95c317226 100644 (file)
@@ -898,6 +898,7 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
        struct rte_kvargs *kvlist;
        struct pmd_devargs pcaps = {0};
        struct pmd_devargs dumpers = {0};
+       struct rte_eth_dev *eth_dev;
        int single_iface = 0;
        int ret;
 
@@ -908,6 +909,18 @@ pmd_pcap_probe(struct rte_vdev_device *dev)
        start_cycles = rte_get_timer_cycles();
        hz = rte_get_timer_hz();
 
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+           strlen(rte_vdev_device_args(dev)) == 0) {
+               eth_dev = rte_eth_dev_attach_secondary(name);
+               if (!eth_dev) {
+                       RTE_LOG(ERR, PMD, "Failed to probe %s\n", name);
+                       return -1;
+               }
+               /* TODO: request info from primary to set up Rx and Tx */
+               eth_dev->dev_ops = &ops;
+               return 0;
+       }
+
        kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
        if (kvlist == NULL)
                return -1;
index b0c134152fd691ee16c36511631d0a339730bd5a..e3243940cba7abce4e6f907e4f8d5fd976ac68b5 100644 (file)
@@ -725,13 +725,26 @@ pmd_probe(struct rte_vdev_device *vdev)
        uint16_t hard_port_id;
        int numa_node;
        void *dev_private;
+       struct rte_eth_dev *eth_dev;
+       const char *name = rte_vdev_device_name(vdev);
 
-       RTE_LOG(INFO, PMD,
-               "Probing device \"%s\"\n",
-               rte_vdev_device_name(vdev));
+       RTE_LOG(INFO, PMD, "Probing device \"%s\"\n", name);
 
        /* Parse input arguments */
        params = rte_vdev_device_args(vdev);
+
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+           strlen(params) == 0) {
+               eth_dev = rte_eth_dev_attach_secondary(name);
+               if (!eth_dev) {
+                       RTE_LOG(ERR, PMD, "Failed to probe %s\n", name);
+                       return -1;
+               }
+               /* TODO: request info from primary to set up Rx and Tx */
+               eth_dev->dev_ops = &pmd_ops;
+               return 0;
+       }
+
        if (!params)
                return -EINVAL;
 
index b18efd8b70e7ce3858c0d092fa78592e7a1a8638..cca5852cc3ac90a9b50a1db16fb70c72bf2c9292 100644 (file)
@@ -1721,6 +1721,7 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
        char tap_name[RTE_ETH_NAME_MAX_LEN];
        char remote_iface[RTE_ETH_NAME_MAX_LEN];
        struct ether_addr user_mac = { .addr_bytes = {0} };
+       struct rte_eth_dev *eth_dev;
 
        tap_type = 1;
        strcpy(tuntap_name, "TAP");
@@ -1728,6 +1729,18 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev)
        name = rte_vdev_device_name(dev);
        params = rte_vdev_device_args(dev);
 
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+           strlen(params) == 0) {
+               eth_dev = rte_eth_dev_attach_secondary(name);
+               if (!eth_dev) {
+                       RTE_LOG(ERR, PMD, "Failed to probe %s\n", name);
+                       return -1;
+               }
+               /* TODO: request info from primary to set up Rx and Tx */
+               eth_dev->dev_ops = &ops;
+               return 0;
+       }
+
        speed = ETH_SPEED_NUM_10G;
        snprintf(tap_name, sizeof(tap_name), "%s%d",
                 DEFAULT_TAP_NAME, tap_unit++);
index fea13eb55421ec81151c2ac3a5f650d460fd27ba..99a7727a39c085c17771834012b5a1ce3b3b3a17 100644 (file)
@@ -1362,9 +1362,22 @@ rte_pmd_vhost_probe(struct rte_vdev_device *dev)
        int client_mode = 0;
        int dequeue_zero_copy = 0;
        int iommu_support = 0;
+       struct rte_eth_dev *eth_dev;
+       const char *name = rte_vdev_device_name(dev);
+
+       RTE_LOG(INFO, PMD, "Initializing pmd_vhost for %s\n", name);
 
-       RTE_LOG(INFO, PMD, "Initializing pmd_vhost for %s\n",
-               rte_vdev_device_name(dev));
+       if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
+           strlen(rte_vdev_device_args(dev)) == 0) {
+               eth_dev = rte_eth_dev_attach_secondary(name);
+               if (!eth_dev) {
+                       RTE_LOG(ERR, PMD, "Failed to probe %s\n", name);
+                       return -1;
+               }
+               /* TODO: request info from primary to set up Rx and Tx */
+               eth_dev->dev_ops = &ops;
+               return 0;
+       }
 
        kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
        if (kvlist == NULL)