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 C2D43A0093; Mon, 2 May 2022 16:11:39 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 64CA640F35; Mon, 2 May 2022 16:11:39 +0200 (CEST) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80072.outbound.protection.outlook.com [40.107.8.72]) by mails.dpdk.org (Postfix) with ESMTP id 29B9540E28 for ; Mon, 2 May 2022 16:11:38 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=duR81varYxrkZRVrMiRCT5l4TYFLdOxDkMqy6fPpX5ihja1Jx6OWRTNQxX5Yr6PggLoxgJueF3saKDI8bGpUtYgzifJ50gZ1sPywKC725lQZCEt+JHAK8tUYU+GpghOS9lUvdwrQM31jBKtMkAwqaoqfLtdXuiHSZPaEi36Wd2UPbc0onCrIr0eF3twMhPppKppAgmz4e9UNUCb4RVwnOVkoRwyducKdIqn2H1LFb5dbuYZXH3ljCDpV+0WUcr332QyPfeexRJHoNKCUceVCHeyC/pRfyjlSuG8oj/tKU+yPf6iU/QSEDpi06eWKuJiRfOnIyMMEbzJdf0AO7m22bQ== 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=muoFmVa+3BCNbXmpIGHSNr5Xjvus3cuTqEnbl8DXxa8=; b=AN6WlfjtKZLrkufgGqvG6g5Di7Pu7ZFJ7ole99GOJTnVQWhWJQDLBiDT9FfRKXIZpk0ZB/Tyj626UVkD6zA8uMRNd0Lat/YI0znAdq3gkJcv1KaCPsY4OXTk6Mzry4eXWyJR8ERWtjXXfd6/LV+24he8xwp3vpWv+nnKZRNbYh2tVEv51ZfODr9oBPY6N+/CUyT4HKaEw0+Y7/7JPgePfzzI084hoCDHkwxHDvBocQWmbw58qAyNIp/C6EcyUP0eWDfdKPBXOlFgMzf2xFQO3t2y+udlZMO4jHdD2JvqMVdnE3QmonrVc/Q375qlnHRuF6olSAHTQDBINlmb9bFBlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=xsightlabs.com; dmarc=pass action=none header.from=xsightlabs.com; dkim=pass header.d=xsightlabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xsightlabs.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=muoFmVa+3BCNbXmpIGHSNr5Xjvus3cuTqEnbl8DXxa8=; b=OVjZVJm0qzJrpaCwG3xIiK4A+zgggz0dZCEjQH3870KbCd3atrs4WCpemuY7YellzQKvAX4RuZGR933Mluaoq6+B9BqXSJuzQ7BUKJlFcDuVTGvvB6dR1LUrrMDVfW1cX/1RDRgRlIjnWC+1YmphnN0mqAHUMlbTFVrP7kCwp0E= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=xsightlabs.com; Received: from DB9P193MB1482.EURP193.PROD.OUTLOOK.COM (2603:10a6:10:2a6::7) by DU2P193MB2002.EURP193.PROD.OUTLOOK.COM (2603:10a6:10:2fa::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14; Mon, 2 May 2022 14:11:37 +0000 Received: from DB9P193MB1482.EURP193.PROD.OUTLOOK.COM ([fe80::3c11:328c:a5e5:7253]) by DB9P193MB1482.EURP193.PROD.OUTLOOK.COM ([fe80::3c11:328c:a5e5:7253%5]) with mapi id 15.20.5206.024; Mon, 2 May 2022 14:11:37 +0000 From: Don Wallwork To: dev@dpdk.org Cc: donw@xsightlabs.com, stephen@networkplumber.org, mb@smartsharesystems.com, anatoly.burakov@intel.com, dmitry.kozliuk@gmail.com, bruce.richardson@intel.com, Honnappa.Nagarahalli@arm.com, nd@arm.com Subject: [PATCH] eal: allow worker lcore stacks to be allocated from hugepage memory Date: Mon, 2 May 2022 10:10:58 -0400 Message-Id: <20220502141058.12707-1-donw@xsightlabs.com> X-Mailer: git-send-email 2.17.1 Content-Type: text/plain X-ClientProxiedBy: MN2PR16CA0037.namprd16.prod.outlook.com (2603:10b6:208:234::6) To DB9P193MB1482.EURP193.PROD.OUTLOOK.COM (2603:10a6:10:2a6::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e00900df-31cd-4e70-4020-08da2c45ab84 X-MS-TrafficTypeDiagnostic: DU2P193MB2002:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GUQ27ROMEJHglVEs+Ll4xGPIx+fm1D501mvZ7WmIIhggztg2BncWPYeRte2toL0pqc84zGg3PpAAO56mNIPd+YUcgS2kwagGBRU+pyeTL/sOC9LpH+yNPp2FVDVqzDF5UXGn4nJsgtlrkadFMakGejlQwtdlDx1DmP4UT9tIfDa+OVpw+XovXxqYEK5FJnqvh1/khlbs1X3B+TfoJA3JViNL1wNRKrOE8uCHJTGxDTew/Kj98IwuSJYB74LS9NC0AVgcreuE2nHN96OSoARhMeqAL7ic6Xib7hvLSe0LOQ9jN12IC6YT3nbs/KR3eE8zxMkVeymmJnDF0YNGENTe0Hl5cs+WdKVxxVRvmbyaTHCSgbdVPZiZDM9tty4xWz9FsuCEQKexQYlMnqWvLdF4odil6JnVmvsgB8H7R7t/nFfaGeo/4rj1wcykRruKQF0jnLc5YTcRhnwBTIWGrwi5CtzqnzPwL0CPo1Gvzk1eqfst/2Ux2EFAkuyWr1MeAK5pra+cOui8YpO98jR437DzKJudf6OEttIZ7v6uph3R5M9/jNn3T+qYXyGi2NS4X8yyR8OrV58KMV8AAQpbCrPpnIsRzUu11f2+uBSxeI6IGDv4EWIWnHxf7Y4jht7o5ORoHMJ4uTvUfg61COaO10mZGCSpo/zhiErKHZCCY95R5M9KehcvWvF7hKnKFrZd7m6D7J5hnjsuitEylu9L2YMGtA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9P193MB1482.EURP193.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(66946007)(66556008)(66476007)(8676002)(186003)(1076003)(2616005)(36756003)(5660300002)(4326008)(8936002)(6512007)(26005)(508600001)(6506007)(6486002)(6916009)(6666004)(52116002)(38100700002)(38350700002)(86362001)(2906002)(316002)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?HH83Lm7X2akHATMNeY1T0fuCo+MrzPQG9gBmBHVcxogJ2BmQgGiHw/GP+A11?= =?us-ascii?Q?QMqqFXZiA5Tha3XZrBvBvV0oxRkk47b2H1HT4i5RA8RJ0WQ3vzKwfZctEXsS?= =?us-ascii?Q?TsNximISSJyBieFy2o0aLQVU+IrrvMS1oBYLKCb5+EyfG2v36r4+4dqZB0Jf?= =?us-ascii?Q?mZsiLxW6NrKBL5VFvbbWp+bNcPeRYXpu84ds3Js8QnUb1sfGZGL7zojk4V/E?= =?us-ascii?Q?vjMZWBBljc56ZnMFu6h0QN1MxL56TWLimjcPvtQvMQ4CV9ijIO/bn1ULhkWK?= =?us-ascii?Q?tzoo6SjDmJQteMPNMmRPF//9Ivjyju0/4DJa9vhFq6k1+IJlRYIPjXxSetFx?= =?us-ascii?Q?HCY8JbTCWviD3OwXV9OIvt+SalbQOpq9iiwpWPkgjAXVdeyuh4k3xDw1hT/4?= =?us-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rHMV9ioEQcy4?= =?us-ascii?Q?VOEZikep4Mx+nyyzdH0YX3ZIwycoQPtTcW0/R4qS1s1cEW7eyuO9lf4SsSFO?= =?us-ascii?Q?rMlMSc05fQMzHndDyRAN0Tvo+y145r1nbu9xg6atgZUMUyBaF4f2CPB/JeAu?= =?us-ascii?Q?At6fLtsJzHr0RkDDY+2OjiyYDR82RjP7nChdd8ktbZYlpzMd1lbtNUrmQXEy?= =?us-ascii?Q?PgKhsfanC6hm8sSLKdeoY0JTmFK5Q68MCfLWRaT9NGoyBfhODaWMREaOaHMZ?= =?us-ascii?Q?zfVjZcPjYLUISSP6dOGaWLXaBpTfAi4nFhCFx+DYn5jpwQ0RDPHaTZN/bemI?= =?us-ascii?Q?6nlOAuqd6Q1QFHYS63ZoJcz9TOQyIykPgGGKyhIg/DI8aJTPo3riQvaKSrbI?= =?us-ascii?Q?XEQsGYGZOUUYAkcEWNKto9qLKi0UJ08ERBdyvAYcfGOWIebArjmprq5Phr17?= =?us-ascii?Q?qHU9Gq6Dpw=3D=3D?= X-OriginatorOrg: xsightlabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: e00900df-31cd-4e70-4020-08da2c45ab84 X-MS-Exchange-CrossTenant-AuthSource: DB9P193MB1482.EURP193.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 May 2022 14:11:36.9689 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 646a3e34-83ea-4273-9177-ab01923abaa9 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ehAH8Fomev2zUKJy5j9rcm6DlJa1f4bQVseHAVSfnbFWl6e69a8iv+xxVEoTzh6fsknzSzRHDZeT3Psupad9PA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2P193MB2002 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 Add support for using hugepages for worker lcore stack memory. The intent is to improve performance by reducing stack memory related TLB misses and also by using memory local to the NUMA node of each lcore. EAL option '--huge-worker-stack [stack-size-kbytes]' is added to allow the feature to be enabled at runtime. If the size is not specified, the system pthread stack size will be used. Signed-off-by: Don Wallwork --- lib/eal/common/eal_common_options.c | 31 ++++++++++++++ lib/eal/common/eal_internal_cfg.h | 4 ++ lib/eal/common/eal_options.h | 2 + lib/eal/linux/eal.c | 65 ++++++++++++++++++++++++++++- 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index f247a42455..be9db9ee37 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -103,6 +103,7 @@ eal_long_options[] = { {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM }, {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM }, {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM}, + {OPT_HUGE_WORKER_STACK, 2, NULL, OPT_HUGE_WORKER_STACK_NUM }, {0, 0, NULL, 0 } }; @@ -1618,6 +1619,22 @@ eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out) return -1; } +static int +eal_parse_huge_worker_stack(const char *arg, size_t *huge_worker_stack_size) +{ + size_t worker_stack_size; + if (arg == NULL) { + *huge_worker_stack_size = USE_OS_STACK_SIZE; + return 0; + } + worker_stack_size = atoi(arg); + if (worker_stack_size == 0) + return -1; + + *huge_worker_stack_size = worker_stack_size * 1024; + return 0; +} + int eal_parse_common_option(int opt, const char *optarg, struct internal_config *conf) @@ -1921,6 +1938,15 @@ eal_parse_common_option(int opt, const char *optarg, } break; + case OPT_HUGE_WORKER_STACK_NUM: + if (eal_parse_huge_worker_stack(optarg, + &conf->huge_worker_stack_size) < 0) { + RTE_LOG(ERR, EAL, "invalid parameter for --" + OPT_HUGE_WORKER_STACK"\n"); + return -1; + } + break; + /* don't know what to do, leave this to caller */ default: return 1; @@ -2235,5 +2261,10 @@ eal_common_usage(void) " --"OPT_NO_PCI" Disable PCI\n" " --"OPT_NO_HPET" Disable HPET\n" " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n" + " --"OPT_HUGE_WORKER_STACK"[=size]\n" + " Allocate worker thread stacks from\n" + " hugepage memory. Size is in units of\n" + " kbytes and defaults to system thread\n" + " stack size if not specified.\n" "\n", RTE_MAX_LCORE); } diff --git a/lib/eal/common/eal_internal_cfg.h b/lib/eal/common/eal_internal_cfg.h index b71faadd18..6a43c872fc 100644 --- a/lib/eal/common/eal_internal_cfg.h +++ b/lib/eal/common/eal_internal_cfg.h @@ -48,6 +48,9 @@ struct hugepage_file_discipline { bool unlink_existing; }; +/** Worker hugepage stack size should default to OS value. */ +#define USE_OS_STACK_SIZE ((size_t)~0) + /** * internal configuration */ @@ -102,6 +105,7 @@ struct internal_config { unsigned int no_telemetry; /**< true to disable Telemetry */ struct simd_bitwidth max_simd_bitwidth; /**< max simd bitwidth path to use */ + size_t huge_worker_stack_size; /**< worker thread stack size in bytes */ }; void eal_reset_internal_config(struct internal_config *internal_cfg); diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 8e4f7202a2..3cc9cb6412 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -87,6 +87,8 @@ enum { OPT_NO_TELEMETRY_NUM, #define OPT_FORCE_MAX_SIMD_BITWIDTH "force-max-simd-bitwidth" OPT_FORCE_MAX_SIMD_BITWIDTH_NUM, +#define OPT_HUGE_WORKER_STACK "huge-worker-stack" + OPT_HUGE_WORKER_STACK_NUM, OPT_LONG_MAX_NUM }; diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 1ef263434a..e8c872ef7b 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -1144,8 +1144,69 @@ rte_eal_init(int argc, char **argv) lcore_config[i].state = WAIT; /* create a thread for each lcore */ - ret = pthread_create(&lcore_config[i].thread_id, NULL, - eal_thread_loop, (void *)(uintptr_t)i); + if (internal_conf->huge_worker_stack_size == 0) { + ret = pthread_create(&lcore_config[i].thread_id, NULL, + eal_thread_loop, + (void *)(uintptr_t)i); + } else { + /* Allocate NUMA aware stack memory and set + * pthread attributes + */ + pthread_attr_t attr; + size_t stack_size; + void *stack_ptr; + + if (pthread_attr_init(&attr) != 0) { + rte_eal_init_alert("Cannot init pthread " + "attributes"); + rte_errno = EFAULT; + return -1; + } + if (internal_conf->huge_worker_stack_size == + USE_OS_STACK_SIZE) { + if (pthread_attr_getstacksize(&attr, + &stack_size) != 0) { + rte_errno = EFAULT; + return -1; + } + } else { + stack_size = + internal_conf->huge_worker_stack_size; + } + stack_ptr = + rte_zmalloc_socket("lcore_stack", + stack_size, + stack_size, + rte_lcore_to_socket_id(i)); + + if (stack_ptr == NULL) { + rte_eal_init_alert("Cannot allocate stack " + "memory for worker lcore"); + rte_errno = ENOMEM; + return -1; + } + + if (pthread_attr_setstack(&attr, + stack_ptr, + stack_size) != 0) { + rte_eal_init_alert("Cannot set pthread " + "stack attributes"); + rte_errno = EFAULT; + return -1; + } + + /* create a thread for each lcore */ + ret = pthread_create(&lcore_config[i].thread_id, &attr, + eal_thread_loop, + (void *)(uintptr_t)i); + + if (pthread_attr_destroy(&attr) != 0) { + rte_eal_init_alert("Cannot destroy pthread " + "attributes"); + rte_errno = EFAULT; + return -1; + } + } if (ret != 0) rte_panic("Cannot create thread\n"); -- 2.17.1