From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BN3-obe.outbound.protection.outlook.com (mail-bn3nam01on0079.outbound.protection.outlook.com [104.47.33.79]) by dpdk.org (Postfix) with ESMTP id 46B442BC5 for ; Tue, 6 Dec 2016 04:52:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=vCyOI/hJvAoalZr+LGOwzBzpTejKF7GCpEVDekLLhHw=; b=nx3Yq1+HV2Z1jtoCf6JkPHx66KMXmpdyQQjqSE8UJh8/ZyBOLyLFr/C52I9B5HhBJMZ3CEPpjaPUBh1wmBlGoCQ32ywf43CQbQZUjadunXEgkLSgD2iRTudotDeyah93jURQrT6Xqpen5TOgyEPgXlCW2QUnAvooryXnR74Hc8A= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jerin.Jacob@cavium.com; Received: from localhost.caveonetworks.com (50.233.148.156) by BY1PR0701MB1723.namprd07.prod.outlook.com (10.162.111.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.693.12; Tue, 6 Dec 2016 03:52:48 +0000 From: Jerin Jacob To: CC: , , , , , Jerin Jacob Date: Tue, 6 Dec 2016 09:22:18 +0530 Message-ID: <1480996340-29871-5-git-send-email-jerin.jacob@caviumnetworks.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1480996340-29871-1-git-send-email-jerin.jacob@caviumnetworks.com> References: <1479447902-3700-2-git-send-email-jerin.jacob@caviumnetworks.com> <1480996340-29871-1-git-send-email-jerin.jacob@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: BLUPR13CA0014.namprd13.prod.outlook.com (10.160.191.24) To BY1PR0701MB1723.namprd07.prod.outlook.com (10.162.111.142) X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1723; 2:CvQmlaKGK0XDUAMGyvqnovmqoEqQ6jy7bmma8jtC1+LmemiVepRvm30fhKFWRAP/tpKLZhXkhSPUCR7mHdrUI4DaEpze5VioQgoGV1zJnAWluQOx81/gwETYwxG/GWJ7YMSoQfrllWj9tQMSvnW3mT4AmI9npAI3+qjlofB394s=; 3:2nVh5dlxILoG9r73BctpGPlsJlzO8xpWk3S0lYqJt9dtBgIiYtv6YKNu7iZJJoBfp/XCYd4VcacTimfSUnHacB/X0kWKflt/pO0sOe6oLy2H81PJCGDfSkmXfeBJckBcsspHMKirrIRdSks4ceCbW1wb5ue+tYnjjCvtaPlcz9s=; 25:nN2OP/tN/c2hJ4R3iq2T6YglBfOjJKRkf5XEAoJlBZS8KUyF/ukn6anqgKpQMizfnHgsoHFtuoyAcTqKIukv2LXrNjTdzBO/l9eKn5g3d5U8TWgLXz/tLw75znIoZBEMdqzuCIiJfNQlNLjcEu/D/zmMg7N1C2vTq91qdub3lfgnez+CoZGHcjkFm9rjCcLqopA6XuuQHdVjuQ8J4zmIkr2ug3t94GpoCFxS/Hn1lmKrhGC8MsIKtPS7kyQFRwFWP6x1pyNQ9oAfJwalVq1TH+vPZhRJRxw9kD4I228RaNhipOkB4mGua6x9k2scQlXKxODfOoAKxfcN44Zf4tXmb1AC4CF3Whqm9ibaJkJX6HX5cMn5xmPyu0i+lYmD2VGKMT9YeQTf72VOQqWUffADXIgIlszVKhjicLqxsFER/wZlKCTZMyr5yZ1yIVj1SjSYXItXxF+n8mKI1tYdA/FITw== X-MS-Office365-Filtering-Correlation-Id: b4447922-7db9-49d3-db96-08d41d8b58d7 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BY1PR0701MB1723; X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1723; 31:nQS/iAo+ZHJq3Ksrku1URVTdxGb4neDOhpMGi4MB52jLFwMKNC+q/21QHmtRwYje6aCQRJs42r3pDUAolrylAKYLObzHQGYrRz8OlAZ1aLyXXM/DJLsIceB04/jv7jCN9Z6p+LLpayhmBXU+J/tEmXaPxaLY533cbGwlB3Cbx76pKE1BHtxvcANOnYBXMhHK00xVvoDCefrtdMisjfZZ67KWIDMxJMdi/uTmrFZ+CbTCyx+UyIwQMDcE1z+UW7ZL; 20:gYtewu55291MFLKnSgaJCdpUkThTss7zNMQeOQDLrRr1QmtUa90/pPQIKXOt3Bzp20eVvrSknKC1yg52Pw34ILuIiWtLqVqLhEwSfbEzDYUYUWnSOvZe1XyulllxDxDQ4oqq1gjj9VMSj3GAxjEFWv1hSx5sNoNf393cPH9oMsdOQgOew6JknKoFmasfj+JZYMACtTiWd2cDRLCCxZNMD7FaGHIWIF4J0C+ouXMpukFaBgCmyQrX/kHk7mHPXZ0tmMr5kqXKWFe1tdcbOSfDgYZiW9t6ZSUTNxAo8xrlXIAi5Y39RzzHXPzd0FM4rNPfBfiMcCq/BdojiEwwjB+FdYR/Ar+KSxp13y5NWBucvs8gh4KJaTYnFdorCc814boHNz+7QEh6JALi//LF6UudYvM31hUyp0fXl2U7xT3l6lRDPMjk2NMIuJ0v9K4DEwYTk8BAOsjhEXoeWwuoOgrbWElJFRqjXo3TLKDgp83Eh7JAb3Y0vRVIIt/yXv5GB8OKKV3aZGisHAM0lX4IHC7fO6a3jrikTDwyKttyQDeN9NLZXQTTo38Etyb/D/BIoPN9qtSUoq60QSpZox12kQdZPYXFus63O7no+bAzVs78Hco= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041248)(20161123555025)(20161123564025)(20161123562025)(20161123560025)(6072148); SRVR:BY1PR0701MB1723; BCL:0; PCL:0; RULEID:; SRVR:BY1PR0701MB1723; X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1723; 4:1PC/c+6Uzm5OVd93lprrzYUHPuUCaAxwsb1mrRByTiuTDAgR1GqWA76G3omPIFR2RlOhncI4QeKrpLOwWznNkpazwTS8Zi7FRG4fRa3sFWhyUncWloyXNMCE3+EZFeZxbSDAy7navUm2DO7uWB9a7B8BhYBb94/pbyr/tQNPZNsNrK76xvqWeaKjlTJ9FmCooLQuIDI0xWT5aKxktMIpHo2IukuZLhNhlt7IkTs2/yFBVU6xFzdae9YIpSynwz3sq9Acrv8uimda4oVObfEMulNiog0wYu96l/um5OvtfTplk1MOrjFtoafrpLtiDZB5FJbIcUZVL7qxuKsAzdA2qYqytMeRIbnzJgWMD21XC977Tbvv/0K5HuVeLhnaBO483lmE78Y+TDlGLvTJSufhzGCtETNHUqz63UCpAwFcw9Hikebv4WTv5Mn4hbrj6h/f2Gy8jo0Hn7L+hFJ5y4TfEuX8478bgGEvZmyM4U7loh7HmvkB1iUhdR6GiyoC70jbdCK22WDBaLGss4CbZ6Acu8xwbWNeXm8TnefeNknp54vuLoNpDp/KM5ZNAGjlVms9s/ySwBpk9ip/utu6/3THrQ== X-Forefront-PRVS: 01480965DA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6069001)(6009001)(7916002)(199003)(189002)(101416001)(110136003)(6916009)(69596002)(4326007)(8666005)(106356001)(76176999)(2351001)(47776003)(97736004)(2906002)(107886002)(7846002)(5660300001)(92566002)(305945005)(48376002)(733004)(42882006)(68736007)(50986999)(39850400001)(50466002)(6666003)(36756003)(2950100002)(5890100001)(81156014)(105586002)(42186005)(3846002)(33646002)(81166006)(8676002)(5003940100001)(6512006)(6506006)(6486002)(53416004)(7736002)(189998001)(38730400001)(4001430100002)(6116002)(50226002)(39840400001)(39450400002)(39410400001)(66066001)(76506005)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BY1PR0701MB1723; H:localhost.caveonetworks.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-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XcMa5AVdR8Jd47Jzg+0i6JESKDkezRlQ1yplI2JM4N6vHYoIRg7dXK56dzLhS1IZ/hd1NC1E=; 5:bQQwAWuygMUFzLismHGsmoZpFZ0zVCL61kAj7UrzFKmWwISH2xZYMpQMoJevtKl6skXGRIed5rf6+5e3UHzCQEItqJ+MtJPk4WpT1l5nU4IMbl71nc3Nr5eWpcWNATJlliYJz0kpcIaMf3Z0lLrWTQ==; 24:eXI/BTezbwjm6rgMrm2upTQXXjw52VjfKiZMU4gS0Wz+kvrojBux5l+fdKlwuwQ5oW9qX5fFswtZ5CCXpOMSPuBI8yfwKmnGZ1Y8IDDaKgc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY1PR0701MB1723; 7:INtrlNz3eLWLunX4qNQ2KSuwZvfV0SXVvV86QruzOqMMS1LwJDJM5dJKo0oY6gIAYNqaUPALt5iPgENsoIegdZMk7bKGNM9E0T1IscFihXPPFqth5nmT4D84Ux1dAaZdMfsBViMKXUX9Spj4b3gmyAdJb4Kd9FeKL17vNF9FfdcVSTynp2xhMYNb/w5XjjRtj1tufmESk69P4nCLJl2Mz5H+eMzPKEGeDmWcIIGhCXpcW3FupOHcYEiR2ADLOrKkIUUnxlqAtqeu7Sm/6+/mHxDu9tym7OOG96iAyTtf4Nz4rdbdGz9LEj9ccNqHpCLJl1f0EVnJ44Bj0sCu1UZy4Y2gc3jtafyrHqID8AqApRI= X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Dec 2016 03:52:48.2162 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1723 Subject: [dpdk-dev] [PATCH v2 4/6] eventdev: implement PMD registration functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Dec 2016 03:52:53 -0000 This patch adds infrastructure for registering the vdev or the PCI based event device. Signed-off-by: Jerin Jacob --- lib/librte_eventdev/rte_eventdev.c | 236 +++++++++++++++++++++++++++ lib/librte_eventdev/rte_eventdev_pmd.h | 111 +++++++++++++ lib/librte_eventdev/rte_eventdev_version.map | 6 + 3 files changed, 353 insertions(+) diff --git a/lib/librte_eventdev/rte_eventdev.c b/lib/librte_eventdev/rte_eventdev.c index 0a1d2d6..084c21c 100644 --- a/lib/librte_eventdev/rte_eventdev.c +++ b/lib/librte_eventdev/rte_eventdev.c @@ -124,6 +124,8 @@ rte_event_dev_info_get(uint8_t dev_id, struct rte_event_dev_info *dev_info) (*dev->dev_ops->dev_infos_get)(dev, dev_info); dev_info->pci_dev = dev->pci_dev; + if (dev->driver) + dev_info->driver_name = dev->driver->pci_drv.driver.name; return 0; } @@ -999,3 +1001,237 @@ rte_event_dev_close(uint8_t dev_id) return (*dev->dev_ops->dev_close)(dev); } + +static inline int +rte_eventdev_data_alloc(uint8_t dev_id, struct rte_eventdev_data **data, + int socket_id) +{ + char mz_name[RTE_EVENTDEV_NAME_MAX_LEN]; + const struct rte_memzone *mz; + int n; + + /* Generate memzone name */ + n = snprintf(mz_name, sizeof(mz_name), "rte_eventdev_data_%u", dev_id); + if (n >= (int)sizeof(mz_name)) + return -EINVAL; + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + mz = rte_memzone_reserve(mz_name, + sizeof(struct rte_eventdev_data), + socket_id, 0); + } else + mz = rte_memzone_lookup(mz_name); + + if (mz == NULL) + return -ENOMEM; + + *data = mz->addr; + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + memset(*data, 0, sizeof(struct rte_eventdev_data)); + + return 0; +} + +static inline uint8_t +rte_eventdev_find_free_device_index(void) +{ + uint8_t dev_id; + + for (dev_id = 0; dev_id < RTE_EVENT_MAX_DEVS; dev_id++) { + if (rte_eventdevs[dev_id].attached == + RTE_EVENTDEV_DETACHED) + return dev_id; + } + return RTE_EVENT_MAX_DEVS; +} + +struct rte_eventdev * +rte_event_pmd_allocate(const char *name, int socket_id) +{ + struct rte_eventdev *eventdev; + uint8_t dev_id; + + if (rte_event_pmd_get_named_dev(name) != NULL) { + RTE_EDEV_LOG_ERR("Event device with name %s already " + "allocated!", name); + return NULL; + } + + dev_id = rte_eventdev_find_free_device_index(); + if (dev_id == RTE_EVENT_MAX_DEVS) { + RTE_EDEV_LOG_ERR("Reached maximum number of event devices"); + return NULL; + } + + eventdev = &rte_eventdevs[dev_id]; + + if (eventdev->data == NULL) { + struct rte_eventdev_data *eventdev_data = NULL; + + int retval = rte_eventdev_data_alloc(dev_id, &eventdev_data, + socket_id); + + if (retval < 0 || eventdev_data == NULL) + return NULL; + + eventdev->data = eventdev_data; + + snprintf(eventdev->data->name, RTE_EVENTDEV_NAME_MAX_LEN, + "%s", name); + + eventdev->data->dev_id = dev_id; + eventdev->data->socket_id = socket_id; + eventdev->data->dev_started = 0; + + eventdev->attached = RTE_EVENTDEV_ATTACHED; + + eventdev_globals.nb_devs++; + } + + return eventdev; +} + +int +rte_event_pmd_release(struct rte_eventdev *eventdev) +{ + int ret; + + if (eventdev == NULL) + return -EINVAL; + + ret = rte_event_dev_close(eventdev->data->dev_id); + if (ret < 0) + return ret; + + eventdev->attached = RTE_EVENTDEV_DETACHED; + eventdev_globals.nb_devs--; + eventdev->data = NULL; + + return 0; +} + +struct rte_eventdev * +rte_event_pmd_vdev_init(const char *name, size_t dev_private_size, + int socket_id) +{ + struct rte_eventdev *eventdev; + + /* Allocate device structure */ + eventdev = rte_event_pmd_allocate(name, socket_id); + if (eventdev == NULL) + return NULL; + + /* Allocate private device structure */ + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + eventdev->data->dev_private = + rte_zmalloc_socket("eventdev device private", + dev_private_size, + RTE_CACHE_LINE_SIZE, + socket_id); + + if (eventdev->data->dev_private == NULL) + rte_panic("Cannot allocate memzone for private device" + " data"); + } + + return eventdev; +} + +int +rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv, + struct rte_pci_device *pci_dev) +{ + struct rte_eventdev_driver *eventdrv; + struct rte_eventdev *eventdev; + + char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN]; + + int retval; + + eventdrv = (struct rte_eventdev_driver *)pci_drv; + if (eventdrv == NULL) + return -ENODEV; + + rte_eal_pci_device_name(&pci_dev->addr, eventdev_name, + sizeof(eventdev_name)); + + eventdev = rte_event_pmd_allocate(eventdev_name, + pci_dev->device.numa_node); + if (eventdev == NULL) + return -ENOMEM; + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + eventdev->data->dev_private = + rte_zmalloc_socket( + "eventdev private structure", + eventdrv->dev_private_size, + RTE_CACHE_LINE_SIZE, + rte_socket_id()); + + if (eventdev->data->dev_private == NULL) + rte_panic("Cannot allocate memzone for private " + "device data"); + } + + eventdev->pci_dev = pci_dev; + eventdev->driver = eventdrv; + + /* Invoke PMD device initialization function */ + retval = (*eventdrv->eventdev_init)(eventdev); + if (retval == 0) + return 0; + + RTE_EDEV_LOG_ERR("driver %s: (vendor_id=0x%x device_id=0x%x)" + " failed", pci_drv->driver.name, + (unsigned int) pci_dev->id.vendor_id, + (unsigned int) pci_dev->id.device_id); + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + rte_free(eventdev->data->dev_private); + + eventdev->attached = RTE_EVENTDEV_DETACHED; + eventdev_globals.nb_devs--; + + return -ENXIO; +} + +int +rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev) +{ + const struct rte_eventdev_driver *eventdrv; + struct rte_eventdev *eventdev; + char eventdev_name[RTE_EVENTDEV_NAME_MAX_LEN]; + int ret; + + if (pci_dev == NULL) + return -EINVAL; + + rte_eal_pci_device_name(&pci_dev->addr, eventdev_name, + sizeof(eventdev_name)); + + eventdev = rte_event_pmd_get_named_dev(eventdev_name); + if (eventdev == NULL) + return -ENODEV; + + eventdrv = (const struct rte_eventdev_driver *)pci_dev->driver; + if (eventdrv == NULL) + return -ENODEV; + + /* Invoke PMD device un-init function */ + if (*eventdrv->eventdev_uninit) { + ret = (*eventdrv->eventdev_uninit)(eventdev); + if (ret) + return ret; + } + + /* Free event device */ + rte_event_pmd_release(eventdev); + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) + rte_free(eventdev->data->dev_private); + + eventdev->pci_dev = NULL; + eventdev->driver = NULL; + + return 0; +} diff --git a/lib/librte_eventdev/rte_eventdev_pmd.h b/lib/librte_eventdev/rte_eventdev_pmd.h index 7d94031..29959ae 100644 --- a/lib/librte_eventdev/rte_eventdev_pmd.h +++ b/lib/librte_eventdev/rte_eventdev_pmd.h @@ -92,6 +92,60 @@ extern "C" { #define RTE_EVENTDEV_DETACHED (0) #define RTE_EVENTDEV_ATTACHED (1) +/** + * Initialisation function of a event driver invoked for each matching + * event PCI device detected during the PCI probing phase. + * + * @param dev + * The dev pointer is the address of the *rte_eventdev* structure associated + * with the matching device and which has been [automatically] allocated in + * the *rte_event_devices* array. + * + * @return + * - 0: Success, the device is properly initialised by the driver. + * In particular, the driver MUST have set up the *dev_ops* pointer + * of the *dev* structure. + * - <0: Error code of the device initialisation failure. + */ +typedef int (*eventdev_init_t)(struct rte_eventdev *dev); + +/** + * Finalisation function of a driver invoked for each matching + * PCI device detected during the PCI closing phase. + * + * @param dev + * The dev pointer is the address of the *rte_eventdev* structure associated + * with the matching device and which has been [automatically] allocated in + * the *rte_event_devices* array. + * + * @return + * - 0: Success, the device is properly finalised by the driver. + * In particular, the driver MUST free the *dev_ops* pointer + * of the *dev* structure. + * - <0: Error code of the device initialisation failure. + */ +typedef int (*eventdev_uninit_t)(struct rte_eventdev *dev); + +/** + * The structure associated with a PMD driver. + * + * Each driver acts as a PCI driver and is represented by a generic + * *event_driver* structure that holds: + * + * - An *rte_pci_driver* structure (which must be the first field). + * + * - The *eventdev_init* function invoked for each matching PCI device. + * + * - The size of the private data to allocate for each matching device. + */ +struct rte_eventdev_driver { + struct rte_pci_driver pci_drv; /**< The PMD is also a PCI driver. */ + unsigned int dev_private_size; /**< Size of device private data. */ + + eventdev_init_t eventdev_init; /**< Device init function. */ + eventdev_uninit_t eventdev_uninit; /**< Device uninit function. */ +}; + /** Global structure used for maintaining state of allocated event devices */ struct rte_eventdev_global { uint8_t nb_devs; /**< Number of devices found */ @@ -388,6 +442,63 @@ struct rte_eventdev_ops { /* Dump internal information */ }; +/** + * Allocates a new eventdev slot for an event device and returns the pointer + * to that slot for the driver to use. + * + * @param name + * Unique identifier name for each device + * @param socket_id + * Socket to allocate resources on. + * @return + * - Slot in the rte_dev_devices array for a new device; + */ +struct rte_eventdev * +rte_event_pmd_allocate(const char *name, int socket_id); + +/** + * Release the specified eventdev device. + * + * @param eventdev + * The *eventdev* pointer is the address of the *rte_eventdev* structure. + * @return + * - 0 on success, negative on error + */ +int +rte_event_pmd_release(struct rte_eventdev *eventdev); + +/** + * Creates a new virtual event device and returns the pointer to that device. + * + * @param name + * PMD type name + * @param dev_private_size + * Size of event PMDs private data + * @param socket_id + * Socket to allocate resources on. + * + * @return + * - Eventdev pointer if device is successfully created. + * - NULL if device cannot be created. + */ +struct rte_eventdev * +rte_event_pmd_vdev_init(const char *name, size_t dev_private_size, + int socket_id); + + +/** + * Wrapper for use by pci drivers as a .probe function to attach to a event + * interface. + */ +int rte_event_pmd_pci_probe(struct rte_pci_driver *pci_drv, + struct rte_pci_device *pci_dev); + +/** + * Wrapper for use by pci drivers as a .remove function to detach a event + * interface. + */ +int rte_event_pmd_pci_remove(struct rte_pci_device *pci_dev); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eventdev/rte_eventdev_version.map b/lib/librte_eventdev/rte_eventdev_version.map index 3cae03d..68b8c81 100644 --- a/lib/librte_eventdev/rte_eventdev_version.map +++ b/lib/librte_eventdev/rte_eventdev_version.map @@ -29,5 +29,11 @@ DPDK_17.02 { rte_event_dequeue_timeout_ticks; + rte_event_pmd_allocate; + rte_event_pmd_release; + rte_event_pmd_vdev_init; + rte_event_pmd_pci_probe; + rte_event_pmd_pci_remove; + local: *; }; -- 2.5.5