get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 52744,
    "url": "http://patches.dpdk.org/api/patches/52744/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20190412135431.3308-2-lukaszx.gosiewski@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20190412135431.3308-2-lukaszx.gosiewski@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20190412135431.3308-2-lukaszx.gosiewski@intel.com",
    "date": "2019-04-12T13:54:30",
    "name": "[v2,1/2] power: add fifo per core for JSON interface",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "800c7828d902cd01d7b7593aa52fa192d14eeecb",
    "submitter": {
        "id": 1281,
        "url": "http://patches.dpdk.org/api/people/1281/?format=api",
        "name": "Lukasz Gosiewski",
        "email": "lukaszx.gosiewski@intel.com"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20190412135431.3308-2-lukaszx.gosiewski@intel.com/mbox/",
    "series": [
        {
            "id": 4298,
            "url": "http://patches.dpdk.org/api/series/4298/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=4298",
            "date": "2019-04-12T13:54:29",
            "name": "power: add fifo per core for JSON interface",
            "version": 2,
            "mbox": "http://patches.dpdk.org/series/4298/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/52744/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/52744/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 032027D05;\n\tSat, 13 Apr 2019 14:35:13 +0200 (CEST)",
            "from mga02.intel.com (mga02.intel.com [134.134.136.20])\n\tby dpdk.org (Postfix) with ESMTP id CAFD51B11F\n\tfor <dev@dpdk.org>; Fri, 12 Apr 2019 15:56:36 +0200 (CEST)",
            "from fmsmga002.fm.intel.com ([10.253.24.26])\n\tby orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t12 Apr 2019 06:56:34 -0700",
            "from lgosiewx-mobl.ger.corp.intel.com ([10.103.104.80])\n\tby fmsmga002.fm.intel.com with ESMTP; 12 Apr 2019 06:56:32 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.60,341,1549958400\"; d=\"scan'208\";a=\"160799620\"",
        "From": "Lukasz Gosiewski <lukaszx.gosiewski@intel.com>",
        "To": "david.hunt@intel.com",
        "Cc": "dev@dpdk.org, lukaszx.krakowiak@intel.com,\n\tLukasz Gosiewski <lukaszx.gosiewski@intel.com>",
        "Date": "Fri, 12 Apr 2019 15:54:30 +0200",
        "Message-Id": "<20190412135431.3308-2-lukaszx.gosiewski@intel.com>",
        "X-Mailer": "git-send-email 2.21.0.windows.1",
        "In-Reply-To": "<20190412135431.3308-1-lukaszx.gosiewski@intel.com>",
        "References": "<20190408104518.21960-1-lukaszx.krakowiak@intel.com>\n\t<20190412135431.3308-1-lukaszx.gosiewski@intel.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "X-Mailman-Approved-At": "Sat, 13 Apr 2019 14:35:08 +0200",
        "Subject": "[dpdk-dev] [PATCH v2 1/2] power: add fifo per core for JSON\n\tinterface",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "From: Lukasz Krakowiak <lukaszx.krakowiak@intel.com>\n\nThis patch implement a separate FIFO for each cpu core.\nFor proper handling JSON interface, removed fields from cmds:\ncore_list, resource_id, name.\n\n---\nv2:\n* updated handling vm_name (use proper buff size)\n* rebase to master changes\n\nSigned-off-by: Lukasz Krakowiak <lukaszx.krakowiak@intel.com>\nSigned-off-by: Lukasz Gosiewski <lukaszx.gosiewski@intel.com>\n---\n examples/vm_power_manager/channel_manager.c | 85 +++++++++++++------\n examples/vm_power_manager/channel_manager.h |  7 +-\n examples/vm_power_manager/channel_monitor.c | 91 +++++++++++++++------\n examples/vm_power_manager/main.c            |  2 +-\n 4 files changed, 129 insertions(+), 56 deletions(-)",
    "diff": "diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c\nindex 05c0eea44..d19276839 100644\n--- a/examples/vm_power_manager/channel_manager.c\n+++ b/examples/vm_power_manager/channel_manager.c\n@@ -346,10 +346,22 @@ setup_channel_info(struct virtual_machine_info **vm_info_dptr,\n \treturn 0;\n }\n \n-static void\n-fifo_path(char *dst, unsigned int len)\n+static int\n+fifo_path(char *dst, unsigned int len, unsigned int id)\n {\n-\tsnprintf(dst, len, \"%sfifo\", CHANNEL_MGR_SOCKET_PATH);\n+\tint cnt;\n+\n+\tcnt = snprintf(dst, len, \"%s%s%d\", CHANNEL_MGR_SOCKET_PATH,\n+\t\t\tCHANNEL_MGR_FIFO_PATTERN_NAME, id);\n+\n+\tif ((cnt < 0) || (cnt > (int)len - 1)) {\n+\t\tRTE_LOG(ERR, CHANNEL_MANAGER, \"Could not create proper \"\n+\t\t\t\"string for fifo path\\n\");\n+\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n }\n \n static int\n@@ -535,40 +547,59 @@ add_channels(const char *vm_name, unsigned *channel_list,\n }\n \n int\n-add_host_channel(void)\n+add_host_channels(void)\n {\n \tstruct channel_info *chan_info;\n \tchar socket_path[PATH_MAX];\n \tint num_channels_enabled = 0;\n \tint ret;\n+\tstruct core_info *ci;\n \n-\tfifo_path(socket_path, sizeof(socket_path));\n-\n-\tret = mkfifo(socket_path, 0660);\n-\tif ((errno != EEXIST) && (ret < 0)) {\n-\t\tRTE_LOG(ERR, CHANNEL_MANAGER, \"Cannot create fifo '%s' error: \"\n-\t\t\t\t\"%s\\n\", socket_path, strerror(errno));\n+\tci = get_core_info();\n+\tif (ci == NULL) {\n+\t\tRTE_LOG(ERR, CHANNEL_MANAGER, \"Cannot allocate memory for core_info\\n\");\n \t\treturn 0;\n \t}\n \n-\tif (access(socket_path, F_OK) < 0) {\n-\t\tRTE_LOG(ERR, CHANNEL_MANAGER, \"Channel path '%s' error: \"\n-\t\t\t\t\"%s\\n\", socket_path, strerror(errno));\n-\t\treturn 0;\n-\t}\n-\tchan_info = rte_malloc(NULL, sizeof(*chan_info), 0);\n-\tif (chan_info == NULL) {\n-\t\tRTE_LOG(ERR, CHANNEL_MANAGER, \"Error allocating memory for \"\n-\t\t\t\t\"channel '%s'\\n\", socket_path);\n-\t\treturn 0;\n-\t}\n-\trte_strlcpy(chan_info->channel_path, socket_path, UNIX_PATH_MAX);\n+\tdo {\n+\t\tif (ci->cd[num_channels_enabled].global_enabled_cpus == 0)\n+\t\t\tcontinue;\n \n-\tif (setup_host_channel_info(&chan_info, 0) < 0) {\n-\t\trte_free(chan_info);\n-\t\treturn 0;\n-\t}\n-\tnum_channels_enabled++;\n+\t\tret = fifo_path(socket_path, sizeof(socket_path),\n+\t\t\t\t\t\t\tnum_channels_enabled);\n+\t\tif (ret < 0)\n+\t\t\treturn 0;\n+\n+\t\tret = mkfifo(socket_path, 0660);\n+\t\tRTE_LOG(DEBUG, CHANNEL_MANAGER, \"TRY CREATE fifo '%s'\\n\",\n+\t\t\tsocket_path);\n+\t\tif ((errno != EEXIST) && (ret < 0)) {\n+\t\t\tRTE_LOG(ERR, CHANNEL_MANAGER, \"Cannot create fifo '%s' error: \"\n+\t\t\t\t\t\"%s\\n\", socket_path, strerror(errno));\n+\t\t\treturn 0;\n+\t\t}\n+\n+\t\tif (access(socket_path, F_OK) < 0) {\n+\t\t\tRTE_LOG(ERR, CHANNEL_MANAGER, \"Channel path '%s' error: \"\n+\t\t\t\t\t\"%s\\n\", socket_path, strerror(errno));\n+\t\t\treturn 0;\n+\t\t}\n+\t\tchan_info = rte_malloc(NULL, sizeof(*chan_info), 0);\n+\t\tif (chan_info == NULL) {\n+\t\t\tRTE_LOG(ERR, CHANNEL_MANAGER, \"Error allocating memory for \"\n+\t\t\t\t\t\"channel '%s'\\n\", socket_path);\n+\t\t\treturn 0;\n+\t\t}\n+\t\tsnprintf(chan_info->channel_path,\n+\t\t\tsizeof(chan_info->channel_path),\n+\t\t\t\"%s\", socket_path);\n+\n+\t\tif (setup_host_channel_info(&chan_info,\n+\t\t\tnum_channels_enabled) < 0) {\n+\t\t\trte_free(chan_info);\n+\t\t\treturn 0;\n+\t\t}\n+\t} while (++num_channels_enabled <= ci->core_count);\n \n \treturn num_channels_enabled;\n }\ndiff --git a/examples/vm_power_manager/channel_manager.h b/examples/vm_power_manager/channel_manager.h\nindex c3cdce492..7fddaf6a6 100644\n--- a/examples/vm_power_manager/channel_manager.h\n+++ b/examples/vm_power_manager/channel_manager.h\n@@ -28,6 +28,9 @@ extern \"C\" {\n /* File socket directory */\n #define CHANNEL_MGR_SOCKET_PATH     \"/tmp/powermonitor/\"\n \n+/* FIFO file name template */\n+#define CHANNEL_MGR_FIFO_PATTERN_NAME   \"fifo\"\n+\n #ifndef UNIX_PATH_MAX\n struct sockaddr_un _sockaddr_un;\n #define UNIX_PATH_MAX sizeof(_sockaddr_un.sun_path)\n@@ -212,13 +215,13 @@ int add_channels(const char *vm_name, unsigned *channel_list,\n \t\tunsigned num_channels);\n \n /**\n- * Set up a fifo by which host applications can send command an policies\n+ * Set up fifos by which host applications can send command an policies\n  * through a fifo to the vm_power_manager\n  *\n  * @return\n  *  - 0 for success\n  */\n-int add_host_channel(void);\n+int add_host_channels(void);\n \n /**\n  * Remove a channel definition from the channel manager. This must only be\ndiff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c\nindex 74df0fe20..41ee8671d 100644\n--- a/examples/vm_power_manager/channel_monitor.c\n+++ b/examples/vm_power_manager/channel_monitor.c\n@@ -29,6 +29,7 @@\n #include <rte_cycles.h>\n #include <rte_ethdev.h>\n #include <rte_pmd_i40e.h>\n+#include <rte_string_fns.h>\n \n #include <libvirt/libvirt.h>\n #include \"channel_monitor.h\"\n@@ -51,7 +52,7 @@ static volatile unsigned run_loop = 1;\n static int global_event_fd;\n static unsigned int policy_is_set;\n static struct epoll_event *global_events_list;\n-static struct policy policies[MAX_CLIENTS];\n+static struct policy policies[POWER_MGR_MAX_CPUS];\n \n #ifdef USE_JANSSON\n \n@@ -130,13 +131,45 @@ set_policy_mac(struct channel_packet *pkt, int idx, char *mac)\n \treturn 0;\n }\n \n+static char*\n+get_resource_name_from_chn_path(const char *channel_path)\n+{\n+\tchar *substr = NULL;\n+\n+\tsubstr = strstr(channel_path, CHANNEL_MGR_FIFO_PATTERN_NAME);\n+\n+\treturn substr;\n+}\n \n static int\n-parse_json_to_pkt(json_t *element, struct channel_packet *pkt)\n+get_resource_id_from_vmname(const char *vm_name)\n+{\n+\tint result = -1;\n+\tint off = 0;\n+\n+\tif (vm_name == NULL)\n+\t\treturn -1;\n+\n+\twhile (vm_name[off] != '\\0') {\n+\t\tif (isdigit(vm_name[off]))\n+\t\t\tbreak;\n+\t\toff++;\n+\t}\n+\tresult = atoi(&vm_name[off]);\n+\tif ((result == 0) && (vm_name[off] != '0'))\n+\t\treturn -1;\n+\n+\treturn result;\n+}\n+\n+static int\n+parse_json_to_pkt(json_t *element, struct channel_packet *pkt,\n+\t\t\t\t\tconst char *vm_name)\n {\n \tconst char *key;\n \tjson_t *value;\n \tint ret;\n+\tint resource_id;\n \n \tmemset(pkt, 0, sizeof(struct channel_packet));\n \n@@ -147,19 +180,23 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)\n \tpkt->command = PKT_POLICY;\n \tpkt->core_type = CORE_TYPE_PHYSICAL;\n \n+\tif (vm_name == NULL) {\n+\t\tRTE_LOG(ERR, CHANNEL_MONITOR,\n+\t\t\t\"vm_name is NULL, request rejected !\\n\");\n+\t\treturn -1;\n+\t}\n+\n \tjson_object_foreach(element, key, value) {\n \t\tif (!strcmp(key, \"policy\")) {\n \t\t\t/* Recurse in to get the contents of profile */\n-\t\t\tret = parse_json_to_pkt(value, pkt);\n+\t\t\tret = parse_json_to_pkt(value, pkt, vm_name);\n \t\t\tif (ret)\n \t\t\t\treturn ret;\n \t\t} else if (!strcmp(key, \"instruction\")) {\n \t\t\t/* Recurse in to get the contents of instruction */\n-\t\t\tret = parse_json_to_pkt(value, pkt);\n+\t\t\tret = parse_json_to_pkt(value, pkt, vm_name);\n \t\t\tif (ret)\n \t\t\t\treturn ret;\n-\t\t} else if (!strcmp(key, \"name\")) {\n-\t\t\tstrcpy(pkt->vm_name, json_string_value(value));\n \t\t} else if (!strcmp(key, \"command\")) {\n \t\t\tchar command[32];\n \t\t\tstrlcpy(command, json_string_value(value), 32);\n@@ -222,16 +259,6 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)\n \t\t\t\t\t\tjson_array_get(value, i));\n \t\t\t\tpkt->timer_policy.quiet_hours[i] = hour;\n \t\t\t}\n-\t\t} else if (!strcmp(key, \"core_list\")) {\n-\t\t\tunsigned int i;\n-\t\t\tsize_t size = json_array_size(value);\n-\n-\t\t\tfor (i = 0; i < size; i++) {\n-\t\t\t\tint core = (int)json_integer_value(\n-\t\t\t\t\t\tjson_array_get(value, i));\n-\t\t\t\tpkt->vcpu_to_control[i] = core;\n-\t\t\t}\n-\t\t\tpkt->num_vcpu = size;\n \t\t} else if (!strcmp(key, \"mac_list\")) {\n \t\t\tunsigned int i;\n \t\t\tsize_t size = json_array_size(value);\n@@ -270,13 +297,21 @@ parse_json_to_pkt(json_t *element, struct channel_packet *pkt)\n \t\t\t\t\t\"Invalid command received in JSON\\n\");\n \t\t\t\treturn -1;\n \t\t\t}\n-\t\t} else if (!strcmp(key, \"resource_id\")) {\n-\t\t\tpkt->resource_id = (uint32_t)json_integer_value(value);\n \t\t} else {\n \t\t\tRTE_LOG(ERR, CHANNEL_MONITOR,\n \t\t\t\t\"Unknown key received in JSON string: %s\\n\",\n \t\t\t\tkey);\n \t\t}\n+\n+\t\tresource_id = get_resource_id_from_vmname(vm_name);\n+\t\tif (resource_id < 0) {\n+\t\t\tRTE_LOG(ERR, CHANNEL_MONITOR,\n+\t\t\t\t\"Could not get resource_id from vm_name:%s\\n\",\n+\t\t\t\tvm_name);\n+\t\t\treturn -1;\n+\t\t}\n+\t\trte_strlcpy(pkt->vm_name, vm_name, VM_MAX_NAME_SZ);\n+\t\tpkt->resource_id = resource_id;\n \t}\n \treturn 0;\n }\n@@ -426,13 +461,13 @@ update_policy(struct channel_packet *pkt)\n {\n \n \tunsigned int updated = 0;\n-\tint i;\n+\tunsigned int i;\n \n \n \tRTE_LOG(INFO, CHANNEL_MONITOR,\n \t\t\t\"Applying policy for %s\\n\", pkt->vm_name);\n \n-\tfor (i = 0; i < MAX_CLIENTS; i++) {\n+\tfor (i = 0; i < RTE_DIM(policies); i++) {\n \t\tif (strcmp(policies[i].pkt.vm_name, pkt->vm_name) == 0) {\n \t\t\t/* Copy the contents of *pkt into the policy.pkt */\n \t\t\tpolicies[i].pkt = *pkt;\n@@ -447,7 +482,7 @@ update_policy(struct channel_packet *pkt)\n \t\t}\n \t}\n \tif (!updated) {\n-\t\tfor (i = 0; i < MAX_CLIENTS; i++) {\n+\t\tfor (i = 0; i < RTE_DIM(policies); i++) {\n \t\t\tif (policies[i].enabled == 0) {\n \t\t\t\tpolicies[i].pkt = *pkt;\n \t\t\t\tget_pcpu_to_control(&policies[i]);\n@@ -465,13 +500,13 @@ update_policy(struct channel_packet *pkt)\n static int\n remove_policy(struct channel_packet *pkt __rte_unused)\n {\n-\tint i;\n+\tunsigned int i;\n \n \t/*\n \t * Disabling the policy is simply a case of setting\n \t * enabled to 0\n \t */\n-\tfor (i = 0; i < MAX_CLIENTS; i++) {\n+\tfor (i = 0; i < RTE_DIM(policies); i++) {\n \t\tif (strcmp(policies[i].pkt.vm_name, pkt->vm_name) == 0) {\n \t\t\tpolicies[i].enabled = 0;\n \t\t\treturn 0;\n@@ -792,6 +827,8 @@ read_json_packet(struct channel_info *chan_info)\n \tint n_bytes, ret;\n \tjson_t *root;\n \tjson_error_t error;\n+\tconst char *resource_name;\n+\n \n \t/* read opening brace to closing brace */\n \tdo {\n@@ -828,13 +865,15 @@ read_json_packet(struct channel_info *chan_info)\n \t\troot = json_loads(json_data, 0, &error);\n \n \t\tif (root) {\n+\t\t\tresource_name = get_resource_name_from_chn_path(\n+\t\t\t\tchan_info->channel_path);\n \t\t\t/*\n \t\t\t * Because our data is now in the json\n \t\t\t * object, we can overwrite the pkt\n \t\t\t * with a channel_packet struct, using\n \t\t\t * parse_json_to_pkt()\n \t\t\t */\n-\t\t\tret = parse_json_to_pkt(root, &pkt);\n+\t\t\tret = parse_json_to_pkt(root, &pkt, resource_name);\n \t\t\tjson_decref(root);\n \t\t\tif (ret) {\n \t\t\t\tRTE_LOG(ERR, CHANNEL_MONITOR,\n@@ -891,9 +930,9 @@ run_channel_monitor(void)\n \t\t}\n \t\trte_delay_us(time_period_ms*1000);\n \t\tif (policy_is_set) {\n-\t\t\tint j;\n+\t\t\tunsigned int j;\n \n-\t\t\tfor (j = 0; j < MAX_CLIENTS; j++) {\n+\t\t\tfor (j = 0; j < RTE_DIM(policies); j++) {\n \t\t\t\tif (policies[j].enabled == 1)\n \t\t\t\t\tapply_policy(&policies[j]);\n \t\t\t}\ndiff --git a/examples/vm_power_manager/main.c b/examples/vm_power_manager/main.c\nindex 893bf4cdd..9f24cf69b 100644\n--- a/examples/vm_power_manager/main.c\n+++ b/examples/vm_power_manager/main.c\n@@ -421,7 +421,7 @@ main(int argc, char **argv)\n \t\treturn -1;\n \t}\n \n-\tadd_host_channel();\n+\tadd_host_channels();\n \n \tprintf(\"Running core monitor on lcore id %d\\n\", lcore_id);\n \trte_eal_remote_launch(run_core_monitor, NULL, lcore_id);\n",
    "prefixes": [
        "v2",
        "1/2"
    ]
}