[dpdk-dev] [PATCH v2] librte_cmdline: FreeBSD Fix oveflow when size of command result structure is greater than BUFSIZ

2014-11-10 Thread Alan Carew
When using test-pmd with flow director in FreeBSD, the application will
segfault/Bus error while parsing the command-line. This is due to how
each commands result structure is represented during parsing, where the offsets
for each tokens value is stored in a character array(char result_buf[BUFSIZ])
in cmdline_parse()(./lib/librte_cmdline/cmdline_parse.c).

The overflow occurs where BUFSIZ is less than the size of a commands result
structure, in this case "struct cmd_pkt_filter_result"
(app/test-pmd/cmdline.c) is 1088 bytes and BUFSIZ on FreeBSD is 1024 bytes as
opposed to 8192 bytes on Linux.

The problem can be reproduced by running test-pmd on FreeBSD:
./testpmd -c 0x3 -n 4 -- -i --portmask=0x3 --pkt-filter-mode=perfect
And adding a filter:
add_perfect_filter 0 udp src 192.168.0.0 1024 dst 192.168.0.0 1024 flexbytes
0x800 vlan 0 queue 0 soft 0x17

This patch removes the OS dependency on BUFSIZ and defines and uses a
library #define CMDLINE_PARSE_RESULT_BUFSIZE 8192

Added boundary checking to ensure this buffer size cannot overflow, with
an error message being produced.

Suggested-by: Olivier MATZ 
http://git.droids-corp.org/?p=libcmdline.git;a=commitdiff;h=b1d5b169352e57df3fc14c51ffad4b83f3e5613f

