[dpdk-dev] [PATCH v8 06/19] ethdev: support attach private device as first
Qi Zhang
qi.z.zhang at intel.com
Mon Jul 2 07:44:37 CEST 2018
When attach a private device from secondary as the first one, we need
to make sure rte_eth_dev_shared_data is initialized, the patch add
necessary IPC for secondary to inform primary to do initialization.
Signed-off-by: Qi Zhang <qi.z.zhang at intel.com>
---
lib/librte_ethdev/ethdev_mp.c | 2 ++
lib/librte_ethdev/ethdev_mp.h | 1 +
lib/librte_ethdev/ethdev_private.h | 3 +++
lib/librte_ethdev/rte_ethdev.c | 31 ++++++++++++++++++++-----------
4 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/lib/librte_ethdev/ethdev_mp.c b/lib/librte_ethdev/ethdev_mp.c
index 8d13da591..28f89dba9 100644
--- a/lib/librte_ethdev/ethdev_mp.c
+++ b/lib/librte_ethdev/ethdev_mp.c
@@ -189,6 +189,8 @@ __handle_secondary_request(void *param)
} else {
ret = tmp_req.result;
}
+ } else if (req->t == REQ_TYPE_SHARE_DATA_PREPARE) {
+ eth_dev_shared_data_prepare();
} else {
ethdev_log(ERR, "unsupported secondary to primary request\n");
ret = -ENOTSUP;
diff --git a/lib/librte_ethdev/ethdev_mp.h b/lib/librte_ethdev/ethdev_mp.h
index 40be46c89..61fc381da 100644
--- a/lib/librte_ethdev/ethdev_mp.h
+++ b/lib/librte_ethdev/ethdev_mp.h
@@ -15,6 +15,7 @@ enum eth_dev_req_type {
REQ_TYPE_PRE_DETACH,
REQ_TYPE_DETACH,
REQ_TYPE_ATTACH_ROLLBACK,
+ REQ_TYPE_SHARE_DATA_PREPARE,
};
struct eth_dev_mp_req {
diff --git a/lib/librte_ethdev/ethdev_private.h b/lib/librte_ethdev/ethdev_private.h
index 981e7de8a..005d63afc 100644
--- a/lib/librte_ethdev/ethdev_private.h
+++ b/lib/librte_ethdev/ethdev_private.h
@@ -36,4 +36,7 @@ int do_eth_dev_attach(const char *devargs, uint16_t *port_id);
*/
int do_eth_dev_detach(uint16_t port_id);
+/* Prepare shared data for multi-process */
+void eth_dev_shared_data_prepare(void);
+
#endif
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 7d89d9f95..408a49f44 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -199,11 +199,14 @@ rte_eth_find_next(uint16_t port_id)
return port_id;
}
-static void
-rte_eth_dev_shared_data_prepare(void)
+void
+eth_dev_shared_data_prepare(void)
{
const unsigned flags = 0;
const struct rte_memzone *mz;
+ struct eth_dev_mp_req req;
+
+ memset(&req, 0, sizeof(req));
rte_spinlock_lock(&rte_eth_shared_data_lock);
@@ -215,6 +218,12 @@ rte_eth_dev_shared_data_prepare(void)
rte_socket_id(), flags);
} else
mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
+ /* if secondary attach a private device first */
+ if (mz == NULL && rte_eal_process_type() != RTE_PROC_PRIMARY) {
+ req.t = REQ_TYPE_SHARE_DATA_PREPARE;
+ eth_dev_request_to_primary(&req);
+ mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA);
+ }
if (mz == NULL)
rte_panic("Cannot allocate ethdev shared data\n");
@@ -255,7 +264,7 @@ rte_eth_dev_allocated(const char *name)
{
struct rte_eth_dev *ethdev;
- rte_eth_dev_shared_data_prepare();
+ eth_dev_shared_data_prepare();
rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
@@ -300,7 +309,7 @@ rte_eth_dev_allocate(const char *name)
uint16_t port_id;
struct rte_eth_dev *eth_dev = NULL;
- rte_eth_dev_shared_data_prepare();
+ eth_dev_shared_data_prepare();
/* Synchronize port creation between primary and secondary threads. */
rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
@@ -339,7 +348,7 @@ rte_eth_dev_attach_secondary(const char *name)
uint16_t i;
struct rte_eth_dev *eth_dev = NULL;
- rte_eth_dev_shared_data_prepare();
+ eth_dev_shared_data_prepare();
/* Synchronize port attachment to primary port creation and release. */
rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
@@ -379,7 +388,7 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
if (eth_dev == NULL)
return -EINVAL;
- rte_eth_dev_shared_data_prepare();
+ eth_dev_shared_data_prepare();
_rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_DESTROY, NULL);
@@ -433,7 +442,7 @@ rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
int __rte_experimental
rte_eth_dev_owner_new(uint64_t *owner_id)
{
- rte_eth_dev_shared_data_prepare();
+ eth_dev_shared_data_prepare();
rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
@@ -488,7 +497,7 @@ rte_eth_dev_owner_set(const uint16_t port_id,
{
int ret;
- rte_eth_dev_shared_data_prepare();
+ eth_dev_shared_data_prepare();
rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
@@ -505,7 +514,7 @@ rte_eth_dev_owner_unset(const uint16_t port_id, const uint64_t owner_id)
{.id = RTE_ETH_DEV_NO_OWNER, .name = ""};
int ret;
- rte_eth_dev_shared_data_prepare();
+ eth_dev_shared_data_prepare();
rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
@@ -520,7 +529,7 @@ rte_eth_dev_owner_delete(const uint64_t owner_id)
{
uint16_t port_id;
- rte_eth_dev_shared_data_prepare();
+ eth_dev_shared_data_prepare();
rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
@@ -542,7 +551,7 @@ rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
int ret = 0;
struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];
- rte_eth_dev_shared_data_prepare();
+ eth_dev_shared_data_prepare();
rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
--
2.13.6
More information about the dev
mailing list