]> git.droids-corp.org - dpdk.git/commitdiff
drivers/net: do not use private ethdev data
authorJianfeng Tan <jianfeng.tan@intel.com>
Tue, 24 Apr 2018 05:51:23 +0000 (05:51 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 24 Apr 2018 10:33:51 +0000 (12:33 +0200)
We introduced private rte_eth_dev_data to allow vdev to be created
both in primary process and secondary process(es). This is not
friendly to multi-process model, for example, it leads to port id
contention issue if two processes both find the data entry is free.

And to get stats of primary vdev in secondary, we must allocate
from the pre-defined array so that we can find it.

Suggested-by: Bruce Richardson <bruce.richardson@intel.com>
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
Reviewed-by: Qi Zhang <qi.z.zhang@intel.com>
drivers/net/af_packet/rte_eth_af_packet.c
drivers/net/cxgbe/cxgbe_main.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/ring/rte_eth_ring.c
drivers/net/tap/rte_eth_tap.c
drivers/net/vhost/rte_eth_vhost.c

index 57eccfd047fc879dab3748304e2aa2131194ea1e..110e8a5cc60e8d6868e775c942298e2cbb305144 100644 (file)
@@ -564,25 +564,17 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
                RTE_LOG(ERR, PMD,
                        "%s: no interface specified for AF_PACKET ethdev\n",
                        name);
-               goto error_early;
+               return -1;
        }
 
        RTE_LOG(INFO, PMD,
                "%s: creating AF_PACKET-backed ethdev on numa socket %u\n",
                name, numa_node);
 
-       /*
-        * now do all data allocation - for eth_dev structure, dummy pci driver
-        * and internal (private) data
-        */
-       data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node);
-       if (data == NULL)
-               goto error_early;
-
        *internals = rte_zmalloc_socket(name, sizeof(**internals),
                                        0, numa_node);
        if (*internals == NULL)
-               goto error_early;
+               return -1;
 
        for (q = 0; q < nb_queues; q++) {
                (*internals)->rx_queue[q].map = MAP_FAILED;
@@ -604,24 +596,24 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
                RTE_LOG(ERR, PMD,
                        "%s: I/F name too long (%s)\n",
                        name, pair->value);
-               goto error_early;
+               return -1;
        }
        if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) {
                RTE_LOG(ERR, PMD,
                        "%s: ioctl failed (SIOCGIFINDEX)\n",
                        name);
-               goto error_early;
+               return -1;
        }
        (*internals)->if_name = strdup(pair->value);
        if ((*internals)->if_name == NULL)
-               goto error_early;
+               return -1;
        (*internals)->if_index = ifr.ifr_ifindex;
 
        if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) == -1) {
                RTE_LOG(ERR, PMD,
                        "%s: ioctl failed (SIOCGIFHWADDR)\n",
                        name);
-               goto error_early;
+               return -1;
        }
        memcpy(&(*internals)->eth_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
 
@@ -775,14 +767,13 @@ rte_pmd_init_internals(struct rte_vdev_device *dev,
 
        (*internals)->nb_queues = nb_queues;
 
-       rte_memcpy(data, (*eth_dev)->data, sizeof(*data));
+       data = (*eth_dev)->data;
        data->dev_private = *internals;
        data->nb_rx_queues = (uint16_t)nb_queues;
        data->nb_tx_queues = (uint16_t)nb_queues;
        data->dev_link = pmd_link;
        data->mac_addrs = &(*internals)->eth_addr;
 
-       (*eth_dev)->data = data;
        (*eth_dev)->dev_ops = &ops;
 
        return 0;
@@ -802,8 +793,6 @@ error:
        }
        free((*internals)->if_name);
        rte_free(*internals);
-error_early:
-       rte_free(data);
        return -1;
 }
 
@@ -985,7 +974,6 @@ rte_pmd_af_packet_remove(struct rte_vdev_device *dev)
        free(internals->if_name);
 
        rte_free(eth_dev->data->dev_private);