Signed-off-by: Alan Carew 
---
 lib/librte_cmdline/cmdline_parse.c | 22 +++---
 lib/librte_cmdline/cmdline_parse.h |  3 +++
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/lib/librte_cmdline/cmdline_parse.c 
b/lib/librte_cmdline/cmdline_parse.c
index 940480d..f86f163 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -138,7 +138,7 @@ nb_common_chars(const char * s1, const char * s2)
  */
 static int
 match_inst(cmdline_parse_inst_t *inst, const char *buf,
-  unsigned int nb_match_token, void * result_buf)
+  unsigned int nb_match_token, void *result_buf, unsigned 
result_buf_size)
 {
unsigned int token_num=0;
cmdline_parse_token_hdr_t * token_p;
@@ -162,10 +162,18 @@ match_inst(cmdline_parse_inst_t *inst, const char *buf,
if ( isendofline(*buf) || iscomment(*buf) )
break;

-   if (result_buf)
+   if (result_buf) {
+   if (token_hdr.offset > result_buf_size) {
+   printf("Parse error(%s:%d): Token offset(%u) 
exceeds maximum "
+   "size(%u)\n", __FILE__, __LINE__, 
token_hdr.offset,
+   result_buf_size);
+   return -ENOBUFS;
+   }
+
n = token_hdr.ops->parse(token_p, buf,
 (char *)result_buf +
 token_hdr.offset);
+   }
else
n = token_hdr.ops->parse(token_p, buf, NULL);

@@ -219,7 +227,7 @@ cmdline_parse(struct cmdline *cl, const char * buf)
unsigned int inst_num=0;
cmdline_parse_inst_t *inst;
const char *curbuf;
-   char result_buf[BUFSIZ];
+   char result_buf[CMDLINE_PARSE_RESULT_BUFSIZE];
void (*f)(void *, struct cmdline *, void *) = NULL;
void *data = NULL;
int comment = 0;
@@ -280,7 +288,7 @@ cmdline_parse(struct cmdline *cl, const char * buf)
debug_printf("INST %d\n", inst_num);

/* fully parsed */
-   tok = match_inst(inst, buf, 0, result_buf);
+   tok = match_inst(inst, buf, 0, result_buf, sizeof(result_buf));

if (tok > 0) /* we matched at least one token */
err = CMDLINE_PARSE_BAD_ARGS;
@@ -377,10 +385,10 @@ cmdline_complete(struct cmdline *cl, const char *buf, int 
*state,
inst = ctx[inst_num];
while (inst) {
/* parse the first tokens of the inst */
-   if (nb_token && match_inst(inst, buf, nb_token, NULL))
+   if (nb_token && match_inst(inst, buf, nb_token, NULL, 
0))
goto next;

-   debug_printf("instruction match \n");
+   debug_printf("instruction match\n");
token_p = inst->tokens[nb_token];
if (token_p)
memcpy(&token_hdr, token_p, sizeof(token_hdr));
@@ -471,7 +479,7 @@ cmdline_complete(struct cmdline *cl, const char *buf, int 
*state,
/* we need to redo it */
inst = ctx[inst_num];

-   if (nb_token && match_inst(inst, buf, nb_token, NULL))
+   if (nb_token && match_inst(inst, buf, nb_token, NULL, 0))
goto next2;

token_p = inst->tokens[nb_token];
diff --git a/lib/librte_cmdline/cmdline_parse.h 
b/lib/librte_cmdli

[dpdk-dev] [PATCH 0/4] librte_pmd_virtio :Fix: virtio_pci.h non-existent virtio feature bit-flag tested

2014-06-05 Thread Alan Carew
This series addresses an issue with librte_pmd_virtio where the offset to the
virtio device specific header may be incorrect depending on whether MSI-X has
been enabled or not.

If MSI-X is configured the device specific header is placed at byte offset 24
relative to the IO base address. 
If MSI-X is not configured the device specific header is placed at
byte offset 20. 

The following macro defined in virtio_pci.h is used to test the
presence of the MSI-X header and determine the correct offset: 
#define VIRTIO_PCI_CONFIG(hw) (((hw)->guest_features & VIRTIO_PCI_FLAG_MSIX) ? 
24 : 20) 

However, VIRTIO_PCI_FLAG_MSIX is not a guest_feature nor is it part of the
Virtio Specification and resolves to the VIRTIO_NET_F_MAC feature as both
are #defined as 0x20. 

VIRTIO_PCI_FLAG_MSIX or similar flag should instead be set by the kernel
driver allocating resources and passed to user space for testing. 
i.e. 
#define VIRTIO_PCI_CONFIG(hw) (((hw)->intr_mode & IGBUIO_MSIX_INTR_MODE) ? 24 : 
20)

To enable this testing of interrupt mode, this series allows for the kernel
driver(igb_uio) to place the configured interrupt mode into a sysfs entry.
sysfs is then parsed by eal_pci to determine the configured mode, which
allows all user space devices to correctly determine the interrupt mode,
including virtio_ethdev.

This series should be applied prior to Anatoly Burakov's
[VFIO] Add VFIO support to DPDK series

Alan Carew (4):
  igb_uio: Add interrupt_mode sysfs entry for igb_uio devices
  eal_pci: Add interrupt mode to rte_pci_device and parsing to eal_pci
  FreeBSD: Adds the equivalent interrupt mode setting and parsing
  virtio: Fixes the VIRTIO_PCI_CONFIG macro to use the correct offset
to the Virtio header

 lib/librte_eal/bsdapp/eal/eal_pci.c|   44 ++
 lib/librte_eal/bsdapp/nic_uio/nic_uio.c|   14 +++
 lib/librte_eal/common/Makefile |1 +
 lib/librte_eal/common/include/rte_pci.h|2 +
 .../common/include/rte_pci_dev_feature_defs.h  |   85 
 .../common/include/rte_pci_dev_features.h  |   70 
 lib/librte_eal/linuxapp/eal/eal_pci.c  |   78 ++
 lib/librte_eal/linuxapp/igb_uio/igb_uio.c  |   48 +---
 lib/librte_pmd_virtio/virtio_ethdev.c  |1 +
 lib/librte_pmd_virtio/virtio_pci.h |4 +-
 10 files changed, 336 insertions(+), 11 deletions(-)
 create mode 100755 lib/librte_eal/common/include/rte_pci_dev_feature_defs.h
 create mode 100755 lib/librte_eal/common/include/rte_pci_dev_features.h



[dpdk-dev] [PATCH 1/4] [PATCH 1/4] igb_uio: Add interrupt_mode sysfs entry for igb_uio devices

2014-06-05 Thread Alan Carew
This patch adds an "interrupt_mode" sysfs entry for igb_uio devices,
allowing userspace eal_pci to track which interrupt mode has been enabled in 
kernel space.
The sysfs entry can be inspected via 
/sys/bus/pci/devices/
---
 .../common/include/rte_pci_dev_feature_defs.h  |   85 
 .../common/include/rte_pci_dev_features.h  |   70 
 lib/librte_eal/linuxapp/igb_uio/igb_uio.c  |   48 +---
 3 files changed, 193 insertions(+), 10 deletions(-)
 create mode 100755 lib/librte_eal/common/include/rte_pci_dev_feature_defs.h
 create mode 100755 lib/librte_eal/common/include/rte_pci_dev_features.h

diff --git a/lib/librte_eal/common/include/rte_pci_dev_feature_defs.h 
b/lib/librte_eal/common/include/rte_pci_dev_feature_defs.h
new file mode 100755
index 000..d23ed7d
--- /dev/null
+++ b/lib/librte_eal/common/include/rte_pci_dev_feature_defs.h
@@ -0,0 +1,85 @@
+/*-
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ *   redistributing this file, you may do so under either license.
+ * 
+ *   GPL LICENSE SUMMARY
+ * 
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ * 
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of version 2 of the GNU General Public License as
+ *   published by the Free Software Foundation.
+ * 
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   General Public License for more details.
+ * 
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *   The full GNU General Public License is included in this distribution
+ *   in the file called LICENSE.GPL.
+ * 
+ *   Contact Information:
+ *   Intel Corporation
+ * 
+ *   BSD LICENSE
+ * 
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ * 
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ * 
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ * 
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ */
+
+#ifndef _RTE_PCI_DEV_DEFS_H_
+#define _RTE_PCI_DEV_DEFS_H_
+
+#define RTE_PCI_DEV_FEATURE_INTR_MODE  "interrupt_mode"
+
+#define INTR_NAME_LEN 10
+
+#define IGBUIO_NONE_INTR_NAME "none"
+#define IGBUIO_LEGACY_INTR_NAME "legacy"
+#define IGBUIO_MSI_INTR_NAME "msi"
+#define IGBUIO_MSIX_INTR_NAME "msix"
+
+
+#define INTR_MODE(id, mode_name) \
+.mode = (id), .name = (mode_name)
+
+/* interrupt mode */
+enum igbuio_intr_mode {
+   IGBUIO_NONE_INTR_MODE = 0,
+   IGBUIO_LEGACY_INTR_MODE,
+   IGBUIO_MSI_INTR_MODE,
+   IGBUIO_MSIX_INTR_MODE,
+   IGBUIO_INTR_MODE_MAX
+};
+
+#endif /* _RTE_PCI_DEV_DEFS_H_ */
diff --git a/lib/librte_eal/common/include/rte_pci_dev_features.h 
b/lib/librte_eal/common/include/rte_pci_dev_features.h
new file mode 100755
index 000..a45c056
--- /dev/null
+++ b/lib/librte_eal/common/include/rte_pci_dev_features.h
@@ -0,0 +1,70 @@
+/*-
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ *   redistributing this file, you may do so under either license.
+ * 
+ *   GPL LICENSE SUMMARY
+ * 
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ * 
+ *   This program is free software; you can redistribute it and/or modify
+ *   

[dpdk-dev] [PATCH 2/4] [PATCH 2/4] eal_pci: Add interrupt mode to rte_pci_device and parsing to eal_pci

2014-06-05 Thread Alan Carew
This patch adds a shared enum between user and kernel space to rte_pci_device.
The value of intr_mode is parsed by eal_pci during pci_uio_map_resource

Signed-off-by: Alan Carew 
---
 lib/librte_eal/common/Makefile  |1 +
 lib/librte_eal/common/include/rte_pci.h |2 +
 lib/librte_eal/linuxapp/eal/eal_pci.c   |   78 +++
 3 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile
index 0016fc5..52d46f3 100644
--- a/lib/librte_eal/common/Makefile
+++ b/lib/librte_eal/common/Makefile
@@ -35,6 +35,7 @@ INC := rte_atomic.h rte_branch_prediction.h rte_byteorder.h 
rte_common.h
 INC += rte_cycles.h rte_debug.h rte_eal.h rte_errno.h rte_launch.h rte_lcore.h
 INC += rte_log.h rte_memcpy.h rte_memory.h rte_memzone.h rte_pci.h
 INC += rte_pci_dev_ids.h rte_per_lcore.h rte_prefetch.h rte_random.h
+INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h
 INC += rte_rwlock.h rte_spinlock.h rte_tailq.h rte_interrupts.h rte_alarm.h
 INC += rte_string_fns.h rte_cpuflags.h rte_version.h rte_tailq_elem.h
 INC += rte_eal_memconfig.h rte_malloc_heap.h
diff --git a/lib/librte_eal/common/include/rte_pci.h 
b/lib/librte_eal/common/include/rte_pci.h
index c793773..5883cd9 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -81,6 +81,7 @@ extern "C" {
 #include 
 #include 
 #include 
+#include 

 TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */
 TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */
@@ -150,6 +151,7 @@ struct rte_pci_device {
const struct rte_pci_driver *driver;/**< Associated driver */
uint16_t max_vfs;   /**< sriov enable if not zero */
int numa_node;  /**< NUMA node connection */
+   enum igbuio_intr_mode intr_mode;/**< Interrupt mode */
struct rte_devargs *devargs;/**< Device user arguments */
 };

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c 
b/lib/librte_eal/linuxapp/eal/eal_pci.c
index ac2c1fe..7dba446 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -67,6 +67,7 @@
 #include 

 #include "rte_pci_dev_ids.h"
+#include "rte_pci_dev_feature_defs.h"
 #include "eal_filesystem.h"
 #include "eal_private.h"

@@ -89,6 +90,17 @@ struct uio_map {
uint64_t phaddr;
 };

+struct rte_pci_dev_intr_mode {
+   enum igbuio_intr_mode mode;
+   const char *name;
+};
+
+/* Table of interrupt modes */
+const struct rte_pci_dev_intr_mode interrupt_modes[] = {
+#define RTE_PCI_DEV_INTR_MODE(id, mode_name) {INTR_MODE(id, mode_name)},
+#include 
+};
+
 /*
  * For multi-process we need to reproduce all PCI mappings in secondary
  * processes, so save them in a tailq.
@@ -106,6 +118,7 @@ TAILQ_HEAD(uio_res_list, uio_resource);

 static struct uio_res_list *uio_res_list = NULL;
 static int pci_parse_sysfs_value(const char *filename, uint64_t *val);
+static int pci_parse_sysfs_intr_mode(const char *filename, struct 
rte_pci_device *dev);

 /* unbind kernel driver for this device */
 static int
@@ -400,6 +413,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
int i, j;
char dirname[PATH_MAX];
char devname[PATH_MAX]; /* contains the /dev/uioX */
+char filename[PATH_MAX];
void *mapaddr;
int uio_num;
uint64_t phaddr;
@@ -435,6 +449,18 @@ pci_uio_map_resource(struct rte_pci_device *dev)
}
dev->intr_handle.type = RTE_INTR_HANDLE_UIO;

+   rte_snprintf(filename, sizeof(filename),
+   SYSFS_PCI_DEVICES "/" PCI_PRI_FMT
+   "/"RTE_PCI_DEV_FEATURE_INTR_MODE,
+   loc->domain, loc->bus, loc->devid, loc->function);
+
+/* Get the kernel configured interrupt mode */
+   if (pci_parse_sysfs_intr_mode(filename, dev) < 0) {
+   RTE_LOG(ERR, EAL, "%s(): cannot determine interrupt_mode\n",
+   __func__);
+   return -1;
+   }
+
/* allocate the mapping details for secondary processes*/
if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
RTE_LOG(ERR, EAL,
@@ -591,6 +617,58 @@ pci_parse_sysfs_value(const char *filename, uint64_t *val)
 return 0;
 }

+/* 
+ * Parse a sysfs file containing a string
+ */ 
+static int
+pci_parse_sysfs_string(const char *filename, char *result_str, int max_len)
+{
+   FILE *f;
+   size_t len;
+
+   f = fopen(filename, "r");
+   if (f == NULL) {
+   RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
+   __func__, filename);
+   return -1;
+   }
+   if (fgets(result_s

[dpdk-dev] [PATCH 3/4] [PATCH 3/4] FreeBSD: Adds the equivalent interrupt mode setting and parsing

2014-06-05 Thread Alan Carew
This patch adds the equivalent functionality to FreeBSD as with patches 1 and 2

Signed-off-by: Alan Carew 
---
 lib/librte_eal/bsdapp/eal/eal_pci.c |   45 +++
 lib/librte_eal/bsdapp/nic_uio/nic_uio.c |   14 +
 2 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c 
b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 94ae461..7c270bb 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -50,6 +50,7 @@
 #include 
 #include 
 #include 
+#include 

 #include 
 #include 
@@ -108,6 +109,44 @@ TAILQ_HEAD(uio_res_list, uio_resource);

 static struct uio_res_list *uio_res_list = NULL;

+struct rte_pci_dev_intr_mode {
+   enum igbuio_intr_mode mode;
+   const char *name;
+};
+
+/* Table of interrupt modes */
+const struct rte_pci_dev_intr_mode interrupt_modes[] = {
+#define RTE_PCI_DEV_INTR_MODE(id, mode_name) {INTR_MODE (id, mode_name)},
+#include 
+};
+
+/*
+ * Determine the kernel configured interrupt mode
+ */
+static int
+pci_parse_intr_mode(struct rte_pci_device *dev)
+{
+   char intr_mode[INTR_NAME_LEN];
+   unsigned int i, num_intr_modes = RTE_DIM(interrupt_modes);
+   size_t sysctl_size = sizeof(intr_mode);
+
+   if (sysctlbyname("hw.nic_uio."RTE_PCI_DEV_FEATURE_INTR_MODE, &intr_mode,
+   &sysctl_size, NULL, 0) < 0) {
+   RTE_LOG(ERR, EAL,
+   "%s(): cannot get sysctlbyname: hw.nic_uio.intr_mode\n",
+__func__);
+   return (-1);
+   }
+   for (i = 0; i < num_intr_modes; i++) {
+   if (!strncmp(intr_mode, interrupt_modes[i].name, 
INTR_NAME_LEN)) {
+   dev->intr_mode = interrupt_modes[i].mode;
+   return 0;
+   }
+   }
+   return -1;
+   
+}
+
 /* unbind kernel driver for this device */
 static int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
@@ -220,6 +259,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
return -1;
}

+   if (pci_parse_intr_mode(dev) < 0) {
+   RTE_LOG(ERR, EAL,
+   "%s(): unable to determine interrupt mode\n", 
__func__);
+   return (-1);
+   }
+
/* save fd if in primary process */
dev->intr_handle.fd = open(devname, O_RDWR);
if (dev->intr_handle.fd < 0) {
diff --git a/lib/librte_eal/bsdapp/nic_uio/nic_uio.c 
b/lib/librte_eal/bsdapp/nic_uio/nic_uio.c
index c10e9aa..0e17d63 100644
--- a/lib/librte_eal/bsdapp/nic_uio/nic_uio.c
+++ b/lib/librte_eal/bsdapp/nic_uio/nic_uio.c
@@ -51,6 +51,10 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
+
+#include 
+#include 


 #define MAX_BARS (PCIR_MAX_BAR_0 + 1)
@@ -116,6 +120,16 @@ const struct device devices[] = {
 };
 #define NUM_DEVICES (sizeof(devices)/sizeof(devices[0]))

+static char nic_uio_intr_mode[] = {IGBUIO_NONE_INTR_NAME};
+
+TUNABLE_STR("hw.nic_uio."RTE_PCI_DEV_FEATURE_INTR_MODE, nic_uio_intr_mode, 
sizeof(nic_uio_intr_mode));
+
+static SYSCTL_NODE(_hw, OID_AUTO, nic_uio, CTLFLAG_RD, 0, "nic_uio");
+
+SYSCTL_STRING(_hw_nic_uio, OID_AUTO, interrupt_mode, CTLFLAG_RW,
+   &nic_uio_intr_mode, sizeof(nic_uio_intr_mode),
+   "Configured interrupt mode");
+

 static devclass_t nic_uio_devclass;

-- 
1.7.0.7



[dpdk-dev] [PATCH 4/4] [PATCH 4/4] virtio: Fixes the VIRTIO_PCI_CONFIG macro to use the correct offset to the Virtio header

2014-06-05 Thread Alan Carew
This final patch address the issue of not being able to determine the correct
offet when MSI-X is disabled.

Signed-off-by: Alan Carew 
---
 lib/librte_pmd_virtio/virtio_ethdev.c |1 +
 lib/librte_pmd_virtio/virtio_pci.h|4 +++-
 2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/lib/librte_pmd_virtio/virtio_ethdev.c 
b/lib/librte_pmd_virtio/virtio_ethdev.c
index c2b4dfb..819e7d7 100644
--- a/lib/librte_pmd_virtio/virtio_ethdev.c
+++ b/lib/librte_pmd_virtio/virtio_ethdev.c
@@ -719,6 +719,7 @@ eth_virtio_dev_init(__rte_unused struct eth_driver *eth_drv,
}
 #endif
hw->io_base = (uint32_t)(uintptr_t)pci_dev->mem_resource[0].addr;
+   hw->intr_mode = pci_dev->intr_mode;

/* Reset the device although not necessary at startup */
vtpci_reset(hw);
diff --git a/lib/librte_pmd_virtio/virtio_pci.h 
b/lib/librte_pmd_virtio/virtio_pci.h
index 96443c7..7b3d0ef 100644
--- a/lib/librte_pmd_virtio/virtio_pci.h
+++ b/lib/librte_pmd_virtio/virtio_pci.h
@@ -44,6 +44,7 @@
 #endif

 #include 
+#include 

 struct virtqueue;

@@ -177,6 +178,7 @@ struct virtio_hw {
uint16_tsubsystem_device_id;
uint16_tsubsystem_vendor_id;
uint8_t revision_id;
+   enumigbuio_intr_mode  intr_mode;
uint8_t mac_addr[ETHER_ADDR_LEN];
int adapter_stopped;
struct  rte_eth_stats eth_stats;
@@ -201,7 +203,7 @@ struct virtio_net_config {
  * The remaining space is defined by each driver as the per-driver
  * configuration space.
  */
-#define VIRTIO_PCI_CONFIG(hw) (((hw)->guest_features & VIRTIO_PCI_FLAG_MSIX) ? 
24 : 20)
+#define VIRTIO_PCI_CONFIG(hw) (((hw)->intr_mode == IGBUIO_MSIX_INTR_MODE) ? 24 
: 20)

 /*
  * How many bits to shift physical queue address written to QUEUE_PFN.
-- 
1.7.0.7



[dpdk-dev] [PATCH 1/2] rte_tailq.h: Fix compilation under FreeBSD

2014-06-05 Thread Alan Carew
Recent change to rte_dump_tailq, which now uses a FILE parameter
causes compilation to fail under FreeBSD and sourced to a
missing include of stdio.h

This and next patch(both small) allows to compile without error.

Signed-off-by: Alan Carew 
---
 lib/librte_eal/common/include/rte_tailq.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/librte_eal/common/include/rte_tailq.h 
b/lib/librte_eal/common/include/rte_tailq.h
index 42df7d2..0ddcc11 100644
--- a/lib/librte_eal/common/include/rte_tailq.h
+++ b/lib/librte_eal/common/include/rte_tailq.h
@@ -45,6 +45,7 @@ extern "C" {
 #endif

 #include 
+#include 

 /** dummy structure type used by the rte_tailq APIs */
 struct rte_dummy {
-- 
1.9.3



[dpdk-dev] [PATCH 2/2] eal_pci: Fix compilation under FreeBSD

2014-06-05 Thread Alan Carew
I'm not sure why this has not caused an issue before, perhaps
missing -Werror=unused-parameter or super-set
and subsequently fixed.
This patch adds __rte_unused to
pci_unbind_kernel_driver(struct rte_pci_device *dev)

Signed-off-by: Alan Carew 
---
 lib/librte_eal/bsdapp/eal/eal_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c 
b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 94ae461..5c4d81b 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -110,7 +110,7 @@ static struct uio_res_list *uio_res_list = NULL;

 /* unbind kernel driver for this device */
 static int
-pci_unbind_kernel_driver(struct rte_pci_device *dev)
+pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 {
RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented "
"for BSD\n");
-- 
1.9.3



[dpdk-dev] [PATCH 0/1] librte_pmd_virtio: Fix incorrect device specific header offset when MSI-X is disabled

2014-06-16 Thread Alan Carew
Following discussion with Stephen Hemminger and Neil Horman:
http://dpdk.org/ml/archives/dev/2014-June/003139.html
http://dpdk.org/ml/archives/dev/2014-June/00.html
http://dpdk.org/ml/archives/dev/2014-June/003295.html

There is no need for sysfs entries, instead localise the logic to
virtio_ethdev, I am basing this on Stephens effort to include
FreeBSD support.

Suggested-by: Neil Horman 
Suggested-by: Stephen Hemminger 

Alan Carew (1):
  librte_pmd_virtio: Fix incorrect device specific header offset when
MSI-X is disabled

 config/common_bsdapp  |  2 +-
 lib/librte_pmd_virtio/virtio_ethdev.c | 28 +++-
 lib/librte_pmd_virtio/virtio_pci.h|  5 ++---
 3 files changed, 30 insertions(+), 5 deletions(-)

-- 
1.9.3



[dpdk-dev] [PATCH 1/1] librte_pmd_virtio: Fix incorrect device specific header offset when MSI-X is disabled

2014-06-16 Thread Alan Carew
Signed-off-by: Alan Carew 
---
 config/common_bsdapp  |  2 +-
 lib/librte_pmd_virtio/virtio_ethdev.c | 28 +++-
 lib/librte_pmd_virtio/virtio_pci.h|  5 ++---
 3 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/config/common_bsdapp b/config/common_bsdapp
index ef8eeab..f7397ee 100644
--- a/config/common_bsdapp
+++ b/config/common_bsdapp
@@ -169,7 +169,7 @@ CONFIG_RTE_IXGBE_RX_OLFLAGS_DISABLE=n
 #
 # Compile burst-oriented VIRTIO PMD driver
 #
-CONFIG_RTE_LIBRTE_VIRTIO_PMD=n
+CONFIG_RTE_LIBRTE_VIRTIO_PMD=y
 CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_INIT=n
 CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_RX=n
 CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_TX=n
diff --git a/lib/librte_pmd_virtio/virtio_ethdev.c 
b/lib/librte_pmd_virtio/virtio_ethdev.c
index d0b419d..ecdf6f8 100644
--- a/lib/librte_pmd_virtio/virtio_ethdev.c
+++ b/lib/librte_pmd_virtio/virtio_ethdev.c
@@ -583,7 +583,8 @@ parse_sysfs_value(const char *filename, unsigned long *val)
return 0;
 }

-static int get_uio_dev(struct rte_pci_addr *loc, char *buf, unsigned int 
buflen)
+static
+int get_uio_dev(struct rte_pci_addr *loc, char *buf, unsigned int buflen)
 {
unsigned int uio_num;
struct dirent *e;
@@ -647,6 +648,30 @@ static int get_uio_dev(struct rte_pci_addr *loc, char 
*buf, unsigned int buflen)

return 0;
 }
+
+static int
+virtio_has_msix(const struct rte_pci_addr *loc)
+{
+   DIR *d;
+   char dirname[PATH_MAX];
+
+   rte_snprintf(dirname, sizeof(dirname),
+SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/msi_irqs",
+loc->domain, loc->bus, loc->devid, loc->function);
+
+   d = opendir(dirname);
+   if (d)
+   closedir(d);
+
+   return (d != NULL);
+}
+#else
+static int
+virtio_has_msix(const struct rte_pci_addr *loc __rte_unused)
+{
+   /* nic_uio does not enable interrupts, return 0 (false). */
+   return 0;
+}
 #endif

 /*
@@ -720,6 +745,7 @@ eth_virtio_dev_init(__rte_unused struct eth_driver *eth_drv,
 start, size);
}
 #endif
+   hw->use_msix = virtio_has_msix(&pci_dev->addr);
hw->io_base = (uint32_t)(uintptr_t)pci_dev->mem_resource[0].addr;

/* Reset the device although not necessary at startup */
diff --git a/lib/librte_pmd_virtio/virtio_pci.h 
b/lib/librte_pmd_virtio/virtio_pci.h
index 864b084..d27b734 100644
--- a/lib/librte_pmd_virtio/virtio_pci.h
+++ b/lib/librte_pmd_virtio/virtio_pci.h
@@ -177,6 +177,7 @@ struct virtio_hw {
uint16_tsubsystem_device_id;
uint16_tsubsystem_vendor_id;
uint8_t revision_id;
+   uint8_t use_msix;
uint8_t mac_addr[ETHER_ADDR_LEN];
int adapter_stopped;
struct  rte_eth_stats eth_stats;
@@ -195,13 +196,11 @@ struct virtio_net_config {
uint16_t   max_virtqueue_pairs;
 } __attribute__((packed));

-/* Value indicated in device config */
-#define VIRTIO_PCI_FLAG_MSIX  0x0020
 /*
  * The remaining space is defined by each driver as the per-driver
  * configuration space.
  */
-#define VIRTIO_PCI_CONFIG(hw) (((hw)->guest_features & VIRTIO_PCI_FLAG_MSIX) ? 
24 : 20)
+#define VIRTIO_PCI_CONFIG(hw) (((hw)->use_msix) ? 24 : 20)

 /*
  * How many bits to shift physical queue address written to QUEUE_PFN.
-- 
1.9.3



[dpdk-dev] [PATCH 01/10] Channel Manager and Monitor for VM Power Management(Host).

2014-09-22 Thread Alan Carew
The manager is responsible for adding communications channels to the Monitor
thread, tracking and reporting VM state and employs the libvirt API for
synchronization with the KVM Hypervisor. The manager interacts with the
Hypervisor to discover the mapping of virtual CPUS(vCPUs) to the host
physical CPUS(pCPUs) and to inspect the VM running state.

The manager provides the following functionality to the CLI:
1) Connect to a libvirtd instance, default: qemu:///system
2) Add a VM to an internal list, each VM is identified by a "name" which must
   correspond a valid libvirt Domain Name.
3) Add communication channels associated with a VM to the epoll based Monitor
   thread.
   The channels must exist and be in the form of:
   /tmp/powermonitor/.. Each channel is a
   Virtio-Serial endpoint configured as an AF_UNIX file socket and opened in
   non-blocking mode.
   Each VM can have a maximum of 64 channels associated with it.
4) Disable or re-enable VM communication channels, channels once added to the
   Monitor thread remain in that threads control, however acting on channel
   requests can be disabled and renabled via CLI.

The monitor is an epoll based infinite loop running in a separate thread that
waits on channel events from VMs and calls the corresponding functions. Channel
definitions from the manager are registered via the epoll event opaque pointer
when calling epoll_ctl(EPOLL_CTL_ADD), this allows for obtaining the channels
file descriptor for reading EPOLLIN events and mapping the vCPU to pCPU(s)
associated with a request from a particular VM.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/channel_manager.c | 643 
 examples/vm_power_manager/channel_manager.h | 273 
 examples/vm_power_manager/channel_monitor.c | 228 ++
 examples/vm_power_manager/channel_monitor.h | 102 +
 4 files changed, 1246 insertions(+)
 create mode 100644 examples/vm_power_manager/channel_manager.c
 create mode 100644 examples/vm_power_manager/channel_manager.h
 create mode 100644 examples/vm_power_manager/channel_monitor.c
 create mode 100644 examples/vm_power_manager/channel_monitor.h

diff --git a/examples/vm_power_manager/channel_manager.c 
b/examples/vm_power_manager/channel_manager.c
new file mode 100644
index 000..7ec798f
--- /dev/null
+++ b/examples/vm_power_manager/channel_manager.c
@@ -0,0 +1,643 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "channel_manager.h"
+#include "channel_commands.h"
+#include "channel_monitor.h"
+
+
+#define SOCKET_PATH "/tmp/powermonitor/"
+
+#define RTE_LOGTYPE_CHANNEL_MANAGER RTE_LOGTYPE_USER1
+
+#define ITERATIVE_BITMASK_CHECK_64(mask_u64b, i) \
+   for (i = 0; mask_u64b; mask_u64b &= ~(1ULL << i++)) \
+   if ((mask_u64b >> i) & 1) \
+
+/* Global pointer to libvirt connection */
+static virConnectPtr global_vir_conn_ptr;
+
+/*
+ * Represents a single Virtual Machine
+ */
+struct virtual_machine_info {
+   char name[MAX_NAME_L

[dpdk-dev] [PATCH 02/10] VM Power Management CLI(Host).

2014-09-22 Thread Alan Carew
The CLI is used for administrating the channel monitor and manager and
manually setting the CPU frequency on the host.

Supports the following commands:
 add_vm [Mul-choice STRING]: add_vm|rm_vm , add a VM for subsequent
  operations with the CLI or remove a previously added VM from the VM Power
  Manager

 rm_vm [Mul-choice STRING]: add_vm|rm_vm , add a VM for subsequent
  operations with the CLI or remove a previously added VM from the VM Power
  Manager

 add_channels [Fixed STRING]: add_channels  |all, add
  communication channels for the specified VM, the virtio channels must be
  enabled in the VM configuration(qemu/libvirt) and the associated VM must be
  active.  is a comma-separated list of channel numbers to add, using the
  keyword 'all' will attempt to add all channels for the VM

 set_channel_status [Fixed STRING]:
  set_channel_status  |all enabled|disabled,  enable or disable
  the communication channels in list(comma-seperated) for the specified VM,
  alternatively list can be replaced with keyword 'all'. Disabled channels will
  still receive packets on the host, however the commands they specify will be
  ignored. Set status to 'enabled' to begin processing requests again.

 show_vm [Fixed STRING]: show_vm , prints the information on the
  specified VM(s), the information lists the number of vCPUS, the pinning to
  pCPU(s) as a bit mask, along with any communication channels associated with
  each VM

 show_cpu_freq_mask [Fixed STRING]: show_cpu_freq_mask , Get the current
  frequency for each core specified in the mask

 set_cpu_freq_mask [Fixed STRING]: set_cpu_freq  ,
  Set the current frequency for the cores specified in  by scaling
  each up/down/min/max.

 show_cpu_freq [Fixed STRING]: Get the current frequency for the specified core

 set_cpu_freq [Fixed STRING]: set_cpu_freq  ,
  Set the current frequency for the specified core by scaling up/down/min/max

 quit [Fixed STRING]: close the application

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/vm_power_cli.c | 567 +++
 examples/vm_power_manager/vm_power_cli.h |  47 +++
 2 files changed, 614 insertions(+)
 create mode 100644 examples/vm_power_manager/vm_power_cli.c
 create mode 100644 examples/vm_power_manager/vm_power_cli.h

diff --git a/examples/vm_power_manager/vm_power_cli.c 
b/examples/vm_power_manager/vm_power_cli.c
new file mode 100644
index 000..f5e3759
--- /dev/null
+++ b/examples/vm_power_manager/vm_power_cli.c
@@ -0,0 +1,567 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vm_power_cli.h"
+#include "channel_manager.h"
+#include "channel_monitor.h"
+#include "power_manager.h"
+#include "channel_commands.h"
+
+struct cmd_quit_result {
+   cmdline_fixed_string_t quit;
+};
+
+static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
+   struct cmdline *cl,
+   __attribute__((unused)) void *data)
+{
+   channel_monitor_exit();
+   channel_manager_exit();
+   power_manager_exit();
+   cmdline_qui

[dpdk-dev] [PATCH 03/10] CPU Frequency Power Management(Host).

2014-09-22 Thread Alan Carew
A wrapper around librte_power, providing locking around the non-threadsafe
library, allowing for frequency changes based on core masks and core numbers
from both the CLI thread and epoll monitor thread.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/power_manager.c | 234 ++
 examples/vm_power_manager/power_manager.h | 191 
 2 files changed, 425 insertions(+)
 create mode 100644 examples/vm_power_manager/power_manager.c
 create mode 100644 examples/vm_power_manager/power_manager.h

diff --git a/examples/vm_power_manager/power_manager.c 
b/examples/vm_power_manager/power_manager.c
new file mode 100644
index 000..ceca532
--- /dev/null
+++ b/examples/vm_power_manager/power_manager.c
@@ -0,0 +1,234 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "power_manager.h"
+
+#define RTE_LOGTYPE_POWER_MANAGER RTE_LOGTYPE_USER1
+
+#define POWER_SCALE_CORE(DIRECTION, core_num, ret) do { \
+   if (!(global_enabled_cpus & (1ULL << core_num))) \
+   return -1; \
+   rte_spinlock_lock(&global_core_freq_info[core_num].power_sl); \
+   ret = rte_power_freq_##DIRECTION(core_num); \
+   rte_spinlock_unlock(&global_core_freq_info[core_num].power_sl); \
+} while (0)
+
+#define POWER_SCALE_MASK(DIRECTION, core_mask, ret) do { \
+   int i; \
+   for (i = 0; core_mask; core_mask &= ~(1 << i++)) { \
+   if (!(global_enabled_cpus & (1ULL << i))) \
+   return -1; \
+   rte_spinlock_lock(&global_core_freq_info[i].power_sl); \
+   ret = rte_power_freq_##DIRECTION(i); \
+   rte_spinlock_unlock(&global_core_freq_info[i].power_sl); \
+   } \
+} while (0)
+
+struct freq_info {
+   rte_spinlock_t power_sl;
+   uint32_t freqs[RTE_MAX_LCORE_FREQS];
+   unsigned num_freqs;
+} __rte_cache_aligned;
+
+static struct freq_info global_core_freq_info[RTE_MAX_LCORE];
+
+static uint64_t global_enabled_cpus;
+
+#define SYSFS_CPU_PATH "/sys/devices/system/cpu/cpu%u/topology/core_id"
+
+static unsigned
+set_host_cpus_mask(void)
+{
+   char path[PATH_MAX];
+   unsigned i;
+   unsigned num_cpus = 0;
+   for (i = 0; i < RTE_MAX_LCORE; i++) {
+   snprintf(path, sizeof(path), SYSFS_CPU_PATH, i);
+   if (access(path, F_OK) == 0) {
+   global_enabled_cpus |= 1 << i;
+   num_cpus++;
+   } else
+   return num_cpus;
+   }
+   return num_cpus;
+}
+
+int
+power_manager_init(void)
+{
+   unsigned i, num_cpus;
+   uint64_t cpu_mask;
+   int ret = 0;
+
+   num_cpus = set_host_cpus_mask();
+   if (num_cpus == 0) {
+   RTE_LOG(ERR, POWER_MANAGER, "Unable to detected host CPUs, 
please "
+   "ensure that sufficient privileges exist to 
inspect sysfs\n");
+   return -1;
+   }
+
+   cpu_mask = global_enabled_cpus;
+   for (i

[dpdk-dev] [PATCH 04/10] CPU Frequency Power Management(Host).

2014-09-22 Thread Alan Carew
A wrapper around librte_power, providing locking around the non-threadsafe
library, allowing for frequency changes based on core masks and core numbers
from both the CLI thread and epoll monitor thread.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/Makefile |  57 +++
 examples/vm_power_manager/main.c   | 113 +
 examples/vm_power_manager/main.h   |  52 +
 3 files changed, 222 insertions(+)
 create mode 100644 examples/vm_power_manager/Makefile
 create mode 100644 examples/vm_power_manager/main.c
 create mode 100644 examples/vm_power_manager/main.h

diff --git a/examples/vm_power_manager/Makefile 
b/examples/vm_power_manager/Makefile
new file mode 100644
index 000..a2f00ea
--- /dev/null
+++ b/examples/vm_power_manager/Makefile
@@ -0,0 +1,57 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriden by command line or environment
+RTE_TARGET ?= x86_64-default-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = vm_power_mgr
+
+# all source are stored in SRCS-y
+SRCS-y := main.c vm_power_cli.c power_manager.c channel_manager.c
+SRCS-y += channel_monitor.c
+
+CFLAGS += -O3 -lvirt -I$(RTE_SDK)/lib/librte_power_vm/
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/vm_power_manager/main.c b/examples/vm_power_manager/main.c
new file mode 100644
index 000..fdb9e73
--- /dev/null
+++ b/examples/vm_power_manager/main.c
@@ -0,0 +1,113 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN 

[dpdk-dev] [PATCH 06/10] Alternate implementation of librte_power for VM Power Management(Guest).

2014-09-22 Thread Alan Carew
Re-using the host based librte_power API the alternate implementation uses
the guest channel API to forward request for frequency changes to the host
monitor.
A subset of the librte_power API is supported:
 rte_power_init(unsigned lcore_id)
 rte_power_exit(unsigned lcore_id)
 rte_power_freq_up(unsigned lcore_id)
 rte_power_freq_down(unsigned lcore_id)
 rte_power_freq_min(unsigned lcore_id)
 rte_power_freq_max(unsigned lcore_id)

The other unsupported APIs from librte_power return -ENOTSUP.

Signed-off-by: Alan Carew 
---
 lib/librte_power_vm/Makefile|  49 ++
 lib/librte_power_vm/rte_power.c | 146 
 2 files changed, 195 insertions(+)
 create mode 100644 lib/librte_power_vm/Makefile
 create mode 100644 lib/librte_power_vm/rte_power.c

diff --git a/lib/librte_power_vm/Makefile b/lib/librte_power_vm/Makefile
new file mode 100644
index 000..284ec2c
--- /dev/null
+++ b/lib/librte_power_vm/Makefile
@@ -0,0 +1,49 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# library name
+LIB = librte_power.a
+
+CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing
+CFLAGS += -I$(RTE_SDK)/lib/librte_power/
+
+# all source are stored in SRCS-y
+SRCS-$(CONFIG_RTE_LIBRTE_POWER_VM) := guest_channel.c rte_power.c
+
+# install this header file
+SYMLINK-y-include := ../librte_power/rte_power.h
+
+# this lib needs eal
+DEPDIRS-$(CONFIG_RTE_LIBRTE_POWER) += lib/librte_eal
+
+include $(RTE_SDK)/mk/rte.lib.mk
diff --git a/lib/librte_power_vm/rte_power.c b/lib/librte_power_vm/rte_power.c
new file mode 100644
index 000..1ce3fb0
--- /dev/null
+++ b/lib/librte_power_vm/rte_power.c
@@ -0,0 +1,146 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT

[dpdk-dev] [PATCH 05/10] VM communication channels for VM Power Management(Guest).

2014-09-22 Thread Alan Carew
Allows for the opening of Virtio-Serial devices on a VM, where a DPDK
application can send packets to the host based monitor. The packet formatted is
specified in channel_commands.h
Each device appears as a serial device in path
/dev/virtio-ports/virtio.serial.port.. where each lcore
in a DPDK application has exclusive to a device/channel.
Each channel is opened in non-blocking mode, after a successful open a test
packet is send to the host to ensure the host side is monitoring.

Signed-off-by: Alan Carew 
---
 lib/librte_power_vm/guest_channel.c | 150 
 lib/librte_power_vm/guest_channel.h |  89 +
 2 files changed, 239 insertions(+)
 create mode 100644 lib/librte_power_vm/guest_channel.c
 create mode 100644 lib/librte_power_vm/guest_channel.h

diff --git a/lib/librte_power_vm/guest_channel.c 
b/lib/librte_power_vm/guest_channel.c
new file mode 100644
index 000..8baa20a
--- /dev/null
+++ b/lib/librte_power_vm/guest_channel.c
@@ -0,0 +1,150 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#include 
+#include 
+
+#include "guest_channel.h"
+#include "channel_commands.h"
+
+#define RTE_LOGTYPE_GUEST_CHANNEL RTE_LOGTYPE_USER1
+
+static int global_fds[RTE_MAX_LCORE];
+
+int
+guest_channel_host_connect(const char *path, unsigned lcore_id)
+{
+   int flags, ret;
+   struct channel_packet pkt;
+   char fd_path[PATH_MAX];
+   int fd = -1;
+
+   if (lcore_id >= RTE_MAX_LCORE) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Channel(%u) is out of range 
0...%d\n",
+   lcore_id, RTE_MAX_LCORE-1);
+   return -1;
+   }
+   /* check if path is already open */
+   if (global_fds[lcore_id] != 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Channel(%u) is already open\n", 
lcore_id);
+   return -1;
+   }
+
+   snprintf(fd_path, PATH_MAX, "%s.%u", path, lcore_id);
+   RTE_LOG(INFO, GUEST_CHANNEL, "Opening channel '%s' for lcore %u\n",
+   fd_path, lcore_id);
+   fd = open(fd_path, O_RDWR);
+   if (fd < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Unable to to connect to '%s' with 
error "
+   "%s\n", fd_path, strerror(errno));
+   return -1;
+   }
+
+   flags = fcntl(fd, F_GETFL, 0);
+   if (flags < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Failed on fcntl get flags for file 
%s\n",
+   fd_path);
+   return -1;
+   }
+
+   flags |= O_NONBLOCK;
+   if (fcntl(fd, F_SETFL, flags) < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Failed on setting non-blocking 
mode for "
+   "file %s", fd_path);
+   return -1;
+   }
+   /* QEMU needs a delay after connection */
+   sleep(1);
+
+   /* Send a test packet, this command is ignored by the host, but a 
successful
+*  send indicates that the host endpoint is monitoring.
+*/
+   pkt.command = CPU_POWER_CONNECT;
+   global

[dpdk-dev] [PATCH 07/10] Packet format for VM Power Management(Host and Guest).

2014-09-22 Thread Alan Carew
Provides a command packet format for host and guest.

Signed-off-by: Alan Carew 
---
 lib/librte_power_vm/channel_commands.h | 68 ++
 1 file changed, 68 insertions(+)
 create mode 100644 lib/librte_power_vm/channel_commands.h

diff --git a/lib/librte_power_vm/channel_commands.h 
b/lib/librte_power_vm/channel_commands.h
new file mode 100644
index 000..4ad65cf
--- /dev/null
+++ b/lib/librte_power_vm/channel_commands.h
@@ -0,0 +1,68 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CHANNEL_COMMANDS_H_
+#define CHANNEL_COMMANDS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+#include 
+
+#if RTE_MAX_LCORE > 64
+#error Maximum number of cores and channels is 64, overflow is guaranteed to \
+   cause problems.
+#endif
+
+#define CPU_POWER 1
+#define CPU_POWER_CONNECT 2
+
+#define CPU_SCALE_UP  1
+#define CPU_SCALE_DOWN2
+#define CPU_SCALE_MAX 3
+#define CPU_SCALE_MIN 4
+
+struct channel_packet {
+   uint64_t resource_id; /* core_num, device */
+   uint32_t unit; /* scale down/up/min/max */
+   uint32_t command; /* Power, IO, etc */
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CHANNEL_COMMANDS_H_ */
-- 
1.9.3



[dpdk-dev] [PATCH 08/10] Build system integration for VM Power Management(Guest and Host)

2014-09-22 Thread Alan Carew
Add CONFIG_RTE_LIBRTE_POWER_VM to config/common_linuxapp, default=n
As both host and guest side rely on the same API(librte_power) but different
implementations, it requires the following configurations:
Host: CONFIG_RTE_LIBRTE_POWER_VM=n and Add CONFIG_RTE_LIBRTE_POWER=y
Guest: CONFIG_RTE_LIBRTE_POWER_VM=y and Add CONFIG_RTE_LIBRTE_POWER=n

When building for either the resulting library is called rte_power.

Signed-off-by: Alan Carew 
---
 config/common_linuxapp | 6 ++
 lib/Makefile   | 1 +
 mk/rte.app.mk  | 4 
 3 files changed, 11 insertions(+)

diff --git a/config/common_linuxapp b/config/common_linuxapp
index 5bee910..fbecad3 100644
--- a/config/common_linuxapp
+++ b/config/common_linuxapp
@@ -332,6 +332,12 @@ CONFIG_RTE_LIBRTE_POWER_DEBUG=n
 CONFIG_RTE_MAX_LCORE_FREQS=64

 #
+# Compile librte_power_vm
+#
+CONFIG_RTE_LIBRTE_POWER_VM=n
+CONFIG_RTE_LIBRTE_POWER_VM_DEBUG=n
+
+#
 # Compile librte_net
 #
 CONFIG_RTE_LIBRTE_NET=y
diff --git a/lib/Makefile b/lib/Makefile
index 10c5bb3..d291459 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -56,6 +56,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_ACL) += librte_acl
 DIRS-$(CONFIG_RTE_LIBRTE_NET) += librte_net
 DIRS-$(CONFIG_RTE_LIBRTE_IP_FRAG) += librte_ip_frag
 DIRS-$(CONFIG_RTE_LIBRTE_POWER) += librte_power
+DIRS-$(CONFIG_RTE_LIBRTE_POWER_VM) += librte_power_vm
 DIRS-$(CONFIG_RTE_LIBRTE_METER) += librte_meter
 DIRS-$(CONFIG_RTE_LIBRTE_SCHED) += librte_sched
 DIRS-$(CONFIG_RTE_LIBRTE_KVARGS) += librte_kvargs
diff --git a/mk/rte.app.mk b/mk/rte.app.mk
index 34dff2a..ce8c684 100644
--- a/mk/rte.app.mk
+++ b/mk/rte.app.mk
@@ -105,6 +105,10 @@ ifeq ($(CONFIG_RTE_LIBRTE_POWER),y)
 LDLIBS += -lrte_power
 endif

+ifeq ($(CONFIG_RTE_LIBRTE_POWER_VM),y)
+LDLIBS += -lrte_power
+endif
+
 ifeq ($(CONFIG_RTE_LIBRTE_ACL),y)
 LDLIBS += -lrte_acl
 endif
-- 
1.9.3



[dpdk-dev] [PATCH 09/10] VM Power Management Unit Tests(Guest)

2014-09-22 Thread Alan Carew
Signed-off-by: Alan Carew 
---
 app/test/Makefile |   1 +
 app/test/autotest_data.py |  13 +++
 app/test/test_power_vm.c  | 215 ++
 3 files changed, 229 insertions(+)
 create mode 100644 app/test/test_power_vm.c

diff --git a/app/test/Makefile b/app/test/Makefile
index 37a3772..39dd08e 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -120,6 +120,7 @@ endif
 SRCS-$(CONFIG_RTE_LIBRTE_METER) += test_meter.c
 SRCS-$(CONFIG_RTE_LIBRTE_KNI) += test_kni.c
 SRCS-$(CONFIG_RTE_LIBRTE_POWER) += test_power.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER_VM) += test_power_vm.c
 SRCS-y += test_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_IVSHMEM) += test_ivshmem.c

