summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHuisong Li <[email protected]>2024-11-11 10:25:50 +0800
committerThomas Monjalon <[email protected]>2024-11-11 11:27:35 +0100
commit4d23d39fd06ed89b2d2566273b95bbecbd48ed83 (patch)
tree6bc6d5e19d42d7b24f5235971179e624999ca482 /examples
parent0bc4795d5994459a3d261afd7f843eb0cabdecf5 (diff)
examples/l3fwd-power: add PM QoS configuration
The '--cpu-resume-latency' can use to control C-state selection. Setting the CPU resume latency to 0 can limit the CPU just to enter C0-state to improve performance, which also may increase the power consumption of platform. Signed-off-by: Huisong Li <[email protected]> Acked-by: Morten Brørup <[email protected]> Acked-by: Chengwen Feng <[email protected]> Acked-by: Konstantin Ananyev <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/l3fwd-power/main.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c
index 7bc524aa16..ae8b55924e 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"
@@ -265,6 +266,9 @@ static uint32_t pause_duration = 1;
static uint32_t scale_freq_min;
static uint32_t scale_freq_max;
+static int cpu_resume_latency = -1;
+static int resume_latency_bk[RTE_MAX_LCORE];
+
static struct rte_mempool * pktmbuf_pool[NB_SOCKETS];
@@ -1497,6 +1501,8 @@ print_usage(const char *prgname)
" -U: set min/max frequency for uncore to maximum value\n"
" -i (frequency index): set min/max frequency for uncore to specified frequency index\n"
" --config (port,queue,lcore): rx queues configuration\n"
+ " --cpu-resume-latency LATENCY: set CPU resume latency to control C-state selection,"
+ " 0 : just allow to enter C0-state\n"
" --high-perf-cores CORELIST: list of high performance cores\n"
" --perf-config: similar as config, cores specified as indices"
" for bins containing high or regular performance cores\n"
@@ -1735,6 +1741,7 @@ parse_pmd_mgmt_config(const char *name)
#define CMD_LINE_OPT_PAUSE_DURATION "pause-duration"
#define CMD_LINE_OPT_SCALE_FREQ_MIN "scale-freq-min"
#define CMD_LINE_OPT_SCALE_FREQ_MAX "scale-freq-max"
+#define CMD_LINE_OPT_CPU_RESUME_LATENCY "cpu-resume-latency"
/* Parse the argument given in the command line of the application */
static int
@@ -1749,6 +1756,7 @@ parse_args(int argc, char **argv)
{"perf-config", 1, 0, 0},
{"high-perf-cores", 1, 0, 0},
{"no-numa", 0, 0, 0},
+ {CMD_LINE_OPT_CPU_RESUME_LATENCY, 1, 0, 0},
{CMD_LINE_OPT_MAX_PKT_LEN, 1, 0, 0},
{CMD_LINE_OPT_PARSE_PTYPE, 0, 0, 0},
{CMD_LINE_OPT_LEGACY, 0, 0, 0},
@@ -1934,6 +1942,15 @@ parse_args(int argc, char **argv)
printf("Scaling frequency maximum configured\n");
}
+ if (!strncmp(lgopts[option_index].name,
+ CMD_LINE_OPT_CPU_RESUME_LATENCY,
+ sizeof(CMD_LINE_OPT_CPU_RESUME_LATENCY))) {
+ if (parse_uint(optarg, INT_MAX,
+ (uint32_t *)&cpu_resume_latency) != 0)
+ return -1;
+ printf("PM QoS configured\n");
+ }
+
break;
default:
@@ -2257,6 +2274,35 @@ init_power_library(void)
return -1;
}
}
+
+ if (cpu_resume_latency != -1) {
+ RTE_LCORE_FOREACH(lcore_id) {
+ /* Back old CPU resume latency. */
+ ret = rte_power_qos_get_cpu_resume_latency(lcore_id);
+ if (ret < 0) {
+ RTE_LOG(ERR, L3FWD_POWER,
+ "Failed to get cpu resume latency on lcore-%u, ret=%d.\n",
+ lcore_id, ret);
+ }
+ resume_latency_bk[lcore_id] = ret;
+
+ /*
+ * Set the cpu resume latency of the worker lcore based
+ * on user's request. If set strict latency (0), just
+ * allow the CPU to enter the shallowest idle state to
+ * improve performance.
+ */
+ ret = rte_power_qos_set_cpu_resume_latency(lcore_id,
+ cpu_resume_latency);
+ if (ret != 0) {
+ RTE_LOG(ERR, L3FWD_POWER,
+ "Failed to set cpu resume latency on lcore-%u, ret=%d.\n",
+ lcore_id, ret);
+ return ret;
+ }
+ }
+ }
+
return ret;
}
@@ -2296,6 +2342,15 @@ deinit_power_library(void)
}
}
}
+
+ if (cpu_resume_latency != -1) {
+ RTE_LCORE_FOREACH(lcore_id) {
+ /* Restore the original value. */
+ rte_power_qos_set_cpu_resume_latency(lcore_id,
+ resume_latency_bk[lcore_id]);
+ }
+ }
+
return ret;
}