-       rte_free(eth_dev->data);
 
        rte_eth_dev_release_port(eth_dev);
 
index c786a1a363fdacd4658f367ad7d261bf81c85679..74bccd514be6cf17606c3b9be53002afef678a53 100644 (file)
@@ -29,7 +29,6 @@
 #include <rte_ether.h>
 #include <rte_ethdev_driver.h>
 #include <rte_ethdev_pci.h>
-#include <rte_malloc.h>
 #include <rte_random.h>
 #include <rte_dev.h>
 #include <rte_kvargs.h>
index c10e970c21e2e6e3548c41f2c99bf57bc0c9e7c2..b7897b65630f67de34a5d72b008697f38e9e70c8 100644 (file)
@@ -336,25 +336,17 @@ eth_kni_create(struct rte_vdev_device *vdev,
        struct pmd_internals *internals;
        struct rte_eth_dev_data *data;
        struct rte_eth_dev *eth_dev;
-       const char *name;
 
        RTE_LOG(INFO, PMD, "Creating kni ethdev on numa socket %u\n",
                        numa_node);
 
-       name = rte_vdev_device_name(vdev);
-       data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node);
-       if (data == NULL)
-               return NULL;
-
        /* reserve an ethdev entry */
        eth_dev = rte_eth_vdev_allocate(vdev, sizeof(*internals));
-       if (eth_dev == NULL) {
-               rte_free(data);
+       if (!eth_dev)
                return NULL;
-       }
 
        internals = eth_dev->data->dev_private;
-       rte_memcpy(data, eth_dev->data, sizeof(*data));
+       data = eth_dev->data;
        data->nb_rx_queues = 1;
        data->nb_tx_queues = 1;
        data->dev_link = pmd_link;
