From patchwork Wed Nov 18 09:41:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 56931 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2459780lbb; Wed, 18 Nov 2015 01:46:14 -0800 (PST) X-Received: by 10.140.143.17 with SMTP id 17mr509073qhp.36.1447839973073; Wed, 18 Nov 2015 01:46:13 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j141si1366493qhc.86.2015.11.18.01.46.12; Wed, 18 Nov 2015 01:46:13 -0800 (PST) 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; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro-org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id B91BA61D83; Wed, 18 Nov 2015 09:46:12 +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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, 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 B144161DAF; Wed, 18 Nov 2015 09:42:31 +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 059D661D91; Wed, 18 Nov 2015 09:42:28 +0000 (UTC) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com [209.85.217.179]) by lists.linaro.org (Postfix) with ESMTPS id BB27061DAF for ; Wed, 18 Nov 2015 09:41:46 +0000 (UTC) Received: by lbbcs9 with SMTP id cs9so21044714lbb.1 for ; Wed, 18 Nov 2015 01:41:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YlbuDOrTCYQ6In3vQ37vPAXRQbw/8mlmtIngNSuZEDU=; b=TCJ81iQAa0vnd8BqfYfBNgZLbfxhybAVTOqevRM/gIFWE+GZPux/edrCjBqs1idy6s CCnT6SarTJsgOFQt1aU8pAaNWULpe7YTJHHDKfmjAxd+d0q/9/4c/mG54FLBOy9I/UWD Po/QnLdZCTOhiB7V93sVlvg1vegU9ioB2TDL37KqlpV7Kig3NCAKR9aXgZl+rVg3WgRc WiqNepW0VySbaGFVrjFSzKkRd8BhVf1dC7b9cC8IzM3YfjpQEKLhry1LchI134skhFxl CsaPsVGxgIrnUw/c32qbfMw0uq0HR6UaYh6s+5axOfPUwBTe75WoCFSip1yiA0mr6ReF b7Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YlbuDOrTCYQ6In3vQ37vPAXRQbw/8mlmtIngNSuZEDU=; b=AzyqwoDLW8m60JbsFAyN9K09GkARwlxSMz5bi91++6PR/j7IqZZOEJRTj8kmFR5+ob C6C3VJ46RmK+2na10aAJL+g96ciJ8MiBtWBUNUU64GPWIo1ABX+xyEFmzcUcOmH6q8zm sauUDP5sIuIBCxPJWevRBL3EQbPeMCgtLCP7A+O/gfzLbAAor+3K+0Gw45Dq7y681te7 Mpbt35AOKJo48l8755mVQADnjogqCzkqiDVJBOq+4IQFkG9T2zs9YxRHJfsUumoAxQqP TspCYeWomQmSJgH8ucr7i/DCRfKB8Wil2Ogp0kH87R1e++Zmy88+rgp2TbaID/bDw+z/ pKCQ== X-Gm-Message-State: ALoCoQkQ31PYzlZ0JYacHdDoC7yY3xuTrdsgHYQzqT5CdhFt2vhp8zRGcClobmRTQbf6LDoq0hgv X-Received: by 10.112.161.168 with SMTP id xt8mr247710lbb.88.1447839705650; Wed, 18 Nov 2015 01:41:45 -0800 (PST) Received: from localhost.localdomain (ppp91-76-161-180.pppoe.mtu-net.ru. [91.76.161.180]) by smtp.gmail.com with ESMTPSA id g80sm296088lfg.44.2015.11.18.01.41.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 18 Nov 2015 01:41:45 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 18 Nov 2015 12:41:37 +0300 Message-Id: <1447839697-21140-6-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447839697-21140-1-git-send-email-maxim.uvarov@linaro.org> References: <1447839697-21140-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv3 5/5] validation: implement pktio statistics counters X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" Signed-off-by: Maxim Uvarov --- test/validation/pktio/pktio.c | 134 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index 6320b77..9f05392 100644 --- a/test/validation/pktio/pktio.c +++ b/test/validation/pktio/pktio.c @@ -23,6 +23,8 @@ #define TEST_SEQ_MAGIC 0x92749451 #define TX_BATCH_LEN 4 +#undef DEBUG_STATS + /** interface names used for testing */ static const char *iface_name[MAX_NUM_IFACES]; @@ -690,6 +692,137 @@ void pktio_test_inq(void) CU_ASSERT(odp_pktio_close(pktio) == 0); } +#ifdef DEBUG_STATS +static void _print_pktio_stats(odp_pktio_stats_t *s, const char *name) +{ + fprintf(stderr, "\n%s:\n" + " in_octets %"PRIu64"\n" + " in_ucast_pkts %"PRIu64"\n" + " in_discards %"PRIu64"\n" + " in_errors %"PRIu64"\n" + " in_unknown_protos %"PRIu64"\n" + " out_octets %"PRIu64"\n" + " out_ucast_pkts %"PRIu64"\n" + " out_discards %"PRIu64"\n" + " out_errors %"PRIu64"\n", + name, + s->in_octets, + s->in_ucast_pkts, + s->in_discards, + s->in_errors, + s->in_unknown_protos, + s->out_octets, + s->out_ucast_pkts, + s->out_discards, + s->out_errors); +} +#endif + +static void pktio_test_statistics_counters(void) +{ + odp_pktio_t pktio[MAX_NUM_IFACES]; + odp_packet_t pkt; + odp_event_t tx_ev[1000]; + odp_event_t ev; + int i, pkts, ret, alloc = 0; + odp_queue_t outq; + uint64_t wait = odp_schedule_wait_time(ODP_TIME_MSEC); + odp_pktio_stats_t stats[2]; + + for (i = 0; i < num_ifaces; i++) { + pktio[i] = create_pktio(i, ODP_PKTIN_MODE_SCHED); + CU_ASSERT_FATAL(pktio[i] != ODP_PKTIO_INVALID); + create_inq(pktio[i], ODP_QUEUE_TYPE_SCHED); + } + + outq = odp_pktio_outq_getdef(pktio[0]); + + ret = odp_pktio_start(pktio[0]); + CU_ASSERT(ret == 0); + if (num_ifaces > 1) { + ret = odp_pktio_start(pktio[1]); + CU_ASSERT(ret == 0); + } + + /* flush packets with magic number in pipes */ + for (i = 0; i < 1000; i++) { + ev = odp_schedule(NULL, wait); + if (ev != ODP_EVENT_INVALID) + odp_event_free(ev); + } + + /* alloc */ + for (alloc = 0; alloc < 1000; alloc++) { + pkt = odp_packet_alloc(default_pkt_pool, packet_len); + if (pkt == ODP_PACKET_INVALID) + break; + pktio_init_packet(pkt); + tx_ev[alloc] = odp_packet_to_event(pkt); + } + + ret = odp_pktio_stats_reset(pktio[0]); + CU_ASSERT(ret == 0); + if (num_ifaces > 1) { + ret = odp_pktio_stats_reset(pktio[1]); + CU_ASSERT(ret == 0); + } + + /* send */ + for (pkts = 0; pkts != alloc; ) { + ret = odp_queue_enq_multi(outq, &tx_ev[pkts], alloc - pkts); + if (ret < 0) { + CU_FAIL("unable to enqueue packet\n"); + break; + } + pkts += ret; + } + + /* get */ + for (i = 0, pkts = 0; i < 1000; i++) { + ev = odp_schedule(NULL, wait); + if (ev != ODP_EVENT_INVALID) { + if (odp_event_type(ev) == ODP_EVENT_PACKET) { + pkt = odp_packet_from_event(ev); + if (pktio_pkt_seq(pkt) != TEST_SEQ_INVALID) + pkts++; + } + odp_event_free(ev); + } + } + + ret = odp_pktio_stats(pktio[0], &stats[0]); + CU_ASSERT(ret == 0); + + if (num_ifaces > 1) { + ret = odp_pktio_stats(pktio[1], &stats[1]); + CU_ASSERT(ret == 0); + CU_ASSERT(stats[1].in_ucast_pkts >= (uint64_t)pkts); + CU_ASSERT(stats[0].out_ucast_pkts == stats[1].in_ucast_pkts); + CU_ASSERT(stats[0].out_octets == stats[1].in_octets); + CU_ASSERT(stats[0].out_octets >= + (PKT_LEN_NORMAL * (uint64_t)pkts)); + } else { + CU_ASSERT(stats[0].in_ucast_pkts == (uint64_t)pkts); + CU_ASSERT(stats[0].in_octets == + (PKT_LEN_NORMAL * (uint64_t)pkts)); + } + + CU_ASSERT(pkts == alloc); + CU_ASSERT(0 == stats[0].in_discards); + CU_ASSERT(0 == stats[0].in_errors); + CU_ASSERT(0 == stats[0].in_unknown_protos); + CU_ASSERT(0 == stats[0].out_discards); + CU_ASSERT(0 == stats[0].out_errors); + + for (i = 0; i < num_ifaces; i++) { +#ifdef DEBUG_STATS + _print_pktio_stats(&stats[i], iface_name[i]); +#endif + destroy_inq(pktio[i]); + CU_ASSERT(odp_pktio_close(pktio[i]) == 0); + } +} + static void pktio_test_start_stop(void) { odp_pktio_t pktio[MAX_NUM_IFACES]; @@ -1057,6 +1190,7 @@ odp_testinfo_t pktio_suite_unsegmented[] = { ODP_TEST_INFO(pktio_test_mac), ODP_TEST_INFO(pktio_test_inq_remdef), ODP_TEST_INFO(pktio_test_start_stop), + ODP_TEST_INFO(pktio_test_statistics_counters), ODP_TEST_INFO_NULL };