diff --git a/app/test/autotest_data.py b/app/test/autotest_data.py
index 878c72e..5c6b60b 100644
--- a/app/test/autotest_data.py
+++ b/app/test/autotest_data.py
@@ -425,6 +425,19 @@ non_parallel_test_group_list = [
]
 },
 {
+   "Prefix" :  "power_vm",
+   "Memory" :  "512",
+   "Tests" :
+   [
+   {
+"Name" :   "Power VM  autotest",
+"Command" :"power_vm_autotest",
+"Func" :   default_autotest,
+"Report" : None,
+   },
+   ]
+},
+{
"Prefix" :  "lpm6",
"Memory" :  "512",
"Tests" :
diff --git a/app/test/test_power_vm.c b/app/test/test_power_vm.c
new file mode 100644
index 000..176fbec
--- /dev/null
+++ b/app/test/test_power_vm.c
@@ -0,0 +1,215 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test.h"
+
+#include 
+
+#define TEST_POWER_VM_LCORE_ID  0U
+#define TEST_POWER_VM_LCORE_INVALID 64U
+
+static int
+test_power_vm(void)
+{
+   int ret;
+
+   /* Test initialisation of invalid lcore */
+   ret = rte_power_init(TEST_POWER_VM_LCORE_INVALID);
+   if (ret != -1) {
+   printf("rte_power_init unexpectedly succeeded on an invalid 
lcore %u\n",
+   TEST_POWER_VM_LCORE_ID);
+   return -1;
+   }
+
+   /* Test initialisation of previously initialised lcore */
+   ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
+   if (ret != 0) {
+   printf("rte_power_init unexpectedly failed on valid lcore %u,"
+   "please ensure that the environment has been 
configured "
+   "correctly and test application is running on a 
VM\n",
+   TEST_POWER_VM_LCORE_ID);
+   return -1;
+   }
+   ret = rte_power_init(TEST_POWER_VM_LCORE_ID);
+   if (ret == 0) {
+   printf("rte_power_init unexpectedly succeeded on calling init 
twice on"
+   "lcore %u\n", TEST_POWER_VM_LCORE_ID);
+   return -1;
+   }
+
+   /* Test frequency up of invalid lcore */
+   ret = rte_power_freq_up(TEST_POWER_VM_LCORE_INVALID);
+   if (ret == 0) {
+   printf("rte_po

[dpdk-dev] [PATCH 10/10] VM Power Management CLI(Guest).

2014-09-22 Thread Alan Carew
Provides a small sample application(guest_vm_power_mgr) to run on a VM.
The application is run by providing a core mask(-c) and number of memory
channels(-n). The core mask corresponds to the number of lcore channels to
attempt to open. A maximum of 64 channels per VM is allowed. The channels must
be monitored by the host.
After successful initialisation a CPU frequency command can be sent to the host
using:
set_cpu_freq  .

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/guest_cli/Makefile   |  56 
 examples/vm_power_manager/guest_cli/main.c |  87 
 examples/vm_power_manager/guest_cli/main.h |  52 +++
 .../guest_cli/vm_power_cli_guest.c | 155 +
 .../guest_cli/vm_power_cli_guest.h |  55 
 5 files changed, 405 insertions(+)
 create mode 100644 examples/vm_power_manager/guest_cli/Makefile
 create mode 100644 examples/vm_power_manager/guest_cli/main.c
 create mode 100644 examples/vm_power_manager/guest_cli/main.h
 create mode 100644 examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
 create mode 100644 examples/vm_power_manager/guest_cli/vm_power_cli_guest.h

diff --git a/examples/vm_power_manager/guest_cli/Makefile 
b/examples/vm_power_manager/guest_cli/Makefile
new file mode 100644
index 000..c380c77
--- /dev/null
+++ b/examples/vm_power_manager/guest_cli/Makefile
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriden by command line or environment
+RTE_TARGET ?= x86_64-default-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = guest_vm_power_mgr
+
+# all source are stored in SRCS-y
+SRCS-y := main.c vm_power_cli_guest.c
+
+CFLAGS += -O3 -I$(RTE_SDK)/lib/librte_power_vm/
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/vm_power_manager/guest_cli/main.c 
b/examples/vm_power_manager/guest_cli/main.c
new file mode 100644
index 000..2715778
--- /dev/null
+++ b/examples/vm_power_manager/guest_cli/main.c
@@ -0,0 +1,87 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "

[dpdk-dev] [PATCH 00/10] VM Power Management

2014-09-22 Thread Alan Carew
The following patches add two DPDK sample applications and an alternate
implementation of librte_power for use in virtualized environments.
The idea is to provide librte_power functionality from within a VM to address
the lack of MSRs to facilitate frequency changes from within a VM.
It is ideally suited for Haswell which provides per core frequency scaling.

The current librte_power affects frequency changes via the acpi-cpufreq
'userspace' power governor, accessed via sysfs.

General Overview:(more information in each patch that follows).
The VM Power Management solution provides two components:

 1)VM: Allows for the a DPDK application in a VM to reuse the librte_power
 interface. Each lcore opens a Virto-Serial endpoint channel to the host,
 where the re-implementation of librte_power simply forwards the requests for
 frequency change to a host based monitor. The host monitor itself uses
 librte_power.
 Each lcore channel corresponds to a
 serial device '/dev/virtio-ports/virtio.serial.port.poweragent.'
 which is opened in non-blocking mode.
 While each Virtual CPU can be mapped to multiple physical CPUs it is
 recommended that each vCPU should be mapped to a single core only.

 2)Host: The host monitor is managed by a CLI, it allows for adding qemu/KVM
 virtual machines and associated channels to the monitor, manually changing
 CPU frequency, inspecting the state of VMs, vCPU to pCPU pinning and managing
 channels.
 Host channel endpoints are Virto-Serial endpoints configured as AF_UNIX file
 sockets which follow a specific naming convention
 i.e /tmp/powermonitor/.,
 each channel has an 1:1 mapping to a VM endpoint
 i.e. /dev/virtio-ports/virtio.serial.port.poweragent.
 Host channel endpoints are opened in non-blocking mode and are monitored via 
epoll.
 Requests over each channel to change frequency are forwarded to the original
 librte_power.

Channels must be manually configured as qemu-kvm command line arguments or
libvirt domain definition(xml) e.g.

 


  
  


Where multiple channels can be configured by specifying multiple 
elements, by replacing , .
(port number) should be incremented by 1 for each new channel element.
More information on Virtio-Serial can be found here:
http://fedoraproject.org/wiki/Features/VirtioSerial
To enable the Hypervisor creation of channels, the host endpoint directory
must be created with qemu permissions:
mkdir /tmp/powermonitor
chown qemu:qemu /tmp/powermonitor

The host application runs on two seperate lcores:
Core N) CLI: For management of Virtual Machines adding channels to Monitor 
thread,
 inspecting state and manually setting CPU frequency [PATCH 02/09]
Core N+1) Monitor Thread: An epoll based infintie loop that waits on channel 
events
 from VMs and calls the corresponing librte_power functions.

A sample application is also provided to run on Virtual Machines, this
application provides a CLI to manually set the frequency of a 
vCPU[PATCH 08/09]

The current l3fwd-power sample application can also be run on a VM.


Alan Carew (10):
  Channel Manager and Monitor for VM Power Management(Host).
  VM Power Management CLI(Host).
  CPU Frequency Power Management(Host).
  CPU Frequency Power Management(Host).
  VM communication channels for VM Power Management(Guest).
  Alternate implementation of librte_power for VM Power
Management(Guest).
  Packet format for VM Power Management(Host and Guest).
  Build system integration for VM Power Management(Guest and Host)
  VM Power Management Unit Tests(Guest)
  VM Power Management CLI(Guest).

 app/test/Makefile  |   1 +
 app/test/autotest_data.py  |  13 +
 app/test/test_power_vm.c   | 215 +++
 config/common_linuxapp |   6 +
 examples/vm_power_manager/Makefile |  57 ++
 examples/vm_power_manager/channel_manager.c| 643 +
 examples/vm_power_manager/channel_manager.h| 273 +
 examples/vm_power_manager/channel_monitor.c| 228 
 examples/vm_power_manager/channel_monitor.h| 102 
 examples/vm_power_manager/guest_cli/Makefile   |  56 ++
 examples/vm_power_manager/guest_cli/main.c |  87 +++
 examples/vm_power_manager/guest_cli/main.h |  52 ++
 .../guest_cli/vm_power_cli_guest.c | 155 +
 .../guest_cli/vm_power_cli_guest.h |  55 ++
 examples/vm_power_manager/main.c   | 113 
 examples/vm_power_manager/main.h   |  52 ++
 examples/vm_power_manager/power_manager.c  | 234 
 examples/vm_power_manager/power_manager.h  | 191 ++
 examples/vm_power_manager/vm_power_cli.c   | 567 ++
 examples/vm_power_manager/vm_power_cli.h   |  47 ++
 lib/Makefile   |   1 +
 lib/librte_power_vm/Makefile   |  49 ++
 lib/librte_power_v

[dpdk-dev] [PATCH v2 00/10] VM Power Management

2014-09-24 Thread Alan Carew
Virtual Machine Power Management.

The following patches add two DPDK sample applications and an alternate
implementation of librte_power for use in virtualized environments.
The idea is to provide librte_power functionality from within a VM to address
the lack of MSRs to facilitate frequency changes from within a VM.
It is ideally suited for Haswell which provides per core frequency scaling.

The current librte_power affects frequency changes via the acpi-cpufreq
'userspace' power governor, accessed via sysfs.

General Overview:(more information in each patch that follows).
The VM Power Management solution provides two components:

 1)VM: Allows for the a DPDK application in a VM to reuse the librte_power
 interface. Each lcore opens a Virto-Serial endpoint channel to the host,
 where the re-implementation of librte_power simply forwards the requests for
 frequency change to a host based monitor. The host monitor itself uses
 librte_power.
 Each lcore channel corresponds to a
 serial device '/dev/virtio-ports/virtio.serial.port.poweragent.'
 which is opened in non-blocking mode.
 While each Virtual CPU can be mapped to multiple physical CPUs it is
 recommended that each vCPU should be mapped to a single core only.

 2)Host: The host monitor is managed by a CLI, it allows for adding qemu/KVM
 virtual machines and associated channels to the monitor, manually changing
 CPU frequency, inspecting the state of VMs, vCPU to pCPU pinning and managing
 channels.
 Host channel endpoints are Virto-Serial endpoints configured as AF_UNIX file
 sockets which follow a specific naming convention
 i.e /tmp/powermonitor/.,
 each channel has an 1:1 mapping to a VM endpoint
 i.e. /dev/virtio-ports/virtio.serial.port.poweragent.
 Host channel endpoints are opened in non-blocking mode and are monitored via 
epoll.
 Requests over each channel to change frequency are forwarded to the original
 librte_power.

Channels must be manually configured as qemu-kvm command line arguments or
libvirt domain definition(xml) e.g.

 


  
  


Where multiple channels can be configured by specifying multiple 
elements, by replacing , .
(port number) should be incremented by 1 for each new channel element.
More information on Virtio-Serial can be found here:
http://fedoraproject.org/wiki/Features/VirtioSerial
To enable the Hypervisor creation of channels, the host endpoint directory
must be created with qemu permissions:
mkdir /tmp/powermonitor
chown qemu:qemu /tmp/powermonitor

The host application runs on two separate lcores:
Core N) CLI: For management of Virtual Machines adding channels to Monitor 
thread,
 inspecting state and manually setting CPU frequency [PATCH 02/09]
