From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0089.outbound.protection.outlook.com [104.47.0.89]) by dpdk.org (Postfix) with ESMTP id 1BD311B16C for ; Sun, 7 Jan 2018 10:46:30 +0100 (CET) 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; bh=DcCYO+6veVt9cQzCZ2DX8E4YB/7JqibipEMxI/dEkVE=; b=EzT467W1cTHsHNvOW4bHLyCB2pZ/Mn/QPargedx7M7fouMpTQgfKOi+3fSiXwoeQZ+2bc3PfZUELT0sNCplxiFKpM5mJaYX6+PlZDGCvi28S4Wp+fC8ru2ITIiFyavWe/i6bSplVE10ElUwDJvLeekPB9A1xyAX9y2STk+N3JJY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by AM0PR0502MB3793.eurprd05.prod.outlook.com (2603:10a6:208:1e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.386.5; Sun, 7 Jan 2018 09:46:27 +0000 From: Matan Azrad To: Thomas Monjalon , Gaetan Rivet , Jingjing Wu Cc: dev@dpdk.org, Neil Horman , Bruce Richardson , Konstantin Ananyev Date: Sun, 7 Jan 2018 09:45:48 +0000 Message-Id: <1515318351-4756-4-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1515318351-4756-1-git-send-email-matan@mellanox.com> References: <1511870281-15282-1-git-send-email-matan@mellanox.com> <1515318351-4756-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: DB3PR0202CA0016.eurprd02.prod.outlook.com (2603:10a6:8:1::29) To AM0PR0502MB3793.eurprd05.prod.outlook.com (2603:10a6:208:1e::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 51866595-c777-4b06-cb3a-08d555b38653 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(48565401081)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:AM0PR0502MB3793; X-Microsoft-Exchange-Diagnostics: 1; AM0PR0502MB3793; 3:NeqAyRdTHKdRsYX1Ebcj1ySJZxEmUGA24U/YGqmh0/H6Na4mN4/SuBjVt40CO27/rMfajvT9SQesyl4vWmenBNNPkgZqqDyp9zF5XtNp/NcvlRVLFZmtyvpZvaizk1rygondCr74opQuwHT4LhpNc/WAfLV4Ja8WXRlfDsRNALw8jn3n/tJ1l5kMjMyoV3W9qJSiwT5qmd9+c9VXtutG7Y7qjNM3h0qGYT8Frv6+0ColkgeGCU3hJnauRbr7zE0R; 25:1OazeVNKlWXIxVoMactIZCbgRHTIfdLCFuTrazTBpPfuCvhaG/fYD+SR8k8fTKU6igFj3fb6a4fCsHCZY4kLW85wHqT8zZQjQdcmdPhABIOwJCk/zIZopPwc9Cj85dMIeOGzpKLbyDkDY6JdVEJXirGSVtMonAOOZkmofmGvnO/iz3tbzSYOdO3E97O+5dYFsYkptu0QyEquMKcfHa2xAPXvxXznzqKiDcQY8CHW7hfOt0yuON8Bu4+/g4C5OJLgNstTNyDXsOxin0aIkbvYjAmmp6CYdJfmKfaJJHos26dBI3qCg1+uNNgrF4nSZa62/zEXUkcKzp34YfeptNa9Eg==; 31:l9Y2yvzuVclBhmBL5J0xPcPLsD2LriWaMJBcVVtAsbudBxXRY/5ck6jWlsvPz6XU6+UPzIpTiPZx4/oTR7JrJmb0Xeb54NM6oZXsmV98OIJJGazM1YCdFFEcHefJbY4s8w+rs40y28uYFcm59LxmKy0v8e9VXNxYD1jA/qP0nE1hrshJfQI2XVpirQWwd5KndJksY2TJFhEzab54ruMgbumeJpGQDG3FilOxY/CkVuQ= X-MS-TrafficTypeDiagnostic: AM0PR0502MB3793: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; AM0PR0502MB3793; 20:zO75lOABymI9zqZyqotIvcHOQLKk4YQ4zEhP65I0HbRTPQLF3bor1RwH4FnmHw57IiJDAngBCiw/OAy57HwjyGEnlYjiBuhwCiNr/eu3Wns5IJQkQ0kzQxkP3nt10KnFnJSGJ6RDlSMTqXLy+eEXFX75m7hBBoSaJz+9TZAWJz74TeAHXA31dQszp4Uo9aK2E3ycZCIVoWnO3oWh93rrnjalSj3+AU3NTQ8PgFwzEbmK+ZUhTrWJ59qgSL3FInxDvSPiLUtN52XmHS4zHpYmWucCKGCXshJDDRR2a6JSfRQA7GZh+M017OyrRUhJ/0ou3tvipdNi1o4/TQs7wnQBGEMdMswPJjkkp+kc3HpYfBY+Qj+d1rfgkX4T3MexsK3S5/aEey6b8ZXy8dxx8f7mFq/2TfR6uodqVlgrwGsN4DoRHnj1P4bCVb88EgJQAyodsIJiyMw1tGQu1PkDFxZCNR9X1b4m4kjf/pBQQyYqtChaPy39/JATG185mqIjOrN6; 4:uihEHMYRkMMjak46hjb7aS3fyO1sLNq8VoFuLQRinXYUt6zoCB1swchOMUSYzVgbM+g5dB5Z/kE0tzHqgsi3fjfcg8Y4GqNxi0cPtjiDuKCip7Grarj3B5r/iuP6XCg0O+Qxk4kUuiYvKRtQ3aWfp3xYIsgp/oYuX59tPV2de1k0YRPL770bs+iWL9NBPf9MW1J3rU5O1kv8N4oFxVuzL6Md47bfUds2+IH5FJGMnnOnMnwJsG/2QlHZ4iwEQuJsu3gwf5MHlXQ37cT1kDL6V/Q2Pv9ta675tmrJOrZAIhi3W8c2Y2Zlu/IkJdKo6MY9 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(60795455431006); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(8121501046)(5005006)(3231023)(944501075)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041268)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(6072148)(201708071742011); SRVR:AM0PR0502MB3793; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:AM0PR0502MB3793; X-Forefront-PRVS: 0545EFAC9A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(396003)(366004)(39860400002)(39380400002)(376002)(199004)(189003)(105586002)(66066001)(8676002)(305945005)(52116002)(47776003)(68736007)(7696005)(76176011)(7736002)(5890100001)(2950100002)(25786009)(81156014)(478600001)(69596002)(55016002)(106356001)(51416003)(48376002)(2906002)(4720700003)(6666003)(6116002)(81166006)(97736004)(59450400001)(50226002)(16586007)(54906003)(53936002)(33026002)(36756003)(50466002)(16526018)(5660300001)(4326008)(386003)(316002)(3846002)(21086003)(86362001)(110136005)(8936002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0502MB3793; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR0502MB3793; 23:wpwi9u4DOiuLJfV+ECZoD2qdjuCAQ4YPIOqSrrI?= =?us-ascii?Q?+PdYzj4bMOeduBQ1lzdEr6HfGZSiauNa8gk26SWOEJErUfHofhENfxmcJlqi?= =?us-ascii?Q?ljxA1FgaQZpj0jg6nMEZIoM2wQAUtBDLDbDs/M1cxtvRA4SVQ9C50gfqEohc?= =?us-ascii?Q?UR6sLSnVinmv1G/lTTZwiHyb2BqXpP5+dOQr+NOYwu4Ue5D/kJiATzjWiVF8?= =?us-ascii?Q?G3+HGcNx9Wis/1ftYoRmD0y51xFwZt1tQOts+EW1OB5ds3vWrwl/EZJGf79V?= =?us-ascii?Q?OWBABagB3HVJKots9Ucv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?bex5rs7h0qFUZffD4m5L+S69kC6azuWRD9lpgRL7q/LSjXp/i6kfPtZfmnA?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM0PR0502MB3793; 6:pU+vlXvVHIgx+huTZ4HbSx1Tq/p07Nhrnmw4UaeYg13Dp3gbHoCWFL6U6StyyFZEuxerv8ZTimklLiMl4s//QHEf9lYY+WGIPeBVaf06GPfMOpbTzv144avrawsGApJia/6Z3dEDuVBGPplOQxoPnsQAHC4nDBCabXwaG7UUuNg2jpiOkgMGNj7VrXcwVashbaH87M+tk3oBsa/bDpAPFIhsxlH59jd1zySWD6o8eIKL9S+ovVBf+eMtH++BTOolhG3c86X5qkm6LYukdbqshdi6rkE70eiwtiFaQ11rCkvhuSom/spCKK9q6Ali3vWBZmZTxtLvxJsHX5wwqYCJ5t4pr1Lfbxzav2xge7KHFdQ=; 5:HMGrGFhdSZj+j77H7QtoPXA6XILKw7Hx2CXm8TvKmVkSdW9fsVlksUYJ0tXcW4Zf98JmJEnabssWqP/BBw/6xas+jxu2eRkCfVxBxYKnsstxPj9vxldJhYfQ2ICw0LAOby1lLMlEdnoA08XGrXUgaMlbS6VFK4oU72UvWHQHwgI=; 24:lEOgBghBqJyAN/ykGwrZm5qbESgTIVo1o74bAWcdVe785Qzgmw1M1KOyjs2njv0JMPZHWScjj24gmCxWj1WiJC7mb/Bi/A0T5VGySX9BzfQ=; 7:II1kepKe4DQGAhIOFu6tK/bGb5Vue/SgN2nXmqXt1Yajrqx7QDmM6okW68zV7yJ/E3LidxgNhkpSPwrOwpf6qPA+ghrjeVGWFtEeKjq9BMXbPIxYx69ARtLf005EV41S4JU5GLxM4GzN8jrPvRCSFAXKZq1a5axH/kBETN8XYuO67mkodPfmrPgLuy8uMwsy0VpM/OPZiayG+YcKJweyCJmHU2NgBE8qLYKrF2sJ01lGt2tyEmNxoBRNvi+SlK9K SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2018 09:46:27.3938 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 51866595-c777-4b06-cb3a-08d555b38653 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0502MB3793 Subject: [dpdk-dev] [PATCH v2 3/6] ethdev: synchronize port allocation 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: Sun, 07 Jan 2018 09:46:30 -0000 Ethernet port allocation was not thread safe, means 2 threads which tried to allocate a new port at the same time might get an identical port identifier and caused to memory overwrite. Actually, all the port configurations were not thread safe from ethdev point of view. The port ownership mechanism added to the ethdev is a good point to redefine the synchronization rules in ethdev: 1. The port allocation and port release synchronization will be managed by ethdev. 2. The port usage synchronization will be managed by the port owner. 3. The port ownership synchronization will be managed by ethdev. Add port allocation synchronization to complete the new rules. Signed-off-by: Matan Azrad --- config/common_base | 4 ++-- lib/librte_ether/rte_ethdev.c | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/config/common_base b/config/common_base index b8ee8f9..980ae3b 100644 --- a/config/common_base +++ b/config/common_base @@ -94,7 +94,7 @@ CONFIG_RTE_MAX_MEMSEG=256 CONFIG_RTE_MAX_MEMZONE=2560 CONFIG_RTE_MAX_TAILQ=32 CONFIG_RTE_ENABLE_ASSERT=n -CONFIG_RTE_LOG_LEVEL=RTE_LOG_INFO +CONFIG_RTE_LOG_LEVEL=RTE_LOG_DEBUG CONFIG_RTE_LOG_DP_LEVEL=RTE_LOG_INFO CONFIG_RTE_LOG_HISTORY=256 CONFIG_RTE_BACKTRACE=y @@ -136,7 +136,7 @@ CONFIG_RTE_LIBRTE_KVARGS=y # Compile generic ethernet library # CONFIG_RTE_LIBRTE_ETHER=y -CONFIG_RTE_LIBRTE_ETHDEV_DEBUG=n +CONFIG_RTE_LIBRTE_ETHDEV_DEBUG=y CONFIG_RTE_MAX_ETHPORTS=32 CONFIG_RTE_MAX_QUEUES_PER_PORT=1024 CONFIG_RTE_LIBRTE_IEEE1588=n diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 0e12452..d30d61f 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -85,6 +85,9 @@ /* spinlock for add/remove tx callbacks */ static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER; +/* spinlock for shared data allocation */ +static rte_spinlock_t rte_eth_share_data_alloc = RTE_SPINLOCK_INITIALIZER; + /* spinlock for eth device ownership management stored in shared memory */ static rte_spinlock_t *rte_eth_dev_ownership_lock; @@ -234,21 +237,27 @@ struct rte_eth_dev * rte_eth_dev_allocate(const char *name) { uint16_t port_id; - struct rte_eth_dev *eth_dev; + struct rte_eth_dev *eth_dev = NULL; + + /* Synchronize share data one time allocation between local threads. */ + rte_spinlock_lock(&rte_eth_share_data_alloc); + if (rte_eth_dev_data == NULL) + rte_eth_dev_share_data_alloc(); + rte_spinlock_unlock(&rte_eth_share_data_alloc); + + /* Synchronize port creation between primary and secondary threads. */ + rte_spinlock_lock(rte_eth_dev_ownership_lock); port_id = rte_eth_dev_find_free_port(); if (port_id == RTE_MAX_ETHPORTS) { RTE_PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n"); - return NULL; + goto unlock; } - if (rte_eth_dev_data == NULL) - rte_eth_dev_share_data_alloc(); - if (rte_eth_dev_allocated(name) != NULL) { RTE_PMD_DEBUG_TRACE("Ethernet Device with name %s already allocated!\n", name); - return NULL; + goto unlock; } eth_dev = eth_dev_get(port_id); @@ -256,6 +265,8 @@ struct rte_eth_dev * eth_dev->data->port_id = port_id; eth_dev->data->mtu = ETHER_MTU; +unlock: + rte_spinlock_unlock(rte_eth_dev_ownership_lock); return eth_dev; } @@ -268,10 +279,16 @@ struct rte_eth_dev * rte_eth_dev_attach_secondary(const char *name) { uint16_t i; - struct rte_eth_dev *eth_dev; + struct rte_eth_dev *eth_dev = NULL; + /* Synchronize share data one time attachment between local threads. */ + rte_spinlock_lock(&rte_eth_share_data_alloc); if (rte_eth_dev_data == NULL) rte_eth_dev_share_data_alloc(); + rte_spinlock_unlock(&rte_eth_share_data_alloc); + + /* Synchronize port attachment to primary port creation and release. */ + rte_spinlock_lock(rte_eth_dev_ownership_lock); for (i = 0; i < RTE_MAX_ETHPORTS; i++) { if (strcmp(rte_eth_dev_data[i].name, name) == 0) @@ -281,12 +298,12 @@ struct rte_eth_dev * RTE_PMD_DEBUG_TRACE( "device %s is not driven by the primary process\n", name); - return NULL; + } else { + eth_dev = eth_dev_get(i); + RTE_ASSERT(eth_dev->data->port_id == i); } - eth_dev = eth_dev_get(i); - RTE_ASSERT(eth_dev->data->port_id == i); - + rte_spinlock_unlock(rte_eth_dev_ownership_lock); return eth_dev; } -- 1.8.3.1