From patchwork Fri Mar 6 12:24:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 45480 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 51BAC204BC for ; Fri, 6 Mar 2015 12:25:22 +0000 (UTC) Received: by wghb13 with SMTP id b13sf43550392wgh.2 for ; Fri, 06 Mar 2015 04:25:21 -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:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=4oOHqu8gX5SPS/J/ooeQbfGo6l3u4TIobakHXlCK1MU=; b=LRssqkyQuVMgPdN3rSxzp26bsCEia15BvAU7kuxUJAYbdjcMCI9QxQB9RPD+ErUa/l 4A15feCfmFwxG4Vw8bmRv+w/OwtQWVMhkfx3dMA+SP/HML3blcPoDWEAoWudUo4BTNq7 SIWX1HJMZ7vJKSsAojY3GslDE+2yVHZUHX5Zi9iZKqQk+EvFFAWSvvqjZtg8hvx7zJVW h+JKjnLvN32qFjgNhS1kCGzoLo3ntEb0jHeYoMUlTXJV2kdn012PNP9IjMkhxB6mNMz+ MP0PHwiiBkiHRdJZtgtGXWwPCn99LaLWpvs28cGSJyY/2LY1q1E6kXkiA41pmeQ7U6VN /w6Q== X-Gm-Message-State: ALoCoQmuydHa4KuMoQgEBI5gLpSsAm8RYY7b/PkK0PWrumHvQm6Z9ynschtalTKItDR1hbzqknSp X-Received: by 10.180.83.168 with SMTP id r8mr2725877wiy.6.1425644721497; Fri, 06 Mar 2015 04:25:21 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.245.44 with SMTP id xl12ls70762lac.29.gmail; Fri, 06 Mar 2015 04:25:21 -0800 (PST) X-Received: by 10.152.22.67 with SMTP id b3mr12201769laf.117.1425644720977; Fri, 06 Mar 2015 04:25:20 -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 yg3si3515725lbb.150.2015.03.06.04.25.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Mar 2015 04:25:20 -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 lbdu14 with SMTP id u14so36039619lbd.0 for ; Fri, 06 Mar 2015 04:25:20 -0800 (PST) X-Received: by 10.152.1.135 with SMTP id 7mr12369138lam.41.1425644720688; Fri, 06 Mar 2015 04:25:20 -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.35.133 with SMTP id h5csp1099825lbj; Fri, 6 Mar 2015 04:25:19 -0800 (PST) X-Received: by 10.52.96.234 with SMTP id dv10mr17888113vdb.56.1425644718950; Fri, 06 Mar 2015 04:25:18 -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 u2si4971887vcm.96.2015.03.06.04.25.17 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 06 Mar 2015 04:25:18 -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 1YTrJZ-0002dq-CH; Fri, 06 Mar 2015 12:25:13 +0000 Received: from mail-la0-f44.google.com ([209.85.215.44]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YTrJT-0002bm-Sf for lng-odp@lists.linaro.org; Fri, 06 Mar 2015 12:25:08 +0000 Received: by labgf13 with SMTP id gf13so32648717lab.5 for ; Fri, 06 Mar 2015 04:25:01 -0800 (PST) X-Received: by 10.112.154.234 with SMTP id vr10mr12271544lbb.115.1425644701786; Fri, 06 Mar 2015 04:25:01 -0800 (PST) Received: from maxim-Aspire-VN7-791.Dlink (broadband-46-188-125-102.2com.net. [46.188.125.102]) by mx.google.com with ESMTPSA id pq1sm1787168lbb.41.2015.03.06.04.25.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Mar 2015 04:25:00 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 6 Mar 2015 15:24:54 +0300 Message-Id: <1425644694-3074-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCHv3] example: odp_packet uncomment polling queues 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 odp_packet examples has polling queues commented out with if 1. Input queue (ODP_QUEUE_TYPE_PKTIN) is not attached to scheduler but it make sense in example show that packets can be accessed with polling queues also. https://bugs.linaro.org/show_bug.cgi?id=301 Signed-off-by: Maxim Uvarov Reviewed-by: Stuart Haslam --- v3: fix more Stuarts comments ;) v2: fix bunch of Stuarts comments. example/packet/odp_pktio.c | 93 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 27 deletions(-) diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c index bb07726..61af855 100644 --- a/example/packet/odp_pktio.c +++ b/example/packet/odp_pktio.c @@ -52,6 +52,11 @@ */ #define APPL_MODE_PKT_QUEUE 1 +/** @def APPL_MODE_PKT_SCHED + * @brief The application will handle packets with sheduler + */ +#define APPL_MODE_PKT_SCHED 2 + /** @def PRINT_APPL_MODE(x) * @brief Macro to print the current status of how the application handles * packets. @@ -123,18 +128,30 @@ static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool, int mode) if (pktio == ODP_PKTIO_INVALID) EXAMPLE_ABORT("Error: pktio create failed for %s\n", dev); - /* no further setup needed for burst mode */ - if (mode == APPL_MODE_PKT_BURST) - return pktio; - - qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; - qparam.sched.sync = ODP_SCHED_SYNC_ATOMIC; - qparam.sched.group = ODP_SCHED_GROUP_DEFAULT; snprintf(inq_name, sizeof(inq_name), "%" PRIu64 "-pktio_inq_def", odp_pktio_to_u64(pktio)); inq_name[ODP_QUEUE_NAME_LEN - 1] = '\0'; - inq_def = odp_queue_create(inq_name, ODP_QUEUE_TYPE_PKTIN, &qparam); + switch (mode) { + case APPL_MODE_PKT_BURST: + /* no further setup needed for burst mode */ + return pktio; + case APPL_MODE_PKT_QUEUE: + inq_def = odp_queue_create(inq_name, + ODP_QUEUE_TYPE_PKTIN, NULL); + break; + case APPL_MODE_PKT_SCHED: + qparam.sched.prio = ODP_SCHED_PRIO_DEFAULT; + qparam.sched.sync = ODP_SCHED_SYNC_ATOMIC; + qparam.sched.group = ODP_SCHED_GROUP_DEFAULT; + + inq_def = odp_queue_create(inq_name, + ODP_QUEUE_TYPE_PKTIN, &qparam); + break; + default: + EXAMPLE_ABORT("invalid mode %d\n", mode); + } + if (inq_def == ODP_QUEUE_INVALID) EXAMPLE_ABORT("Error: pktio inq create failed for %s\n", dev); @@ -162,6 +179,7 @@ static void *pktio_queue_thread(void *arg) odp_pktio_t pktio; thread_args_t *thr_args; odp_queue_t outq_def; + odp_queue_t inq; odp_packet_t pkt; odp_event_t ev; unsigned long pkt_cnt = 0; @@ -183,21 +201,24 @@ static void *pktio_queue_thread(void *arg) thr, odp_pktio_to_u64(pktio), odp_pktio_to_u64(pktio), odp_queue_to_u64(odp_pktio_inq_getdef(pktio))); + if (thr_args->mode == APPL_MODE_PKT_QUEUE) + inq = odp_pktio_inq_getdef(pktio); + else + inq = ODP_QUEUE_INVALID; + /* Loop packets */ for (;;) { odp_pktio_t pktio_tmp; -#if 1 - /* Use schedule to get buf from any input queue */ - ev = odp_schedule(NULL, ODP_SCHED_WAIT); -#else - /* Always dequeue from the same input queue */ - buf = odp_queue_deq(inq_def); - if (!odp_buffer_is_valid(buf)) - continue; -#endif - - pkt = odp_packet_from_event(ev); + if (inq != ODP_QUEUE_INVALID) { + ev = odp_queue_deq(inq); + pkt = odp_packet_from_event(ev); + if (!odp_packet_is_valid(pkt)) + continue; + } else { + ev = odp_schedule(NULL, ODP_SCHED_WAIT); + pkt = odp_packet_from_event(ev); + } /* Drop packets with errors */ if (odp_unlikely(drop_err_pkts(&pkt, 1) == 0)) { @@ -498,10 +519,10 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) {NULL, 0, NULL, 0} }; - appl_args->mode = -1; /* Invalid, must be changed by parsing */ + appl_args->mode = APPL_MODE_PKT_SCHED; while (1) { - opt = getopt_long(argc, argv, "+c:i:m:t:h", + opt = getopt_long(argc, argv, "+c:i:+m:t:h", longopts, &long_index); if (opt == -1) @@ -554,10 +575,20 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) case 'm': i = atoi(optarg); - if (i == 0) + switch (i) { + case 0: appl_args->mode = APPL_MODE_PKT_BURST; - else + break; + case 1: appl_args->mode = APPL_MODE_PKT_QUEUE; + break; + case 2: + appl_args->mode = APPL_MODE_PKT_SCHED; + break; + default: + usage(argv[0]); + exit(EXIT_FAILURE); + } break; case 'h': usage(argv[0]); @@ -605,10 +636,17 @@ static void print_info(char *progname, appl_args_t *appl_args) printf(" %s", appl_args->if_names[i]); printf("\n" "Mode: "); - if (appl_args->mode == APPL_MODE_PKT_BURST) + switch (appl_args->mode) { + case APPL_MODE_PKT_BURST: PRINT_APPL_MODE(APPL_MODE_PKT_BURST); - else + break; + case APPL_MODE_PKT_QUEUE: PRINT_APPL_MODE(APPL_MODE_PKT_QUEUE); + break; + case APPL_MODE_PKT_SCHED: + PRINT_APPL_MODE(APPL_MODE_PKT_SCHED); + break; + } printf("\n\n"); fflush(NULL); } @@ -626,11 +664,12 @@ static void usage(char *progname) "\n" "Mandatory OPTIONS:\n" " -i, --interface Eth interfaces (comma-separated, no spaces)\n" - " -m, --mode 0: Burst send&receive packets (no queues)\n" - " 1: Send&receive packets through ODP queues.\n" "\n" "Optional OPTIONS\n" " -c, --count CPU count.\n" + " -m, --mode 0: Receive and send directly (no queues)\n" + " 1: Receive and send via queues.\n" + " 2: Receive via scheduler, send via queues.\n" " -h, --help Display help and exit.\n" " environment variables: ODP_PKTIO_DISABLE_SOCKET_MMAP\n" " ODP_PKTIO_DISABLE_SOCKET_MMSG\n"