From patchwork Mon Mar 2 18:46:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 45310 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8FC2B214B5 for ; Mon, 2 Mar 2015 18:48:16 +0000 (UTC) Received: by wghk14 with SMTP id k14sf25056288wgh.0 for ; Mon, 02 Mar 2015 10:48:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=z13cB7u8MlmlXj5iYY6fyEbwSdeTGKxwWyJcPQNrxaw=; b=gRYAbBfQ/6mBx9qTdASiqowIoU6iBifNuyNKVrbvvvJmbwqiicSRAtXHzHZ3xPKqlS ln6UKdFEpmCsLC2fxJXtK1kvO2XeQ0zBpCCdmef7dAwi42ut6Qzqucr4Rgp07Ef+9XCj qH9q/S+kZCMSXt6lFKaFmb1IQZH2GvEXTXStPxJFRjtqe31MEmZinyZZl/nKjwesyXhP tEl4a81/VeV+5Dlmi4uWQrqjd6M3IVMpiU20NT1d3nH3SBfvtsNFTGxMQrGW4R6Y/VQA kkHOYAnoTGY+y2JpOeDYcPaJ7Z9jdSn0erK43N6ysQZw0/hBBDLviQvwU5KhKTOQDMk9 +vAQ== X-Gm-Message-State: ALoCoQmyAOUE3TeXJOPcNkGwrX306ZdYDw/3GDQOIWEVwBzEknIM+eE0EyOfa5T+zipEQhnWaq1a X-Received: by 10.152.19.100 with SMTP id d4mr4016421lae.7.1425322095824; Mon, 02 Mar 2015 10:48:15 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.4 with SMTP id f4ls362985lah.18.gmail; Mon, 02 Mar 2015 10:48:15 -0800 (PST) X-Received: by 10.152.23.42 with SMTP id j10mr25317973laf.115.1425322095671; Mon, 02 Mar 2015 10:48:15 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id g2si9414725lag.149.2015.03.02.10.48.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 10:48:15 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by lbiz12 with SMTP id z12so4196916lbi.12 for ; Mon, 02 Mar 2015 10:48:15 -0800 (PST) X-Received: by 10.112.224.3 with SMTP id qy3mr3070995lbc.36.1425322095578; Mon, 02 Mar 2015 10:48:15 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp90306lbj; Mon, 2 Mar 2015 10:48:14 -0800 (PST) X-Received: by 10.140.82.176 with SMTP id h45mr51020837qgd.75.1425322094202; Mon, 02 Mar 2015 10:48:14 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id o65si12422401qhb.19.2015.03.02.10.48.13 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 02 Mar 2015 10:48:14 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YSVNy-0008KT-Mc; Mon, 02 Mar 2015 18:48:10 +0000 Received: from mail-lb0-f169.google.com ([209.85.217.169]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YSVNE-0008AY-Ay for lng-odp@lists.linaro.org; Mon, 02 Mar 2015 18:47:24 +0000 Received: by lbiz11 with SMTP id z11so6125255lbi.3 for ; Mon, 02 Mar 2015 10:47:18 -0800 (PST) X-Received: by 10.152.26.201 with SMTP id n9mr8027019lag.29.1425322038790; Mon, 02 Mar 2015 10:47:18 -0800 (PST) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id i13sm2696725lab.38.2015.03.02.10.47.17 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Mar 2015 10:47:18 -0800 (PST) From: Ciprian Barbu To: lng-odp@lists.linaro.org Date: Mon, 2 Mar 2015 20:46:56 +0200 Message-Id: <1425322017-14636-12-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1425322017-14636-1-git-send-email-ciprian.barbu@linaro.org> References: <1425322017-14636-1-git-send-email-ciprian.barbu@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH NETMAP 11/12] linux-netmap: pktio: add per device RX and TX locks X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ciprian.barbu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 These locks ensure exclusive access to netmap rings when at least two different pktios are opened for the same interface. Exclusive access to pktio instance is already guaranteed via lock_entry and unlock_entry. Signed-off-by: Ciprian Barbu --- platform/linux-netmap/include/odp_packet_netmap.h | 3 +++ platform/linux-netmap/odp_packet_netmap.c | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/platform/linux-netmap/include/odp_packet_netmap.h b/platform/linux-netmap/include/odp_packet_netmap.h index fe376d1..7b69156 100644 --- a/platform/linux-netmap/include/odp_packet_netmap.h +++ b/platform/linux-netmap/include/odp_packet_netmap.h @@ -18,6 +18,7 @@ #include #include #include +#include #define ODP_NETMAP_RING_HW 0 #define ODP_NETMAP_RING_SW 1 @@ -29,6 +30,8 @@ */ typedef struct { char ifname[IFNAMSIZ]; + odp_ticketlock_t rx_lock; + odp_ticketlock_t tx_lock; } netmap_dev_t; /** Packet socket using netmap mmaped rings for both Rx and Tx */ diff --git a/platform/linux-netmap/odp_packet_netmap.c b/platform/linux-netmap/odp_packet_netmap.c index 9b52bd6..8e68d34 100644 --- a/platform/linux-netmap/odp_packet_netmap.c +++ b/platform/linux-netmap/odp_packet_netmap.c @@ -196,6 +196,8 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, nm_dev_cnt++; snprintf(netmap_devs[i].ifname, sizeof(netmap_devs[i].ifname), "%s", netdev); + odp_ticketlock_init(&netmap_devs[i].rx_lock); + odp_ticketlock_init(&netmap_devs[i].tx_lock); pkt_nm->nm_dev = &netmap_devs[i]; } odp_spinlock_unlock(&nm_global_lock); @@ -311,14 +313,19 @@ int recv_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], fds[0].fd = fd; fds[0].events = POLLIN; - ret = poll(fds, 1, POLL_TMO); - if (ret <= 0 || (fds[0].revents & POLLERR)) - return 0; - args.pkt_table = pkt_table; args.nb_rx = 0; args.pkt_nm = pkt_nm; + + odp_ticketlock_lock(&pkt_nm->nm_dev->rx_lock); + ret = poll(fds, 1, POLL_TMO); + if (ret <= 0 || (fds[0].revents & POLLERR)) { + odp_ticketlock_unlock(&pkt_nm->nm_dev->rx_lock); + return 0; + } + nm_dispatch(pkt_nm->desc, len, nm_recv_cb, (uint8_t *)&args); + odp_ticketlock_unlock(&pkt_nm->nm_dev->rx_lock); return args.nb_rx; } @@ -334,9 +341,12 @@ int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], fds[0].fd = fd; fds[0].events = POLLOUT; + odp_ticketlock_lock(&pkt_nm->nm_dev->tx_lock); ret = poll(fds, 1, POLL_TMO); - if (ret <= 0 || (fds[0].revents & POLLERR)) + if (ret <= 0 || (fds[0].revents & POLLERR)) { + odp_ticketlock_unlock(&pkt_nm->nm_dev->tx_lock); goto out; + } for (nb_tx = 0; nb_tx < len; nb_tx++) { odp_packet_t pkt = pkt_table[nb_tx]; @@ -345,6 +355,7 @@ int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], if (nm_inject(pkt_nm->desc, frame, frame_len) == 0) break; } + odp_ticketlock_unlock(&pkt_nm->nm_dev->tx_lock); out: for (tx = 0; tx < len; tx++)