@@ -362,7 +354,6 @@ eth_kni_create(struct rte_vdev_device *vdev,
 
        eth_random_addr(internals->eth_addr.addr_bytes);
 
-       eth_dev->data = data;
        eth_dev->dev_ops = &eth_kni_ops;
 
        internals->no_request_thread = args->no_request_thread;
@@ -458,7 +449,6 @@ eth_kni_remove(struct rte_vdev_device *vdev)
        rte_kni_release(internals->kni);
 
        rte_free(internals);
-       rte_free(eth_dev->data);
 
        rte_eth_dev_release_port(eth_dev);
 
index 74dde9521b7b0cb862a7cf6070c296efb28411af..7d89a3259753b4ca2d40c678c1156f93a2438b95 100644 (file)
@@ -495,7 +495,7 @@ eth_dev_null_create(struct rte_vdev_device *dev,
 {
        const unsigned nb_rx_queues = 1;
        const unsigned nb_tx_queues = 1;
-       struct rte_eth_dev_data *data = NULL;
+       struct rte_eth_dev_data *data;
        struct pmd_internals *internals = NULL;
        struct rte_eth_dev *eth_dev = NULL;
 
@@ -512,19 +512,10 @@ eth_dev_null_create(struct rte_vdev_device *dev,
        RTE_LOG(INFO, PMD, "Creating null ethdev on numa socket %u\n",
                dev->device.numa_node);
 
-       /* now do all data allocation - for eth_dev structure, dummy pci driver
-        * and internal (private) data
-        */
-       data = rte_zmalloc_socket(rte_vdev_device_name(dev), sizeof(*data), 0,
-               dev->device.numa_node);
-       if (!data)
-               return -ENOMEM;
-
        eth_dev = rte_eth_vdev_allocate(dev, sizeof(*internals));
-       if (!eth_dev) {
-               rte_free(data);
+       if (!eth_dev)
                return -ENOMEM;
-       }
+
        /* now put it all together
         * - store queue data in internals,
         * - store numa_node info in ethdev data
@@ -545,13 +536,12 @@ eth_dev_null_create(struct rte_vdev_device *dev,
 
        rte_memcpy(internals->rss_key, default_rss_key, 40);
 
-       rte_memcpy(data, eth_dev->data, sizeof(*data));
+       data = eth_dev->data;
        data->nb_rx_queues = (uint16_t)nb_rx_queues;
        data->nb_tx_queues = (uint16_t)nb_tx_queues;
        data->dev_link = pmd_link;
        data->mac_addrs = &internals->eth_addr;
 
-       eth_dev->data = data;
        eth_dev->dev_ops = &ops;
 
        /* finally assign rx and tx ops */
@@ -669,7 +659,6 @@ rte_pmd_null_remove(struct rte_vdev_device *dev)
                return -1;
 
        rte_free(eth_dev->data->dev_private);
-       rte_free(eth_dev->data);
 
        rte_eth_dev_release_port(eth_dev);
 
index 6d67d257c02d565b07d77ce54bdf9af201695c60..ee06cd355466feb4b76d396780d1684c31a8ec21 100644 (file)
@@ -1068,7 +1068,7 @@ octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
        char octtx_name[OCTEONTX_MAX_NAME_LEN];
        struct octeontx_nic *nic = NULL;
        struct rte_eth_dev *eth_dev = NULL;
-       struct rte_eth_dev_data *data = NULL;
+       struct rte_eth_dev_data *data;
        const char *name = rte_vdev_device_name(dev);
 
        PMD_INIT_FUNC_TRACE();
@@ -1084,13 +1084,6 @@ octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
                return 0;
        }
 
-       data = rte_zmalloc_socket(octtx_name, sizeof(*data), 0, socket_id);
-       if (data == NULL) {
-               octeontx_log_err("failed to allocate devdata");
-               res = -ENOMEM;
-               goto err;
-       }
-
        nic = rte_zmalloc_socket(octtx_name, sizeof(*nic), 0, socket_id);
        if (nic == NULL) {
                octeontx_log_err("failed to allocate nic structure");
@@ -1126,11 +1119,9 @@ octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
        eth_dev->data->kdrv = RTE_KDRV_NONE;
        eth_dev->data->numa_node = dev->device.numa_node;
 
-       rte_memcpy(data, (eth_dev)->data, sizeof(*data));
+       data = eth_dev->data;
        data->dev_private = nic;
-
        data->port_id = eth_dev->data->port_id;
-       snprintf(data->name, sizeof(data->name), "%s", eth_dev->data->name);
 
        nic->ev_queues = 1;
        nic->ev_ports = 1;
@@ -1149,7 +1140,6 @@ octeontx_create(struct rte_vdev_device *dev, int port, uint8_t evdev,
                goto err;
        }
 
-       eth_dev->data = data;
        eth_dev->dev_ops = &octeontx_dev_ops;
 
        /* Finally save ethdev pointer to the NIC structure */
@@ -1217,7 +1207,6 @@ octeontx_remove(struct rte_vdev_device *dev)
 
                rte_free(eth_dev->data->mac_addrs);
                rte_free(eth_dev->data->dev_private);
-               rte_free(eth_dev->data);
                rte_eth_dev_release_port(eth_dev);
                rte_event_dev_close(nic->evdev);
        }
index c1571e1fe9d5915e5aa76fc7c94a297071e16b5c..8740d527f0b60899a19d66a372b82929e454e79e 100644 (file)
@@ -773,27 +773,16 @@ pmd_init_internals(struct rte_vdev_device *vdev,
                struct pmd_internals **internals,
                struct rte_eth_dev **eth_dev)
 {
-       struct rte_eth_dev_data *data = NULL;
+       struct rte_eth_dev_data *data;
        unsigned int numa_node = vdev->device.numa_node;
-       const char *name;
 
-       name = rte_vdev_device_name(vdev);
        RTE_LOG(INFO, PMD, "Creating pcap-backed ethdev on numa socket %d\n",
                numa_node);
 
-       /* now do all data allocation - for eth_dev structure
-        * and internal (private) data
-        */
-       data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node);
-       if (data == NULL)
-               return -1;
-
        /* reserve an ethdev entry */
        *eth_dev = rte_eth_vdev_allocate(vdev, sizeof(**internals));
-       if (*eth_dev == NULL) {
-               rte_free(data);
+       if (!(*eth_dev))
                return -1;
-       }
 
        /* now put it all together
         * - store queue data in internals,
@@ -802,7 +791,7 @@ pmd_init_internals(struct rte_vdev_device *vdev,
         * - and point eth_dev structure to new eth_dev_data structure
         */
        *internals = (*eth_dev)->data->dev_private;
-       rte_memcpy(data, (*eth_dev)->data, sizeof(*data));
+       data = (*eth_dev)->data;
        data->nb_rx_queues = (uint16_t)nb_rx_queues;
        data->nb_tx_queues = (uint16_t)nb_tx_queues;
        data->dev_link = pmd_link;
@@ -812,7 +801,6 @@ pmd_init_internals(struct rte_vdev_device *vdev,
         * NOTE: we'll replace the data element, of originally allocated
         * eth_dev so the rings are local per-process
         */
-       (*eth_dev)->data = data;
        (*eth_dev)->dev_ops = &ops;
 
        return 0;
@@ -1020,7 +1008,6 @@ pmd_pcap_remove(struct rte_vdev_device *dev)
                return -1;
 
        rte_free(eth_dev->data->dev_private);
-       rte_free(eth_dev->data);
 
        rte_eth_dev_release_port(eth_dev);
 
index df13c44be41e2dd12dd39eee689fda9ae344bd3e..e53823adb3e53b6e287c74a932ad0e93c02942c3 100644 (file)
@@ -259,15 +259,6 @@ do_eth_dev_ring_create(const char *name,
        RTE_LOG(INFO, PMD, "Creating rings-backed ethdev on numa socket %u\n",
                        numa_node);
 
-       /* now do all data allocation - for eth_dev structure, dummy pci driver
-        * and internal (private) data
-        */
-       data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node);
-       if (data == NULL) {
-               rte_errno = ENOMEM;
-               goto error;
-       }
-
        rx_queues_local = rte_zmalloc_socket(name,
                        sizeof(void *) * nb_rx_queues, 0, numa_node);
        if (rx_queues_local == NULL) {
@@ -301,10 +292,8 @@ do_eth_dev_ring_create(const char *name,
         * - point eth_dev_data to internals
         * - and point eth_dev structure to new eth_dev_data structure
         */
-       /* NOTE: we'll replace the data element, of originally allocated eth_dev
-        * so the rings are local per-process */
 
-       rte_memcpy(data, eth_dev->data, sizeof(*data));
+       data = eth_dev->data;
        data->rx_queues = rx_queues_local;
        data->tx_queues = tx_queues_local;
 
@@ -326,7 +315,6 @@ do_eth_dev_ring_create(const char *name,
        data->dev_link = pmd_link;
        data->mac_addrs = &internals->address;
 
-       eth_dev->data = data;
        eth_dev->dev_ops = &ops;
        data->kdrv = RTE_KDRV_NONE;
        data->numa_node = numa_node;
@@ -342,7 +330,6 @@ do_eth_dev_ring_create(const char *name,
 error:
        rte_free(rx_queues_local);
        rte_free(tx_queues_local);
-       rte_free(data);
        rte_free(internals);
 
        return -1;
@@ -675,8 +662,6 @@ rte_pmd_ring_remove(struct rte_vdev_device *dev)
        rte_free(eth_dev->data->tx_queues);
        rte_free(eth_dev->data->dev_private);
 
-       rte_free(eth_dev->data);
-
        rte_eth_dev_release_port(eth_dev);
        return 0;
 }
index 915d9373f8c4bd675aa5a1a59343c6d90bad63a1..b18efd8b70e7ce3858c0d092fa78592e7a1a8638 100644 (file)
@@ -1386,12 +1386,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
        RTE_LOG(DEBUG, PMD, "%s device on numa %u\n",
                        tuntap_name, rte_socket_id());
 
-       data = rte_zmalloc_socket(tap_name, sizeof(*data), 0, numa_node);
-       if (!data) {
-               RTE_LOG(ERR, PMD, "%s Failed to allocate data\n", tuntap_name);
-               goto error_exit_nodev;
-       }
-
        dev = rte_eth_vdev_allocate(vdev, sizeof(*pmd));
        if (!dev) {
                RTE_LOG(ERR, PMD, "%s Unable to allocate device struct\n",
@@ -1412,7 +1406,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
        }
 
        /* Setup some default values */
-       rte_memcpy(data, dev->data, sizeof(*data));
+       data = dev->data;
        data->dev_private = pmd;
        data->dev_flags = RTE_ETH_DEV_INTR_LSC;
        data->numa_node = numa_node;
@@ -1423,7 +1417,6 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
        data->nb_rx_queues = 0;
        data->nb_tx_queues = 0;
 
-       dev->data = data;
        dev->dev_ops = &ops;
        dev->rx_pkt_burst = pmd_rx_burst;
        dev->tx_pkt_burst = pmd_tx_burst;
@@ -1574,7 +1567,6 @@ error_exit_nodev:
        RTE_LOG(ERR, PMD, "%s Unable to initialize %s\n",
                tuntap_name, rte_vdev_device_name(vdev));
 
-       rte_free(data);
        return -EINVAL;
 }
 
@@ -1828,7 +1820,6 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
 
        close(internals->ioctl_sock);
        rte_free(eth_dev->data->dev_private);
-       rte_free(eth_dev->data);
 
        rte_eth_dev_release_port(eth_dev);
 
index d7d44a0eb3b61c73b1fabb0f1681c3b0e7cf05ea..fea13eb55421ec81151c2ac3a5f650d460fd27ba 100644 (file)
@@ -1227,7 +1227,7 @@ eth_dev_vhost_create(struct rte_vdev_device *dev, char *iface_name,
        int16_t queues, const unsigned int numa_node, uint64_t flags)
 {
        const char *name = rte_vdev_device_name(dev);
-       struct rte_eth_dev_data *data = NULL;
+       struct rte_eth_dev_data *data;
        struct pmd_internal *internal = NULL;
        struct rte_eth_dev *eth_dev = NULL;
        struct ether_addr *eth_addr = NULL;
@@ -1237,13 +1237,6 @@ eth_dev_vhost_create(struct rte_vdev_device *dev, char *iface_name,
        RTE_LOG(INFO, PMD, "Creating VHOST-USER backend on numa socket %u\n",
                numa_node);
 
-       /* now do all data allocation - for eth_dev structure and internal
-        * (private) data
-        */
-       data = rte_zmalloc_socket(name, sizeof(*data), 0, numa_node);
-       if (data == NULL)
-               goto error;
-
        list = rte_zmalloc_socket(name, sizeof(*list), 0, numa_node);
        if (list == NULL)
                goto error;
@@ -1285,12 +1278,7 @@ eth_dev_vhost_create(struct rte_vdev_device *dev, char *iface_name,
        rte_spinlock_init(&vring_state->lock);
        vring_states[eth_dev->data->port_id] = vring_state;
 
-       /* We'll replace the 'data' originally allocated by eth_dev. So the
-        * vhost PMD resources won't be shared between multi processes.
-        */
-       rte_memcpy(data, eth_dev->data, sizeof(*data));
-       eth_dev->data = data;
-
+       data = eth_dev->data;
        data->nb_rx_queues = queues;
        data->nb_tx_queues = queues;
        internal->max_queues = queues;
@@ -1331,7 +1319,6 @@ error:
                rte_eth_dev_release_port(eth_dev);
        rte_free(internal);
        rte_free(list);
-       rte_free(data);
 
        return -1;
 }
@@ -1462,8 +1449,6 @@ rte_pmd_vhost_remove(struct rte_vdev_device *dev)
        rte_free(vring_states[eth_dev->data->port_id]);
        vring_states[eth_dev->data->port_id] = NULL;
 
-       rte_free(eth_dev->data);
-
        rte_eth_dev_release_port(eth_dev);
 
        return 0;