[2/2] examples/l3fwd-power: add PM QoS request configuration

Message ID 20240320105529.5626-3-lihuisong@huawei.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers
Series introduce PM QoS interface |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS

Commit Message

lihuisong (C) March 20, 2024, 10:55 a.m. UTC
  Add PM QoS request configuration to declease the process resume latency.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
---
 examples/l3fwd-power/main.c | 41 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)
  

Patch

diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index f4adcf41b5..78f292ed02 100644
--- a/examples/l3fwd-power/main.c
+++ b/examples/l3fwd-power/main.c
@@ -47,6 +47,7 @@ 
 #include <rte_telemetry.h>
 #include <rte_power_pmd_mgmt.h>
 #include <rte_power_uncore.h>
+#include <rte_power_qos.h>
 
 #include "perf_core.h"
 #include "main.h"
@@ -2232,12 +2233,48 @@  static int check_ptype(uint16_t portid)
 
 }
 
+static int
+pm_qos_init(void)
+{
+	int cur_cpu_latency;
+	int ret;
+
+	ret = rte_power_qos_get_curr_cpu_latency(&cur_cpu_latency);
+	if (ret < 0) {
+		RTE_LOG(ERR, L3FWD_POWER, "failed to get current cpu latency.\n");
+		return ret;
+	}
+	RTE_LOG(INFO, L3FWD_POWER, "current cpu latency is %dus on system.\n",
+			(cur_cpu_latency / QOS_USEC_PER_SEC));
+
+	ret = rte_power_create_qos_request();
+	if (ret < 0) {
+		RTE_LOG(ERR, L3FWD_POWER, "Failed to create power QoS request.\n");
+		return ret;
+	}
+
+	/*
+	 * Set strict latency requirement to prevent service thread going into
+	 * a deeper sleep state whose resume time is longer.
+	 */
+	ret = rte_power_qos_update_request(PM_QOS_STRICT_LATENCY_VALUE);
+	if (ret < 0)
+		RTE_LOG(ERR, L3FWD_POWER, "Failed to change cpu latency to 0.\n");
+	return ret;
+}
+
 static int
 init_power_library(void)
 {
 	enum power_management_env env;
 	unsigned int lcore_id;
-	int ret = 0;
+	int ret;
+
+	ret = pm_qos_init();
+	if (ret != 0) {
+		RTE_LOG(ERR, L3FWD_POWER, "init power Qos failed.\n");
+		return ret;
+	}
 
 	RTE_LCORE_FOREACH(lcore_id) {
 		/* init power management library */
@@ -2268,6 +2305,8 @@  deinit_power_library(void)
 	unsigned int lcore_id, max_pkg, max_die, die, pkg;
 	int ret = 0;
 
+	rte_power_release_qos_request();
+
 	RTE_LCORE_FOREACH(lcore_id) {
 		/* deinit power management library */
 		ret = rte_power_exit(lcore_id);