Core N+1) Monitor Thread: An epoll based infinite loop that waits on channel 
events
 from VMs and calls the corresponding librte_power functions.

A sample application is also provided to run on Virtual Machines, this
application provides a CLI to manually set the frequency of a 
vCPU[PATCH 08/09]

The current l3fwd-power sample application can also be run on a VM.

Changes in V2:
 Runtime selection of librte_power implementations.
 Updated Unit tests to cover librte_power changes.
 PATCH[0/3] was sent twice, again as PATCH[0/4]
 Miscellaneous fixes.

Alan Carew (10):
  Channel Manager and Monitor for VM Power Management(Host).
  VM Power Management CLI(Host).
  CPU Frequency Power Management(Host).
  VM Power Management application and Makefile.
  VM Power Management CLI(Guest).
  VM communication channels for VM Power Management(Guest).
  librte_power common interface for Guest and Host
  Packet format for VM Power Management(Host and Guest).
  Build system integration for VM Power Management(Guest and Host)
  VM Power Management Unit Tests

 app/test/Makefile  |   3 +-
 app/test/autotest_data.py  |  26 +
 app/test/test_power.c  | 445 ++
 app/test/test_power_acpi_cpufreq.c | 544 +
 app/test/test_power_kvm_vm.c   | 308 ++
 examples/vm_power_manager/Makefile |  57 ++
 examples/vm_power_manager/channel_manager.c| 645 +
 examples/vm_power_manager/channel_manager.h| 273 +
 examples/vm_power_manager/channel_monitor.c| 228 
 examples/vm_power_manager/channel_monitor.h| 102 
 examples/vm_power_manager/guest_cli/Makefile   |  56 ++
 examples/vm_power_manager/guest_cli/main.c |  86 +++
 examples/vm_power_manager/guest_cli/main.h |  52 ++
 .../guest_cli/vm_power_cli_guest.c | 155 +
 .../guest_cli/vm_power_cli_guest.h |  55 ++
 examples/vm_power_manager/main.c   | 113 
 examples/vm_power_manager/main.h   |  52 ++
 examples/vm_power_manager/power_manager.c  | 244 
 examples/vm_power_manager/power_mana

[dpdk-dev] [PATCH v2 01/10] Channel Manager and Monitor for VM Power Management(Host).

2014-09-24 Thread Alan Carew
The manager is responsible for adding communications channels to the Monitor
thread, tracking and reporting VM state and employs the libvirt API for
synchronization with the KVM Hypervisor. The manager interacts with the
Hypervisor to discover the mapping of virtual CPUS(vCPUs) to the host
physical CPUS(pCPUs) and to inspect the VM running state.

The manager provides the following functionality to the CLI:
1) Connect to a libvirtd instance, default: qemu:///system
2) Add a VM to an internal list, each VM is identified by a "name" which must
   correspond a valid libvirt Domain Name.
3) Add communication channels associated with a VM to the epoll based Monitor
   thread.
   The channels must exist and be in the form of:
   /tmp/powermonitor/.. Each channel is a
   Virtio-Serial endpoint configured as an AF_UNIX file socket and opened in
   non-blocking mode.
   Each VM can have a maximum of 64 channels associated with it.
4) Disable or re-enable VM communication channels, channels once added to the
   Monitor thread remain in that threads control, however acting on channel
   requests can be disabled and renabled via CLI.

The monitor is an epoll based infinite loop running in a separate thread that
waits on channel events from VMs and calls the corresponding functions. Channel
definitions from the manager are registered via the epoll event opaque pointer
when calling epoll_ctl(EPOLL_CTL_ADD), this allows for obtaining the channels
file descriptor for reading EPOLLIN events and mapping the vCPU to pCPU(s)
associated with a request from a particular VM.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/channel_manager.c | 645 
 examples/vm_power_manager/channel_manager.h | 273 
 examples/vm_power_manager/channel_monitor.c | 228 ++
 examples/vm_power_manager/channel_monitor.h | 102 +
 4 files changed, 1248 insertions(+)
 create mode 100644 examples/vm_power_manager/channel_manager.c
 create mode 100644 examples/vm_power_manager/channel_manager.h
 create mode 100644 examples/vm_power_manager/channel_monitor.c
 create mode 100644 examples/vm_power_manager/channel_monitor.h

diff --git a/examples/vm_power_manager/channel_manager.c 
b/examples/vm_power_manager/channel_manager.c
new file mode 100644
index 000..fdb0ea5
--- /dev/null
+++ b/examples/vm_power_manager/channel_manager.c
@@ -0,0 +1,645 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "channel_manager.h"
+#include "channel_commands.h"
+#include "channel_monitor.h"
+
+
+#define SOCKET_PATH "/tmp/powermonitor/"
+
+#define RTE_LOGTYPE_CHANNEL_MANAGER RTE_LOGTYPE_USER1
+
+#define ITERATIVE_BITMASK_CHECK_64(mask_u64b, i) \
+   for (i = 0; mask_u64b; mask_u64b &= ~(1ULL << i++)) \
+   if ((mask_u64b >> i) & 1) \
+
+/* Global pointer to libvirt connection */
+static virConnectPtr global_vir_conn_ptr;
+
+/*
+ * Represents a single Virtual Machine
+ */
+struct virtual_machine_info {
+   char name[MAX_NAME_L

[dpdk-dev] [PATCH v2 02/10] VM Power Management CLI(Host).

2014-09-24 Thread Alan Carew
The CLI is used for administrating the channel monitor and manager and
manually setting the CPU frequency on the host.

Supports the following commands:
 add_vm [Mul-choice STRING]: add_vm|rm_vm , add a VM for subsequent
  operations with the CLI or remove a previously added VM from the VM Power
  Manager

 rm_vm [Mul-choice STRING]: add_vm|rm_vm , add a VM for subsequent
  operations with the CLI or remove a previously added VM from the VM Power
  Manager

 add_channels [Fixed STRING]: add_channels  |all, add
  communication channels for the specified VM, the virtio channels must be
  enabled in the VM configuration(qemu/libvirt) and the associated VM must be
  active.  is a comma-separated list of channel numbers to add, using the
  keyword 'all' will attempt to add all channels for the VM

 set_channel_status [Fixed STRING]:
  set_channel_status  |all enabled|disabled,  enable or disable
  the communication channels in list(comma-seperated) for the specified VM,
  alternatively list can be replaced with keyword 'all'. Disabled channels will
  still receive packets on the host, however the commands they specify will be
  ignored. Set status to 'enabled' to begin processing requests again.

 show_vm [Fixed STRING]: show_vm , prints the information on the
  specified VM(s), the information lists the number of vCPUS, the pinning to
  pCPU(s) as a bit mask, along with any communication channels associated with
  each VM

 show_cpu_freq_mask [Fixed STRING]: show_cpu_freq_mask , Get the current
  frequency for each core specified in the mask

 set_cpu_freq_mask [Fixed STRING]: set_cpu_freq  ,
  Set the current frequency for the cores specified in  by scaling
  each up/down/min/max.

 show_cpu_freq [Fixed STRING]: Get the current frequency for the specified core

 set_cpu_freq [Fixed STRING]: set_cpu_freq  ,
  Set the current frequency for the specified core by scaling up/down/min/max

 quit [Fixed STRING]: close the application

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/vm_power_cli.c | 568 +++
 examples/vm_power_manager/vm_power_cli.h |  47 +++
 2 files changed, 615 insertions(+)
 create mode 100644 examples/vm_power_manager/vm_power_cli.c
 create mode 100644 examples/vm_power_manager/vm_power_cli.h

diff --git a/examples/vm_power_manager/vm_power_cli.c 
b/examples/vm_power_manager/vm_power_cli.c
new file mode 100644
index 000..33a4bcf
--- /dev/null
+++ b/examples/vm_power_manager/vm_power_cli.c
@@ -0,0 +1,568 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vm_power_cli.h"
+#include "channel_manager.h"
+#include "channel_monitor.h"
+#include "power_manager.h"
+#include "channel_commands.h"
+
+struct cmd_quit_result {
+   cmdline_fixed_string_t quit;
+};
+
+static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
+   struct cmdline *cl,
+   __attribute__((unused)) void *data)
+{
+   channel_monitor_exit();
+   channel_manager_exit();
+   power_manager_exit();
+   cmdline_quit(cl);
+}
+
+cmdline_pa

[dpdk-dev] [PATCH v2 03/10] CPU Frequency Power Management(Host).

2014-09-24 Thread Alan Carew
A wrapper around librte_power(using ACPI cpufreq), providing locking around the
non-threadsafe library, allowing for frequency changes based on core masks and
core numbers from both the CLI thread and epoll monitor thread.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/power_manager.c | 244 ++
 examples/vm_power_manager/power_manager.h | 186 +++
 2 files changed, 430 insertions(+)
 create mode 100644 examples/vm_power_manager/power_manager.c
 create mode 100644 examples/vm_power_manager/power_manager.h

diff --git a/examples/vm_power_manager/power_manager.c 
b/examples/vm_power_manager/power_manager.c
new file mode 100644
index 000..c736cd0
--- /dev/null
+++ b/examples/vm_power_manager/power_manager.c
@@ -0,0 +1,244 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "power_manager.h"
+
+#define RTE_LOGTYPE_POWER_MANAGER RTE_LOGTYPE_USER1
+
+#define POWER_SCALE_CORE(DIRECTION, core_num , ret) do { \
+   if (core_num > RTE_MAX_LCORE) \
+   return -1; \
+   if (!(global_enabled_cpus & (1ULL << core_num))) \
+   return -1; \
+   rte_spinlock_lock(&global_core_freq_info[core_num].power_sl); \
+   ret = rte_power_freq_##DIRECTION(core_num); \
+   rte_spinlock_unlock(&global_core_freq_info[core_num].power_sl); \
+} while (0)
+
+#define POWER_SCALE_MASK(DIRECTION, core_mask, ret) do { \
+   int i; \
+   for (i = 0; core_mask; core_mask &= ~(1 << i++)) { \
+   if ((core_mask >> i) & 1) { \
+   if (!(global_enabled_cpus & (1ULL << i))) \
+   continue; \
+   rte_spinlock_lock(&global_core_freq_info[i].power_sl); \
+   if (rte_power_freq_##DIRECTION(i) != 1) \
+   ret = -1; \
+   rte_spinlock_unlock(&global_core_freq_info[i].power_sl); \
+   } \
+   } \
+} while (0)
+
+struct freq_info {
+   rte_spinlock_t power_sl;
+   uint32_t freqs[RTE_MAX_LCORE_FREQS];
+   unsigned num_freqs;
+} __rte_cache_aligned;
+
+static struct freq_info global_core_freq_info[RTE_MAX_LCORE];
+
+static uint64_t global_enabled_cpus;
+
+#define SYSFS_CPU_PATH "/sys/devices/system/cpu/cpu%u/topology/core_id"
+
+static unsigned
+set_host_cpus_mask(void)
+{
+   char path[PATH_MAX];
+   unsigned i;
+   unsigned num_cpus = 0;
+   for (i = 0; i < RTE_MAX_LCORE; i++) {
+   snprintf(path, sizeof(path), SYSFS_CPU_PATH, i);
+   if (access(path, F_OK) == 0) {
+   global_enabled_cpus |= 1 << i;
+   num_cpus++;
+   } else
+   return num_cpus;
+   }
+   return num_cpus;
+}
+
+int
+power_manager_init(void)
+{
+   unsigned i, num_cpus;
+   uint64_t cpu_mask;
+   int ret = 0;
+
+   num_cpus = set_host_cpus_mask();
+   if (num_cpus == 0) {
+   RTE_LOG(ERR, POWER_MANAGER, "Unable to detected host CPUs, 
please "
+

[dpdk-dev] [PATCH v2 04/10] VM Power Management application and Makefile.

2014-09-24 Thread Alan Carew
For launching CLI thread and Monitor thread and initialising
resources.
Requires a minimum of two lcores to run, additional cores specified by eal core
mask are not used.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/Makefile |  57 +++
 examples/vm_power_manager/main.c   | 113 +
 examples/vm_power_manager/main.h   |  52 +
 3 files changed, 222 insertions(+)
 create mode 100644 examples/vm_power_manager/Makefile
 create mode 100644 examples/vm_power_manager/main.c
 create mode 100644 examples/vm_power_manager/main.h

diff --git a/examples/vm_power_manager/Makefile 
b/examples/vm_power_manager/Makefile
new file mode 100644
index 000..7d6f943
--- /dev/null
+++ b/examples/vm_power_manager/Makefile
@@ -0,0 +1,57 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriden by command line or environment
+RTE_TARGET ?= x86_64-default-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = vm_power_mgr
+
+# all source are stored in SRCS-y
+SRCS-y := main.c vm_power_cli.c power_manager.c channel_manager.c
+SRCS-y += channel_monitor.c
+
+CFLAGS += -O3 -lvirt -I$(RTE_SDK)/lib/librte_power/
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/vm_power_manager/main.c b/examples/vm_power_manager/main.c
new file mode 100644
index 000..fdb9e73
--- /dev/null
+++ b/examples/vm_power_manager/main.c
@@ -0,0 +1,113 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

[dpdk-dev] [PATCH v2 06/10] VM communication channels for VM Power Management(Guest).

2014-09-24 Thread Alan Carew
Allows for the opening of Virtio-Serial devices on a VM, where a DPDK
application can send packets to the host based monitor. The packet formatted is
specified in channel_commands.h
Each device appears as a serial device in path
/dev/virtio-ports/virtio.serial.port.. where each lcore
in a DPDK application has exclusive to a device/channel.
Each channel is opened in non-blocking mode, after a successful open a test
packet is send to the host to ensure the host side is monitoring.

Signed-off-by: Alan Carew 
---
 lib/librte_power/guest_channel.c | 162 +++
 lib/librte_power/guest_channel.h |  89 +
 2 files changed, 251 insertions(+)
 create mode 100644 lib/librte_power/guest_channel.c
 create mode 100644 lib/librte_power/guest_channel.h

diff --git a/lib/librte_power/guest_channel.c b/lib/librte_power/guest_channel.c
new file mode 100644
index 000..2295665
--- /dev/null
+++ b/lib/librte_power/guest_channel.c
@@ -0,0 +1,162 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#include 
+#include 
+
+#include "guest_channel.h"
+#include "channel_commands.h"
+
+#define RTE_LOGTYPE_GUEST_CHANNEL RTE_LOGTYPE_USER1
+
+static int global_fds[RTE_MAX_LCORE];
+
+int
+guest_channel_host_connect(const char *path, unsigned lcore_id)
+{
+   int flags, ret;
+   struct channel_packet pkt;
+   char fd_path[PATH_MAX];
+   int fd = -1;
+
+   if (lcore_id >= RTE_MAX_LCORE) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Channel(%u) is out of range 
0...%d\n",
+   lcore_id, RTE_MAX_LCORE-1);
+   return -1;
+   }
+   /* check if path is already open */
+   if (global_fds[lcore_id] != 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Channel(%u) is already open with 
fd %d\n",
+   lcore_id, global_fds[lcore_id]);
+   return -1;
+   }
+
+   snprintf(fd_path, PATH_MAX, "%s.%u", path, lcore_id);
+   RTE_LOG(INFO, GUEST_CHANNEL, "Opening channel '%s' for lcore %u\n",
+   fd_path, lcore_id);
+   fd = open(fd_path, O_RDWR);
+   if (fd < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Unable to to connect to '%s' with 
error "
+   "%s\n", fd_path, strerror(errno));
+   return -1;
+   }
+
+   flags = fcntl(fd, F_GETFL, 0);
+   if (flags < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Failed on fcntl get flags for file 
%s\n",
+   fd_path);
+   goto error;
+   }
+
+   flags |= O_NONBLOCK;
+   if (fcntl(fd, F_SETFL, flags) < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Failed on setting non-blocking 
mode for "
+   "file %s", fd_path);
+   goto error;
+   }
+   /* QEMU needs a delay after connection */
+   sleep(1);
+
+   /* Send a test packet, this command is ignored by the host, but a 
successful
+* send indicates that the host endpoint is monitoring.
+*

[dpdk-dev] [PATCH v2 05/10] VM Power Management CLI(Guest).

2014-09-24 Thread Alan Carew
Provides a small sample application(guest_vm_power_mgr) to run on a VM.
The application is run by providing a core mask(-c) and number of memory
channels(-n). The core mask corresponds to the number of lcore channels to
attempt to open. A maximum of 64 channels per VM is allowed. The channels must
be monitored by the host.
After successful initialisation a CPU frequency command can be sent to the host
using:
set_cpu_freq  .

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/guest_cli/Makefile   |  56 
 examples/vm_power_manager/guest_cli/main.c |  86 
 examples/vm_power_manager/guest_cli/main.h |  52 +++
 .../guest_cli/vm_power_cli_guest.c | 155 +
 .../guest_cli/vm_power_cli_guest.h |  55 
 5 files changed, 404 insertions(+)
 create mode 100644 examples/vm_power_manager/guest_cli/Makefile
 create mode 100644 examples/vm_power_manager/guest_cli/main.c
 create mode 100644 examples/vm_power_manager/guest_cli/main.h
 create mode 100644 examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
 create mode 100644 examples/vm_power_manager/guest_cli/vm_power_cli_guest.h

diff --git a/examples/vm_power_manager/guest_cli/Makefile 
b/examples/vm_power_manager/guest_cli/Makefile
new file mode 100644
index 000..167a7ed
--- /dev/null
+++ b/examples/vm_power_manager/guest_cli/Makefile
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriden by command line or environment
+RTE_TARGET ?= x86_64-default-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = guest_vm_power_mgr
+
+# all source are stored in SRCS-y
+SRCS-y := main.c vm_power_cli_guest.c
+
+CFLAGS += -O3 -I$(RTE_SDK)/lib/librte_power/
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/vm_power_manager/guest_cli/main.c 
b/examples/vm_power_manager/guest_cli/main.c
new file mode 100644
index 000..b8f86d0
--- /dev/null
+++ b/examples/vm_power_manager/guest_cli/main.c
@@ -0,0 +1,86 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "

[dpdk-dev] [PATCH v2 08/10] Packet format for VM Power Management(Host and Guest).

2014-09-24 Thread Alan Carew
Provides a command packet format for host and guest.

Signed-off-by: Alan Carew 
---
 lib/librte_power/channel_commands.h | 68 +
 1 file changed, 68 insertions(+)
 create mode 100644 lib/librte_power/channel_commands.h

diff --git a/lib/librte_power/channel_commands.h 
b/lib/librte_power/channel_commands.h
new file mode 100644
index 000..e33e85b
--- /dev/null
+++ b/lib/librte_power/channel_commands.h
@@ -0,0 +1,68 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CHANNEL_COMMANDS_H_
+#define CHANNEL_COMMANDS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+#include 
+
+#if RTE_MAX_LCORE > 64
+#error Maximum number of cores and channels is 64, overflow is guaranteed to \
+   cause problems with VM Power Management
+#endif
+
+#define CPU_POWER 1
+#define CPU_POWER_CONNECT 2
+
+#define CPU_SCALE_UP  1
+#define CPU_SCALE_DOWN2
+#define CPU_SCALE_MAX 3
+#define CPU_SCALE_MIN 4
+
+struct channel_packet {
+   uint64_t resource_id; /* core_num, device */
+   uint32_t unit; /* scale down/up/min/max */
+   uint32_t command; /* Power, IO, etc */
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CHANNEL_COMMANDS_H_ */
-- 
1.9.3



[dpdk-dev] [PATCH v2 09/10] Build system integration for VM Power Management(Guest and Host)

2014-09-24 Thread Alan Carew
librte_power now contains both rte_power_acpi_cpufreq and rte_power_kvm_vm
implementations.

Signed-off-by: Alan Carew 
---
 lib/librte_power/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/librte_power/Makefile b/lib/librte_power/Makefile
index 6185812..d672a5a 100644
--- a/lib/librte_power/Makefile
+++ b/lib/librte_power/Makefile
@@ -37,7 +37,8 @@ LIB = librte_power.a
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing

 # all source are stored in SRCS-y
-SRCS-$(CONFIG_RTE_LIBRTE_POWER) := rte_power.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) := rte_power.c rte_power_acpi_cpufreq.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) += rte_power_kvm_vm.c guest_channel.c

 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_POWER)-include := rte_power.h
-- 
1.9.3



[dpdk-dev] [PATCH v2 07/10] librte_power common interface for Guest and Host

2014-09-24 Thread Alan Carew
Moved the current librte_power implementation to rte_power_acpi_cpufreq, with
renaming of functions only.
Added rte_power_kvm_vm implmentation to support Power Management from a VM.

librte_power now hides the implementation based on the environment used.
A new call rte_power_set_env() can explicidly set the environment, if not
called then auto-detection takes place.

