From patchwork Mon Nov 17 16:12:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 40931 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F29DD24035 for ; Mon, 17 Nov 2014 16:12:59 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id x13sf11531273wgg.9 for ; Mon, 17 Nov 2014 08:12:54 -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=7iAgIit9+01SiCqca4bqmIrj88FYGyl7qBvuUz0qAv4=; b=XFx1G3kTQv0gKUVJSjzk8KFu1oMazqr5lmY36ahvsrR9PVhSume7FEoeKRBnznKmQM pJQxwEAA/MfzPhrMxovBf+3QEJariUd+bt5PD5GMABn3dAVtHaeZBCON5Vk/hp/ZEdht pezKq49Zxsy/BitH3liZ0YJZ1O+8YiLeix84xlGKx0CWLE1ZYGZSj2mW1GMWhZAIUr3W MV7pBmyNs63jJCHHmdVVUtEfrlQvreeDaioySWikTBYmDpE3osGED7+HDDEMjhcgDLhe G86PI7xQMyqxI25GJB+ct6yipTBbV4YcQCGet74ocqHuOmC0VUYolYuQc0I1tNx1upi7 4kJA== X-Gm-Message-State: ALoCoQkkdZ/xoxlleLwNozoxbJ8U28Nx/CCxUygLWskAramIohK1+xS/cLO3r3v/DJophJq6xx7O X-Received: by 10.112.72.106 with SMTP id c10mr569813lbv.15.1416240773421; Mon, 17 Nov 2014 08:12:53 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.5 with SMTP id w5ls1233482law.71.gmail; Mon, 17 Nov 2014 08:12:53 -0800 (PST) X-Received: by 10.112.157.194 with SMTP id wo2mr28613675lbb.55.1416240773265; Mon, 17 Nov 2014 08:12:53 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id b8si52591195lbc.7.2014.11.17.08.12.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Nov 2014 08:12:53 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id 10so16372048lbg.0 for ; Mon, 17 Nov 2014 08:12:53 -0800 (PST) X-Received: by 10.152.37.69 with SMTP id w5mr28280683laj.67.1416240773129; Mon, 17 Nov 2014 08:12:53 -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 ew9csp1180079lbc; Mon, 17 Nov 2014 08:12:52 -0800 (PST) X-Received: by 10.236.210.98 with SMTP id t62mr25843023yho.3.1416240771586; Mon, 17 Nov 2014 08:12:51 -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 68si35268175yhj.205.2014.11.17.08.12.50 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 17 Nov 2014 08:12:51 -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 1XqOv3-0004uJ-7y; Mon, 17 Nov 2014 16:12:49 +0000 Received: from mail-la0-f54.google.com ([209.85.215.54]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XqOuw-0004so-9S for lng-odp@lists.linaro.org; Mon, 17 Nov 2014 16:12:42 +0000 Received: by mail-la0-f54.google.com with SMTP id gf13so6700319lab.13 for ; Mon, 17 Nov 2014 08:12:36 -0800 (PST) X-Received: by 10.152.203.164 with SMTP id kr4mr28660237lac.31.1416240754293; Mon, 17 Nov 2014 08:12:34 -0800 (PST) Received: from localhost.localdomain (broadband-46-188-125-135.2com.net. [46.188.125.135]) by mx.google.com with ESMTPSA id y7sm7673307lay.18.2014.11.17.08.12.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Nov 2014 08:12:33 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 17 Nov 2014 19:12:25 +0300 Message-Id: <1416240745-18280-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] [PATCHv2] 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.169 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 Keep original logic but make function more clear. Signed-off-by: Maxim Uvarov --- 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 | 66 ++++++++++++++++------------------ 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index f35193f..73de80e 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, i); + buf_hdr = tmp_hdr_tbl[0]; return buf_hdr; } @@ -454,25 +448,25 @@ 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_ABORT("queue_deq_multi req: %d, returned %d\n", + num, nbr); - 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); - } - } + 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; }