From patchwork Tue Aug 18 11:01:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 52505 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by patches.linaro.org (Postfix) with ESMTPS id E489522DB1 for ; Tue, 18 Aug 2015 11:15:04 +0000 (UTC) Received: by labth1 with SMTP id th1sf56258531lab.2 for ; Tue, 18 Aug 2015 04:15:03 -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=fs+T4Mggm1YM7KGoIuQKLqlQ6AmMUd4iEml7R//NmTI=; b=IPBe+ZYxloqqx8c6K/24tx19wh9oRbi5zEuJoH0gykLiBQpSjvd0mn5QDltBcnp1+4 unWa2141yOa2mkZCAhDEm8iZ9eDRNEOG2afHay8a2/1lhxn8DA93QeJyjwhI8eku1a9y 0mQK4xfPwtz2bHxK2PMubSoxwdzqL+D65yT3x65eudePzTx0IzkYgPBb6obUfh9ifPfb AX9y9+Ib/e3v5zCGzOynH9oFs4AA5C5YTbBExhJkqG+9rvFv6bsK/XBG5K7tBIVLwIxw 9T/GJ9zxR9O6XaXL21LG1WKt5rvqV1twfpv/9ZtwXmd/cOYC0fvvRJnsH3BvIWajufCA U3Bw== X-Gm-Message-State: ALoCoQn/KZ560XtP2IVpAjBOpFHAXwPrSyUtMyCpgcJBD4SAr29hFfNjZQe0egRLVjb0HL6UFpnW X-Received: by 10.194.80.69 with SMTP id p5mr1659896wjx.2.1439896503504; Tue, 18 Aug 2015 04:15:03 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.103 with SMTP id l7ls778670laf.35.gmail; Tue, 18 Aug 2015 04:15:03 -0700 (PDT) X-Received: by 10.112.51.133 with SMTP id k5mr5647906lbo.107.1439896503193; Tue, 18 Aug 2015 04:15:03 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id bw10si13886047lbc.114.2015.08.18.04.15.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Aug 2015 04:15:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by labd1 with SMTP id d1so97528675lab.1 for ; Tue, 18 Aug 2015 04:15:03 -0700 (PDT) X-Received: by 10.152.203.134 with SMTP id kq6mr5883779lac.106.1439896502933; Tue, 18 Aug 2015 04:15:02 -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.162.200 with SMTP id yc8csp411592lbb; Tue, 18 Aug 2015 04:15:01 -0700 (PDT) X-Received: by 10.50.143.2 with SMTP id sa2mr15620407igb.72.1439896498228; Tue, 18 Aug 2015 04:14:58 -0700 (PDT) Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id w2si9513651igl.17.2015.08.18.04.14.57; Tue, 18 Aug 2015 04:14:58 -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 3262561F63; Tue, 18 Aug 2015 11:14:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252.ec2.internal 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 ip-10-142-244-252.ec2.internal (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 2EB6461F70; Tue, 18 Aug 2015 11:03:44 +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 F14E161F9C; Tue, 18 Aug 2015 11:03:38 +0000 (UTC) Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by lists.linaro.org (Postfix) with ESMTPS id 44C4B61F63 for ; Tue, 18 Aug 2015 11:02:01 +0000 (UTC) Received: by wicja10 with SMTP id ja10so104925686wic.1 for ; Tue, 18 Aug 2015 04:02:00 -0700 (PDT) X-Received: by 10.194.113.101 with SMTP id ix5mr12563433wjb.66.1439895720520; Tue, 18 Aug 2015 04:02:00 -0700 (PDT) Received: from localhost.localdomain ([87.120.178.39]) by smtp.gmail.com with ESMTPSA id e8sm20892047wiz.0.2015.08.18.04.01.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Aug 2015 04:01:59 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Tue, 18 Aug 2015 14:01:38 +0300 Message-Id: <1439895698-18597-13-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1439895698-18597-1-git-send-email-maxim.uvarov@linaro.org> References: <1439895698-18597-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv8 12/12] 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.215.48 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 Simple example app creates one packet i/o to external interface and one ipc pktio to other process. Then transfer packet from external interface to other process and back thought ipc queue. Signed-off-by: Maxim Uvarov --- 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 | 11 + platform/linux-generic/test/pktio_ipc/pktio_ipc.c | 595 +++++++++++++++++++++ .../linux-generic/test/pktio_ipc/pktio_ipc_run | 68 +++ 6 files changed, 679 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/pktio_ipc.c create mode 100755 platform/linux-generic/test/pktio_ipc/pktio_ipc_run diff --git a/platform/linux-generic/m4/configure.m4 b/platform/linux-generic/m4/configure.m4 index ff6ec7d..8733895 100644 --- a/platform/linux-generic/m4/configure.m4 +++ b/platform/linux-generic/m4/configure.m4 @@ -22,4 +22,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/ring/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 d5e78fc..207de74 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 ring +ODP_MODULES = pktio pktio_ipc ring if test_vald TESTS = pktio/pktio_run \ + pktio_ipc/pktio_ipc_run \ ${top_builddir}/platform/linux-generic/test/ring/ring$(EXEEXT) \ ${top_builddir}/test/validation/buffer/buffer_main$(EXEEXT) \ ${top_builddir}/test/validation/classification/classification_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..e02d214 --- /dev/null +++ b/platform/linux-generic/test/pktio_ipc/Makefile.am @@ -0,0 +1,11 @@ +include $(top_srcdir)/test/Makefile.inc +TESTS_ENVIRONMENT += TEST_DIR=${top_builddir}/test/validation + +bin_PROGRAMS = pktio_ipc + +pktio_ipc_CFLAGS = $(AM_CFLAGS) -I${top_srcdir}/example +pktio_ipc_LDFLAGS = $(AM_LDFLAGS) -static + +noinst_HEADERS = $(top_srcdir)/test/test_debug.h + +dist_pktio_ipc_SOURCES = pktio_ipc.c diff --git a/platform/linux-generic/test/pktio_ipc/pktio_ipc.c b/platform/linux-generic/test/pktio_ipc/pktio_ipc.c new file mode 100644 index 0000000..e1febe9 --- /dev/null +++ b/platform/linux-generic/test/pktio_ipc/pktio_ipc.c @@ -0,0 +1,595 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * @example odp_ipc.c ODP IPC example application. + * This example application uses fork() at early start to create 2 + * completely separate processes. Then in main process it + * allocates packet with head and tail magic numbers and packet + * sequence counter inside. Then it sends that packet to second + * process which verifies head magic and modifies that head magic + * to new number. Then packet sent back to main process. Then main + * process validates modified head magic number, tail magic number + * and sequence counter. Master process also prints packet per + * second statistic and packet counters. + */ + +#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 + +/** Application argument */ +static char *pktio_name; + +/** Run time in seconds */ +static int run_time_sec; + +/** 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; + +/* helper funcs */ +static void parse_args(int argc, char *argv[]); +static void print_info(char *progname); +static void usage(char *progname); + +static void busy_sleep(int sec) +{ + uint64_t start_cycle; + uint64_t cycle; + uint64_t diff; + uint64_t wait; + + wait = odp_time_ns_to_cycles(sec * ODP_TIME_SEC); + + start_cycle = odp_time_cycles(); + while (1) { + cycle = odp_time_cycles(); + diff = odp_time_diff_cycles(start_cycle, cycle); + if (wait < diff) + break; + } +} + +/** + * 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. + */ +static odp_pktio_t create_pktio(const char *dev, odp_pool_t pool) +{ + odp_pktio_t pktio; + odp_pktio_t ipc_pktio; + + /* Open a packet IO instance */ + pktio = odp_pktio_open(dev, pool); + if (pktio == ODP_PKTIO_INVALID) + EXAMPLE_ABORT("Error: pktio create failed for %s\n", dev); + + printf("pid: %d, create IPC pktio\n", getpid()); + ipc_pktio = odp_pktio_open("ipc_pktio", pool); + if (ipc_pktio == ODP_PKTIO_INVALID) + EXAMPLE_ABORT("Error: ipc pktio create failed.\n"); + + return pktio; +} + +/** + * 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 pktio; + 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_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(); + + pktio = odp_pktio_lookup(pktio_name); + if (pktio == ODP_PKTIO_INVALID) { + EXAMPLE_ERR(" [%02i] Error: lookup of pktio %s failed\n", + thr, pktio_name); + return -1; + } + + printf(" [%02i] looked up pktio:%02" PRIu64 ", burst mode\n", + thr, odp_pktio_to_u64(pktio)); + + ipc_pktio = odp_pktio_lookup("ipc_pktio"); + if (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 sent; + int ret; + + /* 1. 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; + printf("unable to alloc packet pkts %d\n", + pkts); + break; + } + odp_packet_l4_offset_set(pkt, 30); + + pkt_tbl[i] = pkt; + } + + /* 2. 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"); + } + + /* 3. Send packets to ipc_pktio */ + sent = odp_pktio_send(ipc_pktio, pkt_tbl, pkts); + if (sent < 0) + EXAMPLE_ABORT("error sending to ipc pktio\n"); + if (sent != pkts) { + for (i = sent; i < pkts; i++) + odp_packet_free(pkt_tbl[i]); + } + + /* 4. 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; + int err = 0; + + 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_2) + err++; + + off = odp_packet_len(pkt) - sizeof(pkt_tail_t); + ret = odp_packet_copydata_out(pkt, off, + sizeof(tail), + &tail); + if (ret) + EXAMPLE_ABORT("unable copy out tail data"); + + if (tail.magic != TEST_SEQ_MAGIC) + err++; + + if (head.seq != cnt_recv++) + err++; + + if (odp_unlikely(err)) + stat_errors++; + else + stat_pkts++; + + odp_packet_free(pkt); + } + } + + /* 5. Print stats */ + cycle = odp_time_cycles(); + diff = odp_time_diff_cycles(current_cycle, cycle); + if (onesec_cycles < diff) { + current_cycle = cycle; + printf("pkts: %" PRIu64 ", errors %" PRIu64 ", pps %" PRIu64 ".\n", + stat_pkts, stat_errors, + (stat_pkts - stat_pkts_prev)); + stat_pkts_prev = stat_pkts; + } + + /* 6. 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; + } + } + + return stat_errors ? -3 : 0; +} + +static void ipc_second_exit(int sig EXAMPLE_UNUSED) +{ + exit(0); +} + +static int ipc_second_process(void) +{ + odp_pktio_t pktio; + odp_packet_t pkt_tbl[MAX_PKT_BURST]; + int pkts; + int ret; + int i; + uint64_t start_cycle; + uint64_t cycle; + uint64_t diff; + + signal(SIGTERM, (void (*)(int))ipc_second_exit); + + /* linux shared memory can already have objects with names which + * second process can try to connect. That might be even interrupted + * current application. Might be later I will add magic numbers to + * each ipc object in linux-generic. HW platform should not have that + * problem. So just wait a little while master process will create + * all ipc objects before connecting to them. + */ + busy_sleep(3); + + /* Do lookup packet I/O in IPC shared memory, + * and link it to local pool. */ + while (1) { + pktio = odp_pktio_open("ipc_pktio", ODP_POOL_INVALID); + if (pktio == ODP_PKTIO_INVALID) { + busy_sleep(1); + printf("%s() pid %d: looking for ipc_pktio\n", + __func__, getpid()); + continue; + } + break; + } + + start_cycle = odp_time_cycles(); + + for (;;) { + 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"); + } + + odp_pktio_send(pktio, pkt_tbl, pkts); + + /* 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; + } + } + + return 0; +} + +/** + * ODP packet example main function + */ +int main(int argc, char *argv[]) +{ + odp_pool_t pool; + odp_pool_param_t params; + int f; + int status; + int ret; + + /* Parse and store the application arguments */ + parse_args(argc, argv); + + /* Use fork() before odp_init_global() to have 2 isolated + * processes which need communicate to each other with + * shared memory. + */ + f = fork(); + if (!f) { + printf("Process one pid: %d\n", getpid()); + /* 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); + } + + ipc_second_process(); + return 0; + } + + printf("Process two pid: %d, parent %d\n", getpid(), f); + + /* 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); + + kill(f, SIGTERM); + waitpid(f, &status, WNOHANG); + + return ret; +} + +/** + * Parse and store the command line arguments + * + * @param argc argument count + * @param argv[] argument vector + * @param appl_args Store application arguments here + */ +static void parse_args(int argc, char *argv[]) +{ + int opt; + int long_index; + size_t len; + static struct option longopts[] = { + {"interface", required_argument, NULL, 'i'}, /* return 'i' */ + {"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:i:h", + longopts, &long_index); + + if (opt == -1) + break; /* No more options */ + + switch (opt) { + case 'i': + len = strlen(optarg); + if (len == 0) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + len += 1; /* add room for '\0' */ + + pktio_name = malloc(len); + if (!pktio_name) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + strcpy(pktio_name, optarg); + + break; + case 't': + run_time_sec = atoi(optarg); + break; + case 'h': + usage(argv[0]); + exit(EXIT_SUCCESS); + break; + + default: + break; + } + } + + if (!pktio_name) { + usage(argv[0]); + exit(EXIT_FAILURE); + } + + optind = 1; /* reset 'extern optind' from the getopt lib */ +} + +/** + * Print system and application info + */ +static 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 + */ +static void usage(char *progname) +{ + printf("\n" + "Usage: %s OPTIONS\n" + " E.g. %s -i eth0\n" + "\n" + "OpenDataPlane example application.\n" + "\n" + "Mandatory OPTIONS:\n" + " -i, --interface Eth interface\n" + "\n" + "Optional OPTIONS\n" + " -h, --help Display help and exit.\n" + " environment variables: ODP_PKTIO_DISABLE_SOCKET_MMAP\n" + " ODP_PKTIO_DISABLE_SOCKET_MMSG\n" + " ODP_PKTIO_DISABLE_SOCKET_BASIC\n" + " can be used to advanced pkt I/O selection for linux-generic\n" + "\n", NO_PATH(progname), NO_PATH(progname) + ); +} 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..e126a7b --- /dev/null +++ b/platform/linux-generic/test/pktio_ipc/pktio_ipc_run @@ -0,0 +1,68 @@ +#!/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=${TEST_DIR}/pktio:$PATH +PATH=$(dirname $0):$PATH +PATH=$(dirname $0)/../../../../test/validation/pktio:$PATH +PATH=.:$PATH + +# directory where platform test sources are, including scripts +TEST_SRC_DIR=$(dirname $0) + +# exit codes expected by automake for skipped tests +TEST_SKIPPED=77 + +# Use installed pktio env or for make check take it from platform directory +if [ -f "./pktio_env" ]; then + . ./../pktio/pktio_env +elif [ -f ${TEST_SRC_DIR}/../pktio/pktio_env ]; then + . ${TEST_SRC_DIR}/../pktio/pktio_env +else + echo "BUG: unable to find pktio_env!" + echo "pktio_env has to be in current directory or in platform/\$ODP_PLATFORM/test." + echo "ODP_PLATFORM=\"$ODP_PLATFORM\"" + exit 1 +fi + +run() +{ + local ret=0 + + #need to be root to set the interface: if not, run with default loopback. + if [ "$(id -u)" != "0" ]; then + echo "Need to be root to create shared memory objects" + exit $TEST_SKIPPED + fi + + setup_pktio_env + + pktio_ipc${EXEEXT} -i $IF0 -t 5 + if [ $? -ne 0 ]; then + ret=1 + fi + + cleanup_pktio_env + + if [ $ret -ne 0 ]; then + echo "!!! FAILED !!!" + fi + + exit $ret +} + +case "$1" in + setup) setup_pktio_env ;; + cleanup) cleanup_pktio_env ;; + *) run ;; +esac