rte_power_kvm_vm is subset of the librte_power APIs, the following is supported:
 rte_power_init(unsigned lcore_id)
 rte_power_exit(unsigned lcore_id)
 rte_power_freq_up(unsigned lcore_id)
 rte_power_freq_down(unsigned lcore_id)
 rte_power_freq_min(unsigned lcore_id)
 rte_power_freq_max(unsigned lcore_id)

The other unsupported APIs return -ENOTSUP

Signed-off-by: Alan Carew 
---
 lib/librte_power/rte_power.c  | 540 -
 lib/librte_power/rte_power.h  | 120 +--
 lib/librte_power/rte_power_acpi_cpufreq.c | 545 ++
 lib/librte_power/rte_power_acpi_cpufreq.h | 192 +++
 lib/librte_power/rte_power_common.h   |  39 +++
 lib/librte_power/rte_power_kvm_vm.c   | 160 +
 lib/librte_power/rte_power_kvm_vm.h   | 179 ++
 7 files changed, 1273 insertions(+), 502 deletions(-)
 create mode 100644 lib/librte_power/rte_power_acpi_cpufreq.c
 create mode 100644 lib/librte_power/rte_power_acpi_cpufreq.h
 create mode 100644 lib/librte_power/rte_power_common.h
 create mode 100644 lib/librte_power/rte_power_kvm_vm.c
 create mode 100644 lib/librte_power/rte_power_kvm_vm.h

diff --git a/lib/librte_power/rte_power.c b/lib/librte_power/rte_power.c
index 856da9a..998ed1c 100644
--- a/lib/librte_power/rte_power.c
+++ b/lib/librte_power/rte_power.c
@@ -31,515 +31,113 @@
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */

-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
 #include 

 #include "rte_power.h"
+#include "rte_power_acpi_cpufreq.h"
+#include "rte_power_kvm_vm.h"
+#include "rte_power_common.h"

-#ifdef RTE_LIBRTE_POWER_DEBUG
-#define POWER_DEBUG_TRACE(fmt, args...) do { \
-   RTE_LOG(ERR, POWER, "%s: " fmt, __func__, ## args); \
-   } while (0)
-#else
-#define POWER_DEBUG_TRACE(fmt, args...)
-#endif
-
-#define FOPEN_OR_ERR_RET(f, retval) do { \
-   if ((f) == NULL) { \
-   RTE_LOG(ERR, POWER, "File not openned\n"); \
-   return (retval); \
-   } \
-} while(0)
-
-#define FOPS_OR_NULL_GOTO(ret, label) do { \
-   if ((ret) == NULL) { \
-   RTE_LOG(ERR, POWER, "fgets returns nothing\n"); \
-   goto label; \
-   } \
-} while(0)
-
-#define FOPS_OR_ERR_GOTO(ret, label) do { \
-   if ((ret) < 0) { \
-   RTE_LOG(ERR, POWER, "File operations failed\n"); \
-   goto label; \
-   } \
-} while(0)
-
-#define STR_SIZE 1024
-#define POWER_CONVERT_TO_DECIMAL 10
+enum power_management_env global_default_env = PM_ENV_NOT_SET;

-#define POWER_GOVERNOR_USERSPACE "userspace"
-#define POWER_SYSFILE_GOVERNOR   \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_governor"
-#define POWER_SYSFILE_AVAIL_FREQ \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_frequencies"
-#define POWER_SYSFILE_SETSPEED   \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_setspeed"
+volatile uint32_t global_env_cfg_status = 0;

-enum power_state {
-   POWER_IDLE = 0,
-   POWER_ONGOING,
-   POWER_USED,
-   POWER_UNKNOWN
-};
+/* function pointers */
+rte_power_freqs_t rte_power_freqs  = NULL;
+rte_power_get_freq_t rte_power_get_freq = NULL;
+rte_power_set_freq_t rte_power_set_freq = NULL;
+rte_power_freq_change_t rte_power_freq_up = NULL;
+rte_power_freq_change_t rte_power_freq_down = NULL;
+rte_power_freq_change_t rte_power_freq_max = NULL;
+rte_power_freq_change_t rte_power_freq_min = NULL;

-/**
- * Power info per lcore.
- */
-struct rte_power_info {
-   unsigned lcore_id;   /**< Logical core id */
-   uint32_t freqs[RTE_MAX_LCORE_FREQS]; /**< Frequency array */
-   uint32_t nb_freqs;   /**< number of available freqs */
-   FILE *f; /**< FD of scaling_setspeed */
-   char governor_ori[32];   /**< Original governor name */
-   uint32_t curr_idx;   /**< Freq index in freqs array */
-   volatile uint32_t state; /**< Power in use state */
-} __rte_cache_aligned;
-
-static struct rte_power_info lcore_power_info[RTE_MAX_LCORE];
-
-/**
- * It is to set specific freq for specific logical core, according to the index
- * of supported frequencies.
- */
-static int
-set_freq_internal(struct rte_power_info *pi, uint32_t idx)
+int
+rte_power_set_env(enum power_management_env

[dpdk-dev] [PATCH v2 10/10] VM Power Management Unit Tests

2014-09-24 Thread Alan Carew
Updated the unit tests to cover both librte_power implementations as well as
the external API.

Signed-off-by: Alan Carew 
---
 app/test/Makefile  |   3 +-
 app/test/autotest_data.py  |  26 ++
 app/test/test_power.c  | 445 +++---
 app/test/test_power_acpi_cpufreq.c | 544 +
 app/test/test_power_kvm_vm.c   | 308 +
 5 files changed, 917 insertions(+), 409 deletions(-)
 create mode 100644 app/test/test_power_acpi_cpufreq.c
 create mode 100644 app/test/test_power_kvm_vm.c

diff --git a/app/test/Makefile b/app/test/Makefile
index 37a3772..03ade39 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -119,7 +119,8 @@ endif

 SRCS-$(CONFIG_RTE_LIBRTE_METER) += test_meter.c
 SRCS-$(CONFIG_RTE_LIBRTE_KNI) += test_kni.c
-SRCS-$(CONFIG_RTE_LIBRTE_POWER) += test_power.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) += test_power.c test_power_acpi_cpufreq.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) += test_power_kvm_vm.c
 SRCS-y += test_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_IVSHMEM) += test_ivshmem.c

diff --git a/app/test/autotest_data.py b/app/test/autotest_data.py
index 878c72e..618a946 100644
--- a/app/test/autotest_data.py
+++ b/app/test/autotest_data.py
@@ -425,6 +425,32 @@ non_parallel_test_group_list = [
]
 },
 {
+   "Prefix" :  "power_acpi_cpufreq",
+   "Memory" :  all_sockets(512),
+   "Tests" :
+   [
+   {
+"Name" :   "Power ACPI cpufreq autotest",
+"Command" :"power_acpi_cpufreq_autotest",
+"Func" :   default_autotest,
+"Report" : None,
+   },
+   ]
+},
+{
+   "Prefix" :  "power_kvm_vm",
+   "Memory" :  "512",
+   "Tests" :
+   [
+   {
+"Name" :   "Power KVM VM  autotest",
+"Command" :"power_kvm_vm_autotest",
+"Func" :   default_autotest,
+"Report" : None,
+   },
+   ]
+},
+{
"Prefix" :  "lpm6",
"Memory" :  "512",
"Tests" :
diff --git a/app/test/test_power.c b/app/test/test_power.c
index d9eb420..64a2305 100644
--- a/app/test/test_power.c
+++ b/app/test/test_power.c
@@ -41,437 +41,66 @@

 #include 

-#define TEST_POWER_LCORE_ID  2U
-#define TEST_POWER_LCORE_INVALID ((unsigned)RTE_MAX_LCORE)
-#define TEST_POWER_FREQS_NUM_MAX ((unsigned)RTE_MAX_LCORE_FREQS)
-
-#define TEST_POWER_SYSFILE_CUR_FREQ \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq"
-
-static uint32_t total_freq_num;
-static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX];
-
-static int
-check_cur_freq(unsigned lcore_id, uint32_t idx)
-{
-#define TEST_POWER_CONVERT_TO_DECIMAL 10
-   FILE *f;
-   char fullpath[PATH_MAX];
-   char buf[BUFSIZ];
-   uint32_t cur_freq;
-   int ret = -1;
-
-   if (snprintf(fullpath, sizeof(fullpath),
-   TEST_POWER_SYSFILE_CUR_FREQ, lcore_id) < 0) {
-   return 0;
-   }
-   f = fopen(fullpath, "r");
-   if (f == NULL) {
-   return 0;
-   }
-   if (fgets(buf, sizeof(buf), f) == NULL) {
-   goto fail_get_cur_freq;
-   }
-   cur_freq = strtoul(buf, NULL, TEST_POWER_CONVERT_TO_DECIMAL);
-   ret = (freqs[idx] == cur_freq ? 0 : -1);
-
-fail_get_cur_freq:
-   fclose(f);
-
-   return ret;
-}
-
-/* Check rte_power_freqs() */
-static int
-check_power_freqs(void)
-{
-   uint32_t ret;
-
-   total_freq_num = 0;
-   memset(freqs, 0, sizeof(freqs));
-
-   /* test with an invalid lcore id */
-   ret = rte_power_freqs(TEST_POWER_LCORE_INVALID, freqs,
-   TEST_POWER_FREQS_NUM_MAX);
-   if (ret > 0) {
-   printf("Unexpectedly get available freqs successfully on "
-   "lcore %u\n", TEST_POWER_LCORE_INVALID);
-   return -1;
-   }
-
-   /* test with NULL buffer to save available freqs */
-   ret = rte_power_freqs(TEST_POWER_LCORE_ID, NULL,
-   TEST_POWER_FREQS_NUM_MAX);
-   if (ret > 0) {
-   printf("Unexpectedly get available freqs successfully with "
-   "NULL buffer on lcore %u\n", TEST_POWER_LCORE_ID);
-   return -1;
-   }
-
-   /* test of getting zero number of freqs */
-   ret = rte_power_freqs(TEST_POWER_LCORE_ID, freqs, 0);
-   if (ret > 0) {
-   printf("Unexpectedly get available freqs successfully with "
-   "zero buffer size o

[dpdk-dev] [PATCH v3 00/10] VM Power Management

2014-09-29 Thread Alan Carew
Virtual Machine Power Management.

The following patches add two DPDK sample applications and an alternate
implementation of librte_power for use in virtualized environments.
The idea is to provide librte_power functionality from within a VM to address
the lack of MSRs to facilitate frequency changes from within a VM.
It is ideally suited for Haswell which provides per core frequency scaling.

The current librte_power affects frequency changes via the acpi-cpufreq
'userspace' power governor, accessed via sysfs.

General Overview:(more information in each patch that follows).
The VM Power Management solution provides two components:

 1)VM: Allows for the a DPDK application in a VM to reuse the librte_power
 interface. Each lcore opens a Virto-Serial endpoint channel to the host,
 where the re-implementation of librte_power simply forwards the requests for
 frequency change to a host based monitor. The host monitor itself uses
 librte_power.
 Each lcore channel corresponds to a
 serial device '/dev/virtio-ports/virtio.serial.port.poweragent.'
 which is opened in non-blocking mode.
 While each Virtual CPU can be mapped to multiple physical CPUs it is
 recommended that each vCPU should be mapped to a single core only.

 2)Host: The host monitor is managed by a CLI, it allows for adding qemu/KVM
 virtual machines and associated channels to the monitor, manually changing
 CPU frequency, inspecting the state of VMs, vCPU to pCPU pinning and managing
 channels.
 Host channel endpoints are Virto-Serial endpoints configured as AF_UNIX file
 sockets which follow a specific naming convention
 i.e /tmp/powermonitor/.,
 each channel has an 1:1 mapping to a VM endpoint
 i.e. /dev/virtio-ports/virtio.serial.port.poweragent.
 Host channel endpoints are opened in non-blocking mode and are monitored via 
epoll.
 Requests over each channel to change frequency are forwarded to the original
 librte_power.

Channels must be manually configured as qemu-kvm command line arguments or
libvirt domain definition(xml) e.g.

 


  
  


Where multiple channels can be configured by specifying multiple 
elements, by replacing , .
(port number) should be incremented by 1 for each new channel element.
More information on Virtio-Serial can be found here:
http://fedoraproject.org/wiki/Features/VirtioSerial
To enable the Hypervisor creation of channels, the host endpoint directory
must be created with qemu permissions:
mkdir /tmp/powermonitor
chown qemu:qemu /tmp/powermonitor

The host application runs on two separate lcores:
Core N) CLI: For management of Virtual Machines adding channels to Monitor 
thread,
 inspecting state and manually setting CPU frequency [PATCH 02/09]
Core N+1) Monitor Thread: An epoll based infinite loop that waits on channel 
events
 from VMs and calls the corresponding librte_power functions.

A sample application is also provided to run on Virtual Machines, this
application provides a CLI to manually set the frequency of a 
vCPU[PATCH 08/09]

The current l3fwd-power sample application can also be run on a VM.

Changes in V3:
 Fixed crash in Guest CLI when host application is not running.
 Renamed #defines to be more specific to the module they belong
 Added vCPU pinning via CLI
 Testing feedback

Changes in V2:
 Runtime selection of librte_power implementations.
 Updated Unit tests to cover librte_power changes.
 PATCH[0/3] was sent twice, again as PATCH[0/4]
 Miscellaneous fixes.

Alan Carew (10):
  Channel Manager and Monitor for VM Power Management(Host).
  VM Power Management CLI(Host).
  CPU Frequency Power Management(Host).
  VM Power Management application and Makefile.
  VM Power Management CLI(Guest).
  VM communication channels for VM Power Management(Guest).
  librte_power common interface for Guest and Host
  Packet format for VM Power Management(Host and Guest).
  Build system integration for VM Power Management(Guest and Host)
  VM Power Management Unit Tests

 app/test/Makefile  |   3 +-
 app/test/autotest_data.py  |  26 +
 app/test/test_power.c  | 445 +---
 app/test/test_power_acpi_cpufreq.c | 544 ++
 app/test/test_power_kvm_vm.c   | 308 
 examples/vm_power_manager/Makefile |  57 ++
 examples/vm_power_manager/channel_manager.c| 804 +
 examples/vm_power_manager/channel_manager.h| 314 
 examples/vm_power_manager/channel_monitor.c| 228 ++
 examples/vm_power_manager/channel_monitor.h| 102 +++
 examples/vm_power_manager/guest_cli/Makefile   |  56 ++
 examples/vm_power_manager/guest_cli/main.c |  87 +++
 examples/vm_power_manager/guest_cli/main.h |  52 ++
 .../guest_cli/vm_power_cli_guest.c | 155 
 .../guest_cli/vm_power_cli_guest.h |  55 ++
 examples/vm_power_manager/main.c  

[dpdk-dev] [PATCH v3 01/10] Channel Manager and Monitor for VM Power Management(Host).

2014-09-29 Thread Alan Carew
The manager is responsible for adding communications channels to the Monitor
thread, tracking and reporting VM state and employs the libvirt API for
synchronization with the KVM Hypervisor. The manager interacts with the
Hypervisor to discover the mapping of virtual CPUS(vCPUs) to the host
physical CPUS(pCPUs) and to inspect the VM running state.

The manager provides the following functionality to the CLI:
1) Connect to a libvirtd instance, default: qemu:///system
2) Add a VM to an internal list, each VM is identified by a "name" which must
   correspond a valid libvirt Domain Name.
3) Add communication channels associated with a VM to the epoll based Monitor
   thread.
   The channels must exist and be in the form of:
   /tmp/powermonitor/.. Each channel is a
   Virtio-Serial endpoint configured as an AF_UNIX file socket and opened in
   non-blocking mode.
   Each VM can have a maximum of 64 channels associated with it.
4) Disable or re-enable VM communication channels, channels once added to the
   Monitor thread remain in that threads control, however acting on channel
   requests can be disabled and renabled via CLI.

The monitor is an epoll based infinite loop running in a separate thread that
waits on channel events from VMs and calls the corresponding functions. Channel
definitions from the manager are registered via the epoll event opaque pointer
when calling epoll_ctl(EPOLL_CTL_ADD), this allows for obtaining the channels
file descriptor for reading EPOLLIN events and mapping the vCPU to pCPU(s)
associated with a request from a particular VM.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/channel_manager.c | 804 
 examples/vm_power_manager/channel_manager.h | 314 +++
 examples/vm_power_manager/channel_monitor.c | 228 
 examples/vm_power_manager/channel_monitor.h | 102 
 4 files changed, 1448 insertions(+)
 create mode 100644 examples/vm_power_manager/channel_manager.c
 create mode 100644 examples/vm_power_manager/channel_manager.h
 create mode 100644 examples/vm_power_manager/channel_monitor.c
 create mode 100644 examples/vm_power_manager/channel_monitor.h

