get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 27998,
    "url": "https://patches.dpdk.org/api/patches/27998/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1503676941-80981-7-git-send-email-david.hunt@intel.com/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1503676941-80981-7-git-send-email-david.hunt@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1503676941-80981-7-git-send-email-david.hunt@intel.com",
    "date": "2017-08-25T16:02:17",
    "name": "[dpdk-dev,v1,06/10] examples/vm_power_mgr: add policy to channels",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "00773fed92d653af1e319aa4739a54ae21f83df0",
    "submitter": {
        "id": 342,
        "url": "https://patches.dpdk.org/api/people/342/?format=api",
        "name": "Hunt, David",
        "email": "david.hunt@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1503676941-80981-7-git-send-email-david.hunt@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/27998/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/27998/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id B4BFA8C7E;\n\tFri, 25 Aug 2017 18:02:43 +0200 (CEST)",
            "from mga04.intel.com (mga04.intel.com [192.55.52.120])\n\tby dpdk.org (Postfix) with ESMTP id E37FD7D63\n\tfor <dev@dpdk.org>; Fri, 25 Aug 2017 18:02:35 +0200 (CEST)",
            "from fmsmga001.fm.intel.com ([10.253.24.23])\n\tby fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t25 Aug 2017 09:02:35 -0700",
            "from silpixa00397898.ir.intel.com (HELO\n\tsilpixa00397898.ger.corp.intel.com) ([10.237.223.116])\n\tby fmsmga001.fm.intel.com with ESMTP; 25 Aug 2017 09:02:33 -0700"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos; i=\"5.41,426,1498546800\"; d=\"scan'208\";\n\ta=\"1188144577\"",
        "From": "David Hunt <david.hunt@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "David Hunt <david.hunt@intel.com>,\n\tNemanja Marjanovic <nemanja.marjanovic@intel.com>,\n\tRory Sexton <rory.sexton@intel.com>",
        "Date": "Fri, 25 Aug 2017 17:02:17 +0100",
        "Message-Id": "<1503676941-80981-7-git-send-email-david.hunt@intel.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1503676941-80981-1-git-send-email-david.hunt@intel.com>",
        "References": "<1503676941-80981-1-git-send-email-david.hunt@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v1 06/10] examples/vm_power_mgr: add policy to\n\tchannels",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Signed-off-by: Nemanja Marjanovic <nemanja.marjanovic@intel.com>\nSigned-off-by: Rory Sexton <rory.sexton@intel.com>\nSigned-off-by: David Hunt <david.hunt@intel.com>\n---\n examples/vm_power_manager/channel_monitor.c | 302 +++++++++++++++++++++++++++-\n examples/vm_power_manager/channel_monitor.h |  18 ++\n 2 files changed, 312 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/examples/vm_power_manager/channel_monitor.c b/examples/vm_power_manager/channel_monitor.c\nindex e7f5cc4..94fa03c 100644\n--- a/examples/vm_power_manager/channel_monitor.c\n+++ b/examples/vm_power_manager/channel_monitor.c\n@@ -41,13 +41,16 @@\n #include <sys/types.h>\n #include <sys/epoll.h>\n #include <sys/queue.h>\n+#include <sys/time.h>\n \n #include <rte_log.h>\n #include <rte_memory.h>\n #include <rte_malloc.h>\n #include <rte_atomic.h>\n+#include <rte_cycles.h>\n+#include <rte_ethdev.h>\n \n-\n+#include <libvirt/libvirt.h>\n #include \"channel_monitor.h\"\n #include \"channel_commands.h\"\n #include \"channel_manager.h\"\n@@ -57,10 +60,15 @@\n \n #define MAX_EVENTS 256\n \n-\n+uint64_t vsi_pkt_count_prev[384];\n+uint64_t rdtsc_prev[384];\n+double time_period_s = 1;\n+double cpu_tsc_hz = 2200000000;\n 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_VMS];\n \n void channel_monitor_exit(void)\n {\n@@ -68,6 +76,266 @@ void channel_monitor_exit(void)\n \trte_free(global_events_list);\n }\n \n+static void\n+core_share(int pNo, int z, int x, int t)\n+{\n+\tif (policies[pNo].core_share[z].pcpu == lvm_info[x].pcpus[t]) {\n+\t\tif (strcmp(policies[pNo].pkt.vm_name,\n+\t\t\t\tlvm_info[x].vm_name) != 0) {\n+\t\t\tpolicies[pNo].core_share[z].status = 1;\n+\t\t\tpower_manager_scale_core_max(\n+\t\t\t\t\tpolicies[pNo].core_share[z].pcpu);\n+\t\t}\n+\t}\n+}\n+\n+static void\n+core_share_status(int pNo) {\n+\n+\tint noVms, noVcpus, z, x, t;\n+\n+\tget_all_vm(&noVms, &noVcpus);\n+\n+\t/* Reset Core Share Status. */\n+\tfor (z = 0; z < noVcpus; z++)\n+\t\tpolicies[pNo].core_share[z].status = 0;\n+\n+\t/* Foreach vcpu in a policy. */\n+\tfor (z = 0; z < noVcpus; z++) {\n+\t\t/* Foreach VM on the platform. */\n+\t\tfor (x = 0; x < noVms; x++) {\n+\t\t\t/* Foreach vcpu of VMs on platform. */\n+\t\t\tfor (t = 0; t < noVcpus; t++)\n+\t\t\t\tcore_share(pNo, z, x, t);\n+\t\t}\n+\t}\n+}\n+\n+static void\n+get_pcpu_to_control(struct policy *pol) {\n+\n+\t/* Convert vcpu to pcpu. */\n+\tstruct vm_info info;\n+\tint pcpu, count;\n+\tuint64_t mask_u64b;\n+\n+\tprintf(\"Looking for pcpu for %s\\n\", pol->pkt.vm_name);\n+\tget_info_vm(pol->pkt.vm_name, &info);\n+\n+\tfor (count = 0; count < 2; count++) {\n+\t\tmask_u64b = info.pcpu_mask[pol->pkt.vcpu_to_control[count]];\n+\t\tfor (pcpu = 0; mask_u64b; mask_u64b &= ~(1ULL << pcpu++)) {\n+\t\t\tif ((mask_u64b >> pcpu) & 1)\n+\t\t\t\tpol->core_share[count].pcpu = pcpu;\n+\t\t}\n+\t}\n+}\n+\n+static int\n+get_pfid(struct policy *pol) {\n+\n+\tint i, x, ret = 0, nb_ports;\n+\n+\tnb_ports = rte_eth_dev_count();\n+\tfor (i = 0; i < pol->pkt.nb_mac_to_monitor; i++) {\n+\n+\t\tfor (x = 0; x < nb_ports; x++) {\n+\t\t\tret = vfid_to_pfid_direct(x, pol->pkt.vfid[i]);\n+\t\t\tif (ret != -1) {\n+\t\t\t\tpol->port[i] = x;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\tif (ret == -1) {\n+\t\t\tRTE_LOG(ERR, CHANNEL_MONITOR,\n+\t\t\t\t\"Error with Policy. MAC not found on \"\n+\t\t\t\t\"attached ports \");\n+\t\t\tpol->enabled = 0;\n+\t\t\treturn ret;\n+\t\t}\n+\t\tpol->pfid[i] = ret;\n+\t}\n+\treturn 1;\n+}\n+\n+static int\n+update_policy(struct channel_packet *pkt) {\n+\n+\tunsigned int updated = 0;\n+\n+\tfor (int i = 0; i < MAX_VMS; i++) {\n+\t\tif (strcmp(policies[i].pkt.vm_name, pkt->vm_name) == 0) {\n+\t\t\tpolicies[i].pkt = *pkt;\n+\t\t\tget_pcpu_to_control(&policies[i]);\n+\t\t\tif (get_pfid(&policies[i]) == -1) {\n+\t\t\t\tupdated = 1;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tcore_share_status(i);\n+\t\t\tpolicies[i].enabled = 1;\n+\t\t\tupdated = 1;\n+\t\t}\n+\t}\n+\tif (!updated) {\n+\t\tfor (int i = 0; i < MAX_VMS; 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+\t\t\t\tif (get_pfid(&policies[i]) == -1)\n+\t\t\t\t\tbreak;\n+\t\t\t\tcore_share_status(i);\n+\t\t\t\tpolicies[i].enabled = 1;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn 0;\n+}\n+\n+static uint64_t\n+get_pkt_diff(struct policy *pol) {\n+\n+\tuint64_t vsi_pkt_count,\n+\t\tvsi_pkt_total = 0,\n+\t\tvsi_pkt_count_prev_total = 0;\n+\tdouble rdtsc_curr, rdtsc_diff, diff;\n+\tint x;\n+\n+\tfor (x = 0; x < pol->pkt.nb_mac_to_monitor; x++) {\n+\n+\t\t/*Read vsi stats*/\n+\t\tvsi_pkt_count = read_pf_stats_direct(x, pol->pfid[x]);\n+\t\tvsi_pkt_total += vsi_pkt_count;\n+\n+\t\tvsi_pkt_count_prev_total += vsi_pkt_count_prev[pol->pfid[x]];\n+\t\tvsi_pkt_count_prev[pol->pfid[x]] = vsi_pkt_count;\n+\t}\n+\n+\trdtsc_curr = rte_rdtsc_precise();\n+\trdtsc_diff = rdtsc_curr - rdtsc_prev[pol->pfid[x-1]];\n+\trdtsc_prev[pol->pfid[x-1]] = rdtsc_curr;\n+\n+\tdiff = (vsi_pkt_total - vsi_pkt_count_prev_total) *\n+\t\t\t(cpu_tsc_hz / rdtsc_diff);\n+\n+\treturn diff;\n+}\n+\n+static void\n+apply_traffic_profile(struct policy *pol) {\n+\n+\tint count;\n+\tuint64_t diff = 0;\n+\n+\tdiff = get_pkt_diff(pol);\n+\n+\tprintf(\"Applying traffic profile\\n\");\n+\n+\tif (diff >= (pol->pkt.traffic_policy.max_max_packet_thresh)) {\n+\t\tfor (count = 0; count < 2; count++) {\n+\t\t\tif (pol->core_share[count].status != 1)\n+\t\t\t\tpower_manager_scale_core_max(\n+\t\t\t\t\t\tpol->core_share[count].pcpu);\n+\t\t}\n+\t} else if (diff >= (pol->pkt.traffic_policy.avg_max_packet_thresh)) {\n+\t\tfor (count = 0; count < 2; count++) {\n+\t\t\tif (pol->core_share[count].status != 1)\n+\t\t\t\tpower_manager_scale_core_med(\n+\t\t\t\t\t\tpol->core_share[count].pcpu);\n+\t\t}\n+\t} else if (diff < (pol->pkt.traffic_policy.avg_max_packet_thresh)) {\n+\t\tfor (count = 0; count < 2; count++) {\n+\t\t\tif (pol->core_share[count].status != 1)\n+\t\t\t\tpower_manager_scale_core_min(\n+\t\t\t\t\t\tpol->core_share[count].pcpu);\n+\t\t}\n+\t}\n+}\n+\n+static void\n+apply_time_profile(struct policy *pol) {\n+\n+\tint count, x;\n+\tstruct timeval tv;\n+\tstruct tm *ptm;\n+\tchar time_string[40];\n+\n+\t/* Obtain the time of day, and convert it to a tm struct. */\n+\tgettimeofday(&tv, NULL);\n+\tptm = localtime(&tv.tv_sec);\n+\t/* Format the date and time, down to a single second. */\n+\tstrftime(time_string, sizeof(time_string), \"%Y-%m-%d %H:%M:%S\", ptm);\n+\n+\tfor (x = 0; x < HOURS; x++) {\n+\n+\t\tif (ptm->tm_hour == pol->pkt.timer_policy.busy_hours[x]) {\n+\t\t\tfor (count = 0; count < 2; count++) {\n+\t\t\tif (pol->core_share[count].status != 1)\n+\t\t\t\tprintf(\"Scaling up core %d to max\\n\",\n+\t\t\t\t\t pol->core_share[count].pcpu);\n+\t\t\t\tpower_manager_scale_core_max(\n+\t\t\t\t\t\tpol->core_share[count].pcpu);\n+\t\t\t}\n+\t\t\tbreak;\n+\t\t} else if (ptm->tm_hour ==\n+\t\t\t\tpol->pkt.timer_policy.quiet_hours[x]) {\n+\t\t\tfor (count = 0; count < 2; count++) {\n+\t\t\tif (pol->core_share[count].status != 1)\n+\t\t\t\tprintf(\"Scaling down core %d to min\\n\",\n+\t\t\t\t\t pol->core_share[count].pcpu);\n+\t\t\t\tpower_manager_scale_core_min(\n+\t\t\t\t\t\tpol->core_share[count].pcpu);\n+\t\t\t}\n+\t\t\tbreak;\n+\t\t} else if (ptm->tm_hour ==\n+\t\t\tpol->pkt.timer_policy.hours_to_use_traffic_profile[x]) {\n+\t\t\tapply_traffic_profile(pol);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+}\n+\n+static void\n+apply_workload_profile(struct policy *pol) {\n+\n+\tint count;\n+\n+\tif (pol->pkt.workload == HIGH) {\n+\t\tfor (count = 0; count < 2; count++) {\n+\t\t\tif (pol->core_share[count].status != 1)\n+\t\t\t\tpower_manager_scale_core_max(\n+\t\t\t\t\t\tpol->core_share[count].pcpu);\n+\t\t}\n+\t} else if (pol->pkt.workload == MEDIUM) {\n+\t\tfor (count = 0; count < 2; count++) {\n+\t\t\tif (pol->core_share[count].status != 1)\n+\t\t\t\tpower_manager_scale_core_med(\n+\t\t\t\t\t\tpol->core_share[count].pcpu);\n+\t\t}\n+\t} else if (pol->pkt.workload == LOW) {\n+\t\tfor (count = 0; count < 2; count++) {\n+\t\t\tif (pol->core_share[count].status != 1)\n+\t\t\t\tpower_manager_scale_core_min(\n+\t\t\t\t\t\tpol->core_share[count].pcpu);\n+\t\t}\n+\t}\n+}\n+\n+static void\n+apply_policy(struct policy *pol) {\n+\n+\tstruct channel_packet *pkt = &pol->pkt;\n+\n+\t/*Check policy to use*/\n+\tif (pkt->policy_to_use == TRAFFIC)\n+\t\tapply_traffic_profile(pol);\n+\telse if (pkt->policy_to_use == TIME)\n+\t\tapply_time_profile(pol);\n+\telse if (pkt->policy_to_use == WORKLOAD)\n+\t\tapply_workload_profile(pol);\n+}\n+\n+\n static int\n process_request(struct channel_packet *pkt, struct channel_info *chan_info)\n {\n@@ -128,6 +396,13 @@ process_request(struct channel_packet *pkt, struct channel_info *chan_info)\n \n \t\t}\n \t}\n+\n+\tif (pkt->command == PKT_POLICY) {\n+\t\tprintf(\"\\nProcessing Policy request from Guest\\n\");\n+\t\tupdate_policy(pkt);\n+\t\tpolicy_is_set = 1;\n+\t}\n+\n \t/* Return is not checked as channel status may have been set to DISABLED\n \t * from management thread\n \t */\n@@ -197,9 +472,10 @@ run_channel_monitor(void)\n \t\t\tstruct channel_info *chan_info = (struct channel_info *)\n \t\t\t\t\tglobal_events_list[i].data.ptr;\n \t\t\tif ((global_events_list[i].events & EPOLLERR) ||\n-\t\t\t\t\t(global_events_list[i].events & EPOLLHUP)) {\n+\t\t\t\t(global_events_list[i].events & EPOLLHUP)) {\n \t\t\t\tRTE_LOG(DEBUG, CHANNEL_MONITOR, \"Remote closed connection for \"\n-\t\t\t\t\t\t\"channel '%s'\\n\", chan_info->channel_path);\n+\t\t\t\t\t\t\"channel '%s'\\n\",\n+\t\t\t\t\t\tchan_info->channel_path);\n \t\t\t\tremove_channel(&chan_info);\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -211,14 +487,17 @@ run_channel_monitor(void)\n \t\t\t\tint buffer_len = sizeof(pkt);\n \n \t\t\t\twhile (buffer_len > 0) {\n-\t\t\t\t\tn_bytes = read(chan_info->fd, buffer, buffer_len);\n+\t\t\t\t\tn_bytes = read(chan_info->fd,\n+\t\t\t\t\t\t\tbuffer, buffer_len);\n \t\t\t\t\tif (n_bytes == buffer_len)\n \t\t\t\t\t\tbreak;\n \t\t\t\t\tif (n_bytes == -1) {\n \t\t\t\t\t\terr = errno;\n-\t\t\t\t\t\tRTE_LOG(DEBUG, CHANNEL_MONITOR, \"Received error on \"\n-\t\t\t\t\t\t\t\t\"channel '%s' read: %s\\n\",\n-\t\t\t\t\t\t\t\tchan_info->channel_path, strerror(err));\n+\t\t\t\t\t\tRTE_LOG(DEBUG, CHANNEL_MONITOR,\n+\t\t\t\t\t\t\t\"Received error on \"\n+\t\t\t\t\t\t\t\"channel '%s' read: %s\\n\",\n+\t\t\t\t\t\t\tchan_info->channel_path,\n+\t\t\t\t\t\t\tstrerror(err));\n \t\t\t\t\t\tremove_channel(&chan_info);\n \t\t\t\t\t\tbreak;\n \t\t\t\t\t}\n@@ -229,5 +508,12 @@ run_channel_monitor(void)\n \t\t\t\t\tprocess_request(&pkt, chan_info);\n \t\t\t}\n \t\t}\n+\t\trte_delay_us(time_period_s*1000000);\n+\t\tif (policy_is_set) {\n+\t\t\tfor (int j = 0; j < MAX_VMS; j++) {\n+\t\t\t\tif (policies[j].enabled == 1)\n+\t\t\t\t\tapply_policy(&policies[j]);\n+\t\t\t}\n+\t\t}\n \t}\n }\ndiff --git a/examples/vm_power_manager/channel_monitor.h b/examples/vm_power_manager/channel_monitor.h\nindex c138607..eb1383f 100644\n--- a/examples/vm_power_manager/channel_monitor.h\n+++ b/examples/vm_power_manager/channel_monitor.h\n@@ -35,6 +35,24 @@\n #define CHANNEL_MONITOR_H_\n \n #include \"channel_manager.h\"\n+#include \"channel_commands.h\"\n+\n+struct core_share {\n+\tunsigned int pcpu;\n+\t/*\n+\t * 1 CORE SHARE\n+\t * 0 NOT SHARED\n+\t */\n+\tint status;\n+};\n+\n+struct policy {\n+\tstruct channel_packet pkt;\n+\tuint32_t pfid[MAX_VFS];\n+\tuint32_t port[MAX_VFS];\n+\tunsigned int enabled;\n+\tstruct core_share core_share[2];\n+};\n \n #ifdef __cplusplus\n extern \"C\" {\n",
    "prefixes": [
        "dpdk-dev",
        "v1",
        "06/10"
    ]
}