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 5787F43190; Tue, 17 Oct 2023 22:31:31 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C41E942DF3; Tue, 17 Oct 2023 22:31:26 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 35732402DE for ; Tue, 17 Oct 2023 22:31:19 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 6DE3720B74C1; Tue, 17 Oct 2023 13:31:18 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6DE3720B74C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1697574678; bh=Q+EvG4gLjlvtjVB70zS8hfxg9KyFpSSui2BjIESEaJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NdQl0px9Xpft7IT92IzPKs4++tHQYsMbAgNNVZKzJ57Uv72/vblSBX/9oB6GggLgT a9Gb3YEjBay8urj8zq3sY+Bf4H7n8XS3unaldMFwIA01DAjsLr+8I7bGEOP0fsdStE RASAgVKRfShEvx1a9fpL1AYTfSVXEltAm8w5jxNg= From: Tyler Retzlaff To: dev@dpdk.org Cc: Akhil Goyal , Anatoly Burakov , Andrew Rybchenko , Bruce Richardson , Chenbo Xia , Ciara Power , David Christensen , David Hunt , Dmitry Kozlyuk , Dmitry Malloy , Elena Agostini , Erik Gabriel Carrillo , Fan Zhang , Ferruh Yigit , Harman Kalra , Harry van Haaren , Honnappa Nagarahalli , Jerin Jacob , Konstantin Ananyev , Matan Azrad , Maxime Coquelin , Narcisa Ana Maria Vasile , Nicolas Chautru , Olivier Matz , Ori Kam , Pallavi Kadam , Pavan Nikhilesh , Reshma Pattan , Sameh Gobriel , Shijith Thotton , Sivaprasad Tummala , Stephen Hemminger , Suanming Mou , Sunil Kumar Kori , Thomas Monjalon , Viacheslav Ovsiienko , Vladimir Medvedkin , Yipeng Wang , Tyler Retzlaff Subject: [PATCH v2 01/19] power: use rte optional stdatomic API Date: Tue, 17 Oct 2023 13:30:59 -0700 Message-Id: <1697574677-16578-2-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1697574677-16578-1-git-send-email-roretzla@linux.microsoft.com> References: <1697497745-20664-1-git-send-email-roretzla@linux.microsoft.com> <1697574677-16578-1-git-send-email-roretzla@linux.microsoft.com> 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 the use of gcc builtin __atomic_xxx intrinsics with corresponding rte_atomic_xxx optional stdatomic API Signed-off-by: Tyler Retzlaff --- lib/power/power_acpi_cpufreq.c | 33 +++++++++++++++++---------------- lib/power/power_cppc_cpufreq.c | 25 +++++++++++++------------ lib/power/power_pstate_cpufreq.c | 31 ++++++++++++++++--------------- 3 files changed, 46 insertions(+), 43 deletions(-) diff --git a/lib/power/power_acpi_cpufreq.c b/lib/power/power_acpi_cpufreq.c index 6e57aca..8b55f19 100644 --- a/lib/power/power_acpi_cpufreq.c +++ b/lib/power/power_acpi_cpufreq.c @@ -7,6 +7,7 @@ #include #include +#include #include #include "power_acpi_cpufreq.h" @@ -41,13 +42,13 @@ enum power_state { * Power info per lcore. */ struct acpi_power_info { - unsigned int lcore_id; /**< Logical core id */ + unsigned int lcore_id; /**< Logical core id */ uint32_t freqs[RTE_MAX_LCORE_FREQS]; /**< Frequency array */ uint32_t nb_freqs; /**< number of available freqs */ FILE *f; /**< FD of scaling_setspeed */ char governor_ori[32]; /**< Original governor name */ uint32_t curr_idx; /**< Freq index in freqs array */ - uint32_t state; /**< Power in use state */ + RTE_ATOMIC(uint32_t) state; /**< Power in use state */ uint16_t turbo_available; /**< Turbo Boost available */ uint16_t turbo_enable; /**< Turbo Boost enable/disable */ } __rte_cache_aligned; @@ -249,9 +250,9 @@ struct acpi_power_info { * ordering below as lock to make sure the frequency operations * in the critical section are done under the correct state. */ - if (!__atomic_compare_exchange_n(&(pi->state), &exp_state, - POWER_ONGOING, 0, - __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { + if (!rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, + POWER_ONGOING, + rte_memory_order_acquire, rte_memory_order_relaxed)) { RTE_LOG(INFO, POWER, "Power management of lcore %u is " "in use\n", lcore_id); return -1; @@ -289,15 +290,15 @@ struct acpi_power_info { RTE_LOG(INFO, POWER, "Initialized successfully for lcore %u " "power management\n", lcore_id); exp_state = POWER_ONGOING; - __atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_USED, - 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED); + rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_USED, + rte_memory_order_release, rte_memory_order_relaxed); return 0; fail: exp_state = POWER_ONGOING; - __atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_UNKNOWN, - 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED); + rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_UNKNOWN, + rte_memory_order_release, rte_memory_order_relaxed); return -1; } @@ -321,9 +322,9 @@ struct acpi_power_info { * ordering below as lock to make sure the frequency operations * in the critical section are done under the correct state. */ - if (!__atomic_compare_exchange_n(&(pi->state), &exp_state, - POWER_ONGOING, 0, - __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { + if (!rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, + POWER_ONGOING, + rte_memory_order_acquire, rte_memory_order_relaxed)) { RTE_LOG(INFO, POWER, "Power management of lcore %u is " "not used\n", lcore_id); return -1; @@ -344,15 +345,15 @@ struct acpi_power_info { "'userspace' mode and been set back to the " "original\n", lcore_id); exp_state = POWER_ONGOING; - __atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_IDLE, - 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED); + rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_IDLE, + rte_memory_order_release, rte_memory_order_relaxed); return 0; fail: exp_state = POWER_ONGOING; - __atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_UNKNOWN, - 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED); + rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_UNKNOWN, + rte_memory_order_release, rte_memory_order_relaxed); return -1; } diff --git a/lib/power/power_cppc_cpufreq.c b/lib/power/power_cppc_cpufreq.c index fc9cffe..bb70f6a 100644 --- a/lib/power/power_cppc_cpufreq.c +++ b/lib/power/power_cppc_cpufreq.c @@ -6,6 +6,7 @@ #include #include +#include #include "power_cppc_cpufreq.h" #include "power_common.h" @@ -49,8 +50,8 @@ enum power_state { * Power info per lcore. */ struct cppc_power_info { - unsigned int lcore_id; /**< Logical core id */ - uint32_t state; /**< Power in use state */ + unsigned int lcore_id; /**< Logical core id */ + RTE_ATOMIC(uint32_t) state; /**< Power in use state */ FILE *f; /**< FD of scaling_setspeed */ char governor_ori[32]; /**< Original governor name */ uint32_t curr_idx; /**< Freq index in freqs array */ @@ -353,9 +354,9 @@ struct cppc_power_info { * ordering below as lock to make sure the frequency operations * in the critical section are done under the correct state. */ - if (!__atomic_compare_exchange_n(&(pi->state), &exp_state, - POWER_ONGOING, 0, - __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { + if (!rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, + POWER_ONGOING, + rte_memory_order_acquire, rte_memory_order_relaxed)) { RTE_LOG(INFO, POWER, "Power management of lcore %u is " "in use\n", lcore_id); return -1; @@ -393,12 +394,12 @@ struct cppc_power_info { RTE_LOG(INFO, POWER, "Initialized successfully for lcore %u " "power management\n", lcore_id); - __atomic_store_n(&(pi->state), POWER_USED, __ATOMIC_RELEASE); + rte_atomic_store_explicit(&(pi->state), POWER_USED, rte_memory_order_release); return 0; fail: - __atomic_store_n(&(pi->state), POWER_UNKNOWN, __ATOMIC_RELEASE); + rte_atomic_store_explicit(&(pi->state), POWER_UNKNOWN, rte_memory_order_release); return -1; } @@ -431,9 +432,9 @@ struct cppc_power_info { * ordering below as lock to make sure the frequency operations * in the critical section are done under the correct state. */ - if (!__atomic_compare_exchange_n(&(pi->state), &exp_state, - POWER_ONGOING, 0, - __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { + if (!rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, + POWER_ONGOING, + rte_memory_order_acquire, rte_memory_order_relaxed)) { RTE_LOG(INFO, POWER, "Power management of lcore %u is " "not used\n", lcore_id); return -1; @@ -453,12 +454,12 @@ struct cppc_power_info { RTE_LOG(INFO, POWER, "Power management of lcore %u has exited from " "'userspace' mode and been set back to the " "original\n", lcore_id); - __atomic_store_n(&(pi->state), POWER_IDLE, __ATOMIC_RELEASE); + rte_atomic_store_explicit(&(pi->state), POWER_IDLE, rte_memory_order_release); return 0; fail: - __atomic_store_n(&(pi->state), POWER_UNKNOWN, __ATOMIC_RELEASE); + rte_atomic_store_explicit(&(pi->state), POWER_UNKNOWN, rte_memory_order_release); return -1; } diff --git a/lib/power/power_pstate_cpufreq.c b/lib/power/power_pstate_cpufreq.c index 52aa645..5ca5f60 100644 --- a/lib/power/power_pstate_cpufreq.c +++ b/lib/power/power_pstate_cpufreq.c @@ -12,6 +12,7 @@ #include #include +#include #include "rte_power_pmd_mgmt.h" #include "power_pstate_cpufreq.h" @@ -59,7 +60,7 @@ struct pstate_power_info { uint32_t non_turbo_max_ratio; /**< Non Turbo Max ratio */ uint32_t sys_max_freq; /**< system wide max freq */ uint32_t core_base_freq; /**< core base freq */ - uint32_t state; /**< Power in use state */ + RTE_ATOMIC(uint32_t) state; /**< Power in use state */ uint16_t turbo_available; /**< Turbo Boost available */ uint16_t turbo_enable; /**< Turbo Boost enable/disable */ uint16_t priority_core; /**< High Performance core */ @@ -555,9 +556,9 @@ struct pstate_power_info { * ordering below as lock to make sure the frequency operations * in the critical section are done under the correct state. */ - if (!__atomic_compare_exchange_n(&(pi->state), &exp_state, - POWER_ONGOING, 0, - __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { + if (!rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, + POWER_ONGOING, + rte_memory_order_acquire, rte_memory_order_relaxed)) { RTE_LOG(INFO, POWER, "Power management of lcore %u is " "in use\n", lcore_id); return -1; @@ -600,15 +601,15 @@ struct pstate_power_info { RTE_LOG(INFO, POWER, "Initialized successfully for lcore %u " "power management\n", lcore_id); exp_state = POWER_ONGOING; - __atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_USED, - 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED); + rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_USED, + rte_memory_order_release, rte_memory_order_relaxed); return 0; fail: exp_state = POWER_ONGOING; - __atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_UNKNOWN, - 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED); + rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_UNKNOWN, + rte_memory_order_release, rte_memory_order_relaxed); return -1; } @@ -633,9 +634,9 @@ struct pstate_power_info { * ordering below as lock to make sure the frequency operations * in the critical section are under done the correct state. */ - if (!__atomic_compare_exchange_n(&(pi->state), &exp_state, - POWER_ONGOING, 0, - __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) { + if (!rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, + POWER_ONGOING, + rte_memory_order_acquire, rte_memory_order_relaxed)) { RTE_LOG(INFO, POWER, "Power management of lcore %u is " "not used\n", lcore_id); return -1; @@ -658,15 +659,15 @@ struct pstate_power_info { "'performance' mode and been set back to the " "original\n", lcore_id); exp_state = POWER_ONGOING; - __atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_IDLE, - 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED); + rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_IDLE, + rte_memory_order_release, rte_memory_order_relaxed); return 0; fail: exp_state = POWER_ONGOING; - __atomic_compare_exchange_n(&(pi->state), &exp_state, POWER_UNKNOWN, - 0, __ATOMIC_RELEASE, __ATOMIC_RELAXED); + rte_atomic_compare_exchange_strong_explicit(&(pi->state), &exp_state, POWER_UNKNOWN, + rte_memory_order_release, rte_memory_order_relaxed); return -1; } -- 1.8.3.1