power: clean KVM files
authorMarko Kovacevic <marko.kovacevic@intel.com>
Tue, 12 Dec 2017 14:03:27 +0000 (14:03 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 11 Jan 2018 23:37:07 +0000 (00:37 +0100)
rename private header file rte_power_kvm_vm.c
to power_kvm_vm.c. This prevents the private
functions from leaking into the documentation.
Change any private functions from
rte_<function_name> to just <function_name>.
Reserve the rte_ for public functions

Signed-off-by: Marko Kovacevic <marko.kovacevic@intel.com>
Acked-by: David Hunt <david.hunt@intel.com>
lib/librte_power/Makefile
lib/librte_power/power_kvm_vm.c [new file with mode: 0644]
lib/librte_power/power_kvm_vm.h [new file with mode: 0644]
lib/librte_power/rte_power.c
lib/librte_power/rte_power_kvm_vm.c [deleted file]
lib/librte_power/rte_power_kvm_vm.h [deleted file]

index 686d540..6f85e88 100644 (file)
@@ -15,7 +15,7 @@ LIBABIVER := 1
 
 # all source are stored in SRCS-y
 SRCS-$(CONFIG_RTE_LIBRTE_POWER) := rte_power.c power_acpi_cpufreq.c
-SRCS-$(CONFIG_RTE_LIBRTE_POWER) += rte_power_kvm_vm.c guest_channel.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) += power_kvm_vm.c guest_channel.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_POWER)-include := rte_power.h
diff --git a/lib/librte_power/power_kvm_vm.c b/lib/librte_power/power_kvm_vm.c
new file mode 100644 (file)
index 0000000..38e9066
--- /dev/null
@@ -0,0 +1,126 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ */
+#include <errno.h>
+#include <string.h>
+
+#include <rte_log.h>
+
+#include "guest_channel.h"
+#include "channel_commands.h"
+#include "power_kvm_vm.h"
+#include "power_common.h"
+
+#define FD_PATH "/dev/virtio-ports/virtio.serial.port.poweragent"
+
+static struct channel_packet pkt[CHANNEL_CMDS_MAX_VM_CHANNELS];
+
+
+int
+power_kvm_vm_init(unsigned int lcore_id)
+{
+       if (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {
+               RTE_LOG(ERR, POWER, "Core(%u) is out of range 0...%d\n",
+                               lcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);
+               return -1;
+       }
+       pkt[lcore_id].command = CPU_POWER;
+       pkt[lcore_id].resource_id = lcore_id;
+       return guest_channel_host_connect(FD_PATH, lcore_id);
+}
+
+int
+power_kvm_vm_exit(unsigned int lcore_id)
+{
+       guest_channel_host_disconnect(lcore_id);
+       return 0;
+}
+
+uint32_t
+power_kvm_vm_freqs(__attribute__((unused)) unsigned int lcore_id,
+               __attribute__((unused)) uint32_t *freqs,
+               __attribute__((unused)) uint32_t num)
+{
+       RTE_LOG(ERR, POWER, "rte_power_freqs is not implemented "
+                       "for Virtual Machine Power Management\n");
+       return -ENOTSUP;
+}
+
+uint32_t
+power_kvm_vm_get_freq(__attribute__((unused)) unsigned int lcore_id)
+{
+       RTE_LOG(ERR, POWER, "rte_power_get_freq is not implemented "
+                       "for Virtual Machine Power Management\n");
+       return -ENOTSUP;
+}
+
+int
+power_kvm_vm_set_freq(__attribute__((unused)) unsigned int lcore_id,
+               __attribute__((unused)) uint32_t index)
+{
+       RTE_LOG(ERR, POWER, "rte_power_set_freq is not implemented "
+                       "for Virtual Machine Power Management\n");
+       return -ENOTSUP;
+}
+
+static inline int
+send_msg(unsigned int lcore_id, uint32_t scale_direction)
+{
+       int ret;
+
+       if (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {
+               RTE_LOG(ERR, POWER, "Core(%u) is out of range 0...%d\n",
+                               lcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);
+               return -1;
+       }
+       pkt[lcore_id].unit = scale_direction;
+       ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);
+       if (ret == 0)
+               return 1;
+       RTE_LOG(DEBUG, POWER, "Error sending message: %s\n",
+                       ret > 0 ? strerror(ret) : "channel not connected");
+       return -1;
+}
+
+int
+power_kvm_vm_freq_up(unsigned int lcore_id)
+{
+       return send_msg(lcore_id, CPU_POWER_SCALE_UP);
+}
+
+int
+power_kvm_vm_freq_down(unsigned int lcore_id)
+{
+       return send_msg(lcore_id, CPU_POWER_SCALE_DOWN);
+}
+
+int
+power_kvm_vm_freq_max(unsigned int lcore_id)
+{
+       return send_msg(lcore_id, CPU_POWER_SCALE_MAX);
+}
+
+int
+power_kvm_vm_freq_min(unsigned int lcore_id)
+{
+       return send_msg(lcore_id, CPU_POWER_SCALE_MIN);
+}
+
+int
+power_kvm_vm_turbo_status(__attribute__((unused)) unsigned int lcore_id)
+{
+       RTE_LOG(ERR, POWER, "rte_power_turbo_status is not implemented for Virtual Machine Power Management\n");
+       return -ENOTSUP;
+}
+
+int
+power_kvm_vm_enable_turbo(unsigned int lcore_id)
+{
+       return send_msg(lcore_id, CPU_POWER_ENABLE_TURBO);
+}
+
+int
+power_kvm_vm_disable_turbo(unsigned int lcore_id)
+{
+       return send_msg(lcore_id, CPU_POWER_DISABLE_TURBO);
+}
diff --git a/lib/librte_power/power_kvm_vm.h b/lib/librte_power/power_kvm_vm.h
new file mode 100644 (file)
index 0000000..446d699
--- /dev/null
@@ -0,0 +1,183 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
+ */
+
+#ifndef _POWER_KVM_VM_H
+#define _POWER_KVM_VM_H
+
+/**
+ * @file
+ * RTE Power Management KVM VM
+ */
+
+#include <rte_common.h>
+#include <rte_byteorder.h>
+#include <rte_log.h>
+#include <rte_string_fns.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Initialize power management for a specific lcore.
+ *
+ * @param lcore_id
+ *  lcore id.
+ *
+ * @return
+ *  - 0 on success.
+ *  - Negative on error.
+ */
+int power_kvm_vm_init(unsigned int lcore_id);
+
+/**
+ * Exit power management on a specific lcore.
+ *
+ * @param lcore_id
+ *  lcore id.
+ *
+ * @return
+ *  - 0 on success.
+ *  - Negative on error.
+ */
+int power_kvm_vm_exit(unsigned int lcore_id);
+
+/**
+ * Get the available frequencies of a specific lcore.
+ * It is not currently supported for VM Power Management.
+ *
+ * @param lcore_id
+ *  lcore id.
+ * @param freqs
+ *  The buffer array to save the frequencies.
+ * @param num
+ *  The number of frequencies to get.
+ *
+ * @return
+ *  -ENOTSUP
+ */
+uint32_t power_kvm_vm_freqs(unsigned int lcore_id, uint32_t *freqs,
+               uint32_t num);
+
+/**
+ * Return the current index of available frequencies of a specific lcore.
+ * It is not currently supported for VM Power Management.
+ *
+ * @param lcore_id
+ *  lcore id.
+ *
+ * @return
+ *  -ENOTSUP
+ */
+uint32_t power_kvm_vm_get_freq(unsigned int lcore_id);
+
+/**
+ * Set the new frequency for a specific lcore by indicating the index of
+ * available frequencies.
+ * It is not currently supported for VM Power Management.
+ *
+ * @param lcore_id
+ *  lcore id.
+ * @param index
+ *  The index of available frequencies.
+ *
+ * @return
+ *  -ENOTSUP
+ */
+int power_kvm_vm_set_freq(unsigned int lcore_id, uint32_t index);
+
+/**
+ * Scale up the frequency of a specific lcore. This request is forwarded to the
+ * host monitor.
+ * It should be protected outside of this function for threadsafe.
+ *
+ * @param lcore_id
+ *  lcore id.
+ *
+ * @return
+ *  - 1 on success.
+ *  - Negative on error.
+ */
+int power_kvm_vm_freq_up(unsigned int lcore_id);
+
+/**
+ * Scale down the frequency of a specific lcore according to the available
+ * frequencies.
+ * It should be protected outside of this function for threadsafe.
+ *
+ * @param lcore_id
+ *  lcore id.
+ *
+ * @return
+ *  - 1 on success.
+ *  - Negative on error.
+ */
+int power_kvm_vm_freq_down(unsigned int lcore_id);
+
+/**
+ * Scale up the frequency of a specific lcore to the highest according to the
+ * available frequencies.
+ * It should be protected outside of this function for threadsafe.
+ *
+ * @param lcore_id
+ *  lcore id.
+ *
+ * @return
+ *  - 1 on success.
+ *  - Negative on error.
+ */
+int power_kvm_vm_freq_max(unsigned int lcore_id);
+
+/**
+ * Scale down the frequency of a specific lcore to the lowest according to the
+ * available frequencies.
+ * It should be protected outside of this function for threadsafe.
+ *
+ * @param lcore_id
+ *  lcore id.
+ *
+ * @return
+ *  - 1 on success.
+ *  - Negative on error.
+ */
+int power_kvm_vm_freq_min(unsigned int lcore_id);
+
+/**
+ * It should be protected outside of this function for threadsafe.
+ *
+ * @param lcore_id
+ *  lcore id.
+ *
+ * @return
+ *  -ENOTSUP
+ */
+int power_kvm_vm_turbo_status(unsigned int lcore_id);
+
+/**
+ * It should be protected outside of this function for threadsafe.
+ *
+ * @param lcore_id
+ *  lcore id.
+ *
+ * @return
+ *  - 1 on success.
+ *  - Negative on error.
+ */
+int power_kvm_vm_enable_turbo(unsigned int lcore_id);
+
+/**
+ * It should be protected outside of this function for threadsafe.
+ *
+ * @param lcore_id
+ *  lcore id.
+ *
+ * @return
+ *  - 1 on success.
+ *  - Negative on error.
+ */
+int power_kvm_vm_disable_turbo(unsigned int lcore_id);
+#ifdef __cplusplus
+}
+#endif
+#endif
index f3ded21..6c8fb40 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "rte_power.h"
 #include "power_acpi_cpufreq.h"
