From patchwork Fri Oct 30 15:44:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 55839 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp1302979lbr; Fri, 30 Oct 2015 08:44:48 -0700 (PDT) X-Received: by 10.107.130.101 with SMTP id e98mr12083037iod.77.1446219888414; Fri, 30 Oct 2015 08:44:48 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id ph3si3044030igb.0.2015.10.30.08.44.48; Fri, 30 Oct 2015 08:44:48 -0700 (PDT) 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 D13EE62C53; Fri, 30 Oct 2015 15:44:47 +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_H2,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 48C8362C42; Fri, 30 Oct 2015 15:44:43 +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 5190662C4A; Fri, 30 Oct 2015 15:44:41 +0000 (UTC) Received: from mail-ob0-f176.google.com (mail-ob0-f176.google.com [209.85.214.176]) by lists.linaro.org (Postfix) with ESMTPS id 788C862C40 for ; Fri, 30 Oct 2015 15:44:40 +0000 (UTC) Received: by obctp1 with SMTP id tp1so46887811obc.2 for ; Fri, 30 Oct 2015 08:44:40 -0700 (PDT) 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=JWTX4LUKhHJ1E1s1JsGd3izuuYrtdXfe7xR+mp+9Wh8=; b=r4pExb0Zctox4eLuSPT/tqvsirLa/HtCelpCsJoh5tWCRWwOR+YF2GLrQGDbKx4CpK M8mD7Y8mbmNJ91ECmRoB5CNvkeZ0sdtPaxdHEfb0CtDv9N/uKn2G2TggxsXfW3UJ1MsK Q8JPosBkDl1b0ymWFQ9ls7EagrKRA4Ev3oejhM+Jbtv8+yeZx7DbXmJzTOah6ZKrr85T hf97ReMtc35xHjSSGe8oaUfdRoUl4SJ4dnsPyRPgoj3BcpcGgqYz/2Zaqf21gfkew/uS 4q1maCA4TXttJE5vcA8p9Y+rIkYx11gjUXbeV7EQpa3YjBCFHhsDHcfaYmZf6bXcexeZ F7sA== 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=JWTX4LUKhHJ1E1s1JsGd3izuuYrtdXfe7xR+mp+9Wh8=; b=CCSaiYxi4jVVWWyybI1C2I4qUKbHwAjzDbOAcsbWUXKbdjzOCknG98l9/63s0z5RVk D2emu5FWYfNYdrLzzW5w+9PxSXvgnDB3eb7VTNHfI/uynJg3y+je/TyEfqdCvVqKGjYH FeL/ZrTp/FCp8O9lj/KARvviK4s4fH5ly5Wt0sTNslyHSaPMUJPtmg9KP28/WyUCXkxI FycDesKYojwpoXCZvHoV/r4aRMWX32zqz2urc/Hqtnuq7XyILvXlB8qkekMcc/w8VvaG xxwk2DG4EvfIPr8H9FFGxmtvjh+2ZlGiZktC+oLxJxXJACmkd5cpWQpPedyufe7NYcpq Jyaw== X-Gm-Message-State: ALoCoQlAEeZv3TSKwvKqYKQe0n/gj3gDVn3w+Rae4SZswES98Dia0rn9GakY7e0e9llI9oMuvWu+ X-Received: by 10.60.78.6 with SMTP id x6mr6403352oew.77.1446219879987; Fri, 30 Oct 2015 08:44:39 -0700 (PDT) Received: from Ubuntu15.localdomain (cpe-66-68-129-43.austin.res.rr.com. [66.68.129.43]) by smtp.gmail.com with ESMTPSA id x128sm2984940oix.0.2015.10.30.08.44.39 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Oct 2015 08:44:39 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org, carl.wallen@nokia.com Date: Fri, 30 Oct 2015 10:44:34 -0500 Message-Id: <1446219874-30024-1-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.4 X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH] linux-generic: queue: yield trying to obtain multiple locks 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" To avoid deadlock, especially on unicore systems, force an explicit yield while not holding either lock when attempting to acquire multiple locks for ordered queue processing. 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 | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index a27af0b..4251c7c 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -48,6 +48,22 @@ 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) +{ + int i; + + while (1) { + for (i = 0; i < 10; i++) { + LOCK(&qe1->s.lock); + if (LOCK_TRY(&qe2->s.lock)) + return; + UNLOCK(&qe1->s.lock); + odp_sync_stores(); + } + sched_yield(); + } +} + queue_entry_t *get_qentry(uint32_t queue_id) { return &queue_tbl->queue[queue_id]; @@ -370,11 +386,7 @@ 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);