From patchwork Fri Nov 14 12:48:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 40830 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E4066240ED for ; Fri, 14 Nov 2014 12:49:17 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id bs8sf954330wib.8 for ; Fri, 14 Nov 2014 04:49:17 -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:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=tAYS8yR38y1qCfmVBEJ2DKMnIBvY+DU1Asg84eIaZa0=; b=QE7ZPhQ+RpkALGLjcqiV/Z99XJtDoyGQFcF1i4vh2X63SyD4Is/LlaNbwI2HuMy2TC 0YacpunCp5O1PISnjnbUOD4E7iaOfFgtpsvdi9JnM/nwW/YLjlPuOBax5QyAn01EbF24 e+QSemeIJYAjmNk0OJ2aq6i3eKGXWhWV+yMDFxVefV1Fd4VfqeySjaynw8zgldo309+6 GDXokpW/tu2EHu2i4YMMwqRxIqvhsSgMwOqhSKOJ74utnxDxfl1DR3Myr7NeklpbNmQU bXblTtQSzZ+XgZSD7yKsNNGHpLsZWDny2h7xAEN93AHTFYcFPWpGbFawU6P1QbKeCE51 2lfg== X-Gm-Message-State: ALoCoQkukPTl3vJYdhO9LHXNxz0w/nUcq5F0iE8J899AED+9aVMRxeDVeNYIOab2SSqlSfX4cQbY X-Received: by 10.112.119.194 with SMTP id kw2mr382707lbb.16.1415969357148; Fri, 14 Nov 2014 04:49:17 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.227 with SMTP id ap3ls914436lac.60.gmail; Fri, 14 Nov 2014 04:49:16 -0800 (PST) X-Received: by 10.112.11.133 with SMTP id q5mr2055462lbb.77.1415969356906; Fri, 14 Nov 2014 04:49:16 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id q4si27937917laj.9.2014.11.14.04.49.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Nov 2014 04:49:16 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id gd6so15060132lab.34 for ; Fri, 14 Nov 2014 04:49:16 -0800 (PST) X-Received: by 10.152.6.228 with SMTP id e4mr8058969laa.71.1415969356794; Fri, 14 Nov 2014 04:49:16 -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.184.201 with SMTP id ew9csp757645lbc; Fri, 14 Nov 2014 04:49:15 -0800 (PST) X-Received: by 10.236.32.8 with SMTP id n8mr9803775yha.74.1415969355199; Fri, 14 Nov 2014 04:49:15 -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 l103si50883388qgd.65.2014.11.14.04.49.14 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 14 Nov 2014 04:49:15 -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 1XpGJN-0005UC-GH; Fri, 14 Nov 2014 12:49:13 +0000 Received: from mail-lb0-f180.google.com ([209.85.217.180]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XpGJ1-0005PO-6w for lng-odp@lists.linaro.org; Fri, 14 Nov 2014 12:48:51 +0000 Received: by mail-lb0-f180.google.com with SMTP id z11so5896076lbi.39 for ; Fri, 14 Nov 2014 04:48:45 -0800 (PST) X-Received: by 10.152.21.97 with SMTP id u1mr1819061lae.84.1415969325706; Fri, 14 Nov 2014 04:48:45 -0800 (PST) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id r4sm8175438lar.3.2014.11.14.04.48.44 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Nov 2014 04:48:44 -0800 (PST) From: Ciprian Barbu To: lng-odp@lists.linaro.org Date: Fri, 14 Nov 2014 14:48:25 +0200 Message-Id: <1415969305-13255-5-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415969305-13255-1-git-send-email-ciprian.barbu@linaro.org> References: <1415969305-13255-1-git-send-email-ciprian.barbu@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 NETMAP 4/4] Added per-device lock 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.215.47 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 Signed-off-by: Ciprian Barbu --- platform/linux-netmap/include/odp_packet_netmap.h | 12 +++++- platform/linux-netmap/odp_packet_netmap.c | 49 ++++++++++++++++++----- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/platform/linux-netmap/include/odp_packet_netmap.h b/platform/linux-netmap/include/odp_packet_netmap.h index 2ac10d2..0e4fb09 100644 --- a/platform/linux-netmap/include/odp_packet_netmap.h +++ b/platform/linux-netmap/include/odp_packet_netmap.h @@ -23,6 +23,16 @@ #define NETMAP_BLOCKING_IO +/* Since we allow more than one thread to open the same device + * this struct uinquely identifies a device so that proper locking + * can be implemented + */ +typedef struct { + char ifname[IFNAMSIZ]; + odp_spinlock_t rx_lock; + odp_spinlock_t tx_lock; +} netmap_dev_t; + /** Packet socket using netmap mmaped rings for both Rx and Tx */ typedef struct { odp_buffer_pool_t pool; @@ -34,7 +44,7 @@ typedef struct { uint32_t if_flags; odp_packet_t *pkt_table; /**< Used by recv_pkt_netmap */ int nb_rx; /**< Used by recv_pkt_netmap */ - char ifname[IFNAMSIZ]; + netmap_dev_t *nm_dev; } pkt_netmap_t; /** diff --git a/platform/linux-netmap/odp_packet_netmap.c b/platform/linux-netmap/odp_packet_netmap.c index 37e574b..8c56a66 100644 --- a/platform/linux-netmap/odp_packet_netmap.c +++ b/platform/linux-netmap/odp_packet_netmap.c @@ -58,11 +58,17 @@ static struct nm_desc mmap_desc; /** Used to store the mmap address; filled in first time, used for subsequent calls to nm_open */ -static odp_spinlock_t mmap_desc_lock; +static odp_spinlock_t nm_global_lock; /** Global lock for mmap addr and + dev lookup */ + +#define MAX_DEVS 32 +static netmap_dev_t netmap_devs[MAX_DEVS]; +static int nm_dev_cnt; int odp_netmap_init_global(void) { - odp_spinlock_init(&mmap_desc_lock); + odp_spinlock_init(&nm_global_lock); + memset(netmap_devs, 0, sizeof(netmap_devs)); return 0; } @@ -81,7 +87,7 @@ static int nm_do_ioctl(pkt_netmap_t * const pkt_nm, unsigned long cmd, } memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, pkt_nm->ifname, sizeof(ifr.ifr_name)); + strncpy(ifr.ifr_name, pkt_nm->nm_dev->ifname, sizeof(ifr.ifr_name)); switch (cmd) { case SIOCSIFFLAGS: @@ -125,7 +131,12 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, odp_packet_t pkt; uint8_t *pkt_buf; uint8_t *l2_hdr; - int ret; + int i, ret; + + if (nm_dev_cnt == MAX_DEVS) { + ODP_ERR("Maximum number of devices reached: %d\n", nm_dev_cnt); + return -1; + } if (pool == ODP_BUFFER_POOL_INVALID) return -1; @@ -146,10 +157,9 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, odph_packet_free(pkt); - snprintf(pkt_nm->ifname, sizeof(pkt_nm->ifname), "%s", netdev); snprintf(ifname, sizeof(ifname), "netmap:%s", netdev); - odp_spinlock_lock(&mmap_desc_lock); + odp_spinlock_lock(&nm_global_lock); ODP_DBG("[%04d] Initial mmap addr: %p\n", odp_thread_id(), mmap_desc.mem); @@ -162,7 +172,7 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, if (pkt_nm->desc == NULL) { ODP_ERR("Error opening nm interface: %s\n", strerror(errno)); - odp_spinlock_unlock(&mmap_desc_lock); + odp_spinlock_unlock(&nm_global_lock); return -1; } @@ -170,7 +180,23 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, mmap_desc.mem = pkt_nm->desc->mem; mmap_desc.memsize = pkt_nm->desc->memsize; } - odp_spinlock_unlock(&mmap_desc_lock); + + /* Lookup dev */ + for (i = 0; i < nm_dev_cnt; i++) { + if (!strcmp(netmap_devs[i].ifname, netdev)) { + pkt_nm->nm_dev = &netmap_devs[i]; + break; + } + } + if (i == nm_dev_cnt) { + nm_dev_cnt++; + snprintf(netmap_devs[i].ifname, sizeof(netmap_devs[i].ifname), + "%s", netdev); + odp_spinlock_init(&netmap_devs[i].rx_lock); + odp_spinlock_init(&netmap_devs[i].tx_lock); + pkt_nm->nm_dev = &netmap_devs[i]; + } + odp_spinlock_unlock(&nm_global_lock); ODP_DBG("[%04d] mmap addr %p\n", odp_thread_id(), @@ -182,7 +208,7 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, if ((pkt_nm->if_flags & IFF_UP) == 0) { ODP_DBG("[%04d] %s is down, bringing up...\n", odp_thread_id(), - pkt_nm->ifname); + pkt_nm->nm_dev->ifname); pkt_nm->if_flags |= IFF_UP; } if (ETH_PROMISC) { @@ -293,7 +319,10 @@ int recv_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], pkt_nm->pkt_table = pkt_table; pkt_nm->nb_rx = 0; + + odp_spinlock_lock(&pkt_nm->nm_dev->rx_lock); nm_dispatch(pkt_nm->desc, len, nm_recv_cb, (uint8_t *)pkt_nm); + odp_spinlock_unlock(&pkt_nm->nm_dev->rx_lock); if (pkt_nm->nb_rx) ODP_DBG("[%04d] <=== rcvd %03u frames from netmap adapter\n", @@ -322,6 +351,7 @@ int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], ioctl(fd, NIOCTXSYNC, NULL); #endif + odp_spinlock_lock(&pkt_nm->nm_dev->tx_lock); for (nb_tx = 0; nb_tx < len; nb_tx++) { odp_packet_t pkt = pkt_table[nb_tx]; uint8_t *frame = odp_packet_l2(pkt); @@ -329,6 +359,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)) break; } + odp_spinlock_unlock(&pkt_nm->nm_dev->tx_lock); if (nb_tx) ODP_DBG("[%04d] ===> sent %03u frames to netmap adapter\n",