From: Hajkowski <marcinx.hajkowski@intel.com>
To: david.hunt@intel.com
Cc: dev@dpdk.org, Marcin Hajkowski <marcinx.hajkowski@intel.com>,
Lukasz Krakowiak <lukaszx.krakowiak@intel.com>,
Lukasz Gosiewski <lukaszx.gosiewski@intel.com>
Subject: [dpdk-dev] [PATCH v4 1/2] power: add fifo per core for JSON interface
Date: Thu, 13 Jun 2019 11:21:16 +0200 [thread overview]
Message-ID: <20190613092117.7252-2-marcinx.hajkowski@intel.com> (raw)
In-Reply-To: <20190613092117.7252-1-marcinx.hajkowski@intel.com>
From: Marcin Hajkowski <marcinx.hajkowski@intel.com>
This patch implement a separate FIFO for each cpu core.
For proper handling JSON interface, removed fields from cmds:
core_list, resource_id, name.
Signed-off-by: Lukasz Krakowiak <lukaszx.krakowiak@intel.com>
Signed-off-by: Lukasz Gosiewski <lukaszx.gosiewski@intel.com>
Signed-off-by: Marcin Hajkowski <marcinx.hajkowski@intel.com>
---
examples/vm_power_manager/channel_manager.c | 84 +++++++++++++------
examples/vm_power_manager/channel_manager.h | 7 +-
examples/vm_power_manager/channel_monitor.c | 92 +++++++++++++++------
examples/vm_power_manager/main.c | 2 +-
4 files changed, 128 insertions(+), 57 deletions(-)
diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c
index 81bdf1b84..1a1379bfc 100644
--- a/examples/vm_power_manager/channel_manager.c
+++ b/examples/vm_power_manager/channel_manager.c
@@ -346,10 +346,22 @@ setup_channel_info(struct virtual_machine_info **vm_info_dptr,
return 0;
}
-static void
-fifo_path(char *dst, unsigned int len)
+static int
+fifo_path(char *dst, unsigned int len, unsigned int id)
{
- snprintf(dst, len, "%sfifo", CHANNEL_MGR_SOCKET_PATH);
+ int cnt;
+
+ cnt = snprintf(dst, len, "%s%s%d", CHANNEL_MGR_SOCKET_PATH,
+ CHANNEL_MGR_FIFO_PATTERN_NAME, id);
+
+ if ((cnt < 0) || (cnt > (int)len - 1)) {
+ RTE_LOG(ERR, CHANNEL_MANAGER, "Could not create proper "
+ "string for fifo path\n");
+
+ return -1;
+ }
+
+ return 0;
}
static int
@@ -535,40 +547,58 @@ add_channels(const char *vm_name, unsigned *channel_list,
}
int
-add_host_channel(void)
+add_host_channels(void)
{
struct channel_info *chan_info;
char socket_path[PATH_MAX];
int num_channels_enabled = 0;
int ret;
+ struct core_info *ci;
- fifo_path(socket_path, sizeof(socket_path));
-
- ret = mkfifo(socket_path, 0660);
- if ((errno != EEXIST) && (ret < 0)) {
- RTE_LOG(ERR, CHANNEL_MANAGER, "Cannot create fifo '%s' error: "
- "%s\n", socket_path, strerror(errno));
+ ci = get_core_info();
+ if (ci == NULL) {
+ RTE_LOG(ERR, CHANNEL_MANAGER, "Cannot allocate memory for core_info\n");
return 0;
}
- if (access(socket_path, F_OK) < 0) {
- RTE_LOG(ERR, CHANNEL_MANAGER, "Channel path '%s' error: "
- "%s\n", socket_path, strerror(errno));
- return 0;
- }
- chan_info = rte_malloc(NULL, sizeof(*chan_info), 0);
- if (chan_info == NULL) {
- RTE_LOG(ERR, CHANNEL_MANAGER, "Error allocating memory for "
- "channel '%s'\n", socket_path);
- return 0;
- }
- rte_strlcpy(chan_info->channel_path, socket_path, UNIX_PATH_MAX);
+ do {
+ if (ci->cd[num_channels_enabled].global_enabled_cpus == 0)
+ continue;
- if (setup_host_channel_info(&chan_info, 0) < 0) {
- rte_free(chan_info);
- return 0;
- }
- num_channels_enabled++;
+ ret = fifo_path(socket_path, sizeof(socket_path),
+ num_channels_enabled);
+ if (ret < 0)
+ return 0;
+
+ ret = mkfifo(socket_path, 0660);
+ RTE_LOG(DEBUG, CHANNEL_MANAGER, "TRY CREATE fifo '%s'\n",
+ socket_path);
+ if ((errno != EEXIST) && (ret < 0)) {
+ RTE_LOG(ERR, CHANNEL_MANAGER, "Cannot create fifo '%s' error: "
+ "%s\n", socket_path, strerror(errno));
+ return 0;
+ }
+
+ if (access(socket_path, F_OK) < 0) {
+ RTE_LOG(ERR, CHANNEL_MANAGER, "Channel path '%s' error: "
+ "%s\n", socket_path, strerror(errno));
+ return 0;
+ }
+ chan_info = rte_malloc(NULL, sizeof(*chan_info), 0);
+ if (chan_info == NULL) {
+ RTE_LOG(ERR, CHANNEL_MANAGER, "Error allocating memory for "
+ "channel '%s'\n", socket_path);
+ return 0;
+ }
+ strlcpy(chan_info->channel_path, socket_path,
+ sizeof(chan_info->channel_path));
+
+ if (setup_host_channel_info(&chan_info,
+ num_channels_enabled) < 0) {
+ rte_free(chan_info);
+ return 0;
+ }
+ } while (++num_channels_enabled <= ci->core_count);
return num_channels_enabled;
}
diff --git a/examples/vm_power_manager/channel_manager.h b/examples/vm_power_manager/channel_manager.h
index 251d2163c..3766e93c8 100644
--- a/examples/vm_power_manager/channel_manager.h
+++ b/examples/vm_power_manager/channel_manager.h
@@ -22,6 +22,9 @@ extern "C" {
/* File socket directory */
#define CHANNEL_MGR_SOCKET_PATH "/tmp/powermonitor/"
+/* FIFO file name template */
+#define CHANNEL_MGR_FIFO_PATTERN_NAME "fifo"
+
#ifndef UNIX_PATH_MAX
struct sockaddr_un _sockaddr_un;
#define UNIX_PATH_MAX sizeof(_sockaddr_un.sun_path)
@@ -206,13 +209,13 @@ int add_channels(const char *vm_name, unsigned *channel_list,
unsigned num_channels);
/**
- * Set up a fifo by which host applications can send command an policies
+ * Set up fifos by which host applications can send command an policies
* through a fifo to the vm_power_manager
*
* @return
* - 0 for success
*/
-int add_host_channel(void);
+int add_host_channels(void);
/**
* Remove a channel definition from the channel manager. This must only be
diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c
index aab19ba57..b9a326e7d 100644
--- a/examples/vm_power_manager/channel_monitor.c
+++ b/examples/vm_power_manager/channel_monitor.c
@@ -29,6 +29,7 @@
#include <rte_cycles.h>
#include <rte_ethdev.h>
#include <rte_pmd_i40e.h>
+#include <rte_string_fns.h>
#include <libvirt/libvirt.h>
#include "channel_monitor.h"
@@ -51,7 +52,7 @@ static volatile unsigned run_loop = 1;
static int global_event_fd;
static unsigned int policy_is_set;
static struct epoll_event *global_events_list;
-static struct policy policies[MAX_CLIENTS];
+static struct policy policies[RTE_MAX_LCORE];
#ifdef USE_JANSSON
@@ -130,13 +131,45 @@ set_policy_mac(struct channel_packet *pkt, int idx, char *mac)
return 0;
}
+static char*
+get_resource_name_from_chn_path(const char *channel_path)
+{
+ char *substr = NULL;
+
+ substr = strstr(channel_path, CHANNEL_MGR_FIFO_PATTERN_NAME);
+
+ return substr;
+}
static int
-parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
+get_resource_id_from_vmname(const char *vm_name)
+{
+ int result = -1;
+ int off = 0;
+
+ if (vm_name == NULL)
+ return -1;
+
+ while (vm_name[off] != '\0') {
+ if (isdigit(vm_name[off]))
+ break;
+ off++;
+ }
+ result = atoi(&vm_name[off]);
+ if ((result == 0) && (vm_name[off] != '0'))
+ return -1;
+
+ return result;
+}
+
+static int
+parse_json_to_pkt(json_t *element, struct channel_packet *pkt,
+ const char *vm_name)
{
const char *key;
json_t *value;
int ret;
+ int resource_id;
memset(pkt, 0, sizeof(struct channel_packet));
@@ -147,20 +180,23 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
pkt->command = PKT_POLICY;
pkt->core_type = CORE_TYPE_PHYSICAL;
+ if (vm_name == NULL) {
+ RTE_LOG(ERR, CHANNEL_MONITOR,
+ "vm_name is NULL, request rejected !\n");
+ return -1;
+ }
+
json_object_foreach(element, key, value) {
if (!strcmp(key, "policy")) {
/* Recurse in to get the contents of profile */
- ret = parse_json_to_pkt(value, pkt);
+ ret = parse_json_to_pkt(value, pkt, vm_name);
if (ret)
return ret;
} else if (!strcmp(key, "instruction")) {
/* Recurse in to get the contents of instruction */
- ret = parse_json_to_pkt(value, pkt);
+ ret = parse_json_to_pkt(value, pkt, vm_name);
if (ret)
return ret;
- } else if (!strcmp(key, "name")) {
- strlcpy(pkt->vm_name, json_string_value(value),
- sizeof(pkt->vm_name));
} else if (!strcmp(key, "command")) {
char command[32];
strlcpy(command, json_string_value(value), 32);
@@ -223,16 +259,6 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
json_array_get(value, i));
pkt->timer_policy.quiet_hours[i] = hour;
}
- } else if (!strcmp(key, "core_list")) {
- unsigned int i;
- size_t size = json_array_size(value);
-
- for (i = 0; i < size; i++) {
- int core = (int)json_integer_value(
- json_array_get(value, i));
- pkt->vcpu_to_control[i] = core;
- }
- pkt->num_vcpu = size;
} else if (!strcmp(key, "mac_list")) {
unsigned int i;
size_t size = json_array_size(value);
@@ -271,13 +297,21 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)
"Invalid command received in JSON\n");
return -1;
}
- } else if (!strcmp(key, "resource_id")) {
- pkt->resource_id = (uint32_t)json_integer_value(value);
} else {
RTE_LOG(ERR, CHANNEL_MONITOR,
"Unknown key received in JSON string: %s\n",
key);
}
+
+ resource_id = get_resource_id_from_vmname(vm_name);
+ if (resource_id < 0) {
+ RTE_LOG(ERR, CHANNEL_MONITOR,
+ "Could not get resource_id from vm_name:%s\n",
+ vm_name);
+ return -1;
+ }
+ rte_strlcpy(pkt->vm_name, vm_name, VM_MAX_NAME_SZ);
+ pkt->resource_id = resource_id;
}
return 0;
}
@@ -427,13 +461,13 @@ update_policy(struct channel_packet *pkt)
{
unsigned int updated = 0;
- int i;
+ unsigned int i;
RTE_LOG(INFO, CHANNEL_MONITOR,
"Applying policy for %s\n", pkt->vm_name);
- for (i = 0; i < MAX_CLIENTS; i++) {
+ for (i = 0; i < RTE_DIM(policies); i++) {
if (strcmp(policies[i].pkt.vm_name, pkt->vm_name) == 0) {
/* Copy the contents of *pkt into the policy.pkt */
policies[i].pkt = *pkt;
@@ -451,7 +485,7 @@ update_policy(struct channel_packet *pkt)
}
}
if (!updated) {
- for (i = 0; i < MAX_CLIENTS; i++) {
+ for (i = 0; i < RTE_DIM(policies); i++) {
if (policies[i].enabled == 0) {
policies[i].pkt = *pkt;
get_pcpu_to_control(&policies[i]);
@@ -474,13 +508,13 @@ update_policy(struct channel_packet *pkt)
static int
remove_policy(struct channel_packet *pkt __rte_unused)
{
- int i;
+ unsigned int i;
/*
* Disabling the policy is simply a case of setting
* enabled to 0
*/
- for (i = 0; i < MAX_CLIENTS; i++) {
+ for (i = 0; i < RTE_DIM(policies); i++) {
if (strcmp(policies[i].pkt.vm_name, pkt->vm_name) == 0) {
policies[i].enabled = 0;
return 0;
@@ -801,6 +835,8 @@ read_json_packet(struct channel_info *chan_info)
int n_bytes, ret;
json_t *root;
json_error_t error;
+ const char *resource_name;
+
/* read opening brace to closing brace */
do {
@@ -832,13 +868,15 @@ read_json_packet(struct channel_info *chan_info)
root = json_loads(json_data, 0, &error);
if (root) {
+ resource_name = get_resource_name_from_chn_path(
+ chan_info->channel_path);
/*
* Because our data is now in the json
* object, we can overwrite the pkt
* with a channel_packet struct, using
* parse_json_to_pkt()
*/
- ret = parse_json_to_pkt(root, &pkt);
+ ret = parse_json_to_pkt(root, &pkt, resource_name);
json_decref(root);
if (ret) {
RTE_LOG(ERR, CHANNEL_MONITOR,
@@ -895,9 +933,9 @@ run_channel_monitor(void)
}
rte_delay_us(time_period_ms*1000);
if (policy_is_set) {
- int j;
+ unsigned int j;
- for (j = 0; j < MAX_CLIENTS; j++) {
+ for (j = 0; j < RTE_DIM(policies); j++) {
if (policies[j].enabled == 1)
apply_policy(&policies[j]);
}
diff --git a/examples/vm_power_manager/main.c b/examples/vm_power_manager/main.c
index bc15cb64e..54c704610 100644
--- a/examples/vm_power_manager/main.c
+++ b/examples/vm_power_manager/main.c
@@ -434,7 +434,7 @@ main(int argc, char **argv)
return -1;
}
- add_host_channel();
+ add_host_channels();
printf("Running core monitor on lcore id %d\n", lcore_id);
rte_eal_remote_launch(run_core_monitor, NULL, lcore_id);
--
2.17.2
next prev parent reply other threads:[~2019-06-13 9:23 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-08 10:45 [dpdk-dev] [PATCH 0/2] " Lukasz Krakowiak
2019-04-08 10:45 ` Lukasz Krakowiak
2019-04-08 10:45 ` [dpdk-dev] [PATCH 1/2] " Lukasz Krakowiak
2019-04-08 10:45 ` Lukasz Krakowiak
2019-04-08 10:45 ` [dpdk-dev] [PATCH 2/2] doc: update according to the fifo per core impl Lukasz Krakowiak
2019-04-08 10:45 ` Lukasz Krakowiak
2019-04-12 13:54 ` [dpdk-dev] [PATCH v2 0/2] power: add fifo per core for JSON interface Lukasz Gosiewski
2019-04-12 13:54 ` Lukasz Gosiewski
2019-04-12 13:54 ` [dpdk-dev] [PATCH v2 1/2] " Lukasz Gosiewski
2019-04-12 13:54 ` Lukasz Gosiewski
2019-04-12 13:54 ` [dpdk-dev] [PATCH v2 2/2] doc: update according to the fifo per core impl Lukasz Gosiewski
2019-04-12 13:54 ` Lukasz Gosiewski
2019-04-22 20:37 ` [dpdk-dev] [PATCH v2 0/2] power: add fifo per core for JSON interface Thomas Monjalon
2019-04-22 20:37 ` Thomas Monjalon
2019-04-24 8:21 ` [dpdk-dev] [PATCH v3 0/2] " Lukasz Gosiewski
2019-04-24 8:21 ` Lukasz Gosiewski
2019-04-24 8:21 ` [dpdk-dev] [PATCH v3 1/2] power: " Lukasz Gosiewski
2019-04-24 8:21 ` Lukasz Gosiewski
2019-06-07 8:26 ` Hajkowski, MarcinX
2019-04-24 8:21 ` [dpdk-dev] [PATCH v3 2/2] doc: update according to the fifo per core impl Lukasz Gosiewski
2019-04-24 8:21 ` Lukasz Gosiewski
2019-06-13 9:21 ` [dpdk-dev] [PATCH v4 0/2] Fifo per core Hajkowski
2019-06-13 9:21 ` Hajkowski [this message]
2019-07-08 13:44 ` [dpdk-dev] [PATCH v4 1/2] power: add fifo per core for JSON interface Burakov, Anatoly
2019-07-09 15:07 ` [dpdk-dev] [PATCH v5] " David Hunt
2019-07-09 15:12 ` Burakov, Anatoly
2019-07-09 15:23 ` Hunt, David
2019-07-09 15:21 ` [dpdk-dev] [PATCH v6] " David Hunt
2019-07-09 15:27 ` Hunt, David
2019-07-09 15:38 ` Thomas Monjalon
2019-07-10 21:55 ` Thomas Monjalon
2019-06-13 9:21 ` [dpdk-dev] [PATCH v4 2/2] doc: update according to the fifo per core impl Hajkowski
2019-07-08 13:34 ` Burakov, Anatoly
2019-07-08 15:46 ` Hunt, David
2019-07-04 20:09 ` [dpdk-dev] [PATCH v4 0/2] Fifo per core Thomas Monjalon
2019-06-07 8:50 ` [dpdk-dev] [PATCH 0/2] power: add fifo per core for JSON interface Hajkowski, MarcinX
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190613092117.7252-2-marcinx.hajkowski@intel.com \
--to=marcinx.hajkowski@intel.com \
--cc=david.hunt@intel.com \
--cc=dev@dpdk.org \
--cc=lukaszx.gosiewski@intel.com \
--cc=lukaszx.krakowiak@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).