[v2,1/3] power: add get capabilities API

Message ID 1528711403-29776-1-git-send-email-radu.nicolau@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2,1/3] power: add get capabilities API |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Radu Nicolau June 11, 2018, 10:03 a.m. UTC
  New API added, rte_power_get_capabilities(), that allows the
application to query the power and performance capabilities
of the CPU cores.

Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
---
v2: fixed coding style errors, split test into separate patch

 lib/librte_power/power_acpi_cpufreq.c  | 21 +++++++++++++++++++++
 lib/librte_power/power_acpi_cpufreq.h  | 17 +++++++++++++++++
 lib/librte_power/power_kvm_vm.c        |  8 ++++++++
 lib/librte_power/power_kvm_vm.h        | 17 +++++++++++++++++
 lib/librte_power/rte_power.c           |  3 +++
 lib/librte_power/rte_power.h           | 33 +++++++++++++++++++++++++++++++++
 lib/librte_power/rte_power_version.map |  7 +++++++
 7 files changed, 106 insertions(+)
  

Comments

Hunt, David June 26, 2018, 9:43 a.m. UTC | #1
On 11/6/2018 11:03 AM, Radu Nicolau wrote:
> New API added, rte_power_get_capabilities(), that allows the
> application to query the power and performance capabilities
> of the CPU cores.
>
> Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
> ---
> v2: fixed coding style errors, split test into separate patch
>
>   lib/librte_power/power_acpi_cpufreq.c  | 21 +++++++++++++++++++++
>   lib/librte_power/power_acpi_cpufreq.h  | 17 +++++++++++++++++
>   lib/librte_power/power_kvm_vm.c        |  8 ++++++++
>   lib/librte_power/power_kvm_vm.h        | 17 +++++++++++++++++
>   lib/librte_power/rte_power.c           |  3 +++
>   lib/librte_power/rte_power.h           | 33 +++++++++++++++++++++++++++++++++
>   lib/librte_power/rte_power_version.map |  7 +++++++
>   7 files changed, 106 insertions(+)
>
> diff --git a/lib/librte_power/power_acpi_cpufreq.c b/lib/librte_power/power_acpi_cpufreq.c
> index bce933e..cd5978d 100644
> --- a/lib/librte_power/power_acpi_cpufreq.c
> +++ b/lib/librte_power/power_acpi_cpufreq.c
> @@ -623,3 +623,24 @@ power_acpi_disable_turbo(unsigned int lcore_id)
>   
>   	return 0;
>   }
> +
> +int power_acpi_get_capabilities(unsigned int lcore_id,
> +		struct rte_power_core_capabilities *caps)
> +{
> +	struct rte_power_info *pi;
> +
> +	if (lcore_id >= RTE_MAX_LCORE) {
> +		RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
> +		return -1;
> +	}
> +	if (caps == NULL) {
> +		RTE_LOG(ERR, POWER, "Invalid argument\n");
> +		return -1;
> +	}
> +
> +	pi = &lcore_power_info[lcore_id];
> +	caps->capabilities = 0;
> +	caps->turbo = !!(pi->turbo_available);
> +
> +	return 0;
> +}
> diff --git a/lib/librte_power/power_acpi_cpufreq.h b/lib/librte_power/power_acpi_cpufreq.h
> index edeeb27..77701a9 100644
> --- a/lib/librte_power/power_acpi_cpufreq.h
> +++ b/lib/librte_power/power_acpi_cpufreq.h
> @@ -14,6 +14,7 @@
>   #include <rte_byteorder.h>
>   #include <rte_log.h>
>   #include <rte_string_fns.h>
> +#include "rte_power.h"
>   
>   #ifdef __cplusplus
>   extern "C" {
> @@ -196,6 +197,22 @@ int power_acpi_enable_turbo(unsigned int lcore_id);
>    */
>   int power_acpi_disable_turbo(unsigned int lcore_id);
>   
> +/**
> + * Returns power capabilities for a specific lcore.
> + *
> + * @param lcore_id
> + *  lcore id.
> + * @param caps
> + *  pointer to rte_power_core_capabilities object.
> + *
> + * @return
> + *  - 0 on success.
> + *  - Negative on error.
> + */
> +int power_acpi_get_capabilities(unsigned int lcore_id,
> +		struct rte_power_core_capabilities *caps);
> +
> +
>   #ifdef __cplusplus
>   }
>   #endif
> diff --git a/lib/librte_power/power_kvm_vm.c b/lib/librte_power/power_kvm_vm.c
> index 38e9066..20659b7 100644
> --- a/lib/librte_power/power_kvm_vm.c
> +++ b/lib/librte_power/power_kvm_vm.c
> @@ -124,3 +124,11 @@ power_kvm_vm_disable_turbo(unsigned int lcore_id)
>   {
>   	return send_msg(lcore_id, CPU_POWER_DISABLE_TURBO);
>   }
> +
> +struct rte_power_core_capabilities;
> +int power_kvm_vm_get_capabilities(__rte_unused unsigned int lcore_id,
> +		__rte_unused struct rte_power_core_capabilities *caps)
> +{
> +	RTE_LOG(ERR, POWER, "rte_power_get_capabilities is not implemented for Virtual Machine Power Management\n");
> +	return -ENOTSUP;
> +}
> diff --git a/lib/librte_power/power_kvm_vm.h b/lib/librte_power/power_kvm_vm.h
> index 446d699..94d4aa1 100644
> --- a/lib/librte_power/power_kvm_vm.h
> +++ b/lib/librte_power/power_kvm_vm.h
> @@ -14,6 +14,7 @@
>   #include <rte_byteorder.h>
>   #include <rte_log.h>
>   #include <rte_string_fns.h>
> +#include "rte_power.h"
>   
>   #ifdef __cplusplus
>   extern "C" {
> @@ -177,6 +178,22 @@ int power_kvm_vm_enable_turbo(unsigned int lcore_id);
>    *  - Negative on error.
>    */
>   int power_kvm_vm_disable_turbo(unsigned int lcore_id);
> +
> +/**
> + * Returns power capabilities for a specific lcore.
> + *
> + * @param lcore_id
> + *  lcore id.
> + * @param caps
> + *  pointer to rte_power_core_capabilities object.
> + *
> + * @return
> + *  - 0 on success.
> + *  - Negative on error.
> + */
> +int power_kvm_vm_get_capabilities(unsigned int lcore_id,
> +		struct rte_power_core_capabilities *caps);
> +
>   #ifdef __cplusplus
>   }
>   #endif
> diff --git a/lib/librte_power/rte_power.c b/lib/librte_power/rte_power.c
> index 6c8fb40..208b791 100644
> --- a/lib/librte_power/rte_power.c
> +++ b/lib/librte_power/rte_power.c
> @@ -24,6 +24,7 @@ rte_power_freq_change_t rte_power_freq_min = NULL;
>   rte_power_freq_change_t rte_power_turbo_status;
>   rte_power_freq_change_t rte_power_freq_enable_turbo;
>   rte_power_freq_change_t rte_power_freq_disable_turbo;
> +rte_power_get_capabilities_t rte_power_get_capabilities;
>   
>   int
>   rte_power_set_env(enum power_management_env env)
> @@ -42,6 +43,7 @@ rte_power_set_env(enum power_management_env env)
>   		rte_power_turbo_status = power_acpi_turbo_status;
>   		rte_power_freq_enable_turbo = power_acpi_enable_turbo;
>   		rte_power_freq_disable_turbo = power_acpi_disable_turbo;
> +		rte_power_get_capabilities = power_acpi_get_capabilities;
>   	} else if (env == PM_ENV_KVM_VM) {
>   		rte_power_freqs = power_kvm_vm_freqs;
>   		rte_power_get_freq = power_kvm_vm_get_freq;
> @@ -53,6 +55,7 @@ rte_power_set_env(enum power_management_env env)
>   		rte_power_turbo_status = power_kvm_vm_turbo_status;
>   		rte_power_freq_enable_turbo = power_kvm_vm_enable_turbo;
>   		rte_power_freq_disable_turbo = power_kvm_vm_disable_turbo;
> +		rte_power_get_capabilities = power_kvm_vm_get_capabilities;
>   	} else {
>   		RTE_LOG(ERR, POWER, "Invalid Power Management Environment(%d) set\n",
>   				env);
> diff --git a/lib/librte_power/rte_power.h b/lib/librte_power/rte_power.h
> index b4b7357..0a34b6f 100644
> --- a/lib/librte_power/rte_power.h
> +++ b/lib/librte_power/rte_power.h
> @@ -247,6 +247,39 @@ extern rte_power_freq_change_t rte_power_freq_enable_turbo;
>    */
>   extern rte_power_freq_change_t rte_power_freq_disable_turbo;
>   
> +/**
> + * Power capabilities summary.
> + */
> +struct rte_power_core_capabilities {
> +	RTE_STD_C11
> +	union {
> +		uint64_t capabilities;
> +		RTE_STD_C11
> +		struct {
> +			uint64_t turbo:1;	/**< Turbo can be enabled. */
> +		};
> +	};
> +};
> +
> +/**
> + * Returns power capabilities for a specific lcore.
> + * Function pointer definition. Review each environments
> + * specific documentation for usage.
> + *
> + * @param lcore_id
> + *  lcore id.
> + * @param caps
> + *  pointer to rte_power_core_capabilities object.
> + *
> + * @return
> + *  - 0 on success.
> + *  - Negative on error.
> + */
> +typedef int (*rte_power_get_capabilities_t)(unsigned int lcore_id,
> +		struct rte_power_core_capabilities *caps);
> +
> +extern rte_power_get_capabilities_t rte_power_get_capabilities;
> +
>   
>   #ifdef __cplusplus
>   }
> diff --git a/lib/librte_power/rte_power_version.map b/lib/librte_power/rte_power_version.map
> index 96dc42e..1c577fe 100644
> --- a/lib/librte_power/rte_power_version.map
> +++ b/lib/librte_power/rte_power_version.map
> @@ -25,4 +25,11 @@ DPDK_17.11 {
>   	rte_power_freq_enable_turbo;
>   	rte_power_turbo_status;
>   
> +} DPDK_2.0;
> +
> +DPDK_18.05 {
> +	global:
> +
> +	rte_power_get_capabilities;
> +
>   } DPDK_2.0;
> \ No newline at end of file

