DPDK patches and discussions
 help / color / mirror / Atom feed
From: Feifei Wang <feifei.wang2@arm.com>
To: Ruifeng Wang <ruifeng.wang@arm.com>
Cc: dev@dpdk.org, david.hunt@intel.com, stephen@networkplumber.org,
	thomas@monjalon.net, nd@arm.com,
	Feifei Wang <feifei.wang2@arm.com>
Subject: [PATCH v6 2/2] eal: add power mgmt support on Arm
Date: Mon, 20 Feb 2023 16:51:09 +0800	[thread overview]
Message-ID: <20230220085109.3463640-3-feifei.wang2@arm.com> (raw)
In-Reply-To: <20230220085109.3463640-1-feifei.wang2@arm.com>

For Arm arch, use WFE instruction to enable power monitor API, and use
SEV instruction to enable wake up API.

Signed-off-by: Feifei Wang <feifei.wang2@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Acked-by: David Hunt <david.hunt@intel.com>
---
 doc/guides/rel_notes/release_23_03.rst |  4 ++
 lib/eal/arm/include/rte_pause_64.h     |  5 ++-
 lib/eal/arm/rte_cpuflags.c             |  5 +++
 lib/eal/arm/rte_power_intrinsics.c     | 55 ++++++++++++++++++++++++--
 4 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/doc/guides/rel_notes/release_23_03.rst b/doc/guides/rel_notes/release_23_03.rst
index 7da3d19278..4a5995f2c8 100644
--- a/doc/guides/rel_notes/release_23_03.rst
+++ b/doc/guides/rel_notes/release_23_03.rst
@@ -192,6 +192,10 @@ New Features
   * Added support to capture packets at each graph node with packet metadata and
     node name.
 
+* **Added ARM support for power monitor in the power management library.**
+  * Added power monitor and wake up API support with WFE/SVE
+    instructions for Arm architecture.
+
 
 Removed Items
 -------------
diff --git a/lib/eal/arm/include/rte_pause_64.h b/lib/eal/arm/include/rte_pause_64.h
index c21600ca96..5f70e97481 100644
--- a/lib/eal/arm/include/rte_pause_64.h
+++ b/lib/eal/arm/include/rte_pause_64.h
@@ -25,9 +25,12 @@ static inline void rte_pause(void)
 
 #ifdef RTE_WAIT_UNTIL_EQUAL_ARCH_DEFINED
 
-/* Send an event to quit WFE. */
+/* Send a local event to quit WFE. */
 #define __RTE_ARM_SEVL() { asm volatile("sevl" : : : "memory"); }
 
+/* Send a global event to quit WFE for all cores. */
+#define __RTE_ARM_SEV() { asm volatile("sev" : : : "memory"); }
+
 /* Put processor into low power WFE(Wait For Event) state. */
 #define __RTE_ARM_WFE() { asm volatile("wfe" : : : "memory"); }
 
diff --git a/lib/eal/arm/rte_cpuflags.c b/lib/eal/arm/rte_cpuflags.c
index 93461191c7..90b80709fd 100644
--- a/lib/eal/arm/rte_cpuflags.c
+++ b/lib/eal/arm/rte_cpuflags.c
@@ -163,4 +163,9 @@ void
 rte_cpu_get_intrinsics_support(struct rte_cpu_intrinsics *intrinsics)
 {
 	memset(intrinsics, 0, sizeof(*intrinsics));
+
+#ifdef RTE_ARM_USE_WFE
+	intrinsics->power_monitor = 1;
+#endif
+
 }
diff --git a/lib/eal/arm/rte_power_intrinsics.c b/lib/eal/arm/rte_power_intrinsics.c
index 13f6a3264d..b518401225 100644
--- a/lib/eal/arm/rte_power_intrinsics.c
+++ b/lib/eal/arm/rte_power_intrinsics.c
@@ -7,16 +7,57 @@
 #include "rte_power_intrinsics.h"
 
 /**
- * This function is not supported on ARM.
+ * This function uses WFE instruction to make lcore suspend
+ * execution on ARM.
+ * Note that timestamp based timeout is not supported yet.
  */
 int
 rte_power_monitor(const struct rte_power_monitor_cond *pmc,
 		const uint64_t tsc_timestamp)
 {
-	RTE_SET_USED(pmc);
 	RTE_SET_USED(tsc_timestamp);
 
+#ifdef RTE_ARM_USE_WFE
+	const unsigned int lcore_id = rte_lcore_id();
+	uint64_t cur_value;
+
+	/* prevent non-EAL thread from using this API */
+	if (lcore_id >= RTE_MAX_LCORE)
+		return -EINVAL;
+
+	if (pmc == NULL)
+		return -EINVAL;
+
+	if (pmc->fn == NULL)
+		return -EINVAL;
+
+	switch (pmc->size) {
+	case sizeof(uint8_t):
+		__RTE_ARM_LOAD_EXC_8(pmc->addr, cur_value, __ATOMIC_RELAXED);
+		__RTE_ARM_WFE()
+		break;
+	case sizeof(uint16_t):
+		__RTE_ARM_LOAD_EXC_16(pmc->addr, cur_value, __ATOMIC_RELAXED);
+		__RTE_ARM_WFE()
+		break;
+	case sizeof(uint32_t):
+		__RTE_ARM_LOAD_EXC_32(pmc->addr, cur_value, __ATOMIC_RELAXED);
+		__RTE_ARM_WFE()
+		break;
+	case sizeof(uint64_t):
+		__RTE_ARM_LOAD_EXC_64(pmc->addr, cur_value, __ATOMIC_RELAXED);
+		__RTE_ARM_WFE()
+		break;
+	default:
+		return -EINVAL; /* unexpected size */
+	}
+
+	return 0;
+#else
+	RTE_SET_USED(pmc);
+
 	return -ENOTSUP;
+#endif
 }
 
 /**
@@ -31,14 +72,22 @@ rte_power_pause(const uint64_t tsc_timestamp)
 }
 
 /**
- * This function is not supported on ARM.
+ * This function uses SEV instruction to wake up all cores
+ * on ARM.
+ * Note that lcore_id is not used here.
  */
 int
 rte_power_monitor_wakeup(const unsigned int lcore_id)
 {
 	RTE_SET_USED(lcore_id);
 
+#ifdef RTE_ARM_USE_WFE
+	__RTE_ARM_SEV()
+
+	return 0;
+#else
 	return -ENOTSUP;
+#endif
 }
 
 int
