get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 530,
    "url": "https://patches.dpdk.org/api/patches/530/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20140925172358.GG32725@hmsreliant.think-freely.org/",
    "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": "<20140925172358.GG32725@hmsreliant.think-freely.org>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20140925172358.GG32725@hmsreliant.think-freely.org",
    "date": "2014-09-25T17:23:58",
    "name": "[dpdk-dev,v2] Change alarm cancel function to thread-safe:",
    "commit_ref": null,
    "pull_url": null,
    "state": "not-applicable",
    "archived": true,
    "hash": "4a373f14ba817ab228d52ca6445ed8d53e5408b1",
    "submitter": {
        "id": 32,
        "url": "https://patches.dpdk.org/api/people/32/?format=api",
        "name": "Neil Horman",
        "email": "nhorman@tuxdriver.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20140925172358.GG32725@hmsreliant.think-freely.org/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/530/comments/",
    "check": "pending",
    "checks": "https://patches.dpdk.org/api/patches/530/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 EDAAE7E49;\n\tThu, 25 Sep 2014 19:17:50 +0200 (CEST)",
            "from smtp.tuxdriver.com (charlotte.tuxdriver.com [70.61.120.58])\n\tby dpdk.org (Postfix) with ESMTP id 9B20E68CE\n\tfor <dev@dpdk.org>; Thu, 25 Sep 2014 19:17:48 +0200 (CEST)",
            "from hmsreliant.think-freely.org\n\t([2001:470:8:a08:7aac:c0ff:fec2:933b] helo=localhost)\n\tby smtp.tuxdriver.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.63)\n\t(envelope-from <nhorman@tuxdriver.com>)\n\tid 1XXClr-0007AI-5d; Thu, 25 Sep 2014 13:24:05 -0400"
        ],
        "Date": "Thu, 25 Sep 2014 13:23:58 -0400",
        "From": "Neil Horman <nhorman@tuxdriver.com>",
        "To": "\"Ananyev, Konstantin\" <konstantin.ananyev@intel.com>",
        "Message-ID": "<20140925172358.GG32725@hmsreliant.think-freely.org>",
        "References": "<1411649768-8084-1-git-send-email-michalx.k.jastrzebski@intel.com>\n\t<20140925150807.GD32725@hmsreliant.think-freely.org>\n\t<2601191342CEEE43887BDE71AB977258213769DE@IRSMSX105.ger.corp.intel.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=us-ascii",
        "Content-Disposition": "inline",
        "In-Reply-To": "<2601191342CEEE43887BDE71AB977258213769DE@IRSMSX105.ger.corp.intel.com>",
        "User-Agent": "Mutt/1.5.23 (2014-03-12)",
        "X-Spam-Score": "-2.9 (--)",
        "X-Spam-Status": "No",
        "Cc": "\"dev@dpdk.org\" <dev@dpdk.org>",
        "Subject": "Re: [dpdk-dev] [PATCH v2] Change alarm cancel function to\n\tthread-safe:",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "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>",
        "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": "On Thu, Sep 25, 2014 at 04:03:48PM +0000, Ananyev, Konstantin wrote:\n> \n> \n> > -----Original Message-----\n> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Neil Horman\n> > Sent: Thursday, September 25, 2014 4:08 PM\n> > To: Jastrzebski, MichalX K\n> > Cc: dev@dpdk.org\n> > Subject: Re: [dpdk-dev] [PATCH v2] Change alarm cancel function to thread-safe:\n> > \n> > On Thu, Sep 25, 2014 at 01:56:08PM +0100, Michal Jastrzebski wrote:\n> > >     Change alarm cancel function to thread-safe.\n> > >     It eliminates a race between threads using rte_alarm_cancel and\n> > >     rte_alarm_set.\n> > >\n> > > Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>\n> > > Reviewed-by: Michal Jastrzebski <michalx.k.jastrzebski@intel.com>\n> > >\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, 45 insertions(+), 26 deletions(-)\n> > >\n> > \n> > > diff --git a/lib/librte_eal/common/include/rte_alarm.h b/lib/librte_eal/common/include/rte_alarm.h\n> > > index d451522..e7cbaef 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 outside alarm callback it wait for all callbacks to finish its execution.\n> > >   *\n> > >   * @param cb_fn\n> > >   *  alarm callback\n> > > diff --git a/lib/librte_eal/linuxapp/eal/eal_alarm.c b/lib/librte_eal/linuxapp/eal/eal_alarm.c\n> > > index 480f0cb..ea8dfb4 100644\n> > > --- a/lib/librte_eal/linuxapp/eal/eal_alarm.c\n> > > +++ b/lib/librte_eal/linuxapp/eal/eal_alarm.c\n> > > @@ -69,7 +69,8 @@ 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> > > @@ -108,11 +109,13 @@ 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> > How exactly does this work?  From my read all alarm callbacks are handled by the\n> > thread created in rte_eal_intr_init (which runs forever in\n> > eal_intr_thread_main()). \n> \n> In current implementation - yes.\n> \n>  So every assignment to the above executing_id value\n> > will be from that thread.  As such, anytime rte_eal_alarm_cancel is called from\n> > within a callback we are guaranteed that:\n> > a) the ap->executing flag is set to 1\n> > b) the ap->executing_id value should equal whatever is returned from\n> > pthread_self()\n> \n> Yes\n> \n> > \n> > That will cause the executing counter local to the cancel function to get\n> > incremented, meaning we will deadlock withing that do { ... } while (executing\n> > != 0) loop, no?\n> \n> No, as for the case when cancel is called from callback:\n> pthread_equal(ap->executing_id, pthread_self())\n> would return non-zero value (which means threads ids are equal), so executing will not be incremented. \n> \nAh, pthread_equal is one of the backwards functions that returns zero for\ninequality.  Maybe then rewrite that as:\nif (!pthread_equal(...)\n\nSo its clear that we're looking for inequality there to increment?\n\n> > \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> > > +\n> > >  \t\tLIST_REMOVE(ap, next);\n> > >  \t\trte_free(ap);\n> > >  \t}\n> > > @@ -145,7 +148,7 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)\n> > >  \tif (us < 1 || us > (UINT64_MAX - US_PER_S) || cb_fn == NULL)\n> > >  \t\treturn -EINVAL;\n> > >\n> > > -\tnew_alarm = rte_malloc(NULL, sizeof(*new_alarm), 0);\n> > > +\tnew_alarm = rte_zmalloc(NULL, sizeof(*new_alarm), 0);\n> > >  \tif (new_alarm == NULL)\n> > >  \t\treturn -ENOMEM;\n> > >\n> > > @@ -156,7 +159,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> > This removes the only place where ->executing is cleared again.  If there is\n> > only one change to this bits state (which is the case after this patch), it\n> > seems that you can just use the executing bit as the test in the alarm_cancel\n> > function, and remove all the pthread_self mess.\n> \n> I believe we do need executing_id here.\n> It allows us to distinguish are we executing cancel from a callback or not.\n> \nGiven what you said above, I agree, at least in the current implementation.  It\nstill seems like theres a simpler solution that doesn't require all the\ncomparative gymnastics.\n\nWhat if, instead of testing if you're the callback thread, we turn the executing\nfield of alarm_entry into a bitfield, where bit 0 represents the former\n\"executing\" state, and bit 1 is defined as a \"cancelled\" bit.  Then\nrte_eal_alarm_cancel becomes a search that, when an alarm is found simply or's\nin the cancelled bit to the executing bit field.  When the callback thread runs,\nit skips executing any alarm that is marked as cancelled, but frees all alarm\nentries that are executed or cancelled.  That gives us a single point at which\nfrees of alarm entires happen?  Something like the patch below (completely\nuntested)?\n\nIt also seems like the alarm api as a whole could use some improvement.  The\nway its written right now, theres no way to refer to a specific alarm (i.e.\ncancelation relies on the specification of a function and data pointer, which\nmay refer to multiple timers).  Shouldn't rte_eal_alarm_set return an opaque\nhandle to a unique timer instance that can be store by a caller and used to\nspecfically cancel that timer?  Thats how both the bsd and linux timer\nsubsystems model timers.",
    "diff": "diff --git a/lib/librte_eal/linuxapp/eal/eal_alarm.c b/lib/librte_eal/linuxapp/eal/eal_alarm.c\nindex 480f0cb..73b6dc5 100644\n--- a/lib/librte_eal/linuxapp/eal/eal_alarm.c\n+++ b/lib/librte_eal/linuxapp/eal/eal_alarm.c\n@@ -64,6 +64,9 @@\n #define MS_PER_S 1000\n #define US_PER_S (US_PER_MS * MS_PER_S)\n \n+#define ALARM_EXECUTING (1 << 0) \n+#define ALARM_CANCELLED (1 << 1)\n+ \n struct alarm_entry {\n \tLIST_ENTRY(alarm_entry) next;\n \tstruct timeval time;\n@@ -107,12 +110,14 @@ eal_alarm_callback(struct rte_intr_handle *hdl __rte_unused,\n \t\t\tgettimeofday(&now, NULL) == 0 &&\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\trte_spinlock_unlock(&alarm_list_lk);\n+\t\tap->executing |= ALARM_EXECUTING;\n+\t\tif (likely(!(ap->executing & ALARM_CANCELLED)) {\n+\t\t\trte_spinlock_unlock(&alarm_list_lk);\n \n-\t\tap->cb_fn(ap->cb_arg);\n+\t\t\tap->cb_fn(ap->cb_arg);\n \n-\t\trte_spinlock_lock(&alarm_list_lk);\n+\t\t\trte_spinlock_lock(&alarm_list_lk);\n+\t\t}\n \t\tLIST_REMOVE(ap, next);\n \t\trte_free(ap);\n \t}\n@@ -209,10 +214,9 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)\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\tcb_fn == ap->cb_fn &&\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\tap->executing |= ALARM_CANCELLED;\n \t\tcount++;\n \t}\n \tap_prev = ap;\n@@ -220,10 +224,9 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)\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+\t\tif (cb_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\tap->executing |= ALARM_CANCELLED;\n \t\t\tcount++;\n \t\t\tap = ap_prev;\n \t\t}\n",
    "prefixes": [
        "dpdk-dev",
        "v2"
    ]
}