Show a patch.

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

{
    "id": 475,
    "url": "https://patches.dpdk.org/api/patches/475/",
    "web_url": "https://patches.dpdk.org/patch/475/",
    "project": {
        "id": 1,
        "url": "https://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": "<60ABE07DBB3A454EB7FAD707B4BB1582138971EC@IRSMSX109.ger.corp.intel.com>",
    "date": "2014-09-24T11:38:52",
    "name": "[dpdk-dev] Change alarm cancel function to thread-safe.",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "b5bdb0a4da055dc7aa89f91df5f61060dadb8570",
    "submitter": {
        "id": 74,
        "url": "https://patches.dpdk.org/api/people/74/",
        "name": "Michal Jastrzebski",
        "email": "michalx.k.jastrzebski@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/patch/475/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/475/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/475/checks/",
    "tags": {},
    "headers": {
        "Sender": "\"dev\" <dev-bounces@dpdk.org>",
        "Thread-Index": "AQHP1z+gNpYWcLJ780a2XEwi95k/LJwQKTow",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "X-MS-Has-Attach": "",
        "X-Original-To": "patchwork@dpdk.org",
        "Date": "Wed, 24 Sep 2014 11:38:52 +0000",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "In-Reply-To": "<1411484549-711-1-git-send-email-michalx.k.jastrzebski@intel.com>",
        "Message-ID": "<60ABE07DBB3A454EB7FAD707B4BB1582138971EC@IRSMSX109.ger.corp.intel.com>",
        "X-BeenThere": "dev@dpdk.org",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "Accept-Language": "en-US",
        "References": "<1411484549-711-1-git-send-email-michalx.k.jastrzebski@intel.com>",
        "X-MS-TNEF-Correlator": "",
        "Return-Path": "<dev-bounces@dpdk.org>",
        "x-originating-ip": "[163.33.239.181]",
        "Errors-To": "dev-bounces@dpdk.org",
        "List-Post": "<mailto:dev@dpdk.org>",
        "MIME-Version": "1.0",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 1497FB39D;\n\tWed, 24 Sep 2014 13:32:49 +0200 (CEST)",
            "from mga14.intel.com (mga14.intel.com [192.55.52.115])\n\tby dpdk.org (Postfix) with ESMTP id 162E86896\n\tfor <dev@dpdk.org>; Wed, 24 Sep 2014 13:32:46 +0200 (CEST)",
            "from fmsmga003.fm.intel.com ([10.253.24.29])\n\tby fmsmga103.fm.intel.com with ESMTP; 24 Sep 2014 04:29:46 -0700",
            "from irsmsx102.ger.corp.intel.com ([163.33.3.155])\n\tby FMSMGA003.fm.intel.com with ESMTP; 24 Sep 2014 04:32:59 -0700",
            "from irsmsx105.ger.corp.intel.com (163.33.3.28) by\n\tIRSMSX102.ger.corp.intel.com (163.33.3.155) with Microsoft SMTP\n\tServer (TLS) id 14.3.195.1; Wed, 24 Sep 2014 12:38:53 +0100",
            "from irsmsx109.ger.corp.intel.com ([169.254.13.200]) by\n\tIRSMSX105.ger.corp.intel.com ([169.254.7.158]) with mapi id\n\t14.03.0195.001; Wed, 24 Sep 2014 12:38:53 +0100"
        ],
        "From": "\"Jastrzebski, MichalX K\" <michalx.k.jastrzebski@intel.com>",
        "Precedence": "list",
        "Delivered-To": "patchwork@dpdk.org",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Content-Transfer-Encoding": "quoted-printable",
        "Subject": "Re: [dpdk-dev] [PATCH] Change alarm cancel function to thread-safe.",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "To": "\"dev@dpdk.org\" <dev@dpdk.org>",
        "Content-Language": "en-US",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "X-Mailman-Version": "2.1.15",
        "X-ExtLoop1": "1",
        "Thread-Topic": "[PATCH] Change alarm cancel function to thread-safe.",
        "X-IronPort-AV": "E=Sophos;i=\"4.97,862,1389772800\"; d=\"scan'208\";a=\"390900902\""
    },
    "content": "This patch is related to discussion from mode 4 link bonding patch set.\n\nBest regards\nMichal\n\n-----Original Message-----\nFrom: Jastrzebski, MichalX K \nSent: Tuesday, September 23, 2014 5:02 PM\nTo: dev@dpdk.org\nCc: Jastrzebski, MichalX K; Wodkowski, PawelX\nSubject: [PATCH] Change alarm cancel function to thread-safe.\n\nIt 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(-)\n\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 \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--\n1.7.9.5",
    "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);  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 \n+ 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();  static rte_spinlock_t alarm_list_lk = RTE_SPINLOCK_INITIALIZER;\n \n+\n static struct rte_intr_handle intr_handle = {.fd = -1 };  static int handler_registered = 0;  static void eal_alarm_callback(struct rte_intr_handle *hdl, void *arg); @@ -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",
    "prefixes": [
        "dpdk-dev"
    ]
}