get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 55372,
    "url": "http://patches.dpdk.org/api/patches/55372/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/5c7403e06efccd2c8210ce811fa16c8e56e084b0.1561478924.git.anatoly.burakov@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": "<5c7403e06efccd2c8210ce811fa16c8e56e084b0.1561478924.git.anatoly.burakov@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/5c7403e06efccd2c8210ce811fa16c8e56e084b0.1561478924.git.anatoly.burakov@intel.com",
    "date": "2019-06-25T16:11:42",
    "name": "[2/2] timer: fix resource leak in finalize",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "5afdcb9f6b5b908e60532d34d35b660f4b49df50",
    "submitter": {
        "id": 4,
        "url": "http://patches.dpdk.org/api/people/4/?format=api",
        "name": "Burakov, Anatoly",
        "email": "anatoly.burakov@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/5c7403e06efccd2c8210ce811fa16c8e56e084b0.1561478924.git.anatoly.burakov@intel.com/mbox/",
    "series": [
        {
            "id": 5163,
            "url": "http://patches.dpdk.org/api/series/5163/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=5163",
            "date": "2019-06-25T16:11:40",
            "name": "Fix timer resource leak",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/5163/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/55372/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/55372/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "X-BeenThere": "dev@dpdk.org",
        "Return-Path": "<dev-bounces@dpdk.org>",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>",
        "From": "Anatoly Burakov <anatoly.burakov@intel.com>",
        "To": "dev@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "X-Amp-File-Uploaded": "False",
        "References": [
            "<cover.1561478924.git.anatoly.burakov@intel.com>",
            "<1557354906-2500-1-git-send-email-erik.g.carrillo@intel.com>\n\t<cover.1561478924.git.anatoly.burakov@intel.com>"
        ],
        "In-Reply-To": [
            "<cover.1561478924.git.anatoly.burakov@intel.com>",
            "<cover.1561478924.git.anatoly.burakov@intel.com>"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "X-Mailer": "git-send-email 2.17.1",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id A94DA1BB29;\n\tTue, 25 Jun 2019 18:11:52 +0200 (CEST)",
            "from mga11.intel.com (mga11.intel.com [192.55.52.93])\n\tby dpdk.org (Postfix) with ESMTP id AB7511B9FD\n\tfor <dev@dpdk.org>; Tue, 25 Jun 2019 18:11:46 +0200 (CEST)",
            "from orsmga001.jf.intel.com ([10.7.209.18])\n\tby fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t25 Jun 2019 09:11:46 -0700",
            "from silpixa00399498.ir.intel.com (HELO\n\tsilpixa00399498.ger.corp.intel.com) ([10.237.223.125])\n\tby orsmga001.jf.intel.com with ESMTP; 25 Jun 2019 09:11:45 -0700"
        ],
        "X-Original-To": "patchwork@dpdk.org",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "X-Mailman-Version": "2.1.15",
        "X-ExtLoop1": "1",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "Errors-To": "dev-bounces@dpdk.org",
        "X-IronPort-AV": "E=Sophos;i=\"5.63,416,1557212400\"; d=\"scan'208\";a=\"245120811\"",
        "Subject": "[dpdk-dev] [PATCH 2/2] timer: fix resource leak in finalize",
        "Date": "Tue, 25 Jun 2019 17:11:42 +0100",
        "Message-Id": "<5c7403e06efccd2c8210ce811fa16c8e56e084b0.1561478924.git.anatoly.burakov@intel.com>",
        "Cc": "Robert Sanford <rsanford@akamai.com>,\n\tErik Gabriel Carrillo <erik.g.carrillo@intel.com>",
        "Precedence": "list"
    },
    "content": "Currently, whenever timer library is initialized, the memory is leaked\nbecause there is no telling when primary or secondary processes get\nto use the state, and there is no way to initialize/deinitialize\ntimer library state without race conditions because the data itself\nmust live in shared memory.\n\nHowever, there is now a timer library lock in the shared memory\nconfig, which can be used to synchronize access to the timer\nlibrary shared memory. Use it to initialize/deinitialize timer\nlibrary shared data in a safe way. There is still a way to leak\nthe memory (by killing one of the processes), but we can't do\nanything about that.\n\nAlso, update the API doc. Note that the behavior of the API\nitself did not change - the requirement to call init in every\nprocess was simply not documented explicitly.\n\nSigned-off-by: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>\nSigned-off-by: Anatoly Burakov <anatoly.burakov@intel.com>\n---\n lib/librte_timer/rte_timer.c | 41 ++++++++++++++++++++++++------------\n lib/librte_timer/rte_timer.h |  5 +++--\n 2 files changed, 31 insertions(+), 15 deletions(-)",
    "diff": "diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c\nindex dd7953922..08517c120 100644\n--- a/lib/librte_timer/rte_timer.c\n+++ b/lib/librte_timer/rte_timer.c\n@@ -13,6 +13,7 @@\n #include <rte_atomic.h>\n #include <rte_common.h>\n #include <rte_cycles.h>\n+#include <rte_eal_memconfig.h>\n #include <rte_per_lcore.h>\n #include <rte_memory.h>\n #include <rte_launch.h>\n@@ -61,6 +62,8 @@ struct rte_timer_data {\n };\n \n #define RTE_MAX_DATA_ELS 64\n+static const struct rte_memzone *rte_timer_data_mz;\n+static int *volatile rte_timer_mz_refcnt;\n static struct rte_timer_data *rte_timer_data_arr;\n static const uint32_t default_data_id;\n static uint32_t rte_timer_subsystem_initialized;\n@@ -157,28 +160,30 @@ rte_timer_subsystem_init_v1905(void)\n \tint i, lcore_id;\n \tstatic const char *mz_name = \"rte_timer_mz\";\n \tconst size_t data_arr_size =\n-\t\t\t\tRTE_MAX_DATA_ELS * sizeof(*rte_timer_data_arr);\n+\t\t\tRTE_MAX_DATA_ELS * sizeof(*rte_timer_data_arr);\n+\tconst size_t mem_size = data_arr_size + sizeof(*rte_timer_mz_refcnt);\n \tbool do_full_init = true;\n \n \tif (rte_timer_subsystem_initialized)\n \t\treturn -EALREADY;\n \n-reserve:\n-\trte_errno = 0;\n-\tmz = rte_memzone_reserve_aligned(mz_name, data_arr_size, SOCKET_ID_ANY,\n-\t\t\t\t\t 0, RTE_CACHE_LINE_SIZE);\n+\trte_mcfg_timer_lock();\n+\n+\tmz = rte_memzone_lookup(mz_name);\n \tif (mz == NULL) {\n-\t\tif (rte_errno == EEXIST) {\n-\t\t\tmz = rte_memzone_lookup(mz_name);\n-\t\t\tif (mz == NULL)\n-\t\t\t\tgoto reserve;\n-\n-\t\t\tdo_full_init = false;\n-\t\t} else\n+\t\tmz = rte_memzone_reserve_aligned(mz_name, mem_size,\n+\t\t\t\tSOCKET_ID_ANY, 0, RTE_CACHE_LINE_SIZE);\n+\t\tif (mz == NULL) {\n+\t\t\trte_mcfg_timer_unlock();\n \t\t\treturn -ENOMEM;\n-\t}\n+\t\t}\n+\t\tdo_full_init = true;\n+\t} else\n+\t\tdo_full_init = false;\n \n+\trte_timer_data_mz = mz;\n \trte_timer_data_arr = mz->addr;\n+\trte_timer_mz_refcnt = (void *)((char *)mz->addr + data_arr_size);\n \n \tif (do_full_init) {\n \t\tfor (i = 0; i < RTE_MAX_DATA_ELS; i++) {\n@@ -195,6 +200,9 @@ rte_timer_subsystem_init_v1905(void)\n \t}\n \n \trte_timer_data_arr[default_data_id].internal_flags |= FL_ALLOCATED;\n+\t(*rte_timer_mz_refcnt)++;\n+\n+\trte_mcfg_timer_unlock();\n \n \trte_timer_subsystem_initialized = 1;\n \n@@ -210,6 +218,13 @@ rte_timer_subsystem_finalize(void)\n \tif (!rte_timer_subsystem_initialized)\n \t\treturn;\n \n+\trte_mcfg_timer_lock();\n+\n+\tif (--(*rte_timer_mz_refcnt) == 0)\n+\t\trte_memzone_free(rte_timer_data_mz);\n+\n+\trte_mcfg_timer_unlock();\n+\n \trte_timer_subsystem_initialized = 0;\n }\n \ndiff --git a/lib/librte_timer/rte_timer.h b/lib/librte_timer/rte_timer.h\nindex 2196934b2..a7af10176 100644\n--- a/lib/librte_timer/rte_timer.h\n+++ b/lib/librte_timer/rte_timer.h\n@@ -170,10 +170,11 @@ int __rte_experimental rte_timer_data_dealloc(uint32_t id);\n  * Initializes internal variables (list, locks and so on) for the RTE\n  * timer library.\n  *\n+ * @note\n+ *   This function must be called in every process before using the library.\n+ *\n  * @return\n  *   - 0: Success\n- *   - -EEXIST: Returned in secondary process when primary process has not\n- *      yet initialized the timer subsystem\n  *   - -ENOMEM: Unable to allocate memory needed to initialize timer\n  *      subsystem\n  */\n",
    "prefixes": [
        "2/2"
    ]
}