From patchwork Wed Jan 20 16:37:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoltan Kiss X-Patchwork-Id: 60047 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp3278472lbb; Wed, 20 Jan 2016 08:38:30 -0800 (PST) X-Received: by 10.55.81.2 with SMTP id f2mr46360900qkb.87.1453307910677; Wed, 20 Jan 2016 08:38:30 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g7si44412316qhc.102.2016.01.20.08.38.30; Wed, 20 Jan 2016 08:38:30 -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 Received: by lists.linaro.org (Postfix, from userid 109) id 3E04161712; Wed, 20 Jan 2016 16:38:30 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=hjevW9lO; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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 F13636179C; Wed, 20 Jan 2016 16:37:33 +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 A2FF661745; Wed, 20 Jan 2016 16:37:29 +0000 (UTC) Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by lists.linaro.org (Postfix) with ESMTPS id E7A1B6177B for ; Wed, 20 Jan 2016 16:37:26 +0000 (UTC) Received: by mail-wm0-f53.google.com with SMTP id n5so38631387wmn.0 for ; Wed, 20 Jan 2016 08:37:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=f+WQmgX7Y7AtW96nYijkkJPkjA7UR/mk8JUYzYcpQvE=; b=hjevW9lOc4dZ4nftT5ZrokbMzIVakoYnErNeU8Mt/Us5s+iJW3C81IiwKsvH/D0M00 L7IhBz5OBKSFi5ojAUbwyjalELPm2J3xAJXWlDwYm7MaNE6YDZnexQJK5LYL/WoOG/if GltcqY/Dw7AVoF2pLvr4DXmk23JzLu9UtzCj4= 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:in-reply-to :references; bh=f+WQmgX7Y7AtW96nYijkkJPkjA7UR/mk8JUYzYcpQvE=; b=kZeDH4uPGZx21cSYko6PCbqG9kopTsJ3tW1UPzkTC0XVTH/v4MZyc/+a/fkQU4UNXP Gt1nUzhf9bF4otnZnYVfXgPZRYQ6IMy/C5hdUk7z5mOTJ7oH5jYnryizbbxkkM2r6OtC +Nxgnt7+mD6xQkBIbd89QkDy4r4vFMHFWShF9x08tOzydAKqQNho+ZPwMn8Rq9tsTen6 L4UVuzNvf8PUCBS4NU0IdUR/w/iHvLAlkP5Y8li8LoJo28M7PM3Jh8j+oOVe/9WQYwge raqRQMdF5YrXK172dsR9heJaNoIuskdKk1XM/8TiCElIrsbJxDrVg3A7HbcacWhfIp89 N2Wg== X-Gm-Message-State: AG10YOSXyXqAO9gBiai/5YBsTGj+2AzqgDTPsn+sJOlNeN8kGPm+QkavzKirJtJAsUKyVKNDMSE= X-Received: by 10.28.54.159 with SMTP id y31mr5332175wmh.87.1453307846216; Wed, 20 Jan 2016 08:37:26 -0800 (PST) Received: from localhost.localdomain ([195.11.233.227]) by smtp.googlemail.com with ESMTPSA id l7sm34131552wjx.14.2016.01.20.08.37.25 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 20 Jan 2016 08:37:25 -0800 (PST) From: Zoltan Kiss To: lng-odp@lists.linaro.org Date: Wed, 20 Jan 2016 16:37:11 +0000 Message-Id: <1453307831-15459-3-git-send-email-zoltan.kiss@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453307831-15459-1-git-send-email-zoltan.kiss@linaro.org> References: <1453307831-15459-1-git-send-email-zoltan.kiss@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 2/2] linux-generic: packet_io: separate locks for RX/TX 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" It's possible that two threads want to use the same packet IO in the same time, but one wants RX while the other wants TX. In this case they would block each other unnecessary on the same lock. This could be seen e.g. with odp_l2fwd. Replace that lock with two new ones for each direction. Most callers need both, but send and receive can work with only one. Signed-off-by: Zoltan Kiss --- .../linux-generic/include/odp_packet_io_internal.h | 4 +++- platform/linux-generic/odp_packet_io.c | 27 +++++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 4d73952..84bee1e 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -64,7 +64,9 @@ typedef struct { struct pktio_entry { const struct pktio_if_ops *ops; /**< Implementation specific methods */ - odp_ticketlock_t lock; /**< entry ticketlock */ + /* These two locks together lock the whole pktio device */ + odp_ticketlock_t rxl; /**< RX ticketlock */ + odp_ticketlock_t txl; /**< TX ticketlock */ int taken; /**< is entry taken(1) or free(0) */ int cls_enabled; /**< is classifier enabled */ odp_pktio_t handle; /**< pktio handle */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 267aa01..908f9a4 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -55,7 +55,8 @@ int odp_pktio_init_global(void) for (id = 1; id <= ODP_CONFIG_PKTIO_ENTRIES; ++id) { pktio_entry = &pktio_tbl->entries[id - 1]; - odp_ticketlock_init(&pktio_entry->s.lock); + odp_ticketlock_init(&pktio_entry->s.rxl); + odp_ticketlock_init(&pktio_entry->s.txl); odp_spinlock_init(&pktio_entry->s.cls.lock); odp_spinlock_init(&pktio_entry->s.cls.l2_cos_table.lock); odp_spinlock_init(&pktio_entry->s.cls.l3_cos_table.lock); @@ -106,24 +107,28 @@ static void set_taken(pktio_entry_t *entry) static void lock_entry(pktio_entry_t *entry) { - odp_ticketlock_lock(&entry->s.lock); + odp_ticketlock_lock(&entry->s.rxl); + odp_ticketlock_lock(&entry->s.txl); } static void unlock_entry(pktio_entry_t *entry) { - odp_ticketlock_unlock(&entry->s.lock); + odp_ticketlock_unlock(&entry->s.txl); + odp_ticketlock_unlock(&entry->s.rxl); } static void lock_entry_classifier(pktio_entry_t *entry) { - odp_ticketlock_lock(&entry->s.lock); + odp_ticketlock_lock(&entry->s.rxl); + odp_ticketlock_lock(&entry->s.txl); odp_spinlock_lock(&entry->s.cls.lock); } static void unlock_entry_classifier(pktio_entry_t *entry) { odp_spinlock_unlock(&entry->s.cls.lock); - odp_ticketlock_unlock(&entry->s.lock); + odp_ticketlock_unlock(&entry->s.txl); + odp_ticketlock_unlock(&entry->s.rxl); } static void init_pktio_entry(pktio_entry_t *entry) @@ -385,15 +390,15 @@ int odp_pktio_recv(odp_pktio_t id, odp_packet_t pkt_table[], int len) if (pktio_entry == NULL) return -1; - lock_entry(pktio_entry); + odp_ticketlock_lock(&pktio_entry->s.rxl); if (pktio_entry->s.state == STATE_STOP || pktio_entry->s.param.in_mode == ODP_PKTIN_MODE_DISABLED) { - unlock_entry(pktio_entry); + odp_ticketlock_unlock(&pktio_entry->s.rxl); __odp_errno = EPERM; return -1; } pkts = pktio_entry->s.ops->recv(pktio_entry, pkt_table, len); - unlock_entry(pktio_entry); + odp_ticketlock_unlock(&pktio_entry->s.rxl); if (pkts < 0) return pkts; @@ -412,15 +417,15 @@ int odp_pktio_send(odp_pktio_t id, odp_packet_t pkt_table[], int len) if (pktio_entry == NULL) return -1; - lock_entry(pktio_entry); + odp_ticketlock_lock(&pktio_entry->s.txl); if (pktio_entry->s.state == STATE_STOP || pktio_entry->s.param.out_mode == ODP_PKTOUT_MODE_DISABLED) { - unlock_entry(pktio_entry); + odp_ticketlock_unlock(&pktio_entry->s.txl); __odp_errno = EPERM; return -1; } pkts = pktio_entry->s.ops->send(pktio_entry, pkt_table, len); - unlock_entry(pktio_entry); + odp_ticketlock_unlock(&pktio_entry->s.txl); return pkts; }