From patchwork Thu Mar 26 19:23:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoltan Kiss X-Patchwork-Id: 46383 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 9BAE321585 for ; Thu, 26 Mar 2015 19:24:33 +0000 (UTC) Received: by wibfv9 with SMTP id fv9sf263421wib.1 for ; Thu, 26 Mar 2015 12:24:32 -0700 (PDT) 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=cFgMN3AIBv7iW9kAAL7EKZ4Pcw1bMfU/9t6yfQ2dbDw=; b=FJ/ZeQAv9SiJxOStZl3WQ03jGS40vj58p3xhS8W7jFoM12ewXDbsspFZaLWXZBFRmO RofStib3kLp1MLBVVvTaZ5y5LplHRoMN8qX0yfhL7xr3jE7fQQTjN7sW3sPQ51javucn T+EOTbmn8ASM1hUTcDwv19gAFfUO0O5F7JGO4P1f1TXHAS0Fqm9ytmexntyyevFK8zIQ NyW4H/UyASf9xHyjwuh2HTz0DJElcl8OIojAIfzAjyPs4p3TeirN8urfanKZb8wDzNJB ReJFYQ76cakp8okq0x4JaN7DX8RckDj5N0gAOHDNg9W16SFPRP+mVTIKIpGTNYmWc6yd ha6Q== X-Gm-Message-State: ALoCoQnZV7OdqkIGCdMWHsbNmxmKIUiRfDLiikw+ROVzRGcq/OpiQc7Ud5iXw8vy26Z9R/J0bqx3 X-Received: by 10.112.142.1 with SMTP id rs1mr3694455lbb.19.1427397872836; Thu, 26 Mar 2015 12:24:32 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.121.5 with SMTP id lg5ls239711lab.106.gmail; Thu, 26 Mar 2015 12:24:32 -0700 (PDT) X-Received: by 10.152.7.172 with SMTP id k12mr14893121laa.100.1427397872562; Thu, 26 Mar 2015 12:24:32 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id cq9si5310230lad.134.2015.03.26.12.24.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Mar 2015 12:24:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by labe2 with SMTP id e2so53749478lab.3 for ; Thu, 26 Mar 2015 12:24:32 -0700 (PDT) X-Received: by 10.112.235.227 with SMTP id up3mr5272895lbc.86.1427397872346; Thu, 26 Mar 2015 12:24:32 -0700 (PDT) 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.57.201 with SMTP id k9csp813638lbq; Thu, 26 Mar 2015 12:24:31 -0700 (PDT) X-Received: by 10.140.148.201 with SMTP id 192mr6109753qhu.36.1427397870853; Thu, 26 Mar 2015 12:24:30 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id s8si5897644qce.45.2015.03.26.12.24.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 26 Mar 2015 12:24:30 -0700 (PDT) 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 1YbDOF-0000D0-VC; Thu, 26 Mar 2015 19:24:27 +0000 Received: from mail-wg0-f42.google.com ([74.125.82.42]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YbDNa-00006b-R8 for lng-odp@lists.linaro.org; Thu, 26 Mar 2015 19:23:46 +0000 Received: by wgra20 with SMTP id a20so75374981wgr.3 for ; Thu, 26 Mar 2015 12:23:41 -0700 (PDT) X-Received: by 10.194.122.232 with SMTP id lv8mr29796969wjb.146.1427397821409; Thu, 26 Mar 2015 12:23:41 -0700 (PDT) Received: from localhost.localdomain ([90.152.119.35]) by mx.google.com with ESMTPSA id g5sm9673433wjr.19.2015.03.26.12.23.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Mar 2015 12:23:40 -0700 (PDT) From: Zoltan Kiss To: lng-odp@lists.linaro.org Date: Thu, 26 Mar 2015 19:23:23 +0000 Message-Id: <1427397805-27395-5-git-send-email-zoltan.kiss@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1427397805-27395-1-git-send-email-zoltan.kiss@linaro.org> References: <1427397805-27395-1-git-send-email-zoltan.kiss@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH v2 4/6] netdev-odp: allocate packet metadata in the same buffer as the packet itself 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: zoltan.kiss@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.48 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 Allocating it after every packet receive gives a big performance penalty. So move it into the same buffer pool, right after the packet itself. Signed-off-by: Zoltan Kiss --- v2: - fix style of for loops - delete SHM_OFPBUF_NUM_BUFS and odp_ofpbuf - no need to DPDK offset hack anymore, it was a DPDK error - init ofbuf at startup time lib/netdev-odp.c | 65 +++++++++++++++++++++++++++++--------------------------- lib/ofpbuf.c | 1 - lib/ofpbuf.h | 1 - 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/lib/netdev-odp.c b/lib/netdev-odp.c index ae944f7..b77eea0 100644 --- a/lib/netdev-odp.c +++ b/lib/netdev-odp.c @@ -52,13 +52,11 @@ VLOG_DEFINE_THIS_MODULE(odp); #define SHM_PKT_POOL_NUM_BUFS 32768 - 1 #define SHM_PKT_POOL_BUF_SIZE 1856 -#define SHM_OFPBUF_NUM_BUFS 512 #define SHM_OFPBUF_POOL_BUF_SIZE sizeof(struct dpif_packet) static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); static odp_buffer_pool_t pool; -static odp_buffer_pool_t ofpbuf_pool; static odp_buffer_pool_t struct_pool; static int odp_initialized = 0; @@ -95,7 +93,6 @@ void free_odp_buf(struct ofpbuf *b) { odp_packet_free(b->odp_pkt); - odp_buffer_free(b->odp_ofpbuf); } int @@ -130,11 +127,12 @@ static int odp_class_init(void) { odp_buffer_pool_param_t params; - int result = 0; + int result = 0, i; + odp_packet_t* pkts; - /* create packet pool */ + /* create packet & ofpbuf pool */ - params.buf_size = SHM_PKT_POOL_BUF_SIZE; + params.buf_size = SHM_PKT_POOL_BUF_SIZE + SHM_OFPBUF_POOL_BUF_SIZE; params.buf_align = ODP_CACHE_LINE_SIZE; params.num_bufs = SHM_PKT_POOL_NUM_BUFS; params.buf_type = ODP_BUFFER_TYPE_PACKET; @@ -147,19 +145,32 @@ odp_class_init(void) } odp_buffer_pool_print(pool); - /* create ofpbuf pool */ - - params.buf_size = SHM_OFPBUF_POOL_BUF_SIZE; - params.num_bufs = SHM_OFPBUF_POOL_BUF_SIZE; - params.buf_type = ODP_BUFFER_TYPE_RAW; - - ofpbuf_pool = odp_buffer_pool_create("ofpbuf_pool", ODP_SHM_NULL, ¶ms); - - if (ofpbuf_pool == ODP_BUFFER_POOL_INVALID) { - VLOG_ERR("Error: ofpbuf pool create failed.\n"); + /* Allocate all the packets from the pool and initialize ofpbuf part */ + pkts = malloc(sizeof(odp_packet_t) * params.num_bufs); + for (i = 0; i < params.num_bufs; ++i) { + struct dpif_packet *packet; + char *start; + pkts[i] = odp_packet_alloc(pool, 0); + if (pkts[i] == ODP_PACKET_INVALID) { + VLOG_ERR("Error: packet allocation failed.\n"); return -1; - } - odp_buffer_pool_print(ofpbuf_pool); + } + start = (char *)odp_buffer_addr(odp_packet_to_buffer(pkts[i])); + packet = (struct dpif_packet*) (start + SHM_PKT_POOL_BUF_SIZE); + packet->ofpbuf.odp_pkt = pkts[i]; + ofpbuf_init_odp(&packet->ofpbuf, SHM_PKT_POOL_BUF_SIZE); + /* TODO: odp_packet_alloc reset this to ODP_PACKET_OFFSET_INVALID, and + * ODP-DPDK doesn't set it later on, which causes a crash in + * emc_processing. Workaround this problem here for the moment */ + odp_packet_l2_offset_set(pkts[i], 0); + } + + /* Free our packets up */ + for (i = 0; i < params.num_bufs; i++) + odp_packet_free(pkts[i]); + free(pkts); + + odp_buffer_pool_print(pool); /* create pool for structures */ @@ -359,10 +370,8 @@ netdev_odp_send(struct netdev *netdev, int qid OVS_UNUSED, } } } else { - for (i = 0; i < cnt; i++) { + for (i = 0; i < cnt; i++) odp_pkts[i] = pkts[i]->ofpbuf.odp_pkt; - odp_packet_free(pkts[i]->ofpbuf.odp_ofpbuf); - } pkts_ok = cnt; } @@ -605,17 +614,11 @@ netdev_odp_rxq_recv(struct netdev_rxq *rxq_, struct dpif_packet **packets, return EINVAL; } - /* Allocate an ofpbuf for each valid packet */ + /* Build the array of dpif_packet pointers */ for (i = 0; i < pkts_ok; i++) { - odp_buffer_t buf; - buf = odp_buffer_alloc(ofpbuf_pool); - if (buf == ODP_BUFFER_INVALID) { - out_of_memory(); - } - packets[i] = (struct dpif_packet*) odp_buffer_addr(buf); - ofpbuf_init_odp(&packets[i]->ofpbuf, odp_packet_buf_len(pkt_tbl[i])); - packets[i]->ofpbuf.odp_pkt = pkt_tbl[i]; - packets[i]->ofpbuf.odp_ofpbuf = buf; + char *start; + start = (char*)odp_buffer_addr(odp_packet_to_buffer(pkt_tbl[i])); + packets[i] = (struct dpif_packet*) (start + SHM_PKT_POOL_BUF_SIZE); rx_bytes += odp_packet_len(pkt_tbl[i]); } diff --git a/lib/ofpbuf.c b/lib/ofpbuf.c index 6f27b47..06a8c1c 100644 --- a/lib/ofpbuf.c +++ b/lib/ofpbuf.c @@ -155,7 +155,6 @@ ofpbuf_uninit(struct ofpbuf *b) } else if (b->source == OFPBUF_ODP) { #ifdef ODP_NETDEV odp_packet_free(b->odp_pkt); - odp_buffer_free(b->odp_ofpbuf); #else ovs_assert(b->source != OFPBUF_ODP); #endif diff --git a/lib/ofpbuf.h b/lib/ofpbuf.h index 47cee29..33f3d6a 100644 --- a/lib/ofpbuf.h +++ b/lib/ofpbuf.h @@ -64,7 +64,6 @@ struct ofpbuf { struct rte_mbuf mbuf; /* DPDK mbuf */ #else # ifdef ODP_NETDEV - odp_buffer_t odp_ofpbuf; /* ODP buffer containig this struct ofpbuf */ odp_packet_t odp_pkt; /* ODP packet containing actual payload */ # endif void *base_; /* First byte of allocated space. */