diff --git a/examples/vm_power_manager/channel_manager.c 
b/examples/vm_power_manager/channel_manager.c
new file mode 100644
index 000..a14f191
--- /dev/null
+++ b/examples/vm_power_manager/channel_manager.c
@@ -0,0 +1,804 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "channel_manager.h"
+#include "channel_commands.h"
+#include "channel_monitor.h"
+
+
+#define RTE_LOGTYPE_CHANNEL_MANAGER RTE_LOGTYPE_USER1
+
+#define ITERATIVE_BITMASK_CHECK_64(mask_u64b, i) \
+   for (i = 0; mask_u64b; mask_u64b &= ~(1ULL << i++)) \
+   if ((mask_u64b >> i) & 1) \
+
+/* Global pointer to libvirt connection */
+static virConnectPtr global_vir_conn_ptr;
+
+static unsigned char *global_cpumaps;
+static virVcpuInfo *global_vircpuinfo;
+static size_t global_maplen;
+
+static unsigned global_n_host_cpus;
+
+/*
+ *

[dpdk-dev] [PATCH v3 02/10] VM Power Management CLI(Host).

2014-09-29 Thread Alan Carew
The CLI is used for administrating the channel monitor and manager and
manually setting the CPU frequency on the host.

Supports the following commands:
 add_vm [Mul-choice STRING]: add_vm|rm_vm , add a VM for subsequent
  operations with the CLI or remove a previously added VM from the VM Power
  Manager

 rm_vm [Mul-choice STRING]: add_vm|rm_vm , add a VM for subsequent
  operations with the CLI or remove a previously added VM from the VM Power
  Manager

 add_channels [Fixed STRING]: add_channels  |all, add
  communication channels for the specified VM, the virtio channels must be
  enabled in the VM configuration(qemu/libvirt) and the associated VM must be
  active.  is a comma-separated list of channel numbers to add, using the
  keyword 'all' will attempt to add all channels for the VM

 set_channel_status [Fixed STRING]:
  set_channel_status  |all enabled|disabled,  enable or disable
  the communication channels in list(comma-seperated) for the specified VM,
  alternatively list can be replaced with keyword 'all'. Disabled channels will
  still receive packets on the host, however the commands they specify will be
  ignored. Set status to 'enabled' to begin processing requests again.

 show_vm [Fixed STRING]: show_vm , prints the information on the
  specified VM(s), the information lists the number of vCPUS, the pinning to
  pCPU(s) as a bit mask, along with any communication channels associated with
  each VM

 show_cpu_freq_mask [Fixed STRING]: show_cpu_freq_mask , Get the current
  frequency for each core specified in the mask

 set_cpu_freq_mask [Fixed STRING]: set_cpu_freq  ,
  Set the current frequency for the cores specified in  by scaling
  each up/down/min/max.

 show_cpu_freq [Fixed STRING]: Get the current frequency for the specified core

 set_cpu_freq [Fixed STRING]: set_cpu_freq  ,
  Set the current frequency for the specified core by scaling up/down/min/max

 quit [Fixed STRING]: close the application

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/vm_power_cli.c | 669 +++
 examples/vm_power_manager/vm_power_cli.h |  47 +++
 2 files changed, 716 insertions(+)
 create mode 100644 examples/vm_power_manager/vm_power_cli.c
 create mode 100644 examples/vm_power_manager/vm_power_cli.h

diff --git a/examples/vm_power_manager/vm_power_cli.c 
b/examples/vm_power_manager/vm_power_cli.c
new file mode 100644
index 000..a8cfb3a
--- /dev/null
+++ b/examples/vm_power_manager/vm_power_cli.c
@@ -0,0 +1,669 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vm_power_cli.h"
+#include "channel_manager.h"
+#include "channel_monitor.h"
+#include "power_manager.h"
+#include "channel_commands.h"
+
+struct cmd_quit_result {
+   cmdline_fixed_string_t quit;
+};
+
+static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
+   struct cmdline *cl,
+   __attribute__((unused)) void *data)
+{
+   channel_monitor_exit();
+   channel_manager_exit();
+   power_manager_exit();
+   cmdline_quit(cl);
+}
+
+cmdline_pa

[dpdk-dev] [PATCH v3 03/10] CPU Frequency Power Management(Host).

2014-09-29 Thread Alan Carew
A wrapper around librte_power(using ACPI cpufreq), providing locking around the
non-threadsafe library, allowing for frequency changes based on core masks and
core numbers from both the CLI thread and epoll monitor thread.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/power_manager.c | 244 ++
 examples/vm_power_manager/power_manager.h | 188 +++
 2 files changed, 432 insertions(+)
 create mode 100644 examples/vm_power_manager/power_manager.c
 create mode 100644 examples/vm_power_manager/power_manager.h

diff --git a/examples/vm_power_manager/power_manager.c 
b/examples/vm_power_manager/power_manager.c
new file mode 100644
index 000..b7b1fca
--- /dev/null
+++ b/examples/vm_power_manager/power_manager.c
@@ -0,0 +1,244 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "power_manager.h"
+
+#define RTE_LOGTYPE_POWER_MANAGER RTE_LOGTYPE_USER1
+
+#define POWER_SCALE_CORE(DIRECTION, core_num , ret) do { \
+   if (core_num >= POWER_MGR_MAX_CPUS) \
+   return -1; \
+   if (!(global_enabled_cpus & (1ULL << core_num))) \
+   return -1; \
+   rte_spinlock_lock(&global_core_freq_info[core_num].power_sl); \
+   ret = rte_power_freq_##DIRECTION(core_num); \
+   rte_spinlock_unlock(&global_core_freq_info[core_num].power_sl); \
+} while (0)
+
+#define POWER_SCALE_MASK(DIRECTION, core_mask, ret) do { \
+   int i; \
+   for (i = 0; core_mask; core_mask &= ~(1 << i++)) { \
+   if ((core_mask >> i) & 1) { \
+   if (!(global_enabled_cpus & (1ULL << i))) \
+   continue; \
+   rte_spinlock_lock(&global_core_freq_info[i].power_sl); \
+   if (rte_power_freq_##DIRECTION(i) != 1) \
+   ret = -1; \
+   rte_spinlock_unlock(&global_core_freq_info[i].power_sl); \
+   } \
+   } \
+} while (0)
+
+struct freq_info {
+   rte_spinlock_t power_sl;
+   uint32_t freqs[RTE_MAX_LCORE_FREQS];
+   unsigned num_freqs;
+} __rte_cache_aligned;
+
+static struct freq_info global_core_freq_info[POWER_MGR_MAX_CPUS];
+
+static uint64_t global_enabled_cpus;
+
+#define SYSFS_CPU_PATH "/sys/devices/system/cpu/cpu%u/topology/core_id"
+
+static unsigned
+set_host_cpus_mask(void)
+{
+   char path[PATH_MAX];
+   unsigned i;
+   unsigned num_cpus = 0;
+   for (i = 0; i < POWER_MGR_MAX_CPUS; i++) {
+   snprintf(path, sizeof(path), SYSFS_CPU_PATH, i);
+   if (access(path, F_OK) == 0) {
+   global_enabled_cpus |= 1ULL << i;
+   num_cpus++;
+   } else
+   return num_cpus;
+   }
+   return num_cpus;
+}
+
+int
+power_manager_init(void)
+{
+   unsigned i, num_cpus;
+   uint64_t cpu_mask;
+   int ret = 0;
+
+   num_cpus = set_host_cpus_mask();
+   if (num_cpus == 0) {
+   RTE_LOG(ERR, POWER_MANAGER, "Unable to detected host CPUs, 
please "
+

[dpdk-dev] [PATCH v3 04/10] VM Power Management application and Makefile.

2014-09-29 Thread Alan Carew
For launching CLI thread and Monitor thread and initialising
resources.
Requires a minimum of two lcores to run, additional cores specified by eal core
mask are not used.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/Makefile |  57 +++
 examples/vm_power_manager/main.c   | 113 +
 examples/vm_power_manager/main.h   |  52 +
 3 files changed, 222 insertions(+)
 create mode 100644 examples/vm_power_manager/Makefile
 create mode 100644 examples/vm_power_manager/main.c
 create mode 100644 examples/vm_power_manager/main.h

diff --git a/examples/vm_power_manager/Makefile 
b/examples/vm_power_manager/Makefile
new file mode 100644
index 000..7d6f943
--- /dev/null
+++ b/examples/vm_power_manager/Makefile
@@ -0,0 +1,57 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriden by command line or environment
+RTE_TARGET ?= x86_64-default-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = vm_power_mgr
+
+# all source are stored in SRCS-y
+SRCS-y := main.c vm_power_cli.c power_manager.c channel_manager.c
+SRCS-y += channel_monitor.c
+
+CFLAGS += -O3 -lvirt -I$(RTE_SDK)/lib/librte_power/
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/vm_power_manager/main.c b/examples/vm_power_manager/main.c
new file mode 100644
index 000..e819e6f
--- /dev/null
+++ b/examples/vm_power_manager/main.c
@@ -0,0 +1,113 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

[dpdk-dev] [PATCH v3 06/10] VM communication channels for VM Power Management(Guest).

2014-09-29 Thread Alan Carew
Allows for the opening of Virtio-Serial devices on a VM, where a DPDK
application can send packets to the host based monitor. The packet formatted is
specified in channel_commands.h
Each device appears as a serial device in path
/dev/virtio-ports/virtio.serial.port.. where each lcore
in a DPDK application has exclusive to a device/channel.
Each channel is opened in non-blocking mode, after a successful open a test
packet is send to the host to ensure the host side is monitoring.

Signed-off-by: Alan Carew 
---
 lib/librte_power/guest_channel.c | 162 +++
 lib/librte_power/guest_channel.h |  89 +
 2 files changed, 251 insertions(+)
 create mode 100644 lib/librte_power/guest_channel.c
 create mode 100644 lib/librte_power/guest_channel.h

diff --git a/lib/librte_power/guest_channel.c b/lib/librte_power/guest_channel.c
new file mode 100644
index 000..2295665
--- /dev/null
+++ b/lib/librte_power/guest_channel.c
@@ -0,0 +1,162 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#include 
+#include 
+
+#include "guest_channel.h"
+#include "channel_commands.h"
+
+#define RTE_LOGTYPE_GUEST_CHANNEL RTE_LOGTYPE_USER1
+
+static int global_fds[RTE_MAX_LCORE];
+
+int
+guest_channel_host_connect(const char *path, unsigned lcore_id)
+{
+   int flags, ret;
+   struct channel_packet pkt;
+   char fd_path[PATH_MAX];
+   int fd = -1;
+
+   if (lcore_id >= RTE_MAX_LCORE) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Channel(%u) is out of range 
0...%d\n",
+   lcore_id, RTE_MAX_LCORE-1);
+   return -1;
+   }
+   /* check if path is already open */
+   if (global_fds[lcore_id] != 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Channel(%u) is already open with 
fd %d\n",
+   lcore_id, global_fds[lcore_id]);
+   return -1;
+   }
+
+   snprintf(fd_path, PATH_MAX, "%s.%u", path, lcore_id);
+   RTE_LOG(INFO, GUEST_CHANNEL, "Opening channel '%s' for lcore %u\n",
+   fd_path, lcore_id);
+   fd = open(fd_path, O_RDWR);
+   if (fd < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Unable to to connect to '%s' with 
error "
+   "%s\n", fd_path, strerror(errno));
+   return -1;
+   }
+
+   flags = fcntl(fd, F_GETFL, 0);
+   if (flags < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Failed on fcntl get flags for file 
%s\n",
+   fd_path);
+   goto error;
+   }
+
+   flags |= O_NONBLOCK;
+   if (fcntl(fd, F_SETFL, flags) < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Failed on setting non-blocking 
mode for "
+   "file %s", fd_path);
+   goto error;
+   }
+   /* QEMU needs a delay after connection */
+   sleep(1);
+
+   /* Send a test packet, this command is ignored by the host, but a 
successful
+* send indicates that the host endpoint is monitoring.
+*

[dpdk-dev] [PATCH v3 05/10] VM Power Management CLI(Guest).

2014-09-29 Thread Alan Carew
Provides a small sample application(guest_vm_power_mgr) to run on a VM.
The application is run by providing a core mask(-c) and number of memory
channels(-n). The core mask corresponds to the number of lcore channels to
attempt to open. A maximum of 64 channels per VM is allowed. The channels must
be monitored by the host.
After successful initialisation a CPU frequency command can be sent to the host
using:
set_cpu_freq  .

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/guest_cli/Makefile   |  56 
 examples/vm_power_manager/guest_cli/main.c |  87 
 examples/vm_power_manager/guest_cli/main.h |  52 +++
 .../guest_cli/vm_power_cli_guest.c | 155 +
 .../guest_cli/vm_power_cli_guest.h |  55 
 5 files changed, 405 insertions(+)
 create mode 100644 examples/vm_power_manager/guest_cli/Makefile
 create mode 100644 examples/vm_power_manager/guest_cli/main.c
 create mode 100644 examples/vm_power_manager/guest_cli/main.h
 create mode 100644 examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
 create mode 100644 examples/vm_power_manager/guest_cli/vm_power_cli_guest.h

diff --git a/examples/vm_power_manager/guest_cli/Makefile 
b/examples/vm_power_manager/guest_cli/Makefile
new file mode 100644
index 000..167a7ed
--- /dev/null
+++ b/examples/vm_power_manager/guest_cli/Makefile
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriden by command line or environment
+RTE_TARGET ?= x86_64-default-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = guest_vm_power_mgr
+
+# all source are stored in SRCS-y
+SRCS-y := main.c vm_power_cli_guest.c
+
+CFLAGS += -O3 -I$(RTE_SDK)/lib/librte_power/
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/vm_power_manager/guest_cli/main.c 
b/examples/vm_power_manager/guest_cli/main.c
new file mode 100644
index 000..1e4767a
--- /dev/null
+++ b/examples/vm_power_manager/guest_cli/main.c
@@ -0,0 +1,87 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "

[dpdk-dev] [PATCH v3 08/10] Packet format for VM Power Management(Host and Guest).

2014-09-29 Thread Alan Carew
Provides a command packet format for host and guest.

Signed-off-by: Alan Carew 
---
 lib/librte_power/channel_commands.h | 77 +
 1 file changed, 77 insertions(+)
 create mode 100644 lib/librte_power/channel_commands.h

diff --git a/lib/librte_power/channel_commands.h 
b/lib/librte_power/channel_commands.h
new file mode 100644
index 000..7e78a8b
--- /dev/null
+++ b/lib/librte_power/channel_commands.h
@@ -0,0 +1,77 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CHANNEL_COMMANDS_H_
+#define CHANNEL_COMMANDS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+
+/* Maximum number of CPUs */
+#define CHANNEL_CMDS_MAX_CPUS64
+#if CHANNEL_CMDS_MAX_CPUS > 64
+#error Maximum number of cores is 64, overflow is guaranteed to \
+   cause problems with VM Power Management
+#endif
+
+/* Maximum number of channels per VM */
+#define CHANNEL_CMDS_MAX_VM_CHANNELS 64
+
+/* Maximum number of channels per VM */
+#define CHANNEL_CMDS_MAX_VM_CHANNELS 64
+
+/* Valid Commands */
+#define CPU_POWER   1
+#define CPU_POWER_CONNECT   2
+
+/* CPU Power Command Scaling */
+#define CPU_POWER_SCALE_UP  1
+#define CPU_POWER_SCALE_DOWN2
+#define CPU_POWER_SCALE_MAX 3
+#define CPU_POWER_SCALE_MIN 4
+
+struct channel_packet {
+   uint64_t resource_id; /**< core_num, device */
+   uint32_t unit;/**< scale down/up/min/max */
+   uint32_t command; /**< Power, IO, etc */
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CHANNEL_COMMANDS_H_ */
-- 
1.9.3



[dpdk-dev] [PATCH v3 09/10] Build system integration for VM Power Management(Guest and Host)

2014-09-29 Thread Alan Carew
librte_power now contains both rte_power_acpi_cpufreq and rte_power_kvm_vm
implementations.

Signed-off-by: Alan Carew 
---
 lib/librte_power/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/librte_power/Makefile b/lib/librte_power/Makefile
index 6185812..d672a5a 100644
--- a/lib/librte_power/Makefile
+++ b/lib/librte_power/Makefile
@@ -37,7 +37,8 @@ LIB = librte_power.a
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing

 # all source are stored in SRCS-y
-SRCS-$(CONFIG_RTE_LIBRTE_POWER) := rte_power.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) := rte_power.c rte_power_acpi_cpufreq.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) += rte_power_kvm_vm.c guest_channel.c

 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_POWER)-include := rte_power.h
-- 
1.9.3



[dpdk-dev] [PATCH v3 07/10] librte_power common interface for Guest and Host

2014-09-29 Thread Alan Carew
Moved the current librte_power implementation to rte_power_acpi_cpufreq, with
renaming of functions only.
Added rte_power_kvm_vm implmentation to support Power Management from a VM.

librte_power now hides the implementation based on the environment used.
A new call rte_power_set_env() can explicidly set the environment, if not
called then auto-detection takes place.

rte_power_kvm_vm is subset of the librte_power APIs, the following is supported:
 rte_power_init(unsigned lcore_id)
 rte_power_exit(unsigned lcore_id)
 rte_power_freq_up(unsigned lcore_id)
 rte_power_freq_down(unsigned lcore_id)
 rte_power_freq_min(unsigned lcore_id)
 rte_power_freq_max(unsigned lcore_id)

The other unsupported APIs return -ENOTSUP

Signed-off-by: Alan Carew 
---
 lib/librte_power/rte_power.c  | 540 -
 lib/librte_power/rte_power.h  | 120 +--
 lib/librte_power/rte_power_acpi_cpufreq.c | 545 ++
 lib/librte_power/rte_power_acpi_cpufreq.h | 192 +++
 lib/librte_power/rte_power_common.h   |  39 +++
 lib/librte_power/rte_power_kvm_vm.c   | 135 
 lib/librte_power/rte_power_kvm_vm.h   | 179 ++
 7 files changed, 1248 insertions(+), 502 deletions(-)
 create mode 100644 lib/librte_power/rte_power_acpi_cpufreq.c
 create mode 100644 lib/librte_power/rte_power_acpi_cpufreq.h
 create mode 100644 lib/librte_power/rte_power_common.h
 create mode 100644 lib/librte_power/rte_power_kvm_vm.c
 create mode 100644 lib/librte_power/rte_power_kvm_vm.h

diff --git a/lib/librte_power/rte_power.c b/lib/librte_power/rte_power.c
index 856da9a..998ed1c 100644
--- a/lib/librte_power/rte_power.c
+++ b/lib/librte_power/rte_power.c
@@ -31,515 +31,113 @@
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */

-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
 #include 

 #include "rte_power.h"
+#include "rte_power_acpi_cpufreq.h"
+#include "rte_power_kvm_vm.h"
+#include "rte_power_common.h"

-#ifdef RTE_LIBRTE_POWER_DEBUG
-#define POWER_DEBUG_TRACE(fmt, args...) do { \
-   RTE_LOG(ERR, POWER, "%s: " fmt, __func__, ## args); \
-   } while (0)
-#else
-#define POWER_DEBUG_TRACE(fmt, args...)
-#endif
-
-#define FOPEN_OR_ERR_RET(f, retval) do { \
-   if ((f) == NULL) { \
-   RTE_LOG(ERR, POWER, "File not openned\n"); \
-   return (retval); \
-   } \
-} while(0)
-
-#define FOPS_OR_NULL_GOTO(ret, label) do { \
-   if ((ret) == NULL) { \
-   RTE_LOG(ERR, POWER, "fgets returns nothing\n"); \
-   goto label; \
-   } \
-} while(0)
-
-#define FOPS_OR_ERR_GOTO(ret, label) do { \
-   if ((ret) < 0) { \
-   RTE_LOG(ERR, POWER, "File operations failed\n"); \
-   goto label; \
-   } \
-} while(0)
-
-#define STR_SIZE 1024
-#define POWER_CONVERT_TO_DECIMAL 10
+enum power_management_env global_default_env = PM_ENV_NOT_SET;

-#define POWER_GOVERNOR_USERSPACE "userspace"
-#define POWER_SYSFILE_GOVERNOR   \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_governor"
-#define POWER_SYSFILE_AVAIL_FREQ \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_frequencies"
-#define POWER_SYSFILE_SETSPEED   \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_setspeed"
+volatile uint32_t global_env_cfg_status = 0;

-enum power_state {
-   POWER_IDLE = 0,
-   POWER_ONGOING,
-   POWER_USED,
-   POWER_UNKNOWN
-};
+/* function pointers */
+rte_power_freqs_t rte_power_freqs  = NULL;
+rte_power_get_freq_t rte_power_get_freq = NULL;
+rte_power_set_freq_t rte_power_set_freq = NULL;
+rte_power_freq_change_t rte_power_freq_up = NULL;
+rte_power_freq_change_t rte_power_freq_down = NULL;
+rte_power_freq_change_t rte_power_freq_max = NULL;
+rte_power_freq_change_t rte_power_freq_min = NULL;

-/**
- * Power info per lcore.
- */
-struct rte_power_info {
-   unsigned lcore_id;   /**< Logical core id */
-   uint32_t freqs[RTE_MAX_LCORE_FREQS]; /**< Frequency array */
-   uint32_t nb_freqs;   /**< number of available freqs */
-   FILE *f; /**< FD of scaling_setspeed */
-   char governor_ori[32];   /**< Original governor name */
-   uint32_t curr_idx;   /**< Freq index in freqs array */
-   volatile uint32_t state; /**< Power in use state */
-} __rte_cache_aligned;
-
-static struct rte_power_info lcore_power_info[RTE_MAX_LCORE];
-
-/**
- * It is to set specific freq for specific logical core, according to the index
- * of supported frequencies.
- */
-static int
-set_freq_internal(struct rte_power_info *pi, uint32_t idx)
+int
+rte_power_set_env(enum power_management_env

[dpdk-dev] [PATCH v3 10/10] VM Power Management Unit Tests

2014-09-29 Thread Alan Carew
Updated the unit tests to cover both librte_power implementations as well as
the external API.

Signed-off-by: Alan Carew 
---
 app/test/Makefile  |   3 +-
 app/test/autotest_data.py  |  26 ++
 app/test/test_power.c  | 445 +++---
 app/test/test_power_acpi_cpufreq.c | 544 +
 app/test/test_power_kvm_vm.c   | 308 +
 5 files changed, 917 insertions(+), 409 deletions(-)
 create mode 100644 app/test/test_power_acpi_cpufreq.c
 create mode 100644 app/test/test_power_kvm_vm.c

diff --git a/app/test/Makefile b/app/test/Makefile
index 37a3772..03ade39 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -119,7 +119,8 @@ endif

 SRCS-$(CONFIG_RTE_LIBRTE_METER) += test_meter.c
 SRCS-$(CONFIG_RTE_LIBRTE_KNI) += test_kni.c
-SRCS-$(CONFIG_RTE_LIBRTE_POWER) += test_power.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) += test_power.c test_power_acpi_cpufreq.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) += test_power_kvm_vm.c
 SRCS-y += test_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_IVSHMEM) += test_ivshmem.c

