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 0FA5245879; Tue, 27 Aug 2024 17:11:15 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F249640E2D; Tue, 27 Aug 2024 17:11:14 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2043.outbound.protection.outlook.com [40.107.94.43]) by mails.dpdk.org (Postfix) with ESMTP id 3C0B040E19 for ; Tue, 27 Aug 2024 17:11:13 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=knh/5okQca+CXqP49FoH5VOk5lTzL+iCpPJg0Fx0YjUBNikNyzYShMRaUMkGuFQsyOEk/CZZ4cKu/dtMam+sgQcFav0SN2hunrOrFXWmHQFwH7eYWlTdz2ZNkdfKpnjZr5lHLs//N4kTTQ1mS65XQJdBIcTb+lH082lObyanaEVZSrCzUaGRHVK53cVdXa+rtJ45Z398Uh060OS5gBGBfomXVu5tprXFxA8o2VLoM2FT7/FOuYvgTrMDjYt9umXO9qnp0tuuAyyV/vhinDofnPuaP4ruLfqL7Eko3YsUnKvZJE4vRNuPb712v92EUjAmH2cFvpd96BMYoMeJh5/BmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=wasRx+KUxvbVJpRjuIrY0C1nTGuTgQN4L1hoxylDyFk=; b=nSViCAbnXXd7bZvrW4piz13l13Dfvg51ghFm161EWXDadwK8UrI8ftEyarDtd4G+1eZYPBMFhWBV9g0GORiwJcVrqbbX3H+7k5cuVisL+kf/7cO08dU6eTWLQ4/bbUR57/3NAQKCryh9theoV3kSGKr+vYSIGDhXNyTF0GI8sfAnbcGUQdDzrHkRBQYAbvWgCTM4alb1jisMX/MU67WNckqneUrBINt0Lb7ZLeAqyuKfs0iBEJTyi059zUIDE9ZnHn6zIbn92WE2NqBOMqIu5m2qeCVFDx11YWSGaCcfVbJuv7014foiHE7pDZ2OmFhGUZBDknoqrDOQ6fHqhxPcrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=dpdk.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wasRx+KUxvbVJpRjuIrY0C1nTGuTgQN4L1hoxylDyFk=; b=HARc/r1qY+wJQYbCe/ep0YlB72VaY6YckkcpUIElxDs87pJ2cgDoibd5xIKE7UsbyO/0ODrCKMm3nZ68zimJK08GrCWq4J48br6u8mdLNyBVZoZnEBtoXVJWqQ+dB280AELklBvfYT/dPGTa1aQ4PAoYFbnYpY4+O7sPKHZxZMw= Received: from BN8PR15CA0066.namprd15.prod.outlook.com (2603:10b6:408:80::43) by SA1PR12MB6728.namprd12.prod.outlook.com (2603:10b6:806:257::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.26; Tue, 27 Aug 2024 15:11:10 +0000 Received: from BN1PEPF00006000.namprd05.prod.outlook.com (2603:10b6:408:80:cafe::53) by BN8PR15CA0066.outlook.office365.com (2603:10b6:408:80::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.25 via Frontend Transport; Tue, 27 Aug 2024 15:11:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN1PEPF00006000.mail.protection.outlook.com (10.167.243.232) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7918.13 via Frontend Transport; Tue, 27 Aug 2024 15:11:09 +0000 Received: from BLR-5CG134626B.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Tue, 27 Aug 2024 10:11:04 -0500 From: Vipin Varghese To: , Subject: [RFC 1/2] eal: add llc aware functions Date: Tue, 27 Aug 2024 20:40:13 +0530 Message-ID: <20240827151014.201-2-vipin.varghese@amd.com> X-Mailer: git-send-email 2.41.0.windows.3 In-Reply-To: <20240827151014.201-1-vipin.varghese@amd.com> References: <20240827151014.201-1-vipin.varghese@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN1PEPF00006000:EE_|SA1PR12MB6728:EE_ X-MS-Office365-Filtering-Correlation-Id: 5f345f90-ec9e-4386-a494-08dcc6aa7b83 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?u9FZ+pviok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CkPfZhfdAU?= =?us-ascii?Q?jQGKtJy1trvhZ0RYxDA3tZidiDFy4eZszVMVEcVhJnTgitFRCAks2rfOa4ug?= =?us-ascii?Q?3zW4uMc0Dnl4EJOwblQFIFIMA1k3FiDEIpS5eaWZmkq/4ybThH9WUVZoctuN?= =?us-ascii?Q?Lr/RFtDmzPx4RZ7hNMKyH+/NTR3pwMc7ocuCoMqY+hWEPw1puGCn9zSzPAMH?= =?us-ascii?Q?gIqJpNjb03KO4xTSlBN75etZ8Qd1lKA5mlsbbevjiD+Ya8j/WHzkW4rcKSlK?= =?us-ascii?Q?Gt1KRN0mf3ivh1fJIZzmxjapyn1mM3JmxHJRzNptO99FJEUdsZ6DjtFuuhZI?= =?us-ascii?Q?6C/e3z9O2dASf+FJ8S9sxjxSwFlxr/LqcV3NzCIy11/8ZkdIwgrczG4sy00g?= =?us-ascii?Q?0n9+gfsV60EF0f5RsB1BsB5ZJfUUlTaIMlDxDaKjhFGvhsPHZ95RgWp+Fh45?= =?us-ascii?Q?N8kjPq9pW3kJWzVolubRu1JXCwcjV4m0YHPraBoa+Y+A4oPG4C1Y1QzggDY9?= =?us-ascii?Q?ABUUlVt/NTSHF7Mq56e3QyGrBi6vWb9SOTwggojn3RW3sLVDDuLol5gMMuaT?= =?us-ascii?Q?cvS/1/9KchmqTMYcrU02HVU+HDGI0ZdQ?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2024 15:11:09.7638 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5f345f90-ec9e-4386-a494-08dcc6aa7b83 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN1PEPF00006000.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6728 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 Introduce lcore functions which operates on Last Level Cache for core complexes or chiplet cores. On non chiplet core complexes, the function will iterate over all the available dpdk lcores. Functions added: - rte_get_llc_first_lcores - rte_get_llc_lcore - rte_get_llc_n_lcore Signed-off-by: Vipin Varghese --- lib/eal/common/eal_common_lcore.c | 279 ++++++++++++++++++++++++++++-- 1 file changed, 267 insertions(+), 12 deletions(-) diff --git a/lib/eal/common/eal_common_lcore.c b/lib/eal/common/eal_common_lcore.c index 2ff9252c52..4ff8b9e116 100644 --- a/lib/eal/common/eal_common_lcore.c +++ b/lib/eal/common/eal_common_lcore.c @@ -14,6 +14,7 @@ #ifndef RTE_EXEC_ENV_WINDOWS #include #endif +#include #include "eal_private.h" #include "eal_thread.h" @@ -93,25 +94,279 @@ int rte_lcore_is_enabled(unsigned int lcore_id) return cfg->lcore_role[lcore_id] == ROLE_RTE; } -unsigned int rte_get_next_lcore(unsigned int i, int skip_main, int wrap) +#define LCORE_GET_LLC \ + "ls -d /sys/bus/cpu/devices/cpu%u/cache/index[0-9] | sort -r | grep -m1 index[0-9] | awk -F '[x]' '{print $2}' " +#define LCORE_GET_SHAREDLLC \ + "grep [0-9] /sys/bus/cpu/devices/cpu%u/cache/index%u/shared_cpu_list" + +unsigned int rte_get_llc_first_lcores (rte_cpuset_t *llc_cpu) { - i++; - if (wrap) - i %= RTE_MAX_LCORE; + CPU_ZERO((rte_cpuset_t *)llc_cpu); - while (i < RTE_MAX_LCORE) { - if (!rte_lcore_is_enabled(i) || - (skip_main && (i == rte_get_main_lcore()))) { - i++; - if (wrap) - i %= RTE_MAX_LCORE; + char cmdline[2048] = {'\0'}; + char output_llc[8] = {'\0'}; + char output_threads[16] = {'\0'}; + + for (unsigned int lcore =0; lcore < RTE_MAX_LCORE; lcore++) + { + if (!rte_lcore_is_enabled (lcore)) continue; + + /* get sysfs llc index */ + snprintf(cmdline, 2047, LCORE_GET_LLC, lcore); + FILE *fp = popen (cmdline, "r"); + if (fp == NULL) { + return -1; } - break; + if (fgets(output_llc, sizeof(output_llc) - 1, fp) == NULL) { + pclose(fp); + return -1; + } + pclose(fp); + int llc_index = atoi (output_llc); + + /* get sysfs core group of the same core index*/ + snprintf(cmdline, 2047, LCORE_GET_SHAREDLLC, lcore, llc_index); + fp = popen (cmdline, "r"); + if (fp == NULL) { + return -1; + } + if (fgets(output_threads, sizeof(output_threads) - 1, fp) == NULL) { + pclose(fp); + return -1; + } + pclose(fp); + + output_threads [strlen(output_threads) - 1] = '\0'; + char *smt_thrds[2]; + int smt_threads = rte_strsplit(output_threads, sizeof(output_threads), smt_thrds, 2, ','); + + for (int index = 0; index < smt_threads; index++) { + char *llc[2] = {'\0'}; + int smt_cpu = rte_strsplit(smt_thrds[index], sizeof(smt_thrds[index]), llc, 2, '-'); + RTE_SET_USED(smt_cpu); + + unsigned int first_cpu = atoi (llc[0]); + unsigned int last_cpu = (NULL == llc[1]) ? atoi (llc[0]) : atoi (llc[1]); + + + for (unsigned int temp_cpu = first_cpu; temp_cpu <= last_cpu; temp_cpu++) { + if (rte_lcore_is_enabled(temp_cpu)) { + CPU_SET (temp_cpu, (rte_cpuset_t *) llc_cpu); + lcore = last_cpu; + break; + } + } + } + } + + return CPU_COUNT((rte_cpuset_t *)llc_cpu); +} + +unsigned int +rte_get_llc_lcore (unsigned int lcore, rte_cpuset_t *llc_cpu, + unsigned int *first_cpu, unsigned int * last_cpu) +{ + CPU_ZERO((rte_cpuset_t *)llc_cpu); + + char cmdline[2048] = {'\0'}; + char output_llc[8] = {'\0'}; + char output_threads[16] = {'\0'}; + + *first_cpu = *last_cpu = RTE_MAX_LCORE; + + /* get sysfs llc index */ + snprintf(cmdline, 2047, LCORE_GET_LLC, lcore); + FILE *fp = popen (cmdline, "r"); + if (fp == NULL) { + return -1; + } + if (fgets(output_llc, sizeof(output_llc) - 1, fp) == NULL) { + pclose(fp); + return -1; + } + pclose(fp); + int llc_index = atoi (output_llc); + + /* get sysfs core group of the same core index*/ + snprintf(cmdline, 2047, LCORE_GET_SHAREDLLC, lcore, llc_index); + fp = popen (cmdline, "r"); + if (fp == NULL) { + return -1; + } + + if (fgets(output_threads, sizeof(output_threads) - 1, fp) == NULL) { + pclose(fp); + return -1; } - return i; + pclose(fp); + + output_threads [strlen(output_threads) - 1] = '\0'; + char *smt_thrds[2]; + int smt_threads = rte_strsplit(output_threads, sizeof(output_threads), smt_thrds, 2, ','); + + bool found_first_cpu = false; + unsigned int first_lcore_cpu = RTE_MAX_LCORE; + unsigned int last_lcore_cpu = RTE_MAX_LCORE; + + for (int index = 0; index < smt_threads; index++) { + char *llc[2] = {'\0'}; + int smt_cpu = rte_strsplit(smt_thrds[index], sizeof(smt_thrds[index]), llc, 2, '-'); + RTE_SET_USED(smt_cpu); + + char *end = NULL; + *first_cpu = strtoul (llc[0], end, 10); + *last_cpu = (1 == smt_cpu) ? strtoul (llc[0], end, 10) : strtoul (llc[1], end, 10); + + unsigned int temp_cpu = RTE_MAX_LCORE; + RTE_LCORE_FOREACH(temp_cpu) { + if ((temp_cpu >= *first_cpu) && (temp_cpu <= *last_cpu)) { + CPU_SET (temp_cpu, (rte_cpuset_t *) llc_cpu); + //printf ("rte_get_llc_lcore: temp_cpu %u count %u \n", temp_cpu, CPU_COUNT(llc_cpu)); + + if (false == found_first_cpu) { + first_lcore_cpu = temp_cpu; + found_first_cpu = true; + } + last_lcore_cpu = temp_cpu; + } + //printf ("rte_get_llc_lcore: first %u last %u \n", first_lcore_cpu, last_lcore_cpu); + } + } + + *first_cpu = first_lcore_cpu; + *last_cpu = last_lcore_cpu; + + //printf ("rte_get_llc_lcore: first %u last %u count %u \n", *first_cpu, *last_cpu, CPU_COUNT(llc_cpu)); + return CPU_COUNT((rte_cpuset_t *)llc_cpu); +} + +unsigned int +rte_get_llc_n_lcore (unsigned int lcore, rte_cpuset_t *llc_cpu, + unsigned int *first_cpu, unsigned int * last_cpu, + unsigned int n, bool skip) +{ + bool found_first_cpu = false; + bool found_last_cpu = false; + unsigned int first_lcore_cpu = RTE_MAX_LCORE; + unsigned int last_lcore_cpu = RTE_MAX_LCORE; + + unsigned int temp_count = n; + unsigned int count = rte_get_llc_lcore (lcore, llc_cpu, first_cpu, last_cpu); + + //printf ("rte_get_llc_n_lcore: first %u last %u count %u \n", *first_cpu, *last_cpu, CPU_COUNT(llc_cpu)); + + unsigned int temp_cpu = RTE_MAX_LCORE; + unsigned int temp_last_cpu = RTE_MAX_LCORE; + if (false == skip) { + if (count < n) + return 0; + + RTE_LCORE_FOREACH(temp_cpu) { + if ((temp_cpu >= *first_cpu) && (temp_cpu <= *last_cpu)) { + if (CPU_ISSET(temp_cpu, llc_cpu) && (temp_count)) { + //printf ("rte_get_llc_n_lcore: temp - count %d cpu %u skip %u first %u last %u \n", temp_count, temp_cpu, skip, *first_cpu, *last_cpu); + if (false == found_first_cpu) { + *first_cpu = temp_cpu; + found_first_cpu = true; + } + temp_last_cpu = temp_cpu; + + temp_count -= 1; + continue; + } + } + CPU_CLR(temp_cpu, llc_cpu); + } + *last_cpu = temp_last_cpu; + //printf ("rte_get_llc_n_lcore: start %u last %u count %u\n", *first_cpu, *last_cpu, CPU_COUNT(llc_cpu)); + return n; + } + + int total_core = CPU_COUNT(llc_cpu) - n; + if (total_core <= 0) + return 0; + + RTE_LCORE_FOREACH(temp_cpu) { + if ((temp_cpu >= *first_cpu) && (temp_cpu <= *last_cpu)) { + if (CPU_ISSET(temp_cpu, llc_cpu) && (temp_count)) { + if (temp_count) { + CPU_CLR(temp_cpu, llc_cpu); + temp_count -= 1; + continue; + } + + if (false == found_first_cpu) { + *first_cpu = temp_cpu; + found_first_cpu = true; + } + *last_cpu = temp_cpu; + } + } + } + + //printf ("rte_get_llc_n_lcore: start %u last %u count %u\n", *first_cpu, *last_cpu, total_core); + return total_core; +#if 0 + if (false == skip) { + unsigned int start = *first_cpu, end = *last_cpu, temp_last_cpu = *last_cpu; + for (; (start <= end); start++) + { + if (CPU_ISSET(start, llc_cpu) && (temp_count)) { + temp_count -= 1; + continue; + } else if (CPU_ISSET(start, llc_cpu)) { + temp_last_cpu = (false == is_last_cpu) ? (start - 1) : temp_last_cpu; + is_last_cpu = true; + + CPU_CLR(start, llc_cpu); + } + } + *last_cpu = temp_last_cpu; + return n; + } + + int total_core = CPU_COUNT(llc_cpu) - n; + if (total_core <= 0) + return 0; + + bool is_first_cpu = false; + unsigned int temp_last_cpu = *last_cpu; + for (unsigned int start = *first_cpu, end = *last_cpu; (start <= end) && (temp_count); start++) + { + if (CPU_ISSET(start, llc_cpu) && (temp_count)) { + *first_cpu = (is_first_cpu == false) ? start : *first_cpu; + temp_last_cpu = start; + CPU_CLR(start, llc_cpu); + temp_count -= 1; + } + } + + *last_cpu = temp_last_cpu; + return total_core; +#endif +} + +unsigned int rte_get_next_lcore(unsigned int i, int skip_main, int wrap) +{ + i++; + if (wrap) + i %= RTE_MAX_LCORE; + + while (i < RTE_MAX_LCORE) { + if (!rte_lcore_is_enabled(i) || + (skip_main && (i == rte_get_main_lcore()))) { + i++; + if (wrap) + i %= RTE_MAX_LCORE; + continue; + } + break; + } + return i; } + unsigned int rte_lcore_to_socket_id(unsigned int lcore_id) { -- 2.34.1