Acked-by: David Hunt<david.hunt@intel.com>
  
Thomas Monjalon July 12, 2018, 5:20 p.m. UTC | #2
26/06/2018 11:43, Hunt, David:
> 
> On 11/6/2018 11:03 AM, Radu Nicolau wrote:
> > New API added, rte_power_get_capabilities(), that allows the
> > application to query the power and performance capabilities
> > of the CPU cores.
> >
> > Signed-off-by: Radu Nicolau <radu.nicolau@intel.com>
> 
> Acked-by: David Hunt<david.hunt@intel.com>

Series applied with some fixes for the .map and spacing, thanks.
  

Patch

diff --git a/lib/librte_power/power_acpi_cpufreq.c b/lib/librte_power/power_acpi_cpufreq.c
index bce933e..cd5978d 100644
--- a/lib/librte_power/power_acpi_cpufreq.c
+++ b/lib/librte_power/power_acpi_cpufreq.c
@@ -623,3 +623,24 @@  power_acpi_disable_turbo(unsigned int lcore_id)
 
 	return 0;
 }
+
+int power_acpi_get_capabilities(unsigned int lcore_id,
+		struct rte_power_core_capabilities *caps)
+{
+	struct rte_power_info *pi;
+
+	if (lcore_id >= RTE_MAX_LCORE) {
+		RTE_LOG(ERR, POWER, "Invalid lcore ID\n");
+		return -1;
+	}
+	if (caps == NULL) {
+		RTE_LOG(ERR, POWER, "Invalid argument\n");
+		return -1;
+	}
+
+	pi = &lcore_power_info[lcore_id];
+	caps->capabilities = 0;
+	caps->turbo = !!(pi->turbo_available);
+
+	return 0;
+}
diff --git a/lib/librte_power/power_acpi_cpufreq.h b/lib/librte_power/power_acpi_cpufreq.h
index edeeb27..77701a9 100644
--- a/lib/librte_power/power_acpi_cpufreq.h
+++ b/lib/librte_power/power_acpi_cpufreq.h
@@ -14,6 +14,7 @@ 
 #include <rte_byteorder.h>
 #include <rte_log.h>
 #include <rte_string_fns.h>