diff --git a/app/test/autotest_data.py b/app/test/autotest_data.py
index 878c72e..618a946 100644
--- a/app/test/autotest_data.py
+++ b/app/test/autotest_data.py
@@ -425,6 +425,32 @@ non_parallel_test_group_list = [
]
 },
 {
+   "Prefix" :  "power_acpi_cpufreq",
+   "Memory" :  all_sockets(512),
+   "Tests" :
+   [
+   {
+"Name" :   "Power ACPI cpufreq autotest",
+"Command" :"power_acpi_cpufreq_autotest",
+"Func" :   default_autotest,
+"Report" : None,
+   },
+   ]
+},
+{
+   "Prefix" :  "power_kvm_vm",
+   "Memory" :  "512",
+   "Tests" :
+   [
+   {
+"Name" :   "Power KVM VM  autotest",
+"Command" :"power_kvm_vm_autotest",
+"Func" :   default_autotest,
+"Report" : None,
+   },
+   ]
+},
+{
"Prefix" :  "lpm6",
"Memory" :  "512",
"Tests" :
diff --git a/app/test/test_power.c b/app/test/test_power.c
index d9eb420..64a2305 100644
--- a/app/test/test_power.c
+++ b/app/test/test_power.c
@@ -41,437 +41,66 @@

 #include 

-#define TEST_POWER_LCORE_ID  2U
-#define TEST_POWER_LCORE_INVALID ((unsigned)RTE_MAX_LCORE)
-#define TEST_POWER_FREQS_NUM_MAX ((unsigned)RTE_MAX_LCORE_FREQS)
-
-#define TEST_POWER_SYSFILE_CUR_FREQ \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq"
-
-static uint32_t total_freq_num;
-static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX];
-
-static int
-check_cur_freq(unsigned lcore_id, uint32_t idx)
-{
-#define TEST_POWER_CONVERT_TO_DECIMAL 10
-   FILE *f;
-   char fullpath[PATH_MAX];
-   char buf[BUFSIZ];
-   uint32_t cur_freq;
-   int ret = -1;
-
-   if (snprintf(fullpath, sizeof(fullpath),
-   TEST_POWER_SYSFILE_CUR_FREQ, lcore_id) < 0) {
-   return 0;
-   }
-   f = fopen(fullpath, "r");
-   if (f == NULL) {
-   return 0;
-   }
-   if (fgets(buf, sizeof(buf), f) == NULL) {
-   goto fail_get_cur_freq;
-   }
-   cur_freq = strtoul(buf, NULL, TEST_POWER_CONVERT_TO_DECIMAL);
-   ret = (freqs[idx] == cur_freq ? 0 : -1);
-
-fail_get_cur_freq:
-   fclose(f);
-
-   return ret;
-}
-
-/* Check rte_power_freqs() */
-static int
-check_power_freqs(void)
-{
-   uint32_t ret;
-
-   total_freq_num = 0;
-   memset(freqs, 0, sizeof(freqs));
-
-   /* test with an invalid lcore id */
-   ret = rte_power_freqs(TEST_POWER_LCORE_INVALID, freqs,
-   TEST_POWER_FREQS_NUM_MAX);
-   if (ret > 0) {
-   printf("Unexpectedly get available freqs successfully on "
-   "lcore %u\n", TEST_POWER_LCORE_INVALID);
-   return -1;
-   }
-
-   /* test with NULL buffer to save available freqs */
-   ret = rte_power_freqs(TEST_POWER_LCORE_ID, NULL,
-   TEST_POWER_FREQS_NUM_MAX);
-   if (ret > 0) {
-   printf("Unexpectedly get available freqs successfully with "
-   "NULL buffer on lcore %u\n", TEST_POWER_LCORE_ID);
-   return -1;
-   }
-
-   /* test of getting zero number of freqs */
-   ret = rte_power_freqs(TEST_POWER_LCORE_ID, freqs, 0);
-   if (ret > 0) {
-   printf("Unexpectedly get available freqs successfully with "
-   "zero buffer size o

[dpdk-dev] [PATCH v4 00/10] VM Power Management

2014-10-12 Thread Alan Carew
Virtual Machine Power Management.

The following patches add two DPDK sample applications and an alternate
implementation of librte_power for use in virtualized environments.
The idea is to provide librte_power functionality from within a VM to address
the lack of MSRs to facilitate frequency changes from within a VM.
It is ideally suited for Haswell which provides per core frequency scaling.

The current librte_power affects frequency changes via the acpi-cpufreq
'userspace' power governor, accessed via sysfs.

General Overview:(more information in each patch that follows).
The VM Power Management solution provides two components:

 1)VM: Allows for the a DPDK application in a VM to reuse the librte_power
 interface. Each lcore opens a Virto-Serial endpoint channel to the host,
 where the re-implementation of librte_power simply forwards the requests for
 frequency change to a host based monitor. The host monitor itself uses
 librte_power.
 Each lcore channel corresponds to a
 serial device '/dev/virtio-ports/virtio.serial.port.poweragent.'
 which is opened in non-blocking mode.
 While each Virtual CPU can be mapped to multiple physical CPUs it is
 recommended that each vCPU should be mapped to a single core only.

 2)Host: The host monitor is managed by a CLI, it allows for adding qemu/KVM
 virtual machines and associated channels to the monitor, manually changing
 CPU frequency, inspecting the state of VMs, vCPU to pCPU pinning and managing
 channels.
 Host channel endpoints are Virto-Serial endpoints configured as AF_UNIX file
 sockets which follow a specific naming convention
 i.e /tmp/powermonitor/.,
 each channel has an 1:1 mapping to a VM endpoint
 i.e. /dev/virtio-ports/virtio.serial.port.poweragent.
 Host channel endpoints are opened in non-blocking mode and are monitored via 
epoll.
 Requests over each channel to change frequency are forwarded to the original
 librte_power.

Channels must be manually configured as qemu-kvm command line arguments or
libvirt domain definition(xml) e.g.

 


  
  


Where multiple channels can be configured by specifying multiple 
elements, by replacing , .
(port number) should be incremented by 1 for each new channel element.
More information on Virtio-Serial can be found here:
http://fedoraproject.org/wiki/Features/VirtioSerial
To enable the Hypervisor creation of channels, the host endpoint directory
must be created with qemu permissions:
mkdir /tmp/powermonitor
chown qemu:qemu /tmp/powermonitor

The host application runs on two separate lcores:
Core N) CLI: For management of Virtual Machines adding channels to Monitor 
thread,
 inspecting state and manually setting CPU frequency [PATCH 02/09]
Core N+1) Monitor Thread: An epoll based infinite loop that waits on channel 
events
 from VMs and calls the corresponding librte_power functions.

A sample application is also provided to run on Virtual Machines, this
application provides a CLI to manually set the frequency of a 
vCPU[PATCH 08/09]

The current l3fwd-power sample application can also be run on a VM.

Changes in V4:
 Fixed double free of channel during VM shutdown.

Changes in V3:
 Fixed crash in Guest CLI when host application is not running.
 Renamed #defines to be more specific to the module they belong
 Added vCPU pinning via CLI

Changes in V2:
 Runtime selection of librte_power implementations.
 Updated Unit tests to cover librte_power changes.
 PATCH[0/3] was sent twice, again as PATCH[0/4]
 Miscellaneous fixes.

Alan Carew (10):
  Channel Manager and Monitor for VM Power Management(Host).
  VM Power Management CLI(Host).
  CPU Frequency Power Management(Host).
  VM Power Management application and Makefile.
  VM Power Management CLI(Guest).
  VM communication channels for VM Power Management(Guest).
  librte_power common interface for Guest and Host
  Packet format for VM Power Management(Host and Guest).
  Build system integration for VM Power Management(Guest and Host)
  VM Power Management Unit Tests

 app/test/Makefile  |   3 +-
 app/test/autotest_data.py  |  26 +
 app/test/test_power.c  | 445 +---
 app/test/test_power_acpi_cpufreq.c | 544 ++
 app/test/test_power_kvm_vm.c   | 308 
 examples/vm_power_manager/Makefile |  57 ++
 examples/vm_power_manager/channel_manager.c| 804 +
 examples/vm_power_manager/channel_manager.h| 314 
 examples/vm_power_manager/channel_monitor.c| 231 ++
 examples/vm_power_manager/channel_monitor.h| 102 +++
 examples/vm_power_manager/guest_cli/Makefile   |  56 ++
 examples/vm_power_manager/guest_cli/main.c |  87 +++
 examples/vm_power_manager/guest_cli/main.h |  52 ++
 .../guest_cli/vm_power_cli_guest.c | 155 
 .../guest_cli/vm_power_cli_guest.h |  55 ++
 examples/vm_

[dpdk-dev] [PATCH v4 02/10] VM Power Management CLI(Host).

2014-10-12 Thread Alan Carew
The CLI is used for administrating the channel monitor and manager and
manually setting the CPU frequency on the host.

Supports the following commands:
 add_vm [Mul-choice STRING]: add_vm|rm_vm , add a VM for subsequent
  operations with the CLI or remove a previously added VM from the VM Power
  Manager

 rm_vm [Mul-choice STRING]: add_vm|rm_vm , add a VM for subsequent
  operations with the CLI or remove a previously added VM from the VM Power
  Manager

 add_channels [Fixed STRING]: add_channels  |all, add
  communication channels for the specified VM, the virtio channels must be
  enabled in the VM configuration(qemu/libvirt) and the associated VM must be
  active.  is a comma-separated list of channel numbers to add, using the
  keyword 'all' will attempt to add all channels for the VM

 set_channel_status [Fixed STRING]:
  set_channel_status  |all enabled|disabled,  enable or disable
  the communication channels in list(comma-seperated) for the specified VM,
  alternatively list can be replaced with keyword 'all'. Disabled channels will
  still receive packets on the host, however the commands they specify will be
  ignored. Set status to 'enabled' to begin processing requests again.

 show_vm [Fixed STRING]: show_vm , prints the information on the
  specified VM(s), the information lists the number of vCPUS, the pinning to
  pCPU(s) as a bit mask, along with any communication channels associated with
  each VM

 show_cpu_freq_mask [Fixed STRING]: show_cpu_freq_mask , Get the current
  frequency for each core specified in the mask

 set_cpu_freq_mask [Fixed STRING]: set_cpu_freq  ,
  Set the current frequency for the cores specified in  by scaling
  each up/down/min/max.

 show_cpu_freq [Fixed STRING]: Get the current frequency for the specified core

 set_cpu_freq [Fixed STRING]: set_cpu_freq  ,
  Set the current frequency for the specified core by scaling up/down/min/max

 quit [Fixed STRING]: close the application

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/vm_power_cli.c | 669 +++
 examples/vm_power_manager/vm_power_cli.h |  47 +++
 2 files changed, 716 insertions(+)
 create mode 100644 examples/vm_power_manager/vm_power_cli.c
 create mode 100644 examples/vm_power_manager/vm_power_cli.h

diff --git a/examples/vm_power_manager/vm_power_cli.c 
b/examples/vm_power_manager/vm_power_cli.c
new file mode 100644
index 000..e162e88
--- /dev/null
+++ b/examples/vm_power_manager/vm_power_cli.c
@@ -0,0 +1,669 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "vm_power_cli.h"
+#include "channel_manager.h"
+#include "channel_monitor.h"
+#include "power_manager.h"
+#include "channel_commands.h"
+
+struct cmd_quit_result {
+   cmdline_fixed_string_t quit;
+};
+
+static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
+   struct cmdline *cl,
+   __attribute__((unused)) void *data)
+{
+   channel_monitor_exit();
+   channel_manager_exit();
+   power_manager_exit();
+   cmdline_quit(cl);
+}
+
+cmdline_pa

[dpdk-dev] [PATCH v4 01/10] Channel Manager and Monitor for VM Power Management(Host).

2014-10-12 Thread Alan Carew
The manager is responsible for adding communications channels to the Monitor
thread, tracking and reporting VM state and employs the libvirt API for
synchronization with the KVM Hypervisor. The manager interacts with the
Hypervisor to discover the mapping of virtual CPUS(vCPUs) to the host
physical CPUS(pCPUs) and to inspect the VM running state.

The manager provides the following functionality to the CLI:
1) Connect to a libvirtd instance, default: qemu:///system
2) Add a VM to an internal list, each VM is identified by a "name" which must
   correspond a valid libvirt Domain Name.
3) Add communication channels associated with a VM to the epoll based Monitor
   thread.
   The channels must exist and be in the form of:
   /tmp/powermonitor/.. Each channel is a
   Virtio-Serial endpoint configured as an AF_UNIX file socket and opened in
   non-blocking mode.
   Each VM can have a maximum of 64 channels associated with it.
4) Disable or re-enable VM communication channels, channels once added to the
   Monitor thread remain in that threads control, however acting on channel
   requests can be disabled and renabled via CLI.

The monitor is an epoll based infinite loop running in a separate thread that
waits on channel events from VMs and calls the corresponding functions. Channel
definitions from the manager are registered via the epoll event opaque pointer
when calling epoll_ctl(EPOLL_CTL_ADD), this allows for obtaining the channels
file descriptor for reading EPOLLIN events and mapping the vCPU to pCPU(s)
associated with a request from a particular VM.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/channel_manager.c | 804 
 examples/vm_power_manager/channel_manager.h | 314 +++
 examples/vm_power_manager/channel_monitor.c | 231 
 examples/vm_power_manager/channel_monitor.h | 102 
 4 files changed, 1451 insertions(+)
 create mode 100644 examples/vm_power_manager/channel_manager.c
 create mode 100644 examples/vm_power_manager/channel_manager.h
 create mode 100644 examples/vm_power_manager/channel_monitor.c
 create mode 100644 examples/vm_power_manager/channel_monitor.h

diff --git a/examples/vm_power_manager/channel_manager.c 
b/examples/vm_power_manager/channel_manager.c
new file mode 100644
index 000..a14f191
--- /dev/null
+++ b/examples/vm_power_manager/channel_manager.c
@@ -0,0 +1,804 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "channel_manager.h"
+#include "channel_commands.h"
+#include "channel_monitor.h"
+
+
+#define RTE_LOGTYPE_CHANNEL_MANAGER RTE_LOGTYPE_USER1
+
+#define ITERATIVE_BITMASK_CHECK_64(mask_u64b, i) \
+   for (i = 0; mask_u64b; mask_u64b &= ~(1ULL << i++)) \
+   if ((mask_u64b >> i) & 1) \
+
+/* Global pointer to libvirt connection */
+static virConnectPtr global_vir_conn_ptr;
+
+static unsigned char *global_cpumaps;
+static virVcpuInfo *global_vircpuinfo;
+static size_t global_maplen;
+
+static unsigned global_n_host_cpus;
+
+/*
+ *

[dpdk-dev] [PATCH v4 03/10] CPU Frequency Power Management(Host).

2014-10-12 Thread Alan Carew
A wrapper around librte_power(using ACPI cpufreq), providing locking around the
non-threadsafe library, allowing for frequency changes based on core masks and
core numbers from both the CLI thread and epoll monitor thread.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/power_manager.c | 244 ++
 examples/vm_power_manager/power_manager.h | 188 +++
 2 files changed, 432 insertions(+)
 create mode 100644 examples/vm_power_manager/power_manager.c
 create mode 100644 examples/vm_power_manager/power_manager.h

diff --git a/examples/vm_power_manager/power_manager.c 
b/examples/vm_power_manager/power_manager.c
new file mode 100644
index 000..b7b1fca
--- /dev/null
+++ b/examples/vm_power_manager/power_manager.c
@@ -0,0 +1,244 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "power_manager.h"
+
+#define RTE_LOGTYPE_POWER_MANAGER RTE_LOGTYPE_USER1
+
+#define POWER_SCALE_CORE(DIRECTION, core_num , ret) do { \
+   if (core_num >= POWER_MGR_MAX_CPUS) \
+   return -1; \
+   if (!(global_enabled_cpus & (1ULL << core_num))) \
+   return -1; \
+   rte_spinlock_lock(&global_core_freq_info[core_num].power_sl); \
+   ret = rte_power_freq_##DIRECTION(core_num); \
+   rte_spinlock_unlock(&global_core_freq_info[core_num].power_sl); \
+} while (0)
+
+#define POWER_SCALE_MASK(DIRECTION, core_mask, ret) do { \
+   int i; \
+   for (i = 0; core_mask; core_mask &= ~(1 << i++)) { \
+   if ((core_mask >> i) & 1) { \
+   if (!(global_enabled_cpus & (1ULL << i))) \
+   continue; \
+   rte_spinlock_lock(&global_core_freq_info[i].power_sl); \
+   if (rte_power_freq_##DIRECTION(i) != 1) \
+   ret = -1; \
+   rte_spinlock_unlock(&global_core_freq_info[i].power_sl); \
+   } \
+   } \
+} while (0)
+
+struct freq_info {
+   rte_spinlock_t power_sl;
+   uint32_t freqs[RTE_MAX_LCORE_FREQS];
+   unsigned num_freqs;
+} __rte_cache_aligned;
+
+static struct freq_info global_core_freq_info[POWER_MGR_MAX_CPUS];
+
+static uint64_t global_enabled_cpus;
+
+#define SYSFS_CPU_PATH "/sys/devices/system/cpu/cpu%u/topology/core_id"
+
+static unsigned
+set_host_cpus_mask(void)
+{
+   char path[PATH_MAX];
+   unsigned i;
+   unsigned num_cpus = 0;
+   for (i = 0; i < POWER_MGR_MAX_CPUS; i++) {
+   snprintf(path, sizeof(path), SYSFS_CPU_PATH, i);
+   if (access(path, F_OK) == 0) {
+   global_enabled_cpus |= 1ULL << i;
+   num_cpus++;
+   } else
+   return num_cpus;
+   }
+   return num_cpus;
+}
+
+int
+power_manager_init(void)
+{
+   unsigned i, num_cpus;
+   uint64_t cpu_mask;
+   int ret = 0;
+
+   num_cpus = set_host_cpus_mask();
+   if (num_cpus == 0) {
+   RTE_LOG(ERR, POWER_MANAGER, "Unable to detected host CPUs, 
please "
+

[dpdk-dev] [PATCH v4 04/10] VM Power Management application and Makefile.

2014-10-12 Thread Alan Carew
For launching CLI thread and Monitor thread and initialising
resources.
Requires a minimum of two lcores to run, additional cores specified by eal core
mask are not used.

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/Makefile |  57 ++
 examples/vm_power_manager/main.c   | 117 +
 examples/vm_power_manager/main.h   |  52 +
 3 files changed, 226 insertions(+)
 create mode 100644 examples/vm_power_manager/Makefile
 create mode 100644 examples/vm_power_manager/main.c
 create mode 100644 examples/vm_power_manager/main.h

diff --git a/examples/vm_power_manager/Makefile 
b/examples/vm_power_manager/Makefile
new file mode 100644
index 000..7d6f943
--- /dev/null
+++ b/examples/vm_power_manager/Makefile
@@ -0,0 +1,57 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriden by command line or environment
+RTE_TARGET ?= x86_64-default-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = vm_power_mgr
+
+# all source are stored in SRCS-y
+SRCS-y := main.c vm_power_cli.c power_manager.c channel_manager.c
+SRCS-y += channel_monitor.c
+
+CFLAGS += -O3 -lvirt -I$(RTE_SDK)/lib/librte_power/
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/vm_power_manager/main.c b/examples/vm_power_manager/main.c
new file mode 100644
index 000..875274e
--- /dev/null
+++ b/examples/vm_power_manager/main.c
@@ -0,0 +1,117 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT

[dpdk-dev] [PATCH v4 06/10] VM communication channels for VM Power Management(Guest).

2014-10-12 Thread Alan Carew
Allows for the opening of Virtio-Serial devices on a VM, where a DPDK
application can send packets to the host based monitor. The packet formatted is
specified in channel_commands.h
Each device appears as a serial device in path
/dev/virtio-ports/virtio.serial.port.. where each lcore
in a DPDK application has exclusive to a device/channel.
Each channel is opened in non-blocking mode, after a successful open a test
packet is send to the host to ensure the host side is monitoring.

Signed-off-by: Alan Carew 
---
 lib/librte_power/guest_channel.c | 162 +++
 lib/librte_power/guest_channel.h |  89 +
 2 files changed, 251 insertions(+)
 create mode 100644 lib/librte_power/guest_channel.c
 create mode 100644 lib/librte_power/guest_channel.h

diff --git a/lib/librte_power/guest_channel.c b/lib/librte_power/guest_channel.c
new file mode 100644
index 000..2295665
--- /dev/null
+++ b/lib/librte_power/guest_channel.c
@@ -0,0 +1,162 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+
+#include 
+#include 
+
+#include "guest_channel.h"
+#include "channel_commands.h"
+
+#define RTE_LOGTYPE_GUEST_CHANNEL RTE_LOGTYPE_USER1
+
+static int global_fds[RTE_MAX_LCORE];
+
+int
+guest_channel_host_connect(const char *path, unsigned lcore_id)
+{
+   int flags, ret;
+   struct channel_packet pkt;
+   char fd_path[PATH_MAX];
+   int fd = -1;
+
+   if (lcore_id >= RTE_MAX_LCORE) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Channel(%u) is out of range 
0...%d\n",
+   lcore_id, RTE_MAX_LCORE-1);
+   return -1;
+   }
+   /* check if path is already open */
+   if (global_fds[lcore_id] != 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Channel(%u) is already open with 
fd %d\n",
+   lcore_id, global_fds[lcore_id]);
+   return -1;
+   }
+
+   snprintf(fd_path, PATH_MAX, "%s.%u", path, lcore_id);
+   RTE_LOG(INFO, GUEST_CHANNEL, "Opening channel '%s' for lcore %u\n",
+   fd_path, lcore_id);
+   fd = open(fd_path, O_RDWR);
+   if (fd < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Unable to to connect to '%s' with 
error "
+   "%s\n", fd_path, strerror(errno));
+   return -1;
+   }
+
+   flags = fcntl(fd, F_GETFL, 0);
+   if (flags < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Failed on fcntl get flags for file 
%s\n",
+   fd_path);
+   goto error;
+   }
+
+   flags |= O_NONBLOCK;
+   if (fcntl(fd, F_SETFL, flags) < 0) {
+   RTE_LOG(ERR, GUEST_CHANNEL, "Failed on setting non-blocking 
mode for "
+   "file %s", fd_path);
+   goto error;
+   }
+   /* QEMU needs a delay after connection */
+   sleep(1);
+
+   /* Send a test packet, this command is ignored by the host, but a 
successful
+* send indicates that the host endpoint is monitoring.
+*

[dpdk-dev] [PATCH v4 05/10] VM Power Management CLI(Guest).

2014-10-12 Thread Alan Carew
Provides a small sample application(guest_vm_power_mgr) to run on a VM.
The application is run by providing a core mask(-c) and number of memory
channels(-n). The core mask corresponds to the number of lcore channels to
attempt to open. A maximum of 64 channels per VM is allowed. The channels must
be monitored by the host.
After successful initialisation a CPU frequency command can be sent to the host
using:
set_cpu_freq  .

Signed-off-by: Alan Carew 
---
 examples/vm_power_manager/guest_cli/Makefile   |  56 
 examples/vm_power_manager/guest_cli/main.c |  87 
 examples/vm_power_manager/guest_cli/main.h |  52 +++
 .../guest_cli/vm_power_cli_guest.c | 155 +
 .../guest_cli/vm_power_cli_guest.h |  55 
 5 files changed, 405 insertions(+)
 create mode 100644 examples/vm_power_manager/guest_cli/Makefile
 create mode 100644 examples/vm_power_manager/guest_cli/main.c
 create mode 100644 examples/vm_power_manager/guest_cli/main.h
 create mode 100644 examples/vm_power_manager/guest_cli/vm_power_cli_guest.c
 create mode 100644 examples/vm_power_manager/guest_cli/vm_power_cli_guest.h

diff --git a/examples/vm_power_manager/guest_cli/Makefile 
b/examples/vm_power_manager/guest_cli/Makefile
new file mode 100644
index 000..167a7ed
--- /dev/null
+++ b/examples/vm_power_manager/guest_cli/Makefile
@@ -0,0 +1,56 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+# * Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in
+#   the documentation and/or other materials provided with the
+#   distribution.
+# * Neither the name of Intel Corporation nor the names of its
+#   contributors may be used to endorse or promote products derived
+#   from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overriden by command line or environment
+RTE_TARGET ?= x86_64-default-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# binary name
+APP = guest_vm_power_mgr
+
+# all source are stored in SRCS-y
+SRCS-y := main.c vm_power_cli_guest.c
+
+CFLAGS += -O3 -I$(RTE_SDK)/lib/librte_power/
+CFLAGS += $(WERROR_FLAGS)
+
+# workaround for a gcc bug with noreturn attribute
+# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
+ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y)
+CFLAGS_main.o += -Wno-return-type
+endif
+
+include $(RTE_SDK)/mk/rte.extapp.mk
diff --git a/examples/vm_power_manager/guest_cli/main.c 
b/examples/vm_power_manager/guest_cli/main.c
new file mode 100644
index 000..1e4767a
--- /dev/null
+++ b/examples/vm_power_manager/guest_cli/main.c
@@ -0,0 +1,87 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "

[dpdk-dev] [PATCH v4 08/10] Packet format for VM Power Management(Host and Guest).

2014-10-12 Thread Alan Carew
Provides a command packet format for host and guest.

Signed-off-by: Alan Carew 
---
 lib/librte_power/channel_commands.h | 77 +
 1 file changed, 77 insertions(+)
 create mode 100644 lib/librte_power/channel_commands.h

diff --git a/lib/librte_power/channel_commands.h 
b/lib/librte_power/channel_commands.h
new file mode 100644
index 000..7e78a8b
--- /dev/null
+++ b/lib/librte_power/channel_commands.h
@@ -0,0 +1,77 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CHANNEL_COMMANDS_H_
+#define CHANNEL_COMMANDS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+
+/* Maximum number of CPUs */
+#define CHANNEL_CMDS_MAX_CPUS64
+#if CHANNEL_CMDS_MAX_CPUS > 64
+#error Maximum number of cores is 64, overflow is guaranteed to \
+   cause problems with VM Power Management
+#endif
+
+/* Maximum number of channels per VM */
+#define CHANNEL_CMDS_MAX_VM_CHANNELS 64
+
+/* Maximum number of channels per VM */
+#define CHANNEL_CMDS_MAX_VM_CHANNELS 64
+
+/* Valid Commands */
+#define CPU_POWER   1
+#define CPU_POWER_CONNECT   2
+
+/* CPU Power Command Scaling */
+#define CPU_POWER_SCALE_UP  1
+#define CPU_POWER_SCALE_DOWN2
+#define CPU_POWER_SCALE_MAX 3
+#define CPU_POWER_SCALE_MIN 4
+
+struct channel_packet {
+   uint64_t resource_id; /**< core_num, device */
+   uint32_t unit;/**< scale down/up/min/max */
+   uint32_t command; /**< Power, IO, etc */
+};
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CHANNEL_COMMANDS_H_ */
-- 
1.9.3



