Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/694/?format=api
https://patches.dpdk.org/api/patches/694/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1412173222-22391-1-git-send-email-pawelx.wodkowski@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": "<1412173222-22391-1-git-send-email-pawelx.wodkowski@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1412173222-22391-1-git-send-email-pawelx.wodkowski@intel.com", "date": "2014-10-01T14:20:22", "name": "[dpdk-dev,v3] alarms: Change alarm cancel function to be thread-safe", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": true, "hash": "9e390b51cbd1cbc82c90737370c2098ecc9196e1", "submitter": { "id": 58, "url": "https://patches.dpdk.org/api/people/58/?format=api", "name": "Wodkowski, PawelX", "email": "pawelx.wodkowski@intel.com" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1412173222-22391-1-git-send-email-pawelx.wodkowski@intel.com/mbox/", "series": [], "comments": "https://patches.dpdk.org/api/patches/694/comments/", "check": "pending", "checks": "https://patches.dpdk.org/api/patches/694/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 73CFD6A96;\n\tWed, 1 Oct 2014 16:13:50 +0200 (CEST)", "from mga14.intel.com (mga14.intel.com [192.55.52.115])\n\tby dpdk.org (Postfix) with ESMTP id 0C34568AA\n\tfor <dev@dpdk.org>; Wed, 1 Oct 2014 16:13:46 +0200 (CEST)", "from fmsmga003.fm.intel.com ([10.253.24.29])\n\tby fmsmga103.fm.intel.com with ESMTP; 01 Oct 2014 07:11:04 -0700", "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby FMSMGA003.fm.intel.com with ESMTP; 01 Oct 2014 07:14:06 -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\ts91EKQho006124; Wed, 1 Oct 2014 15:20:27 +0100", "from sivswdev01.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev01.ir.intel.com with ESMTP id s91EKQkS022447;\n\tWed, 1 Oct 2014 15:20:26 +0100", "(from pwodkowx@localhost)\n\tby sivswdev01.ir.intel.com with id s91EKQ23022436;\n\tWed, 1 Oct 2014 15:20:26 +0100" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"4.97,862,1389772800\"; d=\"scan'208\";a=\"394124535\"", "From": "Pawel Wodkowski <pawelx.wodkowski@intel.com>", "To": "dev@dpdk.org", "Date": "Wed, 1 Oct 2014 15:20:22 +0100", "Message-Id": "<1412173222-22391-1-git-send-email-pawelx.wodkowski@intel.com>", "X-Mailer": "git-send-email 1.7.4.1", "Subject": "[dpdk-dev] [PATCH v3] alarms: Change alarm cancel function to be\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": "v3:\nSet rte_errno inside rte_alarm_cancel() to inform caller about canceling result.\n\t\nv2: \nEliminate a race between rte_alarm_set() used in context of executing callback\nfunction and other threads that use rte_alarm_cancel().\n\nSigned-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>\n---\n lib/librte_eal/common/include/rte_alarm.h | 12 ++++-\n lib/librte_eal/linuxapp/eal/eal_alarm.c | 83 ++++++++++++++++++++---------\n 2 files changed, 68 insertions(+), 27 deletions(-)", "diff": "diff --git a/lib/librte_eal/common/include/rte_alarm.h b/lib/librte_eal/common/include/rte_alarm.h\nindex d451522..d5d4e9d 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 execution.\n *\n * @param cb_fn\n * alarm callback\n@@ -86,7 +87,14 @@ int rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb, void *cb_arg);\n * can be used here.\n *\n * @return\n- * - The number of callbacks removed\n+ * - value greater than 0 and rte_errno not changed - returned value is\n+ * the number of canceled alarm callback functions\n+ * - value greater or equal 0 and rte_errno set to EINPROGRESS, at least one\n+ * alarm could not be canceled because cancelation was requested from alarm\n+ * callback context. Returned value is the number of succesfuly canceled\n+ * alarm callbacks\n+ * - 0 and rte_errno set to ENOENT - no alarm found\n+ * - -1 and rte_errno set to EINVAL - invalid parameter (NULL callback)\n */\n int rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg);\n \ndiff --git a/lib/librte_eal/linuxapp/eal/eal_alarm.c b/lib/librte_eal/linuxapp/eal/eal_alarm.c\nindex 480f0cb..4801650 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 \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 \trte_spinlock_lock(&alarm_list_lk);\n \tif (!handler_registered) {\n@@ -202,34 +204,65 @@ 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 err = 0;\n+\tint executing;\n \n-\tif (!cb_fn)\n+\tif (!cb_fn) {\n+\t\trte_errno = EINVAL;\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\t/* If calling from other context, mark that alarm is executing\n+\t\t\t\t * so loop can spin till it finish. Otherwise we are trying to\n+\t\t\t\t * cancel our self - mark it by EINPROGRESS */\n+\t\t\t\tif (pthread_equal(ap->executing_id, pthread_self()) == 0)\n+\t\t\t\t\texecuting++;\n+\t\t\t\telse\n+\t\t\t\t\terr = EINPROGRESS;\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\telse\n+\t\t\t\t\terr = EINPROGRESS;\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+\tif (count == 0 && err == 0)\n+\t\trte_errno = ENOENT;\n+\telse if (err)\n+\t\trte_errno = err;\n+\n \treturn count;\n }\n-\n", "prefixes": [ "dpdk-dev", "v3" ] }{ "id": 694, "url": "