+#include "rte_power.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -196,6 +197,22 @@  int power_acpi_enable_turbo(unsigned int lcore_id);
  */
 int power_acpi_disable_turbo(unsigned int lcore_id);
 
+/**
+ * Returns power capabilities for a specific lcore.
+ *
+ * @param lcore_id
+ *  lcore id.
+ * @param caps
+ *  pointer to rte_power_core_capabilities object.
+ *
+ * @return
+ *  - 0 on success.
+ *  - Negative on error.
+ */
+int power_acpi_get_capabilities(unsigned int lcore_id,
+		struct rte_power_core_capabilities *caps);
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_power/power_kvm_vm.c b/lib/librte_power/power_kvm_vm.c
index 38e9066..20659b7 100644
--- a/lib/librte_power/power_kvm_vm.c
+++ b/lib/librte_power/power_kvm_vm.c
@@ -124,3 +124,11 @@  power_kvm_vm_disable_turbo(unsigned int lcore_id)
 {
 	return send_msg(lcore_id, CPU_POWER_DISABLE_TURBO);
 }
+
+struct rte_power_core_capabilities;
+int power_kvm_vm_get_capabilities(__rte_unused unsigned int lcore_id,
+		__rte_unused struct rte_power_core_capabilities *caps)
+{
+	RTE_LOG(ERR, POWER, "rte_power_get_capabilities is not implemented for Virtual Machine Power Management\n");
+	return -ENOTSUP;
+}
diff --git a/lib/librte_power/power_kvm_vm.h b/lib/librte_power/power_kvm_vm.h
index 446d699..94d4aa1 100644
--- a/lib/librte_power/power_kvm_vm.h
+++ b/lib/librte_power/power_kvm_vm.h
@@ -14,6 +14,7 @@ 
 #include <rte_byteorder.h>
 #include <rte_log.h>
 #include <rte_string_fns.h>
