MCPcopy Create free account
hub / github.com/F-Stack/f-stack / new_device

Function new_device

dpdk/examples/vhost/main.c:1703–1777  ·  view source on GitHub ↗

* A new device is added to a data core. First the device is added to the main linked list * and then allocated to a specific data core. */

Source from the content-addressed store, hash-verified

1701 * and then allocated to a specific data core.
1702 */
1703static int
1704new_device(int vid)
1705{
1706 int lcore, core_add = 0;
1707 uint16_t i;
1708 uint32_t device_num_min = num_devices;
1709 struct vhost_dev *vdev;
1710 int ret;
1711
1712 vdev = rte_zmalloc("vhost device", sizeof(*vdev), RTE_CACHE_LINE_SIZE);
1713 if (vdev == NULL) {
1714 RTE_LOG(INFO, VHOST_DATA,
1715 "(%d) couldn't allocate memory for vhost dev\n",
1716 vid);
1717 return -1;
1718 }
1719 vdev->vid = vid;
1720
1721 for (i = 0; i < RTE_MAX_LCORE; i++) {
1722 vhost_txbuff[i * RTE_MAX_VHOST_DEVICE + vid]
1723 = rte_zmalloc("vhost bufftable",
1724 sizeof(struct vhost_bufftable),
1725 RTE_CACHE_LINE_SIZE);
1726
1727 if (vhost_txbuff[i * RTE_MAX_VHOST_DEVICE + vid] == NULL) {
1728 RTE_LOG(INFO, VHOST_DATA,
1729 "(%d) couldn't allocate memory for vhost TX\n", vid);
1730 return -1;
1731 }
1732 }
1733
1734 int socketid = get_socketid_by_vid(vid);
1735 if (socketid == -1)
1736 return -1;
1737
1738 init_vid2socketid_array(vid, socketid);
1739
1740 ret = vhost_async_channel_register(vid);
1741
1742 if (init_vhost_queue_ops(vid) != 0)
1743 return -1;
1744
1745 if (builtin_net_driver)
1746 vs_vhost_net_setup(vdev);
1747
1748 TAILQ_INSERT_TAIL(&vhost_dev_list, vdev, global_vdev_entry);
1749 vdev->vmdq_rx_q = vid * queues_per_pool + vmdq_queue_base;
1750
1751 /*reset ready flag*/
1752 vdev->ready = DEVICE_MAC_LEARNING;
1753 vdev->remove = 0;
1754
1755 /* Find a suitable lcore to add the device. */
1756 RTE_LCORE_FOREACH_WORKER(lcore) {
1757 if (lcore_info[lcore].device_num < device_num_min) {
1758 device_num_min = lcore_info[lcore].device_num;
1759 core_add = lcore;
1760 }

Callers

nothing calls this directly

Calls 7

rte_zmallocFunction · 0.85
get_socketid_by_vidFunction · 0.85
init_vid2socketid_arrayFunction · 0.85
init_vhost_queue_opsFunction · 0.85
vs_vhost_net_setupFunction · 0.85

Tested by

no test coverage detected