-#include "rte_power_kvm_vm.h"
+#include "power_kvm_vm.h"
 #include "power_common.h"
 
 enum power_management_env global_default_env = PM_ENV_NOT_SET;
@@ -43,16 +43,16 @@ rte_power_set_env(enum power_management_env env)
                rte_power_freq_enable_turbo = power_acpi_enable_turbo;
                rte_power_freq_disable_turbo = power_acpi_disable_turbo;
        } else if (env == PM_ENV_KVM_VM) {
-               rte_power_freqs = rte_power_kvm_vm_freqs;
-               rte_power_get_freq = rte_power_kvm_vm_get_freq;
-               rte_power_set_freq = rte_power_kvm_vm_set_freq;
-               rte_power_freq_up = rte_power_kvm_vm_freq_up;
-               rte_power_freq_down = rte_power_kvm_vm_freq_down;
-               rte_power_freq_min = rte_power_kvm_vm_freq_min;
-               rte_power_freq_max = rte_power_kvm_vm_freq_max;
-               rte_power_turbo_status = rte_power_kvm_vm_turbo_status;
-               rte_power_freq_enable_turbo = rte_power_kvm_vm_enable_turbo;
-               rte_power_freq_disable_turbo = rte_power_kvm_vm_disable_turbo;
+               rte_power_freqs = power_kvm_vm_freqs;
+               rte_power_get_freq = power_kvm_vm_get_freq;
+               rte_power_set_freq = power_kvm_vm_set_freq;
+               rte_power_freq_up = power_kvm_vm_freq_up;
+               rte_power_freq_down = power_kvm_vm_freq_down;
+               rte_power_freq_min = power_kvm_vm_freq_min;
+               rte_power_freq_max = power_kvm_vm_freq_max;
+               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;
        } else {
                RTE_LOG(ERR, POWER, "Invalid Power Management Environment(%d) set\n",
                                env);
@@ -85,7 +85,7 @@ rte_power_init(unsigned int lcore_id)
                return power_acpi_cpufreq_init(lcore_id);
        }
        if (global_default_env == PM_ENV_KVM_VM) {
-               return rte_power_kvm_vm_init(lcore_id);
+               return power_kvm_vm_init(lcore_id);
        }
        /* Auto detect Environment */
        RTE_LOG(INFO, POWER, "Attempting to initialise ACPI cpufreq power "
@@ -97,7 +97,7 @@ rte_power_init(unsigned int lcore_id)
        }
 
        RTE_LOG(INFO, POWER, "Attempting to initialise VM power management...\n");
