From patchwork Tue Mar 5 16:28:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1051852 X-Patchwork-Delegate: ian.stokes@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=samsung.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=samsung.com header.i=@samsung.com header.b="E206DCvO"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44DN3t4TQRz9s7h for ; Wed, 6 Mar 2019 03:42:50 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C727EFCAC; Tue, 5 Mar 2019 16:41:58 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 0B16EFB9C for ; Tue, 5 Mar 2019 16:28:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id E53003F7 for ; Tue, 5 Mar 2019 16:28:41 +0000 (UTC) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20190305162840euoutp016a44a735803ad45b20526a7d2b4c164a~JHOXx7GnO1785317853euoutp01C for ; Tue, 5 Mar 2019 16:28:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20190305162840euoutp016a44a735803ad45b20526a7d2b4c164a~JHOXx7GnO1785317853euoutp01C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1551803320; bh=HMq9hOux3ER2lGOlOYRUAiRsLJveUTYeFq0k8c9d/go=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E206DCvOAsRjl3+mCxQI8y7/6HOVw/Af/jcDyaNJTMMfKEKRec18r8T0alnp3WlN1 PVjq1XarQUrwd1sIjIP/zO/cDD0iy+uHkT2HND0L0l4CvwcDYO+hRy5Uv2C9BV/RnH qWNgngl3rrF60p8excDr1yl8VIC8dNv7ioYIaeXo= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20190305162839eucas1p267d08a93d5a50228382f571f9811b519~JHOXKFMna3232632326eucas1p2R; Tue, 5 Mar 2019 16:28:39 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 80.07.04441.7B3AE7C5; Tue, 5 Mar 2019 16:28:39 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20190305162838eucas1p2cbc6291f28bfc4e09a072a94ecdccfa2~JHOV_iIRU2676526765eucas1p22; Tue, 5 Mar 2019 16:28:38 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20190305162838eusmtrp264aa6f0b0609a74ad6b44e2b7b3d8ec2~JHOVwVgHq2508125081eusmtrp2f; Tue, 5 Mar 2019 16:28:38 +0000 (GMT) X-AuditID: cbfec7f2-5c9ff70000001159-fb-5c7ea3b77d95 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 29.24.04128.6B3AE7C5; Tue, 5 Mar 2019 16:28:38 +0000 (GMT) Received: from imaximets.rnd.samsung.ru (unknown [106.109.129.180]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20190305162837eusmtip1aa7e053c76db3c2cf4df6a43e8a5ee42~JHOVV9d5V0578705787eusmtip1d; Tue, 5 Mar 2019 16:28:37 +0000 (GMT) From: Ilya Maximets To: ovs-dev@openvswitch.org, Ian Stokes Date: Tue, 5 Mar 2019 19:28:27 +0300 Message-Id: <20190305162827.9059-3-i.maximets@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190305162827.9059-1-i.maximets@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOIsWRmVeSWpSXmKPExsWy7djP87rbF9fFGCxpVLPYMm0yq8WV9p/s FhsfnmW1mPvpOaMDi8fiPS+ZPJ7d/M/o0bdlFaPH/+arrAEsUVw2Kak5mWWpRfp2CVwZ6ycf Zy24rlXRvO0AawPjRfkuRk4OCQETiemftrF1MXJxCAmsYJToffuCHSQhJPCFUWLipQiIxGdG iZVL9rDCdDye/oAJIrGcUaJr/W4WCOcHo8StxunMIFVsAjoSp1YfYQSxRQTsJKatamICsZkF /CW6d60FiwsLOEjcnTOLBcRmEVCVaDm1GGwDr4CVxMpbS5ggtslLrN5wAGwmp4C1xLXnf1hB lkkInGCTWLdlJhtEkYvEy4MX2SFsYYlXx7dA2TIS/3fOhxpUL3G/5SUjRHMHo8T0Q/+gEvYS W16fA2rgALpOU2L9Ln2IsKPEu2szWUHCEgJ8EjfeCkLczycxaRvIjyBhXomONiGIahWJ3weX M0PYUhI3332GusBDYsaHL2yQEO1jlFh3r2gCo/wshF0LGBlXMYqnlhbnpqcWG+allusVJ+YW l+al6yXn525iBEb/6X/HP+1g/Hop6RCjAAejEg/v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1I9cAgAA X-CMS-MailID: 20190305162838eucas1p2cbc6291f28bfc4e09a072a94ecdccfa2 X-Msg-Generator: CA X-RootMTR: 20190305162838eucas1p2cbc6291f28bfc4e09a072a94ecdccfa2 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190305162838eucas1p2cbc6291f28bfc4e09a072a94ecdccfa2 References: <20190305162827.9059-1-i.maximets@samsung.com> X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ilya Maximets , Flavio Leitner Subject: [ovs-dev] [PATCH 2/2] netdev-dpdk: Allocate vhost_id dynamically. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 'vhost_id' is an array of 'PATH_MAX' bytes in the middle of 'netdev_dpdk' structure. That is 4K bytes. 'vhost_id' never used on a hot path and there is no need to keep it inside the structure memory. Dynamic allocation will allow to decrease 'struct netdev_dpdk' signigficantly, saving 4KB per ETH port (ETH ports doesn't use 'vhost_id') and almost same value per vhost ports (real 'vhost_id's, in common case, are much shorter). We could save the pointer space by making the union with 'devargs' which is mutually exclusive with 'vhost_id'. As we're just removing the single 'PADDED_MEMBER', the total cacheline layout is not affected. Stats for 'struct netdev_dpdk': Before: /* size: 4992, cachelines: 78 */ After : /* size: 896, cachelines: 14 */ Signed-off-by: Ilya Maximets --- lib/netdev-dpdk.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 93d8e37bb..e5f9a9374 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -400,7 +400,12 @@ struct netdev_dpdk { enum dpdk_dev_type type; enum netdev_flags flags; int link_reset_cnt; - char *devargs; /* Device arguments for dpdk ports */ + union { + /* Device arguments for dpdk ports */ + char *devargs; + /* Identifier used to distinguish vhost devices from each other. */ + char *vhost_id; + }; struct dpdk_tx_queue *tx_q; struct rte_eth_link link; ); @@ -417,11 +422,6 @@ struct netdev_dpdk { /* 3 pad bytes here. */ ); - PADDED_MEMBERS(CACHE_LINE_SIZE, - /* Identifier used to distinguish vhost devices from each other. */ - char vhost_id[PATH_MAX]; - ); - PADDED_MEMBERS(CACHE_LINE_SIZE, struct netdev up; /* In dpdk_list. */ @@ -1276,8 +1276,7 @@ netdev_dpdk_vhost_construct(struct netdev *netdev) /* Take the name of the vhost-user port and append it to the location where * the socket is to be created, then register the socket. */ - snprintf(dev->vhost_id, sizeof dev->vhost_id, "%s/%s", - dpdk_get_vhost_sock_dir(), name); + dev->vhost_id = xasprintf("%s/%s", dpdk_get_vhost_sock_dir(), name); dev->vhost_driver_flags &= ~RTE_VHOST_USER_CLIENT; err = rte_vhost_driver_register(dev->vhost_id, dev->vhost_driver_flags); @@ -1323,6 +1322,11 @@ netdev_dpdk_vhost_construct(struct netdev *netdev) } out: + if (err) { + free(dev->vhost_id); + dev->vhost_id = NULL; + } + ovs_mutex_unlock(&dpdk_mutex); VLOG_WARN_ONCE("dpdkvhostuser ports are considered deprecated; " "please migrate to dpdkvhostuserclient ports."); @@ -1451,13 +1455,14 @@ netdev_dpdk_vhost_destruct(struct netdev *netdev) "socket '%s' must be restarted.", dev->vhost_id); } - vhost_id = xstrdup(dev->vhost_id); + vhost_id = dev->vhost_id; + dev->vhost_id = NULL; common_destruct(dev); ovs_mutex_unlock(&dpdk_mutex); - if (!vhost_id[0]) { + if (!vhost_id) { goto out; } @@ -1906,8 +1911,9 @@ netdev_dpdk_vhost_client_set_config(struct netdev *netdev, ovs_mutex_lock(&dev->mutex); if (!(dev->vhost_driver_flags & RTE_VHOST_USER_CLIENT)) { path = smap_get(args, "vhost-server-path"); - if (path && strcmp(path, dev->vhost_id)) { - strcpy(dev->vhost_id, path); + if (!nullable_string_is_equal(path, dev->vhost_id)) { + free(dev->vhost_id); + dev->vhost_id = nullable_xstrdup(path); /* check zero copy configuration */ if (smap_get_bool(args, "dq-zero-copy", false)) { dev->vhost_driver_flags |= RTE_VHOST_USER_DEQUEUE_ZERO_COPY; @@ -3484,8 +3490,8 @@ new_device(int vid) /* Add device to the vhost port with the same name as that passed down. */ LIST_FOR_EACH(dev, list_node, &dpdk_list) { ovs_mutex_lock(&dev->mutex); - if (strncmp(ifname, dev->vhost_id, IF_NAME_SZ) == 0) { - uint32_t qp_num = rte_vhost_get_vring_num(vid)/VIRTIO_QNUM; + if (nullable_string_is_equal(ifname, dev->vhost_id)) { + uint32_t qp_num = rte_vhost_get_vring_num(vid) / VIRTIO_QNUM; /* Get NUMA information */ newnode = rte_vhost_get_numa_node(vid); @@ -3613,7 +3619,7 @@ vring_state_changed(int vid, uint16_t queue_id, int enable) ovs_mutex_lock(&dpdk_mutex); LIST_FOR_EACH (dev, list_node, &dpdk_list) { ovs_mutex_lock(&dev->mutex); - if (strncmp(ifname, dev->vhost_id, IF_NAME_SZ) == 0) { + if (nullable_string_is_equal(ifname, dev->vhost_id)) { if (enable) { dev->tx_q[qid].map = qid; } else { @@ -4144,8 +4150,7 @@ netdev_dpdk_vhost_client_reconfigure(struct netdev *netdev) * 1. Device hasn't been registered yet. * 2. A path has been specified. */ - if (!(dev->vhost_driver_flags & RTE_VHOST_USER_CLIENT) - && strlen(dev->vhost_id)) { + if (!(dev->vhost_driver_flags & RTE_VHOST_USER_CLIENT) && dev->vhost_id) { /* Register client-mode device. */ vhost_flags |= RTE_VHOST_USER_CLIENT;