From: Kevin Laatz <kevin.laatz@intel.com>
To: dev@dpdk.org
Cc: anatoly.burakov@intel.com, Kevin Laatz <kevin.laatz@intel.com>,
Ray Kinsella <mdr@ashroe.eu>, David Hunt <david.hunt@intel.com>
Subject: [PATCH v5 3/4] lib/power: add get and set API for scaling freq min and max with pstate mode
Date: Tue, 31 May 2022 10:59:35 +0100 [thread overview]
Message-ID: <20220531095936.1965727-4-kevin.laatz@intel.com> (raw)
In-Reply-To: <20220531095936.1965727-1-kevin.laatz@intel.com>
Add new get/set API to allow the user or application to set the minimum
and maximum frequencies to use when scaling.
Previously, the frequency range was determined by the HW capabilities of
the CPU. With this new API, the user or application can constrain this
if required.
Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Acked-by: Ray Kinsella <mdr@ashroe.eu>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Tested-by: David Hunt <david.hunt@intel.com>
---
v5:
* add doc entry for new API
v4:
* fix mismatch between comments and code
* fix return value when max freq is not set
v3:
* updated doxygen comments
* added checks to ensure min/max value is valid
* consider 0 as 'not set' for scaling_freq_max
---
doc/guides/prog_guide/power_man.rst | 12 +++++
lib/power/power_pstate_cpufreq.c | 24 +++++++--
lib/power/rte_power_pmd_mgmt.c | 77 +++++++++++++++++++++++++++
lib/power/rte_power_pmd_mgmt.h | 81 +++++++++++++++++++++++++++++
lib/power/version.map | 4 ++
5 files changed, 193 insertions(+), 5 deletions(-)
diff --git a/doc/guides/prog_guide/power_man.rst b/doc/guides/prog_guide/power_man.rst
index f22513b324..a63a830213 100644
--- a/doc/guides/prog_guide/power_man.rst
+++ b/doc/guides/prog_guide/power_man.rst
@@ -264,6 +264,18 @@ API Overview for Ethernet PMD Power Management
* **Set Pause Duration**: Set the duration of the pause (ms) used in the Pause
mode callback.
+* **Get Scaling Min Freq**: Get the configured minimum frequency to be used in
+ Frequency Scaling mode.
+
+* **Set Scaling Min Freq**: Set the minimum frequency to be used in Frequency
+ Scaling mode.
+
+* **Get Scaling Max Freq**: Get the configured maximum frequency to be used in
+ Frequency Scaling mode.
+
+* **Set Scaling Max Freq**: Set the maximum frequency to be used in Frequency
+ Scaling mode.
+
References
----------
diff --git a/lib/power/power_pstate_cpufreq.c b/lib/power/power_pstate_cpufreq.c
index f4c36179ec..78c9197695 100644
--- a/lib/power/power_pstate_cpufreq.c
+++ b/lib/power/power_pstate_cpufreq.c
@@ -12,6 +12,7 @@
#include <rte_memcpy.h>
+#include "rte_power_pmd_mgmt.h"
#include "power_pstate_cpufreq.h"
#include "power_common.h"
@@ -354,6 +355,7 @@ power_get_available_freqs(struct pstate_power_info *pi)
FILE *f_min = NULL, *f_max = NULL;
int ret = -1;
uint32_t sys_min_freq = 0, sys_max_freq = 0, base_max_freq = 0;
+ int config_min_freq, config_max_freq;
uint32_t i, num_freqs = 0;
/* open all files */
@@ -388,6 +390,18 @@ power_get_available_freqs(struct pstate_power_info *pi)
goto out;
}
+ /* check for config set by user or application to limit frequency range */
+ config_min_freq = rte_power_pmd_mgmt_get_scaling_freq_min(pi->lcore_id);
+ if (config_min_freq < 0)
+ goto out;
+ config_max_freq = rte_power_pmd_mgmt_get_scaling_freq_max(pi->lcore_id);
+ if (config_max_freq < 0)
+ goto out;
+
+ sys_min_freq = RTE_MAX(sys_min_freq, (uint32_t)config_min_freq);
+ if (config_max_freq > 0) /* Only use config_max_freq if a value has been set */
+ sys_max_freq = RTE_MIN(sys_max_freq, (uint32_t)config_max_freq);
+
if (sys_max_freq < sys_min_freq)
goto out;
@@ -411,8 +425,8 @@ power_get_available_freqs(struct pstate_power_info *pi)
/* If turbo is available then there is one extra freq bucket
* to store the sys max freq which value is base_max +1
*/
- num_freqs = (base_max_freq - sys_min_freq) / BUS_FREQ + 1 +
- pi->turbo_available;
+ num_freqs = (RTE_MIN(base_max_freq, sys_max_freq) - sys_min_freq) / BUS_FREQ
+ + 1 + pi->turbo_available;
if (num_freqs >= RTE_MAX_LCORE_FREQS) {
RTE_LOG(ERR, POWER, "Too many available frequencies: %d\n",
num_freqs);
@@ -427,10 +441,10 @@ power_get_available_freqs(struct pstate_power_info *pi)
*/
for (i = 0, pi->nb_freqs = 0; i < num_freqs; i++) {
if ((i == 0) && pi->turbo_available)
- pi->freqs[pi->nb_freqs++] = base_max_freq + 1;
+ pi->freqs[pi->nb_freqs++] = RTE_MIN(base_max_freq, sys_max_freq) + 1;
else
- pi->freqs[pi->nb_freqs++] =
- base_max_freq - (i - pi->turbo_available) * BUS_FREQ;
+ pi->freqs[pi->nb_freqs++] = RTE_MIN(base_max_freq, sys_max_freq) -
+ (i - pi->turbo_available) * BUS_FREQ;
}
ret = 0;
diff --git a/lib/power/rte_power_pmd_mgmt.c b/lib/power/rte_power_pmd_mgmt.c
index 1374cc213d..a66e08e574 100644
--- a/lib/power/rte_power_pmd_mgmt.c
+++ b/lib/power/rte_power_pmd_mgmt.c
@@ -10,9 +10,12 @@
#include <rte_power_intrinsics.h>
#include "rte_power_pmd_mgmt.h"
+#include "power_common.h"
unsigned int emptypoll_max;
unsigned int pause_duration;
+unsigned int scale_freq_min[RTE_MAX_LCORE];
+unsigned int scale_freq_max[RTE_MAX_LCORE];
/* store some internal state */
static struct pmd_conf_data {
@@ -693,8 +696,77 @@ rte_power_pmd_mgmt_get_pause_duration(void)
return pause_duration;
}
+int
+rte_power_pmd_mgmt_set_scaling_freq_min(unsigned int lcore, unsigned int min)
+{
+ if (lcore >= RTE_MAX_LCORE) {
+ RTE_LOG(ERR, POWER, "Invalid lcore ID: %u\n", lcore);
+ return -EINVAL;
+ }
+
+ if (min > scale_freq_max[lcore]) {
+ RTE_LOG(ERR, POWER, "Invalid min frequency: Cannot be greater than max frequency");
+ return -EINVAL;
+ }
+ scale_freq_min[lcore] = min;
+
+ return 0;
+}
+
+int
+rte_power_pmd_mgmt_set_scaling_freq_max(unsigned int lcore, unsigned int max)
+{
+ if (lcore >= RTE_MAX_LCORE) {
+ RTE_LOG(ERR, POWER, "Invalid lcore ID: %u\n", lcore);
+ return -EINVAL;
+ }
+
+ /* Zero means 'not set'. Use UINT32_MAX to enable RTE_MIN/MAX macro use when scaling. */
+ if (max == 0)
+ max = UINT32_MAX;
+ if (max < scale_freq_min[lcore]) {
+ RTE_LOG(ERR, POWER, "Invalid max frequency: Cannot be less than min frequency");
+ return -EINVAL;
+ }
+
+ scale_freq_max[lcore] = max;
+
+ return 0;
+}
+
+int
+rte_power_pmd_mgmt_get_scaling_freq_min(unsigned int lcore)
+{
+ if (lcore >= RTE_MAX_LCORE) {
+ RTE_LOG(ERR, POWER, "Invalid lcore ID: %u\n", lcore);
+ return -EINVAL;
+ }
+
+ if (scale_freq_max[lcore] == 0)
+ RTE_LOG(DEBUG, POWER, "Scaling freq min config not set. Using sysfs min freq.\n");
+
+ return scale_freq_min[lcore];
+}
+
+int
+rte_power_pmd_mgmt_get_scaling_freq_max(unsigned int lcore)
+{
+ if (lcore >= RTE_MAX_LCORE) {
+ RTE_LOG(ERR, POWER, "Invalid lcore ID: %u\n", lcore);
+ return -EINVAL;
+ }
+
+ if (scale_freq_max[lcore] == UINT32_MAX) {
+ RTE_LOG(DEBUG, POWER, "Scaling freq max config not set. Using sysfs max freq.\n");
+ return 0;
+ }
+
+ return scale_freq_max[lcore];
+}
+
RTE_INIT(rte_power_ethdev_pmgmt_init) {
size_t i;
+ int j;
/* initialize all tailqs */
for (i = 0; i < RTE_DIM(lcore_cfgs); i++) {
@@ -705,4 +777,9 @@ RTE_INIT(rte_power_ethdev_pmgmt_init) {
/* initialize config defaults */
emptypoll_max = 512;
pause_duration = 1;
+ /* scaling defaults out of range to ensure not used unless set by user or app */
+ for (j = 0; j < RTE_MAX_LCORE; j++) {
+ scale_freq_min[j] = 0;
+ scale_freq_max[j] = UINT32_MAX;
+ }
}
diff --git a/lib/power/rte_power_pmd_mgmt.h b/lib/power/rte_power_pmd_mgmt.h
index 18a9c3abb5..789fbe0e4d 100644
--- a/lib/power/rte_power_pmd_mgmt.h
+++ b/lib/power/rte_power_pmd_mgmt.h
@@ -148,6 +148,87 @@ __rte_experimental
unsigned int
rte_power_pmd_mgmt_get_pause_duration(void);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice.
+ *
+ * Set the min frequency to be used for frequency scaling or zero to use defaults.
+ *
+ * @note Supported by: Pstate mode.
+ *
+ * @param lcore
+ * The ID of the lcore to set the min frequency for.
+ * @param min
+ * The value, in KiloHertz, to set the minimum frequency to.
+ * @return
+ * 0 on success
+ * <0 on error
+ */
+__rte_experimental
+int
+rte_power_pmd_mgmt_set_scaling_freq_min(unsigned int lcore, unsigned int min);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice.
+ *
+ * Set the max frequency to be used for frequency scaling or zero to use defaults.
+ *
+ * @note Supported by: Pstate mode.
+ *
+ * @param lcore
+ * The ID of the lcore to set the max frequency for.
+ * @param max
+ * The value, in KiloHertz, to set the maximum frequency to.
+ * If 'max' is 0, it is considered 'not set'.
+ * @return
+ * 0 on success
+ * <0 on error
+ */
+__rte_experimental
+int
+rte_power_pmd_mgmt_set_scaling_freq_max(unsigned int lcore, unsigned int max);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice.
+ *
+ * Get the current configured min frequency used for frequency scaling.
+ *
+ * @note Supported by: Pstate mode.
+ *
+ * @param lcore
+ * The ID of the lcore to get the min frequency for.
+ * @return
+ * 0 if no value has been configured via the 'set' API.
+ * >0 if a minimum frequency has been configured. Value is the minimum frequency
+ * , in KiloHertz, used for frequency scaling.
+ * <0 on error
+ */
+__rte_experimental
+int
+rte_power_pmd_mgmt_get_scaling_freq_min(unsigned int lcore);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice.
+ *
+ * Get the current configured max frequency used for frequency scaling.
+ *
+ * @note Supported by: Pstate mode.
+ *
+ * @param lcore
+ * The ID of the lcore to get the max frequency for.
+ * @return
+ * 0 if no value has been configured via the 'set' API.
+ * >0 if a maximum frequency has been configured. Value is the maximum frequency
+ * , in KiloHertz, used for frequency scaling.
+ * <0 on error
+ */
+__rte_experimental
+int
+rte_power_pmd_mgmt_get_scaling_freq_max(unsigned int lcore);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/power/version.map b/lib/power/version.map
index 4673b719f9..a687754f4a 100644
--- a/lib/power/version.map
+++ b/lib/power/version.map
@@ -42,6 +42,10 @@ EXPERIMENTAL {
# added in 22.07
rte_power_pmd_mgmt_get_emptypoll_max;
rte_power_pmd_mgmt_get_pause_duration;
+ rte_power_pmd_mgmt_get_scaling_freq_max;
+ rte_power_pmd_mgmt_get_scaling_freq_min;
rte_power_pmd_mgmt_set_emptypoll_max;
rte_power_pmd_mgmt_set_pause_duration;
+ rte_power_pmd_mgmt_set_scaling_freq_max;
+ rte_power_pmd_mgmt_set_scaling_freq_min;
};
--
2.31.1
next prev parent reply other threads:[~2022-05-31 9:58 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-08 14:08 [PATCH 0/4] Add APIs for configurable power options Kevin Laatz
2022-04-08 14:08 ` [PATCH 1/4] lib/power: add get and set API for emptypoll max Kevin Laatz
2022-04-15 14:43 ` Ray Kinsella
2022-04-19 11:25 ` Kevin Laatz
2022-04-08 14:08 ` [PATCH 2/4] lib/power: add get and set API for pause duration Kevin Laatz
2022-04-08 14:08 ` [PATCH 3/4] lib/power: add get and set API for scaling freq min and max with pstate mode Kevin Laatz
2022-04-08 14:08 ` [PATCH 4/4] examples/l3fwd_power: add cli for configurable options Kevin Laatz
2022-04-19 11:24 ` [PATCH v2 0/4] Add APIs for configurable power options Kevin Laatz
2022-04-19 11:24 ` [PATCH v2 1/4] lib/power: add get and set API for emptypoll max Kevin Laatz
2022-04-19 15:42 ` Ray Kinsella
2022-04-19 11:24 ` [PATCH v2 2/4] lib/power: add get and set API for pause duration Kevin Laatz
2022-04-19 15:42 ` Ray Kinsella
2022-05-18 8:58 ` Burakov, Anatoly
2022-04-19 11:25 ` [PATCH v2 3/4] lib/power: add get and set API for scaling freq min and max with pstate mode Kevin Laatz
2022-04-19 15:43 ` Ray Kinsella
2022-05-18 9:05 ` Burakov, Anatoly
2022-05-23 16:25 ` Kevin Laatz
2022-04-19 11:25 ` [PATCH v2 4/4] examples/l3fwd_power: add cli for configurable options Kevin Laatz
2022-05-18 9:11 ` Burakov, Anatoly
2022-05-23 16:54 ` Kevin Laatz
2022-05-23 20:21 ` [PATCH v3 0/4] Add APIs for configurable power options Kevin Laatz
2022-05-23 20:21 ` [PATCH v3 1/4] lib/power: add get and set API for emptypoll max Kevin Laatz
2022-05-24 13:45 ` Ray Kinsella
2022-05-23 20:21 ` [PATCH v3 2/4] lib/power: add get and set API for pause duration Kevin Laatz
2022-05-23 20:21 ` [PATCH v3 3/4] lib/power: add get and set API for scaling freq min and max with pstate mode Kevin Laatz
2022-05-24 10:00 ` Burakov, Anatoly
2022-05-23 20:21 ` [PATCH v3 4/4] examples/l3fwd_power: add cli for configurable options Kevin Laatz
2022-05-24 10:03 ` Burakov, Anatoly
2022-05-24 13:14 ` [PATCH v4 0/4] Add APIs for configurable power options Kevin Laatz
2022-05-24 13:14 ` [PATCH v4 1/4] lib/power: add get and set API for emptypoll max Kevin Laatz
2022-05-24 14:40 ` David Hunt
2022-05-24 13:14 ` [PATCH v4 2/4] lib/power: add get and set API for pause duration Kevin Laatz
2022-05-24 14:39 ` David Hunt
2022-05-24 13:14 ` [PATCH v4 3/4] lib/power: add get and set API for scaling freq min and max with pstate mode Kevin Laatz
2022-05-24 14:39 ` David Hunt
2022-05-24 13:14 ` [PATCH v4 4/4] examples/l3fwd_power: add cli for configurable options Kevin Laatz
2022-05-24 14:38 ` David Hunt
2022-05-27 16:04 ` [PATCH v4 0/4] Add APIs for configurable power options Burakov, Anatoly
2022-05-31 9:59 ` [PATCH v5 " Kevin Laatz
2022-05-31 9:59 ` [PATCH v5 1/4] lib/power: add get and set API for emptypoll max Kevin Laatz
2022-05-31 9:59 ` [PATCH v5 2/4] lib/power: add get and set API for pause duration Kevin Laatz
2022-06-02 14:01 ` Burakov, Anatoly
2022-06-02 14:53 ` Kevin Laatz
2022-05-31 9:59 ` Kevin Laatz [this message]
2022-05-31 9:59 ` [PATCH v5 4/4] examples/l3fwd_power: add cli for configurable options Kevin Laatz
2022-06-02 15:13 ` [PATCH v6 0/4] Add APIs for configurable power options Kevin Laatz
2022-06-02 15:13 ` [PATCH v6 1/4] lib/power: add get and set API for emptypoll max Kevin Laatz
2022-06-02 15:13 ` [PATCH v6 2/4] lib/power: add get and set API for pause duration Kevin Laatz
2022-06-02 15:13 ` [PATCH v6 3/4] lib/power: add get and set API for scaling freq min and max with pstate mode Kevin Laatz
2022-06-02 15:13 ` [PATCH v6 4/4] examples/l3fwd_power: add cli for configurable options Kevin Laatz
2022-06-04 20:43 ` [PATCH v6 0/4] Add APIs for configurable power options Thomas Monjalon
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=20220531095936.1965727-4-kevin.laatz@intel.com \
--to=kevin.laatz@intel.com \
--cc=anatoly.burakov@intel.com \
--cc=david.hunt@intel.com \
--cc=dev@dpdk.org \
--cc=mdr@ashroe.eu \
/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).