From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3CEE4A04DF; Tue, 11 Aug 2020 22:13:34 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 782FE1C022; Tue, 11 Aug 2020 22:13:33 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 1E8D32BFA for ; Tue, 11 Aug 2020 22:13:31 +0200 (CEST) IronPort-SDR: sLwdrPfTRytnsijmQ/vWP85QzPa2r4nrlyZGt6IqKi22sZE3FinEWSSxrL6TPimy9G6nHz/sR9 fw/u0CMgAcoA== X-IronPort-AV: E=McAfee;i="6000,8403,9710"; a="133360761" X-IronPort-AV: E=Sophos;i="5.76,301,1592895600"; d="scan'208";a="133360761" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Aug 2020 13:13:31 -0700 IronPort-SDR: 4h5byBNYGxAB//Nx4ExkPppb0jF5MJPfBnynOPYXK8Yh7oBZiE+T4QF0wmsKLvN0RX0gFCbcmk ZovDEkF6+tKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,301,1592895600"; d="scan'208";a="276383232" Received: from orsmsx606-2.jf.intel.com (HELO ORSMSX606.amr.corp.intel.com) ([10.22.229.86]) by fmsmga007.fm.intel.com with ESMTP; 11 Aug 2020 13:13:30 -0700 Received: from orsmsx606.amr.corp.intel.com (10.22.229.19) by ORSMSX606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 11 Aug 2020 13:13:30 -0700 Received: from orsmsx113.amr.corp.intel.com (10.22.240.9) by orsmsx606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Tue, 11 Aug 2020 13:13:30 -0700 Received: from ORSEDG001.ED.cps.intel.com (10.7.248.4) by ORSMSX113.amr.corp.intel.com (10.22.240.9) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 11 Aug 2020 13:13:29 -0700 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.168) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 11 Aug 2020 13:13:25 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jqWxeY5306xAY/ZP/DAWeDzGLDD6cxwI0mk4kdNlGZetqZIRCDIFquG+8KsPyKpk10az0umkGS3jIgjHDHBbVukVvi+YaZwEupIYVLi4Cz9x9wWkiUXNmlMJcbhRFvPr62oDtEnO1W+0yRYg5cgQdq5YU6gcIv9YbPuvXcFuu0l/FV4iDArcZxXFmhKoHWYzjT6izaOgcpX26CzVA5xQlfXn/VV3yYFksm2hEI1QzQQsPMCQ1AvcqZZZlhp5vRkhxFt5ya/XoRPp4CQuavag2LfEtukH6+K5H3FXQDxxY3lGVAN9MbOIcvHAhXNaOXHid6F8XhaF27QUZM/KAvfOOA== 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-SenderADCheck; bh=FvVP6x4FFQ0AQXArz702qkKPG3OaKgPowzGQYwJAIj0=; b=hKOVS90rrKzTCBuAWTG3aLnnuji8yet84DIPUodL8vhdIrf5J7FG/u7ZfZ72N4prcTp//PCDY0G7mo5Ajmj9if9FcWhv6i3lfHsXfD3KdcKhf74reMPp4Ek+qxZIZq7Z7lm+rakcu1JQHKUjjgHzncdAixfkjV3gamHiMGBazSDcu7rJrJkyq7aWa7e6LYb/9x1FmvVD+b5rP4NowYiytEpjI09s/A6Bv8y24O0h2FjEXr0fVPIUzLheQSfDwGGFd66sfuhrsgjjVRZqoCMdSGggYm+v7YOt5HZjh079Mw2vfgoP/N+pRyhelDDGALii8g6WzW6wmU/oQVU8s59zTg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FvVP6x4FFQ0AQXArz702qkKPG3OaKgPowzGQYwJAIj0=; b=GTKufwAVN9zRuqT74VAWFwtD/Mxt8z3oTplHDgnBp/qj2VIg2QiGaw0xsighN6yNtKqC6kBSwrBGaDlAXn6jXhspO2Fjr4Yk/+7v5Lh1kcoS4nzbZzgnImnRek0ukNK4Cb8NdB8Xlqdre/0QutvGWNsMKBz8yYSvqd519Ef3/LU= Received: from SN6PR11MB2574.namprd11.prod.outlook.com (2603:10b6:805:59::14) by SN6PR11MB3423.namprd11.prod.outlook.com (2603:10b6:805:db::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.16; Tue, 11 Aug 2020 20:13:24 +0000 Received: from SN6PR11MB2574.namprd11.prod.outlook.com ([fe80::54:b143:c75e:41bd]) by SN6PR11MB2574.namprd11.prod.outlook.com ([fe80::54:b143:c75e:41bd%7]) with mapi id 15.20.3261.025; Tue, 11 Aug 2020 20:13:24 +0000 From: "Eads, Gage" To: Steven Lariau , Olivier Matz CC: "dev@dpdk.org" , "honnappa.nagarahalli@arm.com" , "dharmik.thakkar@arm.com" , "nd@arm.com" Thread-Topic: [PATCH 1/4] test/stack: avoid trivial memory allocations Thread-Index: AQHWa0FByAdNTBStI0ek3KNmWSaOx6kzWGDQ Date: Tue, 11 Aug 2020 20:13:24 +0000 Message-ID: References: <20200805155721.19808-1-steven.lariau@arm.com> <20200805155721.19808-2-steven.lariau@arm.com> In-Reply-To: <20200805155721.19808-2-steven.lariau@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.5.1.3 dlp-product: dlpe-windows dlp-reaction: no-action authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [68.203.30.51] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d3a0fbb0-d44c-43ec-572f-08d83e330054 x-ms-traffictypediagnostic: SN6PR11MB3423: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:281; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: leSPjjKVrV++5DQnO0owFdS7u9Yj+ZsUHkeZddtyOdQpiZ8gjgxDVGxQLlnYfD2cBJW2AfclBWd7uR308QiP4o6uRfKi9ayRAxiXDmO9GbGmKWuvsuTROtG7S7ya22YSy4biu8ZWVlIzIaQYa29b74fjNbciRLGZ+GdD30afci7i2kBbi1Hv8lQNYYX5R95rZBMulRPhEX7R8UzT8HR+YOHxrAHugP7JQuP+EpjSLKyPBRjLc/VUI7Kje4KWByGVmot7y0yZiGktNissnYvavjpSIdGVHKoGVPQRMuytyayxSvAbnxUfFoet+Zi6Qhyv x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR11MB2574.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(346002)(376002)(396003)(366004)(39860400002)(136003)(52536014)(5660300002)(2906002)(110136005)(316002)(6506007)(8936002)(54906003)(186003)(53546011)(7696005)(26005)(33656002)(478600001)(4326008)(83380400001)(9686003)(64756008)(76116006)(66946007)(66446008)(8676002)(66556008)(66476007)(55016002)(71200400001)(86362001); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: 0eZcZUnnII3zZ0XksmEq2AugK0k02QiJvLYJtRgcnKeXrwVT70zvrn5Vyplx/sn4Xggbb7vW1Z5fMM5wG46syz5SUeEEHMGhah5GeqBTDCqK4O6WFR4+duhOhLZ4rRE0RSpbHOBP/41eYdSIPpCRn2XeXa/sm6hEPdSbyhOz2RnBK4ICRT/LtYPFh4vufM+XtFdDHLRNarKLVhyClawLK0vf877TYSqvGv/Eho7wOHszd3PMVhGHG9Eb/wp102MlbW6OwEpoakz3yZgCMOCgQ07p9OGj6H+jlmp6zztb25ewyAjitDDvJUCJgIN1MhzBh7/tw0TTJcKsF4KCm9I4sNXbyiqhkh3hXZhQmC1kPT+AD93hTNyY9GrBMWhqpmEg4d9SiHYIjAObFEgDiI6kEHrloIiTX/7RbLY/FS8h1gSKTf4dsd/9QPQBrq0BJKC4pD2WUtiY7+kkdIS5IbvREYWOF++4RzcR4khkP+j8GvTOyTjfv1sAe9192cBlN0TxVv00l4vOGi/X018DSc+Wo+53ViPgsK84/nJAPbA1yVpSnOmmR8vfBlMwEHf8fEpYWh5io/in8SNWaLOWey4pjCSb20SYHwAT4iM8Y7oINoV6y58GrVEgUYjSYsCa/fkBXff4DkTuz5ZLhvJ8OYIIig== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2574.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d3a0fbb0-d44c-43ec-572f-08d83e330054 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Aug 2020 20:13:24.1127 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: VGf4k4OWsyOCffB4uWI1fhZzfQzalGQHY1klt6aGCYgMViq/14UWso7aZedH4SfynMx6q877pINLkAm3VhMnkQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3423 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH 1/4] test/stack: avoid trivial memory allocations 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Steven, > -----Original Message----- > From: Steven Lariau > Sent: Wednesday, August 5, 2020 10:57 AM > To: Eads, Gage ; Olivier Matz > > Cc: dev@dpdk.org; honnappa.nagarahalli@arm.com; > dharmik.thakkar@arm.com; nd@arm.com; Steven Lariau > > Subject: [PATCH 1/4] test/stack: avoid trivial memory allocations >=20 > Replace the arguments array by one argument. > All objects in the args array have the same values, so there is no need > to use an array, only one struct is enough. > The args object is a lot smaller, and the allocation can be replaced > with a stack variable. >=20 > The allocation of obj_table isn't needed either, because MAX_BULK is > small. The allocation can instead be replaced with a static array. >=20 > Signed-off-by: Steven Lariau > Reviewed-by: Dharmik Thakkar > Reviewed-by: Phil Yang > Reviewed-by: Ruifeng Wang > --- > app/test/test_stack.c | 39 ++++++--------------------------------- > 1 file changed, 6 insertions(+), 33 deletions(-) >=20 > diff --git a/app/test/test_stack.c b/app/test/test_stack.c > index c8dac1f55..5a7273a7d 100644 > --- a/app/test/test_stack.c > +++ b/app/test/test_stack.c > @@ -280,16 +280,9 @@ static int > stack_thread_push_pop(void *args) > { > struct test_args *t =3D args; > - void **obj_table; > + void *obj_table[MAX_BULK]; > int i; >=20 > - obj_table =3D rte_calloc(NULL, STACK_SIZE, sizeof(void *), 0); > - if (obj_table =3D=3D NULL) { > - printf("[%s():%u] failed to calloc %zu bytes\n", > - __func__, __LINE__, STACK_SIZE * sizeof(void *)); > - return -1; > - } > - > for (i =3D 0; i < NUM_ITERS_PER_THREAD; i++) { > unsigned int success, num; >=20 > @@ -310,28 +303,25 @@ stack_thread_push_pop(void *args) > if (rte_stack_push(t->s, obj_table, num) !=3D num) { > printf("[%s():%u] Failed to push %u pointers\n", > __func__, __LINE__, num); > - rte_free(obj_table); > return -1; > } >=20 > if (rte_stack_pop(t->s, obj_table, num) !=3D num) { > printf("[%s():%u] Failed to pop %u pointers\n", > __func__, __LINE__, num); > - rte_free(obj_table); > return -1; > } >=20 > rte_atomic64_sub(t->sz, num); > } >=20 > - rte_free(obj_table); > return 0; > } Agreed, the dynamic allocation is unnecessary. >=20 > static int > test_stack_multithreaded(uint32_t flags) > { > - struct test_args *args; > + struct test_args args; > unsigned int lcore_id; > struct rte_stack *s; > rte_atomic64_t size; > @@ -344,45 +334,28 @@ test_stack_multithreaded(uint32_t flags) > printf("[%s():%u] Running with %u lcores\n", > __func__, __LINE__, rte_lcore_count()); >=20 > - args =3D rte_malloc(NULL, sizeof(struct test_args) * RTE_MAX_LCORE, > 0); > - if (args =3D=3D NULL) { > - printf("[%s():%u] failed to malloc %zu bytes\n", > - __func__, __LINE__, > - sizeof(struct test_args) * RTE_MAX_LCORE); > - return -1; > - } > - > s =3D rte_stack_create("test", STACK_SIZE, rte_socket_id(), flags); > if (s =3D=3D NULL) { > printf("[%s():%u] Failed to create a stack\n", > __func__, __LINE__); > - rte_free(args); > return -1; > } >=20 > rte_atomic64_init(&size); > + args.s =3D s; > + args.sz =3D &size; >=20 > RTE_LCORE_FOREACH_SLAVE(lcore_id) { > - args[lcore_id].s =3D s; > - args[lcore_id].sz =3D &size; > - > if (rte_eal_remote_launch(stack_thread_push_pop, > - &args[lcore_id], lcore_id)) > + &args, lcore_id)) > rte_panic("Failed to launch lcore %d\n", lcore_id); > } In general we shouldn't pass a stack variable to other threads. Though your code here looks fine, I'd rather err on the safe side in case this is ever = used as a template/basis for some other code...particularly since there's no performance/correctness/etc. penalty to using dynamically allocated memory. To support patch 2/4, you can instead convert the rte_malloc to allocate a single shared test_args structure. Or perhaps move patch 4 earlier in the s= eries, and simply pass the stack pointer instead. Thanks, Gage