Show a patch.

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

{
    "id": 470,
    "url": "http://patches.dpdk.org/api/patches/470/",
    "web_url": "http://patches.dpdk.org/patch/470/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/",
        "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"
    },
    "msgid": "<1411484549-711-1-git-send-email-michalx.k.jastrzebski@intel.com>",
    "date": "2014-09-23T15:02:29",
    "name": "[dpdk-dev] Change alarm cancel function to thread-safe.",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "07c288122535261e875c497061bdb244e3aab3bf",
    "submitter": {
        "id": 74,
        "url": "http://patches.dpdk.org/api/people/74/",
        "name": "Michal Jastrzebski",
        "email": "michalx.k.jastrzebski@intel.com"
    },
    "delegate": null,
    "mbox": "http://patches.dpdk.org/patch/470/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/470/comments/",
    "check": "pending",
    "checks": "http://patches.dpdk.org/api/patches/470/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "X-IronPort-AV": "E=Sophos;i=\"5.04,580,1406617200\"; d=\"scan'208\";a=\"607211479\"",
        "Date": "Tue, 23 Sep 2014 16:02:29 +0100",
        "Delivered-To": "patchwork@dpdk.org",
        "Message-Id": "<1411484549-711-1-git-send-email-michalx.k.jastrzebski@intel.com>",
        "X-Original-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 7A7D55920;\n\tTue, 23 Sep 2014 16:58:10 +0200 (CEST)",
            "from mga09.intel.com (mga09.intel.com [134.134.136.24])\n\tby dpdk.org (Postfix) with ESMTP id 1B5E558FE\n\tfor <dev@dpdk.org>; Tue, 23 Sep 2014 16:58:07 +0200 (CEST)",
            "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby orsmga102.jf.intel.com with ESMTP; 23 Sep 2014 07:57:45 -0700",
            "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby orsmga002.jf.intel.com with ESMTP; 23 Sep 2014 08:02:33 -0700",
            "from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com\n\t[10.237.217.45])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\ts8NF2VJx022525; Tue, 23 Sep 2014 16:02:31 +0100",
            "from sivswdev01.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev01.ir.intel.com with ESMTP id s8NF2Woq000754;\n\tTue, 23 Sep 2014 16:02:32 +0100",
            "(from mkjastrx@localhost)\n\tby sivswdev01.ir.intel.com with  id s8NF2VBA000747;\n\tTue, 23 Sep 2014 16:02:31 +0100"
        ],
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>",
        "Subject": "[dpdk-dev] [PATCH] Change alarm cancel function to thread-safe.",
        "Precedence": "list",
        "From": "Michal Jastrzebski <michalx.k.jastrzebski@intel.com>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "X-ExtLoop1": "1",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "X-Mailer": "git-send-email 1.7.4.1",
        "To": "dev@dpdk.org",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "It eliminates a race between threads using rte_alarm_cancel and rte_alarm_set.\n\nSigned-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>\nReviewed-by: Michal Jastrzebski <michalx.k.jastrzebski@intel.com>\n---\n lib/librte_eal/common/include/rte_alarm.h |    3 +-\n lib/librte_eal/linuxapp/eal/eal_alarm.c   |   68 +++++++++++++++++++----------\n 2 files changed, 46 insertions(+), 25 deletions(-)",
    "diff": "diff --git a/lib/librte_eal/common/include/rte_alarm.h b/lib/librte_eal/common/include/rte_alarm.h\nindex d451522..f5f7de4 100644\n--- a/lib/librte_eal/common/include/rte_alarm.h\n+++ b/lib/librte_eal/common/include/rte_alarm.h\n@@ -76,7 +76,8 @@ typedef void (*rte_eal_alarm_callback)(void *arg);\n int rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb, void *cb_arg);\n \n /**\n- * Function to cancel an alarm callback which has been registered before.\n+ * Function to cancel an alarm callback which has been registered before. If\n+ * used ouside alarm callback it wait for all callbacks to finish its execution.\n  *\n  * @param cb_fn\n  *  alarm callback\ndiff --git a/lib/librte_eal/linuxapp/eal/eal_alarm.c b/lib/librte_eal/linuxapp/eal/eal_alarm.c\nindex 480f0cb..0561dbf 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_alarm.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_alarm.c\n@@ -69,12 +69,14 @@ struct alarm_entry {\n \tstruct timeval time;\n \trte_eal_alarm_callback cb_fn;\n \tvoid *cb_arg;\n-\tvolatile int executing;\n+\tvolatile uint8_t executing;\n+\tvolatile pthread_t executing_id;\n };\n \n static LIST_HEAD(alarm_list, alarm_entry) alarm_list = LIST_HEAD_INITIALIZER();\n static rte_spinlock_t alarm_list_lk = RTE_SPINLOCK_INITIALIZER;\n \n+\n static struct rte_intr_handle intr_handle = {.fd = -1 };\n static int handler_registered = 0;\n static void eal_alarm_callback(struct rte_intr_handle *hdl, void *arg);\n@@ -108,11 +110,14 @@ eal_alarm_callback(struct rte_intr_handle *hdl __rte_unused,\n \t\t\t(ap->time.tv_sec < now.tv_sec || (ap->time.tv_sec == now.tv_sec &&\n \t\t\t\t\t\tap->time.tv_usec <= now.tv_usec))){\n \t\tap->executing = 1;\n+\t\tap->executing_id = pthread_self();\n \t\trte_spinlock_unlock(&alarm_list_lk);\n \n \t\tap->cb_fn(ap->cb_arg);\n \n \t\trte_spinlock_lock(&alarm_list_lk);\n+\t\tap->executing = 0;\n+\n \t\tLIST_REMOVE(ap, next);\n \t\trte_free(ap);\n \t}\n@@ -156,7 +161,6 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)\n \tnew_alarm->cb_arg = cb_arg;\n \tnew_alarm->time.tv_usec = (now.tv_usec + us) % US_PER_S;\n \tnew_alarm->time.tv_sec = now.tv_sec + ((now.tv_usec + us) / US_PER_S);\n-\tnew_alarm->executing = 0;\n \n \trte_spinlock_lock(&alarm_list_lk);\n \tif (!handler_registered) {\n@@ -202,34 +206,50 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)\n {\n \tstruct alarm_entry *ap, *ap_prev;\n \tint count = 0;\n+\tint executing;\n \n \tif (!cb_fn)\n \t\treturn -1;\n \n-\trte_spinlock_lock(&alarm_list_lk);\n-\t/* remove any matches at the start of the list */\n-\twhile ((ap = LIST_FIRST(&alarm_list)) != NULL &&\n-\t\t\tcb_fn == ap->cb_fn && ap->executing == 0 &&\n-\t\t\t(cb_arg == (void *)-1 || cb_arg == ap->cb_arg)) {\n-\t\tLIST_REMOVE(ap, next);\n-\t\trte_free(ap);\n-\t\tcount++;\n-\t}\n-\tap_prev = ap;\n-\n-\t/* now go through list, removing entries not at start */\n-\tLIST_FOREACH(ap, &alarm_list, next) {\n-\t\t/* this won't be true first time through */\n-\t\tif (cb_fn == ap->cb_fn &&  ap->executing == 0 &&\n+\tdo {\n+\t\texecuting = 0;\n+\t\trte_spinlock_lock(&alarm_list_lk);\n+\t\t/* remove any matches at the start of the list */\n+\t\twhile ((ap = LIST_FIRST(&alarm_list)) != NULL &&\n+\t\t\t\tcb_fn == ap->cb_fn &&\n \t\t\t\t(cb_arg == (void *)-1 || cb_arg == ap->cb_arg)) {\n-\t\t\tLIST_REMOVE(ap,next);\n-\t\t\trte_free(ap);\n-\t\t\tcount++;\n-\t\t\tap = ap_prev;\n+\n+\t\t\tif (ap->executing == 0) {\n+\t\t\t\tLIST_REMOVE(ap, next);\n+\t\t\t\trte_free(ap);\n+\t\t\t\tcount++;\n+\t\t\t} else {\n+\t\t\t\tif (pthread_equal(ap->executing_id, pthread_self()) == 0)\n+\t\t\t\t\texecuting++;\n+\n+\t\t\t\tbreak;\n+\t\t\t}\n \t\t}\n \t\tap_prev = ap;\n-\t}\n-\trte_spinlock_unlock(&alarm_list_lk);\n+\n+\t\t/* now go through list, removing entries not at start */\n+\t\tLIST_FOREACH(ap, &alarm_list, next) {\n+\t\t\t/* this won't be true first time through */\n+\t\t\tif (cb_fn == ap->cb_fn &&\n+\t\t\t\t\t(cb_arg == (void *)-1 || cb_arg == ap->cb_arg)) {\n+\n+\t\t\t\tif (ap->executing == 0) {\n+\t\t\t\t\tLIST_REMOVE(ap, next);\n+\t\t\t\t\trte_free(ap);\n+\t\t\t\t\tcount++;\n+\t\t\t\t\tap = ap_prev;\n+\t\t\t\t} else if (pthread_equal(ap->executing_id, pthread_self()) == 0)\n+\t\t\t\t\texecuting++;\n+\t\t\t}\n+\t\t\tap_prev = ap;\n+\t\t}\n+\t\trte_spinlock_unlock(&alarm_list_lk);\n+\t} while (executing != 0);\n+\n \treturn count;\n }\n-\n",
    "prefixes": [
        "dpdk-dev"
    ]
}