From patchwork Wed Nov 19 12:35:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41159 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 563F5241C9 for ; Wed, 19 Nov 2014 12:36:11 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id l15sf625382wiw.8 for ; Wed, 19 Nov 2014 04:36:10 -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=ARN7Me68kJwgyu90M28WPvvncvbWLRDpvpjpA44Azgc=; b=m0IKUSPWqPUf309u7Btf+gJPCKA+z9+X0qVh3WDkkrzvyu5geQv47XZAztGds2a5o9 k0yxwEhQ9uLddL5Htmr3ubxaQkPI6zahwsmL2lbz84PCEOQ/0/RgX/QZ/eQdeqGL0w+g +/BvLeD3QmQ9+Rbhcaa4Pyk1027FnfiBsAb5Ebs7A2Xdyre9p3N05KdmVv6Fyh9Xn2JR mZFFtCO6FQGKJ53RKIpj2xfP18CYZ7JQuNK4eEMPIXNnGtS+jWpc8r6guXi+UTTbCjxU GNBaQtMmrcb0C0Ae/eSPZ7ZjQZGiy/H7uvVbSdvygo2eVhXtk3r1bt+hPsZQPVxYEB7+ 6BTQ== X-Gm-Message-State: ALoCoQl/cj862kO3mnDGt5VWI/QHtJPeVJC38i+fnFtg3Vf5QM/NJ/uJzCQAhhDZA0UU0pRj/yYG X-Received: by 10.112.142.36 with SMTP id rt4mr16180310lbb.3.1416400570650; Wed, 19 Nov 2014 04:36:10 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.129 with SMTP id w1ls1357815lal.34.gmail; Wed, 19 Nov 2014 04:36:10 -0800 (PST) X-Received: by 10.153.4.2 with SMTP id ca2mr5251421lad.30.1416400570503; Wed, 19 Nov 2014 04:36:10 -0800 (PST) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id f10si1637904lab.102.2014.11.19.04.36.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Nov 2014 04:36:10 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by mail-lb0-f175.google.com with SMTP id n15so388435lbi.20 for ; Wed, 19 Nov 2014 04:36:10 -0800 (PST) X-Received: by 10.152.42.226 with SMTP id r2mr5214847lal.29.1416400570067; Wed, 19 Nov 2014 04:36:10 -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 ew9csp74087lbc; Wed, 19 Nov 2014 04:36:09 -0800 (PST) X-Received: by 10.140.98.202 with SMTP id o68mr51944104qge.49.1416400568837; Wed, 19 Nov 2014 04:36:08 -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 l5si1944834qgl.30.2014.11.19.04.36.07 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 19 Nov 2014 04:36:08 -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 1Xr4UP-0001cj-VF; Wed, 19 Nov 2014 12:36:05 +0000 Received: from mail-lb0-f178.google.com ([209.85.217.178]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xr4UE-0001cD-DX for lng-odp@lists.linaro.org; Wed, 19 Nov 2014 12:35:54 +0000 Received: by mail-lb0-f178.google.com with SMTP id f15so448388lbj.9 for ; Wed, 19 Nov 2014 04:35:48 -0800 (PST) X-Received: by 10.112.135.229 with SMTP id pv5mr5129137lbb.52.1416400548493; Wed, 19 Nov 2014 04:35:48 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id ed8sm407052lbb.41.2014.11.19.04.35.47 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Nov 2014 04:35:47 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 19 Nov 2014 15:35:40 +0300 Message-Id: <1416400540-9041-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] [PATCHv4] 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.217.175 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 --- v4: - added odp_unlikely() - del copy paste not needed line. 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 | 72 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index f35193f..b7d0b3b 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 (odp_unlikely(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); return nbr; }