From patchwork Tue Nov 18 14:47:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41043 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C07D924035 for ; Tue, 18 Nov 2014 14:48:47 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id lj1sf2777520pab.1 for ; Tue, 18 Nov 2014 06:48:47 -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: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=NqB6tvSCpNbVQcm3UcXL2cDMy8qTKKTxcViwBAiazZM=; b=Gvvp3m0SnS0uidjQj6Imhz5wf1qUk7TUbYYBu8RnLWXo5OtACq4LHyv5T+DfLUL+oa qdzhGMMR9WY1esrdbpRLJ5sYNYZ54ylmcY3rt3mRtbIsgq9G76qQbK9tDt2Km6SjqRBB kzOixv/sx+DpvhB6/TL/4WIS08rYZSHbnHryvMb+G1p0D3Q05vedPPK/yzw8oJbeV9Q6 IJYDoP1Os2fWfKJNSygalPjJ5+wMbCoTzI9wzQrTrbA25r4kuxXdaQPp+aubXxUgfj6D KBi+Q9EnM3kUzl8FwnJLm/9dAl9RgZ2Q3V+Wc20IKn+MuTUBYYPh9vsQ870Gt0Xvdr0j Q0UA== X-Gm-Message-State: ALoCoQl2Fohkq604bwkHR2aBCwj7qUJ2K42QtZLhN0q1knMrDFE5YtpFvAfcphzro/mWKZxgcegU X-Received: by 10.68.228.164 with SMTP id sj4mr45058676pbc.8.1416322127037; Tue, 18 Nov 2014 06:48:47 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.23.134 with SMTP id 6ls5521870qgp.17.gmail; Tue, 18 Nov 2014 06:48:46 -0800 (PST) X-Received: by 10.224.3.196 with SMTP id 4mr44255603qao.79.1416322126916; Tue, 18 Nov 2014 06:48:46 -0800 (PST) Received: from mail-qc0-f173.google.com (mail-qc0-f173.google.com. [209.85.216.173]) by mx.google.com with ESMTPS id c10si68963663qai.70.2014.11.18.06.48.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 06:48:46 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.216.173 as permitted sender) client-ip=209.85.216.173; Received: by mail-qc0-f173.google.com with SMTP id i17so3930637qcy.4 for ; Tue, 18 Nov 2014 06:48:46 -0800 (PST) X-Received: by 10.140.89.200 with SMTP id v66mr43058652qgd.85.1416322126718; Tue, 18 Nov 2014 06:48:46 -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.96.224.201 with SMTP id re9csp37713qdc; Tue, 18 Nov 2014 06:48:46 -0800 (PST) X-Received: by 10.140.95.214 with SMTP id i80mr43158825qge.48.1416322126010; Tue, 18 Nov 2014 06:48:46 -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 b52si32217517qgf.10.2014.11.18.06.48.45 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 18 Nov 2014 06:48:45 -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 1Xqk5C-0003f4-Rx; Tue, 18 Nov 2014 14:48:42 +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 1Xqk56-0003da-Kw for lng-odp@lists.linaro.org; Tue, 18 Nov 2014 14:48:36 +0000 Received: by mail-lb0-f169.google.com with SMTP id 10so17817242lbg.14 for ; Tue, 18 Nov 2014 06:48:30 -0800 (PST) X-Received: by 10.152.116.102 with SMTP id jv6mr23166128lab.40.1416322109871; Tue, 18 Nov 2014 06:48:29 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id d4sm10307912laf.2.2014.11.18.06.48.16 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 06:48:17 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Tue, 18 Nov 2014 17:47:37 +0300 Message-Id: <1416322057-6444-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 X-Topics: patch Subject: [lng-odp] [PATCHv3] simplify pktin_dequeue/pktin_deq_multi functions 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: maxim.uvarov@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.216.173 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 Mostly keep original logic but make function more clear. In pktin_deq_multi() do not do actual rx if there are enough packets in the queue. Signed-off-by: Maxim Uvarov --- v3: - use pkts instead if i in queue_enq_multi(); - do not do actual rx if there are enough packets in the queue. v2: - fixes for checks that Ciprian found. Tested this patch in lxc with ping -f for both burst and queue modes. Maxim. platform/linux-generic/odp_packet_io.c | 74 +++++++++++++++++----------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index f35193f..039003d 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -416,32 +416,26 @@ int pktin_enqueue(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr) odp_buffer_hdr_t *pktin_dequeue(queue_entry_t *qentry) { odp_buffer_hdr_t *buf_hdr; + odp_buffer_t buf; + odp_packet_t pkt_tbl[QUEUE_MULTI_MAX]; + odp_buffer_hdr_t *tmp_hdr_tbl[QUEUE_MULTI_MAX]; + int pkts, i; buf_hdr = queue_deq(qentry); + if (buf_hdr != NULL) + return buf_hdr; - if (buf_hdr == NULL) { - odp_packet_t pkt; - odp_buffer_t buf; - odp_packet_t pkt_tbl[QUEUE_MULTI_MAX]; - odp_buffer_hdr_t *tmp_hdr_tbl[QUEUE_MULTI_MAX]; - int pkts, i, j; - - pkts = odp_pktio_recv(qentry->s.pktin, pkt_tbl, - QUEUE_MULTI_MAX); - - if (pkts > 0) { - pkt = pkt_tbl[0]; - buf = odp_packet_to_buffer(pkt); - buf_hdr = odp_buf_to_hdr(buf); + pkts = odp_pktio_recv(qentry->s.pktin, pkt_tbl, QUEUE_MULTI_MAX); + if (pkts <= 0) + return NULL; - for (i = 1, j = 0; i < pkts; ++i) { - buf = odp_packet_to_buffer(pkt_tbl[i]); - tmp_hdr_tbl[j++] = odp_buf_to_hdr(buf); - } - queue_enq_multi(qentry, tmp_hdr_tbl, j); - } + for (i = 0; i < pkts; ++i) { + buf = odp_packet_to_buffer(pkt_tbl[i]); + tmp_hdr_tbl[i] = odp_buf_to_hdr(buf); } + queue_enq_multi(qentry, tmp_hdr_tbl, pkts); + buf_hdr = tmp_hdr_tbl[0]; return buf_hdr; } @@ -454,25 +448,31 @@ int pktin_enq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) { int nbr; + odp_packet_t pkt_tbl[QUEUE_MULTI_MAX]; + odp_buffer_hdr_t *tmp_hdr_tbl[QUEUE_MULTI_MAX]; + odp_buffer_t buf; + int pkts, i; nbr = queue_deq_multi(qentry, buf_hdr, num); - - if (nbr < num) { - odp_packet_t pkt_tbl[QUEUE_MULTI_MAX]; - odp_buffer_hdr_t *tmp_hdr_tbl[QUEUE_MULTI_MAX]; - odp_buffer_t buf; - int pkts, i; - - pkts = odp_pktio_recv(qentry->s.pktin, pkt_tbl, - QUEUE_MULTI_MAX); - if (pkts > 0) { - for (i = 0; i < pkts; ++i) { - buf = odp_packet_to_buffer(pkt_tbl[i]); - tmp_hdr_tbl[i] = odp_buf_to_hdr(buf); - } - queue_enq_multi(qentry, tmp_hdr_tbl, pkts); - } + if (nbr > num) + ODP_ABORT("queue_deq_multi req: %d, returned %d\n", + num, nbr); + + /** queue already has number of requsted buffers, + * do not do recieve in that case. + */ + if (nbr == num) + return nbr; + + pkts = odp_pktio_recv(qentry->s.pktin, pkt_tbl, QUEUE_MULTI_MAX); + if (pkts <= 0) + return nbr; + + for (i = 0; i < pkts; ++i) { + buf = odp_packet_to_buffer(pkt_tbl[i]); + tmp_hdr_tbl[i] = odp_buf_to_hdr(buf); } - + queue_enq_multi(qentry, tmp_hdr_tbl, pkts); + buf_hdr = &tmp_hdr_tbl[0]; return nbr; }