-- 
2.25.1


  parent reply	other threads:[~2023-02-20  8:51 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-25  6:42 [PATCH v1 0/3] Enable PMD power management " Feifei Wang
2022-08-25  6:42 ` [PATCH v1 1/3] eal: add 8 bits case for wait scheme Feifei Wang
2022-08-25  6:42 ` [PATCH v1 2/3] eal: add power mgmt support on Arm Feifei Wang
2022-08-25  6:42 ` [PATCH v1 3/3] examples/l3fwd-power: enable PMD power mgmt " Feifei Wang
2022-08-29 12:48   ` Hunt, David
2022-10-03  7:12     ` David Marchand
2022-10-11  7:56       ` 回复: " Feifei Wang
2022-10-20 20:41         ` Thomas Monjalon
2022-10-27  9:38           ` 回复: " Feifei Wang
2022-10-20 22:09   ` Stephen Hemminger
2022-10-27  9:43     ` 回复: " Feifei Wang
2022-11-07  7:04 ` [PATCH v2 0/3] Enable PMD power management " Feifei Wang
2022-11-07  7:04   ` [PATCH v2 1/3] eal: add 8 bits case for wait scheme Feifei Wang
2022-11-07  7:04   ` [PATCH v2 2/3] eal: add power mgmt support on Arm Feifei Wang
2022-11-07  7:04   ` [PATCH v2 3/3] examples/l3fwd-power: enable PMD power monitor " Feifei Wang
2022-11-07 16:01     ` Stephen Hemminger
2022-11-08  3:25       ` 回复: " Feifei Wang
2022-11-11  7:26 ` [PATCH v3 0/3] Enable PMD power management " Feifei Wang
2022-11-11  7:26   ` [PATCH v3 1/3] eal: add 8 bits case for wait scheme Feifei Wang
2022-11-11  7:26   ` [PATCH v3 2/3] eal: add power mgmt support on Arm Feifei Wang
2022-11-11  7:26   ` [PATCH v3 3/3] examples/l3fwd-power: enable PMD power monitor " Feifei Wang
2022-11-11  8:22     ` Thomas Monjalon
2022-11-11 10:21       ` 回复: " Feifei Wang
2022-11-11 10:20 ` [PATCH v4 0/4] Enable PMD power management " Feifei Wang
2022-11-11 10:20   ` [PATCH v4 1/4] eal: add 8 bits case for wait scheme Feifei Wang
2022-11-11 10:20   ` [PATCH v4 2/4] eal: add power mgmt support on Arm Feifei Wang
2022-11-11 10:20   ` [PATCH v4 3/4] power: add power monitor support check Feifei Wang
2022-11-11 10:20   ` [PATCH v4 4/4] examples/l3fwd-power: add power monitor wake up API Feifei Wang
2022-12-14  8:14 ` [PATCH v5 0/2] Enable PMD power management on Arm Feifei Wang
2022-12-14  8:14   ` [PATCH v5 1/2] eal: add 8 bits case for wait scheme Feifei Wang
2022-12-14  8:14   ` [PATCH v5 2/2] eal: add power mgmt support on Arm Feifei Wang
2023-02-17 16:23     ` Stephen Hemminger
2023-02-20  1:56       ` 回复: " Feifei Wang
2023-02-17  8:26   ` 回复: [PATCH v5 0/2] Enable PMD power management " Feifei Wang
2023-02-20  8:51 ` [PATCH v6 " Feifei Wang
2023-02-20  8:51   ` [PATCH v6 1/2] eal: add 8 bits case for wait scheme Feifei Wang
2023-02-20  8:51   ` Feifei Wang [this message]
2023-02-20 12:07   ` [PATCH v6 0/2] Enable PMD power management on Arm David Marchand
2023-02-21  2:37     ` 回复: " Feifei Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230220085109.3463640-3-feifei.wang2@arm.com \
    --to=feifei.wang2@arm.com \
    --cc=david.hunt@intel.com \
    --cc=dev@dpdk.org \
    --cc=nd@arm.com \
    --cc=ruifeng.wang@arm.com \
    --cc=stephen@networkplumber.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).