From patchwork Mon Nov 2 17:11:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 55903 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp1382032lbr; Mon, 2 Nov 2015 09:11:50 -0800 (PST) X-Received: by 10.50.222.75 with SMTP id qk11mr11184170igc.60.1446484310739; Mon, 02 Nov 2015 09:11:50 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f41si18037987ioj.52.2015.11.02.09.11.49; Mon, 02 Nov 2015 09:11:50 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id 80E0561B3B; Mon, 2 Nov 2015 17:11:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 8216361A29; Mon, 2 Nov 2015 17:11:45 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id AE64461A49; Mon, 2 Nov 2015 17:11:43 +0000 (UTC) Received: from mail-ob0-f169.google.com (mail-ob0-f169.google.com [209.85.214.169]) by lists.linaro.org (Postfix) with ESMTPS id 9135E61915 for ; Mon, 2 Nov 2015 17:11:42 +0000 (UTC) Received: by obbwb3 with SMTP id wb3so100206210obb.0 for ; Mon, 02 Nov 2015 09:11:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=WACI7cwOPLWMEFV399qo3cDMJDI6yYc01NZ4mTyK9N0=; b=V9rqQCjkyOAeupnBvSh2Qp6VlhzpsNkbLJUn/oNxl8ZcmP1T2rSAvBy/Hb+Nvomlc8 YvVPP3eER4pixc87U1d3SlIYX/5x8JBv0swaTWAt4L5HJ9aoBLyFVLpVJs4ffSLkKbHW GXUJgWmvZbT7H7VGkLJovWG5DXlkhoShrfDUaOzd2B4wjIkpbNoeccgP3jskIQYeSUnR O8Tgwj7KD8i4xfbCPcML/cWkbwY15FEmY7j75MWJJPgC553lf8aeAxjXEpcKMSBJoX2F UX6TFvS1gV8uHS6e6+/yFU4APXRe4/s7FGYClDZq5YPfSSP1RDCr8gSYQDbXLORyq4ME pPzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WACI7cwOPLWMEFV399qo3cDMJDI6yYc01NZ4mTyK9N0=; b=CxXaTl/JBTY3Nq6jahCtozGm1/N/L8vA1ry+OS6N6k3IAjI4T0J9ruS4/+rcrnw+rx e2H+z8+ynsv0flz2SOpBxdKt4jxwNH0BkB4WBp9YRjlPciDs56KyMai06hypAzz/1eaj jrc49pL1EQ5a7vndzYdOKzmCmswrBZKECbSAX8WiXZ2VvQrV0VJhzcMJI54P+qeOJOLV Dcxfc7WTzkfMwsjMRzg/V3vq27kRFn1pmxELkIjcuOGW+rKpB1GVNpyPVVNbD8j0gHQy zfGR2lIVlkxm4kELI5knwQJUB1UHjXcv8X8Dt6mYpWO8WSrT2+RGbJd7S6n70QTWJqpr xZPA== X-Gm-Message-State: ALoCoQke1LkhbJ+9k7JKJB8QzwH47WyhuHLOwzmdA79b/K7ApNKisP4ATyqgD9QL9m/e4+6bjCCC X-Received: by 10.182.116.200 with SMTP id jy8mr15821950obb.35.1446484301901; Mon, 02 Nov 2015 09:11:41 -0800 (PST) Received: from Ubuntu15.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id r65sm9250186oif.7.2015.11.02.09.11.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Nov 2015 09:11:41 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org, carl.wallen@nokia.com Date: Mon, 2 Nov 2015 11:11:37 -0600 Message-Id: <1446484297-837-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: Architecture patch Subject: [lng-odp] [API-NEXT PATCHv2] linux-generic: queue: use locking hierarchy for ordered queueing X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Enqueueing to ordered queues requires two locks (source and target queues). Since any queue can be either source or target, queues do not have a natural locking hierarchy. Create one by using the address of the qentry as the lock order. This addresses the aspect of Bug https://bugs.linaro.org/show_bug.cgi?id=1879 relating to deadlock in unicore systems. Suggested-by: Nicolas Morey-Chaisemartin Signed-off-by: Bill Fischofer --- platform/linux-generic/odp_queue.c | 39 +++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index a27af0b..1c15e17 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -48,6 +48,28 @@ typedef struct queue_table_t { static queue_table_t *queue_tbl; +static inline void get_qe_locks(queue_entry_t *qe1, queue_entry_t *qe2) +{ + /* Special case: enq to self */ + if (qe1 == qe2) { + LOCK(&qe1->s.lock); + return; + } + + /* Since any queue can be either a source or target, queues do not have + * a natural locking hierarchy. Create one by using the qentry address + * as the ordering mechanism. + */ + + if (qe1 < qe2) { + LOCK(&qe1->s.lock); + LOCK(&qe2->s.lock); + } else { + LOCK(&qe2->s.lock); + LOCK(&qe1->s.lock); + } +} + queue_entry_t *get_qentry(uint32_t queue_id) { return &queue_tbl->queue[queue_id]; @@ -370,14 +392,11 @@ int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr, int sustain) /* Need two locks for enq operations from ordered queues */ if (origin_qe) { - LOCK(&origin_qe->s.lock); - while (!LOCK_TRY(&queue->s.lock)) { - UNLOCK(&origin_qe->s.lock); - LOCK(&origin_qe->s.lock); - } + get_qe_locks(origin_qe, queue); if (odp_unlikely(origin_qe->s.status < QUEUE_STATUS_READY)) { UNLOCK(&queue->s.lock); - UNLOCK(&origin_qe->s.lock); + if (origin_qe != queue) + UNLOCK(&origin_qe->s.lock); ODP_ERR("Bad origin queue status\n"); ODP_ERR("queue = %s, origin q = %s, buf = %p\n", queue->s.name, origin_qe->s.name, buf_hdr); @@ -389,7 +408,7 @@ int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr, int sustain) if (odp_unlikely(queue->s.status < QUEUE_STATUS_READY)) { UNLOCK(&queue->s.lock); - if (origin_qe) + if (origin_qe && origin_qe != queue) UNLOCK(&origin_qe->s.lock); ODP_ERR("Bad queue status\n"); return -1; @@ -405,7 +424,8 @@ int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr, int sustain) * we're done here. */ UNLOCK(&queue->s.lock); - UNLOCK(&origin_qe->s.lock); + if (origin_qe != queue) + UNLOCK(&origin_qe->s.lock); return 0; } @@ -477,7 +497,8 @@ int queue_enq(queue_entry_t *queue, odp_buffer_hdr_t *buf_hdr, int sustain) /* Now handle any unblocked complete buffers destined for * other queues, appending placeholder bufs as needed. */ - UNLOCK(&queue->s.lock); + if (origin_qe != queue) + UNLOCK(&queue->s.lock); reorder_complete(origin_qe, &reorder_buf, &placeholder_buf, 1, 0); UNLOCK(&origin_qe->s.lock);