From patchwork Fri Oct 9 11:59:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 54698 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 73D6622DB6 for ; Fri, 9 Oct 2015 12:10:30 +0000 (UTC) Received: by lbos8 with SMTP id s8sf37653484lbo.2 for ; Fri, 09 Oct 2015 05:10:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:date :message-id:in-reply-to:references: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=l7Tfz0yDxD/MBnuIhnszP4YyFIYM/Afx1vtMwVC7Sg4=; b=D70PtTj0Arb7dTFvOLFHY0sArUL91rbooVDea5YSfGAv7c+ugzMlqx0RayE5LEyqp/ hFSyhZZUf1rbF8XYGYmJGjSWz1+4KWxBJ+wr8oguPDKkaOXQ7Hl9hEdrqUeSiMhikQIG ttFMuWrZSFoHhtxk2rueGINUuhxu88l45PO47qMSBDJu7OoL7olns4RZThYsG3bzkLTh oHvRnXzy+lzMILz8QSPWJzFEIarsRTPIaDBIfXH6EfzSs22X+fFtVpAtPIbC8LwAvvoB yKcDNN8cAPJJx9U9Qx1PB6YoEUh+GBkEM4ULpdbxBZ2TzooWgwlVSNcKpcvJYFcuXP0S 5OAw== X-Gm-Message-State: ALoCoQm35ggxVDrmw1zyasxxbY8k4jPhJKW62XpcxZxdX+ePDmr1Xc5ujrdgMY5GCZ709Jn0oXYw X-Received: by 10.112.12.132 with SMTP id y4mr2533364lbb.0.1444392629438; Fri, 09 Oct 2015 05:10:29 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.151.203 with SMTP id z194ls271571lfd.57.gmail; Fri, 09 Oct 2015 05:10:29 -0700 (PDT) X-Received: by 10.112.151.106 with SMTP id up10mr6603857lbb.106.1444392629290; Fri, 09 Oct 2015 05:10:29 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id p4si978705lbw.11.2015.10.09.05.10.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Oct 2015 05:10:29 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by lbbwt4 with SMTP id wt4so78374239lbb.1 for ; Fri, 09 Oct 2015 05:10:29 -0700 (PDT) X-Received: by 10.25.150.199 with SMTP id y190mr4300502lfd.35.1444392629036; Fri, 09 Oct 2015 05:10:29 -0700 (PDT) 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.59.35 with SMTP id w3csp1163623lbq; Fri, 9 Oct 2015 05:10:27 -0700 (PDT) X-Received: by 10.107.41.194 with SMTP id p185mr16728659iop.109.1444392627581; Fri, 09 Oct 2015 05:10:27 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id a7si2253523iga.79.2015.10.09.05.10.27; Fri, 09 Oct 2015 05:10:27 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: by lists.linaro.org (Postfix, from userid 109) id DD7F9619B2; Fri, 9 Oct 2015 12:10:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id EF56F61B76; Fri, 9 Oct 2015 12:00:37 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id E893B61B7F; Fri, 9 Oct 2015 12:00:27 +0000 (UTC) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com [209.85.217.180]) by lists.linaro.org (Postfix) with ESMTPS id 45E4D61A3F for ; Fri, 9 Oct 2015 11:59:12 +0000 (UTC) Received: by lbos8 with SMTP id s8so77428234lbo.0 for ; Fri, 09 Oct 2015 04:59:11 -0700 (PDT) X-Received: by 10.112.181.71 with SMTP id du7mr6288004lbc.37.1444391951128; Fri, 09 Oct 2015 04:59:11 -0700 (PDT) Received: from localhost.localdomain (ppp91-76-161-180.pppoe.mtu-net.ru. [91.76.161.180]) by smtp.gmail.com with ESMTPSA id v19sm235052lfd.7.2015.10.09.04.59.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Oct 2015 04:59:10 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 9 Oct 2015 14:59:04 +0300 Message-Id: <1444391944-20772-9-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1444391944-20772-1-git-send-email-maxim.uvarov@linaro.org> References: <1444391944-20772-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv9 8/8] linux-generic: internal ipc_pktio test X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 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" 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.170 as permitted sender) smtp.mailfrom=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 2 example ipc pktio applications create ipc pktio to each other and do packet transfer, validation magic numbers and packets sequence counters inside it. Signed-off-by: Maxim Uvarov --- platform/linux-generic/Makefile.am | 1 + platform/linux-generic/m4/configure.m4 | 3 +- platform/linux-generic/test/Makefile.am | 3 +- platform/linux-generic/test/pktio_ipc/.gitignore | 1 + platform/linux-generic/test/pktio_ipc/Makefile.am | 15 ++ platform/linux-generic/test/pktio_ipc/ipc_common.c | 150 ++++++++++++ platform/linux-generic/test/pktio_ipc/ipc_common.h | 71 ++++++ platform/linux-generic/test/pktio_ipc/pktio_ipc1.c | 268 +++++++++++++++++++++ platform/linux-generic/test/pktio_ipc/pktio_ipc2.c | 142 +++++++++++ .../linux-generic/test/pktio_ipc/pktio_ipc_run | 55 +++++ 10 files changed, 707 insertions(+), 2 deletions(-) create mode 100644 platform/linux-generic/test/pktio_ipc/.gitignore create mode 100644 platform/linux-generic/test/pktio_ipc/Makefile.am create mode 100644 platform/linux-generic/test/pktio_ipc/ipc_common.c create mode 100644 platform/linux-generic/test/pktio_ipc/ipc_common.h create mode 100644 platform/linux-generic/test/pktio_ipc/pktio_ipc1.c create mode 100644 platform/linux-generic/test/pktio_ipc/pktio_ipc2.c create mode 100755 platform/linux-generic/test/pktio_ipc/pktio_ipc_run diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 71353dd..6fe2f1a 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -5,6 +5,7 @@ include $(top_srcdir)/platform/Makefile.inc AM_CFLAGS += -I$(srcdir)/include AM_CFLAGS += -I$(top_srcdir)/include +AM_CFLAGS += -I$(top_srcdir)/helper AM_CFLAGS += -I$(top_srcdir)/helper/include include_HEADERS = \ diff --git a/platform/linux-generic/m4/configure.m4 b/platform/linux-generic/m4/configure.m4 index 9658274..3a2d743 100644 --- a/platform/linux-generic/m4/configure.m4 +++ b/platform/linux-generic/m4/configure.m4 @@ -21,4 +21,5 @@ m4_include([platform/linux-generic/m4/odp_openssl.m4]) AC_CONFIG_FILES([platform/linux-generic/Makefile platform/linux-generic/test/Makefile - platform/linux-generic/test/pktio/Makefile]) + platform/linux-generic/test/pktio/Makefile + platform/linux-generic/test/pktio_ipc/Makefile]) diff --git a/platform/linux-generic/test/Makefile.am b/platform/linux-generic/test/Makefile.am index 7d1ce1b..db98d28 100644 --- a/platform/linux-generic/test/Makefile.am +++ b/platform/linux-generic/test/Makefile.am @@ -1,10 +1,11 @@ include $(top_srcdir)/test/Makefile.inc TESTS_ENVIRONMENT += TEST_DIR=${top_builddir}/test/validation -ODP_MODULES = pktio +ODP_MODULES = pktio pktio_ipc if test_vald TESTS = pktio/pktio_run \ + pktio_ipc/pktio_ipc_run \ ${top_builddir}/test/validation/buffer/buffer_main$(EXEEXT) \ ${top_builddir}/test/validation/classification/classification_main$(EXEEXT) \ ${top_builddir}/test/validation/cpumask/cpumask_main$(EXEEXT) \ diff --git a/platform/linux-generic/test/pktio_ipc/.gitignore b/platform/linux-generic/test/pktio_ipc/.gitignore new file mode 100644 index 0000000..d2a7ce2 --- /dev/null +++ b/platform/linux-generic/test/pktio_ipc/.gitignore @@ -0,0 +1 @@ +pktio_ipc diff --git a/platform/linux-generic/test/pktio_ipc/Makefile.am b/platform/linux-generic/test/pktio_ipc/Makefile.am new file mode 100644 index 0000000..adf6294 --- /dev/null +++ b/platform/linux-generic/test/pktio_ipc/Makefile.am @@ -0,0 +1,15 @@ +include $(top_srcdir)/test/Makefile.inc +TESTS_ENVIRONMENT += TEST_DIR=${top_builddir}/test/validation + +bin_PROGRAMS = pktio_ipc1\ + pktio_ipc2 + +pktio_ipc1_CFLAGS = $(AM_CFLAGS) -I${top_srcdir}/example +pktio_ipc1_LDFLAGS = $(AM_LDFLAGS) -static +pktio_ipc2_CFLAGS = $(AM_CFLAGS) -I${top_srcdir}/example +pktio_ipc2_LDFLAGS = $(AM_LDFLAGS) -static + +noinst_HEADERS = $(top_srcdir)/test/test_debug.h + +dist_pktio_ipc1_SOURCES = pktio_ipc1.c ipc_common.c +dist_pktio_ipc2_SOURCES = pktio_ipc2.c ipc_common.c diff --git a/platform/linux-generic/test/pktio_ipc/ipc_common.c b/platform/linux-generic/test/pktio_ipc/ipc_common.c new file mode 100644 index 0000000..7a84b07 --- /dev/null +++ b/platform/linux-generic/test/pktio_ipc/ipc_common.c @@ -0,0 +1,150 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "ipc_common.h" + +/** Application argument */ +char *pktio_name; + +/** Run time in seconds */ +int run_time_sec; + +int ipc_odp_packet_sendall(odp_pktio_t pktio, + odp_packet_t pkt_tbl[], int num) +{ + int ret; + int sent = 0; + uint64_t start_cycle; + uint64_t diff; + + start_cycle = odp_time_cycles(); + + while (sent != num) { + ret = odp_pktio_send(pktio, &pkt_tbl[sent], num - sent); + if (ret < 0) + return -1; + + sent += ret; + + diff = odp_time_diff_cycles(start_cycle, odp_time_cycles()); + if (odp_time_ns_to_cycles(3 * ODP_TIME_SEC) < diff) + return -1; + } + + return 0; +} + +/** + * Create a pktio handle. + * + * @param dev Name of device to open + * @param pool Pool to associate with device for packet RX/TX + * + * @return The handle of the created pktio object. + * @retval ODP_PKTIO_INVALID if the create fails. + */ +odp_pktio_t create_pktio(const char *dev EXAMPLE_UNUSED, odp_pool_t pool) +{ + odp_pktio_param_t pktio_param; + odp_pktio_t ipc_pktio; + + memset(&pktio_param, 0, sizeof(pktio_param)); + pktio_param.in_mode = ODP_PKTIN_MODE_SCHED; + + printf("pid: %d, create IPC pktio\n", getpid()); + ipc_pktio = odp_pktio_open("ipc_pktio", pool, &pktio_param); + if (ipc_pktio == ODP_PKTIO_INVALID) + EXAMPLE_ABORT("Error: ipc pktio create failed.\n"); + odp_pktio_start(ipc_pktio); + return ipc_pktio; +} + +/** + * Parse and store the command line arguments + * + * @param argc argument count + * @param argv[] argument vector + * @param appl_args Store application arguments here + */ +void parse_args(int argc, char *argv[]) +{ + int opt; + int long_index; + static struct option longopts[] = { + {"time", required_argument, NULL, 't'}, + {"help", no_argument, NULL, 'h'}, /* return 'h' */ + {NULL, 0, NULL, 0} + }; + + run_time_sec = 0; /* loop forever if time to run is 0 */ + + while (1) { + opt = getopt_long(argc, argv, "+t:h", + longopts, &long_index); + + if (opt == -1) + break; /* No more options */ + + switch (opt) { + case 't': + run_time_sec = atoi(optarg); + break; + case 'h': + usage(argv[0]); + exit(EXIT_SUCCESS); + break; + + default: + break; + } + } + + optind = 1; /* reset 'extern optind' from the getopt lib */ +} + +/** + * Print system and application info + */ +void print_info(char *progname) +{ + printf("\n" + "ODP system info\n" + "---------------\n" + "ODP API version: %s\n" + "CPU model: %s\n" + "CPU freq (hz): %" PRIu64 "\n" + "Cache line size: %i\n" + "CPU count: %i\n" + "\n", + odp_version_api_str(), odp_sys_cpu_model_str(), odp_sys_cpu_hz(), + odp_sys_cache_line_size(), odp_cpu_count()); + + printf("Running ODP appl: \"%s\"\n" + "-----------------\n" + "Using IF: %s\n", + progname, pktio_name); + printf("\n\n"); + fflush(NULL); +} + +/** + * Prinf usage information + */ +void usage(char *progname) +{ + printf("\n" + "Usage: %s OPTIONS\n" + " E.g. %s -t seconds\n" + "\n" + "OpenDataPlane linux-generic ipc test application.\n" + "\n" + "Optional OPTIONS\n" + " -h, --help Display help and exit.\n" + " -t, --time Time to run in seconds.\n" + "\n", NO_PATH(progname), NO_PATH(progname) + ); +} + diff --git a/platform/linux-generic/test/pktio_ipc/ipc_common.h b/platform/linux-generic/test/pktio_ipc/ipc_common.h new file mode 100644 index 0000000..e71a489 --- /dev/null +++ b/platform/linux-generic/test/pktio_ipc/ipc_common.h @@ -0,0 +1,71 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#define _POSIX_C_SOURCE 200809L +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +/** @def SHM_PKT_POOL_SIZE + * @brief Size of the shared memory block + */ +#define SHM_PKT_POOL_SIZE (512 * 2048) + +/** @def SHM_PKT_POOL_BUF_SIZE + * @brief Buffer size of the packet pool buffer + */ +#define SHM_PKT_POOL_BUF_SIZE 1856 + +/** @def MAX_PKT_BURST + * @brief Maximum number of packet bursts + */ +#define MAX_PKT_BURST 16 + +/** Get rid of path in filename - only for unix-type paths using '/' */ +#define NO_PATH(file_name) (strrchr((file_name), '/') ? \ + strrchr((file_name), '/') + 1 : (file_name)) + +#define TEST_SEQ_MAGIC 0x92749451 +#define TEST_SEQ_MAGIC_2 0x81638340 + +#define TEST_ALLOC_MAGIC 0x1234adcd + +/** magic number and sequence at start of packet payload */ +typedef struct ODP_PACKED { + uint32be_t magic; + uint32be_t seq; +} pkt_head_t; + +/** magic number at end of packet payload */ +typedef struct ODP_PACKED { + uint32be_t magic; +} pkt_tail_t; + +/** Application argument */ +char *pktio_name; + +/** Run time in seconds */ +int run_time_sec; + +/* helper funcs */ +void parse_args(int argc, char *argv[]); +void print_info(char *progname); +void usage(char *progname); +odp_pktio_t create_pktio(const char *dev, odp_pool_t pool); +int ipc_odp_packet_sendall(odp_pktio_t pktio, + odp_packet_t pkt_tbl[], int num); diff --git a/platform/linux-generic/test/pktio_ipc/pktio_ipc1.c b/platform/linux-generic/test/pktio_ipc/pktio_ipc1.c new file mode 100644 index 0000000..d2d6038 --- /dev/null +++ b/platform/linux-generic/test/pktio_ipc/pktio_ipc1.c @@ -0,0 +1,268 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "ipc_common.h" + +/** + * @file + * @example pktio_ipc1.c ODP IPC example application. + * This application works in pair with pktio_ipc2 application. + * It opens ipc pktio, allocates packets, sets magic number and + * sends packets to ipc pktio. Then app reads packets and checks + * that magic number was properly updated and there is no packet + * loss (i.e. sequesce counter continiusly incrementing.) + */ + +/** + * Packet IO loopback worker thread using bursts from/to IO resources + * + * @param arg thread arguments of type 'thread_args_t *' + */ +static int pktio_run_loop(odp_pool_t pool) +{ + int thr; + int pkts; + odp_pktio_t ipc_pktio; + odp_packet_t pkt_tbl[MAX_PKT_BURST]; + uint64_t cnt = 0; /* increasing counter on each send packet */ + uint64_t cnt_recv = 0; /* increasing counter to validate + cnt on receive */ + uint64_t stat_pkts = 0; + uint64_t stat_pkts_alloc = 0; + uint64_t stat_pkts_prev = 0; + uint64_t stat_errors = 0; + uint64_t start_cycle; + uint64_t current_cycle; + uint64_t cycle; + uint64_t diff; + uint64_t onesec_cycles; + + thr = odp_thread_id(); + + ipc_pktio = odp_pktio_lookup("ipc_pktio"); + if (ipc_pktio == ODP_PKTIO_INVALID) { + EXAMPLE_ERR(" [%02i] Error: lookup of pktio %s failed\n", + thr, "ipc_pktio"); + return -2; + } + printf(" [%02i] looked up ipc_pktio:%02" PRIu64 ", burst mode\n", + thr, odp_pktio_to_u64(ipc_pktio)); + + onesec_cycles = odp_time_ns_to_cycles(ODP_TIME_SEC); + start_cycle = odp_time_cycles(); + current_cycle = start_cycle; + + /* packets loop */ + for (;;) { + int i; + int ret; + + /* 1. exit loop if time specified */ + cycle = odp_time_cycles(); + if (run_time_sec) { + diff = odp_time_diff_cycles(start_cycle, cycle); + if (odp_time_ns_to_cycles(run_time_sec * + ODP_TIME_SEC) < diff) + break; + } + + /* 2. Receive packets back from ipc_pktio, validate magic + * number sequence counter and free that packet + */ + while (1) { + pkts = odp_pktio_recv(ipc_pktio, pkt_tbl, + MAX_PKT_BURST); + if (pkts <= 0) + break; + + for (i = 0; i < pkts; i++) { + odp_packet_t pkt = pkt_tbl[i]; + pkt_head_t head; + pkt_tail_t tail; + size_t off; + + off = odp_packet_l4_offset(pkt); + if (off == ODP_PACKET_OFFSET_INVALID) + EXAMPLE_ABORT("invalid l4 offset\n"); + + off += ODPH_UDPHDR_LEN; + ret = odp_packet_copydata_out(pkt, off, + sizeof(head), + &head); + if (ret) { + stat_errors++; + odp_packet_free(pkt); + EXAMPLE_DBG("error\n"); + continue; + } + + if (head.magic == TEST_ALLOC_MAGIC) { + stat_pkts_alloc++; + odp_packet_free(pkt); + continue; + } + + if (head.magic != TEST_SEQ_MAGIC_2) { + stat_errors++; + odp_packet_free(pkt); + EXAMPLE_DBG("error\n"); + continue; + } + + off = odp_packet_len(pkt) - sizeof(pkt_tail_t); + ret = odp_packet_copydata_out(pkt, off, + sizeof(tail), + &tail); + if (ret) { + stat_errors++; + odp_packet_free(pkt); + continue; + } + + if (tail.magic != TEST_SEQ_MAGIC) { + stat_errors++; + odp_packet_free(pkt); + continue; + } + + cnt_recv++; + + if (head.seq != cnt_recv) { + stat_errors++; + odp_packet_free(pkt); + EXAMPLE_DBG("head.seq %d - " + "cnt_recv %" PRIu64 "" + " = %" PRIu64 "\n", + head.seq, cnt_recv, + head.seq - cnt_recv); + cnt_recv = head.seq; + continue; + } + + stat_pkts++; + odp_packet_free(pkt); + } + } + + /* 3. emulate that pkts packets were received */ + odp_random_data((uint8_t *)&pkts, sizeof(pkts), 0); + pkts = ((pkts & 0xffff) % MAX_PKT_BURST) + 1; + + for (i = 0; i < pkts; i++) { + odp_packet_t pkt; + + pkt = odp_packet_alloc(pool, SHM_PKT_POOL_BUF_SIZE); + if (pkt == ODP_PACKET_INVALID) { + pkts = i; + EXAMPLE_DBG("unable to alloc packet pkts %d\n", + pkts); + sleep(3); + break; + } + odp_packet_l4_offset_set(pkt, 30); + + pkt_tbl[i] = pkt; + } + pkts = i; + + /* 4. Copy counter and magic numbers to that packets */ + for (i = 0; i < pkts; i++) { + pkt_head_t head; + pkt_tail_t tail; + size_t off; + odp_packet_t pkt = pkt_tbl[i]; + + off = odp_packet_l4_offset(pkt); + if (off == ODP_PACKET_OFFSET_INVALID) + EXAMPLE_ABORT("packet L4 offset not set"); + + head.magic = TEST_SEQ_MAGIC; + head.seq = cnt++; + + off += ODPH_UDPHDR_LEN; + ret = odp_packet_copydata_in(pkt, off, sizeof(head), + &head); + if (ret) + EXAMPLE_ABORT("unable to copy in head data"); + + tail.magic = TEST_SEQ_MAGIC; + off = odp_packet_len(pkt) - sizeof(pkt_tail_t); + ret = odp_packet_copydata_in(pkt, off, sizeof(tail), + &tail); + if (ret) + EXAMPLE_ABORT("unable to copy in tail data"); + } + + /* 5. Send packets to ipc_pktio */ + ret = ipc_odp_packet_sendall(ipc_pktio, pkt_tbl, pkts); + if (ret < 0) + EXAMPLE_DBG("error sending to ipc pktio\n"); + + /* 6. Print stats */ + cycle = odp_time_cycles(); + diff = odp_time_diff_cycles(current_cycle, cycle); + if (onesec_cycles < diff) { + current_cycle = cycle; + printf("\rpkts: %" PRIu64 ", alloc %" PRIu64 "," + " errors %" PRIu64 ", pps %" PRIu64 ".", + stat_pkts, stat_pkts_alloc, stat_errors, + (stat_pkts + stat_pkts_alloc - stat_pkts_prev)); + fflush(stdout); + stat_pkts_prev = stat_pkts + stat_pkts_alloc; + } + } + + return stat_errors > 10 ? -1 : 0; +} + +/** + * ODP packet example main function + */ +int main(int argc, char *argv[]) +{ + odp_pool_t pool; + odp_pool_param_t params; + int ret; + + /* Parse and store the application arguments */ + parse_args(argc, argv); + + /* Init ODP before calling anything else */ + if (odp_init_global(NULL, NULL)) { + EXAMPLE_ERR("Error: ODP global init failed.\n"); + exit(EXIT_FAILURE); + } + + /* Init this thread */ + if (odp_init_local(ODP_THREAD_CONTROL)) { + EXAMPLE_ERR("Error: ODP local init failed.\n"); + exit(EXIT_FAILURE); + } + + /* Print both system and application information */ + print_info(NO_PATH(argv[0])); + + /* Create packet pool */ + memset(¶ms, 0, sizeof(params)); + params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; + params.pkt.len = SHM_PKT_POOL_BUF_SIZE; + params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUF_SIZE; + params.type = ODP_POOL_PACKET; + + pool = odp_pool_create("packet_pool", ¶ms); + if (pool == ODP_POOL_INVALID) { + EXAMPLE_ERR("Error: packet pool create failed.\n"); + exit(EXIT_FAILURE); + } + + odp_pool_print(pool); + + create_pktio(pktio_name, pool); + + ret = pktio_run_loop(pool); + + return ret; +} diff --git a/platform/linux-generic/test/pktio_ipc/pktio_ipc2.c b/platform/linux-generic/test/pktio_ipc/pktio_ipc2.c new file mode 100644 index 0000000..d860416 --- /dev/null +++ b/platform/linux-generic/test/pktio_ipc/pktio_ipc2.c @@ -0,0 +1,142 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * @example pktio_ipc2.c ODP IPC example application. + * This application works in pair with pktio_ipc1 application. + * It opens ipc pktio, reads packets and updates magic number. + * Also it allocates some packets from internal pool and sends + * to ipc pktio. + */ + +#include "ipc_common.h" + +static int ipc_second_process(void) +{ + odp_pktio_t pktio; + odp_pool_param_t params; + odp_pool_t pool; + odp_packet_t pkt_tbl[MAX_PKT_BURST]; + odp_packet_t alloc_pkt; + int pkts; + int ret; + int i; + uint64_t start_cycle; + uint64_t cycle; + uint64_t diff; + + /* Create packet pool */ + memset(¶ms, 0, sizeof(params)); + params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE; + params.pkt.len = SHM_PKT_POOL_BUF_SIZE; + params.pkt.num = SHM_PKT_POOL_SIZE / SHM_PKT_POOL_BUF_SIZE; + params.type = ODP_POOL_PACKET; + + pool = odp_pool_create("packet_pool2", ¶ms); + if (pool == ODP_POOL_INVALID) { + EXAMPLE_ERR("Error: packet pool create failed.\n"); + exit(EXIT_FAILURE); + } + + pktio = create_pktio("xxx", pool); + + start_cycle = odp_time_cycles(); + + for (;;) { + /* exit loop if time specified */ + if (run_time_sec) { + cycle = odp_time_cycles(); + diff = odp_time_diff_cycles(start_cycle, cycle); + if (odp_time_ns_to_cycles(run_time_sec * + ODP_TIME_SEC) < diff) + break; + } + + /* recv some packets and change MAGIC to MAGIC_2 */ + pkts = odp_pktio_recv(pktio, pkt_tbl, MAX_PKT_BURST); + if (pkts <= 0) + continue; + + for (i = 0; i < pkts; i++) { + odp_packet_t pkt = pkt_tbl[i]; + pkt_head_t head; + size_t off; + + off = odp_packet_l4_offset(pkt); + if (off == ODP_PACKET_OFFSET_INVALID) + EXAMPLE_ABORT("invalid l4 offset\n"); + + off += ODPH_UDPHDR_LEN; + ret = odp_packet_copydata_out(pkt, off, sizeof(head), + &head); + if (ret) + EXAMPLE_ABORT("unable copy out head data"); + + if (head.magic != TEST_SEQ_MAGIC) + EXAMPLE_ABORT("Wrong head magic!"); + + /* Modify magic number in packet */ + head.magic = TEST_SEQ_MAGIC_2; + ret = odp_packet_copydata_in(pkt, off, sizeof(head), + &head); + if (ret) + EXAMPLE_ABORT("unable to copy in head data"); + } + + /* send all packets back */ + ret = ipc_odp_packet_sendall(pktio, pkt_tbl, pkts); + if (ret < 0) + EXAMPLE_ABORT("can not send packets\n"); + + /* alloc packet from local pool, set magic to ALLOC_MAGIC, + * and send it.*/ + alloc_pkt = odp_packet_alloc(pool, SHM_PKT_POOL_BUF_SIZE); + if (alloc_pkt != ODP_PACKET_INVALID) { + pkt_head_t head; + size_t off; + + odp_packet_l4_offset_set(alloc_pkt, 30); + + head.magic = TEST_ALLOC_MAGIC; + + off = odp_packet_l4_offset(alloc_pkt); + off += ODPH_UDPHDR_LEN; + ret = odp_packet_copydata_in(alloc_pkt, off, + sizeof(head), + &head); + if (ret) + EXAMPLE_ABORT("unable to copy in head data"); + + pkt_tbl[0] = alloc_pkt; + ret = ipc_odp_packet_sendall(pktio, pkt_tbl, 1); + if (ret < 0) + EXAMPLE_ABORT("can not send packets\n"); + } + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + /* Parse and store the application arguments */ + parse_args(argc, argv); + + if (odp_init_global(NULL, NULL)) { + EXAMPLE_ERR("Error: ODP global init failed.\n"); + exit(EXIT_FAILURE); + } + + /* Init this thread */ + if (odp_init_local(ODP_THREAD_CONTROL)) { + EXAMPLE_ERR("Error: ODP local init failed.\n"); + exit(EXIT_FAILURE); + } + + return ipc_second_process(); +} diff --git a/platform/linux-generic/test/pktio_ipc/pktio_ipc_run b/platform/linux-generic/test/pktio_ipc/pktio_ipc_run new file mode 100755 index 0000000..8eab487 --- /dev/null +++ b/platform/linux-generic/test/pktio_ipc/pktio_ipc_run @@ -0,0 +1,55 @@ +#!/bin/sh +# +# Copyright (c) 2015, Linaro Limited +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +# directories where test binary can be found: +# -in the validation dir when running make check (intree or out of tree) +# -in the script directory, when running after 'make install', or +# -in the validation when running standalone (./pktio_ipc_run) intree. +# -in the current directory. +# running stand alone out of tree requires setting PATH +PATH=./pktio_ipc:$PATH +PATH=$(dirname $0):$PATH +PATH=$(dirname $0)/../../../../platform/linux-generic/test/pktio_ipc:$PATH +PATH=.:$PATH + +run() +{ + local ret=0 + + echo "==== run pktio_ipc1 then pktio_ipc2 ====" + rm -rf /dev/shm/ipc_pktio_* + + pktio_ipc1${EXEEXT} -t 15 & + IPC_PID=$! + + pktio_ipc2${EXEEXT} -t 10 + ret=$? + kill ${IPC_PID} || true + + if [ $ret -ne 0 ]; then + echo "!!! FAILED !!!" + exit $ret + fi + + sleep 1 + echo "==== run pktio_ipc2 then pktio_ipc1 ====" + rm -rf /dev/shm/ipc_pktio_* + + pktio_ipc2${EXEEXT} -t 25 & + IPC_PID=$! + + pktio_ipc1${EXEEXT} -t 20 + ret=$? + kill ${IPC_PID} || true + + exit $ret +} + +case "$1" in + *) run ;; +esac