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 BC90A42BA9; Fri, 26 May 2023 11:03:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 923DB40DDA; Fri, 26 May 2023 11:03:25 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mails.dpdk.org (Postfix) with ESMTP id 3AC6940A89; Fri, 26 May 2023 11:03:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685091804; x=1716627804; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1+PkXqKx2QjBGPHnTH3deR6UDl49YYcD/gWUO8ih4yQ=; b=k1S590y90IXjIsovaGcWAzvK0Qsb6JBroDqFQeCSqW2kTPoU6JtZ9TH1 /hk4KnTX00aKLPZfA/t/5/MCEd5hcyAARW0xGCMrlo/o5ErzRDB1cCTsS zkCZbFmUUW9FxM1mXwr86czCH7HdMwUYhXz6t17Kz/8mLMEkBkffMbYW2 KSkeWvA2EogSCQKl3AKG3KePK8I67pn9tCqe6SaM1ca4aLF1nPNZH3fZy 44sjMHLw4sQ5bfHxZcArrVnY+0ULsbkAE34sF3FAHvBc0J66gafwkI8kE /B2cOsQmJgHPnHCYajjq8MuL8aJL9Z6e3Kx4c+m9CGR0tx19oV2Ihdqcs w==; X-IronPort-AV: E=McAfee;i="6600,9927,10721"; a="338753326" X-IronPort-AV: E=Sophos;i="6.00,193,1681196400"; d="scan'208";a="338753326" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2023 02:03:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10721"; a="951816875" X-IronPort-AV: E=Sophos;i="6.00,193,1681196400"; d="scan'208";a="951816875" Received: from unknown (HELO localhost.localdomain) ([10.239.252.104]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2023 02:03:20 -0700 From: Kaisen You To: dev@dpdk.org Cc: yidingx.zhou@intel.com, thomas@monjalon.net, david.marchand@redhat.com, olivier.matz@6wind.com, ferruh.yigit@amd.com, kaisenx.you@intel.com, zhoumin@loongson.cn, anatoly.burakov@intel.com, stable@dpdk.org Subject: [PATCH v8] enhance NUMA affinity heuristic Date: Fri, 26 May 2023 16:45:35 +0800 Message-Id: <20230526084535.374803-1-kaisenx.you@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230523025004.192071-1-kaisenx.you@intel.com> References: <20230523025004.192071-1-kaisenx.you@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 When a DPDK application is started on only one numa node, memory is allocated for only one socket. When interrupt threads use memory, memory may not be found on the socket where the interrupt thread is currently located, and memory has to be reallocated on the hugepage, this operation will lead to performance degradation. Fixes: 705356f0811f ("eal: simplify control thread creation") Fixes: 770d41bf3309 ("malloc: fix allocation with unknown socket ID") Cc: stable@dpdk.org Signed-off-by: Kaisen You --- Changes since v7: - Update commet, Changes since v6: - New explanation for easy understanding, Changes since v5: - Add comments to the code, Changes since v4: - mod the patch title, Changes since v3: - add the assignment of socket_id in thread initialization, Changes since v2: - add uncommitted local change and fix compilation, Changes since v1: - accomodate for configurations with main lcore running on multiples physical cores belonging to different numa, --- lib/eal/common/eal_common_thread.c | 4 ++++ lib/eal/common/malloc_heap.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 079a385630..22480aa61f 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -252,6 +252,10 @@ static int ctrl_thread_init(void *arg) struct rte_thread_ctrl_params *params = arg; __rte_thread_init(rte_lcore_id(), cpuset); + /* Set control thread socket ID to SOCKET_ID_ANY as control + * threads may be scheduled on any NUMA node. + */ + RTE_PER_LCORE(_socket_id) = SOCKET_ID_ANY; params->ret = rte_thread_set_affinity_by_id(rte_thread_self(), cpuset); if (params->ret != 0) { __atomic_store_n(¶ms->ctrl_thread_status, diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c index d25bdc98f9..d833a71e7a 100644 --- a/lib/eal/common/malloc_heap.c +++ b/lib/eal/common/malloc_heap.c @@ -716,7 +716,16 @@ malloc_get_numa_socket(void) if (conf->socket_mem[socket_id] != 0) return socket_id; } - + /* We couldn't find quickly find a NUMA node where memory was available, + * so fall back to using main lcore socket ID. + */ + socket_id = rte_lcore_to_socket_id(rte_get_main_lcore()); + /* Main lcore socket ID may be SOCKET_ID_ANY in cases when main lcore + * thread is affinitized to multiple NUMA nodes. + */ + if (socket_id != (unsigned int)SOCKET_ID_ANY) + return socket_id; + /* Failed to find meaningful socket ID, so just use the first one available */ return rte_socket_id_by_idx(0); } -- 2.25.1