From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id DBB0F1B1F7 for ; Thu, 28 Jun 2018 03:52:27 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jun 2018 18:52:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,281,1526367600"; d="scan'208";a="52818154" Received: from dpdk51.sh.intel.com ([10.67.110.190]) by orsmga008.jf.intel.com with ESMTP; 27 Jun 2018 18:52:25 -0700 From: Qi Zhang To: thomas@monjalon.net, anatoly.burakov@intel.com Cc: konstantin.ananyev@intel.com, dev@dpdk.org, bruce.richardson@intel.com, ferruh.yigit@intel.com, benjamin.h.shelton@intel.com, narender.vangati@intel.com, Qi Zhang Date: Thu, 28 Jun 2018 09:52:34 +0800 Message-Id: <20180628015247.42232-7-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180628015247.42232-1-qi.z.zhang@intel.com> References: <20180607123849.14439-1-qi.z.zhang@intel.com> <20180628015247.42232-1-qi.z.zhang@intel.com> Subject: [dpdk-dev] [PATCH v6 06/19] ethdev: support attach private device as first 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: Thu, 28 Jun 2018 01:52:28 -0000 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 --- 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 0a93fa669..f2982c790 100644 --- a/lib/librte_ethdev/ethdev_mp.c +++ b/lib/librte_ethdev/ethdev_mp.c @@ -182,6 +182,8 @@ __handle_secondary_request(void *param) 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 54d3d2369..c0f68fe09 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); @@ -432,7 +441,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); @@ -487,7 +496,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); @@ -504,7 +513,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); @@ -519,7 +528,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); @@ -541,7 +550,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