get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/1448/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1448,
    "url": "https://patches.dpdk.org/api/patches/1448/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1416591732-3735-8-git-send-email-pablo.de.lara.guarch@intel.com/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1416591732-3735-8-git-send-email-pablo.de.lara.guarch@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1416591732-3735-8-git-send-email-pablo.de.lara.guarch@intel.com",
    "date": "2014-11-21T17:42:09",
    "name": "[dpdk-dev,v5,07/10] librte_power common interface for Guest and Host",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "47f41bb271b60ab52ff6b293f891d54a80c908e3",
    "submitter": {
        "id": 9,
        "url": "https://patches.dpdk.org/api/people/9/?format=api",
        "name": "De Lara Guarch, Pablo",
        "email": "pablo.de.lara.guarch@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1416591732-3735-8-git-send-email-pablo.de.lara.guarch@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/1448/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/1448/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 34C197FA8;\n\tFri, 21 Nov 2014 18:32:16 +0100 (CET)",
            "from mga01.intel.com (mga01.intel.com [192.55.52.88])\n\tby dpdk.org (Postfix) with ESMTP id CC8417FA8\n\tfor <dev@dpdk.org>; Fri, 21 Nov 2014 18:32:01 +0100 (CET)",
            "from fmsmga001.fm.intel.com ([10.253.24.23])\n\tby fmsmga101.fm.intel.com with ESMTP; 21 Nov 2014 09:42:34 -0800",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby fmsmga001.fm.intel.com with ESMTP; 21 Nov 2014 09:42:22 -0800",
            "from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com\n\t[10.237.217.46])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\tsALHgGSg001859; Fri, 21 Nov 2014 17:42:21 GMT",
            "from sivswdev02.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev02.ir.intel.com with ESMTP id sALHgGDV012239;\n\tFri, 21 Nov 2014 17:42:16 GMT",
            "(from pdelarax@localhost)\n\tby sivswdev02.ir.intel.com with  id sALHgGS9012235;\n\tFri, 21 Nov 2014 17:42:16 GMT"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.07,432,1413270000\"; d=\"scan'208\";a=\"626304603\"",
        "From": "Pablo de Lara <pablo.de.lara.guarch@intel.com>",
        "To": "dev@dpdk.org",
        "Date": "Fri, 21 Nov 2014 17:42:09 +0000",
        "Message-Id": "<1416591732-3735-8-git-send-email-pablo.de.lara.guarch@intel.com>",
        "X-Mailer": "git-send-email 1.7.4.1",
        "In-Reply-To": "<1416591732-3735-1-git-send-email-pablo.de.lara.guarch@intel.com>",
        "References": "<1413142571-23069-1-git-send-email-alan.carew@intel.com>\n\t<1416591732-3735-1-git-send-email-pablo.de.lara.guarch@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v5 07/10] librte_power common interface for Guest\n\tand Host",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "From: Alan Carew <alan.carew@intel.com>\n\nMoved the current librte_power implementation to rte_power_acpi_cpufreq, with\nrenaming of functions only.\nAdded rte_power_kvm_vm implmentation to support Power Management from a VM.\n\nlibrte_power now hides the implementation based on the environment used.\nA new call rte_power_set_env() can explicidly set the environment, if not\ncalled then auto-detection takes place.\n\nrte_power_kvm_vm is subset of the librte_power APIs, the following is supported:\n rte_power_init(unsigned lcore_id)\n rte_power_exit(unsigned lcore_id)\n rte_power_freq_up(unsigned lcore_id)\n rte_power_freq_down(unsigned lcore_id)\n rte_power_freq_min(unsigned lcore_id)\n rte_power_freq_max(unsigned lcore_id)\n\nThe other unsupported APIs return -ENOTSUP\n\nSigned-off-by: Alan Carew <alan.carew@intel.com>\nSigned-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>\n---\n lib/librte_power/rte_power.c              |  540 ++++-------------------------\n lib/librte_power/rte_power.h              |  120 +++++--\n lib/librte_power/rte_power_acpi_cpufreq.c |  545 +++++++++++++++++++++++++++++\n lib/librte_power/rte_power_acpi_cpufreq.h |  192 ++++++++++\n lib/librte_power/rte_power_common.h       |   39 ++\n lib/librte_power/rte_power_kvm_vm.c       |  135 +++++++\n lib/librte_power/rte_power_kvm_vm.h       |  179 ++++++++++\n 7 files changed, 1248 insertions(+), 502 deletions(-)\n create mode 100644 lib/librte_power/rte_power_acpi_cpufreq.c\n create mode 100644 lib/librte_power/rte_power_acpi_cpufreq.h\n create mode 100644 lib/librte_power/rte_power_common.h\n create mode 100644 lib/librte_power/rte_power_kvm_vm.c\n create mode 100644 lib/librte_power/rte_power_kvm_vm.h",
    "diff": "diff --git a/lib/librte_power/rte_power.c b/lib/librte_power/rte_power.c\nindex 856da9a..998ed1c 100644\n--- a/lib/librte_power/rte_power.c\n+++ b/lib/librte_power/rte_power.c\n@@ -31,515 +31,113 @@\n  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n  */\n \n-#include <stdio.h>\n-#include <sys/types.h>\n-#include <sys/stat.h>\n-#include <fcntl.h>\n-#include <stdlib.h>\n-#include <string.h>\n-#include <unistd.h>\n-#include <signal.h>\n-#include <limits.h>\n-\n-#include <rte_memcpy.h>\n #include <rte_atomic.h>\n \n #include \"rte_power.h\"\n+#include \"rte_power_acpi_cpufreq.h\"\n+#include \"rte_power_kvm_vm.h\"\n+#include \"rte_power_common.h\"\n \n-#ifdef RTE_LIBRTE_POWER_DEBUG\n-#define POWER_DEBUG_TRACE(fmt, args...) do { \\\n-\t\tRTE_LOG(ERR, POWER, \"%s: \" fmt, __func__, ## args); \\\n-\t} while (0)\n-#else\n-#define POWER_DEBUG_TRACE(fmt, args...)\n-#endif\n-\n-#define FOPEN_OR_ERR_RET(f, retval) do { \\\n-\tif ((f) == NULL) { \\\n-\t\tRTE_LOG(ERR, POWER, \"File not openned\\n\"); \\\n-\t\treturn (retval); \\\n-\t} \\\n-} while(0)\n-\n-#define FOPS_OR_NULL_GOTO(ret, label) do { \\\n-\tif ((ret) == NULL) { \\\n-\t\tRTE_LOG(ERR, POWER, \"fgets returns nothing\\n\"); \\\n-\t\tgoto label; \\\n-\t} \\\n-} while(0)\n-\n-#define FOPS_OR_ERR_GOTO(ret, label) do { \\\n-\tif ((ret) < 0) { \\\n-\t\tRTE_LOG(ERR, POWER, \"File operations failed\\n\"); \\\n-\t\tgoto label; \\\n-\t} \\\n-} while(0)\n-\n-#define STR_SIZE     1024\n-#define POWER_CONVERT_TO_DECIMAL 10\n+enum power_management_env global_default_env = PM_ENV_NOT_SET;\n \n-#define POWER_GOVERNOR_USERSPACE \"userspace\"\n-#define POWER_SYSFILE_GOVERNOR   \\\n-\t\"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_governor\"\n-#define POWER_SYSFILE_AVAIL_FREQ \\\n-\t\"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_frequencies\"\n-#define POWER_SYSFILE_SETSPEED   \\\n-\t\"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_setspeed\"\n+volatile uint32_t global_env_cfg_status = 0;\n \n-enum power_state {\n-\tPOWER_IDLE = 0,\n-\tPOWER_ONGOING,\n-\tPOWER_USED,\n-\tPOWER_UNKNOWN\n-};\n+/* function pointers */\n+rte_power_freqs_t rte_power_freqs  = NULL;\n+rte_power_get_freq_t rte_power_get_freq = NULL;\n+rte_power_set_freq_t rte_power_set_freq = NULL;\n+rte_power_freq_change_t rte_power_freq_up = NULL;\n+rte_power_freq_change_t rte_power_freq_down = NULL;\n+rte_power_freq_change_t rte_power_freq_max = NULL;\n+rte_power_freq_change_t rte_power_freq_min = NULL;\n \n-/**\n- * Power info per lcore.\n- */\n-struct rte_power_info {\n-\tunsigned lcore_id;                   /**< Logical core id */\n-\tuint32_t freqs[RTE_MAX_LCORE_FREQS]; /**< Frequency array */\n-\tuint32_t nb_freqs;                   /**< number of available freqs */\n-\tFILE *f;                             /**< FD of scaling_setspeed */\n-\tchar governor_ori[32];               /**< Original governor name */\n-\tuint32_t curr_idx;                   /**< Freq index in freqs array */\n-\tvolatile uint32_t state;             /**< Power in use state */\n-} __rte_cache_aligned;\n-\n-static struct rte_power_info lcore_power_info[RTE_MAX_LCORE];\n-\n-/**\n- * It is to set specific freq for specific logical core, according to the index\n- * of supported frequencies.\n- */\n-static int\n-set_freq_internal(struct rte_power_info *pi, uint32_t idx)\n+int\n+rte_power_set_env(enum power_management_env env)\n {\n-\tif (idx >= RTE_MAX_LCORE_FREQS || idx >= pi->nb_freqs) {\n-\t\tRTE_LOG(ERR, POWER, \"Invalid frequency index %u, which \"\n-\t\t\t\"should be less than %u\\n\", idx, pi->nb_freqs);\n-\t\treturn -1;\n-\t}\n-\n-\t/* Check if it is the same as current */\n-\tif (idx == pi->curr_idx)\n+\tif (rte_atomic32_cmpset(&global_env_cfg_status, 0, 1) == 0) {\n \t\treturn 0;\n-\n-\tPOWER_DEBUG_TRACE(\"Freqency[%u] %u to be set for lcore %u\\n\",\n-\t\t\t\tidx, pi->freqs[idx], pi->lcore_id);\n-\tif (fseek(pi->f, 0, SEEK_SET) < 0) {\n-\t\tRTE_LOG(ERR, POWER, \"Fail to set file position indicator to 0 \"\n-\t\t\t\"for setting frequency for lcore %u\\n\", pi->lcore_id);\n-\t\treturn -1;\n \t}\n-\tif (fprintf(pi->f, \"%u\", pi->freqs[idx]) < 0) {\n-\t\tRTE_LOG(ERR, POWER, \"Fail to write new frequency for \"\n-\t\t\t\t\t\"lcore %u\\n\", pi->lcore_id);\n+\tif (env == PM_ENV_ACPI_CPUFREQ) {\n+\t\trte_power_freqs = rte_power_acpi_cpufreq_freqs;\n+\t\trte_power_get_freq = rte_power_acpi_cpufreq_get_freq;\n+\t\trte_power_set_freq = rte_power_acpi_cpufreq_set_freq;\n+\t\trte_power_freq_up = rte_power_acpi_cpufreq_freq_up;\n+\t\trte_power_freq_down = rte_power_acpi_cpufreq_freq_down;\n+\t\trte_power_freq_min = rte_power_acpi_cpufreq_freq_min;\n+\t\trte_power_freq_max = rte_power_acpi_cpufreq_freq_max;\n+\t} else if (env == PM_ENV_KVM_VM) {\n+\t\trte_power_freqs = rte_power_kvm_vm_freqs;\n+\t\trte_power_get_freq = rte_power_kvm_vm_get_freq;\n+\t\trte_power_set_freq = rte_power_kvm_vm_set_freq;\n+\t\trte_power_freq_up = rte_power_kvm_vm_freq_up;\n+\t\trte_power_freq_down = rte_power_kvm_vm_freq_down;\n+\t\trte_power_freq_min = rte_power_kvm_vm_freq_min;\n+\t\trte_power_freq_max = rte_power_kvm_vm_freq_max;\n+\t} else {\n+\t\tRTE_LOG(ERR, POWER, \"Invalid Power Management Environment(%d) set\\n\",\n+\t\t\t\tenv);\n+\t\trte_power_unset_env();\n \t\treturn -1;\n \t}\n-\tfflush(pi->f);\n-\tpi->curr_idx = idx;\n-\n-\treturn 1;\n-}\n-\n-/**\n- * It is to check the current scaling governor by reading sys file, and then\n- * set it into 'userspace' if it is not by writing the sys file. The original\n- * governor will be saved for rolling back.\n- */\n-static int\n-power_set_governor_userspace(struct rte_power_info *pi)\n-{\n-\tFILE *f;\n-\tint ret = -1;\n-\tchar buf[BUFSIZ];\n-\tchar fullpath[PATH_MAX];\n-\tchar *s;\n-\tint val;\n-\n-\tsnprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,\n-\t\t\t\t\t\t\tpi->lcore_id);\n-\tf = fopen(fullpath, \"rw+\");\n-\tFOPEN_OR_ERR_RET(f, ret);\n-\n-\ts = fgets(buf, sizeof(buf), f);\n-\tFOPS_OR_NULL_GOTO(s, out);\n-\n-\t/* Check if current governor is userspace */\n-\tif (strncmp(buf, POWER_GOVERNOR_USERSPACE,\n-\t\tsizeof(POWER_GOVERNOR_USERSPACE)) == 0) {\n-\t\tret = 0;\n-\t\tPOWER_DEBUG_TRACE(\"Power management governor of lcore %u is \"\n-\t\t\t\t\t\"already userspace\\n\", pi->lcore_id);\n-\t\tgoto out;\n-\t}\n-\t/* Save the original governor */\n-\tsnprintf(pi->governor_ori, sizeof(pi->governor_ori), \"%s\", buf);\n-\n-\t/* Write 'userspace' to the governor */\n-\tval = fseek(f, 0, SEEK_SET);\n-\tFOPS_OR_ERR_GOTO(val, out);\n-\n-\tval = fputs(POWER_GOVERNOR_USERSPACE, f);\n-\tFOPS_OR_ERR_GOTO(val, out);\n-\n-\tret = 0;\n-\tRTE_LOG(INFO, POWER, \"Power management governor of lcore %u has been \"\n-\t\t\t\"set to user space successfully\\n\", pi->lcore_id);\n-out:\n-\tfclose(f);\n+\tglobal_default_env = env;\n+\treturn 0;\n \n-\treturn ret;\n }\n \n-/**\n- * It is to get the available frequencies of the specific lcore by reading the\n- * sys file.\n- */\n-static int\n-power_get_available_freqs(struct rte_power_info *pi)\n+void\n+rte_power_unset_env(void)\n {\n-\tFILE *f;\n-\tint ret = -1, i, count;\n-\tchar *p;\n-\tchar buf[BUFSIZ];\n-\tchar fullpath[PATH_MAX];\n-\tchar *freqs[RTE_MAX_LCORE_FREQS];\n-\tchar *s;\n-\n-\tsnprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_AVAIL_FREQ,\n-\t\t\t\t\t\t\t\tpi->lcore_id);\n-\tf = fopen(fullpath, \"r\");\n-\tFOPEN_OR_ERR_RET(f, ret);\n-\n-\ts = fgets(buf, sizeof(buf), f);\n-\tFOPS_OR_NULL_GOTO(s, out);\n-\n-\t/* Strip the line break if there is */\n-\tp = strchr(buf, '\\n');\n-\tif (p != NULL)\n-\t\t*p = 0;\n-\n-\t/* Split string into at most RTE_MAX_LCORE_FREQS frequencies */\n-\tcount = rte_strsplit(buf, sizeof(buf), freqs,\n-\t\t\t\tRTE_MAX_LCORE_FREQS, ' ');\n-\tif (count <= 0) {\n-\t\tRTE_LOG(ERR, POWER, \"No available frequency in \"\n-\t\t\t\"\"POWER_SYSFILE_AVAIL_FREQ\"\\n\", pi->lcore_id);\n-\t\tgoto out;\n-\t}\n-\tif (count >= RTE_MAX_LCORE_FREQS) {\n-\t\tRTE_LOG(ERR, POWER, \"Too many available frequencies : %d\\n\",\n-\t\t\t\t\t\t\t\tcount);\n-\t\tgoto out;\n-\t}\n-\n-\t/* Store the available frequncies into power context */\n-\tfor (i = 0, pi->nb_freqs = 0; i < count; i++) {\n-\t\tPOWER_DEBUG_TRACE(\"Lcore %u frequency[%d]: %s\\n\", pi->lcore_id,\n-\t\t\t\t\t\t\t\ti, freqs[i]);\n-\t\tpi->freqs[pi->nb_freqs++] = strtoul(freqs[i], &p,\n-\t\t\t\t\tPOWER_CONVERT_TO_DECIMAL);\n-\t}\n-\n-\tret = 0;\n-\tPOWER_DEBUG_TRACE(\"%d frequencie(s) of lcore %u are available\\n\",\n-\t\t\t\t\t\tcount, pi->lcore_id);\n-out:\n-\tfclose(f);\n-\n-\treturn ret;\n+\tif (rte_atomic32_cmpset(&global_env_cfg_status, 1, 0) != 0)\n+\t\tglobal_default_env = PM_ENV_NOT_SET;\n }\n \n-/**\n- * It is to fopen the sys file for the future setting the lcore frequency.\n- */\n-static int\n-power_init_for_setting_freq(struct rte_power_info *pi)\n-{\n-\tFILE *f;\n-\tchar fullpath[PATH_MAX];\n-\tchar buf[BUFSIZ];\n-\tuint32_t i, freq;\n-\tchar *s;\n-\n-\tsnprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_SETSPEED,\n-\t\t\t\t\t\t\tpi->lcore_id);\n-\tf = fopen(fullpath, \"rw+\");\n-\tFOPEN_OR_ERR_RET(f, -1);\n-\n-\ts = fgets(buf, sizeof(buf), f);\n-\tFOPS_OR_NULL_GOTO(s, out);\n-\n-\tfreq = strtoul(buf, NULL, POWER_CONVERT_TO_DECIMAL);\n-\tfor (i = 0; i < pi->nb_freqs; i++) {\n-\t\tif (freq == pi->freqs[i]) {\n-\t\t\tpi->curr_idx = i;\n-\t\t\tpi->f = f;\n-\t\t\treturn 0;\n-\t\t}\n-\t}\n-\n-out:\n-\tfclose(f);\n-\n-\treturn -1;\n+enum power_management_env\n+rte_power_get_env(void) {\n+\treturn global_default_env;\n }\n \n int\n rte_power_init(unsigned lcore_id)\n {\n-\tstruct rte_power_info *pi;\n-\n-\tif (lcore_id >= RTE_MAX_LCORE) {\n-\t\tRTE_LOG(ERR, POWER, \"Lcore id %u can not exceeds %u\\n\",\n-\t\t\t\t\tlcore_id, RTE_MAX_LCORE - 1U);\n-\t\treturn -1;\n-\t}\n-\n-\tpi = &lcore_power_info[lcore_id];\n-\tif (rte_atomic32_cmpset(&(pi->state), POWER_IDLE, POWER_ONGOING)\n-\t\t\t\t\t\t\t\t== 0) {\n-\t\tRTE_LOG(INFO, POWER, \"Power management of lcore %u is \"\n-\t\t\t\t\t\t\"in use\\n\", lcore_id);\n-\t\treturn -1;\n-\t}\n-\n-\tpi->lcore_id = lcore_id;\n-\t/* Check and set the governor */\n-\tif (power_set_governor_userspace(pi) < 0) {\n-\t\tRTE_LOG(ERR, POWER, \"Cannot set governor of lcore %u to \"\n-\t\t\t\t\t\t\"userspace\\n\", lcore_id);\n-\t\tgoto fail;\n-\t}\n+\tint ret = -1;\n \n-\t/* Get the available frequencies */\n-\tif (power_get_available_freqs(pi) < 0) {\n-\t\tRTE_LOG(ERR, POWER, \"Cannot get available frequencies of \"\n-\t\t\t\t\t\t\"lcore %u\\n\", lcore_id);\n-\t\tgoto fail;\n+\tif (global_default_env == PM_ENV_ACPI_CPUFREQ) {\n+\t\treturn rte_power_acpi_cpufreq_init(lcore_id);\n \t}\n-\n-\t/* Init for setting lcore frequency */\n-\tif (power_init_for_setting_freq(pi) < 0) {\n-\t\tRTE_LOG(ERR, POWER, \"Cannot init for setting frequency for \"\n-\t\t\t\t\t\t\"lcore %u\\n\", lcore_id);\n-\t\tgoto fail;\n+\tif (global_default_env == PM_ENV_KVM_VM) {\n+\t\treturn rte_power_kvm_vm_init(lcore_id);\n \t}\n-\n-\t/* Set freq to max by default */\n-\tif (rte_power_freq_max(lcore_id) < 0) {\n-\t\tRTE_LOG(ERR, POWER, \"Cannot set frequency of lcore %u \"\n-\t\t\t\t\t\t\"to max\\n\", lcore_id);\n-\t\tgoto fail;\n+\t/* Auto detect Environment */\n+\tRTE_LOG(INFO, POWER, \"Attempting to initialise ACPI cpufreq power \"\n+\t\t\t\"management...\\n\");\n+\tret = rte_power_acpi_cpufreq_init(lcore_id);\n+\tif (ret == 0) {\n+\t\trte_power_set_env(PM_ENV_ACPI_CPUFREQ);\n+\t\tgoto out;\n \t}\n \n-\tRTE_LOG(INFO, POWER, \"Initialized successfully for lcore %u \"\n-\t\t\t\t\t\"power manamgement\\n\", lcore_id);\n-\trte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_USED);\n-\n-\treturn 0;\n-\n-fail:\n-\trte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_UNKNOWN);\n-\n-\treturn -1;\n-}\n-\n-/**\n- * It is to check the governor and then set the original governor back if\n- * needed by writing the the sys file.\n- */\n-static int\n-power_set_governor_original(struct rte_power_info *pi)\n-{\n-\tFILE *f;\n-\tint ret = -1;\n-\tchar buf[BUFSIZ];\n-\tchar fullpath[PATH_MAX];\n-\tchar *s;\n-\tint val;\n-\n-\tsnprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,\n-\t\t\t\t\t\t\tpi->lcore_id);\n-\tf = fopen(fullpath, \"rw+\");\n-\tFOPEN_OR_ERR_RET(f, ret);\n-\n-\ts = fgets(buf, sizeof(buf), f);\n-\tFOPS_OR_NULL_GOTO(s, out);\n-\n-\t/* Check if the governor to be set is the same as current */\n-\tif (strncmp(buf, pi->governor_ori, sizeof(pi->governor_ori)) == 0) {\n-\t\tret = 0;\n-\t\tPOWER_DEBUG_TRACE(\"Power management governor of lcore %u \"\n-\t\t\t\t\t\"has already been set to %s\\n\",\n-\t\t\t\t\tpi->lcore_id, pi->governor_ori);\n+\tRTE_LOG(INFO, POWER, \"Attempting to initialise VM power management...\\n\");\n+\tret = rte_power_kvm_vm_init(lcore_id);\n+\tif (ret == 0) {\n+\t\trte_power_set_env(PM_ENV_KVM_VM);\n \t\tgoto out;\n \t}\n-\n-\t/* Write back the original governor */\n-\tval = fseek(f, 0, SEEK_SET);\n-\tFOPS_OR_ERR_GOTO(val, out);\n-\n-\tval = fputs(pi->governor_ori, f);\n-\tFOPS_OR_ERR_GOTO(val, out);\n-\n-\tret = 0;\n-\tRTE_LOG(INFO, POWER, \"Power manamgement governor of lcore %u \"\n-\t\t\t\t\"has been set back to %s successfully\\n\",\n-\t\t\t\t\tpi->lcore_id, pi->governor_ori);\n+\tRTE_LOG(ERR, POWER, \"Unable to set Power Management Environment for lcore \"\n+\t\t\t\"%u\\n\", lcore_id);\n out:\n-\tfclose(f);\n-\n \treturn ret;\n }\n \n int\n rte_power_exit(unsigned lcore_id)\n {\n-\tstruct rte_power_info *pi;\n-\n-\tif (lcore_id >= RTE_MAX_LCORE) {\n-\t\tRTE_LOG(ERR, POWER, \"Lcore id %u can not exceeds %u\\n\",\n-\t\t\t\t\tlcore_id, RTE_MAX_LCORE - 1U);\n-\t\treturn -1;\n-\t}\n-\tpi = &lcore_power_info[lcore_id];\n-\tif (rte_atomic32_cmpset(&(pi->state), POWER_USED, POWER_ONGOING)\n-\t\t\t\t\t\t\t\t== 0) {\n-\t\tRTE_LOG(INFO, POWER, \"Power management of lcore %u is \"\n-\t\t\t\t\t\t\"not used\\n\", lcore_id);\n-\t\treturn -1;\n-\t}\n-\n-\t/* Close FD of setting freq */\n-\tfclose(pi->f);\n-\tpi->f = NULL;\n-\n-\t/* Set the governor back to the original */\n-\tif (power_set_governor_original(pi) < 0) {\n-\t\tRTE_LOG(ERR, POWER, \"Cannot set the governor of %u back \"\n-\t\t\t\t\t\"to the original\\n\", lcore_id);\n-\t\tgoto fail;\n-\t}\n-\n-\tRTE_LOG(INFO, POWER, \"Power management of lcore %u has exited from \"\n-\t\t\t\t\"'userspace' mode and been set back to the \"\n-\t\t\t\t\t\t\"original\\n\", lcore_id);\n-\trte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_IDLE);\n-\n-\treturn 0;\n-\n-fail:\n-\trte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_UNKNOWN);\n+\tif (global_default_env == PM_ENV_ACPI_CPUFREQ)\n+\t\treturn rte_power_acpi_cpufreq_exit(lcore_id);\n+\tif (global_default_env == PM_ENV_KVM_VM)\n+\t\treturn rte_power_kvm_vm_exit(lcore_id);\n \n+\tRTE_LOG(ERR, POWER, \"Environment has not been set, unable to exit \"\n+\t\t\t\t\"gracefully\\n\");\n \treturn -1;\n-}\n-\n-uint32_t\n-rte_power_freqs(unsigned lcore_id, uint32_t *freqs, uint32_t num)\n-{\n-\tstruct rte_power_info *pi;\n-\n-\tif (lcore_id >= RTE_MAX_LCORE || !freqs) {\n-\t\tRTE_LOG(ERR, POWER, \"Invalid input parameter\\n\");\n-\t\treturn 0;\n-\t}\n-\n-\tpi = &lcore_power_info[lcore_id];\n-\tif (num < pi->nb_freqs) {\n-\t\tRTE_LOG(ERR, POWER, \"Buffer size is not enough\\n\");\n-\t\treturn 0;\n-\t}\n-\trte_memcpy(freqs, pi->freqs, pi->nb_freqs * sizeof(uint32_t));\n-\n-\treturn pi->nb_freqs;\n-}\n-\n-uint32_t\n-rte_power_get_freq(unsigned lcore_id)\n-{\n-\tif (lcore_id >= RTE_MAX_LCORE) {\n-\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n-\t\treturn RTE_POWER_INVALID_FREQ_INDEX;\n-\t}\n-\n-\treturn lcore_power_info[lcore_id].curr_idx;\n-}\n-\n-int\n-rte_power_set_freq(unsigned lcore_id, uint32_t index)\n-{\n-\tif (lcore_id >= RTE_MAX_LCORE) {\n-\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n-\t\treturn -1;\n-\t}\n-\n-\treturn set_freq_internal(&(lcore_power_info[lcore_id]), index);\n-}\n-\n-int\n-rte_power_freq_down(unsigned lcore_id)\n-{\n-\tstruct rte_power_info *pi;\n-\n-\tif (lcore_id >= RTE_MAX_LCORE) {\n-\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n-\t\treturn -1;\n-\t}\n \n-\tpi = &lcore_power_info[lcore_id];\n-\tif (pi->curr_idx + 1 == pi->nb_freqs)\n-\t\treturn 0;\n-\n-\t/* Frequencies in the array are from high to low. */\n-\treturn set_freq_internal(pi, pi->curr_idx + 1);\n }\n-\n-int\n-rte_power_freq_up(unsigned lcore_id)\n-{\n-\tstruct rte_power_info *pi;\n-\n-\tif (lcore_id >= RTE_MAX_LCORE) {\n-\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n-\t\treturn -1;\n-\t}\n-\n-\tpi = &lcore_power_info[lcore_id];\n-\tif (pi->curr_idx == 0)\n-\t\treturn 0;\n-\n-\t/* Frequencies in the array are from high to low. */\n-\treturn set_freq_internal(pi, pi->curr_idx - 1);\n-}\n-\n-int\n-rte_power_freq_max(unsigned lcore_id)\n-{\n-\tif (lcore_id >= RTE_MAX_LCORE) {\n-\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n-\t\treturn -1;\n-\t}\n-\n-\t/* Frequencies in the array are from high to low. */\n-\treturn set_freq_internal(&lcore_power_info[lcore_id], 0);\n-}\n-\n-int\n-rte_power_freq_min(unsigned lcore_id)\n-{\n-\tstruct rte_power_info *pi;\n-\n-\tif (lcore_id >= RTE_MAX_LCORE) {\n-\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n-\t\treturn -1;\n-\t}\n-\n-\tpi = &lcore_power_info[lcore_id];\n-\n-\t/* Frequencies in the array are from high to low. */\n-\treturn set_freq_internal(pi, pi->nb_freqs - 1);\n-}\n-\ndiff --git a/lib/librte_power/rte_power.h b/lib/librte_power/rte_power.h\nindex 9c1419e..9338069 100644\n--- a/lib/librte_power/rte_power.h\n+++ b/lib/librte_power/rte_power.h\n@@ -48,12 +48,48 @@\n extern \"C\" {\n #endif\n \n-#define RTE_POWER_INVALID_FREQ_INDEX (~0)\n+/* Power Management Environment State */\n+enum power_management_env {PM_ENV_NOT_SET, PM_ENV_ACPI_CPUFREQ, PM_ENV_KVM_VM};\n \n /**\n- * Initialize power management for a specific lcore. It will check and set the\n- * governor to userspace for the lcore, get the available frequencies, and\n- * prepare to set new lcore frequency.\n+ * Set the default power management implementation. If this is not called prior\n+ * to rte_power_init(), then auto-detect of the environment will take place.\n+ * It is not thread safe.\n+ *\n+ * @param env\n+ *  env. The environment in which to initialise Power Management for.\n+ *\n+ * @return\n+ *  - 0 on success.\n+ *  - Negative on error.\n+ */\n+int rte_power_set_env(enum power_management_env env);\n+\n+/**\n+ * Unset the global environment configuration.\n+ * This can only be called after all threads have completed.\n+ *\n+ * @param None.\n+ *\n+ * @return\n+ *  None.\n+ */\n+void rte_power_unset_env(void);\n+\n+/**\n+ * Get the default power management implementation.\n+ *\n+ * @param None.\n+ *\n+ * @return\n+ *  power_management_env The configured environment.\n+ */\n+enum power_management_env rte_power_get_env(void);\n+\n+/**\n+ * Initialize power management for a specific lcore. If rte_power_set_env() has\n+ * not been called then an auto-detect of the environment will start and\n+ * initialise the corresponding resources.\n  *\n  * @param lcore_id\n  *  lcore id.\n@@ -65,8 +101,9 @@ extern \"C\" {\n int rte_power_init(unsigned lcore_id);\n \n /**\n- * Exit power management on a specific lcore. It will set the governor to which\n- * is before initialized.\n+ * Exit power management on a specific lcore. This will call the environment\n+ * dependent exit function.\n+ *\n  *\n  * @param lcore_id\n  *  lcore id.\n@@ -78,11 +115,9 @@ int rte_power_init(unsigned lcore_id);\n int rte_power_exit(unsigned lcore_id);\n \n /**\n- * Get the available frequencies of a specific lcore. The return value will be\n- * the minimal one of the total number of available frequencies and the number\n- * of buffer. The index of available frequencies used in other interfaces\n- * should be in the range of 0 to this return value.\n- * It should be protected outside of this function for threadsafe.\n+ * Get the available frequencies of a specific lcore.\n+ * Function pointer definition. Review each environments\n+ * specific documentation for usage.\n  *\n  * @param lcore_id\n  *  lcore id.\n@@ -94,12 +129,15 @@ int rte_power_exit(unsigned lcore_id);\n  * @return\n  *  The number of available frequencies.\n  */\n-uint32_t rte_power_freqs(unsigned lcore_id, uint32_t *freqs, uint32_t num);\n+typedef uint32_t (*rte_power_freqs_t)(unsigned lcore_id, uint32_t *freqs,\n+\t\tuint32_t num);\n+\n+extern rte_power_freqs_t rte_power_freqs;\n \n /**\n- * Return the current index of available frequencies of a specific lcore. It\n- * will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)' if error.\n- * It should be protected outside of this function for threadsafe.\n+ * Return the current index of available frequencies of a specific lcore.\n+ * Function pointer definition. Review each environments\n+ * specific documentation for usage.\n  *\n  * @param lcore_id\n  *  lcore id.\n@@ -107,12 +145,15 @@ uint32_t rte_power_freqs(unsigned lcore_id, uint32_t *freqs, uint32_t num);\n  * @return\n  *  The current index of available frequencies.\n  */\n-uint32_t rte_power_get_freq(unsigned lcore_id);\n+typedef uint32_t (*rte_power_get_freq_t)(unsigned lcore_id);\n+\n+extern rte_power_get_freq_t rte_power_get_freq;\n \n /**\n  * Set the new frequency for a specific lcore by indicating the index of\n  * available frequencies.\n- * It should be protected outside of this function for threadsafe.\n+ * Function pointer definition. Review each environments\n+ * specific documentation for usage.\n  *\n  * @param lcore_id\n  *  lcore id.\n@@ -121,70 +162,87 @@ uint32_t rte_power_get_freq(unsigned lcore_id);\n  *\n  * @return\n  *  - 1 on success with frequency changed.\n- *  - 0 on success without frequency chnaged.\n+ *  - 0 on success without frequency changed.\n  *  - Negative on error.\n  */\n-int rte_power_set_freq(unsigned lcore_id, uint32_t index);\n+typedef int (*rte_power_set_freq_t)(unsigned lcore_id, uint32_t index);\n+\n+extern rte_power_set_freq_t rte_power_set_freq;\n+\n+/**\n+ * Function pointer definition for generic frequency change functions. Review\n+ * each environments specific documentation for usage.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 1 on success with frequency changed.\n+ *  - 0 on success without frequency changed.\n+ *  - Negative on error.\n+ */\n+typedef int (*rte_power_freq_change_t)(unsigned lcore_id);\n \n /**\n  * Scale up the frequency of a specific lcore according to the available\n  * frequencies.\n- * It should be protected outside of this function for threadsafe.\n+ * Review each environments specific documentation for usage.\n  *\n  * @param lcore_id\n  *  lcore id.\n  *\n  * @return\n  *  - 1 on success with frequency changed.\n- *  - 0 on success without frequency chnaged.\n+ *  - 0 on success without frequency changed.\n  *  - Negative on error.\n  */\n-int rte_power_freq_up(unsigned lcore_id);\n+extern rte_power_freq_change_t rte_power_freq_up;\n \n /**\n  * Scale down the frequency of a specific lcore according to the available\n  * frequencies.\n- * It should be protected outside of this function for threadsafe.\n+ * Review each environments specific documentation for usage.\n  *\n  * @param lcore_id\n  *  lcore id.\n  *\n  * @return\n  *  - 1 on success with frequency changed.\n- *  - 0 on success without frequency chnaged.\n+ *  - 0 on success without frequency changed.\n  *  - Negative on error.\n  */\n-int rte_power_freq_down(unsigned lcore_id);\n+\n+extern rte_power_freq_change_t rte_power_freq_down;\n \n /**\n  * Scale up the frequency of a specific lcore to the highest according to the\n  * available frequencies.\n- * It should be protected outside of this function for threadsafe.\n+ * Review each environments specific documentation for usage.\n  *\n  * @param lcore_id\n  *  lcore id.\n  *\n  * @return\n  *  - 1 on success with frequency changed.\n- *  - 0 on success without frequency chnaged.\n+ *  - 0 on success without frequency changed.\n  *  - Negative on error.\n  */\n-int rte_power_freq_max(unsigned lcore_id);\n+extern rte_power_freq_change_t rte_power_freq_max;\n \n /**\n  * Scale down the frequency of a specific lcore to the lowest according to the\n  * available frequencies.\n- * It should be protected outside of this function for threadsafe.\n+ * Review each environments specific documentation for usage..\n  *\n  * @param lcore_id\n  *  lcore id.\n  *\n  * @return\n  *  - 1 on success with frequency changed.\n- *  - 0 on success without frequency chnaged.\n+ *  - 0 on success without frequency changed.\n  *  - Negative on error.\n  */\n-int rte_power_freq_min(unsigned lcore_id);\n+rte_power_freq_change_t rte_power_freq_min;\n \n #ifdef __cplusplus\n }\ndiff --git a/lib/librte_power/rte_power_acpi_cpufreq.c b/lib/librte_power/rte_power_acpi_cpufreq.c\nnew file mode 100644\nindex 0000000..09085c3\n--- /dev/null\n+++ b/lib/librte_power/rte_power_acpi_cpufreq.c\n@@ -0,0 +1,545 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <stdio.h>\n+#include <sys/types.h>\n+#include <sys/stat.h>\n+#include <fcntl.h>\n+#include <stdlib.h>\n+#include <string.h>\n+#include <unistd.h>\n+#include <signal.h>\n+#include <limits.h>\n+\n+#include <rte_memcpy.h>\n+#include <rte_atomic.h>\n+\n+#include \"rte_power_acpi_cpufreq.h\"\n+#include \"rte_power_common.h\"\n+\n+#ifdef RTE_LIBRTE_POWER_DEBUG\n+#define POWER_DEBUG_TRACE(fmt, args...) do { \\\n+\t\tRTE_LOG(ERR, POWER, \"%s: \" fmt, __func__, ## args); \\\n+} while (0)\n+#else\n+#define POWER_DEBUG_TRACE(fmt, args...)\n+#endif\n+\n+#define FOPEN_OR_ERR_RET(f, retval) do { \\\n+\t\tif ((f) == NULL) { \\\n+\t\t\tRTE_LOG(ERR, POWER, \"File not openned\\n\"); \\\n+\t\t\treturn retval; \\\n+\t\t} \\\n+} while (0)\n+\n+#define FOPS_OR_NULL_GOTO(ret, label) do { \\\n+\t\tif ((ret) == NULL) { \\\n+\t\t\tRTE_LOG(ERR, POWER, \"fgets returns nothing\\n\"); \\\n+\t\t\tgoto label; \\\n+\t\t} \\\n+} while (0)\n+\n+#define FOPS_OR_ERR_GOTO(ret, label) do { \\\n+\t\tif ((ret) < 0) { \\\n+\t\t\tRTE_LOG(ERR, POWER, \"File operations failed\\n\"); \\\n+\t\t\tgoto label; \\\n+\t\t} \\\n+} while (0)\n+\n+#define STR_SIZE     1024\n+#define POWER_CONVERT_TO_DECIMAL 10\n+\n+#define POWER_GOVERNOR_USERSPACE \"userspace\"\n+#define POWER_SYSFILE_GOVERNOR   \\\n+\t\t\"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_governor\"\n+#define POWER_SYSFILE_AVAIL_FREQ \\\n+\t\t\"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_frequencies\"\n+#define POWER_SYSFILE_SETSPEED   \\\n+\t\t\"/sys/devices/system/cpu/cpu%u/cpufreq/scaling_setspeed\"\n+\n+enum power_state {\n+\tPOWER_IDLE = 0,\n+\tPOWER_ONGOING,\n+\tPOWER_USED,\n+\tPOWER_UNKNOWN\n+};\n+\n+/**\n+ * Power info per lcore.\n+ */\n+struct rte_power_info {\n+\tunsigned lcore_id;                   /**< Logical core id */\n+\tuint32_t freqs[RTE_MAX_LCORE_FREQS]; /**< Frequency array */\n+\tuint32_t nb_freqs;                   /**< number of available freqs */\n+\tFILE *f;                             /**< FD of scaling_setspeed */\n+\tchar governor_ori[32];               /**< Original governor name */\n+\tuint32_t curr_idx;                   /**< Freq index in freqs array */\n+\tvolatile uint32_t state;             /**< Power in use state */\n+} __rte_cache_aligned;\n+\n+static struct rte_power_info lcore_power_info[RTE_MAX_LCORE];\n+\n+/**\n+ * It is to set specific freq for specific logical core, according to the index\n+ * of supported frequencies.\n+ */\n+static int\n+set_freq_internal(struct rte_power_info *pi, uint32_t idx)\n+{\n+\tif (idx >= RTE_MAX_LCORE_FREQS || idx >= pi->nb_freqs) {\n+\t\tRTE_LOG(ERR, POWER, \"Invalid frequency index %u, which \"\n+\t\t\t\t\"should be less than %u\\n\", idx, pi->nb_freqs);\n+\t\treturn -1;\n+\t}\n+\n+\t/* Check if it is the same as current */\n+\tif (idx == pi->curr_idx)\n+\t\treturn 0;\n+\n+\tPOWER_DEBUG_TRACE(\"Freqency[%u] %u to be set for lcore %u\\n\",\n+\t\t\tidx, pi->freqs[idx], pi->lcore_id);\n+\tif (fseek(pi->f, 0, SEEK_SET) < 0) {\n+\t\tRTE_LOG(ERR, POWER, \"Fail to set file position indicator to 0 \"\n+\t\t\t\t\"for setting frequency for lcore %u\\n\", pi->lcore_id);\n+\t\treturn -1;\n+\t}\n+\tif (fprintf(pi->f, \"%u\", pi->freqs[idx]) < 0) {\n+\t\tRTE_LOG(ERR, POWER, \"Fail to write new frequency for \"\n+\t\t\t\t\"lcore %u\\n\", pi->lcore_id);\n+\t\treturn -1;\n+\t}\n+\tfflush(pi->f);\n+\tpi->curr_idx = idx;\n+\n+\treturn 1;\n+}\n+\n+/**\n+ * It is to check the current scaling governor by reading sys file, and then\n+ * set it into 'userspace' if it is not by writing the sys file. The original\n+ * governor will be saved for rolling back.\n+ */\n+static int\n+power_set_governor_userspace(struct rte_power_info *pi)\n+{\n+\tFILE *f;\n+\tint ret = -1;\n+\tchar buf[BUFSIZ];\n+\tchar fullpath[PATH_MAX];\n+\tchar *s;\n+\tint val;\n+\n+\tsnprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,\n+\t\t\tpi->lcore_id);\n+\tf = fopen(fullpath, \"rw+\");\n+\tFOPEN_OR_ERR_RET(f, ret);\n+\n+\ts = fgets(buf, sizeof(buf), f);\n+\tFOPS_OR_NULL_GOTO(s, out);\n+\n+\t/* Check if current governor is userspace */\n+\tif (strncmp(buf, POWER_GOVERNOR_USERSPACE,\n+\t\t\tsizeof(POWER_GOVERNOR_USERSPACE)) == 0) {\n+\t\tret = 0;\n+\t\tPOWER_DEBUG_TRACE(\"Power management governor of lcore %u is \"\n+\t\t\t\t\"already userspace\\n\", pi->lcore_id);\n+\t\tgoto out;\n+\t}\n+\t/* Save the original governor */\n+\tsnprintf(pi->governor_ori, sizeof(pi->governor_ori), \"%s\", buf);\n+\n+\t/* Write 'userspace' to the governor */\n+\tval = fseek(f, 0, SEEK_SET);\n+\tFOPS_OR_ERR_GOTO(val, out);\n+\n+\tval = fputs(POWER_GOVERNOR_USERSPACE, f);\n+\tFOPS_OR_ERR_GOTO(val, out);\n+\n+\tret = 0;\n+\tRTE_LOG(INFO, POWER, \"Power management governor of lcore %u has been \"\n+\t\t\t\"set to user space successfully\\n\", pi->lcore_id);\n+\tout:\n+\tfclose(f);\n+\n+\treturn ret;\n+}\n+\n+/**\n+ * It is to get the available frequencies of the specific lcore by reading the\n+ * sys file.\n+ */\n+static int\n+power_get_available_freqs(struct rte_power_info *pi)\n+{\n+\tFILE *f;\n+\tint ret = -1, i, count;\n+\tchar *p;\n+\tchar buf[BUFSIZ];\n+\tchar fullpath[PATH_MAX];\n+\tchar *freqs[RTE_MAX_LCORE_FREQS];\n+\tchar *s;\n+\n+\tsnprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_AVAIL_FREQ,\n+\t\t\tpi->lcore_id);\n+\tf = fopen(fullpath, \"r\");\n+\tFOPEN_OR_ERR_RET(f, ret);\n+\n+\ts = fgets(buf, sizeof(buf), f);\n+\tFOPS_OR_NULL_GOTO(s, out);\n+\n+\t/* Strip the line break if there is */\n+\tp = strchr(buf, '\\n');\n+\tif (p != NULL)\n+\t\t*p = 0;\n+\n+\t/* Split string into at most RTE_MAX_LCORE_FREQS frequencies */\n+\tcount = rte_strsplit(buf, sizeof(buf), freqs,\n+\t\t\tRTE_MAX_LCORE_FREQS, ' ');\n+\tif (count <= 0) {\n+\t\tRTE_LOG(ERR, POWER, \"No available frequency in \"\n+\t\t\t\t\"\"POWER_SYSFILE_AVAIL_FREQ\"\\n\", pi->lcore_id);\n+\t\tgoto out;\n+\t}\n+\tif (count >= RTE_MAX_LCORE_FREQS) {\n+\t\tRTE_LOG(ERR, POWER, \"Too many available frequencies : %d\\n\",\n+\t\t\t\tcount);\n+\t\tgoto out;\n+\t}\n+\n+\t/* Store the available frequncies into power context */\n+\tfor (i = 0, pi->nb_freqs = 0; i < count; i++) {\n+\t\tPOWER_DEBUG_TRACE(\"Lcore %u frequency[%d]: %s\\n\", pi->lcore_id,\n+\t\t\t\ti, freqs[i]);\n+\t\tpi->freqs[pi->nb_freqs++] = strtoul(freqs[i], &p,\n+\t\t\t\tPOWER_CONVERT_TO_DECIMAL);\n+\t}\n+\n+\tret = 0;\n+\tPOWER_DEBUG_TRACE(\"%d frequencie(s) of lcore %u are available\\n\",\n+\t\t\tcount, pi->lcore_id);\n+\tout:\n+\tfclose(f);\n+\n+\treturn ret;\n+}\n+\n+/**\n+ * It is to fopen the sys file for the future setting the lcore frequency.\n+ */\n+static int\n+power_init_for_setting_freq(struct rte_power_info *pi)\n+{\n+\tFILE *f;\n+\tchar fullpath[PATH_MAX];\n+\tchar buf[BUFSIZ];\n+\tuint32_t i, freq;\n+\tchar *s;\n+\n+\tsnprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_SETSPEED,\n+\t\t\tpi->lcore_id);\n+\tf = fopen(fullpath, \"rw+\");\n+\tFOPEN_OR_ERR_RET(f, -1);\n+\n+\ts = fgets(buf, sizeof(buf), f);\n+\tFOPS_OR_NULL_GOTO(s, out);\n+\n+\tfreq = strtoul(buf, NULL, POWER_CONVERT_TO_DECIMAL);\n+\tfor (i = 0; i < pi->nb_freqs; i++) {\n+\t\tif (freq == pi->freqs[i]) {\n+\t\t\tpi->curr_idx = i;\n+\t\t\tpi->f = f;\n+\t\t\treturn 0;\n+\t\t}\n+\t}\n+\n+\tout:\n+\tfclose(f);\n+\n+\treturn -1;\n+}\n+\n+int\n+rte_power_acpi_cpufreq_init(unsigned lcore_id)\n+{\n+\tstruct rte_power_info *pi;\n+\n+\tif (lcore_id >= RTE_MAX_LCORE) {\n+\t\tRTE_LOG(ERR, POWER, \"Lcore id %u can not exceeds %u\\n\",\n+\t\t\t\tlcore_id, RTE_MAX_LCORE - 1U);\n+\t\treturn -1;\n+\t}\n+\n+\tpi = &lcore_power_info[lcore_id];\n+\tif (rte_atomic32_cmpset(&(pi->state), POWER_IDLE, POWER_ONGOING)\n+\t\t\t== 0) {\n+\t\tRTE_LOG(INFO, POWER, \"Power management of lcore %u is \"\n+\t\t\t\t\"in use\\n\", lcore_id);\n+\t\treturn -1;\n+\t}\n+\n+\tpi->lcore_id = lcore_id;\n+\t/* Check and set the governor */\n+\tif (power_set_governor_userspace(pi) < 0) {\n+\t\tRTE_LOG(ERR, POWER, \"Cannot set governor of lcore %u to \"\n+\t\t\t\t\"userspace\\n\", lcore_id);\n+\t\tgoto fail;\n+\t}\n+\n+\t/* Get the available frequencies */\n+\tif (power_get_available_freqs(pi) < 0) {\n+\t\tRTE_LOG(ERR, POWER, \"Cannot get available frequencies of \"\n+\t\t\t\t\"lcore %u\\n\", lcore_id);\n+\t\tgoto fail;\n+\t}\n+\n+\t/* Init for setting lcore frequency */\n+\tif (power_init_for_setting_freq(pi) < 0) {\n+\t\tRTE_LOG(ERR, POWER, \"Cannot init for setting frequency for \"\n+\t\t\t\t\"lcore %u\\n\", lcore_id);\n+\t\tgoto fail;\n+\t}\n+\n+\t/* Set freq to max by default */\n+\tif (rte_power_acpi_cpufreq_freq_max(lcore_id) < 0) {\n+\t\tRTE_LOG(ERR, POWER, \"Cannot set frequency of lcore %u \"\n+\t\t\t\t\"to max\\n\", lcore_id);\n+\t\tgoto fail;\n+\t}\n+\n+\tRTE_LOG(INFO, POWER, \"Initialized successfully for lcore %u \"\n+\t\t\t\"power manamgement\\n\", lcore_id);\n+\trte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_USED);\n+\n+\treturn 0;\n+\n+\tfail:\n+\trte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_UNKNOWN);\n+\n+\treturn -1;\n+}\n+\n+/**\n+ * It is to check the governor and then set the original governor back if\n+ * needed by writing the the sys file.\n+ */\n+static int\n+power_set_governor_original(struct rte_power_info *pi)\n+{\n+\tFILE *f;\n+\tint ret = -1;\n+\tchar buf[BUFSIZ];\n+\tchar fullpath[PATH_MAX];\n+\tchar *s;\n+\tint val;\n+\n+\tsnprintf(fullpath, sizeof(fullpath), POWER_SYSFILE_GOVERNOR,\n+\t\t\tpi->lcore_id);\n+\tf = fopen(fullpath, \"rw+\");\n+\tFOPEN_OR_ERR_RET(f, ret);\n+\n+\ts = fgets(buf, sizeof(buf), f);\n+\tFOPS_OR_NULL_GOTO(s, out);\n+\n+\t/* Check if the governor to be set is the same as current */\n+\tif (strncmp(buf, pi->governor_ori, sizeof(pi->governor_ori)) == 0) {\n+\t\tret = 0;\n+\t\tPOWER_DEBUG_TRACE(\"Power management governor of lcore %u \"\n+\t\t\t\t\"has already been set to %s\\n\",\n+\t\t\t\tpi->lcore_id, pi->governor_ori);\n+\t\tgoto out;\n+\t}\n+\n+\t/* Write back the original governor */\n+\tval = fseek(f, 0, SEEK_SET);\n+\tFOPS_OR_ERR_GOTO(val, out);\n+\n+\tval = fputs(pi->governor_ori, f);\n+\tFOPS_OR_ERR_GOTO(val, out);\n+\n+\tret = 0;\n+\tRTE_LOG(INFO, POWER, \"Power management governor of lcore %u \"\n+\t\t\t\"has been set back to %s successfully\\n\",\n+\t\t\tpi->lcore_id, pi->governor_ori);\n+\tout:\n+\tfclose(f);\n+\n+\treturn ret;\n+}\n+\n+int\n+rte_power_acpi_cpufreq_exit(unsigned lcore_id)\n+{\n+\tstruct rte_power_info *pi;\n+\n+\tif (lcore_id >= RTE_MAX_LCORE) {\n+\t\tRTE_LOG(ERR, POWER, \"Lcore id %u can not exceeds %u\\n\",\n+\t\t\t\tlcore_id, RTE_MAX_LCORE - 1U);\n+\t\treturn -1;\n+\t}\n+\tpi = &lcore_power_info[lcore_id];\n+\tif (rte_atomic32_cmpset(&(pi->state), POWER_USED, POWER_ONGOING)\n+\t\t\t== 0) {\n+\t\tRTE_LOG(INFO, POWER, \"Power management of lcore %u is \"\n+\t\t\t\t\"not used\\n\", lcore_id);\n+\t\treturn -1;\n+\t}\n+\n+\t/* Close FD of setting freq */\n+\tfclose(pi->f);\n+\tpi->f = NULL;\n+\n+\t/* Set the governor back to the original */\n+\tif (power_set_governor_original(pi) < 0) {\n+\t\tRTE_LOG(ERR, POWER, \"Cannot set the governor of %u back \"\n+\t\t\t\t\"to the original\\n\", lcore_id);\n+\t\tgoto fail;\n+\t}\n+\n+\tRTE_LOG(INFO, POWER, \"Power management of lcore %u has exited from \"\n+\t\t\t\"'userspace' mode and been set back to the \"\n+\t\t\t\"original\\n\", lcore_id);\n+\trte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_IDLE);\n+\n+\treturn 0;\n+\n+\tfail:\n+\trte_atomic32_cmpset(&(pi->state), POWER_ONGOING, POWER_UNKNOWN);\n+\n+\treturn -1;\n+}\n+\n+uint32_t\n+rte_power_acpi_cpufreq_freqs(unsigned lcore_id, uint32_t *freqs, uint32_t num)\n+{\n+\tstruct rte_power_info *pi;\n+\n+\tif (lcore_id >= RTE_MAX_LCORE || !freqs) {\n+\t\tRTE_LOG(ERR, POWER, \"Invalid input parameter\\n\");\n+\t\treturn 0;\n+\t}\n+\n+\tpi = &lcore_power_info[lcore_id];\n+\tif (num < pi->nb_freqs) {\n+\t\tRTE_LOG(ERR, POWER, \"Buffer size is not enough\\n\");\n+\t\treturn 0;\n+\t}\n+\trte_memcpy(freqs, pi->freqs, pi->nb_freqs * sizeof(uint32_t));\n+\n+\treturn pi->nb_freqs;\n+}\n+\n+uint32_t\n+rte_power_acpi_cpufreq_get_freq(unsigned lcore_id)\n+{\n+\tif (lcore_id >= RTE_MAX_LCORE) {\n+\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n+\t\treturn RTE_POWER_INVALID_FREQ_INDEX;\n+\t}\n+\n+\treturn lcore_power_info[lcore_id].curr_idx;\n+}\n+\n+int\n+rte_power_acpi_cpufreq_set_freq(unsigned lcore_id, uint32_t index)\n+{\n+\tif (lcore_id >= RTE_MAX_LCORE) {\n+\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\treturn set_freq_internal(&(lcore_power_info[lcore_id]), index);\n+}\n+\n+int\n+rte_power_acpi_cpufreq_freq_down(unsigned lcore_id)\n+{\n+\tstruct rte_power_info *pi;\n+\n+\tif (lcore_id >= RTE_MAX_LCORE) {\n+\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tpi = &lcore_power_info[lcore_id];\n+\tif (pi->curr_idx + 1 == pi->nb_freqs)\n+\t\treturn 0;\n+\n+\t/* Frequencies in the array are from high to low. */\n+\treturn set_freq_internal(pi, pi->curr_idx + 1);\n+}\n+\n+int\n+rte_power_acpi_cpufreq_freq_up(unsigned lcore_id)\n+{\n+\tstruct rte_power_info *pi;\n+\n+\tif (lcore_id >= RTE_MAX_LCORE) {\n+\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tpi = &lcore_power_info[lcore_id];\n+\tif (pi->curr_idx == 0)\n+\t\treturn 0;\n+\n+\t/* Frequencies in the array are from high to low. */\n+\treturn set_freq_internal(pi, pi->curr_idx - 1);\n+}\n+\n+int\n+rte_power_acpi_cpufreq_freq_max(unsigned lcore_id)\n+{\n+\tif (lcore_id >= RTE_MAX_LCORE) {\n+\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\t/* Frequencies in the array are from high to low. */\n+\treturn set_freq_internal(&lcore_power_info[lcore_id], 0);\n+}\n+\n+int\n+rte_power_acpi_cpufreq_freq_min(unsigned lcore_id)\n+{\n+\tstruct rte_power_info *pi;\n+\n+\tif (lcore_id >= RTE_MAX_LCORE) {\n+\t\tRTE_LOG(ERR, POWER, \"Invalid lcore ID\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\tpi = &lcore_power_info[lcore_id];\n+\n+\t/* Frequencies in the array are from high to low. */\n+\treturn set_freq_internal(pi, pi->nb_freqs - 1);\n+}\ndiff --git a/lib/librte_power/rte_power_acpi_cpufreq.h b/lib/librte_power/rte_power_acpi_cpufreq.h\nnew file mode 100644\nindex 0000000..68578e9\n--- /dev/null\n+++ b/lib/librte_power/rte_power_acpi_cpufreq.h\n@@ -0,0 +1,192 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#ifndef _RTE_POWER_ACPI_CPUFREQ_H\n+#define _RTE_POWER_ACPI_CPUFREQ_H\n+\n+/**\n+ * @file\n+ * RTE Power Management via userspace ACPI cpufreq\n+ */\n+\n+#include <rte_common.h>\n+#include <rte_byteorder.h>\n+#include <rte_log.h>\n+#include <rte_string_fns.h>\n+\n+#ifdef __cplusplus\n+extern \"C\" {\n+#endif\n+\n+/**\n+ * Initialize power management for a specific lcore. It will check and set the\n+ * governor to userspace for the lcore, get the available frequencies, and\n+ * prepare to set new lcore frequency.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 0 on success.\n+ *  - Negative on error.\n+ */\n+int rte_power_acpi_cpufreq_init(unsigned lcore_id);\n+\n+/**\n+ * Exit power management on a specific lcore. It will set the governor to which\n+ * is before initialized.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 0 on success.\n+ *  - Negative on error.\n+ */\n+int rte_power_acpi_cpufreq_exit(unsigned lcore_id);\n+\n+/**\n+ * Get the available frequencies of a specific lcore. The return value will be\n+ * the minimal one of the total number of available frequencies and the number\n+ * of buffer. The index of available frequencies used in other interfaces\n+ * should be in the range of 0 to this return value.\n+ * It should be protected outside of this function for threadsafe.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ * @param freqs\n+ *  The buffer array to save the frequencies.\n+ * @param num\n+ *  The number of frequencies to get.\n+ *\n+ * @return\n+ *  The number of available frequencies.\n+ */\n+uint32_t rte_power_acpi_cpufreq_freqs(unsigned lcore_id, uint32_t *freqs,\n+\t\tuint32_t num);\n+\n+/**\n+ * Return the current index of available frequencies of a specific lcore. It\n+ * will return 'RTE_POWER_INVALID_FREQ_INDEX = (~0)' if error.\n+ * It should be protected outside of this function for threadsafe.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  The current index of available frequencies.\n+ */\n+uint32_t rte_power_acpi_cpufreq_get_freq(unsigned lcore_id);\n+\n+/**\n+ * Set the new frequency for a specific lcore by indicating the index of\n+ * available frequencies.\n+ * It should be protected outside of this function for threadsafe.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ * @param index\n+ *  The index of available frequencies.\n+ *\n+ * @return\n+ *  - 1 on success with frequency changed.\n+ *  - 0 on success without frequency changed.\n+ *  - Negative on error.\n+ */\n+int rte_power_acpi_cpufreq_set_freq(unsigned lcore_id, uint32_t index);\n+\n+/**\n+ * Scale up the frequency of a specific lcore according to the available\n+ * frequencies.\n+ * It should be protected outside of this function for threadsafe.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 1 on success with frequency changed.\n+ *  - 0 on success without frequency changed.\n+ *  - Negative on error.\n+ */\n+int rte_power_acpi_cpufreq_freq_up(unsigned lcore_id);\n+\n+/**\n+ * Scale down the frequency of a specific lcore according to the available\n+ * frequencies.\n+ * It should be protected outside of this function for threadsafe.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 1 on success with frequency changed.\n+ *  - 0 on success without frequency changed.\n+ *  - Negative on error.\n+ */\n+int rte_power_acpi_cpufreq_freq_down(unsigned lcore_id);\n+\n+/**\n+ * Scale up the frequency of a specific lcore to the highest according to the\n+ * available frequencies.\n+ * It should be protected outside of this function for threadsafe.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 1 on success with frequency changed.\n+ *  - 0 on success without frequency changed.\n+ *  - Negative on error.\n+ */\n+int rte_power_acpi_cpufreq_freq_max(unsigned lcore_id);\n+\n+/**\n+ * Scale down the frequency of a specific lcore to the lowest according to the\n+ * available frequencies.\n+ * It should be protected outside of this function for threadsafe.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 1 on success with frequency changed.\n+ *  - 0 on success without frequency chnaged.\n+ *  - Negative on error.\n+ */\n+int rte_power_acpi_cpufreq_freq_min(unsigned lcore_id);\n+\n+#ifdef __cplusplus\n+}\n+#endif\n+\n+#endif\ndiff --git a/lib/librte_power/rte_power_common.h b/lib/librte_power/rte_power_common.h\nnew file mode 100644\nindex 0000000..64bd168\n--- /dev/null\n+++ b/lib/librte_power/rte_power_common.h\n@@ -0,0 +1,39 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#ifndef RTE_POWER_COMMON_H_\n+#define RTE_POWER_COMMON_H_\n+\n+#define RTE_POWER_INVALID_FREQ_INDEX (~0)\n+\n+#endif /* RTE_POWER_COMMON_H_ */\ndiff --git a/lib/librte_power/rte_power_kvm_vm.c b/lib/librte_power/rte_power_kvm_vm.c\nnew file mode 100644\nindex 0000000..3ccd92b\n--- /dev/null\n+++ b/lib/librte_power/rte_power_kvm_vm.c\n@@ -0,0 +1,135 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+#include <errno.h>\n+#include <string.h>\n+\n+#include <rte_log.h>\n+#include <rte_config.h>\n+\n+#include \"guest_channel.h\"\n+#include \"channel_commands.h\"\n+#include \"rte_power_kvm_vm.h\"\n+#include \"rte_power_common.h\"\n+\n+#define FD_PATH \"/dev/virtio-ports/virtio.serial.port.poweragent\"\n+\n+static struct channel_packet pkt[CHANNEL_CMDS_MAX_VM_CHANNELS];\n+\n+\n+int\n+rte_power_kvm_vm_init(unsigned lcore_id)\n+{\n+\tif (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {\n+\t\tRTE_LOG(ERR, POWER, \"Core(%u) is out of range 0...%d\\n\",\n+\t\t\t\tlcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);\n+\t\treturn -1;\n+\t}\n+\tpkt[lcore_id].command = CPU_POWER;\n+\tpkt[lcore_id].resource_id = lcore_id;\n+\treturn guest_channel_host_connect(FD_PATH, lcore_id);\n+}\n+\n+int\n+rte_power_kvm_vm_exit(unsigned lcore_id)\n+{\n+\tguest_channel_host_disconnect(lcore_id);\n+\treturn 0;\n+}\n+\n+uint32_t\n+rte_power_kvm_vm_freqs(__attribute__((unused)) unsigned lcore_id,\n+\t\t__attribute__((unused)) uint32_t *freqs,\n+\t\t__attribute__((unused)) uint32_t num)\n+{\n+\tRTE_LOG(ERR, POWER, \"rte_power_freqs is not implemented \"\n+\t\t\t\"for Virtual Machine Power Management\\n\");\n+\treturn -ENOTSUP;\n+}\n+\n+uint32_t\n+rte_power_kvm_vm_get_freq(__attribute__((unused)) unsigned lcore_id)\n+{\n+\tRTE_LOG(ERR, POWER, \"rte_power_get_freq is not implemented \"\n+\t\t\t\"for Virtual Machine Power Management\\n\");\n+\treturn -ENOTSUP;\n+}\n+\n+int\n+rte_power_kvm_vm_set_freq(__attribute__((unused)) unsigned lcore_id,\n+\t\t__attribute__((unused)) uint32_t index)\n+{\n+\tRTE_LOG(ERR, POWER, \"rte_power_set_freq is not implemented \"\n+\t\t\t\"for Virtual Machine Power Management\\n\");\n+\treturn -ENOTSUP;\n+}\n+\n+static inline int\n+send_msg(unsigned lcore_id, uint32_t scale_direction)\n+{\n+\tint ret;\n+\tif (lcore_id >= CHANNEL_CMDS_MAX_VM_CHANNELS) {\n+\t\tRTE_LOG(ERR, POWER, \"Core(%u) is out of range 0...%d\\n\",\n+\t\t\t\tlcore_id, CHANNEL_CMDS_MAX_VM_CHANNELS-1);\n+\t\treturn -1;\n+\t}\n+\tpkt[lcore_id].unit = scale_direction;\n+\tret = guest_channel_send_msg(&pkt[lcore_id], lcore_id);\n+\tif (ret == 0)\n+\t\treturn 1;\n+\tRTE_LOG(DEBUG, POWER, \"Error sending message: %s\\n\", strerror(ret));\n+\treturn -1;\n+}\n+\n+int\n+rte_power_kvm_vm_freq_up(unsigned lcore_id)\n+{\n+\treturn send_msg(lcore_id, CPU_POWER_SCALE_UP);\n+}\n+\n+int\n+rte_power_kvm_vm_freq_down(unsigned lcore_id)\n+{\n+\treturn send_msg(lcore_id, CPU_POWER_SCALE_DOWN);\n+}\n+\n+int\n+rte_power_kvm_vm_freq_max(unsigned lcore_id)\n+{\n+\treturn send_msg(lcore_id, CPU_POWER_SCALE_MAX);\n+}\n+\n+int\n+rte_power_kvm_vm_freq_min(unsigned lcore_id)\n+{\n+\treturn send_msg(lcore_id, CPU_POWER_SCALE_MIN);\n+}\ndiff --git a/lib/librte_power/rte_power_kvm_vm.h b/lib/librte_power/rte_power_kvm_vm.h\nnew file mode 100644\nindex 0000000..dcbc878\n--- /dev/null\n+++ b/lib/librte_power/rte_power_kvm_vm.h\n@@ -0,0 +1,179 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#ifndef _RTE_POWER_KVM_VM_H\n+#define _RTE_POWER_KVM_VM_H\n+\n+/**\n+ * @file\n+ * RTE Power Management KVM VM\n+ */\n+\n+#include <rte_common.h>\n+#include <rte_byteorder.h>\n+#include <rte_log.h>\n+#include <rte_string_fns.h>\n+\n+#ifdef __cplusplus\n+extern \"C\" {\n+#endif\n+\n+/**\n+ * Initialize power management for a specific lcore.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 0 on success.\n+ *  - Negative on error.\n+ */\n+int rte_power_kvm_vm_init(unsigned lcore_id);\n+\n+/**\n+ * Exit power management on a specific lcore.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 0 on success.\n+ *  - Negative on error.\n+ */\n+int rte_power_kvm_vm_exit(unsigned lcore_id);\n+\n+/**\n+ * Get the available frequencies of a specific lcore.\n+ * It is not currently supported for VM Power Management.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ * @param freqs\n+ *  The buffer array to save the frequencies.\n+ * @param num\n+ *  The number of frequencies to get.\n+ *\n+ * @return\n+ *  -ENOTSUP\n+ */\n+uint32_t rte_power_kvm_vm_freqs(unsigned lcore_id, uint32_t *freqs,\n+\t\tuint32_t num);\n+\n+/**\n+ * Return the current index of available frequencies of a specific lcore.\n+ * It is not currently supported for VM Power Management.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  -ENOTSUP\n+ */\n+uint32_t rte_power_kvm_vm_get_freq(unsigned lcore_id);\n+\n+/**\n+ * Set the new frequency for a specific lcore by indicating the index of\n+ * available frequencies.\n+ * It is not currently supported for VM Power Management.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ * @param index\n+ *  The index of available frequencies.\n+ *\n+ * @return\n+ *  -ENOTSUP\n+ */\n+int rte_power_kvm_vm_set_freq(unsigned lcore_id, uint32_t index);\n+\n+/**\n+ * Scale up the frequency of a specific lcore. This request is forwarded to the\n+ * host monitor.\n+ * It should be protected outside of this function for threadsafe.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 1 on success.\n+ *  - Negative on error.\n+ */\n+int rte_power_kvm_vm_freq_up(unsigned lcore_id);\n+\n+/**\n+ * Scale down the frequency of a specific lcore according to the available\n+ * frequencies.\n+ * It should be protected outside of this function for threadsafe.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 1 on success.\n+ *  - Negative on error.\n+ */\n+int rte_power_kvm_vm_freq_down(unsigned lcore_id);\n+\n+/**\n+ * Scale up the frequency of a specific lcore to the highest according to the\n+ * available frequencies.\n+ * It should be protected outside of this function for threadsafe.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 1 on success.\n+ *  - Negative on error.\n+ */\n+int rte_power_kvm_vm_freq_max(unsigned lcore_id);\n+\n+/**\n+ * Scale down the frequency of a specific lcore to the lowest according to the\n+ * available frequencies.\n+ * It should be protected outside of this function for threadsafe.\n+ *\n+ * @param lcore_id\n+ *  lcore id.\n+ *\n+ * @return\n+ *  - 1 on success.\n+ *  - Negative on error.\n+ */\n+int rte_power_kvm_vm_freq_min(unsigned lcore_id);\n+\n+#ifdef __cplusplus\n+}\n+#endif\n+\n+#endif\n",
    "prefixes": [
        "dpdk-dev",
        "v5",
        "07/10"
    ]
}