-       ret = rte_power_kvm_vm_init(lcore_id);
+       ret = power_kvm_vm_init(lcore_id);
        if (ret == 0) {
                rte_power_set_env(PM_ENV_KVM_VM);
                goto out;
@@ -114,7 +114,7 @@ rte_power_exit(unsigned int lcore_id)
        if (global_default_env == PM_ENV_ACPI_CPUFREQ)
                return power_acpi_cpufreq_exit(lcore_id);
        if (global_default_env == PM_ENV_KVM_VM)
-               return rte_power_kvm_vm_exit(lcore_id);
+               return power_kvm_vm_exit(lcore_id);
 
        RTE_LOG(ERR, POWER, "Environment has not been set, unable to exit "
                                "gracefully\n");
diff --git a/lib/librte_power/rte_power_kvm_vm.c b/lib/librte_power/rte_power_kvm_vm.c
deleted file mode 100644 (file)
index caef4d9..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2010-2014 Intel Corporation
- */
-#include <errno.h>
-#include <string.h>
-
-#include <rte_log.h>
-
-#include "guest_channel.h"
-#include "channel_commands.h"
-#include "rte_power_kvm_vm.h"
-#include "power_common.h"
-
-#define FD_PATH "/dev/virtio-ports/virtio.serial.port.poweragent"
-
-static struct channel_packet pkt[CHANNEL_CMDS_MAX_VM_CHANNELS];
-
-
-int
-rte_power_kvm_vm_init(unsigned int lcore_id)
-{
-       if (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {
-               RTE_LOG(ERR, POWER, "Core(%u) is out of range 0...%d\n",
-                               lcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);
-               return -1;
-       }
-       pkt[lcore_id].command = CPU_POWER;
-       pkt[lcore_id].resource_id = lcore_id;
-       return guest_channel_host_connect(FD_PATH, lcore_id);
-}
-
-int
-rte_power_kvm_vm_exit(unsigned int lcore_id)
-{
-       guest_channel_host_disconnect(lcore_id);
-       return 0;
-}
-
-uint32_t
-rte_power_kvm_vm_freqs(__attribute__((unused)) unsigned int lcore_id,
-               __attribute__((unused)) uint32_t *freqs,
-               __attribute__((unused)) uint32_t num)
-{
-       RTE_LOG(ERR, POWER, "rte_power_freqs is not implemented "
-                       "for Virtual Machine Power Management\n");
-       return -ENOTSUP;
-}
-
-uint32_t
-rte_power_kvm_vm_get_freq(__attribute__((unused)) unsigned int lcore_id)
-{
-       RTE_LOG(ERR, POWER, "rte_power_get_freq is not implemented "
-                       "for Virtual Machine Power Management\n");
-       return -ENOTSUP;
-}
-
-int
-rte_power_kvm_vm_set_freq(__attribute__((unused)) unsigned int lcore_id,
-               __attribute__((unused)) uint32_t index)
-{
-       RTE_LOG(ERR, POWER, "rte_power_set_freq is not implemented "
-                       "for Virtual Machine Power Management\n");
-       return -ENOTSUP;
-}
-
-static inline int
-send_msg(unsigned int lcore_id, uint32_t scale_direction)
-{
-       int ret;
-
-       if (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {
-               RTE_LOG(ERR, POWER, "Core(%u) is out of range 0...%d\n",
-                               lcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);
-               return -1;
-       }
-       pkt[lcore_id].unit = scale_direction;
-       ret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);
-       if (ret == 0)
-               return 1;
-       RTE_LOG(DEBUG, POWER, "Error sending message: %s\n",
-                       ret > 0 ? strerror(ret) : "channel not connected");
-       return -1;
-}
-
-int
-rte_power_kvm_vm_freq_up(unsigned int lcore_id)
-{
-       return send_msg(lcore_id, CPU_POWER_SCALE_UP);
-}
-
-int
-rte_power_kvm_vm_freq_down(unsigned int lcore_id)
-{
-       return send_msg(lcore_id, CPU_POWER_SCALE_DOWN);
-}
-
-int
-rte_power_kvm_vm_freq_max(unsigned int lcore_id)
-{
-       return send_msg(lcore_id, CPU_POWER_SCALE_MAX);
-}
-
-int
-rte_power_kvm_vm_freq_min(unsigned int lcore_id)
-{
-       return send_msg(lcore_id, CPU_POWER_SCALE_MIN);
-}
-
-int
-rte_power_kvm_vm_turbo_status(__attribute__((unused)) unsigned int lcore_id)
-{
-       RTE_LOG(ERR, POWER, "rte_power_turbo_status is not implemented for Virtual Machine Power Management\n");
-       return -ENOTSUP;
-}
-
-int
-rte_power_kvm_vm_enable_turbo(unsigned int lcore_id)
-{
-       return send_msg(lcore_id, CPU_POWER_ENABLE_TURBO);
-}
-
-int
-rte_power_kvm_vm_disable_turbo(unsigned int lcore_id)
-{
-       return send_msg(lcore_id, CPU_POWER_DISABLE_TURBO);
-}
diff --git a/lib/librte_power/rte_power_kvm_vm.h b/lib/librte_power/rte_power_kvm_vm.h
deleted file mode 100644 (file)
index 3d50c97..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2010-2014 Intel Corporation
- */
-
-#ifndef _RTE_POWER_KVM_VM_H
-#define _RTE_POWER_KVM_VM_H
-
-/**
- * @file
- * RTE Power Management KVM VM
- */
-
-#include <rte_common.h>
-#include <rte_byteorder.h>
-#include <rte_log.h>
-#include <rte_string_fns.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * Initialize power management for a specific lcore.
- *
- * @param lcore_id
- *  lcore id.
- *
- * @return
- *  - 0 on success.
- *  - Negative on error.
- */
-int rte_power_kvm_vm_init(unsigned int lcore_id);
-
-/**
- * Exit power management on a specific lcore.
- *
- * @param lcore_id
- *  lcore id.
- *
- * @return
- *  - 0 on success.
- *  - Negative on error.
- */
-int rte_power_kvm_vm_exit(unsigned int lcore_id);
-
-/**
- * Get the available frequencies of a specific lcore.
- * It is not currently supported for VM Power Management.
- *
- * @param lcore_id
- *  lcore id.
- * @param freqs
- *  The buffer array to save the frequencies.
- * @param num
- *  The number of frequencies to get.
- *
- * @return
- *  -ENOTSUP
- */
-uint32_t rte_power_kvm_vm_freqs(unsigned int lcore_id, uint32_t *freqs,
-               uint32_t num);
-
-/**
- * Return the current index of available frequencies of a specific lcore.
- * It is not currently supported for VM Power Management.
- *
- * @param lcore_id
- *  lcore id.
- *
- * @return
- *  -ENOTSUP
- */
-uint32_t rte_power_kvm_vm_get_freq(unsigned int lcore_id);
-
-/**
- * Set the new frequency for a specific lcore by indicating the index of
- * available frequencies.
- * It is not currently supported for VM Power Management.
- *
- * @param lcore_id
- *  lcore id.
- * @param index
- *  The index of available frequencies.
- *
- * @return
- *  -ENOTSUP
- */
-int rte_power_kvm_vm_set_freq(unsigned int lcore_id, uint32_t index);
-
-/**
- * Scale up the frequency of a specific lcore. This request is forwarded to the
- * host monitor.
- * It should be protected outside of this function for threadsafe.
- *
- * @param lcore_id
- *  lcore id.
- *
- * @return
- *  - 1 on success.
- *  - Negative on error.
- */
-int rte_power_kvm_vm_freq_up(unsigned int lcore_id);
-
-/**
- * Scale down the frequency of a specific lcore according to the available
- * frequencies.
- * It should be protected outside of this function for threadsafe.
- *
- * @param lcore_id
- *  lcore id.
- *
- * @return
- *  - 1 on success.
- *  - Negative on error.
- */
-int rte_power_kvm_vm_freq_down(unsigned int lcore_id);
-
-/**
- * Scale up the frequency of a specific lcore to the highest according to the
- * available frequencies.
- * It should be protected outside of this function for threadsafe.
- *
- * @param lcore_id
- *  lcore id.
- *
- * @return
- *  - 1 on success.
- *  - Negative on error.
- */
-int rte_power_kvm_vm_freq_max(unsigned int lcore_id);
-
-/**
- * Scale down the frequency of a specific lcore to the lowest according to the
- * available frequencies.
- * It should be protected outside of this function for threadsafe.
- *
- * @param lcore_id
- *  lcore id.
- *
- * @return
- *  - 1 on success.
- *  - Negative on error.
- */
-int rte_power_kvm_vm_freq_min(unsigned int lcore_id);
-
-/**
- * It should be protected outside of this function for threadsafe.
- *
- * @param lcore_id
- *  lcore id.
- *
- * @return
- *  -ENOTSUP
- */
-int rte_power_kvm_vm_turbo_status(unsigned int lcore_id);
-
-/**
- * It should be protected outside of this function for threadsafe.
- *
- * @param lcore_id
- *  lcore id.
- *
- * @return
- *  - 1 on success.
- *  - Negative on error.
- */
-int rte_power_kvm_vm_enable_turbo(unsigned int lcore_id);
-
-/**
- * It should be protected outside of this function for threadsafe.
- *
- * @param lcore_id
- *  lcore id.
- *
- * @return
- *  - 1 on success.
- *  - Negative on error.
- */
-int rte_power_kvm_vm_disable_turbo(unsigned int lcore_id);
-#ifdef __cplusplus
-}
-#endif
-#endif