From patchwork Mon Nov 2 16:08:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 55901 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp1350904lbr; Mon, 2 Nov 2015 08:08:59 -0800 (PST) X-Received: by 10.55.207.3 with SMTP id e3mr30406467qkj.32.1446480539105; Mon, 02 Nov 2015 08:08:59 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id y203si15973548qka.43.2015.11.02.08.08.58; Mon, 02 Nov 2015 08:08:59 -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 6A8EC61586; Mon, 2 Nov 2015 16:08:58 +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 2387561942; Mon, 2 Nov 2015 16:08:54 +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 D828861942; Mon, 2 Nov 2015 16:08:51 +0000 (UTC) Received: from mail-oi0-f45.google.com (mail-oi0-f45.google.com [209.85.218.45]) by lists.linaro.org (Postfix) with ESMTPS id EB39C619CF for ; Mon, 2 Nov 2015 16:08:20 +0000 (UTC) Received: by oiao187 with SMTP id o187so97506134oia.3 for ; Mon, 02 Nov 2015 08:08:20 -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=FpPyamMFvKyaLuLa4dxbsgYrSQevaCiJl0nNfyqaUh0=; b=sIm3Q6WWjDYpcB1CipOiPOqMACRVkEIcx/5LQn3NOdmSf2dWfX6Ihx1MABOOjbFwb/ bCAT6sr8PztSp80+6otprVFTRNEEZg+JCrxGR07h2MxV2cxCBSV0rMdQQEzDtewSB8F2 9+EW0y76kH1bg3S/YoW9s4Zi2xSh1wrXjwACNpjIrHLhRBszGHBEyREKrphb9fDDHQxk jumkoXayzaTjXnYx9c6zRVdp5iFwQE+Er2srx4QZ+U9WGiWfTNVaihIEOfQKvJa65a/M uzqohAKlnSC753/RBHGm+L5TfDfpF3/YIaV5fe5HKGyd3EHQJpMfbAvq5nJzsp4DMdh6 aPQg== 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=FpPyamMFvKyaLuLa4dxbsgYrSQevaCiJl0nNfyqaUh0=; b=DyR4QAiPomfVeg1PxMS0S4FZ9NBYZRO57liQRhJddsHZ7P3EiQR9tGCBW6IEjfs4z5 NkKFpp+SOf1RI3zIUKyoQZeAODVWPPWsgkV4bf6EAuP0cOUlEw1ZnShSY0iS+HUsshX2 GR4V8bnG1jHdcIREK9YHT/Ebf8vQjfnCF31VzmLGLHQZko7yKHelcrxwt4yQl/LNcdjP jrOGSzPGO47Tzy1/U63wESq2lNzICOK5cQ0Nju67SvuNlQLU8DLgw+Cml8P6fajhVL7T Z5/s5aoaffP7DtgK/S6j73WK87QEQJ+9Ti/nofCQ0zgZPm8qPbIEoYgvjxy1vv52pC3b Qr0g== X-Gm-Message-State: ALoCoQlzp1YpvFiFcnyrOqopd2zk49b5+lGRkhI2/1Du93RMgEh9saN2jDocAdzI9JPMm8CYZPFH X-Received: by 10.202.217.7 with SMTP id q7mr14263445oig.29.1446480500441; Mon, 02 Nov 2015 08:08:20 -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 p133sm1156523oif.9.2015.11.02.08.08.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Nov 2015 08:08:19 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org, carl.wallen@nokia.com Date: Mon, 2 Nov 2015 10:08:15 -0600 Message-Id: <1446480495-21778-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 PATCH] 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. 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);