From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10057.outbound.protection.outlook.com [40.107.1.57]) by dpdk.org (Postfix) with ESMTP id 762981B437 for ; Wed, 10 Oct 2018 09:03:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QjYpbvxAbHv8/RLgg6P2G0arOTDXaFUX1h2p0CaoVFw=; b=TSnEmgXH8T4vAtfbWy20jtUpHqBOj7NBVcNX6CNktQmZAuvMIv8BA5X1qNJFAROm/JLgX2vfJ29rFrviKeO3u40NRm473d1qHdDg7NNtqp2Vc+fNURk58vGRqbh3HStMEtgW5GJcfqsUTuRNZsuHlbQptmhco/atmuIBL4+fu80= Received: from DB5PR05MB1254.eurprd05.prod.outlook.com (10.162.157.140) by DB5PR05MB1894.eurprd05.prod.outlook.com (10.166.173.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.28; Wed, 10 Oct 2018 07:03:24 +0000 Received: from DB5PR05MB1254.eurprd05.prod.outlook.com ([fe80::3516:b329:5c35:51a5]) by DB5PR05MB1254.eurprd05.prod.outlook.com ([fe80::3516:b329:5c35:51a5%2]) with mapi id 15.20.1207.029; Wed, 10 Oct 2018 07:03:24 +0000 From: Raslan Darawsheh To: "keith.wiles@intel.com" CC: Thomas Monjalon , "dev@dpdk.org" , Shahaf Shuler , Raslan Darawsheh , Ori Kam , "ferruh.yigit@intel.com" Thread-Topic: [PATCH v5 3/3] net/tap: add queues when attaching from secondary process Thread-Index: AQHUYGdVjg5G5Plj80K1ylRergQzag== Date: Wed, 10 Oct 2018 07:03:24 +0000 Message-ID: <1539154988-20652-3-git-send-email-rasland@mellanox.com> References: <1539154988-20652-1-git-send-email-rasland@mellanox.com> In-Reply-To: <1539154988-20652-1-git-send-email-rasland@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: AM5PR0701CA0017.eurprd07.prod.outlook.com (2603:10a6:203:51::27) To DB5PR05MB1254.eurprd05.prod.outlook.com (2a01:111:e400:51cc::12) authentication-results: spf=none (sender IP is ) smtp.mailfrom=rasland@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [37.142.13.130] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB5PR05MB1894; 6:s9WFNO938oLgq8kar2LLqiQR0GSSAUGijnGVT/JXV9SQWQ3zT2Oj43a5ibIeBKyve0kYXotPWIt3T4SDpXm+9hj7uNPR0yfCruCHrSVNDz68Mmbm1zBSp47ClyFWD/dbTROXGOvXUfqkjMhgEBcem5voIj/aaqDCPnpBnUMnMzkpZtzFj0Y1/MJFD3ZMH9lZ0FXyxMtHaNDH+y1ifhfaAmOlz5pBFjnkz1TJ+FqW5qylEnncAaNVYYHwPEsJWpD/kMlSncyMHKXFMCwL9UUbr/xjY9MM8+6IGpCNV7FQGfHmiePDj1OdcS/Wb9VEJtck3yagDExYXXMC9L9rzjWNfqEo/E77/D4qDHTplV7ctKmWx/x66zXiIS7X1btGS6MP/DiIzqC1Kb+2uAa8FqhyqEwkl8BHyjD0wdAUzwY2TW2Po2/R4qafaufv9hsGlKuWZjjMaW2Uc9LasszZPPBH2A==; 5:RliIsNF7iogVO5F/Edt2XOBXhzdaWnfmuFVf6AioXwGqVRa57Fs7LK7OPqTsjhsUKYmK6W6CqQu7kEny2RK/SCxlo7mrmPlhpj96EMk2f2Ism6bu1iWn8ZLMLdi7d087zphlkyF+SeUtm8S/VPGhjzh/cl0qyUod2W7XCVlnyxA=; 7:Q3t5YndPuqfB8qdhcfa9lhZLBR8A79YE9igR9ifFnG6wI/z6vtJF5J9PNwMMi+JxeNNU/ee5+HHeyNn1hHybu1kmSmMRNneVRTrwmiKtVS8oUvO6nnI2GD9A3gpoT0pbxJ1fSThNfqX/rGNffWk2AgNjDXcZIAmI7/2ZVlfzbShi5Kj3+uL2/0RDetRYZtmyrkAXt63SPKMrzNARbMRNtf3ahEmg/Zg7VvllO1Zd54evJvGM5uxfppZpccNNANzv x-ms-office365-filtering-correlation-id: fd32d4b8-9b57-462f-c359-08d62e7e7817 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DB5PR05MB1894; x-ms-traffictypediagnostic: DB5PR05MB1894: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(72170088055959); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(10201501046)(3231355)(944501410)(4982022)(52105095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(201708071742011)(7699051); SRVR:DB5PR05MB1894; BCL:0; PCL:0; RULEID:; SRVR:DB5PR05MB1894; x-forefront-prvs: 08213D42D3 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(39860400002)(396003)(366004)(136003)(346002)(189003)(199004)(66066001)(305945005)(478600001)(8936002)(71200400001)(71190400001)(14444005)(52116002)(5660300001)(76176011)(316002)(5024004)(4326008)(7736002)(11346002)(446003)(2900100001)(2616005)(26005)(97736004)(476003)(186003)(966005)(386003)(6486002)(99286004)(6436002)(6116002)(3846002)(6512007)(6306002)(2351001)(2906002)(53936002)(6506007)(81166006)(105586002)(25786009)(81156014)(106356001)(5640700003)(14454004)(68736007)(6916009)(36756003)(2501003)(102836004)(5250100002)(8676002)(86362001)(50226002)(486006)(256004)(54906003); DIR:OUT; SFP:1101; SCL:1; SRVR:DB5PR05MB1894; H:DB5PR05MB1254.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: zXevAml6fdqne0UWlCv/57tT2X9qQaaigJ7Cf755yn2SPyUK9ifRXl6UsuY08V5N0Xq8JY1Snln8fRTpfvw4bu7ZsmGbNUaCpCwdleHUYIlE2tEktvSB57GzZhCOt9G2B8WiE1pHJ6V4kQCa6fvoo66BDciEJY/jw/tDX2gbfEpRRfqhJgTQ8cNmSLvjm9eHjXTSmKxFYSo+XtlSeX5vrMpACH4fl6MaKi0khgnYazRFuQP3syNEmqgXRobruf8PU/DrbaKxpgpPRhPUyEo5CH2RoZ6FBI+x08RBdgnrX5HNqyltW9I3S39iyw59EMsAr2krbpclKiUGaJ6ThTC+lR0UhIBnUAmmouxUzh2atEs= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd32d4b8-9b57-462f-c359-08d62e7e7817 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Oct 2018 07:03:24.0588 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR05MB1894 Subject: [dpdk-dev] [PATCH v5 3/3] net/tap: add queues when attaching from secondary process 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: Wed, 10 Oct 2018 07:03:26 -0000 In the case the device is created by the primary process, the secondary must request some file descriptors to attach the queues. The file descriptors are shared via IPC Unix socket. Thanks to the IPC synchronization, the secondary process is now able to do Rx/Tx on a TAP created by the primary process. Signed-off-by: Raslan Darawsheh Signed-off-by: Thomas Monjalon --- v2: - translate file descriptors via IPC API - add documentation v3: - rabse the commit - use private static array for fd's to be local for each process v4: - removed TODO and FIXME tags - used strlcpy instead of strcpy v5: rebase the commit on top of Alejandro Lucero patch for secondary process private pointer. http://patches.dpdk.org/patch/46185/ --- --- doc/guides/nics/tap.rst | 16 ++++ doc/guides/rel_notes/release_18_11.rst | 5 ++ drivers/net/tap/Makefile | 1 + drivers/net/tap/meson.build | 1 + drivers/net/tap/rte_eth_tap.c | 147 +++++++++++++++++++++++++++++= +++- 5 files changed, 169 insertions(+), 1 deletion(-) diff --git a/doc/guides/nics/tap.rst b/doc/guides/nics/tap.rst index 2714868..9a3d7b3 100644 --- a/doc/guides/nics/tap.rst +++ b/doc/guides/nics/tap.rst @@ -152,6 +152,22 @@ Distribute IPv4 TCP packets using RSS to a given MAC a= ddress over queues 0-3:: testpmd> flow create 0 priority 4 ingress pattern eth dst is 0a:0b:0c:0= d:0e:0f \ / ipv4 / tcp / end actions rss queues 0 1 2 3 end / end =20 +Multi-process sharing +--------------------- + +It is possible to attach an existing TAP device in a secondary process, +by declaring it as a vdev with the same name as in the primary process, +and without any parameter. + +The port attached in a secondary process will give access to the +statistics and the queues. +Therefore it can be used for monitoring or Rx/Tx processing. + +The IPC synchronization of Rx/Tx queues is currently limited: + + - Maximum 8 queues shared + - Synchronized on probing, but not on later port update + Example ------- =20 diff --git a/doc/guides/rel_notes/release_18_11.rst b/doc/guides/rel_notes/= release_18_11.rst index 2133a5b..3240b52 100644 --- a/doc/guides/rel_notes/release_18_11.rst +++ b/doc/guides/rel_notes/release_18_11.rst @@ -104,6 +104,11 @@ New Features the specified port. The port must be stopped before the command call in = order to reconfigure queues. =20 +* **Added TAP Rx/Tx queues sharing with a secondary process.** + + A secondary process can attach a TAP device created in the primary proce= ss, + probe the queues, and process Rx/Tx in a secondary process. + =20 API Changes ----------- diff --git a/drivers/net/tap/Makefile b/drivers/net/tap/Makefile index 3243365..7748283 100644 --- a/drivers/net/tap/Makefile +++ b/drivers/net/tap/Makefile @@ -22,6 +22,7 @@ CFLAGS +=3D -O3 CFLAGS +=3D -I$(SRCDIR) CFLAGS +=3D -I. CFLAGS +=3D $(WERROR_FLAGS) +CFLAGS +=3D -DALLOW_EXPERIMENTAL_API LDLIBS +=3D -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring LDLIBS +=3D -lrte_ethdev -lrte_net -lrte_kvargs -lrte_hash LDLIBS +=3D -lrte_bus_vdev -lrte_gso diff --git a/drivers/net/tap/meson.build b/drivers/net/tap/meson.build index 37f65b7..f7e8852 100644 --- a/drivers/net/tap/meson.build +++ b/drivers/net/tap/meson.build @@ -35,6 +35,7 @@ args =3D [ 'TCA_ACT_BPF_FD' ], ] config =3D configuration_data() +allow_experimental_apis =3D true foreach arg:args config.set(arg[0], cc.has_header_symbol(arg[1], arg[2])) endforeach diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 3372d54..83c9288 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include =20 #include #include @@ -62,6 +64,10 @@ #define TAP_GSO_MBUFS_NUM \ (TAP_GSO_MBUFS_PER_CORE * TAP_GSO_MBUF_CACHE_SIZE) =20 +/* IPC key for queue fds sync */ +#define TAP_MP_KEY "tap_mp_sync_queues" + +static int tap_devices_count; static struct rte_vdev_driver pmd_tap_drv; static struct rte_vdev_driver pmd_tun_drv; =20 @@ -100,6 +106,17 @@ enum ioctl_mode { REMOTE_ONLY, }; =20 +/* Message header to synchronize queues via IPC */ +struct ipc_queues { + char port_name[RTE_DEV_NAME_MAX_LEN]; + int rxq_count; + int txq_count; + /* + * The file descriptors are in the dedicated part + * of the Unix message to be translated by the kernel. + */ +}; + static int tap_intr_handle_set(struct rte_eth_dev *dev, int set); =20 /** @@ -2006,6 +2023,102 @@ rte_pmd_tun_probe(struct rte_vdev_device *dev) return ret; } =20 +/* Request queue file descriptors from secondary to primary. */ +static int +tap_mp_attach_queues(const char *port_name, struct rte_eth_dev *dev) +{ + int ret; + struct timespec timeout =3D {.tv_sec =3D 1, .tv_nsec =3D 0}; + struct rte_mp_msg request, *reply; + struct rte_mp_reply replies; + struct ipc_queues *request_param =3D (struct ipc_queues *)request.param; + struct ipc_queues *reply_param; + struct pmd_process_private *process_private =3D dev->process_private; + int queue, fd_iterator; + + /* Prepare the request */ + strlcpy(request.name, TAP_MP_KEY, sizeof(request.name)); + strlcpy(request_param->port_name, port_name, + sizeof(request_param->port_name)); + request.len_param =3D sizeof(*request_param); + /* Send request and receive reply */ + ret =3D rte_mp_request_sync(&request, &replies, &timeout); + if (ret < 0) { + TAP_LOG(ERR, "Failed to request queues from primary: %d", + rte_errno); + return -1; + } + reply =3D &replies.msgs[0]; + reply_param =3D (struct ipc_queues *)reply->param; + TAP_LOG(DEBUG, "Received IPC reply for %s", reply_param->port_name); + + /* Attach the queues from received file descriptors */ + dev->data->nb_rx_queues =3D reply_param->rxq_count; + dev->data->nb_tx_queues =3D reply_param->txq_count; + fd_iterator =3D 0; + for (queue =3D 0; queue < reply_param->rxq_count; queue++) + process_private->rxq_fds[queue] =3D reply->fds[fd_iterator++]; + for (queue =3D 0; queue < reply_param->txq_count; queue++) + process_private->txq_fds[queue] =3D reply->fds[fd_iterator++]; + + return 0; +} + +/* Send the queue file descriptors from the primary process to secondary. = */ +static int +tap_mp_sync_queues(const struct rte_mp_msg *request, const void *peer) +{ + struct rte_eth_dev *dev; + struct pmd_process_private *process_private; + struct rte_mp_msg reply; + const struct ipc_queues *request_param =3D + (const struct ipc_queues *)request->param; + struct ipc_queues *reply_param =3D + (struct ipc_queues *)reply.param; + uint16_t port_id; + int queue; + int ret; + + /* Get requested port */ + TAP_LOG(DEBUG, "Received IPC request for %s", request_param->port_name); + ret =3D rte_eth_dev_get_port_by_name(request_param->port_name, &port_id); + if (ret) { + TAP_LOG(ERR, "Failed to get port id for %s", + request_param->port_name); + return -1; + } + dev =3D &rte_eth_devices[port_id]; + process_private =3D dev->process_private; + + /* Fill file descriptors for all queues */ + reply.num_fds =3D 0; + reply_param->rxq_count =3D 0; + for (queue =3D 0; queue < dev->data->nb_rx_queues; queue++) { + reply.fds[reply.num_fds++] =3D process_private->rxq_fds[queue]; + reply_param->rxq_count++; + } + RTE_ASSERT(reply_param->rxq_count =3D=3D dev->data->nb_rx_queues); + RTE_ASSERT(reply_param->txq_count =3D=3D dev->data->nb_tx_queues); + RTE_ASSERT(reply.num_fds <=3D RTE_MP_MAX_FD_NUM); + + reply_param->txq_count =3D 0; + for (queue =3D 0; queue < dev->data->nb_tx_queues; queue++) { + reply.fds[reply.num_fds++] =3D process_private->txq_fds[queue]; + reply_param->txq_count++; + } + + /* Send reply */ + strlcpy(reply.name, request->name, sizeof(reply.name)); + strlcpy(reply_param->port_name, request_param->port_name, + sizeof(reply_param->port_name)); + reply.len_param =3D sizeof(*reply_param); + if (rte_mp_reply(&reply, peer) < 0) { + TAP_LOG(ERR, "Failed to reply an IPC request to sync queues"); + return -1; + } + return 0; +} + /* Open a TAP interface device. */ static int @@ -2032,9 +2145,28 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) TAP_LOG(ERR, "Failed to probe %s", name); return -1; } - /* TODO: request info from primary to set up Rx and Tx */ eth_dev->dev_ops =3D &ops; eth_dev->device =3D &dev->device; + eth_dev->rx_pkt_burst =3D pmd_rx_burst; + eth_dev->tx_pkt_burst =3D pmd_tx_burst; + if (!rte_eal_primary_proc_alive(NULL)) { + TAP_LOG(ERR, "Primary process is missing"); + return -1; + } + eth_dev->process_private =3D (struct pmd_process_private *) + rte_zmalloc_socket(name, + sizeof(struct pmd_process_private), + RTE_CACHE_LINE_SIZE, + eth_dev->device->numa_node); + if (eth_dev->process_private =3D=3D NULL) { + TAP_LOG(ERR, + "Failed to alloc memory for process private"); + return -1; + } + + ret =3D tap_mp_attach_queues(name, eth_dev); + if (ret !=3D 0) + return -1; rte_eth_dev_probing_finish(eth_dev); return 0; } @@ -2082,6 +2214,14 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) TAP_LOG(NOTICE, "Initializing pmd_tap for %s as %s", name, tap_name); =20 + /* Register IPC feed callback */ + ret =3D rte_mp_action_register(TAP_MP_KEY, tap_mp_sync_queues); + if (ret < 0 && rte_errno !=3D EEXIST && tap_devices_count) { + TAP_LOG(ERR, "%s: Failed to register IPC callback: %s", + tuntap_name, strerror(rte_errno)); + goto leave; + } + tap_devices_count++; ret =3D eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac, ETH_TUNTAP_TYPE_TAP); =20 @@ -2089,6 +2229,8 @@ rte_pmd_tap_probe(struct rte_vdev_device *dev) if (ret =3D=3D -1) { TAP_LOG(ERR, "Failed to create pmd for %s as %s", name, tap_name); + if (!tap_devices_count) + rte_mp_action_unregister(TAP_MP_KEY); tap_unit--; /* Restore the unit number */ } rte_kvargs_free(kvlist); @@ -2137,6 +2279,9 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev) close(internals->ioctl_sock); rte_free(eth_dev->data->dev_private); rte_free(eth_dev->process_private); + if (tap_devices_count =3D=3D 1) + rte_mp_action_unregister(TAP_MP_KEY); + tap_devices_count--; rte_eth_dev_release_port(eth_dev); =20 if (internals->ka_fd !=3D -1) { --=20 2.7.4