get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 47516,
    "url": "https://patches.dpdk.org/api/patches/47516/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20181027091750.17254-8-harry.van.haaren@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": "<20181027091750.17254-8-harry.van.haaren@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20181027091750.17254-8-harry.van.haaren@intel.com",
    "date": "2018-10-27T09:17:45",
    "name": "[v10,07/12] telemetry: update metrics before sending stats",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "b38ed1420f0818607817ec1aab0f1005cc9f20cc",
    "submitter": {
        "id": 317,
        "url": "https://patches.dpdk.org/api/people/317/?format=api",
        "name": "Van Haaren, Harry",
        "email": "harry.van.haaren@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20181027091750.17254-8-harry.van.haaren@intel.com/mbox/",
    "series": [
        {
            "id": 2132,
            "url": "https://patches.dpdk.org/api/series/2132/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=2132",
            "date": "2018-10-27T09:17:38",
            "name": "Introduce Telemetry Library",
            "version": 10,
            "mbox": "https://patches.dpdk.org/series/2132/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/47516/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/47516/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 C03325323;\n\tSat, 27 Oct 2018 11:20:23 +0200 (CEST)",
            "from mga18.intel.com (mga18.intel.com [134.134.136.126])\n\tby dpdk.org (Postfix) with ESMTP id 48C524F94\n\tfor <dev@dpdk.org>; Sat, 27 Oct 2018 11:19:41 +0200 (CEST)",
            "from orsmga008.jf.intel.com ([10.7.209.65])\n\tby orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t27 Oct 2018 02:19:40 -0700",
            "from silpixa00399779.ir.intel.com (HELO\n\tsilpixa00399779.ger.corp.intel.com) ([10.237.223.188])\n\tby orsmga008.jf.intel.com with ESMTP; 27 Oct 2018 02:19:38 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.54,431,1534834800\"; d=\"scan'208\";a=\"84903894\"",
        "From": "Harry van Haaren <harry.van.haaren@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "thomas@monjalon.net, bruce.richardson@intel.com,\n\tstephen@networkplumber.org, gaetan.rivet@6wind.com,\n\tshreyansh.jain@nxp.com, \n\tmattias.ronnblom@ericsson.com, Ciara Power <ciara.power@intel.com>,\n\tBrian Archbold <brian.archbold@intel.com>,\n\tKevin Laatz <kevin.laatz@intel.com>",
        "Date": "Sat, 27 Oct 2018 10:17:45 +0100",
        "Message-Id": "<20181027091750.17254-8-harry.van.haaren@intel.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20181027091750.17254-1-harry.van.haaren@intel.com>",
        "References": "<20181026235933.79779-1-harry.van.haaren@intel.com>\n\t<20181027091750.17254-1-harry.van.haaren@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v10 07/12] telemetry: update metrics before\n\tsending stats",
        "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: Ciara Power <ciara.power@intel.com>\n\nThis patch adds functionality to update the statistics in\nthe metrics library with values from the ethdev stats.\n\nValues need to be updated before they are encoded into a JSON\nmessage and sent to the client that requested them. The JSON encoding\nwill be added in a subsequent patch.\n\nSigned-off-by: Ciara Power <ciara.power@intel.com>\nSigned-off-by: Brian Archbold <brian.archbold@intel.com>\nSigned-off-by: Kevin Laatz <kevin.laatz@intel.com>\nAcked-by: Harry van Haaren <harry.van.haaren@intel.com>\n---\n lib/librte_telemetry/rte_telemetry.c          | 134 ++++++++++++++++++\n lib/librte_telemetry/rte_telemetry_internal.h |   4 +\n lib/librte_telemetry/rte_telemetry_parser.c   |  17 +++\n 3 files changed, 155 insertions(+)",
    "diff": "diff --git a/lib/librte_telemetry/rte_telemetry.c b/lib/librte_telemetry/rte_telemetry.c\nindex cac788438..7616e7c91 100644\n--- a/lib/librte_telemetry/rte_telemetry.c\n+++ b/lib/librte_telemetry/rte_telemetry.c\n@@ -46,6 +46,78 @@ rte_telemetry_is_port_active(int port_id)\n \treturn 0;\n }\n \n+static int32_t\n+rte_telemetry_update_metrics_ethdev(struct telemetry_impl *telemetry,\n+\tuint16_t port_id, int reg_start_index)\n+{\n+\tint ret, num_xstats, i;\n+\tstruct rte_eth_xstat *eth_xstats;\n+\n+\tif (!rte_eth_dev_is_valid_port(port_id)) {\n+\t\tTELEMETRY_LOG_ERR(\"port_id: %d is invalid\", port_id);\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -1;\n+\t}\n+\n+\tret = rte_telemetry_is_port_active(port_id);\n+\tif (ret < 1) {\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -1;\n+\t}\n+\n+\tnum_xstats = rte_eth_xstats_get(port_id, NULL, 0);\n+\tif (num_xstats < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"rte_eth_xstats_get(%u) failed: %d\", port_id,\n+\t\t\t\tnum_xstats);\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EPERM);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -1;\n+\t}\n+\n+\teth_xstats = malloc(sizeof(struct rte_eth_xstat) * num_xstats);\n+\tif (eth_xstats == NULL) {\n+\t\tTELEMETRY_LOG_ERR(\"Failed to malloc memory for xstats\");\n+\t\tret = rte_telemetry_send_error_response(telemetry, -ENOMEM);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -1;\n+\t}\n+\n+\tret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats);\n+\tif (ret < 0 || ret > num_xstats) {\n+\t\tfree(eth_xstats);\n+\t\tTELEMETRY_LOG_ERR(\"rte_eth_xstats_get(%u) len%i failed: %d\",\n+\t\t\t\tport_id, num_xstats, ret);\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EPERM);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\treturn -1;\n+\t}\n+\n+\tuint64_t xstats_values[num_xstats];\n+\tfor (i = 0; i < num_xstats; i++)\n+\t\txstats_values[i] = eth_xstats[i].value;\n+\n+\tret = rte_metrics_update_values(port_id, reg_start_index, xstats_values,\n+\t\t\tnum_xstats);\n+\tif (ret < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Could not update metrics values\");\n+\t\tret = rte_telemetry_send_error_response(telemetry, -EPERM);\n+\t\tif (ret < 0)\n+\t\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\t\tfree(eth_xstats);\n+\t\treturn -1;\n+\t}\n+\n+\tfree(eth_xstats);\n+\treturn 0;\n+}\n+\n int32_t\n rte_telemetry_write_to_socket(struct telemetry_impl *telemetry,\n \tconst char *json_string)\n@@ -130,6 +202,68 @@ rte_telemetry_send_error_response(struct telemetry_impl *telemetry,\n \treturn 0;\n }\n \n+int32_t\n+rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,\n+\tuint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry)\n+{\n+\tint ret, i;\n+\tchar *json_buffer = NULL;\n+\n+\tif (telemetry == NULL) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid telemetry argument\");\n+\t\treturn -1;\n+\t}\n+\n+\tif (metric_ids == NULL) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid metric_ids array\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tif (num_metric_ids < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid num_metric_ids, must be positive\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tif (port_ids == NULL) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid port_ids array\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tif (num_port_ids < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Invalid num_port_ids, must be positive\");\n+\t\tgoto einval_fail;\n+\t}\n+\n+\tfor (i = 0; i < num_port_ids; i++) {\n+\t\tif (!rte_eth_dev_is_valid_port(port_ids[i])) {\n+\t\t\tTELEMETRY_LOG_ERR(\"Port: %d invalid\", port_ids[i]);\n+\t\t\tgoto einval_fail;\n+\t\t}\n+\n+\t\tret = rte_telemetry_update_metrics_ethdev(telemetry,\n+\t\t\tport_ids[i], telemetry->reg_index);\n+\t\tif (ret < 0) {\n+\t\t\tTELEMETRY_LOG_ERR(\"Failed to update ethdev metrics\");\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\tret = rte_telemetry_write_to_socket(telemetry, json_buffer);\n+\tif (ret < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Could not write to socket\");\n+\t\treturn -1;\n+\t}\n+\n+\treturn 0;\n+\n+einval_fail:\n+\tret = rte_telemetry_send_error_response(telemetry, -EINVAL);\n+\tif (ret < 0)\n+\t\tTELEMETRY_LOG_ERR(\"Could not send error\");\n+\treturn -1;\n+}\n+\n+\n static int32_t\n rte_telemetry_reg_ethdev_to_metrics(uint16_t port_id)\n {\ndiff --git a/lib/librte_telemetry/rte_telemetry_internal.h b/lib/librte_telemetry/rte_telemetry_internal.h\nindex 86a5ba15e..0082cb2ca 100644\n--- a/lib/librte_telemetry/rte_telemetry_internal.h\n+++ b/lib/librte_telemetry/rte_telemetry_internal.h\n@@ -71,4 +71,8 @@ rte_telemetry_unregister_client(struct telemetry_impl *telemetry,\n int32_t\n rte_telemetry_is_port_active(int port_id);\n \n+int32_t\n+rte_telemetry_send_ports_stats_values(uint32_t *metric_ids, int num_metric_ids,\n+\tuint32_t *port_ids, int num_port_ids, struct telemetry_impl *telemetry);\n+\n #endif\ndiff --git a/lib/librte_telemetry/rte_telemetry_parser.c b/lib/librte_telemetry/rte_telemetry_parser.c\nindex 556abbe4a..03a58a2fd 100644\n--- a/lib/librte_telemetry/rte_telemetry_parser.c\n+++ b/lib/librte_telemetry/rte_telemetry_parser.c\n@@ -258,6 +258,7 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,\n \tint ret, num_metrics, i, p;\n \tstruct rte_metric_name *names;\n \tuint64_t num_port_ids = 0;\n+\tuint32_t port_ids[RTE_MAX_ETHPORTS];\n \n \tif (telemetry == NULL) {\n \t\tTELEMETRY_LOG_ERR(\"Invalid telemetry argument\");\n@@ -313,6 +314,7 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,\n \tuint32_t stat_ids[num_metrics];\n \n \tRTE_ETH_FOREACH_DEV(p) {\n+\t\tport_ids[num_port_ids] = p;\n \t\tnum_port_ids++;\n \t}\n \n@@ -337,6 +339,13 @@ rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,\n \t\tgoto fail;\n \t}\n \n+\tret = rte_telemetry_send_ports_stats_values(stat_ids, num_metrics,\n+\t\tport_ids, num_port_ids, telemetry);\n+\tif (ret < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Sending ports stats values failed\");\n+\t\tgoto fail;\n+\t}\n+\n \treturn 0;\n \n fail:\n@@ -428,6 +437,14 @@ rte_telemetry_command_ports_stats_values_by_name(struct telemetry_impl\n \t\tTELEMETRY_LOG_ERR(\"Could not convert stat names to IDs\");\n \t\treturn -1;\n \t}\n+\n+\tret = rte_telemetry_send_ports_stats_values(stat_ids, num_stat_names,\n+\t\tport_ids, num_port_ids, telemetry);\n+\tif (ret < 0) {\n+\t\tTELEMETRY_LOG_ERR(\"Sending ports stats values failed\");\n+\t\treturn -1;\n+\t}\n+\n \treturn 0;\n }\n \n",
    "prefixes": [
        "v10",
        "07/12"
    ]
}