From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E6AF9A04FF; Tue, 24 May 2022 13:43:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CCE9A40140; Tue, 24 May 2022 13:43:57 +0200 (CEST) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2058.outbound.protection.outlook.com [40.107.237.58]) by mails.dpdk.org (Postfix) with ESMTP id 12829400D6 for ; Tue, 24 May 2022 13:43:57 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZbCAll6x3t05E3B4/QUve/aOfo7obbGTJi5+6osKJFpKYzTek9dMQsYkOb33cmmaq6INd70B8bChzIgDsuYW0ENvH6Qnz80YfD9HcXw8izZFYg4hMmbz/Gf7Ie7Ik6HesR+mYbjprzhV5F+/hOAkam/sNXWuTXD3xwFaHoyS6YSlfRSUm46srcfnNNpNsBu0gxzS6iQ880urg7a4lTCyIPNnb/ZbJIiFC7Jh/ISDaC7ajIxZAMSodz9y1uTe+v5m9vLKaaq5jfi5+dAQMztz3IIkxc2NipHFMy0ZJkGJGGOv9M0p77tOLRaNNvRZpQepdLDEcfM//vDHh58ciIrC3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0lbBRuqIPrZskNa0QEfCEnZr+aPjH4Hkq1DpS8SLczM=; b=QIoONKNM67BS/GwLiHsjr5ezMiSm32j1ypxLHxRvZKSkcah462a/TAUSgzhagP+zBjSCcJADSTo939WNl8rPfEX9vT3FPD7qcAG8dfGuGTEAvPW9m1MLFDbzfGDlQlIUHoS37C/xl41S4iKsfkhuUs6m0aYgQj0GJnJ2HlwjhPLLOQrJrdoWllauL8vqrP1UG/kS00iFH0w1t1HeERJbLrMNlla1HPEa/L7tLD9sFkWdpdZ6Hli+qZZtr3bwzWxO5V4iK69zeKboY849c3zUD8VcMjq+QYBk0xP34jRWuwbLk2/q7n25hCTCcaC0kY/su4uNrsZSOjWGfYCjIN+vyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=softfail (sender ip is 149.199.80.198) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=fail (p=quarantine sp=quarantine pct=100) action=quarantine header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0lbBRuqIPrZskNa0QEfCEnZr+aPjH4Hkq1DpS8SLczM=; b=sas6eUW9FPpdcNGjj5TvCFctiUfz3Tdl4ujUG24wAAVytKTWdA3niAXA6aJ4JzXZiqSX59fazYv0AM/yZK5GyD3H86h5aTSPtnRdn1cTqkCG9UfInDqJrB5DktXAKH5NUvXn+YaC5fDVDXZx6TUQomP3xIQ8yekiEcTjKjwhJ38= Received: from BN6PR1101CA0016.namprd11.prod.outlook.com (2603:10b6:405:4a::26) by DM8PR02MB8293.namprd02.prod.outlook.com (2603:10b6:8:f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.15; Tue, 24 May 2022 11:43:55 +0000 Received: from BN1NAM02FT011.eop-nam02.prod.protection.outlook.com (2603:10b6:405:4a:cafe::e6) by BN6PR1101CA0016.outlook.office365.com (2603:10b6:405:4a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5293.13 via Frontend Transport; Tue, 24 May 2022 11:43:55 +0000 X-MS-Exchange-Authentication-Results: spf=softfail (sender IP is 149.199.80.198) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=fail action=quarantine header.from=amd.com; Received-SPF: SoftFail (protection.outlook.com: domain of transitioning amd.com discourages use of 149.199.80.198 as permitted sender) Received: from xir-pvapexch01.xlnx.xilinx.com (149.199.80.198) by BN1NAM02FT011.mail.protection.outlook.com (10.13.2.129) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5273.14 via Frontend Transport; Tue, 24 May 2022 11:43:55 +0000 Received: from xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.14; Tue, 24 May 2022 12:43:54 +0100 Received: from smtp.xilinx.com (172.21.105.197) by xir-pvapexch01.xlnx.xilinx.com (172.21.17.15) with Microsoft SMTP Server id 15.1.2176.14 via Frontend Transport; Tue, 24 May 2022 12:43:54 +0100 Envelope-to: david.marchand@redhat.com, dev@dpdk.org, thomas@monjalon.net, andrew.rybchenko@oktetlabs.ru, xiaoyun.li@intel.com, aman.deep.singh@intel.com, yuying.zhang@intel.com, bruce.richardson@intel.com Received: from [10.71.116.115] (port=37757) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1ntSx8-0006px-3W; Tue, 24 May 2022 12:43:54 +0100 Message-ID: <63b3fadd-f700-ae30-8174-102d91a0794d@amd.com> Date: Tue, 24 May 2022 12:43:53 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH 2/6] app/testpmd: register driver specific commands Content-Language: en-US To: David Marchand CC: dev , Thomas Monjalon , Andrew Rybchenko , Xiaoyun Li , Aman Singh , Yuying Zhang , Bruce Richardson References: <20220513075718.18674-1-david.marchand@redhat.com> <20220523071031.1868862-1-david.marchand@redhat.com> <20220523071031.1868862-3-david.marchand@redhat.com> From: Ferruh Yigit In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3e51e2e0-3c51-45e2-9ffe-08da3d7aaedf X-MS-TrafficTypeDiagnostic: DM8PR02MB8293:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 2 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Qrx0U4w60V7ObTk3inziVX42/SKvoNQcQa4ewhNketgMCcLCW8jZFoBdoguZTo6yMuEIE1ATKn07O/9f00AN944efj8MKnzbXQBeU7hqnrJ3KNQD2HM+vVSN4XQ/YaqVw3P9SOHYBWvviVjzEahG2n239bER5LVu6dKSgaoTqYR+0xxy2yIYlSEQw4Kw48wSrOovBgI58y1TwCsax9BvWZx/NuKqxKHsSGdHgxfZVoD5Fxmr+cL/4pcrprO7x5332HeMj3x1LumeOoX6eeH7EC8DuWxpjKmPC157OGNli7A4d4/yp3C3VgKZ4ULNy4pScua7WzBvyKtDZQW4SgHDyHS1IhNwy8BfRFekzcL7x3FoXUSfef/XOeCqxF22Tlbgn+cylo6rDfNkpGYGXn1Zp4dTJb+Uo5NDV3q/O4cFHGj4Lwe15Mj3hVQWPKXmKqkCVYbgGlLDSlBYjf2bWSzMHDRSl8xYVFzg7fuKPeIfjdLplV+Xh2DFByZTdD/LAAwV6VgBacDw6+9Ev0f5rLuLwuLnTJEfA0h2Kzw+xNmzMblWTcGHOL4a1p/VWvDYB6+K5KgnPhIZ7qB+mSJox0jtBc4ykPrGc47aCZUk7Q84bhSCnITCvFFGYdciN8qFw1Lw01eavZsRDU5SmEODnWfK79WBBllLWudhsqzPgeDe/DgKIsiWwGZZ1WX/ZFD0w5d12z2Ua6OiUjAfXt4LbpG3wtolQXq+MfFCN5Gb5zXBaFQ= X-Forefront-Antispam-Report: CIP:149.199.80.198; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:xir-pvapexch01.xlnx.xilinx.com; PTR:unknown-80-198.xilinx.com; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(70586007)(4326008)(70206006)(8676002)(44832011)(2906002)(31696002)(356005)(7636003)(9786002)(8936002)(336012)(5660300002)(47076005)(508600001)(40460700003)(2616005)(26005)(53546011)(86362001)(316002)(6916009)(54906003)(35950700001)(82310400005)(36756003)(31686004)(50156003)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.onmicrosoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 May 2022 11:43:55.3666 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e51e2e0-3c51-45e2-9ffe-08da3d7aaedf X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.80.198]; Helo=[xir-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: BN1NAM02FT011.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR02MB8293 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 5/24/2022 11:53 AM, David Marchand wrote: > [CAUTION: External Email] > > On Mon, May 23, 2022 at 8:10 PM Ferruh Yigit wrote: >> >> On 5/23/2022 8:10 AM, David Marchand wrote: >>> +int >>> +init_cmdline(void) >>> +{ >>> + struct testpmd_commands *c; >>> + cmdline_parse_ctx_t *ctx; >>> + unsigned int count = 0; >>> + unsigned int i; >>> + >>> + /* initialize non-constant commands */ >>> + cmd_set_fwd_mode_init(); >>> + cmd_set_fwd_retry_mode_init(); >>> + >>> + main_ctx = NULL; >>> + for (i = 0; builtin_ctx[i] != NULL; i++) { >>> + ctx = realloc(main_ctx, (count + i + 1) * sizeof(*ctx)); >>> + if (ctx == NULL) >>> + goto err; >>> + main_ctx = ctx; >> >> Instead of 'realloc()', check and assign pointer in each entry, what do >> you think about first calculate the size and alloc once, both for >> 'builtin_ctx' & driver specific command? >> But of course trade off is to loop twice in that case. > > Yes, I hesitated because of the duplicated loop (and I found no > "elegant" macro). > I'm ok with the suggestion, this makes the code simpler. > > > int > init_cmdline(void) > { > struct testpmd_commands *c; > unsigned int count; > unsigned int i; > > /* initialize non-constant commands */ > cmd_set_fwd_mode_init(); > cmd_set_fwd_retry_mode_init(); > > count = 0; > for (i = 0; builtin_ctx[i] != NULL; i++, count++) > ; > TAILQ_FOREACH(c, &commands_head, next) { > for (i = 0; c->commands[i].ctx != NULL; i++, count++) > ; > } > > /* cmdline expects a NULL terminated array */ > main_ctx = calloc(count + 1, sizeof(main_ctx[0])); > if (main_ctx == NULL) > return -1; > > count = 0; > for (i = 0; builtin_ctx[i] != NULL; i++, count++) > main_ctx[count] = builtin_ctx[i]; > TAILQ_FOREACH(c, &commands_head, next) { > for (i = 0; c->commands[i].ctx != NULL; i++, count++) > main_ctx[count] = c->commands[i].ctx; > } > > return 0; > } > ack