From patchwork Wed Mar 4 09:26:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 45386 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 64C5D21486 for ; Wed, 4 Mar 2015 09:26:43 +0000 (UTC) Received: by lbiz11 with SMTP id z11sf12646723lbi.2 for ; Wed, 04 Mar 2015 01:26:42 -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=qTTYqLlvoE0s7ykrqgv4i3WZhhgBEBzun+NtAbrCjUk=; b=Y0k87ML3BW9mtJzTmKlzBetcSvHjfGREpd0WSySjSArL7qy7Kqhy5+kT6kdV8fUkfl 99drGPNT6Gj0aYYmOPSy07rJME+46uDBZiVRAOE71YOKLcidZzFTTAG97LmbUdAr8mcx 4u8a5flplaT08yxiaeHxcsj4qT/aESifr08PGiYtd8pZ5RZAonpzZ38zJBMBST4EUDor g+aQJq3jeBJB40MwrekYSnKPEn6DUMts66+d0BvCSKGjFv+n0e+yx/GZ9th3azSpEIF8 fzGak8WL8LLbZ6B09jpFOa0h/dkHeuL1VB1u9CSNdMs/yvKE3zl7m29NOywQvNQ5LvFW ZcSg== X-Gm-Message-State: ALoCoQnJOfRx6cyZlMS0r7q6himPSLXQfHhysF6jMsMOI/jnTg16gpLFAVQ+g6fvsXJAPfWGI8C+ X-Received: by 10.112.219.102 with SMTP id pn6mr475134lbc.12.1425461202350; Wed, 04 Mar 2015 01:26:42 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.20.8 with SMTP id j8ls160928lae.7.gmail; Wed, 04 Mar 2015 01:26:42 -0800 (PST) X-Received: by 10.112.12.196 with SMTP id a4mr2678688lbc.8.1425461202020; Wed, 04 Mar 2015 01:26:42 -0800 (PST) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id bl10si2144318lbc.68.2015.03.04.01.26.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Mar 2015 01:26:42 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by labgf13 with SMTP id gf13so18620382lab.5 for ; Wed, 04 Mar 2015 01:26:41 -0800 (PST) X-Received: by 10.112.211.200 with SMTP id ne8mr2421273lbc.73.1425461201873; Wed, 04 Mar 2015 01:26:41 -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 h5csp1100408lbj; Wed, 4 Mar 2015 01:26:40 -0800 (PST) X-Received: by 10.107.149.212 with SMTP id x203mr9531711iod.12.1425461200147; Wed, 04 Mar 2015 01:26:40 -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 j10si14240001igj.49.2015.03.04.01.26.38 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 04 Mar 2015 01:26:40 -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 1YT5Zb-0000gx-PE; Wed, 04 Mar 2015 09:26:35 +0000 Received: from mail-lb0-f173.google.com ([209.85.217.173]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YT5ZW-0000gs-Co for lng-odp@lists.linaro.org; Wed, 04 Mar 2015 09:26:30 +0000 Received: by lbiz12 with SMTP id z12so14992879lbi.12 for ; Wed, 04 Mar 2015 01:26:24 -0800 (PST) X-Received: by 10.112.12.196 with SMTP id a4mr2677798lbc.8.1425461184660; Wed, 04 Mar 2015 01:26:24 -0800 (PST) Received: from localhost.localdomain (ppp91-76-170-205.pppoe.mtu-net.ru. [91.76.170.205]) by mx.google.com with ESMTPSA id zo8sm651324lbc.37.2015.03.04.01.26.23 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Mar 2015 01:26:23 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 4 Mar 2015 12:26:15 +0300 Message-Id: <1425461175-8018-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Subject: [lng-odp] [PATCHv2] 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.215.41 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 --- v2: fix bunch of Stuarts comments. example/packet/odp_pktio.c | 99 +++++++++++++++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 27 deletions(-) diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c index bb07726..43f94a3 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,11 +179,13 @@ 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; unsigned long err_cnt = 0; + thr = odp_thread_id(); thr_args = arg; @@ -183,21 +202,29 @@ 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))); + /* Always dequeue from the same input queue */ + inq = odp_pktio_inq_getdef(pktio); + /* 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); + switch (thr_args->mode) { + case APPL_MODE_PKT_QUEUE: + ev = odp_queue_deq(inq); + pkt = odp_packet_from_event(ev); + if (!odp_packet_is_valid(pkt)) + continue; + break; + case APPL_MODE_PKT_SCHED: + /* Use schedule to get buf from any input queue */ + ev = odp_schedule(NULL, ODP_SCHED_WAIT); + pkt = odp_packet_from_event(ev); + break; + default: + EXAMPLE_ERR("unexpected mode %d\n", thr_args->mode); + return NULL; + } /* Drop packets with errors */ if (odp_unlikely(drop_err_pkts(&pkt, 1) == 0)) { @@ -498,10 +525,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 +581,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 +642,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 +670,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"