From patchwork Thu Mar 19 19:13:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zoltan Kiss X-Patchwork-Id: 46078 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 EF8272153C for ; Thu, 19 Mar 2015 19:14:37 +0000 (UTC) Received: by wivr20 with SMTP id r20sf14569694wiv.0 for ; Thu, 19 Mar 2015 12:14:37 -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=Ibb11pg1xyQ6ybt+3Ash1+iiMMV/JG3/7H4IYzk+F40=; b=F57Y5jrbHXMZgy2nm4GV+jqY8tXDJKQwTwE8rziScpfgTm+0o+q9eBVaRA1dIUPTUm 4iL52tgJunzGJpUW0RSa57MmeN6ZpEw46N7yDs340TUx/JbUzjnqtMBdZ9NApe7o0qe9 WuerAK0veLqSfNJMK8Rpn3Ir1csyBHnJL3y9sD0ZoDs1pT91XP1Vr2subh6VsHsdd9F4 NweHk29knMncK9b8Uc3lucM4l3O6Tn1NJfSgbz54M2Zu91CTHsorKfnkFGzEzvKe8jb8 BD+5BaOif/y3rPD8cwji4asB8yP355h0VpXXdtAhdnnuSms539N8RBmxLyd99N0Z3ryi iS3g== X-Gm-Message-State: ALoCoQnJBfZVe+RIdq/1H9gpKmqYkOSFUqo+9eM+hyswLe/qLzVX4OJfOSOnDHErkOdAboSdEfkF X-Received: by 10.180.210.132 with SMTP id mu4mr1132133wic.5.1426792477288; Thu, 19 Mar 2015 12:14:37 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.130 with SMTP id v2ls276659lae.98.gmail; Thu, 19 Mar 2015 12:14:37 -0700 (PDT) X-Received: by 10.152.88.1 with SMTP id bc1mr41901376lab.20.1426792477018; Thu, 19 Mar 2015 12:14:37 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id kv10si1624250lac.89.2015.03.19.12.14.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 12:14:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbnq5 with SMTP id q5so32008613lbn.0 for ; Thu, 19 Mar 2015 12:14:36 -0700 (PDT) X-Received: by 10.112.211.200 with SMTP id ne8mr69139854lbc.73.1426792476565; Thu, 19 Mar 2015 12:14:36 -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.35.133 with SMTP id h5csp589094lbj; Thu, 19 Mar 2015 12:14:35 -0700 (PDT) X-Received: by 10.55.20.35 with SMTP id e35mr119306305qkh.37.1426792475313; Thu, 19 Mar 2015 12:14:35 -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 f35si2128890qki.85.2015.03.19.12.14.32 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Mar 2015 12:14:35 -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 1YYftm-0001Cv-E9; Thu, 19 Mar 2015 19:14:30 +0000 Received: from mail-wi0-f179.google.com ([209.85.212.179]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YYftT-0001AS-DN for lng-odp@lists.linaro.org; Thu, 19 Mar 2015 19:14:11 +0000 Received: by wibg7 with SMTP id g7so126517051wib.1 for ; Thu, 19 Mar 2015 12:14:06 -0700 (PDT) X-Received: by 10.180.75.103 with SMTP id b7mr18908896wiw.32.1426792446019; Thu, 19 Mar 2015 12:14:06 -0700 (PDT) Received: from localhost.localdomain ([90.152.119.35]) by mx.google.com with ESMTPSA id s19sm8680658wik.18.2015.03.19.12.14.04 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 12:14:05 -0700 (PDT) From: Zoltan Kiss To: lng-odp@lists.linaro.org Date: Thu, 19 Mar 2015 19:13:44 +0000 Message-Id: <1426792426-12507-5-git-send-email-zoltan.kiss@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426792426-12507-1-git-send-email-zoltan.kiss@linaro.org> References: <1426792426-12507-1-git-send-email-zoltan.kiss@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 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.217.176 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 itselg. Note, initialization still happens for every packet, that needs to be further optimized. Signed-off-by: Zoltan Kiss --- lib/netdev-odp.c | 67 +++++++++++++++++++++++++++++++------------------------- lib/ofpbuf.c | 1 - 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/lib/netdev-odp.c b/lib/netdev-odp.c index 0b13f7f..4b13bfe 100644 --- a/lib/netdev-odp.c +++ b/lib/netdev-odp.c @@ -58,7 +58,6 @@ VLOG_DEFINE_THIS_MODULE(odp); 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 +94,6 @@ void free_odp_buf(struct ofpbuf *b) { odp_packet_free(b->odp_pkt); - odp_buffer_free(b->odp_ofpbuf); } int @@ -130,11 +128,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 +146,34 @@ 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])); + /* TODO: This 256 magic value is needed for ODP-DPDK, when the buffer is + * allocated by rte_eth_rx_burst the start is at a different place. + * Probably due to headroom, this is a workaround here at the moment */ + packet = (struct dpif_packet*) (start + SHM_PKT_POOL_BUF_SIZE - 256); + packet->ofpbuf.odp_pkt = pkts[i]; + /* 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 +373,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 +617,12 @@ 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); + ofpbuf_init_odp(&packets[i]->ofpbuf, 0); 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