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 A233C45B12; Fri, 11 Oct 2024 10:29:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 21DC44065D; Fri, 11 Oct 2024 10:28:32 +0200 (CEST) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2067.outbound.protection.outlook.com [40.107.20.67]) by mails.dpdk.org (Postfix) with ESMTP id 2822A402DC for ; Fri, 11 Oct 2024 10:28:23 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IgS7Q3xpwUJbEW+jSk61WBaXwRpSIjXPPgT7VJcxdNdo5BS7MAj43mGPYWSJkx+EHcLKX7HJA2FincBQ91sodpzTVyzp6DtdkEJO7rN7QiIfxZZ5aez+G1tOgMpJ46djlbf9GUHljJsABgVsdeyqaCEwhgj+wyouxcgOazKQOxS+Ex6Qg6wUk2MMcsIdGODyt+bCneKk/5PSGIE3fmtHRCGUMdfzOgQ1l2b7+np7GFOrc4Gne2yTeb2jJq3A7TU4cbExTxrZImT7RL6J43eSZiWkr2jEp+//E2G2WNcCUirGumUiwPm67YmtEjQ136oIx99+tyvPO/4OeYSWgdB6Vw== 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=ZkIKv5i0ytANi2Qv4NhA4vS3QvO0U4Y3yKKe5bexizg=; b=RjyaSXJH3blCPDsCB0iWiIsrNTONCf28IA9kCHyRjpRA+nxfNDxr20Yrke9fAQ6hBJnR41L5/Rttf2UPhzWo5eytA1NXr6/TA0JNQQusihy0/2af5aQieZkgQzq95EP/XCa6eAuexlCx6YddkXrOhd3mzcqf7gaXRACoY4kGS7vsBkWn3zoO36Q9K3rF+1WJoNe9WRL+3GL7gzcvc7UC5cDXZBc6ncd0YjbPl6drM5YPG15RwLqscv9DvRPVUD4j9Wzs70cpEMu9u+uYtO2xb1cYFMHaaUr6fQ8ICAv+7GYlBuovjCJUptB4RzSOVdaG4ykGkgMjMlrNiE9rfu6kIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZkIKv5i0ytANi2Qv4NhA4vS3QvO0U4Y3yKKe5bexizg=; b=kN30ZxRgJ1i7AxADxmFHjHq2abQkNdDHP+yVWsMO7fJw5YGdZBJz4RZej4fE5mADI3aJqGIEPBs0yCamel2WBFsO0rUmFmSmokDWmpLKyONWokEjCVFgwcGld/gUAtDCU3hWdtXFfs0mlPSo3WZqR4byui6O2Sp6Fo4J7niHGiXavz+188BoMmqzLgpZuONUGsNlJJYY45hF7Z8tJhJuNcr6ExkJvAQriDxfCmKy1W74qQSe0dIcMIWzfdShOvAKCyqvGYMN6yfDbLvDgbQsUGykrCv8Ju3E54Nq9HSsr5b2IfQhmMbzMEXybzX3698BoYxICMgkUOHsKpHREFeLgw== Received: from AM4PR0302CA0013.eurprd03.prod.outlook.com (2603:10a6:205:2::26) by VI1PR07MB6399.eurprd07.prod.outlook.com (2603:10a6:800:137::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Fri, 11 Oct 2024 08:28:18 +0000 Received: from AMS0EPF000001AE.eurprd05.prod.outlook.com (2603:10a6:205:2:cafe::e8) by AM4PR0302CA0013.outlook.office365.com (2603:10a6:205:2::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.20 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by AMS0EPF000001AE.mail.protection.outlook.com (10.167.16.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 11 Oct 2024 08:28:18 +0000 Received: from seliicinfr00049.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.61) with Microsoft SMTP Server id 15.2.1544.11; Fri, 11 Oct 2024 10:28:16 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00049.seli.gic.ericsson.se (Postfix) with ESMTP id 21B5838007F; Fri, 11 Oct 2024 10:28:16 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Stephen Hemminger , Konstantin Ananyev , David Marchand , Jerin Jacob , Luka Jankovic , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= , Konstantin Ananyev , Chengwen Feng Subject: [PATCH v10 6/7] service: keep per-lcore state in lcore variable Date: Fri, 11 Oct 2024 10:19:00 +0200 Message-ID: <20241011081901.816211-7-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241011081901.816211-1-mattias.ronnblom@ericsson.com> References: <20241010142205.813134-2-mattias.ronnblom@ericsson.com> <20241011081901.816211-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AMS0EPF000001AE:EE_|VI1PR07MB6399:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e07e4ed-b935-49ff-ca9f-08dce9cea8df X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?ZVk3bDlWeEtCTDBnalN0Qm9CNGhsRXVPdk15Wlh3MDVhM3ZmNGx6R0lPNGJm?= =?utf-8?B?RTZ4TFkrdjBJaStCS0IxUTV0dFpicUVZWnlxTEgrRlVYZUUxWTdSQlVqejlo?= =?utf-8?B?cm1BQUZRWWx2a0Ezc3dOVDJNVmUrSG5nTXpCb0liaVNCdFZncVM5L0VQaXAy?= =?utf-8?B?RUFjd2pXNmtwbC9vMkFSZkhFK0E5Q2RJdU85Y2hsdlBMcmZyZXlKMUNyY1lv?= =?utf-8?B?VEtycnMwOEdBSlpDNDVhRjhGTkdZRXQrYnY5TThVOWY4NVpZSnhMYVIxbEtL?= =?utf-8?B?UzZVK3l2MGhLU3h3Vks1bHlDcVB5dXQ1WGc3OEFvM3F6eVFMOEE1SjRDNVhS?= =?utf-8?B?bkF0ek5YS09pNUs0b3hZOTI0S2VjUVZOQ1hNNUtsaVNFVkNId1RxY3RmMEs5?= =?utf-8?B?U3ZtVUZubjV4T24vUXpJT1FWVDlpUXhCTnBMT2RLOVg4MWh2SExEYk5qR2pm?= =?utf-8?B?YldGQjdENE1RMWJZbm05aStDdHBmb1lVczQyQkhsbXRGMkFOUDhxTFB6d2Zv?= =?utf-8?B?TlBiUFMvT0ovelRTM0hJTC9NSVFkQ01zeW14YUhEL2NvOVB4bklVemEraEFW?= =?utf-8?B?Uy91YllkYTgwNS80NjlBL3VYNm15dTdHbEdFQWZvYjNvZ0JHWjl0eE9ubnhr?= =?utf-8?B?RDRJbmFvOUkwdzRtK3g2TzFLVlV1VXcxQ0E5aHE3ekY0Q29aaFkzUzJlYjhI?= =?utf-8?B?bUxUMTgxZTdvVDV6MGhXVGNCQWpMYlZqTkVQSXVyMWFmdnhmNnpteG1FRFRV?= =?utf-8?B?aWt3UHllcE5SYnhkUTNHMVZnb0JSbUI1KzZmUHVzc1ZxcVMxK2M1bHY0V2Iw?= =?utf-8?B?dFhJSk1OSlNpZ2w0ODVNdUNxckdvZWNUSkNkd3dmcEhRaTJjQlN2L0J1VGVS?= =?utf-8?B?YlNFQ1Qza1B2TitYbVhnVUFTdzFYaGFWNE5IR3JzNWFKTE4xUWgrMGZkcjBi?= =?utf-8?B?ZndQK3gzOERMbHFjNmZQR0tsYkZ4cVhMQS9WL0hzeFJkb2paSmJFTGRoWnBE?= =?utf-8?B?L3ZBNXc4K25VRytrMXZlTllvRFdhQWZKOVJ5Ykc0aTRSQ2hPb3I0ZURsbkFp?= =?utf-8?B?dlhmR2VNQkZOVC9Yak5BRHBPclNhMWdyYVF2L1BJdTF1VDN4d0NzVVBRT0ZK?= =?utf-8?B?L0lMdlV5Qjh0WHg0alhDUWFBVDY4UVhTZXhKZExnR0NyRDBVM1hBU25JQ01M?= =?utf-8?B?UWdQclZ0eFZPMTZVT2dmcnFhZ09PVnE0K2kwdXhmVWhaaGJzVGxRK0I3VVdT?= =?utf-8?B?b3phMGVUbWdBcERaaTl4MUhMcWFYWEM0OVU0SzRiMDdhWlhDMzk5ZFFoU1Vr?= =?utf-8?B?OWdGVklXanRjelgreFY5N1hrdGN4aXFvU3VWUG5QOUxVTEtpaEtzMEplYlJ4?= =?utf-8?B?MkVDZFZjMVJzMFhVVkpBb2hWckRaNnplTllDdHNFeHFkd1lnQ2hkaEljbGRi?= =?utf-8?B?SE5DeS9PL29PK2RNZS81U0ZhNERFRmxPc0czbVRvOSt0R3QwRWgxUTk4eTE0?= =?utf-8?B?a1g5aGk2OWhPbmcxZzRoUUs0ZUtVa1pNQVp4SzJLVGdEdk5aWnoraFpKazMz?= =?utf-8?B?QXhJcGo5MG9DS2tya0lsQ1NGcDQzdXJMUERsRXh3SHlhVzMzZGd1UHpGVVpa?= =?utf-8?B?L1BLYmhjd2k5dWUrNzZvZllBenJqSHFWS1BLejVSYXh0dG1DdllLTFNoTnFt?= =?utf-8?B?ajQ2OXZyQURhK1NoMVMvL1JqR2VWcGNSN2ZKcFBMOW1zZGJxR1NJV05DMGdv?= =?utf-8?B?d2twTUlocUVLWUpVRjk1SnY2UDAyOXVPYTdJZnZYelEvbkphQ2Y2bFBGQkFJ?= =?utf-8?B?MHp0ZEFYYjFDN0hLNVJUVXo3VnN0TFVjclJHUEVBQ2IwZEEvSm9tazk4dFZv?= =?utf-8?Q?EMnqYSoC+qEc1?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 08:28:18.4759 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3e07e4ed-b935-49ff-ca9f-08dce9cea8df X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: AMS0EPF000001AE.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR07MB6399 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 Replace static array of cache-aligned structs with an lcore variable, to slightly benefit code simplicity and performance. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Konstantin Ananyev Acked-by: Chengwen Feng Acked-by: Stephen Hemminger -- PATCH v7: * Update to match new FOREACH API. RFC v6: * Remove a now-redundant lcore variable value memset(). RFC v5: * Fix lcore value pointer bug introduced by RFC v4. RFC v4: * Remove strange-looking lcore value lookup potentially containing invalid lcore id. (Morten Brørup) * Replace misplaced tab with space. (Morten Brørup) --- lib/eal/common/rte_service.c | 117 +++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 52 deletions(-) diff --git a/lib/eal/common/rte_service.c b/lib/eal/common/rte_service.c index a38c594ce4..3d2c12c39b 100644 --- a/lib/eal/common/rte_service.c +++ b/lib/eal/common/rte_service.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -77,7 +78,7 @@ struct __rte_cache_aligned core_state { static uint32_t rte_service_count; static struct rte_service_spec_impl *rte_services; -static struct core_state *lcore_states; +static RTE_LCORE_VAR_HANDLE(struct core_state, lcore_states); static uint32_t rte_service_library_initialized; int32_t @@ -103,12 +104,8 @@ rte_service_init(void) goto fail_mem; } - lcore_states = rte_calloc("rte_service_core_states", RTE_MAX_LCORE, - sizeof(struct core_state), RTE_CACHE_LINE_SIZE); - if (!lcore_states) { - EAL_LOG(ERR, "error allocating core states array"); - goto fail_mem; - } + if (lcore_states == NULL) + RTE_LCORE_VAR_ALLOC(lcore_states); int i; struct rte_config *cfg = rte_eal_get_configuration(); @@ -124,7 +121,6 @@ rte_service_init(void) return 0; fail_mem: rte_free(rte_services); - rte_free(lcore_states); return -ENOMEM; } @@ -138,7 +134,6 @@ rte_service_finalize(void) rte_eal_mp_wait_lcore(); rte_free(rte_services); - rte_free(lcore_states); rte_service_library_initialized = 0; } @@ -288,7 +283,6 @@ rte_service_component_register(const struct rte_service_spec *spec, int32_t rte_service_component_unregister(uint32_t id) { - uint32_t i; struct rte_service_spec_impl *s; SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL); @@ -296,9 +290,11 @@ rte_service_component_unregister(uint32_t id) s->internal_flags &= ~(SERVICE_F_REGISTERED); + unsigned int lcore_id; + struct core_state *cs; /* clear the run-bit in all cores */ - for (i = 0; i < RTE_MAX_LCORE; i++) - lcore_states[i].service_mask &= ~(UINT64_C(1) << id); + RTE_LCORE_VAR_FOREACH_VALUE(lcore_id, cs, lcore_states) + cs->service_mask &= ~(UINT64_C(1) << id); memset(&rte_services[id], 0, sizeof(struct rte_service_spec_impl)); @@ -467,7 +463,10 @@ rte_service_may_be_active(uint32_t id) return -EINVAL; for (i = 0; i < lcore_count; i++) { - if (lcore_states[ids[i]].service_active_on_lcore[id]) + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(ids[i], lcore_states); + + if (cs->service_active_on_lcore[id]) return 1; } @@ -477,7 +476,7 @@ rte_service_may_be_active(uint32_t id) int32_t rte_service_run_iter_on_app_lcore(uint32_t id, uint32_t serialize_mt_unsafe) { - struct core_state *cs = &lcore_states[rte_lcore_id()]; + struct core_state *cs = RTE_LCORE_VAR_VALUE(lcore_states); struct rte_service_spec_impl *s; SERVICE_VALID_GET_OR_ERR_RET(id, s, -EINVAL); @@ -499,8 +498,7 @@ service_runner_func(void *arg) { RTE_SET_USED(arg); uint8_t i; - const int lcore = rte_lcore_id(); - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_VALUE(lcore_states); rte_atomic_store_explicit(&cs->thread_active, 1, rte_memory_order_seq_cst); @@ -546,13 +544,15 @@ service_runner_func(void *arg) int32_t rte_service_lcore_may_be_active(uint32_t lcore) { - if (lcore >= RTE_MAX_LCORE || !lcore_states[lcore].is_service_core) + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + + if (lcore >= RTE_MAX_LCORE || !cs->is_service_core) return -EINVAL; /* Load thread_active using ACQUIRE to avoid instructions dependent on * the result being re-ordered before this load completes. */ - return rte_atomic_load_explicit(&lcore_states[lcore].thread_active, + return rte_atomic_load_explicit(&cs->thread_active, rte_memory_order_acquire); } @@ -560,9 +560,12 @@ int32_t rte_service_lcore_count(void) { int32_t count = 0; - uint32_t i; - for (i = 0; i < RTE_MAX_LCORE; i++) - count += lcore_states[i].is_service_core; + + unsigned int lcore_id; + struct core_state *cs; + RTE_LCORE_VAR_FOREACH_VALUE(lcore_id, cs, lcore_states) + count += cs->is_service_core; + return count; } @@ -579,7 +582,8 @@ rte_service_lcore_list(uint32_t array[], uint32_t n) uint32_t i; uint32_t idx = 0; for (i = 0; i < RTE_MAX_LCORE; i++) { - struct core_state *cs = &lcore_states[i]; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(i, lcore_states); if (cs->is_service_core) { array[idx] = i; idx++; @@ -595,7 +599,7 @@ rte_service_lcore_count_services(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -ENOTSUP; @@ -647,30 +651,31 @@ rte_service_start_with_defaults(void) static int32_t service_update(uint32_t sid, uint32_t lcore, uint32_t *set, uint32_t *enabled) { + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + /* validate ID, or return error value */ if (!service_valid(sid) || lcore >= RTE_MAX_LCORE || - !lcore_states[lcore].is_service_core) + !cs->is_service_core) return -EINVAL; uint64_t sid_mask = UINT64_C(1) << sid; if (set) { - uint64_t lcore_mapped = lcore_states[lcore].service_mask & - sid_mask; + uint64_t lcore_mapped = cs->service_mask & sid_mask; if (*set && !lcore_mapped) { - lcore_states[lcore].service_mask |= sid_mask; + cs->service_mask |= sid_mask; rte_atomic_fetch_add_explicit(&rte_services[sid].num_mapped_cores, 1, rte_memory_order_relaxed); } if (!*set && lcore_mapped) { - lcore_states[lcore].service_mask &= ~(sid_mask); + cs->service_mask &= ~(sid_mask); rte_atomic_fetch_sub_explicit(&rte_services[sid].num_mapped_cores, 1, rte_memory_order_relaxed); } } if (enabled) - *enabled = !!(lcore_states[lcore].service_mask & (sid_mask)); + *enabled = !!(cs->service_mask & (sid_mask)); return 0; } @@ -698,13 +703,14 @@ set_lcore_state(uint32_t lcore, int32_t state) { /* mark core state in hugepage backed config */ struct rte_config *cfg = rte_eal_get_configuration(); + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); cfg->lcore_role[lcore] = state; /* mark state in process local lcore_config */ lcore_config[lcore].core_role = state; /* update per-lcore optimized state tracking */ - lcore_states[lcore].is_service_core = (state == ROLE_SERVICE); + cs->is_service_core = (state == ROLE_SERVICE); rte_eal_trace_service_lcore_state_change(lcore, state); } @@ -715,14 +721,16 @@ rte_service_lcore_reset_all(void) /* loop over cores, reset all to mask 0 */ uint32_t i; for (i = 0; i < RTE_MAX_LCORE; i++) { - if (lcore_states[i].is_service_core) { - lcore_states[i].service_mask = 0; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(i, lcore_states); + if (cs->is_service_core) { + cs->service_mask = 0; set_lcore_state(i, ROLE_RTE); /* runstate act as guard variable Use * store-release memory order here to synchronize * with load-acquire in runstate read functions. */ - rte_atomic_store_explicit(&lcore_states[i].runstate, + rte_atomic_store_explicit(&cs->runstate, RUNSTATE_STOPPED, rte_memory_order_release); } } @@ -738,17 +746,19 @@ rte_service_lcore_add(uint32_t lcore) { if (lcore >= RTE_MAX_LCORE) return -EINVAL; - if (lcore_states[lcore].is_service_core) + + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + if (cs->is_service_core) return -EALREADY; set_lcore_state(lcore, ROLE_SERVICE); /* ensure that after adding a core the mask and state are defaults */ - lcore_states[lcore].service_mask = 0; + cs->service_mask = 0; /* Use store-release memory order here to synchronize with * load-acquire in runstate read functions. */ - rte_atomic_store_explicit(&lcore_states[lcore].runstate, RUNSTATE_STOPPED, + rte_atomic_store_explicit(&cs->runstate, RUNSTATE_STOPPED, rte_memory_order_release); return rte_eal_wait_lcore(lcore); @@ -760,7 +770,7 @@ rte_service_lcore_del(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -EINVAL; @@ -784,7 +794,7 @@ rte_service_lcore_start(uint32_t lcore) if (lcore >= RTE_MAX_LCORE) return -EINVAL; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (!cs->is_service_core) return -EINVAL; @@ -814,6 +824,8 @@ rte_service_lcore_start(uint32_t lcore) int32_t rte_service_lcore_stop(uint32_t lcore) { + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + if (lcore >= RTE_MAX_LCORE) return -EINVAL; @@ -821,12 +833,11 @@ rte_service_lcore_stop(uint32_t lcore) * memory order here to synchronize with store-release * in runstate update functions. */ - if (rte_atomic_load_explicit(&lcore_states[lcore].runstate, rte_memory_order_acquire) == + if (rte_atomic_load_explicit(&cs->runstate, rte_memory_order_acquire) == RUNSTATE_STOPPED) return -EALREADY; uint32_t i; - struct core_state *cs = &lcore_states[lcore]; uint64_t service_mask = cs->service_mask; for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { @@ -847,7 +858,7 @@ rte_service_lcore_stop(uint32_t lcore) /* Use store-release memory order here to synchronize with * load-acquire in runstate read functions. */ - rte_atomic_store_explicit(&lcore_states[lcore].runstate, RUNSTATE_STOPPED, + rte_atomic_store_explicit(&cs->runstate, RUNSTATE_STOPPED, rte_memory_order_release); rte_eal_trace_service_lcore_stop(lcore); @@ -858,7 +869,7 @@ rte_service_lcore_stop(uint32_t lcore) static uint64_t lcore_attr_get_loops(unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->loops, rte_memory_order_relaxed); } @@ -866,7 +877,7 @@ lcore_attr_get_loops(unsigned int lcore) static uint64_t lcore_attr_get_cycles(unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->cycles, rte_memory_order_relaxed); } @@ -874,7 +885,7 @@ lcore_attr_get_cycles(unsigned int lcore) static uint64_t lcore_attr_get_service_calls(uint32_t service_id, unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->service_stats[service_id].calls, rte_memory_order_relaxed); @@ -901,7 +912,7 @@ lcore_attr_get_service_error_calls(uint32_t service_id, unsigned int lcore) static uint64_t lcore_attr_get_service_cycles(uint32_t service_id, unsigned int lcore) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); return rte_atomic_load_explicit(&cs->service_stats[service_id].cycles, rte_memory_order_relaxed); @@ -917,7 +928,10 @@ attr_get(uint32_t id, lcore_attr_get_fun lcore_attr_get) uint64_t sum = 0; for (lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { - if (lcore_states[lcore].is_service_core) + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); + + if (cs->is_service_core) sum += lcore_attr_get(id, lcore); } @@ -979,12 +993,11 @@ int32_t rte_service_lcore_attr_get(uint32_t lcore, uint32_t attr_id, uint64_t *attr_value) { - struct core_state *cs; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (lcore >= RTE_MAX_LCORE || !attr_value) return -EINVAL; - cs = &lcore_states[lcore]; if (!cs->is_service_core) return -ENOTSUP; @@ -1009,7 +1022,8 @@ rte_service_attr_reset_all(uint32_t id) return -EINVAL; for (lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = + RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); cs->service_stats[id] = (struct service_stats) {}; } @@ -1020,12 +1034,11 @@ rte_service_attr_reset_all(uint32_t id) int32_t rte_service_lcore_attr_reset_all(uint32_t lcore) { - struct core_state *cs; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); if (lcore >= RTE_MAX_LCORE) return -EINVAL; - cs = &lcore_states[lcore]; if (!cs->is_service_core) return -ENOTSUP; @@ -1060,7 +1073,7 @@ static void service_dump_calls_per_lcore(FILE *f, uint32_t lcore) { uint32_t i; - struct core_state *cs = &lcore_states[lcore]; + struct core_state *cs = RTE_LCORE_VAR_LCORE_VALUE(lcore, lcore_states); fprintf(f, "%02d\t", lcore); for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { -- 2.43.0