[dpdk-dev] [PATCH v4 09/10] Build system integration for VM Power Management(Guest and Host)

2014-10-12 Thread Alan Carew
librte_power now contains both rte_power_acpi_cpufreq and rte_power_kvm_vm
implementations.

Signed-off-by: Alan Carew 
---
 lib/librte_power/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/librte_power/Makefile b/lib/librte_power/Makefile
index 6185812..d672a5a 100644
--- a/lib/librte_power/Makefile
+++ b/lib/librte_power/Makefile
@@ -37,7 +37,8 @@ LIB = librte_power.a
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -fno-strict-aliasing

 # all source are stored in SRCS-y
-SRCS-$(CONFIG_RTE_LIBRTE_POWER) := rte_power.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) := rte_power.c rte_power_acpi_cpufreq.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) += rte_power_kvm_vm.c guest_channel.c

 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_POWER)-include := rte_power.h
-- 
1.9.3



[dpdk-dev] [PATCH v4 07/10] librte_power common interface for Guest and Host

2014-10-12 Thread Alan Carew
Moved the current librte_power implementation to rte_power_acpi_cpufreq, with
renaming of functions only.
Added rte_power_kvm_vm implmentation to support Power Management from a VM.

librte_power now hides the implementation based on the environment used.
A new call rte_power_set_env() can explicidly set the environment, if not
called then auto-detection takes place.

rte_power_kvm_vm is subset of the librte_power APIs, the following is supported:
 rte_power_init(unsigned lcore_id)
 rte_power_exit(unsigned lcore_id)
 rte_power_freq_up(unsigned lcore_id)
 rte_power_freq_down(unsigned lcore_id)
 rte_power_freq_min(unsigned lcore_id)
 rte_power_freq_max(unsigned lcore_id)

The other unsupported APIs return -ENOTSUP

Signed-off-by: Alan Carew 
---
 lib/librte_power/rte_power.c  | 540 -
 lib/librte_power/rte_power.h  | 120 +--
 lib/librte_power/rte_power_acpi_cpufreq.c | 545 ++
 lib/librte_power/rte_power_acpi_cpufreq.h | 192 +++
 lib/librte_power/rte_power_common.h   |  39 +++
 lib/librte_power/rte_power_kvm_vm.c   | 135 
 lib/librte_power/rte_power_kvm_vm.h   | 179 ++
 7 files changed, 1248 insertions(+), 502 deletions(-)
 create mode 100644 lib/librte_power/rte_power_acpi_cpufreq.c
 create mode 100644 lib/librte_power/rte_power_acpi_cpufreq.h
 create mode 100644 lib/librte_power/rte_power_common.h
 create mode 100644 lib/librte_power/rte_power_kvm_vm.c
 create mode 100644 lib/librte_power/rte_power_kvm_vm.h

diff --git a/lib/librte_power/rte_power.c b/lib/librte_power/rte_power.c
index 856da9a..998ed1c 100644
--- a/lib/librte_power/rte_power.c
+++ b/lib/librte_power/rte_power.c
@@ -31,515 +31,113 @@
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */

-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
 #include 

 #include "rte_power.h"
+#include "rte_power_acpi_cpufreq.h"
+#include "rte_power_kvm_vm.h"
+#include "rte_power_common.h"

-#ifdef RTE_LIBRTE_POWER_DEBUG
-#define POWER_DEBUG_TRACE(fmt, args...) do { \
-   RTE_LOG(ERR, POWER, "%s: " fmt, __func__, ## args); \
-   } while (0)
-#else
-#define POWER_DEBUG_TRACE(fmt, args...)
-#endif
-
-#define FOPEN_OR_ERR_RET(f, retval) do { \
-   if ((f) == NULL) { \
-   RTE_LOG(ERR, POWER, "File not openned\n"); \
-   return (retval); \
-   } \
-} while(0)
-
-#define FOPS_OR_NULL_GOTO(ret, label) do { \
-   if ((ret) == NULL) { \
-   RTE_LOG(ERR, POWER, "fgets returns nothing\n"); \
-   goto label; \
-   } \
-} while(0)
-
-#define FOPS_OR_ERR_GOTO(ret, label) do { \
-   if ((ret) < 0) { \
-   RTE_LOG(ERR, POWER, "File operations failed\n"); \
-   goto label; \
-   } \
-} while(0)
-
-#define STR_SIZE 1024
-#define POWER_CONVERT_TO_DECIMAL 10
+enum power_management_env global_default_env = PM_ENV_NOT_SET;

-#define POWER_GOVERNOR_USERSPACE "userspace"
-#define POWER_SYSFILE_GOVERNOR   \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_governor"
-#define POWER_SYSFILE_AVAIL_FREQ \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_available_frequencies"
-#define POWER_SYSFILE_SETSPEED   \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_setspeed"
+volatile uint32_t global_env_cfg_status = 0;

-enum power_state {
-   POWER_IDLE = 0,
-   POWER_ONGOING,
-   POWER_USED,
-   POWER_UNKNOWN
-};
+/* function pointers */
+rte_power_freqs_t rte_power_freqs  = NULL;
+rte_power_get_freq_t rte_power_get_freq = NULL;
+rte_power_set_freq_t rte_power_set_freq = NULL;
+rte_power_freq_change_t rte_power_freq_up = NULL;
+rte_power_freq_change_t rte_power_freq_down = NULL;
+rte_power_freq_change_t rte_power_freq_max = NULL;
+rte_power_freq_change_t rte_power_freq_min = NULL;

-/**
- * Power info per lcore.
- */
-struct rte_power_info {
-   unsigned lcore_id;   /**< Logical core id */
-   uint32_t freqs[RTE_MAX_LCORE_FREQS]; /**< Frequency array */
-   uint32_t nb_freqs;   /**< number of available freqs */
-   FILE *f; /**< FD of scaling_setspeed */
-   char governor_ori[32];   /**< Original governor name */
-   uint32_t curr_idx;   /**< Freq index in freqs array */
-   volatile uint32_t state; /**< Power in use state */
-} __rte_cache_aligned;
-
-static struct rte_power_info lcore_power_info[RTE_MAX_LCORE];
-
-/**
- * It is to set specific freq for specific logical core, according to the index
- * of supported frequencies.
- */
-static int
-set_freq_internal(struct rte_power_info *pi, uint32_t idx)
+int
+rte_power_set_env(enum power_management_env

[dpdk-dev] [PATCH v4 10/10] VM Power Management Unit Tests

2014-10-12 Thread Alan Carew
Updated the unit tests to cover both librte_power implementations as well as
the external API.

Signed-off-by: Alan Carew 
---
 app/test/Makefile  |   3 +-
 app/test/autotest_data.py  |  26 ++
 app/test/test_power.c  | 445 +++---
 app/test/test_power_acpi_cpufreq.c | 544 +
 app/test/test_power_kvm_vm.c   | 308 +
 5 files changed, 917 insertions(+), 409 deletions(-)
 create mode 100644 app/test/test_power_acpi_cpufreq.c
 create mode 100644 app/test/test_power_kvm_vm.c

diff --git a/app/test/Makefile b/app/test/Makefile
index 6af6d76..9417eda 100644
--- a/app/test/Makefile
+++ b/app/test/Makefile
@@ -119,7 +119,8 @@ endif

 SRCS-$(CONFIG_RTE_LIBRTE_METER) += test_meter.c
 SRCS-$(CONFIG_RTE_LIBRTE_KNI) += test_kni.c
-SRCS-$(CONFIG_RTE_LIBRTE_POWER) += test_power.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) += test_power.c test_power_acpi_cpufreq.c
+SRCS-$(CONFIG_RTE_LIBRTE_POWER) += test_power_kvm_vm.c
 SRCS-y += test_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_IVSHMEM) += test_ivshmem.c

diff --git a/app/test/autotest_data.py b/app/test/autotest_data.py
index 878c72e..618a946 100644
--- a/app/test/autotest_data.py
+++ b/app/test/autotest_data.py
@@ -425,6 +425,32 @@ non_parallel_test_group_list = [
]
 },
 {
+   "Prefix" :  "power_acpi_cpufreq",
+   "Memory" :  all_sockets(512),
+   "Tests" :
+   [
+   {
+"Name" :   "Power ACPI cpufreq autotest",
+"Command" :"power_acpi_cpufreq_autotest",
+"Func" :   default_autotest,
+"Report" : None,
+   },
+   ]
+},
+{
+   "Prefix" :  "power_kvm_vm",
+   "Memory" :  "512",
+   "Tests" :
+   [
+   {
+"Name" :   "Power KVM VM  autotest",
+"Command" :"power_kvm_vm_autotest",
+"Func" :   default_autotest,
+"Report" : None,
+   },
+   ]
+},
+{
"Prefix" :  "lpm6",
"Memory" :  "512",
"Tests" :
diff --git a/app/test/test_power.c b/app/test/test_power.c
index d9eb420..64a2305 100644
--- a/app/test/test_power.c
+++ b/app/test/test_power.c
@@ -41,437 +41,66 @@

 #include 

-#define TEST_POWER_LCORE_ID  2U
-#define TEST_POWER_LCORE_INVALID ((unsigned)RTE_MAX_LCORE)
-#define TEST_POWER_FREQS_NUM_MAX ((unsigned)RTE_MAX_LCORE_FREQS)
-
-#define TEST_POWER_SYSFILE_CUR_FREQ \
-   "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq"
-
-static uint32_t total_freq_num;
-static uint32_t freqs[TEST_POWER_FREQS_NUM_MAX];
-
-static int
-check_cur_freq(unsigned lcore_id, uint32_t idx)
-{
-#define TEST_POWER_CONVERT_TO_DECIMAL 10
-   FILE *f;
-   char fullpath[PATH_MAX];
-   char buf[BUFSIZ];
-   uint32_t cur_freq;
-   int ret = -1;
-
-   if (snprintf(fullpath, sizeof(fullpath),
-   TEST_POWER_SYSFILE_CUR_FREQ, lcore_id) < 0) {
-   return 0;
-   }
-   f = fopen(fullpath, "r");
-   if (f == NULL) {
-   return 0;
-   }
-   if (fgets(buf, sizeof(buf), f) == NULL) {
-   goto fail_get_cur_freq;
-   }
-   cur_freq = strtoul(buf, NULL, TEST_POWER_CONVERT_TO_DECIMAL);
-   ret = (freqs[idx] == cur_freq ? 0 : -1);
-
-fail_get_cur_freq:
-   fclose(f);
-
-   return ret;
-}
-
-/* Check rte_power_freqs() */
-static int
-check_power_freqs(void)
-{
-   uint32_t ret;
-
-   total_freq_num = 0;
-   memset(freqs, 0, sizeof(freqs));
-
-   /* test with an invalid lcore id */
-   ret = rte_power_freqs(TEST_POWER_LCORE_INVALID, freqs,
-   TEST_POWER_FREQS_NUM_MAX);
-   if (ret > 0) {
-   printf("Unexpectedly get available freqs successfully on "
-   "lcore %u\n", TEST_POWER_LCORE_INVALID);
-   return -1;
-   }
-
-   /* test with NULL buffer to save available freqs */
-   ret = rte_power_freqs(TEST_POWER_LCORE_ID, NULL,
-   TEST_POWER_FREQS_NUM_MAX);
-   if (ret > 0) {
-   printf("Unexpectedly get available freqs successfully with "
-   "NULL buffer on lcore %u\n", TEST_POWER_LCORE_ID);
-   return -1;
-   }
-
-   /* test of getting zero number of freqs */
-   ret = rte_power_freqs(TEST_POWER_LCORE_ID, freqs, 0);
-   if (ret > 0) {
-   printf("Unexpectedly get available freqs successfully with "
-   "zero buffer size o

[dpdk-dev] [PATCH] librte_eal: FreeBSD contigmem prevent possible buffer overrun during module unload.

2014-10-14 Thread Alan Carew
The maximum mount contiguous memory regions for FreeBSD is limited by
RTE_CONTIGMEM_MAX_NUM_BUFS, a pointer to each region is stored in
static void * contigmem_buffers[RTE_CONTIGMEM_MAX_NUM_BUFS]

A user can specify a greater amount via hw.contigmem.num_buffers,
while the allocation logic will prevent this allocation from occuring the logic
in contigmem_unload() will attempt to free hw.contigmem.num_buffers and an
overrun occurs.

This patch limits the freeing to a maximum of RTE_CONTIGMEM_MAX_NUM_BUFS.

Signed-off-by: Alan Carew 
---
 lib/librte_eal/bsdapp/contigmem/contigmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/bsdapp/contigmem/contigmem.c 
b/lib/librte_eal/bsdapp/contigmem/contigmem.c
index b71474a..b1a23fa 100644
--- a/lib/librte_eal/bsdapp/contigmem/contigmem.c
+++ b/lib/librte_eal/bsdapp/contigmem/contigmem.c
@@ -178,7 +178,7 @@ contigmem_unload()
if (contigmem_eh_tag != NULL)
EVENTHANDLER_DEREGISTER(process_exit, contigmem_eh_tag);

-   for (i = 0; i < contigmem_num_buffers; i++)
+   for (i = 0; i < RTE_CONTIGMEM_MAX_NUM_BUFS; i++)
if (contigmem_buffers[i] != NULL)
contigfree(contigmem_buffers[i], contigmem_buffer_size,
M_CONTIGMEM);
-- 
1.9.3



[dpdk-dev] [PATCH] librte_cmdline: FreeBSD Fix oveflow when size of command result structure is greater than BUFSIZ

2014-10-20 Thread Alan Carew
When using test-pmd with flow director in FreeBSD, the application will
segfault/Bus error while parsing the command-line. This is due to how
each commands result structure is represented during parsing, where the offsets
for each tokens value is stored in a character array(char result_buf[BUFSIZ])
in cmdline_parse()(./lib/librte_cmdline/cmdline_parse.c).

The overflow occurs where BUFSIZ is less than the size of a commands result
structure, in this case "struct cmd_pkt_filter_result"
(app/test-pmd/cmdline.c) is 1088 bytes and BUFSIZ on FreeBSD is 1024 bytes as
opposed to 8192 bytes on Linux.

This patch removes the OS dependency on BUFSIZ and defines and uses a
library #define CMDLINE_PARSE_RESULT_BUFSIZE 8192

The problem can be reproduced by running test-pmd on FreeBSD:
./testpmd -c 0x3 -n 4 -- -i --portmask=0x3 --pkt-filter-mode=perfect
And adding a filter:
add_perfect_filter 0 udp src 192.168.0.0 1024 dst 192.168.0.0 1024 flexbytes
0x800 vlan 0 queue 0 soft 0x17

Signed-off-by: Alan Carew 
---
 lib/librte_cmdline/cmdline_parse.c | 2 +-
 lib/librte_cmdline/cmdline_parse.h | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/librte_cmdline/cmdline_parse.c 
b/lib/librte_cmdline/cmdline_parse.c
index 940480d..29f1afd 100644
--- a/lib/librte_cmdline/cmdline_parse.c
+++ b/lib/librte_cmdline/cmdline_parse.c
@@ -219,7 +219,7 @@ cmdline_parse(struct cmdline *cl, const char * buf)
unsigned int inst_num=0;
cmdline_parse_inst_t *inst;
const char *curbuf;
-   char result_buf[BUFSIZ];
+   char result_buf[CMDLINE_PARSE_RESULT_BUFSIZE];
void (*f)(void *, struct cmdline *, void *) = NULL;
void *data = NULL;
int comment = 0;
diff --git a/lib/librte_cmdline/cmdline_parse.h 
b/lib/librte_cmdline/cmdline_parse.h
index f18836d..dae53ba 100644
--- a/lib/librte_cmdline/cmdline_parse.h
+++ b/lib/librte_cmdline/cmdline_parse.h
@@ -80,6 +80,9 @@ extern "C" {
 #define CMDLINE_PARSE_COMPLETE_AGAIN1
 #define CMDLINE_PARSE_COMPLETED_BUFFER  2

+/* maximum buffer size for parsed result */
+#define CMDLINE_PARSE_RESULT_BUFSIZE 8192
+
 /**
  * Stores a pointer to the ops struct, and the offset: the place to
  * write the parsed result in the destination structure.
-- 
1.9.3