From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30044.outbound.protection.outlook.com [40.107.3.44]) by dpdk.org (Postfix) with ESMTP id CCB672BD3 for ; Tue, 2 Oct 2018 12:34:13 +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=HVoC3oes+se5fjrjEA/iuVw4jzJYg7oC+FWkXXMe3M8=; b=JcutRoxE0rhxN66skS4T0r9hbon5lUERLXN1cwodN5yQxzL4PdVPRPHfRAQ0eofkepOsiXeQnBJeQQ8H/2jKO7SWYJTszg8bdcdsjNYinTX2Ru/1lujBuFPg9mnWDgvgeBjFUI/Vlurev/aIE6Sq/TetZnZmpKnyd9cFnmX3cGc= Received: from DB5PR05MB1254.eurprd05.prod.outlook.com (10.162.157.140) by DB5PR05MB1094.eurprd05.prod.outlook.com (10.161.240.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1164.25; Tue, 2 Oct 2018 10:34:11 +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.1185.024; Tue, 2 Oct 2018 10:34:11 +0000 From: Raslan Darawsheh To: "keith.wiles@intel.com" CC: Thomas Monjalon , "dev@dpdk.org" , Shahaf Shuler , Raslan Darawsheh , Ori Kam Thread-Topic: [PATCH v4 2/2] net/tap: add queues when attaching from secondary process Thread-Index: AQHUWjt1TJ8DCxvOHUeF0NxWtMS8Xg== Date: Tue, 2 Oct 2018 10:34:11 +0000 Message-ID: <1538476438-20891-2-git-send-email-rasland@mellanox.com> References: <1538047196-13789-2-git-send-email-rasland@mellanox.com> <1538476438-20891-1-git-send-email-rasland@mellanox.com> In-Reply-To: <1538476438-20891-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: AM4PR05CA0018.eurprd05.prod.outlook.com (2603:10a6:205::31) 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; DB5PR05MB1094; 6:9P2J1LN/MM9DIeQvomMa/upjIvwJX+6hdHYVMKiSdr17VMxU2xX1CMQeSvM1fOYqwnpqc1wEmMXfYaUvPlne1QxcmSR8yBv4a5enDpa11xpG4A+fNinHGjXjwi8Xi3pxDswqigIrLHvYJJ9ueEiZmjC19Kv00mbjUpTRGGAMDsOqCD8zMRIBir/Tv3VqFEoYlRvg8uXG1gxhfmf0vC4Vy+qcL5ONeCI00OFEkNCWIXO80eOHKfrgm9Ja2G5SBcwjobUbcPDv1Sy5x922sdDifMlcJqm85fV7nLpVpbLZamjdXKFcqlpcNVjJlflowNHrO4F39PHjWpY34+BukDX0EOk1FnGyYORZcA9ed5Am2pnqX6r9+A2qj9gcCUbYidMSzGXFKILqaQuRf0YcWNWWxn1gdFJdwjf97TphksCabpmxkBI8xHpCwdEX7ycJ6Szy8Z6isz3wsJf1IyfISJeZLQ==; 5:0vMa+C56vaBSocNYG8/4EqMgUzPV2VNCc24TBx1ynX5JPYE2m8Eq6NK528KwvgiEE0+OMZGbubNXZ18lRP3ESkTBt/Aomuup3cmlRcOAtFHiARNvvx4/dOLjlQJ96P2YlS8emr7df3PSmu+5Fd6K43a6MRzPfIDb+SNtkzTtwOw=; 7:ixV4Kzb8Z6hFgv9eD4mqYZndIbn2VFDAeGMibR8E4XtrH5iJ9BRhGFwkbZRWFhap7CLWvGwHxDLZEmYPunsB0pm2e3l7ge6bSZPXivWLXGGkeMgnkstvnQg5ZPn0gEHgZMDd3uo6aS5cu+tTx4thTZ/vx+mZRmrVG5KQpCOzMM9BNOe4qwiHL9aEfMuP4fAfyxAuB72t4PgPZQE2SLInPp7+Ehh8YQ/BOUogbL6CakYY2H8BaPbcfILXOO4gmIBS x-ms-office365-filtering-correlation-id: 83a18686-f38f-44ab-da87-08d628529763 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DB5PR05MB1094; x-ms-traffictypediagnostic: DB5PR05MB1094: 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)(8121501046)(5005006)(3231355)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699051); SRVR:DB5PR05MB1094; BCL:0; PCL:0; RULEID:; SRVR:DB5PR05MB1094; x-forefront-prvs: 0813C68E65 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(376002)(366004)(346002)(396003)(136003)(199004)(189003)(71190400001)(71200400001)(14454004)(256004)(6916009)(478600001)(8676002)(8936002)(50226002)(25786009)(3846002)(6116002)(97736004)(107886003)(4326008)(5660300001)(5024004)(2906002)(53936002)(6486002)(14444005)(2900100001)(36756003)(6512007)(6436002)(5250100002)(2501003)(102836004)(106356001)(86362001)(446003)(105586002)(26005)(11346002)(2616005)(54906003)(186003)(5640700003)(486006)(52116002)(476003)(6506007)(386003)(99286004)(81156014)(76176011)(68736007)(81166006)(305945005)(7736002)(316002)(2351001)(66066001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB5PR05MB1094; H:DB5PR05MB1254.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: SMRt16yH8h9/LLhFxdfvWfIGLmBXj6yyR/No/6z+ZZ8HfQhZL9yvFvIxGT9mIDknx3RLyqEyUt1e24xd9SerTtUb/xGwYLv50uh5OhejpkRYCqnwdrfdxUR9rF1axtOsuls/jDTErylvrMMcwtevVxINJOI3CCFcjRO6HI0dimq+qd0CHGJ50QIFkqb6cgM4sfgiH/pvVRF5xRQvTIYfYhMro4ghHdnCbif8dM/zfoW6k4xJwdx7BQjFra7Dl0orYsAx15tD1QWYjGvUMRJwrGHF7SgYymlSNcN62QbBhlT81f3HmR0gGWOpN6jgjFZ1YN+Y6i97LeqG1gjgdbawldls4+9+ovcyipldm+j5wnM= 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: 83a18686-f38f-44ab-da87-08d628529763 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Oct 2018 10:34:11.6830 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR05MB1094 Subject: [dpdk-dev] [PATCH v4 2/2] 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: Tue, 02 Oct 2018 10:34:14 -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: - change strcpy to be strlcpy - remove the fixme and todo from comments. --- --- doc/guides/nics/tap.rst | 16 ++++ doc/guides/rel_notes/release_18_11.rst | 4 + drivers/net/tap/Makefile | 1 + drivers/net/tap/rte_eth_tap.c | 133 +++++++++++++++++++++++++++++= +++- 4 files changed, 153 insertions(+), 1 deletion(-) diff --git a/doc/guides/nics/tap.rst b/doc/guides/nics/tap.rst index 2714868..d1f3e1c 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: + + - Only 8 queues + - 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 8c4bb54..a9dda5b 100644 --- a/doc/guides/rel_notes/release_18_11.rst +++ b/doc/guides/rel_notes/release_18_11.rst @@ -67,6 +67,10 @@ New Features SR-IOV option in Hyper-V and Azure. This is an alternative to the previo= us vdev_netvsc, tap, and failsafe drivers combination. =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/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 8cc4552..a751f76 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,9 @@ #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 struct rte_vdev_driver pmd_tap_drv; static struct rte_vdev_driver pmd_tun_drv; static struct pmd_process_private *process_private; @@ -101,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 /** @@ -1980,6 +1996,99 @@ 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; + 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 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]; + + /* 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); + 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++; + } + RTE_ASSERT(reply_param->txq_count =3D=3D dev->data->nb_tx_queues); + RTE_ASSERT(reply.num_fds <=3D RTE_MP_MAX_FD_NUM); + + /* 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 @@ -2006,9 +2115,23 @@ 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; + } + 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); + + ret =3D tap_mp_attach_queues(name, eth_dev); + if (ret !=3D 0) + return -1; rte_eth_dev_probing_finish(eth_dev); return 0; } @@ -2056,6 +2179,13 @@ 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_LOG(ERR, "%s: Failed to register IPC callback: %s", + tuntap_name, strerror(rte_errno)); + goto leave; + } ret =3D eth_dev_tap_create(dev, tap_name, remote_iface, &user_mac, ETH_TUNTAP_TYPE_TAP); =20 @@ -2063,6 +2193,7 @@ 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); + rte_mp_action_unregister(TAP_MP_KEY); tap_unit--; /* Restore the unit number */ } rte_kvargs_free(kvlist); --=20 2.7.4