+#include "rte_power.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -177,6 +178,22 @@  int power_kvm_vm_enable_turbo(unsigned int lcore_id);
  *  - Negative on error.
  */
 int power_kvm_vm_disable_turbo(unsigned int lcore_id);
+
+/**
+ * Returns power capabilities for a specific lcore.
+ *
+ * @param lcore_id
+ *  lcore id.
+ * @param caps
+ *  pointer to rte_power_core_capabilities object.
+ *
+ * @return
+ *  - 0 on success.
+ *  - Negative on error.
+ */
+int power_kvm_vm_get_capabilities(unsigned int lcore_id,
+		struct rte_power_core_capabilities *caps);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_power/rte_power.c b/lib/librte_power/rte_power.c
index 6c8fb40..208b791 100644
--- a/lib/librte_power/rte_power.c
+++ b/lib/librte_power/rte_power.c
@@ -24,6 +24,7 @@  rte_power_freq_change_t rte_power_freq_min = NULL;
 rte_power_freq_change_t rte_power_turbo_status;
 rte_power_freq_change_t rte_power_freq_enable_turbo;
 rte_power_freq_change_t rte_power_freq_disable_turbo;
+rte_power_get_capabilities_t rte_power_get_capabilities;
 
 int
 rte_power_set_env(enum power_management_env env)
@@ -42,6 +43,7 @@  rte_power_set_env(enum power_management_env env)
 		rte_power_turbo_status = power_acpi_turbo_status;
 		rte_power_freq_enable_turbo = power_acpi_enable_turbo;
 		rte_power_freq_disable_turbo = power_acpi_disable_turbo;
+		rte_power_get_capabilities = power_acpi_get_capabilities;
 	} else if (env == PM_ENV_KVM_VM) {
 		rte_power_freqs = power_kvm_vm_freqs;
 		rte_power_get_freq = power_kvm_vm_get_freq;
@@ -53,6 +55,7 @@  rte_power_set_env(enum power_management_env env)
 		rte_power_turbo_status = power_kvm_vm_turbo_status;
 		rte_power_freq_enable_turbo = power_kvm_vm_enable_turbo;
 		rte_power_freq_disable_turbo = power_kvm_vm_disable_turbo;
+		rte_power_get_capabilities = power_kvm_vm_get_capabilities;
 	} else {
 		RTE_LOG(ERR, POWER, "Invalid Power Management Environment(%d) set\n",
 				env);
diff --git a/lib/librte_power/rte_power.h b/lib/librte_power/rte_power.h
index b4b7357..0a34b6f 100644
--- a/lib/librte_power/rte_power.h
+++ b/lib/librte_power/rte_power.h
@@ -247,6 +247,39 @@  extern rte_power_freq_change_t rte_power_freq_enable_turbo;
  */
 extern rte_power_freq_change_t rte_power_freq_disable_turbo;
 
+/**
+ * Power capabilities summary.
+ */
+struct rte_power_core_capabilities {
+	RTE_STD_C11
+	union {
+		uint64_t capabilities;
+		RTE_STD_C11
+		struct {
+			uint64_t turbo:1;	/**< Turbo can be enabled. */
+		};
+	};
+};
+
+/**
+ * Returns power capabilities for a specific lcore.
+ * Function pointer definition. Review each environments
+ * specific documentation for usage.
+ *
+ * @param lcore_id
+ *  lcore id.
+ * @param caps
+ *  pointer to rte_power_core_capabilities object.
+ *
+ * @return
+ *  - 0 on success.
+ *  - Negative on error.
+ */
+typedef int (*rte_power_get_capabilities_t)(unsigned int lcore_id,
+		struct rte_power_core_capabilities *caps);
+
+extern rte_power_get_capabilities_t rte_power_get_capabilities;
+
 
 #ifdef __cplusplus
 }
diff --git a/lib/librte_power/rte_power_version.map b/lib/librte_power/rte_power_version.map
index 96dc42e..1c577fe 100644
--- a/lib/librte_power/rte_power_version.map
+++ b/lib/librte_power/rte_power_version.map
@@ -25,4 +25,11 @@  DPDK_17.11 {
 	rte_power_freq_enable_turbo;
 	rte_power_turbo_status;
 
+} DPDK_2.0;
+
+DPDK_18.05 {
+	global:
+
+	rte_power_get_capabilities;
+
 } DPDK_2.0;
\ No newline at end of file