From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00044.outbound.protection.outlook.com [40.107.0.44]) by dpdk.org (Postfix) with ESMTP id BB6A21C00 for ; Mon, 4 Dec 2017 16:44:11 +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=fGxOBA2RnJ4xkdfatI4A6WyWpCbcrg3opyuB5+VR8FU=; b=qGtQg2o9htneVtzlMctPiW946eBcdyjPf7zYsTVyzqujpdRRfl7AzZzb+x0UNfBUjIWwCylY4S3YwXlW6pNGw0pMTWtm3e+S4n2WwLE8S4j2F8lK5w3+8mFaacQyTfyDIVvumbndCMeiQfDIpV1WuDT6UJWd0IOTImXKWlVcaxs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matan@mellanox.com; Received: from mellanox.com (37.142.13.130) by AM6PR0502MB3653.eurprd05.prod.outlook.com (2603:10a6:209:9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Mon, 4 Dec 2017 15:44:09 +0000 From: Matan Azrad To: Thomas Monjalon Cc: dev@dpdk.org Date: Mon, 4 Dec 2017 15:43:41 +0000 Message-Id: <1512402221-17630-1-git-send-email-matan@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1512028170-18637-1-git-send-email-matan@mellanox.com> References: <1512028170-18637-1-git-send-email-matan@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [37.142.13.130] X-ClientProxiedBy: HE1PR06CA0136.eurprd06.prod.outlook.com (2603:10a6:7:16::23) To AM6PR0502MB3653.eurprd05.prod.outlook.com (2603:10a6:209:9::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0d379feb-3908-4e58-c8cf-08d53b2ddca1 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603286); SRVR:AM6PR0502MB3653; X-Microsoft-Exchange-Diagnostics: 1; AM6PR0502MB3653; 3:8rfzQYZ5dkCXL/wzMlUlfxQ9WqzF1zRnqjpLyXpEL4Zq88gsYNB9oHCazrmScq3In20cuBoArVzLmVfC+SdRTveIRQAKC1uh/dfEKpGHDfeMaoVKnjhwNQMl4Z5z9jCwkef3T3KyMtN/SKfCNioUc90V2d0Wsj/48Xvmm6GRSW8X4LlQZ2rTfgGMIu0BvXNchu7Vix6i2SylXwSlYCCUSG3VlgZ0ljjpPYB2XGjVpf0wPWzQ/K0+uYcy+YO5OBm8; 25:SiZtcL4dLmSbSd/8kXEZXtrz05zlRfgJckGadyCMR5m6LxANR2qyOUnNsJku05D2VKAXb6SgbTrhhC+BMIUIRT0LtnsWVOajSU4SMD58a7eI4V5e7Zsp5LHVxLXUJ9vrzWAPtijA0936Gy9w5f5jW3MLzK6NirMIM9ZjNWmx+Fqg2xd+sUf2Y43Y+XxtMy/qxR8GD9vWy9vu6X1WhcYR/nVCvDGSj3gizo/UPA/W+PcvF5E3voREZejmv27EgjS1LcPVdtPZnfJaSjfXQDAtTF1O0pIPXF0LjOaEY/Ku2y+StgknqkJUuoESWRI+8LtAL8TAAP9J3uDNpOpIwc5NCg==; 31:Cq3IEm8gcbvaA7DmMgSufAcAjViOOQOCM/JuJXzoJq0YR2W4F48kpV9QmAw8CKPGjcYL4Id8uwFUSJbVz6n3G+b4NIt+t2lrRlPWF1768ZaCtiW3YWk6HfOodq+fxXDzdgqoFW9QYMvqE6V37tIzBEoD8FOVv4Qheoghvlq/RurNd/K6uwHtlTNitvr2Z7wW6BDmDjvH+agoK0jr4KUZTBjWtlQ6CPNpL1XhGWvfRT8= X-MS-TrafficTypeDiagnostic: AM6PR0502MB3653: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; AM6PR0502MB3653; 20:9DzSvVP6cdo1n5dOT2qOVE9tpmzcjr9dtlE9NS0m+xPZ/YpCjRD1SEdMRr2Kwn49P69j435AKiw7ezrIRenWln7R2GKopUKSeF6RCypq1UUogFnzZGtMgQiI0lCUb5woF7/Hw4xGErCz7O+VvqpGYIC0AARJZwlvGiM9Zpk8okO8yeTqEpWSJNge8oJLL6kPrdDDq6e/dD3G/OpNXF6h67EHBafcnxZLgpfrF9Xdaf9o4th8J2ELkPNYtM4gh3RUM0soctpqZ4OZeiuCg4oJk9ARYHJAD4XMELUn3AM29U0v0u1mdsI8jvS2PZ2eOuYMAZHzm9KMpwPjxDOT97uFeegbjCyaKb2w8JB5qNt9XfsQQIqf+KktTcYeyI9tMYfY6tpR81PkKK07kBZvC0kN44FihqaZu8+x3vHvbXBYHGBy4k82GCfEoGpTUK97oLlCIf3MI/EF5xpyhG1W7gezcR9kuemyYoV+S4Pdq6QJhjZp2niHcHNwSl6gWsMjRAxd; 4:p/oaIEedG0BV6/0MXJcI8b03PyxXlh2JeEfj6KX/nNCk0r/XkKSaSM0O45YAp05wntFDT0WwhtFgxTYUQvpBXhZPKPljbx8aOaPvZvSoWg6IHbrAKxSWNeLiuiPzlYdxQJb/h/B11hMn6Hsz5mQI2gkOXP/22wim4W2iPkXz7HyKpMAqFkxDsE/i9mjEpCMi7DOkypv62NETGCZM88rElP2x8c+eP2g54tsEbmn/L+BP6uIL2iDd2vKCZMSkx24KJVX8MZNQiiqDEe26LqVUvw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(10201501046)(3231022)(6055026)(6041248)(20161123555025)(20161123560025)(20161123564025)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:AM6PR0502MB3653; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:AM6PR0502MB3653; X-Forefront-PRVS: 051158ECBB X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(366004)(376002)(39860400002)(346002)(189002)(199003)(5890100001)(478600001)(86362001)(106356001)(189998001)(16526018)(2950100002)(50466002)(101416001)(81156014)(21086003)(81166006)(25786009)(48376002)(47776003)(66066001)(4720700003)(6666003)(6916009)(68736007)(7736002)(316002)(50226002)(33646002)(105586002)(4326008)(36756003)(69596002)(55016002)(33026002)(8936002)(7696005)(51416003)(52116002)(6116002)(3846002)(2906002)(97736004)(8676002)(53936002)(76176011)(5660300001)(305945005)(16586007); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR0502MB3653; H:mellanox.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; AM6PR0502MB3653; 23:LvQN+koCtJdHByW4sObtA5q5nKytLVqqTBso340?= =?us-ascii?Q?LZVLxpmmVZYaBT5voa7YrtimFz1BzndCbnTz2uVpyi/OO6eWgFIcoHTjUGDT?= =?us-ascii?Q?zHGVw17EXMEpSIdmRXEVaY0UdPfoeMoXFb/cB3aeG8hRrWrhaQbCR3VcIUlD?= =?us-ascii?Q?A2PSio8Uat+pokHA4/rZCAMg7KQMspciGZgKlFE6ZJhdCb7Tlx6rQ3mRm9z3?= =?us-ascii?Q?aeKDIHMkDnycBG6WPAtfZJR7tGMBW4FtkxTcKpGJZYLZs5L7sFQdCXUmhsrC?= =?us-ascii?Q?Rd+778iJLZepB5HQXtcNgvb8QmkIsV4Z/MmRew+Boefymt8rMQrDunZLLqMQ?= =?us-ascii?Q?CzAd0CEOhYPCVGqXAnWsDYcFnLrLCpmfs+8NbufR3IrSN3bsPQgwTqB5f2/e?= =?us-ascii?Q?sYYQQles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bRSUES1jJLYN1de0xwCkS8QKlE6iz9uvWPRhFg9mOdmqNACFt3bkss4tkswWDy9qnbJNYHz0Ah2UErSem6kXyOnol++5vfJFsGksu0pqxjflwofmythc1DfFFg5okqr4S9RS8JKrZtTYwazk1LdcTnk7lP6pdJYWMsOpuupASosk3tYSlBknrXzhwIa2nk4QA7yPX3ylCr57xDfxsoqh2JLep0NC0oPzsI+kqS9oNUNPD58GNoMYCZmJDeOZk9H0Ty2akjMLpIArZ7UiwOhmSY/qgTr/FM4Bm44CezG3k4mwH7ppJtijiK66BPM9mTp0AMc=; 5:fnotCaa2+6cNqo53JMccnBXKo0RJ5lAVOxiK4BZn2SLUlB9FRMuUKtx/Et8tGrpG53Cs/ZI7uD7HTWZn//KZ0sTH4za/ONfjJgkj7cRSM6IuwxCRFP5UALe/tapwOcrQIVCChCyU7Dmt/YpkHG2HQBIxz8pCM4hxLlLjjsy28O8=; 24:B7xOMsGg2VvJWGwxbqAOxlvjhnsbD5OjTaH3rSRBuEgSYSDCs9IMCRsg318rqOeRK087b43B0Rj7qzgAQ9JrHbsAc/5lkE/OjmDgvS7d/XY=; 7:hFumyPAMTAuXc/9uby8u2d3Cn/XmDQDF7vHZJz44PgfoQaw5QEP4USDPhbk33pC58lLcH4paUfx5KB9fA/L9ApCpQzTrp42MESgveAuXcVcF2uBuKfQS6/lWSZs8rjEltJyII8yHNJTAQT5hDXBSbedvyCWZB0lCn6zt5GdJHImW+XVBtPMYn+XStzq5VIwzp3Vs5UNFVRP5p2cTbM1lvwrepOn/Q6PtExFFBePaIzb/IVb9C0g6q5GKD5UgP0zU SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2017 15:44:09.7388 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0d379feb-3908-4e58-c8cf-08d53b2ddca1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0502MB3653 Subject: [dpdk-dev] [PATCH v2] ethdev: allow all ports event registration 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: Mon, 04 Dec 2017 15:44:12 -0000 Add option to register event callback for all ports by one call to rte_eth_dev_callback_register using port_id=RTE_ETH_ALL. In this case the callback is also registered to invalid ports. Signed-off-by: Matan Azrad --- lib/librte_ether/rte_ethdev.c | 124 +++++++++++++++++++++++++++++------------- lib/librte_ether/rte_ethdev.h | 8 ++- 2 files changed, 91 insertions(+), 41 deletions(-) V2: Move the ports cb lists initialization to dpdk init time (before the main calling). diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 318af28..9ffc296 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -73,6 +73,8 @@ static struct rte_eth_dev_data *rte_eth_dev_data; static uint8_t eth_dev_last_created_port; +RTE_INIT(eth_dev_init_cb_lists); + /* spinlock for eth device callbacks */ static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER; @@ -204,13 +206,21 @@ struct rte_eth_dev * eth_dev->data = &rte_eth_dev_data[port_id]; eth_dev->state = RTE_ETH_DEV_ATTACHED; - TAILQ_INIT(&(eth_dev->link_intr_cbs)); eth_dev_last_created_port = port_id; return eth_dev; } +static void +eth_dev_init_cb_lists(void) +{ + int i; + + for (i = 0; i < RTE_MAX_ETHPORTS; i++) + TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs); +} + struct rte_eth_dev * rte_eth_dev_allocate(const char *name) { @@ -2827,37 +2837,59 @@ int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx, { struct rte_eth_dev *dev; struct rte_eth_dev_callback *user_cb; + uint32_t next_port; + uint32_t last_port; if (!cb_fn) return -EINVAL; - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); + if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) { + RTE_LOG(ERR, EAL, "Invalid port_id=%d\n", port_id); + return -EINVAL; + } + + if (port_id == RTE_ETH_ALL) { + next_port = 0; + last_port = RTE_MAX_ETHPORTS - 1; + } else { + next_port = last_port = port_id; + } - dev = &rte_eth_devices[port_id]; rte_spinlock_lock(&rte_eth_dev_cb_lock); - TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) { - if (user_cb->cb_fn == cb_fn && - user_cb->cb_arg == cb_arg && - user_cb->event == event) { - break; + do { + dev = &rte_eth_devices[next_port]; + + TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) { + if (user_cb->cb_fn == cb_fn && + user_cb->cb_arg == cb_arg && + user_cb->event == event) { + break; + } } - } - /* create a new callback. */ - if (user_cb == NULL) { - user_cb = rte_zmalloc("INTR_USER_CALLBACK", - sizeof(struct rte_eth_dev_callback), 0); - if (user_cb != NULL) { - user_cb->cb_fn = cb_fn; - user_cb->cb_arg = cb_arg; - user_cb->event = event; - TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next); + /* create a new callback. */ + if (user_cb == NULL) { + user_cb = rte_zmalloc("INTR_USER_CALLBACK", + sizeof(struct rte_eth_dev_callback), 0); + if (user_cb != NULL) { + user_cb->cb_fn = cb_fn; + user_cb->cb_arg = cb_arg; + user_cb->event = event; + TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), + user_cb, next); + } else { + rte_spinlock_unlock(&rte_eth_dev_cb_lock); + rte_eth_dev_callback_unregister(port_id, event, + cb_fn, cb_arg); + return -ENOMEM; + } + } - } + } while (++next_port <= last_port); rte_spinlock_unlock(&rte_eth_dev_cb_lock); - return (user_cb == NULL) ? -ENOMEM : 0; + return 0; } int @@ -2868,36 +2900,50 @@ int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx, int ret; struct rte_eth_dev *dev; struct rte_eth_dev_callback *cb, *next; + uint32_t next_port; + uint32_t last_port; if (!cb_fn) return -EINVAL; - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); + if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) { + RTE_LOG(ERR, EAL, "Invalid port_id=%d\n", port_id); + return -EINVAL; + } + + if (port_id == RTE_ETH_ALL) { + next_port = 0; + last_port = RTE_MAX_ETHPORTS - 1; + } else { + next_port = last_port = port_id; + } - dev = &rte_eth_devices[port_id]; rte_spinlock_lock(&rte_eth_dev_cb_lock); - ret = 0; - for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; cb = next) { + do { + dev = &rte_eth_devices[next_port]; + ret = 0; + for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; + cb = next) { - next = TAILQ_NEXT(cb, next); + next = TAILQ_NEXT(cb, next); - if (cb->cb_fn != cb_fn || cb->event != event || - (cb->cb_arg != (void *)-1 && - cb->cb_arg != cb_arg)) - continue; + if (cb->cb_fn != cb_fn || cb->event != event || + (cb->cb_arg != (void *)-1 && cb->cb_arg != cb_arg)) + continue; - /* - * if this callback is not executing right now, - * then remove it. - */ - if (cb->active == 0) { - TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next); - rte_free(cb); - } else { - ret = -EAGAIN; + /* + * if this callback is not executing right now, + * then remove it. + */ + if (cb->active == 0) { + TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next); + rte_free(cb); + } else { + ret = -EAGAIN; + } } - } + } while (++next_port <= last_port); rte_spinlock_unlock(&rte_eth_dev_cb_lock); return ret; diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 341c2d6..ff783fe 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1137,6 +1137,8 @@ struct rte_eth_dcb_info { struct rte_eth_dev; +#define RTE_ETH_ALL RTE_MAX_ETHPORTS + struct rte_eth_dev_callback; /** @internal Structure to keep track of registered callbacks */ TAILQ_HEAD(rte_eth_dev_cb_list, rte_eth_dev_callback); @@ -3536,10 +3538,11 @@ typedef int (*rte_eth_dev_cb_fn)(uint16_t port_id, /** - * Register a callback function for specific port id. + * Register a callback function for port id event. * * @param port_id * Port id. + * RTE_ETH_ALL means register the event for all port ids. * @param event * Event interested. * @param cb_fn @@ -3556,10 +3559,11 @@ int rte_eth_dev_callback_register(uint16_t port_id, rte_eth_dev_cb_fn cb_fn, void *cb_arg); /** - * Unregister a callback function for specific port id. + * Unregister a callback function for port id event. * * @param port_id * Port id. + * RTE_ETH_ALL means unregister the event for all port ids. * @param event * Event interested. * @param cb_fn -- 1.8.3.1